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

#include <ParticleInventory.h>

Inheritance diagram for cheat::ParticleInventory:
cheat::ParticleInventoryService

Classes

struct  MCTObjects
 A simple struct to contain the MC Truth information. More...
 
struct  ParticleInventoryConfig
 FHICL Validation Object This struct is used for loading the fhicl configuration. More...
 

Public Member Functions

 ParticleInventory (const ParticleInventoryConfig &config)
 
 ParticleInventory (const fhicl::ParameterSet &pSet)
 
 ParticleInventory (ParticleInventory const &)=delete
 
template<typename Evt >
void PrepEvent (const Evt &evt)
 Function to set up the ParticleInventory state for an event. This is a function to tell the ParticleInventory to prepare itself to work with a particular event. More...
 
bool ParticleListReady () const
 A simple check to determine if the ParticleList has already been prepared for this event or not. More...
 
bool MCTruthListReady () const
 A simple check to determine if the MCTruthList has already been prepared and cached or not. More...
 
bool TrackIdToMCTruthReady () const
 A simple check to determine if the TrackIdToMCTruth map has been prepared or not. More...
 
template<typename Evt >
void PrepParticleList (const Evt &evt) const
 A function to load the ParticleList and cache it This function will find the particle list and load it for later use. Ideally this would would be used for a "lazy" loading of the backtracker, but this does not work in the current setup of art. More...
 
template<typename Evt >
void PrepTrackIdToMCTruthIndex (const Evt &evt) const
 A function to prepare and cache a map of TrackIds and MCTruth object indicies from fMCTruthList. More...
 
template<typename Evt >
void PrepMCTruthList (const Evt &evt) const
 A function to load and cache the MCTruthList of the event. More...
 
template<typename Evt >
void PrepMCTruthListAndTrackIdToMCTruthIndex (const Evt &evt) const
 A function to make both PrepTrackIdToMCTruthIndex and PrepMCTruthList run when both are needed. More...
 
template<typename Evt >
bool CanRun (const Evt &evt) const
 A short function to check if use of the backtracker is appropriate or not based on the type of input file. This function simply checks to see if the file loaded is real data, or MC Simulation, as backtracking on real data makes no sense. If one does try to backtrack real data, this will throw and exception. More...
 
const sim::ParticleList & ParticleList () const
 
void SetEveIdCalculator (sim::EveIdCalculator *ec)
 
const std::vector< art::Ptr
< simb::MCTruth > > & 
MCTruthList () const
 
const std::map< int, int > & TrackIdToMCTruthIndex () const
 
void ClearEvent ()
 
const simb::MCParticle * TrackIdToParticle_P (int const &id) const
 
simb::MCParticle TrackIdToParticle (int const &id) const
 
const simb::MCParticle * TrackIdToMotherParticle_P (int const &id) const
 
simb::MCParticle TrackIdToMotherParticle (int const &id) const
 
const art::Ptr< simb::MCTruth > & TrackIdToMCTruth_P (int const &id) const
 
simb::MCTruth TrackIdToMCTruth (int const &id) const
 
int TrackIdToEveTrackId (const int &tid) const
 
const art::Ptr< simb::MCTruth > & ParticleToMCTruth_P (const simb::MCParticle *p) const
 
simb::MCTruth ParticleToMCTruth (const simb::MCParticle *p) const
 
const std::vector< art::Ptr
< simb::MCTruth > > & 
MCTruthVector_Ps () const
 
std::vector< const
simb::MCParticle * > 
MCTruthToParticles_Ps (art::Ptr< simb::MCTruth > const &mct) const
 
std::set< int > GetSetOfTrackIds () const
 
std::set< int > GetSetOfEveIds () const
 

Private Attributes

sim::ParticleList fParticleList
 
MCTObjects fMCTObj
 
art::InputTag fG4ModuleLabel
 
std::string fEveIdCalculator
 
bool fOverrideRealData
 

Detailed Description

Definition at line 170 of file ParticleInventory.h.

Constructor & Destructor Documentation

cheat::ParticleInventory::ParticleInventory ( const ParticleInventoryConfig config)

Definition at line 22 of file ParticleInventory.cc.

23  :fG4ModuleLabel(config.G4ModuleLabel()),
24  fEveIdCalculator(config.EveIdCalculator()),
25  fOverrideRealData(config.OverrideRealData())
26  {
27  }
cheat::ParticleInventory::ParticleInventory ( const fhicl::ParameterSet &  pSet)

