HighLAND
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
AnalysisLoop Class Reference

#include <AnalysisLoop.hxx>

Public Member Functions

 AnalysisLoop (AnalysisAlgorithm *ana, int argc, char *argv[])
 Constructor which parses and sanity checks the command line options.
 
void Loop (int nmax=0, int imin=0)
 
void Execute ()
 
void SetEvent (AnaEventC *event)
 

Protected Member Functions

bool Initialize ()
 
void Finalize ()
 
bool InitializeSpill ()
 
void FinalizeSpill ()
 
void InitializeBunch ()
 
void FinalizeBunch ()
 
void InitializeConfiguration ()
 
bool FinalizeConfiguration ()
 
void InitializeToy ()
 
bool FinalizeToy ()
 Called after each toy experiment is complete.
 
void InitializeSelection (const SelectionBase &sel)
 
void FinalizeSelection (const SelectionBase &sel)
 
bool Process (SelectionBase &selec)
 
void DefineCorrections ()
 Define the corrections to be applied.
 
void DefineConfigurations ()
 Define the configurations (micro-trees) and which systematics should be applied in each "configuration".
 
void DefineMicroTrees ()
 Define the variables that should be stored in the output micro-trees.
 
void DefineTruthTree ()
 Define the "truth" tree. See FillTruthTree().
 
void FillCategories ()
 
void FillMicroTrees ()
 Fill the standard configurations trees: More...
 
void FillToyVarsInMicroTrees ()
 Fill the standard configurations only toy-dependent variables.
 
void PrintUsage (const std::string &programName)
 
More...
 
AnalysisAlgorithmana ()
 
void FillHeaderTree ()
 Fill the "header" tree, which includes POT information etc.
 
void FillConfigTree ()
 Fill the "config" tree, which includes details of the analysis cuts etc.
 

Protected Attributes

Long64_t _entry
 Fill the "truth" tree. More...
 
std::string _inputFileName
 Path to the input file, as defined by the user.
 
std::string _inputFileType
 
std::string _outputFileName
 What to call the output file, as defined by the user.
 
std::string _inputSkimFileName
 Path to the file with the list of events to skim, as defined by the user.
 
bool _enableTruthTree
 Whether the "truth" tree should be filled. See FillTruthTree().
 
bool _cosmicMode
 
bool _versionCheck
 Check version compatibility between nd280AnalysisTools compilation and oaAnalysis file.
 
bool _fillTrees
 Whether to fill the trees and create an output file or not.
 
MemoryUsage _memory
 Tools for tracking memory usage.
 
AnaEventC_event
 

Detailed Description

This class is a base class for analyses.

It specifies the interface that analyses should conform to, although user analyses should inherit from baseAnalysis, not AnalysisLoop directly. baseAnalysis implements all the required functions, so the user doesn't have to implement all the functions themselves.

The class also contains the low-level functionality for running the analysis, including the all-important Loop function.

Definition at line 17 of file AnalysisLoop.hxx.

Member Function Documentation

§ Execute()

void AnalysisLoop::Execute ( )

Simply calls Loop with the appropriate parameters as read from the command line.

Definition at line 1333 of file AnalysisLoop.cxx.

1333  {
1334 //********************************************************************
1335  Loop(_entry_nmax, _entry_imin);
1336 }
void Loop(int nmax=0, int imin=0)

§ FillCategories()

void AnalysisLoop::FillCategories ( )
protected

Fill the track categories for color drawing. There is a definition in baseAnalysis, and the user can specify their own if they have defined their own custom categories.

§ FillMicroTrees()

void AnalysisLoop::FillMicroTrees ( )
protected

Fill the standard configurations trees:

Fill the truth tree. The truth tree is designed to contain information about all true signal events, including those that the analysis didn't select as signal.

The derived version should fill the relevant variables, and return whether the tree should be written or not. The derived function is only called once per spill!

Definition at line 1173 of file AnalysisLoop.cxx.

1173  {
1174 //********************************************************************
1175 
1176  // Fill the entry number in the input tree
1177  ana().output().FillVar(AnalysisAlgorithm::entry, (int) _entry);
1178 
1179  // Fill the tree for the current configuration provided the true codes for color drawing
1180  std::map< std::string, TrackCategoryDefinition* >::iterator it;
1181  Int_t categ_index = AnalysisAlgorithm::firstCategory;
1182  for (it=ana().cat().GetCategories().begin();it!=ana().cat().GetCategories().end();it++, categ_index++ ){
1183  std::string categ_name = it->first;
1184  TrackCategoryDefinition& categ = *(it->second);
1185  if (categ.IsMultiType()){
1186  for (unsigned int i=0;i<categ.GetNTypes();i++)
1187  ana().output().FillVectorVar(categ_index, (int)ana().cat().CheckCategoryType(categ_name,i),i);
1188  }
1189  else ana().output().FillVar(categ_index, ana().cat().GetCode(categ_name));
1190  }
1191 
1192  // reference toy
1193  ana().output().FillVar(AnalysisAlgorithm::toy_ref, ana().conf().GetCurrentConfiguration()->GetRefToyIndex());
1194 
1195  // Call the derive classes functions
1196  ana().SetAnalysisPoint(AnalysisAlgorithm::kFillMicroTrees);
1197  ana().FillMicroTrees();
1198 
1199  // Call the base class function and actually fills the tree
1200  // (fill the toy configuration variables: toy_index, toy_weight)
1201  ana().output().FillMicroTrees();
1202 }
bool IsMultiType()
Is this a multi-type category ? (Can several types coexist?)
void FillVectorVar(Int_t index, Float_t var, Int_t indx=-1)
Fill a vector variable.
std::map< std::string, TrackCategoryDefinition * > & GetCategories()
Get the map of track categories.
void SetAnalysisPoint(enumAnalysisPoint point)
Set the point of the analysis at which AnalysisLoop is.
void FillVar(Int_t index, Float_t var)
Fill a single variable.
unsigned int GetNTypes()
Number of types defined for this category.
Long64_t _entry
Fill the "truth" tree.

§ Finalize()

void AnalysisLoop::Finalize ( )
protected

Called after all processing is complete. Cleans up, then writes to and closes the output file.

Definition at line 500 of file AnalysisLoop.cxx.

500  {
501 //********************************************************************
502 
503  // Finalize the derived class
504  ana().SetAnalysisPoint(AnalysisAlgorithm::kFinalize);
505  ana().Finalize();
506 
507  // Create and fill the header tree with a single entry
508  if (_fillTrees) {
509  FillHeaderTree();
510 
511  // Save all trees after looping over all events
512  std::vector< TTree* >::iterator it;
513  for (it=ana().output().GetTrees().begin();it!=ana().output().GetTrees().end();it++){
514  (*it)->AutoSave("SaveSelf");
515  }
516 
517  // Write out memory usage, if needed.
518  _memory.Write();
519 
520  // Close the output file
521  ana().output().CloseOutputFile();
522  }
523 }
MemoryUsage _memory
Tools for tracking memory usage.
void FillHeaderTree()
Fill the "header" tree, which includes POT information etc.
void SetAnalysisPoint(enumAnalysisPoint point)
Set the point of the analysis at which AnalysisLoop is.
virtual void Finalize()
[AnalysisAlgorithm_optional]
bool _fillTrees
Whether to fill the trees and create an output file or not.
std::vector< TTree *> & GetTrees()
Returns the map of trees.
Definition: TreeManager.hxx:25
void CloseOutputFile()
close the output file
void Write()
Write histograms of the memory usage to the output file.
Definition: MemoryUsage.cxx:27

§ FinalizeBunch()

void AnalysisLoop::FinalizeBunch ( )
protected

Called after each bunch is finished, simply calling the user's derived version.

Definition at line 449 of file AnalysisLoop.cxx.

449  {
450 //********************************************************************
451 
452  // The PreviousToyBox must be Reset after processing one event (all toys)
453  ana().sel().FinalizeEvent(*_event);
454 
455  // Derived classes
456  ana().SetAnalysisPoint(AnalysisAlgorithm::kFinalizeBunch);
457  ana().FinalizeBunch();
458 
459  // Delete the event
460  delete _event;
461 }
void SetAnalysisPoint(enumAnalysisPoint point)
Set the point of the analysis at which AnalysisLoop is.
void FinalizeEvent(const AnaEventC &event)
Delete the PreviousToyBox pointer for the last toy of the event for all enabled selections.

§ FinalizeConfiguration()

bool AnalysisLoop::FinalizeConfiguration ( )
protected

Fill the tree for this bunch, including the "truth" tree if it is enabled. The derived version should fill any variabled in the micro-tree that don't depend on the exact analysis.

Definition at line 409 of file AnalysisLoop.cxx.

409  {
410 //********************************************************************
411 
412  // Delete the array for systematics weights. Will create a new one in InitializeConfiguration (TODO)
413  if (_weightSyst) delete [] _weightSyst;
414  _weightSyst = NULL;
415 
416  // Delete the SystBox for the current event
417  if (_event->GetIsMC() && ana().evar().GetNEnabledEventVariations()>0)
418  ana().evar().FinalizeEvent(*_event);
419 
420  // Delete the SystBox for the current event
421  if (_event->GetIsMC() && ana().eweight().GetNEnabledEventWeights()>0)
422  ana().eweight().FinalizeEvent(*_event);
423 
424  // Finalize the configuration for the User AnalysisAlgorithm
425  ana().SetAnalysisPoint(AnalysisAlgorithm::kFinalizeConfiguration);
426  if (!ana().FinalizeConfiguration()) return false;
427 
428  // When requested fill the tree only for events that pass the selection at least for one of the toys
429  // conf_passed is true when at least one of the toys passes the selection
430  if (!_fillTrees || (!_conf_passed && ana().GetFillSuccessOnly())) return true;
431 
432  // Only fill the tree for events that pass a given cut
433  if (!ana().CheckAccumLevelToSave()) return false;
434 
435  // Reset the categories for the current track
436  ana().cat().ResetCurrentCategories();
437 
438  // Fill categories for color drawing for the current track
439  ana().SetAnalysisPoint(AnalysisAlgorithm::kFillCategories);
440  ana().FillCategories();
441 
442  // Fill all micro-trees (main trees for analysis)
443  FillMicroTrees();
444 
445  return true;
446 }
UInt_t GetNEnabledEventWeights()
Returns the number of enabled EventWeights.
void FinalizeEvent(AnaEventC &event)
Delete the SystBox for all EventWeights.
UInt_t GetNEnabledEventVariations()
Returns the number of enabled EventVariations.
void SetAnalysisPoint(enumAnalysisPoint point)
Set the point of the analysis at which AnalysisLoop is.
void ResetCurrentCategories()
Reset the properties of the current track.
bool _fillTrees
Whether to fill the trees and create an output file or not.
void FinalizeEvent(AnaEventC &event)
Delete the SystBox for all EventVariations.
void FillMicroTrees()
Fill the standard configurations trees:
bool FinalizeConfiguration()
virtual bool GetIsMC() const =0
Return whether this event is from Monte Carlo or not.

§ FinalizeSelection()

void AnalysisLoop::FinalizeSelection ( const SelectionBase sel)
protected

Compute the weight for this selection by applying the systematic weights. Only for MC when any of the weight systematics is enabled,

Definition at line 357 of file AnalysisLoop.cxx.

357  {
358 //********************************************************************
359 
360  /// Compute the weight for this selection by applying the systematic weights. Only for MC when any of the weight systematics is enabled,
361  // and when the selection was passed. TODO: now that this is not only a systematic it could be also used for data
362  if (_toy_passed && _event->GetIsMC() && ana().eweight().GetNEnabledEventWeights()>0){
363  // Get the current Toy Experiment
364  ToyExperiment* toy = ana().conf().GetCurrentConfiguration()->GetToyMaker().GetToyExperiment(ana().conf().GetToyIndex());
365  // Apply the relevant weight systematics for the current selection. Internally loops over branches in the selection and compute the weights only
366  // for the succesfull branches
367  ana().eweight().ComputeEventWeights(selec,*toy, *_event, selec.GetPreviousToyBox(*_event), _weightSyst);
368  }
369 
370  // finalize selection for the user analysis. TODO: currently not used by any analysis.
371  ana().SetAnalysisPoint(AnalysisAlgorithm::kFinalizeSelection);
372  ana().FinalizeSelection(selec);
373 }
UInt_t GetNEnabledEventWeights()
Returns the number of enabled EventWeights.
ConfigurationBase * GetCurrentConfiguration() const
return the current configuration
ToyMaker & GetToyMaker()
Returns the ToyMaker.
void SetAnalysisPoint(enumAnalysisPoint point)
Set the point of the analysis at which AnalysisLoop is.
ToyExperiment * GetToyExperiment(UInt_t index)
Returns the Toy experiment with a given index.
Definition: ToyMaker.hxx:35
virtual bool GetIsMC() const =0
Return whether this event is from Monte Carlo or not.
Weight_h ComputeEventWeights(const ToyExperiment &toy, const AnaEventC &event, const ToyBoxB &ToyBox)
Compute all eventWeights. Returns the total event normalization weight.

§ FinalizeSpill()

void AnalysisLoop::FinalizeSpill ( )
protected

Called after each spill is finished. Calls the user's derived version before deleting the current active Spill in the InputManager.

Definition at line 464 of file AnalysisLoop.cxx.

464  {
465 //********************************************************************
466 
467  if (_fillTrees){
468 
469  // Fill only the truth tree
470  ana().output().SetFillSingleTree(OutputManager::truth);
471  ana().output().SetCurrentTree(OutputManager::truth);
472 
473  // call the derived class function
474  ana().SetAnalysisPoint(AnalysisAlgorithm::kFillTruthTree);
475  ana().FillTruthTree();
476 
477  // Fill all trees
478  ana().output().SetFillAllTrees();
479 
480  // Finalize the derived class
481  ana().SetAnalysisPoint(AnalysisAlgorithm::kFinalizeSpill);
482  ana().FinalizeSpill();
483 
484  _memory.LogMemory();
485 
486  // Save all trees every NENTRIES_TREESAVE
487  if (_entry%NENTRIES_TREESAVE == 0){
488  std::vector< TTree* >::iterator it;
489  for (it=ana().output().GetTrees().begin();it!=ana().output().GetTrees().end();it++){
490  (*it)->AutoSave("SaveSelf");
491  }
492  }
493  }
494  // delete Spill, CorrectedSpill and RawSpill
495  ana().input().DeleteSpill();
496 
497 }
MemoryUsage _memory
Tools for tracking memory usage.
void LogMemory()
Definition: MemoryUsage.cxx:18
void DeleteSpill()
clean up the remaining pointers to the spills.
void SetCurrentTree(Int_t index)
Sets the current tree provided the index.
Definition: TreeManager.hxx:58
void SetAnalysisPoint(enumAnalysisPoint point)
Set the point of the analysis at which AnalysisLoop is.
bool _fillTrees
Whether to fill the trees and create an output file or not.
std::vector< TTree *> & GetTrees()
Returns the map of trees.
Definition: TreeManager.hxx:25
Long64_t _entry
Fill the "truth" tree.

§ Initialize()

bool AnalysisLoop::Initialize ( )
protected

Initialize the entire analysis. Calls the Initialize() function in the user's derived class as part of the initialization.

Definition at line 152 of file AnalysisLoop.cxx.

152  {
153 //********************************************************************
154 
155  // Define the InputConverters. This must be called before the InputManager is initialized
156  ana().SetAnalysisPoint(AnalysisAlgorithm::kDefineInputConverters);
157  ana().DefineInputConverters();
158 
159  // Define Productions
160  ana().SetAnalysisPoint(AnalysisAlgorithm::kDefineProductions);
161  ana().DefineProductions();
162 
163  // Set the skim file name
164  anaUtils::skimFileName = _inputSkimFileName;
165 
166  // Initialize the InputManager by specifying the input type and the input file
167  if (!ana().input().Initialize(_inputFileName,_inputFileType, _cosmicMode)) return false;
168 
169  // Tell the AnalysisAlgorithm to perform version checking to make sure the sofware version and the input file match each other
171 
172  // Initialize the User Analysis Algorithm. It can overwride the production via parameters file in baseAnalysis
173  ana().SetAnalysisPoint(AnalysisAlgorithm::kInitialize);
174  if (!ana().Initialize()) return false;
175 
176  // This will take care of data/MC differences in detector volumes definitions
177  // Should be applied after the version has been defined
178  // TODO. Moved temporarily to baseAnalysis.cxx to avoid dependency on psycheND280Utils
179  // ND::hgman().InitializeGeometry(ana().input().GetIsMC());
180 
181  // Initialise the Output Manager.
182  ana().output().Initialize();
183 
184  // Open the output file
185  if (_fillTrees)
186  if (!ana().output().OpenOutputFile(_outputFileName)) return false;
187 
188  // if (ana().input().GetChain() == 0) return;
189 
190  // Define the Corrections
192 
193  // Define the selection (s)
194  ana().SetAnalysisPoint(AnalysisAlgorithm::kDefineSelections);
195  ana().DefineSelections();
196 
197  // Initialize the Selections (create the ToyBox)
198  ana().sel().CreateToyBoxArray(_entry_nmax);
199 
200  // Define the Systematics
201  ana().SetAnalysisPoint(AnalysisAlgorithm::kDefineSystematics);
202  ana().DefineSystematics();
203 
204  // Define the configurations
206 
207  // Define the micro tree variables
208  if (_fillTrees)
210 
211  // Define the "truth tree" variables
213  DefineTruthTree();
214 
215  // Create and fill the "config" tree with a single entry
216  if (_fillTrees)
217  FillConfigTree();
218 
219  // Fill allways the event summary even when the selection is not passed
220  ana().sel().SetForceFillEventSummary(true);
221 
222  return true;
223 }
void DefineCorrections()
Define the corrections to be applied.
void CreateToyBoxArray(Int_t nevents)
Create the array of PreviousToyBox for all enabled selections.
void DefineMicroTrees()
Define the variables that should be stored in the output micro-trees.
std::string _inputFileType
bool _versionCheck
Check version compatibility between nd280AnalysisTools compilation and oaAnalysis file...
void SetAnalysisPoint(enumAnalysisPoint point)
Set the point of the analysis at which AnalysisLoop is.
std::string _inputFileName
Path to the input file, as defined by the user.
void DefineTruthTree()
Define the "truth" tree. See FillTruthTree().
void SetForceFillEventSummary(bool force)
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 SetVersionCheck(bool check)
Set version checking.
bool _enableTruthTree
Whether the "truth" tree should be filled. See FillTruthTree().

§ InitializeBunch()

void AnalysisLoop::InitializeBunch ( )
protected

Initialize each bunch of each spill, simply calling the user's derived version.

Definition at line 273 of file AnalysisLoop.cxx.

273  {
274 //********************************************************************
275 
276  // Create the event from the spill and the current bunch (needed by psyche packages)
277  _event = ana().MakeEvent();
278  ana().SetEvent(_event);
279 
280  // Create and fill the EventBox for the current event
281  ana().sel().InitializeEvent(*_event);
282 
283  // Initialize the Bunch in the User Analysis Algorithm
284  ana().SetAnalysisPoint(AnalysisAlgorithm::kInitializeBunch);
285  ana().InitializeBunch();
286 }
virtual AnaEventC * MakeEvent()=0
[AnalysisAlgorithm_optional]
void SetEvent(AnaEventC *event)
Set the current event into the algorithm and all used algorithms.
void SetAnalysisPoint(enumAnalysisPoint point)
Set the point of the analysis at which AnalysisLoop is.
void InitializeEvent(AnaEventC &event)
Initialize the EventBox for all enabled selections.

§ InitializeConfiguration()

void AnalysisLoop::InitializeConfiguration ( )
protected

Initialize each configuration for each bunch. The current active configuration should already have been changed by Loop().

Definition at line 289 of file AnalysisLoop.cxx.

289  {
290 //********************************************************************
291 
292  // Initialize the tree associated to the current configuration (put all variables to the default value)
293  if (_fillTrees)
294  ana().output().InitializeTree(ana().output().GetCurrentTree(), ana().GetInitializeTrees());
295 
296  if (ana().evar().HasEventVariations()){
297  // Enable the appropriate EventVariations for this configuration
298  ana().evar().DisableAllEventVariations();
299  ana().evar().EnableEventVariations(ana().conf().GetEnabledEventVariations());
300 
301  // Create the SystBox array (only the first time it is called for each EventVariation)
302  ana().evar().Initialize(_entry_nmax);
303 
304  // Initialize The SystBox for EventVariations
305  ana().evar().InitializeEvent(ana().sel(),*_event);
306  }
307 
308  if (ana().eweight().HasEventWeights()){
309  // Enable the appropriate EventWeights for this configuration
310  ana().eweight().DisableAllEventWeights();
311  ana().eweight().EnableEventWeights(ana().conf().GetEnabledEventWeights());
312 
313  // Create an array to store the systematics weights. (TODO. Is it faster to just resize the existing array ?)
314  _nWeightSyst= ana().eweight().GetNEnabledEventWeights();
315  anaUtils::CreateArray(_weightSyst, _nWeightSyst);
316 
317  // Create the SystBox array (only the first time it is called for each EventWeight)
318  ana().eweight().Initialize(ana().sel(),_entry_nmax);
319 
320  // Initialize The SystBox for variation systematics
321  ana().eweight().InitializeEvent(ana().sel(),*_event);
322  }
323 
324  // Initialize the Configuration in the User Analysis Algorithm
325  ana().InitializeConfiguration();
326 }
UInt_t GetNEnabledEventWeights()
Returns the number of enabled EventWeights.
void InitializeEvent(SelectionManager &sel, AnaEventC &event)
Fill the SystBox for the enabled EventWeights.
void DisableAllEventVariations()
Disable all eventVariations.
void InitializeEvent(SelectionManager &sel, AnaEventC &event)
Fill the SystBox for the enabled EventVariations.
void DisableAllEventWeights()
Disable all eventWeights.
bool _fillTrees
Whether to fill the trees and create an output file or not.
void EnableEventVariations(const std::vector< Int_t > &systs)
Enable the EventVariations registered with the given indices.
void EnableEventWeights(const std::vector< Int_t > &systs)
Enable the EventWeights registered with the given indices.

§ InitializeSpill()

bool AnalysisLoop::InitializeSpill ( )
protected

Initialize each spill, including reading it from the input file, and applying any corrections specified by the user. Calls the user's derived version after applying the corrections.

Definition at line 226 of file AnalysisLoop.cxx.

226  {
227 //********************************************************************
228 
229  // Initialize the OutputManager (TODO)
230  if (_fillTrees)
231  ana().output().InitializeEntry();
232 
233  // Initialize the truth tree (which does not belong to any configuration)
234  if (_fillTrees)
235  ana().output().InitializeTree(OutputManager::truth);
236 
237  // To compute the entry increment
238  Int_t entry0 = _entry;
239 
240  // Fill the spill structure for the current spill from the input tree
241  bool spillOK = ana().input().LoadSpill(_entry);
242 
243  // To compute the entry increment
244  Int_t entry1 = _entry;
245 
246  // Increment the number of entries run so far
247  _entry_count += entry1-entry0;
248 
249  // Dump info about number of entries run
250  if (_entry_count%1000==0 || _entry_count == _entry_nmax)
251  std::cout << "entry: " << _entry_count << " of " << _entry_nmax << " (" << (100*_entry_count/_entry_nmax) << "%) --> " << _entry << std::endl;
252 
253  // return if the read spill is not OK
254  if (!spillOK) return false;
255 
256  // Apply Corrections. This will affect all configurations
257  ana().corr().ApplyCorrections(ana().input().GetCorrectedSpill());
258 
259  // Create a clone of the Corrected Spill
260  ana().input().MakeFinalSpill();
261 
262  // Record the POT for this spill
263  ana().input().IncrementPOTBySpill();
264 
265  // initialize the spill in the User Analysis Algorithm
266  ana().SetAnalysisPoint(AnalysisAlgorithm::kInitializeSpill);
267  if (!ana().InitializeSpill()) return false;
268 
269  return true;
270 }
void IncrementPOTBySpill()
void SetAnalysisPoint(enumAnalysisPoint point)
Set the point of the analysis at which AnalysisLoop is.
void ApplyCorrections(AnaSpillC &spill)
Apply all corrections.
bool _fillTrees
Whether to fill the trees and create an output file or not.
void MakeFinalSpill()
Creates a clone of the corrected Spill. This must be done after applying corrections.
bool LoadSpill(Long64_t &entry)
Long64_t _entry
Fill the "truth" tree.
bool InitializeSpill()

§ InitializeToy()

void AnalysisLoop::InitializeToy ( )
protected

Initialize each toy experiment for each configuration, including applying any systematic variations. The user's derived version is called after variations have been applied.

Definition at line 329 of file AnalysisLoop.cxx.

329  {
330 //********************************************************************
331 
332  // Apply variation systematics. Only for MC. TODO: now that this is not only a systematic it could be also used for data
333  if (_event->GetIsMC() && ana().evar().GetNEnabledEventVariations()>0){
334 
335  // Get the current Toy Experiment
336  ToyExperiment* toy = ana().conf().GetCurrentConfiguration()->GetToyMaker().GetToyExperiment(ana().conf().GetToyIndex());
337 
338  // Apply systematic variations for systematic error propagation
339  ana().evar().ApplyEventVariations(*toy, *_event);
340  }
341 
342  // Initialize this toy experiment for the user Analysis Algorithm
343  ana().SetAnalysisPoint(AnalysisAlgorithm::kInitializeToy);
344  ana().InitializeToy();
345 }
ConfigurationBase * GetCurrentConfiguration() const
return the current configuration
ToyMaker & GetToyMaker()
Returns the ToyMaker.
UInt_t GetNEnabledEventVariations()
Returns the number of enabled EventVariations.
void SetAnalysisPoint(enumAnalysisPoint point)
Set the point of the analysis at which AnalysisLoop is.
void ApplyEventVariations(const ToyExperiment &toy, AnaEventC &event)
Apply all EventVariations.
ToyExperiment * GetToyExperiment(UInt_t index)
Returns the Toy experiment with a given index.
Definition: ToyMaker.hxx:35
virtual bool GetIsMC() const =0
Return whether this event is from Monte Carlo or not.

§ Loop()

void AnalysisLoop::Loop ( int  nmax = 0,
int  imin = 0 
)

This is the main looping function that controls the analysis. It initializes the analysis, then loops over

  • Spills in the input file
    • Bunches in each spill
      • Configurations for each bunch (which sets of systematics to apply)
        • toy experiments for each configuration (the MC throws for each systematic)

Definition at line 957 of file AnalysisLoop.cxx.

957  {
958 //********************************************************************
959 
960  if (!Initialize()) return;
961 
962  // Get the number of entries in the tree
963  Long64_t nentries = ana().input().GetEntries();
964 
965  if (imin>nentries){
966  std::cout << "AnalysisLoop::Loop(). input tree has " << nentries << " entries. You cannot start from entry " << imin << std::endl;
967  return;
968  }
969 
970  // Compute the number of entries to be run
971  if (nmax==0 || imin+nmax>nentries) _entry_nmax = nentries-imin;
972  else _entry_nmax = nmax;
973 
974  // Compute the number of the last entry to be run
975  _entry_imax = _entry_imin+_entry_nmax;
976 
977  if (ana().input().InputIsFlatTree())
978  std::cout << "AnalysisLoop::Loop(). input tree has " << nentries << " entries for " << ana().input().header().GetPOT() << " good POT" << std::endl;
979  else
980  std::cout << "AnalysisLoop::Loop(). input tree has " << nentries << " entries (POT counted on the fly)" << std::endl;
981  std::cout << "AnalysisLoop::Loop(). loop over " << _entry_nmax << " entries from entry number "<< _entry_imin << std::endl;
982 
983  double delta_t[20]={0};
984 
985  //--------- Loop over entries in the tree ----------------------------------
986  _entry=_entry_imin;
987  while (_entry<_entry_imax) {
988 
989  // Initialize clock
990  timeval tim;
991  gettimeofday(&tim, NULL);
992  double t0=tim.tv_sec+(tim.tv_usec/1000000.0);
993 
994  // Fills the full Spill structure (it could imply reading several entries in input tree)
995  bool spillOK = InitializeSpill();
996 
997  // Break the loop (at the moment only for skimmed events, when the last interesting event is processed)
998  if (anaUtils::breakLoop) break;
999 
1000  // go to the next spill if this one is not OK
1001  if (!spillOK) continue;
1002 
1003  gettimeofday(&tim, NULL);
1004  double t1=tim.tv_sec+(tim.tv_usec/1000000.0);
1005 
1006  delta_t[0] += t1-t0;
1007 
1008  //---- For each Spill loop over Bunches ----
1009  for (unsigned int ibunch=0;ibunch<ana().input().GetSpill().Bunches.size();ibunch++){
1010  gettimeofday(&tim, NULL);
1011  double t2=tim.tv_sec+(tim.tv_usec/1000000.0);
1012 
1013  ana().input().SetCurrentBunch(ibunch);
1014  InitializeBunch();
1015 
1016  gettimeofday(&tim, NULL);
1017  double t3=tim.tv_sec+(tim.tv_usec/1000000.0);
1018 
1019 
1020  delta_t[1] += t3-t2;
1021 
1022 
1023  //---- For each bunch loop over configurations ----
1024  for (std::vector<ConfigurationBase*>::iterator it= ana().conf().GetConfigurations().begin();it!=ana().conf().GetConfigurations().end();it++){
1025  ConfigurationBase* conf = *it;
1026 
1027  gettimeofday(&tim, NULL);
1028  double t4=tim.tv_sec+(tim.tv_usec/1000000.0);
1029 
1030  if (!conf->IsEnabled()) continue;
1031  ana().conf().SetCurrentConfigurationIndex(conf->GetIndex());
1032  ana().output().SetCurrentTree(conf->GetTreeIndex());
1034 
1035  gettimeofday(&tim, NULL);
1036  double t5=tim.tv_sec+(tim.tv_usec/1000000.0);
1037 
1038  delta_t[2] += t5-t4;
1039 
1040  _conf_passed=false;
1041 
1042  //---- For each configuration loop over toys --------
1043  for (int n=0;n<conf->GetNToys();n++){
1044 
1045  gettimeofday(&tim, NULL);
1046  double t6=tim.tv_sec+(tim.tv_usec/1000000.0);
1047 
1048  ana().conf().SetToyIndex(n);
1049  ana().output().SetToyIndex(n);
1050  InitializeToy();
1051 
1052  gettimeofday(&tim, NULL);
1053  double t7=tim.tv_sec+(tim.tv_usec/1000000.0);
1054 
1055  delta_t[3] += t7-t6;
1056 
1057  //---- For each toy loop over selections --------
1058  for (std::vector<SelectionBase*>::iterator sit= ana().sel().GetSelections().begin();sit!=ana().sel().GetSelections().end();sit++){
1059  SelectionBase& selec = **sit;
1060  if (!selec.IsEnabled()) continue;
1061  gettimeofday(&tim, NULL);
1062  double t8=tim.tv_sec+(tim.tv_usec/1000000.0);
1063 
1064  InitializeSelection(selec);
1065 
1066  gettimeofday(&tim, NULL);
1067  double t9=tim.tv_sec+(tim.tv_usec/1000000.0);
1068 
1069  delta_t[4] += t9-t8;
1070 
1071  _toy_passed = Process(selec);
1072 
1073  gettimeofday(&tim, NULL);
1074  double t10=tim.tv_sec+(tim.tv_usec/1000000.0);
1075 
1076  delta_t[5] += t10-t9;
1077 
1078  FinalizeSelection(selec);
1079 
1080  gettimeofday(&tim, NULL);
1081  double t11=tim.tv_sec+(tim.tv_usec/1000000.0);
1082 
1083 
1084  delta_t[6] += t11-t10;
1085  if (_toy_passed) _conf_passed=true;
1086  }
1087 
1088  gettimeofday(&tim, NULL);
1089  double t12=tim.tv_sec+(tim.tv_usec/1000000.0);
1090 
1091  if (!FinalizeToy()) break;
1092 
1093  gettimeofday(&tim, NULL);
1094  double t13=tim.tv_sec+(tim.tv_usec/1000000.0);
1095 
1096  delta_t[7] += t13-t12;
1097 
1098  }
1099 
1100  gettimeofday(&tim, NULL);
1101  double t14=tim.tv_sec+(tim.tv_usec/1000000.0);
1102 
1104 
1105  gettimeofday(&tim, NULL);
1106  double t15=tim.tv_sec+(tim.tv_usec/1000000.0);
1107 
1108  delta_t[8] += t15-t14;
1109  }
1110  gettimeofday(&tim, NULL);
1111  double t16=tim.tv_sec+(tim.tv_usec/1000000.0);
1112 
1113  FinalizeBunch();
1114 
1115  gettimeofday(&tim, NULL);
1116  double t17=tim.tv_sec+(tim.tv_usec/1000000.0);
1117 
1118  delta_t[9] += t17-t16;
1119  }
1120  gettimeofday(&tim, NULL);
1121  double t18=tim.tv_sec+(tim.tv_usec/1000000.0);
1122  FinalizeSpill();
1123  gettimeofday(&tim, NULL);
1124  double t19=tim.tv_sec+(tim.tv_usec/1000000.0);
1125 
1126  delta_t[10] += t19-t18;
1127 
1128  delta_t[11] += t19-t0;
1129  }
1130 
1131  for (Int_t i=0;i<11;i++)
1132  delta_t[12] += delta_t[i];
1133 
1134 
1135  std::cout << "time profile --------------" << std::endl;
1136  std::cout << "Ini Spill: " << delta_t[0] << std::endl;
1137  std::cout << "Ini Bunch: " << delta_t[1] << std::endl;
1138  std::cout << "Ini Conf: " << delta_t[2] << std::endl;
1139  std::cout << "Ini Toy (v syst): " << delta_t[3] << std::endl;
1140  std::cout << "Ini Sel: " << delta_t[4] << std::endl;
1141  std::cout << "Selection: " << delta_t[5] << std::endl;
1142  std::cout << "End Sel (w syst): " << delta_t[6] << std::endl;
1143  std::cout << "End Toy: " << delta_t[7] << std::endl;
1144  std::cout << "End Conf: " << delta_t[8] << std::endl;
1145  std::cout << "End Bunch: " << delta_t[9] << std::endl;
1146  std::cout << "End Spill: " << delta_t[10] << std::endl;
1147  std::cout << "Total: " << delta_t[11] << std::endl;
1148  std::cout << "Total wo t: " << delta_t[12] << std::endl;
1149 
1150 
1151 
1152  Finalize();
1153 }
bool Process(SelectionBase &selec)
void SetCurrentConfigurationIndex(Int_t conf)
Set the index of the current configuration.
void FinalizeSelection(const SelectionBase &sel)
Int_t GetNToys() const
Get and sets the number of toys.
std::vector< AnaBunchC * > Bunches
The reconstructed objects, split into timing bunches.
void SetCurrentBunch(int ibunch)
Set the current bunch index.
void InitializeConfiguration()
std::vector< SelectionBase * > & GetSelections()
Return the map of selections.
void FinalizeSpill()
void SetToyIndex(int index)
Set and gets the index of the current toy.
Int_t GetTreeIndex() const
Returns the index of the tree associated to this configuration in the TreeManager.
Double_t GetPOT()
This is the method used externaly. It corresponds to POT that passed beam and ND280 quality cuts...
Definition: Header.hxx:36
void SetCurrentTree(Int_t index)
Sets the current tree provided the index.
Definition: TreeManager.hxx:58
AnaSpillC & GetSpill()
Get the current spill (to have corrections and systematics applied to it).
std::vector< ConfigurationBase * > & GetConfigurations()
return the vector of configurations
Long64_t GetEntries()
Return the number of entries in the input file tree(s).
void SetToyIndex(Int_t index)
Set and gets the index of the current toy experiment.
bool FinalizeConfiguration()
void InitializeToy()
Int_t GetIndex() const
Returns the configuration index (should match the one in the Configuration Manager) ...
void FinalizeBunch()
void InitializeBunch()
Long64_t _entry
Fill the "truth" tree.
bool InitializeSpill()
bool FinalizeToy()
Called after each toy experiment is complete.

§ PrintUsage()

void AnalysisLoop::PrintUsage ( const std::string &  programName)
protected


Simple usage statement, for if the user gave bad command line options.

Definition at line 1315 of file AnalysisLoop.cxx.

1315  {
1316 //********************************************************************
1317  std::cout << "usage: " << programName << " [options] [input-file]" << std::endl;
1318  std::cout << std::endl;
1319  std::cout << "Options:" << std::endl;
1320  std::cout << " -c Run in cosmics mode, putting all tracks in one 'bunch'" << std::endl;
1321  std::cout << " -o <file> Set the name of an output file (mandatory)" << std::endl;
1322  std::cout << " -n <cnt> Only read <cnt> events" << std::endl;
1323  std::cout << " -s <cnt> Skip <cnt> events" << std::endl;
1324  std::cout << " -e <file> Set the name of file containing events to skim (format: run subrun event)" << std::endl;
1325  std::cout << " -p <file> Set the name of a parameter override file" << std::endl;
1326  std::cout << " -v Don't Check version compatibility between nd280AnalysisTools and oaAnalysis file" << std::endl;
1327  std::cout << " -r Don't fill any trees and don't create an output file (mainly for speed tests)" << std::endl;
1328  std::cout << " -m Dumps on the screen the memory usage" << std::endl;
1329  std::exit(1);
1330 }

§ Process()

bool AnalysisLoop::Process ( SelectionBase selec)
protected

The main function called to run the analysis. The derived version should apply any cuts, and return whether the current active bunch passed the cuts or not.

Definition at line 1156 of file AnalysisLoop.cxx.

1156  {
1157 //********************************************************************
1158 
1159  // Returns true when any of the branches is passed
1160  // Internaly the CheckRedoSelection is called. The returned boolean is returned as argument
1161  // by the Apply method of the selection such that we can save the redo value in the micro-tree
1162  bool redo = false;
1163  bool ToyPassed = selec.Apply(*_event, redo);
1164 
1165  // fill a variable saying if selection was redone for this toy experiment
1166  if (_fillTrees)
1167  ana().output().FillToyVar(AnalysisAlgorithm::redo, (int)redo);
1168 
1169  return ToyPassed;
1170 }
bool Apply(AnaEventC &event, bool &redo)
Apply all steps in the selection.
void FillToyVar(Int_t index, Int_t var)
Fill a single analysis variable.
bool _fillTrees
Whether to fill the trees and create an output file or not.

Member Data Documentation

§ _cosmicMode

bool AnalysisLoop::_cosmicMode
protected

Whether to run in "cosmics" mode, where all the tracks are saved in a single bunch.

Definition at line 166 of file AnalysisLoop.hxx.

§ _entry

Long64_t AnalysisLoop::_entry
protected

Fill the "truth" tree.

The number of entries we have read in.

Definition at line 146 of file AnalysisLoop.hxx.

§ _inputFileType

std::string AnalysisLoop::_inputFileType
protected

This was used when the user could specify what type of input file they had provided. Now this is done automatically.

Definition at line 153 of file AnalysisLoop.hxx.


The documentation for this class was generated from the following files: