Belle II Software development
CDCDedxSkimCDST.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#include <cdc/modules/CDCDedxSkimCDST/CDCDedxSkimCDST.h>
10
11#include <analysis/dataobjects/Particle.h>
12#include <analysis/dataobjects/ParticleList.h>
13#include <mdst/dataobjects/PIDLikelihood.h>
14#include <mdst/dataobjects/Track.h>
15
16#include <framework/datastore/SelectSubset.h>
17
18#include <unordered_set>
19
20using namespace Belle2;
21
22REG_MODULE(CDCDedxSkimCDST);
23
25{
26
27 setDescription("Extract dE/dx information for calibration development.");
28 addParam("particleLists", m_strParticleList, "Vector of ParticleLists to save", std::vector<std::string>());
29 addParam("ListsType", isRecList, "Yes for reco particle list else No ", true);
30}
31
33
35{
36
37 B2INFO("Selecting two good tracks for radiative bhabha candidates...");
38
39 // required input
40 m_dedxTracks.isRequired();
41
42 // declare the subset
43 StoreArray<CDCDedxTrack> set("CDCDedxTracks");
44 set.isRequired();
45 m_selector.registerSubset(set);
46 // m_selector.inheritAllRelations();
47
48 // build a map to relate input strings to the right particle type
49 // std::map<std::string, std::string> pdgMap = {{"pi+", "211"}, {"K+", "321"}, {"mu+", "13"}, {"e+", "11"}, {"p+", "2212"}, {"deuteron", "1000010020"}};
50
51}
52
54{
55
56 int nParticleList = m_strParticleList.size();
57 std::unordered_set<int> indicesToKeep;
58
59 // **************************************************
60 //
61 // LOOP OVER particles in the given particle lists
62 //
63 // **************************************************
64
65 for (int iList = 0; iList < nParticleList; iList++) {
66 // make sure the list exists and is not empty
68 if (!particlelist or particlelist->getListSize(true) == 0) {
69 continue;
70 }
71
72 //loop over the particles in the list and follow the links to the
73 //dE/dx information (Particle -> PIDLikelihood -> Track -> CDCDedxTrack)
74 //Gen1 used if supplied list is from FS particle and +Gen2 is used when supply reco list
75 for (unsigned int iPGen1 = 0; iPGen1 < particlelist->getListSize(true); iPGen1++) {
76
77 Particle* fPartGen1 = particlelist->getParticle(iPGen1, true);
78 if (!fPartGen1) {
79 B2WARNING("No particles in the list...");
80 continue;
81 }
82
83 if (isRecList) {
84
85 for (unsigned iPGen2 = 0; iPGen2 < fPartGen1->getNDaughters(); ++iPGen2) {
86
87 const Particle* fPartGen2 = fPartGen1->getDaughter(iPGen2);
88
89 PIDLikelihood* pid = fPartGen2->getRelatedTo<PIDLikelihood>();
90 if (!pid) {
91 B2WARNING("Searching w/ 2nd Gen >> No related PID likelihood found");
92 continue;
93 }
94
95 Track* track = pid->getRelatedFrom<Track>();
96 if (!track) {
97 B2WARNING("Searching w/ 2nd Gen >> No related Track found");
98 continue;
99 }
100
101 CDCDedxTrack* dedxTrack = track->getRelatedTo<CDCDedxTrack>();
102 if (!dedxTrack) {
103 B2WARNING("Searching w/ 2nd Gen >> No related CDCDedxTrack found");
104 continue;
105 } else {
106 indicesToKeep.insert(dedxTrack->getArrayIndex());
107 }
108 }
109
110 } else {
111
112 PIDLikelihood* pid = fPartGen1->getRelatedTo<PIDLikelihood>();
113 if (!pid) {
114 B2WARNING("No related PID likelihood found");
115 continue;
116 }
117
118 Track* track = pid->getRelatedFrom<Track>();
119 if (!track) {
120 B2WARNING("No related Track found");
121 continue;
122 }
123
124 CDCDedxTrack* dedxTrack = track->getRelatedTo<CDCDedxTrack>();
125 if (!dedxTrack) {
126 B2WARNING("No related CDCDedxTrack found");
127 continue;
128 } else {
129 indicesToKeep.insert(dedxTrack->getArrayIndex());
130 }
131
132 }
133 }
134 }
135
136 // remove tracks with no Particle association
137 auto selector = [indicesToKeep](const CDCDedxTrack * d) -> bool {
138 if (indicesToKeep.size() > 2)
139 {
140 std::cout << "More than three good tracks!" << std::endl;
141 return false;
142 }
143 int idx = d->getArrayIndex();
144 if (indicesToKeep.count(idx) == 1) return true;
145 return false;
146 };
147 m_selector.select(selector);
148}
149
151{
152 B2INFO("CDCDedxSkimCDST terminated: \n");
153}
CDCDedxSkimCDSTModule()
Default constructor.
virtual void initialize() override
Initialize the module.
virtual void event() override
Selection function to skim DataStore.
virtual void terminate() override
End of the event processing.
bool isRecList
set particle list type FS or reco particle list
virtual ~CDCDedxSkimCDSTModule()
Destructor.
SelectSubset< CDCDedxTrack > m_selector
Used to get a subset of the input array.
StoreArray< CDCDedxTrack > m_dedxTracks
Input array of CDCDedxTracks.
std::vector< std::string > m_strParticleList
Vector of ParticleLists to write out.
Debug output for CDCDedxPID module.
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
Module()
Constructor.
Definition Module.cc:30
Class to collect log likelihoods from TOP, ARICH, dEdx, ECL and KLM aimed for output to mdst includes...
Class to store reconstructed particles.
Definition Particle.h:76
unsigned getNDaughters(void) const
Returns number of daughter particles.
Definition Particle.h:747
const Particle * getDaughter(unsigned i) const
Returns a pointer to the i-th daughter particle.
Definition Particle.cc:662
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
TO * getRelatedTo(const std::string &name="", const std::string &namedRelation="") const
Get the object to which this object has a relation.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
Definition StoreArray.h:113
Type-safe access to single objects in the data store.
Definition StoreObjPtr.h:96
Class that bundles various TrackFitResults.
Definition Track.h:25
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.