11 #include "nusimdata/SimulationBase/MCParticle.h"
12 #include "nusimdata/SimulationBase/MCTruth.h"
15 #include "art/Framework/Core/EDAnalyzer.h"
16 #include "art/Framework/Core/ModuleMacros.h"
17 #include "art/Framework/Principal/Event.h"
18 #include "art/Framework/Principal/Handle.h"
19 #include "art/Framework/Services/Registry/ServiceHandle.h"
20 #include "art_root_io/TFileService.h"
21 #include "canvas/Persistency/Common/FindManyP.h"
22 #include "fhiclcpp/ParameterSet.h"
23 #include "messagefacility/MessageLogger/MessageLogger.h"
26 #include "TEfficiency.h"
27 #include "TGraphAsymmErrors.h"
31 #define MAX_SHOWERS 1000
43 void beginJob()
override;
44 void endJob()
override;
45 void beginRun(
const art::Run& run)
override;
49 const art::Event& evt,
54 const simb::MCParticle*& MCparticle,
59 const art::Event& evt,
61 bool insideFV(
double vertex[4]);
62 void doEfficiencies();
107 TEfficiency* h_Eff_Ev = 0;
108 TEfficiency* h_Eff_Ev_dEdx = 0;
109 TEfficiency* h_Eff_Ee = 0;
110 TEfficiency* h_Eff_Ee_dEdx = 0;
111 TEfficiency* h_Eff_Pe = 0;
112 TEfficiency* h_Eff_theta = 0;
208 double MC_incoming_P[4];
209 double MC_lepton_startMomentum[4];
210 double MC_lepton_endMomentum[4];
211 double MC_lepton_startXYZT[4];
212 double MC_lepton_endXYZT[4];
252 art::ServiceHandle<geo::Geometry const>
geom;
257 NeutrinoShowerEff::NeutrinoShowerEff(fhicl::ParameterSet
const&
p) : EDAnalyzer(p)
278 cout <<
"job begin..." << endl;
281 auto const* geo = lar::providerFrom<geo::Geometry>();
290 for (
size_t i = 0; i < geo->NTPC(); ++i) {
291 double local[3] = {0., 0., 0.};
292 double world[3] = {0., 0., 0.};
295 if (minx > world[0] - geo->DetHalfWidth(i)) minx = world[0] - geo->DetHalfWidth(i);
296 if (maxx < world[0] + geo->DetHalfWidth(i)) maxx = world[0] + geo->DetHalfWidth(i);
297 if (miny > world[1] - geo->DetHalfHeight(i)) miny = world[1] - geo->DetHalfHeight(i);
298 if (maxy < world[1] + geo->DetHalfHeight(i)) maxy = world[1] + geo->DetHalfHeight(i);
299 if (minz > world[2] - geo->DetLength(i) / 2.) minz = world[2] - geo->DetLength(i) / 2.;
300 if (maxz < world[2] + geo->DetLength(i) / 2.) maxz = world[2] + geo->DetLength(i) / 2.;
316 art::ServiceHandle<art::TFileService const>
tfs;
318 double E_bins[21] = {0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4, 4.5, 5.0,
319 5.5, 6.0, 7.0, 8.0, 10.0, 12.0, 14.0, 17.0, 20.0, 25.0};
320 double theta_bin[44] = {0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.,
321 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 22.,
322 24., 26., 28., 30., 32., 34., 36., 38., 40., 42., 44.,
323 46., 48., 50., 55., 60., 65., 70., 75., 80., 85., 90.};
327 tfs->make<TH1D>(
"h_Ev_den",
328 "Neutrino Energy; Neutrino Energy (GeV); Shower Reconstruction Efficiency",
333 tfs->make<TH1D>(
"h_Ev_num",
334 "Neutrino Energy; Neutrino Energy (GeV); Shower Reconstruction Efficiency",
339 tfs->make<TH1D>(
"h_Ev_num_dEdx",
340 "Neutrino Energy; Neutrino Energy (GeV); Shower Reconstruction Efficiency",
346 tfs->make<TH1D>(
"h_Ee_den",
347 "Electron Energy; Electron Energy (GeV); Shower Reconstruction Efficiency",
352 tfs->make<TH1D>(
"h_Ee_num",
353 "Electron Energy; Electron Energy (GeV); Shower Reconstruction Efficiency",
358 tfs->make<TH1D>(
"h_Ee_num_dEdx",
359 "Electron Energy; Electron Energy (GeV); Shower Reconstruction Efficiency",
366 "Electron Momentum; Electron Momentum (GeV); Shower reconstruction Efficiency",
372 "Electron Momentum; Electron Momentum (GeV); Shower reconstruction Efficiency",
379 "CosTheta; CosTheta w.r.t beam direction (Degrees); Shower reconstruction Efficiency",
385 "CosTheta; CosTheta w.r.t beam direction (Degrees); Shower reconstruction Efficiency",
391 "h_Efrac_shContamination",
"Efrac Lepton; Energy fraction (contamination);", 60, 0, 1.2);
394 tfs->make<TH1D>(
"h_Efrac_shPurity",
"Efrac Lepton; Energy fraction (Purity);", 60, 0, 1.2);
397 tfs->make<TH1D>(
"h_Ecomplet_lepton",
"Ecomplet Lepton; Shower Completeness;", 60, 0, 1.2);
401 tfs->make<TH1D>(
"h_HighestHitsProducedParticlePDG_NueCC",
402 "PDG Code; PDG Code;",
408 tfs->make<TH1D>(
"h_HighestHitsProducedParticlePDG_bkg",
409 "PDG Code; PDG Code;",
416 "h_Efrac_NueCCPurity",
"Efrac NueCC; Energy fraction (Purity);", 60, 0, 1.2);
419 tfs->make<TH1D>(
"h_Ecomplet_NueCC",
"Ecomplet NueCC; Shower Completeness;", 60, 0, 1.2);
423 "h_Efrac_bkgPurity",
"Efrac bkg; Energy fraction (Purity);", 60, 0, 1.2);
426 tfs->make<TH1D>(
"h_Ecomplet_bkg",
"Ecomplet bkg; Shower Completeness;", 60, 0, 1.2);
430 tfs->make<TH1D>(
"h_esh_bestplane_NueCC",
"Best plane; Best plane;", 4, -0.5, 3.5);
432 tfs->make<TH1D>(
"h_esh_bestplane_NC",
"Best plane; Best plane;", 4, -0.5, 3.5);
434 "dE/dX; Electron or Positron dE/dX (MeV/cm);",
439 "dE/dX; Electron or Positron dE/dX (MeV/cm);",
444 tfs->make<TH1D>(
"h_dEdX_photon_NueCC",
"dE/dX; photon dE/dX (MeV/cm);", 100, 0.0, 15.0);
446 tfs->make<TH1D>(
"h_dEdX_photon_NC",
"dE/dX; photon dE/dX (MeV/cm);", 100, 0.0, 15.0);
448 tfs->make<TH1D>(
"h_dEdX_proton_NueCC",
"dE/dX; proton dE/dX (MeV/cm);", 100, 0.0, 15.0);
450 tfs->make<TH1D>(
"h_dEdX_proton_NC",
"dE/dX; proton dE/dX (MeV/cm);", 100, 0.0, 15.0);
452 tfs->make<TH1D>(
"h_dEdX_neutron_NueCC",
"dE/dX; neutron dE/dX (MeV/cm);", 100, 0.0, 15.0);
454 tfs->make<TH1D>(
"h_dEdX_neutron_NC",
"dE/dX; neutron dE/dX (MeV/cm);", 100, 0.0, 15.0);
456 "h_dEdX_chargedpion_NueCC",
"dE/dX; charged pion dE/dX (MeV/cm);", 100, 0.0, 15.0);
458 "h_dEdX_chargedpion_NC",
"dE/dX; charged pion dE/dX (MeV/cm);", 100, 0.0, 15.0);
460 "h_dEdX_neutralpion_NueCC",
"dE/dX; neutral pion dE/dX (MeV/cm);", 100, 0.0, 15.0);
462 "h_dEdX_neutralpion_NC",
"dE/dX; neutral pion dE/dX (MeV/cm);", 100, 0.0, 15.0);
464 "h_dEdX_everythingelse_NueCC",
"dE/dX; everythingelse dE/dX (MeV/cm);", 100, 0.0, 15.0);
466 "h_dEdX_everythingelse_NC",
"dE/dX; everythingelse dE/dX (MeV/cm);", 100, 0.0, 15.0);
469 tfs->make<TH1D>(
"h_dEdXasymm_electronorpositron_NueCC",
470 "dE/dX asymmetry; Electron or Positron dE/dX asymmetry;",
475 "h_dEdXasymm_photon_NC",
"dE/dX asymmetry; photon dE/dx asymmetry;", 60, 0.0, 1.2);
478 tfs->make<TH1D>(
"h_mpi0_electronorpositron_NueCC",
479 "m(#gamma#gamma); Electron or Positron dE/dX (MeV/cm);",
484 "h_mpi0_photon_NC",
"m(#gamma#gamma); Electron or Positron dE/dX (MeV/cm);", 100, 0, 1);
507 h_mpi0_photon_NC->Sumw2();
509 h_trklike_em = tfs->make<TH1D>(
"h_trklike_em",
"EM hits; Track-like Score;", 100, 0, 1);
511 tfs->make<TH1D>(
"h_trklike_nonem",
"Non-EM hits; Track-like Score;", 100, 0, 1);
515 tfs->make<TH1D>(
"h_CosThetaShDirwrtTrueparticle_electronorpositron_NueCC",
516 "CosTheta; cos#theta;",
521 tfs->make<TH1D>(
"h_CosThetaShDirwrtTrueparticle_electronorpositron_NC",
522 "CosTheta;cos#theta;",
527 "h_CosThetaShDirwrtTrueparticle_photon_NueCC",
"CosTheta;cos#theta;", 110, -1.1, 1.1);
529 "h_CosThetaShDirwrtTrueparticle_photon_NC",
"CosTheta;cos#theta;", 110, -1.1, 1.1);
531 "h_CosThetaShDirwrtTrueparticle_proton_NueCC",
"CosTheta;cos#theta;", 110, -1.1, 1.1);
533 "h_CosThetaShDirwrtTrueparticle_proton_NC",
"CosTheta;cos#theta;", 110, -1.1, 1.1);
535 "h_CosThetaShDirwrtTrueparticle_chargedpion_NueCC",
"CosTheta;cos#theta;", 110, -1.1, 1.1);
537 "h_CosThetaShDirwrtTrueparticle_chargedpion_NC",
"CosTheta;cos#theta;", 110, -1.1, 1.1);
541 tfs->make<TH1D>(
"h_ShStartXwrtTrueparticleStartXDiff_electronorpositron_NueCC",
542 "ShVx-TrueParticleVx; ShVx-TrueParticleVx (cm);",
547 tfs->make<TH1D>(
"h_ShStartYwrtTrueparticleStartYDiff_electronorpositron_NueCC",
548 "ShVy-TrueParticleVy; ShVy-TrueParticleVy (cm);",
553 tfs->make<TH1D>(
"h_ShStartZwrtTrueparticleStartZDiff_electronorpositron_NueCC",
554 "ShVz-TrueParticleVz; ShVz-TrueParticleVz (cm);",
560 tfs->make<TH1D>(
"h_ShStartXwrtTrueparticleStartXDiff_electronorpositron_NC",
561 "ShVx-TrueParticleVx; ShVx-TrueParticleVx (cm);",
566 tfs->make<TH1D>(
"h_ShStartYwrtTrueparticleStartYDiff_electronorpositron_NC",
567 "ShVy-TrueParticleVy; ShVy-TrueParticleVy (cm);",
572 tfs->make<TH1D>(
"h_ShStartZwrtTrueparticleStartZDiff_electronorpositron_NC",
573 "ShVz-TrueParticleVz; ShVz-TrueParticleVz (cm);",
579 tfs->make<TH1D>(
"h_ShStartXwrtTrueparticleStartXDiff_photon_NueCC",
580 "ShVx-TrueParticleVx; ShVx-TrueParticleVx (cm);",
585 tfs->make<TH1D>(
"h_ShStartYwrtTrueparticleStartYDiff_photon_NueCC",
586 "ShVy-TrueParticleVy; ShVy-TrueParticleVy (cm);",
591 tfs->make<TH1D>(
"h_ShStartZwrtTrueparticleStartZDiff_photon_NueCC",
592 "ShVz-TrueParticleVz; ShVz-TrueParticleVz (cm);",
598 tfs->make<TH1D>(
"h_ShStartXwrtTrueparticleStartXDiff_photon_NC",
599 "ShVx-TrueParticleVx; ShVx-TrueParticleVx (cm);",
604 tfs->make<TH1D>(
"h_ShStartYwrtTrueparticleStartYDiff_photon_NC",
605 "ShVy-TrueParticleVy; ShVy-TrueParticleVy (cm);",
610 tfs->make<TH1D>(
"h_ShStartZwrtTrueparticleStartZDiff_photon_NC",
611 "ShVz-TrueParticleVz; ShVz-TrueParticleVz (cm);",
617 tfs->make<TH1D>(
"h_ShStartXwrtTrueparticleEndXDiff_photon_NueCC",
618 "ShVx-TrueParticleVx; ShVx-TrueParticleVx (cm);",
623 tfs->make<TH1D>(
"h_ShStartYwrtTrueparticleEndYDiff_photon_NueCC",
624 "ShVy-TrueParticleVy; ShVy-TrueParticleVy (cm);",
629 tfs->make<TH1D>(
"h_ShStartZwrtTrueparticleEndZDiff_photon_NueCC",
630 "ShVz-TrueParticleVz; ShVz-TrueParticleVz (cm);",
636 tfs->make<TH1D>(
"h_ShStartXwrtTrueparticleEndXDiff_photon_NC",
637 "ShVx-TrueParticleVx; ShVx-TrueParticleVx (cm);",
642 tfs->make<TH1D>(
"h_ShStartYwrtTrueparticleEndYDiff_photon_NC",
643 "ShVy-TrueParticleVy; ShVy-TrueParticleVy (cm);",
648 tfs->make<TH1D>(
"h_ShStartZwrtTrueparticleEndZDiff_photon_NC",
649 "ShVz-TrueParticleVz; ShVz-TrueParticleVz (cm);",
655 tfs->make<TH1D>(
"h_ShStartXwrtTrueparticleStartXDiff_proton_NueCC",
656 "ShVx-TrueParticleVx; ShVx-TrueParticleVx (cm);",
661 tfs->make<TH1D>(
"h_ShStartYwrtTrueparticleStartYDiff_proton_NueCC",
662 "ShVy-TrueParticleVy; ShVy-TrueParticleVy (cm);",
667 tfs->make<TH1D>(
"h_ShStartZwrtTrueparticleStartZDiff_proton_NueCC",
668 "ShVz-TrueParticleVz; ShVz-TrueParticleVz (cm);",
674 tfs->make<TH1D>(
"h_ShStartXwrtTrueparticleStartXDiff_proton_NC",
675 "ShVx-TrueParticleVx; ShVx-TrueParticleVx (cm);",
680 tfs->make<TH1D>(
"h_ShStartYwrtTrueparticleStartYDiff_proton_NC",
681 "ShVy-TrueParticleVy; ShVy-TrueParticleVy (cm);",
686 tfs->make<TH1D>(
"h_ShStartZwrtTrueparticleStartZDiff_proton_NC",
687 "ShVz-TrueParticleVz; ShVz-TrueParticleVz (cm);",
693 tfs->make<TH1D>(
"h_ShStartXwrtTrueparticleStartXDiff_chargedpion_NueCC",
694 "ShVx-TrueParticleVx; ShVx-TrueParticleVx (cm);",
699 tfs->make<TH1D>(
"h_ShStartYwrtTrueparticleStartYDiff_chargedpion_NueCC",
700 "ShVy-TrueParticleVy; ShVy-TrueParticleVy (cm);",
705 tfs->make<TH1D>(
"h_ShStartZwrtTrueparticleStartZDiff_chargedpion_NueCC",
706 "ShVz-TrueParticleVz; ShVz-TrueParticleVz (cm);",
712 tfs->make<TH1D>(
"h_ShStartXwrtTrueparticleStartXDiff_chargedpion_NC",
713 "ShVx-TrueParticleVx; ShVx-TrueParticleVx (cm);",
718 tfs->make<TH1D>(
"h_ShStartYwrtTrueparticleStartYDiff_chargedpion_NC",
719 "ShVy-TrueParticleVy; ShVy-TrueParticleVy (cm);",
724 tfs->make<TH1D>(
"h_ShStartZwrtTrueparticleStartZDiff_chargedpion_NC",
725 "ShVz-TrueParticleVz; ShVz-TrueParticleVz (cm);",
731 h_CosThetaShDirwrtTrueparticle_electronorpositron_NueCC->Sumw2();
782 fEventTree =
new TTree(
"Event",
"Event Tree from Sim & Reco");
839 mf::LogInfo(
"NeutrinoShowerEff") <<
"begin run..." << endl;
848 Event =
event.id().event();
851 bool isFiducial =
false;
853 auto const clockData =
854 art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(event);
864 const art::Event& event,
869 art::Handle<std::vector<simb::MCTruth>> MCtruthHandle;
871 std::vector<art::Ptr<simb::MCTruth>> MCtruthlist;
872 art::fill_ptr_vector(MCtruthlist, MCtruthHandle);
873 art::Ptr<simb::MCTruth> MCtruth;
876 int MCinteractions = MCtruthlist.size();
877 for (
int i = 0; i < MCinteractions; i++) {
878 MCtruth = MCtruthlist[i];
879 if (MCtruth->NeutrinoSet()) {
880 simb::MCNeutrino
nu = MCtruth->GetNeutrino();
883 else if (nu.CCNC() == 1)
885 simb::MCParticle neutrino = nu.Nu();
891 const TLorentzVector& nu_momentum = nu.Nu().Momentum(0);
893 const TLorentzVector&
vertex = neutrino.Position(0);
895 simb::MCParticle lepton = nu.Lepton();
901 simb::MCParticle* MClepton = NULL;
902 art::ServiceHandle<cheat::ParticleInventoryService const> pi_serv;
903 const sim::ParticleList& plist = pi_serv->ParticleList();
904 simb::MCParticle* particle = 0;
906 for (sim::ParticleList::const_iterator ipar = plist.begin(); ipar != plist.end(); ++ipar) {
907 particle = ipar->second;
909 particle->Mother() == 0) {
910 const TLorentzVector& lepton_momentum = particle->Momentum(0);
911 const TLorentzVector& lepton_position = particle->Position(0);
912 const TLorentzVector& lepton_positionEnd = particle->EndPosition();
913 const TLorentzVector& lepton_momentumEnd = particle->EndMomentum();
924 if (!isFiducial)
return;
933 theta_e *= (180.0 / 3.14159);
939 h_Ee_den->Fill(MC_lepton_startMomentum[3]);
950 art::Handle<std::vector<recob::Shower>> showerHandle;
952 mf::LogError(
"NeutrinoShowerEff")
956 std::vector<art::Ptr<recob::Shower>> showerlist;
957 art::fill_ptr_vector(showerlist, showerHandle);
959 art::Handle<std::vector<recob::Hit>> hitHandle;
960 std::vector<art::Ptr<recob::Hit>> all_hits;
961 if (event.getByLabel(
fHitModuleLabel, hitHandle)) { art::fill_ptr_vector(all_hits, hitHandle); }
967 double Efrac_contamination = 999.0;
968 double Efrac_contaminationNueCC = 999.0;
970 double Ecomplet_lepton = 0.0;
971 double Ecomplet_NueCC = 0.0;
972 int ParticlePDG_HighestShHits = 0;
973 int shower_bestplane = 0;
974 double Showerparticlededx_inbestplane = 0.0;
975 double dEdxasymm_largestshw = -1.;
977 int showerPDGwithHighestHitsforFillingdEdX =
980 double ShAngle = -9999.0, ShVxTrueParticleVxDiff = -9999.0, ShVyTrueParticleVyDiff = -9999.0,
981 ShVzTrueParticleVzDiff = -9999.0, ShStartVxTrueParticleEndVxDiff = -9999.0,
982 ShStartVyTrueParticleEndVyDiff = -9999.0, ShStartVzTrueParticleEndVzDiff = -9999.0;
984 const simb::MCParticle* MClepton_reco = NULL;
993 art::Ptr<recob::Shower>
shower = showerlist[i];
1002 for (
size_t j = 0; j < shower->Energy().size(); j++)
1004 for (
size_t j = 0; j < shower->MIPEnergy().size(); j++)
1006 for (
size_t j = 0; j < shower->dEdx().size(); j++)
1007 sh_dEdx[i][j] = shower->dEdx()[j];
1009 double dEdxasymm = -1;
1011 if (shower->best_plane() >= 0 && shower->best_plane() < int(shower->dEdx().size())) {
1012 dEdx0 = shower->dEdx()[shower->best_plane()];
1016 for (
int j = 0; j < 3; ++j) {
1017 if (j == shower->best_plane())
continue;
1018 if (j >=
int(shower->Energy().size()))
continue;
1019 if (shower->Energy()[j] > maxE) {
1020 maxE = shower->Energy()[j];
1021 dEdx1 = shower->dEdx()[j];
1024 if (dEdx0 || dEdx1) { dEdxasymm =
std::abs(dEdx0 - dEdx1) / (dEdx0 + dEdx1); }
1027 if (shower->best_plane() >= 0 && shower->best_plane() < int(shower->Energy().size())) {
1028 if (shower->Energy()[shower->best_plane()] > E1st) {
1033 E1st = shower->Energy()[shower->best_plane()];
1034 p1[0] = E1st * shower->Direction().X();
1035 p1[1] = E1st * shower->Direction().Y();
1036 p1[2] = E1st * shower->Direction().Z();
1039 if (shower->Energy()[shower->best_plane()] > E2nd) {
1040 E2nd = shower->Energy()[shower->best_plane()];
1041 p2[0] = E2nd * shower->Direction().X();
1042 p2[1] = E2nd * shower->Direction().Y();
1043 p2[2] = E2nd * shower->Direction().Z();
1048 std::vector<art::Ptr<recob::Hit>> sh_hits = sh_hitsAll.at(i);
1050 if (!sh_hits.size()) {
1053 art::Handle<std::vector<recob::PFParticle>> pfpHandle;
1054 std::vector<art::Ptr<recob::PFParticle>> pfps;
1055 if (event.getByLabel(
fShowerModuleLabel, pfpHandle)) art::fill_ptr_vector(pfps, pfpHandle);
1057 art::Handle<std::vector<recob::Cluster>> clusterHandle;
1058 std::vector<art::Ptr<recob::Cluster>> clusters;
1060 art::fill_ptr_vector(clusters, clusterHandle);
1064 if (fmps.isValid()) {
1065 std::vector<art::Ptr<recob::PFParticle>> pfs = fmps.at(i);
1066 for (
size_t ipf = 0; ipf < pfs.size(); ++ipf) {
1067 if (fmcp.isValid()) {
1068 std::vector<art::Ptr<recob::Cluster>> clus = fmcp.at(pfs[ipf].key());
1069 for (
size_t iclu = 0; iclu < clus.size(); ++iclu) {
1070 if (fmhc.isValid()) {
1071 std::vector<art::Ptr<recob::Hit>> hits = fmhc.at(clus[iclu].key());
1072 for (
size_t ihit = 0; ihit < hits.size(); ++ihit) {
1073 sh_hits.push_back(hits[ihit]);
1082 const simb::MCParticle* particle;
1083 double tmpEfrac_contamination =
1086 double tmpEcomplet = 0;
1088 int tmp_nHits = sh_hits.size();
1090 truthMatcher(clockData, all_hits, sh_hits, particle, tmpEfrac_contamination, tmpEcomplet);
1091 if (!particle)
continue;
1094 sh_purity[i] = 1 - tmpEfrac_contamination;
1098 sh_pdg[i] = particle->PdgCode();
1101 if (tmp_nHits > nHits) {
1103 dEdxasymm_largestshw = dEdxasymm;
1105 Ecomplet_NueCC = tmpEcomplet;
1106 Efrac_contaminationNueCC = tmpEfrac_contamination;
1112 (ShDirMag * particle->P());
1114 ShVxTrueParticleVxDiff =
sh_start_X[i] - particle->Vx();
1115 ShVyTrueParticleVyDiff =
sh_start_Y[i] - particle->Vy();
1116 ShVzTrueParticleVzDiff =
sh_start_Z[i] - particle->Vz();
1119 if (ShVxTrueParticleVxDiff > 5)
1120 ShVxTrueParticleVxDiff = 4.99;
1121 else if (ShVxTrueParticleVxDiff < -5)
1122 ShVxTrueParticleVxDiff = -5;
1123 if (ShVyTrueParticleVyDiff > 5)
1124 ShVyTrueParticleVyDiff = 4.99;
1125 else if (ShVyTrueParticleVyDiff < -5)
1126 ShVyTrueParticleVyDiff = -5;
1127 if (ShVzTrueParticleVzDiff > 5)
1128 ShVzTrueParticleVzDiff = 4.99;
1129 else if (ShVzTrueParticleVzDiff < -5)
1130 ShVzTrueParticleVzDiff = -5;
1132 ShStartVxTrueParticleEndVxDiff =
sh_start_X[i] - particle->EndX();
1133 ShStartVyTrueParticleEndVyDiff =
sh_start_Y[i] - particle->EndY();
1134 ShStartVzTrueParticleEndVzDiff =
sh_start_Z[i] - particle->EndZ();
1136 if (
std::abs(particle->PdgCode()) == 11) { ParticlePDG_HighestShHits = 1; }
1137 else if (particle->PdgCode() == 22) {
1138 ParticlePDG_HighestShHits = 2;
1141 ParticlePDG_HighestShHits = 3;
1146 shower_bestplane = shower->best_plane();
1147 if (shower_bestplane < 0 || shower_bestplane >=
int(shower->dEdx().size())) {
1149 for (
size_t i = 0; i < shower->dEdx().size(); ++i) {
1150 if (shower->dEdx()[i]) {
1151 shower_bestplane = i;
1156 if (shower_bestplane < 0 || shower_bestplane >=
int(shower->dEdx().size())) {
1158 shower_bestplane = 0;
1161 if (shower_bestplane >= 0
and shower_bestplane <
int(shower->dEdx().size()))
1162 Showerparticlededx_inbestplane = shower->dEdx()[shower_bestplane];
1164 if (
std::abs(particle->PdgCode()) == 11) {
1165 showerPDGwithHighestHitsforFillingdEdX = 1;
1167 else if (particle->PdgCode() == 22) {
1168 showerPDGwithHighestHitsforFillingdEdX = 2;
1170 else if (particle->PdgCode() == 2212) {
1171 showerPDGwithHighestHitsforFillingdEdX = 3;
1173 else if (particle->PdgCode() == 2112) {
1174 showerPDGwithHighestHitsforFillingdEdX = 4;
1176 else if (
std::abs(particle->PdgCode()) == 211) {
1177 showerPDGwithHighestHitsforFillingdEdX = 5;
1179 else if (particle->PdgCode() == 111) {
1180 showerPDGwithHighestHitsforFillingdEdX = 6;
1183 showerPDGwithHighestHitsforFillingdEdX = 7;
1193 if (tmpEcomplet > Ecomplet_lepton) {
1195 Ecomplet_lepton = tmpEcomplet;
1197 Efrac_contamination = tmpEfrac_contamination;
1198 MClepton_reco = particle;
1204 if (p1.Mag() && p2.Mag()) {
sh_mpi0 = sqrt(pow(p1.Mag() + p2.Mag(), 2) - (p1 + p2).Mag2()); }
1208 if (MClepton_reco && MClepton) {
1215 if (Efrac_contamination < fMaxEfrac && Ecomplet_lepton >
fMinCompleteness) {
1219 h_Ee_num->Fill(MC_lepton_startMomentum[3]);
1222 if (Showerparticlededx_inbestplane > 1 && Showerparticlededx_inbestplane < 3) {
1234 if (ParticlePDG_HighestShHits > 0) {
1239 if (showerPDGwithHighestHitsforFillingdEdX == 1)
1247 ShVxTrueParticleVxDiff);
1249 ShVyTrueParticleVyDiff);
1251 ShVzTrueParticleVzDiff);
1257 else if (showerPDGwithHighestHitsforFillingdEdX == 2)
1269 else if (showerPDGwithHighestHitsforFillingdEdX == 3)
1278 else if (showerPDGwithHighestHitsforFillingdEdX == 4)
1282 else if (showerPDGwithHighestHitsforFillingdEdX == 5)
1290 else if (showerPDGwithHighestHitsforFillingdEdX == 6)
1294 else if (showerPDGwithHighestHitsforFillingdEdX == 7)
1300 else if (!
MC_isCC && isFiducial) {
1303 if (ParticlePDG_HighestShHits > 0) {
1308 if (showerPDGwithHighestHitsforFillingdEdX == 1)
1317 else if (showerPDGwithHighestHitsforFillingdEdX == 2)
1334 else if (showerPDGwithHighestHitsforFillingdEdX == 3)
1343 else if (showerPDGwithHighestHitsforFillingdEdX == 4)
1347 else if (showerPDGwithHighestHitsforFillingdEdX == 5)
1355 else if (showerPDGwithHighestHitsforFillingdEdX == 6)
1359 else if (showerPDGwithHighestHitsforFillingdEdX == 7)
1366 checkCNNtrkshw<4>(clockData, event, all_hits);
1374 const simb::MCParticle*& MCparticle,
1383 art::ServiceHandle<cheat::BackTrackerService const> bt_serv;
1384 art::ServiceHandle<cheat::ParticleInventoryService const> pi_serv;
1385 std::map<int, double> trkID_E;
1386 for (
size_t j = 0; j < shower_hits.size(); ++j) {
1387 art::Ptr<recob::Hit>
hit = shower_hits[j];
1388 std::vector<sim::TrackIDE>
TrackIDs = bt_serv->HitToEveTrackIDEs(clockData, hit);
1389 for (
size_t k = 0;
k < TrackIDs.size();
k++) {
1390 if (trkID_E.find(
std::abs(TrackIDs[
k].trackID)) == trkID_E.end())
1391 trkID_E[
std::abs(TrackIDs[k].trackID)] = 0;
1392 trkID_E[
std::abs(TrackIDs[k].trackID)] += TrackIDs[
k].energy;
1395 double max_E = -999.0;
1396 double total_E = 0.0;
1398 double partial_E = 0.0;
1400 if (
empty(trkID_E))
return;
1402 for (std::map<int, double>::iterator ii = trkID_E.begin(); ii != trkID_E.end(); ++ii) {
1403 total_E += ii->second;
1404 if ((ii->second) > max_E) {
1405 partial_E = ii->second;
1407 TrackID = ii->first;
1410 MCparticle = pi_serv->TrackIdToParticle_P(TrackID);
1412 Efrac = 1 - (partial_E / total_E);
1415 double totenergy = 0;
1416 for (
size_t k = 0;
k < all_hits.size(); ++
k) {
1417 art::Ptr<recob::Hit>
hit = all_hits[
k];
1418 std::vector<sim::TrackIDE>
TrackIDs = bt_serv->HitToEveTrackIDEs(clockData, hit);
1419 for (
size_t l = 0; l < TrackIDs.size(); ++l) {
1420 if (
std::abs(TrackIDs[l].trackID) ==
TrackID) { totenergy += TrackIDs[l].energy; }
1423 Ecomplet = partial_E / totenergy;
1433 double x = vertex[0];
1434 double y = vertex[1];
1435 double z = vertex[2];
1448 art::ServiceHandle<art::TFileService const>
tfs;
1452 TGraphAsymmErrors* grEff_Ev =
h_Eff_Ev->CreateGraph();
1453 grEff_Ev->Write(
"grEff_Ev");
1459 TGraphAsymmErrors* grEff_Ev_dEdx =
h_Eff_Ev_dEdx->CreateGraph();
1460 grEff_Ev_dEdx->Write(
"grEff_Ev_dEdx");
1466 TGraphAsymmErrors* grEff_Ee =
h_Eff_Ee->CreateGraph();
1467 grEff_Ee->Write(
"grEff_Ee");
1473 TGraphAsymmErrors* grEff_Ee_dEdx =
h_Eff_Ee_dEdx->CreateGraph();
1474 grEff_Ee_dEdx->Write(
"grEff_Ee_dEdx");
1480 TGraphAsymmErrors* grEff_Pe =
h_Eff_Pe->CreateGraph();
1481 grEff_Pe->Write(
"grEff_Pe");
1486 TGraphAsymmErrors* grEff_theta =
h_Eff_theta->CreateGraph();
1487 grEff_theta->Write(
"grEff_theta");
1498 const art::Event&
evt,
1503 art::ServiceHandle<cheat::BackTrackerService const> bt_serv;
1504 art::ServiceHandle<cheat::ParticleInventoryService const> pi_serv;
1508 int trkLikeIdx = hitResults->getIndex(
"track");
1509 int emLikeIdx = hitResults->getIndex(
"em");
1510 if ((trkLikeIdx < 0) || (emLikeIdx < 0)) {
1511 throw cet::exception(
"NeutrinoShowerEff")
1512 <<
"No em/track labeled columns in MVA data products." << std::endl;
1515 for (
size_t i = 0; i < all_hits.size(); ++i) {
1517 bool isEMparticle =
false;
1519 std::vector<sim::TrackIDE>
TrackIDs = bt_serv->HitToEveTrackIDEs(clockData, all_hits[i]);
1520 if (!TrackIDs.size())
continue;
1522 int trkid = INT_MAX;
1524 for (
size_t k = 0;
k < TrackIDs.size();
k++) {
1525 if (TrackIDs[
k].energy > maxE) {
1526 maxE = TrackIDs[
k].energy;
1527 trkid = TrackIDs[
k].trackID;
1530 if (trkid != INT_MAX) {
1531 auto* particle = pi_serv->TrackIdToParticle_P(trkid);
1533 pdg = particle->PdgCode();
1537 isEMparticle =
true;
1541 auto vout = hitResults->getOutput(all_hits[i]);
1542 double trk_like = -1, trk_or_em = vout[trkLikeIdx] + vout[emLikeIdx];
1543 if (trk_or_em > 0) {
1544 trk_like = vout[trkLikeIdx] / trk_or_em;
1553 std::cout <<
"Couldn't get hitResults." << std::endl;
1587 for (
int j = 0; j < 3; j++) {
process_name opflash particleana ie ie ie z
process_name opflashCryo1 flashfilter analyze
double sh_length[MAX_SHOWERS]
TH1D * h_ShStartXwrtTrueparticleStartXDiff_electronorpositron_NC
void checkCNNtrkshw(detinfo::DetectorClocksData const &clockData, const art::Event &evt, std::vector< art::Ptr< recob::Hit >> all_hits)
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
TH1D * h_CosThetaShDirwrtTrueparticle_photon_NC
TH1D * h_ShStartZwrtTrueparticleStartZDiff_proton_NueCC
TH1D * h_ShStartXwrtTrueparticleEndXDiff_photon_NC
Utilities related to art service access.
double sh_energy[MAX_SHOWERS][3]
TH1D * h_dEdX_electronorpositron_NueCC
TH1D * h_ShStartXwrtTrueparticleStartXDiff_chargedpion_NC
process_name opflash particleana ie x
TH1D * h_ShStartYwrtTrueparticleEndYDiff_photon_NC
double sh_direction_X[MAX_SHOWERS]
TH1D * h_dEdX_everythingelse_NC
std::vector< TrackID > TrackIDs
TH1D * h_dEdX_neutron_NueCC
TH1D * h_CosThetaShDirwrtTrueparticle_proton_NC
TH1D * h_ShStartYwrtTrueparticleStartYDiff_electronorpositron_NC
Geometry information for a single TPC.
TH1D * h_HighestHitsProducedParticlePDG_NueCC
double sh_dEdx[MAX_SHOWERS][3]
art::InputTag fMCTruthModuleLabel
void analyze(const art::Event &evt) override
TH1D * h_ShStartZwrtTrueparticleEndZDiff_photon_NueCC
TH1D * h_dEdXasymm_photon_NC
void truthMatcher(detinfo::DetectorClocksData const &clockData, std::vector< art::Ptr< recob::Hit >> all_hits, std::vector< art::Ptr< recob::Hit >> shower_hits, const simb::MCParticle *&MCparticle, double &Efrac, double &Ecomplet)
TH1D * h_ShStartXwrtTrueparticleStartXDiff_chargedpion_NueCC
TH1D * h_ShStartZwrtTrueparticleStartZDiff_chargedpion_NC
TH1D * h_ShStartXwrtTrueparticleStartXDiff_electronorpositron_NueCC
TH1D * h_mpi0_electronorpositron_NueCC
TH1D * h_CosThetaShDirwrtTrueparticle_electronorpositron_NC
TH1D * h_ShStartXwrtTrueparticleStartXDiff_proton_NC
TH1D * h_ShStartXwrtTrueparticleStartXDiff_photon_NueCC
TH1D * h_CosThetaShDirwrtTrueparticle_photon_NueCC
TH1D * h_ShStartYwrtTrueparticleStartYDiff_electronorpositron_NueCC
TH1D * h_ShStartYwrtTrueparticleStartYDiff_proton_NueCC
TEfficiency * h_Eff_Ev_dEdx
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
TH1D * h_ShStartZwrtTrueparticleStartZDiff_chargedpion_NueCC
TH1D * h_dEdX_chargedpion_NueCC
process_name opflash particleana ie ie y
TH1D * h_ShStartYwrtTrueparticleEndYDiff_photon_NueCC
TH1D * h_ShStartZwrtTrueparticleStartZDiff_photon_NC
double sh_purity[MAX_SHOWERS]
TH1D * h_ShStartZwrtTrueparticleStartZDiff_proton_NC
double sh_completeness[MAX_SHOWERS]
art::InputTag fShowerModuleLabel
art::InputTag fHitModuleLabel
int sh_bestplane[MAX_SHOWERS]
int sh_hasPrimary_e[MAX_SHOWERS]
double sh_dEdxasymm[MAX_SHOWERS]
double sh_direction_Z[MAX_SHOWERS]
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
TH1D * h_esh_bestplane_NC
double sh_start_Y[MAX_SHOWERS]
TEfficiency * h_Eff_Ee_dEdx
bool insideFV(double vertex[4])
double sh_direction_Y[MAX_SHOWERS]
double sh_start_X[MAX_SHOWERS]
TH1D * h_CosThetaShDirwrtTrueparticle_proton_NueCC
The standard subrun data definition.
TH1D * h_ShStartYwrtTrueparticleStartYDiff_photon_NueCC
Declaration of cluster object.
TH1D * h_ShStartZwrtTrueparticleStartZDiff_photon_NueCC
TH1D * h_CosThetaShDirwrtTrueparticle_chargedpion_NC
TH1D * h_ShStartYwrtTrueparticleStartYDiff_chargedpion_NC
TH1D * h_CosThetaShDirwrtTrueparticle_chargedpion_NueCC
double sh_start_Z[MAX_SHOWERS]
double MC_lepton_endMomentum[4]
TH1D * h_dEdX_neutralpion_NueCC
TH1D * h_ShStartZwrtTrueparticleStartZDiff_electronorpositron_NueCC
TH1D * h_dEdX_neutralpion_NC
TH1D * h_Efrac_NueCCPurity
double MC_lepton_startMomentum[4]
TH1D * h_ShStartXwrtTrueparticleEndXDiff_photon_NueCC
TH1D * h_HighestHitsProducedParticlePDG_bkg
TH1D * h_ShStartYwrtTrueparticleStartYDiff_chargedpion_NueCC
TH1D * h_dEdX_electronorpositron_NC
art::InputTag fCNNEMModuleLabel
Contains all timing reference information for the detector.
TH1D * h_ShStartXwrtTrueparticleStartXDiff_proton_NueCC
double MC_lepton_startXYZT[4]
void processEff(detinfo::DetectorClocksData const &clockData, const art::Event &evt, bool &isFiducial)
TH1D * h_ShStartYwrtTrueparticleStartYDiff_proton_NC
TH1D * h_dEdXasymm_electronorpositron_NueCC
TH1D * h_esh_bestplane_NueCC
TH1D * h_dEdX_chargedpion_NC
art::ServiceHandle< art::TFileService > tfs
TH1D * h_dEdX_proton_NueCC
TH1D * h_ShStartXwrtTrueparticleStartXDiff_photon_NC
void beginRun(const art::Run &run) override
TH1D * h_ShStartYwrtTrueparticleStartYDiff_photon_NC
TH1D * h_Efrac_shContamination
double sh_Efrac_contamination[MAX_SHOWERS]
TH1D * h_ShStartZwrtTrueparticleStartZDiff_electronorpositron_NC
double sh_MIPenergy[MAX_SHOWERS][3]
TEfficiency * h_Eff_theta
bool empty(FixedBins< T, C > const &) noexcept
TH1D * h_dEdX_photon_NueCC
TH1D * h_dEdX_everythingelse_NueCC
void LocalToWorld(const double *tpc, double *world) const
Transform point from local TPC frame to world frame.
art::ServiceHandle< geo::Geometry const > geom
static std::unique_ptr< MVAReader > create(const art::Event &evt, const art::InputTag &tag)
physics associatedGroupsWithLeft p1
art framework interface to geometry description
BEGIN_PROLOG could also be cout
TH1D * h_ShStartZwrtTrueparticleEndZDiff_photon_NC
TH1D * h_CosThetaShDirwrtTrueparticle_electronorpositron_NueCC
int sh_nHits[MAX_SHOWERS]
double MC_lepton_endXYZT[4]