Definition at line 30 of file ParticleInventory.cc.

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  }
cheat::ParticleInventory::ParticleInventory ( ParticleInventory const &  )
delete

Member Function Documentation

template<typename Evt >
bool cheat::ParticleInventory::CanRun ( const Evt &  evt) const

A short function to check if use of the backtracker is appropriate or not based on the type of input file. This function simply checks to see if the file loaded is real data, or MC Simulation, as backtracking on real data makes no sense. If one does try to backtrack real data, this will throw and exception.

void cheat::ParticleInventory::ClearEvent ( )

Definition at line 38 of file ParticleInventory.cc.

38  {
39  fParticleList.clear();
40  fMCTObj.fMCTruthList.clear();
42  }
sim::ParticleList fParticleList
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
A vector containing the MCTruth objects.
std::set< int > cheat::ParticleInventory::GetSetOfEveIds ( ) const

Definition at line 113 of file ParticleInventory.cc.

113  {
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  }
sim::ParticleList fParticleList
std::set< int > GetSetOfTrackIds() const
std::set< int > cheat::ParticleInventory::GetSetOfTrackIds ( ) const

Definition at line 104 of file ParticleInventory.cc.

104  {
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  }
sim::ParticleList fParticleList
const std::vector< art::Ptr<simb::MCTruth> >& cheat::ParticleInventory::MCTruthList ( ) const
inline

Definition at line 218 of file ParticleInventory.h.

218 { return fMCTObj.fMCTruthList;}
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
A vector containing the MCTruth objects.
bool cheat::ParticleInventory::MCTruthListReady ( ) const
inline

A simple check to determine if the MCTruthList has already been prepared and cached or not.

Definition at line 201 of file ParticleInventory.h.

201 { return !( (fMCTObj.fMCTruthList).empty() ); }
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
A vector containing the MCTruth objects.
bool empty(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:555
std::vector< const simb::MCParticle * > cheat::ParticleInventory::MCTruthToParticles_Ps ( art::Ptr< simb::MCTruth > const &  mct) const

Definition at line 92 of file ParticleInventory.cc.

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  }
sim::ParticleList fParticleList
const art::Ptr< simb::MCTruth > & TrackIdToMCTruth_P(int const &id) const
const std::vector< art::Ptr< simb::MCTruth > > & cheat::ParticleInventory::MCTruthVector_Ps ( ) const

Definition at line 87 of file ParticleInventory.cc.

87  {
88  return fMCTObj.fMCTruthList;
89  }
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
A vector containing the MCTruth objects.
const sim::ParticleList& cheat::ParticleInventory::ParticleList ( ) const
inline

Definition at line 215 of file ParticleInventory.h.

215 { return fParticleList; }
sim::ParticleList fParticleList
bool cheat::ParticleInventory::ParticleListReady ( ) const
inline

A simple check to determine if the ParticleList has already been prepared for this event or not.

Definition at line 200 of file ParticleInventory.h.

200 { return !( fParticleList.empty() ); }
sim::ParticleList fParticleList
simb::MCTruth cheat::ParticleInventory::ParticleToMCTruth ( const simb::MCParticle *  p) const
inline

Definition at line 241 of file ParticleInventory.h.

242  { return *(this->ParticleToMCTruth_P(p)); }
pdgs p
Definition: selectors.fcl:22
const art::Ptr< simb::MCTruth > & ParticleToMCTruth_P(const simb::MCParticle *p) const
const art::Ptr< simb::MCTruth > & cheat::ParticleInventory::ParticleToMCTruth_P ( const simb::MCParticle *  p) const

Definition at line 81 of file ParticleInventory.cc.

82  {
83  return this->TrackIdToMCTruth_P(p->TrackId());
84  }
pdgs p
Definition: selectors.fcl:22
const art::Ptr< simb::MCTruth > & TrackIdToMCTruth_P(int const &id) const
template<typename Evt >
void cheat::ParticleInventory::PrepEvent ( const Evt &  evt)

Function to set up the ParticleInventory state for an event. This is a function to tell the ParticleInventory to prepare itself to work with a particular event.

Parameters
evtThe event the ParticleInventory should work with. *Note. This use breaks the multithreading model because the service has a "state".
template<typename Evt >
void cheat::ParticleInventory::PrepMCTruthList ( const Evt &  evt) const

