All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
truth::MCTruthAssociations Class Reference

Obtains truth matching by using hit <–> MCParticle associations. More...

#include <MCTruthAssociations.h>

Classes

struct  HitPartAssnsStruct
 

Public Member Functions

 MCTruthAssociations (fhicl::ParameterSet const &config)
 
void setup (const HitParticleAssociationsVec &, const MCParticleVec &, const MCTruthAssns &, const geo::GeometryCore &)
 
const MCTruthParticleListgetParticleList () const
 
const simb::MCParticle * TrackIDToParticle (int const &id) const
 
const simb::MCParticle * TrackIDToMotherParticle (int const &id) const
 
const art::Ptr< simb::MCTruth > & TrackIDToMCTruth (int const &id) const
 
const art::Ptr< simb::MCTruth > & ParticleToMCTruth (const simb::MCParticle *p) const
 
std::vector< const
simb::MCParticle * > 
MCTruthToParticles (art::Ptr< simb::MCTruth > const &mct) const
 
const MCTruthTruthVecMCTruthVector () const
 
std::vector< TrackIDEHitToTrackID (const recob::Hit *) const
 
std::vector< TrackIDEHitToTrackID (art::Ptr< recob::Hit > const &) const
 
const std::vector< std::vector
< art::Ptr< recob::Hit > > > 
TrackIDsToHits (std::vector< art::Ptr< recob::Hit >> const &, std::vector< int > const &) const
 
std::vector< TrackIDEHitToEveID (art::Ptr< recob::Hit > const &hit) const
 
std::vector< double > HitToXYZ (art::Ptr< recob::Hit > const &hit) const
 
std::vector< double > SpacePointHitsToXYZ (art::PtrVector< recob::Hit > const &hits) const
 
double HitCollectionPurity (std::set< int >, std::vector< art::Ptr< recob::Hit > > const &) const
 
double HitCollectionEfficiency (std::set< int >, std::vector< art::Ptr< recob::Hit > > const &, std::vector< art::Ptr< recob::Hit > > const &, geo::View_t const &) const
 
double HitChargeCollectionPurity (std::set< int >, std::vector< art::Ptr< recob::Hit > > const &) const
 
double HitChargeCollectionEfficiency (std::set< int >, std::vector< art::Ptr< recob::Hit > > const &, std::vector< art::Ptr< recob::Hit > > const &, geo::View_t const &) const
 
std::set< int > GetSetOfEveIDs () const
 
std::set< int > GetSetOfTrackIDs () const
 
std::set< int > GetSetOfEveIDs (std::vector< art::Ptr< recob::Hit > > const &) const
 
std::set< int > GetSetOfTrackIDs (std::vector< art::Ptr< recob::Hit > > const &) const
 

Private Types

using HitMatchDataPair = std::pair< const recob::Hit *, const anab::BackTrackerHitMatchingData * >
 
using PartMatchDataPair = std::pair< const simb::MCParticle *, const anab::BackTrackerHitMatchingData * >
 
using HitToPartVecMap = std::map< const recob::Hit *, std::set< PartMatchDataPair >>
 
using PartToHitVecMap = std::map< const simb::MCParticle *, std::set< HitMatchDataPair >>
 
using MCTruthTrackIDMap = std::unordered_map< int, art::Ptr< simb::MCTruth >>
 
using HitPartAssnsList = std::list< HitPartAssnsStruct >
 

Private Member Functions

int calculateEvdID (int) const
 
double length (const recob::Track *) const
 
double length (const detinfo::DetectorPropertiesData &detProp, const simb::MCParticle &part, double dx, TVector3 &start, TVector3 &end, TVector3 &startmom, TVector3 &endmom, unsigned int tpc=0, unsigned int cstat=0) const
 

Private Attributes

HitPartAssnsList fHitPartAssnsVec
 Container for the (multiple) associations. More...
 
MCTruthParticleList fParticleList
 ParticleList to map track ID to. More...
 
MCTruthTruthVec fMCTruthVec
 all the MCTruths for the event More...
 
MCTruthTrackIDMap fTrackIDToMCTruthIndex
 map of track ids to MCTruthList entry More...
 
float fMinHitEnergyFraction
 
geo::GeometryCore const * fGeometry = nullptr
 

Detailed Description

