Belle II Software  release-06-00-14
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 <framework/core/Module.h>
12 #include <analysis/VariableManager/Manager.h>
13 #include <framework/datastore/StoreObjPtr.h>
14 #include <framework/dataobjects/EventMetaData.h>
15 #include <framework/pcore/RootMergeable.h>
16 
17 #include <TTree.h>
18 #include <TFile.h>
19 
20 #include <string>
21 
22 namespace Belle2 {
34  public:
37 
42  virtual void initialize() override;
44  virtual void event() override;
46  virtual void terminate() override;
47 
48  private:
52  float getInverseSamplingRateWeight(const Particle* particle);
53 
55  std::string m_particleList;
57  std::vector<std::string> m_variables;
59  std::string m_fileName;
61  std::string m_treeName;
62 
64  std::shared_ptr<TFile> m_file{nullptr};
67  // Counter branch addresses (event number, candidate number etc)
68  int m_event{ -1};
69  int m_run{ -1};
70  int m_experiment{ -1};
71  int m_production{ -1};
72  int m_candidate{ -1};
73  unsigned int m_ncandidates{0};
75  std::vector<double> m_branchAddresses;
77  std::vector<Variable::Manager::FunctionPtr> m_functions;
78 
80  std::tuple<std::string, std::map<int, unsigned int>> m_sampling;
82  std::string m_sampling_name;
84  std::map<int, unsigned int> m_sampling_rates;
85 
87  std::map<int, unsigned long int> m_sampling_counts;
90  };
92 } // end namespace Belle2
Base class for Modules.
Definition: Module.h:72
Class to store reconstructed particles.
Definition: Particle.h:74
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 ROO...
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::vector< double > m_branchAddresses
Variable branch addresses.
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.
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::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.
float getInverseSamplingRateWeight(const Particle *particle)
Calculate inverse sampling rate weight.
std::string m_treeName
Name of the TTree.
const Variable::Manager::Var * m_sampling_variable
Variable Pointer to target variable.
Abstract base class for different kinds of events.
A variable returning a floating-point value for a given Particle.
Definition: Manager.h:133