34 #include "art_root_io/TFileService.h" 35 #include "canvas/Persistency/Common/FindManyP.h" 64 Name(
"CalorimetryAlg"),
Comment(
"Used to calculate electron lifetime correction.")
90 virtual void endJob()
override;
97 const std::vector< sim::SimChannel > &
channels,
98 float & emLike,
float & trackLike)
const;
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;
108 const std::unordered_map< int, const simb::MCParticle* > & particleMap)
const;
111 const std::vector< sim::SimChannel > &
channels,
113 const std::array<float, MVA_LENGTH> & cnn_out,
190 fEventTree = tfs->make<TTree>(
"event",
"event info");
218 fClusterTree = tfs->make<TTree>(
"cluster",
"clusters info");
224 fHitTree = tfs->make<TTree>(
"hits",
"hits info");
239 for (
size_t i = 0; i < 100; ++i)
252 TTree *thrTree = tfs->make<TTree>(
"threshold",
"error rate vs threshold");
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");
259 for (
size_t i = 0; i < 100; ++i)
284 for (
size_t i = 0; i < 100; ++i)
307 for (
auto const& particle : *particleHandle) {
fParticleMap[particle.TrackId()] = &particle; }
318 const art::FindManyP<recob::Cluster> clusFromPfps(pfpHandle, e,
fPfpModuleLabel);
319 const art::FindManyP<recob::Hit> hitsFromClus(cluHandle, e,
fPfpModuleLabel);
338 const art::FindManyP<recob::Hit> hitsFromClusters(cluResults->dataHandle(),
e, cluResults->dataTag());
340 for (
size_t c = 0;
c < cluResults->size(); ++
c)
346 const std::vector< art::Ptr<recob::Hit> > & hits = hitsFromClusters.at(
c);
347 std::array<float, MVA_LENGTH> cnn_out = cluResults->getOutput(
c);
363 for (
size_t i = 0; i < 100; ++i)
384 else {
mf::LogWarning(
"TrainingDataAlg") <<
"MVA FOR CLUSTERS NOT FOUND"; }
391 const std::vector< sim::SimChannel > &
channels,
392 float & emLike,
float & trackLike)
const 394 emLike = 0; trackLike = 0;
395 for (
auto const&
channel : channels)
398 auto const& timeSlices =
channel.TDCIDEMap();
399 for (
auto const& timeSlice : timeSlices)
402 auto const& energyDeposits = timeSlice.second;
403 for (
auto const& energyDeposit : energyDeposits)
405 int trackID = energyDeposit.trackID;
413 else if (trackID > 0)
427 if (!pdg) pdg = particle.
PdgCode();
430 if ((pdg == 11) || (pdg == -11) || (pdg == 22)) emLike +=
energy;
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 445 emLike = 0; trackLike = 0;
446 for (
size_t i = 0; i < pfparticles.size(); ++i)
448 const auto & pfp = pfparticles[i];
449 const auto & clus = pfpclus.at(i);
452 for (
const auto &
c : clus)
454 const auto & hits = cluhits.at(
c.key());
455 for (
const auto &
h : hits)
461 if ((pfp.PdgCode() == 11) || pfp.PdgCode() == -11) { emLike += hitdep; }
462 else { trackLike += hitdep; }
468 const std::unordered_map< int, const simb::MCParticle* > & particleMap)
const 470 bool hasElectron =
false, hasNuMu =
false, hasNuE =
false;
473 if ((pdg == 13) && (particle.
EndProcess() ==
"FastScintillation"))
476 for (
size_t d = 0;
d < nSec; ++
d)
478 auto d_search = particleMap.find(particle.
Daughter(
d));
479 if (d_search != particleMap.end())
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;
490 return (hasElectron && hasNuMu && hasNuE);
495 const std::vector< sim::SimChannel > &
channels,
497 const std::array<float, MVA_LENGTH> & cnn_out,
503 std::unordered_map<int, int> mcHitPid;
512 double totEnSh = 0, totEnTrk = 0, totEnMichel = 0;
513 for (
auto const &
hit: hits)
516 auto hitChannelNumber =
hit->Channel();
518 double hitEn = 0, hitEnSh = 0, hitEnTrk = 0, hitEnMichel = 0;
520 auto const & vout = hit_outs[
hit.key()];
526 for (
auto const &
channel : channels)
528 if (
channel.Channel() != hitChannelNumber)
continue;
531 auto const& timeSlices =
channel.TDCIDEMap();
532 for (
auto const& timeSlice : timeSlices)
534 int time = timeSlice.first;
538 auto const & energyDeposits = timeSlice.second;
540 for (
auto const & energyDeposit : energyDeposits)
542 int trackID = energyDeposit.trackID;
547 if (trackID < 0) { hitEnSh +=
energy; }
548 else if (trackID > 0)
556 if ((pdg == 11) || (pdg == -11) || (pdg == 22)) hitEnSh +=
energy;
564 auto const & mother = *((*msearch).second);
569 else {
mf::LogWarning(
"TrainingDataAlg") <<
"PARTICLE NOT FOUND"; }
576 totEnTrk += hitEnTrk;
577 totEnMichel += hitEnMichel;
582 int hitPidMc_0p5 = -1;
583 if (hitEnSh > hitEnTrk)
593 mcHitPid[
hit.key()] = hitPidMc_0p5;
594 auto const & hout = hit_outs[
hit.key()];
598 fHitEM_mc = hitEnSh / (hitEnSh + hitEnTrk);
600 int hitPidMc_0p85 = -1;
601 double hitDep = hitEnSh + hitEnTrk;
602 if (hitEnSh > 0.85 * hitDep)
607 else if (hitEnTrk > 0.85 * hitDep)
614 bool mcMichel =
false;
624 for (
size_t i = 0; i < 100; ++i)
626 double thr = 0.01 * i;
665 if (totEnSh > 1.5 * totEnTrk)
669 else if (totEnTrk > 1.5 * totEnSh)
674 for (
size_t i = 0; i < 100; ++i)
676 double thr = 0.01 * i;
708 for (
auto const &
h : hits)
710 auto const & vout = hit_outs[
h.key()];
711 double hitPidValue = 0;
713 if (h_trk_or_sh > 0) hitPidValue = vout[
fTrkLikeIdx] / h_trk_or_sh;
716 <<
h->WireID().TPC <<
" " <<
h->WireID().Wire <<
" " <<
h->PeakTime() <<
" " 718 << mcHitPid[
h.key()] <<
" " <<
fPidValue <<
" " << hitPidValue;
art::InputTag fSimulationProducerLabel
Store parameters for running LArG4.
std::ofstream fHitsOutFile
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)
fhicl::Atom< bool > SaveHitsFile
float fHitsTrack_OK_0p5[100]
AdcChannelData::View View
std::unordered_map< int, const simb::MCParticle * > fParticleMap
float fHitsTrack_OK_0p85[100]
Declaration of signal hit object.
art::InputTag fNNetModuleLabel
int getIndex(const std::string &name) const
Index of column with given name, or -1 if name not found.
Set of hits with a 2D structure.
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.
PointIdEffTest & operator=(PointIdEffTest const &)=delete
EDAnalyzer(fhicl::ParameterSet const &pset)
int NumberDaughters() const
virtual void beginJob() override
int Daughter(const int i) const
Access the description of detector geometry.
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
float fHitsEM_OK_0p5[100]
#define DEFINE_ART_MODULE(klass)
virtual void beginRun(const art::Run &run) override
std::string EndProcess() const
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
virtual void endJob() override
std::vector< FeatureVector< N > > const & outputs() const
Access the vector of the feature vectors.
PlaneID_t Plane
Index of the plane within its TPC.
Description of geometry of one entire detector.
Declaration of cluster object.
Provides recob::Track data product.
Detector simulation of raw signals on wires.
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
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
float fHitRecoFractionEM[100]
Declaration of basic channel signal object.
float fHitsMichel_OK_0p5[100]
Collection of Physical constants used in LArSoft.
double LifetimeCorrection(double time, double T0=0) const
float fHitsEM_OK_0p85[100]
calo::CalorimetryAlg fCalorimetryAlg
static std::unique_ptr< MVAReader > create(const art::Event &evt, const art::InputTag &tag)
art::InputTag fPfpModuleLabel
double GeVToElectrons() const
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
h
training ###############################
float fHitsMichel_False_0p5[100]
fhicl::Atom< art::InputTag > NNetModuleLabel