52 #include "TDirectory.h" 54 #include "TEfficiency.h" 55 #include "TGraphAsymmErrors.h" 58 #define MAX_SHOWERS 1000 82 void endJob()
override;
83 void beginRun(
art::Run const& run)
override;
84 void doEfficiencies();
85 bool insideFV(
double vertex[4]);
131 double MC_incoming_P[4];
132 double MC_lepton_startMomentum[4];
133 double MC_lepton_endMomentum[40];
134 double MC_lepton_startXYZT[4];
135 double MC_lepton_endXYZT[4];
175 TEfficiency* h_Eff_Ev = 0;
176 TEfficiency* h_Eff_Ee = 0;
187 fMCTruthModuleLabel (p.
get<
std::string >(
"MCTruthModuleLabel")),
188 fHitModuleLabel (p.
get<
std::string >(
"HitModuleLabel")),
189 fShowerModuleLabel (p.
get<
std::string >(
"ShowerModuleLabel")),
190 fTruthMatchDataModuleLabel (p.
get<
std::string >(
"TruthMatchDataModuleLabel")),
191 fNeutrinoPDGcode (p.
get<int>(
"NeutrinoPDGcode")),
192 fLeptonPDGcode (p.
get<int>(
"LeptonPDGcode")),
193 fSaveMCTree (p.
get<bool>(
"SaveMCTree")),
194 fHitShowerThroughPFParticle (p.
get<bool>(
"HitShowerThroughPFParticle")),
195 fMinPurity (p.
get<double>(
"MinPurity")),
196 fMinCompleteness (p.
get<double>(
"MinCompleteness")),
197 fFidVolCutX (p.
get<float>(
"FidVolCutX")),
198 fFidVolCutY (p.
get<float>(
"FidVolCutY")),
199 fFidVolCutZ (p.
get<float>(
"FidVolCutZ"))
209 auto const*
geo = lar::providerFrom<geo::Geometry>();
217 for (
size_t i = 0; i<
geo->NTPC(); ++i){
218 double local[3] = {0.,0.,0.};
219 double world[3] = {0.,0.,0.};
228 if (minx > world[0] -
geo->DetHalfWidth(i)) minx = world[0]-
geo->DetHalfWidth(i);
229 if (maxx < world[0] +
geo->DetHalfWidth(i)) maxx = world[0]+
geo->DetHalfWidth(i);
230 if (miny > world[1] -
geo->DetHalfHeight(i)) miny = world[1]-
geo->DetHalfHeight(i);
231 if (maxy < world[1] +
geo->DetHalfHeight(i)) maxy = world[1]+
geo->DetHalfHeight(i);
232 if (minz > world[2] -
geo->DetLength(i)/2.) minz = world[2]-
geo->DetLength(i)/2.;
233 if (maxz < world[2] +
geo->DetLength(i)/2.) maxz = world[2]+
geo->DetLength(i)/2.;
250 double E_bins[21] = {0,0.5,1.0,1.5,2.0,2.5,3.0,3.5,4,4.5,5.0,5.5,6.0,7.0,8.0,10.0,12.0,14.0,17.0,20.0,25.0};
254 h_Ev_den = tfs->
make<TH1D>(
"h_Ev_den",
"Neutrino Energy; Neutrino Energy (GeV); Shower Reconstruction Efficiency", 20, E_bins);
256 h_Ev_num = tfs->
make<TH1D>(
"h_Ev_num",
"Neutrino Energy; Neutrino Energy (GeV); Shower Reconstruction Efficiency",20,E_bins);
259 h_Ee_den = tfs->
make<TH1D>(
"h_Ee_den",
"Electron Energy; Electron Energy (GeV); Shower Reconstruction Efficiency",20,E_bins);
261 h_Ee_num = tfs->
make<TH1D>(
"h_Ee_num",
"Electron Energy; Electron Energy (GeV); Shower Reconstruction Efficiency",20,E_bins);
265 fEventTree =
new TTree(
"Event",
"Event Tree from Sim & Reco");
297 mf::LogInfo(
"ShowerEff") <<
"==== begin run ... ====" << endl;
321 std::vector<art::Ptr<simb::MCTruth>> MCtruthlist;
325 int MCinteractions = MCtruthlist.size();
327 for (
int i=0; i<MCinteractions; i++){
328 MCtruth = MCtruthlist[i];
339 const TLorentzVector& nu_momentum = nu.
Nu().
Momentum(0);
356 int nParticles = MCtruthlist[0]->NParticles();
358 for (
int i=0; i<nParticles; i++){
375 particle = ipar->second;
379 const TLorentzVector& lepton_momentum =particle->
Momentum(0);
380 const TLorentzVector& lepton_position =particle->
Position(0);
381 const TLorentzVector& lepton_positionEnd = particle->
EndPosition();
382 const TLorentzVector& lepton_momentumEnd = particle->
EndMomentum();
399 bool isFiducial =
false;
428 std::vector<art::Ptr<recob::Hit>> all_hits;
435 double ehit_total =0.0;
439 std::map<int,double> all_hits_trk_Q;
440 for (
size_t i=0; i < all_hits.size(); ++i) {
442 auto particles = fmhitmc.at(hit.
key());
443 auto hitmatch = fmhitmc.
data(hit.
key());
444 double maxenergy = -1e9;
446 for (
size_t j = 0; j < particles.size(); ++j){
447 if (!particles[j])
continue;
451 if ( (hitmatch[j]->
energy) > maxenergy ){
452 maxenergy = hitmatch[j]->energy;
457 all_hits_trk_Q[hit_TrackId] += hit->
Integral();
466 double temp_sh_ehit_Q = 0.0;
467 double temp_sh_allHit_Q = 0.0;
468 int temp_sh_TrackId = -999;
472 std::vector<art::Ptr<recob::Shower>> showerlist;
482 std::map<int,double> showers_trk_Q;
487 std::map<int,double> sh_hits_trk_Q;
488 sh_hits_trk_Q.clear();
504 std::vector<art::Ptr<recob::Hit>> sh_hits;
514 std::vector<art::Ptr<recob::PFParticle> > pfps;
518 std::vector<art::Ptr<recob::Cluster> > clusters;
524 std::vector<art::Ptr<recob::PFParticle>> pfs = fmps.at(i);
525 for (
size_t ipf = 0; ipf<pfs.size(); ++ipf){
527 std::vector<art::Ptr<recob::Cluster>> clus = fmcp.at(pfs[ipf].key());
528 for (
size_t iclu = 0; iclu<clus.size(); ++iclu){
530 std::vector<art::Ptr<recob::Hit>>
hits = fmhc.at(clus[iclu].key());
531 for (
size_t ihit = 0; ihit<hits.size(); ++ihit){
532 sh_hits.push_back(hits[ihit]);
550 sh_hits = sh_hitsAll.at(i);
555 for (
size_t k=0; k < sh_hits.size(); ++k) {
557 auto particles = fmhitmc.at(hit.
key());
558 auto hitmatch = fmhitmc.
data(hit.
key());
559 double maxenergy = -1e9;
561 for (
size_t j = 0; j < particles.size(); ++j){
562 if (!particles[j])
continue;
566 if ( (hitmatch[j]->
energy) > maxenergy ){
567 maxenergy = hitmatch[j]->energy;
575 sh_hits_trk_Q[hit_TrackId] += hit->
Integral();
581 double maxshowerQ = -1.0e9;
585 if (k->second > maxshowerQ) {
586 maxshowerQ = k->second;
623 if (MClepton_reco && MClepton) {
625 if ((temp_sh_allHit_Q >= temp_sh_ehit_Q) && (temp_sh_ehit_Q > 0.0)) {
646 double temp_esh_1_allhit = -1.0e9;
647 int temp_shower_index = -999;
648 int temp_esh_index = 0;
662 temp_shower_index = i;
685 TGraphAsymmErrors *grEff_Ev =
h_Eff_Ev->CreateGraph();
686 grEff_Ev->Write(
"grEff_Ev");
692 TGraphAsymmErrors *grEff_Ee =
h_Eff_Ee->CreateGraph();
693 grEff_Ee->Write(
"grEff_Ee");
702 double x = vertex[0];
703 double y = vertex[1];
704 double z = vertex[2];
double esh_each_purity[MAX_SHOWERS]
double sh_direction_X[MAX_SHOWERS]
const simb::MCParticle * TrackIdToParticle_P(int const &id)
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
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
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]
const art::Ptr< simb::MCTruth > & ParticleToMCTruth_P(const simb::MCParticle *p)
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]
Class def header for mcstep data container.
bool fHitShowerThroughPFParticle
int sh_TrackId[MAX_SHOWERS]
std::string fShowerModuleLabel
int InteractionType() const
const simb::MCParticle & Lepton() const
#define DEFINE_ART_MODULE(klass)
Provides recob::Track data product.
std::string fHitModuleLabel
double esh_each_completeness[MAX_SHOWERS]
int sh_hasPrimary_e[MAX_SHOWERS]
void analyze(art::Event const &e) override
bool insideFV(double vertex[4])
const TVector3 & Direction() const
double sh_start_Z[MAX_SHOWERS]
Declaration of cluster object.
Class def header for mctrack data container.
double sh_purity[MAX_SHOWERS]
constexpr std::tuple_element_t< I, art::AssnsNode< L, R, D > > & get(art::AssnsNode< L, R, D > &t) noexcept
Detector simulation of raw signals on wires.
double sh_ehit_Q[MAX_SHOWERS]
double MC_lepton_startXYZT[4]
double MC_lepton_endXYZT[4]
double sh_direction_Z[MAX_SHOWERS]
T * make(ARGS...args) const
Utility object to perform functions of association.
double sh_completeness[MAX_SHOWERS]
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
double MC_lepton_endMomentum[40]
double sh_allhit_Q[MAX_SHOWERS]
const TLorentzVector & Momentum(const int i=0) const
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
Class def header for MCShower data container.
EventNumber_t event() const
void beginRun(art::Run const &run) override
const sim::ParticleList & ParticleList()
std::string fTruthMatchDataModuleLabel
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
const simb::MCParticle * TrackIdToMotherParticle_P(int const &id)
Event generator information.
Namespace collecting geometry-related classes utilities.
double sh_start_X[MAX_SHOWERS]
const TLorentzVector & EndMomentum() const
void LocalToWorld(const double *tpc, double *world) const
Transform point from local TPC frame to world frame.
art framework interface to geometry description
double sh_length[MAX_SHOWERS]