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