LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ParticleInventory.cc
Go to the documentation of this file.
1 //
3 // ParticleInventory.cc
4 // Author: JStock
5 // EMail: jason.stock@mines.sdsmt.edu
6 // 2017-09-12
7 //
9 
10 //STL includes
11 //ROOT includes
12 //Framework includes
13 #include "fhiclcpp/ParameterSet.h"
15 //LArSoft includes
18 
19 namespace cheat {
20 
22  : fG4ModuleLabel(config.G4ModuleLabel())
23  , fEveIdCalculator(config.EveIdCalculator())
24  , fOverrideRealData(config.OverrideRealData())
25  {}
26 
27  //----------------------------------------------------------------------
29  : fG4ModuleLabel(pSet.get<art::InputTag>("G4ModuleLabel", "largeant"))
30  , fEveIdCalculator(pSet.get<std::string>("EveIdCalculator", "EmEveIdCalculator"))
31  , fOverrideRealData(pSet.get<bool>("OverrideRealData", false))
32  {}
33 
34  //-----------------------------------------------------------------------
36  {
38  fMCTObj.fMCTruthList.clear();
40  }
41 
42  //deliverables
43 
44  //-----------------------------------------------------------------------
45  //TrackIdToParticlePtr
47  {
49  if (part_it == fParticleList.end()) {
50  mf::LogWarning("ParticleInventory")
51  << "Particle with TrackId: " << id << " not found in inventory. "
52  << "Returning null pointer.";
53  return 0;
54  }
55  return part_it->second;
56  } //End TrackIdToParticle
57 
58  //-----------------------------------------------------------------------
60  {
61  return this->TrackIdToParticle_P(fParticleList.EveId(abs(id)));
62  }
63 
64  //-----------------------------------------------------------------------
66  {
67  // find the entry in the MCTruth collection for this track id
68  auto mctItr = fMCTObj.fTrackIdToMCTruthIndex.find(abs(id));
69  if (mctItr != fMCTObj.fTrackIdToMCTruthIndex.end()) {
70  int partIndex = mctItr->second;
71  return fMCTObj.fMCTruthList.at(partIndex);
72  }
73  else {
74  throw cet::exception("ParticleInventory")
75  << "Attempt to find MCTruth for TrackId: " << id << " has failed.";
76  }
77  }
78 
79  //-----------------------------------------------------------------------
81  const simb::MCParticle* p) const
82  {
83  return this->TrackIdToMCTruth_P(p->TrackId());
84  }
85 
86  //-----------------------------------------------------------------------
87  const std::vector<art::Ptr<simb::MCTruth>>& ParticleInventory::MCTruthVector_Ps() const
88  {
89  return fMCTObj.fMCTruthList;
90  }
91 
92  //-----------------------------------------------------------------------
93  std::vector<const simb::MCParticle*> ParticleInventory::MCTruthToParticles_Ps(
94  art::Ptr<simb::MCTruth> const& mct) const
95  {
96  std::vector<const simb::MCParticle*> ret;
97  // sim::ParticleList::value_type is a pair (track Id, particle pointer)
98  for (const sim::ParticleList::value_type& TrackIdpair : fParticleList) {
99  if (this->TrackIdToMCTruth_P(TrackIdpair.first) == mct) ret.push_back(TrackIdpair.second);
100  }
101  return ret;
102  }
103 
104  //-----------------------------------------------------------------------
106  {
107  std::set<int> ret;
108  for (auto partItr = fParticleList.begin(); partItr != fParticleList.end(); ++partItr) {
109  ret.emplace((partItr->second)->TrackId());
110  }
111  return ret;
112  }
113 
114  //-----------------------------------------------------------------------
115  std::set<int> ParticleInventory::GetSetOfEveIds() const
116  {
117  std::set<int> ret;
118  std::set<int> tIds = this->GetSetOfTrackIds();
119  for (auto tId : tIds) {
120  ret.emplace(fParticleList.EveId(tId));
121  }
122  return ret;
123  }
124 
125 } //namespace
sim::ParticleList fParticleList
FHICL Validation Object This struct is used for loading the fhicl configuration.
list_type::value_type value_type
Definition: ParticleList.h:130
list_type::const_iterator const_iterator
Definition: ParticleList.h:132
constexpr auto abs(T v)
Returns the absolute value of the argument.
STL namespace.
int EveId(const int trackID) const
Particle class.
int TrackId() const
Definition: MCParticle.h:211
iterator find(const key_type &key)
Definition: ParticleList.h:318
const std::vector< art::Ptr< simb::MCTruth > > & MCTruthVector_Ps() const
std::vector< const simb::MCParticle * > MCTruthToParticles_Ps(art::Ptr< simb::MCTruth > const &mct) const
const simb::MCParticle * TrackIdToParticle_P(int const &id) const
std::set< int > GetSetOfTrackIds() const
iterator begin()
Definition: ParticleList.h:305
std::set< int > GetSetOfEveIds() const
const art::Ptr< simb::MCTruth > & ParticleToMCTruth_P(const simb::MCParticle *p) const
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
code to link reconstructed objects back to the MC truth information
Definition: BackTracker.cc:22
const simb::MCParticle * TrackIdToMotherParticle_P(int const &id) const
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Header for the ParticleInvenotry Service Provider.
Definition: MVAAlg.h:12
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
A vector containing the MCTruth objects.
ParticleInventory(const ParticleInventoryConfig &config)
const art::Ptr< simb::MCTruth > & TrackIdToMCTruth_P(int const &id) const
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33