Crombie Tools
HistAnalysis.h
Go to the documentation of this file.
1 /**
2  @file HistAnalysis.h
3  Definition of HistAnalysis class.
4  @author Daniel Abercrombie <dabercro@mit.edu>
5 */
6 
7 #ifndef CROMBIETOOLS_ANALYSISTOOLS_HISTANALYSIS_H
8 #define CROMBIETOOLS_ANALYSISTOOLS_HISTANALYSIS_H
9 
10 #include <vector>
11 
12 #include "TString.h"
13 #include "TH1D.h"
14 
15 #include "FileConfigReader.h"
16 
17 /**
18  @ingroup analysisgroup
19  @class HistAnalysis
20  Class for histogram-based analysis.
21  This class handles MCConfigs and data and performs useful tasks
22  with the resulting histograms.
23 */
24 
26 {
27  public:
29  virtual ~HistAnalysis() {}
30 
31  /// Sets the signal MC based on the limit tree name and which config to use
32  inline void SetSignalName ( TString name, FileType type = kBackground ) { fSignalName = name; fSignalType = type; }
33 
34  /// Sets the base cut
35  inline void SetBaseCut ( TCut cut ) { fBaseCut = cut; fDataBaseCut = cut; }
36  /// Sets the base cut for MC and Data
37  inline void SetBaseCut ( TCut cut, TCut datacut ) { fBaseCut = cut; fDataBaseCut = datacut; }
38 
39  /// Sets the format string for the scale factor table
40  inline void SetFormat ( TString format ) { fFormat = format; }
41 
42  /// Sets the type of way to identify signal and backgrounds
43  inline void SetSearchBy ( SearchBy search ) { fSearchBy = search; }
44 
45  /// Different methods of doing cut and count
47  kCutAndCount = 0, ///< Does scale factor through a simple cut and count with background subtraction
48  };
49  /// Does scale factors between background-subtracted data and signal MC for each bin
50  TH1D* DoScaleFactors ( TString PlotVar, Int_t NumBins, Double_t *XBins,
52  /// Does scale factors between background-subtracted data and signal MC with easier binning
53  TH1D* DoScaleFactors ( TString PlotVar, Int_t NumBins, Double_t MinX, Double_t MaxX,
55 
56  /// Plots the scale factors with variable binning
57  void PlotScaleFactors ( TString FileBase, TString PlotVar, Int_t NumBins, Double_t *XBins,
58  TString XLabel, ScaleFactorMethod method = kCutAndCount );
59  /// Plots the scale factors
60  void PlotScaleFactors ( TString FileBase, TString PlotVar, Int_t NumBins, Double_t MinX, Double_t MaxX,
61  TString XLabel, ScaleFactorMethod method = kCutAndCount );
62 
63  /// Sets various other cut levels for scalefactors.
64  void AddScaleFactorCut ( TString name, TCut cut, TCut datacut = "" );
65  /// Resets the values saved for the scale factor cuts
66  void ResetScaleFactorCuts ();
67 
68  /// Reweights based on some expression in MC to match data shape and makes a histogram for CorrectionApplicator to use
69  void MakeReweightHist ( TString OutFile, TString OutHist, TString PlotVar,
70  Int_t NumBins, Double_t *XBins );
71 
72  /// Reweights based on some expression in MC with easier to use binning
73  void MakeReweightHist ( TString OutFile, TString OutHist, TString PlotVar,
74  Int_t NumBins, Double_t MinX, Double_t MaxX );
75 
76  /// Does cut and count scale factors between background-subtracted data and signal MC with a single bin
77  TH1D* DoScaleFactorsCutAndCount ( TString PlotVar, Double_t MinX, Double_t MaxX )
78  { return DoScaleFactors(PlotVar, 1, MinX, MaxX, kCutAndCount); }
79 
80  /// Different methods of printing the scale factor tables
82  kNone = 0, ///< Does not print output from hist analysis
83  kPresentation, ///< Prints output narrow enough for a presentation
84  kNote, ///< Prints output detailed enough for an analysis note
85  };
86  /// Sets whether to print any tables for notes or presentations
87  inline void SetPrintingMethod ( PrintingMethod method ) { fPrintingMethod = method; }
88 
89  /// Sets the amount the background is scaled by
90  inline void ChangeBackground ( Double_t factor ) { fBackgroundChange = factor; }
91 
92  /// Sets whether or not to normalize backgrounds before comparing to data
93  inline void SetNormalized ( Bool_t norm ) { fNormalized = norm; }
94 
95  /// Sets the base cut with character array
96  inline void SetBaseCut ( const char* cut ) { SetBaseCut(TCut(cut)); }
97  /// Sets the base cut for MC and Data with character array
98  inline void SetBaseCut ( const char* cut, const char* datacut ) { SetBaseCut(TCut(cut), TCut(datacut)); }
99 
100  /// Sets various other cut levels for scalefactors.
101  void AddScaleFactorCut ( TString name, const char* cut, const char* datacut = 0 )
102  { AddScaleFactorCut(name, TCut(cut), TCut(datacut)); }
103 
104  protected:
105  TString fSignalName = ""; ///< Legend entry of the signal that we are using from the MCConfig
106  FileType fSignalType = kBackground; ///< Which MC list to get the signal files from
107  TCut fBaseCut = "1"; ///< Sets the cut to use for MC events in the analysis
108  TCut fDataBaseCut = "1"; ///< Sets the cut to use for data in the analysis
109 
110  SearchBy fSearchBy = kLimitName; ///< Defines the string that is compared when identifying signal
111 
112  Double_t fBackgroundChange = 0.0; ///< Amount the background is scaled by to test scale factor systematic uncertainties
113  Bool_t fNormalized = true; ///< Determines whether or not to normalize backgrounds before comparing to data
114 
115  private:
116  std::vector<TCut> fScaleFactorCuts; ///< Vector of cuts to do scale factor measurements on
117  std::vector<TCut> fDataSFCuts; ///< Vector of cuts on data to do scale factor measurements on
118  std::vector<TString> fCutNames; ///< Vector of cut names to print out table
119 
120  TString fFormat = "%.2f"; ///< Format string for the output tables
121  PrintingMethod fPrintingMethod = kPresentation; ///< Stores type of method to use for making scale factor tables
122  UInt_t fNumCreated = 0; ///< The number of scale factor histograms made so far
123 
124  ClassDef(HistAnalysis,1)
125 };
126 
127 #endif