Typedefs | Functions
TruthMatchUtils Namespace Reference

Typedefs

typedef int G4ID
 
typedef float EDeposit
 
typedef std::map< G4ID, EDepositIDToEDepositMap
 

Functions

bool Valid (const G4ID g4ID) noexcept
 Test whether a G4ID returned by the TruthMatchUtils functions is valid. More...
 
G4ID TrueParticleID (detinfo::DetectorClocksData const &clockData, const art::Ptr< recob::Hit > &pHit, const bool rollupUnsavedIDs)
 The G4 ID of the true particle which deposits the most energy in the recob::Hit. More...
 
G4ID TrueParticleIDFromTotalTrueEnergy (detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit >> &pHits, const bool rollupUnsavedIDs)
 The G4 ID of the true particle which deposits the most energy in a vector of recob::Hit. More...
 
G4ID TrueParticleIDFromTotalRecoCharge (detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit >> &pHits, const bool rollupUnsavedIDs)
 The G4 ID of the true particle whose matched hits have produced the largest amount of reconstructed charge in a recob::Hit vector. More...
 
G4ID TrueParticleIDFromTotalRecoHits (detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit >> &pHits, const bool rollupUnsavedIDs)
 The G4 ID of the true particle who has been truth-matched to the most hits in a recob::Hit vector. More...
 
void FillG4IDToEnergyDepositMap (IDToEDepositMap &idToEDepMap, detinfo::DetectorClocksData const &clockData, const art::Ptr< recob::Hit > &pHit, const bool rollupUnsavedIDs)
 Fill an energy deposition map (maps G4 ID to true energy deposition) for a recob::Hit. More...
 

Typedef Documentation

Definition at line 28 of file TruthMatchUtils.h.

typedef int TruthMatchUtils::G4ID

Definition at line 27 of file TruthMatchUtils.h.

Definition at line 29 of file TruthMatchUtils.h.

Function Documentation

void TruthMatchUtils::FillG4IDToEnergyDepositMap ( IDToEDepositMap idToEDepMap,
detinfo::DetectorClocksData const &  clockData,
const art::Ptr< recob::Hit > &  pHit,
const bool  rollupUnsavedIDs 
)

Fill an energy deposition map (maps G4 ID to true energy deposition) for a recob::Hit.

Parameters
idToEDepMapthe energy deposition map to be filled
pHitthe recob::Hit to be assessed
rollupUnsavedIDswhether to squash energy deposits for non-saved G4 particles (e.g. shower secondaries) its saved ancestor particle

Definition at line 168 of file TruthMatchUtils.cc.

172 {
174  const std::vector<sim::TrackIDE> trackIDEs(btServ->HitToTrackIDEs(clockData, pHit));
175  if (trackIDEs.empty()) return;
176 
177  for (const sim::TrackIDE& trackIDE : trackIDEs) {
178  const G4ID g4ID(
179  static_cast<G4ID>(rollupUnsavedIDs ? std::abs(trackIDE.trackID) : trackIDE.trackID));
180  const EDeposit eDep(static_cast<EDeposit>(trackIDE.energy));
181  auto [iterator, inserted] = idToEDepMap.try_emplace(g4ID, eDep);
182  if (!inserted) iterator->second += eDep;
183  }
184 
185  if (idToEDepMap.empty()) {
187  << "TruthMatchUtils::FillG4IDToEnergyDepositMap did not fill the IDToEDepositMap map (map "
188  "size == "
189  << idToEDepMap.size() << ")."
190  << " The sim::TrackIDE vector size is " << trackIDEs.size()
191  << ". The IDToEDepositMap should not be empty when the"
192  << " sim::TrackIDE vector is also not empty. Something has gone wrong.";
193  }
194 
195  return;
196 }
intermediate_table::iterator iterator
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
T abs(T value)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
Ionization energy from a Geant4 track.
Definition: SimChannel.h:25
TruthMatchUtils::G4ID TruthMatchUtils::TrueParticleID ( detinfo::DetectorClocksData const &  clockData,
const art::Ptr< recob::Hit > &  pHit,
const bool  rollupUnsavedIDs 
)

The G4 ID of the true particle which deposits the most energy in the recob::Hit.

Parameters
pHitthe recob::Hit to be assessed
rollupUnsavedIDswhether to squash energy deposits for non-saved G4 particles (e.g. shower secondaries) its saved ancestor particle
Returns
the ID of the G4 particle

Definition at line 65 of file TruthMatchUtils.cc.

68 {
69  IDToEDepositMap idToEDepMap;
70  TruthMatchUtils::FillG4IDToEnergyDepositMap(idToEDepMap, clockData, pHit, rollupUnsavedIDs);
71  if (idToEDepMap.empty()) return kInvalidG4ID;
72 
73  return MaxEDepElementInMap(idToEDepMap)->first;
74 }
std::map< G4ID, EDeposit > IDToEDepositMap
void FillG4IDToEnergyDepositMap(IDToEDepositMap &idToEDepMap, detinfo::DetectorClocksData const &clockData, const art::Ptr< recob::Hit > &pHit, const bool rollupUnsavedIDs)
Fill an energy deposition map (maps G4 ID to true energy deposition) for a recob::Hit.
TruthMatchUtils::G4ID TruthMatchUtils::TrueParticleIDFromTotalRecoCharge ( detinfo::DetectorClocksData const &  clockData,
const std::vector< art::Ptr< recob::Hit >> &  pHits,
const bool  rollupUnsavedIDs 
)

The G4 ID of the true particle whose matched hits have produced the largest amount of reconstructed charge in a recob::Hit vector.

Parameters
pHitsthe recob::Hit vector to be assessed
rollupUnsavedIDswhether to squash energy deposits for non-saved G4 particles (e.g. shower secondaries) its saved ancestor particle
Returns
the ID of the G4 particle

Definition at line 95 of file TruthMatchUtils.cc.

98 {
99  IDToEDepositMap idToChargeDepMap;
100  for (const art::Ptr<recob::Hit>& pHit : pHits) {
101  const G4ID g4ID(TruthMatchUtils::TrueParticleID(clockData, pHit, rollupUnsavedIDs));
102  const EDeposit recoCharge(static_cast<EDeposit>(pHit->Integral()));
103  auto [iterator, inserted] = idToChargeDepMap.try_emplace(g4ID, recoCharge);
104  if (!inserted) iterator->second += recoCharge;
105  }
106 
107  if (idToChargeDepMap.empty()) return kInvalidG4ID;
108 
109  return MaxEDepElementInMap(idToChargeDepMap)->first;
110 }
intermediate_table::iterator iterator
G4ID TrueParticleID(detinfo::DetectorClocksData const &clockData, const art::Ptr< recob::Hit > &pHit, const bool rollupUnsavedIDs)
The G4 ID of the true particle which deposits the most energy in the recob::Hit.
std::map< G4ID, EDeposit > IDToEDepositMap
TruthMatchUtils::G4ID TruthMatchUtils::TrueParticleIDFromTotalRecoHits ( detinfo::DetectorClocksData const &  clockData,
const std::vector< art::Ptr< recob::Hit >> &  pHits,
const bool  rollupUnsavedIDs 
)

The G4 ID of the true particle who has been truth-matched to the most hits in a recob::Hit vector.

Parameters
pHitsthe recob::Hit vector to be assessed
rollupUnsavedIDswhether to squash energy deposits for non-saved G4 particles (e.g. shower secondaries) its saved ancestor particle
Returns
the ID of the G4 particle

Definition at line 115 of file TruthMatchUtils.cc.

118 {
119  std::map<G4ID, unsigned int> idToHitCountMap;
120  for (const art::Ptr<recob::Hit>& pHit : pHits) {
121  const G4ID g4ID(TruthMatchUtils::TrueParticleID(clockData, pHit, rollupUnsavedIDs));
122  auto [iterator, inserted] = idToHitCountMap.try_emplace(g4ID, 1);
123  if (!(inserted)) iterator->second++;
124  }
125 
126  if (idToHitCountMap.empty()) return kInvalidG4ID;
127 
128  std::map<unsigned int, std::vector<G4ID>> hitCountToIDMap;
129  for (auto const& [g4ID, hitCount] : idToHitCountMap) {
130  auto [iterator, inserted] = hitCountToIDMap.try_emplace(hitCount, std::vector<G4ID>{g4ID});
131  if (!inserted) iterator->second.emplace_back(g4ID);
132  }
133 
134  if (hitCountToIDMap.empty()) {
136  << "TruthMatchUtils::TrueParticleIDFromTotalRecoHits - Did not fill the hit count to g4 ID "
137  "vector map"
138  << "(map size == " << hitCountToIDMap.size() << ")."
139  << " The G4 ID to hit count map size is " << idToHitCountMap.size()
140  << ". The hit count to G4 ID vector map should not be empty in this case."
141  << " Something has gone wrong.";
142  }
143 
144  std::map<unsigned int, std::vector<G4ID>>::const_reverse_iterator lastElementIt(
145  hitCountToIDMap.rbegin());
146  unsigned int nMaxContributingIDs(lastElementIt->second.size());
147 
148  if (0 == nMaxContributingIDs) {
150  << "TruthMatchUtils::TrueParticleIDFromTotalRecoHits - Counted a max number of contributing "
151  "hits ("
152  << lastElementIt->first << " hits) but did not find any G4 IDs. Something has gone wrong.";
153  }
154  else if (1 < nMaxContributingIDs) {
155  mf::LogInfo("TruthMatchUtils::TrueParticleIDFromTotalRecoHits")
156  << "There are " << nMaxContributingIDs
157  << " particles which tie for highest number of contributing hits (" << lastElementIt->first
158  << " hits). Using TruthMatchUtils::TrueParticleIDFromTotalTrueEnergy instead." << std::endl;
159  return TruthMatchUtils::TrueParticleIDFromTotalTrueEnergy(clockData, pHits, rollupUnsavedIDs);
160  }
161 
162  return lastElementIt->second.front();
163 }
intermediate_table::iterator iterator
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
G4ID TrueParticleID(detinfo::DetectorClocksData const &clockData, const art::Ptr< recob::Hit > &pHit, const bool rollupUnsavedIDs)
The G4 ID of the true particle which deposits the most energy in the recob::Hit.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
G4ID TrueParticleIDFromTotalTrueEnergy(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit >> &pHits, const bool rollupUnsavedIDs)
The G4 ID of the true particle which deposits the most energy in a vector of recob::Hit.
QTextStream & endl(QTextStream &s)
TruthMatchUtils::G4ID TruthMatchUtils::TrueParticleIDFromTotalTrueEnergy ( detinfo::DetectorClocksData const &  clockData,
const std::vector< art::Ptr< recob::Hit >> &  pHits,
const bool  rollupUnsavedIDs 
)

The G4 ID of the true particle which deposits the most energy in a vector of recob::Hit.

Parameters
pHitsthe recob::Hit vector to be assessed
rollupUnsavedIDswhether to squash energy deposits for non-saved G4 particles (e.g. shower secondaries) its saved ancestor particle
Returns
the ID of the G4 particle

Definition at line 79 of file TruthMatchUtils.cc.

82 {
83  IDToEDepositMap idToEDepMap;
84  for (const art::Ptr<recob::Hit>& pHit : pHits)
85  TruthMatchUtils::FillG4IDToEnergyDepositMap(idToEDepMap, clockData, pHit, rollupUnsavedIDs);
86 
87  if (idToEDepMap.empty()) return kInvalidG4ID;
88 
89  return MaxEDepElementInMap(idToEDepMap)->first;
90 }
std::map< G4ID, EDeposit > IDToEDepositMap
void FillG4IDToEnergyDepositMap(IDToEDepositMap &idToEDepMap, detinfo::DetectorClocksData const &clockData, const art::Ptr< recob::Hit > &pHit, const bool rollupUnsavedIDs)
Fill an energy deposition map (maps G4 ID to true energy deposition) for a recob::Hit.
bool TruthMatchUtils::Valid ( const G4ID  g4ID)
noexcept

Test whether a G4ID returned by the TruthMatchUtils functions is valid.

Parameters
g4IDthe G4ID to be tested
Returns
validity bool

Definition at line 57 of file TruthMatchUtils.cc.

58 {
59  return kInvalidG4ID != g4ID;
60 }