A function to load and cache the MCTruthList of the event.

template<typename Evt >
void cheat::ParticleInventory::PrepMCTruthListAndTrackIdToMCTruthIndex ( const Evt &  evt) const

A function to make both PrepTrackIdToMCTruthIndex and PrepMCTruthList run when both are needed.

template<typename Evt >
void cheat::ParticleInventory::PrepParticleList ( const Evt &  evt) const

A function to load the ParticleList and cache it This function will find the particle list and load it for later use. Ideally this would would be used for a "lazy" loading of the backtracker, but this does not work in the current setup of art.

template<typename Evt >
void cheat::ParticleInventory::PrepTrackIdToMCTruthIndex ( const Evt &  evt) const

A function to prepare and cache a map of TrackIds and MCTruth object indicies from fMCTruthList.

void cheat::ParticleInventory::SetEveIdCalculator ( sim::EveIdCalculator *  ec)
inline

Definition at line 216 of file ParticleInventory.h.

216 { fParticleList.AdoptEveIdCalculator(ec); }
sim::ParticleList fParticleList
int cheat::ParticleInventory::TrackIdToEveTrackId ( const int &  tid) const
inline

Definition at line 238 of file ParticleInventory.h.

238 { return fParticleList.EveId(tid);}
sim::ParticleList fParticleList
simb::MCTruth cheat::ParticleInventory::TrackIdToMCTruth ( int const &  id) const
inline

Definition at line 233 of file ParticleInventory.h.

234  { return *(this->TrackIdToMCTruth_P(id)); }
const art::Ptr< simb::MCTruth > & TrackIdToMCTruth_P(int const &id) const
const art::Ptr< simb::MCTruth > & cheat::ParticleInventory::TrackIdToMCTruth_P ( int const &  id) const

Definition at line 67 of file ParticleInventory.cc.

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  }
T abs(T value)
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
A vector containing the MCTruth objects.
const std::map< int, int >& cheat::ParticleInventory::TrackIdToMCTruthIndex ( ) const
inline

Definition at line 220 of file ParticleInventory.h.

bool cheat::ParticleInventory::TrackIdToMCTruthReady ( ) const
inline

A simple check to determine if the TrackIdToMCTruth map has been prepared or not.

Definition at line 202 of file ParticleInventory.h.

202 { return !(fMCTObj.fTrackIdToMCTruthIndex.empty());}
simb::MCParticle cheat::ParticleInventory::TrackIdToMotherParticle ( int const &  id) const
inline

Definition at line 229 of file ParticleInventory.h.

230  { return *(this->TrackIdToMotherParticle_P(id)); }
const simb::MCParticle * TrackIdToMotherParticle_P(int const &id) const
const simb::MCParticle * cheat::ParticleInventory::TrackIdToMotherParticle_P ( int const &  id) const

Definition at line 61 of file ParticleInventory.cc.

62  {
63  return this->TrackIdToParticle_P(fParticleList.EveId(abs(id)));
64  }
sim::ParticleList fParticleList
T abs(T value)
const simb::MCParticle * TrackIdToParticle_P(int const &id) const
simb::MCParticle cheat::ParticleInventory::TrackIdToParticle ( int const &  id) const
inline

Definition at line 225 of file ParticleInventory.h.

226  { return *(this->TrackIdToParticle_P(id)); }//Users are encouraged to use TrackIdToParticleP
const simb::MCParticle * TrackIdToParticle_P(int const &id) const
const simb::MCParticle * cheat::ParticleInventory::TrackIdToParticle_P ( int const &  id) const

Definition at line 48 of file ParticleInventory.cc.

48  {
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
sim::ParticleList fParticleList

Member Data Documentation

std::string cheat::ParticleInventory::fEveIdCalculator
private

Definition at line 267 of file ParticleInventory.h.

art::InputTag cheat::ParticleInventory::fG4ModuleLabel
private

Definition at line 260 of file ParticleInventory.h.

MCTObjects cheat::ParticleInventory::fMCTObj
mutableprivate

Definition at line 258 of file ParticleInventory.h.

bool cheat::ParticleInventory::fOverrideRealData
private

Definition at line 268 of file ParticleInventory.h.

sim::ParticleList cheat::ParticleInventory::fParticleList
mutableprivate

Definition at line 253 of file ParticleInventory.h.


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