HighLAND
AnalysisManager.hxx
1 #ifndef AnalysisManager_hxx_seen
2 #define AnalysisManager_hxx_seen
3 
4 
5 #include "SystematicManager.hxx"
6 #include "EventWeightManager.hxx"
7 #include "EventVariationManager.hxx"
8 #include "InputManager.hxx"
9 #include "SelectionManager.hxx"
10 #include "Experiment.hxx"
11 #include "FluxWeighting.hxx"
12 
13 
14 typedef std::string SelEnum;
15 typedef std::string SystEnum;
16 
17 /// This class is the Top level interface for the library.
18 
19 
21 
22 public:
23 
25  virtual ~AnalysisManager(){}
26 
27  void DefineProduction();
28  void DefineInputConverters();
29  void DefineSelections();
30  void DefineSystematics();
31 
32  /*
33  enum SystEnum{
34  kMomScale = 0,
35  kMomResol,
36  kChargeConf,
37  kTpcTrackEff
38  };
39 
40  enum SelEnum{
41  kTrackerNumuCC = 0,
42  };
43 
44 
45  enum InputEnum{
46  kHighlandTree = 0,
47  kP0dTree
48  };
49  */
50 
51  /// Returns the systematic manager
53 
54  /// Returns the EventWeight manager
56 
57  /// Returns the EventVariation manager
59 
60  /// Returns the input manager
62 
63  /// Returns the selection manager
65 
66  /// Sets the Experiment
67  void SetExperiment(Experiment* exp){_exp=exp;}
68 
69  /// Process one event. The input is the event. The output is a boolean (return value)
70  /// telling us whether at least one selection was passes for the current event, and a vector of Weight_hs
71  /// with the weights for each selection
72  bool ProcessEvent(const ToyExperiment& toy, AnaEventB& event, std::vector<Weight_h>& totalWeightSystVector, std::vector<Weight_h>& fluxWeightSystVector);
73  bool ProcessEvent(const ToyExperiment& toy, AnaEventB& event, std::vector<Weight_h>& totalWeightSystVector, std::vector<Weight_h>& fluxWeightSystVector, Float_t& POTweight);
74  bool ProcessEvent(AnaEventB& event, Float_t& POTWeight);
75  bool ProcessEvent(AnaEventB& event);
76 
77  /// Process one event method for use in BANFF and MaCh3 fitters
78  bool ProcessEvent(const ToyExperiment& toy, AnaEventB& event, Weight_h& totalWeight,Weight_h& FluxWeightSyst);
79 
80  /// Create the evevt array for preloading events
81  void CreateEventArray(Int_t nmax);
82 
83  /// Read the specified number of events from the file and save them into an array. Default(-1) is all events
84  bool ReadEvents(const std::string& inputFile, Int_t nmax=-1);
85 
86  /// Read the specified number of events from the current DataSample and save them into an array. Default(-1) is all events
87  bool ReadEvents(Int_t nmax=-1);
88 
89  /// Read the specified number of events from the DataSample and save them into an array. Default(-1) is all events
90  bool ReadEvents(DataSample* sample, Int_t nmax=-1);
91 
92  /// Set the maximum number of events to process
93  void SetNEventsToProcess(Int_t nmax){_nEventsToProcess=nmax;}
94 
95  /// Returns The SuperEvent with a given index from the array
96  AnaSuperEventB* GetSuperEvent(Int_t eventIndex){if (eventIndex>=(Int_t)_nEventsInArray) return NULL; return _eventArray[eventIndex];}
97 
98  /// Returns The Event with a given index from the array
99  AnaEventB* GetEvent(Int_t eventIndex);
100 
101  /// Returns The next SuperEvent
103 
104  /// Returns The next Event
106 
107  /// Returns the number of entries in the input tree
108  UInt_t GetEntries();
109 
110 
111  /// Method to load a given single event, without pre-loading.
112  /// Fill the raw AnaEventB structure.
113  /// The argument entry (the entry number in the input tree)
114  /// will be modified inside the method by the specific converter (hence the non-cont reference).
115  /// The way entry is modified will depend on whether the input file is event based
116  /// (every call to this method will increment by one the argument entry) or
117  /// spill based (several events -- one per bunch -- correspond to the same spill, so
118  /// once the first event in a given spill is read entry number will not be varied
119  /// until all events in that spill are processed).
120  /// Returns whether the event was successfully filled.
121  bool LoadEvent(Long64_t& entry);
122 
123  void PreloadEvents(bool preloadData = 1, bool preloadMC = 1);
124  bool PreloadMCEvents(std::vector<std::string> inputFiles, std::vector<float> POT_weights);
125  bool PreloadDataEvents(std::vector<std::string> inputFiles);
126  AnaSuperEventB* GetPreloadedMCSuperEvent(int i);
127  AnaSuperEventB* GetPreloadedDataSuperEvent(int i);
128  void CreateMCEventArray(Int_t nmax);
129  void CreateDataEventArray(Int_t nmax);
130  UInt_t GetNMCEvents(){return _nEventsInMCArray;}
131  UInt_t GetNDataEvents(){return _nEventsInDataArray;}
132  bool Initialize(Int_t nmax);
133  void InitialiseDataTChain();
134  void InitialiseMCTChain();
135 
136  void ResetEventsProcessed();
137 
138  /// Fill the raw AnaEventB structure and create a AnaSuperEventB from
139  /// the raw event (all done by InputManagerB calls).
140  /// The input entry number will be modified internally
141  /// by the specific converter (hence the non-cont reference) .
142  /// This will depend on whether the input file is spill based or event based.
143  AnaSuperEventB* LoadSuperEvent(Long64_t& evtIndex);
144 
145  FluxWeighting* GetFluxWeighting(){return _flux;}
146 
147  /// Check to see whether the event is from the right run period for the selection
148  /// This is important for making sure we do not run the anti-neutrino mode selections
149  /// on neutrino mode data
150  bool CheckSelectionAgainstRunPeriod(SelectionBase* selec, int RunPeriod);
151 
152  /// Return the number of preloaded events
153  UInt_t GetNPreloadedEvents() const {return _nEventsInArray;}
154 
155 protected:
156 
157  /// An instance of the systematic manager
159 
160  /// An instance of the EventWeight manager
162 
163  /// An instance of the EventVariation manager
165 
166  /// An instance of the input manager
168 
169  /// An instance of the selection manager
171 
172  /// The array of events
174 
175  /// the number of events in the array
177 
178  /// whether to apply detector event weight or not
180 
181  /// whether to apply detector event variation or not
183 
184  /// whether to apply Flux weight systematic or not
186 
187  /// The current event in the event array
189 
190  /// The Experiment
192 
193  /// The Toy Experiment
195 
196  std::vector<DataSample*>::iterator _currentSample;
197 
198  SampleGroup* _currentSampleGroup;
199 
200  std::vector<DataSample*> _samples;
201 
202  /// the maximum number of events to process
204 
205  /// the number of events processed so far
207 
208  /// Access to the flux weighting.
210 
211  /// Flag to enable/disable flux weight
213 
214  /// Flag to tell psyche whether to initialise pion systematics, taken from parameters file
215  /// Pion systematic initialisation is very very slow, so disabling this when it is not needed speeds
216  /// the event loading by a factor of 30
218 
219  /// Flux file and option
220  std::string _fluxFile;
221  std::string _fluxTuning;
222  std::string _fluxVersion;
223 
224  /// The array of preloaded MC events
226 
227  /// The array of preloaded Data events
229 
230  /// the number of events in the preloaded MC array
232 
233  /// the number of events in the preloaded Data array
235 
236  /// The POT weight for each MC file loaded into the Analysis Manager
237  std::vector<Float_t> _POT_weights;
238 
239  bool _doFGD1;
240  bool _doFGD2;
241 
242 };
243 
244 #endif
245 
bool ReadEvents(const std::string &inputFile, Int_t nmax=-1)
Read the specified number of events from the file and save them into an array. Default(-1) is all eve...
ToyExperiment _toy
The Toy Experiment.
bool _applyEventVariations
whether to apply detector event variation or not
This class is the Top level interface for the library.
SelectionManager _sel
An instance of the selection manager.
InputManager _input
An instance of the input manager.
std::vector< Float_t > _POT_weights
The POT weight for each MC file loaded into the Analysis Manager.
bool _applyFluxWeightSystematic
whether to apply Flux weight systematic or not
SystematicManager _syst
An instance of the systematic manager.
bool CheckSelectionAgainstRunPeriod(SelectionBase *selec, int RunPeriod)
EventVariationManager _var
An instance of the EventVariation manager.
UInt_t _nEventsInArray
the number of events in the array
void SetExperiment(Experiment *exp)
Sets the Experiment.
InputManager & input()
Returns the input manager.
bool _applyFluxWeight
Flag to enable/disable flux weight.
AnaEventB * GetNextEvent()
Returns The next Event.
AnaSuperEventB ** _dataEventArray
The array of preloaded Data events.
The maximum number of systematics that is supported.
bool LoadEvent(Long64_t &entry)
UInt_t _nEventsInMCArray
the number of events in the preloaded MC array
SelectionManager & sel()
Returns the selection manager.
Experiment * _exp
The Experiment.
EventVariationManager & evar()
Returns the EventVariation manager.
bool ProcessEvent(const ToyExperiment &toy, AnaEventB &event, std::vector< Weight_h > &totalWeightSystVector, std::vector< Weight_h > &fluxWeightSystVector)
AnaSuperEventB * LoadSuperEvent(Long64_t &evtIndex)
AnaSuperEventB * GetNextSuperEvent()
Returns The next SuperEvent.
UInt_t GetNPreloadedEvents() const
Return the number of preloaded events.
AnaSuperEventB ** _eventArray
The array of events.
EventWeightManager _weight
An instance of the EventWeight manager.
AnaEventB * GetEvent(Int_t eventIndex)
Returns The Event with a given index from the array.
void CreateEventArray(Int_t nmax)
Create the evevt array for preloading events.
UInt_t GetEntries()
Returns the number of entries in the input tree.
Int_t _nEventsProcessed
the number of events processed so far
Int_t _currentEvent
The current event in the event array.
void SetNEventsToProcess(Int_t nmax)
Set the maximum number of events to process.
UInt_t _nEventsInDataArray
the number of events in the preloaded Data array
std::string _fluxFile
Flux file and option.
AnaSuperEventB ** _mcEventArray
The array of preloaded MC events.
FluxWeighting * _flux
Access to the flux weighting.
SystematicManager & syst()
Returns the systematic manager.
EventWeightManager & eweight()
Returns the EventWeight manager.
Int_t _nEventsToProcess
the maximum number of events to process
AnaSuperEventB * GetSuperEvent(Int_t eventIndex)
Returns The SuperEvent with a given index from the array.
bool _applyEventWeights
whether to apply detector event weight or not