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

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-10-20/CAFAna/Fit/ISurface.h"

Inheritance diagram for ana::ISurface:
ana::BayesianSurface ana::FrequentistSurface ana::SurfaceKrige

Public Member Functions

 ISurface ()
 
virtual ~ISurface ()
 
double BestLikelihood () const
 
double GetBestFitX () const
 
double GetBestFitY () const
 
void Draw () const
 Draw the surface itself. More...
 
void DrawBestFit (Color_t color, Int_t marker=kFullCircle) const
 Draw the best fit point. More...
 
void DrawContour (TH2 *fc, Style_t style, Color_t color, double minchi=-1)
 
std::vector< TGraph * > GetGraphs (TH2 *fc, double minchi=-1)
 For expert use, custom painting of contours. More...
 
TH2 * ToTH2 (double minchi=-1) const
 
void SetTitle (const char *str)
 

Protected Member Functions

double BinCenterX (int bin) const
 
double BinCenterY (int bin) const
 
void SaveToHelper (TDirectory *dir) const
 dir should already be the appropriate sub-directory More...
 
void EnsureAxes () const
 

Static Protected Member Functions

static void FillSurfObj (ISurface &surf, TDirectory *dir)
 

Protected Attributes

double fBestLikelihood
 
double fBestFitX
 
double fBestFitY
 
TH2F * fHist
 
bool fLogX
 
bool fLogY
 
std::vector< double > fSeedValues
 

Detailed Description

Definition at line 17 of file ISurface.h.

Constructor & Destructor Documentation

ana::ISurface::ISurface ( )
inline

Definition at line 20 of file ISurface.h.

21  : fBestLikelihood(std::numeric_limits<double>::signaling_NaN()),
22  fBestFitX(std::numeric_limits<double>::signaling_NaN()),
23  fBestFitY(std::numeric_limits<double>::signaling_NaN()),
24  fHist(nullptr), fLogX(false), fLogY(false)
25  {}
TH2F * fHist
Definition: ISurface.h:66
bool fLogX
Definition: ISurface.h:67
double fBestFitY
Definition: ISurface.h:65
bool fLogY
Definition: ISurface.h:67
double fBestFitX
Definition: ISurface.h:64
double fBestLikelihood
Definition: ISurface.h:63
virtual ana::ISurface::~ISurface ( )
inlinevirtual

Definition at line 27 of file ISurface.h.

27 {}

Member Function Documentation

double ana::ISurface::BestLikelihood ( ) const
inline

Definition at line 29 of file ISurface.h.

References fBestLikelihood.

29 {return fBestLikelihood;}
double fBestLikelihood
Definition: ISurface.h:63
double ana::ISurface::BinCenterX ( int  bin) const
protected

Definition at line 244 of file ISurface.cxx.

References visualisationForPaperMasterPlot::ax, fHist, and fLogX.

Referenced by ana::BayesianSurface::BuildHist(), EnsureAxes(), ana::FrequentistSurface::FillSurface(), ana::FrequentistSurface::FindMinimum(), and GetBestFitY().

245  {
246  const TAxis* ax = fHist->GetXaxis();
247  return fLogX ? ax->GetBinCenterLog(bin) : ax->GetBinCenter(bin);
248  }
TH2F * fHist
Definition: ISurface.h:66
bool fLogX
Definition: ISurface.h:67
float bin[41]
Definition: plottest35.C:14
double ana::ISurface::BinCenterY ( int  bin) const
protected

Definition at line 251 of file ISurface.cxx.

References visualisationForPaperMasterPlot::ax, fHist, and fLogY.

Referenced by ana::BayesianSurface::BuildHist(), EnsureAxes(), ana::FrequentistSurface::FillSurface(), ana::FrequentistSurface::FindMinimum(), and GetBestFitY().

252  {
253  const TAxis* ax = fHist->GetYaxis();
254  return fLogY ? ax->GetBinCenterLog(bin) : ax->GetBinCenter(bin);
255  }
TH2F * fHist
Definition: ISurface.h:66
float bin[41]
Definition: plottest35.C:14
bool fLogY
Definition: ISurface.h:67
void ana::ISurface::Draw ( ) const

Draw the surface itself.

Definition at line 19 of file ISurface.cxx.

References EnsureAxes(), and fHist.

Referenced by cc(), demo5(), GetBestFitY(), modularextrap_demo_nue(), modularextrap_demo_numu(), Plot2DSlices(), plot_3flavor_withsysts(), test_ana(), test_stanfit_statsonly(), and test_stanfit_withsysts().

