HighLAND
AnalysisLoop.hxx
1 #ifndef AnalysisLoop_h
2 #define AnalysisLoop_h
3 
4 #include "MemoryUsage.hxx"
5 #include "CoreDataClasses.hxx"
6 #include "AnalysisAlgorithm.hxx"
7 
8 /// This class is a base class for analyses.
9 ///
10 /// It specifies the interface that analyses should conform to, although user
11 /// analyses should inherit from baseAnalysis, not AnalysisLoop directly.
12 /// baseAnalysis implements all the required functions, so the user doesn't
13 /// have to implement all the functions themselves.
14 ///
15 /// The class also contains the low-level functionality for running the
16 /// analysis, including the all-important Loop function.
18  public :
19 
20  /// Constructor which parses and sanity checks the command line options.
21  AnalysisLoop(AnalysisAlgorithm* ana, int argc, char *argv[]);
22 
23  virtual ~AnalysisLoop(){}
24 
25  /// This is the main looping function that controls the analysis. It
26  /// initializes the analysis, then loops over
27  /// - Spills in the input file
28  /// - Bunches in each spill
29  /// - Configurations for each bunch (which sets of systematics to apply)
30  /// - toy experiments for each configuration (the MC throws for each systematic)
31  /// - Call the user's Process() function.
32  void Loop(int nmax=0, int imin=0);
33 
34  /// Simply calls Loop with the appropriate parameters as read from the
35  /// command line.
36  void Execute();
37 
38  void SetEvent(AnaEventC* event){_event= event;}
39 
40  protected:
41 
42  /// Initialize the entire analysis. Calls the Initialize() function in the
43  /// user's derived class as part of the initialization.
44  bool Initialize();
45 
46  /// Called after all processing is complete. Cleans up, then writes to and
47  /// closes the output file.
48  void Finalize();
49 
50  /// Initialize each spill, including reading it from the input file, and
51  /// applying any corrections specified by the user. Calls the user's
52  /// derived version after applying the corrections.
53  bool InitializeSpill();
54 
55  /// Called after each spill is finished. Calls the user's derived version
56  /// before deleting the current active Spill in the InputManager.
57  void FinalizeSpill();
58 
59  /// Initialize each bunch of each spill, simply calling the user's derived
60  /// version.
61  void InitializeBunch();
62 
63  /// Called after each bunch is finished, simply calling the user's derived
64  /// version.
65  void FinalizeBunch();
66 
67  /// Initialize each configuration for each bunch. The current active
68  /// configuration should already have been changed by Loop().
70 
71  /// Fill the tree for this bunch, including the "truth" tree if it is enabled.
72  /// The derived version should fill any variabled in the micro-tree that
73  /// don't depend on the exact analysis.
74  bool FinalizeConfiguration();
75 
76  /// Initialize each toy experiment for each configuration, including
77  /// applying any systematic variations. The user's derived version is called
78  /// after variations have been applied.
79  void InitializeToy();
80 
81  /// Called after each toy experiment is complete.
82  bool FinalizeToy();
83 
84  void InitializeSelection(const SelectionBase& sel);
85 
86  void FinalizeSelection(const SelectionBase& sel);
87 
88 
89  /// The main function called to run the analysis. The derived version should
90  /// apply any cuts, and return whether the current active bunch passed the
91  /// cuts or not.
92  bool Process(SelectionBase& selec);
93 
94  /// Define the corrections to be applied
95  void DefineCorrections();
96 
97  /// Define the configurations (micro-trees) and which systematics should be applied in each "configuration".
98  void DefineConfigurations();
99 
100  /// Define the variables that should be stored in the output micro-trees.
101  void DefineMicroTrees();
102 
103  /// Define the "truth" tree. See FillTruthTree().
104  void DefineTruthTree();
105 
106  /// Fill the track categories for color drawing. There is a definition in
107  /// baseAnalysis, and the user can specify their own if they have defined
108  /// their own custom categories.
109  void FillCategories() ;
110 
111  /// Fill the truth tree. The truth tree is designed to contain information
112  /// about all true signal events, including those that the analysis didn't
113  /// select as signal.
114  ///
115  /// The derived version should fill the relevant variables, and return whether
116  /// the tree should be written or not. The derived function is only called
117  /// once per spill!
118  // void FillTruthTree(const AnaTrueVertex& vtx);
119 
120  /// Fill the standard configurations trees:
121  void FillMicroTrees();
122 
123  /// Fill the standard configurations only toy-dependent variables
125 
126  ///------------------------------------------------------------------------------
127 
128  /// Simple usage statement, for if the user gave bad command line options.
129  void PrintUsage(const std::string& programName);
130 
131  // Return the current AnalysisAlgorithm
132  AnalysisAlgorithm& ana(){return *_ana;}
133 
134  protected:
135 
136  /// Fill the "header" tree, which includes POT information etc.
137  void FillHeaderTree();
138 
139  /// Fill the "config" tree, which includes details of the analysis cuts etc.
140  void FillConfigTree();
141 
142  /// Fill the "truth" tree
143  // void FillTruthTree();
144 
145  /// The number of entries we have read in.
146  Long64_t _entry;
147 
148  /// Path to the input file, as defined by the user.
149  std::string _inputFileName;
150 
151  /// This was used when the user could specify what type of input file they
152  /// had provided. Now this is done automatically.
153  std::string _inputFileType;
154 
155  /// What to call the output file, as defined by the user.
156  std::string _outputFileName;
157 
158  /// Path to the file with the list of events to skim, as defined by the user.
159  std::string _inputSkimFileName;
160 
161  /// Whether the "truth" tree should be filled. See FillTruthTree().
163 
164  /// Whether to run in "cosmics" mode, where all the tracks are saved in a
165  /// single bunch.
167 
168  /// Check version compatibility between nd280AnalysisTools compilation and oaAnalysis file
170 
171  /// Whether to fill the trees and create an output file or not
172  bool _fillTrees;
173 
174  /// Tools for tracking memory usage
176 
177  AnaEventC* _event;
178 
179  private:
180 
181  /// The number of entries in the tree to run over.
182  int _entry_nmax;
183 
184  /// The entry in the tree to start from.
185  int _entry_imin;
186 
187  /// The entry in the tree to finish with.
188  int _entry_imax;
189 
190  /// Total number of entries run so far
191  int _entry_count;
192 
193  /// The Analysis algorithm to run
194  AnalysisAlgorithm* _ana;
195 
196  /// The vector of weights for the weight systematics and corrections
197  Weight_h* _weightSyst;
198  Float_t* _weightCorr;
199  Int_t _nWeightSyst;
200 
201 
202  /// The current toy experiment weight
203  Double_t _toy_weight;
204 
205  /// Is the current toy succesful for any of the branches ?
206  bool _toy_passed;
207 
208  /// Is the current configuration succesful for any of the toys ?
209  bool _conf_passed;
210 
211 public:
212 
213 };
214 
215 #endif
void DefineCorrections()
Define the corrections to be applied.
MemoryUsage _memory
Tools for tracking memory usage.
void Loop(int nmax=0, int imin=0)
AnalysisLoop(AnalysisAlgorithm *ana, int argc, char *argv[])
Constructor which parses and sanity checks the command line options.
void FillHeaderTree()
Fill the "header" tree, which includes POT information etc.
bool Process(SelectionBase &selec)
void FinalizeSelection(const SelectionBase &sel)
void DefineMicroTrees()
Define the variables that should be stored in the output micro-trees.
std::string _inputFileType
void InitializeConfiguration()
bool _versionCheck
Check version compatibility between nd280AnalysisTools compilation and oaAnalysis file...
void FinalizeSpill()
void FillToyVarsInMicroTrees()
Fill the standard configurations only toy-dependent variables.
void FillCategories()
std::string _inputFileName
Path to the input file, as defined by the user.
void PrintUsage(const std::string &programName)
void DefineTruthTree()
Define the "truth" tree. See FillTruthTree().
std::string _inputSkimFileName
Path to the file with the list of events to skim, as defined by the user.
void DefineConfigurations()
Define the configurations (micro-trees) and which systematics should be applied in each "configuratio...
std::string _outputFileName
What to call the output file, as defined by the user.
void FillConfigTree()
Fill the "config" tree, which includes details of the analysis cuts etc.
bool _fillTrees
Whether to fill the trees and create an output file or not.
void FillMicroTrees()
Fill the standard configurations trees:
bool FinalizeConfiguration()
void InitializeToy()
bool _enableTruthTree
Whether the "truth" tree should be filled. See FillTruthTree().
void FinalizeBunch()
void InitializeBunch()
Long64_t _entry
Fill the "truth" tree.
bool InitializeSpill()
bool FinalizeToy()
Called after each toy experiment is complete.