Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ana::FCSurface Class Reference

Pseudo-experiments, binned to match a log-likelihood surface. More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-11-25/CAFAna/FC/FCSurface.h"

Public Member Functions

 FCSurface (int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax)
 
 ~FCSurface ()
 
void Add (const FCPoint &pt, std::string plot)
 
void Add (const FCCollection &coln, std::string plot="delta")
 
TH2 * SurfaceForSignificance (double sig)
 
void DrawBins ()
 
const FCBinGetBin (int x, int y) const
 
const TH2F * Binning () const
 
void SaveToFile (const std::string &fname) const
 

Static Public Member Functions

static std::unique_ptr< FCSurfaceLoadFromFile (const std::string &fname)
 

Protected Member Functions

 FCSurface ()
 

Protected Attributes

TH2F * fBinning
 
std::vector< FCBinfBins
 
bool fPrintedWarning
 

Detailed Description

Pseudo-experiments, binned to match a log-likelihood surface.

Definition at line 14 of file FCSurface.h.

Constructor & Destructor Documentation

ana::FCSurface::FCSurface ( int  nbinsx,
double  xmin,
double  xmax,
int  nbinsy,
double  ymin,
double  ymax 
)

Definition at line 20 of file FCSurface.cxx.

References fBinning, fBins, fPrintedWarning, and ana::UniqueName().

22  {
23  DontAddDirectory guard;
24 
25  fBinning = new TH2F(UniqueName().c_str(), "",
26  nbinsx, xmin, xmax, nbinsy, ymin, ymax);
27 
28  fBins.resize((nbinsx+2)*(nbinsy+2));
29  fPrintedWarning = false;
30  }
std::map< std::string, double > xmax
std::vector< FCBin > fBins
Definition: FCSurface.h:38
Double_t ymax
Definition: plot.C:25
bool fPrintedWarning
Definition: FCSurface.h:39
TH2F * fBinning
Definition: FCSurface.h:37
Int_t nbinsx
Definition: plot.C:23
Double_t ymin
Definition: plot.C:24
std::string UniqueName()
Return a different string each time, for creating histograms.
Definition: Utilities.cxx:29
ana::FCSurface::~FCSurface ( )

Definition at line 33 of file FCSurface.cxx.

References fBinning.

34  {
35  delete fBinning;
36  }
TH2F * fBinning
Definition: FCSurface.h:37
ana::FCSurface::FCSurface ( )
inlineprotected

Definition at line 35 of file FCSurface.h.

References fPrintedWarning.

35 { fPrintedWarning = false; }
bool fPrintedWarning
Definition: FCSurface.h:39

Member Function Documentation

void ana::FCSurface::Add ( const FCPoint pt,
std::string  plot 
)

Definition at line 39 of file FCSurface.cxx.

References bin, om::cout, allTimeWatchdog::endl, exit(), fBinning, fBins, ana::FCPoint::ProfDmsq(), ana::FCPoint::TrueDelta(), ana::FCPoint::TrueDmsq(), ana::FCPoint::TrueTh13(), ana::FCPoint::TrueTh23(), and ana::FCPoint::Up().

Referenced by Add(), FCCorrectSlice(), joint_fit_2017_contours(), joint_fit_2018_contours(), joint_fit_2019_contours(), nova_official_data_release(), plot_cont_expfriends(), plot_joint_fit_2020_contours(), plotContProf(), and plots().

40  {
41  if(pt.Up()<0)
42  return;
43 
44  int bin;
45  if(plot == "delta")
46  bin = fBinning->FindBin(pt.TrueDelta(), 0);
47  else if(plot == "ssth23")
48  bin = fBinning->FindBin(pt.TrueTh23(), 0);
49  else if(plot == "th13")
50  bin = fBinning->FindBin(pt.TrueTh13(), 0);
51  else if(plot == "dmsq")
52  bin = fBinning->FindBin(pt.TrueDmsq(), 0);
53  else if(plot == "deltassth23")
54  bin = fBinning->FindBin(pt.TrueDelta(), pt.TrueTh23());
55  else if(plot == "ssth23dmsq32") {
56  bin = fBinning->FindBin(pt.TrueTh23(), pt.TrueDmsq());
57  }
58  else if(plot == "deltath13")
59  bin = fBinning->FindBin(pt.TrueTh13(), pt.TrueDelta());
60  else if(plot == "mass")
61  bin = fBinning->FindBin(pt.ProfDmsq(), 0);
62  else {
63  std::cout << "I don't know what plot you're trying to make." << std::endl;
64  std::cout << "You might have to add the option to FCSurface::Add(). " << std::endl;
65  exit(1);
66  }
67 
68  // For deltassth23, since the first and last x bins cover the same range
69  // in sin(delta_CP), we want to merge these two columns of bins
70  if(plot == "deltassth23"){
71  // Get binwidth so we can decide whether trueDelta falls in either
72  // of these bins
73  double binWidth = fBinning->GetXaxis()->GetBinWidth(1);
74  // If trueDelta falls into the first bin, also add it to the last
75  if(pt.TrueDelta() > -1*binWidth/2 && pt.TrueDelta() < binWidth/2) {
76  int mergeBin = fBinning->FindBin(pt.TrueDelta()+2, pt.TrueTh23());
77  fBins[mergeBin].Add(pt);
78  }
79  // If trueDelta falls into the last bin, also add it to the first
80  if(pt.TrueDelta() > 2-binWidth/2 && pt.TrueDelta() < 2+binWidth/2) {
81  int mergeBin = fBinning->FindBin(pt.TrueDelta()-2, pt.TrueTh23());
82  fBins[mergeBin].Add(pt);
83  }
84  }
85 
86  fBins[bin].Add(pt);
87  }
std::vector< FCBin > fBins
Definition: FCSurface.h:38
TH2F * fBinning
Definition: FCSurface.h:37
float bin[41]
Definition: plottest35.C:14
OStream cout
Definition: OStream.cxx:6
exit(0)
void plot(std::string label, std::map< std::string, std::map< std::string, Spectrum * >> &plots, bool log)
void ana::FCSurface::Add ( const FCCollection coln,
std::string  plot = "delta" 
)

Definition at line 90 of file FCSurface.cxx.

References Add(), ana::Progress::Done(), getGoodRuns4SAM::n, ana::FCCollection::NPoints(), plot(), ana::FCCollection::Point(), cacheDefinitionData::prog, and ana::Progress::SetProgress().

91  {
92  Progress prog("Filling FCSurface from collection");
93  const unsigned int N = coln.NPoints();
94 
95  for(unsigned int n = 0; n < N; ++n){
96  if(n%100000 == 0) prog.SetProgress(double(n)/N);
97  Add(coln.Point(n), plot);
98  }
99  prog.Done();
100  }
void Add(const FCPoint &pt, std::string plot)
Definition: FCSurface.cxx:39
void plot(std::string label, std::map< std::string, std::map< std::string, Spectrum * >> &plots, bool log)
const TH2F* ana::FCSurface::Binning ( ) const
inline

Definition at line 30 of file FCSurface.h.

References fBinning, plot_validation_datamc::fname, LoadFromFile(), SaveToFile(), and string.

Referenced by MakeSummaryTable().

30 {return fBinning;}
TH2F * fBinning
Definition: FCSurface.h:37
void ana::FCSurface::DrawBins ( )

Definition at line 133 of file FCSurface.cxx.

References bin, plot_validation_datamc::c, fBinning, fBins, X, submit_syst::x, Y, and submit_syst::y.

134  {
135  TVirtualPad* c = gPad;
136  if(!c) c = new TCanvas;
137 
138  const int X = fBinning->GetNbinsX();
139  const int Y = fBinning->GetNbinsY();
140  c->Divide(X, Y);
141 
142  for(int x = 1; x < X+1; ++x){
143  for(int y = 1; y < Y+1; ++y){
144  c->cd(x+(y-1)*X);
145  const int bin = fBinning->GetBin(x, y);
146  fBins[bin].Draw();
147  }
148  }
149  }
std::vector< FCBin > fBins
Definition: FCSurface.h:38
Float_t Y
Definition: plot.C:38
TH2F * fBinning
Definition: FCSurface.h:37
float bin[41]
Definition: plottest35.C:14
Float_t X
Definition: plot.C:38
const FCBin * ana::FCSurface::GetBin ( int  x,
int  y 
) const

Definition at line 152 of file FCSurface.cxx.

References fBinning, and fBins.

Referenced by FCCorrectSlice(), and MakeSummaryTable().

153  {
154  return &fBins[fBinning->GetBin(x, y)];
155  }
std::vector< FCBin > fBins
Definition: FCSurface.h:38
TH2F * fBinning
Definition: FCSurface.h:37
std::unique_ptr< FCSurface > ana::FCSurface::LoadFromFile ( const std::string fname)
static

Definition at line 170 of file FCSurface.cxx.

References ana::assert(), fin, ana::FCBin::FromTree(), MECModelEnuComparisons::i, ana::FCBin::InitFromTree(), ana::pnfs2xrootd(), runNovaSAM::ret, and make_root_from_grid_output::tr.

Referenced by Binning(), FCCorrectSlice(), and plots().

171  {
172  DontAddDirectory guard;
173 
174  std::unique_ptr<FCSurface> ret(new FCSurface);
175 
176  TFile* fin = TFile::Open(pnfs2xrootd(fname).c_str());
177  assert(!fin->IsZombie());
178 
179  ret->fBinning = (TH2F*)(fin->Get("bins")->Clone());
180 
181  TTree* tr = (TTree*)fin->Get("fcsurf");
182  assert(tr);
183 
185 
186  for(int i = 0; i < tr->GetEntries(); ++i)
187  ret->fBins.push_back(FCBin::FromTree(tr, i));
188 
189  delete fin;
190 
191  return ret;
192  }
TString fin
Definition: Style.C:24
std::string pnfs2xrootd(std::string loc, bool unauth)
Definition: UtilsExt.cxx:237
static FCBin FromTree(TTree *tr, int idx)
Definition: FCBin.cxx:125
static void InitFromTree(TTree *tr)
Definition: FCBin.cxx:107
assert(nhit_max >=nhit_nbins)
void ana::FCSurface::SaveToFile ( const std::string fname) const

Definition at line 158 of file FCSurface.cxx.

References bin, fBinning, fBins, submit_syst::fout, ana::FCBin::InitToTree(), and make_root_from_grid_output::tr.

Referenced by Binning(), and plots().

159  {
160  TFile fout(fname.c_str(), "RECREATE");
161  fBinning->Write("bins");
162 
163  TTree tr("fcsurf", "fcsurf");
165  for(const FCBin& bin : fBins) bin.ToTree(&tr);
166  tr.Write();
167  }
std::vector< FCBin > fBins
Definition: FCSurface.h:38
TH2F * fBinning
Definition: FCSurface.h:37
float bin[41]
Definition: plottest35.C:14
static void InitToTree(TTree *tr)
Definition: FCBin.cxx:89
TH2 * ana::FCSurface::SurfaceForSignificance ( double  sig)

Definition at line 103 of file FCSurface.cxx.

References ana::assert(), bin, om::cout, allTimeWatchdog::endl, fBinning, fBins, fPrintedWarning, std::isinf(), std::isnan(), test_ParserArtEvents::log, ana::UniqueName(), submit_syst::x, and submit_syst::y.

Referenced by joint_fit_2017_contours(), joint_fit_2018_contours(), joint_fit_2019_contours(), nova_official_data_release(), plot_cont_expfriends(), plot_joint_fit_2020_contours(), plotContProf(), and plots().

104  {
105  DontAddDirectory guard;
106 
107  TH2* hRet = new TH2F(*fBinning);
108  hRet->SetName(UniqueName().c_str());
109 
110  // Don't do overflow and underflow
111  for(int x = 1; x < hRet->GetNbinsX()+1; ++x){
112  for(int y = 1; y < hRet->GetNbinsY()+1; ++y){
113  const int bin = hRet->GetBin(x, y);
114  if(fBins[bin].Empty()){
115  double crit2D = -2*log(1-sig);
116  hRet->SetBinContent(bin,crit2D);
117  if (!fPrintedWarning) std::cout << "WARNING, NO FCPOINTS IN THIS BIN, fall back on 2D Gaussian up value." << std::endl;
118  fPrintedWarning = true;
119  continue;
120  }
121  const double up = fBins[bin].UpValueForSignificance(sig);
122  assert(!std::isinf(up) && !std::isnan(up));
123  hRet->SetBinContent(bin, up);
124  }
125  }
126 
127  hRet->SetMinimum(0);
128 
129  return hRet;
130  }
int isinf(const stan::math::var &a)
Definition: std_isinf.hpp:16
std::vector< FCBin > fBins
Definition: FCSurface.h:38
int isnan(const stan::math::var &a)
Definition: std_isnan.hpp:18
bool fPrintedWarning
Definition: FCSurface.h:39
TH2F * fBinning
Definition: FCSurface.h:37
float bin[41]
Definition: plottest35.C:14
OStream cout
Definition: OStream.cxx:6
assert(nhit_max >=nhit_nbins)
std::string UniqueName()
Return a different string each time, for creating histograms.
Definition: Utilities.cxx:29

Member Data Documentation

TH2F* ana::FCSurface::fBinning
protected
std::vector<FCBin> ana::FCSurface::fBins
protected

Definition at line 38 of file FCSurface.h.

Referenced by Add(), DrawBins(), FCSurface(), GetBin(), SaveToFile(), and SurfaceForSignificance().

bool ana::FCSurface::fPrintedWarning
mutableprotected

Definition at line 39 of file FCSurface.h.

Referenced by FCSurface(), and SurfaceForSignificance().


The documentation for this class was generated from the following files: