Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
nnet::PointIdEffTest Class Reference
Inheritance diagram for nnet::PointIdEffTest:
art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::Observer art::ModuleBase

Classes

struct  Config
 

Public Types

enum  EId { kShower = 0, kTrack = 1, kMichel = 2 }
 
using Parameters = art::EDAnalyzer::Table< Config >
 
- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 

Public Member Functions

 PointIdEffTest (Parameters const &config)
 
 PointIdEffTest (PointIdEffTest const &)=delete
 
 PointIdEffTest (PointIdEffTest &&)=delete
 
PointIdEffTestoperator= (PointIdEffTest const &)=delete
 
PointIdEffTestoperator= (PointIdEffTest &&)=delete
 
- Public Member Functions inherited from art::EDAnalyzer
 EDAnalyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDAnalyzer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Analyzer
virtual ~Analyzer () noexcept
 
 Analyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 Analyzer (Table< Config > const &config)
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Observer
 ~Observer () noexcept
 
 Observer (Observer const &)=delete
 
 Observer (Observer &&)=delete
 
Observeroperator= (Observer const &)=delete
 
Observeroperator= (Observer &&)=delete
 
void registerProducts (ProductDescriptions &, ModuleDescription const &)
 
void fillDescriptions (ModuleDescription const &)
 
fhicl::ParameterSetID selectorConfig () const
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

void beginRun (const art::Run &run) override
 
void beginJob () override
 
void endJob () override
 
void analyze (art::Event const &e) override
 
void cleanup ()
 
void countTruthDep (const std::vector< sim::SimChannel > &channels, float &emLike, float &trackLike) const
 
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
 
bool isMuonDecaying (const simb::MCParticle &particle, const std::unordered_map< int, const simb::MCParticle * > &particleMap) const
 
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)
 

Private Attributes

int fRun
 
int fEvent
 
float fMcDepEM
 
float fMcDepTrack
 
float fMcFractionEM
 
float fPfpDepEM
 
float fPfpDepTrack
 
float fHitEM_0p5
 
float fHitTrack_0p5
 
float fHitMichel_0p5
 
float fHitMcFractionEM
 
float fHitEM_mc
 
float fpEM
 
float fHitMichel_mc
 
float fpMichel_hit
 
float fpMichel_cl
 
float fOutTrk
 
float fOutEM
 
float fOutNone
 
float fHitEM_0p85
 
float fHitTrack_0p85
 
float fTotHit
 
float fCleanHit
 
float fHitsEM_OK_0p5 [100]
 
float fHitsTrack_OK_0p5 [100]
 
float fHitsMichel_OK_0p5 [100]
 
float fHitsMichel_False_0p5 [100]
 
float fHitsEM_OK_0p85 [100]
 
float fHitsTrack_OK_0p85 [100]
 
float fHitRecoEM [100]
 
float fHitRecoFractionEM [100]
 
int fMcPid
 
int fClSize
 
float fPidValue
 
int fTrkOk [100]
 
int fTrkBad [100]
 
int fShOk [100]
 
int fShBad [100]
 
int fNone
 
int fTotal
 
double fElectronsToGeV
 
int fTrkLikeIdx
 
int fEmLikeIdx
 
int fNoneIdx
 
int fMichelLikeIdx
 
TTree * fEventTree
 
TTree * fClusterTree
 
TTree * fHitTree
 
std::ofstream fHitsOutFile
 
unsigned int fView
 
std::unordered_map< int, const simb::MCParticle * > fParticleMap
 
calo::CalorimetryAlg fCalorimetryAlg
 
art::InputTag fSimulationProducerLabel
 
art::InputTag fPfpModuleLabel
 
art::InputTag fNNetModuleLabel
 
bool fSaveHitsFile
 

Additional Inherited Members

- Protected Member Functions inherited from art::Observer
std::string const & processName () const
 
bool wantAllEvents () const noexcept
 
bool wantEvent (ScheduleID id, Event const &e) const
 
Handle< TriggerResultsgetTriggerResults (Event const &e) const
 
 Observer (fhicl::ParameterSet const &config)
 
 Observer (std::vector< std::string > const &select_paths, std::vector< std::string > const &reject_paths, fhicl::ParameterSet const &config)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 55 of file PointIdEffTest_module.cc.

Member Typedef Documentation

Definition at line 81 of file PointIdEffTest_module.cc.

Member Enumeration Documentation

Constructor & Destructor Documentation

nnet::PointIdEffTest::PointIdEffTest ( Parameters const &  config)
explicit

