Belle II Software light-2501-betelgeuse
TrackingEnergyLossCorrection.cc
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// Own header.
10#include <analysis/modules/TrackingSystematics/TrackingEnergyLossCorrection.h>
11
12#include <framework/datastore/StoreObjPtr.h>
13#include <framework/core/ModuleParam.templateDetails.h>
14#include <analysis/VariableManager/Manager.h>
15#include <analysis/dataobjects/ParticleList.h>
16
17#include <Math/Vector4D.h>
18
19#include <map>
20
21using namespace Belle2;
22
23REG_MODULE(TrackingEnergyLossCorrection);
24
26{
28 R"DOC(Module to modify Energy of tracks from the lists. Include in your code as
29
30.. code:: python
31
32 mypath.add_module("TrackingEnergyLossCorrection", particleLists=['pi+:cut'], correction=0.001)
33
34The module modifies the input particleLists by subtracting the correction value to the track energy and rescaling the momenta
35
36 )DOC");
38 // Parameter definitions
39 addParam("particleLists", m_ParticleLists, "input particle lists");
40 addParam("correction", m_correction, "correction value to be subtracted from the particle energy",
41 nan("")); // Nan
42 addParam("payloadName", m_payloadName, "ID of table used for reweighing", std::string(""));
43 addParam("correctionName", m_correctionName, "Label for the correction in the look up table", std::string(""));
44}
45
47{
48 if (!isnan(m_correction) && !m_payloadName.empty()) {
49 B2FATAL("It's not allowed to provide both a valid value for the scale parameter and a non-empty table name. Please decide for one of the two options!");
50 } else if (isnan(m_correction) && m_payloadName.empty()) {
51 B2FATAL("Neither a valid value for the scale parameter nor a non-empty table name was provided. Please set (exactly) one of the two options!");
52 } else if (!m_payloadName.empty()) {
53 m_ParticleWeightingLookUpTable = std::make_unique<DBObjPtr<ParticleWeightingLookUpTable>>(m_payloadName);
54
55 std::vector<std::string> variables = Variable::Manager::Instance().resolveCollections((
56 *m_ParticleWeightingLookUpTable.get())->getAxesNames());
57 for (const auto& i_variable : variables) {
59 if (!var) {
60 B2FATAL("Variable '" << i_variable << "' is not available in Variable::Manager!");
61 }
62 }
63 }
64}
65
67{
68 for (auto& iList : m_ParticleLists) {
69 StoreObjPtr<ParticleList> particleList(iList);
70
71 //check particle List exists and has particles
72 if (!particleList) {
73 B2ERROR("ParticleList " << iList << " not found");
74 continue;
75 }
76
77 size_t nPart = particleList->getListSize();
78 for (size_t iPart = 0; iPart < nPart; iPart++) {
79 auto particle = particleList->getParticle(iPart);
80 if (particle->getParticleSource() != Particle::EParticleSourceObject::c_Composite and
81 particle->getParticleSource() != Particle::EParticleSourceObject::c_V0 and
82 particle->getParticleSource() != Particle::EParticleSourceObject::c_Track) {
83 B2WARNING("particle source " << particle->getParticleSource() <<
84 " is not within the expected values. please check before continuing");
85 continue;
86 }
88 }
89 }
90}
91
92
93// Getting LookUp info for given particle in given event
95{
96 std::vector<std::string> variables = Variable::Manager::Instance().resolveCollections((
97 *m_ParticleWeightingLookUpTable.get())->getAxesNames());
98
99 std::map<std::string, double> values;
100 for (const auto& i_variable : variables) {
102 double value = std::get<double>(var->function(particle));
103 values.insert(std::make_pair(i_variable, value));
104 }
105 WeightInfo info = (*m_ParticleWeightingLookUpTable.get())->getInfo(values);
106 for (const auto& entry : info) {
107 particle->writeExtraInfo(m_payloadName + "_" + entry.first, entry.second);
108 }
109
110 return particle->getExtraInfo(m_payloadName + "_" + m_correctionName);
111}
112
113
114
116{
117 if (particle->getParticleSource() == Particle::EParticleSourceObject::c_Composite or
118 particle->getParticleSource() == Particle::EParticleSourceObject::c_V0) {
119 for (auto daughter : particle->getDaughters()) {
120 setEnergyLossCorrection(daughter);
121 }
122 double px = 0;
123 double py = 0;
124 double pz = 0;
125 double E = 0;
126 for (auto daughter : particle->getDaughters()) {
127 px += daughter->getPx();
128 py += daughter->getPy();
129 pz += daughter->getPz();
130 E += daughter->getEnergy();
131 }
132 const ROOT::Math::PxPyPzEVector vec(px, py, pz, E);
133 particle->set4Vector(vec);
134 } else if (particle->getParticleSource() == Particle::EParticleSourceObject::c_Track) {
135 if (!isnan(m_correction)) {
137 } else if (!m_correctionName.empty()) {
138 particle->setEnergyLossCorrection(getCorrectionValue(particle));
139 }
140 }
141
142
143}
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
Class to store reconstructed particles.
Definition: Particle.h:76
void writeExtraInfo(const std::string &name, const double value)
Sets the user defined extraInfo.
Definition: Particle.cc:1392
std::vector< Belle2::Particle * > getDaughters() const
Returns a vector of pointers to daughter particles.
Definition: Particle.cc:667
void set4Vector(const ROOT::Math::PxPyPzEVector &p4)
Sets Lorentz vector.
Definition: Particle.h:282
void setEnergyLossCorrection(double energyLossCorrection)
Sets Energy loss correction.
Definition: Particle.h:317
EParticleSourceObject getParticleSource() const
Returns particle source as defined with enum EParticleSourceObject.
Definition: Particle.h:489
double getExtraInfo(const std::string &name) const
Return given value if set.
Definition: Particle.cc:1373
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
std::vector< std::string > m_ParticleLists
input particle lists
virtual void initialize() override
Initializes the modules and checks the validity of the input parameters.
virtual void event() override
Function to be executed at each event.
double getCorrectionValue(Particle *particle)
Returns the needed correction for particle based on payloadName and correctionName.
TrackingEnergyLossCorrectionModule()
Constructor: Sets the description, the properties and the parameters of the module.
void setEnergyLossCorrection(Particle *particle)
function to set the Energy correction value
std::unique_ptr< DBObjPtr< ParticleWeightingLookUpTable > > m_ParticleWeightingLookUpTable
Pointer to the table in DB.
std::string m_correctionName
Name of the correction from table.
std::vector< std::string > resolveCollections(const std::vector< std::string > &variables)
Resolve Collection Returns variable names corresponding to the given collection or if it is not a col...
Definition: Manager.cc:180
const Var * getVariable(std::string name)
Get the variable belonging to the given key.
Definition: Manager.cc:58
static Manager & Instance()
get singleton instance.
Definition: Manager.cc:26
std::map< std::string, double > WeightInfo
Weight information: a line from the weight lookup table.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:649
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24
A variable returning a floating-point value for a given Particle.
Definition: Manager.h:145