ProtoDUNETruthUtils.h
Go to the documentation of this file.
1 #ifndef PROTODUNE_TRUTH_UTILS_H
2 #define PROTODUNE_TRUTH_UTILS_H
3 
4 ///////////////////////////////////////////////////////////////
5 // ProtoDUNETruthUtils
6 // - Class to help analysers access useful truth information
7 //
8 // Leigh Whitehead - leigh.howard.whitehead@cern.ch
9 ///////////////////////////////////////////////////////////////
10 
11 
21 
23 
24 namespace detinfo {
25  class DetectorClocksData;
26 }
27 
28 namespace protoana {
29 
32  particle(0x0), nSharedHits(0), nSharedDeltaRayHits(0) {};
33 
34  const simb::MCParticle * particle;
35  size_t nSharedHits;
37  };
38 
40 
41  public:
42 
45 
46  // Get shared hits between reco objects and MCParticle.
47 
48  std::vector< const recob::Hit * > FillSharedHits(
49  detinfo::DetectorClocksData const& clockData,
50  const simb::MCParticle & mcpart,
51  const std::vector<const recob::Hit *> & hitsVec,
52  bool delta_ray, bool use_eve = true) const;
53 
54  std::vector<const recob::Hit*> GetSharedHits(detinfo::DetectorClocksData const& clockData,
55  const simb::MCParticle &mcpart,
56  const recob::PFParticle &pfpart, const art::Event &evt, std::string pfparticleModule, bool delta_ray = false) const;
57  std::vector<const recob::Hit*> GetSharedHits(detinfo::DetectorClocksData const& clockData,
58  const simb::MCParticle &mcpart,
59  const recob::Track &track, const art::Event &evt, std::string trackModule, bool delta_ray = false) const;
60  std::vector<const recob::Hit*> GetSharedHits(detinfo::DetectorClocksData const& clockData,
61  const simb::MCParticle &mcpart,
62  const recob::Shower &shower, const art::Event &evt, std::string showerModule, bool delta_ray = false) const;
63 
64  // Get hits associated with an MCParticle.
65  std::vector<const recob::Hit*> GetMCParticleHits(
66  detinfo::DetectorClocksData const& clockData,
67  const simb::MCParticle &mcpart,
68  const art::Event &evt,
69  std::string hitModule,
70  bool use_eve = true) const;
71 
72  // Get completeness and purity of reconstructed objects.
73  template <typename T>
74  double GetCompleteness(detinfo::DetectorClocksData const& clockData,
75  const T &recobj,
76  const art::Event &evt,
77  std::string recoModule,
78  std::string hitModule) const;
79 
80  double GetPurity(detinfo::DetectorClocksData const& clockData,
81  const recob::PFParticle &pfpart, const art::Event &evt,
82  std::string pfparticleModule) const;
83  double GetPurity(detinfo::DetectorClocksData const& clockData,
84  const recob::Track &track, const art::Event &evt,
85  std::string trackModule) const;
86  double GetPurity(detinfo::DetectorClocksData const& clockData,
87  const recob::Shower &shower, const art::Event &evt,
88  std::string showerModule) const;
89 
90  // Get MCParticle list from a hit vector depending on whether the hits came from a shower or track.
91  std::vector<std::pair<const simb::MCParticle*, double>> GetMCParticleListFromTrackHits
92  (detinfo::DetectorClocksData const& clockData,
93  const std::vector<const recob::Hit*>& hitVec, bool use_eve = true) const;
94  std::vector<std::pair<const simb::MCParticle*, double>> GetMCParticleListFromShowerHits
95  (detinfo::DetectorClocksData const& clockData,
96  const std::vector<const recob::Hit*>& hitVec) const;
97 
98  // Contributions of MCParticles to PFParticles and vice versa
99  std::vector<std::pair<const simb::MCParticle*, double>> GetMCParticleListFromPFParticle
100  (detinfo::DetectorClocksData const& clockData,
101  const recob::PFParticle &pfpart, art::Event const &evt, std::string pfparticleModule) const;
102  std::vector<std::pair<const recob::PFParticle*, double>> GetPFParticleListFromMCParticle
103  (detinfo::DetectorClocksData const& clockData,
104  const simb::MCParticle &part, art::Event const &evt,
105  std::string pfparticleModule, bool use_eve = true) const;
106 
107  // Contributions of MCParticles to tracks and vice versa
108  std::vector<std::pair<const simb::MCParticle*, double>> GetMCParticleListFromRecoTrack
109  (detinfo::DetectorClocksData const& clockData,
110  const recob::Track &track, art::Event const &evt, std::string trackModule) const;
111  std::vector<std::pair<const recob::Track*, double>> GetRecoTrackListFromMCParticle
112  (detinfo::DetectorClocksData const& clockData,
113  const simb::MCParticle &part, art::Event const &evt, std::string trackModule) const;
114 
115  // Contributions of MCParticles to showers and vice versa
116  std::vector<std::pair<const simb::MCParticle*, double>> GetMCParticleListFromRecoShower
117  (detinfo::DetectorClocksData const& clockData,
118  const recob::Shower &shower, art::Event const &evt, std::string showerModule) const;
119  std::vector<std::pair<const recob::Shower*, double>> GetRecoShowerListFromMCParticle
120  (detinfo::DetectorClocksData const& clockData,
121  const simb::MCParticle &part, art::Event const &evt, std::string showerModule) const;
122 
123  // Best match getters between MC and reconstruction
124  const simb::MCParticle* GetMCParticleFromPFParticle
125  (detinfo::DetectorClocksData const& clockData,
126  const recob::PFParticle &pfpart, art::Event const &evt, std::string pfparticleModule) const;
127  const recob::PFParticle* GetPFParticleFromMCParticle
128  (detinfo::DetectorClocksData const& clockData,
129  const simb::MCParticle &part, art::Event const &evt, std::string pfparticleModule) const;
130  const simb::MCParticle* GetMCParticleFromRecoTrack
131  (detinfo::DetectorClocksData const& clockData,
132  const recob::Track &track, art::Event const &evt, std::string trackModule) const;
133  const recob::Track* GetRecoTrackFromMCParticle
134  (detinfo::DetectorClocksData const& clockData,
135  const simb::MCParticle &part, art::Event const &evt, std::string trackModule) const;
136  const simb::MCParticle* GetMCParticleFromRecoShower
137  (detinfo::DetectorClocksData const& clockData,
138  const recob::Shower &shower, art::Event const &evt, std::string showerModule) const;
139  const recob::Shower* GetRecoShowerFromMCParticle
140  (detinfo::DetectorClocksData const& clockData,
141  const simb::MCParticle &part, art::Event const &evt, std::string showerModule) const;
142 
143  // General overloaded MCParticle match getters
144  const simb::MCParticle* GetMCParticleFromReco
145  (detinfo::DetectorClocksData const& clockData,
146  const recob::PFParticle &pfpart, art::Event const &evt, std::string pfparticleModule) const;
147  const simb::MCParticle* GetMCParticleFromReco
148  (detinfo::DetectorClocksData const& clockData,
149  const recob::Track &track, art::Event const &evt, std::string trackModule) const;
150  const simb::MCParticle* GetMCParticleFromReco
151  (detinfo::DetectorClocksData const& clockData,
152  const recob::Shower &shower, art::Event const &evt, std::string showerModule) const;
153 
154  std::vector<std::pair<const simb::MCParticle*, double>> GetMCParticleListFromReco
155  (detinfo::DetectorClocksData const& clockData,
156  const recob::PFParticle &pfpart, art::Event const &evt, std::string pfparticleModule) const;
157  std::vector<std::pair<const simb::MCParticle*, double>> GetMCParticleListFromReco
158  (detinfo::DetectorClocksData const& clockData,
159  const recob::Track &track, art::Event const &evt, std::string trackModule) const;
160  std::vector<std::pair<const simb::MCParticle*, double>> GetMCParticleListFromReco
161  (detinfo::DetectorClocksData const& clockData,
162  const recob::Shower &shower, art::Event const &evt, std::string showerModule) const;
163 
164  // Match Reco to True by Number of Hits contributed as opposed to Energy contributed
165  template <typename T>
166  //std::vector< std::pair< const simb::MCParticle*, size_t > > GetMCParticleListByHits
167  std::vector< MCParticleSharedHits > GetMCParticleListByHits
168  (detinfo::DetectorClocksData const& clockData,
169  const T &recobj, const art::Event &evt, std::string recoModule, std::string hitModule) const;
170 
171  template <typename T>
172  //const simb::MCParticle * GetMCParticleByHits
173  const MCParticleSharedHits GetMCParticleByHits
174  (detinfo::DetectorClocksData const& clockData,
175  const T &recobj, const art::Event &evt, std::string recoModule, std::string hitModule) const;
176 
177 
178  const simb::MCParticle* MatchPduneMCtoG4( const simb::MCParticle & pDunePart, const art::Event & evt );
179  const simb::MCParticle* GetGeantGoodParticle(const simb::MCTruth &genTruth, const art::Event &evt) const;
180 
181  // Converting times in LArSoft can be a bit of a minefield. These functions convert true times in ns
182  // to pandora times in ns
183  const float ConvertTrueTimeToPandoraTimeNano(detinfo::DetectorClocksData const& clockData,
184  const simb::MCParticle &part) const;
185  const float ConvertTrueTimeToPandoraTimeNano(detinfo::DetectorClocksData const& clockData,
186  const float trueTime) const;
187  // Microsecond versions
188  const float ConvertTrueTimeToPandoraTimeMicro(detinfo::DetectorClocksData const& clockData,
189  const simb::MCParticle &part) const;
190  const float ConvertTrueTimeToPandoraTimeMicro(detinfo::DetectorClocksData const& clockData,
191  const float trueTime) const;
192 
193  // Get interaction process key.
194  int GetProcessKey(std::string process);
195 
196  // Get the MC truth deposited energy
197  double GetDepEnergyMC(const art::Event &evt, geo::GeometryCore const * fGeom, int trackid, int whichview) const;
198 
199  // Get first trajectory point in TPC active volume
200  int GetFirstTrajectoryPointInTPCActiveVolume(const simb::MCParticle& mcpart, double tpcactiveXlow, double tpcactiveXhigh, double tpcactiveYlow, double tpcactiveYhigh, double tpcactiveZlow, double tpcactiveZhigh);
201 
202  // Get MC Particle length in TPC active volume
203  double GetMCParticleLengthInTPCActiveVolume(const simb::MCParticle& mcpart, double tpcactiveXlow, double tpcactiveXhigh, double tpcactiveYlow, double tpcactiveYhigh, double tpcactiveZlow, double tpcactiveZhigh);
204 
205  // Estimate last point energy loss
206  // By default the kinetic energy at the last trajectory point is zero. Estimate the energy loss of the last trajectory by using the average energy loss of the track in the TPC active volume
207  double GetDepEnergyAtLastTrajPoint(const simb::MCParticle& mcpart, double tpcactiveXlow, double tpcactiveXhigh, double tpcactiveYlow, double tpcactiveYhigh, double tpcactiveZlow, double tpcactiveZhigh);
208 
209  // Get particle's kinetic energy at the interaction vertex
210  // It takes the particle's energy at the next to the final trajectory point and subtracts the estimated kinetic energy of the last trajectory point (by default is zero)
211  double GetKinEnergyAtVertex(const simb::MCParticle& mcpart, double kinene_lastpoint=0.0);
212 
213 
214  // Get the sim::IDEs from the MCParticle, organized by the trajectory points
215  std::map< size_t, std::vector< const sim::IDE * > > GetSimIDEs( const simb::MCParticle & mcpart );
216 
217  // Get the sim::IDes between 2 points in space
218  std::vector<const sim::IDE *> GetSimIDEsBetweenPoints(const simb::MCParticle & mcpart, const TLorentzVector & p1,
219  const TLorentzVector &p2);
220 
221  std::map< int, std::vector< int > > GetMapMCToPFPs_ByHits(detinfo::DetectorClocksData const& clockData,
222  const art::Event & evt, std::string pfpTag, std::string hitTag );
223 
224  private:
225 
226 
227  };
228 
229  //Define this it the source file, but outside of class
230  bool sort_IDEs( const sim::IDE * i1, const sim::IDE * i2)/*{
231  return( i1->z < i2->z );
232  }*/;
233 
234 }
235 
236 #endif
std::string string
Definition: nybbler.cc:12
Particle class.
art framework interface to geometry description
def process(f, kind)
Definition: search.py:254
Ionization at a point of the TPC sensitive volume.
Definition: SimChannel.h:84
bool sort_IDEs(const sim::IDE *i1, const sim::IDE *i2)
General LArSoft Utilities.
Description of geometry of one entire detector.
Declaration of signal hit object.
const simb::MCParticle * particle
Hierarchical representation of particle flow.
Definition: PFParticle.h:44
Contains all timing reference information for the detector.
Provides recob::Track data product.
Access the description of detector geometry.
TCEvent evt
Definition: DataStructs.cxx:7
Event generator information.
Definition: MCTruth.h:32
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49