LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
CheckBackTracking_module.cc
Go to the documentation of this file.
1 //
3 // CheckBackTracking module
4 //
5 // brebel@fnal.gov
6 //
8 
9 #include <set>
10 #include <string>
11 #include <vector>
12 
13 // LArSoft includes
21 
22 // Framework includes
29 #include "fhiclcpp/ParameterSet.h"
31 
32 namespace cheat {
34  public:
35  explicit CheckBackTracking(fhicl::ParameterSet const& pset);
36 
37  void analyze(art::Event const& evt);
38 
39  private:
40  std::string fHitModuleLabel;
41  std::string fG4ModuleLabel;
42  };
43 }
44 
45 namespace cheat {
46 
47  //--------------------------------------------------------------------
49  : EDAnalyzer(pset)
50  , fHitModuleLabel{pset.get<std::string>("HitModuleLabel", "ffthit")}
51  , fG4ModuleLabel{pset.get<std::string>("G4ModuleLabel", "largeant")}
52  {}
53 
54  //--------------------------------------------------------------------
56  {
57 
58  // grab the hits that have been reconstructed
60  evt.getByLabel(fHitModuleLabel, hitcol);
61 
62  // make a vector of them - we aren't writing anything out to a file
63  // so no need for a art::PtrVector here
64  std::vector<art::Ptr<recob::Hit>> hits;
65  art::fill_ptr_vector(hits, hitcol);
66 
67  // loop over the hits and figure out which particle contributed to each one
68  std::vector<art::Ptr<recob::Hit>>::iterator itr = hits.begin();
69 
72 
73  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
74 
75  // make a collection of the distinct eve ID values
76  std::set<int> eveIDs;
77 
78  while (itr != hits.end()) {
79 
80  // print the truth information for this hit
81  mf::LogInfo("CheckBackTracking") << *((*itr).get()) << "\n channel is: " << (*itr)->Channel();
82 
83  std::vector<sim::TrackIDE> trackides = bt_serv->HitToTrackIDEs(clockData, *itr);
84  std::vector<sim::TrackIDE> eveides = bt_serv->HitToEveTrackIDEs(clockData, *itr);
85  std::vector<double> xyz = bt_serv->HitToXYZ(clockData, *itr);
86 
87  mf::LogInfo("CheckBackTracking")
88  << "hit weighted mean position is (" << xyz[0] << "," << xyz[1] << "," << xyz[2] << ")";
89 
90  for (size_t t = 0; t < trackides.size(); ++t) {
91 
92  // find the Eve particle for the current trackID
93  int eveID = pi_serv->ParticleList().EveId(trackides[t].trackID);
94 
95  mf::LogInfo("CheckBackTracking")
96  << "track id: " << trackides[t].trackID << " contributed " << trackides[t].energy << "/"
97  << trackides[t].energyFrac << " to the current hit and has eveID: " << eveID;
98  }
99 
100  for (size_t e = 0; e < eveides.size(); ++e) {
101  mf::LogInfo("CheckBackTracking")
102  << "eve id: " << eveides[e].trackID << " contributed " << eveides[e].energy << "/"
103  << eveides[e].energyFrac << " to the current hit";
104 
105  if (eveIDs.find(eveides[e].trackID) == eveIDs.end()) eveIDs.insert(eveides[e].trackID);
106  }
107 
108  itr++;
109  } // end loop over hits
110 
111  // loop over the eveID values and calculate the purity and efficiency for
112  // each
113  std::set<int>::iterator setitr = eveIDs.begin();
114  while (setitr != eveIDs.end()) {
115 
116  std::set<int> id;
117  id.insert(*setitr);
118  mf::LogInfo("CheckBackTracking")
119  << "eve ID: " << *setitr << " purity: " << bt_serv->HitCollectionPurity(clockData, id, hits)
120  << " efficiency: " << bt_serv->HitCollectionEfficiency(clockData, id, hits, hits, geo::k3D);
121 
122  setitr++;
123  }
124 
125  return;
126 
127  } // end analyze
128 
129 } // end namespace
130 
131 namespace cheat {
132 
134 
135 }
intermediate_table::iterator iterator
std::string fHitModuleLabel
label for module creating recob::Hit objects
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Declaration of signal hit object.
double HitCollectionEfficiency(detinfo::DetectorClocksData const &clockData, 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
CheckBackTracking(fhicl::ParameterSet const &pset)
std::vector< double > HitToXYZ(detinfo::DetectorClocksData const &clockData, const recob::Hit &hit) const
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
int EveId(const int trackID) const
3-dimensional objects, potentially hits, clusters, prongs, etc.
Definition: geo_types.h:141
void hits()
Definition: readHits.C:15
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
double HitCollectionPurity(detinfo::DetectorClocksData const &clockData, std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit >> const &hits) const
T get(std::string const &key) const
Definition: ParameterSet.h:314
std::string fG4ModuleLabel
label for module running G4 and making particles, etc
Definition of data types for geometry description.
const sim::ParticleList & ParticleList() const
code to link reconstructed objects back to the MC truth information
Definition: BackTracker.cc:22
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
std::vector< sim::TrackIDE > HitToEveTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
object containing MC truth information necessary for making RawDigits and doing back tracking ...
TCEvent evt
Definition: DataStructs.cxx:8
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:306
void analyze(art::Event const &evt)
Particle list in DetSim contains Monte Carlo particle information.
Float_t e
Definition: plot.C:35