Obtains truth matching by using hit <–> MCParticle associations.

Configuration

Definition at line 64 of file MCTruthAssociations.h.

Member Typedef Documentation

Definition at line 144 of file MCTruthAssociations.h.

Definition at line 160 of file MCTruthAssociations.h.

using truth::MCTruthAssociations::HitToPartVecMap = std::map<const recob::Hit*,std::set<PartMatchDataPair>>
private

Definition at line 146 of file MCTruthAssociations.h.

using truth::MCTruthAssociations::MCTruthTrackIDMap = std::unordered_map<int, art::Ptr<simb::MCTruth>>
private

Definition at line 148 of file MCTruthAssociations.h.

using truth::MCTruthAssociations::PartMatchDataPair = std::pair<const simb::MCParticle*,const anab::BackTrackerHitMatchingData*>
private

Definition at line 145 of file MCTruthAssociations.h.

using truth::MCTruthAssociations::PartToHitVecMap = std::map<const simb::MCParticle*, std::set<HitMatchDataPair>>
private

Definition at line 147 of file MCTruthAssociations.h.

Constructor & Destructor Documentation

truth::MCTruthAssociations::MCTruthAssociations ( fhicl::ParameterSet const &  config)

Definition at line 33 of file MCTruthAssociations.cpp.

34 {
35  fMinHitEnergyFraction = config.get<float>("MinHitEnergyFraction", 0.);
36 }

Member Function Documentation

int truth::MCTruthAssociations::calculateEvdID ( int  ) const
private
const MCTruthParticleList & truth::MCTruthAssociations::getParticleList ( ) const

Definition at line 107 of file MCTruthAssociations.cpp.

108 {
109  return fParticleList;
110 }
MCTruthParticleList fParticleList
ParticleList to map track ID to.
std::set< int > truth::MCTruthAssociations::GetSetOfEveIDs ( ) const

Definition at line 494 of file MCTruthAssociations.cpp.

495 {
496  std::set<int> eveIDs;
497  const MCTruthParticleList& particleList = getParticleList();
498 
499  for(const auto& pl : particleList) eveIDs.insert(particleList.EveId(pl.first));
500 
501  return eveIDs;
502 }
const MCTruthParticleList & getParticleList() const
std::set< int > truth::MCTruthAssociations::GetSetOfEveIDs ( std::vector< art::Ptr< recob::Hit > > const &  hitVec) const

Definition at line 517 of file MCTruthAssociations.cpp.

518 {
519  std::set<int> eveIDs;
520 
521  for(const auto& hit : hitVec)
522  {
523  const std::vector<TrackIDE> ideVec = HitToEveID(hit);
524 
525  // loop over the ides and extract the track ids
526  for(const auto& trackIDE : ideVec) eveIDs.insert(trackIDE.trackID);
527  }
528 
529  return eveIDs;
530 }
std::vector< TrackIDE > HitToEveID(art::Ptr< recob::Hit > const &hit) const
process_name hit
Definition: cheaterreco.fcl:51
std::set< int > truth::MCTruthAssociations::GetSetOfTrackIDs ( ) const

Definition at line 505 of file MCTruthAssociations.cpp.

506 {
507  // fParticleList::value_type is a pair (track, particle pointer)
508  std::set<int> trackIDs;
509  const MCTruthParticleList& particleList = getParticleList();
510 
511  for (const auto& pl: particleList) trackIDs.insert(pl.first);
512 
513  return trackIDs;
514 }
const MCTruthParticleList & getParticleList() const
std::set< int > truth::MCTruthAssociations::GetSetOfTrackIDs ( std::vector< art::Ptr< recob::Hit > > const &  hitVec) const

Definition at line 533 of file MCTruthAssociations.cpp.

534 {
535  std::set<int> trackIDs;
536 
537  for(const auto& hit : hitVec)
538  {
539  std::vector<TrackIDE> trackIDEVec = this->HitToTrackID(hit);
540 
541  for(const auto& trackIDE : trackIDEVec) trackIDs.insert(trackIDE.trackID);
542  }
543 
544  return trackIDs;
545 }
process_name hit
Definition: cheaterreco.fcl:51
std::vector< TrackIDE > HitToTrackID(const recob::Hit *) const
double truth::MCTruthAssociations::HitChargeCollectionEfficiency ( std::set< int >  trackIDs,
std::vector< art::Ptr< recob::Hit > > const &  hitVec,
std::vector< art::Ptr< recob::Hit > > const &  allHitVec,
geo::View_t const &  view 
) const

