RecoCheckAna_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: RecoCheckAna
3 // Module Type: analyzer
4 // File: RecoCheckAna.h
5 //
6 // Generated at Fri Jul 15 09:54:26 2011 by Brian Rebel using artmod
7 // from art v0_07_04.
8 ////////////////////////////////////////////////////////////////////////
9 
10 #include <map>
11 #include <utility> // std::move()
12 
13 #include "TH1.h"
14 #include "TH2.h"
15 #include "TTree.h"
16 
22 #include "art_root_io/TFileService.h"
24 #include "canvas/Persistency/Common/FindManyP.h"
27 #include "fhiclcpp/ParameterSet.h"
29 
41 #include "nug4/ParticleNavigation/ParticleList.h"
43 
44 namespace cheat {
45  class RecoCheckAna;
46 }
47 
49 public:
50  explicit RecoCheckAna(fhicl::ParameterSet const& p);
51 
52 private:
53  void analyze(art::Event const& e) override;
54  void beginRun(art::Run const& r) override;
55 
56  void CheckReco(
57  detinfo::DetectorClocksData const& clockData,
58  int const& colID,
59  std::vector<art::Ptr<recob::Hit>> const& allhits,
60  std::vector<art::Ptr<recob::Hit>> const& colHits,
61  std::map<std::pair<int, int>, std::pair<double, double>>& g4RecoBaseIDToPurityEfficiency);
62  void CheckRecoClusters(art::Event const& evt,
63  std::string const& label,
64  art::Handle<std::vector<recob::Cluster>> const& clscol,
65  std::vector<art::Ptr<recob::Hit>> const& allhits);
66  void CheckRecoTracks(art::Event const& evt,
67  std::string const& label,
68  art::Handle<std::vector<recob::Track>> const& tcol,
69  std::vector<art::Ptr<recob::Hit>> const& allhits);
70  void CheckRecoShowers(art::Event const& evt,
71  std::string const& label,
72  art::Handle<std::vector<recob::Shower>> const& scol,
73  std::vector<art::Ptr<recob::Hit>> const& allhits);
74  void CheckRecoVertices(art::Event const& evt,
75  std::string const& label,
76  art::Handle<std::vector<recob::Vertex>> const& vtxcol,
77  std::vector<art::Ptr<recob::Hit>> const& allhits);
78  void CheckRecoEvents(art::Event const& evt,
79  std::string const& label,
80  art::Handle<std::vector<recob::Event>> const& evtcol,
81  std::vector<art::Ptr<recob::Hit>> const& allhits);
82  // method to fill the histograms and TTree
83  void FillResults(detinfo::DetectorClocksData const& clockData,
84  std::vector<art::Ptr<recob::Hit>> const& allhits);
85 
86  // helper method to the above for clusters, showers and tracks
87  void FlattenMap(
88  std::map<std::pair<int, int>, std::pair<double, double>> const& g4RecoBaseIDToPurityEfficiency,
89  std::map<int, std::vector<std::pair<int, std::pair<double, double>>>>&
90  g4IDToRecoBasePurityEfficiency,
91  TH1D* purity,
92  TH1D* efficiency,
93  TH1D* purityEfficiency,
94  TH2D* purityEfficiency2D);
95 
98 
99  std::string fHitModuleLabel; ///< label for module making the hits
100  std::string fClusterModuleLabel; ///< label for module making the clusters
101  std::string fShowerModuleLabel; ///< label for module making the showers
102  std::string fTrackModuleLabel; ///< label for module making the tracks
103  std::string fVertexModuleLabel; ///< label for module making the vertices
104  std::string fEventModuleLabel; ///< label for module making the events
105 
106  bool fCheckClusters; ///< should we check the reconstruction of clusters?
107  bool fCheckShowers; ///< should we check the reconstruction of showers?
108  bool fCheckTracks; ///< should we check the reconstruction of tracks?
109  bool fCheckVertices; ///< should we check the reconstruction of vertices?
110  bool fCheckEvents; ///< should we check the reconstruction of events?
111 
112  TH1D* fClusterPurity; ///< histogram of cluster purity
113  TH1D* fClusterEfficiency; ///< histogram of cluster efficiency
114  TH1D* fClusterPurityEfficiency; ///< histogram of cluster efficiency times purity
115  TH2D* fClusterPurityEfficiency2D; ///< scatter histogram of cluster purity and efficiency
116  TH1D* fShowerPurity; ///< histogram of shower purity
117  TH1D* fShowerEfficiency; ///< histogram of shower efficiency
118  TH1D* fShowerPurityEfficiency; ///< histogram of shower efficiency times purity
119  TH2D* fShowerPurityEfficiency2D; ///< scatter histogram of cluster purity and efficiency
120  TH1D* fTrackPurity; ///< histogram of track purity
121  TH1D* fTrackEfficiency; ///< histogram of track efficiency
122  TH1D* fTrackPurityEfficiency; ///< histogram of track efficiency times purity
123  TH2D* fTrackPurityEfficiency2D; ///< scatter histogram of cluster purity and efficiency
124  TH1D* fVertexPurity; ///< histogram of vertex purity
125  TH1D* fVertexEfficiency; ///< histogram of vertex efficiency
126  TH1D* fVertexPurityEfficiency; ///< histogram of vertex efficiency times purity
127  TH1D* fEventPurity; ///< histogram of event purity
128  TH1D* fEventEfficiency; ///< histogram of event efficiency
129  TH1D* fEventPurityEfficiency; ///< histogram of event efficiency times purity
130 
131  // The following maps have a pair of the G4 track id and RecoBase object
132  // id as the key and then the purity and efficiency (in that order) of the RecoBase object
133  // as the value
134  std::map<std::pair<int, int>, std::pair<double, double>> fG4ClusterIDToPurityEfficiency;
135  std::map<std::pair<int, int>, std::pair<double, double>> fG4ShowerIDToPurityEfficiency;
136  std::map<std::pair<int, int>, std::pair<double, double>> fG4TrackIDToPurityEfficiency;
137 
138  TTree* fTree; ///< TTree to save efficiencies
139  int frun; ///< run number
140  int fevent; ///< event number
141  int ftrackid; ///< geant track ID
142  int fpdg; ///< particle pdg code
143  double fpmom; ///< particle momentum
144  double fhiteff; ///< hitfinder efficiency for this particle
145  int fnclu; ///< number of clusters for this particle
146  std::vector<double> fclueff; ///< cluster efficiencies
147  std::vector<double> fclupur; ///< cluster purities
148  std::vector<int> fcluid; ///< cluster IDs
149  int fnshw; ///< number of showers for this particle
150  std::vector<double> fshweff; ///< shower efficiencies
151  std::vector<double> fshwpur; ///< shower purities
152  std::vector<int> fshwid; ///< shower IDs
153  int fntrk; ///< number of tracks for this particle
154  std::vector<double> ftrkeff; ///< track efficiencies
155  std::vector<double> ftrkpur; ///< track purities
156  std::vector<int> ftrkid; ///< track IDs
157 };
158 
159 //-------------------------------------------------------------------
161  : EDAnalyzer(p)
162  , fHitModuleLabel{p.get<std::string>("HitModuleLabel")}
163  , fClusterModuleLabel{p.get<std::string>("ClusterModuleLabel")}
164  , fShowerModuleLabel{p.get<std::string>("ShowerModuleLabel")}
165  , fTrackModuleLabel{p.get<std::string>("TrackModuleLabel")}
166  , fVertexModuleLabel{p.get<std::string>("VertexModuleLabel")}
167  , fEventModuleLabel{p.get<std::string>("EventModuleLabel")}
168  , fCheckClusters{p.get<bool>("CheckClusters")}
169  , fCheckShowers{p.get<bool>("CheckShowers")}
170  , fCheckTracks{p.get<bool>("CheckTracks")}
171  , fCheckVertices{p.get<bool>("CheckVertices")}
172  , fCheckEvents{p.get<bool>("CheckEvents")}
173 {}
174 
175 //-------------------------------------------------------------------
176 void
178 {
179  // check that this is MC, stop if it isn't
180  if (e.isRealData()) {
181  mf::LogWarning("RecoVetter") << "attempting to run MC truth check on "
182  << "real data, bail";
183  return;
184  }
185 
186  // get all hits in the event to figure out how many there are
188  e.getByLabel(fHitModuleLabel, hithdl);
189  std::vector<art::Ptr<recob::Hit>> allhits;
190  art::fill_ptr_vector(allhits, hithdl);
191 
192  // define variables to hold the reconstructed objects
198 
199  if (fCheckClusters) {
200  e.getByLabel(fClusterModuleLabel, clscol);
201  if (!clscol.failedToGet()) this->CheckRecoClusters(e, fClusterModuleLabel, clscol, allhits);
202  }
203  if (fCheckTracks) {
204  e.getByLabel(fTrackModuleLabel, trkcol);
205  if (!trkcol.failedToGet()) this->CheckRecoTracks(e, fTrackModuleLabel, trkcol, allhits);
206  }
207  if (fCheckShowers) {
208  e.getByLabel(fShowerModuleLabel, shwcol);
209  if (!shwcol.failedToGet()) this->CheckRecoShowers(e, fShowerModuleLabel, shwcol, allhits);
210  }
211  if (fCheckVertices) {
212  e.getByLabel(fVertexModuleLabel, vtxcol);
213  if (!vtxcol.failedToGet()) this->CheckRecoVertices(e, fVertexModuleLabel, vtxcol, allhits);
214  }
215  if (fCheckEvents) {
216  e.getByLabel(fEventModuleLabel, evtcol);
217  if (!evtcol.failedToGet()) this->CheckRecoEvents(e, fEventModuleLabel, evtcol, allhits);
218  }
219 
220  frun = e.run();
221  fevent = e.id().event();
222 
223  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
224  this->FillResults(clockData, allhits);
225 
226  return;
227 }
228 
229 //-------------------------------------------------------------------
230 void
232 {
234 
235  if (fCheckEvents) {
236  fEventPurity = tfs->make<TH1D>("eventPurity", ";Purity;Events", 100, 0., 1.1);
237  fEventEfficiency = tfs->make<TH1D>("eventEfficiency", ";Efficiency;Events", 100, 0., 1.1);
239  tfs->make<TH1D>("eventPurityEfficiency", ";purityEfficiency;Events", 110, 0., 1.1);
240  }
241  if (fCheckVertices) {
242  fVertexPurity = tfs->make<TH1D>("vertexPurity", ";Purity;Vertices", 100, 0., 1.1);
243  fVertexEfficiency = tfs->make<TH1D>("vertexEfficiency", ";Efficiency;Vertices", 100, 0., 1.1);
245  tfs->make<TH1D>("vertexPurityEfficiency", ";purityEfficiency;Vertex", 110, 0., 1.1);
246  }
247  if (fCheckTracks) {
248  fTrackPurity = tfs->make<TH1D>("trackPurity", ";Purity;Tracks", 100, 0., 1.1);
249  fTrackEfficiency = tfs->make<TH1D>("trackEfficiency", ";Efficiency;Tracks", 100, 0., 1.1);
251  tfs->make<TH1D>("trackPurityEfficiency", ";purityEfficiency;Tracks", 110, 0., 1.1);
253  tfs->make<TH2D>("trackPurityEfficiency2D", ";purity;efficiency", 110, 0., 1.1, 110, 0., 1.1);
254  }
255  if (fCheckShowers) {
256  fShowerPurity = tfs->make<TH1D>("showerPurity", ";Purity;Showers", 100, 0., 1.1);
257  fShowerEfficiency = tfs->make<TH1D>("showerEfficiency", ";Efficiency;Showers", 100, 0., 1.1);
259  tfs->make<TH1D>("showerPurityEfficiency", ";purityEfficiency;Showers", 110, 0., 1.1);
261  tfs->make<TH2D>("showerPurityEfficiency2D", ";purity;efficiency", 110, 0., 1.1, 110, 0., 1.1);
262  }
263  if (fCheckClusters) {
264  fClusterPurity = tfs->make<TH1D>("clusterPurity", ";Purity;Clusters", 110, 0., 1.1);
265  fClusterEfficiency = tfs->make<TH1D>("clusterEfficiency", ";Efficiency;Clusters", 110, 0., 1.1);
267  tfs->make<TH1D>("clusterPurityEfficiency", ";purityEfficiency;Clusters", 110, 0., 1.1);
268  fClusterPurityEfficiency2D = tfs->make<TH2D>(
269  "clusterPurityEfficiency2D", ";purity;efficiency", 110, 0., 1.1, 110, 0., 1.1);
270  }
271 
272  fTree = tfs->make<TTree>("cheatertree", "cheater tree");
273  fTree->Branch("run", &frun, "run/I");
274  fTree->Branch("event", &fevent, "event/I");
275  fTree->Branch("trackid", &ftrackid, "trackid/I");
276  fTree->Branch("pdg", &fpdg, "pdg/I");
277  fTree->Branch("pmom", &fpmom, "pmom/D");
278  fTree->Branch("hiteff", &fhiteff, "hiteff/D");
279  fTree->Branch("nclu", &fnclu, "nclu/I");
280  fTree->Branch("clueff", &fclueff);
281  fTree->Branch("clupur", &fclupur);
282  fTree->Branch("cluid", &fcluid);
283  fTree->Branch("nshw", &fnshw, "nshw/I");
284  fTree->Branch("shweff", &fshweff);
285  fTree->Branch("shwpur", &fshwpur);
286  fTree->Branch("shwid", &fshwid);
287  fTree->Branch("ntrk", &fntrk, "ntrk/I");
288  fTree->Branch("trkeff", &ftrkeff);
289  fTree->Branch("trkpur", &ftrkpur);
290  fTree->Branch("trkid", &ftrkid);
291 
292  return;
293 }
294 
295 //-------------------------------------------------------------------
296 // colID is the ID of the RecoBase object and colHits are the recob::Hits
297 // associated with it
298 void
300  detinfo::DetectorClocksData const& clockData,
301  int const& colID,
302  std::vector<art::Ptr<recob::Hit>> const& allhits,
303  std::vector<art::Ptr<recob::Hit>> const& colHits,
304  std::map<std::pair<int, int>, std::pair<double, double>>& g4RecoBaseIDToPurityEfficiency)
305 {
306 
307  // grab the set of track IDs for these hits
308  std::set<int> trackIDs = fBT->GetSetOfTrackIds(clockData, colHits);
309 
310  geo::View_t view = colHits[0]->View();
311 
312  std::set<int>::iterator itr = trackIDs.begin();
313  while (itr != trackIDs.end()) {
314 
315  std::set<int> id;
316  id.insert(*itr);
317 
318  // use the cheat::BackTrackerService to find purity and efficiency for these
319  // hits
320  double purity = fBT->HitCollectionPurity(clockData, id, colHits);
321  double efficiency = fBT->HitCollectionEfficiency(clockData, id, colHits, allhits, view);
322 
323  // make the purity and efficiency pair
324  std::pair<double, double> pe(purity, efficiency);
325 
326  // make the pair of the RecoBase object id to the pair of purity/efficiency
327  std::pair<int, int> g4reco(*itr, colID);
328 
329  // insert idpe into the map
330  g4RecoBaseIDToPurityEfficiency[g4reco] = pe;
331 
332  itr++;
333 
334  } // end loop over eveIDs
335 
336  return;
337 }
338 
339 //-------------------------------------------------------------------
340 void
342  std::string const& label,
343  art::Handle<std::vector<recob::Cluster>> const& clscol,
344  std::vector<art::Ptr<recob::Hit>> const& allhits)
345 {
346  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
347  art::FindManyP<recob::Hit> fmh(clscol, evt, label);
348 
349  for (size_t c = 0; c < clscol->size(); ++c) {
350 
351  // get the hits associated with this event
352  std::vector<art::Ptr<recob::Hit>> hits = fmh.at(c);
353 
354  this->CheckReco(clockData, clscol->at(c).ID(), allhits, hits, fG4ClusterIDToPurityEfficiency);
355 
356  } // end loop over clusters
357 
358  return;
359 }
360 
361 //-------------------------------------------------------------------
362 void
364  std::string const& label,
365  art::Handle<std::vector<recob::Track>> const& tcol,
366  std::vector<art::Ptr<recob::Hit>> const& allhits)
367 {
368  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
369  art::FindManyP<recob::Hit> fmh(tcol, evt, label);
370 
371  for (size_t p = 0; p < tcol->size(); ++p) {
372 
373  // get the hits associated with this event
374  std::vector<art::Ptr<recob::Hit>> hits = fmh.at(p);
375 
376  this->CheckReco(clockData, tcol->at(p).ID(), allhits, hits, fG4TrackIDToPurityEfficiency);
377 
378  } // end loop over tracks
379 
380  return;
381 }
382 
383 //-------------------------------------------------------------------
384 void
386  std::string const& label,
387  art::Handle<std::vector<recob::Shower>> const& scol,
388  std::vector<art::Ptr<recob::Hit>> const& allhits)
389 {
390  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
391  art::FindManyP<recob::Hit> fmh(scol, evt, label);
392 
393  for (size_t p = 0; p < scol->size(); ++p) {
394 
395  // get the hits associated with this event
396  std::vector<art::Ptr<recob::Hit>> hits = fmh.at(p);
397 
398  this->CheckReco(clockData, scol->at(p).ID(), allhits, hits, fG4ShowerIDToPurityEfficiency);
399 
400  } // end loop over events
401 
402  return;
403 }
404 
405 //-------------------------------------------------------------------
406 //a true vertex will either consist of primary particles originating from
407 //the interaction vertex, or a primary particle decaying to make daughters
408 void
410  std::string const& label,
411  art::Handle<std::vector<recob::Vertex>> const& vtxcol,
412  std::vector<art::Ptr<recob::Hit>> const& allhits)
413 {
414  const sim::ParticleList& plist = fPI->ParticleList();
415 
416  std::vector<std::set<int>> ids(1);
417  // loop over all primary particles and put their ids into the first set of the
418  // vector. add another set for each primary particle that also has daughters
419  // and put those daughters into the new set
420  // PartPair is a (track ID, particle pointer) pair
421  for (const auto& PartPair : plist) {
422  auto trackID = PartPair.first;
423  if (!plist.IsPrimary(trackID)) continue;
424  const simb::MCParticle& part = *(PartPair.second);
425  ids[0].insert(trackID);
426  if (part.NumberDaughters() > 0) {
427  std::set<int> dv;
428  for (int d = 0; d < part.NumberDaughters(); ++d)
429  dv.insert(part.Daughter(d));
430  ids.push_back(std::move(dv));
431  } // end if this primary particle has daughters
432  } // end loop over primaries
433 
434  art::FindManyP<recob::Hit> fmh(vtxcol, evt, label);
435 
436  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
437 
438  for (size_t v = 0; v < vtxcol->size(); ++v) {
439 
440  // get the hits associated with this event
441  std::vector<art::Ptr<recob::Hit>> hits = fmh.at(v);
442 
443  double maxPurity = -1.;
444  double maxEfficiency = -1.;
445 
446  for (size_t tv = 0; tv < ids.size(); ++tv) {
447 
448  // use the cheat::BackTrackerService to find purity and efficiency for
449  // these hits
450  double purity = fBT->HitCollectionPurity(clockData, ids[tv], hits);
451  double efficiency = fBT->HitCollectionEfficiency(clockData, ids[tv], hits, allhits, geo::k3D);
452 
453  if (purity > maxPurity) maxPurity = purity;
454  if (efficiency > maxEfficiency) maxEfficiency = efficiency;
455  }
456 
457  fVertexPurity->Fill(maxPurity);
458  fVertexEfficiency->Fill(maxEfficiency);
459  fVertexPurityEfficiency->Fill(maxPurity * maxEfficiency);
460 
461  } // end loop over vertices
462 
463  return;
464 }
465 
466 //-------------------------------------------------------------------
467 // in this method one should loop over the primary particles from a given
468 // MCTruth collection
469 /// \todo need to divy it up in the case where there is more than 1 true interaction in a spill
470 void
472  std::string const& label,
473  art::Handle<std::vector<recob::Event>> const& evtcol,
474  std::vector<art::Ptr<recob::Hit>> const& allhits)
475 {
476  const sim::ParticleList& plist = fPI->ParticleList();
477 
478  // loop over all primaries in the plist and grab them and their daughters to put into
479  // the set of track ids to pass on to the back tracker
480  std::set<int> ids;
481  for (const auto& PartPair : plist) {
482  auto trackID = PartPair.first;
483  if (!plist.IsPrimary(trackID)) continue;
484  const simb::MCParticle& part = *(PartPair.second);
485  ids.insert(trackID);
486  for (int d = 0; d < part.NumberDaughters(); ++d)
487  ids.insert(part.Daughter(d));
488  } // end loop over primaries
489 
490  art::FindManyP<recob::Hit> fmh(evtcol, evt, label);
491 
492  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
493  for (size_t ev = 0; ev < evtcol->size(); ++ev) {
494 
495  // get the hits associated with this event
496  std::vector<art::Ptr<recob::Hit>> hits = fmh.at(ev);
497 
498  // use the cheat::BackTrackerService to find purity and efficiency for these
499  // hits
500  double purity = fBT->HitCollectionPurity(clockData, ids, hits);
501  double efficiency = fBT->HitCollectionEfficiency(clockData, ids, hits, allhits, geo::k3D);
502 
503  fEventPurity->Fill(purity);
504  fEventEfficiency->Fill(efficiency);
505  fEventPurityEfficiency->Fill(purity * efficiency);
506 
507  } // end loop over events
508 
509  return;
510 }
511 
512 //-------------------------------------------------------------------
513 void
515  std::map<std::pair<int, int>, std::pair<double, double>> const& g4RecoBaseIDToPurityEfficiency,
516  std::map<int, std::vector<std::pair<int, std::pair<double, double>>>>&
517  g4IDToRecoBasePurityEfficiency,
518  TH1D* purity,
519  TH1D* efficiency,
520  TH1D* purityEfficiency,
521  TH2D* purityEfficiency2D)
522 {
523 
524  std::map<std::pair<int, int>, std::pair<double, double>>::const_iterator rbItr =
525  g4RecoBaseIDToPurityEfficiency.begin();
526 
527  // map of key cluster ID to pair of purity, efficiency
528  std::map<int, std::pair<double, double>> recoBIDToPurityEfficiency;
529  std::map<int, std::pair<double, double>>::iterator rbpeItr;
530 
531  while (rbItr != g4RecoBaseIDToPurityEfficiency.end()) {
532 
533  // trackID, cluster ID
534  std::pair<int, int> g4cl = rbItr->first;
535  // purity, efficiency
536  std::pair<double, double> pe = rbItr->second;
537 
538  // add the efficiency and purity values for clusters corresponding
539  // to the current g4 id to the map
540  // pair of cluster id, pair of purity, efficiency
541  std::pair<int, std::pair<double, double>> clpe(g4cl.second, pe);
542  // g4IDToRecoBasePurityEfficiency is a map with key of trackID of a vector of clusterIDs of pairs of purity and efficiency
543  g4IDToRecoBasePurityEfficiency[g4cl.first].push_back(clpe);
544 
545  // now find the maximum purity to determine the purity and efficiency
546  // for this RecoBase object
547  rbpeItr = recoBIDToPurityEfficiency.find(g4cl.second);
548  if (rbpeItr != recoBIDToPurityEfficiency.end()) {
549  std::pair<double, double> curpe = rbpeItr->second;
550  if (pe.first > curpe.first) recoBIDToPurityEfficiency[g4cl.second] = pe;
551  }
552  else
553  recoBIDToPurityEfficiency[g4cl.second] = pe;
554 
555  rbItr++;
556  }
557 
558  rbpeItr = recoBIDToPurityEfficiency.begin();
559 
560  // now fill the histograms,
561  while (rbpeItr != recoBIDToPurityEfficiency.end()) {
562  purity->Fill(rbpeItr->second.first);
563  efficiency->Fill(rbpeItr->second.second);
564  purityEfficiency->Fill(rbpeItr->second.first * rbpeItr->second.second);
565  purityEfficiency2D->Fill(rbpeItr->second.first, rbpeItr->second.second);
566  rbpeItr++;
567  }
568 
569  return;
570 }
571 
572 //-------------------------------------------------------------------
573 void
575  std::vector<art::Ptr<recob::Hit>> const& allhits)
576 {
577  // map the g4 track id to energy deposited in a hit
578  std::map<int, double> g4IDToHitEnergy;
579  for (size_t h = 0; h < allhits.size(); ++h) {
580  const std::vector<sim::TrackIDE> hitTrackIDs = fBT->HitToTrackIDEs(clockData, allhits[h]);
581  for (size_t e = 0; e < hitTrackIDs.size(); ++e) {
582  g4IDToHitEnergy[hitTrackIDs[e].trackID] += hitTrackIDs[e].energy;
583  }
584  } // end loop over hits to fill map
585 
586  // flatten the G4RecoBaseIDToPurityEfficiency maps to have just the g4ID as
587  // the key and the rest of the information in vector form
588  std::map<int, std::vector<std::pair<int, std::pair<double, double>>>>
589  g4IDToClusterPurityEfficiency;
590  std::map<int, std::vector<std::pair<int, std::pair<double, double>>>>
591  g4IDToShowerPurityEfficiency;
592  std::map<int, std::vector<std::pair<int, std::pair<double, double>>>> g4IDToTrackPurityEfficiency;
593  std::map<int, std::vector<std::pair<int, std::pair<double, double>>>>::iterator g4peItr;
594 
595  if (fCheckClusters)
597  g4IDToClusterPurityEfficiency,
602  if (fCheckShowers)
604  g4IDToShowerPurityEfficiency,
609  if (fCheckTracks)
611  g4IDToTrackPurityEfficiency,
612  fTrackPurity,
616 
617  // fill the tree vectors
618  // get all the eveIDs from this event
619  std::set<int> trackIDs = fBT->GetSetOfTrackIds();
620  std::set<int>::const_iterator trackItr = trackIDs.begin();
621 
622  // loop over them
623  while (trackItr != trackIDs.end()) {
624 
625  const simb::MCParticle* part = fPI->TrackIdToParticle_P(*trackItr);
626 
627  ftrackid = std::abs(*trackItr);
628  fpdg = part->PdgCode();
629  fpmom = part->P();
630 
631  // figure out how much of the energy deposited from this particle is stored in hits
632  std::vector<const sim::IDE*> ides = fBT->TrackIdToSimIDEs_Ps(*trackItr);
633  double totalDep = 0.;
634  for (size_t i = 0; i < ides.size(); ++i)
635  totalDep += ides[i]->energy;
636 
637  if (totalDep > 0.) fhiteff = g4IDToHitEnergy[*trackItr] / totalDep;
638 
639  std::vector<std::pair<int, std::pair<double, double>>> clVec;
640  std::vector<std::pair<int, std::pair<double, double>>> shVec;
641  std::vector<std::pair<int, std::pair<double, double>>> trVec;
642 
643  if (g4IDToClusterPurityEfficiency.find(*trackItr) != g4IDToClusterPurityEfficiency.end())
644  clVec = g4IDToClusterPurityEfficiency.find(*trackItr)->second;
645 
646  if (g4IDToShowerPurityEfficiency.find(*trackItr) != g4IDToShowerPurityEfficiency.end())
647  shVec = g4IDToShowerPurityEfficiency.find(*trackItr)->second;
648 
649  if (g4IDToTrackPurityEfficiency.find(*trackItr) != g4IDToTrackPurityEfficiency.end())
650  trVec = g4IDToTrackPurityEfficiency.find(*trackItr)->second;
651 
652  fnclu = clVec.size();
653  fnshw = shVec.size();
654  fntrk = trVec.size();
655 
656  for (size_t c = 0; c < clVec.size(); ++c) {
657  fcluid.push_back(clVec[c].first);
658  fclupur.push_back(clVec[c].second.first);
659  fclueff.push_back(clVec[c].second.second);
660  }
661 
662  for (size_t s = 0; s < shVec.size(); ++s) {
663  fshwid.push_back(shVec[s].first);
664  fshwpur.push_back(shVec[s].second.first);
665  fshweff.push_back(shVec[s].second.second);
666  }
667 
668  for (size_t t = 0; t < trVec.size(); ++t) {
669  ftrkid.push_back(trVec[t].first);
670  ftrkpur.push_back(trVec[t].second.first);
671  ftrkeff.push_back(trVec[t].second.second);
672  }
673 
674  fTree->Fill();
675 
676  trackItr++;
677  }
678 
679  // clean up for the next event
680 
681  // clear the maps of G4 track id to efficiency and purity for
682  // various RecoBase objects
686 
687  // clear the vectors hooked up to the tree
688  fclueff.clear();
689  fclupur.clear();
690  fcluid.clear();
691  ftrkeff.clear();
692  ftrkpur.clear();
693  ftrkid.clear();
694  fshweff.clear();
695  fshwpur.clear();
696  fshwid.clear();
697 
698  return;
699 }
700 
art::ServiceHandle< cheat::BackTrackerService const > fBT
the back tracker service
intermediate_table::iterator iterator
int fpdg
particle pdg code
int fnshw
number of showers for this particle
int PdgCode() const
Definition: MCParticle.h:212
void analyze(art::Event const &e) override
TH1D * fTrackPurityEfficiency
histogram of track efficiency times purity
bool fCheckVertices
should we check the reconstruction of vertices?
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
std::string string
Definition: nybbler.cc:12
const simb::MCParticle * TrackIdToParticle_P(int id) const
double fhiteff
hitfinder efficiency for this particle
TH1D * fClusterPurityEfficiency
histogram of cluster efficiency times purity
int fnclu
number of clusters for this particle
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
void CheckReco(detinfo::DetectorClocksData const &clockData, int const &colID, std::vector< art::Ptr< recob::Hit >> const &allhits, std::vector< art::Ptr< recob::Hit >> const &colHits, std::map< std::pair< int, int >, std::pair< double, double >> &g4RecoBaseIDToPurityEfficiency)
void CheckRecoEvents(art::Event const &evt, std::string const &label, art::Handle< std::vector< recob::Event >> const &evtcol, std::vector< art::Ptr< recob::Hit >> const &allhits)
struct vector vector
art::ServiceHandle< cheat::ParticleInventoryService const > fPI
the back tracker service
int fntrk
number of tracks for this particle
std::vector< const sim::IDE * > TrackIdToSimIDEs_Ps(int const &id) const
RecoCheckAna(fhicl::ParameterSet const &p)
intermediate_table::const_iterator const_iterator
TH1D * fEventPurity
histogram of event purity
bool fCheckEvents
should we check the reconstruction of events?
std::map< std::pair< int, int >, std::pair< double, double > > fG4ClusterIDToPurityEfficiency
TH2D * fTrackPurityEfficiency2D
scatter histogram of cluster purity and efficiency
void beginRun(art::Run const &r) override
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
Particle class.
TH1D * fEventEfficiency
histogram of event efficiency
int NumberDaughters() const
Definition: MCParticle.h:217
Definition: Run.h:17
TH1D * fVertexPurity
histogram of vertex purity
int Daughter(const int i) const
Definition: MCParticle.cxx:112
TH1D * fEventPurityEfficiency
histogram of event efficiency times purity
3-dimensional objects, potentially hits, clusters, prongs, etc.
Definition: geo_types.h:135
TH1D * fVertexPurityEfficiency
histogram of vertex efficiency times purity
bool isRealData() const
T abs(T value)
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
void CheckRecoTracks(art::Event const &evt, std::string const &label, art::Handle< std::vector< recob::Track >> const &tcol, std::vector< art::Ptr< recob::Hit >> const &allhits)
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
std::set< int > GetSetOfTrackIds() const
std::vector< double > fclupur
cluster purities
std::vector< double > fshweff
shower efficiencies
double HitCollectionPurity(detinfo::DetectorClocksData const &clockData, std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit >> const &hits) const
def move(depos, offset)
Definition: depos.py:107
bool fCheckClusters
should we check the reconstruction of clusters?
double P(const int i=0) const
Definition: MCParticle.h:234
T get(std::string const &key) const
Definition: ParameterSet.h:271
std::vector< double > fshwpur
shower purities
TTree * fTree
TTree to save efficiencies.
std::vector< int > fshwid
shower IDs
TH1D * fVertexEfficiency
histogram of vertex efficiency
std::vector< int > ftrkid
track IDs
std::vector< double > ftrkeff
track efficiencies
p
Definition: test.py:223
bool fCheckTracks
should we check the reconstruction of tracks?
std::vector< double > fclueff
cluster efficiencies
std::string fTrackModuleLabel
label for module making the tracks
RunNumber_t run() const
Definition: DataViewImpl.cc:71
double fpmom
particle momentum
void FlattenMap(std::map< std::pair< int, int >, std::pair< double, double >> const &g4RecoBaseIDToPurityEfficiency, std::map< int, std::vector< std::pair< int, std::pair< double, double >>>> &g4IDToRecoBasePurityEfficiency, TH1D *purity, TH1D *efficiency, TH1D *purityEfficiency, TH2D *purityEfficiency2D)
std::vector< int > fcluid
cluster IDs
std::vector< double > ftrkpur
track purities
Definition of data types for geometry description.
bool fCheckShowers
should we check the reconstruction of showers?
const sim::ParticleList & ParticleList() const
std::map< std::pair< int, int >, std::pair< double, double > > fG4TrackIDToPurityEfficiency
void CheckRecoShowers(art::Event const &evt, std::string const &label, art::Handle< std::vector< recob::Shower >> const &scol, std::vector< art::Ptr< recob::Hit >> const &allhits)
Declaration of signal hit object.
code to link reconstructed objects back to the MC truth information
Definition: BackTracker.cc:22
int ftrackid
geant track ID
Contains all timing reference information for the detector.
TH1D * fShowerPurityEfficiency
histogram of shower efficiency times purity
TH1D * fClusterPurity
histogram of cluster purity
std::map< std::pair< int, int >, std::pair< double, double > > fG4ShowerIDToPurityEfficiency
void FillResults(detinfo::DetectorClocksData const &clockData, std::vector< art::Ptr< recob::Hit >> const &allhits)
void CheckRecoVertices(art::Event const &evt, std::string const &label, art::Handle< std::vector< recob::Vertex >> const &vtxcol, std::vector< art::Ptr< recob::Hit >> const &allhits)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Provides recob::Track data product.
std::string fClusterModuleLabel
label for module making the clusters
EventNumber_t event() const
Definition: EventID.h:116
TH1D * fClusterEfficiency
histogram of cluster efficiency
TH1D * fShowerPurity
histogram of shower purity
void CheckRecoClusters(art::Event const &evt, std::string const &label, art::Handle< std::vector< recob::Cluster >> const &clscol, std::vector< art::Ptr< recob::Hit >> const &allhits)
std::string fShowerModuleLabel
label for module making the showers
TH1D * fShowerEfficiency
histogram of shower efficiency
std::string fEventModuleLabel
label for module making the events
TCEvent evt
Definition: DataStructs.cxx:7
TH1D * fTrackPurity
histogram of track purity
TH2D * fClusterPurityEfficiency2D
scatter histogram of cluster purity and efficiency
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
std::string fVertexModuleLabel
label for module making the vertices
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:85
if(!yymsg) yymsg
static QCString * s
Definition: config.cpp:1042
TH1D * fTrackEfficiency
histogram of track efficiency
EventID id() const
Definition: Event.cc:34
bool failedToGet() const
Definition: Handle.h:198
TH2D * fShowerPurityEfficiency2D
scatter histogram of cluster purity and efficiency
std::string fHitModuleLabel
label for module making the hits