20  {
21  EnsureAxes();
22 
23  fHist->Draw("colz same");
24 
25  // colz obliterated them
26  gPad->RedrawAxis();
27 
28  gPad->Update();
29  }
TH2F * fHist
Definition: ISurface.h:66
void EnsureAxes() const
Definition: ISurface.cxx:63
void ana::ISurface::DrawBestFit ( Color_t  color,
Int_t  marker = kFullCircle 
) const

Draw the best fit point.

Definition at line 32 of file ISurface.cxx.

References EnsureAxes(), fBestFitX, and fBestFitY.

Referenced by cc(), demo5(), demo_CPT(), drawSensitivity(), GetBestFitY(), getSensitivity(), make_contours(), modularextrap_demo_nue(), modularextrap_demo_numu(), Plot2DSlices(), plot_3flavor_withsysts(), starPlot(), syst_test(), template_basic(), template_GENIE_systs(), template_nonGENIE_systs(), test_ana(), test_stanfit_statsonly(), and test_stanfit_withsysts().

33  {
34  EnsureAxes();
35 
36  TMarker *mark = new TMarker(fBestFitX, fBestFitY, marker);
37  mark->SetMarkerSize(1.5);
38  mark->SetMarkerColor(color);
39  mark->Draw();
40  gPad->Update();
41  }
double fBestFitY
Definition: ISurface.h:65
void EnsureAxes() const
Definition: ISurface.cxx:63
double fBestFitX
Definition: ISurface.h:64
void ana::ISurface::DrawContour ( TH2 *  fc,
Style_t  style,
Color_t  color,
double  minchi = -1 
)
Parameters
fcSurface to compare against for this significance level
styleLine style for TAttLine, solid, dotted, dashed etc
colorLine color for TAttLine
minchi$\chi^2$ of best fit to compare against. Default: best fit from this surface.

Definition at line 44 of file ISurface.cxx.

References EnsureAxes(), MECModelEnuComparisons::g, GetGraphs(), and APDGainPoints::gs.

Referenced by cc(), demo5(), Draw2DSurface(), drawSensitivity(), GetBestFitY(), getSensitivity(), make_contours(), make_nom_expt(), modularextrap_demo_nue(), modularextrap_demo_numu(), Plot2DSlice(), Plot2DSlices(), plot_3flavor_withsysts(), plotContProf(), plots(), starPlot(), syst_test(), template_basic(), template_GENIE_systs(), template_nonGENIE_systs(), test_ana(), test_stanfit_statsonly(), and test_stanfit_withsysts().

46  {
47  EnsureAxes();
48 
49  std::vector<TGraph *> gs = GetGraphs(fc, minchi);
50 
51  for (TGraph *g: gs)
52  {
53  g->SetLineWidth(3);//2);
54  g->SetLineStyle(style);
55  g->SetLineColor(color);
56  g->Draw("l");
57  }
58 
59  gPad->Update();
60  }
std::vector< TGraph * > GetGraphs(TH2 *fc, double minchi=-1)
For expert use, custom painting of contours.
Definition: ISurface.cxx:106
void EnsureAxes() const
Definition: ISurface.cxx:63
void ana::ISurface::EnsureAxes ( ) const
protected

Definition at line 63 of file ISurface.cxx.

References visualisationForPaperMasterPlot::ax, file_size_ana::axes, BinCenterX(), BinCenterY(), fHist, fLogX, fLogY, genie::utils::style::Format(), and ana::UniqueName().

Referenced by Draw(), DrawBestFit(), and DrawContour().

