HighLAND
SelectionBase.hxx
1 #ifndef SelectionBase_h
2 #define SelectionBase_h
3 
4 #include "StepBase.hxx"
5 #include "HLClonesArray.hxx"
6 
7 #include "CoreDataClasses.hxx"
8 #include "Deprecated.hxx"
9 #include <vector>
10 #include <string>
11 #include <sstream>
12 
13 /// The maximum number of steps that is supported.
14 const UInt_t NMAXSTEPS=50;
15 
16 /// The maximum number of branches that are supported. May be expanded in the
17 /// future.
18 const UInt_t NMAXBRANCHES=20;
19 
20 /// The maximum number of selections that is supported.
21 const UInt_t NMAXSELECTIONS=10;
22 
23 /// Base class for an event selection
24 /// It should implement the methods
25 /// - DefineSteps
26 /// - MakeBox
27 /// - MakeEventSummary
28 /// - FillEventSummary
29 
30 /// This class that handles the registration of steps (cuts and actions),
31 /// and records which cuts were passed
32 ///
33 /// The main way you will interact with this class is using the AddStep() function
34 ///
35 /// If your analysis only has a single "branch" to it, then adding cuts is very simple. All you have to do
36 /// is define cuts that inherit from the CutBase base class, and add them using
37 /// AddStep(Step type, "Pretty name", new YourNewCut());
38 ///
39 /// You should add them in DefineSteps() method of your selection. The steps should be added in the
40 /// order in which you call them. You can have up to NMAXSTEPS cuts. For example for the
41 /// CC-Inclusive selection
42 ///
43 /// AddStep(StepBase::kCut, "event quality", new EventQualityCut(), true);
44 /// AddStep(StepBase::kCut, "> 0 tracks ", new TotalMultiplicityCut(), true);
45 /// AddStep(StepBase::kAction, "find leading tracks",new FindLeadingTracksAction());
46 /// AddStep(StepBase::kAction, "find vertex", new FindVertexAction());
47 /// AddStep(StepBase::kCut, "quality+fiducial", new TrackQualityFiducialCut(), true);
48 /// AddStep(StepBase::kAction, "find veto track", new FindVetoTrackAction());
49 /// AddStep(StepBase::kCut, "veto", new ExternalVetoCut());
50 /// AddStep(StepBase::kAction, "find oofv track", new FindOOFVTrackAction());
51 /// AddStep(StepBase::kCut, "External FGD1", new ExternalFGD1lastlayersCut());
52 /// AddStep(StepBase::kCut, "muon PID", new MuonPIDCut());
53 ///
54 /// last "true" means the step sequence is broken if cut is not passed (default is "false")
55 
56 /// Cut branches
57 ///
58 /// Your analysis can contain several branches that contain common steps. For example, CC0pi, CC1pi and
59 /// CCNpi branches. You can have up to NMAXBRANCHES branches. There are a few subtleties to be aware of
60 /// when using branches, which are best explained using the following example code, which would all appear
61 /// in your yourSelection class. For the CC multi-pion selection
62 
63 /// Additional actions for the multi-pi selection.
64 ///
65 /// AddStep(StepBase::kAction, "find_pions", new FindPionsAction());
66 /// AddStep(StepBase::kAction, "find_tpc1", new FindTPC1TracksAction());
67 
68 /// Add a split to the trunk with 3 branches.
69 /// AddSplit(3);
70 
71 /// First branch is for CC-0pi
72 /// AddStep(0, StepBase::kCut, "CC-0pi", new NoPionCut());
73 
74 /// Second branch is for CC-1pi
75 /// AddStep(1, StepBase::kCut, "CC-1pi", new OnePionCut());
76 
77 /// Third branch is for CC-Other
78 /// AddStep(2, StepBase::kCut, "CC-Other", new OthersCut());
79 
80 /// Set the branch aliases to the three branches
81 /// SetBranchAlias(0,"CC-0pi",0);
82 /// SetBranchAlias(1,"CC-1pi",1);
83 /// SetBranchAlias(2,"CC-Other",2);
84 
85 
86 class SelectionBase: public TObject{
87 public:
88  SelectionBase(bool forceBreak=true, Int_t eventBoxId=UNASSIGNEDID);
89  virtual ~SelectionBase(){}
90 
91  //========= These are mandatory functions ==================
92 
93  /// Define all steps in the selection
94  virtual void DefineSteps(){std::cout << "ERROR: DefineSteps must be implemented in your Selection!!!" << std::endl;exit(1);}// = 0;
95 
96  /// Define the detector Fiducial Volume in which this selection is applied
97  virtual void DefineDetectorFV(){std::cout << "ERROR: DefineDetectorFV must be implemented in your Selection!!!" << std::endl;exit(1);}// = 0;
98 
99  /// Create the appropriate type of box
100  virtual ToyBoxB* MakeToyBox(){std::cout << "ERROR: MakeToyBox must be implemented in your Selection!!!" << std::endl;exit(1);return NULL;}// = 0;
101 
102  /// Fill the EventBox with the objects needed by this selection
103  virtual void InitializeEvent(AnaEventC&){std::cout << "ERROR: InitializeEvent must be implemented in your Selection!!!" << std::endl;exit(1);}// = 0;
104 
105  //==========================================================
106 
107  //---- These are optional functions, needed by FITTERS but not by highland2 analyses --------------
108 
109  /// Fill the Event Summary, needed by fitters
110  virtual bool FillEventSummary(AnaEventC&, Int_t*){return true;}// = 0;
111 
112  /// Return the sample type, needed by fitters
113  virtual SampleId_h GetSampleId(){return UNASSIGNEDID;}// = 0;
114 
115  //---- These are optional functions, but recommended to customize systematics and increase speed --------------
116 
117  /// Is this track relevant for a given systematic (prior to selection, call when initializing the event, valid for all toys in the same event)
118  virtual bool IsRelevantRecObjectForSystematic(const AnaEventC&, AnaRecObjectC*, SystId_h syst_index, Int_t branch=0) const {(void)syst_index;(void)branch;return true;}
119 
120  /// Is this true track relevant for a given systematic (prior to selection, call when initializing the event, valid for all toys in the same event)
121  virtual bool IsRelevantTrueObjectForSystematic(const AnaEventC&, AnaTrueObjectC*, SystId_h syst_index, Int_t branch=0) const {(void)syst_index;(void)branch;return true;}
122 
123  /// Is this track relevant for a given systematic (after selection, called for each toy)
124  virtual bool IsRelevantRecObjectForSystematicInToy(const AnaEventC&, const ToyBoxB&, AnaRecObjectC*, SystId_h syst_index, Int_t branch=0) const {(void)syst_index;(void)branch;return true;}
125 
126  /// Is this true track relevant for a given systematic (after selection, called for each toy)
127  virtual bool IsRelevantTrueObjectForSystematicInToy(const AnaEventC&, const ToyBoxB&, AnaTrueObjectC*, SystId_h syst_index, Int_t branch=0) const {(void)syst_index;(void)branch;return true;}
128 
129  /// Is this systematic relevant for this selection
130  virtual bool IsRelevantSystematic(const AnaEventC&, const ToyBoxB&, SystId_h syst_index, Int_t branch=0) const {(void)syst_index;(void)branch;return true;}
131 
132  /// This method is called after the systematic is applied (Apply). It should decide wheder the
133  /// selection has to be redone or not.
134  virtual bool CheckRedoSelection(const AnaEventC&, const ToyBoxB& PreviousToyBox, Int_t& redoFromStep){(void)PreviousToyBox;redoFromStep=0;return true;}
135 
136  //==========================================================
137 
138  /// Initialize this selection: defines the steps and the detectorFV
139  void Initialize();
140 
141  /// Validates this selection
142  void Validate() const;
143 
144  /// Apply all steps in the selection
145  bool Apply(AnaEventC& event, bool& redo);
146 
147  /// Return the title of this selection. A nice version of the name.
148  const std::string& Title() const{return _title;}
149 
150  /// Return the name of this selection. This overrides the TObject::GetName() interface.
151  virtual const char* GetName() const {return _name.c_str();}
152 
153  /// Return the name of this selection.
154  const std::string& Name() const{return _name;}
155 
156  /// Set the title of this selection, which is the "nice" version of the selection name,
157  void SetTitle(const std::string& title){_title=title;}
158 
159  /// Set the name of this selection, which is used internally by the SelectionManager
160  void SetName(const std::string& name){_name=name;}
161 
162  /// enable and disable selection
163  void Enable(){_enabled=true;}
164  void Disable(){_enabled=false;}
165 
166  // Is this selection enabled ?
167  bool IsEnabled() const {return _enabled;}
168 
169  /// When using the framework by a fitter (i.e. BANFF) we want to break the step sequence when a cut is not passed, that is
170  /// we are interested about events that pass all cuts. In this case _forceBreak should be true. On the other hand it should be false
171  /// in highland since we might be interested about events that didn't pass a specific cut.
172  bool GetForceBreak() const {return _forceBreak;}
173 
174  // Print statistics for this selection
175  void PrintStatistics() const;
176  void PrintStatistics(const std::string& name) const;
177  void PrintStatistics(UInt_t ID) const;
178 
179  /// Create the array of PreviousToyBox
180  void CreateToyBoxArray(Int_t nevents);
181 
182  /// Delete the PreviousToyBox pointer for the last toy of the event
183  void FinalizeEvent(const AnaEventC& event);
184 
185  //-----------------------------------------------------------------
186 
187  /// Add a user step to the selection.
188  /// One should specify the branching sequence, the step type, the title and the cut_break (whether to break the step sequence quen a cut is not passed)
189  void AddStep( StepBase::TypeEnum type, const std::string& title, StepBase* step, bool cut_break=false);
190  void AddStep(Int_t b0, StepBase::TypeEnum type, const std::string& title, StepBase* step, bool cut_break=false);
191  void AddStep(Int_t b0, Int_t b1, StepBase::TypeEnum type, const std::string& title, StepBase* step, bool cut_break=false);
192  void AddStep(Int_t b0, Int_t b1, Int_t b2, StepBase::TypeEnum type, const std::string& title, StepBase* step, bool cut_break=false);
193  void AddStep(Int_t b0, Int_t b1, Int_t b2, Int_t b3, StepBase::TypeEnum type, const std::string& title, StepBase* step, bool cut_break=false);
194  void AddStep(Int_t b0, Int_t b1, Int_t b2, Int_t b3, Int_t b4, StepBase::TypeEnum type, const std::string& title, StepBase* step, bool cut_break=false);
195  void AddStep(Int_t b0, Int_t b1, Int_t b2, Int_t b3, Int_t b4, Int_t b5, StepBase::TypeEnum type, const std::string& title, StepBase* step, bool cut_break=false);
196  void AddStep(Int_t b0, Int_t b1, Int_t b2, Int_t b3, Int_t b4, Int_t b5, Int_t b6, StepBase::TypeEnum type, const std::string& title, StepBase* step, bool cut_break=false);
197  void AddStep(Int_t b0, Int_t b1, Int_t b2, Int_t b3, Int_t b4, Int_t b5, Int_t b6, Int_t b7, StepBase::TypeEnum type, const std::string& title, StepBase* step, bool cut_break=false);
198  void AddStep(const std::vector<UInt_t>& branch_seq, StepBase::TypeEnum type, const std::string& title, StepBase* step, bool cut_break=false);
199 
200  // This is the basic function to add the step
201  void AddStep(const std::vector<UInt_t>& branch_seq, StepBase* step);
202 
203  // This is the basic function to add several step
204  void AddSteps(const std::vector<UInt_t>& branch_seq, const std::vector<StepBase*>& steps);
205 
206  /// Add a split in the step sequence. The user should specify the number of branches in this split and the branch sequence
207  void AddSplit(UInt_t nbranches, Int_t b0=-1, Int_t b1=-1, Int_t b2=-1, Int_t b3=-1, Int_t b4=-1, Int_t b5=-1, Int_t b6=-1, Int_t b7=-1);
208  void AddSplit(UInt_t nbranches, const std::vector<UInt_t>& branch_seq);
209 
210  void AddBranch(Int_t ibranch, const std::vector<UInt_t>& branch_seq, const std::string& alias="");
211 
212 
213  /// Replace a step (same structure of AddStep, but for only one step at once)
214 // void ReplaceStep(const std::vector<UInt_t>& branch_seq, UInt_t step_nbr, StepBase::TypeEnum type, const std::string& title, StepBase* step, bool cut_break=false);
215 
216  /// Remove a step
217 // void RemoveStep(const std::vector<UInt_t>& branch_seq, UInt_t step_nbr);
218 
219  /// Insert a step after the specified cut
220 // void InsertStep(const std::vector<UInt_t>& branch_seq, UInt_t step_nbr,StepBase::TypeEnum type, const std::string& title, StepBase* step, bool cut_break=false);
221 
222  /// Disable step
223 // void DisableStep(const std::vector<UInt_t>& branch_seq, UInt_t step_nbr);
224 
225  /// Disable step provided title and branch ID
226  void DisableStep(const std::string& title, Int_t ID=-1);
227 
228  /// Disable step provided title and branch ID
229  void RemoveStep(const std::string& title, Int_t ID=-1);
230 
231  /// Replace step provided title and branch ID of the step to replace
232  void ReplaceStep(const std::string& old_title, Int_t ID, StepBase::TypeEnum type, const std::string& title, StepBase* step, bool cut_break=false);
233 
234  // Insert step after step with a given title and branch ID
235  void InsertStep(const std::string& previous_title, Int_t ID, StepBase::TypeEnum type, const std::string& title, StepBase* step, bool cut_break=false);
236 
237 
238  /// Copy a clone of the steps in range first-last from branch sbranch1 in selection ssel1 to sbranch2 in selection ssel2
239  void CopySteps(SelectionBase& sel1, UInt_t branchID1, UInt_t first, UInt_t last,
240  Int_t b0=-1, Int_t b1=-1, Int_t b2=-1, Int_t b3=-1, Int_t b4=-1, Int_t b5=-1, Int_t b6=-1, Int_t b7=-1);
241 
242  void CopySteps(SelectionBase& sel1, const std::string& sbranch1, UInt_t first, UInt_t last,
243  Int_t b0=-1, Int_t b1=-1, Int_t b2=-1, Int_t b3=-1, Int_t b4=-1, Int_t b5=-1, Int_t b6=-1, Int_t b7=-1);
244 
245  void CopySteps(SelectionBase& sel1, UInt_t branchID1, UInt_t first, UInt_t last, const std::vector<UInt_t>& branch_seq2);
246  // void CopySteps(SelectionBase& sel1, UInt_t first, UInt_t last,const std::string& sbranch2="trunk"){
247  // CopySteps(sel1,"trunk",first,last,sbranch2);
248  // }
249 
250  /// Copy a clone of all the steps from branch sbranch1 in selection ssel1 to first branch in selection 2
251  void CopySteps(SelectionBase& sel1, const std::string& sbranch1="trunk");
252 
253 
254  /// Copy a clone of the steps with number istep from branch sbranch1 in selection ssel1 to sbranch2 in selection ssel2
255  void CopyStep(SelectionBase& sel1, const std::string& sbranch1, UInt_t istep, Int_t b0=-1, Int_t b1=-1, Int_t b2=-1, Int_t b3=-1, Int_t b4=-1, Int_t b5=-1, Int_t b6=-1, Int_t b7=-1);
256  void CopyStep(SelectionBase& sel1, UInt_t istep, Int_t b0=-1, Int_t b1=-1, Int_t b2=-1, Int_t b3=-1, Int_t b4=-1, Int_t b5=-1, Int_t b6=-1, Int_t b7=-1){
257  CopyStep(sel1,"trunk",istep, b0,b1,b2,b3,b4,b5,b6,b7);
258  }
259 
260 
261  //-----------------------------------------------------
262 
263  /// Get all steps in a given branch provided the branch sequence (vector of integers)
264  std::vector<StepBase*> GetStepsInBranch(const std::vector<UInt_t>& branch_seq, UInt_t first=0, UInt_t last=NMAXSTEPS-1) const;
265 
266  /// Get all steps in a given branch provided the branch sequence (vector of integers)
267  std::vector<StepBase*> GetStepsInBranchWithDummy(const std::vector<UInt_t>& branch_seq, UInt_t first=0, UInt_t last=NMAXSTEPS-1) const;
268 
269  /// Get all steps in a given branch provided the branch alias
270  std::vector<StepBase*> GetStepsInBranch(const std::string& branch, UInt_t first=0, UInt_t last=NMAXSTEPS-1) const;
271 
272  /// Get all steps in a given branch provided the branch uniqueID
273  std::vector<StepBase*> GetStepsInBranch(UInt_t ID, UInt_t first=0, UInt_t last=NMAXSTEPS-1) const;
274 
275  /// Get all cuts in a given branch provided the branch alias
276  std::vector<StepBase*> GetCutsInBranch(const std::string& branch) const;
277 
278  /// Get all cuts in a given branch provided the branch uniqueID
279  std::vector<StepBase*> GetCutsInBranch(UInt_t ID) const;
280 
281  /// Get the last step in a given branch provided the branch sequence (individual integers)
282  StepBase* GetLastStepInBranch(Int_t b0=-1, Int_t b1=-1, Int_t b2=-1, Int_t b3=-1, Int_t b4=-1, Int_t b5=-1, Int_t b6=-1, Int_t b7=-1) const;
283 
284  /// Get the last step in a given branch provided the branch sequence (vector of integers)
285  StepBase* GetLastStepInBranch(const std::vector<UInt_t>& branch) const;
286 
287  /// Get the last step in a given branch provided the branch alias
288  StepBase* GetLastStepInBranch(const std::string& branch) const;
289 
290  /// Get step in a given branch provided the branch sequence (vector of integers) and the step index
291  StepBase* GetStepInBranch(const std::vector<UInt_t>& branch_seq, UInt_t index) const;
292 
293  /// Get step in a given branch provided the branch alias and the step index
294  StepBase* GetStepInBranch(const std::string& branch, UInt_t index) const;
295 
296  /// Get step in a given branch provided the branch uniqueID and the step index
297  StepBase* GetStepInBranch(UInt_t ID, UInt_t index) const;
298 
299  //-----------------------------------------------------
300 
301  /// Convert the branch sequence into a string
302  std::string ConvertBranchToString(const std::vector<UInt_t>& branch, Int_t upToSplit=-1) const;
303 
304  /// Convert the branch sequence of individual integers into a vector of integers
305  std::vector<UInt_t> ConvertBranch(Int_t b0=-1, Int_t b1=-1, Int_t b2=-1, Int_t b3=-1, Int_t b4=-1, Int_t b5=-1, Int_t b6=-1, Int_t b7=-1) const;
306 
307  /// Set the branch alias and unique ID provided the branch sequence
308  void SetBranchAlias(Int_t ID, const std::string& name, Int_t b0=-1, Int_t b1=-1, Int_t b2=-1, Int_t b3=-1, Int_t b4=-1, Int_t b5=-1, Int_t b6=-1, Int_t b7=-1);
309 
310  /// Get the branch sequence for a specific branch alias
311  std::vector<UInt_t> GetBranchSequence(const std::string& name) const;
312 
313  /// Get the branch sequence for a specific branch unique ID
314  std::vector<UInt_t> GetBranchSequence(Int_t ID) const;
315 
316  /// Gets the branch unique ID with a given alias
317  Int_t GetBranchUniqueID(const std::string& name) const;
318 
319  /// Gets the branch alias for a given branch unique ID
320  std::string GetBranchAlias(Int_t ID) const;
321 
322  //-----------------------------------------------------
323 
324  /// Apply a range of steps in a branch
325  bool ApplySteps(AnaEventC& event, ToyBoxB& box, const std::string& branch, Int_t ifirst=0, Int_t ilast=NMAXSTEPS);
326 
327  /// Apply all registered steps in a threadsafe way
328  bool ApplySteps(AnaEventC& event, ToyBoxB& box, Int_t firstStepToApply);
329 
330  /// Return whether the specified cut was passed or not.
331  bool GetCutPassed(Int_t icut, Int_t branch=0) const{return _cut_passed[branch][icut];}
332 
333  /// Get the accumulated cut level - the maximum cut number for which all
334  /// lower cut numbers were passed.
335  // Int_t GetAccumCutLevel(Int_t branch=0) const{return _accum_cut_level[branch];}
336  Int_t GetAccumCutLevel(Int_t branch=0) const{return GetPreviousToyBox().AccumLevel[branch];}
337 
338  /// Reset all cuts to "not passed", and set the accumulated cut level to 0.
339  void InitializeCutLevels();
340 
341  /// Get the maximum cut level for this event and the last processed toy
343 
344  /// Get the maximum cut level for this event and all toys
346 
347  /// Is the preselection passed in any of the branches
348  bool PreSelectionPassed(const AnaEventC& event);
349 
350  /// Set the pre-selection accum level
352 
353  /// Set the pre-selection accum level
355 
356  /// Set the Selection index
357  void SetEnabledIndex(Int_t index) {_selEnabledIndex=index;}
358 
359  /// Get the Selection index
360  Int_t GetEnabledIndex() const {return _selEnabledIndex;}
361 
362  /// Set the detector in which the Fiducial Volume is defined
363  void SetDetectorFV(SubDetId_h det, Int_t ibranch=-1);
364 
365  /// Get the detector in which the Fiducial Volume is defined
366  SubDetId_h GetDetectorFV(Int_t ibranch=0) const;
367 
368  /// Returns the Id of the EventBox to be used in this selection
369  EventBoxId_h GetEventBoxId() const { return _eventBoxId;}
370 
371  //-----------------------------------------------------
372 
373  /// Check the existence of branch
374  bool HasBranch(Int_t ibranch, const std::string& fromMethod="HasBranch") const;
375 
376  /// Return the number of branches
377  UInt_t GetNBranches() const{return _branchSequence.size();}
378 
379  /// Return all the names of the steps, in the order they were added.
380  std::vector<std::string> GetStepNames(Int_t ibranch=0) const;
381 
382  /// Return all the names of the cuts, in the order they were added.
383  std::vector<std::string> GetCutNames(Int_t ibranch=0) const;
384 
385  /// Return an step provided the title and the Branch ID
386  StepBase* GetStep(const std::string& title, Int_t ID=0) const;
387 
388  /// Return the cut number (starting at 0) corresponding to an step with a given title
389  Int_t GetCutNumber(const std::string& title, Int_t ID=0) const;
390 
391  /// Return the step number (starting at 0) corresponding to an step with a given title
392  Int_t GetStepNumber(const std::string& title, Int_t ID=0) const;
393 
394  /// Return the number of steps in a given branch
395 // UInt_t GetNSteps(Int_t branch);
396 
397  /// Return the number of cuts that have been added.
398  UInt_t GetNMaxCuts() const;
399 
400  /// Return the number of cuts in a given branch
401  UInt_t GetNCuts(Int_t branch) const;
402 
403  /// By default EventSummary class is created and filled when the selection is passed. But this might be necessary also for events not passing the selection
404  /// The user can force the EventSummary to be filled always.
406 
407  /// Returns the flag to fill the EventSummary even when the selection is not passed
409 
410  /// Dumps the list of branches
411  void DumpBranches() const;
412 
413  /// Print out the index, name and title of each step for a given branch (no argument for all branches)
414  void DumpSteps(const std::string& branch="", bool onlycuts=false) const;
415  void DumpSteps(Int_t ID, bool onlycuts=false) const;
416 
417  /// Print out the index, name and title of each cut for a given branch (no argument for all branches)
418  void DumpCuts(Int_t branch=-1) const {DumpSteps(branch,true);}
419 
420  /// Set the Run periods (defined in AnalysisUtils) for which this selection is valid
421  /// By default all run periods are valid
422  void SetValidRunPeriods(std::string runPeriods);
423 
424  /// Method to see whether this selection should be applied to the given run period
425  bool IsValidRun(int runPeriod) const {return _validRunPeriods[runPeriod];}
426 
427  /// Get the ToyBox of the last processed toy for a particular event
428  const ToyBoxB& GetPreviousToyBox(const AnaEventC& event) const;
429 
430  /// Get the ToyBox of the last processed toy (only for no MULTITHREAD)
431  const ToyBoxB& GetPreviousToyBox() const;
432 
433  //-----------------------------------------------------
434 
435  ClassDef(SelectionBase, 1);
436 
437 protected:
438 
439  /// Add a branch unique ID to all steps in that branch
440  void AddBranchUniqueID(std::vector<StepBase*>& steps, UInt_t ibranch);
441 
442  /// Apply the step. This is the
443  /// important function that calls Apply() in the relevant step.
444  bool ApplyStep(AnaEventC& event, ToyBoxB& box, const StepBase& step, Int_t branch=-1);
445 
446  /// Apply all steps recursively provided the first step in a threadsafe way
447  bool ApplyStepRecursive(AnaEventC& event, ToyBoxB& box, const StepBase& step, Int_t firstStepToApply);
448 
449  /// Set whether the current cut was passed, and increment the current cut
450  /// counter. Return value is the same as the input "passed" value. Calls
451  /// the other CutPassed interface if "passed" is true.
452  bool CutPassed(bool passed, Int_t branch, ToyBoxB& box);
453 
454  /// Check whetehr a cut is passed and set the relevant all_cuts_passed field if it is not passed
455  /// THis is the threadsafe version of the selection
456  bool CutPassed(bool ok, const StepBase& step, ToyBoxB& box);
457 
458 
459 protected:
460 
461  /// The index of the selection in the selection manager (for enabled selections)
462  Int_t _selEnabledIndex; //!
463 
464  // The detector FV in which the selection is performed
465  SubDetId_h _detectorFV[NMAXBRANCHES]; //!
466 
467  /// The name of the selection
468  std::string _name;
469 
470  /// the nice name of the selection
471  std::string _title;
472 
473  /// is this selection enabled ?
474  bool _enabled;
475 
476  /// The preselection accum level
478 
479  /// The cuts that were passed.
480  bool _cut_passed[NMAXBRANCHES][NMAXSTEPS]; //!
481 
482  /// The current cut level.
483  Int_t _current_cut[NMAXBRANCHES]; //!
484 
485  /// The top level steps in the trunk
486  std::vector<StepBase*> _firstSteps;
487 
488  /// Association between a branch unique ID (entry in vector) and branch alias
489  std::vector<std::string> _branchAlias;
490 
491  /// Association between a branch unique ID (entry in vector) and branch sequence
492  std::vector< std::vector<UInt_t> > _branchSequence;
493 
494  /// Number of cuts in each branch
495  std::vector<UInt_t> _nCutsInBranch;
496 
497  /// Used for statistics
498  std::vector<UInt_t > _nEventsPassed; //!
499  int _cut_passed_stats[NMAXBRANCHES][NMAXSTEPS]; //!
500 
501  /// When using the framework by a fitter (i.e. BANFF) we want to break the step sequence when a cut is not passed, that is
502  /// we are interested about events that pass all cuts. In this case _forceBreak should be true. On the other hand it should be false
503  /// in highland since we might be interested about events that didn't pass a specific cut.
505 
506  /// By default EventSummary class is created and filled when the selection is passed. But this might be necessary also for events not passing the selection
507  /// The user can force the EventSummary to be filled always.
509 
510  /// Boolean array to store valid run periods for this selection
511  /// Should use enumeration in future to set size of this
512  bool _validRunPeriods[10]; //!
513 
514  /// Array of pointers to the PreviousToyBox (for each event)
516 
517  /// This is the maximum accum level of any of the branches in all toys
519 
520  /// The ID of the EventBox to be used
521  EventBoxId_h _eventBoxId; //!
522 
523  /// Is this selection initialized ?
524  bool _initialized; //!
525 };
526 
527 
528 #endif
virtual bool IsRelevantSystematic(const AnaEventC &, const ToyBoxB &, SystId_h syst_index, Int_t branch=0) const
Is this systematic relevant for this selection.
bool _validRunPeriods[10]
bool _cut_passed[NMAXBRANCHES][NMAXSTEPS]
The cuts that were passed.
std::string _name
The name of the selection.
std::vector< StepBase * > _firstSteps
The top level steps in the trunk.
void SetTitle(const std::string &title)
Set the title of this selection, which is the "nice" version of the selection name,.
void DumpBranches() const
Dumps the list of branches.
void DumpCuts(Int_t branch=-1) const
Print out the index, name and title of each cut for a given branch (no argument for all branches) ...
Int_t GetStepNumber(const std::string &title, Int_t ID=0) const
Return the step number (starting at 0) corresponding to an step with a given title.
StepBase * GetLastStepInBranch(Int_t b0=-1, Int_t b1=-1, Int_t b2=-1, Int_t b3=-1, Int_t b4=-1, Int_t b5=-1, Int_t b6=-1, Int_t b7=-1) const
Get the last step in a given branch provided the branch sequence (individual integers) ...
void AddBranchUniqueID(std::vector< StepBase *> &steps, UInt_t ibranch)
Add a branch unique ID to all steps in that branch.
Int_t _selEnabledIndex
The index of the selection in the selection manager (for enabled selections)
bool GetForceBreak() const
bool ApplyStep(AnaEventC &event, ToyBoxB &box, const StepBase &step, Int_t branch=-1)
void Enable()
enable and disable selection
std::string GetBranchAlias(Int_t ID) const
Gets the branch alias for a given branch unique ID.
const std::string & Name() const
Return the name of this selection.
Int_t MaxAccumLevel
Definition: ToyBoxB.hxx:39
void DumpSteps(const std::string &branch="", bool onlycuts=false) const
Print out the index, name and title of each step for a given branch (no argument for all branches) ...
void CopyStep(SelectionBase &sel1, const std::string &sbranch1, UInt_t istep, Int_t b0=-1, Int_t b1=-1, Int_t b2=-1, Int_t b3=-1, Int_t b4=-1, Int_t b5=-1, Int_t b6=-1, Int_t b7=-1)
Copy a clone of the steps with number istep from branch sbranch1 in selection ssel1 to sbranch2 in se...
void CopySteps(SelectionBase &sel1, UInt_t branchID1, UInt_t first, UInt_t last, Int_t b0=-1, Int_t b1=-1, Int_t b2=-1, Int_t b3=-1, Int_t b4=-1, Int_t b5=-1, Int_t b6=-1, Int_t b7=-1)
Copy a clone of the steps in range first-last from branch sbranch1 in selection ssel1 to sbranch2 in ...
void SetPreSelectionAccumLevel(Int_t presel)
Set the pre-selection accum level.
UInt_t GetNMaxCuts() const
Return the number of steps in a given branch.
EventBoxId_h GetEventBoxId() const
Returns the Id of the EventBox to be used in this selection.
std::vector< std::string > GetStepNames(Int_t ibranch=0) const
Return all the names of the steps, in the order they were added.
EventBoxId_h _eventBoxId
The ID of the EventBox to be used.
void SetValidRunPeriods(std::string runPeriods)
virtual SampleId_h GetSampleId()
Return the sample type, needed by fitters.
StepBase * GetStepInBranch(const std::vector< UInt_t > &branch_seq, UInt_t index) const
Get step in a given branch provided the branch sequence (vector of integers) and the step index...
std::string _title
the nice name of the selection
void InitializeCutLevels()
Reset all cuts to "not passed", and set the accumulated cut level to 0.
bool PreSelectionPassed(const AnaEventC &event)
Is the preselection passed in any of the branches.
bool ApplySteps(AnaEventC &event, ToyBoxB &box, const std::string &branch, Int_t ifirst=0, Int_t ilast=NMAXSTEPS)
Apply a range of steps in a branch.
void AddSplit(UInt_t nbranches, Int_t b0=-1, Int_t b1=-1, Int_t b2=-1, Int_t b3=-1, Int_t b4=-1, Int_t b5=-1, Int_t b6=-1, Int_t b7=-1)
Add a split in the step sequence. The user should specify the number of branches in this split and th...
bool _enabled
is this selection enabled ?
Int_t GetBranchUniqueID(const std::string &name) const
Gets the branch unique ID with a given alias.
bool ApplyStepRecursive(AnaEventC &event, ToyBoxB &box, const StepBase &step, Int_t firstStepToApply)
Apply all steps recursively provided the first step in a threadsafe way.
void SetName(const std::string &name)
Set the name of this selection, which is used internally by the SelectionManager. ...
void CreateToyBoxArray(Int_t nevents)
Create the array of PreviousToyBox.
void SetEnabledIndex(Int_t index)
Set the Selection index.
virtual ToyBoxB * MakeToyBox()
Create the appropriate type of box.
std::vector< std::string > _branchAlias
Association between a branch unique ID (entry in vector) and branch alias.
virtual bool IsRelevantRecObjectForSystematicInToy(const AnaEventC &, const ToyBoxB &, AnaRecObjectC *, SystId_h syst_index, Int_t branch=0) const
Is this track relevant for a given systematic (after selection, called for each toy) ...
virtual void InitializeEvent(AnaEventC &)
Fill the EventBox with the objects needed by this selection.
void SetForceFillEventSummary(bool force)
virtual const char * GetName() const
Return the name of this selection. This overrides the TObject::GetName() interface.
Int_t GetMaxAccumCutLevelForAllToys() const
Get the maximum cut level for this event and all toys.
std::vector< UInt_t > _nCutsInBranch
Number of cuts in each branch.
std::vector< StepBase * > GetCutsInBranch(const std::string &branch) const
Get all cuts in a given branch provided the branch alias.
const ToyBoxB & GetPreviousToyBox() const
Get the ToyBox of the last processed toy (only for no MULTITHREAD)
bool Apply(AnaEventC &event, bool &redo)
Apply all steps in the selection.
std::vector< StepBase * > GetStepsInBranch(const std::vector< UInt_t > &branch_seq, UInt_t first=0, UInt_t last=NMAXSTEPS-1) const
Get all steps in a given branch provided the branch sequence (vector of integers) ...
std::vector< UInt_t > GetBranchSequence(const std::string &name) const
Get the branch sequence for a specific branch alias.
const std::string & Title() const
Return the title of this selection. A nice version of the name.
virtual bool FillEventSummary(AnaEventC &, Int_t *)
Fill the Event Summary, needed by fitters.
UInt_t GetNCuts(Int_t branch) const
Return the number of cuts in a given branch.
void RemoveStep(const std::string &title, Int_t ID=-1)
Disable step provided title and branch ID.
std::vector< UInt_t > ConvertBranch(Int_t b0=-1, Int_t b1=-1, Int_t b2=-1, Int_t b3=-1, Int_t b4=-1, Int_t b5=-1, Int_t b6=-1, Int_t b7=-1) const
Convert the branch sequence of individual integers into a vector of integers.
void Validate() const
Validates this selection.
virtual bool IsRelevantRecObjectForSystematic(const AnaEventC &, AnaRecObjectC *, SystId_h syst_index, Int_t branch=0) const
Is this track relevant for a given systematic (prior to selection, call when initializing the event...
void FinalizeEvent(const AnaEventC &event)
Delete the PreviousToyBox pointer for the last toy of the event.
virtual void DefineSteps()
Define all steps in the selection.
bool CutPassed(bool passed, Int_t branch, ToyBoxB &box)
void SetBranchAlias(Int_t ID, const std::string &name, Int_t b0=-1, Int_t b1=-1, Int_t b2=-1, Int_t b3=-1, Int_t b4=-1, Int_t b5=-1, Int_t b6=-1, Int_t b7=-1)
Set the branch alias and unique ID provided the branch sequence.
UInt_t GetNBranches() const
Return the number of branches.
virtual bool IsRelevantTrueObjectForSystematic(const AnaEventC &, AnaTrueObjectC *, SystId_h syst_index, Int_t branch=0) const
Is this true track relevant for a given systematic (prior to selection, call when initializing the ev...
std::vector< UInt_t > _nEventsPassed
Used for statistics.
void DisableStep(const std::string &title, Int_t ID=-1)
Replace a step (same structure of AddStep, but for only one step at once)
Int_t * AccumLevel
Accum level for each branch in this toy in the selection this ToyBox belongs to.
Definition: ToyBoxB.hxx:35
bool IsValidRun(int runPeriod) const
Method to see whether this selection should be applied to the given run period.
void SetDetectorFV(SubDetId_h det, Int_t ibranch=-1)
Set the detector in which the Fiducial Volume is defined.
std::vector< std::string > GetCutNames(Int_t ibranch=0) const
Return all the names of the cuts, in the order they were added.
void ReplaceStep(const std::string &old_title, Int_t ID, StepBase::TypeEnum type, const std::string &title, StepBase *step, bool cut_break=false)
Replace step provided title and branch ID of the step to replace.
std::string ConvertBranchToString(const std::vector< UInt_t > &branch, Int_t upToSplit=-1) const
Convert the branch sequence into a string.
StepBase * GetStep(const std::string &title, Int_t ID=0) const
Return an step provided the title and the Branch ID.
Int_t _maxAccumLevelForAllToys
This is the maximum accum level of any of the branches in all toys.
bool HasBranch(Int_t ibranch, const std::string &fromMethod="HasBranch") const
Check the existence of branch.
std::vector< StepBase * > GetStepsInBranchWithDummy(const std::vector< UInt_t > &branch_seq, UInt_t first=0, UInt_t last=NMAXSTEPS-1) const
Get all steps in a given branch provided the branch sequence (vector of integers) ...
bool _initialized
Is this selection initialized ?
virtual bool IsRelevantTrueObjectForSystematicInToy(const AnaEventC &, const ToyBoxB &, AnaTrueObjectC *, SystId_h syst_index, Int_t branch=0) const
Is this true track relevant for a given systematic (after selection, called for each toy) ...
Int_t GetAccumCutLevel(Int_t branch=0) const
bool GetCutPassed(Int_t icut, Int_t branch=0) const
Return whether the specified cut was passed or not.
Int_t _presel_accum_cut_level
The preselection accum level.
virtual bool CheckRedoSelection(const AnaEventC &, const ToyBoxB &PreviousToyBox, Int_t &redoFromStep)
ToyBoxB ** PreviousToyBox
Array of pointers to the PreviousToyBox (for each event)
Int_t GetMaxAccumCutLevel() const
Get the maximum cut level for this event and the last processed toy.
SubDetId_h GetDetectorFV(Int_t ibranch=0) const
Get the detector in which the Fiducial Volume is defined.
virtual void DefineDetectorFV()
Define the detector Fiducial Volume in which this selection is applied.
bool _forceFillEventSummary
Int_t _current_cut[NMAXBRANCHES]
The current cut level.
Int_t GetEnabledIndex() const
Get the Selection index.
std::vector< std::vector< UInt_t > > _branchSequence
Association between a branch unique ID (entry in vector) and branch sequence.
void AddStep(StepBase::TypeEnum type, const std::string &title, StepBase *step, bool cut_break=false)
void Initialize()
Initialize this selection: defines the steps and the detectorFV.
Int_t GetCutNumber(const std::string &title, Int_t ID=0) const
Return the cut number (starting at 0) corresponding to an step with a given title.
bool GetForceFillEventSummary() const
Returns the flag to fill the EventSummary even when the selection is not passed.
Int_t GetPreSelectionAccumLevel() const
Set the pre-selection accum level.
TypeEnum
Enumerator describing the values that _type member can take.
Definition: StepBase.hxx:22