LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
RecoCheckAna_module.cc
Go to the documentation of this file.
1 // 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.
9 
10 #include <map>
11 #include <set>
12 #include <utility> // std::move(), std::pair
13 #include <vector>
14 
15 #include "TH1.h"
16 #include "TH2.h"
17 #include "TTree.h"
18 
24 #include "art_root_io/TFileService.h"
29 #include "fhiclcpp/ParameterSet.h"
31 
45 
46 namespace cheat {
47  class RecoCheckAna;
48 }
49 
51 public:
52  explicit RecoCheckAna(fhicl::ParameterSet const& p);
53 
54 private:
55  void analyze(art::Event const& e) override;
56  void beginRun(art::Run const& r) override;
57 
58  void CheckReco(
59  detinfo::DetectorClocksData const& clockData,
60  int const& colID,
61  std::vector<art::Ptr<recob::Hit>> const& allhits,
62  std::vector<art::Ptr<recob::Hit>> const& colHits,
63  std::map<std::pair<int, int>, std::pair<double, double>>& g4RecoBaseIDToPurityEfficiency);
64  void CheckRecoClusters(art::Event const& evt,
65  std::string const& label,
66  art::Handle<std::vector<recob::Cluster>> const& clscol,
67  std::vector<art::Ptr<recob::Hit>> const& allhits);
68  void CheckRecoTracks(art::Event const& evt,
69  std::string const& label,
70  art::Handle<std::vector<recob::Track>> const& tcol,
71  std::vector<art::Ptr<recob::Hit>> const& allhits);
72  void CheckRecoShowers(art::Event const& evt,
73  std::string const& label,
74  art::Handle<std::vector<recob::Shower>> const& scol,
75  std::vector<art::Ptr<recob::Hit>> const& allhits);
76  void CheckRecoVertices(art::Event const& evt,
77  std::string const& label,
78  art::Handle<std::vector<recob::Vertex>> const& vtxcol,
79  std::vector<art::Ptr<recob::Hit>> const& allhits);
80  void CheckRecoEvents(art::Event const& evt,
81  std::string const& label,
82  art::Handle<std::vector<recob::Event>> const& evtcol,
83  std::vector<art::Ptr<recob::Hit>> const& allhits);
84  // method to fill the histograms and TTree
85  void FillResults(detinfo::DetectorClocksData const& clockData,
86  std::vector<art::Ptr<recob::Hit>> const& allhits);
87 
88  // helper method to the above for clusters, showers and tracks
89  void FlattenMap(
90  std::map<std::pair<int, int>, std::pair<double, double>> const& g4RecoBaseIDToPurityEfficiency,
91  std::map<int, std::vector<std::pair<int, std::pair<double, double>>>>&
92  g4IDToRecoBasePurityEfficiency,
93  TH1D* purity,
94  TH1D* efficiency,
95  TH1D* purityEfficiency,
96  TH2D* purityEfficiency2D);
97 
100 
101  std::string fHitModuleLabel;
102  std::string fClusterModuleLabel;
103  std::string fShowerModuleLabel;
104  std::string fTrackModuleLabel;
105  std::string fVertexModuleLabel;
106  std::string fEventModuleLabel;
107 
113 
122  TH1D* fTrackPurity;
129  TH1D* fEventPurity;
132 
133  // The following maps have a pair of the G4 track id and RecoBase object
134  // id as the key and then the purity and efficiency (in that order) of the RecoBase object
135  // as the value
136  std::map<std::pair<int, int>, std::pair<double, double>> fG4ClusterIDToPurityEfficiency;
137  std::map<std::pair<int, int>, std::pair<double, double>> fG4ShowerIDToPurityEfficiency;
138  std::map<std::pair<int, int>, std::pair<double, double>> fG4TrackIDToPurityEfficiency;
139 
140  TTree* fTree;
141  int frun;
142  int fevent;
143  int ftrackid;
144  int fpdg;
145  double fpmom;
146  double fhiteff;
147  int fnclu;
148  std::vector<double> fclueff;
149  std::vector<double> fclupur;
150  std::vector<int> fcluid;
151  int fnshw;
152  std::vector<double> fshweff;
153  std::vector<double> fshwpur;
154  std::vector<int> fshwid;
155  int fntrk;
156  std::vector<double> ftrkeff;
157  std::vector<double> ftrkpur;
158  std::vector<int> ftrkid;
159 };
160 
161 //-------------------------------------------------------------------
163  : EDAnalyzer(p)
164  , fHitModuleLabel{p.get<std::string>("HitModuleLabel")}
165  , fClusterModuleLabel{p.get<std::string>("ClusterModuleLabel")}
166  , fShowerModuleLabel{p.get<std::string>("ShowerModuleLabel")}
167  , fTrackModuleLabel{p.get<std::string>("TrackModuleLabel")}
168  , fVertexModuleLabel{p.get<std::string>("VertexModuleLabel")}
169  , fEventModuleLabel{p.get<std::string>("EventModuleLabel")}
170  , fCheckClusters{p.get<bool>("CheckClusters")}
171  , fCheckShowers{p.get<bool>("CheckShowers")}
172  , fCheckTracks{p.get<bool>("CheckTracks")}
173  , fCheckVertices{p.get<bool>("CheckVertices")}
174  , fCheckEvents{p.get<bool>("CheckEvents")}
175 {}
176 
177 //-------------------------------------------------------------------
179 {
180  // check that this is MC, stop if it isn't
181  if (e.isRealData()) {
182  mf::LogWarning("RecoVetter") << "attempting to run MC truth check on "
183  << "real data, bail";
184  return;
185  }
186 
187  // get all hits in the event to figure out how many there are
189  e.getByLabel(fHitModuleLabel, hithdl);
190  std::vector<art::Ptr<recob::Hit>> allhits;
191  art::fill_ptr_vector(allhits, hithdl);
192 
193  // define variables to hold the reconstructed objects
199 
200  if (fCheckClusters) {
201  e.getByLabel(fClusterModuleLabel, clscol);
202  if (!clscol.failedToGet()) this->CheckRecoClusters(e, fClusterModuleLabel, clscol, allhits);
203  }
204  if (fCheckTracks) {
205  e.getByLabel(fTrackModuleLabel, trkcol);
206  if (!trkcol.failedToGet()) this->CheckRecoTracks(e, fTrackModuleLabel, trkcol, allhits);
207  }
208  if (fCheckShowers) {
209  e.getByLabel(fShowerModuleLabel, shwcol);
210  if (!shwcol.failedToGet()) this->CheckRecoShowers(e, fShowerModuleLabel, shwcol, allhits);
211  }
212  if (fCheckVertices) {
213  e.getByLabel(fVertexModuleLabel, vtxcol);
214  if (!vtxcol.failedToGet()) this->CheckRecoVertices(e, fVertexModuleLabel, vtxcol, allhits);
215  }
216  if (fCheckEvents) {
217  e.getByLabel(fEventModuleLabel, evtcol);
218  if (!evtcol.failedToGet()) this->CheckRecoEvents(e, fEventModuleLabel, evtcol, allhits);
219  }
220 
221  frun = e.run();
222  fevent = e.id().event();
223 
224  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
225  this->FillResults(clockData, allhits);
226 
227  return;
228 }
229 
230 //-------------------------------------------------------------------
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
299  detinfo::DetectorClocksData const& clockData,
300  int const& colID,
301  std::vector<art::Ptr<recob::Hit>> const& allhits,
302  std::vector<art::Ptr<recob::Hit>> const& colHits,
303  std::map<std::pair<int, int>, std::pair<double, double>>& g4RecoBaseIDToPurityEfficiency)
304 {
305 
306  // grab the set of track IDs for these hits
307  std::set<int> trackIDs = fBT->GetSetOfTrackIds(clockData, colHits);
308 
309  geo::View_t view = colHits[0]->View();
310 
311  std::set<int>::iterator itr = trackIDs.begin();
312  while (itr != trackIDs.end()) {
313 
314  std::set<int> id;
315  id.insert(*itr);
316 
317  // use the cheat::BackTrackerService to find purity and efficiency for these
318  // hits
319  double purity = fBT->HitCollectionPurity(clockData, id, colHits);
320  double efficiency = fBT->HitCollectionEfficiency(clockData, id, colHits, allhits, view);
321 
322  // make the purity and efficiency pair
323  std::pair<double, double> pe(purity, efficiency);
324 
325  // make the pair of the RecoBase object id to the pair of purity/efficiency
326  std::pair<int, int> g4reco(*itr, colID);
327 
328  // insert idpe into the map
329  g4RecoBaseIDToPurityEfficiency[g4reco] = pe;
330 
331  itr++;
332 
333  } // end loop over eveIDs
334 
335  return;
336 }
337 
338 //-------------------------------------------------------------------
340  std::string const& label,
341  art::Handle<std::vector<recob::Cluster>> const& clscol,
342  std::vector<art::Ptr<recob::Hit>> const& allhits)
343 {
344  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
345  art::FindManyP<recob::Hit> fmh(clscol, evt, label);
346 
347  for (size_t c = 0; c < clscol->size(); ++c) {
348 
349  // get the hits associated with this event
350  std::vector<art::Ptr<recob::Hit>> hits = fmh.at(c);
351 
352  this->CheckReco(clockData, clscol->at(c).ID(), allhits, hits, fG4ClusterIDToPurityEfficiency);
353 
354  } // end loop over clusters
355 
356  return;
357 }
358 
359 //-------------------------------------------------------------------
361  std::string const& label,
362  art::Handle<std::vector<recob::Track>> const& tcol,
363  std::vector<art::Ptr<recob::Hit>> const& allhits)
364 {
365  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
366  art::FindManyP<recob::Hit> fmh(tcol, evt, label);
367 
368  for (size_t p = 0; p < tcol->size(); ++p) {
369 
370  // get the hits associated with this event
371  std::vector<art::Ptr<recob::Hit>> hits = fmh.at(p);
372 
373  this->CheckReco(clockData, tcol->at(p).ID(), allhits, hits, fG4TrackIDToPurityEfficiency);
374 
375  } // end loop over tracks
376 
377  return;
378 }
379 
380 //-------------------------------------------------------------------
382  std::string const& label,
383  art::Handle<std::vector<recob::Shower>> const& scol,
384  std::vector<art::Ptr<recob::Hit>> const& allhits)
385 {
386  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
387  art::FindManyP<recob::Hit> fmh(scol, evt, label);
388 
389  for (size_t p = 0; p < scol->size(); ++p) {
390 
391  // get the hits associated with this event
392  std::vector<art::Ptr<recob::Hit>> hits = fmh.at(p);
393 
394  this->CheckReco(clockData, scol->at(p).ID(), allhits, hits, fG4ShowerIDToPurityEfficiency);
395 
396  } // end loop over events
397 
398  return;
399 }
400 
401 //-------------------------------------------------------------------
402 //a true vertex will either consist of primary particles originating from
403 //the interaction vertex, or a primary particle decaying to make daughters
405  std::string const& label,
406  art::Handle<std::vector<recob::Vertex>> const& vtxcol,
407  std::vector<art::Ptr<recob::Hit>> const& allhits)
408 {
409  const sim::ParticleList& plist = fPI->ParticleList();
410 
411  std::vector<std::set<int>> ids(1);
412  // loop over all primary particles and put their ids into the first set of the
413  // vector. add another set for each primary particle that also has daughters
414  // and put those daughters into the new set
415  // PartPair is a (track ID, particle pointer) pair
416  for (const auto& PartPair : plist) {
417  auto trackID = PartPair.first;
418  if (!plist.IsPrimary(trackID)) continue;
419  const simb::MCParticle& part = *(PartPair.second);
420  ids[0].insert(trackID);
421  if (part.NumberDaughters() > 0) {
422  std::set<int> dv;
423  for (int d = 0; d < part.NumberDaughters(); ++d)
424  dv.insert(part.Daughter(d));
425  ids.push_back(std::move(dv));
426  } // end if this primary particle has daughters
427  } // end loop over primaries
428 
429  art::FindManyP<recob::Hit> fmh(vtxcol, evt, label);
430 
431  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
432 
433  for (size_t v = 0; v < vtxcol->size(); ++v) {
434 
435  // get the hits associated with this event
436  std::vector<art::Ptr<recob::Hit>> hits = fmh.at(v);
437 
438  double maxPurity = -1.;
439  double maxEfficiency = -1.;
440 
441  for (size_t tv = 0; tv < ids.size(); ++tv) {
442 
443  // use the cheat::BackTrackerService to find purity and efficiency for
444  // these hits
445  double purity = fBT->HitCollectionPurity(clockData, ids[tv], hits);
446  double efficiency = fBT->HitCollectionEfficiency(clockData, ids[tv], hits, allhits, geo::k3D);
447 
448  if (purity > maxPurity) maxPurity = purity;
449  if (efficiency > maxEfficiency) maxEfficiency = efficiency;
450  }
451 
452  fVertexPurity->Fill(maxPurity);
453  fVertexEfficiency->Fill(maxEfficiency);
454  fVertexPurityEfficiency->Fill(maxPurity * maxEfficiency);
455 
456  } // end loop over vertices
457 
458  return;
459 }
460 
461 //-------------------------------------------------------------------
462 // in this method one should loop over the primary particles from a given
463 // MCTruth collection
466  std::string const& label,
467  art::Handle<std::vector<recob::Event>> const& evtcol,
468  std::vector<art::Ptr<recob::Hit>> const& allhits)
469 {
470  const sim::ParticleList& plist = fPI->ParticleList();
471 
472  // loop over all primaries in the plist and grab them and their daughters to put into
473  // the set of track ids to pass on to the back tracker
474  std::set<int> ids;
475  for (const auto& PartPair : plist) {
476  auto trackID = PartPair.first;
477  if (!plist.IsPrimary(trackID)) continue;
478  const simb::MCParticle& part = *(PartPair.second);
479  ids.insert(trackID);
480  for (int d = 0; d < part.NumberDaughters(); ++d)
481  ids.insert(part.Daughter(d));
482  } // end loop over primaries
483 
484  art::FindManyP<recob::Hit> fmh(evtcol, evt, label);
485 
486  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
487  for (size_t ev = 0; ev < evtcol->size(); ++ev) {
488 
489  // get the hits associated with this event
490  std::vector<art::Ptr<recob::Hit>> hits = fmh.at(ev);
491 
492  // use the cheat::BackTrackerService to find purity and efficiency for these
493  // hits
494  double purity = fBT->HitCollectionPurity(clockData, ids, hits);
495  double efficiency = fBT->HitCollectionEfficiency(clockData, ids, hits, allhits, geo::k3D);
496 
497  fEventPurity->Fill(purity);
498  fEventEfficiency->Fill(efficiency);
499  fEventPurityEfficiency->Fill(purity * efficiency);
500 
501  } // end loop over events
502 
503  return;
504 }
505 
506 //-------------------------------------------------------------------
508  std::map<std::pair<int, int>, std::pair<double, double>> const& g4RecoBaseIDToPurityEfficiency,
509  std::map<int, std::vector<std::pair<int, std::pair<double, double>>>>&
510  g4IDToRecoBasePurityEfficiency,
511  TH1D* purity,
512  TH1D* efficiency,
513  TH1D* purityEfficiency,
514  TH2D* purityEfficiency2D)
515 {
516 
517  std::map<std::pair<int, int>, std::pair<double, double>>::const_iterator rbItr =
518  g4RecoBaseIDToPurityEfficiency.begin();
519 
520  // map of key cluster ID to pair of purity, efficiency
521  std::map<int, std::pair<double, double>> recoBIDToPurityEfficiency;
522  std::map<int, std::pair<double, double>>::iterator rbpeItr;
523 
524  while (rbItr != g4RecoBaseIDToPurityEfficiency.end()) {
525 
526  // trackID, cluster ID
527  std::pair<int, int> g4cl = rbItr->first;
528  // purity, efficiency
529  std::pair<double, double> pe = rbItr->second;
530 
531  // add the efficiency and purity values for clusters corresponding
532  // to the current g4 id to the map
533  // pair of cluster id, pair of purity, efficiency
534  std::pair<int, std::pair<double, double>> clpe(g4cl.second, pe);
535  // g4IDToRecoBasePurityEfficiency is a map with key of trackID of a vector of clusterIDs of pairs of purity and efficiency
536  g4IDToRecoBasePurityEfficiency[g4cl.first].push_back(clpe);
537 
538  // now find the maximum purity to determine the purity and efficiency
539  // for this RecoBase object
540  rbpeItr = recoBIDToPurityEfficiency.find(g4cl.second);
541  if (rbpeItr != recoBIDToPurityEfficiency.end()) {
542  std::pair<double, double> curpe = rbpeItr->second;
543  if (pe.first > curpe.first) recoBIDToPurityEfficiency[g4cl.second] = pe;
544  }
545  else
546  recoBIDToPurityEfficiency[g4cl.second] = pe;
547 
548  rbItr++;
549  }
550 
551  rbpeItr = recoBIDToPurityEfficiency.begin();
552 
553  // now fill the histograms,
554  while (rbpeItr != recoBIDToPurityEfficiency.end()) {
555  purity->Fill(rbpeItr->second.first);
556  efficiency->Fill(rbpeItr->second.second);
557  purityEfficiency->Fill(rbpeItr->second.first * rbpeItr->second.second);
558  purityEfficiency2D->Fill(rbpeItr->second.first, rbpeItr->second.second);
559  rbpeItr++;
560  }
561 
562  return;
563 }
564 
565 //-------------------------------------------------------------------
567  std::vector<art::Ptr<recob::Hit>> const& allhits)
568 {
569  // map the g4 track id to energy deposited in a hit
570  std::map<int, double> g4IDToHitEnergy;
571  for (size_t h = 0; h < allhits.size(); ++h) {
572  const std::vector<sim::TrackIDE> hitTrackIDs = fBT->HitToTrackIDEs(clockData, allhits[h]);
573  for (size_t e = 0; e < hitTrackIDs.size(); ++e) {
574  g4IDToHitEnergy[hitTrackIDs[e].trackID] += hitTrackIDs[e].energy;
575  }
576  } // end loop over hits to fill map
577 
578  // flatten the G4RecoBaseIDToPurityEfficiency maps to have just the g4ID as
579  // the key and the rest of the information in vector form
580  std::map<int, std::vector<std::pair<int, std::pair<double, double>>>>
581  g4IDToClusterPurityEfficiency;
582  std::map<int, std::vector<std::pair<int, std::pair<double, double>>>>
583  g4IDToShowerPurityEfficiency;
584  std::map<int, std::vector<std::pair<int, std::pair<double, double>>>> g4IDToTrackPurityEfficiency;
585  std::map<int, std::vector<std::pair<int, std::pair<double, double>>>>::iterator g4peItr;
586 
587  if (fCheckClusters)
589  g4IDToClusterPurityEfficiency,
594  if (fCheckShowers)
596  g4IDToShowerPurityEfficiency,
601  if (fCheckTracks)
603  g4IDToTrackPurityEfficiency,
604  fTrackPurity,
608 
609  // fill the tree vectors
610  // get all the eveIDs from this event
611  std::set<int> trackIDs = fBT->GetSetOfTrackIds();
612  std::set<int>::const_iterator trackItr = trackIDs.begin();
613 
614  // loop over them
615  while (trackItr != trackIDs.end()) {
616 
617  const simb::MCParticle* part = fPI->TrackIdToParticle_P(*trackItr);
618 
619  ftrackid = std::abs(*trackItr);
620  fpdg = part->PdgCode();
621  fpmom = part->P();
622 
623  // figure out how much of the energy deposited from this particle is stored in hits
624  std::vector<const sim::IDE*> ides = fBT->TrackIdToSimIDEs_Ps(*trackItr);
625  double totalDep = 0.;
626  for (size_t i = 0; i < ides.size(); ++i)
627  totalDep += ides[i]->energy;
628 
629  if (totalDep > 0.) fhiteff = g4IDToHitEnergy[*trackItr] / totalDep;
630 
631  std::vector<std::pair<int, std::pair<double, double>>> clVec;
632  std::vector<std::pair<int, std::pair<double, double>>> shVec;
633  std::vector<std::pair<int, std::pair<double, double>>> trVec;
634 
635  if (g4IDToClusterPurityEfficiency.find(*trackItr) != g4IDToClusterPurityEfficiency.end())
636  clVec = g4IDToClusterPurityEfficiency.find(*trackItr)->second;
637 
638  if (g4IDToShowerPurityEfficiency.find(*trackItr) != g4IDToShowerPurityEfficiency.end())
639  shVec = g4IDToShowerPurityEfficiency.find(*trackItr)->second;
640 
641  if (g4IDToTrackPurityEfficiency.find(*trackItr) != g4IDToTrackPurityEfficiency.end())
642  trVec = g4IDToTrackPurityEfficiency.find(*trackItr)->second;
643 
644  fnclu = clVec.size();
645  fnshw = shVec.size();
646  fntrk = trVec.size();
647 
648  for (size_t c = 0; c < clVec.size(); ++c) {
649  fcluid.push_back(clVec[c].first);
650  fclupur.push_back(clVec[c].second.first);
651  fclueff.push_back(clVec[c].second.second);
652  }
653 
654  for (size_t s = 0; s < shVec.size(); ++s) {
655  fshwid.push_back(shVec[s].first);
656  fshwpur.push_back(shVec[s].second.first);
657  fshweff.push_back(shVec[s].second.second);
658  }
659 
660  for (size_t t = 0; t < trVec.size(); ++t) {
661  ftrkid.push_back(trVec[t].first);
662  ftrkpur.push_back(trVec[t].second.first);
663  ftrkeff.push_back(trVec[t].second.second);
664  }
665 
666  fTree->Fill();
667 
668  trackItr++;
669  }
670 
671  // clean up for the next event
672 
673  // clear the maps of G4 track id to efficiency and purity for
674  // various RecoBase objects
678 
679  // clear the vectors hooked up to the tree
680  fclueff.clear();
681  fclupur.clear();
682  fcluid.clear();
683  ftrkeff.clear();
684  ftrkpur.clear();
685  ftrkid.clear();
686  fshweff.clear();
687  fshwpur.clear();
688  fshwid.clear();
689 
690  return;
691 }
692 
art::ServiceHandle< cheat::BackTrackerService const > fBT
the back tracker service
TRandom r
Definition: spectrum.C:23
intermediate_table::iterator iterator
int fpdg
particle pdg code
int fnshw
number of showers for this particle
int PdgCode() const
Definition: MCParticle.h:213
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.
const simb::MCParticle * TrackIdToParticle_P(int id) const
double fhiteff
hitfinder efficiency for this particle
TH1D * fClusterPurityEfficiency
histogram of cluster efficiency times purity
Declaration of signal hit object.
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)
art::ServiceHandle< cheat::ParticleInventoryService const > fPI
the back tracker service
constexpr auto abs(T v)
Returns the absolute value of the argument.
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
bool isRealData() const
Definition: Event.cc:53
TH2D * fTrackPurityEfficiency2D
scatter histogram of cluster purity and efficiency
void beginRun(art::Run const &r) override
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
Particle class.
TH1D * fEventEfficiency
histogram of event efficiency
int NumberDaughters() const
Definition: MCParticle.h:218
Definition: Run.h:37
TH1D * fVertexPurity
histogram of vertex purity
int Daughter(const int i) const
Definition: MCParticle.cxx:118
TH1D * fEventPurityEfficiency
histogram of event efficiency times purity
3-dimensional objects, potentially hits, clusters, prongs, etc.
Definition: geo_types.h:141
TH1D * fVertexPurityEfficiency
histogram of vertex efficiency times purity
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
TString part[npart]
Definition: Style.C:32
void hits()
Definition: readHits.C:15
if(nlines<=0)
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)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
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
bool fCheckClusters
should we check the reconstruction of clusters?
double P(const int i=0) const
Definition: MCParticle.h:235
T get(std::string const &key) const
Definition: ParameterSet.h:314
std::vector< double > fshwpur
shower purities
TTree * fTree
TTree to save efficiencies.
std::vector< int > fshwid
shower IDs
double energy
Definition: plottest35.C:25
TH1D * fVertexEfficiency
histogram of vertex efficiency
std::vector< int > ftrkid
track IDs
std::vector< double > ftrkeff
track efficiencies
Float_t d
Definition: plot.C:235
Provides recob::Track data product.
bool fCheckTracks
should we check the reconstruction of tracks?
std::vector< double > fclueff
cluster efficiencies
std::string fTrackModuleLabel
label for module making the tracks
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
Declaration of cluster object.
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)
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
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
object containing MC truth information necessary for making RawDigits and doing back tracking ...
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:8
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:306
std::string fVertexModuleLabel
label for module making the vertices
Particle list in DetSim contains Monte Carlo particle information.
Float_t e
Definition: plot.C:35
RunNumber_t run() const
Definition: Event.cc:29
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:82
TH1D * fTrackEfficiency
histogram of track efficiency
EventID id() const
Definition: Event.cc:23
bool failedToGet() const
Definition: Handle.h:210
TH2D * fShowerPurityEfficiency2D
scatter histogram of cluster purity and efficiency
std::string fHitModuleLabel
label for module making the hits