All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sbnana/sbnana/CAFAna/Analysis/Surface.h
Go to the documentation of this file.
1 #pragma once
2 
5 
8 
9 #include "Rtypes.h"
10 #include "TAttMarker.h"
11 
12 #include <iostream>
13 #include <map>
14 #include <memory>
15 
16 class TGraph;
17 class TH2;
18 class TH2F;
19 
20 namespace ana
21 {
22  class IExperiment;
23  class IFitVar;
24 
25  /// Log-likelihood scan across two parameters
26  class Surface
27  {
28  public:
29  friend class MedianSurface;
30 
31  /// \param expt The experiment object to draw \f$ \chi^2 \f$ values from
32  /// \param calc Values for oscillation parameters to be held fixed
33  /// \param xvar Oscillation parameter to place on the x axis
34  /// \param nbinsx Number of bins along x axis
35  /// \param xmin Minimum value of x axis
36  /// \param xmax Maximum value of x axis
37  /// \param nbinsy Number of bins along y axis
38  /// \param ymin Minimum value of y axis
39  /// \param ymax Maximum value of y axis
40  /// \param profVars Oscillation parameters to profile over
41  /// \param profSysts Systematic parameters to profile over
42  /// \param seedPts Try all combinations of these params as seeds
43  /// \param systSeedPts Try all of these systematic combinations as seeds
44  /// \param parallel Use all the cores on this machine? Be careful...
45  Surface(const IExperiment* expt,
47  const IFitVar* xvar, int nbinsx, double xmin, double xmax,
48  const IFitVar* yvar, int nbinsy, double ymin, double ymax,
49  const std::vector<const IFitVar*>& profVars = {},
50  const std::vector<const ISyst*>& profSysts = {},
51  const std::map<const IFitVar*, std::vector<double>>& seedPts = {},
52  const std::vector<SystShifts>& systSeedPts = {},
53  bool parallel = false,
55 
56 
57  /// \param expt The experiment object to draw \f$ \chi^2 \f$ values from
58  /// \param calc Values for oscillation parameters to be held fixed
59  /// \param xax A FitAxis for the first variable
60  /// \param yax A FitAxis for the second variable
61  /// \param profVars Oscillation parameters to profile over
62  /// \param profSysts Systematic parameters to profile over
63  /// \param seedPts Try all combinations of these params as seeds
64  /// \param systSeedPts Try all of these systematic combinations as seeds
65  /// \param parallel Use all the cores on this machine? Be careful...
66  Surface(const IExperiment* expt,
68  const FitAxis& xax,
69  const FitAxis& yax,
70  const std::vector<const IFitVar*>& profVars = {},
71  const std::vector<const ISyst*>& profSysts = {},
72  const std::map<const IFitVar*, std::vector<double>>& seedPts = {},
73  const std::vector<SystShifts>& systSeedPts = {},
74  bool parallel = false,
76 
77  /// Draw the surface itself
78  void Draw() const;
79  /// Draw the best fit point
80  void DrawBestFit(Color_t color, Int_t marker=kFullCircle) const;
81  double MinChi() const {return fMinChi;}
82  double GetMinX() const {return fMinX;}
83  double GetMinY() const {return fMinY;}
84 
85  /// \param fc Surface to compare against for this significance level
86  /// \param style Line style for TAttLine, solid, dotted, dashed etc
87  /// \param color Line color for TAttLine
88  /// \param minchi \f$\chi^2\f$ of best fit to compare against.
89  /// Default: best fit from this surface.
90  void DrawContour(TH2* fc, Style_t style, Color_t color,
91  double minchi = -1);
92  TH2F* ToTH2(double minchi = -1) const;
93  void SetTitle(const char* str);
94 
95  /// Maps of the values taken on by the profiled parameters
96  std::vector<TH2*> GetProfiledHists() {return fProfHists;}
97  /// Deprecated. Retained for backwards compatibility.
98  std::vector<TH2*> GetMarginalizedHists() {return fProfHists;}
99 
100  /// For expert use, custom painting of contours
101  std::vector<TGraph*> GetGraphs(TH2* fc, double minchi = -1);
102 
103  void SaveTo(TDirectory* dir) const;
104  static std::unique_ptr<Surface> LoadFrom(TDirectory* dir);
105  static std::unique_ptr<Surface> LoadFromMulti(const std::vector<TFile*>& files, const std::string& label);
106  static std::unique_ptr<Surface> LoadFromMulti(const std::string& wildcard, const std::string& label);
107 
108  protected:
109  Surface(){};
110 
111  void EnsureAxes() const;
112  void CheckMask(const std::string& func) const;
113 
114  void FillSurface(const std::string& progTitle,
115  const IExperiment* expt,
117  const FitAxis& xax, const FitAxis& yax,
118  const std::vector<const IFitVar*>& profVars,
119  const std::vector<const ISyst*>& profSysts,
120  const std::map<const IFitVar*, std::vector<double>>& seedPts,
121  const std::vector<SystShifts>& systSeedPts);
122 
123  void FillSurfacePoint(const IExperiment* expt,
125  const FitAxis& xax, double x,
126  const FitAxis& yax, double y,
127  const std::vector<const IFitVar*>& profVars,
128  const std::vector<const ISyst*>& profSysts,
129  const std::map<const IFitVar*, std::vector<double>>& seedPts,
130  const std::vector<SystShifts>& systSeedPts);
131 
132  bool fParallel;
134 
135  double fMinChi;
136  double fMinX, fMinY; // Best fit point
137  TH2F* fHist;
138  bool fLogX, fLogY;
139  std::vector<TH2*> fProfHists;
140  std::vector<double> fSeedValues;
141  std::vector<int> fBinMask;
142  };
143 
144  /// Up-value surface for 68% confidence in 2D in gaussian approximation
145  TH2* Gaussian68Percent2D(const Surface& s);
146  /// Up-value surface for 90% confidence in 2D in gaussian approximation
147  TH2* Gaussian90Percent2D(const Surface& s);
148  /// Up-value surface for 95% confidence in 2D in gaussian approximation
149  TH2* Gaussian95Percent2D(const Surface& s);
150  /// Up-value surface for 2 sigma confidence in 2D in gaussian approximation
151  TH2* Gaussian2Sigma2D (const Surface& s);
152  /// Up-value surface for 99% confidence in 2D in gaussian approximation
153  TH2* Gaussian99Percent2D(const Surface& s);
154  /// Up-value surface for 3 sigma confidence in 2D in gaussian approximation
155  TH2* Gaussian3Sigma2D (const Surface& s);
156  /// Up-value surface for 5 sigma confidence in 2D in gaussian approximation
157  TH2* Gaussian5Sigma2D (const Surface& s);
158 
159 
160  // First approximation of the correct up-values to use for ss2th13 vs delta
161 
162  /// Up-value surface for 68% confidence in 1D in gaussian approximation
163  TH2* Gaussian68Percent1D(const Surface& s);
164  /// Up-value surface for 90% confidence in 1D in gaussian approximation
165  TH2* Gaussian90Percent1D(const Surface& s);
166  /// Up-value surface for 95% confidence in 1D in gaussian approximation
167  TH2* Gaussian95Percent1D(const Surface& s);
168  /// Up-value surface for 2 sigma confidence in 1D in gaussian approximation
169  TH2* Gaussian2Sigma1D (const Surface& s);
170  /// Up-value surface for 99% confidence in 1D in gaussian approximation
171  TH2* Gaussian99Percent1D(const Surface& s);
172  /// Up-value surface for 3 sigma confidence in 1D in gaussian approximation
173  TH2* Gaussian3Sigma1D (const Surface& s);
174 
175  /// Up-value surface for 90% confidence in 1D in 1-sided gaussian approximation
176  TH2* Gaussian90Percent1D1Sided(const Surface& s);
177  /// Up-value surface for 95% confidence in 1D in 1-sided gaussian approximation
178  TH2* Gaussian95Percent1D1Sided(const Surface& s);
179  /// Up-value surface for 99% confidence in 1D in 1-sided gaussian approxiamtion
180  TH2* Gaussian99Percent1D1Sided(const Surface& s);
181  /// Up-value surface for 3 sigma confidence in 1D in 1-sided gaussian approximation
182  TH2* Gaussian3Sigma1D1Sided(const Surface& s);
183  /// Up-value surface for 5 sigma confidence in 1D in 1-sided gaussian approximation
184  TH2* Gaussian5Sigma1D1Sided(const Surface& s);
185 
186 }
TH2 * Gaussian2Sigma1D(const Surface &s)
Up-value surface for 2 sigma confidence in 1D in gaussian approximation.
TH2 * Gaussian2Sigma2D(const Surface &s)
Up-value surface for 2 sigma confidence in 2D in gaussian approximation.
void DrawBestFit(Color_t color, Int_t marker=kFullCircle) const
Draw the best fit point.
process_name opflash particleana ie x
Log-likelihood scan across two parameters.
TH2 * Gaussian90Percent1D(const Surface &s)
Up-value surface for 90% confidence in 1D in gaussian approximation.
void SaveTo(TDirectory *dir) const
void FillSurfacePoint(const IExperiment *expt, osc::IOscCalcAdjustable *calc, const FitAxis &xax, double x, const FitAxis &yax, double y, const std::vector< const IFitVar * > &profVars, const std::vector< const ISyst * > &profSysts, const std::map< const IFitVar *, std::vector< double >> &seedPts, const std::vector< SystShifts > &systSeedPts)
TH2 * Gaussian95Percent2D(const Surface &s)
Up-value surface for 95% confidence in 2D in gaussian approximation.
void DrawContour(TH2 *fc, Style_t style, Color_t color, double minchi=-1)
TH2 * Gaussian68Percent1D(const Surface &s)
Up-value surface for 68% confidence in 1D in gaussian approximation.
TH2 * Gaussian68Percent2D(const Surface &s)
Up-value surface for 68% confidence in 2D in gaussian approximation.
def style
Definition: util.py:237
process_name opflashCryoW ana
std::vector< TH2 * > GetProfiledHists()
Maps of the values taken on by the profiled parameters.
TH2 * Gaussian90Percent2D(const Surface &s)
Up-value surface for 90% confidence in 2D in gaussian approximation.
void FillSurface(const std::string &progTitle, const IExperiment *expt, osc::IOscCalcAdjustable *calc, const FitAxis &xax, const FitAxis &yax, const std::vector< const IFitVar * > &profVars, const std::vector< const ISyst * > &profSysts, const std::map< const IFitVar *, std::vector< double >> &seedPts, const std::vector< SystShifts > &systSeedPts)
TH2 * Gaussian95Percent1D(const Surface &s)
Up-value surface for 95% confidence in 1D in gaussian approximation.
TH2 * Gaussian3Sigma1D(const Surface &s)
Up-value surface for 3 sigma confidence in 1D in gaussian approximation.
TH2 * Gaussian5Sigma2D(const Surface &s)
Up-value surface for 5 sigma confidence in 2D in gaussian approximation.
process_name pandoraGausCryo1 vertexChargeCryo1 vertexStubCryo1 xmin
static std::unique_ptr< Surface > LoadFromMulti(const std::vector< TFile * > &files, const std::string &label)
TH2 * Gaussian99Percent2D(const Surface &s)
Up-value surface for 99% confidence in 2D in gaussian approximation.
process_name opflash particleana ie ie y
std::vector< TH2 * > GetMarginalizedHists()
Deprecated. Retained for backwards compatibility.
static std::unique_ptr< Surface > LoadFrom(TDirectory *dir)
TH2 * Gaussian3Sigma2D(const Surface &s)
Up-value surface for 3 sigma confidence in 2D in gaussian approximation.
TH2 * Gaussian99Percent1D1Sided(const Surface &s)
Up-value surface for 99% confidence in 1D in 1-sided gaussian approxiamtion.
TH2 * Gaussian90Percent1D1Sided(const Surface &s)
Up-value surface for 90% confidence in 1D in 1-sided gaussian approximation.
TH2 * Gaussian95Percent1D1Sided(const Surface &s)
Up-value surface for 95% confidence in 1D in 1-sided gaussian approximation.
void CheckMask(const std::string &func) const
tuple dir
Definition: dropbox.py:28
int prec
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
TH2 * Gaussian3Sigma1D1Sided(const Surface &s)
Up-value surface for 3 sigma confidence in 1D in 1-sided gaussian approximation.
Base class defining interface for experiments.
Definition: IExperiment.h:21
TH2 * Gaussian5Sigma1D1Sided(const Surface &s)
Up-value surface for 5 sigma confidence in 1D in 1-sided gaussian approximation.
void Draw() const
Draw the surface itself.
Interface definition for fittable variables.
Definition: IFitVar.h:14
TH2F * ToTH2(double minchi=-1) const
Precision
Definition: Fit.h:42
TH2 * Gaussian99Percent1D(const Surface &s)
Up-value surface for 99% confidence in 1D in gaussian approximation.
std::vector< TGraph * > GetGraphs(TH2 *fc, double minchi=-1)
For expert use, custom painting of contours.
Collect information describing the axis of a fit variable.
Definition: FitAxis.h:10