25 #include "art_root_io/TFileService.h" 27 #include "cetlib_except/exception.h" 43 double bdist(
const TVector3& pos)
56 return std::min({d1, d2, d3, d4, d5, d6});
73 double mctime = mctrk.
Start().
T();
80 int ntraj = mctrk.size();
81 for (
int itraj = 0; itraj < ntraj; ++itraj) {
82 const TLorentzVector& vec = mctrk[itraj].Position();
83 double dx = pos[0] - vec.X() - mcdx;
84 double dy = pos[1] - vec.Y();
85 double dz = pos[2] - vec.Z();
86 double dist = std::sqrt(dx * dx + dy * dy + dz * dz);
87 if (best_traj < 0 || dist < max_dist) {
123 int n = mctrk.size();
126 for (
int i = 0; i <
n; ++i) {
127 TVector3 pos = mctrk[i].Position().Vect();
133 if (pos.X() >= xmin && pos.X() <= xmax && pos.Y() >= ymin && pos.Y() <= ymax &&
134 pos.Z() >= zmin && pos.Z() <= zmax) {
140 startmom = 0.001 * mctrk[i].Momentum().Vect();
144 result += disp.Mag();
149 endmom = 0.001 * mctrk[i].Momentum().Vect();
159 void effcalc(
const TH1* hnum,
const TH1* hden, TH1* heff)
161 int nbins = hnum->GetNbinsX();
162 if (nbins != hden->GetNbinsX())
163 throw cet::exception(
"SeedAna") <<
"effcalc[" __FILE__
"]: incompatible histograms (I)\n";
164 if (nbins != heff->GetNbinsX())
165 throw cet::exception(
"SeedAna") <<
"effcalc[" __FILE__
"]: incompatible histograms (II)\n";
169 for (
int ibin = 0; ibin <= nbins + 1; ++ibin) {
170 double num = hnum->GetBinContent(ibin);
171 double den = hden->GetBinContent(ibin);
173 heff->SetBinContent(ibin, 0.);
174 heff->SetBinError(ibin, 0.);
177 double eff = num /
den;
178 if (eff < 0.) eff = 0.;
179 if (eff > 1.) eff = 1.;
180 double err = std::sqrt(eff * (1. - eff) / den);
181 heff->SetBinContent(ibin, eff);
182 heff->SetBinError(ibin, err);
186 heff->SetMinimum(0.);
187 heff->SetMaximum(1.05);
188 heff->SetMarkerStyle(20);
193 void mulcalc(
const TH1* hnum,
const TH1* hden, TH1* hmul)
195 int nbins = hnum->GetNbinsX();
196 if (nbins != hden->GetNbinsX())
197 throw cet::exception(
"SeedAna") <<
"mulcalc[" __FILE__
"]: incompatible histograms (I)\n";
198 if (nbins != hmul->GetNbinsX())
199 throw cet::exception(
"SeedAna") <<
"mulcalc[" __FILE__
"]: incompatible histograms (II)\n";
203 for (
int ibin = 0; ibin <= nbins + 1; ++ibin) {
204 double num = hnum->GetBinContent(ibin);
205 double den = hden->GetBinContent(ibin);
207 hmul->SetBinContent(ibin, 0.);
208 hmul->SetBinError(ibin, 0.);
211 double mul = num /
den;
212 if (mul < 0.) mul = 0.;
213 double err = std::sqrt((1. + mul) * mul / den);
214 hmul->SetBinContent(ibin, mul);
215 hmul->SetBinError(ibin, err);
219 hmul->SetMinimum(0.);
220 hmul->SetMarkerStyle(20);
250 MCHists(
const std::string& subdir);
254 TH2F* fHduvcosth{
nullptr};
255 TH1F* fHcosth{
nullptr};
256 TH1F* fHmcu{
nullptr};
257 TH1F* fHmcv{
nullptr};
258 TH1F* fHmcw{
nullptr};
259 TH1F* fHmcdudw{
nullptr};
260 TH1F* fHmcdvdw{
nullptr};
264 TH1F* fHmcstartx{
nullptr};
265 TH1F* fHmcstarty{
nullptr};
266 TH1F* fHmcstartz{
nullptr};
267 TH1F* fHmcendx{
nullptr};
268 TH1F* fHmcendy{
nullptr};
269 TH1F* fHmcendz{
nullptr};
270 TH1F* fHmctheta{
nullptr};
271 TH1F* fHmcphi{
nullptr};
272 TH1F* fHmctheta_xz{
nullptr};
273 TH1F* fHmctheta_yz{
nullptr};
274 TH1F* fHmcmom{
nullptr};
275 TH1F* fHmclen{
nullptr};
279 TH1F* fHmstartx{
nullptr};
280 TH1F* fHmstarty{
nullptr};
281 TH1F* fHmstartz{
nullptr};
282 TH1F* fHmendx{
nullptr};
283 TH1F* fHmendy{
nullptr};
284 TH1F* fHmendz{
nullptr};
285 TH1F* fHmtheta{
nullptr};
286 TH1F* fHmphi{
nullptr};
287 TH1F* fHmtheta_xz{
nullptr};
288 TH1F* fHmtheta_yz{
nullptr};
289 TH1F* fHmmom{
nullptr};
290 TH1F* fHmlen{
nullptr};
294 TH1F* fHgstartx{
nullptr};
295 TH1F* fHgstarty{
nullptr};
296 TH1F* fHgstartz{
nullptr};
297 TH1F* fHgendx{
nullptr};
298 TH1F* fHgendy{
nullptr};
299 TH1F* fHgendz{
nullptr};
300 TH1F* fHgtheta{
nullptr};
301 TH1F* fHgphi{
nullptr};
302 TH1F* fHgtheta_xz{
nullptr};
303 TH1F* fHgtheta_yz{
nullptr};
304 TH1F* fHgmom{
nullptr};
305 TH1F* fHglen{
nullptr};
309 TH1F* fHmulstartx{
nullptr};
310 TH1F* fHmulstarty{
nullptr};
311 TH1F* fHmulstartz{
nullptr};
312 TH1F* fHmulendx{
nullptr};
313 TH1F* fHmulendy{
nullptr};
314 TH1F* fHmulendz{
nullptr};
315 TH1F* fHmultheta{
nullptr};
316 TH1F* fHmulphi{
nullptr};
317 TH1F* fHmultheta_xz{
nullptr};
318 TH1F* fHmultheta_yz{
nullptr};
319 TH1F* fHmulmom{
nullptr};
320 TH1F* fHmullen{
nullptr};
324 TH1F* fHestartx{
nullptr};
325 TH1F* fHestarty{
nullptr};
326 TH1F* fHestartz{
nullptr};
327 TH1F* fHeendx{
nullptr};
328 TH1F* fHeendy{
nullptr};
329 TH1F* fHeendz{
nullptr};
330 TH1F* fHetheta{
nullptr};
331 TH1F* fHephi{
nullptr};
332 TH1F* fHetheta_xz{
nullptr};
333 TH1F* fHetheta_yz{
nullptr};
334 TH1F* fHemom{
nullptr};
335 TH1F* fHelen{
nullptr};
381 art::TFileDirectory topdir = tfs->mkdir(
"seedana",
"SeedAna histograms");
382 art::TFileDirectory
dir = topdir.mkdir(subdir);
389 fHz = dir.make<TH1F>(
"z",
"Z Position", 100, 0., geom->
DetLength());
391 dir.make<TH1F>(
"dist",
"Position Distance to Boundary", 100, -10., geom->
DetHalfWidth());
392 fHtheta = dir.make<TH1F>(
"theta",
"Theta", 100, 0., 3.142);
393 fHphi = dir.make<TH1F>(
"phi",
"Phi", 100, -3.142, 3.142);
394 fHtheta_xz = dir.make<TH1F>(
"theta_xz",
"Theta_xz", 100, -3.142, 3.142);
395 fHtheta_yz = dir.make<TH1F>(
"theta_yz",
"Theta_yz", 100, -3.142, 3.142);
412 art::TFileDirectory topdir = tfs->mkdir(
"seedana",
"SeedAna histograms");
413 art::TFileDirectory
dir = topdir.mkdir(subdir);
418 dir.make<TH2F>(
"duvcosth",
"Delta(uv) vs. Colinearity", 100, 0.95, 1., 100, 0., 1.);
419 fHcosth = dir.make<TH1F>(
"colin",
"Colinearity", 100, 0.95, 1.);
420 fHmcu = dir.make<TH1F>(
"mcu",
"MC Truth U", 100, -5., 5.);
421 fHmcv = dir.make<TH1F>(
"mcv",
"MC Truth V", 100, -5., 5.);
422 fHmcw = dir.make<TH1F>(
"mcw",
"MC Truth W", 100, -20., 20.);
423 fHmcdudw = dir.make<TH1F>(
"mcdudw",
"MC Truth U Slope", 100, -0.2, 0.2);
424 fHmcdvdw = dir.make<TH1F>(
"mcdvdw",
"MV Truth V Slope", 100, -0.2, 0.2);
426 fHmcstartx = dir.make<TH1F>(
428 fHmcstarty = dir.make<TH1F>(
430 fHmcstartz = dir.make<TH1F>(
"mczstart",
"MC Z Start Position", 10, 0., geom->
DetLength());
431 fHmcendx = dir.make<TH1F>(
433 fHmcendy = dir.make<TH1F>(
435 fHmcendz = dir.make<TH1F>(
"mczend",
"MC Z End Position", 10, 0., geom->
DetLength());
436 fHmctheta = dir.make<TH1F>(
"mctheta",
"MC Theta", 20, 0., 3.142);
437 fHmcphi = dir.make<TH1F>(
"mcphi",
"MC Phi", 10, -3.142, 3.142);
438 fHmctheta_xz = dir.make<TH1F>(
"mctheta_xz",
"MC Theta_xz", 40, -3.142, 3.142);
439 fHmctheta_yz = dir.make<TH1F>(
"mctheta_yz",
"MC Theta_yz", 40, -3.142, 3.142);
440 fHmcmom = dir.make<TH1F>(
"mcmom",
"MC Momentum", 10, 0., 10.);
441 fHmclen = dir.make<TH1F>(
"mclen",
"MC Particle Length", 10, 0., 1.1 * geom->
DetLength());
443 fHmstartx = dir.make<TH1F>(
"mxstart",
444 "Matched X Start Position",
448 fHmstarty = dir.make<TH1F>(
450 fHmstartz = dir.make<TH1F>(
"mzstart",
"Matched Z Start Position", 10, 0., geom->
DetLength());
451 fHmendx = dir.make<TH1F>(
453 fHmendy = dir.make<TH1F>(
455 fHmendz = dir.make<TH1F>(
"mzend",
"Matched Z End Position", 10, 0., geom->
DetLength());
456 fHmtheta = dir.make<TH1F>(
"mtheta",
"Matched Theta", 20, 0., 3.142);
457 fHmphi = dir.make<TH1F>(
"mphi",
"Matched Phi", 10, -3.142, 3.142);
458 fHmtheta_xz = dir.make<TH1F>(
"mtheta_xz",
"Matched Theta_xz", 40, -3.142, 3.142);
459 fHmtheta_yz = dir.make<TH1F>(
"mtheta_yz",
"Matched Theta_yz", 40, -3.142, 3.142);
460 fHmmom = dir.make<TH1F>(
"mmom",
"Matched Momentum", 10, 0., 10.);
461 fHmlen = dir.make<TH1F>(
"mlen",
"Matched Particle Length", 10, 0., 1.1 * geom->
DetLength());
463 fHgstartx = dir.make<TH1F>(
"gxstart",
464 "Good X Start Position",
468 fHgstarty = dir.make<TH1F>(
470 fHgstartz = dir.make<TH1F>(
"gzstart",
"Good Z Start Position", 10, 0., geom->
DetLength());
471 fHgendx = dir.make<TH1F>(
473 fHgendy = dir.make<TH1F>(
475 fHgendz = dir.make<TH1F>(
"gzend",
"Good Z End Position", 10, 0., geom->
DetLength());
476 fHgtheta = dir.make<TH1F>(
"gtheta",
"Good Theta", 20, 0., 3.142);
477 fHgphi = dir.make<TH1F>(
"gphi",
"Good Phi", 10, -3.142, 3.142);
478 fHgtheta_xz = dir.make<TH1F>(
"gtheta_xz",
"Good Theta_xz", 40, -3.142, 3.142);
479 fHgtheta_yz = dir.make<TH1F>(
"gtheta_yz",
"Good Theta_yz", 40, -3.142, 3.142);
480 fHgmom = dir.make<TH1F>(
"gmom",
"Good Momentum", 10, 0., 10.);
481 fHglen = dir.make<TH1F>(
"glen",
"Good Particle Length", 10, 0., 1.1 * geom->
DetLength());
483 fHmulstartx = dir.make<TH1F>(
"mulxstart",
484 "Multiplicity vs. X Start Position",
488 fHmulstarty = dir.make<TH1F>(
"mulystart",
489 "Multiplicity vs. Y Start Position",
494 dir.make<TH1F>(
"mulzstart",
"Multiplicity vs. Z Start Position", 10, 0., geom->
DetLength());
495 fHmulendx = dir.make<TH1F>(
"mulxend",
496 "Multiplicity vs. X End Position",
500 fHmulendy = dir.make<TH1F>(
"mulyend",
501 "Multiplicity vs. Y End Position",
506 dir.make<TH1F>(
"mulzend",
"Multiplicity vs. Z End Position", 10, 0., geom->
DetLength());
507 fHmultheta = dir.make<TH1F>(
"multheta",
"Multiplicity vs. Theta", 20, 0., 3.142);
508 fHmulphi = dir.make<TH1F>(
"mulphi",
"Multiplicity vs. Phi", 10, -3.142, 3.142);
509 fHmultheta_xz = dir.make<TH1F>(
"multheta_xz",
"Multiplicity vs. Theta_xz", 40, -3.142, 3.142);
510 fHmultheta_yz = dir.make<TH1F>(
"multheta_yz",
"Multiplicity vs. Theta_yz", 40, -3.142, 3.142);
511 fHmulmom = dir.make<TH1F>(
"mulmom",
"Multiplicity vs. Momentum", 10, 0., 10.);
513 dir.make<TH1F>(
"mullen",
"Multiplicity vs. Particle Length", 10, 0., 1.1 * geom->
DetLength());
515 fHestartx = dir.make<TH1F>(
"exstart",
516 "Efficiency vs. X Start Position",
520 fHestarty = dir.make<TH1F>(
"eystart",
521 "Efficiency vs. Y Start Position",
526 dir.make<TH1F>(
"ezstart",
"Efficiency vs. Z Start Position", 10, 0., geom->
DetLength());
527 fHeendx = dir.make<TH1F>(
"exend",
528 "Efficiency vs. X End Position",
532 fHeendy = dir.make<TH1F>(
534 fHeendz = dir.make<TH1F>(
"ezend",
"Efficiency vs. Z End Position", 10, 0., geom->
DetLength());
535 fHetheta = dir.make<TH1F>(
"etheta",
"Efficiency vs. Theta", 20, 0., 3.142);
536 fHephi = dir.make<TH1F>(
"ephi",
"Efficiency vs. Phi", 10, -3.142, 3.142);
537 fHetheta_xz = dir.make<TH1F>(
"etheta_xz",
"Efficiency vs. Theta_xz", 40, -3.142, 3.142);
538 fHetheta_yz = dir.make<TH1F>(
"etheta_yz",
"Efficiency vs. Theta_yz", 40, -3.142, 3.142);
539 fHemom = dir.make<TH1F>(
"emom",
"Efficiency vs. Momentum", 10, 0., 10.);
541 dir.make<TH1F>(
"elen",
"Efficiency vs. Particle Length", 10, 0., 1.1 * geom->
DetLength());
561 mf::LogInfo(
"SeedAna") <<
"SeedAna configured with the following parameters:\n" 564 <<
" Dump = " <<
fDump <<
"\n" 565 <<
" MinMCKE = " <<
fMinMCKE <<
"\n" 580 std::unique_ptr<mf::LogInfo> pdump;
583 pdump = std::unique_ptr<mf::LogInfo>(
new mf::LogInfo(
"TrackAna"));
597 std::map<const recob::Seed*, int> seedmap;
609 *pdump <<
"MC Tracks\n" 610 <<
" Id pdg x y z dx dy dz " 612 <<
"--------------------------------------------------------------------------------" 622 imctrk != mctrackh->end();
642 double mctime = mctrk.
Start().
T();
651 double plen = length(detProp, mctrk, mcdx, mcstart, mcend, mcstartmom, mcendmom);
661 double pstart = mcstartmom.Mag();
662 double pend = mcendmom.Mag();
663 *pdump <<
"\nOffset" << std::setw(3) << mctrk.
TrackID() << std::setw(6)
664 << mctrk.
PdgCode() <<
" " << std::fixed << std::setprecision(2)
665 << std::setw(10) << mcdx <<
"\nStart " << std::setw(3) << mctrk.
TrackID()
666 << std::setw(6) << mctrk.
PdgCode() <<
" " << std::fixed
667 << std::setprecision(2) << std::setw(10) << mcstart[0] << std::setw(10)
668 << mcstart[1] << std::setw(10) << mcstart[2];
670 *pdump <<
" " << std::fixed << std::setprecision(3) << std::setw(10)
671 << mcstartmom[0] / pstart << std::setw(10) << mcstartmom[1] / pstart
672 << std::setw(10) << mcstartmom[2] / pstart;
675 *pdump << std::setw(32) <<
" ";
676 *pdump << std::setw(12) << std::fixed << std::setprecision(3) << pstart;
677 *pdump <<
"\nEnd " << std::setw(3) << mctrk.
TrackID() << std::setw(6)
678 << mctrk.
PdgCode() <<
" " << std::fixed << std::setprecision(2)
679 << std::setw(10) << mcend[0] << std::setw(10) << mcend[1] << std::setw(10)
682 *pdump <<
" " << std::fixed << std::setprecision(3) << std::setw(10)
683 << mcendmom[0] / pend << std::setw(10) << mcendmom[1] / pend
684 << std::setw(10) << mcendmom[2] / pend;
687 *pdump << std::setw(32) <<
" ";
688 *pdump << std::setw(12) << std::fixed << std::setprecision(3) << pend <<
"\n";
694 std::ostringstream ostr;
700 double mctheta_xz = std::atan2(mcstartmom.X(), mcstartmom.Z());
701 double mctheta_yz = std::atan2(mcstartmom.Y(), mcstartmom.Z());
709 mchists.
fHmctheta->Fill(mcstartmom.Theta());
710 mchists.
fHmcphi->Fill(mcstartmom.Phi());
713 mchists.
fHmcmom->Fill(mcstartmom.Mag());
723 int nseed = seedh->size();
724 for (
int i = 0; i < nseed; ++i) {
727 if (seedmap.count(&seed) == 0) seedmap[&seed] = -1;
741 double dirmag = dir.Mag();
742 double diryz = std::sqrt(dir.Y() * dir.Y() + dir.Z() * dir.Z());
744 double sinth = dir.X() / dirmag;
745 double costh = diryz / dirmag;
749 sinphi = -dir.Y() / diryz;
750 cosphi = dir.Z() / diryz;
755 rot(0, 1) = sinth * sinphi;
757 rot(2, 1) = -costh * sinphi;
758 rot(0, 2) = -sinth * cosphi;
760 rot(2, 2) = costh * cosphi;
764 int itraj = mcmatch(detProp, mctrk, seed);
769 TVector3 mcpos = mctrk[itraj].Position().Vect() - pos;
770 TVector3 mcmom = mctrk[itraj].Momentum().Vect();
776 TVector3 mcmoml = rot * mcmom;
777 TVector3 mcposl = rot * mcpos;
779 if (mcmoml.Z() < 0.) mcmoml = -mcmoml;
780 double costh = mcmoml.Z() / mcmoml.Mag();
782 double u = mcposl.X();
783 double v = mcposl.Y();
784 double w = mcposl.Z();
786 double pu = mcmoml.X();
787 double pv = mcmoml.Y();
788 double pw = mcmoml.Z();
790 double dudw = pu / pw;
791 double dvdw = pv / pw;
793 double u0 = u - w * dudw;
794 double v0 = v - w * dvdw;
795 double uv0 = std::sqrt(u0 * u0 + v0 * v0);
812 mchists.
fHmcu->Fill(u0);
813 mchists.
fHmcv->Fill(v0);
814 mchists.
fHmcw->Fill(w);
829 mchists.
fHmendx->Fill(mcend.X());
830 mchists.
fHmendy->Fill(mcend.Y());
831 mchists.
fHmendz->Fill(mcend.Z());
832 mchists.
fHmtheta->Fill(mcstartmom.Theta());
833 mchists.
fHmphi->Fill(mcstartmom.Phi());
836 mchists.
fHmmom->Fill(mcstartmom.Mag());
837 mchists.
fHmlen->Fill(plen);
850 mchists.
fHgendx->Fill(mcend.X());
851 mchists.
fHgendy->Fill(mcend.Y());
852 mchists.
fHgendz->Fill(mcend.Z());
853 mchists.
fHgtheta->Fill(mcstartmom.Theta());
854 mchists.
fHgphi->Fill(mcstartmom.Phi());
857 mchists.
fHgmom->Fill(mcstartmom.Mag());
858 mchists.
fHglen->Fill(plen);
873 int nseed = seedh->size();
875 if (nseed > 0 && pdump != 0) {
876 *pdump <<
"\nReconstructed Seeds\n" 877 <<
" MCid x y z dx dy dz " 879 <<
"--------------------------------------------------------------------------------" 883 for (
int i = 0; i < nseed; ++i) {
894 double mdir = dir.Mag();
895 if (mdir != 0.) { dir *= (1. / mdir); }
897 double dpos = bdist(pos);
898 double theta_xz = std::atan2(dir.X(), dir.Z());
899 double theta_yz = std::atan2(dir.Y(), dir.Z());
904 int mcid = seedmap[&
seed];
905 *pdump << std::setw(15) << mcid <<
" " << std::fixed << std::setprecision(2)
906 << std::setw(10) << pos[0] << std::setw(10) << pos[1] << std::setw(10) << pos[2]
907 <<
" " << std::fixed << std::setprecision(3) << std::setw(10) << dir[0]
908 << std::setw(10) << dir[1] << std::setw(10) << dir[2] <<
"\n";
916 rhists.
fHx->Fill(pos.X());
917 rhists.
fHy->Fill(pos.Y());
918 rhists.
fHz->Fill(pos.Z());
919 rhists.
fHdist->Fill(dpos);
920 rhists.
fHtheta->Fill(dir.Theta());
921 rhists.
fHphi->Fill(dir.Phi());
942 const MCHists& mchists = i->second;
960 const MCHists& mchists = i->second;
std::string fMCTrackModuleLabel
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
void GetPoint(double *Pt, double *Err) const
Length_t DetHalfWidth(TPCID const &tpcid=tpc_zero) const
Returns the half width of the active volume of the specified TPC.
constexpr auto abs(T v)
Returns the absolute value of the argument.
std::string fSeedModuleLabel
unsigned int ReadOutWindowSize() const
EDAnalyzer(fhicl::ParameterSet const &pset)
tick ticks
Alias for common language habits.
Length_t DetLength(TPCID const &tpcid=tpc_zero) const
Returns the length of the active volume of the specified TPC.
MCHists(const std::string &subdir)
void analyze(const art::Event &evt) override
bool isValid() const noexcept
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
#define DEFINE_ART_MODULE(klass)
double ConvertXToTicks(double X, int p, int t, int c) const
double DriftVelocity(double efield=0., double temperature=0.) const
cm/us
Class def header for mctrack data container.
std::map< int, RecoHists > fRecoHistMap
const TLorentzVector & Momentum() const
SeedAna(fhicl::ParameterSet const &pset)
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
std::map< int, MCHists > fMCHistMap
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
const MCStep & Start() const
Length_t DetHalfHeight(TPCID const &tpcid=tpc_zero) const
Returns the half height of the active volume of the specified TPC.
unsigned int TrackID() const
void GetDirection(double *Dir, double *Err) const
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
RecoHists(const std::string &subdir)