25 #include "art_root_io/TFileService.h" 26 #include "cetlib_except/exception.h" 43 bdist(
const TVector3&
pos,
unsigned int = 0,
unsigned int = 0)
56 return std::min({d1, d2, d3, d4, d5, d6});
74 double mctime = mctrk.
Start().
T();
81 int ntraj = mctrk.size();
82 for (
int itraj = 0; itraj < ntraj; ++itraj) {
83 const TLorentzVector& vec = mctrk[itraj].Position();
84 double dx = pos[0] - vec.X() - mcdx;
85 double dy = pos[1] - vec.Y();
86 double dz = pos[2] - vec.Z();
87 double dist = std::sqrt(dx * dx + dy * dy + dz * dz);
88 if (best_traj < 0 || dist < max_dist) {
125 int n = mctrk.size();
128 for (
int i = 0; i <
n; ++i) {
129 TVector3 pos = mctrk[i].Position().Vect();
135 if (pos.X() >= xmin && pos.X() <= xmax && pos.Y() >= ymin && pos.Y() <= ymax &&
136 pos.Z() >= zmin && pos.Z() <= zmax) {
142 startmom = 0.001 * mctrk[i].Momentum().Vect();
146 result += disp.Mag();
151 endmom = 0.001 * mctrk[i].Momentum().Vect();
162 effcalc(
const TH1* hnum,
const TH1* hden, TH1* heff)
164 int nbins = hnum->GetNbinsX();
165 if (nbins != hden->GetNbinsX())
166 throw cet::exception(
"SeedAna") <<
"effcalc[" __FILE__
"]: incompatible histograms (I)\n";
167 if (nbins != heff->GetNbinsX())
168 throw cet::exception(
"SeedAna") <<
"effcalc[" __FILE__
"]: incompatible histograms (II)\n";
172 for (
int ibin = 0; ibin <= nbins + 1; ++ibin) {
173 double num = hnum->GetBinContent(ibin);
174 double den = hden->GetBinContent(ibin);
176 heff->SetBinContent(ibin, 0.);
177 heff->SetBinError(ibin, 0.);
180 double eff = num / den;
181 if (eff < 0.) eff = 0.;
182 if (eff > 1.) eff = 1.;
183 double err = std::sqrt(eff * (1. - eff) / den);
184 heff->SetBinContent(ibin, eff);
185 heff->SetBinError(ibin, err);
189 heff->SetMinimum(0.);
190 heff->SetMaximum(1.05);
191 heff->SetMarkerStyle(20);
197 mulcalc(
const TH1* hnum,
const TH1* hden, TH1* hmul)
199 int nbins = hnum->GetNbinsX();
200 if (nbins != hden->GetNbinsX())
201 throw cet::exception(
"SeedAna") <<
"mulcalc[" __FILE__
"]: incompatible histograms (I)\n";
202 if (nbins != hmul->GetNbinsX())
203 throw cet::exception(
"SeedAna") <<
"mulcalc[" __FILE__
"]: incompatible histograms (II)\n";
207 for (
int ibin = 0; ibin <= nbins + 1; ++ibin) {
208 double num = hnum->GetBinContent(ibin);
209 double den = hden->GetBinContent(ibin);
211 hmul->SetBinContent(ibin, 0.);
212 hmul->SetBinError(ibin, 0.);
215 double mul = num / den;
216 if (mul < 0.) mul = 0.;
217 double err = std::sqrt((1. + mul) * mul / den);
218 hmul->SetBinContent(ibin, mul);
219 hmul->SetBinError(ibin, err);
223 hmul->SetMinimum(0.);
224 hmul->SetMarkerStyle(20);
258 TH2F* fHduvcosth{
nullptr};
259 TH1F* fHcosth{
nullptr};
260 TH1F* fHmcu{
nullptr};
261 TH1F* fHmcv{
nullptr};
262 TH1F* fHmcw{
nullptr};
263 TH1F* fHmcdudw{
nullptr};
264 TH1F* fHmcdvdw{
nullptr};
268 TH1F* fHmcstartx{
nullptr};
269 TH1F* fHmcstarty{
nullptr};
270 TH1F* fHmcstartz{
nullptr};
271 TH1F* fHmcendx{
nullptr};
272 TH1F* fHmcendy{
nullptr};
273 TH1F* fHmcendz{
nullptr};
274 TH1F* fHmctheta{
nullptr};
275 TH1F* fHmcphi{
nullptr};
276 TH1F* fHmctheta_xz{
nullptr};
277 TH1F* fHmctheta_yz{
nullptr};
278 TH1F* fHmcmom{
nullptr};
279 TH1F* fHmclen{
nullptr};
283 TH1F* fHmstartx{
nullptr};
284 TH1F* fHmstarty{
nullptr};
285 TH1F* fHmstartz{
nullptr};
286 TH1F* fHmendx{
nullptr};
287 TH1F* fHmendy{
nullptr};
288 TH1F* fHmendz{
nullptr};
289 TH1F* fHmtheta{
nullptr};
290 TH1F* fHmphi{
nullptr};
291 TH1F* fHmtheta_xz{
nullptr};
292 TH1F* fHmtheta_yz{
nullptr};
293 TH1F* fHmmom{
nullptr};
294 TH1F* fHmlen{
nullptr};
298 TH1F* fHgstartx{
nullptr};
299 TH1F* fHgstarty{
nullptr};
300 TH1F* fHgstartz{
nullptr};
301 TH1F* fHgendx{
nullptr};
302 TH1F* fHgendy{
nullptr};
303 TH1F* fHgendz{
nullptr};
304 TH1F* fHgtheta{
nullptr};
305 TH1F* fHgphi{
nullptr};
306 TH1F* fHgtheta_xz{
nullptr};
307 TH1F* fHgtheta_yz{
nullptr};
308 TH1F* fHgmom{
nullptr};
309 TH1F* fHglen{
nullptr};
313 TH1F* fHmulstartx{
nullptr};
314 TH1F* fHmulstarty{
nullptr};
315 TH1F* fHmulstartz{
nullptr};
316 TH1F* fHmulendx{
nullptr};
317 TH1F* fHmulendy{
nullptr};
318 TH1F* fHmulendz{
nullptr};
319 TH1F* fHmultheta{
nullptr};
320 TH1F* fHmulphi{
nullptr};
321 TH1F* fHmultheta_xz{
nullptr};
322 TH1F* fHmultheta_yz{
nullptr};
323 TH1F* fHmulmom{
nullptr};
324 TH1F* fHmullen{
nullptr};
328 TH1F* fHestartx{
nullptr};
329 TH1F* fHestarty{
nullptr};
330 TH1F* fHestartz{
nullptr};
331 TH1F* fHeendx{
nullptr};
332 TH1F* fHeendy{
nullptr};
333 TH1F* fHeendz{
nullptr};
334 TH1F* fHetheta{
nullptr};
335 TH1F* fHephi{
nullptr};
336 TH1F* fHetheta_xz{
nullptr};
337 TH1F* fHetheta_yz{
nullptr};
338 TH1F* fHemom{
nullptr};
339 TH1F* fHelen{
nullptr};
385 art::TFileDirectory topdir = tfs->mkdir(
"seedana",
"SeedAna histograms");
386 art::TFileDirectory
dir = topdir.mkdir(subdir);
393 fHz = dir.make<TH1F>(
"z",
"Z Position", 100, 0., geom->
DetLength());
395 dir.make<TH1F>(
"dist",
"Position Distance to Boundary", 100, -10., geom->
DetHalfWidth());
396 fHtheta = dir.make<TH1F>(
"theta",
"Theta", 100, 0., 3.142);
397 fHphi = dir.make<TH1F>(
"phi",
"Phi", 100, -3.142, 3.142);
398 fHtheta_xz = dir.make<TH1F>(
"theta_xz",
"Theta_xz", 100, -3.142, 3.142);
399 fHtheta_yz = dir.make<TH1F>(
"theta_yz",
"Theta_yz", 100, -3.142, 3.142);
416 art::TFileDirectory topdir = tfs->mkdir(
"seedana",
"SeedAna histograms");
417 art::TFileDirectory
dir = topdir.mkdir(subdir);
422 dir.make<TH2F>(
"duvcosth",
"Delta(uv) vs. Colinearity", 100, 0.95, 1., 100, 0., 1.);
423 fHcosth = dir.make<TH1F>(
"colin",
"Colinearity", 100, 0.95, 1.);
424 fHmcu = dir.make<TH1F>(
"mcu",
"MC Truth U", 100, -5., 5.);
425 fHmcv = dir.make<TH1F>(
"mcv",
"MC Truth V", 100, -5., 5.);
426 fHmcw = dir.make<TH1F>(
"mcw",
"MC Truth W", 100, -20., 20.);
427 fHmcdudw = dir.make<TH1F>(
"mcdudw",
"MC Truth U Slope", 100, -0.2, 0.2);
428 fHmcdvdw = dir.make<TH1F>(
"mcdvdw",
"MV Truth V Slope", 100, -0.2, 0.2);
430 fHmcstartx = dir.make<TH1F>(
432 fHmcstarty = dir.make<TH1F>(
434 fHmcstartz = dir.make<TH1F>(
"mczstart",
"MC Z Start Position", 10, 0., geom->
DetLength());
435 fHmcendx = dir.make<TH1F>(
437 fHmcendy = dir.make<TH1F>(
439 fHmcendz = dir.make<TH1F>(
"mczend",
"MC Z End Position", 10, 0., geom->
DetLength());
440 fHmctheta = dir.make<TH1F>(
"mctheta",
"MC Theta", 20, 0., 3.142);
441 fHmcphi = dir.make<TH1F>(
"mcphi",
"MC Phi", 10, -3.142, 3.142);
442 fHmctheta_xz = dir.make<TH1F>(
"mctheta_xz",
"MC Theta_xz", 40, -3.142, 3.142);
443 fHmctheta_yz = dir.make<TH1F>(
"mctheta_yz",
"MC Theta_yz", 40, -3.142, 3.142);
444 fHmcmom = dir.make<TH1F>(
"mcmom",
"MC Momentum", 10, 0., 10.);
445 fHmclen = dir.make<TH1F>(
"mclen",
"MC Particle Length", 10, 0., 1.1 * geom->
DetLength());
447 fHmstartx = dir.make<TH1F>(
"mxstart",
448 "Matched X Start Position",
452 fHmstarty = dir.make<TH1F>(
454 fHmstartz = dir.make<TH1F>(
"mzstart",
"Matched Z Start Position", 10, 0., geom->
DetLength());
455 fHmendx = dir.make<TH1F>(
457 fHmendy = dir.make<TH1F>(
459 fHmendz = dir.make<TH1F>(
"mzend",
"Matched Z End Position", 10, 0., geom->
DetLength());
460 fHmtheta = dir.make<TH1F>(
"mtheta",
"Matched Theta", 20, 0., 3.142);
461 fHmphi = dir.make<TH1F>(
"mphi",
"Matched Phi", 10, -3.142, 3.142);
462 fHmtheta_xz = dir.make<TH1F>(
"mtheta_xz",
"Matched Theta_xz", 40, -3.142, 3.142);
463 fHmtheta_yz = dir.make<TH1F>(
"mtheta_yz",
"Matched Theta_yz", 40, -3.142, 3.142);
464 fHmmom = dir.make<TH1F>(
"mmom",
"Matched Momentum", 10, 0., 10.);
465 fHmlen = dir.make<TH1F>(
"mlen",
"Matched Particle Length", 10, 0., 1.1 * geom->
DetLength());
467 fHgstartx = dir.make<TH1F>(
"gxstart",
468 "Good X Start Position",
472 fHgstarty = dir.make<TH1F>(
474 fHgstartz = dir.make<TH1F>(
"gzstart",
"Good Z Start Position", 10, 0., geom->
DetLength());
475 fHgendx = dir.make<TH1F>(
477 fHgendy = dir.make<TH1F>(
479 fHgendz = dir.make<TH1F>(
"gzend",
"Good Z End Position", 10, 0., geom->
DetLength());
480 fHgtheta = dir.make<TH1F>(
"gtheta",
"Good Theta", 20, 0., 3.142);
481 fHgphi = dir.make<TH1F>(
"gphi",
"Good Phi", 10, -3.142, 3.142);
482 fHgtheta_xz = dir.make<TH1F>(
"gtheta_xz",
"Good Theta_xz", 40, -3.142, 3.142);
483 fHgtheta_yz = dir.make<TH1F>(
"gtheta_yz",
"Good Theta_yz", 40, -3.142, 3.142);
484 fHgmom = dir.make<TH1F>(
"gmom",
"Good Momentum", 10, 0., 10.);
485 fHglen = dir.make<TH1F>(
"glen",
"Good Particle Length", 10, 0., 1.1 * geom->
DetLength());
487 fHmulstartx = dir.make<TH1F>(
"mulxstart",
488 "Multiplicity vs. X Start Position",
492 fHmulstarty = dir.make<TH1F>(
"mulystart",
493 "Multiplicity vs. Y Start Position",
498 dir.make<TH1F>(
"mulzstart",
"Multiplicity vs. Z Start Position", 10, 0., geom->
DetLength());
499 fHmulendx = dir.make<TH1F>(
"mulxend",
500 "Multiplicity vs. X End Position",
504 fHmulendy = dir.make<TH1F>(
"mulyend",
505 "Multiplicity vs. Y End Position",
510 dir.make<TH1F>(
"mulzend",
"Multiplicity vs. Z End Position", 10, 0., geom->
DetLength());
511 fHmultheta = dir.make<TH1F>(
"multheta",
"Multiplicity vs. Theta", 20, 0., 3.142);
512 fHmulphi = dir.make<TH1F>(
"mulphi",
"Multiplicity vs. Phi", 10, -3.142, 3.142);
513 fHmultheta_xz = dir.make<TH1F>(
"multheta_xz",
"Multiplicity vs. Theta_xz", 40, -3.142, 3.142);
514 fHmultheta_yz = dir.make<TH1F>(
"multheta_yz",
"Multiplicity vs. Theta_yz", 40, -3.142, 3.142);
515 fHmulmom = dir.make<TH1F>(
"mulmom",
"Multiplicity vs. Momentum", 10, 0., 10.);
517 dir.make<TH1F>(
"mullen",
"Multiplicity vs. Particle Length", 10, 0., 1.1 * geom->
DetLength());
519 fHestartx = dir.make<TH1F>(
"exstart",
520 "Efficiency vs. X Start Position",
524 fHestarty = dir.make<TH1F>(
"eystart",
525 "Efficiency vs. Y Start Position",
530 dir.make<TH1F>(
"ezstart",
"Efficiency vs. Z Start Position", 10, 0., geom->
DetLength());
531 fHeendx = dir.make<TH1F>(
"exend",
532 "Efficiency vs. X End Position",
536 fHeendy = dir.make<TH1F>(
538 fHeendz = dir.make<TH1F>(
"ezend",
"Efficiency vs. Z End Position", 10, 0., geom->
DetLength());
539 fHetheta = dir.make<TH1F>(
"etheta",
"Efficiency vs. Theta", 20, 0., 3.142);
540 fHephi = dir.make<TH1F>(
"ephi",
"Efficiency vs. Phi", 10, -3.142, 3.142);
541 fHetheta_xz = dir.make<TH1F>(
"etheta_xz",
"Efficiency vs. Theta_xz", 40, -3.142, 3.142);
542 fHetheta_yz = dir.make<TH1F>(
"etheta_yz",
"Efficiency vs. Theta_yz", 40, -3.142, 3.142);
543 fHemom = dir.make<TH1F>(
"emom",
"Efficiency vs. Momentum", 10, 0., 10.);
545 dir.make<TH1F>(
"elen",
"Efficiency vs. Particle Length", 10, 0., 1.1 * geom->
DetLength());
565 mf::LogInfo(
"SeedAna") <<
"SeedAna configured with the following parameters:\n" 568 <<
" Dump = " <<
fDump <<
"\n" 569 <<
" MinMCKE = " <<
fMinMCKE <<
"\n" 585 std::unique_ptr<mf::LogInfo> pdump;
588 pdump = std::unique_ptr<mf::LogInfo>(
new mf::LogInfo(
"TrackAna"));
602 std::map<const recob::Seed*, int> seedmap;
614 *pdump <<
"MC Tracks\n" 615 <<
" Id pdg x y z dx dy dz " 617 <<
"--------------------------------------------------------------------------------" 627 imctrk != mctrackh->end();
647 double mctime = mctrk.
Start().
T();
656 double plen = length(detProp, mctrk, mcdx, mcstart, mcend, mcstartmom, mcendmom);
666 double pstart = mcstartmom.Mag();
667 double pend = mcendmom.Mag();
673 << mcstart[1] <<
std::setw(10) << mcstart[2];
676 << mcstartmom[0] / pstart <<
std::setw(10) << mcstartmom[1] / pstart
677 <<
std::setw(10) << mcstartmom[2] / pstart;
688 << mcendmom[0] / pend <<
std::setw(10) << mcendmom[1] / pend
699 std::ostringstream ostr;
705 double mctheta_xz = std::atan2(mcstartmom.X(), mcstartmom.Z());
706 double mctheta_yz = std::atan2(mcstartmom.Y(), mcstartmom.Z());
714 mchists.
fHmctheta->Fill(mcstartmom.Theta());
715 mchists.
fHmcphi->Fill(mcstartmom.Phi());
718 mchists.
fHmcmom->Fill(mcstartmom.Mag());
728 int nseed = seedh->size();
729 for (
int i = 0; i < nseed; ++i) {
732 if (seedmap.count(&seed) == 0) seedmap[&seed] = -1;
746 double dirmag = dir.Mag();
747 double diryz = std::sqrt(dir.Y() * dir.Y() + dir.Z() * dir.Z());
749 double sinth = dir.X() / dirmag;
750 double costh = diryz / dirmag;
754 sinphi = -dir.Y() / diryz;
755 cosphi = dir.Z() / diryz;
760 rot(0, 1) = sinth * sinphi;
762 rot(2, 1) = -costh * sinphi;
763 rot(0, 2) = -sinth * cosphi;
765 rot(2, 2) = costh * cosphi;
769 int itraj = mcmatch(detProp, mctrk, seed);
774 TVector3 mcpos = mctrk[itraj].Position().Vect() -
pos;
775 TVector3 mcmom = mctrk[itraj].Momentum().Vect();
781 TVector3 mcmoml = rot * mcmom;
782 TVector3 mcposl = rot * mcpos;
784 if (mcmoml.Z() < 0.) mcmoml = -mcmoml;
785 double costh = mcmoml.Z() / mcmoml.Mag();
787 double u = mcposl.X();
788 double v = mcposl.Y();
789 double w = mcposl.Z();
791 double pu = mcmoml.X();
792 double pv = mcmoml.Y();
793 double pw = mcmoml.Z();
795 double dudw = pu / pw;
796 double dvdw = pv / pw;
798 double u0 = u - w * dudw;
799 double v0 = v - w * dvdw;
800 double uv0 = std::sqrt(u0 * u0 + v0 * v0);
817 mchists.
fHmcu->Fill(u0);
818 mchists.
fHmcv->Fill(v0);
819 mchists.
fHmcw->Fill(w);
827 seedmap[&seed] = mctrk.
TrackID();
834 mchists.
fHmendx->Fill(mcend.X());
835 mchists.
fHmendy->Fill(mcend.Y());
836 mchists.
fHmendz->Fill(mcend.Z());
837 mchists.
fHmtheta->Fill(mcstartmom.Theta());
838 mchists.
fHmphi->Fill(mcstartmom.Phi());
841 mchists.
fHmmom->Fill(mcstartmom.Mag());
842 mchists.
fHmlen->Fill(plen);
855 mchists.
fHgendx->Fill(mcend.X());
856 mchists.
fHgendy->Fill(mcend.Y());
857 mchists.
fHgendz->Fill(mcend.Z());
858 mchists.
fHgtheta->Fill(mcstartmom.Theta());
859 mchists.
fHgphi->Fill(mcstartmom.Phi());
862 mchists.
fHgmom->Fill(mcstartmom.Mag());
863 mchists.
fHglen->Fill(plen);
878 int nseed = seedh->size();
880 if (nseed > 0 && pdump != 0) {
881 *pdump <<
"\nReconstructed Seeds\n" 882 <<
" MCid x y z dx dy dz " 884 <<
"--------------------------------------------------------------------------------" 888 for (
int i = 0; i < nseed; ++i) {
899 double mdir = dir.Mag();
900 if (mdir != 0.) { dir *= (1. / mdir); }
902 double dpos = bdist(pos);
903 double theta_xz = std::atan2(dir.X(), dir.Z());
904 double theta_yz = std::atan2(dir.Y(), dir.Z());
909 int mcid = seedmap[&seed];
921 rhists.
fHx->Fill(pos.X());
922 rhists.
fHy->Fill(pos.Y());
923 rhists.
fHz->Fill(pos.Z());
924 rhists.
fHdist->Fill(dpos);
925 rhists.
fHtheta->Fill(dir.Theta());
926 rhists.
fHphi->Fill(dir.Phi());
948 const MCHists& mchists = i->second;
966 const MCHists& mchists = i->second;
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
geo::Length_t DetHalfWidth(geo::TPCID const &tpcid) const
Returns the half width of the active volume of the specified TPC.
std::string fMCTrackModuleLabel
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
void GetPoint(double *Pt, double *Err) const
std::string fSeedModuleLabel
unsigned int ReadOutWindowSize() const
EDAnalyzer(fhicl::ParameterSet const &pset)
tick ticks
Alias for common language habits.
Q_EXPORT QTSManip setprecision(int p)
art framework interface to geometry description
MCHists(const std::string &subdir)
void analyze(const art::Event &evt) override
bool isValid() const noexcept
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
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)
double ConvertXToTicks(double X, int p, int t, int c) const
geo::Length_t DetLength(geo::TPCID const &tpcid) const
Returns the length of the active volume of the specified TPC.
double DriftVelocity(double efield=0., double temperature=0.) const
cm/us
Class def header for mctrack data container.
std::map< int, RecoHists > fRecoHistMap
void err(const char *fmt,...)
const TLorentzVector & Momentum() const
Q_EXPORT QTSManip setw(int w)
SeedAna(fhicl::ParameterSet const &pset)
std::map< int, MCHists > fMCHistMap
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
const MCStep & Start() const
unsigned int TrackID() const
auto const & get(AssnsNode< L, R, D > const &r)
void GetDirection(double *Dir, double *Err) const
cet::coded_exception< error, detail::translate > exception
RecoHists(const std::string &subdir)