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/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 bool valid = m_decayDescriptor.init(m_decayString);
66 if (!valid) {
67 B2ERROR("Invalid input decay string: " << m_decayString);
68 }
69
70 if (m_threshold < 0.1 || 0.99 < m_threshold) {
71 B2ERROR("Please provide pi0veto threshold from 0.10 to 0.99 for Pi0VetoEfficiencySystematicsModule");
72 }
73
74 //Table is identified with mode and threshold
75 std::string tableName = m_tableName + "_" + m_mode + std::to_string((int)(m_threshold * 100 + 0.001));
76 m_ParticleWeightingLookUpTable = std::make_unique<DBObjPtr<ParticleWeightingLookUpTable>>(tableName);
77}
78
79
81{
82
83 for (auto& iList : m_ParticleLists) {
84 StoreObjPtr<ParticleList> particleList(iList);
85
86 //check particle List exists and has particles
87 if (!particleList) {
88 B2ERROR("ParticleList " << iList << " not found");
89 continue;
90 }
91
92 size_t nPart = particleList->getListSize();
93 for (size_t iPart = 0; iPart < nPart; iPart++) {
94 auto particle = particleList->getParticle(iPart);
95 std::vector<const Particle*> selectedParticles = m_decayDescriptor.getSelectionParticles(particle);
96 int nSelected = selectedParticles.size();
97 // Hard photon must be specified by decayString
98 if (nSelected != 1) {
99 B2ERROR("You selected " << nSelected << " particle(s). Select only a hard photon");
100 break;
101 }
102 const Particle* selectedDaughterParticle = selectedParticles[0];
103 addPi0VetoEfficiencyRatios(particle, selectedDaughterParticle);
104 }
105 }
106
107}
108
110{
111 if (hardPhoton->getParticleSource() == Particle::EParticleSourceObject::c_ECLCluster
112 && hardPhoton->getPDGCode() == Const::photon.getPDGCode()) {
113 //The selected particle is photon reconstructed from ECL cluster
114 WeightInfo info = getInfo(hardPhoton);
115 for (const auto& entry : info) {
116 const std::string extraInfoName = "Pi0VetoEfficiencySystematics_" + m_mode + m_suffix + "_" + entry.first;
117 if (B->hasExtraInfo(extraInfoName)) {
118 if (B->getExtraInfo(extraInfoName) != entry.second) {
119 B2INFO("extraInfo " << extraInfoName << " has been already set and will be overwritten. Original: "
120 << B->getExtraInfo(extraInfoName) << ", New: " << entry.second);
121 B->setExtraInfo(extraInfoName, entry.second);
122 }
123 } else {
124 B->addExtraInfo(extraInfoName, entry.second);
125 }
126 }
127 } else {
128 B2WARNING("The given hard photon is not from ECL or not photon");
129 }
130}
static const ParticleType photon
photon particle
Definition Const.h:673
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
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::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:145