Belle II Software  release-05-02-19
VariablesToEventBasedTreeModule.h
1 #pragma once
2 /**************************************************************************
3 * BASF2 (Belle Analysis Framework 2) *
4 * Copyright(C) 2013-2018 - Belle II Collaboration *
5 * *
6 * Author: The Belle II Collaboration *
7 * Contributors: Thomas Keck *
8 * Sam Cunliffe *
9 * *
10 * This software is provided "as is" without any warranty. *
11 **************************************************************************/
12 
13 #include <framework/core/Module.h>
14 #include <analysis/VariableManager/Manager.h>
15 #include <framework/datastore/StoreObjPtr.h>
16 #include <framework/dataobjects/EventMetaData.h>
17 #include <framework/pcore/RootMergeable.h>
18 
19 #include <TFile.h>
20 
21 #include <string>
22 
23 namespace Belle2 {
33  class VariablesToEventBasedTreeModule : public Module {
34  public:
37 
42  virtual void initialize() override;
44  virtual void event() override;
46  virtual void terminate() override;
47 
48  private:
53 
55  std::string m_particleList;
57  std::vector<std::string> m_variables;
59  std::vector<std::string> m_event_variables;
61  unsigned int m_maxCandidates;
63  std::string m_fileName;
65  std::string m_treeName;
66 
68  std::shared_ptr<TFile> m_file{nullptr};
72  std::vector<Variable::Manager::FunctionPtr> m_functions;
74  std::vector<Variable::Manager::FunctionPtr> m_event_functions;
75  int m_event{ -1};
76  int m_run{ -1};
77  int m_experiment{ -1};
78  unsigned int m_ncandidates{ 0};
79  float m_weight{0.0};
81  std::vector<std::vector<double>> m_values;
83  std::vector<double> m_event_values;
84 
86  std::tuple<std::string, std::map<int, unsigned int>> m_sampling;
88  std::string m_sampling_name;
90  std::map<int, unsigned int> m_sampling_rates;
91 
93  std::map<int, unsigned long int> m_sampling_counts;
97 
98  };
100 } // end namespace Belle2
Belle2::VariablesToEventBasedTreeModule::m_maxCandidates
unsigned int m_maxCandidates
maximum number of candidates which is written out
Definition: VariablesToEventBasedTreeModule.h:70
Belle2::VariablesToEventBasedTreeModule::m_event_variables
std::vector< std::string > m_event_variables
List of event variables to save.
Definition: VariablesToEventBasedTreeModule.h:68
Belle2::Variable::Manager::Var
A variable returning a floating-point value for a given Particle.
Definition: Manager.h:137
Belle2::VariablesToEventBasedTreeModule::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: VariablesToEventBasedTreeModule.h:95
Belle2::VariablesToEventBasedTreeModule::m_fileName
std::string m_fileName
Name of ROOT file for output.
Definition: VariablesToEventBasedTreeModule.h:72
Belle2::VariablesToEventBasedTreeModule::m_file
std::shared_ptr< TFile > m_file
ROOT file for output.
Definition: VariablesToEventBasedTreeModule.h:77
Belle2::VariablesToEventBasedTreeModule::m_event
int m_event
event number
Definition: VariablesToEventBasedTreeModule.h:84
Belle2::VariablesToEventBasedTreeModule::m_values
std::vector< std::vector< double > > m_values
Values corresponding to given variables.
Definition: VariablesToEventBasedTreeModule.h:90
Belle2::VariablesToEventBasedTreeModule::m_event_values
std::vector< double > m_event_values
Values corresponding to given event variables.
Definition: VariablesToEventBasedTreeModule.h:92
Belle2::VariablesToEventBasedTreeModule::m_ncandidates
unsigned int m_ncandidates
number of candidates in this event
Definition: VariablesToEventBasedTreeModule.h:87
Belle2::VariablesToEventBasedTreeModule::m_event_functions
std::vector< Variable::Manager::FunctionPtr > m_event_functions
List of function pointers corresponding to given event variables.
Definition: VariablesToEventBasedTreeModule.h:83
Belle2::VariablesToEventBasedTreeModule::m_treeName
std::string m_treeName
Name of the TTree.
Definition: VariablesToEventBasedTreeModule.h:74
Belle2::VariablesToEventBasedTreeModule::event
virtual void event() override
Method called for each event.
Definition: VariablesToEventBasedTreeModule.cc:169
Belle2::VariablesToEventBasedTreeModule::m_tree
StoreObjPtr< RootMergeable< TTree > > m_tree
The ROOT TNtuple for output.
Definition: VariablesToEventBasedTreeModule.h:79
Belle2::VariablesToEventBasedTreeModule::m_variables
std::vector< std::string > m_variables
List of variables to save.
Definition: VariablesToEventBasedTreeModule.h:66
Belle2::VariablesToEventBasedTreeModule::m_experiment
int m_experiment
experiment number
Definition: VariablesToEventBasedTreeModule.h:86
Belle2::VariablesToEventBasedTreeModule::m_run
int m_run
run number
Definition: VariablesToEventBasedTreeModule.h:85
Belle2::VariablesToEventBasedTreeModule::getInverseSamplingRateWeight
float getInverseSamplingRateWeight()
Calculate inverse sampling rate weight.
Definition: VariablesToEventBasedTreeModule.cc:149
Belle2::VariablesToEventBasedTreeModule::initialize
virtual void initialize() override
Initialises the module.
Definition: VariablesToEventBasedTreeModule.cc:60
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::VariablesToEventBasedTreeModule::VariablesToEventBasedTreeModule
VariablesToEventBasedTreeModule()
Constructor.
Definition: VariablesToEventBasedTreeModule.cc:31
Belle2::VariablesToEventBasedTreeModule::m_sampling_name
std::string m_sampling_name
Variable name of sampling variable.
Definition: VariablesToEventBasedTreeModule.h:97
Belle2::VariablesToEventBasedTreeModule::terminate
virtual void terminate() override
Write TTree to file, and close file if necessary.
Definition: VariablesToEventBasedTreeModule.cc:199
Belle2::VariablesToEventBasedTreeModule::m_functions
std::vector< Variable::Manager::FunctionPtr > m_functions
List of function pointers corresponding to given variables.
Definition: VariablesToEventBasedTreeModule.h:81
Belle2::VariablesToEventBasedTreeModule::m_particleList
std::string m_particleList
Name of particle list with reconstructed particles.
Definition: VariablesToEventBasedTreeModule.h:64
Belle2::VariablesToEventBasedTreeModule::m_sampling_variable
const Variable::Manager::Var * m_sampling_variable
Variable Pointer to target variable.
Definition: VariablesToEventBasedTreeModule.h:101
Belle2::VariablesToEventBasedTreeModule::m_sampling_counts
std::map< int, unsigned long int > m_sampling_counts
Current number of samples with this value.
Definition: VariablesToEventBasedTreeModule.h:102
Belle2::VariablesToEventBasedTreeModule::m_weight
float m_weight
weight of this event
Definition: VariablesToEventBasedTreeModule.h:88
Belle2::VariablesToEventBasedTreeModule::m_sampling_rates
std::map< int, unsigned int > m_sampling_rates
Inverse sampling rates.
Definition: VariablesToEventBasedTreeModule.h:99
Belle2::VariablesToEventBasedTreeModule::m_eventMetaData
StoreObjPtr< EventMetaData > m_eventMetaData
event metadata (get event number etc)
Definition: VariablesToEventBasedTreeModule.h:105