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 <reconstruction/modules/CDCDedxSkimCDST/CDCDedxSkimCDST.h>
10
11#include <mdst/dataobjects/Track.h>
12#include <mdst/dataobjects/PIDLikelihood.h>
13
14#include <framework/datastore/SelectSubset.h>
15
16#include <unordered_set>
17
18using namespace Belle2;
19using namespace Dedx;
20
21REG_MODULE(CDCDedxSkimCDST);
22
24{
25
26 setDescription("Extract dE/dx information for calibration development.");
27 addParam("particleLists", m_strParticleList, "Vector of ParticleLists to save", std::vector<std::string>());
28 addParam("ListsType", isRecList, "Yes for reco particle list else No ", true);
29}
30
32
34{
35
36 B2INFO("Selecting two good tracks for radiative bhabha candidates...");
37
38 // required input
39 m_dedxTracks.isRequired();
40
41 // declare the subset
42 StoreArray<CDCDedxTrack> set("CDCDedxTracks");
43 set.isRequired();
44 m_selector.registerSubset(set);
45 // m_selector.inheritAllRelations();
46
47 // build a map to relate input strings to the right particle type
48 // std::map<std::string, std::string> pdgMap = {{"pi+", "211"}, {"K+", "321"}, {"mu+", "13"}, {"e+", "11"}, {"p+", "2212"}, {"deuteron", "1000010020"}};
49
50}
51
53{
54
55 int nParticleList = m_strParticleList.size();
56 std::unordered_set<int> indicesToKeep;
57
58 // **************************************************
59 //
60 // LOOP OVER particles in the given particle lists
61 //
62 // **************************************************
63
64 for (int iList = 0; iList < nParticleList; iList++) {
65 // make sure the list exists and is not empty
67 if (!particlelist or particlelist->getListSize(true) == 0) {
68 continue;
69 }
70
71 //loop over the particles in the list and follow the links to the
72 //dE/dx information (Particle -> PIDLikelihood -> Track -> CDCDedxTrack)
73 //Gen1 used if supplied list is from FS particle and +Gen2 is used when supply reco list
74 for (unsigned int iPGen1 = 0; iPGen1 < particlelist->getListSize(true); iPGen1++) {
75
76 Particle* fPartGen1 = particlelist->getParticle(iPGen1, true);
77 if (!fPartGen1) {
78 B2WARNING("No particles in the list...");
79 continue;
80 }
81
82 if (isRecList) {
83
84 for (unsigned iPGen2 = 0; iPGen2 < fPartGen1->getNDaughters(); ++iPGen2) {
85
86 const Particle* fPartGen2 = fPartGen1->getDaughter(iPGen2);
87
88 PIDLikelihood* pid = fPartGen2->getRelatedTo<PIDLikelihood>();
89 if (!pid) {
90 B2WARNING("Searching w/ 2nd Gen >> No related PID likelihood found");
91 continue;
92 }
93
94 Track* track = pid->getRelatedFrom<Track>();
95 if (!track) {
96 B2WARNING("Searching w/ 2nd Gen >> No related Track found");
97 continue;
98 }
99
100 CDCDedxTrack* dedxTrack = track->getRelatedTo<CDCDedxTrack>();
101 if (!dedxTrack) {
102 B2WARNING("Searching w/ 2nd Gen >> No related CDCDedxTrack found");
103 continue;
104 } else {
105 indicesToKeep.insert(dedxTrack->getArrayIndex());
106 }
107 }
108
109 } else {
110
111 PIDLikelihood* pid = fPartGen1->getRelatedTo<PIDLikelihood>();
112 if (!pid) {
113 B2WARNING("No related PID likelihood found");
114 continue;
115 }
116
117 Track* track = pid->getRelatedFrom<Track>();
118 if (!track) {
119 B2WARNING("No related Track found");
120 continue;
121 }
122
123 CDCDedxTrack* dedxTrack = track->getRelatedTo<CDCDedxTrack>();
124 if (!dedxTrack) {
125 B2WARNING("No related CDCDedxTrack found");
126 continue;
127 } else {
128 indicesToKeep.insert(dedxTrack->getArrayIndex());
129 }
130
131 }
132 }
133 }
134
135 // remove tracks with no Particle association
136 auto selector = [indicesToKeep](const CDCDedxTrack * d) -> bool {
137 if (indicesToKeep.size() > 2)
138 {
139 std::cout << "More than three good tracks!" << std::endl;
140 return false;
141 }
142 int idx = d->getArrayIndex();
143 if (indicesToKeep.count(idx) == 1) return true;
144 return false;
145 };
146 m_selector.select(selector);
147}
148
150{
151 B2INFO("CDCDedxSkimCDST terminated: \n");
152}
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.
Definition: CDCDedxTrack.h:25
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 collect log likelihoods from TOP, ARICH, dEdx, ECL and KLM aimed for output to mdst includes...
Definition: PIDLikelihood.h:29
Class to store reconstructed particles.
Definition: Particle.h:75
unsigned getNDaughters(void) const
Returns number of daughter particles.
Definition: Particle.h:727
const Particle * getDaughter(unsigned i) const
Returns a pointer to the i-th daughter particle.
Definition: Particle.cc:631
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:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.