All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 <set>
10 #include <string>
11 #include <vector>
12 
13 // LArSoft includes
20 #include "nug4/ParticleNavigation/ParticleList.h"
21 
22 // Framework includes
23 #include "art/Framework/Core/EDAnalyzer.h"
24 #include "art/Framework/Core/ModuleMacros.h"
25 #include "art/Framework/Principal/Event.h"
26 #include "art/Framework/Principal/Handle.h"
27 #include "art/Framework/Services/Registry/ServiceHandle.h"
28 #include "canvas/Persistency/Common/Ptr.h"
29 #include "fhiclcpp/ParameterSet.h"
30 #include "messagefacility/MessageLogger/MessageLogger.h"
31 
32 namespace cheat {
33  class CheckBackTracking : public art::EDAnalyzer {
34  public:
35  explicit CheckBackTracking(fhicl::ParameterSet const& pset);
36 
37  void analyze(art::Event const& evt);
38 
39  private:
40  std::string fHitModuleLabel; ///< label for module creating recob::Hit objects
41  std::string fG4ModuleLabel; ///< label for module running G4 and making particles, etc
42  };
43 }
44 
45 namespace cheat {
46 
47  //--------------------------------------------------------------------
48  CheckBackTracking::CheckBackTracking(fhicl::ParameterSet const& pset)
49  : EDAnalyzer(pset)
50  , fHitModuleLabel{pset.get<std::string>("HitModuleLabel", "ffthit")}
51  , fG4ModuleLabel{pset.get<std::string>("G4ModuleLabel", "largeant")}
52  {}
53 
54  //--------------------------------------------------------------------
55  void
56  CheckBackTracking::analyze(art::Event const& evt)
57  {
58 
59  // grab the hits that have been reconstructed
60  art::Handle<std::vector<recob::Hit>> hitcol;
61  evt.getByLabel(fHitModuleLabel, hitcol);
62 
63  // make a vector of them - we aren't writing anything out to a file
64  // so no need for a art::PtrVector here
65  std::vector<art::Ptr<recob::Hit>> hits;
66  art::fill_ptr_vector(hits, hitcol);
67 
68  // loop over the hits and figure out which particle contributed to each one
69  std::vector<art::Ptr<recob::Hit>>::iterator itr = hits.begin();
70 
71  art::ServiceHandle<cheat::BackTrackerService const> bt_serv;
72  art::ServiceHandle<cheat::ParticleInventoryService const> pi_serv;
73 
74  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
75 
76  // make a collection of the distinct eve ID values
77  std::set<int> eveIDs;
78 
79  while (itr != hits.end()) {
80 
81  // print the truth information for this hit
82  mf::LogInfo("CheckBackTracking") << *((*itr).get()) << "\n channel is: " << (*itr)->Channel();
83 
84  std::vector<sim::TrackIDE> trackides = bt_serv->HitToTrackIDEs(clockData, *itr);
85  std::vector<sim::TrackIDE> eveides = bt_serv->HitToEveTrackIDEs(clockData, *itr);
86  std::vector<double> xyz = bt_serv->HitToXYZ(clockData, *itr);
87 
88  mf::LogInfo("CheckBackTracking")
89  << "hit weighted mean position is (" << xyz[0] << "," << xyz[1] << "," << xyz[2] << ")";
90 
91  for (size_t t = 0; t < trackides.size(); ++t) {
92 
93  // find the Eve particle for the current trackID
94  int eveID = pi_serv->ParticleList().EveId(trackides[t].trackID);
95 
96  mf::LogInfo("CheckBackTracking")
97  << "track id: " << trackides[t].trackID << " contributed " << trackides[t].energy << "/"
98  << trackides[t].energyFrac << " to the current hit and has eveID: " << eveID;
99  }
100 
101  for (size_t e = 0; e < eveides.size(); ++e) {
102  mf::LogInfo("CheckBackTracking")
103  << "eve id: " << eveides[e].trackID << " contributed " << eveides[e].energy << "/"
104  << eveides[e].energyFrac << " to the current hit";
105 
106  if (eveIDs.find(eveides[e].trackID) == eveIDs.end()) eveIDs.insert(eveides[e].trackID);
107  }
108 
109  itr++;
110  } // end loop over hits
111 
112  // loop over the eveID values and calculate the purity and efficiency for
113  // each
114  std::set<int>::iterator setitr = eveIDs.begin();
115  while (setitr != eveIDs.end()) {
116 
117  std::set<int> id;
118  id.insert(*setitr);
119  mf::LogInfo("CheckBackTracking")
120  << "eve ID: " << *setitr << " purity: " << bt_serv->HitCollectionPurity(clockData, id, hits)
121  << " efficiency: " << bt_serv->HitCollectionEfficiency(clockData, id, hits, hits, geo::k3D);
122 
123  setitr++;
124  }
125 
126  return;
127 
128  } // end analyze
129 
130 } // end namespace
131 
132 namespace cheat {
133 
134  DEFINE_ART_MODULE(CheckBackTracking)
135 
136 }
std::string fHitModuleLabel
label for module creating recob::Hit objects
Declaration of signal hit object.
CheckBackTracking(fhicl::ParameterSet const &pset)
3-dimensional objects, potentially hits, clusters, prongs, etc.
Definition: geo_types.h:135
std::string fG4ModuleLabel
label for module running G4 and making particles, etc
Definition of data types for geometry description.
object containing MC truth information necessary for making RawDigits and doing back tracking ...
do i e
TCEvent evt
Definition: DataStructs.cxx:8
void analyze(art::Event const &evt)