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