Belle II Software development
TrackingEfficiency.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/TrackingSystematics/TrackingEfficiency.h>
11
12#include <framework/datastore/StoreObjPtr.h>
13#include <framework/core/ModuleParam.templateDetails.h>
14#include <analysis/dataobjects/ParticleList.h>
15
16#include <TRandom.h>
17#include <Math/Vector4D.h>
18
19#include <map>
20#include <utility>
21
22using namespace Belle2;
23
24REG_MODULE(TrackingEfficiency);
25
27{
29 R"DOC(Module to remove tracks from the lists at random. Include in your code as
30
31.. code:: python
32
33 mypath.add_module("TrackingEfficiency", particleLists=['pi+:cut'], frac=0.01)
34
35The module modifies the input particleLists by randomly removing tracks with the probability frac.
37 )DOC");
39 // Parameter definitions
40 addParam("particleLists", m_ParticleLists, "input particle lists");
41 addParam("frac", m_frac, "probability to remove the particle", 0.0);
42}
43
45{
46 // map from mdstSource to decision
47 std::map <int, bool> sourceToRemove;
48
49 // determine list of mdst tracks:
50 for (auto& iList : m_ParticleLists) {
51 StoreObjPtr<ParticleList> particleList(iList);
52 //check particle List exists and has particles
53 if (!particleList) {
54 B2ERROR("ParticleList " << iList << " not found");
55 continue;
56 }
57
58 if (!Const::chargedStableSet.contains(Const::ParticleType(abs(particleList->getPDGCode())))) {
59 B2ERROR("The provided particlelist " << iList << " does not contain track-based particles.");
60 }
61
62 std::vector<unsigned int> toRemove;
63 size_t nPart = particleList->getListSize();
64 for (size_t iPart = 0; iPart < nPart; iPart++) {
65 auto particle = particleList->getParticle(iPart);
66 unsigned mdstSource = particle->getMdstSource();
67 bool remove;
68 if (sourceToRemove.find(mdstSource) != sourceToRemove.end()) {
69 // found, use entry
70 remove = sourceToRemove.at(mdstSource);
71 } else {
72 // not found, generate and store it
73 auto prob = gRandom->Uniform();
74 remove = prob < m_frac;
75 sourceToRemove.insert(std::pair{mdstSource, remove});
76 }
77 if (remove) toRemove.push_back(particle->getArrayIndex());
78 }
79 particleList->removeParticles(toRemove);
80 }
81}
82
The ParticleType class for identifying different particle types.
Definition Const.h:408
static const ParticleSet chargedStableSet
set of charged stable particles
Definition Const.h:618
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
Type-safe access to single objects in the data store.
Definition StoreObjPtr.h:96
std::vector< std::string > m_ParticleLists
input particle lists
void event() override
Function to be executed at each event.
double m_frac
fraction of particles to be removed from the particlelist
TrackingEfficiencyModule()
Constructor: Sets the description, the properties and the parameters of 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: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.