Belle II Software development
PhotonEfficiencySystematics.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/PhotonEfficiencySystematics/PhotonEfficiencySystematics.h>
11
12#include <analysis/dataobjects/Particle.h>
13#include <analysis/dataobjects/ParticleList.h>
14#include <analysis/VariableManager/Manager.h>
15
16#include <framework/database/DBObjPtr.h>
17#include <framework/datastore/StoreObjPtr.h>
18#include <framework/core/ModuleParam.templateDetails.h>
19
20#include <map>
21
22using namespace Belle2;
23
24//-----------------------------------------------------------------
25// Register module
26//-----------------------------------------------------------------
27
28REG_MODULE(PhotonEfficiencySystematics);
29
30//-----------------------------------------------------------------
31// Implementation
32//-----------------------------------------------------------------
33
35{
37 R"DOC(Module to include data/MC weights for photon detection efficiency. Include in your code as
38
39.. code:: python
40
41 mypath.add_module("PhotonEfficiencySystematics", particleLists=['gamma:cut'], tableName=tableName_Weight)
42
43 )DOC");
45 // Parameter definitions
46 addParam("particleLists", m_ParticleLists, "input particle lists");
47 addParam("tableName", m_tableName, "ID of table used for reweighing");
48}
49
50// Getting LookUp info for given particle in given event
52{
53 std::vector<std::string> variables = Variable::Manager::Instance().resolveCollections((
54 *m_ParticleWeightingLookUpTable.get())->getAxesNames());
55 std::map<std::string, double> values;
56 for (const auto& i_variable : variables) {
58 if (!var) {
59 B2ERROR("Variable '" << i_variable << "' is not available in Variable::Manager!");
60 }
61 values.insert(std::make_pair(i_variable, std::get<double>(var->function(particle))));
62 }
63
64 return (*m_ParticleWeightingLookUpTable.get())->getInfo(values);
65}
66
68{
69 m_ParticleWeightingLookUpTable = std::make_unique<DBObjPtr<ParticleWeightingLookUpTable>>(m_tableName);
70}
71
72
74{
75 for (auto& iList : m_ParticleLists) {
76 StoreObjPtr<ParticleList> particleList(iList);
77
78 //check particle List exists and has particles
79 if (!particleList) {
80 B2ERROR("ParticleList " << iList << " not found");
81 continue;
82 }
83
84 size_t nPart = particleList->getListSize();
85 for (size_t iPart = 0; iPart < nPart; iPart++) {
86 auto particle = particleList->getParticle(iPart);
88 }
89 }
90
91}
92
94{
95 if (particle->getParticleSource() == Particle::EParticleSourceObject::c_ECLCluster
96 && particle->getPDGCode() == Const::photon.getPDGCode()) {
97 //particle is photon reconstructed from ECL cluster
98 WeightInfo info = getInfo(particle);
99 for (const auto& entry : info) {
100 const std::string extraInfoName = m_tableName + "_" + entry.first;
101 if (particle->hasExtraInfo(extraInfoName)) {
102 if (particle->getExtraInfo(extraInfoName) != entry.second) {
103 B2INFO("extraInfo " << extraInfoName << " has been already set and will be overwritten. Original: "
104 << particle->getExtraInfo(extraInfoName) << ", New: " << entry.second);
105 particle->setExtraInfo(extraInfoName, entry.second);
106 }
107 } else {
108 particle->addExtraInfo(extraInfoName, entry.second);
109 }
110 }
111 }
112}
113
int getPDGCode() const
PDG code.
Definition Const.h:473
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
std::vector< std::string > m_ParticleLists
input particle lists
virtual void event() override
Function to be executed at each event.
WeightInfo getInfo(const Particle *particle)
Get LookUp information for the particle.
std::unique_ptr< DBObjPtr< ParticleWeightingLookUpTable > > m_ParticleWeightingLookUpTable
Pointer to the table in DB.
virtual void beginRun() override
Nothing so far.
PhotonEfficiencySystematicsModule()
Constructor: Sets the description, the properties and the parameters of the module.
void addPhotonDetectionEfficiencyRatios(Particle *particle)
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