Belle II Software  release-05-02-19
TrackingSystematics.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2020 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Sasha Glazov *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 // Own include
12 #include <analysis/modules/TrackingSystematics/TrackingSystematics.h>
13 
14 // dataobjects
15 #include <analysis/dataobjects/Particle.h>
16 #include <analysis/dataobjects/ParticleList.h>
17 
18 #include <framework/datastore/StoreObjPtr.h>
19 
20 #include <map>
21 #include <TRandom.h>
22 
23 using namespace Belle2;
24 
25 REG_MODULE(TrackingEfficiency);
26 REG_MODULE(TrackingMomentum);
27 
29 {
31  R"DOC(Module to remove tracks from the lists at random. Include in your code as
32 
33  .. code:: python
34 
35  mypath.add_module("TrackingEfficiency", particleLists=['pi+:cut'], frac=0.01)
36 
37 The module modifies the input particleLists by randomly removing tracks with the probability frac.
38 
39  )DOC");
40  // Parameter definitions
41  addParam("particleLists", m_ParticleLists, "input particle lists");
42  addParam("frac", m_frac, "probability to remove the particle", 0.0);
43 }
44 
46 {
47  // map from mdstIndex to decision
48  std::map <unsigned, bool> indexToRemove;
49 
50  // determine list of mdst tracks:
51  for (auto& iList : m_ParticleLists) {
52  StoreObjPtr<ParticleList> particleList(iList);
53  //check particle List exists and has particles
54  if (!particleList) {
55  B2ERROR("ParticleList " << iList << " not found");
56  continue;
57  }
58 
59  if (!Const::chargedStableSet.contains(Const::ParticleType(abs(particleList->getPDGCode())))) {
60  B2ERROR("The provided particlelist " << iList << " does not contain track-based particles.");
61  }
62 
63  std::vector<unsigned int> toRemove;
64  size_t nPart = particleList->getListSize();
65  for (size_t iPart = 0; iPart < nPart; iPart++) {
66  auto particle = particleList->getParticle(iPart);
67  unsigned mdstIndex = particle->getMdstArrayIndex();
68  bool remove;
69  if (indexToRemove.find(mdstIndex) != indexToRemove.end()) {
70  // found, use entry
71  remove = indexToRemove.at(mdstIndex);
72  } else {
73  // not found, generate and store it
74  auto prob = gRandom->Uniform();
75  remove = prob < m_frac;
76  indexToRemove.insert(std::pair{mdstIndex, remove});
77  }
78  if (remove) toRemove.push_back(particle->getArrayIndex());
79  }
80  particleList->removeParticles(toRemove);
81  }
82 }
83 
85 {
86  setDescription(
87  R"DOC(Module to modify momentum of tracks from the lists. Include in your code as
88 
89  .. code:: python
90 
91  mypath.add_module("TrackingMomentum", particleLists=['pi+:cut'], scale=0.999)
92 
93 The module modifies the input particleLists by scaling track momenta as given by the parameter scale
94 
95  )DOC");
96  // Parameter definitions
97  addParam("particleLists", m_ParticleLists, "input particle lists");
98  addParam("scale", m_scale, "scale factor to be applied to 3-momentum", 0.999);
99 }
100 
102 {
103  for (auto& iList : m_ParticleLists) {
104  StoreObjPtr<ParticleList> particleList(iList);
105 
106  //check particle List exists and has particles
107  if (!particleList) {
108  B2ERROR("ParticleList " << iList << " not found");
109  continue;
110  }
111 
112  if (!Const::chargedStableSet.contains(Const::ParticleType(abs(particleList->getPDGCode())))) {
113  B2ERROR("The provided particlelist " << iList << " does not contain track-based particles.");
114  }
115 
116  size_t nPart = particleList->getListSize();
117  for (size_t iPart = 0; iPart < nPart; iPart++) {
118  auto particle = particleList->getParticle(iPart);
119 
120  double m = particle->getMass();
121  TVector3 p = m_scale * particle->getMomentum();
122  double e = sqrt(p.Mag2() + m * m);
123  particle->set4Vector(TLorentzVector(p, e));
124  }
125  }
126 }
Belle2::TrackingMomentumModule::m_ParticleLists
std::vector< std::string > m_ParticleLists
input particle lists
Definition: TrackingSystematics.h:75
Belle2::TrackingMomentumModule::event
virtual void event() override
Function to be executed at each event.
Definition: TrackingSystematics.cc:85
Belle2::TrackingEfficiencyModule::m_ParticleLists
std::vector< std::string > m_ParticleLists
input particle lists
Definition: TrackingSystematics.h:52
prepareAsicCrosstalkSimDB.e
e
aux.
Definition: prepareAsicCrosstalkSimDB.py:53
Belle2::Module::setDescription
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:216
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::TrackingEfficiencyModule::m_frac
double m_frac
fraction of particles to be removed from the particlelist
Definition: TrackingSystematics.h:54
Belle2::Const::chargedStableSet
static const ParticleSet chargedStableSet
set of charged stable particles
Definition: Const.h:494
Belle2::TrackingMomentumModule::TrackingMomentumModule
TrackingMomentumModule()
Constructor: Sets the description, the properties and the parameters of the module.
Definition: TrackingSystematics.cc:76
Belle2::TrackingMomentumModule::m_scale
double m_scale
input momentum scale modifier
Definition: TrackingSystematics.h:77
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::Module::addParam
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:562
Belle2::Const::ParticleType
The ParticleType class for identifying different particle types.
Definition: Const.h:284
Belle2::TrackingEfficiencyModule::TrackingEfficiencyModule
TrackingEfficiencyModule()
Constructor: Sets the description, the properties and the parameters of the module.
Definition: TrackingSystematics.cc:28
Belle2::TrackingEfficiencyModule::event
virtual void event() override
Function to be executed at each event.
Definition: TrackingSystematics.cc:37