BackTracker.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file BackTracker.h
3 /// \brief back track the reconstruction to the simulation
4 ///
5 /// \version $Id: BackTracker.h,v 1.37 2012-12-06 15:03:39 lein Exp $
6 /// \author brebel@fnal.gov
7 ////////////////////////////////////////////////////////////////////////
8 
9 
10 #ifndef CHEAT_BACKTRACKER_H
11 #define CHEAT_BACKTRACKER_H
12 
13 #include <map>
14 #include <unordered_map>
15 #include <vector>
16 
19 #include "NovaDAQConventions/DAQConventions.h"
20 #include "RecoBase/CellHit.h"
21 #include "RecoBase/WeightedHit.h"
22 #include "RecoBase/Cluster.h"
23 #include "RecoBase/Track.h"
25 #include "Simulation/Particle.h"
26 #include "Simulation/TrueEnergy.h"
27 #include "Simulation/FLSHit.h"
30 
33 #include "fhiclcpp/types/Atom.h"
34 
35 ///code to link reconstructed objects back to the MC truth information
36 namespace cheat{
37 
38  struct TrackIDE
39  {
40  int trackID; ///< Geant4 supplied trackID
41  float energyFrac; ///< fraction of hit energy from the particle with this trackID
42  float energy; ///< energy from the particle with this trackID
43  };
44 
46  {
47  art::Ptr<simb::MCTruth> neutrinoInt; ///< Truth information about neutrino interaction
48  double efficiency; ///< Efficiency (based on FLS energy) of neutrino interaction relative to slice
49  double purity; ///< Purity (based on FLS energy) of neutrino interaction relative to slice
50  unsigned int truthColIndex; ///< Position in column vector of MCTruths from the event
51  double energySlice; ///< Sum of FLS hits from the neutrino contributing to hits included in the slice
52  double energyTotal; ///< Sum of FLS hits from the neutrino contributing to any hit in the event
53  int nSliceHits; ///< Number of hits from this neutrino in this slice
54  int nTotalHits; ///< Total number of hits the neutrino left in the detector
55 
56  };
57 
59  {
60  art::Ptr<simb::MCTruth> neutrinoInt; ///< Truth information about neutrino interaction
61  unsigned int truthColIndex; ///< Position in column vector of MCTruths from the event
62  };
63 
65  {
66  int trackID; ///< Truth particle track ID
67  double efficiency; ///< Efficiency of particle relative to track
68  double purity; ///< Putity of particle relative to track
69  int pdg; ///< Pdg of particle
70  };
71 
72  /// Does \a a have less energy than \a b?
73  bool CompareByEnergy(const TrackIDE& a, const TrackIDE& b);
74 
75  /// Function for NeutrinoEffPur's nu interaction to slice efficiency
76  double EffMetric(const cheat::NeutrinoEffPur& ep);
77 
78  /// Function for NeutrinoEffPur's nu interaction to slice purity
79  double PurMetric(const cheat::NeutrinoEffPur& ep);
80 
81  /// Function for NeutrinoEffPur's nu interaction to slice efficiency * purity
82  double EffPurMetric(const cheat::NeutrinoEffPur& ep);
83 
84  /// Function for NeutrinoEffPur's nu interaction to slice energy
85  double EnergyMetric(const cheat::NeutrinoEffPur& ep);
86 
87  /// Many functions come in four variants. The core implementation is in terms
88  /// of vector<const T*>, which is the common basis all the others can be
89  /// converted to. If you have an art::Handle<vector<T>> you can just
90  /// dereference it to get this type. If you happen to have a vector<T> or
91  /// vector<Ptr<T>> or PtrVector<T>, overloads are provided so that those are
92  /// just as easy to work with.
94  {
95  public:
96  struct Params
97  {
98  template<class T> using Atom = fhicl::Atom<T>;
100  using Name = fhicl::Name;
101 
102  Atom<std::string> GeantModuleLabel{Name("GeantModuleLabel"), Comment("Module that produced the sim::Particle objects")};
103  Atom<std::string> PhotonModuleLabel{Name("PhotonModuleLabel"), Comment("Module that produced the sim::PhotonSignal objects")};
104  Atom<bool> DoHitsCheck{Name("DoHitsCheck"), Comment("Do hit by hit check in HitCollectionEfficiency?")};
105  Atom<double> MinContribFrac{Name("MinContribFrac"), Comment("Minimum fractional contribution a particle must make to a CellHit's energy to be counted"), 0.1};
106  Atom<int> MinPhysicsHits{Name("MinPhysicsHits"), Comment("Minimum number of hits in a cluster that are not noise for the function IsHitsNoise to return false"), 4};
107  Atom<double> MinPhysicsFrac{Name("MinPhysicsFrac"), Comment("If cluster fails to have MinPhysicsHits, can still have function IsHitsNoise return false if fraction of physics hits is at least MinPhysicsFrac"), 0.5};
108  Atom<bool> MRMode{Name("MRMode"), Comment("Are we running over a muon removed file?")};
109  Atom<bool> MCOverlayMode{Name("MCOverlayMode"), Comment("If MC is overlaid on real data, still backtrack")};
110  Atom<std::string> TrueEnergyModuleLabel{Name("TrueEnergyModuleLabel"), Comment("Module that produced the sim::TrueEnergy objects")};
111  };
112 
113  // Allows 'nova --print-description' to work
115 
116  BackTracker(const Parameters& params, art::ActivityRegistry& reg);
117  ~BackTracker();
118 
119  /// This function rebuilds the various maps we need to answer backtracking queries.
120  /// It is called automatically before each event is processed. For jobs involving
121  /// Monte Carlo generation, this is too soon. So, ReadoutSim also calls this function
122  /// when it knows all the relevant products have been produced. Requiring this kind
123  /// of cooperation from other modules for a service to function properly is not
124  /// recommended in general. In this case it seems like the least-bad option, but
125  /// think very carefully before adding any other examples. "Do as I say, not as I do".
126  void Rebuild(const art::Event& evt);
127 
128  /// \brief Is this a file with truth info in? (Is BackTracker going to be
129  /// any use to you?)
130  ///
131  /// True if we succeeded in retrieving FLSHits, ie in general for MC
132  /// files. Expected false in data, and mock data etc.
133  bool HaveTruthInfo() const {return fHaveTruthInfo;}
134 
135  /// \brief Returns the PhotonSignals contributing the signal in the
136  /// specified cell. WARNING: Use with extreme caution! Most users should use HitToPhotonSignal
137  /// instead. Only use the cell version if you really want to know ALL the photon signals
138  /// in the cell for the entire time window, NOT time-associated with the hit.
139  ///
140  /// Sorted from highest signal to lowest (which is probably not much use,
141  /// since energy from one particle can be split over several signals).
142  const std::vector<sim::PhotonSignal> CellToPhotonSignal(unsigned int const& plane,
143  unsigned int const& cell) const;
144 
145  /// \brief Returns the PhotonSignals contributing the signal in the
146  /// specified hit.
147  ///
148  /// Sorted from highest signal to lowest (which is probably not much use,
149  /// since energy from one particle can be split over several signals).
150  const std::vector<sim::PhotonSignal> HitToPhotonSignal(const art::Ptr<rb::CellHit>& hit) const;
151 
152  /// \brief Returns the FLSHits contributing the signal in the specified
153  /// cell. WARNING: Use with extreme caution! Most users should use HitToFLSHit
154  /// instead. Only use the cell version if you really want to know ALL the FLSHits
155  /// in the cell for the entire time window, NOT time-associated with the hit.
156  ///
157  /// The vector is sorted to return in order of highest contributing Geant4
158  /// track to lowest.
159  const std::vector<sim::FLSHit> CellToFLSHit(unsigned int const& plane,
160  unsigned int const& cell) const;
161 
162  /// \brief All the FLSHits that contributed to this hit, sorted from most
163  /// to least light
164  std::vector<sim::FLSHit> HitToFLSHit(const rb::CellHit& hit) const;
165 
166  std::vector<sim::FLSHit> HitToFLSHit(const art::Ptr<rb::CellHit>& hit) const
167  {
168  return HitToFLSHit(*hit);
169  }
170 
171  /// \brief All the FLSHits that were created by the track id trackID,
172  /// sorted from most to least light
173  std::vector<sim::FLSHit> ParticleToFLSHit(const int& trackID) const;
174 
175  /// \brief All the FLSHits that were created by the track id trackID,
176  /// which also have a particular pdg. Most users should use the other
177  /// version of this function. However, sometimes when our truth is
178  /// condensed, the same mother track ID is assigned to FLS hits made
179  /// by non-important daughters, who can have different PDG values. An
180  /// example of this is a muon track, whose delta rays often have the track
181  /// id of the mother muon. By using this version of the function, you can
182  /// ensure you are looking only at the FLS hits deposited by the muon.
183  std::vector<sim::FLSHit> ParticleToFLSHit(const int trackID, const int pdg) const;
184 
185  /// \brief The total energy deposited in this cell by all FLSHits with this
186  /// trackId
187  const double EnergyFromTrackId(const art::Ptr<rb::CellHit>& hit, int trackId, bool useBirksE = false) const;
188 
189  /// \brief Returns the sim::Particle object contributing the most light to
190  /// the specified rb::CellHit
191  const sim::Particle* HitToParticle(art::Ptr<rb::CellHit> const& hit,
192  bool quiet = false) const;
193 
194  /// \brief Returns the sim::Particle object contributing the most light to
195  /// the specified rb::CellHit
196  const sim::Particle* HitToParticle(const rb::CellHit& hit,
197  bool quiet = false) const;
198 
199  /// Is this hit not associated with any particles?
200  bool IsNoise(const art::Ptr<rb::CellHit>& hit) const;
201  /// Is this hit not associated with any particles?
202  bool IsNoise(const rb::CellHit& hit) const;
203 
204  /// Of this collection of hits, is it mostly noise or physics hits? True indicates noise.
205  bool IsHitsNoise(std::vector< art::Ptr<rb::CellHit> > const& hits) const;
206 
207  /// \brief Returns a pointer to the sim::Particle object corresponding to
208  /// the given TrackID
209  const sim::Particle* TrackIDToParticle(int const& id) const;
210  const sim::Particle* TrackIDToMotherParticle(int const& id) const;
211 
212  const art::Ptr<simb::MCTruth>& TrackIDToMCTruth(int const& id) const;
213  const art::Ptr<simb::MCTruth>& ParticleToMCTruth(const sim::Particle* p) const;
214  std::vector<const sim::Particle*> MCTruthToParticles(art::Ptr<simb::MCTruth> const& mct) const;
215 
216  /// \brief Returns the XYZ position of the energy deposition for a given
217  /// hit.
218  ///
219  /// Note the return value is in cell coordinates, not detector
220  TVector3 HitToXYZ(art::Ptr<rb::CellHit> const& hit, bool useBirksE = false) const;
221 
222  /// \brief Returns vector of sim::Particle objects contributing to the
223  /// given collection of hits.
224  ///
225  /// Orders the returned vector with the particle contributing the most
226  /// light in the collection first.
227  std::vector<const sim::Particle*> HitsToParticle(const std::vector<const rb::CellHit*>& hits) const;
228  std::vector<const sim::Particle*> HitsToParticle(const std::vector<rb::CellHit>& hits) const
229  {
230  return HitsToParticle(VecToVecRawPtr(hits));
231  }
232  std::vector<const sim::Particle*> HitsToParticle(const std::vector<art::Ptr<rb::CellHit>>& hits) const
233  {
234  return HitsToParticle(VecPtrToVecRawPtr(hits));
235  }
236  std::vector<const sim::Particle*> HitsToParticle(const art::PtrVector<rb::CellHit>& hits) const
237  {
238  return HitsToParticle(PtrVecToVecRawPtr(hits));
239  }
240 
241  /// \brief Returns vector of TrackIDE structs contributing to the given
242  /// collection of hits.
243  ///
244  /// Orders the returned vector with the trackID contributing the most
245  /// energy in the collection first.
246  std::vector<TrackIDE> HitsToTrackIDE(const std::vector<const rb::CellHit*>& hits, bool useBirksE = false) const;
247 
248  std::vector<TrackIDE> HitsToTrackIDE(const std::vector<rb::CellHit>& hits, bool useBirksE = false) const
249  {
250  return HitsToTrackIDE(VecToVecRawPtr(hits), useBirksE);
251  }
252 
253  std::vector<TrackIDE> HitsToTrackIDE(const std::vector<art::Ptr<rb::CellHit>>& hits, bool useBirksE = false) const
254  {
255  return HitsToTrackIDE(VecPtrToVecRawPtr(hits), useBirksE);
256  }
257 
258  std::vector<TrackIDE> HitsToTrackIDE(const art::PtrVector<rb::CellHit>& hits, bool useBirksE = false) const
259  {
260  return HitsToTrackIDE(PtrVecToVecRawPtr(hits), useBirksE);
261  }
262 
263  /// Convenience function. \ref HitsToTrackIDE but for a single hit.
264  std::vector<TrackIDE> HitToTrackIDE(const rb::CellHit& hit, bool useBirksE = false) const;
265 
266  std::vector<TrackIDE> HitToTrackIDE(const art::Ptr<rb::CellHit>& hit, bool useBirksE = false) const;
267 
268 
269  /// \brief Returns the fraction of hits in a collection that come from the
270  /// specified Geant4 track ids.
271  ///
272  double HitCollectionPurity(const std::set<int>& trackIDs,
273  const std::vector<rb::WeightedHit>& whits,
274  std::map<int, double>* purMap = 0,
275  std::map<int, int>* parents = 0,
276  bool energyPur = false) const;
277 
278  /// \brief Returns the fraction of hits in a collection that come from the
279  /// specified Geant4 track ids.
280  ///
281  /// The optional \a purMap parameter returns the purities for each of the
282  /// track IDs individually.
283  ///
284  /// The optional \a parents parameter maps particle IDs to the IDs they
285  ///
286  /// The optional \a energyPur parameter allows the purity to be calculated based on FLS energy instead of number of hits
287  double HitCollectionPurity(const std::set<int>& trackIDs,
288  const std::vector<const rb::CellHit*>& hits,
289  std::map<int, double>* purMap = 0,
290  std::map<int, int>* parents = 0,
291  bool energyPur = false) const;
292 
293  double HitCollectionPurity(const std::set<int>& trackIDs,
294  const std::vector<rb::CellHit>& hits,
295  std::map<int, double>* purMap = 0,
296  std::map<int, int>* parents = 0,
297  bool energyPur = false) const
298  {
299  return HitCollectionPurity(trackIDs, VecToVecRawPtr(hits), purMap, parents, energyPur);
300  }
301 
302  double HitCollectionPurity(const std::set<int>& trackIDs,
303  const std::vector<art::Ptr<rb::CellHit>>& hits,
304  std::map<int, double>* purMap = 0,
305  std::map<int, int>* parents = 0,
306  bool energyPur = false) const
307  {
308  return HitCollectionPurity(trackIDs, VecPtrToVecRawPtr(hits), purMap, parents, energyPur);
309  }
310 
311  double HitCollectionPurity(const std::set<int>& trackIDs,
312  const art::PtrVector<rb::CellHit>& hits,
313  std::map<int, double>* purMap = 0,
314  std::map<int, int>* parents = 0,
315  bool energyPur = false) const
316  {
317  return HitCollectionPurity(trackIDs, PtrVecToVecRawPtr(hits), purMap, parents, energyPur);
318  }
319 
320  /// \brief Returns the fraction of all energy in an event from a specific set
321  /// of Geant4 track IDs that are represented in a collection of weighted hits
322  ///
323  /// \a desiredHits and
324  /// \a totalHits are also optional parameters that are the number of hits from the given set of
325  /// trackIds in the given slice and the total number of hits from these trackId's in the detector respectively
326  double HitCollectionEfficiency(const std::set<int>& trackIDs,
327  const std::vector<rb::WeightedHit>& whits,
328  const std::vector<const rb::CellHit*>& allhits,
329  const geo::View_t& view,
330  std::map<int, double>* effMap = 0,
331  bool energyEff = false,
332  double* desiredEnergy = 0,
333  double* totalEnergy = 0,
334  int* desiredHits = 0,
335  int* totalHits = 0) const;
336 
337  double HitCollectionEfficiency(const std::set<int>& trackIDs,
338  const std::vector<rb::WeightedHit>& whits,
339  const std::vector<rb::CellHit>& allhits,
340  const geo::View_t& view,
341  std::map<int, double>* effMap = 0,
342  bool energyEff = false,
343  double* desiredEnergy = 0,
344  double* totalEnergy = 0,
345  int* desiredHits = 0,
346  int* totalHits = 0) const
347  {
348  return HitCollectionEfficiency(trackIDs, whits, VecToVecRawPtr(allhits), view, effMap, energyEff, desiredEnergy, totalEnergy, desiredHits, totalHits);
349  }
350 
351  double HitCollectionEfficiency(const std::set<int>& trackIDs,
352  const std::vector<rb::WeightedHit>& whits,
353  const std::vector<art::Ptr<rb::CellHit>>& allhits,
354  const geo::View_t& view,
355  std::map<int, double>* effMap = 0,
356  bool energyEff = false,
357  double* desiredEnergy = 0,
358  double* totalEnergy = 0,
359  int* desiredHits = 0,
360  int* totalHits = 0) const
361  {
362  return HitCollectionEfficiency(trackIDs, whits, VecPtrToVecRawPtr(allhits), view, effMap, energyEff, desiredEnergy, totalEnergy, desiredHits, totalHits);
363  }
364 
365  double HitCollectionEfficiency(const std::set<int>& trackIDs,
366  const std::vector<rb::WeightedHit>& whits,
367  const art::PtrVector<rb::CellHit>& allhits,
368  const geo::View_t& view,
369  std::map<int, double>* effMap = 0,
370  bool energyEff = false,
371  double* desiredEnergy = 0,
372  double* totalEnergy = 0,
373  int* desiredHits = 0,
374  int* totalHits = 0) const
375  {
376  return HitCollectionEfficiency(trackIDs, whits, PtrVecToVecRawPtr(allhits), view, effMap, energyEff, desiredEnergy, totalEnergy, desiredHits, totalHits);
377  }
378 
379 
380 
381  /// \brief Returns the fraction of all hits in an event from a specific set
382  /// of Geant4 track IDs that are represented in a collection of hits
383  ///
384  /// The optional \a effMap parameter returns the efficiencies for each of
385  /// the track IDs individually.
386  ///
387  /// The optional \a energyPur parameter allows the efficiency to be calculated based on FLS energy instead of number of hits
388  /// \a desiredHits and \a totalHits are also optional parameters that are the number of hits from the given set of trackIds
389  /// in the given slice and the total number of hits from these trackId's in the detector respectively
390  double HitCollectionEfficiency(const std::set<int>& trackIDs,
391  const std::vector<const rb::CellHit*>& hits,
392  const std::vector<const rb::CellHit*>& allhits,
393  const geo::View_t& view,
394  std::map<int, double>* effMap = 0,
395  bool energyEff = false,
396  double* desiredEnergy = 0,
397  double* totalEnergy = 0,
398  int* desiredHits = 0,
399  int* totalHits = 0) const;
400 
401  double HitCollectionEfficiency(const std::set<int>& trackIDs,
402  const std::vector<rb::CellHit>& hits,
403  const std::vector<rb::CellHit>& allhits,
404  const geo::View_t& view,
405  std::map<int, double>* effMap = 0,
406  bool energyEff = false,
407  double* desiredEnergy = 0,
408  double* totalEnergy = 0,
409  int* desiredHits = 0,
410  int* totalHits = 0) const
411  {
412  return HitCollectionEfficiency(trackIDs,
413  VecToVecRawPtr(hits),
414  VecToVecRawPtr(allhits),
415  view,
416  effMap, energyEff, desiredEnergy,
417  totalEnergy, desiredHits, totalHits);
418  }
419 
420  double HitCollectionEfficiency(const std::set<int>& trackIDs,
421  const std::vector<art::Ptr<rb::CellHit>>& hits,
422  const std::vector<art::Ptr<rb::CellHit>>& allhits,
423  const geo::View_t& view,
424  std::map<int, double>* effMap = 0,
425  bool energyEff = false,
426  double* desiredEnergy = 0,
427  double* totalEnergy = 0,
428  int* desiredHits = 0,
429  int* totalHits = 0) const
430  {
431  return HitCollectionEfficiency(trackIDs,
432  VecPtrToVecRawPtr(hits),
433  VecPtrToVecRawPtr(allhits),
434  view,
435  effMap, energyEff, desiredEnergy,
436  totalEnergy, desiredHits, totalHits);
437  }
438 
439  double HitCollectionEfficiency(std::set<int> trackIDs,
440  const art::PtrVector<rb::CellHit>& hits,
441  const art::PtrVector<rb::CellHit>& allhits,
442  const geo::View_t& view,
443  std::map<int, double>* effMap = 0,
444  bool energyEff = false,
445  double* desiredEnergy = 0,
446  double* totalEnergy = 0,
447  int* desiredHits = 0,
448  int* totalHits = 0) const
449  {
450  return HitCollectionEfficiency(trackIDs,
451  PtrVecToVecRawPtr(hits),
452  PtrVecToVecRawPtr(allhits),
453  view,
454  effMap, energyEff, desiredEnergy,
455  totalEnergy, desiredHits, totalHits);
456  }
457 
458  /// \brief Tool for NumuEAna that allows one to see if primary muon (or any track ID you feed the function)
459  /// contributes to enough hits in the slice to pass the hit cut. It is currently set at 4 hits in each view.
460  bool PassMuonCuts(int trackID, art::PtrVector<rb::CellHit> const& hits) const;
461 
462  /// \brief Tool for function SliceToNeutrinoInteractions, tells how to sort by putting structures with highest efficiency first.
463  static bool sort_eff(const NeutrinoEffPur& a, const NeutrinoEffPur& b);
464 
465  /// \brief Tool for function SliceToNeutrinoInteractions, tells how to sort by putting structures with highest purity first.
466  static bool sort_pur(const NeutrinoEffPur& a, const NeutrinoEffPur& b);
467 
468  /// \brief Tool for function SliceToNeutrinoIndex, tells how to sort by putting structures with highest efficiency first.
469  static bool sort_idxeff(const std::pair<int,NeutrinoEffPur>& a, const std::pair<int,NeutrinoEffPur>& b);
470 
471  /// \brief Tool for function SliceToNeutrinoIndex, tells how to sort by putting structures with highest purity first.
472  static bool sort_idxpur(const std::pair<int,NeutrinoEffPur>& a, const std::pair<int,NeutrinoEffPur>& b);
473 
474 
475  /// \brief Given a collection of hits (often a slice), returns vector of neutrino indices
476  /// corresponding to the vector from SliceToNeutrinoInteractions.
477  std::vector<int>
478  SliceToNeutrinoIndex(const std::vector<const rb::CellHit*>& sliceHits,
479  const std::vector<const rb::CellHit*>& allHits,
480  bool sortPur = false) const;
481 
482  /// \brief Given a collection of hits (often a slice), returns vector of structures of neutrino interactions,
483  /// efficiency, and purity of that neutrino interaction relative to the slice. Efficiency is defined as FLS energy
484  /// from neutrino interaction in slice / total FLS energy from neutrino interaction in event.
485  /// This vector is sorted from the highest efficiency interaction to lowest.
486  std::vector<NeutrinoEffPur>
487  SliceToNeutrinoInteractions(const std::vector<const rb::CellHit*>& sliceHits,
488  const std::vector<const rb::CellHit*>& allHits,
489  bool sortPur = false) const;
490 
491  std::vector<NeutrinoEffPur>
492  SliceToNeutrinoInteractions(const std::vector<rb::CellHit>& sliceHits,
493  const std::vector<rb::CellHit>& allHits,
494  bool sortPur = false) const
495  {
496  return SliceToNeutrinoInteractions(VecToVecRawPtr(sliceHits),
497  VecToVecRawPtr(allHits),
498  sortPur);
499  }
500 
501  std::vector<NeutrinoEffPur>
502  SliceToNeutrinoInteractions(const std::vector<art::Ptr<rb::CellHit>>& sliceHits,
503  const std::vector<art::Ptr<rb::CellHit>>& allHits,
504  bool sortPur = false) const
505  {
506  return SliceToNeutrinoInteractions(VecPtrToVecRawPtr(sliceHits),
507  VecPtrToVecRawPtr(allHits),
508  sortPur);
509  }
510 
511  std::vector<NeutrinoEffPur>
513  const art::PtrVector<rb::CellHit>& allHits,
514  bool sortPur = false) const
515  {
516  return SliceToNeutrinoInteractions(PtrVecToVecRawPtr(sliceHits),
517  PtrVecToVecRawPtr(allHits),
518  sortPur);
519  }
520 
521  std::vector<NeutrinoEffPur>
522  SliceToNeutrinoInteractions(const art::Ptr<rb::Cluster>& sliceCluster,
523  const std::vector<const rb::CellHit*>& allHits,
524  bool sortPur = false) const;
525 
526  std::vector<NeutrinoEffPur>
528  const std::vector<rb::CellHit>& allHits,
529  bool sortPur = false) const
530  {
531  return SliceToNeutrinoInteractions(sliceCluster,
532  VecToVecRawPtr(allHits),
533  sortPur);
534  }
535 
536  std::vector<NeutrinoEffPur>
538  const std::vector<art::Ptr<rb::CellHit>>& allHits,
539  bool sortPur = false) const
540  {
541  return SliceToNeutrinoInteractions(sliceCluster,
542  VecPtrToVecRawPtr(allHits),
543  sortPur);
544  }
545 
546  std::vector<NeutrinoEffPur>
548  const art::PtrVector<rb::CellHit>& allHits,
549  bool sortPur = false) const
550  {
551  return SliceToNeutrinoInteractions(sliceCluster,
552  PtrVecToVecRawPtr(allHits),
553  sortPur);
554  }
555 
556 
557  ///\brief Given a vector of indexed neutrino interaction and a vector of slice truth tables, returns a
558  /// vector of neutrino interaction indices ordered by best match to the corresponding slice. Here, best
559  /// match is determined according to the given cheat::NeutrinoEffPur functions for the slice and the nu.
560  std::vector <int> SliceToOrderedNuIds(const std::vector<cheat::NeutrinoWithIndex>& nusWithIdx,
561  const std::vector<std::vector<cheat::NeutrinoEffPur>>& slTruthTable,
562  std::function<double(const cheat::NeutrinoEffPur&)> slMetric,
563  std::function<double(const cheat::NeutrinoEffPur&)> nuMetric) const;
564 
565  std::vector <int> SliceToOrderedNuIdsByEff(const std::vector<cheat::NeutrinoWithIndex>& nusWithIdx,
566  const std::vector<std::vector<cheat::NeutrinoEffPur>>& slTruthTable) const;
567 
568  std::vector <int> SliceToOrderedNuIdsByPur(const std::vector<cheat::NeutrinoWithIndex>& nusWithIdx,
569  const std::vector<std::vector<cheat::NeutrinoEffPur>>& slTruthTable) const;
570 
571  std::vector <int> SliceToOrderedNuIdsByEffPur(const std::vector<cheat::NeutrinoWithIndex>& nusWithIdx,
572  const std::vector<std::vector<cheat::NeutrinoEffPur>>& slTruthTable) const;
573 
574  std::vector <int> SliceToOrderedNuIdsByEnergy(const std::vector<cheat::NeutrinoWithIndex>& nusWithIdx,
575  const std::vector<std::vector<cheat::NeutrinoEffPur>>& slTruthTable) const;
576 
577  /// \brief Given a collection of hits (often a slice), returns vector of structures of MCTruth,
578  /// efficiency, and purity of that neutrino interaction relative to the slice. Efficiency is defined as FLS energy
579  /// from neutrino interaction in slice / total FLS energy from neutrino interaction in event.
580  /// This vector is sorted from the highest efficiency interaction to lowest. This function returns all MCTruth,
581  /// including those without neutrino interactions, i.e. cosmics.
582  std::vector<NeutrinoEffPur>
583  SliceToMCTruth(const std::vector<const rb::CellHit*>& sliceHits,
584  const std::vector<const rb::CellHit*>& allHits,
585  bool sortPur = false) const;
586 
587  std::vector<NeutrinoEffPur>
588  SliceToMCTruth(const std::vector<rb::CellHit>& sliceHits,
589  const std::vector<rb::CellHit>& allHits,
590  bool sortPur = false) const
591  {
592  return SliceToMCTruth(VecToVecRawPtr(sliceHits),
593  VecToVecRawPtr(allHits),
594  sortPur);
595  }
596 
597  std::vector<NeutrinoEffPur>
598  SliceToMCTruth(const std::vector<art::Ptr<rb::CellHit>>& sliceHits,
599  const std::vector<art::Ptr<rb::CellHit>>& allHits,
600  bool sortPur = false) const
601  {
602  return SliceToMCTruth(VecPtrToVecRawPtr(sliceHits),
603  VecPtrToVecRawPtr(allHits),
604  sortPur);
605  }
606 
607  std::vector<NeutrinoEffPur>
609  const art::PtrVector<rb::CellHit>& allHits,
610  bool sortPur = false) const
611  {
612  return SliceToMCTruth(PtrVecToVecRawPtr(sliceHits),
613  PtrVecToVecRawPtr(allHits),
614  sortPur);
615  }
616 
617  std::vector<NeutrinoEffPur>
618  SliceToMCTruth(const art::Ptr<rb::Cluster>& sliceCluster,
619  const std::vector<const rb::CellHit*>& allHits,
620  bool sortPur = false) const;
621 
622  std::vector<NeutrinoEffPur>
624  const std::vector<rb::CellHit>& allHits,
625  bool sortPur = false) const
626  {
627  return SliceToMCTruth(sliceCluster, VecToVecRawPtr(allHits), sortPur);
628  }
629 
630  std::vector<NeutrinoEffPur>
632  const std::vector<art::Ptr<rb::CellHit>>& allHits,
633  bool sortPur = false) const
634  {
635  return SliceToMCTruth(sliceCluster, VecPtrToVecRawPtr(allHits), sortPur);
636  }
637 
638  std::vector<NeutrinoEffPur>
640  const art::PtrVector<rb::CellHit>& allHits,
641  bool sortPur = false) const
642  {
643  return SliceToMCTruth(sliceCluster, PtrVecToVecRawPtr(allHits), sortPur);
644  }
645 
646  /// \brief Given ALL the slices in an event, including the noise slice, returns a vector of vector of structures of MCTruth,
647  /// efficiency, and purity of that MCTruth interaction relative to the slice.
648  /// The returned vector is the same size as the total number of slices, including the noise slice, which is treated the same
649  /// as any other slice. It is sorted in the same order as the slice list.
650  /// For each entry, there is a vector of NeutrinoEffPurs. This vector is the same size as the MCTruth list. It is sorted in
651  /// the same order as the MCTruth list.
652  /// Every slice/MCTruth pair shows up, even if the contribution is zero.
653  /// Efficiency is defined as FLS energy from a MCTruth in a slice / total FLS energy from a MCTruth in event.
654  /// This function is agnostic to MCTruth and treates them all the same, including those without neutrino interactions, i.e. cosmics.
655  std::vector<std::vector<cheat::NeutrinoEffPur>>
656  SlicesToMCTruthsTable(const std::vector<const rb::Cluster*>& sliceList) const;
657 
658  std::vector<std::vector<cheat::NeutrinoEffPur>>
659  SlicesToMCTruthsTable(const std::vector<rb::Cluster>& sliceList) const
660  {
661  return SlicesToMCTruthsTable(VecToVecRawPtr(sliceList));
662  }
663 
664  std::vector<std::vector<cheat::NeutrinoEffPur>>
665  SlicesToMCTruthsTable(const std::vector<art::Ptr<rb::Cluster>>& sliceList) const
666  {
667  return SlicesToMCTruthsTable(VecPtrToVecRawPtr(sliceList));
668  }
669 
670  std::vector<std::vector<cheat::NeutrinoEffPur>>
672  {
673  return SlicesToMCTruthsTable(PtrVecToVecRawPtr(sliceList));
674  }
675 
676  /// \brief Given a collection of reconstructed tracks, this method finds the best match for each reco track to the
677  /// input track id particles.
678  ///
679  /// For each reconstructed track, the true particle that best matches the track by
680  /// purity from the input trkIDs is determined. Each input track ID is only allowed to match at most one input
681  /// track and any track IDs specified in the input allowedDaughters are not counted against a tracks purity.
682  /// The tracks are matched to particles in the order that they appear in the input vector. Each entry in the
683  /// returned vector of ParticleEffPur corresponds to the track in the same position as the input track vector and
684  /// holds the matched track id, efficiency, purity, and pdg of the best matched particle for the given track. If
685  /// no track id is found to match the track, then the purity, efficiency, and pdg will be zero. You need to check
686  /// that a match exists before trying to use the matched track id in other functions
687  std::vector<ParticleEffPur>
688  TracksToParticles(const std::vector<const rb::Track*>& tracks,
689  const std::set<int>& trkIDs,
690  const std::set<int>& allowedDaughters,
691  const std::vector<const rb::CellHit*>& allHits) const;
692 
693  std::vector<ParticleEffPur>
694  TracksToParticles(const std::vector<rb::Track>& tracks,
695  const std::set<int>& trkIDs,
696  const std::set<int>& allowedDaughters,
697  const std::vector<rb::CellHit>& allHits) const
698  {
699  return TracksToParticles(VecToVecRawPtr(tracks),
700  trkIDs, allowedDaughters,
701  VecToVecRawPtr(allHits));
702  }
703 
704  std::vector<ParticleEffPur>
705  TracksToParticles(const std::vector<art::Ptr<rb::Track>>& tracks,
706  const std::set<int>& trkIDs,
707  const std::set<int>& allowedDaughters,
708  const std::vector<art::Ptr<rb::CellHit>>& allHits) const
709  {
710  return TracksToParticles(VecPtrToVecRawPtr(tracks),
711  trkIDs, allowedDaughters,
712  VecPtrToVecRawPtr(allHits));
713  }
714 
715  std::vector<ParticleEffPur>
717  const std::set<int>& trkIDs,
718  const std::set<int>& allowedDaughters,
719  const art::PtrVector<rb::CellHit>& allHits) const
720  {
721  return TracksToParticles(PtrVecToVecRawPtr(tracks),
722  trkIDs, allowedDaughters,
723  PtrVecToVecRawPtr(allHits));
724  }
725 
726  std::vector<ParticleEffPur>
727  TracksToParticles(const std::vector<art::Ptr<rb::Track>>& tracks,
728  const std::set<int>& trkIDs,
729  const std::set<int>& allowedDaughters,
730  const art::PtrVector<rb::CellHit>& allHits) const
731  {
732  return TracksToParticles(VecPtrToVecRawPtr(tracks),
733  trkIDs, allowedDaughters,
734  PtrVecToVecRawPtr(allHits));
735  }
736 
737 
738  /// \brief Function primarily for CAFMaker - returns a vector of all MCTruth interactions along with their truth vector position
739  std::vector <NeutrinoWithIndex> allNeutrinoInteractions() const;
740 
741  std::vector <NeutrinoWithIndex> allMCTruth() const;
742 
743  /// \brief Get a reference to the ParticleNavigator
744  const sim::ParticleNavigator& ParticleNavigator() const { return fParticleNav; }
745 
746  /// \brief Get all G4 track ids present in the event.
747  ///
748  /// These do not include ids from EM shower secondaries, tertiaries, etc as
749  /// they are not saved as particles.
750  const std::set<int> GetTrackIDList() const { return fTrackIDs; }
751 
752  /// \brief:
753  // Return a vector of clusters where the hits are separated by MCTruth. A hit that
754  // had contributions from more than one MCTruth is clustered with the MCTruth that
755  // contributed the most energy. Noise hits are put into the last cluster.
756  //
757  // NOTE: It is not always the case that all MCTruths contribute hits to the event record,
758  // so some of the clusters returned might be empty!
759  std::vector<rb::Cluster> ClusterByTruth(std::vector< art::Ptr< rb::CellHit > > const &hits);
760 
761  /// \brief:
762  // Given a list of hits (usually all hits) this returns a cluster of only the PRIMARY hits
763  // associated with a specific MCTruth.
764  //
765  // NOTE: A hit will only be added to this cluster if its primary energy contribution came from this MCTruth.
766  rb::Cluster MCTruthToCluster(art::Ptr<simb::MCTruth> const& truth,
767  std::vector< art::Ptr< rb::CellHit > > const& hits);
768 
769  void HitToParticlesMap(const std::vector<const rb::Cluster*>& sliceList,
770  const int& sliceIdx);
771 
772  void HitToParticlesMap(const std::vector<rb::Cluster>& sliceList,
773  const int& sliceIdx)
774  {
775  return HitToParticlesMap(VecToVecRawPtr(sliceList), sliceIdx);
776  }
777 
778  void HitToParticlesMap(const std::vector<art::Ptr<rb::Cluster>>& sliceList,
779  const int& sliceIdx)
780  {
781  return HitToParticlesMap(VecPtrToVecRawPtr(sliceList), sliceIdx);
782  }
783 
785  const int& sliceIdx)
786  {
787  return HitToParticlesMap(PtrVecToVecRawPtr(sliceList), sliceIdx);
788  }
789 
790  cheat::ParticleEffPur ClusterToParticle(const std::vector<const rb::Cluster*>& sliceList,
791  const std::vector<const rb::CellHit*>& hits,
792  const int& sliceIdx);
793 
794  cheat::ParticleEffPur ClusterToParticle(const std::vector<rb::Cluster>& sliceList,
795  const std::vector<rb::CellHit>& hits,
796  const int& sliceIdx)
797  {
798  return ClusterToParticle(VecToVecRawPtr(sliceList),
799  VecToVecRawPtr(hits),
800  sliceIdx);
801  }
802 
804  const std::vector<art::Ptr<rb::CellHit>>& hits,
805  const int& sliceIdx)
806  {
807  return ClusterToParticle(VecPtrToVecRawPtr(sliceList),
808  VecPtrToVecRawPtr(hits),
809  sliceIdx);
810  }
811 
813  const art::PtrVector< rb::CellHit >& hits,
814  const int& sliceIdx)
815  {
816  return ClusterToParticle(PtrVecToVecRawPtr(sliceList),
817  PtrVecToVecRawPtr(hits),
818  sliceIdx);
819  }
820 
821  /// \brief
822  /// A function to calculate the amount of energy from a given MCParticle which is not contained in the detector.
823  /// Will return the energy the particle had when it exited the detector.
824  /// Should a particle stop in the detector then the "Escaping energy" is 0.
825  /// It has the option of returning the energy that a particle deposited energy in the detector.
826  /// This is calclated from EnEnt - EnEsc, this has the deficiency that depositions from daughters may be doubly counted,
827  /// however this is what the function CalcDaughterEscapingEnergy is for.
828  /// There is a flag "UseMCPart", this controls whether to use the saved MCParticles, or to use the more accurate GEANT4
829  /// information, which takes into account all daughter particles.
830  /// Currently it is defaulted to true, ie use the MCParticles, as the GEANT4 info is not usually in the event record yet.
831  float CalcEscapingEnergy( const sim::Particle &Par, bool UseMCPart = true, std::string G4Label = "trueens" );
832  float CalcEscapingEnergy( const sim::Particle &Par, float& EnDep, bool UseMCPart = true, std::string G4Label = "trueens" );
833 
834  /// \brief
835  /// A function to be used in conjunction with CalcTotalEscapingEnergy to calculate the energy which the daughters of a
836  /// a given sim::Particle deposited in the detector.
837  float CalcDaughterEscapingEnergy( const sim::Particle &Par );
838 
839  /// \brief
840  /// An extension of CalcEscapingEnergy which also takes into account the energy which the daughters of given sim::Particle's
841  /// deposit in the detector.
842  /// To do this it calls CalcDaughterEscapingEnergy, which in turn calls CalcEscapingEnergy for all of the daughters.
843  float CalcTotalEscapingEnergy( const sim::Particle &Par, bool UseMCPart = true, std::string G4Label = "trueens" );
844  float CalcTotalEscapingEnergy( const sim::Particle &Par, float& ParEnDep, bool UseMCPart = true, std::string G4Label = "trueens" );
845 
846  /// \brief
847  /// A function which returns the trajectory point at which the particle first enters and leave the detector volume.
848  /// The trajectory point is returned so that the user can determine the energies etc which the particle had at this
849  /// point.
850  /// Should the particle have been generated in the detector then TrajEnt == 0 will be returned.
851  /// Should the particle stop in the detector then TrajEx == NumberTrajectoryPoints()-1 will be returned.
852  /// Should the particle never enter the detector then holder values TrajEnter == TrajEx == -5 will be returned.
853  bool InterceptsDetector( const sim::Particle &Par, int &TrajEnt, int &TrajEx );
854 
855  private:
856  /// \brief Helper function for implementing overloads
857  ///
858  /// NB the pointers are only valid so long as the parent \a xs is still
859  /// around
860  template<class T> std::vector<const T*>
862  {
863  std::vector<const T*> ret;
864  ret.reserve(xs.size());
865  for(const art::Ptr<T>& x: xs) ret.push_back(x.get());
866  return ret;
867  }
868 
869  /// Helper function for implementing overloads
870  ///
871  /// NB the pointers are only valid so long as the parent \a xs is still
872  /// around
873  template<class T> std::vector<const T*>
874  VecPtrToVecRawPtr(const std::vector<art::Ptr<T>>& xs) const
875  {
876  std::vector<const T*> ret;
877  ret.reserve(xs.size());
878  for(const art::Ptr<T>& x: xs) ret.push_back(x.get());
879  return ret;
880  }
881 
882  /// Helper function for implementing overloads
883  ///
884  /// NB the pointers are only valid so long as the parent \a xs is still
885  /// around
886  template<class T> std::vector<const T*>
887  VecToVecRawPtr(const std::vector<T>& xs) const
888  {
889  std::vector<const T*> ret;
890  ret.reserve(xs.size());
891  for(const T& x: xs) ret.push_back(&x);
892  return ret;
893  }
894 
895  /// Helper for HitCollectionEfficiency and HitCollectionPurity
897  {
898  public:
899  RawWeightedHit(const rb::WeightedHit& h) : hit(h.hit.get()), weight(h.weight) {}
900  RawWeightedHit(const rb::CellHit* h, double w) : hit(h), weight(w) {}
901  const rb::CellHit* hit;
902  double weight;
903  };
904 
905  /// Internal implementation of public \ref HitCollectionPurity
906  double HitCollectionPurity(const std::set<int>& trackIDs,
907  const std::vector<RawWeightedHit>& whits,
908  std::map<int, double>* purMap = 0,
909  std::map<int, int>* parents = 0,
910  bool energyPur = false) const;
911 
912  /// Internal implementation of public \ref HitCollectionEfficiency
913  double HitCollectionEfficiency(const std::set<int>& trackIDs,
914  const std::vector<RawWeightedHit>& whits,
915  const std::vector<const rb::CellHit*>& allhits,
916  const geo::View_t& view,
917  std::map<int, double>* effMap = 0,
918  bool energyEff = false,
919  double* desiredEnergy = 0,
920  double* totalEnergy = 0,
921  int* desiredHits = 0,
922  int* totalHits = 0) const;
923 
924  /// \brief Internal helper, decides if a PhotonSignal and CellHit are close
925  /// enough to match.
926  bool CloseInTime(const rb::CellHit& chit, const sim::PhotonSignal& phot) const;
927 
928  /// \brief Internal helper, adds the contributions from each particle in
929  /// this cell to the map
930  void AccumulateHitContributions(rb::CellHit const& hit,
931  std::map<int, int> & idToNPhot) const;
932 
934 
935  bool fHaveTruthInfo; ///< Set by \ref Rebuild
936 
937  novadaq::cnv::DetId fDetID; ///< detector id
938 
939  std::unordered_map< geo::OfflineChan, std::list<sim::FLSHit> > fCellToFLSHit; ///< map of FLSHits in each cell in event
940  std::unordered_map< int, std::list<sim::FLSHit> > fTrackIDToFLSHit; ///< map of G4 track ids to FLSHits
941  std::unordered_map< geo::OfflineChan, std::vector<sim::PhotonSignal> > fCellToPhotonSignal; ///< map of PhotonSignals in each cell in event
942  sim::ParticleNavigator fParticleNav; ///< Particle navigator to map track ID to Particle
943  std::set<int> fTrackIDs; ///< G4 track ids for all particles in the events
944  std::vector< art::Ptr<simb::MCTruth> > fMCTruthList; ///< all the MCTruths for this event
945  std::map<int, int> fTrackIDToMCTruthIndex; ///< map of track id values to MCTruthList entry
946  std::vector< art::Ptr<sim::TrueEnergy> > fTrueEnergyList; ///< all the TrueEnergy's for this event
947  std::map<int, int> fTrackIDToTrueEIndex; ///< map of track id values to TrueEnergy entry
948 
949  /// map of cellHit to trackIDEs that contributed energy to the hit.
950  /// cellhit information is encoded as TDC*1000,000+Plane*1000+Cell
951  std::map<double, std::vector<cheat::TrackIDE> > fCellToIDs;
952  std::map<int, float > fIdToEnergy;
953 
956  };
957 } // namespace
958 
960 #endif // CHEAT_BACKTRACKER_H
void HitToParticlesMap(const art::PtrVector< rb::Cluster > &sliceList, const int &sliceIdx)
Definition: BackTracker.h:784
std::vector< const T * > VecPtrToVecRawPtr(const std::vector< art::Ptr< T >> &xs) const
Definition: BackTracker.h:874
std::vector< const T * > PtrVecToVecRawPtr(const art::PtrVector< T > &xs) const
Helper function for implementing overloads.
Definition: BackTracker.h:861
std::unordered_map< geo::OfflineChan, std::vector< sim::PhotonSignal > > fCellToPhotonSignal
map of PhotonSignals in each cell in event
Definition: BackTracker.h:941
std::vector< NeutrinoEffPur > SliceToMCTruth(const std::vector< rb::CellHit > &sliceHits, const std::vector< rb::CellHit > &allHits, bool sortPur=false) const
Definition: BackTracker.h:588
std::vector< TrackIDE > HitsToTrackIDE(const std::vector< rb::CellHit > &hits, bool useBirksE=false) const
Definition: BackTracker.h:248
std::vector< const sim::Particle * > HitsToParticle(const std::vector< rb::CellHit > &hits) const
Definition: BackTracker.h:228
std::set< int > fTrackIDs
G4 track ids for all particles in the events.
Definition: BackTracker.h:943
const sim::ParticleNavigator & ParticleNavigator() const
Get a reference to the ParticleNavigator.
Definition: BackTracker.h:744
const Var weight
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
float energyFrac
fraction of hit energy from the particle with this trackID
Definition: BackTracker.h:41
cheat::ParticleEffPur ClusterToParticle(const std::vector< art::Ptr< rb::Cluster >> &sliceList, const std::vector< art::Ptr< rb::CellHit >> &hits, const int &sliceIdx)
Definition: BackTracker.h:803
const char * p
Definition: xmltok.h:285
std::map< double, std::vector< cheat::TrackIDE > > fCellToIDs
Definition: BackTracker.h:951
int trackID
Truth particle track ID.
Definition: BackTracker.h:66
unsigned int truthColIndex
Position in column vector of MCTruths from the event.
Definition: BackTracker.h:50
float energy
energy from the particle with this trackID
Definition: BackTracker.h:42
A collection of associated CellHits.
Definition: Cluster.h:47
std::vector< ParticleEffPur > TracksToParticles(const std::vector< art::Ptr< rb::Track >> &tracks, const std::set< int > &trkIDs, const std::set< int > &allowedDaughters, const art::PtrVector< rb::CellHit > &allHits) const
Definition: BackTracker.h:727
std::vector< std::vector< cheat::NeutrinoEffPur > > SlicesToMCTruthsTable(const std::vector< rb::Cluster > &sliceList) const
Definition: BackTracker.h:659
int nTotalHits
Total number of hits the neutrino left in the detector.
Definition: BackTracker.h:54
double energyTotal
Sum of FLS hits from the neutrino contributing to any hit in the event.
Definition: BackTracker.h:52
std::vector< ParticleEffPur > TracksToParticles(const std::vector< art::Ptr< rb::Track >> &tracks, const std::set< int > &trkIDs, const std::set< int > &allowedDaughters, const std::vector< art::Ptr< rb::CellHit >> &allHits) const
Definition: BackTracker.h:705
#define DECLARE_ART_SERVICE(svc, scope)
Definition: ServiceMacros.h:91
double purity
Putity of particle relative to track.
Definition: BackTracker.h:68
std::vector< NeutrinoEffPur > SliceToNeutrinoInteractions(const art::PtrVector< rb::CellHit > &sliceHits, const art::PtrVector< rb::CellHit > &allHits, bool sortPur=false) const
Definition: BackTracker.h:512
double HitCollectionEfficiency(std::set< int > trackIDs, const art::PtrVector< rb::CellHit > &hits, const art::PtrVector< rb::CellHit > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
Definition: BackTracker.h:439
std::vector< NeutrinoEffPur > SliceToNeutrinoInteractions(const art::Ptr< rb::Cluster > &sliceCluster, const std::vector< rb::CellHit > &allHits, bool sortPur=false) const
Definition: BackTracker.h:527
double HitCollectionEfficiency(const std::set< int > &trackIDs, const std::vector< rb::CellHit > &hits, const std::vector< rb::CellHit > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
Definition: BackTracker.h:401
std::vector< std::vector< cheat::NeutrinoEffPur > > SlicesToMCTruthsTable(const art::PtrVector< rb::Cluster > &sliceList) const
Definition: BackTracker.h:671
double efficiency
Efficiency (based on FLS energy) of neutrino interaction relative to slice.
Definition: BackTracker.h:48
std::unordered_map< geo::OfflineChan, std::list< sim::FLSHit > > fCellToFLSHit
map of FLSHits in each cell in event
Definition: BackTracker.h:939
Helper for HitCollectionEfficiency and HitCollectionPurity.
Definition: BackTracker.h:896
std::vector< art::Ptr< simb::MCTruth > > fMCTruthList
all the MCTruths for this event
Definition: BackTracker.h:944
std::vector< NeutrinoEffPur > SliceToMCTruth(const art::Ptr< rb::Cluster > &sliceCluster, const art::PtrVector< rb::CellHit > &allHits, bool sortPur=false) const
Definition: BackTracker.h:639
cheat::ParticleEffPur ClusterToParticle(const std::vector< rb::Cluster > &sliceList, const std::vector< rb::CellHit > &hits, const int &sliceIdx)
Definition: BackTracker.h:794
void HitToParticlesMap(const std::vector< art::Ptr< rb::Cluster >> &sliceList, const int &sliceIdx)
Definition: BackTracker.h:778
std::unordered_map< int, std::list< sim::FLSHit > > fTrackIDToFLSHit
map of G4 track ids to FLSHits
Definition: BackTracker.h:940
std::map< int, float > fIdToEnergy
Definition: BackTracker.h:952
void hits()
Definition: readHits.C:15
int trackID
Geant4 supplied trackID.
Definition: BackTracker.h:40
std::vector< NeutrinoEffPur > SliceToMCTruth(const art::Ptr< rb::Cluster > &sliceCluster, const std::vector< rb::CellHit > &allHits, bool sortPur=false) const
Definition: BackTracker.h:623
std::vector< sim::FLSHit > HitToFLSHit(const art::Ptr< rb::CellHit > &hit) const
Definition: BackTracker.h:166
std::vector< NeutrinoEffPur > SliceToNeutrinoInteractions(const std::vector< rb::CellHit > &sliceHits, const std::vector< rb::CellHit > &allHits, bool sortPur=false) const
Definition: BackTracker.h:492
std::vector< art::Ptr< sim::TrueEnergy > > fTrueEnergyList
all the TrueEnergy&#39;s for this event
Definition: BackTracker.h:946
sim::ParticleNavigator fParticleNav
Particle navigator to map track ID to Particle.
Definition: BackTracker.h:942
const double a
std::vector< NeutrinoEffPur > SliceToNeutrinoInteractions(const art::Ptr< rb::Cluster > &sliceCluster, const art::PtrVector< rb::CellHit > &allHits, bool sortPur=false) const
Definition: BackTracker.h:547
int evt
double efficiency
Efficiency of particle relative to track.
Definition: BackTracker.h:67
cheat::ParticleEffPur ClusterToParticle(const art::PtrVector< rb::Cluster > &sliceList, const art::PtrVector< rb::CellHit > &hits, const int &sliceIdx)
Definition: BackTracker.h:812
bool CompareByEnergy(const TrackIDE &a, const TrackIDE &b)
Does a have less energy than b?
double EnergyMetric(const cheat::NeutrinoEffPur &ep)
Function for NeutrinoEffPur&#39;s nu interaction to slice energy.
std::map< int, int > fTrackIDToTrueEIndex
map of track id values to TrueEnergy entry
Definition: BackTracker.h:947
double HitCollectionEfficiency(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, const std::vector< art::Ptr< rb::CellHit >> &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
Definition: BackTracker.h:351
int pdg
Pdg of particle.
Definition: BackTracker.h:69
std::vector< NeutrinoEffPur > SliceToMCTruth(const art::Ptr< rb::Cluster > &sliceCluster, const std::vector< art::Ptr< rb::CellHit >> &allHits, bool sortPur=false) const
Definition: BackTracker.h:631
size_type size() const
Definition: PtrVector.h:308
double HitCollectionPurity(const std::set< int > &trackIDs, const std::vector< rb::CellHit > &hits, std::map< int, double > *purMap=0, std::map< int, int > *parents=0, bool energyPur=false) const
Definition: BackTracker.h:293
std::vector< ParticleEffPur > TracksToParticles(const art::PtrVector< rb::Track > &tracks, const std::set< int > &trkIDs, const std::set< int > &allowedDaughters, const art::PtrVector< rb::CellHit > &allHits) const
Definition: BackTracker.h:716
std::vector< std::vector< cheat::NeutrinoEffPur > > SlicesToMCTruthsTable(const std::vector< art::Ptr< rb::Cluster >> &sliceList) const
Definition: BackTracker.h:665
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
double EffPurMetric(const cheat::NeutrinoEffPur &ep)
Function for NeutrinoEffPur&#39;s nu interaction to slice efficiency * purity.
A rawdata::RawDigit with channel information decoded.
Definition: CellHit.h:27
std::vector< const sim::Particle * > HitsToParticle(const std::vector< art::Ptr< rb::CellHit >> &hits) const
Definition: BackTracker.h:232
int nSliceHits
Number of hits from this neutrino in this slice.
Definition: BackTracker.h:53
double HitCollectionEfficiency(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, const std::vector< rb::CellHit > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
Definition: BackTracker.h:337
code to link reconstructed objects back to the MC truth information
Definition: FillTruth.h:16
double HitCollectionEfficiency(const std::set< int > &trackIDs, const std::vector< art::Ptr< rb::CellHit >> &hits, const std::vector< art::Ptr< rb::CellHit >> &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
Definition: BackTracker.h:420
bool fHaveTruthInfo
Set by Rebuild.
Definition: BackTracker.h:935
std::vector< NeutrinoEffPur > SliceToNeutrinoInteractions(const std::vector< art::Ptr< rb::CellHit >> &sliceHits, const std::vector< art::Ptr< rb::CellHit >> &allHits, bool sortPur=false) const
Definition: BackTracker.h:502
std::vector< NeutrinoEffPur > SliceToMCTruth(const art::PtrVector< rb::CellHit > &sliceHits, const art::PtrVector< rb::CellHit > &allHits, bool sortPur=false) const
Definition: BackTracker.h:608
RawWeightedHit(const rb::WeightedHit &h)
Definition: BackTracker.h:899
std::map< int, int > fTrackIDToMCTruthIndex
map of track id values to MCTruthList entry
Definition: BackTracker.h:945
Definition: structs.h:12
double energySlice
Sum of FLS hits from the neutrino contributing to hits included in the slice.
Definition: BackTracker.h:51
bool HaveTruthInfo() const
Is this a file with truth info in? (Is BackTracker going to be any use to you?)
Definition: BackTracker.h:133
const hit & b
Definition: hits.cxx:21
RawWeightedHit(const rb::CellHit *h, double w)
Definition: BackTracker.h:900
const std::set< int > GetTrackIDList() const
Get all G4 track ids present in the event.
Definition: BackTracker.h:750
Simple hit+weight pair, returned from rb::Cluster::WeightedHits.
Definition: WeightedHit.h:18
std::vector< TrackIDE > HitsToTrackIDE(const std::vector< art::Ptr< rb::CellHit >> &hits, bool useBirksE=false) const
Definition: BackTracker.h:253
void HitToParticlesMap(const std::vector< rb::Cluster > &sliceList, const int &sliceIdx)
Definition: BackTracker.h:772
double PurMetric(const cheat::NeutrinoEffPur &ep)
Function for NeutrinoEffPur&#39;s nu interaction to slice purity.
double EffMetric(const cheat::NeutrinoEffPur &ep)
Function for NeutrinoEffPur&#39;s nu interaction to slice efficiency.
double HitCollectionPurity(const std::set< int > &trackIDs, const art::PtrVector< rb::CellHit > &hits, std::map< int, double > *purMap=0, std::map< int, int > *parents=0, bool energyPur=false) const
Definition: BackTracker.h:311
double T
Definition: Xdiff_gwt.C:5
std::vector< const T * > VecToVecRawPtr(const std::vector< T > &xs) const
Definition: BackTracker.h:887
static Var totalEnergy(const std::shared_ptr< CAFAnaModel > &model)
Definition: LSTMEVar.h:77
art::Ptr< simb::MCTruth > neutrinoInt
Truth information about neutrino interaction.
Definition: BackTracker.h:60
double HitCollectionEfficiency(const std::set< int > &trackIDs, const std::vector< rb::WeightedHit > &whits, const art::PtrVector< rb::CellHit > &allhits, const geo::View_t &view, std::map< int, double > *effMap=0, bool energyEff=false, double *desiredEnergy=0, double *totalEnergy=0, int *desiredHits=0, int *totalHits=0) const
Definition: BackTracker.h:365
std::vector< NeutrinoEffPur > SliceToMCTruth(const std::vector< art::Ptr< rb::CellHit >> &sliceHits, const std::vector< art::Ptr< rb::CellHit >> &allHits, bool sortPur=false) const
Definition: BackTracker.h:598
Float_t w
Definition: plot.C:20
Simple object representing a (plane, cell) pair.
novadaq::cnv::DetId fDetID
detector id
Definition: BackTracker.h:937
double HitCollectionPurity(const std::set< int > &trackIDs, const std::vector< art::Ptr< rb::CellHit >> &hits, std::map< int, double > *purMap=0, std::map< int, int > *parents=0, bool energyPur=false) const
Definition: BackTracker.h:302
std::vector< TrackIDE > HitsToTrackIDE(const art::PtrVector< rb::CellHit > &hits, bool useBirksE=false) const
Definition: BackTracker.h:258
std::vector< NeutrinoEffPur > SliceToNeutrinoInteractions(const art::Ptr< rb::Cluster > &sliceCluster, const std::vector< art::Ptr< rb::CellHit >> &allHits, bool sortPur=false) const
Definition: BackTracker.h:537
art::Ptr< simb::MCTruth > neutrinoInt
Truth information about neutrino interaction.
Definition: BackTracker.h:47
std::vector< const sim::Particle * > HitsToParticle(const art::PtrVector< rb::CellHit > &hits) const
Definition: BackTracker.h:236
double purity
Purity (based on FLS energy) of neutrino interaction relative to slice.
Definition: BackTracker.h:49
unsigned int truthColIndex
Position in column vector of MCTruths from the event.
Definition: BackTracker.h:61
std::vector< ParticleEffPur > TracksToParticles(const std::vector< rb::Track > &tracks, const std::set< int > &trkIDs, const std::set< int > &allowedDaughters, const std::vector< rb::CellHit > &allHits) const
Definition: BackTracker.h:694