Definition at line 434 of file MCTruthAssociations.cpp.

438 {
439  // get the list of EveIDs that correspond to the hits in this collection
440  // and the energy associated with the desired trackID
441  float desired = 0.;
442  float total = 0.;
443 
444  // don't have to check the view in the hits collection because
445  // those are assumed to be from the object we are testing and will
446  // the correct view by definition then.
447  for(const auto& hit : hitVec)
448  {
449  std::vector<TrackIDE> hitTrackIDs = this->HitToTrackID(hit);
450 
451  // don't worry about hits where the energy fraction for the chosen
452  // trackID is < 0.1
453  // also don't double count if this hit has more than one of the
454  // desired track IDs associated with it
455  for(const auto& trackIDE : hitTrackIDs)
456  {
457  if (trackIDs.find(trackIDE.trackID) != trackIDs.end() &&
458  trackIDE.energyFrac >= fMinHitEnergyFraction)
459  {
460  desired += hit->Integral();
461  break;
462  }
463  }
464  }
465 
466  // now figure out how many hits in the whole collection are associated with this id
467  for(const auto& hit : allHitVec)
468  {
469 
470  // check that we are looking at the appropriate view here
471  // in the case of 3D objects we take all hits
472  if(hit->View() != view && view != geo::k3D ) continue;
473 
474  std::vector<TrackIDE> hitTrackIDs = this->HitToTrackID(hit);
475 
476  for (const auto& trackIDE : hitTrackIDs)
477  {
478  if (trackIDs.find(trackIDE.trackID) != trackIDs.end() &&
479  trackIDE.energyFrac >= fMinHitEnergyFraction)
480  {
481  total += hit->Integral();
482  break;
483  }
484  }
485  }
486 
487  double efficiency = 0.;
488  if(total > 0.) efficiency = desired/total;
489 
490  return efficiency;
491 }
process_name hit
Definition: cheaterreco.fcl:51
std::vector< TrackIDE > HitToTrackID(const recob::Hit *) const
3-dimensional objects, potentially hits, clusters, prongs, etc.
Definition: geo_types.h:135
double truth::MCTruthAssociations::HitChargeCollectionPurity ( std::set< int >  trackIDs,
std::vector< art::Ptr< recob::Hit > > const &  hitVec 
) const

Definition at line 398 of file MCTruthAssociations.cpp.

400 {
401  // get the list of EveIDs that correspond to the hits in this collection
402  // if the EveID shows up in the input list of trackIDs, then it counts
403  float total = 0;
404  float desired = 0.;
405 
406  // don't have to check the view in the hits collection because
407  // those are assumed to be from the object we are testing and will
408  // the correct view by definition then.
409  for(const auto& hit : hitVec)
410  {
411  std::vector<TrackIDE> hitTrackIDEVec = this->HitToTrackID(hit);
412 
413  total += hit->Integral();
414 
415  for(const auto& trackIDE : hitTrackIDEVec)
416  {
417  if (trackIDs.find(trackIDE.trackID) != trackIDs.end())
418  {
419  desired += hit->Integral();
420  break;
421  }
422  }
423 
424  }
425 
426  double purity = 0.;
427  if(total > 0) purity = desired/total;
428 
429  return purity;
430 }
process_name hit
Definition: cheaterreco.fcl:51
std::vector< TrackIDE > HitToTrackID(const recob::Hit *) const
double truth::MCTruthAssociations::HitCollectionEfficiency ( std::set< int >  trackIDs,
std::vector< art::Ptr< recob::Hit > > const &  hitVec,
std::vector< art::Ptr< recob::Hit > > const &  allHitVec,
geo::View_t const &  view 
) const

Definition at line 338 of file MCTruthAssociations.cpp.

342 {
343  // get the list of EveIDs that correspond to the hits in this collection
344  // and the energy associated with the desired trackID
345  float desired = 0.;
346  float total = 0.;
347 
348  // don't have to check the view in the hits collection because
349  // those are assumed to be from the object we are testing and will
350  // the correct view by definition then.
351  for(const auto& hit : hitVec)
352  {
353  std::vector<TrackIDE> hitTrackIDs = this->HitToTrackID(hit);
354 
355  // don't worry about hits where the energy fraction for the chosen
356  // trackID is < 0.1
357  // also don't double count if this hit has more than one of the
358  // desired track IDs associated with it
359  for(const auto& trackIDE : hitTrackIDs)
360  {
361  if (trackIDs.find(trackIDE.trackID) != trackIDs.end() &&
362  trackIDE.energyFrac >= fMinHitEnergyFraction)
363  {
364  desired += 1.;
365  break;
366  }
367  }
368  }
369 
370  // now figure out how many hits in the whole collection are associated with this id
371  for(const auto& hit : allHitVec)
372  {
373 
374  // check that we are looking at the appropriate view here
375  // in the case of 3D objects we take all hits
376  if(hit->View() != view && view != geo::k3D ) continue;
377 
378  std::vector<TrackIDE> hitTrackIDs = this->HitToTrackID(hit);
379 
380  for (const auto& trackIDE : hitTrackIDs)
381  {
382  if (trackIDs.find(trackIDE.trackID) != trackIDs.end() &&
383  trackIDE.energyFrac >= fMinHitEnergyFraction)
384  {
385  total += 1.;
386  break;
387  }
388  }
389  }
390 
391  double efficiency = 0.;
392  if(total > 0.) efficiency = desired/total;
393 
394  return efficiency;
395 }
process_name hit
Definition: cheaterreco.fcl:51
std::vector< TrackIDE > HitToTrackID(const recob::Hit *) const
3-dimensional objects, potentially hits, clusters, prongs, etc.
Definition: geo_types.h:135
double truth::MCTruthAssociations::HitCollectionPurity ( std::set< int >  trackIDs,
std::vector< art::Ptr< recob::Hit > > const &  hitVec 
) const

Definition at line 305 of file MCTruthAssociations.cpp.

307 {
308  // get the list of EveIDs that correspond to the hits in this collection
309  // if the EveID shows up in the input list of trackIDs, then it counts
310  float total = hitVec.size();;
311  float desired = 0.;
312 
313  // don't have to check the plane in the hits collection because
314  // those are assumed to be from the object we are testing and will
315  // the correct plane by definition then.
316  for(const auto& hit : hitVec)
317  {
318  std::vector<TrackIDE> hitTrackIDEVec = this->HitToTrackID(hit.get());
319 
320  for(const auto& trackIDE : hitTrackIDEVec)
321  {
322  if (trackIDs.find(trackIDE.trackID) != trackIDs.end())
323  {
324  desired += 1.;
325  break;
326  }
327  }
328  }
329 
330  double purity = 0.;
331  if(total > 0) purity = desired/total;
332 
333  return purity;
334 }
process_name hit
Definition: cheaterreco.fcl:51
std::vector< TrackIDE > HitToTrackID(const recob::Hit *) const
std::vector< TrackIDE > truth::MCTruthAssociations::HitToEveID ( art::Ptr< recob::Hit > const &  hit) const

Definition at line 261 of file MCTruthAssociations.cpp.

262 {
263  std::vector<TrackIDE> trackIDEVec = this->HitToTrackID(hit.get());
264 
265  // Need the particle list, want the "biggest" one to make sure we have all the particles
266  const MCTruthParticleList& particleList = getParticleList();
267 
268  // Create a map which will go between eve ids and TrackIDEs
269  std::unordered_map<int, TrackIDE> idToTrackIDEMap;
270 
271  for(const auto& trackID : trackIDEVec)
272  {
273  int eveTrackID = particleList.EveId(trackID.trackID);
274  TrackIDE& eveTrackIDE = idToTrackIDEMap[eveTrackID];
275 
276  eveTrackIDE.trackID = eveTrackID;
277  eveTrackIDE.energyFrac += trackID.energyFrac;
278  eveTrackIDE.energy += trackID.energy;
279  eveTrackIDE.numElectrons += trackID.numElectrons;
280  }
281 
282  // Now create an output container and move info to it
283  std::vector<TrackIDE> eveTrackIDEVec;
284 
285  for(const auto& eveIDEPair : idToTrackIDEMap) eveTrackIDEVec.emplace_back(eveIDEPair.second);
286 
287  return eveTrackIDEVec;
288 }
process_name hit
Definition: cheaterreco.fcl:51
std::vector< TrackIDE > HitToTrackID(const recob::Hit *) const
const MCTruthParticleList & getParticleList() const
std::vector< TrackIDE > truth::MCTruthAssociations::HitToTrackID ( const recob::Hit hit) const

