162 fNClusters=tfs->
make<TH1F>(
"fNoClustersInEvent",
"Number of Clusters", 40,0 ,400);
167 fCREP2 = tfs->
make<TH1F>(
"CREP2",
"CREP2",50,0,1);
168 fCRE = tfs->
make<TH1F>(
"CRE",
"CR Efficiency",50,0,1);
169 fCRP = tfs->
make<TH1F>(
"CRP",
"CR Purity",50,0,1);
172 fNuKE_elec = tfs->
make<TH1F>(
"NuKE_elec",
"NuKE electron",100,0,4000);
176 fNuKE_prot = tfs->
make<TH1F>(
"NuKE_prot",
"NuKE proton",100,0,4000);
184 fNuE_elec = tfs->
make<TH1F>(
"NuE_elec",
"Nu Efficiency electron",50,0,1);
185 fNuE_muon = tfs->
make<TH1F>(
"NuE_muon",
"Nu Efficiency muon",50,0,1);
186 fNuE_pion = tfs->
make<TH1F>(
"NuE_pion",
"Nu Efficiency pion",50,0,1);
187 fNuE_kaon = tfs->
make<TH1F>(
"NuE_kaon",
"Nu Efficiency kaon",50,0,1);
188 fNuE_prot = tfs->
make<TH1F>(
"NuE_prot",
"Nu Efficiency proton",50,0,1);
190 fNuP_elec = tfs->
make<TH1F>(
"NuP_elec",
"Nu Purity electron",50,0,1);
191 fNuP_muon = tfs->
make<TH1F>(
"NuP_muon",
"Nu Purity muon",50,0,1);
192 fNuP_pion = tfs->
make<TH1F>(
"NuP_pion",
"Nu Purity pion",50,0,1);
193 fNuP_kaon = tfs->
make<TH1F>(
"NuP_kaon",
"Nu Purity kaon",50,0,1);
194 fNuP_prot = tfs->
make<TH1F>(
"NuP_prot",
"Nu Purity proton",50,0,1);
201 fNuEP2_KE_elec = tfs->
make<TProfile>(
"NuEP2_KE_elec",
"NuEP2 electron vs KE",20,0,2000);
214 if(geom->
Nplanes() > 3)
return;
219 std::vector< art::Ptr<recob::Hit> > allhits;
221 if(allhits.size() == 0)
return;
227 if(clusterListHandle->size() == 0)
return;
233 double xyz[3] = {0,0,0};
234 for(
unsigned int ii = 0; ii < vertexListHandle->size(); ++ii){
246 for(
unsigned int ii = 0; ii < PFPListHandle->size(); ++ii){
257 std::vector<const simb::MCParticle*> plist2;
259 std::vector<std::vector<art::Ptr<recob::Hit>>> hlist2;
261 std::vector<std::vector<short>> truToCl;
263 std::vector<std::vector<unsigned short>> nTruHitInCl;
265 std::vector<unsigned short> nRecHitInCl;
270 float aveNuEP2mu = 0.;
271 float numNuEP2mu = 0.;
272 float aveNuEP2nm = 0.;
273 float numNuEP2nm = 0.;
279 int neutTrackID = -1;
280 std::vector<int> tidlist;
281 float neutEnergy = -1.;
282 int neutIntType = -1;
287 int pdg = abs(part->
PdgCode());
293 <<
"Pre-Cuts origin "<<theTruth->
Origin()<<
" trackID "<<trackID
295 <<
" E "<<part->
E()<<
" mass "<<part->
Mass()
296 <<
" Mother "<<part->
Mother() + neutTrackID
302 neutTrackID = trackID;
304 neutEnergy = 1000. * theNeutrino.
Nu().
E();
306 neutCCNC = theNeutrino.
CCNC();
309 for(
unsigned short iv = 0; iv < recoVtxList.
size(); ++iv) {
310 recoVtxList[iv]->XYZ(xyz);
317 bool isCharged = (pdg == 11) || (pdg == 13) || (pdg == 211)
318 || (pdg == 321) || (pdg == 2212);
321 if(!isCharged)
continue;
323 float KE = 1000 * (part->
E() - part->
Mass());
328 if(part->
Process() !=
"primary")
continue;
348 if(part->
Process() ==
"NeutronInelastic")
continue;
349 plist2.push_back(part);
350 tidlist.push_back(trackID);
352 std::vector<short> temp {-1, -1, -1};
353 truToCl.push_back(temp);
355 std::vector<unsigned short> temp2(3);
356 nTruHitInCl.push_back(temp2);
360 <<
" Origin "<<theTruth->
Origin()<<
" trackID "<<trackID
363 <<
" Mother "<<part->
Mother() + neutTrackID
367 if(plist2.size() == 0)
return;
371 if(hlist2.size() != plist2.size()) {
373 <<
"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 for(
unsigned short dpl = plist2.size() - 1; dpl > 0; --dpl) {
387 if(plist2[dpl]->Mother() == 0)
continue;
389 if(abs(plist2[dpl]->PdgCode()) == 11)
continue;
391 int motherID = neutTrackID + plist2[dpl]->Mother() - 1;
393 if(motherID < 0)
continue;
396 for(
unsigned short kpl = 0; kpl < plist2.size(); ++kpl) {
397 if(plist2[kpl]->Mother() == motherID) ++ndtr;
400 if(ndtr > 1)
continue;
403 for(
unsigned short jpl = dpl - 1; jpl > 0; --jpl) {
404 if(plist2[jpl]->TrackId() == motherID) {
410 if(mpl < 0)
continue;
412 if(plist2[dpl]->PdgCode() != plist2[mpl]->PdgCode())
continue;
413 moda.push_back(std::make_pair(mpl, dpl));
419 for (
unsigned int ii = 0; ii < clusterListHandle->size(); ++ii){
425 nRecHitInCl.resize(clusters.
size());
429 std::map< geo::View_t, unsigned int > ViewToPlane;
430 for(
unsigned int plane=0; plane < geom->
Nplanes(); ++plane){
432 ViewToPlane[view] = plane;
434 for(
size_t icl = 0; icl < clusters.
size(); ++icl){
435 unsigned int plane = ViewToPlane[clusters[icl]->View()];
436 std::vector< art::Ptr<recob::Hit> > cluhits = fmh.at(icl);
438 nRecHitInCl[icl] = cluhits.size();
440 std::vector<unsigned short> nHitInPl2(plist2.size());
441 for(
size_t iht = 0; iht < cluhits.size(); ++iht){
450 for(
unsigned short ipl = 0; ipl < plist2.size(); ++ipl) {
451 unsigned short imat = 0;
452 for(imat = 0; imat < hlist2[ipl].size(); ++imat) {
453 if(cluhits[iht] == hlist2[ipl][imat])
break;
455 if(imat < hlist2[ipl].size()) {
460 if(hitInPl2 < 0)
continue;
464 for(
unsigned short imd = 0; imd < moda.size(); ++imd) {
465 if(moda[imd].second == hitInPl2) hitInPl2 = moda[imd].first;
468 ++nHitInPl2[hitInPl2];
472 unsigned short nhit = 0;
474 for(
unsigned int ipl = 0; ipl < nHitInPl2.size(); ++ipl) {
475 if(nHitInPl2[ipl] > nhit) {
476 nhit = nHitInPl2[ipl];
484 if(nhit > nTruHitInCl[imtru][plane]) {
485 truToCl[imtru][plane] = icl;
486 nTruHitInCl[imtru][plane] = nhit;
492 for(
unsigned short ipl = 0; ipl < plist2.size(); ++ipl) {
495 for(
unsigned short ii = 0; ii < moda.size(); ++ii) {
496 if(moda[ii].second == ipl) {
504 if(hlist2[ipl].size() < 3)
continue;
506 int trackID = plist2[ipl]->TrackId();
509 float KE = 1000 * (plist2[ipl]->E() - plist2[ipl]->Mass());
510 int PDG = abs(plist2[ipl]->PdgCode());
512 std::vector<short> nTru(geom->
Nplanes());
513 std::vector<short> nRec(geom->
Nplanes());
514 std::vector<short> nTruRec(geom->
Nplanes());
515 std::vector<float> eff(geom->
Nplanes());
516 std::vector<float> pur(geom->
Nplanes());
517 std::vector<float> ep(geom->
Nplanes());
518 for(
unsigned int plane = 0; plane < geom->
Nplanes(); ++plane) {
521 for(
unsigned short ii = 0; ii < hlist2[ipl].size(); ++ii){
522 if(ViewToPlane[hlist2[ipl][ii]->View()] == plane) ++nTru[plane];
527 unsigned short mom = ipl;
528 std::vector<std::pair<unsigned short, unsigned short>>::reverse_iterator
530 while(rit != moda.rend()) {
531 if((*rit).first == mom) {
532 unsigned short dau = (*rit).second;
533 for(
unsigned short jj = 0; jj < hlist2[dau].size(); ++jj) {
534 if(ViewToPlane[hlist2[dau][jj]->View()] == plane) ++nTru[plane];
545 if(nTru[plane] == 0) {
550 short icl = truToCl[ipl][plane];
551 nRec[plane] = nRecHitInCl[icl];
552 nTruRec[plane] = nTruHitInCl[ipl][plane];
556 eff[plane] = (float)nTruRec[plane] / (
float)nTru[plane];
558 pur[plane] = (float)nTruRec[plane] / (
float)nRec[plane];
559 ep[plane] = eff[plane] * pur[plane];
562 std::vector<float> temp;
564 std::sort(temp.begin(), temp.end());
566 unsigned short ii = temp.size() - 2;
567 float ep2 = temp[ii];
570 short ep2Cluster = 0;
571 for(
unsigned short jj = 0; jj < temp.size(); ++jj) {
574 ep2Cluster = truToCl[ipl][ep2Plane];
579 std::array<double, 2> clBeg, clEnd;
580 if(ep2Cluster >= 0) {
581 clBeg[0] = clusters[ep2Cluster]->StartWire();
582 clBeg[1] = clusters[ep2Cluster]->StartTick();
583 clEnd[0] = clusters[ep2Cluster]->EndWire();
584 clEnd[1] = clusters[ep2Cluster]->EndTick();
593 fCRE->Fill(eff[ep2Plane]);
594 fCRP->Fill(pur[ep2Plane]);
598 <<
">>>CREP2 "<<std::fixed<<std::setprecision(2)<<ep2
599 <<
" E "<<eff[ep2Plane]<<std::setprecision(2)<<
" P "<<pur[ep2Plane]
600 <<
" P:W:T "<<ep2Plane<<
":"<<(int)clBeg[0]<<
":"<<(
int)clBeg[1]
601 <<
"-"<<ep2Plane<<
":"<<(int)clEnd[0]<<
":"<<(
int)clEnd[1]
602 <<
" PDG "<<PDG<<
" KE "<<(int)KE<<
" MeV";
609 aveNuEP2mu += ep2 * wght;
612 aveNuEP2nm += ep2 * wght;
621 }
else if(PDG == 13) {
627 }
else if(PDG == 211) {
633 }
else if(PDG == 321) {
639 }
else if(PDG == 2212) {
647 <<
">>>NuEP2 "<<std::fixed<<std::setprecision(2)<<ep2
648 <<
" E "<<eff[ep2Plane]<<std::setprecision(2)<<
" P "<<pur[ep2Plane]
649 <<
" P:W:T "<<ep2Plane<<
":"<<(int)clBeg[0]<<
":"<<(
int)clBeg[1]
650 <<
"-"<<ep2Plane<<
":"<<(int)clEnd[0]<<
":"<<(
int)clEnd[1]
651 <<
" PDG "<<PDG<<
" KE "<<(int)KE<<
" MeV ";
655 mfp<<
" Truth P:W:T ";
656 for(
unsigned int plane = 0; plane < geom->
Nplanes(); ++plane) {
657 unsigned short loW = 9999;
658 unsigned short loT = 0;
659 unsigned short hiW = 0;
660 unsigned short hiT = 0;
661 for(
unsigned short ii = 0; ii < hlist2[ipl].size(); ++ii){
662 if(ViewToPlane[hlist2[ipl][ii]->View()] == plane) {
674 mfp<<plane<<
":"<<loW<<
":"<<loT<<
"-"<<plane<<
":"<<hiW<<
":"<<hiT<<
" ";
681 if(numNuEP2mu > 0.) ave1 = aveNuEP2mu/numNuEP2mu;
684 if(numNuEP2nm > 0.) ave2 = aveNuEP2nm/numNuEP2nm;
687 if(numCREP2 > 0.) ave3 = aveCREP2/numCREP2;
692 std::string nuType =
"Other";
694 if(neutIntType == 1001) nuType =
"CCQE";
695 if(neutIntType == 1091) nuType =
"DIS";
696 if(neutIntType == 1097) nuType =
"COH";
697 if(neutIntType > 1002 && neutIntType < 1091) nuType =
"RES";
706 <<
" Enu "<<std::fixed<<std::setprecision(0)<<neutEnergy
707 <<
std::right<<std::fixed<<std::setprecision(2)
710 <<
" CosmicRays "<<ave3
711 <<
" CCNC "<<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::...
const std::vector< std::vector< art::Ptr< recob::Hit > > > TrackIdsToHits_Ps(std::vector< int > const &tkIds, std::vector< art::Ptr< recob::Hit > > const &hitsIn)
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::vector< float > fElecKERange
const simb::MCNeutrino & GetNeutrino() const
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
PlaneGeo const & Plane(unsigned int const p, unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified wire.
std::string fVertexModuleLabel
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
geo::WireID WireID() const
Initial tdc tick for hit.
Declaration of signal hit object.
const simb::MCParticle & Nu() const
void analyze(const art::Event &evt)
read access to event
list_type::const_iterator const_iterator
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
std::string Process() const
std::string fClusterModuleLabel
std::vector< float > fPionKERange
TProfile * fNuEP2_KE_kaon
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
int InteractionType() const
View_t View() const
Which coordinate does this plane measure.
TProfile * fNuEP2_KE_elec
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
#define DEFINE_ART_MODULE(klass)
void push_back(Ptr< U > const &p)
TProfile * fNuEP2_KE_pion
std::string fPFParticleModuleLabel
EDAnalyzer(Table< Config > const &config)
Declaration of cluster object.
TProfile * fNuEP2_KE_prot
double Vx(const int i=0) const
float PeakTime() const
Time of the signal peak, in tick units.
T * make(ARGS...args) const
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
Example routine for calculating the "ultimate e-m mother" of a particle in a simulated event...
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
TProfile * fNuEP2_KE_muon
PFPAna(fhicl::ParameterSet const &pset)
double Vz(const int i=0) const
EventNumber_t event() const
std::vector< float > fMuonKERange
Declaration of basic channel signal object.
const sim::ParticleList & ParticleList()
std::string fTrackModuleLabel
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Particle list in DetSim contains Monte Carlo particle information.
Event generator information.
double Vy(const int i=0) const
art framework interface to geometry description
std::vector< float > fKaonKERange
const art::Ptr< simb::MCTruth > & TrackIdToMCTruth_P(int const &id)