Belle II Software light-2406-ragdoll
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#include <iostream>
11
12#include <framework/datastore/StoreObjPtr.h>
13#include <framework/core/ModuleParam.templateDetails.h>
14#include <framework/core/Environment.h>
15#include <analysis/VariableManager/Manager.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.");
35 // Parameter definitions
36 std::vector<std::string> emptylist;
37 addParam("particleLists", m_ParticleLists, "input particle lists", emptylist);
38 addParam("decayString", m_decayString, "decay string", std::string(""));
39 addParam("tableName", m_tableName, "table name of the payloads", std::string(""));
40 addParam("threshold", m_threshold, "threshold of pi0 veto", 0.);
41 addParam("mode", m_mode, "pi0 veto option name", std::string(""));
42 addParam("suffix", m_suffix, "suffix of extrainfo", std::string(""));
43}
44
45// Getting LookUp info for given hard photon in given event
47{
48 std::vector<std::string> variables = Variable::Manager::Instance().resolveCollections((
49 *m_ParticleWeightingLookUpTable.get())->getAxesNames());
50 std::map<std::string, double> values;
51 for (const auto& i_variable : variables) {
53 if (!var) {
54 B2ERROR("Variable '" << i_variable << "' is not available in Variable::Manager!");
55 }
56 values.insert(std::make_pair(i_variable, std::get<double>(var->function(particle))));
57 }
58
59 return (*m_ParticleWeightingLookUpTable.get())->getInfo(values);
60}
61
63{
65 if (!valid) {
66 B2ERROR("Invalid input decay string: " << m_decayString);
67 }
68
69 if (m_threshold < 0.1 || 0.99 < m_threshold) {
70 B2ERROR("Please provide pi0veto threshold from 0.10 to 0.99 for Pi0VetoEfficiencySystematicsModule");
71 }
72
73 //Table is identified with mode and threshold
74 std::string tableName = m_tableName + "_" + m_mode + std::to_string((int)(m_threshold * 100 + 0.001));
75 m_ParticleWeightingLookUpTable = std::make_unique<DBObjPtr<ParticleWeightingLookUpTable>>(tableName);
76}
77
78
80{
81
82 for (auto& iList : m_ParticleLists) {
83 StoreObjPtr<ParticleList> particleList(iList);
84
85 //check particle List exists and has particles
86 if (!particleList) {
87 B2ERROR("ParticleList " << iList << " not found");
88 continue;
89 }
90
91 size_t nPart = particleList->getListSize();
92 for (size_t iPart = 0; iPart < nPart; iPart++) {
93 auto particle = particleList->getParticle(iPart);
94 std::vector<const Particle*> selectedParticles = m_decayDescriptor.getSelectionParticles(particle);
95 int nSelected = selectedParticles.size();
96 // Hard photon must be specified by decayString
97 if (nSelected != 1) {
98 B2ERROR("You selected " << nSelected << " particle(s). Select only a hard photon");
99 break;
100 }
101 const Particle* selectedDaughterParticle = selectedParticles[0];
102 addPi0VetoEfficiencyRatios(particle, selectedDaughterParticle);
103 }
104 }
105
106}
107
109{
110 if (hardPhoton->getParticleSource() == Particle::EParticleSourceObject::c_ECLCluster
111 && hardPhoton->getPDGCode() == Const::photon.getPDGCode()) {
112 //The selected particle is photon reconstructed from ECL cluster
113 WeightInfo info = getInfo(hardPhoton);
114 for (const auto& entry : info) {
115 const std::string extraInfoName = "Pi0VetoEfficiencySystematics_" + m_mode + m_suffix + "_" + entry.first;
116 if (B->hasExtraInfo(extraInfoName)) {
117 if (B->getExtraInfo(extraInfoName) != entry.second) {
118 B2INFO("extraInfo " << extraInfoName << " has been already set and will be overwritten. Original: "
119 << B->getExtraInfo(extraInfoName) << ", New: " << entry.second);
120 B->setExtraInfo(extraInfoName, entry.second);
121 }
122 } else {
123 B->addExtraInfo(extraInfoName, entry.second);
124 }
125 }
126 } else {
127 B2WARNING("The given hard photon is not from ECL or not photon");
128 }
129}
int getPDGCode() const
PDG code.
Definition: Const.h:473
static const ParticleType photon
photon particle
Definition: Const.h:673
bool init(const std::string &str)
Initialise the DecayDescriptor from given string.
std::vector< const Particle * > getSelectionParticles(const Particle *particle)
Get a vector of pointers with selected daughters in the decay tree.
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
Class to store reconstructed particles.
Definition: Particle.h:75
void setExtraInfo(const std::string &name, double value)
Sets the user-defined data of given name to the given value.
Definition: Particle.cc:1317
bool hasExtraInfo(const std::string &name) const
Return whether the extra info with the given name is set.
Definition: Particle.cc:1266
int getPDGCode(void) const
Returns PDG code.
Definition: Particle.h:454
void addExtraInfo(const std::string &name, double value)
Sets the user-defined data of given name to the given value.
Definition: Particle.cc:1336
EParticleSourceObject getParticleSource() const
Returns particle source as defined with enum EParticleSourceObject.
Definition: Particle.h:478
double getExtraInfo(const std::string &name) const
Return given value if set.
Definition: Particle.cc:1289
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::string m_suffix
Suffix of extrainfo name.
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:179
const Var * getVariable(std::string name)
Get the variable belonging to the given key.
Definition: Manager.cc:57
static Manager & Instance()
get singleton instance.
Definition: Manager.cc:25
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:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
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:146