Belle II Software  release-08-01-10
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 #include <iostream>
12 
13 #include <framework/datastore/StoreObjPtr.h>
14 #include <framework/core/ModuleParam.templateDetails.h>
15 #include <framework/core/Environment.h>
16 #include <analysis/VariableManager/Manager.h>
17 
18 #include <map>
19 
20 using namespace Belle2;
21 
22 //-----------------------------------------------------------------
23 // Register module
24 //-----------------------------------------------------------------
25 
26 REG_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");
42  // Parameter definitions
43  addParam("particleLists", m_ParticleLists, "input particle lists");
44  addParam("tableName", m_tableName, "ID of table used for reweighing");
45 }
46 
47 // Getting LookUp info for given particle in given event
49 {
50  std::vector<std::string> variables = Variable::Manager::Instance().resolveCollections((
51  *m_ParticleWeightingLookUpTable.get())->getAxesNames());
52  std::map<std::string, double> values;
53  for (const auto& i_variable : variables) {
55  if (!var) {
56  B2ERROR("Variable '" << i_variable << "' is not available in Variable::Manager!");
57  }
58  values.insert(std::make_pair(i_variable, std::get<double>(var->function(particle))));
59  }
60 
61  return (*m_ParticleWeightingLookUpTable.get())->getInfo(values);
62 }
63 
65 {
66  m_ParticleWeightingLookUpTable = std::make_unique<DBObjPtr<ParticleWeightingLookUpTable>>(m_tableName);
67 }
68 
69 
71 {
72  for (auto& iList : m_ParticleLists) {
73  StoreObjPtr<ParticleList> particleList(iList);
74 
75  //check particle List exists and has particles
76  if (!particleList) {
77  B2ERROR("ParticleList " << iList << " not found");
78  continue;
79  }
80 
81  size_t nPart = particleList->getListSize();
82  for (size_t iPart = 0; iPart < nPart; iPart++) {
83  auto particle = particleList->getParticle(iPart);
85  }
86  }
87 
88 }
89 
91 {
92  if (particle->getParticleSource() == Particle::EParticleSourceObject::c_ECLCluster
93  && particle->getPDGCode() == Const::photon.getPDGCode()) {
94  //particle is photon reconstructed from ECL cluster
95  WeightInfo info = getInfo(particle);
96  for (const auto& entry : info) {
97  particle->addExtraInfo(m_tableName + "_" + entry.first, entry.second);
98  }
99  }
100 }
101 
int getPDGCode() const
PDG code.
Definition: Const.h:464
static const ParticleType photon
photon particle
Definition: Const.h:664
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
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: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.
REG_MODULE(arichBtest)
Register the Module.
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
Abstract base class for different kinds of events.
A variable returning a floating-point value for a given Particle.
Definition: Manager.h:146