PointIdEffTest_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: PointIdEffTest
3 // Module Type: analyzer
4 // File: PointIdEffTest_module.cc
5 //
6 // Author: dorota.stefan@cern.ch
7 //
8 // Generated at Fri Apr 29 06:42:27 2016 by Dorota Stefan using artmod
9 // from cetpkgsupport v1_10_01.
10 ////////////////////////////////////////////////////////////////////////
11 
26 
34 #include "art_root_io/TFileService.h"
35 #include "canvas/Persistency/Common/FindManyP.h"
37 #include "fhiclcpp/types/Atom.h"
38 #include "fhiclcpp/types/Table.h"
40 
43 
44 #include "TH1.h"
45 #include "TTree.h"
46 
47 #include <cmath>
48 #include <fstream>
49 #include <iostream>
50 
51 #define MVA_LENGTH 4
52 
53 namespace nnet {
54 
56  public:
57  enum EId { kShower = 0, kTrack = 1, kMichel = 2 };
58 
59  struct Config {
60  using Name = fhicl::Name;
62 
64  Name("CalorimetryAlg"),
65  Comment("Used to calculate electron lifetime correction.")};
66 
68  Comment("Simulation producer")};
69 
71  Name("PfpModuleLabel"),
72  Comment("PFP producer tag, to compare with NNet results")};
73 
75  Comment("NNet outputs tag")};
76 
77  fhicl::Atom<bool> SaveHitsFile{Name("SaveHitsFile"), Comment("Dump hits info to text file")};
78 
79  fhicl::Atom<unsigned int> View{Name("View"), Comment("Which view is evaluated")};
80  };
82 
83  explicit PointIdEffTest(Parameters const& config);
84 
85  PointIdEffTest(PointIdEffTest const&) = delete;
86  PointIdEffTest(PointIdEffTest&&) = delete;
87  PointIdEffTest& operator=(PointIdEffTest const&) = delete;
89 
90  private:
91  void beginRun(const art::Run& run) override;
92  void beginJob() override;
93  void endJob() override;
94  void analyze(art::Event const& e) override;
95 
96  void cleanup();
97 
98  void countTruthDep(const std::vector<sim::SimChannel>& channels,
99  float& emLike,
100  float& trackLike) const;
101 
102  void countPfpDep(detinfo::DetectorClocksData const& clockData,
103  detinfo::DetectorPropertiesData const& detProp,
104  const std::vector<recob::PFParticle>& pfparticles,
105  const art::FindManyP<recob::Cluster>& pfpclus,
106  const art::FindManyP<recob::Hit>& cluhits,
107  float& emLike,
108  float& trackLike) const;
109 
110  bool isMuonDecaying(const simb::MCParticle& particle,
111  const std::unordered_map<int, const simb::MCParticle*>& particleMap) const;
112 
113  int testCNN(detinfo::DetectorClocksData const& clockData,
114  detinfo::DetectorPropertiesData const& detProp,
115  const std::vector<sim::SimChannel>& channels,
116  const std::vector<art::Ptr<recob::Hit>>& hits,
117  const std::array<float, MVA_LENGTH>& cnn_out,
119  size_t cidx);
120 
121  int fRun, fEvent;
125  float fHitEM_mc, fpEM;
130 
131  //const int kEffSize = 100;
135  float fHitRecoEM[100], fHitRecoFractionEM[100];
136 
137  int fMcPid;
138  int fClSize;
139  float fPidValue; // P(track-like)
140 
141  int fTrkOk[100], fTrkBad[100];
142  int fShOk[100], fShBad[100];
143  int fNone, fTotal;
144 
146 
148 
150 
151  std::ofstream fHitsOutFile;
152 
153  unsigned int fView;
154 
155  std::unordered_map<int, const simb::MCParticle*> fParticleMap;
156 
162  };
163 
164 } // namespace nnet
165 
167  : art::EDAnalyzer(config)
168  , fMcPid(-1)
169  , fClSize(0)
170  , fTrkLikeIdx(-1)
171  , fEmLikeIdx(-1)
172  , fNoneIdx(-1)
173  , fMichelLikeIdx(-1)
174  , fView(config().View())
175  , fCalorimetryAlg(config().CalorimetryAlg())
177  , fPfpModuleLabel(config().PfpModuleLabel())
178  , fNNetModuleLabel(config().NNetModuleLabel())
179  , fSaveHitsFile(config().SaveHitsFile())
180 {}
181 
182 void
184 {
186  fElectronsToGeV = 1. / larParameters->GeVToElectrons();
187 }
188 
189 void
191 {
193 
194  fEventTree = tfs->make<TTree>("event", "event info");
195  fEventTree->Branch("fRun", &fRun, "fRun/I");
196  fEventTree->Branch("fEvent", &fEvent, "fEvent/I");
197  fEventTree->Branch("fMcDepEM", &fMcDepEM, "fMcDepEM/F");
198  fEventTree->Branch("fMcDepTrack", &fMcDepTrack, "fMcDepTrack/F");
199  fEventTree->Branch("fMcFractionEM", &fMcFractionEM, "fMcFractionEM/F");
200  fEventTree->Branch("fPfpDepEM", &fPfpDepEM, "fPfpDepEM/F");
201  fEventTree->Branch("fPfpDepTrack", &fPfpDepTrack, "fPfpDepTrack/F");
202  fEventTree->Branch("fHitEM_0p5", &fHitEM_0p5, "fHitEM_0p5/F");
203  fEventTree->Branch("fHitMichel_0p5", &fHitMichel_0p5, "fHitMichel_0p5/F");
204  fEventTree->Branch("fHitTrack_0p5", &fHitTrack_0p5, "fHitTrack_0p5/F");
205  fEventTree->Branch("fHitMcFractionEM", &fHitMcFractionEM, "fHitMcFractionEM/F");
206  fEventTree->Branch("fHitEM_0p85", &fHitEM_0p85, "fHitEM_0p85/F");
207  fEventTree->Branch("fHitTrack_0p85", &fHitTrack_0p85, "fHitTrack_0p85/F");
208  fEventTree->Branch("fCleanHit", &fCleanHit, "fCleanHit/F");
209 
210  fEventTree->Branch("fHitsEM_OK_0p5", fHitsEM_OK_0p5, "fHitsEM_OK_0p5[100]/F");
211  fEventTree->Branch("fHitsTrack_OK_0p5", fHitsTrack_OK_0p5, "fHitsTrack_OK_0p5[100]/F");
212  fEventTree->Branch("fHitsMichel_OK_0p5", fHitsMichel_OK_0p5, "fHitsMichel_OK_0p5[100]/F");
213  fEventTree->Branch(
214  "fHitsMichel_False_0p5", fHitsMichel_False_0p5, "fHitsMichel_False_0p5[100]/F");
215 
216  fEventTree->Branch("fHitsEM_OK_0p85", fHitsEM_OK_0p85, "fHitsEM_OK_0p85[100]/F");
217  fEventTree->Branch("fHitsTrack_OK_0p85", fHitsTrack_OK_0p85, "fHitsTrack_OK_0p85[100]/F");
218 
219  fEventTree->Branch("fHitRecoEM", fHitRecoEM, "fHitRecoEM[100]/F");
220  fEventTree->Branch("fHitRecoFractionEM", fHitRecoFractionEM, "fHitRecoFractionEM[100]/F");
221 
222  fClusterTree = tfs->make<TTree>("cluster", "clusters info");
223  fClusterTree->Branch("fMcPid", &fMcPid, "fMcPid/I");
224  fClusterTree->Branch("fClSize", &fClSize, "fClSize/I");
225  fClusterTree->Branch("fPidValue", &fPidValue, "fPidValue/F");
226  fClusterTree->Branch("fpMichel_cl", &fpMichel_cl, "fpMichel_cl/F");
227 
228  fHitTree = tfs->make<TTree>("hits", "hits info");
229  fHitTree->Branch("fRun", &fRun, "fRun/I");
230  fHitTree->Branch("fEvent", &fEvent, "fEvent/I");
231  fHitTree->Branch("fHitEM_mc", &fHitEM_mc, "fHitEM_mc/F");
232  fHitTree->Branch("fpEM", &fpEM, "fpEM/F");
233  fHitTree->Branch("fPidValue", &fPidValue, "fPidValue/F");
234  fHitTree->Branch("fHitMichel_mc", &fHitMichel_mc, "fHitMichel_mc/F");
235  fHitTree->Branch("fpMichel_hit", &fpMichel_hit, "fpMichel_hit/F");
236  fHitTree->Branch("fOutTrk", &fOutTrk, "fOutTrk/F");
237  fHitTree->Branch("fOutEM", &fOutEM, "fOutEM/F");
238  fHitTree->Branch("fOutNone", &fOutNone, "fOutNone/F");
239 
240  if (fSaveHitsFile) fHitsOutFile.open("hits_pid.prn");
241 
242  fNone = 0;
243  fTotal = 0;
244  for (size_t i = 0; i < 100; ++i) {
245  fShOk[i] = 0;
246  fShBad[i] = 0;
247  fTrkOk[i] = 0;
248  fTrkBad[i] = 0;
249  }
250 }
251 
252 void
254 {
255  if (fSaveHitsFile) fHitsOutFile.close();
256 
258 
259  TTree* thrTree = tfs->make<TTree>("threshold", "error rate vs threshold");
260 
261  float thr, shErr, trkErr;
262  thrTree->Branch("thr", &thr, "thr/F");
263  thrTree->Branch("shErr", &shErr, "shErr/F");
264  thrTree->Branch("trkErr", &trkErr, "trkErr/F");
265 
266  for (size_t i = 0; i < 100; ++i) {
267  thr = 0.01 * i;
268  shErr = fShBad[i] / float(fShBad[i] + fShOk[i]);
269  trkErr = fTrkBad[i] / float(fTrkBad[i] + fTrkOk[i]);
270  thrTree->Fill();
271  }
272 }
273 
274 void
276 {
277  fParticleMap.clear();
278 
279  fMcDepEM = 0;
280  fMcDepTrack = 0;
281  fMcFractionEM = 0;
282  fPfpDepEM = 0;
283  fPfpDepTrack = 0;
284  fHitEM_0p5 = 0;
285  fHitTrack_0p5 = 0;
286  fHitEM_0p85 = 0;
287  fHitTrack_0p85 = 0;
288  fHitMichel_0p5 = 0;
289  fHitMcFractionEM = 0;
290  fTotHit = 0;
291  fCleanHit = 0;
292 
293  for (size_t i = 0; i < 100; ++i) {
294  fHitsEM_OK_0p5[i] = 0;
295  fHitsTrack_OK_0p5[i] = 0;
296  fHitsEM_OK_0p85[i] = 0;
297  fHitsTrack_OK_0p85[i] = 0;
298  fHitsMichel_OK_0p5[i] = 0;
299  fHitsMichel_False_0p5[i] = 0;
300  fHitRecoEM[i] = 0;
301  fHitRecoFractionEM[i] = 0;
302  }
303 
304  fTrkLikeIdx = -1;
305  fEmLikeIdx = -1;
306  fNoneIdx = -1;
307  fMichelLikeIdx = -1;
308 }
309 
310 void
312 {
313  cleanup(); // remove everything from members
314 
315  fRun = e.run();
316  fEvent = e.id().event();
317 
318  // access to MC information
319 
320  // MC particles list
321  auto particleHandle = e.getValidHandle<std::vector<simb::MCParticle>>(fSimulationProducerLabel);
322  for (auto const& particle : *particleHandle) {
323  fParticleMap[particle.TrackId()] = &particle;
324  }
325 
326  // SimChannels
327  auto simChannelHandle = e.getValidHandle<std::vector<sim::SimChannel>>(fSimulationProducerLabel);
328  countTruthDep(*simChannelHandle, fMcDepEM, fMcDepTrack);
329 
330  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
331  auto const detProp =
333 
334  // PFParticle selection results
336  if (e.getByLabel(fPfpModuleLabel, pfpHandle)) {
337  auto cluHandle = e.getValidHandle<std::vector<recob::Cluster>>(fPfpModuleLabel);
338  const art::FindManyP<recob::Cluster> clusFromPfps(pfpHandle, e, fPfpModuleLabel);
339  const art::FindManyP<recob::Hit> hitsFromClus(cluHandle, e, fPfpModuleLabel);
340  countPfpDep(
341  clockData, detProp, *pfpHandle, clusFromPfps, hitsFromClus, fPfpDepEM, fPfpDepTrack);
342  }
343 
344  // output from cnn's
345 
347  e, fNNetModuleLabel); // hit-by-hit outpus just to be dumped to file for debugging
348  fTrkLikeIdx = hitResults.getIndex("track");
349  fEmLikeIdx = hitResults.getIndex("em");
350  fNoneIdx = hitResults.getIndex("none");
351  fMichelLikeIdx = hitResults.getIndex("michel");
352  if ((fTrkLikeIdx < 0) || (fEmLikeIdx < 0)) {
353  throw cet::exception("PointIdEffTest")
354  << "No em/track labeled columns in MVA data products." << std::endl;
355  }
356 
358  e, fNNetModuleLabel); // outputs for clusters recovered in not-throwing way
359  if (cluResults) {
360  const art::FindManyP<recob::Hit> hitsFromClusters(
361  cluResults->dataHandle(), e, cluResults->dataTag());
362 
363  for (size_t c = 0; c < cluResults->size(); ++c) {
364  const recob::Cluster& clu = cluResults->item(c);
365 
366  if (clu.Plane().Plane != fView) continue;
367 
368  const std::vector<art::Ptr<recob::Hit>>& hits = hitsFromClusters.at(c);
369  std::array<float, MVA_LENGTH> cnn_out = cluResults->getOutput(c);
370 
371  testCNN(clockData,
372  detProp,
373  *simChannelHandle,
374  hits,
375  cnn_out,
376  hitResults.outputs(),
377  c); // test hits in the cluster
378  }
379 
380  if (fTotHit > 0)
382  else
383  fCleanHit = 0;
384 
385  double totMcDep = fMcDepEM + fMcDepTrack;
386  if (totMcDep)
387  fMcFractionEM = fMcDepEM / totMcDep;
388  else
389  fMcFractionEM = 0;
390 
391  double totEmTrk0p5 = fHitEM_0p5 + fHitTrack_0p5;
392  if (totEmTrk0p5 > 0)
393  fHitMcFractionEM = fHitEM_0p5 / totEmTrk0p5;
394  else
395  fHitMcFractionEM = 0;
396 
397  for (size_t i = 0; i < 100; ++i) {
398  if (fHitEM_0p5 > 0)
400  else
401  fHitsEM_OK_0p5[i] = 0;
402 
403  if (fHitTrack_0p5 > 0)
405  else
406  fHitsTrack_OK_0p5[i] = 0;
407 
408  if (fHitEM_0p85 > 0)
410  else
411  fHitsEM_OK_0p85[i] = 0;
412 
413  if (fHitTrack_0p85 > 0)
415  else
416  fHitsTrack_OK_0p85[i] = 0;
417 
418  if (totEmTrk0p5 > 0)
419  fHitRecoFractionEM[i] = fHitRecoEM[i] / totEmTrk0p5;
420  else
421  fHitRecoFractionEM[i] = 0;
422  }
423 
424  fEventTree->Fill();
425  }
426  else {
427  mf::LogWarning("TrainingDataAlg") << "MVA FOR CLUSTERS NOT FOUND";
428  }
429 
430  cleanup(); // remove everything from members
431 }
432 /******************************************/
433 
434 void
435 nnet::PointIdEffTest::countTruthDep(const std::vector<sim::SimChannel>& channels,
436  float& emLike,
437  float& trackLike) const
438 {
439  emLike = 0;
440  trackLike = 0;
441  for (auto const& channel : channels) {
442  // for every time slice in this channel:
443  auto const& timeSlices = channel.TDCIDEMap();
444  for (auto const& timeSlice : timeSlices) {
445  // loop over the energy deposits.
446  auto const& energyDeposits = timeSlice.second;
447  for (auto const& energyDeposit : energyDeposits) {
448  int trackID = energyDeposit.trackID;
449 
450  double energy = energyDeposit.numElectrons * fElectronsToGeV * 1000;
451 
452  if (trackID < 0) { emLike += energy; }
453  else if (trackID > 0) {
454  auto search = fParticleMap.find(trackID);
455  bool found = true;
456  if (search == fParticleMap.end()) {
457  mf::LogWarning("TrainingDataAlg") << "PARTICLE NOT FOUND";
458  found = false;
459  }
460 
461  int pdg = 0;
462  if (found) {
463  const simb::MCParticle& particle = *((*search).second);
464  if (!pdg) pdg = particle.PdgCode(); // not EM activity so read what PDG it is
465  }
466 
467  if ((pdg == 11) || (pdg == -11) || (pdg == 22))
468  emLike += energy;
469  else
470  trackLike += energy;
471  }
472  }
473  }
474  }
475 }
476 /******************************************/
477 
478 void
480  detinfo::DetectorPropertiesData const& detProp,
481  const std::vector<recob::PFParticle>& pfparticles,
482  const art::FindManyP<recob::Cluster>& pfpclus,
483  const art::FindManyP<recob::Hit>& cluhits,
484  float& emLike,
485  float& trackLike) const
486 {
487  emLike = 0;
488  trackLike = 0;
489  for (size_t i = 0; i < pfparticles.size(); ++i) {
490  const auto& pfp = pfparticles[i];
491  const auto& clus = pfpclus.at(i);
492 
493  float hitdep = 0;
494  for (const auto& c : clus) {
495  const auto& hits = cluhits.at(c.key());
496  for (const auto& h : hits) {
497  if (h->View() == fView) {
498  hitdep +=
499  h->SummedADC() * fCalorimetryAlg.LifetimeCorrection(clockData, detProp, h->PeakTime());
500  }
501  }
502  }
503 
504  if ((pfp.PdgCode() == 11) || pfp.PdgCode() == -11) { emLike += hitdep; }
505  else {
506  trackLike += hitdep;
507  }
508  }
509 }
510 /******************************************/
511 
512 bool
514  const simb::MCParticle& particle,
515  const std::unordered_map<int, const simb::MCParticle*>& particleMap) const
516 {
517  bool hasElectron = false, hasNuMu = false, hasNuE = false;
518 
519  int pdg = abs(particle.PdgCode());
520  if ((pdg == 13) && (particle.EndProcess() == "FastScintillation")) // potential muon decay at rest
521  {
522  unsigned int nSec = particle.NumberDaughters();
523  for (size_t d = 0; d < nSec; ++d) {
524  auto d_search = particleMap.find(particle.Daughter(d));
525  if (d_search != particleMap.end()) {
526  auto const& daughter = *((*d_search).second);
527  int d_pdg = abs(daughter.PdgCode());
528  if (d_pdg == 11)
529  hasElectron = true;
530  else if (d_pdg == 14)
531  hasNuMu = true;
532  else if (d_pdg == 12)
533  hasNuE = true;
534  }
535  }
536  }
537 
538  return (hasElectron && hasNuMu && hasNuE);
539 }
540 /******************************************/
541 
542 int
544  detinfo::DetectorPropertiesData const& detProp,
545  const std::vector<sim::SimChannel>& channels,
546  const std::vector<art::Ptr<recob::Hit>>& hits,
547  const std::array<float, MVA_LENGTH>& cnn_out,
549  size_t cidx)
550 {
551  fClSize = hits.size();
552 
553  std::unordered_map<int, int> mcHitPid;
554 
555  fPidValue = 0;
556  double p_trk_or_sh = cnn_out[fTrkLikeIdx] + cnn_out[fEmLikeIdx];
557  if (p_trk_or_sh > 0) { fPidValue = cnn_out[fTrkLikeIdx] / p_trk_or_sh; }
558 
559  double p_michel = 0;
560  if (fMichelLikeIdx >= 0) { fpMichel_cl = cnn_out[fMichelLikeIdx]; }
561 
562  double totEnSh = 0, totEnTrk = 0, totEnMichel = 0;
563  for (auto const& hit : hits) {
564  // the channel associated with this hit.
565  auto hitChannelNumber = hit->Channel();
566 
567  double hitEn = 0, hitEnSh = 0, hitEnTrk = 0, hitEnMichel = 0;
568 
569  auto const& vout = hit_outs[hit.key()];
570  fOutTrk = vout[fTrkLikeIdx];
571  fOutEM = vout[fEmLikeIdx];
572  if (fNoneIdx >= 0) { fOutNone = vout[fNoneIdx]; }
573  if (fMichelLikeIdx >= 0) { p_michel = vout[fMichelLikeIdx]; }
574 
575  for (auto const& channel : channels) {
576  if (channel.Channel() != hitChannelNumber) continue;
577 
578  // for every time slice in this channel:
579  auto const& timeSlices = channel.TDCIDEMap();
580  for (auto const& timeSlice : timeSlices) {
581  int time = timeSlice.first;
582  if (std::abs(hit->TimeDistanceAsRMS(time)) < 1.0) {
583  // loop over the energy deposits.
584  auto const& energyDeposits = timeSlice.second;
585 
586  for (auto const& energyDeposit : energyDeposits) {
587  int trackID = energyDeposit.trackID;
588 
589  double energy = energyDeposit.numElectrons * fElectronsToGeV * 1000;
590  hitEn += energy;
591 
592  if (trackID < 0) { hitEnSh += energy; } // EM activity
593  else if (trackID > 0) {
594  auto search = fParticleMap.find(trackID);
595  if (search != fParticleMap.end()) {
596  const simb::MCParticle& particle = *((*search).second);
597  int pdg = particle.PdgCode(); // not EM activity so read what PDG it is
598 
599  if ((pdg == 11) || (pdg == -11) || (pdg == 22))
600  hitEnSh += energy;
601  else
602  hitEnTrk += energy;
603 
604  if (pdg == 11) // electron, check if it is Michel
605  {
606  auto msearch = fParticleMap.find(particle.Mother());
607  if (msearch != fParticleMap.end()) {
608  auto const& mother = *((*msearch).second);
609  if (isMuonDecaying(mother, fParticleMap)) { hitEnMichel += energy; }
610  }
611  }
612  }
613  else {
614  mf::LogWarning("TrainingDataAlg") << "PARTICLE NOT FOUND";
615  }
616  }
617  }
618  }
619  }
620  }
621  totEnSh += hitEnSh;
622  totEnTrk += hitEnTrk;
623  totEnMichel += hitEnMichel;
624 
625  double hitAdc =
626  hit->SummedADC() * fCalorimetryAlg.LifetimeCorrection(clockData, detProp, hit->PeakTime());
627  fTotHit += hitAdc;
628 
629  int hitPidMc_0p5 = -1;
630  if (hitEnSh > hitEnTrk) {
631  fHitEM_0p5 += hitAdc;
632  hitPidMc_0p5 = nnet::PointIdEffTest::kShower;
633  }
634  else {
635  fHitTrack_0p5 += hitAdc;
636  hitPidMc_0p5 = nnet::PointIdEffTest::kTrack;
637  }
638  mcHitPid[hit.key()] = hitPidMc_0p5;
639  auto const& hout = hit_outs[hit.key()];
640  fpEM = 0;
641  float hit_trk_or_sh = hout[fTrkLikeIdx] + hout[fEmLikeIdx];
642  if (hit_trk_or_sh > 0) fpEM = hout[fEmLikeIdx] / hit_trk_or_sh;
643  fHitEM_mc = hitEnSh / (hitEnSh + hitEnTrk);
644 
645  int hitPidMc_0p85 = -1;
646  double hitDep = hitEnSh + hitEnTrk;
647  if (hitEnSh > 0.85 * hitDep) {
648  fHitEM_0p85 += hitAdc;
649  fCleanHit += hitAdc;
650  hitPidMc_0p85 = nnet::PointIdEffTest::kShower;
651  }
652  else if (hitEnTrk > 0.85 * hitDep) {
653  fHitTrack_0p85 += hitAdc;
654  fCleanHit += hitAdc;
655  hitPidMc_0p85 = nnet::PointIdEffTest::kTrack;
656  }
657 
658  bool mcMichel = false;
659  fpMichel_hit = p_michel;
660  fHitMichel_mc = hitEnMichel / hitEn;
661  if (fHitMichel_mc > 0.5) {
662  fHitMichel_0p5 += hitAdc;
663  mcMichel = true;
664  }
665 
666  fHitTree->Fill();
667 
668  for (size_t i = 0; i < 100; ++i) {
669  double thr = 0.01 * i;
670 
671  if (p_michel > thr) {
672  if (mcMichel) { fHitsMichel_OK_0p5[i] += hitAdc; }
673  else {
674  fHitsMichel_False_0p5[i] += hitAdc;
675  }
676  }
677 
678  int recoPid = -1;
679  if (fPidValue < thr) {
681  fHitRecoEM[i] += hitAdc;
682  }
683  else
685 
686  if ((recoPid == nnet::PointIdEffTest::kShower) &&
687  (hitPidMc_0p5 == nnet::PointIdEffTest::kShower)) {
688  fHitsEM_OK_0p5[i] += hitAdc;
689  }
690  else if ((recoPid == nnet::PointIdEffTest::kTrack) &&
691  (hitPidMc_0p5 == nnet::PointIdEffTest::kTrack)) {
692  fHitsTrack_OK_0p5[i] += hitAdc;
693  }
694 
695  if ((recoPid == nnet::PointIdEffTest::kShower) &&
696  (hitPidMc_0p85 == nnet::PointIdEffTest::kShower)) {
697  fHitsEM_OK_0p85[i] += hitAdc;
698  }
699  else if ((recoPid == nnet::PointIdEffTest::kTrack) &&
700  (hitPidMc_0p85 == nnet::PointIdEffTest::kTrack)) {
701  fHitsTrack_OK_0p85[i] += hitAdc;
702  }
703  }
704  }
705 
706  // ************ count clusters *************
707 
708  fMcPid = -1;
709  if (totEnSh > 1.5 * totEnTrk) // major energy deposit from EM activity
710  {
712  }
713  else if (totEnTrk > 1.5 * totEnSh) {
715  }
716 
717  for (size_t i = 0; i < 100; ++i) {
718  double thr = 0.01 * i;
719 
720  int recoPid = -1;
721  if (fPidValue < thr)
723  else
725 
727  fShOk[i] += fClSize;
728  }
729  else if ((recoPid == nnet::PointIdEffTest::kTrack) &&
731  fTrkOk[i] += fClSize;
732  }
733  else if ((recoPid == nnet::PointIdEffTest::kShower) &&
735  fTrkBad[i] += fClSize;
736  }
737  else if ((recoPid == nnet::PointIdEffTest::kTrack) &&
739  fShBad[i] += fClSize;
740  }
741  else {
742  fNone++;
743  }
744  }
745  fTotal++;
746 
747  if (fSaveHitsFile) {
748  for (auto const& h : hits) {
749  auto const& vout = hit_outs[h.key()];
750  double hitPidValue = 0;
751  double h_trk_or_sh = vout[fTrkLikeIdx] + vout[fEmLikeIdx];
752  if (h_trk_or_sh > 0) hitPidValue = vout[fTrkLikeIdx] / h_trk_or_sh;
753 
754  fHitsOutFile << fRun << " " << fEvent << " " << h->WireID().TPC << " " << h->WireID().Wire
755  << " " << h->PeakTime() << " "
756  << h->SummedADC() *
757  fCalorimetryAlg.LifetimeCorrection(clockData, detProp, h->PeakTime())
758  << " " << mcHitPid[h.key()] << " " << fPidValue << " " << hitPidValue;
759 
760  if (fMichelLikeIdx >= 0) {
761  fHitsOutFile << " " << vout[fMichelLikeIdx]; // is michel?
762  }
763 
764  fHitsOutFile << " " << cidx << std::endl;
765  }
766  }
767 
768  fClusterTree->Fill();
769  return fMcPid;
770 }
771 /******************************************/
772 
art::InputTag fSimulationProducerLabel
Store parameters for running LArG4.
int PdgCode() const
Definition: MCParticle.h:212
G4double thr[100]
Definition: G4S2Light.cc:59
AdcChannelData::View View
int Mother() const
Definition: MCParticle.h:213
struct vector vector
ChannelGroupService::Name Name
int getIndex(const std::string &name) const
Index of column with given name, or -1 if name not found.
Definition: MVAReader.h:82
void countPfpDep(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const std::vector< recob::PFParticle > &pfparticles, const art::FindManyP< recob::Cluster > &pfpclus, const art::FindManyP< recob::Hit > &cluhits, float &emLike, float &trackLike) const
Set of hits with a 2D structure.
Definition: Cluster.h:71
uint8_t channel
Definition: CRTFragment.hh:201
void countTruthDep(const std::vector< sim::SimChannel > &channels, float &emLike, float &trackLike) const
geo::PlaneID Plane() const
Returns the plane ID this cluster lies on.
Definition: Cluster.h:744
PointIdEffTest & operator=(PointIdEffTest const &)=delete
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
Particle class.
int NumberDaughters() const
Definition: MCParticle.h:217
Definition: Run.h:17
int Daughter(const int i) const
Definition: MCParticle.cxx:112
T abs(T value)
void analyze(art::Event const &e) override
std::unordered_map< int, const simb::MCParticle * > fParticleMap
PointIdEffTest(Parameters const &config)
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
void beginRun(const art::Run &run) override
std::string EndProcess() const
Definition: MCParticle.h:216
int testCNN(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const std::vector< sim::SimChannel > &channels, const std::vector< art::Ptr< recob::Hit >> &hits, const std::array< float, MVA_LENGTH > &cnn_out, const std::vector< anab::FeatureVector< MVA_LENGTH >> &hit_outs, size_t cidx)
static Config * config
Definition: config.cpp:1054
bool isMuonDecaying(const simb::MCParticle &particle, const std::unordered_map< int, const simb::MCParticle * > &particleMap) const
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
fhicl::Atom< art::InputTag > PfpModuleLabel
Definition: search.py:1
RunNumber_t run() const
Definition: DataViewImpl.cc:71
std::vector< FeatureVector< N > > const & outputs() const
Access the vector of the feature vectors.
Definition: MVAReader.h:126
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
fhicl::Table< calo::CalorimetryAlg::Config > CalorimetryAlg
Detector simulation of raw signals on wires.
Declaration of signal hit object.
fhicl::Atom< art::InputTag > SimModuleLabel
#define Comment
Contains all timing reference information for the detector.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
Provides recob::Track data product.
fhicl::Atom< art::InputTag > NNetModuleLabel
EventNumber_t event() const
Definition: EventID.h:116
Declaration of basic channel signal object.
double LifetimeCorrection(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, double time, double T0=0) const
Collection of Physical constants used in LArSoft.
calo::CalorimetryAlg fCalorimetryAlg
static std::unique_ptr< MVAReader > create(const art::Event &evt, const art::InputTag &tag)
Definition: MVAReader.h:110
EventID id() const
Definition: Event.cc:34
double GeVToElectrons() const
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)