BackTracker.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////
2 //
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 //
10 ////////////////////////////////////////////////////////////////////////////
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{
69  fhicl::Name("HitTimeRMS"),
70  fhicl::Comment("The number of RMS units to move away"
71  "from a Hit peak time for searching IDE."),
72  1.0};
73  };
74 
76  const cheat::ParticleInventory* partInv,
77  const geo::GeometryCore* geom);
78  BackTracker(const fhicl::ParameterSet& pSet,
79  const cheat::ParticleInventory* partInv,
80  const geo::GeometryCore* geom);
81 
82  // I may need to include this to delete copy of service providers.
83  BackTracker(BackTracker const&) = delete;
84 
85  template <typename Evt>
86  void PrepEvent(const Evt& evt);
87 
88  template <typename Evt>
89  void PrepSimChannels(const Evt& evt);
90 
91  //-----------------------------------------------------
92  template <typename Evt>
93  bool
94  CanRun(const Evt& evt)
95  {
96  return !evt.isRealData() || fOverrideRealData;
97  }
98 
99  //-----------------------------------------------------
100  template <typename Evt>
101  std::vector<art::Ptr<recob::Hit>> SpacePointToHits_Ps(art::Ptr<recob::SpacePoint> const& spt,
102  const Evt& evt) const;
103 
104  //-----------------------------------------------------
105  template <typename Evt>
106  std::vector<double> SpacePointToXYZ(detinfo::DetectorClocksData const& clockData,
107  art::Ptr<recob::SpacePoint> const& spt,
108  const Evt& evt) const;
109 
110  //-----------------------------------------------------
111  void ClearEvent();
112 
113  bool
115  {
116  return !fSimChannels.empty();
117  }
118 
119  const std::vector<art::Ptr<sim::SimChannel>>&
120  SimChannels() const
121  {
122  return fSimChannels;
123  }
124  // All Hit List would go here. We explicitly choose not to include it, as
125  // the user should not be using backtracker to access Hits. This could
126  // change in a concievable future use case where we also allow the user to
127  // define what the "AllHitList" should be, though this would have
128  // ramifications on other functions.
129 
130  std::vector<const sim::IDE*> TrackIdToSimIDEs_Ps(int const& id) const;
131  std::vector<const sim::IDE*> TrackIdToSimIDEs_Ps(int const& id, const geo::View_t view) const;
132 
133  /**
134  * @brief Returns the cached `sim::SimChannel` on the specified `channel`.
135  * @param channel ID of the TPC channel to find
136  * @return _art_ pointer to `sim::SimChannel`, or an null pointer if none
137  * @see FindSimChannel()
138  */
139  art::Ptr<sim::SimChannel> FindSimChannelPtr(raw::ChannelID_t channel) const;
140 
141  /**
142  * @brief Returns the cached `sim::SimChannel` on the specified `channel`.
143  * @param channel ID of the TPC channel to find
144  * @return _art_ pointer to `sim::SimChannel`
145  * @throw cet::exception (category: `"BackTracker"`) if no `sim::SimChannel`
146  * for the requested `channel` found
147  * @see FindSimChannelPtr()
148  */
149  art::Ptr<sim::SimChannel> FindSimChannel(raw::ChannelID_t channel) const;
150 
151  std::vector<sim::TrackIDE> ChannelToTrackIDEs(detinfo::DetectorClocksData const& clockData,
152  raw::ChannelID_t channel,
153  const double hit_start_time,
154  const double hit_end_time) const;
155 
156  // Track IDEs cannot be returned as pointers, as they dont exist in the data
157  // product, and we will not be storing them.
158  std::vector<sim::TrackIDE> HitToTrackIDEs(detinfo::DetectorClocksData const& clockData,
159  recob::Hit const& hit) const;
160  std::vector<sim::TrackIDE>
162  art::Ptr<recob::Hit> const& hit) const
163  {
164  return this->HitToTrackIDEs(clockData, *hit);
165  }
166 
167  std::vector<int> HitToTrackIds(detinfo::DetectorClocksData const& clockData,
168  recob::Hit const& hit) const;
169  // std::vector< const int> HitToTrackId(art::Ptr<recob::Hit> const& hit) {
170  // return this->HitToTrackId(*hit); }
171 
172  std::vector<sim::TrackIDE> HitToEveTrackIDEs(detinfo::DetectorClocksData const& clockData,
173  recob::Hit const& hit) const;
174  std::vector<sim::TrackIDE>
176  art::Ptr<recob::Hit> const& hit) const
177  {
178  return this->HitToEveTrackIDEs(clockData, *hit);
179  }
180 
181  // I will not return these by copy, as that could get very large very
182  // quickly.
183  std::vector<art::Ptr<recob::Hit>> TrackIdToHits_Ps(
184  detinfo::DetectorClocksData const& clockData,
185  int tkId,
186  std::vector<art::Ptr<recob::Hit>> const& hitsIn) const;
187 
188  std::vector<std::vector<art::Ptr<recob::Hit>>> TrackIdsToHits_Ps(
189  detinfo::DetectorClocksData const& clockData,
190  std::vector<int> const& tkIds,
191  std::vector<art::Ptr<recob::Hit>> const& hitsIn) const;
192 
193  std::vector<sim::IDE> HitToAvgSimIDEs(detinfo::DetectorClocksData const& clockData,
194  recob::Hit const& hit) const;
195  std::vector<sim::IDE>
197  art::Ptr<recob::Hit> const& hit) const
198  {
199  return this->HitToAvgSimIDEs(clockData, *hit);
200  }
201 
202  std::vector<const sim::IDE*> HitToSimIDEs_Ps(detinfo::DetectorClocksData const& clockData,
203  recob::Hit const& hit) const;
204  std::vector<const sim::IDE*>
206  art::Ptr<recob::Hit> const& hit) const
207  {
208  return this->HitToSimIDEs_Ps(clockData, *hit);
209  }
210 
211  std::vector<double> SimIDEsToXYZ(std::vector<sim::IDE> const& ides) const;
212  std::vector<double> SimIDEsToXYZ(std::vector<const sim::IDE*> const& ide_Ps) const;
213 
214  std::vector<double> HitToXYZ(detinfo::DetectorClocksData const& clockData,
215  const recob::Hit& hit) const;
216  std::vector<double>
217  HitToXYZ(detinfo::DetectorClocksData const& clockData, art::Ptr<recob::Hit> const& hit) const
218  {
219  return this->HitToXYZ(clockData, *hit);
220  }
221 
222  double HitCollectionPurity(detinfo::DetectorClocksData const& clockData,
223  std::set<int> const& trackIds,
224  std::vector<art::Ptr<recob::Hit>> const& hits) const;
225  double HitChargeCollectionPurity(detinfo::DetectorClocksData const& clockData,
226  std::set<int> const& trackIds,
227  std::vector<art::Ptr<recob::Hit>> const& hits) const;
228 
229  double HitCollectionEfficiency(detinfo::DetectorClocksData const& clockData,
230  std::set<int> const& trackIds,
231  std::vector<art::Ptr<recob::Hit>> const& hits,
232  std::vector<art::Ptr<recob::Hit>> const& allhits,
233  geo::View_t const& view) const;
234 
235  double HitChargeCollectionEfficiency(detinfo::DetectorClocksData const& clockData,
236  std::set<int> const& trackIds,
237  std::vector<art::Ptr<recob::Hit>> const& hits,
238  std::vector<art::Ptr<recob::Hit>> const& allhits,
239  geo::View_t const& view) const;
240 
241  std::set<int>
243  {
244  return fPartInv->GetSetOfTrackIds();
245  }
246  std::set<int>
248  {
249  return fPartInv->GetSetOfEveIds();
250  }
251 
252  std::set<int> GetSetOfTrackIds(detinfo::DetectorClocksData const& clockData,
253  std::vector<art::Ptr<recob::Hit>> const& hits) const;
254  std::set<int> GetSetOfEveIds(detinfo::DetectorClocksData const& clockData,
255  std::vector<art::Ptr<recob::Hit>> const& hits) const;
256 
257  std::vector<double> SpacePointHitsToWeightedXYZ(
258  detinfo::DetectorClocksData const& clockData,
259  std::vector<art::Ptr<recob::Hit>> const& hits) const;
260 
261  private:
262  const cheat::ParticleInventory* fPartInv; // The constructor needs to put something in here
267  const double fMinHitEnergyFraction;
268  const bool fOverrideRealData;
269  const double fHitTimeRMS;
270 
271  mutable std::vector<art::Ptr<sim::SimChannel>> fSimChannels;
272 
273  }; // end class BackTracker
274 
275 } // end namespace cheat
276 
277 #include "BackTracker.tcc"
278 
279 #endif // CHEAT_BACKTRACKER_H
const art::InputTag fHitLabel
Definition: BackTracker.h:266
const geo::GeometryCore * fGeom
Definition: BackTracker.h:263
Reconstruction base classes.
std::vector< art::Ptr< sim::SimChannel > > fSimChannels
Definition: BackTracker.h:271
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Declaration of signal hit object.
const art::InputTag fSimChannelModuleLabel
Definition: BackTracker.h:265
struct vector vector
const double fMinHitEnergyFraction
Definition: BackTracker.h:267
uint8_t channel
Definition: CRTFragment.hh:201
std::vector< double > HitToXYZ(detinfo::DetectorClocksData const &clockData, art::Ptr< recob::Hit > const &hit) const
Definition: BackTracker.h:217
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, art::Ptr< recob::Hit > const &hit) const
Definition: BackTracker.h:161
bool CanRun(const Evt &evt)
Definition: BackTracker.h:94
static Config * config
Definition: config.cpp:1054
bool SimChannelsReady() const
Definition: BackTracker.h:114
std::set< int > GetSetOfTrackIds() const
Definition: BackTracker.h:242
const cheat::ParticleInventory * fPartInv
Definition: BackTracker.h:262
const double fHitTimeRMS
Definition: BackTracker.h:269
General LArSoft Utilities.
Description of geometry of one entire detector.
std::vector< sim::TrackIDE > HitToEveTrackIDEs(detinfo::DetectorClocksData const &clockData, art::Ptr< recob::Hit > const &hit) const
Definition: BackTracker.h:175
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:120
std::set< int > GetSetOfEveIds() const
Definition: BackTracker.h:247
std::vector< const sim::IDE * > HitToSimIDEs_Ps(detinfo::DetectorClocksData const &clockData, art::Ptr< recob::Hit > const &hit) const
Definition: BackTracker.h:205
code to link reconstructed objects back to the MC truth information
Definition: BackTracker.cc:22
#define Comment
const bool fOverrideRealData
Definition: BackTracker.h:268
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:264
VDColdboxChannelRanges::Name Name
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
TCEvent evt
Definition: DataStructs.cxx:7
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:196
Verifies that the geometry check information is available.