33 #include "cetlib_except/exception.h" 55 double bdist(
const TVector3& pos,
unsigned int = 0,
unsigned int = 0)
80 for(
int i = 1; i <
n; ++i) {
93 TVector3& start, TVector3&
end, TVector3& startmom, TVector3& endmom,
94 unsigned int = 0,
unsigned int = 0)
115 for(
int i = 0; i <
n; ++i) {
116 TVector3 pos = part.
Position(i).Vect();
122 if(pos.X() >= xmin &&
130 if(ticks >= 0. && ticks < detprop->ReadOutWindowSize()) {
137 result += disp.Mag();
155 TVector3& start, TVector3& end, TVector3& startmom, TVector3& endmom,
156 unsigned int = 0,
unsigned int = 0)
162 auto const* detprop = lar::providerFrom<detinfo::DetectorPropertiesService>();
176 int n = mctrk.size();
179 for(
int i = 0; i <
n; ++i) {
180 TVector3 pos = mctrk[i].Position().Vect();
186 if(pos.X() >= xmin &&
194 if(ticks >= 0. && ticks < detprop->ReadOutWindowSize()) {
197 startmom = 0.001 * mctrk[i].Momentum().Vect();
201 result += disp.Mag();
206 endmom = 0.001 * mctrk[i].Momentum().Vect();
216 void effcalc(
const TH1* hnum,
const TH1* hden, TH1* heff)
218 int nbins = hnum->GetNbinsX();
219 if (nbins != hden->GetNbinsX())
220 throw cet::exception(
"TrackAna") <<
"effcalc[" __FILE__
"]: incompatible histograms (I)\n";
221 if (nbins != heff->GetNbinsX())
222 throw cet::exception(
"TrackAna") <<
"effcalc[" __FILE__
"]: incompatible histograms (II)\n";
226 for(
int ibin = 0; ibin <= nbins+1; ++ibin) {
227 double num = hnum->GetBinContent(ibin);
228 double den = hden->GetBinContent(ibin);
230 heff->SetBinContent(ibin, 0.);
231 heff->SetBinError(ibin, 0.);
234 double eff = num /
den;
239 double err = std::sqrt(eff * (1.-eff) / den);
240 heff->SetBinContent(ibin, eff);
241 heff->SetBinError(ibin, err);
245 heff->SetMinimum(0.);
246 heff->SetMaximum(1.05);
247 heff->SetMarkerStyle(20);
251 class flattener :
public std::vector<unsigned int> {
255 flattener() :
std::
vector<unsigned int>() {};
257 flattener(
const std::vector<std::vector<unsigned int> >& input)
262 void Convert(
const std::vector<std::vector<unsigned int> >& input)
266 for(
auto const& vec : input)
267 length += vec.size();
270 for(
auto const& vec : input)
271 for(
auto const&
value : vec)
334 MCHists(
const std::string& subdir);
442 template <
typename T> std::vector<size_t> fsort_indexes(
const std::vector<T> &v) ;
513 TrackAna::RecoHists::RecoHists(
const std::string& subdir)
534 fHstartx = dir.
make<TH1F>(
"xstart",
"X Start Position",
536 fHstarty = dir.
make<TH1F>(
"ystart",
"Y Start Position",
538 fHstartz = dir.
make<TH1F>(
"zstart",
"Z Start Position",
540 fHstartd = dir.
make<TH1F>(
"dstart",
"Start Position Distance to Boundary",
542 fHendx = dir.
make<TH1F>(
"xend",
"X End Position",
544 fHendy = dir.
make<TH1F>(
"yend",
"Y End Position",
546 fHendz = dir.
make<TH1F>(
"zend",
"Z End Position",
548 fHendd = dir.
make<TH1F>(
"dend",
"End Position Distance to Boundary",
550 fHtheta = dir.
make<TH1F>(
"theta",
"Theta", 100, 0., 3.142);
551 fHphi = dir.
make<TH1F>(
"phi",
"Phi", 100, -3.142, 3.142);
552 fHtheta_xz = dir.
make<TH1F>(
"theta_xz",
"Theta_xz", 100, -3.142, 3.142);
553 fHtheta_yz = dir.
make<TH1F>(
"theta_yz",
"Theta_yz", 100, -3.142, 3.142);
554 fHmom = dir.
make<TH1F>(
"mom",
"Momentum", 100, 0., 10.);
555 fHmoml = dir.
make<TH1F>(
"moml",
"Momentum", 100, 0., 1.);
556 fHlen = dir.
make<TH1F>(
"len",
"Track Length", 100, 0., 1.1 * geom->
DetLength());
557 fHlens = dir.
make<TH1F>(
"lens",
"Track Length", 100, 0., 0.1 * geom->
DetLength());
558 fHHitChg = dir.
make<TH1F>(
"hchg",
"Hit Charge (ADC counts)", 100, 0., 4000.);
559 fHHitWidth = dir.
make<TH1F>(
"hwid",
"Hit Width (ticks)", 40, 0., 20.);
560 fHHitPdg = dir.
make<TH1F>(
"hpdg",
"Hit Pdg code",5001, -2500.5, +2500.5);
561 fHHitTrkId = dir.
make<TH1F>(
"htrkid",
"Hit Track ID", 401, -200.5, +200.5);
562 fModeFrac = dir.
make<TH1F>(
"hmodefrac",
"quasi-Purity: Fraction of component tracks with the Track mode value", 20, 0.01, 1.01);
563 fNTrkIdTrks = dir.
make<TH1F>(
"hntrkids",
"quasi-Efficiency: Number of stitched tracks in which TrkId appears", 20, 0., +10.0);
564 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);
565 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);
566 fNTrkIdTrks3->GetXaxis()->SetTitle(
"Sorted-by-Descending-CPlane-Hits outer Track Number");
567 fNTrkIdTrks3->GetYaxis()->SetTitle(
"Sorted-by-Descending-True-Length G4Track");
573 TrackAna::MCHists::MCHists() :
675 fHduvcosth = dir.
make<TH2F>(
"duvcosth",
"Delta(uv) vs. Colinearity",
676 100, 0.95, 1., 100, 0., 1.);
677 fHcosth = dir.
make<TH1F>(
"colin",
"Colinearity", 100, 0.95, 1.);
678 fHmcu = dir.
make<TH1F>(
"mcu",
"MC Truth U", 100, -5., 5.);
679 fHmcv = dir.
make<TH1F>(
"mcv",
"MC Truth V", 100, -5., 5.);
680 fHmcw = dir.
make<TH1F>(
"mcw",
"MC Truth W", 100, -20., 20.);
681 fHupull = dir.
make<TH1F>(
"dupull",
"U Pull", 100, -20., 20.);
682 fHvpull = dir.
make<TH1F>(
"dvpull",
"V Pull", 100, -20., 20.);
683 fHmcdudw = dir.
make<TH1F>(
"mcdudw",
"MC Truth U Slope", 100, -0.2, 0.2);
684 fHmcdvdw = dir.
make<TH1F>(
"mcdvdw",
"MV Truth V Slope", 100, -0.2, 0.2);
685 fHdudwpull = dir.
make<TH1F>(
"dudwpull",
"U Slope Pull", 100, -10., 10.);
686 fHdvdwpull = dir.
make<TH1F>(
"dvdwpull",
"V Slope Pull", 100, -10., 10.);
687 fHHitEff = dir.
make<TH1F>(
"hiteff",
"MC Hit Efficiency", 100, 0., 1.0001);
688 fHHitPurity = dir.
make<TH1F>(
"hitpurity",
"MC Hit Purity", 100, 0., 1.0001);
689 fHstartdx = dir.
make<TH1F>(
"startdx",
"Start Delta x", 100, -10., 10.);
690 fHstartdy = dir.
make<TH1F>(
"startdy",
"Start Delta y", 100, -10., 10.);
691 fHstartdz = dir.
make<TH1F>(
"startdz",
"Start Delta z", 100, -10., 10.);
692 fHenddx = dir.
make<TH1F>(
"enddx",
"End Delta x", 100, -10., 10.);
693 fHenddy = dir.
make<TH1F>(
"enddy",
"End Delta y", 100, -10., 10.);
694 fHenddz = dir.
make<TH1F>(
"enddz",
"End Delta z", 100, -10., 10.);
695 fHlvsl = dir.
make<TH2F>(
"lvsl",
"Reco Length vs. MC Truth Length",
697 fHdl = dir.
make<TH1F>(
"dl",
"Track Length Minus MC Particle Length", 100, -50., 50.);
698 fHpvsp = dir.
make<TH2F>(
"pvsp",
"Reco Momentum vs. MC Truth Momentum",
699 100, 0., 5., 100, 0., 5.);
700 fHpvspc = dir.
make<TH2F>(
"pvspc",
"Reco Momentum vs. MC Truth Momentum (Contained Tracks)",
701 100, 0., 5., 100, 0., 5.);
702 fHdp = dir.
make<TH1F>(
"dp",
"Reco-MC Momentum Difference", 100, -5., 5.);
703 fHdpc = dir.
make<TH1F>(
"dpc",
"Reco-MC Momentum Difference (Contained Tracks)",
705 fHppull = dir.
make<TH1F>(
"ppull",
"Momentum Pull", 100, -10., 10.);
706 fHppullc = dir.
make<TH1F>(
"ppullc",
"Momentum Pull (Contained Tracks)", 100, -10., 10.);
714 fHmcendx = dir.
make<TH1F>(
"mcxend",
"MC X End Position",
716 fHmcendy = dir.
make<TH1F>(
"mcyend",
"MC Y End Position",
718 fHmcendz = dir.
make<TH1F>(
"mczend",
"MC Z End Position",
720 fHmctheta = dir.
make<TH1F>(
"mctheta",
"MC Theta", 20, 0., 3.142);
721 fHmcphi = dir.
make<TH1F>(
"mcphi",
"MC Phi", 10, -3.142, 3.142);
722 fHmctheta_xz = dir.
make<TH1F>(
"mctheta_xz",
"MC Theta_xz", 40, -3.142, 3.142);
723 fHmctheta_yz = dir.
make<TH1F>(
"mctheta_yz",
"MC Theta_yz", 40, -3.142, 3.142);
724 fHmcmom = dir.
make<TH1F>(
"mcmom",
"MC Momentum", 10, 0., 10.);
725 fHmcmoml = dir.
make<TH1F>(
"mcmoml",
"MC Momentum", 10, 0., 1.);
726 fHmcke = dir.
make<TH1F>(
"mcke",
"MC Kinetic Energy", 10, 0., 10.);
727 fHmckel = dir.
make<TH1F>(
"mckel",
"MC Kinetic Energy", 10, 0., 1.);
731 fHgstartx = dir.
make<TH1F>(
"gxstart",
"Good X Start Position",
733 fHgstarty = dir.
make<TH1F>(
"gystart",
"Good Y Start Position",
735 fHgstartz = dir.
make<TH1F>(
"gzstart",
"Good Z Start Position",
737 fHgendx = dir.
make<TH1F>(
"gxend",
"Good X End Position",
739 fHgendy = dir.
make<TH1F>(
"gyend",
"Good Y End Position",
741 fHgendz = dir.
make<TH1F>(
"gzend",
"Good Z End Position",
743 fHgtheta = dir.
make<TH1F>(
"gtheta",
"Good Theta", 20, 0., 3.142);
744 fHgphi = dir.
make<TH1F>(
"gphi",
"Good Phi", 10, -3.142, 3.142);
745 fHgtheta_xz = dir.
make<TH1F>(
"gtheta_xz",
"Good Theta_xz", 40, -3.142, 3.142);
746 fHgtheta_yz = dir.
make<TH1F>(
"gtheta_yz",
"Good Theta_yz", 40, -3.142, 3.142);
747 fHgmom = dir.
make<TH1F>(
"gmom",
"Good Momentum", 10, 0., 10.);
748 fHgmoml = dir.
make<TH1F>(
"gmoml",
"Good Momentum", 10, 0., 1.);
749 fHgke = dir.
make<TH1F>(
"gke",
"Good Kinetic Energy", 10, 0., 10.);
750 fHgkel = dir.
make<TH1F>(
"gkel",
"Good Kinetic Energy", 10, 0., 1.);
754 fHestartx = dir.
make<TH1F>(
"exstart",
"Efficiency vs. X Start Position",
756 fHestarty = dir.
make<TH1F>(
"eystart",
"Efficiency vs. Y Start Position",
758 fHestartz = dir.
make<TH1F>(
"ezstart",
"Efficiency vs. Z Start Position",
760 fHeendx = dir.
make<TH1F>(
"exend",
"Efficiency vs. X End Position",
762 fHeendy = dir.
make<TH1F>(
"eyend",
"Efficiency vs. Y End Position",
764 fHeendz = dir.
make<TH1F>(
"ezend",
"Efficiency vs. Z End Position",
766 fHetheta = dir.
make<TH1F>(
"etheta",
"Efficiency vs. Theta", 20, 0., 3.142);
767 fHephi = dir.
make<TH1F>(
"ephi",
"Efficiency vs. Phi", 10, -3.142, 3.142);
768 fHetheta_xz = dir.
make<TH1F>(
"etheta_xz",
"Efficiency vs. Theta_xz", 40, -3.142, 3.142);
769 fHetheta_yz = dir.
make<TH1F>(
"etheta_yz",
"Efficiency vs. Theta_yz", 40, -3.142, 3.142);
770 fHemom = dir.
make<TH1F>(
"emom",
"Efficiency vs. Momentum", 10, 0., 10.);
771 fHemoml = dir.
make<TH1F>(
"emoml",
"Efficiency vs. Momentum", 10, 0., 1.);
772 fHeke = dir.
make<TH1F>(
"eke",
"Efficiency vs. Kinetic Energy", 10, 0., 10.);
773 fHekel = dir.
make<TH1F>(
"ekel",
"Efficiency vs. Kinetic Energy", 10, 0., 1.);
774 fHelen = dir.
make<TH1F>(
"elen",
"Efficiency vs. Particle Length",
776 fHelens = dir.
make<TH1F>(
"elens",
"Efficiency vs. Particle Length",
794 ,
fDump(pset.get<int>(
"Dump"))
795 ,
fMinMCKE(pset.get<double>(
"MinMCKE"))
796 ,
fMinMCLen(pset.get<double>(
"MinMCLen"))
803 ,
fOrigin(pset.get<
std::string>(
"MCTrackOrigin",
"Any"))
811 if(
fOrigin.find(
"Beam") != std::string::npos) {
814 }
else if(
fOrigin.find(
"Cosmic") != std::string::npos) {
817 }
else if(
fOrigin.find(
"Super") != std::string::npos) {
820 }
else if(
fOrigin.find(
"Single") != std::string::npos) {
828 <<
"TrackAna configured with the following parameters:\n" 835 <<
" Dump = " <<
fDump <<
"\n" 836 <<
" MinMCKE = " <<
fMinMCKE <<
"\n" 864 std::unique_ptr<mf::LogInfo> pdump;
867 pdump = std::unique_ptr<mf::LogInfo>(
new mf::LogInfo(
"TrackAna"));
879 std::vector<std::pair<const sim::MCTrack*, int>> selected_mctracks;
883 selected_mctracks.reserve(mctrackh->size());
888 *pdump <<
"MC Tracks\n" 889 <<
" Id pdg x y z dx dy dz p\n" 890 <<
"-------------------------------------------------------------------------------------------\n";
898 imctrk != mctrackh->end(); ++imctrk) {
906 int apdg = std::abs(pdg);
921 double mctime = mctrk.
Start().
T();
930 double plen = length(mctrk, mcdx, mcstart, mcend, mcstartmom, mcendmom);
939 selected_mctracks.push_back(std::make_pair(&mctrk, -1));
944 double pstart = mcstartmom.Mag();
945 double pend = mcendmom.Mag();
947 << std::setw(3) << mctrk.
TrackID()
948 << std::setw(6) << mctrk.
PdgCode()
950 << std::fixed << std::setprecision(2)
951 << std::setw(10) << mcdx
953 << std::setw(3) << mctrk.
TrackID()
954 << std::setw(6) << mctrk.
PdgCode()
956 << std::fixed << std::setprecision(2)
957 << std::setw(10) << mcstart[0]
958 << std::setw(10) << mcstart[1]
959 << std::setw(10) << mcstart[2];
962 << std::fixed << std::setprecision(3)
963 << std::setw(10) << mcstartmom[0]/pstart
964 << std::setw(10) << mcstartmom[1]/pstart
965 << std::setw(10) << mcstartmom[2]/pstart;
968 *pdump << std::setw(32) <<
" ";
969 *pdump << std::setw(12) << std::fixed << std::setprecision(3) << pstart;
971 << std::setw(3) << mctrk.
TrackID()
972 << std::setw(6) << mctrk.
PdgCode()
974 << std::fixed << std::setprecision(2)
975 << std::setw(10) << mcend[0]
976 << std::setw(10) << mcend[1]
977 << std::setw(10) << mcend[2];
980 << std::fixed << std::setprecision(3)
981 << std::setw(10) << mcendmom[0]/pend
982 << std::setw(10) << mcendmom[1]/pend
983 << std::setw(10) << mcendmom[2]/pend;
986 *pdump << std::setw(32)<<
" ";
987 *pdump << std::setw(12) << std::fixed << std::setprecision(3) << pend
988 <<
"\nLength: " << plen <<
"\n";
994 std::ostringstream ostr;
995 ostr <<
"MC" << (
fIgnoreSign ?
"All" : (pdg > 0 ?
"Pos" :
"Neg")) << std::abs(pdg);
1000 double mctheta_xz = std::atan2(mcstartmom.X(), mcstartmom.Z());
1001 double mctheta_yz = std::atan2(mcstartmom.Y(), mcstartmom.Z());
1002 double mcmom = mcstartmom.Mag();
1004 double mcke = mcmom*mcmom / (std::sqrt(mcmom*mcmom + mcmass*mcmass) + mcmass);
1006 mchists.fHmcstartx->Fill(mcstart.X());
1007 mchists.fHmcstarty->Fill(mcstart.Y());
1008 mchists.fHmcstartz->Fill(mcstart.Z());
1009 mchists.fHmcendx->Fill(mcend.X());
1010 mchists.fHmcendy->Fill(mcend.Y());
1011 mchists.fHmcendz->Fill(mcend.Z());
1012 mchists.fHmctheta->Fill(mcstartmom.Theta());
1013 mchists.fHmcphi->Fill(mcstartmom.Phi());
1014 mchists.fHmctheta_xz->Fill(mctheta_xz);
1015 mchists.fHmctheta_yz->Fill(mctheta_yz);
1016 mchists.fHmcmom->Fill(mcmom);
1017 mchists.fHmcmoml->Fill(mcmom);
1018 mchists.fHmcke->Fill(mcke);
1019 mchists.fHmckel->Fill(mcke);
1020 mchists.fHmclen->Fill(plen);
1021 mchists.fHmclens->Fill(plen);
1040 std::vector<art::Ptr<recob::Hit> > allhits;
1042 allhits.reserve(hith->size());
1043 for(
unsigned int i=0; i<hith->size(); ++i) {
1044 allhits.emplace_back(hith, i);
1059 <<
"TrackAna read " << trackvh->size()
1060 <<
" vectors of Stitched PtrVectorsof tracks.";
1067 *pdump <<
"\nReconstructed Tracks\n" 1068 <<
" Id MCid x y z dx dy dz p\n" 1069 <<
"-------------------------------------------------------------------------------------------\n";
1074 int ntrack = trackh->size();
1075 for(
int i = 0; i < ntrack; ++i) {
1081 std::vector<art::Ptr<recob::Hit> > trackhits;
1082 tkhit_find.
get(i, trackhits);
1095 TVector3 pos = track.
Vertex();
1097 TVector3 end = track.
End();
1101 double dpos = bdist(pos);
1102 double dend = bdist(end);
1103 double tlen = length(track);
1104 double theta_xz = std::atan2(dir.X(), dir.Z());
1105 double theta_yz = std::atan2(dir.Y(), dir.Z());
1115 rhists.
fHendx->Fill(end.X());
1116 rhists.
fHendy->Fill(end.Y());
1117 rhists.
fHendz->Fill(end.Z());
1118 rhists.
fHendd->Fill(dend);
1119 rhists.
fHtheta->Fill(dir.Theta());
1120 rhists.
fHphi->Fill(dir.Phi());
1127 rhists.
fHmom->Fill(mom);
1128 rhists.
fHmoml->Fill(mom);
1129 rhists.
fHlen->Fill(tlen);
1130 rhists.
fHlens->Fill(tlen);
1138 for(
int swap=0; swap<2; ++swap) {
1149 int start_point = (swap == 0 ? 0 : ntraj-1);
1155 rot(1, 0) = -rot(1, 0);
1156 rot(2, 0) = -rot(2, 0);
1157 rot(1, 1) = -rot(1, 1);
1158 rot(2, 1) = -rot(2, 1);
1159 rot(1, 2) = -rot(1, 2);
1160 rot(2, 2) = -rot(2, 2);
1170 theta_xz = std::atan2(dir.X(), dir.Z());
1171 theta_yz = std::atan2(dir.Y(), dir.Z());
1182 for(
unsigned int imc = 0; imc < selected_mctracks.size(); ++imc) {
1183 const sim::MCTrack& mctrk = *selected_mctracks[imc].first;
1188 throw cet::exception(
"TrackAna") <<
"no particle with ID=" << pdg <<
"\n";
1189 const MCHists& mchists = iMCHistMap->second;
1193 double mctime = mctrk.
Start().
T();
1201 TVector3 mcstartmom;
1203 double plen = length(mctrk, mcdx, mcstart, mcend, mcstartmom, mcendmom);
1207 TVector3 mcpos = mcstart - pos;
1212 TVector3 mcmoml = rot * mcstartmom;
1213 TVector3 mcposl = rot * mcpos;
1215 double colinearity = mcmoml.Z() / mcmoml.Mag();
1217 double u = mcposl.X();
1218 double v = mcposl.Y();
1219 double w = mcposl.Z();
1221 double pu = mcmoml.X();
1222 double pv = mcmoml.Y();
1223 double pw = mcmoml.Z();
1225 double dudw = pu / pw;
1226 double dvdw = pv / pw;
1228 double u0 = u - w * dudw;
1229 double v0 = v - w * dvdw;
1230 double uv0 = std::sqrt(u0*u0 + v0*v0);
1240 mchists.
fHdudwpull->Fill(dudw / std::sqrt(cov(2,2)));
1241 mchists.
fHdvdwpull->Fill(dvdw / std::sqrt(cov(3,3)));
1243 mchists.
fHcosth->Fill(colinearity);
1248 mchists.
fHmcu->Fill(u0);
1249 mchists.
fHmcv->Fill(v0);
1250 mchists.
fHmcw->Fill(w);
1251 mchists.
fHupull->Fill(u0 / std::sqrt(cov(0,0)));
1252 mchists.
fHvpull->Fill(v0 / std::sqrt(cov(1,1)));
1258 double mctheta_xz = std::atan2(mcstartmom.X(), mcstartmom.Z());
1259 double mctheta_yz = std::atan2(mcstartmom.Y(), mcstartmom.Z());
1260 double mcmom = mcstartmom.Mag();
1262 double mcke = mcmom*mcmom / (std::sqrt(mcmom*mcmom + mcmass*mcmass) + mcmass);
1264 mchists.
fHstartdx->Fill(pos.X() - mcstart.X());
1265 mchists.
fHstartdy->Fill(pos.Y() - mcstart.Y());
1266 mchists.
fHstartdz->Fill(pos.Z() - mcstart.Z());
1267 mchists.
fHenddx->Fill(end.X() - mcend.X());
1268 mchists.
fHenddy->Fill(end.Y() - mcend.Y());
1269 mchists.
fHenddz->Fill(end.Z() - mcend.Z());
1270 mchists.
fHlvsl->Fill(plen, tlen);
1271 mchists.
fHdl->Fill(tlen - plen);
1272 mchists.
fHpvsp->Fill(mcmom, mom);
1273 double dp = mom - mcmom;
1274 mchists.
fHdp->Fill(dp);
1275 mchists.
fHppull->Fill(dp / std::sqrt(cov(4,4)));
1276 if(std::abs(dpos) >= 5. && std::abs(dend) >= 5.) {
1277 mchists.
fHpvspc->Fill(mcmom, mom);
1278 mchists.
fHdpc->Fill(dp);
1279 mchists.
fHppullc->Fill(dp / std::sqrt(cov(4,4)));
1294 std::set<int> tkidset;
1295 tkidset.insert(mcid);
1297 bt_serv->HitCollectionEfficiency(tkidset, trackhits, allhits,
geo::k3D);
1298 double hitpurity = bt_serv->HitCollectionPurity(tkidset, trackhits);
1307 mchists.
fHgendx->Fill(mcend.X());
1308 mchists.
fHgendy->Fill(mcend.Y());
1309 mchists.
fHgendz->Fill(mcend.Z());
1310 mchists.
fHgtheta->Fill(mcstartmom.Theta());
1311 mchists.
fHgphi->Fill(mcstartmom.Phi());
1314 mchists.
fHgmom->Fill(mcmom);
1316 mchists.
fHgke->Fill(mcke);
1317 mchists.
fHgkel->Fill(mcke);
1318 mchists.
fHglen->Fill(plen);
1322 selected_mctracks[imc].second = i;
1326 float KE = ptkl->
E() - ptkl->
Mass();
1327 std::string KEUnits =
" GeV";
1335 <<
" Match MCTkID "<<std::setw(6)<<mctrk.
TrackID()
1336 <<
" Origin "<<mctrk.
Origin()
1337 <<
" PDG"<<std::setw(5)<<mctrk.
PdgCode()
1338 <<
" KE"<<std::setw(4)<<(int)KE<<KEUnits
1339 <<
" RecoTrkID "<<track.
ID()
1340 <<
" hitEff "<<std::setprecision(2)<<hiteff<<
" hitPur "<<hitpurity;
1341 int sWire, sTick, eWire, eTick;
1343 for(
unsigned short ipl = 0; ipl < geom->
Nplanes(); ++ipl) {
1348 mf::LogVerbatim(
"TrackAna")<<
" Wire:Tick in Pln "<<ipl<<
" W:T "<<sWire<<
":"<<sTick<<
" - "<<eWire<<
":"<<eTick;
1360 TVector3 pos = track.
Vertex();
1362 TVector3 end = track.
End();
1368 *pdump <<
"\nOffset" 1369 << std::setw(3) << track.
ID()
1370 << std::setw(6) << mcid
1372 << std::fixed << std::setprecision(2)
1373 << std::setw(10) << trackdx
1375 << std::setw(3) << track.
ID()
1376 << std::setw(6) << mcid
1378 << std::fixed << std::setprecision(2)
1379 << std::setw(10) << pos[0]
1380 << std::setw(10) << pos[1]
1381 << std::setw(10) << pos[2];
1384 << std::fixed << std::setprecision(3)
1385 << std::setw(10) << dir[0]
1386 << std::setw(10) << dir[1]
1387 << std::setw(10) << dir[2];
1390 *pdump << std::setw(32) <<
" ";
1391 *pdump << std::setw(12) << std::fixed << std::setprecision(3) << pstart;
1393 << std::setw(3) << track.
ID()
1394 << std::setw(6) << mcid
1396 << std::fixed << std::setprecision(2)
1397 << std::setw(10) << end[0]
1398 << std::setw(10) << end[1]
1399 << std::setw(10) << end[2];
1402 << std::fixed << std::setprecision(3)
1403 << std::setw(10) << enddir[0]
1404 << std::setw(10) << enddir[1]
1405 << std::setw(10) << enddir[2];
1408 *pdump << std::setw(32)<<
" ";
1409 *pdump << std::setw(12) << std::fixed << std::setprecision(3) << pend
1410 <<
"\nLength: " << tlen <<
"\n";
1418 for(
unsigned int imc = 0; imc < selected_mctracks.size(); ++imc) {
1419 if(selected_mctracks[imc].second >= 0)
continue;
1420 const sim::MCTrack& mctrk = *selected_mctracks[imc].first;
1422 float KE = ptkl->
E() - ptkl->
Mass();
1423 std::string KEUnits =
" GeV";
1430 TVector3 mcstart, mcend, mcstartmom, mcendmom;
1432 double plen = length(mctrk, mcdx, mcstart, mcend, mcstartmom, mcendmom);
1434 <<
" NoMat MCTkID "<<std::setw(6)<<mctrk.
TrackID()
1435 <<
" Origin "<<mctrk.
Origin()
1436 <<
" PDG"<<std::setw(5)<<mctrk.
PdgCode()
1437 <<
" KE"<<std::setw(4)<<(int)KE<<KEUnits
1438 <<
" Length "<<std::fixed<<std::setprecision(1)<<plen<<
" cm";
1440 int sWire, sTick, eWire, eTick;
1442 for(
unsigned short ipl = 0; ipl < geom->
Nplanes(); ++ipl) {
1448 <<
" W:T "<<sWire<<
":"<<sTick<<
" - "<<eWire<<
":"<<eTick;
1464 std::map<int, std::map<int, art::PtrVector<recob::Hit>> > hitmap;
1465 std::map<int, int > KEmap;
1474 int ntv(trackvh->size());
1476 std::vector < art::PtrVector<recob::Track> >
::const_iterator cti = trackvh->begin();
1481 int nsppts_assnwhole = fswhole.size();
1482 std::cout <<
"TrackAna: Number of clumps of Spacepoints from Assn for all Tracks: " << nsppts_assnwhole << std::endl;
1488 std::cout <<
"\n" <<
"\t\t TrkAna: Fresh fRecoHistMap[0] ******* \n" << std::endl;
1492 std::vector < std::vector <unsigned int> > NtrkIdsAll;
1493 std::vector < double > ntvsorted;
1498 for (
int o = 0; o < ntv; ++o)
1503 int ntrack = pvtrack.
size();
1505 std::vector< std::vector <unsigned int> > NtrkId_Hit;
1506 std::vector<unsigned int> vecMode;
1509 for(
int i = 0; i < ntrack; ++i) {
1521 int nsppts_assn = fs.at(i).size();
1525 const auto&
sppt = fs.at(i);
1535 std::vector <unsigned int> vecNtrkIds;
1536 for(
int is = 0; is < nsppts_assn; ++is) {
1537 int nhits = fh.at(is).size();
1538 for(
int ih = 0; ih < nhits; ++ih) {
1539 const auto&
hit = fh.at(is).at(ih);
1551 int trackID = std::abs(itid->trackID);
1552 hitmap[trackID][o].push_back(
hit);
1554 if (justOne) { vecNtrkIds.push_back(trackID); justOne=
false; }
1565 TVector3 mcstartmom;
1567 double mctime = part->
T();
1570 double plen = length(*part, mcdx, mcstart, mcend, mcstartmom, mcendmom);
1572 KEmap[(int)(1e6*plen)] = trackID;
1583 NtrkId_Hit.push_back(vecNtrkIds);
1586 int max(-12),
n(1), ind(0);
1587 std::sort(vecNtrkIds.begin(),vecNtrkIds.end());
1588 std::vector<unsigned int> strkIds(vecNtrkIds);
1589 while ( ii < vecNtrkIds.size() )
1591 if (strkIds.at(ii) != strkIds.at(ii-1))
1599 if (n>
max) {
max =
n; ind = ii;}
1604 if (strkIds.begin()!=strkIds.end())
1605 mode = strkIds.at(ind);
1606 vecMode.push_back(mode);
1609 if (strkIds.size()!=0)
1610 rhistsStitched.
fModeFrac->Fill((
double)
max/(
double)strkIds.size());
1619 if (!assns)
throw cet::exception(
"TrackAna") <<
"Bad Associations. \n";
1626 NtrkIdsAll.push_back(vecMode);
1628 std::unique(NtrkIdsAll.back().begin(),NtrkIdsAll.back().end());
1630 for (
auto const val : NtrkIdsAll.back())
1633 sum += hitmap[val][o].size();
1635 ntvsorted.push_back(sum);
1644 for (
auto it = KEmap.rbegin(); it!=KEmap.rend(); ++it)
1660 for (
auto it = KEmap.rbegin(); it!=KEmap.rend(); ++it)
1662 int val = it->second;
1665 rhistsStitched.
fNTrkIdTrks3->Fill(o,v,hitmap[val][o].size());
1673 flattener flat(NtrkIdsAll);
1674 std::vector <unsigned int> &v = flat;
1676 for (
auto const val : v)
1681 double T(part->
E() - 0.001*part->
Mass());
1682 rhistsStitched.
fNTrkIdTrks->Fill(std::count(v.begin(),v.end(),val));
1683 rhistsStitched.
fNTrkIdTrks2->Fill(std::count(v.begin(),v.end(),val),T);
1701 <<
"TrackAna statistics:\n" 1708 const MCHists& mchists = i->second;
1729 template <
typename T>
1732 std::vector<size_t> idx(v.size());
1733 for (
size_t i = 0; i != idx.size(); ++i) idx[i] = i;
1735 std::sort(idx.begin(), idx.end(),
1736 [&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)
TVector3 LocationAtPoint(unsigned int p) const
Covariance matrices are either set or not.
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
TVector3 VertexDirection() const
Covariance matrices are either set or not.
std::string fTrkSpptAssocModuleLabel
TMatrixD EndCovariance() const
Covariance matrices are either set or not.
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.
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.
#define DEFINE_ART_MODULE(klass)
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.
double T(const int i=0) const
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.
Provides recob::Track data product.
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
std::map< int, RecoHists > fRecoHistMap
TVector3 Vertex() const
Covariance matrices are either set or not.
const TLorentzVector & Momentum(const int i=0) const
TMatrixD VertexCovariance() const
Covariance matrices are either set or not.
TVector3 EndDirection() const
Covariance matrices are either set or not.
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
TVector3 End() const
Covariance matrices are either set or not.
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.