64  {
65  // Could have a file temporarily open
66  DontAddDirectory guard;
67 
68  // If this pad has already been drawn in, already has axes
69  if (gPad && !gPad->GetListOfPrimitives()->IsEmpty()) return;
70 
71  const TAxis *ax = fHist->GetXaxis();
72  const TAxis *ay = fHist->GetYaxis();
73  const double Nx = ax->GetNbins();
74  const double Ny = ay->GetNbins();
75 
76  // Axes with limits where the user originally requested them, which we
77  // adjusted to be the centres of the first and last bins.
78  TH2 *axes = new TH2C(UniqueName().c_str(),
79  TString::Format(";%s;%s",
80  ax->GetTitle(), ay->GetTitle()),
81  Nx - 1, BinCenterX(1), BinCenterX(Nx),
82  Ny - 1, BinCenterY(1), BinCenterY(Ny));
83  axes->Draw();
84 
85  if(fHist){
86  // "colz same" will reuse axis's min and max, so set them helpfully here
87  axes->SetMinimum(fHist->GetMinimum());
88  axes->SetMaximum(fHist->GetMaximum());
89  }
90 
91  axes->SetTitle(fHist->GetTitle());
92  axes->GetXaxis()->SetLabelSize(ax->GetLabelSize());
93  axes->GetYaxis()->SetLabelSize(ay->GetLabelSize());
94  axes->GetXaxis()->SetLabelOffset(ax->GetLabelOffset());
95  axes->GetYaxis()->SetLabelOffset(ay->GetLabelOffset());
96  axes->GetXaxis()->CenterTitle();
97  axes->GetYaxis()->CenterTitle();
98 
99  if(fLogX) gPad->SetLogx();
100  if(fLogY) gPad->SetLogy();
101 
102  gPad->Update();
103  }
double BinCenterX(int bin) const
Definition: ISurface.cxx:244
double BinCenterY(int bin) const
Definition: ISurface.cxx:251
TH2F * fHist
Definition: ISurface.h:66
bool fLogX
Definition: ISurface.h:67
bool fLogY
Definition: ISurface.h:67
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
std::string UniqueName()
Return a different string each time, for creating histograms.
Definition: Utilities.cxx:29
void ana::ISurface::FillSurfObj ( ISurface surf,
TDirectory *  dir 
)
staticprotected

Definition at line 214 of file ISurface.cxx.

References fBestFitX, fBestFitY, fBestLikelihood, fHist, fSeedValues, compare_h5_caf::idx, and registry_explorer::v.

Referenced by GetBestFitY(), ana::BayesianSurface::LoadFrom(), and ana::FrequentistSurface::LoadFrom().

215  {
216 
217  const TVectorD v = *(TVectorD *) dir->Get("minValues");
218  const TVectorD s = *(TVectorD *) dir->Get("seeds");
219 
220  surf.fHist = (TH2F *) dir->Get("hist");
221  surf.fBestLikelihood = v[0];
222  surf.fBestFitX = v[1];
223  surf.fBestFitY = v[2];
224 
225  for (int idx = 0; idx < s.GetNrows(); ++idx)
226  surf.fSeedValues.push_back(s[idx]);
227 
228  }
const XML_Char * s
Definition: expat.h:262
TDirectory * dir
Definition: macro.C:5
surf
Definition: demo5.py:35
double ana::ISurface::GetBestFitX ( ) const
inline

Definition at line 30 of file ISurface.h.

References fBestFitX.

Referenced by test_stanfit_statsonly().

30 {return fBestFitX;}
double fBestFitX
Definition: ISurface.h:64
double ana::ISurface::GetBestFitY ( ) const
inline
std::vector< TGraph * > ana::ISurface::GetGraphs ( TH2 *  fc,
double  minchi = -1 
)

For expert use, custom painting of contours.

Definition at line 106 of file ISurface.cxx.

References fBestLikelihood, fHist, runNovaSAM::ret, PandAna.Demos.tute_pid_validation::specs, demo5::surf, tmp, and ana::UniqueName().

Referenced by DrawContour(), and GetBestFitY().

107  {
108  std::vector<TGraph*> ret;
109 
110  if(minchi < 0) minchi = fBestLikelihood;
111  std::unique_ptr<TH2> surf((TH2*)fHist->Clone(UniqueName().c_str()));
112  surf->Add(fc, -1);
113 
114  TVirtualPad* bak = gPad;
115 
116  const bool wasbatch = gROOT->IsBatch();
117  gROOT->SetBatch(); // User doesn't want to see our temporary canvas
118  TCanvas tmp;
119 
120  gStyle->SetOptStat(0);
121 
122  const double level = minchi-fBestLikelihood;
123  surf->SetContour(1, &level);
124  surf->Draw("cont list");
125 
126  tmp.Update();
127  tmp.Paint();
128 
129  gROOT->SetBatch(wasbatch);
130  gPad = bak;
131 
132  // The graphs we need (contained inside TLists, contained inside
133  // TObjArrays) are in the list of specials. But we need to be careful about
134  // types, because other stuff can get in here too (TDatabasePDG for
135  // example).
136  TCollection* specs = gROOT->GetListOfSpecials();
137 
138  TIter nextSpec(specs);
139  while(TObject* spec = nextSpec()){
140  if(!spec->InheritsFrom(TObjArray::Class())) continue;
141  TObjArray* conts = (TObjArray*)spec;
142 
143  if(conts->IsEmpty()) continue;
144 
145  if(!conts->At(0)->InheritsFrom(TList::Class())) continue;
146  TList* cont = (TList*)conts->At(0);
147 
148  TIter nextObj(cont);
149  // Contour could be split into multiple pieces
150  while(TObject* obj = nextObj()){
151  if(!obj->InheritsFrom(TGraph::Class())) continue;
152 
153  ret.push_back((TGraph*)obj->Clone(UniqueName().c_str()));
154  } // end for obj
155  } // end for spec
156 
157  return ret;
158  }
Float_t tmp
Definition: plot.C:36
TH2F * fHist
Definition: ISurface.h:66
double fBestLikelihood
Definition: ISurface.h:63
std::string UniqueName()
Return a different string each time, for creating histograms.
Definition: Utilities.cxx:29
surf
Definition: demo5.py:35
void ana::ISurface::SaveToHelper ( TDirectory *  dir) const
protected

