ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrkrHitTruthAssocv1.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrkrHitTruthAssocv1.cc
1 
8 #include "TrkrHitTruthAssocv1.h"
9 #include "TrkrDefs.h"
10 
11 #include <g4main/PHG4HitDefs.h>
12 
13 #include <algorithm>
14 #include <ostream> // for operator<<, endl, basic_ostream, bas...
15 
16 void
18 { m_map.clear(); }
19 
20 void
21 TrkrHitTruthAssocv1::identify(std::ostream &os) const
22 {
23  os << "-----TrkrHitTruthAssocv1-----" << std::endl;
24  os << "Number of associations: " << m_map.size() << std::endl;
25 
26  for( const auto& entry : m_map )
27  {
28  int layer = TrkrDefs::getLayer(entry.first);
29  os << " hitset key: " << entry.first << " layer " << layer
30  << " hit key: " << entry.second.first
31  << " g4hit key: " << entry.second.second
32  << std::endl;
33  }
34 
35  os << "------------------------------" << std::endl;
36 
37  return;
38 }
39 
40 void
42 {
43  // the association we want is between TrkrHit and PHG4Hit, but we need to know which TrkrHitSet the TrkrHit is in
44  m_map.insert (std::make_pair(hitsetkey, std::make_pair(hitkey, g4hitkey)));
45 }
46 
47 void
49 {
50  // the association we want is between TrkrHit and PHG4Hit, but we need to know which TrkrHitSet the TrkrHit is in
51  // check if this association already exists
52  // We need all hitsets with this key
53  const auto hitsetrange = m_map.equal_range(hitsetkey);
54  if( std::any_of(
55  hitsetrange.first,
56  hitsetrange.second,
57  [&hitkey, &g4hitkey]( const MMap::value_type& pair ) { return pair.second.first == hitkey && pair.second.second == g4hitkey; } ) )
58  { return; }
59 
60  // Does not exist, create it
61  const auto assoc = std::make_pair(hitkey, g4hitkey);
62  m_map.insert(hitsetrange.second, std::make_pair(hitsetkey, std::move(assoc)));
63 }
64 
65 void
67 {
68  // remove all entries for this TrkrHit and its PHG4Hits, but we need to know which TrkrHitSet the TrkrHit is in
69  // check if this association already exists
70  // We need all hitsets with this key
71  const auto hitsetrange = m_map.equal_range(hitsetkey);
72  for( auto mapiter = hitsetrange.first; mapiter != hitsetrange.second; ++mapiter)
73  {
74  if(mapiter->second.first == hitkey)
75  {
76  m_map.erase (mapiter);
77  return;
78  }
79  }
80 
81 }
82 
83 void
84 TrkrHitTruthAssocv1::getG4Hits(const TrkrDefs::hitsetkey hitsetkey, const unsigned int hidx, MMap &temp_map) const
85 {
86  const auto hitsetrange = m_map.equal_range(hitsetkey);
87  std::copy_if( hitsetrange.first, hitsetrange.second, std::inserter( temp_map, temp_map.end() ),
88  [hidx]( MMap::const_reference pair ) { return pair.second.first == hidx; } );
89 }