ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ECCEFastPIDReco.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ECCEFastPIDReco.cc
1 
2 #include "ECCEFastPIDReco.h"
3 #include "ECCEFastPIDMap.h"
4 
8 
11 
12 #include <g4main/PHG4Hit.h>
14 #include <g4main/PHG4Particle.h>
16 
18 #include <phool/PHCompositeNode.h>
19 #include <phool/PHIODataNode.h>
20 #include <phool/PHNode.h> // for PHNode
21 #include <phool/PHNodeIterator.h>
22 #include <phool/PHObject.h> // for PHObject
23 #include <phool/PHRandomSeed.h>
24 #include <phool/getClass.h>
25 #include <phool/phool.h>
26 
28 
29 #include <TRandom.h>
30 
31 #include <cassert>
32 #include <iostream>
33 
34 using namespace std;
35 
36 //____________________________________________________________________________..
39  const std::string &name)
40  : SubsysReco(name), m_pidmap(map), m_PIDDetector(det) {
41  if (!map) {
42  std::cout << "ECCEFastPIDReco::ECCEFastPIDReco(): Fatal Error missing "
43  "ECCEFastPIDMap"
44  << std::endl;
45  exit(1);
46  }
47 }
48 
49 //____________________________________________________________________________..
51  if (m_pidmap)
52  delete m_pidmap;
53 }
54 
55 //____________________________________________________________________________..
57  // many fast PID import code used gRandom.
58  // Quick fix to override seed.
59  // Should switch well controlled gsl_rng
60  gRandom->SetSeed(PHRandomSeed());
61 
63 }
64 
65 //____________________________________________________________________________..
68  findNode::getClass<SvtxTrackMap>(topNode, m_TrackmapNodeName);
69  if (!m_SvtxTrackMap) {
70  cout << __PRETTY_FUNCTION__ << " " << Name()
71  << ": fatal error missing node " << m_TrackmapNodeName << endl;
73  }
74 
76  m_truthInfo =
77  findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");
78  if (!m_truthInfo) {
79  cout << __PRETTY_FUNCTION__ << " " << Name()
80  << ": PHG4TruthInfoContainer node is missing, can't collect G4 truth "
81  "particles"
82  << endl;
84  }
85 
86  if (m_matchG4Hit) {
87  m_g4hits = findNode::getClass<PHG4HitContainer>(topNode, m_G4HitNodeName);
88  if (!m_g4hits) {
89  cout << __PRETTY_FUNCTION__ << " " << Name() << ": PHG4HitContainer "
90  << m_G4HitNodeName << " node is missing, can't match to g4hits"
91  << endl;
93  }
94  }
95 
96  m_EICPIDParticleContainer = findNode::getClass<EICPIDParticleContainer>(
100 
103 
104  PHNodeIterator iter(topNode);
105  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(
106  iter.findFirst("PHCompositeNode", "DST"));
107  assert(dstNode);
108  dstNode->addNode(pid_node);
109  if (Verbosity() > 0) {
110  cout << m_EICPIDParticleMapNodeName << " node added" << endl;
111  }
112  }
113 
115 }
116 
117 //____________________________________________________________________________..
119  assert(m_SvtxTrackMap);
121 
122  if (Verbosity() >= 1) {
123  cout << __PRETTY_FUNCTION__ << " " << Name() << ": m_SvtxTrackMap = ";
125  }
126 
127  for (const auto &track_pair : *m_SvtxTrackMap) {
128  const SvtxTrack *track = track_pair.second;
129  assert(track);
130 
131  const SvtxTrack_FastSim *fasttrack =
132  dynamic_cast<const SvtxTrack_FastSim *>(track);
133 
134  if (!fasttrack) {
135  if (Verbosity()) {
136  cout << __PRETTY_FUNCTION__ << " " << Name()
137  << " : ignore none SvtxTrack_FastSim track: ";
138  track->identify();
139  }
140  } else { // process track
141 
142  assert(m_truthInfo);
143 
144  PHG4Particle *g4particle =
146  assert(g4particle);
147 
148  const int truth_pid = g4particle->get_pid();
149 
150  CLHEP::Hep3Vector momentum(g4particle->get_px(), g4particle->get_py(),
151  g4particle->get_pz());
152 
153  bool matched = false;
154  if (m_matchG4Hit) {
155  matched = false;
156 
157  // find hit in detector vol.
158  assert(m_g4hits);
159 
160  auto hit_range = m_g4hits->getHits();
161  for (auto hititer = hit_range.first; hititer != hit_range.second;
162  ++hititer) {
163  const PHG4Hit *hit = hititer->second;
164  assert(hit);
165 
166  // match first hit of track in PID detector:
167  if (hit->get_trkid() == g4particle->get_track_id()) {
168  if (Verbosity() >= 2) {
169  cout << __PRETTY_FUNCTION__ << " " << Name() << " Named "
170  << Name() << " with hits " << m_G4HitNodeName
171  << ": matching track ";
172  fasttrack->identify();
173  cout << "with particle: ";
174  g4particle->identify();
175  cout << "with hit: ";
176  hit->identify();
177  cout << "Result in momentum of " << momentum.mag()
178  << "GeV/c at eta = " << momentum.eta() << endl;
179  }
180 
181  matched = true;
182 
183  break;
184  }
185  } // for
186 
187  if (not matched) {
188  if (Verbosity() >= 2) {
189  cout << __PRETTY_FUNCTION__ << " " << Name() << " Named " << Name()
190  << " did NOT match hits in " << m_G4HitNodeName
191  << " with track ";
192  fasttrack->identify();
193  cout << "with particle: ";
194  g4particle->identify();
195  }
196  }
197  } // if (m_matchG4Hit)
198  else {
199  if (Verbosity() >= 2) {
200  cout << __PRETTY_FUNCTION__ << " " << Name() << " Named " << Name()
201  << " with hits " << m_G4HitNodeName << ": matching track ";
202  fasttrack->identify();
203  cout << "with particle: ";
204  g4particle->identify();
205  cout << "Result in momentum of " << momentum.mag()
206  << "GeV/c at eta = " << momentum.eta() << endl;
207  }
208  matched = true;
209  }
210 
211  auto pid_iter =
213  EICPIDParticle *pidparticle = pid_iter->second;
214  assert(pidparticle);
215 
216  pidparticle->set_property(EICPIDParticle::Truth_PID, truth_pid);
218  (float)momentum.mag());
220  (float)momentum.eta());
221 
222  assert(m_pidmap);
223 
224  if (matched) {
226  m_pidmap->getFastSmearLogLikelihood(truth_pid, momentum.mag(),
227  momentum.theta());
228 
229  for (const auto &pair : ll_map)
230  pidparticle->set_LogLikelyhood(pair.first, m_PIDDetector,
231  pair.second);
232  }
233 
234  if (Verbosity() >= 2) {
235  pidparticle->identify();
236  }
237  }
238  }
239 
240  if (Verbosity()) {
241  cout << __PRETTY_FUNCTION__ << " " << Name()
242  << " : done processing from trackmap ";
243  m_SvtxTrackMap->identify();
244  cout << __PRETTY_FUNCTION__ << " " << Name()
245  << " : produced EICPIDParticleContainer ";
247  }
248 
250 }
251 
252 //____________________________________________________________________________..
255 }