LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 //Includes
15 #include <vector>
16 
17 #include "ParticleInventory.h"
18 
19 
20 #include "fhiclcpp/types/Atom.h"
21 #include "fhiclcpp/types/Table.h"
22 
30 
31 /*namespace recob{
32  class SpacePoint;
33  }*/
34 
35 
36 namespace cheat{
37 
38  class BackTracker{
39  public:
40 
41  //Structure for configuration parameters. (fhicl validation)
42  struct fhiclConfig{
43  fhicl::Atom<art::InputTag> G4ModuleLabel{fhicl::Name("G4ModuleLabel"), fhicl::Comment("The label of the LArG4 module used to produce the art file we will be using."), "largeant"};
44  fhicl::Atom<art::InputTag> DefaultHitModuleLabel{fhicl::Name("DefaultHitModuleLabel"), fhicl::Comment("The label of the module used to produce the hits in the art file we will default to when no hitlist is provided."), "hitfd"};
45  fhicl::Atom<double> MinHitEnergyFraction{fhicl::Name("MinHitEnergyFraction"), fhicl::Comment("The minimum contribution an energy deposit must make to a Hit to be considered part of that hit."),0.010};
46  fhicl::Atom<bool> OverrideRealData{fhicl::Name("OverrideRealData"),fhicl::Comment("Option when overlaying simulation on real data, to tell the backtracker to continue even if event looks like data."),false};
47  };
48 
49 
50  BackTracker(const fhiclConfig& config,
51  const cheat::ParticleInventory* partInv,
52  const geo::GeometryCore* geom,
53  const detinfo::DetectorClocks* detClock );
54  BackTracker(const fhicl::ParameterSet& pSet,
55  const cheat::ParticleInventory* partInv,
56  const geo::GeometryCore* geom,
57  const detinfo::DetectorClocks* detClock );
58  //I may need to include this to delete copy of service providers.
59  BackTracker(BackTracker const&) = delete;
60 
61  template<typename Evt>
62  void PrepEvent ( const Evt& evt );
63 
64  template<typename Evt>
65  void PrepSimChannels ( const Evt& evt );
66 
67 // template<typename Evt>
68 // void PrepAllHitList ( const Evt& evt);
69 
70  //-----------------------------------------------------
71  template<typename Evt>
72  bool CanRun(const Evt& evt){ return ( !(evt.isRealData()) || fOverrideRealData);}
73 
74  //-----------------------------------------------------
75  template<typename Evt>
76  const std::vector< art::Ptr< recob::Hit > > SpacePointToHits_Ps(art::Ptr< recob::SpacePoint> const& spt, const Evt& evt) const;
77 
78  //-----------------------------------------------------
79  template<typename Evt>
80  const std::vector< double > SpacePointToXYZ( art::Ptr< recob::SpacePoint > const& spt, const Evt& evt) const;
81 
82 
83  //-----------------------------------------------------
84  void ClearEvent();
85 
86 
87  bool SimChannelsReady() const { return !( fSimChannels.empty() ); }
88 // bool AllHitListReady () const { return !( fAllHitList.empty() ); }
89 
90  const std::vector<art::Ptr<sim::SimChannel>>& SimChannels() const { return fSimChannels; }
91  //All Hit List would go here. We explicitly choose not to include it, as the user should not be using backtracker to access Hits. This could change in a concievable future use case where we also allow the user to define what the "AllHitList" should be, though this would have ramifications on other functions.
92 
93  const std::vector<const sim::IDE* > TrackIdToSimIDEs_Ps(int const& id) const;
94  //const std::vector<const sim::IDE> TrackIdToSimIDEs (int const& id) const;
95  const std::vector<const sim::IDE* > TrackIdToSimIDEs_Ps(int const& id, const geo::View_t view) const;
96  //std::vector<const sim::IDE> TrackIdToSimIDEs (int const& id, const geo::View_t view) const;
97 
99 
100  const std::vector< sim::TrackIDE > ChannelToTrackIDEs(raw::ChannelID_t channel, const double hit_start_time, const double hit_end_time) const;
101 
102 
103  //Track IDEs cannot be returned as pointers, as they dont exist in the data product, and we will not be storing them.
104  const std::vector< sim::TrackIDE> HitToTrackIDEs(recob::Hit const& hit) const;
105  const std::vector< sim::TrackIDE> HitToTrackIDEs(art::Ptr<recob::Hit> const& hit) const { return this->HitToTrackIDEs(*hit);}
106 
107  const std::vector< int > HitToTrackIds(recob::Hit const& hit) const ;
108  // std::vector< const int> HitToTrackId(art::Ptr<recob::Hit> const& hit) { return this->HitToTrackId(*hit); }
109 
110  const std::vector<sim::TrackIDE> HitToEveTrackIDEs(recob::Hit const& hit) const;
111  const std::vector<sim::TrackIDE> HitToEveTrackIDEs(art::Ptr<recob::Hit> const& hit) const{ return this->HitToEveTrackIDEs(*hit);}
112 
113  //I will not return these by copy, as that could get very large very quickly.
114  std::vector< art::Ptr<recob::Hit> > TrackIdToHits_Ps( const int& tkId, std::vector< art::Ptr< recob::Hit > > const& hitsIn ) const;
115 //I am not allowing this function for now, as caching the allhitlist indiscriminately is a catastrophically bad idea.
116 // std::vector< art::Ptr<recob::Hit> > TrackIdToHits_Ps( const int& tkId ) const
117 // {return this->TrackIdToHits_Ps(tkId, fAllHitList); }
118 
119  std::vector< std::vector< art::Ptr<recob::Hit> > > TrackIdsToHits_Ps( std::vector<int> const& tkIds, std::vector< art::Ptr< recob::Hit > > const& hitsIn ) const;
120 // std::vector< std::vector< art::Ptr<recob::Hit> > > TrackIdsToHits_Ps( std::vector<int> const& tkIds ) const
121 // {return this->TrackIdsToHits_Ps(tkIds, fAllHitList);}
122 
123  const std::vector< sim::IDE > HitToAvgSimIDEs ( recob::Hit const& hit) const;
124  const std::vector< sim::IDE > HitToAvgSimIDEs ( art::Ptr<recob::Hit> hit) const{ return this->HitToAvgSimIDEs(*hit);}
125 
126  const std::vector< const sim::IDE* > HitToSimIDEs_Ps (recob::Hit const& hit) const;
127  const std::vector< const sim::IDE* > HitToSimIDEs_Ps (art::Ptr< recob::Hit > const& hit) const { return this->HitToSimIDEs_Ps (*hit); }
128 
129  //const std::vector< sim::IDE > HitToSimIDEs (recob::Hit const& hit);
130  // std::vector< const sim::IDE > HitToSimIDEs (art::Ptr< recob::Hit > const& hit) { return this->HitToSimIDEsPs (*hit); }
131 
132  const std::vector<double> SimIDEsToXYZ( std::vector< sim::IDE > const& ides) const;
133  const std::vector<double> SimIDEsToXYZ( std::vector< const sim::IDE* > const& ide_Ps) const;
134 
135  const std::vector<double> HitToXYZ(const recob::Hit& hit) const;
136  const std::vector<double> HitToXYZ(art::Ptr<recob::Hit> const& hit) const{ return this->HitToXYZ(*hit);}
137 
138 
139 
140  const double HitCollectionPurity( std::set<int> const& trackIds, std::vector< art::Ptr<recob::Hit> > const& hits) const;
141  const double HitChargeCollectionPurity( std::set<int> const& trackIds, std::vector< art::Ptr<recob::Hit> > const& hits) const;
142 
143  const double HitCollectionEfficiency( std::set<int> const& trackIds, std::vector< art::Ptr<recob::Hit> > const& hits, std::vector< art::Ptr<recob::Hit> > const& allhits, geo::View_t const& view) const;
144 
145 
146  const double HitChargeCollectionEfficiency( std::set<int> trackIds, std::vector< art::Ptr<recob::Hit> > const& hits, std::vector< art::Ptr<recob::Hit> > const& allhits, geo::View_t const& view) const;
147 
148  const std::set<int> GetSetOfTrackIds() const { return fPartInv->GetSetOfTrackIds();}
149  const std::set<int> GetSetOfEveIds() const { return fPartInv->GetSetOfEveIds();}
150 
151  const std::set<int> GetSetOfTrackIds( std::vector< art::Ptr< recob::Hit > > const& hits ) const;
152  const std::set<int> GetSetOfEveIds( std::vector< art::Ptr< recob::Hit > > const& hits ) const;
153 
154  const std::vector< double> SpacePointHitsToWeightedXYZ(std::vector<art::Ptr<recob::Hit>> const& hits) const;
155 
156  private:
157  const cheat::ParticleInventory* fPartInv; //The constructor needs to put something in here
162  const double fMinHitEnergyFraction;
163  const bool fOverrideRealData;
164 
165  mutable std::vector<art::Ptr<sim::SimChannel>> fSimChannels;
166 // mutable std::vector< art::Ptr<recob::Hit> > fAllHitList;
167 
168  };//end class BackTracker
169 
170 }//end namespace cheat
171 
172 #include "BackTracker.tcc"
173 
174 #endif //CHEAT_BACKTRACKER_H
fhicl::Atom< bool > OverrideRealData
Definition: BackTracker.h:46
const art::InputTag fHitLabel
Definition: BackTracker.h:161
const std::vector< double > SpacePointHitsToWeightedXYZ(std::vector< art::Ptr< recob::Hit >> const &hits) const
Definition: BackTracker.cc:512
const geo::GeometryCore * fGeom
Definition: BackTracker.h:158
void PrepSimChannels(const Evt &evt)
std::vector< art::Ptr< sim::SimChannel > > fSimChannels
Definition: BackTracker.h:165
fhicl::Atom< double > MinHitEnergyFraction
Definition: BackTracker.h:45
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
const detinfo::DetectorClocks * fDetClocks
Definition: BackTracker.h:159
const std::vector< const sim::IDE * > HitToSimIDEs_Ps(art::Ptr< recob::Hit > const &hit) const
Definition: BackTracker.h:127
Declaration of signal hit object.
const std::set< int > GetSetOfEveIds() const
Definition: BackTracker.h:149
const std::vector< sim::TrackIDE > ChannelToTrackIDEs(raw::ChannelID_t channel, const double hit_start_time, const double hit_end_time) const
Definition: BackTracker.cc:114
const double fMinHitEnergyFraction
Definition: BackTracker.h:162
const std::vector< double > HitToXYZ(art::Ptr< recob::Hit > const &hit) const
Definition: BackTracker.h:136
pure virtual base interface for detector clocks
const std::vector< sim::TrackIDE > HitToTrackIDEs(recob::Hit const &hit) const
Definition: BackTracker.cc:164
const double HitCollectionEfficiency(std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit > > const &hits, std::vector< art::Ptr< recob::Hit > > const &allhits, geo::View_t const &view) const
Definition: BackTracker.cc:422
const std::vector< int > HitToTrackIds(recob::Hit const &hit) const
Definition: BackTracker.cc:174
bool CanRun(const Evt &evt)
Definition: BackTracker.h:72
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
Access the description of detector geometry.
const std::vector< const sim::IDE * > TrackIdToSimIDEs_Ps(int const &id) const
Definition: BackTracker.cc:59
void hits()
Definition: readHits.C:15
bool SimChannelsReady() const
Definition: BackTracker.h:87
art::Ptr< sim::SimChannel > FindSimChannel(raw::ChannelID_t channel) const
Definition: BackTracker.cc:101
const std::vector< art::Ptr< recob::Hit > > SpacePointToHits_Ps(art::Ptr< recob::SpacePoint > const &spt, const Evt &evt) const
const std::vector< double > HitToXYZ(const recob::Hit &hit) const
Definition: BackTracker.cc:383
std::vector< std::vector< art::Ptr< recob::Hit > > > TrackIdsToHits_Ps(std::vector< int > const &tkIds, std::vector< art::Ptr< recob::Hit > > const &hitsIn) const
Definition: BackTracker.cc:241
std::set< int > GetSetOfTrackIds() const
const double HitChargeCollectionPurity(std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit > > const &hits) const
Definition: BackTracker.cc:405
const cheat::ParticleInventory * fPartInv
Definition: BackTracker.h:157
const std::vector< const sim::IDE * > HitToSimIDEs_Ps(recob::Hit const &hit) const
Definition: BackTracker.cc:291
const std::vector< sim::TrackIDE > HitToEveTrackIDEs(recob::Hit const &hit) const
Definition: BackTracker.cc:184
std::set< int > GetSetOfEveIds() const
Description of geometry of one entire detector.
Detector simulation of raw signals on wires.
Conversion of times between different formats and references.
fhicl::Atom< art::InputTag > G4ModuleLabel
Definition: BackTracker.h:43
const std::vector< art::Ptr< sim::SimChannel > > & SimChannels() const
Definition: BackTracker.h:90
const std::vector< sim::TrackIDE > HitToEveTrackIDEs(art::Ptr< recob::Hit > const &hit) const
Definition: BackTracker.h:111
fhicl::Atom< art::InputTag > DefaultHitModuleLabel
Definition: BackTracker.h:44
code to link reconstructed objects back to the MC truth information
Definition: BackTracker.cc:26
const std::vector< double > SpacePointToXYZ(art::Ptr< recob::SpacePoint > const &spt, const Evt &evt) const
const double HitChargeCollectionEfficiency(std::set< int > trackIds, std::vector< art::Ptr< recob::Hit > > const &hits, std::vector< art::Ptr< recob::Hit > > const &allhits, geo::View_t const &view) const
Definition: BackTracker.cc:454
const bool fOverrideRealData
Definition: BackTracker.h:163
const std::set< int > GetSetOfTrackIds() const
Definition: BackTracker.h:148
const std::vector< sim::IDE > HitToAvgSimIDEs(art::Ptr< recob::Hit > hit) const
Definition: BackTracker.h:124
object containing MC truth information necessary for making RawDigits and doing back tracking ...
const std::vector< sim::IDE > HitToAvgSimIDEs(recob::Hit const &hit) const
Definition: BackTracker.cc:279
Header for the ParticleInvenotry Service Provider.
const art::InputTag fG4ModuleLabel
Definition: BackTracker.h:160
const std::vector< double > SimIDEsToXYZ(std::vector< sim::IDE > const &ides) const
Definition: BackTracker.cc:354
Data structure containing constant pointers to classes.
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:49
TCEvent evt
Definition: DataStructs.cxx:5
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:27
std::vector< art::Ptr< recob::Hit > > TrackIdToHits_Ps(const int &tkId, std::vector< art::Ptr< recob::Hit > > const &hitsIn) const
Definition: BackTracker.cc:218
const double HitCollectionPurity(std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit > > const &hits) const
Definition: BackTracker.cc:389
const std::vector< sim::TrackIDE > HitToTrackIDEs(art::Ptr< recob::Hit > const &hit) const
Definition: BackTracker.h:105
void PrepEvent(const Evt &evt)
BackTracker(const fhiclConfig &config, const cheat::ParticleInventory *partInv, const geo::GeometryCore *geom, const detinfo::DetectorClocks *detClock)
Definition: BackTracker.cc:29