Definition at line 166 of file PointIdEffTest_module.cc.

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())
176  , fSimulationProducerLabel(config().SimModuleLabel())
177  , fPfpModuleLabel(config().PfpModuleLabel())
178  , fNNetModuleLabel(config().NNetModuleLabel())
179  , fSaveHitsFile(config().SaveHitsFile())
180 {}
art::InputTag fSimulationProducerLabel
AdcChannelData::View View
static Config * config
Definition: config.cpp:1054
calo::CalorimetryAlg fCalorimetryAlg
nnet::PointIdEffTest::PointIdEffTest ( PointIdEffTest const &  )
delete
nnet::PointIdEffTest::PointIdEffTest ( PointIdEffTest &&  )
delete

Member Function Documentation

void nnet::PointIdEffTest::analyze ( art::Event const &  e)
overrideprivatevirtual

Implements art::EDAnalyzer.

Definition at line 311 of file PointIdEffTest_module.cc.

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 }
art::InputTag fSimulationProducerLabel
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
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
std::unordered_map< int, const simb::MCParticle * > fParticleMap
const double e
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)
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
static std::unique_ptr< MVAReader > create(const art::Event &evt, const art::InputTag &tag)
Definition: MVAReader.h:110
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
void nnet::PointIdEffTest::beginJob ( )
overrideprivatevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 190 of file PointIdEffTest_module.cc.

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 }
void nnet::PointIdEffTest::beginRun ( const art::Run run)
overrideprivate
void nnet::PointIdEffTest::cleanup ( )
private

Definition at line 275 of file PointIdEffTest_module.cc.

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 }
std::unordered_map< int, const simb::MCParticle * > fParticleMap
void nnet::PointIdEffTest::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
private

Definition at line 479 of file PointIdEffTest_module.cc.

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 }
double LifetimeCorrection(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, double time, double T0=0) const
calo::CalorimetryAlg fCalorimetryAlg
void nnet::PointIdEffTest::countTruthDep ( const std::vector< sim::SimChannel > &  channels,
float &  emLike,
float &  trackLike 
) const
private

Definition at line 435 of file PointIdEffTest_module.cc.

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 }
int PdgCode() const
Definition: MCParticle.h:212
uint8_t channel
Definition: CRTFragment.hh:201
std::unordered_map< int, const simb::MCParticle * > fParticleMap
Definition: search.py:1
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
void nnet::PointIdEffTest::endJob ( )
overrideprivatevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 253 of file PointIdEffTest_module.cc.

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 }
G4double thr[100]
Definition: G4S2Light.cc:59
bool nnet::PointIdEffTest::isMuonDecaying ( const simb::MCParticle particle,
const std::unordered_map< int, const simb::MCParticle * > &  particleMap 
) const
private

Definition at line 513 of file PointIdEffTest_module.cc.

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 }
int PdgCode() const
Definition: MCParticle.h:212
int NumberDaughters() const
Definition: MCParticle.h:217
int Daughter(const int i) const
Definition: MCParticle.cxx:112
T abs(T value)
std::string EndProcess() const
Definition: MCParticle.h:216
PointIdEffTest& nnet::PointIdEffTest::operator= ( PointIdEffTest const &  )
delete
PointIdEffTest& nnet::PointIdEffTest::operator= ( PointIdEffTest &&  )
delete
int nnet::PointIdEffTest::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 
)
private

Definition at line 543 of file PointIdEffTest_module.cc.

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 }
int PdgCode() const
Definition: MCParticle.h:212
G4double thr[100]
Definition: G4S2Light.cc:59
int Mother() const
Definition: MCParticle.h:213
uint8_t channel
Definition: CRTFragment.hh:201
T abs(T value)
std::unordered_map< int, const simb::MCParticle * > fParticleMap
bool isMuonDecaying(const simb::MCParticle &particle, const std::unordered_map< int, const simb::MCParticle * > &particleMap) const
Definition: search.py:1
Detector simulation of raw signals on wires.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
double LifetimeCorrection(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, double time, double T0=0) const
calo::CalorimetryAlg fCalorimetryAlg
QTextStream & endl(QTextStream &s)

Member Data Documentation

calo::CalorimetryAlg nnet::PointIdEffTest::fCalorimetryAlg
private

Definition at line 157 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fCleanHit
private

Definition at line 129 of file PointIdEffTest_module.cc.

int nnet::PointIdEffTest::fClSize
private

Definition at line 138 of file PointIdEffTest_module.cc.

TTree * nnet::PointIdEffTest::fClusterTree
private

Definition at line 149 of file PointIdEffTest_module.cc.

double nnet::PointIdEffTest::fElectronsToGeV
private

