ParticleInventory.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // ParticleInventory.cc
4 // Author: JStock
5 // EMail: jason.stock@mines.sdsmt.edu
6 // 2017-09-12
7 //
8 ////////////////////////////////////////////////////////////////////////
9 
10 //STL includes
11 //ROOT includes
12 //Framework includes
13 #include "fhiclcpp/ParameterSet.h"
15 //LArSoft includes
18 
19 
20 namespace cheat{
21 
23  :fG4ModuleLabel(config.G4ModuleLabel()),
24  fEveIdCalculator(config.EveIdCalculator()),
25  fOverrideRealData(config.OverrideRealData())
26  {
27  }
28 
29  //----------------------------------------------------------------------
31  :fG4ModuleLabel(pSet.get<art::InputTag>("G4ModuleLabel", "largeant")),
32  fEveIdCalculator(pSet.get<std::string>("EveIdCalculator", "EmEveIdCalculator")),
33  fOverrideRealData(pSet.get<bool>("OverrideRealData", false))
34  {
35  }
36 
37  //-----------------------------------------------------------------------
39  fParticleList.clear();
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  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
sim::ParticleList fParticleList
FHICL Validation Object This struct is used for loading the fhicl configuration.
std::string string
Definition: nybbler.cc:12
STL namespace.
intermediate_table::const_iterator const_iterator
Particle class.
int TrackId() const
Definition: MCParticle.h:210
const std::vector< art::Ptr< simb::MCTruth > > & MCTruthVector_Ps() const
T abs(T value)
std::vector< const simb::MCParticle * > MCTruthToParticles_Ps(art::Ptr< simb::MCTruth > const &mct) const
static Config * config
Definition: config.cpp:1054
const simb::MCParticle * TrackIdToParticle_P(int const &id) const
std::set< int > GetSetOfTrackIds() const
p
Definition: test.py:223
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:22
const simb::MCParticle * TrackIdToMotherParticle_P(int const &id) const
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Header for the ParticleInvenotry Service Provider.
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
A vector containing the MCTruth objects.
ParticleInventory(const ParticleInventoryConfig &config)
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
const art::Ptr< simb::MCTruth > & TrackIdToMCTruth_P(int const &id) const
int bool
Definition: qglobal.h:345
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33