Definition at line 180 of file MCTruthAssociations.cpp.

181 {
182  std::vector<TrackIDE> trackIDEs;
183 
184  // Apply brute force loop through all possible collections
185  for(const auto& hitPartAssns : fHitPartAssnsVec)
186  {
187  HitToPartVecMap::const_iterator hitMatchPairItr = hitPartAssns.fHitToPartVecMap.find(hit);
188 
189  if (hitMatchPairItr != hitPartAssns.fHitToPartVecMap.end())
190  {
191  size_t nTrackIDEs(hitMatchPairItr->second.size());
192 
193  trackIDEs.reserve(nTrackIDEs);
194 
195  for (const auto& matchPair : hitMatchPairItr->second)
196  {
197  const simb::MCParticle* part = matchPair.first;
198  const anab::BackTrackerHitMatchingData* data = matchPair.second;
199 
200  TrackIDE trackIDE;
201 
202  trackIDE.trackID = part->TrackId();
203  trackIDE.energyFrac = data->ideFraction;
204  trackIDE.energy = data->energy;
205  trackIDE.numElectrons = data->numElectrons;
206 
207  trackIDEs.emplace_back(trackIDE);
208  }
209 
210  break;
211  }
212  }
213 
214  return trackIDEs;
215 }
HitPartAssnsList fHitPartAssnsVec
Container for the (multiple) associations.
std::vector< TrackIDE > truth::MCTruthAssociations::HitToTrackID ( art::Ptr< recob::Hit > const &  hit) const

Definition at line 217 of file MCTruthAssociations.cpp.

218 {
219  return HitToTrackID(hit.get());
220 }
process_name hit
Definition: cheaterreco.fcl:51
std::vector< TrackIDE > HitToTrackID(const recob::Hit *) const
std::vector< double > truth::MCTruthAssociations::HitToXYZ ( art::Ptr< recob::Hit > const &  hit) const

Definition at line 291 of file MCTruthAssociations.cpp.

292 {
293  mf::LogWarning("MCTruthAssociations") << " ** HitToXYZ currently not implemented in MCTruthAssociations, return a zero point";
294  return std::vector<double>() = {0.,0.,0.};
295 }
double truth::MCTruthAssociations::length ( const recob::Track track) const
private

Definition at line 549 of file MCTruthAssociations.cpp.

550 {
551  return track->Length();
552 }
double Length(size_t p=0) const
Access to various track properties.
double truth::MCTruthAssociations::length ( const detinfo::DetectorPropertiesData detProp,
const simb::MCParticle &  part,
double  dx,
TVector3 &  start,
TVector3 &  end,
TVector3 &  startmom,
TVector3 &  endmom,
unsigned int  tpc = 0,
unsigned int  cstat = 0 
) const
private

Definition at line 556 of file MCTruthAssociations.cpp.

