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