HighLAND
AnalysisAlgorithm.cxx
1 #include "AnalysisAlgorithm.hxx"
2 
3 // By default don't allow non-exclusive selections
4 bool _allowNonExclusiveSelections = false;
5 
6 //********************************************************************
8 //********************************************************************
9 
10  if (ana){
11  _inputManager = &(ana->input());
12  _selManager = &(ana->sel());
13  _corrManager = &(ana->corr());
14  _systManager = &(ana->syst());
15  _weightManager = &(ana->eweight());
16  _variationManager = &(ana->evar());
17  _outputManager = &(ana->output());
18  _confManager = &(ana->conf());
19  _categManager = &(ana->cat());
20  _docManager = &(ana->doc());
21  }
22  else{
24  _selManager = new SelectionManager();
31  _categManager = new CategoryManager();
32  _docManager = new DocStringManager();
33  }
34 
35  _outputManager->SetDocStringManager(_docManager);
36 
37  anaUtils::_categ = &cat();
38 
39  for (UInt_t i=0;i<NMAXSELECTIONS;i++)
40  _box[i] = NULL;
41 
43 
44  // Minimum cut level to save the event. By default save everything
46 
47  // By default save events that don't pass the selection
48  _fillSuccessOnly=false;
49 
50  // By default initialize micro-trees at the beginning of each configuration
51  _initializeTrees=true;
52 
53  /// Boolean parameter to know whether nny of the methods that sets things into used analysis has been called
54  _setMethodCalled=false;
55 
56 
57  /// Version check enabled by default
58  _versionCheck = true;
59 }
60 
61 //********************************************************************
63 //********************************************************************
64 
65  if (_setMethodCalled){
66  std::cout << "ERROR. AnalysisAlgorithm::UseAnalysis() cannot be called after setting some analysis dependent parameters" << std::endl;
67  exit(0);
68  }
69 
70  _usedAnalyses.push_back(ana);
71 }
72 
73 //********************************************************************
75 //********************************************************************
76 
77  // At least one branch of one of the enabled selections should fulfill the condition
78  for (std::vector<SelectionBase*>::iterator it=sel().GetSelections().begin();it!=sel().GetSelections().end();it++){
79  if ((*it)->IsEnabled() && (*it)->GetMaxAccumCutLevel() >= GetMinAccumCutLevelToSave()) return true;
80  }
81  return false;
82 }
83 
84 //********************************************************************
85 void AnalysisAlgorithm::SetAnalysisPoint(enumAnalysisPoint point){
86 //********************************************************************
87 
88  // Set the analysis point for this algorithm
89  _analysisPoint = point;
90 
91  // Set the analysis point for all used algorithms
92  for (std::vector<AnalysisAlgorithm*>::iterator it=_usedAnalyses.begin();it!=_usedAnalyses.end();it++){
93  (*it)->SetAnalysisPoint(point);
94  }
95 }
96 
97 
98 //********************************************************************
100 //********************************************************************
101 
102  // Any of the methods that sets things into used analysis has been called
103  _setMethodCalled = true;
104 
105  _min_accum_cut_level = level;
106 
107  // Use the same accum cut level for all used analyses
108  for (std::vector<AnalysisAlgorithm*>::iterator it=_usedAnalyses.begin();it!=_usedAnalyses.end();it++){
109  (*it)->SetMinAccumCutLevelToSave(level);
110  }
111 }
112 
113 //********************************************************************
115 //********************************************************************
116 
117  // Any of the methods that sets things into used analysis has been called
118  _setMethodCalled = true;
119 
120  // Set the event into this algorithm
121  _event = event;
122 
123  // Use the same event for all used analyses
124  for (std::vector<AnalysisAlgorithm*>::iterator it=_usedAnalyses.begin();it!=_usedAnalyses.end();it++){
125  (*it)->SetEvent(_event);
126  }
127 }
128 
129 //********************************************************************
130 void AnalysisAlgorithm::SetToyBox(const ToyBoxB* box, Int_t isel){
131 //********************************************************************
132 
133  // Any of the methods that sets things into used analysis has been called
134  _setMethodCalled = true;
135 
136  // set the box into this algorithm
137  _box[isel] = box;
138 
139  // Use the same event for all used analyses
140  for (std::vector<AnalysisAlgorithm*>::iterator it=_usedAnalyses.begin();it!=_usedAnalyses.end();it++){
141  (*it)->SetToyBox(box, isel);
142  }
143 }
144 
145 //********************************************************************
146 const ToyBoxB& AnalysisAlgorithm::boxB(Int_t isel) const{
147 //********************************************************************
148 
149  if (_analysisPoint == kFillTruthTree){
150  std::cout << "ERROR. AnalysisAlgorithm::boxB(). The ToyBox cannot be accessed from FillTruthTree method !!!" << std::endl;
151  exit(1);
152  }
153 
154  if (isel==-1){
155  if (!_box[_selectedSelection]){
156  std::cout << "ERROR. AnalysisAlgorithm::boxB(). No ToyBox exist for selection 0. Probably because no selection has been added to the manager !!!" << std::endl;
157  exit(1);
158  }
159  return *_box[_selectedSelection];
160  }
161  else
162  return *_box[isel];
163 
164 }
165 
166 //********************************************************************
168 //********************************************************************
169 
170  // Any of the methods that sets things into used analysis has been called
171  _setMethodCalled = true;
172 
173  // The selected selection in this analysis
174  _selectedSelection = sel;
175 
176  // Select the selection for each of the used analysis
177  for (std::vector<AnalysisAlgorithm*>::iterator it=_usedAnalyses.begin();it!=_usedAnalyses.end();it++){
178  (*it)->SetSelectedSelection(sel);
179  }
180 }
181 
182 
183 //********************************************************************
185 //********************************************************************
186 
187  // This method Sets the appropriate ToyBox to be used when filling the Micro-trees.
188  // If any of the selections is succesfull chose the first found
189  // If not chose the one with higher accum_level
190 
191  static bool first = true;
192 
193  Int_t maxAccumLevel=-1;
194  bool found=false;
195 
196  for (std::vector<SelectionBase*>::iterator it=sel().GetSelections().begin();it!=sel().GetSelections().end();it++){
197  SelectionBase* selec = *it;
198  if (!selec->IsEnabled()) continue;
199 
200  Int_t isel = selec->GetEnabledIndex();
201 
202  // Get the ToyBox of the previous Toy
203  const ToyBoxB& box = selec->GetPreviousToyBox();
204 
205  if (first){
206  // Set the box into this and all used algorithms. Only the first time since the Box is always the same for a given selection
207  SetToyBox(&box,isel);
208  }
209 
210  if (!found){
211  if (box.SuccessfulBranch>-1){
212  SetSelectedSelection(isel);
213  found=true;
214  }
215  else if (selec->GetMaxAccumCutLevel()> maxAccumLevel){
216  SetSelectedSelection(isel);
217  maxAccumLevel = selec->GetMaxAccumCutLevel();
218  }
219  }
220  else if (box.SuccessfulBranch>-1){
221  std::cout << "AnalysisAlgorithm::FinalizeToyBase(). Selections are not mutually exclusive !!! Run/Subrun/Event/Bunch "
223  << " passing selection '" << selec->Name() << ", was also successfull in selection '" << sel().GetSelection(_selectedSelection)->Name() << "'."
224  << " Results for first selection being passed will be saved in micro-trees for this event. " << std::endl;
225  if (!_allowNonExclusiveSelections){
226  std::cout << "Non exclusive selections are in general problematic. THE PROGRAM WILL STOP NOW !!!!" << std::endl;
227  std::cout << "Set '_allowNonExclusiveSelections=true' at the begining of highlandTools/vXrY/src/AnalysisAlgorithm.cxx to allow non-exclusive selections" << std::endl;
228  exit(1);
229  }
230  }
231 
232  }
233  first = false;
234 }
235 
236 
EventVariationManager * _variationManager
EventVariation Manager.
void SetSelectedSelection(Int_t sel)
Select one of the selections.
void SetMinAccumCutLevelToSave(Int_t level)
Set the minimum accumulated cut level to save an event into the micro-tree.
const std::string & Name() const
Return the name of this selection.
ConfigurationManager * _confManager
Configuration Manager.
bool _setMethodCalled
Boolean parameter to know whether nny of the methods that sets things into used analysis has been cal...
void SetToyBox(const ToyBoxB *box, Int_t isel=0)
Set the current box into the algorithm and all used algorithms. This is useful when one Analysis uses...
Int_t _selectedSelection
The selected selection.
const ToyBoxB & GetPreviousToyBox(const AnaEventC &event) const
Get the ToyBox of the last processed toy for a particular event.
const ToyBoxB * _box[NMAXSELECTIONS]
The analysis box.
void SetEvent(AnaEventC *event)
Set the current event into the algorithm and all used algorithms.
std::vector< SelectionBase * > & GetSelections()
Return the map of selections.
OutputManager * _outputManager
Output Manager.
AnaEventC * _event
The current event.
HighlandInputManager * _inputManager
Input Manager: access to the current Event.
The maximum number of systematics that is supported.
AnalysisAlgorithm(AnalysisAlgorithm *ana=NULL)
bool _fillSuccessOnly
Fill trees and process weight systematics only when any of the branches is succesful.
CorrectionManager * _corrManager
Correction Manager.
Int_t SuccessfulBranch
The branch that is successful for this toy in the selection this ToyBox belongs to.
Definition: ToyBoxB.hxx:46
SystematicManager * _systManager
Systematics Manager.
void SetAnalysisPoint(enumAnalysisPoint point)
Set the point of the analysis at which AnalysisLoop is.
Int_t _min_accum_cut_level
the minimum accumulated cut level to save an event into the micro-tree
EventWeightManager * _weightManager
EventWeight Manager.
std::vector< AnalysisAlgorithm * > _usedAnalyses
The Vector of used analysis.
bool CheckAccumLevelToSave()
Check if the condition is fulfilled for at least one branch.
void UseAnalysis(AnalysisAlgorithm *ana)
Used a given analysis.
Int_t GetMinAccumCutLevelToSave()
Get the minimum accumulated cut level to save an event into the micro-tree.
SelectionBase * GetSelection(const std::string &name, bool print_error=true)
Return the selection that was registered with the given name. NULL if it does not exist...
void FinalizeToyBase()
[AnalysisAlgorithm_mandatory]
virtual std::string GetEventInfoString() const
User-frienly method to get event info (run,subrun,etc)
bool _initializeTrees
Initialize trees at the beginning of each configuration.
Int_t GetMaxAccumCutLevel() const
Get the maximum cut level for this event and the last processed toy.
Int_t GetEnabledIndex() const
Get the Selection index.