Belle II Software  release-06-02-00
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 
18 using namespace Belle2;
19 using namespace Dedx;
20 
21 REG_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
66  StoreObjPtr<ParticleList> particlelist(m_strParticleList[iList]);
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 }
Extracts dE/dx information for calibration testing.
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.
virtual ~CDCDedxSkimCDSTModule()
Destructor.
Debug output for CDCDedxPID module.
Definition: CDCDedxTrack.h:25
Base class for Modules.
Definition: Module.h:72
Class to collect log likelihoods from TOP, ARICH, dEdx, ECL and KLM aimed for output to mdst includes...
Definition: PIDLikelihood.h:26
Class to store reconstructed particles.
Definition: Particle.h:74
unsigned getNDaughters(void) const
Returns number of daughter particles.
Definition: Particle.h:647
const Particle * getDaughter(unsigned i) const
Returns a pointer to the i-th daughter particle.
Definition: Particle.cc:639
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:95
Class that bundles various TrackFitResults.
Definition: Track.h:25
#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.