Belle II Software  release-08-01-10
VariablesToNtupleModule.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 #include <analysis/dataobjects/RestOfEvent.h>
13 
14 #include <framework/core/Module.h>
15 #include <framework/datastore/StoreObjPtr.h>
16 #include <framework/dataobjects/EventMetaData.h>
17 #include <framework/pcore/RootMergeable.h>
18 
19 #include <TTree.h>
20 #include <TFile.h>
21 
22 #include <string>
23 
24 namespace Belle2 {
30  class StringWrapper;
31 
38  public:
41 
46  virtual void initialize() override;
48  virtual void event() override;
50  virtual void terminate() override;
51 
52  private:
56  float getInverseSamplingRateWeight(const Particle* particle);
57 
59  std::string m_particleList;
61  std::vector<std::string> m_variables;
63  std::string m_fileName;
65  std::string m_treeName;
67  std::string m_fileNameSuffix;
70 
72  std::shared_ptr<TFile> m_file{nullptr};
75  // Counter branch addresses (event number, candidate number etc)
76  int m_event{ -1};
77  int m_run{ -1};
78  int m_experiment{ -1};
79  int m_production{ -1};
80  int m_candidate{ -1};
81  unsigned int m_ncandidates{0};
83  std::vector<double> m_branchAddressesDouble;
85  std::vector<int> m_branchAddressesInt;
87  std::vector<std::pair<Variable::Manager::FunctionPtr, Variable::Manager::VariableDataType>> m_functions;
88 
90  std::tuple<std::string, std::map<int, unsigned int>> m_sampling;
92  std::string m_sampling_name;
94  std::map<int, unsigned int> m_sampling_rates;
95 
97  std::map<int, unsigned long int> m_sampling_counts;
100  std::string m_MCDecayString;
105  unsigned int m_nSignalSideCandidates{0};
107  };
109 } // end namespace Belle2
Base class for Modules.
Definition: Module.h:72
Class to store reconstructed particles.
Definition: Particle.h:75
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 ROO...
StoreObjPtr< RestOfEvent > m_roe
ROE object.
std::vector< std::string > m_variables
List of 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
total n candidates
virtual void terminate() override
Write TTree to file, and close file if necessary.
StoreObjPtr< EventMetaData > m_eventMetaData
the event information
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::vector< std::pair< Variable::Manager::FunctionPtr, Variable::Manager::VariableDataType > > m_functions
List of pairs of function pointers and respective data type corresponding to given variables.
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< int > m_branchAddressesInt
Branch addresses of variables of type int (or bool)
int m_basketsize
Size of TBaskets in the output ROOT file in bytes.
int m_production
production ID (to distinguish MC samples)
unsigned int m_nSignalSideCandidates
total n signal-side candidates
StoreObjPtr< StringWrapper > m_stringWrapper
string wrapper storing the MCDecayString
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::vector< double > m_branchAddressesDouble
Branch addresses of variables of type double.
std::string m_sampling_name
Variable name of sampling variable.
float getInverseSamplingRateWeight(const Particle *particle)
Calculate inverse sampling rate weight.
std::string m_treeName
Name of the TTree.
std::string m_signalSideParticleList
Name of signal-side particle list
const Variable::Manager::Var * m_sampling_variable
Variable Pointer to target variable.
int m_signalSideCandidate
signal-side candidate counter
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