19 #include "art_root_io/TFileService.h" 36 #include "TEfficiency.h" 37 #include "TGraphAsymmErrors.h" 42 #define MAX_SHOWERS 1000 66 void endJob()
override;
67 void beginRun(
art::Run const& run)
override;
68 void doEfficiencies();
69 bool insideFV(
double vertex[4]);
113 double MC_incoming_P[4];
114 double MC_lepton_startMomentum[4];
115 double MC_lepton_endMomentum[40];
116 double MC_lepton_startXYZT[4];
117 double MC_lepton_endXYZT[4];
158 TEfficiency* h_Eff_Ev = 0;
159 TEfficiency* h_Eff_Ee = 0;
165 , fMCTruthModuleLabel(p.
get<
std::string>(
"MCTruthModuleLabel"))
166 , fHitModuleLabel(p.
get<
std::string>(
"HitModuleLabel"))
167 , fShowerModuleLabel(p.
get<
std::string>(
"ShowerModuleLabel"))
168 , fTruthMatchDataModuleLabel(p.
get<
std::string>(
"TruthMatchDataModuleLabel"))
169 , fNeutrinoPDGcode(p.
get<int>(
"NeutrinoPDGcode"))
170 , fLeptonPDGcode(p.
get<int>(
"LeptonPDGcode"))
171 , fSaveMCTree(p.
get<bool>(
"SaveMCTree"))
172 , fHitShowerThroughPFParticle(p.
get<bool>(
"HitShowerThroughPFParticle"))
173 , fMinPurity(p.
get<double>(
"MinPurity"))
174 , fMinCompleteness(p.
get<double>(
"MinCompleteness"))
175 , fFidVolCutX(p.
get<float>(
"FidVolCutX"))
176 , fFidVolCutY(p.
get<float>(
"FidVolCutY"))
177 , fFidVolCutZ(p.
get<float>(
"FidVolCutZ"))
184 auto const*
geo = lar::providerFrom<geo::Geometry>();
192 auto const world = tpc.GetCenter();
194 if (minx > world.X() - tpc.HalfWidth()) minx = world.X() - tpc.HalfWidth();
195 if (maxx < world.X() + tpc.HalfWidth()) maxx = world.X() + tpc.HalfWidth();
196 if (miny > world.Y() - tpc.HalfHeight()) miny = world.Y() - tpc.HalfHeight();
197 if (maxy < world.Y() + tpc.HalfHeight()) maxy = world.Y() + tpc.HalfHeight();
198 if (minz > world.Z() - tpc.Length() / 2.) minz = world.Z() - tpc.Length() / 2.;
199 if (maxz < world.Z() + tpc.Length() / 2.) maxz = world.Z() + tpc.Length() / 2.;
211 double E_bins[21] = {0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4, 4.5, 5.0,
212 5.5, 6.0, 7.0, 8.0, 10.0, 12.0, 14.0, 17.0, 20.0, 25.0};
215 tfs->make<TH1D>(
"h_Ev_den",
216 "Neutrino Energy; Neutrino Energy (GeV); Shower Reconstruction Efficiency",
221 tfs->make<TH1D>(
"h_Ev_num",
222 "Neutrino Energy; Neutrino Energy (GeV); Shower Reconstruction Efficiency",
228 tfs->make<TH1D>(
"h_Ee_den",
229 "Electron Energy; Electron Energy (GeV); Shower Reconstruction Efficiency",
234 tfs->make<TH1D>(
"h_Ee_num",
235 "Electron Energy; Electron Energy (GeV); Shower Reconstruction Efficiency",
241 fEventTree =
new TTree(
"Event",
"Event Tree from Sim & Reco");
255 "esh_each_purity", &
esh_each_purity,
"esh_each_purity[count_primary_e_in_Event]/D");
258 "esh_each_completeness[count_primary_e_in_Event]/D");
273 mf::LogInfo(
"ShowerEff") <<
"==== begin run ... ====" << endl;
289 std::vector<art::Ptr<simb::MCTruth>> MCtruthlist;
293 int MCinteractions = MCtruthlist.size();
294 for (
int i = 0; i < MCinteractions; i++) {
295 MCtruth = MCtruthlist[i];
300 else if (nu.
CCNC() == 1)
308 const TLorentzVector& nu_momentum = nu.
Nu().
Momentum(0);
327 particle = ipar->second;
331 particle->
Mother() == 0) {
332 const TLorentzVector& lepton_momentum = particle->
Momentum(0);
333 const TLorentzVector& lepton_position = particle->
Position(0);
334 const TLorentzVector& lepton_positionEnd = particle->
EndPosition();
335 const TLorentzVector& lepton_momentumEnd = particle->
EndMomentum();
348 bool isFiducial =
false;
350 if (!isFiducial) {
return; }
363 std::vector<art::Ptr<recob::Hit>> all_hits;
366 double ehit_total = 0.0;
371 std::map<int, double> all_hits_trk_Q;
372 for (
size_t i = 0; i < all_hits.size(); ++i) {
375 fmhitmc.at(hit.
key());
376 auto hitmatch = fmhitmc.
data(hit.
key());
377 double maxenergy = -1e9;
379 for (
size_t j = 0; j < particles.size(); ++j) {
380 if (!particles[j])
continue;
384 if ((hitmatch[j]->
energy) > maxenergy) {
385 maxenergy = hitmatch[j]->energy;
390 all_hits_trk_Q[hit_TrackId] +=
398 double temp_sh_ehit_Q = 0.0;
399 double temp_sh_allHit_Q = 0.0;
400 int temp_sh_TrackId = -999;
404 std::vector<art::Ptr<recob::Shower>> showerlist;
411 std::map<int, double> showers_trk_Q;
415 std::map<int, double> sh_hits_trk_Q;
416 sh_hits_trk_Q.clear();
428 std::vector<art::Ptr<recob::Hit>> sh_hits;
436 std::vector<art::Ptr<recob::PFParticle>> pfps;
440 std::vector<art::Ptr<recob::Cluster>> clusters;
448 if (fmps.isValid()) {
449 std::vector<art::Ptr<recob::PFParticle>> pfs = fmps.at(i);
450 for (
size_t ipf = 0; ipf < pfs.size(); ++ipf) {
451 if (fmcp.isValid()) {
452 std::vector<art::Ptr<recob::Cluster>> clus = fmcp.at(pfs[ipf].key());
453 for (
size_t iclu = 0; iclu < clus.size(); ++iclu) {
454 if (fmhc.isValid()) {
455 std::vector<art::Ptr<recob::Hit>>
hits = fmhc.at(clus[iclu].key());
456 for (
size_t ihit = 0; ihit < hits.size(); ++ihit) {
457 sh_hits.push_back(hits[ihit]);
472 for (
size_t k = 0; k < sh_hits.size(); ++k) {
474 auto particles = fmhitmc.at(hit.
key());
475 auto hitmatch = fmhitmc.
data(hit.
key());
476 double maxenergy = -1e9;
478 for (
size_t j = 0; j < particles.size(); ++j) {
479 if (!particles[j])
continue;
483 if ((hitmatch[j]->
energy) > maxenergy) {
484 maxenergy = hitmatch[j]->energy;
490 sh_hits_trk_Q[hit_TrackId] += hit->
Integral();
494 double maxshowerQ = -1.0e9;
496 if (k->second > maxshowerQ) {
497 maxshowerQ = k->second;
532 if (MClepton_reco && MClepton) {
535 if ((temp_sh_allHit_Q >= temp_sh_ehit_Q) && (temp_sh_ehit_Q > 0.0)) {
536 esh_purity = temp_sh_ehit_Q / temp_sh_allHit_Q;
553 double temp_esh_1_allhit = -1.0e9;
554 int temp_shower_index = -999;
555 int temp_esh_index = 0;
569 temp_shower_index = i;
590 TGraphAsymmErrors* grEff_Ev =
h_Eff_Ev->CreateGraph();
591 grEff_Ev->Write(
"grEff_Ev");
597 TGraphAsymmErrors* grEff_Ee =
h_Eff_Ee->CreateGraph();
598 grEff_Ee->Write(
"grEff_Ee");
606 double x = vertex[0];
607 double y = vertex[1];
608 double z = vertex[2];
double esh_each_purity[MAX_SHOWERS]
double sh_direction_X[MAX_SHOWERS]
SubRunNumber_t subRun() const
const TVector3 & ShowerStart() const
const TLorentzVector & Position(const int i=0) const
const simb::MCNeutrino & GetNeutrino() const
double MC_lepton_startEnergy
Utilities related to art service access.
const TLorentzVector & EndPosition() const
double esh_1_completeness
NuShowerEff(fhicl::ParameterSet const &p)
double sh_start_Y[MAX_SHOWERS]
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
const simb::MCParticle * TrackIdToParticle_P(int id) const
Declaration of signal hit object.
const simb::MCParticle & Nu() const
int count_primary_e_in_Event
list_type::const_iterator const_iterator
Geometry information for a single TPC.
double sh_direction_Y[MAX_SHOWERS]
constexpr auto abs(T v)
Returns the absolute value of the argument.
std::string fMCTruthModuleLabel
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
data_const_reference data(size_type i) const
double MC_lepton_startMomentum[4]
const art::Ptr< simb::MCTruth > & ParticleToMCTruth_P(const simb::MCParticle *p) const
bool fHitShowerThroughPFParticle
int sh_TrackId[MAX_SHOWERS]
std::string fShowerModuleLabel
int InteractionType() const
const simb::MCParticle & Lepton() const
#define DEFINE_ART_MODULE(klass)
std::string fHitModuleLabel
double esh_each_completeness[MAX_SHOWERS]
int sh_hasPrimary_e[MAX_SHOWERS]
void analyze(art::Event const &e) override
key_type key() const noexcept
bool insideFV(double vertex[4])
const TVector3 & Direction() const
double sh_start_Z[MAX_SHOWERS]
Declaration of cluster object.
double sh_purity[MAX_SHOWERS]
Detector simulation of raw signals on wires.
const sim::ParticleList & ParticleList() const
double sh_ehit_Q[MAX_SHOWERS]
double MC_lepton_startXYZT[4]
double MC_lepton_endXYZT[4]
double sh_direction_Z[MAX_SHOWERS]
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
double sh_completeness[MAX_SHOWERS]
double MC_lepton_endMomentum[40]
double sh_allhit_Q[MAX_SHOWERS]
const TLorentzVector & Momentum(const int i=0) const
EventNumber_t event() const
void beginRun(art::Run const &run) override
std::string fTruthMatchDataModuleLabel
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
const simb::MCParticle * TrackIdToMotherParticle_P(int id) const
Event generator information.
Namespace collecting geometry-related classes utilities.
double sh_start_X[MAX_SHOWERS]
const TLorentzVector & EndMomentum() const
art framework interface to geometry description
double sh_length[MAX_SHOWERS]