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