Belle II Software light-2609-luna
Pi0VetoEfficiencySystematics.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#include <analysis/modules/Pi0VetoEfficiencySystematics/Pi0VetoEfficiencySystematics.h>
10
11#include <framework/database/DBObjPtr.h>
12#include <framework/datastore/StoreObjPtr.h>
13#include <framework/core/ModuleParam.templateDetails.h>
14#include <analysis/VariableManager/Manager.h>
15#include <analysis/dataobjects/Particle.h>
16#include <analysis/dataobjects/ParticleList.h>
17
18#include <map>
19
20using namespace Belle2;
21
22//-----------------------------------------------------------------
23// Register module
24//-----------------------------------------------------------------
25
26REG_MODULE(Pi0VetoEfficiencySystematics);
27
28//-----------------------------------------------------------------
29// Implementation
30//-----------------------------------------------------------------
31
33{
34 setDescription("Includes data/MC weights for pi0 veto efficiency as extraInfo for a given particle list. One must call writeP0EtaVeto function in advance. Weights and their errors will be provided for given mode and threshold.");
36 // Parameter definitions
37 std::vector<std::string> emptylist;
38 addParam("particleLists", m_ParticleLists, "input particle lists", emptylist);
39 addParam("decayString", m_decayString, "decay string", std::string(""));
40 addParam("tableName", m_tableName, "table name of the payloads", std::string(""));
41 addParam("threshold", m_threshold, "threshold of pi0 veto", 0.);
42 addParam("mode", m_mode, "pi0 veto option name", std::string(""));
43 addParam("suffix", m_suffix, "suffix of extrainfo", std::string(""));
44}
45
46// Getting LookUp info for given hard photon in given event
48{
49 std::vector<std::string> variables = Variable::Manager::Instance().resolveCollections((
50 *m_ParticleWeightingLookUpTable.get())->getAxesNames());
51 std::map<std::string, double> values;
52 for (const auto& i_variable : variables) {
54 if (!var) {
55 B2ERROR("Variable '" << i_variable << "' is not available in Variable::Manager!");
56 }
57 values.insert(std::make_pair(i_variable, std::get<double>(var->function(particle))));
58 }
59
60 return (*m_ParticleWeightingLookUpTable.get())->getInfo(values);
61}
62
64{
65 B2WARNING("The Pi0VetoEfficiencySystematics module (and modularAnalysis.addPi0VetoEfficiencySystematics) is deprecated "
66 "and will be removed in February 2027. Please use the generic ParticleWeighting module instead, with "
67 "tableName='<tableName>_<mode><thresholdPercent>', where <thresholdPercent> is the threshold in percent "
68 "as a two-digit integer (e.g. 'Pi0VetoEfficiencySystematics_Mar2022_standard30' for threshold=0.30), "
69 "and selectedDaughters set to the decay string selecting the hard photon. "
70 "Note that the weights are then stored as extraInfo of the hard photon, not of the mother particle. "
71 "See the documentation of modularAnalysis.addPi0VetoEfficiencySystematics for details.");
72
73 bool valid = m_decayDescriptor.init(m_decayString);
74 if (!valid) {
75 B2ERROR("Invalid input decay string: " << m_decayString);
76 }
77
78 if (m_threshold < 0.1 || 0.99 < m_threshold) {
79 B2ERROR("Please provide pi0veto threshold from 0.10 to 0.99 for Pi0VetoEfficiencySystematicsModule");
80 }
81
82 //Table is identified with mode and threshold
83 std::string tableName = m_tableName + "_" + m_mode + std::to_string((int)(m_threshold * 100 + 0.001));
84 m_ParticleWeightingLookUpTable = std::make_unique<DBObjPtr<ParticleWeightingLookUpTable>>(tableName);
85}
86
87
89{
90
91 for (auto& iList : m_ParticleLists) {
92 StoreObjPtr<ParticleList> particleList(iList);
93
94 //check particle List exists and has particles
95 if (!particleList) {
96 B2ERROR("ParticleList " << iList << " not found");
97 continue;
98 }
99
100 size_t nPart = particleList->getListSize();
101 for (size_t iPart = 0; iPart < nPart; iPart++) {
102 auto particle = particleList->getParticle(iPart);
103 std::vector<const Particle*> selectedParticles = m_decayDescriptor.getSelectionParticles(particle);
104 int nSelected = selectedParticles.size();
105 // Hard photon must be specified by decayString
106 if (nSelected != 1) {
107 B2ERROR("You selected " << nSelected << " particle(s). Select only a hard photon");
108 break;
109 }
110 const Particle* selectedDaughterParticle = selectedParticles[0];
111 addPi0VetoEfficiencyRatios(particle, selectedDaughterParticle);
112 }
113 }
114
115}
116
118{
119 if (hardPhoton->getParticleSource() == Particle::EParticleSourceObject::c_ECLCluster
120 && hardPhoton->getPDGCode() == Const::photon.getPDGCode()) {
121 //The selected particle is photon reconstructed from ECL cluster
122 WeightInfo info = getInfo(hardPhoton);
123 for (const auto& entry : info) {
124 const std::string extraInfoName = "Pi0VetoEfficiencySystematics_" + m_mode + m_suffix + "_" + entry.first;
125 if (B->hasExtraInfo(extraInfoName)) {
126 if (B->getExtraInfo(extraInfoName) != entry.second) {
127 B2INFO("extraInfo " << extraInfoName << " has been already set and will be overwritten. Original: "
128 << B->getExtraInfo(extraInfoName) << ", New: " << entry.second);
129 B->setExtraInfo(extraInfoName, entry.second);
130 }
131 } else {
132 B->addExtraInfo(extraInfoName, entry.second);
133 }
134 }
135 } else {
136 B2WARNING("The given hard photon is not from ECL or not photon");
137 }
138}
static const ParticleType photon
photon particle
Definition Const.h:674
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
Module()
Constructor.
Definition Module.cc:30
@ 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 setExtraInfo(const std::string &name, double value)
Sets the user-defined data of given name to the given value.
Definition Particle.cc:1402
bool hasExtraInfo(const std::string &name) const
Return whether the extra info with the given name is set.
Definition Particle.cc:1351
int getPDGCode(void) const
Returns PDG code.
Definition Particle.h:465
void addExtraInfo(const std::string &name, double value)
Sets the user-defined data of given name to the given value.
Definition Particle.cc:1421
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:1374
std::vector< std::string > m_ParticleLists
input particle lists
virtual void initialize() override
Initializes the module.
virtual void event() override
Function to be executed at each event.
std::string m_decayString
Decay string to select primary photon.
WeightInfo getInfo(const Particle *particle)
Get LookUp information for the particle.
std::unique_ptr< DBObjPtr< ParticleWeightingLookUpTable > > m_ParticleWeightingLookUpTable
Pointer to the table in DB.
DecayDescriptor m_decayDescriptor
decay descriptor which specifies the primary photon
std::string m_tableName
Table name of the payloads.
Pi0VetoEfficiencySystematicsModule()
Constructor: Sets the description, the properties and the parameters of the module.
void addPi0VetoEfficiencyRatios(Particle *B, const Particle *hardPhoton)
function to add appropriate data/mc ratio weight to a particle
Type-safe access to single objects in the data store.
Definition StoreObjPtr.h:96
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.
A variable returning a floating-point value for a given Particle.
Definition Manager.h:146