CutOptimizer.h
1 /* -*- C++ -*-.*********************************************************************************************
2  Author: Ben Strutt
3  Email: strutt@physics.ucla.edu
4 
5  Description:
6  Read in trees of ANITA event summaries and try to separate signal and background...
7 ***********************************************************************************************************/
8 
9 #ifndef CUT_OPTIMIZER_H
10 #define CUT_OPTIMIZER_H
11 
12 
13 #include "TString.h"
14 #include "TChain.h"
15 #include "TXMLEngine.h"
16 
17 
18 class TH2D;
19 class TEfficiency;
20 
21 namespace Acclaim{
22 
23  class SummarySet;
24 
30  class CutOptimizer {
31 
32  public:
33 
34  // typedef std::pair<const char*, bool> FormulaString;
35 
36  static void setDebug(bool db);
37  static TString branchifyName(const char* formStr);
38 
39  CutOptimizer(const char* signalGlob, const char* backgroundGlob = NULL);
40  virtual ~CutOptimizer();
41  void optimize(const std::vector<const TCut*>& signalSelection,
42  const std::vector<const TCut*>& backgroundSelection,
43  const std::vector<TString>& formulaStrings,
44  const char* outFileName = "");
45 
46 
47  // /**
48  // * Add to a list of extra tree for which you wish to calculate the MVA score
49  // *
50  // * @param treeName is the name of the tree to create
51  // * @param glob is the wildcard filenames for the ROOT files containing AnitaEventSummary trees (named sunTree)
52  // * @param spectatorSelection is a vector of TCut variables used to choose the spectators
53  // *
54  // * @return the number of spectator trees to be prepared
55  // */
56  // size_t addSpectatorTree(const char* treeName, const char* glob, const std::vector<const TCut*>& spectatorSelection){
57  // fSpecTreeNames.push_back(treeName);
58  // fSpecGlobs.push_back(glob);
59  // fSpecSelections.push_back(spectatorSelection);
60  // return fSpecSelections.size();
61  // }
62 
63  protected:
64 
65  enum BranchType{
66  kUnassigned,
67  kInt,
68  kFloat
69  };
70 
71  TFile* makeOutputFile(const char* outFileName);
72  // void generateSignalAndBackgroundTreesProof(const std::vector<const TCut*>& signalSelection,
73  // const std::vector<const TCut*>& backgroundSelection,
74  // const std::vector<FormulaString>& treeVars);
75  // BranchType setBranchFromFormula(TTree* t, const TTreeFormula* f, const char* formulaString, Int_t* intPtr, Float_t* floatPtr);
76 
77  TString fSignalGlob;
78  TString fBackgroundGlob;
79  TString fOutFileName;
80  TFile* fOutFile;
81  TChain* fSignalTree;
82  TChain* fBackgroundTree;
83  // TTree* fRejectedSignalTree;
84  // TTree* fRejectedBackgroundTree;
85  // Bool_t fDoAllPeaks;
86  // Bool_t fSaveTrees;
87  // std::vector<Float_t> fSignalFloatVals;
88  // std::vector<Float_t> fBackgroundFloatVals;
89  // std::vector<Int_t> fSignalIntVals;
90  // std::vector<Int_t> fBackgroundIntVals;
91 
92  // std::vector<TString> fSpecTreeNames;
93  // std::vector<TString> fSpecGlobs;
94  // std::vector<std::vector<const TCut*> > fSpecSelections;
95  // std::vector<TTree*> fSpecTrees;
96 
97  static const int numEffVars = 2;
98  enum{
99  kSNR,
100  kEnergy
101  };
102  static const int numCutOrders = 2;
103  enum {
104  kInSequence,
105  kIfFirst
106  // kIfLast
107  };
108 
109  std::vector<TEfficiency*>fSignalEffs[numEffVars][numCutOrders];
110 
111 
112 
113 
114 
115 
116 
117 
118 
119  // /**
120  // * @class FormulaHolder
121  // * @brief Contains the TTreeFormula and trick TChain into notifying all the formulas
122  // */
123 
124  // class FormulaHolder : public TObject {
125  // public:
126  // FormulaHolder(TChain* c);
127  // virtual ~FormulaHolder();
128  // virtual Bool_t Notify();
129  // virtual size_t add(const char* formulaString);
130  // TTreeFormula* at(UInt_t i) {return fForms.at(i);}
131  // const char* str(UInt_t i) const {return fFormStrs.at(i);}
132  // size_t N(){return fForms.size();}
133  // protected:
134  // TChain* fChain;
135  // std::vector<TTreeFormula*> fForms;
136  // std::vector<const char*> fFormStrs;
137  // };
138 
139 
140 
141 
142 
143 
144 
145 
146 
147  public:
148 
154  class FisherResult : public TNamed {
155 
156  typedef std::map<int, double> WeightMap;
157  typedef std::map<int, TString> ExpressionMap;
158 
159  public:
165  FisherResult(const char* fileName = "") : TNamed("FisherResult", fileName){
166  getResultFromXML(fileName);
167  }
168  TString getFisherFormula() const;
169  TH2D* makeTimeHist(int nBinsX, int nBinsY, TTree* t, EColor col, int varInd=0, const char* extraName = "") const;
170  virtual void Print(Option_t* opt = "") const;
171  void getExpressions(std::vector<TString>& expressions) const;
172  double getWeight(const char* expression);
173 
174  protected:
175  void getResultFromXML(const char* filename);
176  void parseNode(TXMLEngine* xml, XMLNodePointer_t node, Int_t level);
177 
178  ExpressionMap fExpressions;
179  WeightMap fWeights;
180 
182  };
183 
184 
185 
186 
187 
188  };
189 
190 }
191 #endif //CUT_OPTIMIZER
CutOptimizer(const char *signalGlob, const char *backgroundGlob=NULL)
Get the results of the Fisher Discriminant into a more useful form.
Definition: CutOptimizer.h:154
Namespace which wraps everything in the library.
ClassDef(FisherResult, 1)
List of variable weights.
static TString branchifyName(const char *formStr)
**
WeightMap fWeights
List of variable names.
Definition: CutOptimizer.h:179
A class to parse AnitaEventSummary trees, extract quantities of interest, feed them into a TMVA frame...
Definition: CutOptimizer.h:30
FisherResult(const char *fileName="")
Definition: CutOptimizer.h:165
TFile * makeOutputFile(const char *outFileName)