Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrkrTruthTrackContainerv1.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrkrTruthTrackContainerv1.cc
2 #include "TrkrTruthTrackv1.h"
3 
4 #include <algorithm>
5 #include <g4main/PHG4Particle.h>
7 #include <g4main/PHG4VtxPoint.h>
8 #include <iostream>
9 #include <phool/phool.h>
10 #include <set>
11 
12 using std::endl;
13 using std::cout;
14 using std::set;
15 
17 {
18  for (auto entry : m_data)
19  {
20  delete entry.second;
21  }
22  m_data.clear();
23 }
24 
26 {
27  if (!track) return;
28  const auto id { track->getTrackid() };
29  if (hasTrackid(id)) {
30  cout << PHWHERE << "Warning, replacing existing track-id("<<id<<")" << endl;
31  }
32  m_data[id] = track;
33 }
34 
36 {
37  if (!hasTrackid(trackid)) {
38  cout << PHWHERE << " Asking for TrkrTruthTrack " << trackid
39  << " which is not present. Returning empty track." << endl;
40  TrkrTruthTrack* track = new TrkrTruthTrackv1();
41  return track;
42  }
43  return m_data[trackid];
44 }
45 
47  // return the track if already in m_data, otherwise make it and return the newly made track
48  if (hasTrackid(id)) return m_data[id];
49  PHG4Particle* particle = /*(PHG4Particlev3*)*/ truth_info->GetParticle(id);
50  if (particle == nullptr) {
51  cout << PHWHERE << " Note: embedded track from PHG4TruthInfoContainer, id( "
52  << id <<" )without an associated PHG4Particle" << endl;
53  auto current_track = new TrkrTruthTrackv1();
54  current_track->setTrackid(id);
55  m_data[id] = current_track;
56  return current_track;
57  }
58  int vtxid = particle->get_vtx_id();
59  PHG4VtxPoint* vtx = truth_info->GetVtx(vtxid);
60  auto current_track = new TrkrTruthTrackv1(id, particle, vtx) ;
61  m_data[id] = current_track;
62  return current_track;
63 }
64 
65 
67 {
68  return std::make_pair(m_data.begin(), m_data.end());
69 }
70 
71 bool TrkrTruthTrackContainerv1::hasTrackid(unsigned int id) const
72 {
73  return (m_data.find(id) != m_data.end());
74 }
75 
77 {
78  return m_data;
79 }
80 
81 void TrkrTruthTrackContainerv1::identify(std::ostream& os) const
82 {
83  os << " TrkrTruthTrackContainer data. Containter " << (int)m_data.size() << " tracks" << std::endl;
84  int cnt = 0;
85  for (auto& entry : m_data)
86  {
87  os << " Track(" << cnt << "): " << std::endl;
88  entry.second->identify(os);
89  ++cnt;
90  }
91 }