All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
old.PhotonBackTrackerService.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file PhotonBackTracker.h
3 /// \brief back track the reconstruction to the simulation
4 ///
5 /// \author jstock@fnal.gov
6 // \adapted from BackTracker.h by brebel@fnal.gov
7 ////////////////////////////////////////////////////////////////////////
8 #ifndef CHEAT_PHOTONBACKTRACKERER_H
9 #define CHEAT_PHOTONBACKTRACKERER_H
10 #ifdef __GNUC__
11 #define DEPRECATED __attribute__((deprecated))
12 #else
13 #define DEPRECATED
14 #endif
15 
16 
17 
18 #include <vector>
19 
20 #include "fhiclcpp/ParameterSet.h"
21 #include "art/Framework/Principal/Run.h"
22 #include "art/Framework/Services/Registry/ActivityRegistry.h"
23 #include "art/Framework/Services/Registry/ServiceHandle.h"
24 
26 #include "nusimdata/SimulationBase/MCParticle.h"
27 #include "nug4/ParticleNavigation/ParticleList.h"
29 #include "nug4/ParticleNavigation/EveIdCalculator.h"
30 #include "nusimdata/SimulationBase/MCTruth.h"
35 
37 
38 /*namespace recob{
39  class SpacePoint;
40 }*/
41 
42 ///code to link reconstructed objects back to the MC truth information
43 namespace cheat{
44 
45  class PhotonBackTracker
46  {
47 
48  public:
49 
50  PhotonBackTracker(fhicl::ParameterSet const& pset,
51  art::ActivityRegistry& reg);
53 
54  void reconfigure(fhicl::ParameterSet const& pset);
55 
56  // The Rebuild function rebuilds the various maps we need to answer backtracking queries.
57  // It is called automatically before each event is processed. For jobs involving
58  // Monte Carlo generation, this is too soon. So, we'll call rebuild after those data
59  // products are put into the event in LArG4. This is the least bad way of ensuring the
60  // PhotonBackTracker works in jobs that combine MC production and reconstruction analysis based
61  // on MC truth. Don't copy this design pattern without talking to brebel@fnal.gov first
62  void Rebuild(const art::Event& evt);
63 
64  // Get a reference to the ParticleList
65  const sim::ParticleList& ParticleList() const { return fParticleList; }
66 
67  // Set the EveIdCalculator for the owned ParticleList
68  void SetEveIdCalculator(sim::EveIdCalculator *ec) { fParticleList.AdoptEveIdCalculator(ec); }
69 
70  // Return a pointer to the simb::MCParticle object corresponding to
71  // the given TrackID
72  const simb::MCParticle* TrackIDToParticle(int const& id) const;
73  const simb::MCParticle* TrackIDToMotherParticle(int const& id) const;
74 
75  std::vector<sim::SDP> TrackIDToSimSDP(int const& id) const;
76 
77  // Get art::Ptr<> to simb::MCTruth and related information
78  const art::Ptr<simb::MCTruth>& TrackIDToMCTruth(int const& id) const;
79  const art::Ptr<simb::MCTruth>& ParticleToMCTruth(const simb::MCParticle* p) const;
80  std::vector<const simb::MCParticle*> MCTruthToParticles(art::Ptr<simb::MCTruth> const& mct) const;
81  const std::vector< art::Ptr<simb::MCTruth> >& MCTruthVector() const { return fMCTruthList; }
82 
83  // this method will return the Geant4 track IDs of
84  // the particles contributing ionization electrons to the identified hit
85  DEPRECATED std::vector<sim::TrackSDP> OpHitToTrackID(art::Ptr<recob::OpHit> const& hit)
86  {return OpHitToTrackSDPs(hit);}
87  std::vector<sim::TrackSDP> OpHitToTrackSDPs(art::Ptr<recob::OpHit> const& hit);
88 
89  // method to return a subset of allhits that are matched to a list of TrackIDs
90  const std::vector<std::vector<art::Ptr<recob::OpHit>>> TrackIDsToOpHits(std::vector<art::Ptr<recob::OpHit>> const& allhits,
91  std::vector<int> const& tkIDs);
92 
93  // method to return the EveIDs of particles contributing ionization
94  // electrons to the identified hit
95  std::vector<sim::TrackSDP> OpHitToEveSDPs(art::Ptr<recob::OpHit> const& hit);
96  std::vector<sim::TrackSDP> OpHitToEveID(art::Ptr<recob::OpHit> const& hit);
97 
98  //@{
99  // method to return sim::SDP objects associated with a given hit
100  void OpHitToSDPs(recob::OpHit const& hit,
101  std::vector<sim::SDP>& sdps) const;
103  std::vector<sim::SDP>& sdps) const
104  { OpHitToSDPs( hit, sdps); }
105  void OpHitToSDPs(art::Ptr<recob::OpHit> const& hit,
106  std::vector<sim::SDP>& sdps) const
107  { OpHitToSDPs(*hit, sdps); }
108  DEPRECATED void OpHitToSimSDPs(art::Ptr<recob::OpHit> const& hit,
109  std::vector<sim::SDP>& sdps) const
110  { OpHitToSDPs(*hit, sdps); }
111  //@}
112 
113  // method to return the XYZ position of the weighted average energy deposition for a given hit
114  std::vector<double> SimSDPsToXYZ(std::vector<sim::SDP> const& sdps);
115 
116  // method to return the XYZ position of the weighted average energy deposition for a given hit
117  std::vector<double> OpHitToXYZ(art::Ptr<recob::OpHit> const& hit);
118 
119  // method to return the XYZ position of a space point (unweighted average XYZ of component hits).
120 /* std::vector<double> SpacePointToXYZ(art::Ptr<recob::SpacePoint> const& spt,
121  art::Event const& evt,
122  std::string const& label);*/
123 
124  // method to return the XYZ position of a space point (unweighted average XYZ of component hits).
125 /* std::vector<double> SpacePointHitsToXYZ(art::PtrVector<recob::Hit> const& hits);*/
126 
127  // method to return the fraction of hits in a collection that come from the specified Geant4 track ids
128  double OpHitCollectionPurity(std::set<int> trackIDs,
129  std::vector< art::Ptr<recob::OpHit> > const& hits);
130 
131  // method to return the fraction of all hits in an event from a specific set of Geant4 track IDs that are
132  // represented in a collection of hits
133  double OpHitCollectionEfficiency(std::set<int> trackIDs,
134  std::vector< art::Ptr<recob::OpHit> > const& hits,
135  std::vector< art::Ptr<recob::OpHit> > const& allhits);
136  double OpHitCollectionEfficiency(std::set<int> trackIDs,
137  std::vector< art::Ptr<recob::OpHit> > const& hits,
138  std::vector< art::Ptr<recob::OpHit> > const& allhits,
139  geo::View_t const& view);
140 
141  // method to return the fraction of charge in a collection that come from the specified Geant4 track ids
142  double OpHitChargeCollectionPurity(std::set<int> trackIDs,
143  std::vector< art::Ptr<recob::OpHit> > const& hits);
144 
145  // method to return the fraction of all charge in an event from a specific set of Geant4 track IDs that are
146  // represented in a collection of hits
147  double OpHitChargeCollectionEfficiency(std::set<int> trackIDs,
148  std::vector< art::Ptr<recob::OpHit> > const& hits,
149  std::vector< art::Ptr<recob::OpHit> > const& allhits);
150  double OpHitChargeCollectionEfficiency(std::set<int> trackIDs,
151  std::vector< art::Ptr<recob::OpHit> > const& hits,
152  std::vector< art::Ptr<recob::OpHit> > const& allhits,
153  geo::View_t const& view);
154 
155  // method to return all EveIDs corresponding to the current sim::ParticleList
156  std::set<int> GetSetOfEveIDs();
157 
158  // method to return all TrackIDs corresponding to the current sim::ParticleList
159  std::set<int> GetSetOfTrackIDs();
160 
161  // method to return all EveIDs corresponding to the given list of hits
162  std::set<int> GetSetOfEveIDs(std::vector< art::Ptr<recob::OpHit> > const& hits);
163 
164  // method to return all TrackIDs corresponding to the given list of hits
165  std::set<int> GetSetOfTrackIDs(std::vector< art::Ptr<recob::OpHit> > const& hits);
166 
167  const std::vector< art::Ptr< sim::OpDetBacktrackerRecord >>& OpDetBacktrackerRecords() const { return cOpDetBacktrackerRecords; }
168 
169  void ChannelToTrackSDPs(std::vector<sim::TrackSDP>& trackSDPs,
170  int channel,
171  const double hit_start_time,
172  const double hit_end_time);
173 
174  private:
175 
176  geo::GeometryCore const* geom = lar::providerFrom<geo::Geometry>();
177 
178  const art::Ptr< sim::OpDetBacktrackerRecord > FindOpDetBacktrackerRecord(int channel) const;
179 
180  const void shouldThisFail() const;
181 
182  bool have_complained;
183 
184  sim::ParticleList fParticleList; ///< ParticleList to map track ID to sim::Particle
185  sim::LArVoxelList fVoxelList; ///< List to map the position of energy depostions
186  ///< in voxels to the particles depositing the
187  ///< energy
188  std::vector< art::Ptr<simb::MCTruth> > fMCTruthList; ///< all the MCTruths for the event
189  std::vector< art::Ptr< sim::OpDetBacktrackerRecord >> cOpDetBacktrackerRecords; ///< all the OpDetBacktrackerRecords for the event
190  std::map<int, int> fTrackIDToMCTruthIndex; ///< map of track ids to MCTruthList entry
191  std::string fG4ModuleLabel; ///< label for geant4 module
192  double fMinOpHitEnergyFraction; ///< minimum fraction of energy a track id has to
193  double fDelay; //Shift in time
194  ///< contribute to a hit to be counted in
195  ///< purity and efficiency calculations
196  ///< based on hit collections
197  };
198 } // namespace
199 
200 DECLARE_ART_SERVICE(cheat::PhotonBackTracker, LEGACY)
201 #endif // CHEAT_PHOTONBACKTRACKER_H
const simb::MCParticle * TrackIDToParticle(int const &id) const
std::vector< const simb::MCParticle * > MCTruthToParticles(art::Ptr< simb::MCTruth > const &mct) const
DEPRECATED void OpHitToSimSDPs(recob::OpHit const &hit, std::vector< sim::SDP > &sdps) const
#define DEPRECATED
std::vector< double > OpHitToXYZ(art::Ptr< recob::OpHit > const &hit)
void SetEveIdCalculator(sim::EveIdCalculator *ec)
std::map< int, int > fTrackIDToMCTruthIndex
map of track ids to MCTruthList entry
Container of LAr voxel information.
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
std::vector< sim::SDP > TrackIDToSimSDP(int const &id) const
pdgs p
Definition: selectors.fcl:22
std::vector< double > SimSDPsToXYZ(std::vector< sim::SDP > const &sdps)
process_name hit
Definition: cheaterreco.fcl:51
double OpHitCollectionPurity(std::set< int > trackIDs, std::vector< art::Ptr< recob::OpHit > > const &hits)
const art::Ptr< simb::MCTruth > & ParticleToMCTruth(const simb::MCParticle *p) const
std::string fG4ModuleLabel
label for geant4 module
double OpHitChargeCollectionEfficiency(std::set< int > trackIDs, std::vector< art::Ptr< recob::OpHit > > const &hits, std::vector< art::Ptr< recob::OpHit > > const &allhits)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
Access the description of detector geometry.
void OpHitToSDPs(recob::OpHit const &hit, std::vector< sim::SDP > &sdps) const
void reconfigure(fhicl::ParameterSet const &pset)
DEPRECATED void OpHitToSimSDPs(art::Ptr< recob::OpHit > const &hit, std::vector< sim::SDP > &sdps) const
std::vector< sim::TrackSDP > OpHitToEveSDPs(art::Ptr< recob::OpHit > const &hit)
void ChannelToTrackSDPs(std::vector< sim::TrackSDP > &trackSDPs, int channel, const double hit_start_time, const double hit_end_time)
double OpHitCollectionEfficiency(std::set< int > trackIDs, std::vector< art::Ptr< recob::OpHit > > const &hits, std::vector< art::Ptr< recob::OpHit > > const &allhits)
const simb::MCParticle * TrackIDToMotherParticle(int const &id) const
Description of geometry of one entire detector.
void Rebuild(const art::Event &evt)
Definition of data types for geometry description.
void OpHitToSDPs(art::Ptr< recob::OpHit > const &hit, std::vector< sim::SDP > &sdps) const
const sim::ParticleList & ParticleList() const
std::vector< sim::TrackSDP > OpHitToTrackSDPs(art::Ptr< recob::OpHit > const &hit)
std::vector< sim::TrackSDP > OpHitToEveID(art::Ptr< recob::OpHit > const &hit)
PhotonBackTracker(fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
const art::Ptr< sim::OpDetBacktrackerRecord > FindOpDetBacktrackerRecord(int channel) const
geo::GeometryCore const * geom
double fMinOpHitEnergyFraction
minimum fraction of energy a track id has to
const std::vector< art::Ptr< simb::MCTruth > > & MCTruthVector() const
TCEvent evt
Definition: DataStructs.cxx:8
std::vector< art::Ptr< sim::OpDetBacktrackerRecord > > cOpDetBacktrackerRecords
all the OpDetBacktrackerRecords for the event
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
all the MCTruths for the event
double OpHitChargeCollectionPurity(std::set< int > trackIDs, std::vector< art::Ptr< recob::OpHit > > const &hits)
const std::vector< art::Ptr< sim::OpDetBacktrackerRecord > > & OpDetBacktrackerRecords() const
const std::vector< std::vector< art::Ptr< recob::OpHit > > > TrackIDsToOpHits(std::vector< art::Ptr< recob::OpHit >> const &allhits, std::vector< int > const &tkIDs)
sim::ParticleList fParticleList
ParticleList to map track ID to sim::Particle.
art framework interface to geometry description
DEPRECATED std::vector< sim::TrackSDP > OpHitToTrackID(art::Ptr< recob::OpHit > const &hit)
const art::Ptr< simb::MCTruth > & TrackIDToMCTruth(int const &id) const