30 #include "art_root_io/TFileService.h" 31 #include "canvas/Persistency/Common/FindManyP.h" 32 #include "cetlib_except/exception.h" 56 bdist(
const TVector3&
pos,
unsigned int = 0,
unsigned int = 0)
69 return std::min({d1, d2, d3, d4, d5, d6});
106 for (
int i = 0; i <
n; ++i) {
107 TVector3 pos = part.
Position(i).Vect();
113 if (pos.X() >= xmin && pos.X() <= xmax && pos.Y() >= ymin && pos.Y() <= ymax &&
114 pos.Z() >= zmin && pos.Z() <= zmax) {
124 result += disp.Mag();
163 int n = mctrk.size();
166 for (
int i = 0; i <
n; ++i) {
167 TVector3 pos = mctrk[i].Position().Vect();
173 if (pos.X() >= xmin && pos.X() <= xmax && pos.Y() >= ymin && pos.Y() <= ymax &&
174 pos.Z() >= zmin && pos.Z() <= zmax) {
180 startmom = 0.001 * mctrk[i].Momentum().Vect();
184 result += disp.Mag();
189 endmom = 0.001 * mctrk[i].Momentum().Vect();
200 effcalc(
const TH1* hnum,
const TH1* hden, TH1* heff)
202 int nbins = hnum->GetNbinsX();
203 if (nbins != hden->GetNbinsX())
204 throw cet::exception(
"TrackAna") <<
"effcalc[" __FILE__
"]: incompatible histograms (I)\n";
205 if (nbins != heff->GetNbinsX())
206 throw cet::exception(
"TrackAna") <<
"effcalc[" __FILE__
"]: incompatible histograms (II)\n";
210 for (
int ibin = 0; ibin <= nbins + 1; ++ibin) {
211 double num = hnum->GetBinContent(ibin);
212 double den = hden->GetBinContent(ibin);
214 heff->SetBinContent(ibin, 0.);
215 heff->SetBinError(ibin, 0.);
218 double eff = num / den;
219 if (eff < 0.) eff = 0.;
220 if (eff > 1.) eff = 1.;
221 double err = std::sqrt(eff * (1. - eff) / den);
222 heff->SetBinContent(ibin, eff);
223 heff->SetBinError(ibin, err);
227 heff->SetMinimum(0.);
228 heff->SetMaximum(1.05);
229 heff->SetMarkerStyle(20);
232 class flattener :
public std::vector<unsigned int> {
246 for (
auto const& vec :
input)
247 length += vec.size();
250 for (
auto const& vec : input)
251 for (
auto const&
value : vec)
271 TH1F* fHstartx{
nullptr};
272 TH1F* fHstarty{
nullptr};
273 TH1F* fHstartz{
nullptr};
274 TH1F* fHstartd{
nullptr};
275 TH1F* fHendx{
nullptr};
276 TH1F* fHendy{
nullptr};
277 TH1F* fHendz{
nullptr};
278 TH1F* fHendd{
nullptr};
279 TH1F* fHtheta{
nullptr};
280 TH1F* fHphi{
nullptr};
281 TH1F* fHtheta_xz{
nullptr};
282 TH1F* fHtheta_yz{
nullptr};
283 TH1F* fHmom{
nullptr};
284 TH1F* fHmoml{
nullptr};
285 TH1F* fHlen{
nullptr};
286 TH1F* fHlens{
nullptr};
290 TH1F* fHHitChg{
nullptr};
291 TH1F* fHHitWidth{
nullptr};
292 TH1F* fHHitPdg{
nullptr};
293 TH1F* fHHitTrkId{
nullptr};
294 TH1F* fModeFrac{
nullptr};
295 TH1F* fNTrkIdTrks{
nullptr};
296 TH2F* fNTrkIdTrks2{
nullptr};
297 TH2F* fNTrkIdTrks3{
nullptr};
307 TH2F* fHduvcosth{
nullptr};
308 TH1F* fHcosth{
nullptr};
309 TH1F* fHmcu{
nullptr};
310 TH1F* fHmcv{
nullptr};
311 TH1F* fHmcw{
nullptr};
312 TH1F* fHupull{
nullptr};
313 TH1F* fHvpull{
nullptr};
314 TH1F* fHmcdudw{
nullptr};
315 TH1F* fHmcdvdw{
nullptr};
316 TH1F* fHdudwpull{
nullptr};
317 TH1F* fHdvdwpull{
nullptr};
318 TH1F* fHHitEff{
nullptr};
319 TH1F* fHHitPurity{
nullptr};
323 TH1F* fHstartdx{
nullptr};
324 TH1F* fHstartdy{
nullptr};
325 TH1F* fHstartdz{
nullptr};
326 TH1F* fHenddx{
nullptr};
327 TH1F* fHenddy{
nullptr};
328 TH1F* fHenddz{
nullptr};
329 TH2F* fHlvsl{
nullptr};
331 TH2F* fHpvsp{
nullptr};
332 TH2F* fHpvspc{
nullptr};
334 TH1F* fHdpc{
nullptr};
335 TH1F* fHppull{
nullptr};
336 TH1F* fHppullc{
nullptr};
340 TH1F* fHmcstartx{
nullptr};
341 TH1F* fHmcstarty{
nullptr};
342 TH1F* fHmcstartz{
nullptr};
343 TH1F* fHmcendx{
nullptr};
344 TH1F* fHmcendy{
nullptr};
345 TH1F* fHmcendz{
nullptr};
346 TH1F* fHmctheta{
nullptr};
347 TH1F* fHmcphi{
nullptr};
348 TH1F* fHmctheta_xz{
nullptr};
349 TH1F* fHmctheta_yz{
nullptr};
350 TH1F* fHmcmom{
nullptr};
351 TH1F* fHmcmoml{
nullptr};
352 TH1F* fHmcke{
nullptr};
353 TH1F* fHmckel{
nullptr};
354 TH1F* fHmclen{
nullptr};
355 TH1F* fHmclens{
nullptr};
359 TH1F* fHgstartx{
nullptr};
360 TH1F* fHgstarty{
nullptr};
361 TH1F* fHgstartz{
nullptr};
362 TH1F* fHgendx{
nullptr};
363 TH1F* fHgendy{
nullptr};
364 TH1F* fHgendz{
nullptr};
365 TH1F* fHgtheta{
nullptr};
366 TH1F* fHgphi{
nullptr};
367 TH1F* fHgtheta_xz{
nullptr};
368 TH1F* fHgtheta_yz{
nullptr};
369 TH1F* fHgmom{
nullptr};
370 TH1F* fHgmoml{
nullptr};
371 TH1F* fHgke{
nullptr};
372 TH1F* fHgkel{
nullptr};
373 TH1F* fHglen{
nullptr};
374 TH1F* fHglens{
nullptr};
378 TH1F* fHestartx{
nullptr};
379 TH1F* fHestarty{
nullptr};
380 TH1F* fHestartz{
nullptr};
381 TH1F* fHeendx{
nullptr};
382 TH1F* fHeendy{
nullptr};
383 TH1F* fHeendz{
nullptr};
384 TH1F* fHetheta{
nullptr};
385 TH1F* fHephi{
nullptr};
386 TH1F* fHetheta_xz{
nullptr};
387 TH1F* fHetheta_yz{
nullptr};
388 TH1F* fHemom{
nullptr};
389 TH1F* fHemoml{
nullptr};
390 TH1F* fHeke{
nullptr};
391 TH1F* fHekel{
nullptr};
392 TH1F* fHelen{
nullptr};
393 TH1F* fHelens{
nullptr};
402 void endJob()
override;
408 std::vector<size_t> fsort_indexes(
const std::vector<double>& v);
458 art::TFileDirectory topdir = tfs->mkdir(
"trkana",
"TrackAna histograms");
459 art::TFileDirectory
dir = topdir.mkdir(subdir);
463 fHstartx = dir.make<TH1F>(
465 fHstarty = dir.make<TH1F>(
467 fHstartz = dir.make<TH1F>(
"zstart",
"Z Start Position", 100, 0., geom->
DetLength());
468 fHstartd = dir.make<TH1F>(
469 "dstart",
"Start Position Distance to Boundary", 100, -10., geom->
DetHalfWidth());
470 fHendx = dir.make<TH1F>(
474 fHendz = dir.make<TH1F>(
"zend",
"Z End Position", 100, 0., geom->
DetLength());
476 dir.make<TH1F>(
"dend",
"End Position Distance to Boundary", 100, -10., geom->
DetHalfWidth());
477 fHtheta = dir.make<TH1F>(
"theta",
"Theta", 100, 0., 3.142);
478 fHphi = dir.make<TH1F>(
"phi",
"Phi", 100, -3.142, 3.142);
479 fHtheta_xz = dir.make<TH1F>(
"theta_xz",
"Theta_xz", 100, -3.142, 3.142);
480 fHtheta_yz = dir.make<TH1F>(
"theta_yz",
"Theta_yz", 100, -3.142, 3.142);
481 fHmom = dir.make<TH1F>(
"mom",
"Momentum", 100, 0., 10.);
482 fHmoml = dir.make<TH1F>(
"moml",
"Momentum", 100, 0., 1.);
483 fHlen = dir.make<TH1F>(
"len",
"Track Length", 100, 0., 1.1 * geom->
DetLength());
484 fHlens = dir.make<TH1F>(
"lens",
"Track Length", 100, 0., 0.1 * geom->
DetLength());
485 fHHitChg = dir.make<TH1F>(
"hchg",
"Hit Charge (ADC counts)", 100, 0., 4000.);
486 fHHitWidth = dir.make<TH1F>(
"hwid",
"Hit Width (ticks)", 40, 0., 20.);
487 fHHitPdg = dir.make<TH1F>(
"hpdg",
"Hit Pdg code", 5001, -2500.5, +2500.5);
488 fHHitTrkId = dir.make<TH1F>(
"htrkid",
"Hit Track ID", 401, -200.5, +200.5);
490 dir.make<TH1F>(
"hmodefrac",
491 "quasi-Purity: Fraction of component tracks with the Track mode value",
496 dir.make<TH1F>(
"hntrkids",
497 "quasi-Efficiency: Number of stitched tracks in which TrkId appears",
501 fNTrkIdTrks2 = dir.make<TH2F>(
"hntrkids2",
502 "Number of stitched tracks in which TrkId appears vs KE [GeV]",
509 fNTrkIdTrks3 = dir.make<TH2F>(
"hntrkids3",
510 "MC Track vs Reco Track, wtd by nhits on Collection Plane",
517 fNTrkIdTrks3->GetXaxis()->SetTitle(
"Sorted-by-Descending-CPlane-Hits outer Track Number");
518 fNTrkIdTrks3->GetYaxis()->SetTitle(
"Sorted-by-Descending-True-Length G4Track");
532 art::TFileDirectory topdir = tfs->mkdir(
"trkana",
"TrackAna histograms");
533 art::TFileDirectory
dir = topdir.mkdir(subdir);
538 dir.make<TH2F>(
"duvcosth",
"Delta(uv) vs. Colinearity", 100, 0.95, 1., 100, 0., 1.);
539 fHcosth = dir.make<TH1F>(
"colin",
"Colinearity", 100, 0.95, 1.);
540 fHmcu = dir.make<TH1F>(
"mcu",
"MC Truth U", 100, -5., 5.);
541 fHmcv = dir.make<TH1F>(
"mcv",
"MC Truth V", 100, -5., 5.);
542 fHmcw = dir.make<TH1F>(
"mcw",
"MC Truth W", 100, -20., 20.);
543 fHupull = dir.make<TH1F>(
"dupull",
"U Pull", 100, -20., 20.);
544 fHvpull = dir.make<TH1F>(
"dvpull",
"V Pull", 100, -20., 20.);
545 fHmcdudw = dir.make<TH1F>(
"mcdudw",
"MC Truth U Slope", 100, -0.2, 0.2);
546 fHmcdvdw = dir.make<TH1F>(
"mcdvdw",
"MV Truth V Slope", 100, -0.2, 0.2);
547 fHdudwpull = dir.make<TH1F>(
"dudwpull",
"U Slope Pull", 100, -10., 10.);
548 fHdvdwpull = dir.make<TH1F>(
"dvdwpull",
"V Slope Pull", 100, -10., 10.);
549 fHHitEff = dir.make<TH1F>(
"hiteff",
"MC Hit Efficiency", 100, 0., 1.0001);
550 fHHitPurity = dir.make<TH1F>(
"hitpurity",
"MC Hit Purity", 100, 0., 1.0001);
551 fHstartdx = dir.make<TH1F>(
"startdx",
"Start Delta x", 100, -10., 10.);
552 fHstartdy = dir.make<TH1F>(
"startdy",
"Start Delta y", 100, -10., 10.);
553 fHstartdz = dir.make<TH1F>(
"startdz",
"Start Delta z", 100, -10., 10.);
554 fHenddx = dir.make<TH1F>(
"enddx",
"End Delta x", 100, -10., 10.);
555 fHenddy = dir.make<TH1F>(
"enddy",
"End Delta y", 100, -10., 10.);
556 fHenddz = dir.make<TH1F>(
"enddz",
"End Delta z", 100, -10., 10.);
557 fHlvsl = dir.make<TH2F>(
"lvsl",
558 "Reco Length vs. MC Truth Length",
565 fHdl = dir.make<TH1F>(
"dl",
"Track Length Minus MC Particle Length", 100, -50., 50.);
567 dir.make<TH2F>(
"pvsp",
"Reco Momentum vs. MC Truth Momentum", 100, 0., 5., 100, 0., 5.);
568 fHpvspc = dir.make<TH2F>(
569 "pvspc",
"Reco Momentum vs. MC Truth Momentum (Contained Tracks)", 100, 0., 5., 100, 0., 5.);
570 fHdp = dir.make<TH1F>(
"dp",
"Reco-MC Momentum Difference", 100, -5., 5.);
571 fHdpc = dir.make<TH1F>(
"dpc",
"Reco-MC Momentum Difference (Contained Tracks)", 100, -5., 5.);
572 fHppull = dir.make<TH1F>(
"ppull",
"Momentum Pull", 100, -10., 10.);
573 fHppullc = dir.make<TH1F>(
"ppullc",
"Momentum Pull (Contained Tracks)", 100, -10., 10.);
575 fHmcstartx = dir.make<TH1F>(
577 fHmcstarty = dir.make<TH1F>(
579 fHmcstartz = dir.make<TH1F>(
"mczstart",
"MC Z Start Position", 10, 0., geom->
DetLength());
580 fHmcendx = dir.make<TH1F>(
582 fHmcendy = dir.make<TH1F>(
584 fHmcendz = dir.make<TH1F>(
"mczend",
"MC Z End Position", 10, 0., geom->
DetLength());
585 fHmctheta = dir.make<TH1F>(
"mctheta",
"MC Theta", 20, 0., 3.142);
586 fHmcphi = dir.make<TH1F>(
"mcphi",
"MC Phi", 10, -3.142, 3.142);
587 fHmctheta_xz = dir.make<TH1F>(
"mctheta_xz",
"MC Theta_xz", 40, -3.142, 3.142);
588 fHmctheta_yz = dir.make<TH1F>(
"mctheta_yz",
"MC Theta_yz", 40, -3.142, 3.142);
589 fHmcmom = dir.make<TH1F>(
"mcmom",
"MC Momentum", 10, 0., 10.);
590 fHmcmoml = dir.make<TH1F>(
"mcmoml",
"MC Momentum", 10, 0., 1.);
591 fHmcke = dir.make<TH1F>(
"mcke",
"MC Kinetic Energy", 10, 0., 10.);
592 fHmckel = dir.make<TH1F>(
"mckel",
"MC Kinetic Energy", 10, 0., 1.);
593 fHmclen = dir.make<TH1F>(
"mclen",
"MC Particle Length", 10, 0., 1.1 * geom->
DetLength());
594 fHmclens = dir.make<TH1F>(
"mclens",
"MC Particle Length", 10, 0., 0.1 * geom->
DetLength());
596 fHgstartx = dir.make<TH1F>(
"gxstart",
597 "Good X Start Position",
601 fHgstarty = dir.make<TH1F>(
603 fHgstartz = dir.make<TH1F>(
"gzstart",
"Good Z Start Position", 10, 0., geom->
DetLength());
604 fHgendx = dir.make<TH1F>(
606 fHgendy = dir.make<TH1F>(
608 fHgendz = dir.make<TH1F>(
"gzend",
"Good Z End Position", 10, 0., geom->
DetLength());
609 fHgtheta = dir.make<TH1F>(
"gtheta",
"Good Theta", 20, 0., 3.142);
610 fHgphi = dir.make<TH1F>(
"gphi",
"Good Phi", 10, -3.142, 3.142);
611 fHgtheta_xz = dir.make<TH1F>(
"gtheta_xz",
"Good Theta_xz", 40, -3.142, 3.142);
612 fHgtheta_yz = dir.make<TH1F>(
"gtheta_yz",
"Good Theta_yz", 40, -3.142, 3.142);
613 fHgmom = dir.make<TH1F>(
"gmom",
"Good Momentum", 10, 0., 10.);
614 fHgmoml = dir.make<TH1F>(
"gmoml",
"Good Momentum", 10, 0., 1.);
615 fHgke = dir.make<TH1F>(
"gke",
"Good Kinetic Energy", 10, 0., 10.);
616 fHgkel = dir.make<TH1F>(
"gkel",
"Good Kinetic Energy", 10, 0., 1.);
617 fHglen = dir.make<TH1F>(
"glen",
"Good Particle Length", 10, 0., 1.1 * geom->
DetLength());
618 fHglens = dir.make<TH1F>(
"glens",
"Good Particle Length", 10, 0., 0.1 * geom->
DetLength());
620 fHestartx = dir.make<TH1F>(
"exstart",
621 "Efficiency vs. X Start Position",
625 fHestarty = dir.make<TH1F>(
"eystart",
626 "Efficiency vs. Y Start Position",
631 dir.make<TH1F>(
"ezstart",
"Efficiency vs. Z Start Position", 10, 0., geom->
DetLength());
632 fHeendx = dir.make<TH1F>(
"exend",
633 "Efficiency vs. X End Position",
637 fHeendy = dir.make<TH1F>(
639 fHeendz = dir.make<TH1F>(
"ezend",
"Efficiency vs. Z End Position", 10, 0., geom->
DetLength());
640 fHetheta = dir.make<TH1F>(
"etheta",
"Efficiency vs. Theta", 20, 0., 3.142);
641 fHephi = dir.make<TH1F>(
"ephi",
"Efficiency vs. Phi", 10, -3.142, 3.142);
642 fHetheta_xz = dir.make<TH1F>(
"etheta_xz",
"Efficiency vs. Theta_xz", 40, -3.142, 3.142);
643 fHetheta_yz = dir.make<TH1F>(
"etheta_yz",
"Efficiency vs. Theta_yz", 40, -3.142, 3.142);
644 fHemom = dir.make<TH1F>(
"emom",
"Efficiency vs. Momentum", 10, 0., 10.);
645 fHemoml = dir.make<TH1F>(
"emoml",
"Efficiency vs. Momentum", 10, 0., 1.);
646 fHeke = dir.make<TH1F>(
"eke",
"Efficiency vs. Kinetic Energy", 10, 0., 10.);
647 fHekel = dir.make<TH1F>(
"ekel",
"Efficiency vs. Kinetic Energy", 10, 0., 1.);
649 dir.make<TH1F>(
"elen",
"Efficiency vs. Particle Length", 10, 0., 1.1 * geom->
DetLength());
651 dir.make<TH1F>(
"elens",
"Efficiency vs. Particle Length", 10, 0., 0.1 * geom->
DetLength());
661 , fTrackModuleLabel(pset.
get<
std::
string>(
"TrackModuleLabel"))
662 , fMCTrackModuleLabel(pset.
get<
std::
string>(
"MCTrackModuleLabel"))
663 , fSpacepointModuleLabel(pset.
get<
std::
string>(
"SpacepointModuleLabel"))
664 , fStitchModuleLabel(pset.
get<
std::
string>(
"StitchModuleLabel"))
665 , fTrkSpptAssocModuleLabel(pset.
get<
std::
string>(
"TrkSpptAssocModuleLabel"))
666 , fHitSpptAssocModuleLabel(pset.
get<
std::
string>(
"HitSpptAssocModuleLabel"))
667 , fHitModuleLabel(pset.
get<
std::
string>(
"HitModuleLabel"))
668 , fDump(pset.
get<
int>(
"Dump"))
669 , fMinMCKE(pset.
get<double>(
"MinMCKE"))
670 , fMinMCLen(pset.
get<double>(
"MinMCLen"))
671 , fMatchColinearity(pset.
get<double>(
"MatchColinearity"))
672 , fMatchDisp(pset.
get<double>(
"MatchDisp"))
673 , fWMatchDisp(pset.
get<double>(
"WMatchDisp"))
674 , fMatchLength(pset.
get<double>(
"MatchLength"))
675 , fIgnoreSign(pset.
get<
bool>(
"IgnoreSign"))
676 , fStitchedAnalysis(pset.
get<
bool>(
"StitchedAnalysis", false))
677 , fOrigin(pset.
get<
std::
string>(
"MCTrackOrigin",
"Any"))
678 , fPrintLevel(pset.
get<
int>(
"PrintLevel", 0))
685 if (
fOrigin.find(
"Beam") != std::string::npos) {
689 else if (
fOrigin.find(
"Cosmic") != std::string::npos) {
693 else if (
fOrigin.find(
"Super") != std::string::npos) {
697 else if (
fOrigin.find(
"Single") != std::string::npos) {
704 mf::LogInfo(
"TrackAna") <<
"TrackAna configured with the following parameters:\n" 711 <<
" Dump = " <<
fDump <<
"\n" 712 <<
" MinMCKE = " <<
fMinMCKE <<
"\n" 728 std::unique_ptr<mf::LogInfo> pdump;
731 pdump = std::make_unique<mf::LogInfo>(
"TrackAna");
743 std::vector<std::pair<const sim::MCTrack*, int>> selected_mctracks;
749 if (mc && mctrackh.
isValid()) {
751 selected_mctracks.reserve(mctrackh->size());
756 *pdump <<
"MC Tracks\n" 757 <<
" Id pdg x y z dx dy dz " 759 <<
"--------------------------------------------------------------------------------" 768 imctrk != mctrackh->end();
791 double mctime = mctrk.
Start().
T();
801 length(clockData, detProp, mctrk, mcdx, mcstart, mcend, mcstartmom, mcendmom);
810 selected_mctracks.push_back(std::make_pair(&mctrk, -1));
815 double pstart = mcstartmom.Mag();
816 double pend = mcendmom.Mag();
822 << mcstart[1] <<
std::setw(10) << mcstart[2];
825 << mcstartmom[0] / pstart <<
std::setw(10) << mcstartmom[1] / pstart
826 <<
std::setw(10) << mcstartmom[2] / pstart;
837 << mcendmom[0] / pend <<
std::setw(10) << mcendmom[1] / pend
843 <<
"\nLength: " << plen <<
"\n";
849 std::ostringstream ostr;
855 double mctheta_xz = std::atan2(mcstartmom.X(), mcstartmom.Z());
856 double mctheta_yz = std::atan2(mcstartmom.Y(), mcstartmom.Z());
857 double mcmom = mcstartmom.Mag();
859 double mcke = mcmom * mcmom / (
std::hypot(mcmom, mcmass) + mcmass);
867 mchists.
fHmctheta->Fill(mcstartmom.Theta());
868 mchists.
fHmcphi->Fill(mcstartmom.Phi());
873 mchists.
fHmcke->Fill(mcke);
894 std::vector<art::Ptr<recob::Hit>> allhits;
896 allhits.reserve(hith->size());
897 for (
unsigned int i = 0; i < hith->size(); ++i) {
898 allhits.emplace_back(hith, i);
911 mf::LogDebug(
"TrackAna") <<
"TrackAna read " << trackvh->size()
912 <<
" vectors of Stitched PtrVectorsof tracks.";
919 *pdump <<
"\nReconstructed Tracks\n" 920 <<
" Id MCid x y z dx dy dz " 922 <<
"--------------------------------------------------------------------------------" 928 int ntrack = trackh->size();
929 for (
int i = 0; i < ntrack; ++i) {
935 std::vector<art::Ptr<recob::Hit>> trackhits;
936 tkhit_find.
get(i, trackhits);
946 TVector3 pos = track.
Vertex<TVector3>();
948 TVector3 end = track.
End<TVector3>();
952 double dpos = bdist(pos);
953 double dend = bdist(end);
954 double tlen = length(track);
955 double theta_xz = std::atan2(dir.X(), dir.Z());
956 double theta_yz = std::atan2(dir.Y(), dir.Z());
965 rhists.
fHendx->Fill(end.X());
966 rhists.
fHendy->Fill(end.Y());
967 rhists.
fHendz->Fill(end.Z());
968 rhists.
fHendd->Fill(dend);
969 rhists.
fHtheta->Fill(dir.Theta());
970 rhists.
fHphi->Fill(dir.Phi());
976 rhists.
fHmom->Fill(mom);
978 rhists.
fHlen->Fill(tlen);
979 rhists.
fHlens->Fill(tlen);
997 int start_point = (
swap == 0 ? 0 : ntraj - 1);
1003 rot(1, 0) = -rot(1, 0);
1004 rot(2, 0) = -rot(2, 0);
1005 rot(1, 1) = -rot(1, 1);
1006 rot(2, 1) = -rot(2, 1);
1007 rot(1, 2) = -rot(1, 2);
1008 rot(2, 2) = -rot(2, 2);
1010 pos = track.
End<TVector3>();
1012 end = track.
Vertex<TVector3>();
1018 theta_xz = std::atan2(dir.X(), dir.Z());
1019 theta_yz = std::atan2(dir.Y(), dir.Z());
1030 for (
unsigned int imc = 0; imc < selected_mctracks.size(); ++imc) {
1031 const sim::MCTrack& mctrk = *selected_mctracks[imc].first;
1036 throw cet::exception(
"TrackAna") <<
"no particle with ID=" << pdg <<
"\n";
1037 const MCHists& mchists = iMCHistMap->second;
1041 double mctime = mctrk.
Start().
T();
1049 TVector3 mcstartmom;
1052 length(clockData, detProp, mctrk, mcdx, mcstart, mcend, mcstartmom, mcendmom);
1056 TVector3 mcpos = mcstart -
pos;
1061 TVector3 mcmoml = rot * mcstartmom;
1062 TVector3 mcposl = rot * mcpos;
1064 double colinearity = mcmoml.Z() / mcmoml.Mag();
1066 double u = mcposl.X();
1067 double v = mcposl.Y();
1068 double w = mcposl.Z();
1070 double pu = mcmoml.X();
1071 double pv = mcmoml.Y();
1072 double pw = mcmoml.Z();
1074 double dudw = pu / pw;
1075 double dvdw = pv / pw;
1077 double u0 = u - w * dudw;
1078 double v0 = v - w * dvdw;
1089 mchists.
fHdudwpull->Fill(dudw / std::sqrt(cov(2, 2)));
1090 mchists.
fHdvdwpull->Fill(dvdw / std::sqrt(cov(3, 3)));
1092 mchists.
fHcosth->Fill(colinearity);
1097 mchists.
fHmcu->Fill(u0);
1098 mchists.
fHmcv->Fill(v0);
1099 mchists.
fHmcw->Fill(w);
1100 mchists.
fHupull->Fill(u0 / std::sqrt(cov(0, 0)));
1101 mchists.
fHvpull->Fill(v0 / std::sqrt(cov(1, 1)));
1107 double mctheta_xz = std::atan2(mcstartmom.X(), mcstartmom.Z());
1108 double mctheta_yz = std::atan2(mcstartmom.Y(), mcstartmom.Z());
1109 double mcmom = mcstartmom.Mag();
1111 double mcke = mcmom * mcmom / (
std::hypot(mcmom, mcmass) + mcmass);
1113 mchists.
fHstartdx->Fill(pos.X() - mcstart.X());
1114 mchists.
fHstartdy->Fill(pos.Y() - mcstart.Y());
1115 mchists.
fHstartdz->Fill(pos.Z() - mcstart.Z());
1116 mchists.
fHenddx->Fill(end.X() - mcend.X());
1117 mchists.
fHenddy->Fill(end.Y() - mcend.Y());
1118 mchists.
fHenddz->Fill(end.Z() - mcend.Z());
1119 mchists.
fHlvsl->Fill(plen, tlen);
1120 mchists.
fHdl->Fill(tlen - plen);
1121 mchists.
fHpvsp->Fill(mcmom, mom);
1122 double dp = mom - mcmom;
1123 mchists.
fHdp->Fill(dp);
1124 mchists.
fHppull->Fill(dp / std::sqrt(cov(4, 4)));
1126 mchists.
fHpvspc->Fill(mcmom, mom);
1127 mchists.
fHdpc->Fill(dp);
1128 mchists.
fHppullc->Fill(dp / std::sqrt(cov(4, 4)));
1142 std::set<int> tkidset;
1143 tkidset.insert(mcid);
1145 clockData, tkidset, trackhits, allhits,
geo::k3D);
1155 mchists.
fHgendx->Fill(mcend.X());
1156 mchists.
fHgendy->Fill(mcend.Y());
1157 mchists.
fHgendz->Fill(mcend.Z());
1158 mchists.
fHgtheta->Fill(mcstartmom.Theta());
1159 mchists.
fHgphi->Fill(mcstartmom.Phi());
1162 mchists.
fHgmom->Fill(mcmom);
1164 mchists.
fHgke->Fill(mcke);
1165 mchists.
fHgkel->Fill(mcke);
1166 mchists.
fHglen->Fill(plen);
1170 selected_mctracks[imc].second = i;
1174 float KE = ptkl->
E() - ptkl->
Mass();
1186 << hiteff <<
" hitPur " << hitpurity;
1187 int sWire, sTick, eWire, eTick;
1189 for (
unsigned short ipl = 0; ipl < geom->
Nplanes(); ++ipl) {
1195 <<
" Wire:Tick in Pln " << ipl <<
" W:T " << sWire <<
":" << sTick
1196 <<
" - " << eWire <<
":" << eTick;
1208 TVector3 pos = track.
Vertex<TVector3>();
1210 TVector3 end = track.
End<TVector3>();
1238 <<
"\nLength: " << tlen <<
"\n";
1246 for (
unsigned int imc = 0; imc < selected_mctracks.size(); ++imc) {
1247 if (selected_mctracks[imc].
second >= 0)
continue;
1248 const sim::MCTrack& mctrk = *selected_mctracks[imc].first;
1250 float KE = ptkl->
E() - ptkl->
Mass();
1258 TVector3 mcstart, mcend, mcstartmom, mcendmom;
1260 double plen = length(clockData, detProp, mctrk, mcdx, mcstart, mcend, mcstartmom, mcendmom);
1267 int sWire, sTick, eWire, eTick;
1269 for (
unsigned short ipl = 0; ipl < geom->
Nplanes(); ++ipl) {
1274 mf::LogVerbatim(
"TrackAna") <<
" Wire:Tick in Pln " << ipl <<
" W:T " << sWire <<
":" 1275 << sTick <<
" - " << eWire <<
":" << eTick;
1291 std::map<int, std::map<int, art::PtrVector<recob::Hit>>> hitmap;
1292 std::map<int, int> KEmap;
1301 int ntv(trackvh->size());
1303 std::vector<art::PtrVector<recob::Track>>
::const_iterator cti = trackvh->begin();
1307 int nsppts_assnwhole = fswhole.size();
1308 std::cout <<
"TrackAna: Number of clumps of Spacepoints from Assn for all Tracks: " 1315 <<
"\t\t TrkAna: Fresh fRecoHistMap[0] ******* \n" 1320 std::vector<std::vector<unsigned int>> NtrkIdsAll;
1321 std::vector<double> ntvsorted;
1326 for (
int o = 0; o < ntv; ++o)
1329 int ntrack = pvtrack.
size();
1330 std::vector<std::vector<unsigned int>> NtrkId_Hit;
1331 std::vector<unsigned int> vecMode;
1334 for (
int i = 0; i < ntrack; ++i) {
1343 int nsppts_assn = fs.at(i).size();
1345 const auto&
sppt = fs.at(i);
1355 std::vector<unsigned int> vecNtrkIds;
1356 for (
int is = 0; is < nsppts_assn; ++is) {
1357 int nhits = fh.at(is).size();
1358 for (
int ih = 0;
ih < nhits; ++
ih) {
1359 const auto&
hit = fh.at(is).at(
ih);
1371 int trackID =
std::abs(itid->trackID);
1372 hitmap[trackID][o].push_back(
hit);
1375 vecNtrkIds.push_back(trackID);
1388 TVector3 mcstartmom;
1390 double mctime = part->
T();
1394 length(clockData, detProp, *part, mcdx, mcstart, mcend, mcstartmom, mcendmom);
1396 KEmap[(
int)(1e6 * plen)] = trackID;
1406 NtrkId_Hit.push_back(vecNtrkIds);
1409 int max(-12),
n(1), ind(0);
1410 std::sort(vecNtrkIds.begin(), vecNtrkIds.end());
1411 std::vector<unsigned int> strkIds(vecNtrkIds);
1412 while (ii < vecNtrkIds.size()) {
1413 if (strkIds.at(ii) != strkIds.at(ii - 1)) { n = 1; }
1424 if (strkIds.begin() != strkIds.end()) mode = strkIds.at(ind);
1425 vecMode.push_back(mode);
1427 if (strkIds.size() != 0)
1428 rhistsStitched.
fModeFrac->Fill((
double)
max / (
double)strkIds.size());
1437 if (!assns)
throw cet::exception(
"TrackAna") <<
"Bad Associations. \n";
1443 NtrkIdsAll.push_back(vecMode);
1445 std::unique(NtrkIdsAll.back().begin(), NtrkIdsAll.back().end());
1447 for (
auto const val : NtrkIdsAll.back()) {
1448 sum += hitmap[
val][o].size();
1450 ntvsorted.push_back(sum);
1458 for (
auto it = KEmap.rbegin(); it != KEmap.rend(); ++it) {
1466 for (
auto it = KEmap.rbegin(); it != KEmap.rend(); ++it) {
1467 int val = it->second;
1475 flattener
flat(NtrkIdsAll);
1476 std::vector<unsigned int>& v =
flat;
1479 for (
auto const val : v) {
1482 double T(part->
E() - 0.001 * part->
Mass());
1497 mf::LogInfo(
"TrackAna") <<
"TrackAna statistics:\n" 1504 const MCHists& mchists = i->second;
1529 std::vector<size_t> idx(v.size());
1530 for (
size_t i = 0; i != idx.size(); ++i)
1533 std::sort(idx.begin(), idx.end(), [&v](
size_t i1,
size_t i2) {
1534 return v[i1] > v[i2];
def analyze(root, level, gtrees, gbranches, doprint)
double E(const int i=0) const
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
unsigned int NumberTrajectoryPoints() const
const TLorentzVector & Position(const int i=0) const
simb::Origin_t Origin() const
double EndMomentum() const
EventNumber_t event() const
double VertexMomentum() const
geo::Length_t DetHalfWidth(geo::TPCID const &tpcid) const
Returns the half width of the active volume of the specified TPC.
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
std::string fHitSpptAssocModuleLabel
std::string fTrkSpptAssocModuleLabel
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
const simb::MCParticle * TrackIdToParticle_P(int id) const
std::string fSpacepointModuleLabel
double HitCollectionEfficiency(detinfo::DetectorClocksData const &clockData, std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit >> const &hits, std::vector< art::Ptr< recob::Hit >> const &allhits, geo::View_t const &view) const
enum simb::_ev_origin Origin_t
event origin types
static constexpr double fs
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
Vector_t VertexDirection() const
const SMatrixSym55 & VertexCovariance() const
unsigned int ReadOutWindowSize() const
std::string fStitchModuleLabel
tick ticks
Alias for common language habits.
Q_EXPORT QTSManip setprecision(int p)
std::map< int, MCHists > fMCHistMap
art framework interface to geometry description
std::enable_if_t< std::is_arithmetic_v< T >, T > hypot(T x, T y)
3-dimensional objects, potentially hits, clusters, prongs, etc.
Rotation_t GlobalToLocalRotationAtPoint(size_t p) const
bool isValid() const noexcept
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
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.
fInnerVessel push_back(Point(-578.400000, 0.000000, 0.000000))
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)
void swap(Handle< T > &a, Handle< T > &b)
std::vector< size_t > fsort_indexes(const std::vector< double > &v)
static const int NoParticleId
double HitCollectionPurity(detinfo::DetectorClocksData const &clockData, std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit >> const &hits) const
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.
void anaStitch(const art::Event &evt, detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp)
Point_t const & Vertex() const
double T(const int i=0) const
double ConvertXToTicks(double X, int p, int t, int c) const
const SMatrixSym55 & EndCovariance() const
geo::Length_t DetLength(geo::TPCID const &tpcid) const
Returns the length of the active volume of the specified TPC.
std::string fMCTrackModuleLabel
static int max(int a, int b)
double DriftVelocity(double efield=0., double temperature=0.) const
cm/us
Class def header for mctrack data container.
void err(const char *fmt,...)
void analyze(const art::Event &evt) override
Detector simulation of raw signals on wires.
const TLorentzVector & Momentum() const
Q_EXPORT QTSManip setw(int w)
bool Convert(const vector< std::string > &input, std::vector< T > &v)
simb::Origin_t fOriginValue
Declaration of signal hit object.
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Contains all timing reference information for the detector.
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
Vector_t EndDirection() const
std::map< int, RecoHists > fRecoHistMap
const TLorentzVector & Momentum(const int i=0) const
Provides recob::Track data product.
Point_t const & End() const
const MCStep & Start() const
vector< vector< double > > clear
std::string fTrackModuleLabel
unsigned int TrackID() const
Tools and modules for checking out the basics of the Monte Carlo.
auto const & get(AssnsNode< L, R, D > const &r)
second_as<> second
Type of time stored in seconds, in double precision.
std::string fHitModuleLabel
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
QTextStream & endl(QTextStream &s)
Signal from collection planes.