33 #include "cetlib_except/exception.h" 55 double bdist(
const TVector3& pos,
unsigned int = 0,
unsigned int = 0)
82 TVector3& start, TVector3&
end, TVector3& startmom, TVector3& endmom,
83 unsigned int = 0,
unsigned int = 0)
104 for(
int i = 0; i <
n; ++i) {
105 TVector3 pos = part.
Position(i).Vect();
111 if(pos.X() >= xmin &&
119 if(ticks >= 0. && ticks < detprop->ReadOutWindowSize()) {
126 result += disp.Mag();
144 TVector3& start, TVector3& end, TVector3& startmom, TVector3& endmom,
145 unsigned int = 0,
unsigned int = 0)
151 auto const* detprop = lar::providerFrom<detinfo::DetectorPropertiesService>();
165 int n = mctrk.size();
168 for(
int i = 0; i <
n; ++i) {
169 TVector3 pos = mctrk[i].Position().Vect();
175 if(pos.X() >= xmin &&
183 if(ticks >= 0. && ticks < detprop->ReadOutWindowSize()) {
186 startmom = 0.001 * mctrk[i].Momentum().Vect();
190 result += disp.Mag();
195 endmom = 0.001 * mctrk[i].Momentum().Vect();
205 void effcalc(
const TH1* hnum,
const TH1* hden, TH1* heff)
207 int nbins = hnum->GetNbinsX();
208 if (nbins != hden->GetNbinsX())
209 throw cet::exception(
"TrackAna") <<
"effcalc[" __FILE__
"]: incompatible histograms (I)\n";
210 if (nbins != heff->GetNbinsX())
211 throw cet::exception(
"TrackAna") <<
"effcalc[" __FILE__
"]: incompatible histograms (II)\n";
215 for(
int ibin = 0; ibin <= nbins+1; ++ibin) {
216 double num = hnum->GetBinContent(ibin);
217 double den = hden->GetBinContent(ibin);
219 heff->SetBinContent(ibin, 0.);
220 heff->SetBinError(ibin, 0.);
223 double eff = num /
den;
228 double err = std::sqrt(eff * (1.-eff) / den);
229 heff->SetBinContent(ibin, eff);
230 heff->SetBinError(ibin, err);
234 heff->SetMinimum(0.);
235 heff->SetMaximum(1.05);
236 heff->SetMarkerStyle(20);
240 class flattener :
public std::vector<unsigned int> {
244 flattener() :
std::
vector<unsigned int>() {};
246 flattener(
const std::vector<std::vector<unsigned int> >& input)
251 void Convert(
const std::vector<std::vector<unsigned int> >& input)
255 for(
auto const& vec : input)
256 length += vec.size();
259 for(
auto const& vec : input)
260 for(
auto const&
value : vec)
323 MCHists(
const std::string& subdir);
431 template <
typename T> std::vector<size_t> fsort_indexes(
const std::vector<T> &v) ;
502 TrackAna::RecoHists::RecoHists(
const std::string& subdir)
523 fHstartx = dir.
make<TH1F>(
"xstart",
"X Start Position",
525 fHstarty = dir.
make<TH1F>(
"ystart",
"Y Start Position",
527 fHstartz = dir.
make<TH1F>(
"zstart",
"Z Start Position",
529 fHstartd = dir.
make<TH1F>(
"dstart",
"Start Position Distance to Boundary",
531 fHendx = dir.
make<TH1F>(
"xend",
"X End Position",
533 fHendy = dir.
make<TH1F>(
"yend",
"Y End Position",
535 fHendz = dir.
make<TH1F>(
"zend",
"Z End Position",
537 fHendd = dir.
make<TH1F>(
"dend",
"End Position Distance to Boundary",
539 fHtheta = dir.
make<TH1F>(
"theta",
"Theta", 100, 0., 3.142);
540 fHphi = dir.
make<TH1F>(
"phi",
"Phi", 100, -3.142, 3.142);
541 fHtheta_xz = dir.
make<TH1F>(
"theta_xz",
"Theta_xz", 100, -3.142, 3.142);
542 fHtheta_yz = dir.
make<TH1F>(
"theta_yz",
"Theta_yz", 100, -3.142, 3.142);
543 fHmom = dir.
make<TH1F>(
"mom",
"Momentum", 100, 0., 10.);
544 fHmoml = dir.
make<TH1F>(
"moml",
"Momentum", 100, 0., 1.);
545 fHlen = dir.
make<TH1F>(
"len",
"Track Length", 100, 0., 1.1 * geom->
DetLength());
546 fHlens = dir.
make<TH1F>(
"lens",
"Track Length", 100, 0., 0.1 * geom->
DetLength());
547 fHHitChg = dir.
make<TH1F>(
"hchg",
"Hit Charge (ADC counts)", 100, 0., 4000.);
548 fHHitWidth = dir.
make<TH1F>(
"hwid",
"Hit Width (ticks)", 40, 0., 20.);
549 fHHitPdg = dir.
make<TH1F>(
"hpdg",
"Hit Pdg code",5001, -2500.5, +2500.5);
550 fHHitTrkId = dir.
make<TH1F>(
"htrkid",
"Hit Track ID", 401, -200.5, +200.5);
551 fModeFrac = dir.
make<TH1F>(
"hmodefrac",
"quasi-Purity: Fraction of component tracks with the Track mode value", 20, 0.01, 1.01);
552 fNTrkIdTrks = dir.
make<TH1F>(
"hntrkids",
"quasi-Efficiency: Number of stitched tracks in which TrkId appears", 20, 0., +10.0);
553 fNTrkIdTrks2 = dir.
make<TH2F>(
"hntrkids2",
"Number of stitched tracks in which TrkId appears vs KE [GeV]", 20, 0., +10.0, 20, 0.0, 1.5);
554 fNTrkIdTrks3 = dir.
make<TH2F>(
"hntrkids3",
"MC Track vs Reco Track, wtd by nhits on Collection Plane", 10, -0.5, 9.5, 10, -0.5, 9.5);
555 fNTrkIdTrks3->GetXaxis()->SetTitle(
"Sorted-by-Descending-CPlane-Hits outer Track Number");
556 fNTrkIdTrks3->GetYaxis()->SetTitle(
"Sorted-by-Descending-True-Length G4Track");
562 TrackAna::MCHists::MCHists() :
664 fHduvcosth = dir.
make<TH2F>(
"duvcosth",
"Delta(uv) vs. Colinearity",
665 100, 0.95, 1., 100, 0., 1.);
666 fHcosth = dir.
make<TH1F>(
"colin",
"Colinearity", 100, 0.95, 1.);
667 fHmcu = dir.
make<TH1F>(
"mcu",
"MC Truth U", 100, -5., 5.);
668 fHmcv = dir.
make<TH1F>(
"mcv",
"MC Truth V", 100, -5., 5.);
669 fHmcw = dir.
make<TH1F>(
"mcw",
"MC Truth W", 100, -20., 20.);
670 fHupull = dir.
make<TH1F>(
"dupull",
"U Pull", 100, -20., 20.);
671 fHvpull = dir.
make<TH1F>(
"dvpull",
"V Pull", 100, -20., 20.);
672 fHmcdudw = dir.
make<TH1F>(
"mcdudw",
"MC Truth U Slope", 100, -0.2, 0.2);
673 fHmcdvdw = dir.
make<TH1F>(
"mcdvdw",
"MV Truth V Slope", 100, -0.2, 0.2);
674 fHdudwpull = dir.
make<TH1F>(
"dudwpull",
"U Slope Pull", 100, -10., 10.);
675 fHdvdwpull = dir.
make<TH1F>(
"dvdwpull",
"V Slope Pull", 100, -10., 10.);
676 fHHitEff = dir.
make<TH1F>(
"hiteff",
"MC Hit Efficiency", 100, 0., 1.0001);
677 fHHitPurity = dir.
make<TH1F>(
"hitpurity",
"MC Hit Purity", 100, 0., 1.0001);
678 fHstartdx = dir.
make<TH1F>(
"startdx",
"Start Delta x", 100, -10., 10.);
679 fHstartdy = dir.
make<TH1F>(
"startdy",
"Start Delta y", 100, -10., 10.);
680 fHstartdz = dir.
make<TH1F>(
"startdz",
"Start Delta z", 100, -10., 10.);
681 fHenddx = dir.
make<TH1F>(
"enddx",
"End Delta x", 100, -10., 10.);
682 fHenddy = dir.
make<TH1F>(
"enddy",
"End Delta y", 100, -10., 10.);
683 fHenddz = dir.
make<TH1F>(
"enddz",
"End Delta z", 100, -10., 10.);
684 fHlvsl = dir.
make<TH2F>(
"lvsl",
"Reco Length vs. MC Truth Length",
686 fHdl = dir.
make<TH1F>(
"dl",
"Track Length Minus MC Particle Length", 100, -50., 50.);
687 fHpvsp = dir.
make<TH2F>(
"pvsp",
"Reco Momentum vs. MC Truth Momentum",
688 100, 0., 5., 100, 0., 5.);
689 fHpvspc = dir.
make<TH2F>(
"pvspc",
"Reco Momentum vs. MC Truth Momentum (Contained Tracks)",
690 100, 0., 5., 100, 0., 5.);
691 fHdp = dir.
make<TH1F>(
"dp",
"Reco-MC Momentum Difference", 100, -5., 5.);
692 fHdpc = dir.
make<TH1F>(
"dpc",
"Reco-MC Momentum Difference (Contained Tracks)",
694 fHppull = dir.
make<TH1F>(
"ppull",
"Momentum Pull", 100, -10., 10.);
695 fHppullc = dir.
make<TH1F>(
"ppullc",
"Momentum Pull (Contained Tracks)", 100, -10., 10.);
703 fHmcendx = dir.
make<TH1F>(
"mcxend",
"MC X End Position",
705 fHmcendy = dir.
make<TH1F>(
"mcyend",
"MC Y End Position",
707 fHmcendz = dir.
make<TH1F>(
"mczend",
"MC Z End Position",
709 fHmctheta = dir.
make<TH1F>(
"mctheta",
"MC Theta", 20, 0., 3.142);
710 fHmcphi = dir.
make<TH1F>(
"mcphi",
"MC Phi", 10, -3.142, 3.142);
711 fHmctheta_xz = dir.
make<TH1F>(
"mctheta_xz",
"MC Theta_xz", 40, -3.142, 3.142);
712 fHmctheta_yz = dir.
make<TH1F>(
"mctheta_yz",
"MC Theta_yz", 40, -3.142, 3.142);
713 fHmcmom = dir.
make<TH1F>(
"mcmom",
"MC Momentum", 10, 0., 10.);
714 fHmcmoml = dir.
make<TH1F>(
"mcmoml",
"MC Momentum", 10, 0., 1.);
715 fHmcke = dir.
make<TH1F>(
"mcke",
"MC Kinetic Energy", 10, 0., 10.);
716 fHmckel = dir.
make<TH1F>(
"mckel",
"MC Kinetic Energy", 10, 0., 1.);
720 fHgstartx = dir.
make<TH1F>(
"gxstart",
"Good X Start Position",
722 fHgstarty = dir.
make<TH1F>(
"gystart",
"Good Y Start Position",
724 fHgstartz = dir.
make<TH1F>(
"gzstart",
"Good Z Start Position",
726 fHgendx = dir.
make<TH1F>(
"gxend",
"Good X End Position",
728 fHgendy = dir.
make<TH1F>(
"gyend",
"Good Y End Position",
730 fHgendz = dir.
make<TH1F>(
"gzend",
"Good Z End Position",
732 fHgtheta = dir.
make<TH1F>(
"gtheta",
"Good Theta", 20, 0., 3.142);
733 fHgphi = dir.
make<TH1F>(
"gphi",
"Good Phi", 10, -3.142, 3.142);
734 fHgtheta_xz = dir.
make<TH1F>(
"gtheta_xz",
"Good Theta_xz", 40, -3.142, 3.142);
735 fHgtheta_yz = dir.
make<TH1F>(
"gtheta_yz",
"Good Theta_yz", 40, -3.142, 3.142);
736 fHgmom = dir.
make<TH1F>(
"gmom",
"Good Momentum", 10, 0., 10.);
737 fHgmoml = dir.
make<TH1F>(
"gmoml",
"Good Momentum", 10, 0., 1.);
738 fHgke = dir.
make<TH1F>(
"gke",
"Good Kinetic Energy", 10, 0., 10.);
739 fHgkel = dir.
make<TH1F>(
"gkel",
"Good Kinetic Energy", 10, 0., 1.);
743 fHestartx = dir.
make<TH1F>(
"exstart",
"Efficiency vs. X Start Position",
745 fHestarty = dir.
make<TH1F>(
"eystart",
"Efficiency vs. Y Start Position",
747 fHestartz = dir.
make<TH1F>(
"ezstart",
"Efficiency vs. Z Start Position",
749 fHeendx = dir.
make<TH1F>(
"exend",
"Efficiency vs. X End Position",
751 fHeendy = dir.
make<TH1F>(
"eyend",
"Efficiency vs. Y End Position",
753 fHeendz = dir.
make<TH1F>(
"ezend",
"Efficiency vs. Z End Position",
755 fHetheta = dir.
make<TH1F>(
"etheta",
"Efficiency vs. Theta", 20, 0., 3.142);
756 fHephi = dir.
make<TH1F>(
"ephi",
"Efficiency vs. Phi", 10, -3.142, 3.142);
757 fHetheta_xz = dir.
make<TH1F>(
"etheta_xz",
"Efficiency vs. Theta_xz", 40, -3.142, 3.142);
758 fHetheta_yz = dir.
make<TH1F>(
"etheta_yz",
"Efficiency vs. Theta_yz", 40, -3.142, 3.142);
759 fHemom = dir.
make<TH1F>(
"emom",
"Efficiency vs. Momentum", 10, 0., 10.);
760 fHemoml = dir.
make<TH1F>(
"emoml",
"Efficiency vs. Momentum", 10, 0., 1.);
761 fHeke = dir.
make<TH1F>(
"eke",
"Efficiency vs. Kinetic Energy", 10, 0., 10.);
762 fHekel = dir.
make<TH1F>(
"ekel",
"Efficiency vs. Kinetic Energy", 10, 0., 1.);
763 fHelen = dir.
make<TH1F>(
"elen",
"Efficiency vs. Particle Length",
765 fHelens = dir.
make<TH1F>(
"elens",
"Efficiency vs. Particle Length",
783 ,
fDump(pset.get<int>(
"Dump"))
784 ,
fMinMCKE(pset.get<double>(
"MinMCKE"))
785 ,
fMinMCLen(pset.get<double>(
"MinMCLen"))
792 ,
fOrigin(pset.get<
std::string>(
"MCTrackOrigin",
"Any"))
800 if(
fOrigin.find(
"Beam") != std::string::npos) {
803 }
else if(
fOrigin.find(
"Cosmic") != std::string::npos) {
806 }
else if(
fOrigin.find(
"Super") != std::string::npos) {
809 }
else if(
fOrigin.find(
"Single") != std::string::npos) {
817 <<
"TrackAna configured with the following parameters:\n" 824 <<
" Dump = " <<
fDump <<
"\n" 825 <<
" MinMCKE = " <<
fMinMCKE <<
"\n" 853 std::unique_ptr<mf::LogInfo> pdump;
856 pdump = std::unique_ptr<mf::LogInfo>(
new mf::LogInfo(
"TrackAna"));
868 std::vector<std::pair<const sim::MCTrack*, int>> selected_mctracks;
872 selected_mctracks.reserve(mctrackh->size());
877 *pdump <<
"MC Tracks\n" 878 <<
" Id pdg x y z dx dy dz p\n" 879 <<
"-------------------------------------------------------------------------------------------\n";
887 imctrk != mctrackh->end(); ++imctrk) {
895 int apdg = std::abs(pdg);
910 double mctime = mctrk.
Start().
T();
919 double plen = length(mctrk, mcdx, mcstart, mcend, mcstartmom, mcendmom);
928 selected_mctracks.push_back(std::make_pair(&mctrk, -1));
933 double pstart = mcstartmom.Mag();
934 double pend = mcendmom.Mag();
936 << std::setw(3) << mctrk.
TrackID()
937 << std::setw(6) << mctrk.
PdgCode()
939 << std::fixed << std::setprecision(2)
940 << std::setw(10) << mcdx
942 << std::setw(3) << mctrk.
TrackID()
943 << std::setw(6) << mctrk.
PdgCode()
945 << std::fixed << std::setprecision(2)
946 << std::setw(10) << mcstart[0]
947 << std::setw(10) << mcstart[1]
948 << std::setw(10) << mcstart[2];
951 << std::fixed << std::setprecision(3)
952 << std::setw(10) << mcstartmom[0]/pstart
953 << std::setw(10) << mcstartmom[1]/pstart
954 << std::setw(10) << mcstartmom[2]/pstart;
957 *pdump << std::setw(32) <<
" ";
958 *pdump << std::setw(12) << std::fixed << std::setprecision(3) << pstart;
960 << std::setw(3) << mctrk.
TrackID()
961 << std::setw(6) << mctrk.
PdgCode()
963 << std::fixed << std::setprecision(2)
964 << std::setw(10) << mcend[0]
965 << std::setw(10) << mcend[1]
966 << std::setw(10) << mcend[2];
969 << std::fixed << std::setprecision(3)
970 << std::setw(10) << mcendmom[0]/pend
971 << std::setw(10) << mcendmom[1]/pend
972 << std::setw(10) << mcendmom[2]/pend;
975 *pdump << std::setw(32)<<
" ";
976 *pdump << std::setw(12) << std::fixed << std::setprecision(3) << pend
977 <<
"\nLength: " << plen <<
"\n";
983 std::ostringstream ostr;
984 ostr <<
"MC" << (
fIgnoreSign ?
"All" : (pdg > 0 ?
"Pos" :
"Neg")) << std::abs(pdg);
989 double mctheta_xz = std::atan2(mcstartmom.X(), mcstartmom.Z());
990 double mctheta_yz = std::atan2(mcstartmom.Y(), mcstartmom.Z());
991 double mcmom = mcstartmom.Mag();
993 double mcke = mcmom*mcmom / (std::sqrt(mcmom*mcmom + mcmass*mcmass) + mcmass);
995 mchists.fHmcstartx->Fill(mcstart.X());
996 mchists.fHmcstarty->Fill(mcstart.Y());
997 mchists.fHmcstartz->Fill(mcstart.Z());
998 mchists.fHmcendx->Fill(mcend.X());
999 mchists.fHmcendy->Fill(mcend.Y());
1000 mchists.fHmcendz->Fill(mcend.Z());
1001 mchists.fHmctheta->Fill(mcstartmom.Theta());
1002 mchists.fHmcphi->Fill(mcstartmom.Phi());
1003 mchists.fHmctheta_xz->Fill(mctheta_xz);
1004 mchists.fHmctheta_yz->Fill(mctheta_yz);
1005 mchists.fHmcmom->Fill(mcmom);
1006 mchists.fHmcmoml->Fill(mcmom);
1007 mchists.fHmcke->Fill(mcke);
1008 mchists.fHmckel->Fill(mcke);
1009 mchists.fHmclen->Fill(plen);
1010 mchists.fHmclens->Fill(plen);
1029 std::vector<art::Ptr<recob::Hit> > allhits;
1031 allhits.reserve(hith->size());
1032 for(
unsigned int i=0; i<hith->size(); ++i) {
1033 allhits.emplace_back(hith, i);
1048 <<
"TrackAna read " << trackvh->size()
1049 <<
" vectors of Stitched PtrVectorsof tracks.";
1056 *pdump <<
"\nReconstructed Tracks\n" 1057 <<
" Id MCid x y z dx dy dz p\n" 1058 <<
"-------------------------------------------------------------------------------------------\n";
1063 int ntrack = trackh->size();
1064 for(
int i = 0; i < ntrack; ++i) {
1070 std::vector<art::Ptr<recob::Hit> > trackhits;
1071 tkhit_find.
get(i, trackhits);
1084 TVector3 pos = track.
Vertex<TVector3>();
1086 TVector3 end = track.
End<TVector3>();
1090 double dpos = bdist(pos);
1091 double dend = bdist(end);
1092 double tlen = length(track);
1093 double theta_xz = std::atan2(dir.X(), dir.Z());
1094 double theta_yz = std::atan2(dir.Y(), dir.Z());
1104 rhists.
fHendx->Fill(end.X());
1105 rhists.
fHendy->Fill(end.Y());
1106 rhists.
fHendz->Fill(end.Z());
1107 rhists.
fHendd->Fill(dend);
1108 rhists.
fHtheta->Fill(dir.Theta());
1109 rhists.
fHphi->Fill(dir.Phi());
1116 rhists.
fHmom->Fill(mom);
1117 rhists.
fHmoml->Fill(mom);
1118 rhists.
fHlen->Fill(tlen);
1119 rhists.
fHlens->Fill(tlen);
1127 for(
int swap=0; swap<2; ++swap) {
1137 int start_point = (swap == 0 ? 0 : ntraj-1);
1143 rot(1, 0) = -rot(1, 0);
1144 rot(2, 0) = -rot(2, 0);
1145 rot(1, 1) = -rot(1, 1);
1146 rot(2, 1) = -rot(2, 1);
1147 rot(1, 2) = -rot(1, 2);
1148 rot(2, 2) = -rot(2, 2);
1150 pos = track.
End<TVector3>();
1152 end = track.
Vertex<TVector3>();
1158 theta_xz = std::atan2(dir.X(), dir.Z());
1159 theta_yz = std::atan2(dir.Y(), dir.Z());
1170 for(
unsigned int imc = 0; imc < selected_mctracks.size(); ++imc) {
1171 const sim::MCTrack& mctrk = *selected_mctracks[imc].first;
1176 throw cet::exception(
"TrackAna") <<
"no particle with ID=" << pdg <<
"\n";
1177 const MCHists& mchists = iMCHistMap->second;
1181 double mctime = mctrk.
Start().
T();
1189 TVector3 mcstartmom;
1191 double plen = length(mctrk, mcdx, mcstart, mcend, mcstartmom, mcendmom);
1195 TVector3 mcpos = mcstart - pos;
1200 TVector3 mcmoml = rot * mcstartmom;
1201 TVector3 mcposl = rot * mcpos;
1203 double colinearity = mcmoml.Z() / mcmoml.Mag();
1205 double u = mcposl.X();
1206 double v = mcposl.Y();
1207 double w = mcposl.Z();
1209 double pu = mcmoml.X();
1210 double pv = mcmoml.Y();
1211 double pw = mcmoml.Z();
1213 double dudw = pu / pw;
1214 double dvdw = pv / pw;
1216 double u0 = u - w * dudw;
1217 double v0 = v - w * dvdw;
1218 double uv0 = std::sqrt(u0*u0 + v0*v0);
1228 mchists.
fHdudwpull->Fill(dudw / std::sqrt(cov(2,2)));
1229 mchists.
fHdvdwpull->Fill(dvdw / std::sqrt(cov(3,3)));
1231 mchists.
fHcosth->Fill(colinearity);
1236 mchists.
fHmcu->Fill(u0);
1237 mchists.
fHmcv->Fill(v0);
1238 mchists.
fHmcw->Fill(w);
1239 mchists.
fHupull->Fill(u0 / std::sqrt(cov(0,0)));
1240 mchists.
fHvpull->Fill(v0 / std::sqrt(cov(1,1)));
1246 double mctheta_xz = std::atan2(mcstartmom.X(), mcstartmom.Z());
1247 double mctheta_yz = std::atan2(mcstartmom.Y(), mcstartmom.Z());
1248 double mcmom = mcstartmom.Mag();
1250 double mcke = mcmom*mcmom / (std::sqrt(mcmom*mcmom + mcmass*mcmass) + mcmass);
1252 mchists.
fHstartdx->Fill(pos.X() - mcstart.X());
1253 mchists.
fHstartdy->Fill(pos.Y() - mcstart.Y());
1254 mchists.
fHstartdz->Fill(pos.Z() - mcstart.Z());
1255 mchists.
fHenddx->Fill(end.X() - mcend.X());
1256 mchists.
fHenddy->Fill(end.Y() - mcend.Y());
1257 mchists.
fHenddz->Fill(end.Z() - mcend.Z());
1258 mchists.
fHlvsl->Fill(plen, tlen);
1259 mchists.
fHdl->Fill(tlen - plen);
1260 mchists.
fHpvsp->Fill(mcmom, mom);
1261 double dp = mom - mcmom;
1262 mchists.
fHdp->Fill(dp);
1263 mchists.
fHppull->Fill(dp / std::sqrt(cov(4,4)));
1264 if(std::abs(dpos) >= 5. && std::abs(dend) >= 5.) {
1265 mchists.
fHpvspc->Fill(mcmom, mom);
1266 mchists.
fHdpc->Fill(dp);
1267 mchists.
fHppullc->Fill(dp / std::sqrt(cov(4,4)));
1282 std::set<int> tkidset;
1283 tkidset.insert(mcid);
1285 bt_serv->HitCollectionEfficiency(tkidset, trackhits, allhits,
geo::k3D);
1286 double hitpurity = bt_serv->HitCollectionPurity(tkidset, trackhits);
1295 mchists.
fHgendx->Fill(mcend.X());
1296 mchists.
fHgendy->Fill(mcend.Y());
1297 mchists.
fHgendz->Fill(mcend.Z());
1298 mchists.
fHgtheta->Fill(mcstartmom.Theta());
1299 mchists.
fHgphi->Fill(mcstartmom.Phi());
1302 mchists.
fHgmom->Fill(mcmom);
1304 mchists.
fHgke->Fill(mcke);
1305 mchists.
fHgkel->Fill(mcke);
1306 mchists.
fHglen->Fill(plen);
1310 selected_mctracks[imc].second = i;
1314 float KE = ptkl->
E() - ptkl->
Mass();
1315 std::string KEUnits =
" GeV";
1323 <<
" Match MCTkID "<<std::setw(6)<<mctrk.
TrackID()
1324 <<
" Origin "<<mctrk.
Origin()
1325 <<
" PDG"<<std::setw(5)<<mctrk.
PdgCode()
1326 <<
" KE"<<std::setw(4)<<(int)KE<<KEUnits
1327 <<
" RecoTrkID "<<track.
ID()
1328 <<
" hitEff "<<std::setprecision(2)<<hiteff<<
" hitPur "<<hitpurity;
1329 int sWire, sTick, eWire, eTick;
1331 for(
unsigned short ipl = 0; ipl < geom->
Nplanes(); ++ipl) {
1336 mf::LogVerbatim(
"TrackAna")<<
" Wire:Tick in Pln "<<ipl<<
" W:T "<<sWire<<
":"<<sTick<<
" - "<<eWire<<
":"<<eTick;
1348 TVector3 pos = track.
Vertex<TVector3>();
1350 TVector3 end = track.
End<TVector3>();
1356 *pdump <<
"\nOffset" 1357 << std::setw(3) << track.
ID()
1358 << std::setw(6) << mcid
1360 << std::fixed << std::setprecision(2)
1361 << std::setw(10) << trackdx
1363 << std::setw(3) << track.
ID()
1364 << std::setw(6) << mcid
1366 << std::fixed << std::setprecision(2)
1367 << std::setw(10) << pos[0]
1368 << std::setw(10) << pos[1]
1369 << std::setw(10) << pos[2];
1372 << std::fixed << std::setprecision(3)
1373 << std::setw(10) << dir[0]
1374 << std::setw(10) << dir[1]
1375 << std::setw(10) << dir[2];
1378 *pdump << std::setw(32) <<
" ";
1379 *pdump << std::setw(12) << std::fixed << std::setprecision(3) << pstart;
1381 << std::setw(3) << track.
ID()
1382 << std::setw(6) << mcid
1384 << std::fixed << std::setprecision(2)
1385 << std::setw(10) << end[0]
1386 << std::setw(10) << end[1]
1387 << std::setw(10) << end[2];
1390 << std::fixed << std::setprecision(3)
1391 << std::setw(10) << enddir[0]
1392 << std::setw(10) << enddir[1]
1393 << std::setw(10) << enddir[2];
1396 *pdump << std::setw(32)<<
" ";
1397 *pdump << std::setw(12) << std::fixed << std::setprecision(3) << pend
1398 <<
"\nLength: " << tlen <<
"\n";
1406 for(
unsigned int imc = 0; imc < selected_mctracks.size(); ++imc) {
1407 if(selected_mctracks[imc].second >= 0)
continue;
1408 const sim::MCTrack& mctrk = *selected_mctracks[imc].first;
1410 float KE = ptkl->
E() - ptkl->
Mass();
1411 std::string KEUnits =
" GeV";
1418 TVector3 mcstart, mcend, mcstartmom, mcendmom;
1420 double plen = length(mctrk, mcdx, mcstart, mcend, mcstartmom, mcendmom);
1422 <<
" NoMat MCTkID "<<std::setw(6)<<mctrk.
TrackID()
1423 <<
" Origin "<<mctrk.
Origin()
1424 <<
" PDG"<<std::setw(5)<<mctrk.
PdgCode()
1425 <<
" KE"<<std::setw(4)<<(int)KE<<KEUnits
1426 <<
" Length "<<std::fixed<<std::setprecision(1)<<plen<<
" cm";
1428 int sWire, sTick, eWire, eTick;
1430 for(
unsigned short ipl = 0; ipl < geom->
Nplanes(); ++ipl) {
1436 <<
" W:T "<<sWire<<
":"<<sTick<<
" - "<<eWire<<
":"<<eTick;
1452 std::map<int, std::map<int, art::PtrVector<recob::Hit>> > hitmap;
1453 std::map<int, int > KEmap;
1462 int ntv(trackvh->size());
1464 std::vector < art::PtrVector<recob::Track> >
::const_iterator cti = trackvh->begin();
1469 int nsppts_assnwhole = fswhole.size();
1470 std::cout <<
"TrackAna: Number of clumps of Spacepoints from Assn for all Tracks: " << nsppts_assnwhole << std::endl;
1476 std::cout <<
"\n" <<
"\t\t TrkAna: Fresh fRecoHistMap[0] ******* \n" << std::endl;
1480 std::vector < std::vector <unsigned int> > NtrkIdsAll;
1481 std::vector < double > ntvsorted;
1486 for (
int o = 0; o < ntv; ++o)
1491 int ntrack = pvtrack.
size();
1493 std::vector< std::vector <unsigned int> > NtrkId_Hit;
1494 std::vector<unsigned int> vecMode;
1497 for(
int i = 0; i < ntrack; ++i) {
1509 int nsppts_assn = fs.at(i).size();
1513 const auto&
sppt = fs.at(i);
1523 std::vector <unsigned int> vecNtrkIds;
1524 for(
int is = 0; is < nsppts_assn; ++is) {
1525 int nhits = fh.at(is).size();
1526 for(
int ih = 0; ih < nhits; ++ih) {
1527 const auto&
hit = fh.at(is).at(ih);
1539 int trackID = std::abs(itid->trackID);
1540 hitmap[trackID][o].push_back(
hit);
1542 if (justOne) { vecNtrkIds.push_back(trackID); justOne=
false; }
1553 TVector3 mcstartmom;
1555 double mctime = part->
T();
1558 double plen = length(*part, mcdx, mcstart, mcend, mcstartmom, mcendmom);
1560 KEmap[(int)(1e6*plen)] = trackID;
1571 NtrkId_Hit.push_back(vecNtrkIds);
1574 int max(-12),
n(1), ind(0);
1575 std::sort(vecNtrkIds.begin(),vecNtrkIds.end());
1576 std::vector<unsigned int> strkIds(vecNtrkIds);
1577 while ( ii < vecNtrkIds.size() )
1579 if (strkIds.at(ii) != strkIds.at(ii-1))
1587 if (n>
max) {
max =
n; ind = ii;}
1592 if (strkIds.begin()!=strkIds.end())
1593 mode = strkIds.at(ind);
1594 vecMode.push_back(mode);
1597 if (strkIds.size()!=0)
1598 rhistsStitched.
fModeFrac->Fill((
double)
max/(
double)strkIds.size());
1607 if (!assns)
throw cet::exception(
"TrackAna") <<
"Bad Associations. \n";
1614 NtrkIdsAll.push_back(vecMode);
1616 std::unique(NtrkIdsAll.back().begin(),NtrkIdsAll.back().end());
1618 for (
auto const val : NtrkIdsAll.back())
1621 sum += hitmap[val][o].size();
1623 ntvsorted.push_back(sum);
1632 for (
auto it = KEmap.rbegin(); it!=KEmap.rend(); ++it)
1648 for (
auto it = KEmap.rbegin(); it!=KEmap.rend(); ++it)
1650 int val = it->second;
1653 rhistsStitched.
fNTrkIdTrks3->Fill(o,v,hitmap[val][o].size());
1661 flattener flat(NtrkIdsAll);
1662 std::vector <unsigned int> &v = flat;
1664 for (
auto const val : v)
1669 double T(part->
E() - 0.001*part->
Mass());
1670 rhistsStitched.
fNTrkIdTrks->Fill(std::count(v.begin(),v.end(),val));
1671 rhistsStitched.
fNTrkIdTrks2->Fill(std::count(v.begin(),v.end(),val),T);
1689 <<
"TrackAna statistics:\n" 1696 const MCHists& mchists = i->second;
1717 template <
typename T>
1720 std::vector<size_t> idx(v.size());
1721 for (
size_t i = 0; i != idx.size(); ++i) idx[i] = i;
1723 std::sort(idx.begin(), idx.end(),
1724 [&v](
size_t i1,
size_t i2) {
return v[i1] > v[i2];});
double E(const int i=0) const
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
const simb::MCParticle * TrackIdToParticle_P(int const &id)
unsigned int NumberTrajectoryPoints() const
const TLorentzVector & Position(const int i=0) const
simb::Origin_t Origin() const
double EndMomentum() const
double VertexMomentum() const
std::vector< size_t > fsort_indexes(const std::vector< T > &v)
geo::Length_t DetHalfWidth(geo::TPCID const &tpcid) const
Returns the half width of the active volume of the specified TPC.
std::string fHitSpptAssocModuleLabel
std::string fTrkSpptAssocModuleLabel
const std::vector< sim::TrackIDE > HitToTrackIDEs(recob::Hit const &hit)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::string fSpacepointModuleLabel
Declaration of signal hit object.
enum simb::_ev_origin Origin_t
event origin types
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
Vector_t VertexDirection() const
Access to track direction at different points.
const SMatrixSym55 & VertexCovariance() const
Access to covariance matrices.
std::string fStitchModuleLabel
TrackAna(fhicl::ParameterSet const &pset)
void anaStitch(const art::Event &evt)
TFileDirectory mkdir(std::string const &dir, std::string const &descr="")
std::map< int, MCHists > fMCHistMap
virtual double ConvertXToTicks(double X, int p, int t, int c) const =0
3-dimensional objects, potentially hits, clusters, prongs, etc.
Rotation_t GlobalToLocalRotationAtPoint(size_t p) const
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
geo::Length_t DetHalfHeight(geo::TPCID const &tpcid) const
Returns the half height of the active volume of the specified TPC.
double Length(size_t p=0) const
Access to various track properties.
#define DEFINE_ART_MODULE(klass)
Provides recob::Track data product.
static const int NoParticleId
single particles thrown at the detector
geo::WireID::WireID_t NearestWire(geo::Point_t const &point, geo::PlaneID const &planeid) const
Returns the index of wire closest to position in the specified TPC.
Point_t const & Vertex() const
Access to track position at different points.
double T(const int i=0) const
const SMatrixSym55 & EndCovariance() const
Access to covariance matrices.
geo::Length_t DetLength(geo::TPCID const &tpcid) const
Returns the length of the active volume of the specified TPC.
std::string fMCTrackModuleLabel
EventNumber_t event() const
EDAnalyzer(Table< Config > const &config)
void analyze(const art::Event &evt)
Class def header for mctrack data container.
Detector simulation of raw signals on wires.
const TLorentzVector & Momentum() const
simb::Origin_t fOriginValue
T * make(ARGS...args) const
std::string value(boost::any const &)
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
virtual double DriftVelocity(double efield=0., double temperature=0.) const =0
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
Vector_t EndDirection() const
Access to track direction at different points.
std::map< int, RecoHists > fRecoHistMap
const TLorentzVector & Momentum(const int i=0) const
Point_t const & End() const
Access to track position at different points.
const MCStep & Start() const
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
size_type get(size_type i, reference item, data_reference data) const
std::string fTrackModuleLabel
unsigned int TrackID() const
std::string fHitModuleLabel
Tools and modules for checking out the basics of the Monte Carlo.
art framework interface to geometry description
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
cet::coded_exception< error, detail::translate > exception
Signal from collection planes.