Belle II Software development
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/dataobjects/EventExtraInfo.h>
18#include <framework/dataobjects/FileMetaData.h>
19#include <framework/pcore/RootMergeable.h>
20
21#include <TTree.h>
22#include <TFile.h>
23
24#include <string>
25
26namespace Belle2 {
32 class StringWrapper;
33
40 public:
43
48 virtual void initialize() override;
50 virtual void event() override;
52 virtual void terminate() override;
53
54 private:
58 float getInverseSamplingRateWeight(const Particle* particle);
59
61 void fillFileMetaData();
62
64 std::string m_particleList;
66 std::vector<std::string> m_variables;
68 std::string m_fileName;
70 std::string m_treeName;
72 std::string m_fileNameSuffix;
77
79 std::shared_ptr<TFile> m_file{nullptr};
82 // Counter branch addresses (event number, candidate number etc)
83 int m_event{ -1};
84 int m_run{ -1};
85 int m_experiment{ -1};
86 int m_production{ -1};
87 int m_candidate{ -1};
88 unsigned int m_ncandidates{0};
89 unsigned int m_eventCount{0};
92 int m_runLow{0};
93 int m_runHigh{0};
94 int m_eventLow{0};
95 int m_eventHigh{0};
98 std::vector<float> m_branchAddressesFloat;
99
101 std::vector<double> m_branchAddressesDouble;
102
104 std::vector<int> m_branchAddressesInt;
106 std::vector<std::pair<Variable::Manager::FunctionPtr, Variable::Manager::VariableDataType>> m_functions;
107
109 std::tuple<std::string, std::map<int, unsigned int>> m_sampling;
111 std::string m_sampling_name;
113 std::map<int, unsigned int> m_sampling_rates;
114
116 std::map<int, unsigned long int> m_sampling_counts;
119 std::string m_MCDecayString;
124 unsigned int m_nSignalSideCandidates{0};
129 std::string m_eventType;
131 std::map<std::string, std::string> m_dataDescription;
133 std::vector<std::string> m_parentLfns;
141 };
143} // end namespace Belle2
@ c_Persistent
Object is available during entire execution time.
Definition: DataStore.h:60
Base class for Modules.
Definition: Module.h:72
Class to store reconstructed particles.
Definition: Particle.h:76
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...
StoreObjPtr< RestOfEvent > m_roe
ROE object.
StoreObjPtr< FileMetaData > m_inputFileMetaData
Pointer to the input file meta data.
bool m_useFloat
Use float type for floating-point numbers.
void fillFileMetaData()
Create and fill FileMetaData object.
std::vector< std::string > m_variables
List of variables to save.
std::vector< float > m_branchAddressesFloat
Branch addresses of variables of type float.
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< std::string, std::string > m_dataDescription
Additional metadata description.
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
unsigned int m_eventCount
event counter
StoreObjPtr< StringWrapper > m_stringWrapper
string wrapper storing the MCDecayString
bool m_storeEventType
If true, the branch eventType is added.
std::string m_particleList
Name of particle list with reconstructed particles.
bool m_ignoreCommandLineOverride
if true, ignore override of filename
std::string m_eventType
EventType to be filled.
StoreObjPtr< FileMetaData > m_outputFileMetaData
File meta data to be stored in the output ntuple file.
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.
int m_experimentLow
lowest experiment number
StoreObjPtr< EventExtraInfo > m_eventExtraInfo
pointer to EventExtraInfo
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_experimentHigh
highest experiment number
int m_signalSideCandidate
signal-side candidate counter
std::vector< std::string > m_parentLfns
Vector of parent file LFNs.
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:145