Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SvtxTruthRecoTableEval.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SvtxTruthRecoTableEval.cc
1 
3 #include "SvtxEvalStack.h"
4 #include "SvtxTrackEval.h"
5 #include "SvtxTruthEval.h"
6 
9 #include <phool/PHDataNode.h>
10 #include <phool/PHNode.h>
11 #include <phool/PHNodeIterator.h>
12 #include <phool/PHObject.h>
13 #include <phool/getClass.h>
14 #include <phool/phool.h>
15 
16 #include <g4main/PHG4Particle.h>
18 
23 
24 #include <CLHEP/Vector/ThreeVector.h>
25 
26 #include <phool/PHCompositeNode.h>
27 
28 //____________________________________________________________________________..
30  : SubsysReco(name)
31 {
32 }
33 
34 //____________________________________________________________________________..
36 
37 //____________________________________________________________________________..
39 {
41 }
42 
43 //____________________________________________________________________________..
45 {
47  {
49  }
50 
52 }
53 
54 //____________________________________________________________________________..
56 {
57  if (!m_svtxevalstack)
58  {
59  m_svtxevalstack = std::make_unique<SvtxEvalStack>(topNode);
60  m_svtxevalstack->set_strict(false);
61  m_svtxevalstack->set_verbosity(Verbosity());
62  m_svtxevalstack->set_use_initial_vertex(true);
63  m_svtxevalstack->set_use_genfit_vertex(false);
64  m_svtxevalstack->next_event(topNode);
65  }
66  else
67  {
68  m_svtxevalstack->next_event(topNode);
69  }
70 
71  if (Verbosity() > 1)
72  {
73  std::cout << "Fill truth map " << std::endl;
74  }
75  fillTruthMap(topNode);
76 
77  if (Verbosity() > 1)
78  {
79  std::cout << "Fill reco map " << std::endl;
80  }
81  fillRecoMap(topNode);
82 
84 }
85 
86 //____________________________________________________________________________..
88 {
89  if (Verbosity() > 0)
90  {
91  std::cout << "Truth track map " << std::endl;
93  std::cout << std::endl
94  << "Reco track map " << std::endl;
96  }
98 }
99 
100 //____________________________________________________________________________..
102 {
104 }
105 
107 {
108  PHG4TruthInfoContainer *truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");
109  assert(truthinfo);
110 
111  SvtxTrackEval *trackeval = m_svtxevalstack->get_track_eval();
112  trackeval->set_verbosity(Verbosity());
113  assert(trackeval);
114 
116  if (m_scanForPrimaries)
117  {
118  range = truthinfo->GetPrimaryParticleRange();
119  }
120 
121  for (auto iter = range.first; iter != range.second; ++iter)
122  {
123  PHG4Particle *g4particle = iter->second;
124 
125  const double momentum = CLHEP::
126  Hep3Vector(g4particle->get_px(), g4particle->get_py(), g4particle->get_pz())
127  .mag();
128 
129  // only record particle above minimal momentum requirement.
130  if (momentum < m_minMomentumTruthMap)
131  {
132  continue;
133  }
134 
135  int gtrackID = g4particle->get_track_id();
136  const std::set<SvtxTrack *> &alltracks = trackeval->all_tracks_from(g4particle);
137 
138  // not to record zero associations
139  if (alltracks.size() == 0)
140  {
141  continue;
142  }
143 
145 
146  for (auto track : alltracks)
147  {
150  float clusCont = trackeval->get_nclusters_contribution(track, g4particle);
151 
152  auto iterator = recomap.find(clusCont);
153  if (iterator == recomap.end())
154  {
155  std::set<unsigned int> dumset;
156  dumset.insert(track->get_id());
157  recomap.insert(std::make_pair(clusCont, dumset));
158  }
159  else
160  {
161  iterator->second.insert(track->get_id());
162  }
163  }
164 
165  if (Verbosity() > 1)
166  {
167  std::cout << " Inserting gtrack id " << gtrackID << " with map size " << recomap.size() << std::endl;
168  }
169 
170  m_truthMap->insert(gtrackID, recomap);
171  }
172 
173  m_truthMap->setProcessed(true);
174 }
175 
177 {
178  SvtxTrackMap *trackMap = findNode::getClass<SvtxTrackMap>(topNode, "SvtxTrackMap");
179 
180  assert(trackMap);
181 
182  SvtxTrackEval *trackeval = m_svtxevalstack->get_track_eval();
183  assert(trackeval);
184 
185  for (const auto &[key, track] : *trackMap)
186  {
187  const std::set<PHG4Particle *> &allparticles = trackeval->all_truth_particles(track);
189  for (PHG4Particle *g4particle : allparticles)
190  {
191  float clusCont = trackeval->get_nclusters_contribution(track, g4particle);
192  auto iterator = truthmap.find(clusCont);
193  if (iterator == truthmap.end())
194  {
195  std::set<int> dumset;
196  dumset.insert(g4particle->get_track_id());
197  truthmap.insert(std::make_pair(clusCont, dumset));
198  }
199  else
200  {
201  iterator->second.insert(g4particle->get_track_id());
202  }
203  }
204  if (Verbosity() > 1)
205  {
206  std::cout << " Inserting track id " << key << " with truth map size " << truthmap.size() << std::endl;
207  }
208  m_recoMap->insert(key, truthmap);
209  }
210 
211  m_recoMap->setProcessed(true);
212 }
213 
215 {
216  PHNodeIterator iter(topNode);
217 
218  PHCompositeNode *dstNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "DST"));
219 
220  if (!dstNode)
221  {
222  std::cerr << "DST node is missing, quitting" << std::endl;
223  throw std::runtime_error("Failed to find DST node in SvtxTruthRecoTableEval::createNodes");
224  }
225 
226  PHCompositeNode *svtxNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "SVTX"));
227 
228  if (!svtxNode)
229  {
230  svtxNode = new PHCompositeNode("SVTX");
231  dstNode->addNode(svtxNode);
232  }
233 
234  m_truthMap = findNode::getClass<PHG4ParticleSvtxMap>(topNode, "PHG4ParticleSvtxMap");
235  if (!m_truthMap)
236  {
238  PHIODataNode<PHObject> *truthNode =
239  new PHIODataNode<PHObject>(m_truthMap, "PHG4ParticleSvtxMap", "PHObject");
240  svtxNode->addNode(truthNode);
241  }
242 
243  m_recoMap = findNode::getClass<SvtxPHG4ParticleMap>(topNode, "SvtxPHG4ParticleMap");
244  if (!m_recoMap)
245  {
247  PHIODataNode<PHObject> *recoNode =
248  new PHIODataNode<PHObject>(m_recoMap, "SvtxPHG4ParticleMap", "PHObject");
249  svtxNode->addNode(recoNode);
250  }
251 
253 }