Belle II Software  release-05-02-19
VariablesToNtupleModule.h
1 /*************************************************************************
2 * BASF2 (Belle Analysis Framework 2) *
3 * Copyright(C) 2013-2018 Belle II Collaboration *
4 * *
5 * Author: The Belle II Collaboration *
6 * Contributors: Christian Pulvermacher *
7 * Thomas Keck *
8 * Simon Wehle *
9 * Sam Cunliffe *
10 * *
11 * This software is provided "as is" without any warranty. *
12 **************************************************************************/
13 
14 #pragma once
15 
16 #include <framework/core/Module.h>
17 #include <analysis/VariableManager/Manager.h>
18 #include <framework/datastore/StoreObjPtr.h>
19 #include <framework/dataobjects/EventMetaData.h>
20 #include <framework/pcore/RootMergeable.h>
21 
22 #include <TTree.h>
23 #include <TFile.h>
24 
25 #include <string>
26 
27 namespace Belle2 {
38  class VariablesToNtupleModule : public Module {
39  public:
42 
47  virtual void initialize() override;
49  virtual void event() override;
51  virtual void terminate() override;
52 
53  private:
57  float getInverseSamplingRateWeight(const Particle* particle);
58 
60  std::string m_particleList;
62  std::vector<std::string> m_variables;
64  std::string m_fileName;
66  std::string m_treeName;
67 
69  std::shared_ptr<TFile> m_file{nullptr};
72  // Counter branch addresses (event number, candidate number etc)
73  int m_event{ -1};
74  int m_run{ -1};
75  int m_experiment{ -1};
76  int m_candidate{ -1};
77  unsigned int m_ncandidates{0};
79  std::vector<double> m_branchAddresses;
81  std::vector<Variable::Manager::FunctionPtr> m_functions;
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;
94  };
96 } // end namespace Belle2
Belle2::VariablesToNtupleModule::initialize
virtual void initialize() override
Initialises the module.
Definition: VariablesToNtupleModule.cc:63
Belle2::Variable::Manager::Var
A variable returning a floating-point value for a given Particle.
Definition: Manager.h:137
Belle2::VariablesToNtupleModule::m_run
int m_run
run number
Definition: VariablesToNtupleModule.h:85
Belle2::VariablesToNtupleModule::m_particleList
std::string m_particleList
Name of particle list with reconstructed particles.
Definition: VariablesToNtupleModule.h:71
Belle2::VariablesToNtupleModule::m_file
std::shared_ptr< TFile > m_file
ROOT file for output.
Definition: VariablesToNtupleModule.h:80
Belle2::VariablesToNtupleModule::m_eventMetaData
StoreObjPtr< EventMetaData > m_eventMetaData
the event information
Definition: VariablesToNtupleModule.h:103
Belle2::VariablesToNtupleModule::m_candidate
int m_candidate
candidate counter
Definition: VariablesToNtupleModule.h:87
Belle2::VariablesToNtupleModule::m_ncandidates
unsigned int m_ncandidates
total n candidates
Definition: VariablesToNtupleModule.h:88
Belle2::VariablesToNtupleModule::m_variables
std::vector< std::string > m_variables
List of variables to save.
Definition: VariablesToNtupleModule.h:73
Belle2::VariablesToNtupleModule::m_experiment
int m_experiment
experiment number
Definition: VariablesToNtupleModule.h:86
Belle2::VariablesToNtupleModule::m_sampling_variable
const Variable::Manager::Var * m_sampling_variable
Variable Pointer to target variable.
Definition: VariablesToNtupleModule.h:101
Belle2::VariablesToNtupleModule::m_sampling_counts
std::map< int, unsigned long int > m_sampling_counts
Current number of samples with this value.
Definition: VariablesToNtupleModule.h:102
Belle2::VariablesToNtupleModule::m_functions
std::vector< Variable::Manager::FunctionPtr > m_functions
List of function pointers corresponding to given variables.
Definition: VariablesToNtupleModule.h:92
Belle2::VariablesToNtupleModule::terminate
virtual void terminate() override
Write TTree to file, and close file if necessary.
Definition: VariablesToNtupleModule.cc:214
Belle2::VariablesToNtupleModule::m_event
int m_event
event number
Definition: VariablesToNtupleModule.h:84
Belle2::VariablesToNtupleModule::event
virtual void event() override
Method called for each event.
Definition: VariablesToNtupleModule.cc:182
Belle2::VariablesToNtupleModule::getInverseSamplingRateWeight
float getInverseSamplingRateWeight(const Particle *particle)
Calculate inverse sampling rate weight.
Definition: VariablesToNtupleModule.cc:164
Belle2::VariablesToNtupleModule::m_sampling
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.
Definition: VariablesToNtupleModule.h:95
Belle2::VariablesToNtupleModule::m_treeName
std::string m_treeName
Name of the TTree.
Definition: VariablesToNtupleModule.h:77
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::VariablesToNtupleModule::m_fileName
std::string m_fileName
Name of ROOT file for output.
Definition: VariablesToNtupleModule.h:75
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::VariablesToNtupleModule::VariablesToNtupleModule
VariablesToNtupleModule()
Constructor.
Definition: VariablesToNtupleModule.cc:39
Belle2::Particle
Class to store reconstructed particles.
Definition: Particle.h:77
Belle2::VariablesToNtupleModule::m_sampling_name
std::string m_sampling_name
Variable name of sampling variable.
Definition: VariablesToNtupleModule.h:97
Belle2::VariablesToNtupleModule::m_tree
StoreObjPtr< RootMergeable< TTree > > m_tree
The ROOT TNtuple for output.
Definition: VariablesToNtupleModule.h:82
Belle2::VariablesToNtupleModule::m_branchAddresses
std::vector< double > m_branchAddresses
Variable branch addresses.
Definition: VariablesToNtupleModule.h:90
Belle2::VariablesToNtupleModule::m_sampling_rates
std::map< int, unsigned int > m_sampling_rates
Inverse sampling rates.
Definition: VariablesToNtupleModule.h:99