20 #include "art_root_io/TFileService.h" 21 #include "canvas/Persistency/Common/FindManyP.h" 36 #include "nug4/ParticleNavigation/ParticleList.h" 136 if (found != std::string::npos)
moduleID = 1;
138 if (found != std::string::npos)
moduleID = 2;
140 if (found != std::string::npos)
moduleID = 3;
142 if (found != std::string::npos)
moduleID = 4;
158 fNClusters = tfs->make<TH1F>(
"fNoClustersInEvent",
"Number of Clusters", 40, 0, 400);
159 fNHitInCluster = tfs->make<TH1F>(
"fNHitInCluster",
"NHitInCluster", 100, 0, 100);
163 fCREP2 = tfs->make<TH1F>(
"CREP2",
"CREP2", 50, 0, 1);
164 fCRE = tfs->make<TH1F>(
"CRE",
"CR Efficiency", 50, 0, 1);
165 fCRP = tfs->make<TH1F>(
"CRP",
"CR Purity", 50, 0, 1);
168 fNuKE_elec = tfs->make<TH1F>(
"NuKE_elec",
"NuKE electron", 100, 0, 4000);
169 fNuKE_muon = tfs->make<TH1F>(
"NuKE_muon",
"NuKE muon", 100, 0, 4000);
170 fNuKE_pion = tfs->make<TH1F>(
"NuKE_pion",
"NuKE pion", 100, 0, 4000);
171 fNuKE_kaon = tfs->make<TH1F>(
"NuKE_kaon",
"NuKE kaon", 100, 0, 4000);
172 fNuKE_prot = tfs->make<TH1F>(
"NuKE_prot",
"NuKE proton", 100, 0, 4000);
174 fNuEP2_elec = tfs->make<TH1F>(
"NuEP2_elec",
"NuEP2 electron", 50, 0, 1);
175 fNuEP2_muon = tfs->make<TH1F>(
"NuEP2_muon",
"NuEP2 muon", 50, 0, 1);
176 fNuEP2_pion = tfs->make<TH1F>(
"NuEP2_pion",
"NuEP2 pion", 50, 0, 1);
177 fNuEP2_kaon = tfs->make<TH1F>(
"NuEP2_kaon",
"NuEP2 kaon", 50, 0, 1);
178 fNuEP2_prot = tfs->make<TH1F>(
"NuEP2_prot",
"NuEP2 proton", 50, 0, 1);
180 fNuE_elec = tfs->make<TH1F>(
"NuE_elec",
"Nu Efficiency electron", 50, 0, 1);
181 fNuE_muon = tfs->make<TH1F>(
"NuE_muon",
"Nu Efficiency muon", 50, 0, 1);
182 fNuE_pion = tfs->make<TH1F>(
"NuE_pion",
"Nu Efficiency pion", 50, 0, 1);
183 fNuE_kaon = tfs->make<TH1F>(
"NuE_kaon",
"Nu Efficiency kaon", 50, 0, 1);
184 fNuE_prot = tfs->make<TH1F>(
"NuE_prot",
"Nu Efficiency proton", 50, 0, 1);
186 fNuP_elec = tfs->make<TH1F>(
"NuP_elec",
"Nu Purity electron", 50, 0, 1);
187 fNuP_muon = tfs->make<TH1F>(
"NuP_muon",
"Nu Purity muon", 50, 0, 1);
188 fNuP_pion = tfs->make<TH1F>(
"NuP_pion",
"Nu Purity pion", 50, 0, 1);
189 fNuP_kaon = tfs->make<TH1F>(
"NuP_kaon",
"Nu Purity kaon", 50, 0, 1);
190 fNuP_prot = tfs->make<TH1F>(
"NuP_prot",
"Nu Purity proton", 50, 0, 1);
193 fNuVtx_dx = tfs->make<TH1F>(
"Vtx dx",
"Vtx dx", 80, -10, 10);
194 fNuVtx_dy = tfs->make<TH1F>(
"Vtx dy",
"Vtx dy", 80, -10, 10);
195 fNuVtx_dz = tfs->make<TH1F>(
"Vtx dz",
"Vtx dz", 80, -10, 10);
197 fNuEP2_KE_elec = tfs->make<TProfile>(
"NuEP2_KE_elec",
"NuEP2 electron vs KE", 200, 0, 2000);
198 fNuEP2_KE_muon = tfs->make<TProfile>(
"NuEP2_KE_muon",
"NuEP2 muon vs KE", 200, 0, 2000);
199 fNuEP2_KE_pion = tfs->make<TProfile>(
"NuEP2_KE_pion",
"NuEP2 pion vs KE", 200, 0, 2000);
200 fNuEP2_KE_kaon = tfs->make<TProfile>(
"NuEP2_KE_kaon",
"NuEP2 kaon vs KE", 200, 0, 2000);
201 fNuEP2_KE_prot = tfs->make<TProfile>(
"NuEP2_KE_prot",
"NuEP2 proton vs KE", 200, 0, 2000);
216 mf::LogError(
"ClusterAna") <<
"Too many planes for this code...";
223 std::vector<art::Ptr<recob::Hit>> allhits;
225 if (allhits.size() == 0)
return;
231 if (clusterListHandle->size() == 0) {
232 std::cout <<
"No clusters in event. Hits size " << allhits.size() <<
"\n";
238 double xyz[3] = {0, 0, 0};
240 if (vertexListHandle.
isValid()) {
242 for (
unsigned int ii = 0; ii < vertexListHandle->size(); ++ii) {
252 sim::ParticleList
const& plist = pi_serv->
ParticleList();
254 std::vector<const simb::MCParticle*> plist2;
256 std::vector<std::vector<art::Ptr<recob::Hit>>> hlist2;
258 std::vector<std::vector<short>> truToCl;
260 std::vector<std::vector<unsigned short>> nTruHitInCl;
262 std::vector<unsigned short> nRecHitInCl;
267 float aveNuEP2mu = 0.;
268 float numNuEP2mu = 0.;
269 float aveNuEP2nm = 0.;
270 float numNuEP2nm = 0.;
276 int neutTrackID = -1;
277 std::vector<int> tidlist;
278 float neutEnergy = -1.;
279 int neutIntType = -1;
281 bool isNeutrino =
false;
282 bool isSingleParticle =
false;
295 float KE = 1000 * (part->
E() - part->
Mass());
299 if ((isNeutrino || isSingleParticle) && neutTrackID < 0) {
300 neutTrackID = trackID;
303 neutEnergy = 1000. * theNeutrino.
Nu().
E();
305 neutCCNC = theNeutrino.
CCNC();
308 for (
unsigned short iv = 0; iv < recoVtxList.
size(); ++iv) {
309 recoVtxList[iv]->XYZ(xyz);
318 <<
" PDG " << part->
PdgCode() <<
" KE " << (
int)KE <<
" MeV " 319 <<
" neutTrackID " << neutTrackID <<
" Mother " 322 bool isCharged = (pdg == 11) || (pdg == 13) || (pdg == 211) || (pdg == 321) || (pdg == 2212);
324 if (!isCharged)
continue;
330 if (part->
Process() !=
"primary")
continue;
350 if (part->
Process() ==
"NeutronInelastic")
continue;
351 plist2.push_back(part);
352 tidlist.push_back(trackID);
354 std::vector<short>
temp{-1, -1, -1};
355 truToCl.push_back(
temp);
357 std::vector<unsigned short> temp2(3);
358 nTruHitInCl.push_back(temp2);
362 <<
"plist2[" << plist2.size() - 1 <<
"]" 363 <<
" Origin " << theTruth->
Origin() <<
" trackID " << trackID <<
" PDG " 364 << part->
PdgCode() <<
" KE " << (
int)KE <<
" Mother " << part->
Mother() + neutTrackID - 1
365 <<
" Proc " << part->
Process();
368 if (plist2.size() == 0)
return;
372 if (hlist2.size() != plist2.size()) {
373 mf::LogError(
"ClusterAna") <<
"MC particle list size " << plist2.size()
374 <<
" != size of MC particle true hits lists " << hlist2.size();
380 std::vector<std::pair<unsigned short, unsigned short>> moda;
385 unsigned short ii, dpl, jj, jpl, kpl;
386 for (ii = 0; ii < plist2.size(); ++ii) {
387 dpl = plist2.size() - 1 - ii;
389 if (plist2[dpl]->Mother() == 0)
continue;
391 if (
abs(plist2[dpl]->
PdgCode()) == 11)
continue;
393 int motherID = neutTrackID + plist2[dpl]->Mother() - 1;
395 if (motherID != neutTrackID)
continue;
398 for (kpl = 0; kpl < plist2.size(); ++kpl) {
399 if (plist2[kpl]->Mother() == motherID) ++ndtr;
402 if (ndtr > 1)
continue;
405 for (jj = 0; jj < plist2.size(); ++jj) {
406 jpl = plist2.size() - 1 - jj;
407 if (plist2[jpl]->TrackId() == motherID) {
415 <<
" mother of daughter " << dpl <<
" not found. mpl = " << mpl;
420 moda.push_back(std::make_pair(mpl, dpl));
426 for (
unsigned int ii = 0; ii < clusterListHandle->size(); ++ii) {
432 nRecHitInCl.resize(clusters.
size());
436 std::map<geo::View_t, unsigned int> ViewToPlane;
437 for (
unsigned int plane = 0; plane < geom->
Nplanes(); ++plane) {
439 ViewToPlane[view] = plane;
441 for (
size_t icl = 0; icl < clusters.
size(); ++icl) {
442 unsigned int plane = ViewToPlane[clusters[icl]->View()];
443 std::vector<art::Ptr<recob::Hit>> cluhits = fmh.at(icl);
445 nRecHitInCl[icl] = cluhits.size();
447 std::vector<unsigned short> nHitInPl2(plist2.size());
448 for (
size_t iht = 0; iht < cluhits.size(); ++iht) {
452 for (
unsigned short ipl = 0; ipl < plist2.size(); ++ipl) {
453 unsigned short imat = 0;
454 for (imat = 0; imat < hlist2[ipl].size(); ++imat) {
455 if (cluhits[iht] == hlist2[ipl][imat])
break;
457 if (imat < hlist2[ipl].
size()) {
462 if (hitInPl2 < 0)
continue;
466 for (
unsigned short imd = 0; imd < moda.size(); ++imd) {
467 if (moda[imd].
second == hitInPl2) hitInPl2 = moda[imd].first;
470 ++nHitInPl2[hitInPl2];
474 unsigned short nhit = 0;
476 for (
unsigned int ipl = 0; ipl < nHitInPl2.size(); ++ipl) {
477 if (nHitInPl2[ipl] > nhit) {
478 nhit = nHitInPl2[ipl];
486 if (nhit > nTruHitInCl[imtru][plane]) {
487 truToCl[imtru][plane] = icl;
488 nTruHitInCl[imtru][plane] =
nhit;
494 for (
unsigned short ipl = 0; ipl < plist2.size(); ++ipl) {
497 for (
unsigned short ii = 0; ii < moda.size(); ++ii) {
498 if (moda[ii].
second == ipl) {
503 if (skipit)
continue;
506 if (hlist2[ipl].
size() < 3)
continue;
508 int trackID = plist2[ipl]->TrackId();
511 float KE = 1000 * (plist2[ipl]->E() - plist2[ipl]->Mass());
514 std::vector<short> nTru(geom->
Nplanes());
515 std::vector<short> nRec(geom->
Nplanes());
516 std::vector<short> nTruRec(geom->
Nplanes());
517 std::vector<float> eff(geom->
Nplanes());
518 std::vector<float> pur(geom->
Nplanes());
519 std::vector<float> ep(geom->
Nplanes());
520 for (
unsigned int plane = 0; plane < geom->
Nplanes(); ++plane) {
523 for (
unsigned short ii = 0; ii < hlist2[ipl].size(); ++ii) {
524 if (ViewToPlane[hlist2[ipl][ii]->
View()] == plane) ++nTru[plane];
528 unsigned short mom = ipl;
529 std::vector<std::pair<unsigned short, unsigned short>>::reverse_iterator rit =
531 while (rit != moda.rend()) {
532 if ((*rit).first == mom) {
533 unsigned short dau = (*rit).second;
534 for (
unsigned short jj = 0; jj < hlist2[dau].size(); ++jj) {
535 if (ViewToPlane[hlist2[dau][jj]->
View()] == plane) ++nTru[plane];
544 if (nTru[plane] == 0)
continue;
546 if (nTru[plane] < 3)
continue;
547 short icl = truToCl[ipl][plane];
548 if (icl < 0) { nRec[plane] = 0; }
550 nRec[plane] = nRecHitInCl[icl];
552 nTruRec[plane] = nTruHitInCl[ipl][plane];
555 if (nTru[plane] > 0) eff[plane] = (
float)nTruRec[plane] / (
float)nTru[plane];
556 if (nRec[plane] > 0) pur[plane] = (
float)nTruRec[plane] / (
float)nRec[plane];
558 if (eff[plane] == 0) { eff[plane] = 0.001; }
559 if (pur[plane] == 0) { pur[plane] = 0.001; }
560 if (eff[plane] >= 1) { eff[plane] = 0.999; }
561 if (pur[plane] >= 1) { pur[plane] = 0.999; }
562 ep[plane] = eff[plane] * pur[plane];
566 << eff[plane] <<
" " << pur[plane] <<
"\n";
569 std::vector<float>
temp;
571 std::sort(temp.begin(), temp.end());
573 unsigned short ii = temp.size() - 2;
574 float ep2 = temp[ii];
577 short ep2Cluster = 0;
578 for (
unsigned short jj = 0; jj < temp.size(); ++jj) {
581 ep2Cluster = truToCl[ipl][ep2Plane];
586 std::array<double, 2> clBeg, clEnd;
587 if (ep2Cluster >= 0) {
588 clBeg[0] = clusters[ep2Cluster]->StartWire();
589 clBeg[1] = clusters[ep2Cluster]->StartTick();
590 clEnd[0] = clusters[ep2Cluster]->EndWire();
591 clEnd[1] = clusters[ep2Cluster]->EndTick();
600 fCRE->Fill(eff[ep2Plane]);
601 fCRP->Fill(pur[ep2Plane]);
606 <<
">>>CREP2 " << std::fixed <<
std::setprecision(2) << ep2 <<
" E " << eff[ep2Plane]
607 <<
std::setprecision(2) <<
" P " << pur[ep2Plane] <<
" P:W:T " << ep2Plane <<
":" 608 << (
int)clBeg[0] <<
":" << (
int)clBeg[1] <<
"-" << ep2Plane <<
":" << (
int)clEnd[0]
609 <<
":" << (
int)clEnd[1] <<
" PDG " << PDG <<
" KE " << (
int)KE <<
" MeV";
616 aveNuEP2mu += ep2 * wght;
620 aveNuEP2nm += ep2 * wght;
630 else if (PDG == 13) {
637 else if (PDG == 211) {
644 else if (PDG == 321) {
651 else if (PDG == 2212) {
660 <<
">>>NuEP2 " << std::fixed <<
std::setprecision(2) << ep2 <<
" E " << eff[ep2Plane]
661 <<
std::setprecision(2) <<
" P " << pur[ep2Plane] <<
" P:W:T " << ep2Plane <<
":" 662 << (
int)clBeg[0] <<
":" << (
int)clBeg[1] <<
"-" << ep2Plane <<
":" << (
int)clEnd[0]
663 <<
":" << (
int)clEnd[1] <<
" PDG " << PDG <<
" KE " << (
int)KE <<
" MeV ";
667 mfp <<
" Truth P:W:T ";
668 for (
unsigned int plane = 0; plane < geom->
Nplanes(); ++plane) {
669 unsigned short loW = 9999;
670 unsigned short loT = 0;
671 unsigned short hiW = 0;
672 unsigned short hiT = 0;
673 for (
unsigned short ii = 0; ii < hlist2[ipl].size(); ++ii) {
674 if (ViewToPlane[hlist2[ipl][ii]->
View()] == plane) {
686 mfp << plane <<
":" << loW <<
":" << loT <<
"-" << plane <<
":" << hiW <<
":" << hiT
694 if (numNuEP2mu > 0.) ave1 = aveNuEP2mu / numNuEP2mu;
697 if (numNuEP2nm > 0.) ave2 = aveNuEP2nm / numNuEP2nm;
700 if (numCREP2 > 0.) ave3 = aveCREP2 / numCREP2;
705 if (neutIntType == 1001) nuType =
"CCQE";
706 if (neutIntType == 1091) nuType =
"DIS";
707 if (neutIntType == 1097) nuType =
"COH";
708 if (neutIntType > 1002 && neutIntType < 1091) nuType =
"RES";
717 <<
"EvtEP2 " << evt.
id().
event() <<
" NuType " << nuType <<
" Enu " << std::fixed
719 <<
" NuMuons " << ave1 <<
" NuPiKp " << ave2 <<
" CosmicRays " << ave3 <<
" CCNC " 720 << 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::string fHitsModuleLabel
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
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
WireID_t Wire
Index of the wire within its plane.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
Cluster finding and building.
EDAnalyzer(fhicl::ParameterSet const &pset)
std::string Process() const
Q_EXPORT QTSManip setprecision(int p)
art framework interface to geometry description
void analyze(const art::Event &evt) override
std::vector< float > fElecKERange
bool isValid() const noexcept
TProfile * fNuEP2_KE_muon
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.
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
ClusterAna(fhicl::ParameterSet const &pset)
#define DEFINE_ART_MODULE(klass)
void push_back(Ptr< U > const &p)
const art::Ptr< simb::MCTruth > & TrackIdToMCTruth_P(int id) const
single particles thrown at the detector
TProfile * fNuEP2_KE_kaon
std::vector< float > fProtKERange
std::vector< float > fKaonKERange
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
std::string fVertexModuleLabel
const sim::ParticleList & ParticleList() const
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_pion
double Vz(const int i=0) const
EventNumber_t event() const
std::string fClusterModuleLabel
TProfile * fNuEP2_KE_elec
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.
std::vector< float > fPionKERange
std::vector< float > fMuonKERange
double Vy(const int i=0) const
TProfile * fNuEP2_KE_prot