Belle II Software development
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/datastore/StoreObjPtr.h>
12#include <framework/core/ModuleParam.templateDetails.h>
13#include <analysis/VariableManager/Manager.h>
14#include <analysis/dataobjects/ParticleList.h>
15
16#include <map>
17
18using namespace Belle2;
19
20//-----------------------------------------------------------------
21// Register module
22//-----------------------------------------------------------------
23
24REG_MODULE(Pi0VetoEfficiencySystematics);
25
26//-----------------------------------------------------------------
27// Implementation
28//-----------------------------------------------------------------
29
31{
32 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.");
34 // Parameter definitions
35 std::vector<std::string> emptylist;
36 addParam("particleLists", m_ParticleLists, "input particle lists", emptylist);
37 addParam("decayString", m_decayString, "decay string", std::string(""));
38 addParam("tableName", m_tableName, "table name of the payloads", std::string(""));
39 addParam("threshold", m_threshold, "threshold of pi0 veto", 0.);
40 addParam("mode", m_mode, "pi0 veto option name", std::string(""));
41 addParam("suffix", m_suffix, "suffix of extrainfo", std::string(""));
42}
43
44// Getting LookUp info for given hard photon in given event
46{
47 std::vector<std::string> variables = Variable::Manager::Instance().resolveCollections((
48 *m_ParticleWeightingLookUpTable.get())->getAxesNames());
49 std::map<std::string, double> values;
50 for (const auto& i_variable : variables) {
52 if (!var) {
53 B2ERROR("Variable '" << i_variable << "' is not available in Variable::Manager!");
54 }
55 values.insert(std::make_pair(i_variable, std::get<double>(var->function(particle))));
56 }
57
58 return (*m_ParticleWeightingLookUpTable.get())->getInfo(values);
59}
60
62{
64 if (!valid) {
65 B2ERROR("Invalid input decay string: " << m_decayString);
66 }
67
68 if (m_threshold < 0.1 || 0.99 < m_threshold) {
69 B2ERROR("Please provide pi0veto threshold from 0.10 to 0.99 for Pi0VetoEfficiencySystematicsModule");
70 }
71
72 //Table is identified with mode and threshold
73 std::string tableName = m_tableName + "_" + m_mode + std::to_string((int)(m_threshold * 100 + 0.001));
74 m_ParticleWeightingLookUpTable = std::make_unique<DBObjPtr<ParticleWeightingLookUpTable>>(tableName);
75}
76
77
79{
80
81 for (auto& iList : m_ParticleLists) {
82 StoreObjPtr<ParticleList> particleList(iList);
83
84 //check particle List exists and has particles
85 if (!particleList) {
86 B2ERROR("ParticleList " << iList << " not found");
87 continue;
88 }
89
90 size_t nPart = particleList->getListSize();
91 for (size_t iPart = 0; iPart < nPart; iPart++) {
92 auto particle = particleList->getParticle(iPart);
93 std::vector<const Particle*> selectedParticles = m_decayDescriptor.getSelectionParticles(particle);
94 int nSelected = selectedParticles.size();
95 // Hard photon must be specified by decayString
96 if (nSelected != 1) {
97 B2ERROR("You selected " << nSelected << " particle(s). Select only a hard photon");
98 break;
99 }
100 const Particle* selectedDaughterParticle = selectedParticles[0];
101 addPi0VetoEfficiencyRatios(particle, selectedDaughterParticle);
102 }
103 }
104
105}
106
108{
109 if (hardPhoton->getParticleSource() == Particle::EParticleSourceObject::c_ECLCluster
110 && hardPhoton->getPDGCode() == Const::photon.getPDGCode()) {
111 //The selected particle is photon reconstructed from ECL cluster
112 WeightInfo info = getInfo(hardPhoton);
113 for (const auto& entry : info) {
114 const std::string extraInfoName = "Pi0VetoEfficiencySystematics_" + m_mode + m_suffix + "_" + entry.first;
115 if (B->hasExtraInfo(extraInfoName)) {
116 if (B->getExtraInfo(extraInfoName) != entry.second) {
117 B2INFO("extraInfo " << extraInfoName << " has been already set and will be overwritten. Original: "
118 << B->getExtraInfo(extraInfoName) << ", New: " << entry.second);
119 B->setExtraInfo(extraInfoName, entry.second);
120 }
121 } else {
122 B->addExtraInfo(extraInfoName, entry.second);
123 }
124 }
125 } else {
126 B2WARNING("The given hard photon is not from ECL or not photon");
127 }
128}
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
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
int getPDGCode(void) const
Returns PDG code.
Definition: Particle.h:465
EParticleSourceObject getParticleSource() const
Returns particle source as defined with enum EParticleSourceObject.
Definition: Particle.h:489
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:95
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:145