21 #include "art_root_io/TFileService.h" 22 #include "canvas/Persistency/Common/FindManyP.h" 38 #include "nug4/ParticleNavigation/ParticleList.h" 131 fNClusters = tfs->make<TH1F>(
"fNoClustersInEvent",
"Number of Clusters", 40, 0, 400);
132 fNHitInCluster = tfs->make<TH1F>(
"fNHitInCluster",
"NHitInCluster", 100, 0, 100);
136 fCREP2 = tfs->make<TH1F>(
"CREP2",
"CREP2", 50, 0, 1);
137 fCRE = tfs->make<TH1F>(
"CRE",
"CR Efficiency", 50, 0, 1);
138 fCRP = tfs->make<TH1F>(
"CRP",
"CR Purity", 50, 0, 1);
141 fNuKE_elec = tfs->make<TH1F>(
"NuKE_elec",
"NuKE electron", 100, 0, 4000);
142 fNuKE_muon = tfs->make<TH1F>(
"NuKE_muon",
"NuKE muon", 100, 0, 4000);
143 fNuKE_pion = tfs->make<TH1F>(
"NuKE_pion",
"NuKE pion", 100, 0, 4000);
144 fNuKE_kaon = tfs->make<TH1F>(
"NuKE_kaon",
"NuKE kaon", 100, 0, 4000);
145 fNuKE_prot = tfs->make<TH1F>(
"NuKE_prot",
"NuKE proton", 100, 0, 4000);
147 fNuEP2_elec = tfs->make<TH1F>(
"NuEP2_elec",
"NuEP2 electron", 50, 0, 1);
148 fNuEP2_muon = tfs->make<TH1F>(
"NuEP2_muon",
"NuEP2 muon", 50, 0, 1);
149 fNuEP2_pion = tfs->make<TH1F>(
"NuEP2_pion",
"NuEP2 pion", 50, 0, 1);
150 fNuEP2_kaon = tfs->make<TH1F>(
"NuEP2_kaon",
"NuEP2 kaon", 50, 0, 1);
151 fNuEP2_prot = tfs->make<TH1F>(
"NuEP2_prot",
"NuEP2 proton", 50, 0, 1);
153 fNuE_elec = tfs->make<TH1F>(
"NuE_elec",
"Nu Efficiency electron", 50, 0, 1);
154 fNuE_muon = tfs->make<TH1F>(
"NuE_muon",
"Nu Efficiency muon", 50, 0, 1);
155 fNuE_pion = tfs->make<TH1F>(
"NuE_pion",
"Nu Efficiency pion", 50, 0, 1);
156 fNuE_kaon = tfs->make<TH1F>(
"NuE_kaon",
"Nu Efficiency kaon", 50, 0, 1);
157 fNuE_prot = tfs->make<TH1F>(
"NuE_prot",
"Nu Efficiency proton", 50, 0, 1);
159 fNuP_elec = tfs->make<TH1F>(
"NuP_elec",
"Nu Purity electron", 50, 0, 1);
160 fNuP_muon = tfs->make<TH1F>(
"NuP_muon",
"Nu Purity muon", 50, 0, 1);
161 fNuP_pion = tfs->make<TH1F>(
"NuP_pion",
"Nu Purity pion", 50, 0, 1);
162 fNuP_kaon = tfs->make<TH1F>(
"NuP_kaon",
"Nu Purity kaon", 50, 0, 1);
163 fNuP_prot = tfs->make<TH1F>(
"NuP_prot",
"Nu Purity proton", 50, 0, 1);
166 fNuVtx_dx = tfs->make<TH1F>(
"Vtx dx",
"Vtx dx", 80, -10, 10);
167 fNuVtx_dy = tfs->make<TH1F>(
"Vtx dy",
"Vtx dy", 80, -10, 10);
168 fNuVtx_dz = tfs->make<TH1F>(
"Vtx dz",
"Vtx dz", 80, -10, 10);
170 fNuEP2_KE_elec = tfs->make<TProfile>(
"NuEP2_KE_elec",
"NuEP2 electron vs KE", 20, 0, 2000);
171 fNuEP2_KE_muon = tfs->make<TProfile>(
"NuEP2_KE_muon",
"NuEP2 muon vs KE", 20, 0, 2000);
172 fNuEP2_KE_pion = tfs->make<TProfile>(
"NuEP2_KE_pion",
"NuEP2 pion vs KE", 20, 0, 2000);
173 fNuEP2_KE_kaon = tfs->make<TProfile>(
"NuEP2_KE_kaon",
"NuEP2 kaon vs KE", 20, 0, 2000);
174 fNuEP2_KE_prot = tfs->make<TProfile>(
"NuEP2_KE_prot",
"NuEP2 proton vs KE", 20, 0, 2000);
182 if (geom->
Nplanes() > 3)
return;
187 std::vector<art::Ptr<recob::Hit>> allhits;
189 if (
empty(allhits))
return;
195 if (clusterListHandle->size() == 0)
return;
201 double xyz[3] = {0, 0, 0};
202 for (
unsigned int ii = 0; ii < vertexListHandle->size(); ++ii) {
212 for (
unsigned int ii = 0; ii < PFPListHandle->size(); ++ii) {
221 sim::ParticleList
const& plist = pi_serv->
ParticleList();
223 std::vector<const simb::MCParticle*> plist2;
225 std::vector<std::vector<art::Ptr<recob::Hit>>> hlist2;
227 std::vector<std::vector<short>> truToCl;
229 std::vector<std::vector<unsigned short>> nTruHitInCl;
231 std::vector<unsigned short> nRecHitInCl;
236 float aveNuEP2mu = 0.;
237 float numNuEP2mu = 0.;
238 float aveNuEP2nm = 0.;
239 float numNuEP2nm = 0.;
245 int neutTrackID = -1;
246 std::vector<int> tidlist;
247 float neutEnergy = -1.;
248 int neutIntType = -1;
263 << trackID <<
" PDG " << part->
PdgCode() <<
" E " << part->
E()
264 <<
" mass " << part->
Mass() <<
" Mother " 265 << part->
Mother() + neutTrackID <<
" Proc " << part->
Process();
270 neutTrackID = trackID;
272 neutEnergy = 1000. * theNeutrino.
Nu().
E();
274 neutCCNC = theNeutrino.
CCNC();
275 for (
unsigned short iv = 0; iv < recoVtxList.
size(); ++iv) {
276 recoVtxList[iv]->XYZ(xyz);
283 bool isCharged = (pdg == 11) || (pdg == 13) || (pdg == 211) || (pdg == 321) || (pdg == 2212);
285 if (!isCharged)
continue;
287 float KE = 1000 * (part->
E() - part->
Mass());
292 if (part->
Process() !=
"primary")
continue;
312 if (part->
Process() ==
"NeutronInelastic")
continue;
313 plist2.push_back(part);
314 tidlist.push_back(trackID);
316 std::vector<short>
temp{-1, -1, -1};
317 truToCl.push_back(
temp);
319 std::vector<unsigned short> temp2(3);
320 nTruHitInCl.push_back(temp2);
324 <<
" trackID " << trackID <<
" PDG " << part->
PdgCode() <<
" KE " 325 << (
int)KE <<
" Mother " << part->
Mother() + neutTrackID
326 <<
" Proc " << part->
Process();
329 if (
empty(plist2))
return;
333 if (hlist2.size() != plist2.size()) {
334 mf::LogError(
"PFPAna") <<
"MC particle list size " << plist2.size()
335 <<
" != size of MC particle true hits lists " << hlist2.size();
341 std::vector<std::pair<unsigned short, unsigned short>> moda;
346 for (
unsigned short dpl = plist2.size() - 1; dpl > 0; --dpl) {
348 if (plist2[dpl]->Mother() == 0)
continue;
350 if (
abs(plist2[dpl]->
PdgCode()) == 11)
continue;
352 int motherID = neutTrackID + plist2[dpl]->Mother() - 1;
354 if (motherID < 0)
continue;
357 for (
unsigned short kpl = 0; kpl < plist2.size(); ++kpl) {
358 if (plist2[kpl]->Mother() == motherID) ++ndtr;
361 if (ndtr > 1)
continue;
364 for (
unsigned short jpl = dpl - 1; jpl > 0; --jpl) {
365 if (plist2[jpl]->TrackId() == motherID) {
371 if (mpl < 0)
continue;
373 if (plist2[dpl]->
PdgCode() != plist2[mpl]->PdgCode())
continue;
374 moda.push_back(std::make_pair(mpl, dpl));
380 for (
unsigned int ii = 0; ii < clusterListHandle->size(); ++ii) {
386 nRecHitInCl.resize(clusters.
size());
390 std::map<geo::View_t, unsigned int> ViewToPlane;
391 for (
unsigned int plane = 0; plane < geom->
Nplanes(); ++plane) {
393 ViewToPlane[view] = plane;
395 for (
size_t icl = 0; icl < clusters.
size(); ++icl) {
396 unsigned int plane = ViewToPlane[clusters[icl]->View()];
397 std::vector<art::Ptr<recob::Hit>> cluhits = fmh.at(icl);
399 nRecHitInCl[icl] = cluhits.size();
401 std::vector<unsigned short> nHitInPl2(plist2.size());
402 for (
size_t iht = 0; iht < cluhits.size(); ++iht) {
411 for (
unsigned short ipl = 0; ipl < plist2.size(); ++ipl) {
412 unsigned short imat = 0;
413 for (imat = 0; imat < hlist2[ipl].size(); ++imat) {
414 if (cluhits[iht] == hlist2[ipl][imat])
break;
416 if (imat < hlist2[ipl].
size()) {
421 if (hitInPl2 < 0)
continue;
425 for (
unsigned short imd = 0; imd < moda.size(); ++imd) {
426 if (moda[imd].
second == hitInPl2) hitInPl2 = moda[imd].first;
429 ++nHitInPl2[hitInPl2];
433 unsigned short nhit = 0;
435 for (
unsigned int ipl = 0; ipl < nHitInPl2.size(); ++ipl) {
436 if (nHitInPl2[ipl] > nhit) {
437 nhit = nHitInPl2[ipl];
445 if (nhit > nTruHitInCl[imtru][plane]) {
446 truToCl[imtru][plane] = icl;
447 nTruHitInCl[imtru][plane] =
nhit;
453 for (
unsigned short ipl = 0; ipl < plist2.size(); ++ipl) {
456 for (
unsigned short ii = 0; ii < moda.size(); ++ii) {
457 if (moda[ii].
second == ipl) {
462 if (skipit)
continue;
465 if (hlist2[ipl].
size() < 3)
continue;
467 int trackID = plist2[ipl]->TrackId();
470 float KE = 1000 * (plist2[ipl]->E() - plist2[ipl]->Mass());
473 std::vector<short> nTru(geom->
Nplanes());
474 std::vector<short> nRec(geom->
Nplanes());
475 std::vector<short> nTruRec(geom->
Nplanes());
476 std::vector<float> eff(geom->
Nplanes());
477 std::vector<float> pur(geom->
Nplanes());
478 std::vector<float> ep(geom->
Nplanes());
479 for (
unsigned int plane = 0; plane < geom->
Nplanes(); ++plane) {
482 for (
unsigned short ii = 0; ii < hlist2[ipl].size(); ++ii) {
483 if (ViewToPlane[hlist2[ipl][ii]->
View()] == plane) ++nTru[plane];
488 unsigned short mom = ipl;
489 std::vector<std::pair<unsigned short, unsigned short>>::reverse_iterator rit =
491 while (rit != moda.rend()) {
492 if ((*rit).first == mom) {
493 unsigned short dau = (*rit).second;
494 for (
unsigned short jj = 0; jj < hlist2[dau].size(); ++jj) {
495 if (ViewToPlane[hlist2[dau][jj]->
View()] == plane) ++nTru[plane];
507 if (nTru[plane] == 0) {
512 short icl = truToCl[ipl][plane];
513 nRec[plane] = nRecHitInCl[icl];
514 nTruRec[plane] = nTruHitInCl[ipl][plane];
517 if (nTru[plane] > 0) eff[plane] = (
float)nTruRec[plane] / (
float)nTru[plane];
518 if (nRec[plane] > 0) pur[plane] = (
float)nTruRec[plane] / (
float)nRec[plane];
519 ep[plane] = eff[plane] * pur[plane];
522 std::vector<float>
temp;
524 std::sort(temp.begin(), temp.end());
526 unsigned short ii = temp.size() - 2;
527 float ep2 = temp[ii];
530 short ep2Cluster = 0;
531 for (
unsigned short jj = 0; jj < temp.size(); ++jj) {
534 ep2Cluster = truToCl[ipl][ep2Plane];
539 std::array<double, 2> clBeg, clEnd;
540 if (ep2Cluster >= 0) {
541 clBeg[0] = clusters[ep2Cluster]->StartWire();
542 clBeg[1] = clusters[ep2Cluster]->StartTick();
543 clEnd[0] = clusters[ep2Cluster]->EndWire();
544 clEnd[1] = clusters[ep2Cluster]->EndTick();
553 fCRE->Fill(eff[ep2Plane]);
554 fCRP->Fill(pur[ep2Plane]);
559 <<
">>>CREP2 " << std::fixed <<
std::setprecision(2) << ep2 <<
" E " << eff[ep2Plane]
560 <<
std::setprecision(2) <<
" P " << pur[ep2Plane] <<
" P:W:T " << ep2Plane <<
":" 561 << (
int)clBeg[0] <<
":" << (
int)clBeg[1] <<
"-" << ep2Plane <<
":" << (
int)clEnd[0]
562 <<
":" << (
int)clEnd[1] <<
" PDG " << PDG <<
" KE " << (
int)KE <<
" MeV";
569 aveNuEP2mu += ep2 * wght;
573 aveNuEP2nm += ep2 * wght;
583 else if (PDG == 13) {
590 else if (PDG == 211) {
597 else if (PDG == 321) {
604 else if (PDG == 2212) {
613 <<
">>>NuEP2 " << std::fixed <<
std::setprecision(2) << ep2 <<
" E " << eff[ep2Plane]
614 <<
std::setprecision(2) <<
" P " << pur[ep2Plane] <<
" P:W:T " << ep2Plane <<
":" 615 << (
int)clBeg[0] <<
":" << (
int)clBeg[1] <<
"-" << ep2Plane <<
":" << (
int)clEnd[0]
616 <<
":" << (
int)clEnd[1] <<
" PDG " << PDG <<
" KE " << (
int)KE <<
" MeV ";
620 mfp <<
" Truth P:W:T ";
621 for (
unsigned int plane = 0; plane < geom->
Nplanes(); ++plane) {
622 unsigned short loW = 9999;
623 unsigned short loT = 0;
624 unsigned short hiW = 0;
625 unsigned short hiT = 0;
626 for (
unsigned short ii = 0; ii < hlist2[ipl].size(); ++ii) {
627 if (ViewToPlane[hlist2[ipl][ii]->
View()] == plane) {
639 mfp << plane <<
":" << loW <<
":" << loT <<
"-" << plane <<
":" << hiW <<
":" << hiT
647 if (numNuEP2mu > 0.) ave1 = aveNuEP2mu / numNuEP2mu;
650 if (numNuEP2nm > 0.) ave2 = aveNuEP2nm / numNuEP2nm;
653 if (numCREP2 > 0.) ave3 = aveCREP2 / numCREP2;
658 if (neutIntType == 1001) nuType =
"CCQE";
659 if (neutIntType == 1091) nuType =
"DIS";
660 if (neutIntType == 1097) nuType =
"COH";
661 if (neutIntType > 1002 && neutIntType < 1091) nuType =
"RES";
672 <<
" NuPiKp " << ave2 <<
" CosmicRays " << ave3 <<
" CCNC " 673 << neutCCNC <<
" IntType " << neutIntType;
double E(const int i=0) const
void XYZ(double *xyz) const
Legacy method to access vertex position, preserved to avoid breaking code. Please try to use Vertex::...
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::vector< float > fElecKERange
const simb::MCNeutrino & GetNeutrino() const
PlaneGeo const & Plane(unsigned int const p, unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified wire.
AdcChannelData::View View
std::string fVertexModuleLabel
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
geo::WireID WireID() const
const simb::MCParticle & Nu() const
simb::Origin_t Origin() const
std::string fHitsModuleLabel
std::vector< float > fProtKERange
int PdgCode() const
Return the type of particle as a PDG ID.
WireID_t Wire
Index of the wire within its plane.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
EDAnalyzer(fhicl::ParameterSet const &pset)
std::string Process() const
Q_EXPORT QTSManip setprecision(int p)
std::string fClusterModuleLabel
art framework interface to geometry description
std::vector< float > fPionKERange
TProfile * fNuEP2_KE_kaon
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
int InteractionType() const
View_t View() const
Which coordinate does this plane measure.
TProfile * fNuEP2_KE_elec
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
int PdgCode(Resonance_t res, int Q)
(resonance id, charge) -> PDG code
#define DEFINE_ART_MODULE(klass)
void push_back(Ptr< U > const &p)
const art::Ptr< simb::MCTruth > & TrackIdToMCTruth_P(int id) const
TProfile * fNuEP2_KE_pion
std::string fPFParticleModuleLabel
std::vector< std::vector< art::Ptr< recob::Hit > > > TrackIdsToHits_Ps(detinfo::DetectorClocksData const &clockData, std::vector< int > const &tkIds, std::vector< art::Ptr< recob::Hit >> const &hitsIn) const
const sim::ParticleList & ParticleList() const
TProfile * fNuEP2_KE_prot
double Vx(const int i=0) const
float PeakTime() const
Time of the signal peak, in tick units.
Declaration of signal hit object.
Encapsulate the construction of a single detector plane.
TProfile * fNuEP2_KE_muon
PFPAna(fhicl::ParameterSet const &pset)
double Vz(const int i=0) const
EventNumber_t event() const
std::vector< float > fMuonKERange
std::string fTrackModuleLabel
auto const & get(AssnsNode< L, R, D > const &r)
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
second_as<> second
Type of time stored in seconds, in double precision.
Event generator information.
void analyze(const art::Event &evt) override
double Vy(const int i=0) const
std::vector< float > fKaonKERange
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.