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-08-04/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

void SaveTo (TDirectory *dir) const
 
void EnsureAxes () const
 

Static Protected Member Functions

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

Protected Attributes

double fBestLikelihood
 
double fBestFitX
 
double fBestFitY
 
TH2F * fHist
 
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)
25  {}
TH2F * fHist
Definition: ISurface.h:62
double fBestFitY
Definition: ISurface.h:61
double fBestFitX
Definition: ISurface.h:60
double fBestLikelihood
Definition: ISurface.h:59
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.

Referenced by ana::NumuSurface::DrawBestFit(), ana::NueSurface::MinChi(), and ana::NumuSurface::MinChi().

29 {return fBestLikelihood;}
double fBestLikelihood
Definition: ISurface.h:59
void ana::ISurface::Draw ( ) const

Draw the surface itself.

Definition at line 20 of file ISurface.cxx.

References EnsureAxes(), and fHist.

Referenced by cc(), demo5(), ana::NueSurface::Draw(), ana::NumuSurface::Draw(), GetBestFitY(), modularextrap_demo_nue(), modularextrap_demo_numu(), Plot2DSlices(), test_ana(), test_external_constraints(), test_stanfit_statsonly(), and test_stanfit_withsysts().

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

Draw the best fit point.

Definition at line 33 of file ISurface.cxx.

References EnsureAxes(), fBestFitX, and fBestFitY.

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

34  {
35  EnsureAxes();
36 
37  TMarker *mark = new TMarker(fBestFitX, fBestFitY, marker);
38  mark->SetMarkerSize(1.5);
39  mark->SetMarkerColor(color);
40  mark->Draw();
41  gPad->Update();
42  }
double fBestFitY
Definition: ISurface.h:61
void EnsureAxes() const
Definition: ISurface.cxx:64
double fBestFitX
Definition: ISurface.h:60
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 45 of file ISurface.cxx.

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

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

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

Definition at line 64 of file ISurface.cxx.

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

Referenced by Draw(), DrawBestFit(), DrawContour(), and ana::NueSurface::DrawValley().

65  {
66  // Could have a file temporarily open
67  DontAddDirectory guard;
68 
69  // If this pad has already been drawn in, already has axes
70  if (gPad && !gPad->GetListOfPrimitives()->IsEmpty()) return;
71 
72  // Old, hackier solution
73  /*
74  std::cout << gPad->GetListOfPrimitives()->GetEntries() << std::endl;
75  // Which pads have we already drawn axes in? Never draw axes in them
76  // again. Unfortunately UniqueID() never seems to be set. If that's the
77  // case, set it to a random value and hope...
78  static std::set<UInt_t> already;
79  if(already.count(gPad->GetUniqueID())) return;
80  if(gPad->GetUniqueID() == 0) gPad->SetUniqueID(rand());
81  already.insert(gPad->GetUniqueID());
82  */
83 
84  const TAxis *ax = fHist->GetXaxis();
85  const TAxis *ay = fHist->GetYaxis();
86  const double Nx = ax->GetNbins();
87  const double Ny = ay->GetNbins();
88 
89  // Axes with limits where the user originally requested them, which we
90  // adjusted to be the centres of the first and last bins.
91  TH2 *axes = new TH2C(UniqueName().c_str(),
92  TString::Format(";%s;%s",
93  ax->GetTitle(), ay->GetTitle()),
94  Nx - 1, ax->GetBinCenter(1), ax->GetBinCenter(Nx),
95  Ny - 1, ay->GetBinCenter(1), ay->GetBinCenter(Ny));
96  axes->Draw();
97 
98  if(fHist){
99  // "colz same" will reuse axis's min and max, so set them helpfully here
100  axes->SetMinimum(fHist->GetMinimum());
101  axes->SetMaximum(fHist->GetMaximum());
102  }
103 
104  axes->SetTitle(fHist->GetTitle());
105  axes->GetXaxis()->SetLabelSize(ax->GetLabelSize());
106  axes->GetYaxis()->SetLabelSize(ay->GetLabelSize());
107  axes->GetXaxis()->SetLabelOffset(ax->GetLabelOffset());
108  axes->GetYaxis()->SetLabelOffset(ay->GetLabelOffset());
109  axes->GetXaxis()->CenterTitle();
110  axes->GetYaxis()->CenterTitle();
111  gPad->Update();
112  }
TH2F * fHist
Definition: ISurface.h:62
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:30
void ana::ISurface::FillSurfObj ( ISurface surf,
TDirectory *  dir 
)
staticprotected

Definition at line 219 of file ISurface.cxx.

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

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

220  {
221 
222  const TVectorD v = *(TVectorD *) dir->Get("minValues");
223  const TVectorD s = *(TVectorD *) dir->Get("seeds");
224 
225  surf.fHist = (TH2F *) dir->Get("hist");
226  surf.fBestLikelihood = v[0];
227  surf.fBestFitX = v[1];
228  surf.fBestFitY = v[2];
229 
230  for (int idx = 0; idx < s.GetNrows(); ++idx)
231  surf.fSeedValues.push_back(s[idx]);
232 
233  }
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:60
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 115 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().

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

Definition at line 198 of file ISurface.cxx.

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

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

199  {
200  TDirectory *oldDir = gDirectory;
201  dir->cd();
202 
203  TVectorD v(3);
204  v[0] = fBestLikelihood;
205  v[1] = fBestFitX;
206  v[2] = fBestFitY;
207  v.Write("minValues");
208 
209  fHist->Write("hist");
210 
211  TVectorD s(fSeedValues.size(), &fSeedValues[0]);
212  s.Write("seeds");
213 
214  if (oldDir)
215  oldDir->cd();
216  }
const XML_Char * s
Definition: expat.h:262
TH2F * fHist
Definition: ISurface.h:62
double fBestFitY
Definition: ISurface.h:61
std::vector< double > fSeedValues
Definition: ISurface.h:63
TDirectory * dir
Definition: macro.C:5
double fBestFitX
Definition: ISurface.h:60
double fBestLikelihood
Definition: ISurface.h:59
void ana::ISurface::SetTitle ( const char *  str)

Definition at line 192 of file ISurface.cxx.

References fHist.

Referenced by GetBestFitY(), plots(), ana::NumuSurface::SetTitle(), ana::NueSurface::SetTitle(), and test_external_constraints().

193  {
194  fHist->SetTitle(str);
195  }
TH2F * fHist
Definition: ISurface.h:62
TH2 * ana::ISurface::ToTH2 ( double  minchi = -1) const

Definition at line 170 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(), run_joint_fit_2020_contours(), sensitivity2018(), sensitivity2020(), and test_stanfit_withsysts().

171  {
172  // Could have a file temporarily open
173  DontAddDirectory guard;
174 
175  TH2 *ret = new TH2F(*fHist);
176 
177  if (minchi >= 0)
178  {
179  for (int x = 0; x < ret->GetNbinsX() + 2; ++x)
180  {
181  for (int y = 0; y < ret->GetNbinsY() + 2; ++y)
182  {
183  ret->SetBinContent(x, y, ret->GetBinContent(x, y) + fBestLikelihood - minchi);
184  }
185  }
186  }
187 
188  return ret;
189  }
TH2F * fHist
Definition: ISurface.h:62
double fBestLikelihood
Definition: ISurface.h:59

Member Data Documentation

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

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