All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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"
14 #include "messagefacility/MessageLogger/MessageLogger.h"
15 //LArSoft includes
17 #include "nusimdata/SimulationBase/MCParticle.h"
18 
19 
20 namespace cheat{
21 
23  :fG4ModuleLabel(config.G4ModuleLabel()),
24  fEveIdCalculator(config.EveIdCalculator()),
25  fOverrideRealData(config.OverrideRealData())
26  {
27  }
28 
29  //----------------------------------------------------------------------
30  ParticleInventory::ParticleInventory(const fhicl::ParameterSet& pSet )
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
48  const simb::MCParticle* ParticleInventory::TrackIdToParticle_P(int const& id) const {
49  sim::ParticleList::const_iterator part_it = fParticleList.find(id);
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  //-----------------------------------------------------------------------
61  const simb::MCParticle* ParticleInventory::TrackIdToMotherParticle_P(int const& id) const
62  {
63  return this->TrackIdToParticle_P(fParticleList.EveId(abs(id)));
64  }
65 
66  //-----------------------------------------------------------------------
67  const art::Ptr<simb::MCTruth>& ParticleInventory::TrackIdToMCTruth_P(int const& id) const
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  //-----------------------------------------------------------------------
81  const art::Ptr<simb::MCTruth>& ParticleInventory::ParticleToMCTruth_P(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  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
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
FHICL Validation Object This struct is used for loading the fhicl configuration.
pdgs p
Definition: selectors.fcl:22
static constexpr bool
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
const simb::MCParticle * TrackIdToParticle_P(int const &id) const
std::set< int > GetSetOfTrackIds() const
std::set< int > GetSetOfEveIds() const
const art::Ptr< simb::MCTruth > & ParticleToMCTruth_P(const simb::MCParticle *p) const
const simb::MCParticle * TrackIdToMotherParticle_P(int const &id) const
Header for the ParticleInvenotry Service Provider.
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