All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 <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 
19 #include "art/Framework/Core/EDAnalyzer.h"
20 #include "art/Framework/Core/ModuleMacros.h"
21 #include "art/Framework/Principal/Event.h"
22 #include "art/Framework/Principal/Handle.h"
23 #include "art/Framework/Services/Registry/ServiceHandle.h"
24 #include "art_root_io/TFileService.h"
25 #include "canvas/Persistency/Common/Assns.h"
26 #include "canvas/Persistency/Common/FindManyP.h"
27 #include "canvas/Persistency/Common/Ptr.h"
28 #include "canvas/Persistency/Provenance/EventID.h"
29 #include "fhiclcpp/ParameterSet.h"
30 #include "messagefacility/MessageLogger/MessageLogger.h"
31 
43 #include "nug4/ParticleNavigation/ParticleList.h"
44 #include "nusimdata/SimulationBase/MCParticle.h"
45 
46 namespace cheat {
47  class RecoCheckAna;
48 }
49 
50 class cheat::RecoCheckAna : public art::EDAnalyzer {
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 
98  art::ServiceHandle<cheat::BackTrackerService const> fBT; ///< the back tracker service
99  art::ServiceHandle<cheat::ParticleInventoryService const> fPI; ///< the back tracker service
100 
101  std::string fHitModuleLabel; ///< label for module making the hits
102  std::string fClusterModuleLabel; ///< label for module making the clusters
103  std::string fShowerModuleLabel; ///< label for module making the showers
104  std::string fTrackModuleLabel; ///< label for module making the tracks
105  std::string fVertexModuleLabel; ///< label for module making the vertices
106  std::string fEventModuleLabel; ///< label for module making the events
107 
108  bool fCheckClusters; ///< should we check the reconstruction of clusters?
109  bool fCheckShowers; ///< should we check the reconstruction of showers?
110  bool fCheckTracks; ///< should we check the reconstruction of tracks?
111  bool fCheckVertices; ///< should we check the reconstruction of vertices?
112  bool fCheckEvents; ///< should we check the reconstruction of events?
113 
114  TH1D* fClusterPurity; ///< histogram of cluster purity
115  TH1D* fClusterEfficiency; ///< histogram of cluster efficiency
116  TH1D* fClusterPurityEfficiency; ///< histogram of cluster efficiency times purity
117  TH2D* fClusterPurityEfficiency2D; ///< scatter histogram of cluster purity and efficiency
118  TH1D* fShowerPurity; ///< histogram of shower purity
119  TH1D* fShowerEfficiency; ///< histogram of shower efficiency
120  TH1D* fShowerPurityEfficiency; ///< histogram of shower efficiency times purity
121  TH2D* fShowerPurityEfficiency2D; ///< scatter histogram of cluster purity and efficiency
122  TH1D* fTrackPurity; ///< histogram of track purity
123  TH1D* fTrackEfficiency; ///< histogram of track efficiency
124  TH1D* fTrackPurityEfficiency; ///< histogram of track efficiency times purity
125  TH2D* fTrackPurityEfficiency2D; ///< scatter histogram of cluster purity and efficiency
126  TH1D* fVertexPurity; ///< histogram of vertex purity
127  TH1D* fVertexEfficiency; ///< histogram of vertex efficiency
128  TH1D* fVertexPurityEfficiency; ///< histogram of vertex efficiency times purity
129  TH1D* fEventPurity; ///< histogram of event purity
130  TH1D* fEventEfficiency; ///< histogram of event efficiency
131  TH1D* fEventPurityEfficiency; ///< histogram of event efficiency times purity
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; ///< TTree to save efficiencies
141  int frun; ///< run number
142  int fevent; ///< event number
143  int ftrackid; ///< geant track ID
144  int fpdg; ///< particle pdg code
145  double fpmom; ///< particle momentum
146  double fhiteff; ///< hitfinder efficiency for this particle
147  int fnclu; ///< number of clusters for this particle
148  std::vector<double> fclueff; ///< cluster efficiencies
149  std::vector<double> fclupur; ///< cluster purities
150  std::vector<int> fcluid; ///< cluster IDs
151  int fnshw; ///< number of showers for this particle
152  std::vector<double> fshweff; ///< shower efficiencies
153  std::vector<double> fshwpur; ///< shower purities
154  std::vector<int> fshwid; ///< shower IDs
155  int fntrk; ///< number of tracks for this particle
156  std::vector<double> ftrkeff; ///< track efficiencies
157  std::vector<double> ftrkpur; ///< track purities
158  std::vector<int> ftrkid; ///< track IDs
159 };
160 
161 //-------------------------------------------------------------------
162 cheat::RecoCheckAna::RecoCheckAna(fhicl::ParameterSet const& p)
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 //-------------------------------------------------------------------
178 void
179 cheat::RecoCheckAna::analyze(art::Event const& e)
180 {
181  // check that this is MC, stop if it isn't
182  if (e.isRealData()) {
183  mf::LogWarning("RecoVetter") << "attempting to run MC truth check on "
184  << "real data, bail";
185  return;
186  }
187 
188  // get all hits in the event to figure out how many there are
189  art::Handle<std::vector<recob::Hit>> hithdl;
190  e.getByLabel(fHitModuleLabel, hithdl);
191  std::vector<art::Ptr<recob::Hit>> allhits;
192  art::fill_ptr_vector(allhits, hithdl);
193 
194  // define variables to hold the reconstructed objects
195  art::Handle<std::vector<recob::Cluster>> clscol;
196  art::Handle<std::vector<recob::Track>> trkcol;
197  art::Handle<std::vector<recob::Shower>> shwcol;
198  art::Handle<std::vector<recob::Vertex>> vtxcol;
199  art::Handle<std::vector<recob::Event>> evtcol;
200 
201  if (fCheckClusters) {
202  e.getByLabel(fClusterModuleLabel, clscol);
203  if (!clscol.failedToGet()) this->CheckRecoClusters(e, fClusterModuleLabel, clscol, allhits);
204  }
205  if (fCheckTracks) {
206  e.getByLabel(fTrackModuleLabel, trkcol);
207  if (!trkcol.failedToGet()) this->CheckRecoTracks(e, fTrackModuleLabel, trkcol, allhits);
208  }
209  if (fCheckShowers) {
210  e.getByLabel(fShowerModuleLabel, shwcol);
211  if (!shwcol.failedToGet()) this->CheckRecoShowers(e, fShowerModuleLabel, shwcol, allhits);
212  }
213  if (fCheckVertices) {
214  e.getByLabel(fVertexModuleLabel, vtxcol);
215  if (!vtxcol.failedToGet()) this->CheckRecoVertices(e, fVertexModuleLabel, vtxcol, allhits);
216  }
217  if (fCheckEvents) {
218  e.getByLabel(fEventModuleLabel, evtcol);
219  if (!evtcol.failedToGet()) this->CheckRecoEvents(e, fEventModuleLabel, evtcol, allhits);
220  }
221 
222  frun = e.run();
223  fevent = e.id().event();
224 
225  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
226  this->FillResults(clockData, allhits);
227 
228  return;
229 }
230 
231 //-------------------------------------------------------------------
232 void
233 cheat::RecoCheckAna::beginRun(art::Run const& /*r*/)
234 {
235  art::ServiceHandle<art::TFileService const> tfs;
236 
237  if (fCheckEvents) {
238  fEventPurity = tfs->make<TH1D>("eventPurity", ";Purity;Events", 100, 0., 1.1);
239  fEventEfficiency = tfs->make<TH1D>("eventEfficiency", ";Efficiency;Events", 100, 0., 1.1);
241  tfs->make<TH1D>("eventPurityEfficiency", ";purityEfficiency;Events", 110, 0., 1.1);
242  }
243  if (fCheckVertices) {
244  fVertexPurity = tfs->make<TH1D>("vertexPurity", ";Purity;Vertices", 100, 0., 1.1);
245  fVertexEfficiency = tfs->make<TH1D>("vertexEfficiency", ";Efficiency;Vertices", 100, 0., 1.1);
247  tfs->make<TH1D>("vertexPurityEfficiency", ";purityEfficiency;Vertex", 110, 0., 1.1);
248  }
249  if (fCheckTracks) {
250  fTrackPurity = tfs->make<TH1D>("trackPurity", ";Purity;Tracks", 100, 0., 1.1);
251  fTrackEfficiency = tfs->make<TH1D>("trackEfficiency", ";Efficiency;Tracks", 100, 0., 1.1);
253  tfs->make<TH1D>("trackPurityEfficiency", ";purityEfficiency;Tracks", 110, 0., 1.1);
255  tfs->make<TH2D>("trackPurityEfficiency2D", ";purity;efficiency", 110, 0., 1.1, 110, 0., 1.1);
256  }
257  if (fCheckShowers) {
258  fShowerPurity = tfs->make<TH1D>("showerPurity", ";Purity;Showers", 100, 0., 1.1);
259  fShowerEfficiency = tfs->make<TH1D>("showerEfficiency", ";Efficiency;Showers", 100, 0., 1.1);
261  tfs->make<TH1D>("showerPurityEfficiency", ";purityEfficiency;Showers", 110, 0., 1.1);
263  tfs->make<TH2D>("showerPurityEfficiency2D", ";purity;efficiency", 110, 0., 1.1, 110, 0., 1.1);
264  }
265  if (fCheckClusters) {
266  fClusterPurity = tfs->make<TH1D>("clusterPurity", ";Purity;Clusters", 110, 0., 1.1);
267  fClusterEfficiency = tfs->make<TH1D>("clusterEfficiency", ";Efficiency;Clusters", 110, 0., 1.1);
269  tfs->make<TH1D>("clusterPurityEfficiency", ";purityEfficiency;Clusters", 110, 0., 1.1);
270  fClusterPurityEfficiency2D = tfs->make<TH2D>(
271  "clusterPurityEfficiency2D", ";purity;efficiency", 110, 0., 1.1, 110, 0., 1.1);
272  }
273 
274  fTree = tfs->make<TTree>("cheatertree", "cheater tree");
275  fTree->Branch("run", &frun, "run/I");
276  fTree->Branch("event", &fevent, "event/I");
277  fTree->Branch("trackid", &ftrackid, "trackid/I");
278  fTree->Branch("pdg", &fpdg, "pdg/I");
279  fTree->Branch("pmom", &fpmom, "pmom/D");
280  fTree->Branch("hiteff", &fhiteff, "hiteff/D");
281  fTree->Branch("nclu", &fnclu, "nclu/I");
282  fTree->Branch("clueff", &fclueff);
283  fTree->Branch("clupur", &fclupur);
284  fTree->Branch("cluid", &fcluid);
285  fTree->Branch("nshw", &fnshw, "nshw/I");
286  fTree->Branch("shweff", &fshweff);
287  fTree->Branch("shwpur", &fshwpur);
288  fTree->Branch("shwid", &fshwid);
289  fTree->Branch("ntrk", &fntrk, "ntrk/I");
290  fTree->Branch("trkeff", &ftrkeff);
291  fTree->Branch("trkpur", &ftrkpur);
292  fTree->Branch("trkid", &ftrkid);
293 
294  return;
295 }
296 
297 //-------------------------------------------------------------------
298 // colID is the ID of the RecoBase object and colHits are the recob::Hits
299 // associated with it
300 void
302  detinfo::DetectorClocksData const& clockData,
303  int const& colID,
304  std::vector<art::Ptr<recob::Hit>> const& allhits,
305  std::vector<art::Ptr<recob::Hit>> const& colHits,
306  std::map<std::pair<int, int>, std::pair<double, double>>& g4RecoBaseIDToPurityEfficiency)
307 {
308 
309  // grab the set of track IDs for these hits
310  std::set<int> trackIDs = fBT->GetSetOfTrackIds(clockData, colHits);
311 
312  geo::View_t view = colHits[0]->View();
313 
314  std::set<int>::iterator itr = trackIDs.begin();
315  while (itr != trackIDs.end()) {
316 
317  std::set<int> id;
318  id.insert(*itr);
319 
320  // use the cheat::BackTrackerService to find purity and efficiency for these
321  // hits
322  double purity = fBT->HitCollectionPurity(clockData, id, colHits);
323  double efficiency = fBT->HitCollectionEfficiency(clockData, id, colHits, allhits, view);
324 
325  // make the purity and efficiency pair
326  std::pair<double, double> pe(purity, efficiency);
327 
328  // make the pair of the RecoBase object id to the pair of purity/efficiency
329  std::pair<int, int> g4reco(*itr, colID);
330 
331  // insert idpe into the map
332  g4RecoBaseIDToPurityEfficiency[g4reco] = pe;
333 
334  itr++;
335 
336  } // end loop over eveIDs
337 
338  return;
339 }
340 
341 //-------------------------------------------------------------------
342 void
344  std::string const& label,
345  art::Handle<std::vector<recob::Cluster>> const& clscol,
346  std::vector<art::Ptr<recob::Hit>> const& allhits)
347 {
348  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
349  art::FindManyP<recob::Hit> fmh(clscol, evt, label);
350 
351  for (size_t c = 0; c < clscol->size(); ++c) {
352 
353  // get the hits associated with this event
354  std::vector<art::Ptr<recob::Hit>> hits = fmh.at(c);
355 
356  this->CheckReco(clockData, clscol->at(c).ID(), allhits, hits, fG4ClusterIDToPurityEfficiency);
357 
358  } // end loop over clusters
359 
360  return;
361 }
362 
363 //-------------------------------------------------------------------
364 void
366  std::string const& label,
367  art::Handle<std::vector<recob::Track>> const& tcol,
368  std::vector<art::Ptr<recob::Hit>> const& allhits)
369 {
370  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
371  art::FindManyP<recob::Hit> fmh(tcol, evt, label);
372 
373  for (size_t p = 0; p < tcol->size(); ++p) {
374 
375  // get the hits associated with this event
376  std::vector<art::Ptr<recob::Hit>> hits = fmh.at(p);
377 
378  this->CheckReco(clockData, tcol->at(p).ID(), allhits, hits, fG4TrackIDToPurityEfficiency);
379 
380  } // end loop over tracks
381 
382  return;
383 }
384 
385 //-------------------------------------------------------------------
386 void
388  std::string const& label,
389  art::Handle<std::vector<recob::Shower>> const& scol,
390  std::vector<art::Ptr<recob::Hit>> const& allhits)
391 {
392  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
393  art::FindManyP<recob::Hit> fmh(scol, evt, label);
394 
395  for (size_t p = 0; p < scol->size(); ++p) {
396 
397  // get the hits associated with this event
398  std::vector<art::Ptr<recob::Hit>> hits = fmh.at(p);
399 
400  this->CheckReco(clockData, scol->at(p).ID(), allhits, hits, fG4ShowerIDToPurityEfficiency);
401 
402  } // end loop over events
403 
404  return;
405 }
406 
407 //-------------------------------------------------------------------
408 //a true vertex will either consist of primary particles originating from
409 //the interaction vertex, or a primary particle decaying to make daughters
410 void
412  std::string const& label,
413  art::Handle<std::vector<recob::Vertex>> const& vtxcol,
414  std::vector<art::Ptr<recob::Hit>> const& allhits)
415 {
416  const sim::ParticleList& plist = fPI->ParticleList();
417 
418  std::vector<std::set<int>> ids(1);
419  // loop over all primary particles and put their ids into the first set of the
420  // vector. add another set for each primary particle that also has daughters
421  // and put those daughters into the new set
422  // PartPair is a (track ID, particle pointer) pair
423  for (const auto& PartPair : plist) {
424  auto trackID = PartPair.first;
425  if (!plist.IsPrimary(trackID)) continue;
426  const simb::MCParticle& part = *(PartPair.second);
427  ids[0].insert(trackID);
428  if (part.NumberDaughters() > 0) {
429  std::set<int> dv;
430  for (int d = 0; d < part.NumberDaughters(); ++d)
431  dv.insert(part.Daughter(d));
432  ids.push_back(std::move(dv));
433  } // end if this primary particle has daughters
434  } // end loop over primaries
435 
436  art::FindManyP<recob::Hit> fmh(vtxcol, evt, label);
437 
438  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
439 
440  for (size_t v = 0; v < vtxcol->size(); ++v) {
441 
442  // get the hits associated with this event
443  std::vector<art::Ptr<recob::Hit>> hits = fmh.at(v);
444 
445  double maxPurity = -1.;
446  double maxEfficiency = -1.;
447 
448  for (size_t tv = 0; tv < ids.size(); ++tv) {
449 
450  // use the cheat::BackTrackerService to find purity and efficiency for
451  // these hits
452  double purity = fBT->HitCollectionPurity(clockData, ids[tv], hits);
453  double efficiency = fBT->HitCollectionEfficiency(clockData, ids[tv], hits, allhits, geo::k3D);
454 
455  if (purity > maxPurity) maxPurity = purity;
456  if (efficiency > maxEfficiency) maxEfficiency = efficiency;
457  }
458 
459  fVertexPurity->Fill(maxPurity);
460  fVertexEfficiency->Fill(maxEfficiency);
461  fVertexPurityEfficiency->Fill(maxPurity * maxEfficiency);
462 
463  } // end loop over vertices
464 
465  return;
466 }
467 
468 //-------------------------------------------------------------------
469 // in this method one should loop over the primary particles from a given
470 // MCTruth collection
471 /// \todo need to divy it up in the case where there is more than 1 true interaction in a spill
472 void
474  std::string const& label,
475  art::Handle<std::vector<recob::Event>> const& evtcol,
476  std::vector<art::Ptr<recob::Hit>> const& allhits)
477 {
478  const sim::ParticleList& plist = fPI->ParticleList();
479 
480  // loop over all primaries in the plist and grab them and their daughters to put into
481  // the set of track ids to pass on to the back tracker
482  std::set<int> ids;
483  for (const auto& PartPair : plist) {
484  auto trackID = PartPair.first;
485  if (!plist.IsPrimary(trackID)) continue;
486  const simb::MCParticle& part = *(PartPair.second);
487  ids.insert(trackID);
488  for (int d = 0; d < part.NumberDaughters(); ++d)
489  ids.insert(part.Daughter(d));
490  } // end loop over primaries
491 
492  art::FindManyP<recob::Hit> fmh(evtcol, evt, label);
493 
494  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
495  for (size_t ev = 0; ev < evtcol->size(); ++ev) {
496 
497  // get the hits associated with this event
498  std::vector<art::Ptr<recob::Hit>> hits = fmh.at(ev);
499 
500  // use the cheat::BackTrackerService to find purity and efficiency for these
501  // hits
502  double purity = fBT->HitCollectionPurity(clockData, ids, hits);
503  double efficiency = fBT->HitCollectionEfficiency(clockData, ids, hits, allhits, geo::k3D);
504 
505  fEventPurity->Fill(purity);
506  fEventEfficiency->Fill(efficiency);
507  fEventPurityEfficiency->Fill(purity * efficiency);
508 
509  } // end loop over events
510 
511  return;
512 }
513 
514 //-------------------------------------------------------------------
515 void
517  std::map<std::pair<int, int>, std::pair<double, double>> const& g4RecoBaseIDToPurityEfficiency,
518  std::map<int, std::vector<std::pair<int, std::pair<double, double>>>>&
519  g4IDToRecoBasePurityEfficiency,
520  TH1D* purity,
521  TH1D* efficiency,
522  TH1D* purityEfficiency,
523  TH2D* purityEfficiency2D)
524 {
525 
526  std::map<std::pair<int, int>, std::pair<double, double>>::const_iterator rbItr =
527  g4RecoBaseIDToPurityEfficiency.begin();
528 
529  // map of key cluster ID to pair of purity, efficiency
530  std::map<int, std::pair<double, double>> recoBIDToPurityEfficiency;
531  std::map<int, std::pair<double, double>>::iterator rbpeItr;
532 
533  while (rbItr != g4RecoBaseIDToPurityEfficiency.end()) {
534 
535  // trackID, cluster ID
536  std::pair<int, int> g4cl = rbItr->first;
537  // purity, efficiency
538  std::pair<double, double> pe = rbItr->second;
539 
540  // add the efficiency and purity values for clusters corresponding
541  // to the current g4 id to the map
542  // pair of cluster id, pair of purity, efficiency
543  std::pair<int, std::pair<double, double>> clpe(g4cl.second, pe);
544  // g4IDToRecoBasePurityEfficiency is a map with key of trackID of a vector of clusterIDs of pairs of purity and efficiency
545  g4IDToRecoBasePurityEfficiency[g4cl.first].push_back(clpe);
546 
547  // now find the maximum purity to determine the purity and efficiency
548  // for this RecoBase object
549  rbpeItr = recoBIDToPurityEfficiency.find(g4cl.second);
550  if (rbpeItr != recoBIDToPurityEfficiency.end()) {
551  std::pair<double, double> curpe = rbpeItr->second;
552  if (pe.first > curpe.first) recoBIDToPurityEfficiency[g4cl.second] = pe;
553  }
554  else
555  recoBIDToPurityEfficiency[g4cl.second] = pe;
556 
557  rbItr++;
558  }
559 
560  rbpeItr = recoBIDToPurityEfficiency.begin();
561 
562  // now fill the histograms,
563  while (rbpeItr != recoBIDToPurityEfficiency.end()) {
564  purity->Fill(rbpeItr->second.first);
565  efficiency->Fill(rbpeItr->second.second);
566  purityEfficiency->Fill(rbpeItr->second.first * rbpeItr->second.second);
567  purityEfficiency2D->Fill(rbpeItr->second.first, rbpeItr->second.second);
568  rbpeItr++;
569  }
570 
571  return;
572 }
573 
574 //-------------------------------------------------------------------
575 void
577  std::vector<art::Ptr<recob::Hit>> const& allhits)
578 {
579  // map the g4 track id to energy deposited in a hit
580  std::map<int, double> g4IDToHitEnergy;
581  for (size_t h = 0; h < allhits.size(); ++h) {
582  const std::vector<sim::TrackIDE> hitTrackIDs = fBT->HitToTrackIDEs(clockData, allhits[h]);
583  for (size_t e = 0; e < hitTrackIDs.size(); ++e) {
584  g4IDToHitEnergy[hitTrackIDs[e].trackID] += hitTrackIDs[e].energy;
585  }
586  } // end loop over hits to fill map
587 
588  // flatten the G4RecoBaseIDToPurityEfficiency maps to have just the g4ID as
589  // the key and the rest of the information in vector form
590  std::map<int, std::vector<std::pair<int, std::pair<double, double>>>>
591  g4IDToClusterPurityEfficiency;
592  std::map<int, std::vector<std::pair<int, std::pair<double, double>>>>
593  g4IDToShowerPurityEfficiency;
594  std::map<int, std::vector<std::pair<int, std::pair<double, double>>>> g4IDToTrackPurityEfficiency;
595  std::map<int, std::vector<std::pair<int, std::pair<double, double>>>>::iterator g4peItr;
596 
597  if (fCheckClusters)
599  g4IDToClusterPurityEfficiency,
604  if (fCheckShowers)
606  g4IDToShowerPurityEfficiency,
611  if (fCheckTracks)
613  g4IDToTrackPurityEfficiency,
614  fTrackPurity,
618 
619  // fill the tree vectors
620  // get all the eveIDs from this event
621  std::set<int> trackIDs = fBT->GetSetOfTrackIds();
622  std::set<int>::const_iterator trackItr = trackIDs.begin();
623 
624  // loop over them
625  while (trackItr != trackIDs.end()) {
626 
627  const simb::MCParticle* part = fPI->TrackIdToParticle_P(*trackItr);
628 
629  ftrackid = std::abs(*trackItr);
630  fpdg = part->PdgCode();
631  fpmom = part->P();
632 
633  // figure out how much of the energy deposited from this particle is stored in hits
634  std::vector<const sim::IDE*> ides = fBT->TrackIdToSimIDEs_Ps(*trackItr);
635  double totalDep = 0.;
636  for (size_t i = 0; i < ides.size(); ++i)
637  totalDep += ides[i]->energy;
638 
639  if (totalDep > 0.) fhiteff = g4IDToHitEnergy[*trackItr] / totalDep;
640 
641  std::vector<std::pair<int, std::pair<double, double>>> clVec;
642  std::vector<std::pair<int, std::pair<double, double>>> shVec;
643  std::vector<std::pair<int, std::pair<double, double>>> trVec;
644 
645  if (g4IDToClusterPurityEfficiency.find(*trackItr) != g4IDToClusterPurityEfficiency.end())
646  clVec = g4IDToClusterPurityEfficiency.find(*trackItr)->second;
647 
648  if (g4IDToShowerPurityEfficiency.find(*trackItr) != g4IDToShowerPurityEfficiency.end())
649  shVec = g4IDToShowerPurityEfficiency.find(*trackItr)->second;
650 
651  if (g4IDToTrackPurityEfficiency.find(*trackItr) != g4IDToTrackPurityEfficiency.end())
652  trVec = g4IDToTrackPurityEfficiency.find(*trackItr)->second;
653 
654  fnclu = clVec.size();
655  fnshw = shVec.size();
656  fntrk = trVec.size();
657 
658  for (size_t c = 0; c < clVec.size(); ++c) {
659  fcluid.push_back(clVec[c].first);
660  fclupur.push_back(clVec[c].second.first);
661  fclueff.push_back(clVec[c].second.second);
662  }
663 
664  for (size_t s = 0; s < shVec.size(); ++s) {
665  fshwid.push_back(shVec[s].first);
666  fshwpur.push_back(shVec[s].second.first);
667  fshweff.push_back(shVec[s].second.second);
668  }
669 
670  for (size_t t = 0; t < trVec.size(); ++t) {
671  ftrkid.push_back(trVec[t].first);
672  ftrkpur.push_back(trVec[t].second.first);
673  ftrkeff.push_back(trVec[t].second.second);
674  }
675 
676  fTree->Fill();
677 
678  trackItr++;
679  }
680 
681  // clean up for the next event
682 
683  // clear the maps of G4 track id to efficiency and purity for
684  // various RecoBase objects
688 
689  // clear the vectors hooked up to the tree
690  fclueff.clear();
691  fclupur.clear();
692  fcluid.clear();
693  ftrkeff.clear();
694  ftrkpur.clear();
695  ftrkid.clear();
696  fshweff.clear();
697  fshwpur.clear();
698  fshwid.clear();
699 
700  return;
701 }
702 
703 DEFINE_ART_MODULE(cheat::RecoCheckAna)
art::ServiceHandle< cheat::BackTrackerService const > fBT
the back tracker service
int fpdg
particle pdg code
int fnshw
number of showers for this particle
then if[["$THISISATEST"==1]]
Definition: neoSmazza.sh:95
void analyze(art::Event const &e) override
TH1D * fTrackPurityEfficiency
histogram of track efficiency times purity
bool fCheckVertices
should we check the reconstruction of vertices?
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
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
pdgs p
Definition: selectors.fcl:22
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
int fntrk
number of tracks for this particle
RecoCheckAna(fhicl::ParameterSet const &p)
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
TH1D * fEventEfficiency
histogram of event efficiency
TH1D * fVertexPurity
histogram of vertex purity
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
while getopts h
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
T abs(T value)
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)
std::vector< double > fclupur
cluster purities
std::vector< double > fshweff
shower efficiencies
bool fCheckClusters
should we check the reconstruction of clusters?
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
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.
Provides recob::Track data product.
bool fCheckShowers
should we check the reconstruction of showers?
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)
int ftrackid
geant track ID
Represents the Event implemented as a self balancing binary search tree.
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
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
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)
object containing MC truth information necessary for making RawDigits and doing back tracking ...
do i e
std::string fClusterModuleLabel
label for module making the clusters
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
art::ServiceHandle< art::TFileService > tfs
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
std::string fVertexModuleLabel
label for module making the vertices
esac echo uname r
TH1D * fTrackEfficiency
histogram of track efficiency
TH2D * fShowerPurityEfficiency2D
scatter histogram of cluster purity and efficiency
std::string fHitModuleLabel
label for module making the hits