LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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 #include <map>
12 //ROOT includes
13 //Framework includes
15 //LArSoft includes
22 
23 
24 namespace cheat{
25 
27  :fG4ModuleLabel(config.G4ModuleLabel())
28  {
29  }
30 
31  //----------------------------------------------------------------------
33  :fG4ModuleLabel(pSet.get<art::InputTag>("G4ModuleLabel", "largeant"))
34  {
35  }
36 
37  //-----------------------------------------------------------------------
40  fMCTObj.fMCTruthList.clear();
42  }
43 
44  //deliverables
45 
46  //-----------------------------------------------------------------------
47  //TrackIdToParticlePtr
50  if(part_it == fParticleList.end()){
51  mf::LogWarning("ParticleInventory") << "Particle with TrackId: "
52  << id << " not found in inventory. "
53  << "Returning null pointer.";
54  return 0;
55  }
56  return part_it->second;
57  }//End TrackIdToParticle
58 
59 
60  //-----------------------------------------------------------------------
62  {
63  return this->TrackIdToParticle_P(fParticleList.EveId(abs(id)));
64  }
65 
66  //-----------------------------------------------------------------------
68  {
69  // find the entry in the MCTruth collection for this track id
70  auto mctItr = fMCTObj.fTrackIdToMCTruthIndex.find(abs(id));
71  if(mctItr!=fMCTObj.fTrackIdToMCTruthIndex.end()){
72  int partIndex = mctItr->second;
73  return fMCTObj.fMCTruthList.at(partIndex);
74  }else{
75  throw cet::exception("ParticleInventory") << "Attempt to find MCTruth for TrackId: "
76  << id <<" has failed.";
77  }
78  }
79 
80  //-----------------------------------------------------------------------
82  {
83  return this->TrackIdToMCTruth_P(p->TrackId());
84  }
85 
86  //-----------------------------------------------------------------------
87  const std::vector< art::Ptr<simb::MCTruth> >& ParticleInventory::MCTruthVector_Ps() const {
88  return fMCTObj.fMCTruthList;
89  }
90 
91  //-----------------------------------------------------------------------
92  const std::vector<const simb::MCParticle*> ParticleInventory::MCTruthToParticles_Ps(art::Ptr<simb::MCTruth> const& mct) const
93  {
94  std::vector<const simb::MCParticle*> ret;
95  // sim::ParticleList::value_type is a pair (track Id, particle pointer)
96  for (const sim::ParticleList::value_type& TrackIdpair: fParticleList) {
97  if( this->TrackIdToMCTruth_P(TrackIdpair.first) == mct )
98  ret.push_back(TrackIdpair.second);
99  }
100  return ret;
101  }
102 
103  //-----------------------------------------------------------------------
104  std::set<int> ParticleInventory::GetSetOfTrackIds() const{
105  std::set<int> ret;
106  for( auto partItr=fParticleList.begin(); partItr!=fParticleList.end(); ++partItr){
107  ret.emplace((partItr->second)->TrackId());
108  }
109  return ret;
110  }
111 
112  //-----------------------------------------------------------------------
113  std::set<int> ParticleInventory::GetSetOfEveIds() const{
114  std::set<int> ret;
115  std::set<int> tIds=this->GetSetOfTrackIds();
116  for(auto tId : tIds){
117  ret.emplace(fParticleList.EveId(tId));
118  }
119  return ret;
120  }
121 
122 
123 } //namespace
124 
125 
126 
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
int EveId(const int trackID) const
Particle class.
int TrackId() const
Definition: MCParticle.h:214
iterator find(const key_type &key)
Definition: ParticleList.h:318
const std::vector< art::Ptr< simb::MCTruth > > & MCTruthVector_Ps() 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
code to link reconstructed objects back to the MC truth information
Definition: BackTracker.cc:26
Utility object to perform functions of association.
const simb::MCParticle * TrackIdToMotherParticle_P(int const &id) const
Example routine for calculating the "ultimate e-m mother" of a particle in a simulated event...
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Header for the ParticleInvenotry Service Provider.
HLT enums.
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
Tools and modules for checking out the basics of the Monte Carlo.
const std::vector< const simb::MCParticle * > MCTruthToParticles_Ps(art::Ptr< simb::MCTruth > const &mct) const
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33