Belle II Software  release-08-01-10
VariablesToEventBasedTreeModule.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #pragma once
10 
11 #include <analysis/VariableManager/Manager.h>
12 
13 #include <framework/core/Module.h>
14 #include <framework/datastore/StoreObjPtr.h>
15 #include <framework/dataobjects/EventMetaData.h>
16 #include <framework/pcore/RootMergeable.h>
17 
18 #include <TFile.h>
19 
20 #include <string>
21 
22 namespace Belle2 {
28  class StringWrapper;
29 
35  public:
38 
43  virtual void initialize() override;
45  virtual void event() override;
47  virtual void terminate() override;
48 
49  private:
54 
56  std::string m_particleList;
58  std::vector<std::string> m_variables;
60  std::vector<std::string> m_event_variables;
62  unsigned int m_maxCandidates;
64  std::string m_fileName;
66  std::string m_treeName;
68  std::string m_fileNameSuffix;
69 
71  std::shared_ptr<TFile> m_file{nullptr};
75  std::vector<Variable::Manager::FunctionPtr> m_functions;
77  std::vector<Variable::Manager::FunctionPtr> m_event_functions;
78  int m_event{ -1};
79  int m_run{ -1};
80  int m_experiment{ -1};
81  int m_production{ -1};
82  unsigned int m_ncandidates{ 0};
83  float m_weight{0.0};
85  std::vector<std::vector<double>> m_valuesDouble;
87  std::vector<std::vector<int>> m_valuesInt;
89  std::vector<double> m_event_valuesDouble;
91  std::vector<int> m_event_valuesInt;
92 
94  std::tuple<std::string, std::map<int, unsigned int>> m_sampling;
96  std::string m_sampling_name;
98  std::map<int, unsigned int> m_sampling_rates;
99 
101  std::map<int, unsigned long int> m_sampling_counts;
105 
106  std::string m_MCDecayString;
108  };
110 } // end namespace Belle2
Base class for Modules.
Definition: Module.h:72
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
Module to calculate variables specified by the user for a given ParticleList and save them into a TTr...
std::vector< std::string > m_variables
List of variables to save.
unsigned int m_maxCandidates
maximum number of candidates which is written out
std::vector< std::string > m_event_variables
List of event variables to save.
virtual void initialize() override
Initialises the module.
std::map< int, unsigned int > m_sampling_rates
Inverse sampling rates.
std::vector< int > m_event_valuesInt
Values of type int corresponding to given event variables.
virtual void event() override
Method called for each event.
unsigned int m_ncandidates
number of candidates in this event
virtual void terminate() override
Write TTree to file, and close file if necessary.
StoreObjPtr< EventMetaData > m_eventMetaData
event metadata (get event number etc)
std::map< int, unsigned long int > m_sampling_counts
Current number of samples with this value.
std::string m_fileName
Name of ROOT file for output.
std::tuple< std::string, std::map< int, unsigned int > > m_sampling
Tuple of variable name and a map of integer values and inverse sampling rate.
std::vector< std::vector< double > > m_valuesDouble
Values of type double corresponding to given variables.
float getInverseSamplingRateWeight()
Calculate inverse sampling rate weight.
int m_production
production ID (to distinguish MC samples)
StoreObjPtr< StringWrapper > m_stringWrapper
string wrapper storing the MCDecayString
std::vector< Variable::Manager::FunctionPtr > m_functions
List of function pointers corresponding to given variables.
std::string m_particleList
Name of particle list with reconstructed particles.
StoreObjPtr< RootMergeable< TTree > > m_tree
The ROOT TNtuple for output.
std::shared_ptr< TFile > m_file
ROOT file for output.
std::string m_sampling_name
Variable name of sampling variable.
std::vector< std::vector< int > > m_valuesInt
Values of type int corresponding to given variables.
std::vector< double > m_event_valuesDouble
Values of type double corresponding to given event variables.
const Variable::Manager::Var * m_sampling_variable
Variable Pointer to target variable.
std::vector< Variable::Manager::FunctionPtr > m_event_functions
List of function pointers corresponding to given event variables.
std::string m_fileNameSuffix
Suffix to be appended to the output file name.
std::string m_MCDecayString
MC decay string to be filled.
Abstract base class for different kinds of events.
A variable returning a floating-point value for a given Particle.
Definition: Manager.h:146