560 {
561  // Get fiducial volume boundary.
562  double xmin = -0.1;
563  double xmax = 2.*fGeometry->DetHalfWidth() + 0.1;
564  double ymin = -fGeometry->DetHalfHeight() + 0.1;
565  double ymax = fGeometry->DetHalfHeight() + 0.1;
566  double zmin = -0.1;
567  double zmax = fGeometry->DetLength() + 0.1;
568 
569  double readOutWindowSize = detProp.ReadOutWindowSize();
570 
571  double result = 0.;
572  TVector3 disp;
573  int n = part.NumberTrajectoryPoints();
574  bool first = true;
575 
576  // Loop over the complete collection of trajectory points
577  for(int i = 0; i < n; ++i)
578  {
579  TVector3 pos = part.Position(i).Vect();
580 
581  // Make fiducial cuts.
582  // There are two sets here:
583  // 1) We check the original x,y,z position of the trajectory points and require they be
584  // within the confines of the physical TPC
585  // 2) We then check the timing of the presumed hit and make sure it lies within the
586  // readout window for this simulation
587 
588  if(pos.X() >= xmin &&
589  pos.X() <= xmax &&
590  pos.Y() >= ymin &&
591  pos.Y() <= ymax &&
592  pos.Z() >= zmin &&
593  pos.Z() <= zmax)
594  {
595  pos[0] += dx;
596  double ticks = detProp.ConvertXToTicks(pos[0], 0, 0, 0);
597 
598  if(ticks >= 0. && ticks < readOutWindowSize)
599  {
600  if(first)
601  {
602  start = pos;
603  startmom = part.Momentum(i).Vect();
604  }
605  else
606  {
607  disp -= pos;
608  result += disp.Mag();
609  }
610  first = false;
611  disp = pos;
612  end = pos;
613  endmom = part.Momentum(i).Vect();
614  }
615  }
616  }
617 
618  return result;
619 }
geo::Length_t DetHalfWidth(geo::TPCID const &tpcid) const
Returns the half width of the active volume of the specified TPC.
tick ticks
Alias for common language habits.
Definition: electronics.h:78
process_name pandoraGausCryo1 vertexChargeCryo1 vertexStubCryo1 xmin
geo::Length_t DetHalfHeight(geo::TPCID const &tpcid) const
Returns the half height of the active volume of the specified TPC.
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
double ConvertXToTicks(double X, int p, int t, int c) const
geo::Length_t DetLength(geo::TPCID const &tpcid) const
Returns the length of the active volume of the specified TPC.
geo::GeometryCore const * fGeometry
std::vector< const simb::MCParticle * > truth::MCTruthAssociations::MCTruthToParticles ( art::Ptr< simb::MCTruth > const &  mct) const

Definition at line 158 of file MCTruthAssociations.cpp.

159 {
160  std::vector<const simb::MCParticle*> ret;
161 
162  // I'm slightly uncertain what is going on here since I naively would think a track ID is
163  // unique to an MCParticle... but this is what was done previously so copied here...
164  // sim::ParticleList::value_type is a pair (track ID, particle pointer)
165  for (const MCTruthParticleList::value_type& TrackIDpair : fParticleList)
166  {
167  if (TrackIDToMCTruth(TrackIDpair.first) == mct) ret.push_back(TrackIDpair.second);
168  }
169 
170  return ret;
171 }
list_type::value_type value_type
const art::Ptr< simb::MCTruth > & TrackIDToMCTruth(int const &id) const
MCTruthParticleList fParticleList
ParticleList to map track ID to.
const MCTruthTruthVec & truth::MCTruthAssociations::MCTruthVector ( ) const

Definition at line 173 of file MCTruthAssociations.cpp.

174 {
175  return fMCTruthVec;
176 }
MCTruthTruthVec fMCTruthVec
all the MCTruths for the event
const art::Ptr< simb::MCTruth > & truth::MCTruthAssociations::ParticleToMCTruth ( const simb::MCParticle *  p) const

Definition at line 153 of file MCTruthAssociations.cpp.

154 {
155  return this->TrackIDToMCTruth(p->TrackId());
156 }
pdgs p
Definition: selectors.fcl:22
const art::Ptr< simb::MCTruth > & TrackIDToMCTruth(int const &id) const
void truth::MCTruthAssociations::setup ( const HitParticleAssociationsVec partToHitAssnsVec,
const MCParticleVec mcPartVec,
const MCTruthAssns truthToPartAssns,
const geo::GeometryCore geometry 
)

Definition at line 38 of file MCTruthAssociations.cpp.

42 {
43  // Keep track of input services
45 
46  fHitPartAssnsVec.clear();
47 
48  // Loop through the input vector of associations
49  for(const HitParticleAssociations* partToHitAssns : partToHitAssnsVec)
50  {
51  // Note that one element of our struct is non copiable which means
52  // we need to construct in place before filling
53  fHitPartAssnsVec.emplace_back();
54 
55  HitPartAssnsStruct& hitPartAssns = fHitPartAssnsVec.back();
56 
57  // Clear the maps in case they were previously filled
58  hitPartAssns.fHitToPartVecMap.clear();
59  hitPartAssns.fPartToHitVecMap.clear();
60 
61  // Build out the maps between hits/particles
62  for(HitParticleAssociations::const_iterator partHitItr = partToHitAssns->begin(); partHitItr != partToHitAssns->end(); ++partHitItr)
63  {
64  const art::Ptr<simb::MCParticle>& mcParticle = partHitItr->first;
65  const art::Ptr<recob::Hit>& recoHit = partHitItr->second;
66  const anab::BackTrackerHitMatchingData* data = partHitItr->data;
67 
68  hitPartAssns.fHitToPartVecMap[recoHit.get()].insert(PartMatchDataPair(mcParticle.get(),data));
69  hitPartAssns.fPartToHitVecMap[mcParticle.get()].insert(HitMatchDataPair(recoHit.get(),data));
70  }
71 
72  mf::LogDebug("MCTruthAssociations") << "Built maps with " << hitPartAssns.fHitToPartVecMap.size() << " hits, " << hitPartAssns.fPartToHitVecMap.size() << "\n";
73  }
74 
75  // Note that there is only one instance of MCTruth <--> MCParticle associations so we do this external to the above loop
77  fMCTruthVec.clear();
78  fTrackIDToMCTruthIndex.clear();
79 
80  for(const auto& mcParticle : mcPartVec)
81  {
82  fParticleList.Add(mcParticle.get());
83 
84  try
85  {
86  art::Ptr<simb::MCTruth> mcTruth = truthToPartAssns.at(mcParticle.key());
87 
88  // Add to the list
89  if (std::find(fMCTruthVec.begin(),fMCTruthVec.end(),mcTruth) == fMCTruthVec.end())
90  fMCTruthVec.push_back(mcTruth);
91 
92  fTrackIDToMCTruthIndex[mcParticle->TrackId()] = mcTruth;
93  }
94  catch(...)
95  {
96  mf::LogDebug("MCTruthAssociations") << ">>>> No MCTruth found for particle: " << *mcParticle << "\n";
97  }
98  }
99 
100  // Follow former backtracker convention of resetting the eve id calculator each event...
101  // Note that the calculator is stored as a unique_ptr (mutable) so memory ok
102  fParticleList.AdoptEveIdCalculator(new MCTruthEmEveIdCalculator);
103 
104  return;
105 }
std::pair< const simb::MCParticle *, const anab::BackTrackerHitMatchingData * > PartMatchDataPair
art::Assns< simb::MCParticle, recob::Hit, anab::BackTrackerHitMatchingData > HitParticleAssociations
std::pair< const recob::Hit *, const anab::BackTrackerHitMatchingData * > HitMatchDataPair
MCTruthTruthVec fMCTruthVec
all the MCTruths for the event
const geo::GeometryCore * geometry
HitPartAssnsList fHitPartAssnsVec
Container for the (multiple) associations.
MCTruthTrackIDMap fTrackIDToMCTruthIndex
map of track ids to MCTruthList entry
void AdoptEveIdCalculator(MCTruthEveIdCalculator *) const
void Add(const simb::MCParticle *value)
MCTruthParticleList fParticleList
ParticleList to map track ID to.
geo::GeometryCore const * fGeometry
std::vector< double > truth::MCTruthAssociations::SpacePointHitsToXYZ ( art::PtrVector< recob::Hit > const &  hits) const

Definition at line 298 of file MCTruthAssociations.cpp.

299 {
300  mf::LogWarning("MCTruthAssociations") << " ** SpacePointHitsToXYZ currently not implemented in MCTruthAssociations, return a zero point";
301  return std::vector<double>() = {0.,0.,0.};
302 }
const std::vector< std::vector< art::Ptr< recob::Hit > > > truth::MCTruthAssociations::TrackIDsToHits ( std::vector< art::Ptr< recob::Hit >> const &  allHits,
std::vector< int > const &  tkIDs 
) const

Definition at line 223 of file MCTruthAssociations.cpp.