Definition at line 145 of file PointIdEffTest_module.cc.

int nnet::PointIdEffTest::fEmLikeIdx
private

Definition at line 147 of file PointIdEffTest_module.cc.

int nnet::PointIdEffTest::fEvent
private

Definition at line 121 of file PointIdEffTest_module.cc.

TTree* nnet::PointIdEffTest::fEventTree
private

Definition at line 149 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fHitEM_0p5
private

Definition at line 124 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fHitEM_0p85
private

Definition at line 128 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fHitEM_mc
private

Definition at line 125 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fHitMcFractionEM
private

Definition at line 124 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fHitMichel_0p5
private

Definition at line 124 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fHitMichel_mc
private

Definition at line 126 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fHitRecoEM[100]
private

Definition at line 135 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fHitRecoFractionEM[100]
private

Definition at line 135 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fHitsEM_OK_0p5[100]
private

Definition at line 132 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fHitsEM_OK_0p85[100]
private

Definition at line 134 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fHitsMichel_False_0p5[100]
private

Definition at line 133 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fHitsMichel_OK_0p5[100]
private

Definition at line 133 of file PointIdEffTest_module.cc.

std::ofstream nnet::PointIdEffTest::fHitsOutFile
private

Definition at line 151 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fHitsTrack_OK_0p5[100]
private

Definition at line 132 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fHitsTrack_OK_0p85[100]
private

Definition at line 134 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fHitTrack_0p5
private

Definition at line 124 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fHitTrack_0p85
private

Definition at line 128 of file PointIdEffTest_module.cc.

TTree * nnet::PointIdEffTest::fHitTree
private

Definition at line 149 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fMcDepEM
private

Definition at line 122 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fMcDepTrack
private

Definition at line 122 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fMcFractionEM
private

Definition at line 122 of file PointIdEffTest_module.cc.

int nnet::PointIdEffTest::fMcPid
private

Definition at line 137 of file PointIdEffTest_module.cc.

int nnet::PointIdEffTest::fMichelLikeIdx
private

Definition at line 147 of file PointIdEffTest_module.cc.

art::InputTag nnet::PointIdEffTest::fNNetModuleLabel
private

Definition at line 160 of file PointIdEffTest_module.cc.

int nnet::PointIdEffTest::fNone
private

Definition at line 143 of file PointIdEffTest_module.cc.

int nnet::PointIdEffTest::fNoneIdx
private

Definition at line 147 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fOutEM
private

Definition at line 127 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fOutNone
private

Definition at line 127 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fOutTrk
private

Definition at line 127 of file PointIdEffTest_module.cc.

std::unordered_map<int, const simb::MCParticle*> nnet::PointIdEffTest::fParticleMap
private

Definition at line 155 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fpEM
private

Definition at line 125 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fPfpDepEM
private

Definition at line 123 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fPfpDepTrack
private

Definition at line 123 of file PointIdEffTest_module.cc.

art::InputTag nnet::PointIdEffTest::fPfpModuleLabel
private

Definition at line 159 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fPidValue
private

Definition at line 139 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fpMichel_cl
private

Definition at line 126 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fpMichel_hit
private

Definition at line 126 of file PointIdEffTest_module.cc.

int nnet::PointIdEffTest::fRun
private

Definition at line 121 of file PointIdEffTest_module.cc.

bool nnet::PointIdEffTest::fSaveHitsFile
private

Definition at line 161 of file PointIdEffTest_module.cc.

int nnet::PointIdEffTest::fShBad[100]
private

Definition at line 142 of file PointIdEffTest_module.cc.

int nnet::PointIdEffTest::fShOk[100]
private

Definition at line 142 of file PointIdEffTest_module.cc.

art::InputTag nnet::PointIdEffTest::fSimulationProducerLabel
private

Definition at line 158 of file PointIdEffTest_module.cc.

int nnet::PointIdEffTest::fTotal
private

Definition at line 143 of file PointIdEffTest_module.cc.

float nnet::PointIdEffTest::fTotHit
private

Definition at line 129 of file PointIdEffTest_module.cc.

int nnet::PointIdEffTest::fTrkBad[100]
private

Definition at line 141 of file PointIdEffTest_module.cc.

int nnet::PointIdEffTest::fTrkLikeIdx
private

Definition at line 147 of file PointIdEffTest_module.cc.

int nnet::PointIdEffTest::fTrkOk[100]
private

Definition at line 141 of file PointIdEffTest_module.cc.

unsigned int nnet::PointIdEffTest::fView
private

Definition at line 153 of file PointIdEffTest_module.cc.


The documentation for this class was generated from the following file: