LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
BackTracker.h
Go to the documentation of this file.
1 //
3 // \file BackTracker.h
4 // \brief Functions needed by the BackTracker service in order to connect truth information with reconstruction.
5 //
6 // \author jason.stock@mines.sdsmt.edu
7 //
8 // Based on the original BackTracker by brebel@fnal.gov
9 //
11 #ifndef CHEAT_BACKTRACKER_H
12 #define CHEAT_BACKTRACKER_H
13 
14 #include <vector>
15 
16 #include "fhiclcpp/types/Atom.h"
17 
23 
24 namespace fhicl {
25  class ParameterSet;
26 }
27 namespace detinfo {
28  class DetectorClocksData;
29 }
30 namespace geo {
31  class GeometryCore;
32 }
33 namespace recob {
34  class SpacePoint;
35 }
36 
37 namespace cheat {
38 
39  class BackTracker {
40  public:
41  // Structure for configuration parameters. (fhicl validation)
42  struct fhiclConfig {
44  fhicl::Name("G4ModuleLabel"),
45  fhicl::Comment("The label of the LArG4 module used to produce the "
46  "art file we will be using."),
47  "largeant"};
48  fhicl::Atom<art::InputTag> SimChannelModuleLabel{
49  fhicl::Name("SimChannelModuleLabel"),
50  fhicl::Comment("The label of the module containing the sim::SimChannel product."),
51  G4ModuleLabel()}; // -- D.R. label not required, if not provided
52  // defaults to the value of G4ModuleLabel
53  fhicl::Atom<art::InputTag> DefaultHitModuleLabel{
54  fhicl::Name("DefaultHitModuleLabel"),
55  fhicl::Comment("The label of the module used to produce the hits in the art file "
56  "we will default to when no hitlist is provided."),
57  "hitfd"};
58  fhicl::Atom<double> MinHitEnergyFraction{
59  fhicl::Name("MinHitEnergyFraction"),
60  fhicl::Comment("The minimum contribution an energy deposit must "
61  "make to a Hit to be considered part of that hit."),
62  0.010};
63  fhicl::Atom<bool> OverrideRealData{
64  fhicl::Name("OverrideRealData"),
65  fhicl::Comment("Option when overlaying simulation on real data, to tell the "
66  "backtracker to continue even if event looks like data."),
67  false};
68  fhicl::Atom<double> HitTimeRMS{fhicl::Name("HitTimeRMS"),
69  fhicl::Comment("The number of RMS units to move away"
70  "from a Hit peak time for searching IDE."),
71  1.0};
72  };
73 
74  BackTracker(const fhiclConfig& config,
75  const cheat::ParticleInventory* partInv,
76  const geo::GeometryCore* geom);
77  BackTracker(const fhicl::ParameterSet& pSet,
78  const cheat::ParticleInventory* partInv,
79  const geo::GeometryCore* geom);
80 
81  // I may need to include this to delete copy of service providers.
82  BackTracker(BackTracker const&) = delete;
83 
84  template <typename Evt>
85  void PrepEvent(const Evt& evt);
86 
87  template <typename Evt>
88  void PrepSimChannels(const Evt& evt);
89 
90  //-----------------------------------------------------
91  template <typename Evt>
92  bool CanRun(const Evt& evt)
93  {
94  return !evt.isRealData() || fOverrideRealData;
95  }
96 
97  //-----------------------------------------------------
98  template <typename Evt>
99  std::vector<art::Ptr<recob::Hit>> SpacePointToHits_Ps(art::Ptr<recob::SpacePoint> const& spt,
100  const Evt& evt) const;
101 
102  //-----------------------------------------------------
103  template <typename Evt>
104  std::vector<double> SpacePointToXYZ(detinfo::DetectorClocksData const& clockData,
105  art::Ptr<recob::SpacePoint> const& spt,
106  const Evt& evt) const;
107 
108  //-----------------------------------------------------
109  void ClearEvent();
110 
111  bool SimChannelsReady() const { return !fSimChannels.empty(); }
112 
113  const std::vector<art::Ptr<sim::SimChannel>>& SimChannels() const { return fSimChannels; }
114  // All Hit List would go here. We explicitly choose not to include it, as
115  // the user should not be using backtracker to access Hits. This could
116  // change in a concievable future use case where we also allow the user to
117  // define what the "AllHitList" should be, though this would have
118  // ramifications on other functions.
119 
120  std::vector<const sim::IDE*> TrackIdToSimIDEs_Ps(int const& id) const;
121  std::vector<const sim::IDE*> TrackIdToSimIDEs_Ps(int const& id, const geo::View_t view) const;
122 
129  art::Ptr<sim::SimChannel> FindSimChannelPtr(raw::ChannelID_t channel) const;
130 
139  art::Ptr<sim::SimChannel> FindSimChannel(raw::ChannelID_t channel) const;
140 
141  std::vector<sim::TrackIDE> ChannelToTrackIDEs(detinfo::DetectorClocksData const& clockData,
142  raw::ChannelID_t channel,
143  const double hit_start_time,
144  const double hit_end_time) const;
145 
146  // Track IDEs cannot be returned as pointers, as they dont exist in the data
147  // product, and we will not be storing them.
148  std::vector<sim::TrackIDE> HitToTrackIDEs(detinfo::DetectorClocksData const& clockData,
149  recob::Hit const& hit) const;
150  std::vector<sim::TrackIDE> HitToTrackIDEs(detinfo::DetectorClocksData const& clockData,
151  art::Ptr<recob::Hit> const& hit) const
152  {
153  return this->HitToTrackIDEs(clockData, *hit);
154  }
155 
156  std::vector<int> HitToTrackIds(detinfo::DetectorClocksData const& clockData,
157  recob::Hit const& hit) const;
158  // std::vector< const int> HitToTrackId(art::Ptr<recob::Hit> const& hit) {
159  // return this->HitToTrackId(*hit); }
160 
161  std::vector<sim::TrackIDE> HitToEveTrackIDEs(detinfo::DetectorClocksData const& clockData,
162  recob::Hit const& hit) const;
163  std::vector<sim::TrackIDE> HitToEveTrackIDEs(detinfo::DetectorClocksData const& clockData,
164  art::Ptr<recob::Hit> const& hit) const
165  {
166  return this->HitToEveTrackIDEs(clockData, *hit);
167  }
168 
169  // I will not return these by copy, as that could get very large very
170  // quickly.
171  std::vector<art::Ptr<recob::Hit>> TrackIdToHits_Ps(
172  detinfo::DetectorClocksData const& clockData,
173  int tkId,
174  std::vector<art::Ptr<recob::Hit>> const& hitsIn) const;
175 
176  std::vector<std::vector<art::Ptr<recob::Hit>>> TrackIdsToHits_Ps(
177  detinfo::DetectorClocksData const& clockData,
178  std::vector<int> const& tkIds,
179  std::vector<art::Ptr<recob::Hit>> const& hitsIn) const;
180 
181  std::vector<sim::IDE> HitToAvgSimIDEs(detinfo::DetectorClocksData const& clockData,
182  recob::Hit const& hit) const;
183  std::vector<sim::IDE> HitToAvgSimIDEs(detinfo::DetectorClocksData const& clockData,
184  art::Ptr<recob::Hit> const& hit) const
185  {
186  return this->HitToAvgSimIDEs(clockData, *hit);
187  }
188 
189  std::vector<const sim::IDE*> HitToSimIDEs_Ps(detinfo::DetectorClocksData const& clockData,
190  recob::Hit const& hit) const;
191  std::vector<const sim::IDE*> HitToSimIDEs_Ps(detinfo::DetectorClocksData const& clockData,
192  art::Ptr<recob::Hit> const& hit) const
193  {
194  return this->HitToSimIDEs_Ps(clockData, *hit);
195  }
196 
197  std::vector<double> SimIDEsToXYZ(std::vector<sim::IDE> const& ides) const;
198  std::vector<double> SimIDEsToXYZ(std::vector<const sim::IDE*> const& ide_Ps) const;
199 
200  std::vector<double> HitToXYZ(detinfo::DetectorClocksData const& clockData,
201  const recob::Hit& hit) const;
202  std::vector<double> HitToXYZ(detinfo::DetectorClocksData const& clockData,
203  art::Ptr<recob::Hit> const& hit) const
204  {
205  return this->HitToXYZ(clockData, *hit);
206  }
207 
208  double HitCollectionPurity(detinfo::DetectorClocksData const& clockData,
209  std::set<int> const& trackIds,
210  std::vector<art::Ptr<recob::Hit>> const& hits) const;
211  double HitChargeCollectionPurity(detinfo::DetectorClocksData const& clockData,
212  std::set<int> const& trackIds,
213  std::vector<art::Ptr<recob::Hit>> const& hits) const;
214 
215  double HitCollectionEfficiency(detinfo::DetectorClocksData const& clockData,
216  std::set<int> const& trackIds,
218  std::vector<art::Ptr<recob::Hit>> const& allhits,
219  geo::View_t const& view) const;
220 
221  double HitChargeCollectionEfficiency(detinfo::DetectorClocksData const& clockData,
222  std::set<int> const& trackIds,
224  std::vector<art::Ptr<recob::Hit>> const& allhits,
225  geo::View_t const& view) const;
226 
227  std::set<int> GetSetOfTrackIds() const { return fPartInv->GetSetOfTrackIds(); }
228  std::set<int> GetSetOfEveIds() const { return fPartInv->GetSetOfEveIds(); }
229 
230  std::set<int> GetSetOfTrackIds(detinfo::DetectorClocksData const& clockData,
231  std::vector<art::Ptr<recob::Hit>> const& hits) const;
232  std::set<int> GetSetOfEveIds(detinfo::DetectorClocksData const& clockData,
233  std::vector<art::Ptr<recob::Hit>> const& hits) const;
234 
235  std::vector<double> SpacePointHitsToWeightedXYZ(
236  detinfo::DetectorClocksData const& clockData,
237  std::vector<art::Ptr<recob::Hit>> const& hits) const;
238 
239  private:
240  const cheat::ParticleInventory* fPartInv; // The constructor needs to put something in here
245  const double fMinHitEnergyFraction;
246  const bool fOverrideRealData;
247  const double fHitTimeRMS;
248 
249  mutable std::vector<art::Ptr<sim::SimChannel>> fSimChannels;
250 
251  }; // end class BackTracker
252 
253 } // end namespace cheat
254 
255 #include "BackTracker.tcc"
256 
257 #endif // CHEAT_BACKTRACKER_H
const art::InputTag fHitLabel
Definition: BackTracker.h:244
const geo::GeometryCore * fGeom
Definition: BackTracker.h:241
Reconstruction base classes.
std::vector< art::Ptr< sim::SimChannel > > fSimChannels
Definition: BackTracker.h:249
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Declaration of signal hit object.
const art::InputTag fSimChannelModuleLabel
Definition: BackTracker.h:243
const double fMinHitEnergyFraction
Definition: BackTracker.h:245
std::vector< double > HitToXYZ(detinfo::DetectorClocksData const &clockData, art::Ptr< recob::Hit > const &hit) const
Definition: BackTracker.h:202
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, art::Ptr< recob::Hit > const &hit) const
Definition: BackTracker.h:150
bool CanRun(const Evt &evt)
Definition: BackTracker.h:92
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
void hits()
Definition: readHits.C:15
bool SimChannelsReady() const
Definition: BackTracker.h:111
parameter set interface
std::set< int > GetSetOfTrackIds() const
Definition: BackTracker.h:227
const cheat::ParticleInventory * fPartInv
Definition: BackTracker.h:240
const double fHitTimeRMS
Definition: BackTracker.h:247
General LArSoft Utilities.
Description of geometry of one entire detector.
Definition: GeometryCore.h:119
std::vector< sim::TrackIDE > HitToEveTrackIDEs(detinfo::DetectorClocksData const &clockData, art::Ptr< recob::Hit > const &hit) const
Definition: BackTracker.h:163
Definition of data types for geometry description.
Detector simulation of raw signals on wires.
const std::vector< art::Ptr< sim::SimChannel > > & SimChannels() const
Definition: BackTracker.h:113
std::set< int > GetSetOfEveIds() const
Definition: BackTracker.h:228
std::vector< const sim::IDE * > HitToSimIDEs_Ps(detinfo::DetectorClocksData const &clockData, art::Ptr< recob::Hit > const &hit) const
Definition: BackTracker.h:191
code to link reconstructed objects back to the MC truth information
Definition: BackTracker.cc:22
const bool fOverrideRealData
Definition: BackTracker.h:246
Contains all timing reference information for the detector.
object containing MC truth information necessary for making RawDigits and doing back tracking ...
Header for the ParticleInvenotry Service Provider.
const art::InputTag fG4ModuleLabel
Definition: BackTracker.h:242
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:46
TCEvent evt
Definition: DataStructs.cxx:8
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
std::vector< sim::IDE > HitToAvgSimIDEs(detinfo::DetectorClocksData const &clockData, art::Ptr< recob::Hit > const &hit) const
Definition: BackTracker.h:183
Namespace collecting geometry-related classes utilities.