LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
PhotonBackTracker.h
Go to the documentation of this file.
1 //
3 // \file PhotonBackTracker.h
4 // \brief The functions needed for the PhotonBackTracker class needed by the PhotonBackTrackerService in order to connect truth information with reconstruction.
5 // \author jason.stock@mines.sdsmt.edu
6 //
7 // Based on the original BackTracker by brebel@fnal.gov
8 //
10 //
11 //TODO: Impliment alternate backtracking scheme developed by T. Usher
12 //
14 #ifndef CHEAT_PHOTONBACKTRACKER_H
15 #define CHEAT_PHOTONBACKTRACKER_H
16 
17 //CPP
18 #include <map>
19 #include <unordered_set>
20 #include <vector>
21 
22 //Framework
25 #include "fhiclcpp/fwd.h"
26 #include "fhiclcpp/types/Atom.h"
28 
29 //LArSoft
35 
36 namespace cheat {
37  class ParticleInventory;
38 }
39 namespace sim {
40  struct SDP;
41  struct TrackSDP;
42 }
43 
44 namespace cheat {
45  class PhotonBackTracker {
46  public:
47  struct fhiclConfig {
49  fhicl::Name("Delay"),
50  fhicl::Comment("The delay time needed to correctly account for the optical simulation and "
51  "optical systems simulation. (The time between when a g4partcile was made, "
52  "and when the simulation write out says a signal was recorded)."),
53  0};
55  fhicl::Name("G4ModuleLabel"),
57  "The label of the LArG4 module used to produce the art file we will be using."),
58  "largeant"};
60  fhicl::Name("G4ModuleLabels"),
62  "The labels of the LArG4 modules used to produce the art file we will be using."),
64  // The following should be removed and replaced with some way to access the
65  // OpHitLabel given by the user in their own analysis module to avoid differing
66  // definitions.
68  fhicl::Name("OpHitLabel"),
69  fhicl::Comment("The default label for the module to use when grabbing OpHits"),
70  "ophit"};
71  // The following should be removed and replaced with some way to access the
72  // OpFlashLabel given by the user in their own analysis module to avoid differing
73  // definitions.
75  fhicl::Name("OpFlashLabel"),
76  fhicl::Comment("The default label for the module to use when grabbing OpFlash"),
77  "opflash"};
78  fhicl::Atom<double> MinOpHitEnergyFraction{
79  fhicl::Name("MinOpHitEnergyFraction"),
80  fhicl::Comment("The minimum contribution an energy deposit must make to a Hit to be "
81  "considered part of that hit."),
82  0.010};
83  };
84 
85  //----------------------------------------------------------------
86  PhotonBackTracker(fhiclConfig const& config,
87  const cheat::ParticleInventory* partInv,
88  geo::WireReadoutGeom const* wireReadoutGeom);
89 
90  //----------------------------------------------------------------
92  const cheat::ParticleInventory* partInv,
93  geo::WireReadoutGeom const* wireReadoutGeom);
94 
95  //----------------------------------------------------------------
96  PhotonBackTracker(PhotonBackTracker const&) = delete;
97 
98  //-----------------------------------------------------
99  template <typename Evt>
100  void PrepEvent(Evt const& evt);
101 
102  //-----------------------------------------------------
103  template <typename Evt>
104  bool CanRun(Evt const& evt);
105 
106  //-----------------------------------------------------
107  template <typename Evt>
108  void PrepOpDetBTRs(Evt const& evt);
109 
110  //-----------------------------------------------------
111  template <typename Evt>
112  void PrepOpFlashToOpHits(Evt const& evt);
113 
114  //-----------------------------------------------------
115  std::vector<art::Ptr<recob::OpHit>> OpFlashToOpHits_Ps(art::Ptr<recob::OpFlash>& flash_P) const;
116 
117  //-----------------------------------------------------
118  std::vector<double> OpFlashToXYZ(art::Ptr<recob::OpFlash>& flash_P) const;
119 
120  //-----------------------------------------------------
121  std::set<int> OpFlashToTrackIds(art::Ptr<recob::OpFlash>& flash_P) const;
122 
123  double GetDelay() const;
124  void ClearEvent();
125  bool BTRsReady() const;
126  bool OpFlashToOpHitsReady() const;
127 
128  std::vector<art::Ptr<sim::OpDetBacktrackerRecord>> const& OpDetBTRs() const;
129  std::vector<const sim::SDP*> TrackIdToSimSDPs_Ps(int id) const;
130  art::Ptr<sim::OpDetBacktrackerRecord> FindOpDetBTR(int opDetNum) const;
131 
132  //-----------------------------------------------------
133 
134  std::vector<sim::TrackSDP> OpDetToTrackSDPs(int OpDetNum,
135  double opHit_start_time,
136  double opHit_end_time) const;
137  std::vector<sim::TrackSDP> OpHitToTrackSDPs(art::Ptr<recob::OpHit> const& opHit_P) const;
138  std::vector<sim::TrackSDP> OpHitToTrackSDPs(recob::OpHit const& opHit) const;
139  std::vector<int> OpHitToTrackIds(recob::OpHit const& opHit) const;
140  std::vector<int> OpHitToTrackIds(art::Ptr<recob::OpHit> const& opHit) const;
141  std::vector<int> OpHitToEveTrackIds(recob::OpHit const& opHit);
142  std::vector<int> OpHitToEveTrackIds(art::Ptr<recob::OpHit> const& opHit_P);
143  std::vector<sim::TrackSDP> OpHitToEveTrackSDPs(art::Ptr<recob::OpHit> const& opHit_P) const;
144  std::vector<sim::TrackSDP> OpHitToEveTrackSDPs(recob::OpHit const& opHit) const;
145 
146  //-----------------------------------------------------
147  std::vector<art::Ptr<recob::OpHit>> TrackIdToOpHits_Ps(
148  int tkId,
149  std::vector<art::Ptr<recob::OpHit>> const& hitsIn) const;
150  std::vector<std::vector<art::Ptr<recob::OpHit>>> TrackIdsToOpHits_Ps(
151  std::vector<int> const& tkIds,
152  std::vector<art::Ptr<recob::OpHit>> const& hitsIn) const;
153 
154  //-----------------------------------------------------
155  std::vector<const sim::SDP*> OpHitToSimSDPs_Ps(recob::OpHit const& opHit) const;
156  std::vector<const sim::SDP*> OpHitToSimSDPs_Ps(art::Ptr<recob::OpHit> const& opHit_P) const;
157  std::vector<const sim::SDP*> OpHitsToSimSDPs_Ps(
158  std::vector<art::Ptr<recob::OpHit>> const& opHits_Ps) const;
159 
160  //-----------------------------------------------------
161  std::vector<double> SimSDPsToXYZ(std::vector<sim::SDP> const& sdps) const&;
162  std::vector<double> SimSDPsToXYZ(std::vector<const sim::SDP*> const& sdps_Ps) const&;
163 
164  //-----------------------------------------------------
165  std::vector<double> OpHitToXYZ(art::Ptr<recob::OpHit> const& opHit);
166  std::vector<double> OpHitToXYZ(recob::OpHit const& opHit);
167  std::vector<double> OpHitsToXYZ(std::vector<art::Ptr<recob::OpHit>> const& opHits_Ps) const;
168 
169  //-----------------------------------------------------
170  std::unordered_set<const sim::SDP*> OpHitToEveSimSDPs_Ps(recob::OpHit const& opHit);
171  std::unordered_set<const sim::SDP*> OpHitToEveSimSDPs_Ps(art::Ptr<recob::OpHit>& opHit_P);
172 
173  //-----------------------------------------------------
174  std::set<int> GetSetOfEveIds() const;
175  std::set<int> GetSetOfTrackIds() const;
176  std::set<int> GetSetOfEveIds(std::vector<art::Ptr<recob::OpHit>> const& opHits) const;
177  std::set<int> GetSetOfEveIds(std::vector<recob::OpHit> const& opHits) const;
178  std::set<int> GetSetOfTrackIds(std::vector<art::Ptr<recob::OpHit>> const& opHits) const;
179  std::set<int> GetSetOfTrackIds(std::vector<recob::OpHit> const& opHits) const;
180 
181  //-----------------------------------------------------
182  double OpHitCollectionPurity(std::set<int> const& tkIds,
183  std::vector<art::Ptr<recob::OpHit>> const& opHits);
184  double OpHitLightCollectionPurity(std::set<int> const& tkIds,
185  std::vector<art::Ptr<recob::OpHit>> const& opHits);
186  double OpHitCollectionEfficiency(std::set<int> const& tkIds,
187  std::vector<art::Ptr<recob::OpHit>> const& opHits,
188  std::vector<art::Ptr<recob::OpHit>> const& opHitsIn);
189  double OpHitLightCollectionEfficiency(std::set<int> const& tkIds,
190  std::vector<art::Ptr<recob::OpHit>> const& opHits,
191  std::vector<art::Ptr<recob::OpHit>> const& opHitsIn);
192 
193  private:
194  const cheat::ParticleInventory* fPartInv; //The constructor needs to put something in here
196  const double fDelay;
198  const std::vector<art::InputTag> fG4ModuleLabels;
202  mutable std::vector<art::Ptr<sim::OpDetBacktrackerRecord>> priv_OpDetBTRs;
203  std::map<art::Ptr<recob::OpFlash>, std::vector<art::Ptr<recob::OpHit>>> priv_OpFlashToOpHits;
204  };
205 }
206 
207 #include "PhotonBackTracker.tcc"
208 
209 #endif
const double fMinOpHitEnergyFraction
std::map< art::Ptr< recob::OpFlash >, std::vector< art::Ptr< recob::OpHit > > > priv_OpFlashToOpHits
const art::InputTag fG4ModuleLabel
const geo::WireReadoutGeom * fWireReadoutGeom
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
const cheat::ParticleInventory * fPartInv
std::vector< art::Ptr< sim::OpDetBacktrackerRecord > > priv_OpDetBTRs
Interface for a class providing readout channel mapping to geometry.
Monte Carlo Simulation.
Definition of data types for geometry description.
const art::InputTag fOpFlashLabel
code to link reconstructed objects back to the MC truth information
Definition: BackTracker.cc:24
const std::vector< art::InputTag > fG4ModuleLabels
const art::InputTag fOpHitLabel
TCEvent evt
Definition: DataStructs.cxx:8