34 #include "art_root_io/TFileService.h" 35 #include "canvas/Persistency/Common/FindManyP.h" 64 Name(
"CalorimetryAlg"),
65 Comment(
"Used to calculate electron lifetime correction.")};
68 Comment(
"Simulation producer")};
71 Name(
"PfpModuleLabel"),
72 Comment(
"PFP producer tag, to compare with NNet results")};
100 float& trackLike)
const;
104 const std::vector<recob::PFParticle>& pfparticles,
105 const art::FindManyP<recob::Cluster>& pfpclus,
106 const art::FindManyP<recob::Hit>& cluhits,
108 float& trackLike)
const;
111 const std::unordered_map<int, const simb::MCParticle*>& particleMap)
const;
115 const std::vector<sim::SimChannel>&
channels,
117 const std::array<float, MVA_LENGTH>& cnn_out,
194 fEventTree = tfs->make<TTree>(
"event",
"event info");
222 fClusterTree = tfs->make<TTree>(
"cluster",
"clusters info");
228 fHitTree = tfs->make<TTree>(
"hits",
"hits info");
244 for (
size_t i = 0; i < 100; ++i) {
259 TTree* thrTree = tfs->make<TTree>(
"threshold",
"error rate vs threshold");
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");
266 for (
size_t i = 0; i < 100; ++i) {
293 for (
size_t i = 0; i < 100; ++i) {
322 for (
auto const& particle : *particleHandle) {
338 const art::FindManyP<recob::Cluster> clusFromPfps(pfpHandle, e,
fPfpModuleLabel);
339 const art::FindManyP<recob::Hit> hitsFromClus(cluHandle, e,
fPfpModuleLabel);
354 <<
"No em/track labeled columns in MVA data products." <<
std::endl;
360 const art::FindManyP<recob::Hit> hitsFromClusters(
361 cluResults->dataHandle(),
e, cluResults->dataTag());
363 for (
size_t c = 0;
c < cluResults->size(); ++
c) {
368 const std::vector<art::Ptr<recob::Hit>>& hits = hitsFromClusters.at(
c);
369 std::array<float, MVA_LENGTH> cnn_out = cluResults->getOutput(
c);
397 for (
size_t i = 0; i < 100; ++i) {
403 if (fHitTrack_0p5 > 0)
427 mf::LogWarning(
"TrainingDataAlg") <<
"MVA FOR CLUSTERS NOT FOUND";
437 float& trackLike)
const 441 for (
auto const&
channel : channels) {
443 auto const& timeSlices =
channel.TDCIDEMap();
444 for (
auto const& timeSlice : timeSlices) {
446 auto const& energyDeposits = timeSlice.second;
447 for (
auto const& energyDeposit : energyDeposits) {
448 int trackID = energyDeposit.trackID;
452 if (trackID < 0) { emLike +=
energy; }
453 else if (trackID > 0) {
464 if (!pdg) pdg = particle.
PdgCode();
467 if ((pdg == 11) || (pdg == -11) || (pdg == 22))
481 const std::vector<recob::PFParticle>& pfparticles,
482 const art::FindManyP<recob::Cluster>& pfpclus,
483 const art::FindManyP<recob::Hit>& cluhits,
485 float& trackLike)
const 489 for (
size_t i = 0; i < pfparticles.size(); ++i) {
490 const auto& pfp = pfparticles[i];
491 const auto& clus = pfpclus.at(i);
494 for (
const auto&
c : clus) {
495 const auto& hits = cluhits.at(
c.key());
496 for (
const auto&
h : hits) {
504 if ((pfp.PdgCode() == 11) || pfp.PdgCode() == -11) { emLike += hitdep; }
515 const std::unordered_map<int, const simb::MCParticle*>& particleMap)
const 517 bool hasElectron =
false, hasNuMu =
false, hasNuE =
false;
520 if ((pdg == 13) && (particle.
EndProcess() ==
"FastScintillation"))
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());
530 else if (d_pdg == 14)
532 else if (d_pdg == 12)
538 return (hasElectron && hasNuMu && hasNuE);
545 const std::vector<sim::SimChannel>&
channels,
547 const std::array<float, MVA_LENGTH>& cnn_out,
553 std::unordered_map<int, int> mcHitPid;
562 double totEnSh = 0, totEnTrk = 0, totEnMichel = 0;
563 for (
auto const&
hit : hits) {
565 auto hitChannelNumber =
hit->Channel();
567 double hitEn = 0, hitEnSh = 0, hitEnTrk = 0, hitEnMichel = 0;
569 auto const& vout = hit_outs[
hit.key()];
575 for (
auto const&
channel : channels) {
576 if (
channel.Channel() != hitChannelNumber)
continue;
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) {
584 auto const& energyDeposits = timeSlice.second;
586 for (
auto const& energyDeposit : energyDeposits) {
587 int trackID = energyDeposit.trackID;
592 if (trackID < 0) { hitEnSh +=
energy; }
593 else if (trackID > 0) {
599 if ((pdg == 11) || (pdg == -11) || (pdg == 22))
608 auto const& mother = *((*msearch).second);
622 totEnTrk += hitEnTrk;
623 totEnMichel += hitEnMichel;
629 int hitPidMc_0p5 = -1;
630 if (hitEnSh > hitEnTrk) {
638 mcHitPid[
hit.key()] = hitPidMc_0p5;
639 auto const& hout = hit_outs[
hit.key()];
643 fHitEM_mc = hitEnSh / (hitEnSh + hitEnTrk);
645 int hitPidMc_0p85 = -1;
646 double hitDep = hitEnSh + hitEnTrk;
647 if (hitEnSh > 0.85 * hitDep) {
652 else if (hitEnTrk > 0.85 * hitDep) {
658 bool mcMichel =
false;
668 for (
size_t i = 0; i < 100; ++i) {
669 double thr = 0.01 * i;
671 if (p_michel > thr) {
709 if (totEnSh > 1.5 * totEnTrk)
713 else if (totEnTrk > 1.5 * totEnSh) {
717 for (
size_t i = 0; i < 100; ++i) {
718 double thr = 0.01 * i;
748 for (
auto const&
h : hits) {
749 auto const& vout = hit_outs[
h.key()];
750 double hitPidValue = 0;
752 if (h_trk_or_sh > 0) hitPidValue = vout[
fTrkLikeIdx] / h_trk_or_sh;
755 <<
" " <<
h->PeakTime() <<
" " 758 <<
" " << mcHitPid[
h.key()] <<
" " <<
fPidValue <<
" " << hitPidValue;
float fHitsTrack_OK_0p85[100]
art::InputTag fSimulationProducerLabel
Store parameters for running LArG4.
std::ofstream fHitsOutFile
AdcChannelData::View View
float fHitsMichel_OK_0p5[100]
ChannelGroupService::Name Name
art::InputTag fNNetModuleLabel
int getIndex(const std::string &name) const
Index of column with given name, or -1 if name not found.
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.
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)
fhicl::Atom< bool > SaveHitsFile
int NumberDaughters() const
int Daughter(const int i) const
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
#define DEFINE_ART_MODULE(klass)
void beginRun(const art::Run &run) override
std::string EndProcess() 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)
bool isMuonDecaying(const simb::MCParticle &particle, const std::unordered_map< int, const simb::MCParticle * > &particleMap) const
float fHitsEM_OK_0p5[100]
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
float fHitsTrack_OK_0p5[100]
fhicl::Atom< art::InputTag > PfpModuleLabel
std::vector< FeatureVector< N > > const & outputs() const
Access the vector of the feature vectors.
PlaneID_t Plane
Index of the plane within its TPC.
fhicl::Table< calo::CalorimetryAlg::Config > CalorimetryAlg
float fHitRecoFractionEM[100]
Detector simulation of raw signals on wires.
Declaration of signal hit object.
fhicl::Atom< art::InputTag > SimModuleLabel
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
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.
float fHitsMichel_False_0p5[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
float fHitsEM_OK_0p85[100]
QTextStream & endl(QTextStream &s)