dir should already be the appropriate sub-directory

Definition at line 189 of file ISurface.cxx.

References fBestFitX, fBestFitY, fBestLikelihood, fHist, fLogX, fLogY, fSeedValues, and registry_explorer::v.

Referenced by GetBestFitY(), ana::BayesianSurface::SaveTo(), and ana::FrequentistSurface::SaveTo().

190  {
191  TDirectory *oldDir = gDirectory;
192 
193  dir->cd();
194 
195  TVectorD v(3);
196  v[0] = fBestLikelihood;
197  v[1] = fBestFitX;
198  v[2] = fBestFitY;
199  v.Write("minValues");
200 
201  fHist->Write("hist");
202 
203  TVectorD s(fSeedValues.size(), &fSeedValues[0]);
204  s.Write("seeds");
205 
206  TObjString(fLogX ? "yes" : "no").Write("logx");
207  TObjString(fLogY ? "yes" : "no").Write("logy");
208 
209  if (oldDir)
210  oldDir->cd();
211  }
const XML_Char * s
Definition: expat.h:262
TH2F * fHist
Definition: ISurface.h:66
bool fLogX
Definition: ISurface.h:67
double fBestFitY
Definition: ISurface.h:65
bool fLogY
Definition: ISurface.h:67
std::vector< double > fSeedValues
Definition: ISurface.h:68
TDirectory * dir
Definition: macro.C:5
double fBestFitX
Definition: ISurface.h:64
double fBestLikelihood
Definition: ISurface.h:63
void ana::ISurface::SetTitle ( const char *  str)

Definition at line 183 of file ISurface.cxx.

References fHist.

Referenced by GetBestFitY(), and plots().

184  {
185  fHist->SetTitle(str);
186  }
TH2F * fHist
Definition: ISurface.h:66
TH2 * ana::ISurface::ToTH2 ( double  minchi = -1) const

Definition at line 161 of file ISurface.cxx.

References fBestLikelihood, fHist, runNovaSAM::ret, submit_syst::x, and submit_syst::y.

Referenced by CAF_makeCAFSensitivities_for_FNEX(), demoFitContours(), ana::Flat(), GetBestFitY(), joint_fit_2017_contours(), joint_fit_2018_contours(), joint_fit_2019_contours(), joint_fit_future_contour_univ(), MakeCAFSensitivities_for_FNEX(), Plot2DSlice(), Plot2DSlices(), plot_3flavor_withsysts(), run_joint_fit_2020_contours(), sensitivity2018(), sensitivity2020(), and test_stanfit_withsysts().

162  {
163  // Could have a file temporarily open
164  DontAddDirectory guard;
165 
166  TH2 *ret = new TH2F(*fHist);
167 
168  if (minchi >= 0)
169  {
170  for (int x = 0; x < ret->GetNbinsX() + 2; ++x)
171  {
172  for (int y = 0; y < ret->GetNbinsY() + 2; ++y)
173  {
174  ret->SetBinContent(x, y, ret->GetBinContent(x, y) + fBestLikelihood - minchi);
175  }
176  }
177  }
178 
179  return ret;
180  }
TH2F * fHist
Definition: ISurface.h:66
double fBestLikelihood
Definition: ISurface.h:63

Member Data Documentation

double ana::ISurface::fBestFitX
protected
double ana::ISurface::fBestFitY
protected
double ana::ISurface::fBestLikelihood
protected
TH2F* ana::ISurface::fHist
protected
bool ana::ISurface::fLogX
protected
bool ana::ISurface::fLogY
protected
std::vector<double> ana::ISurface::fSeedValues
protected

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