Belle II Software  release-06-02-00
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 #include <framework/core/Module.h>
11 #include <analysis/VariableManager/Manager.h>
12 #include <framework/datastore/StoreObjPtr.h>
13 #include <framework/dataobjects/EventMetaData.h>
14 #include <framework/pcore/RootMergeable.h>
15 
16 #include <TFile.h>
17 
18 #include <string>
19 
20 namespace Belle2 {
31  public:
34 
39  virtual void initialize() override;
41  virtual void event() override;
43  virtual void terminate() override;
44 
45  private:
50 
52  std::string m_particleList;
54  std::vector<std::string> m_variables;
56  std::vector<std::string> m_event_variables;
58  unsigned int m_maxCandidates;
60  std::string m_fileName;
62  std::string m_treeName;
63 
65  std::shared_ptr<TFile> m_file{nullptr};
69  std::vector<Variable::Manager::FunctionPtr> m_functions;
71  std::vector<Variable::Manager::FunctionPtr> m_event_functions;
72  int m_event{ -1};
73  int m_run{ -1};
74  int m_experiment{ -1};
75  int m_production{ -1};
76  unsigned int m_ncandidates{ 0};
77  float m_weight{0.0};
79  std::vector<std::vector<double>> m_values;
81  std::vector<double> m_event_values;
82 
84  std::tuple<std::string, std::map<int, unsigned int>> m_sampling;
86  std::string m_sampling_name;
88  std::map<int, unsigned int> m_sampling_rates;
89 
91  std::map<int, unsigned long int> m_sampling_counts;
95 
96  };
98 } // end namespace Belle2
Base class for Modules.
Definition: Module.h:72
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:95
Module to calculate variables specified by the user for a given ParticleList and save them into a TTr...
std::vector< double > m_event_values
Values corresponding to given event variables.
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.
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.
float getInverseSamplingRateWeight()
Calculate inverse sampling rate weight.
int m_production
production ID (to distinguish MC samples)
std::vector< Variable::Manager::FunctionPtr > m_functions
List of function pointers corresponding to given variables.
std::vector< std::vector< double > > m_values
Values 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.
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.
Abstract base class for different kinds of events.
A variable returning a floating-point value for a given Particle.
Definition: Manager.h:133