Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:18:19

0001 #include "TrkrTruthTrackContainerv1.h"
0002 #include "TrkrTruthTrackv1.h"
0003 
0004 #include <g4main/PHG4Particle.h>
0005 #include <g4main/PHG4TruthInfoContainer.h>
0006 #include <g4main/PHG4VtxPoint.h>
0007 
0008 #include <phool/phool.h>
0009 
0010 #include <algorithm>
0011 #include <iostream>
0012 #include <set>
0013 
0014 void TrkrTruthTrackContainerv1::Reset()
0015 {
0016   for (auto entry : m_data)
0017   {
0018     delete entry.second;
0019   }
0020   m_data.clear();
0021 }
0022 
0023 void TrkrTruthTrackContainerv1::addTruthTrack(TrkrTruthTrack* track)
0024 {
0025   if (!track)
0026   {
0027     return;
0028   }
0029   const auto id{track->getTrackid()};
0030   if (hasTrackid(id))
0031   {
0032     std::cout << PHWHERE << "Warning, replacing existing track-id(" << id << ")" << std::endl;
0033   }
0034   m_data[id] = track;
0035 }
0036 
0037 TrkrTruthTrack* TrkrTruthTrackContainerv1::getTruthTrack(unsigned int trackid)
0038 {
0039   if (!hasTrackid(trackid))
0040   {
0041     std::cout << PHWHERE << " Asking for TrkrTruthTrack " << trackid
0042               << " which is not present. Returning empty track." << std::endl;
0043     TrkrTruthTrack* track = new TrkrTruthTrackv1();
0044     return track;
0045   }
0046   return m_data[trackid];
0047 }
0048 
0049 TrkrTruthTrack* TrkrTruthTrackContainerv1::getTruthTrack(unsigned int id, PHG4TruthInfoContainer* truth_info)
0050 {
0051   // return the track if already in m_data, otherwise make it and return the newly made track
0052   if (hasTrackid(id))
0053   {
0054     return m_data[id];
0055   }
0056   PHG4Particle* particle = /*(PHG4Particlev3*)*/ truth_info->GetParticle(id);
0057   if (particle == nullptr)
0058   {
0059     std::cout << PHWHERE << " Note: embedded track from PHG4TruthInfoContainer, id( "
0060               << id << " )without an associated PHG4Particle" << std::endl;
0061     auto current_track = new TrkrTruthTrackv1();
0062     current_track->setTrackid(id);
0063     m_data[id] = current_track;
0064     return current_track;
0065   }
0066   int vtxid = particle->get_vtx_id();
0067   PHG4VtxPoint* vtx = truth_info->GetVtx(vtxid);
0068   auto current_track = new TrkrTruthTrackv1(id, particle, vtx);
0069   m_data[id] = current_track;
0070   return current_track;
0071 }
0072 
0073 TrkrTruthTrackContainer::ConstRange TrkrTruthTrackContainerv1::getTruthTrackRange() const
0074 {
0075   return std::make_pair(m_data.begin(), m_data.end());
0076 }
0077 
0078 bool TrkrTruthTrackContainerv1::hasTrackid(unsigned int id) const
0079 {
0080   return (m_data.find(id) != m_data.end());
0081 }
0082 
0083 TrkrTruthTrackContainer::Map& TrkrTruthTrackContainerv1::getMap()
0084 {
0085   return m_data;
0086 }
0087 
0088 void TrkrTruthTrackContainerv1::identify(std::ostream& os) const
0089 {
0090   os << " TrkrTruthTrackContainer data.  Containter " << (int) m_data.size() << " tracks" << std::endl;
0091   int cnt = 0;
0092   for (auto& entry : m_data)
0093   {
0094     os << " Track(" << cnt << "): " << std::endl;
0095     entry.second->identify(os);
0096     ++cnt;
0097   }
0098 }