LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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::ParticleListParticleList () 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::MCParticleTrackIdToParticle_P (int const &id) const
 
simb::MCParticle TrackIdToParticle (int const &id) const
 
const simb::MCParticleTrackIdToMotherParticle_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 174 of file ParticleInventory.h.

Constructor & Destructor Documentation

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

Definition at line 21 of file ParticleInventory.cc.

Referenced by cheat::ParticleInventoryService::ParticleInventoryService().

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

Definition at line 28 of file ParticleInventory.cc.

29  : fG4ModuleLabel(pSet.get<art::InputTag>("G4ModuleLabel", "largeant"))
30  , fEveIdCalculator(pSet.get<std::string>("EveIdCalculator", "EmEveIdCalculator"))
31  , fOverrideRealData(pSet.get<bool>("OverrideRealData", false))
32  {}
T get(std::string const &key) const
Definition: ParameterSet.h:314
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.

Referenced by cheat::ParticleInventoryService::priv_CanRun().

void cheat::ParticleInventory::ClearEvent ( )
std::set< int > cheat::ParticleInventory::GetSetOfEveIds ( ) const

Definition at line 115 of file ParticleInventory.cc.

References sim::ParticleList::EveId(), fParticleList, and GetSetOfTrackIds().

Referenced by cheat::ParticleInventoryService::GetSetOfEveIds(), and cheat::PhotonBackTracker::GetSetOfEveIds().

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

Definition at line 105 of file ParticleInventory.cc.

References sim::ParticleList::begin(), sim::ParticleList::end(), and fParticleList.

Referenced by GetSetOfEveIds(), cheat::ParticleInventoryService::GetSetOfTrackIds(), and cheat::PhotonBackTracker::GetSetOfTrackIds().

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  }
sim::ParticleList fParticleList
iterator begin()
Definition: ParticleList.h:305
const std::vector<art::Ptr<simb::MCTruth> >& cheat::ParticleInventory::MCTruthList ( ) const
inline

Definition at line 223 of file ParticleInventory.h.

223 { 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 206 of file ParticleInventory.h.

References util::empty().

206 { return !((fMCTObj.fMCTruthList).empty()); }
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
A vector containing the MCTruth objects.
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Definition: StdUtils.h:109
std::vector< const simb::MCParticle * > cheat::ParticleInventory::MCTruthToParticles_Ps ( art::Ptr< simb::MCTruth > const &  mct) const

Definition at line 93 of file ParticleInventory.cc.

References fParticleList, and TrackIdToMCTruth_P().

Referenced by cheat::ParticleInventoryService::MCTruthToParticles_Ps().

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  }
sim::ParticleList fParticleList
list_type::value_type value_type
Definition: ParticleList.h:130
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.

References fMCTObj, and cheat::ParticleInventory::MCTObjects::fMCTruthList.

Referenced by cheat::ParticleInventoryService::MCTruthVector_Ps().

88  {
89  return fMCTObj.fMCTruthList;
90  }
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
A vector containing the MCTruth objects.
const sim::ParticleList& cheat::ParticleInventory::ParticleList ( ) const
inline
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 205 of file ParticleInventory.h.

205 { return !(fParticleList.empty()); }
sim::ParticleList fParticleList
bool empty() const
Definition: ParticleList.h:314
simb::MCTruth cheat::ParticleInventory::ParticleToMCTruth ( const simb::MCParticle p) const
inline

Definition at line 258 of file ParticleInventory.h.

259  {
260  return *(this->ParticleToMCTruth_P(p));
261  }
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 80 of file ParticleInventory.cc.

References simb::MCParticle::TrackId(), and TrackIdToMCTruth_P().

82  {
83  return this->TrackIdToMCTruth_P(p->TrackId());
84  }
int TrackId() const
Definition: MCParticle.h:211
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.

Referenced by cheat::ParticleInventoryService::priv_PrepMCTruthList().

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.

Referenced by cheat::ParticleInventoryService::priv_PrepParticleList().

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.

Referenced by cheat::ParticleInventoryService::priv_PrepTrackIdToMCTruthIndex().

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

Definition at line 221 of file ParticleInventory.h.

sim::ParticleList fParticleList
static void AdoptEveIdCalculator(EveIdCalculator *)
int cheat::ParticleInventory::TrackIdToEveTrackId ( const int &  tid) const
inline

Definition at line 254 of file ParticleInventory.h.

Referenced by cheat::BackTracker::HitToEveTrackIDEs(), and cheat::ParticleInventoryService::TrackIdToEveTrackId().

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

Definition at line 246 of file ParticleInventory.h.

248  {
249  return *(this->TrackIdToMCTruth_P(id));
250  }
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 65 of file ParticleInventory.cc.

References util::abs(), fMCTObj, cheat::ParticleInventory::MCTObjects::fMCTruthList, and cheat::ParticleInventory::MCTObjects::fTrackIdToMCTruthIndex.

Referenced by MCTruthToParticles_Ps(), ParticleToMCTruth_P(), and cheat::ParticleInventoryService::TrackIdToMCTruth_P().

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  }
constexpr auto abs(T v)
Returns the absolute value of the argument.
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
A vector containing the MCTruth objects.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
const std::map<int, int>& cheat::ParticleInventory::TrackIdToMCTruthIndex ( ) const
inline

Definition at line 225 of file ParticleInventory.h.

226  {
228  }
bool cheat::ParticleInventory::TrackIdToMCTruthReady ( ) const
inline

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

Definition at line 207 of file ParticleInventory.h.

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

Definition at line 239 of file ParticleInventory.h.

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

Definition at line 59 of file ParticleInventory.cc.

References util::abs(), sim::ParticleList::EveId(), fParticleList, and TrackIdToParticle_P().

Referenced by cheat::ParticleInventoryService::TrackIdToMotherParticle_P().

60  {
61  return this->TrackIdToParticle_P(fParticleList.EveId(abs(id)));
62  }
sim::ParticleList fParticleList
constexpr auto abs(T v)
Returns the absolute value of the argument.
int EveId(const int trackID) const
const simb::MCParticle * TrackIdToParticle_P(int const &id) const
simb::MCParticle cheat::ParticleInventory::TrackIdToParticle ( int const &  id) const
inline

Definition at line 233 of file ParticleInventory.h.

234  {
235  return *(this->TrackIdToParticle_P(id));
236  } //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 46 of file ParticleInventory.cc.

References sim::ParticleList::end(), sim::ParticleList::find(), and fParticleList.

Referenced by TrackIdToMotherParticle_P(), and cheat::ParticleInventoryService::TrackIdToParticle_P().

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
sim::ParticleList fParticleList
list_type::const_iterator const_iterator
Definition: ParticleList.h:132
iterator find(const key_type &key)
Definition: ParticleList.h:318
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning

Member Data Documentation

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

Definition at line 288 of file ParticleInventory.h.

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

Definition at line 281 of file ParticleInventory.h.

MCTObjects cheat::ParticleInventory::fMCTObj
mutableprivate

Definition at line 279 of file ParticleInventory.h.

Referenced by ClearEvent(), MCTruthVector_Ps(), and TrackIdToMCTruth_P().

bool cheat::ParticleInventory::fOverrideRealData
private

Definition at line 289 of file ParticleInventory.h.

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

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