225 {
226  // returns a subset of the hits in the allhits collection that are matched
227  // to MC particles listed in tkIDs
228 
229  // temporary vector of TrackIDs and Ptrs to hits so only one
230  // loop through the (possibly large) allhits collection is needed
231  std::unordered_map<int, std::vector<art::Ptr<recob::Hit>>> trackIDHitVecMap;
232 
233  for(const auto& hit : allHits)
234  {
235  std::vector<TrackIDE> trackIDEVec = this->HitToTrackID(hit.get());
236 
237  for(const auto trackIDE : trackIDEVec)
238  {
239  for(auto trackID : tkIDs)
240  {
241  if(trackID == trackIDE.trackID && trackIDE.energyFrac > fMinHitEnergyFraction)
242  {
243  trackIDHitVecMap[trackID].push_back(hit);
244  }
245  }
246  }
247  }
248 
249  // now build the truHits vector that will be returned to the caller
250  std::vector<std::vector<art::Ptr<recob::Hit>>> truHits;
251 
252  for(const auto& trackHitPair : trackIDHitVecMap) truHits.emplace_back(trackHitPair.second);
253 
254  return truHits;
255 }
process_name hit
Definition: cheaterreco.fcl:51
std::vector< TrackIDE > HitToTrackID(const recob::Hit *) const
const art::Ptr< simb::MCTruth > & truth::MCTruthAssociations::TrackIDToMCTruth ( int const &  id) const

Definition at line 140 of file MCTruthAssociations.cpp.

141 {
142  // find the entry in the MCTruth collection for this track id
143  MCTruthTrackIDMap::const_iterator trackTruthItr = fTrackIDToMCTruthIndex.find(abs(id));
144 
145  if (trackTruthItr == fTrackIDToMCTruthIndex.end())
146  throw cet::exception("MCTruthAssociations") << "attempting to find MCTruth index for "
147  << "out of range value: " << id
148  << "/" << fMCTruthVec.size() << "\n";
149 
150  return trackTruthItr->second;
151 }
MCTruthTruthVec fMCTruthVec
all the MCTruths for the event
MCTruthTrackIDMap fTrackIDToMCTruthIndex
map of track ids to MCTruthList entry
T abs(T value)
const simb::MCParticle * truth::MCTruthAssociations::TrackIDToMotherParticle ( int const &  id) const

Definition at line 132 of file MCTruthAssociations.cpp.

133 {
134  // get the mother id from the particle navigator
135  // the EveId was adopted in the Rebuild method
136  return this->TrackIDToParticle(fParticleList.EveId(abs(id)));
137 }
int EveId(const int trackID) const
T abs(T value)
const simb::MCParticle * TrackIDToParticle(int const &id) const
MCTruthParticleList fParticleList
ParticleList to map track ID to.
const simb::MCParticle * truth::MCTruthAssociations::TrackIDToParticle ( int const &  id) const

Definition at line 113 of file MCTruthAssociations.cpp.

114 {
115  // Pointer to return
116  const simb::MCParticle* mcParticle(0);
117 
119 
120  if (partItr != fParticleList.end()) mcParticle = partItr->second;
121 
122  if(!mcParticle)
123  {
124  mf::LogWarning("MCTruthAssociations") << "can't find particle with track id "
125  << id << " in MCTruthParticleList"
126  << " returning null pointer";
127  }
128 
129  return mcParticle;
130 }
list_type::const_iterator const_iterator
iterator find(const key_type &key)
MCTruthParticleList fParticleList
ParticleList to map track ID to.

Member Data Documentation

geo::GeometryCore const* truth::MCTruthAssociations::fGeometry = nullptr
private

Definition at line 179 of file MCTruthAssociations.h.

HitPartAssnsList truth::MCTruthAssociations::fHitPartAssnsVec
private

Container for the (multiple) associations.

Definition at line 169 of file MCTruthAssociations.h.

MCTruthTruthVec truth::MCTruthAssociations::fMCTruthVec
private

all the MCTruths for the event

Definition at line 171 of file MCTruthAssociations.h.

float truth::MCTruthAssociations::fMinHitEnergyFraction
private

minimum fraction of energy a track id has to contribute to a hit to be counted in purity and efficiency calculations based on hit collections

Definition at line 174 of file MCTruthAssociations.h.

MCTruthParticleList truth::MCTruthAssociations::fParticleList
private

ParticleList to map track ID to.

Definition at line 170 of file MCTruthAssociations.h.

MCTruthTrackIDMap truth::MCTruthAssociations::fTrackIDToMCTruthIndex
private

map of track ids to MCTruthList entry

Definition at line 172 of file MCTruthAssociations.h.


The documentation for this class was generated from the following files: