28 #include "cetlib_except/exception.h" 46 double bdist(
const TVector3& pos,
unsigned int = 0,
unsigned int = 0)
77 double mctime = mctrk.
Start().
T();
84 int ntraj = mctrk.size();
85 for(
int itraj = 0; itraj < ntraj; ++itraj) {
86 const TLorentzVector& vec = mctrk[itraj].Position();
87 double dx = pos[0] - vec.X() - mcdx;
88 double dy = pos[1] - vec.Y();
89 double dz = pos[2] - vec.Z();
90 double dist = std::sqrt(dx*dx + dy*dy + dz*dz);
91 if(best_traj < 0 || dist < max_dist) {
104 TVector3& start, TVector3&
end, TVector3& startmom, TVector3& endmom,
105 unsigned int = 0,
unsigned int = 0)
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 &&
141 if(ticks >= 0. && ticks < detprop->ReadOutWindowSize()) {
144 startmom = 0.001 * mctrk[i].Momentum().Vect();
148 result += disp.Mag();
153 endmom = 0.001 * mctrk[i].Momentum().Vect();
163 void effcalc(
const TH1* hnum,
const TH1* hden, TH1* heff)
165 int nbins = hnum->GetNbinsX();
166 if (nbins != hden->GetNbinsX())
167 throw cet::exception(
"SeedAna") <<
"effcalc[" __FILE__
"]: incompatible histograms (I)\n";
168 if (nbins != heff->GetNbinsX())
169 throw cet::exception(
"SeedAna") <<
"effcalc[" __FILE__
"]: incompatible histograms (II)\n";
173 for(
int ibin = 0; ibin <= nbins+1; ++ibin) {
174 double num = hnum->GetBinContent(ibin);
175 double den = hden->GetBinContent(ibin);
177 heff->SetBinContent(ibin, 0.);
178 heff->SetBinError(ibin, 0.);
181 double eff = num /
den;
186 double err = std::sqrt(eff * (1.-eff) / den);
187 heff->SetBinContent(ibin, eff);
188 heff->SetBinError(ibin, err);
192 heff->SetMinimum(0.);
193 heff->SetMaximum(1.05);
194 heff->SetMarkerStyle(20);
199 void mulcalc(
const TH1* hnum,
const TH1* hden, TH1* hmul)
201 int nbins = hnum->GetNbinsX();
202 if (nbins != hden->GetNbinsX())
203 throw cet::exception(
"SeedAna") <<
"mulcalc[" __FILE__
"]: incompatible histograms (I)\n";
204 if (nbins != hmul->GetNbinsX())
205 throw cet::exception(
"SeedAna") <<
"mulcalc[" __FILE__
"]: incompatible histograms (II)\n";
209 for(
int ibin = 0; ibin <= nbins+1; ++ibin) {
210 double num = hnum->GetBinContent(ibin);
211 double den = hden->GetBinContent(ibin);
213 hmul->SetBinContent(ibin, 0.);
214 hmul->SetBinError(ibin, 0.);
217 double mul = num /
den;
220 double err = std::sqrt((1. + mul) * mul / den);
221 hmul->SetBinContent(ibin, mul);
222 hmul->SetBinError(ibin, err);
226 hmul->SetMinimum(0.);
227 hmul->SetMarkerStyle(20);
267 MCHists(
const std::string& subdir);
430 fHdist = dir.
make<TH1F>(
"dist",
"Position Distance to Boundary",
432 fHtheta = dir.
make<TH1F>(
"theta",
"Theta", 100, 0., 3.142);
433 fHphi = dir.
make<TH1F>(
"phi",
"Phi", 100, -3.142, 3.142);
434 fHtheta_xz = dir.
make<TH1F>(
"theta_xz",
"Theta_xz", 100, -3.142, 3.142);
435 fHtheta_yz = dir.
make<TH1F>(
"theta_yz",
"Theta_yz", 100, -3.142, 3.142);
534 fHduvcosth = dir.
make<TH2F>(
"duvcosth",
"Delta(uv) vs. Colinearity",
535 100, 0.95, 1., 100, 0., 1.);
536 fHcosth = dir.
make<TH1F>(
"colin",
"Colinearity", 100, 0.95, 1.);
537 fHmcu = dir.
make<TH1F>(
"mcu",
"MC Truth U", 100, -5., 5.);
538 fHmcv = dir.
make<TH1F>(
"mcv",
"MC Truth V", 100, -5., 5.);
539 fHmcw = dir.
make<TH1F>(
"mcw",
"MC Truth W", 100, -20., 20.);
540 fHmcdudw = dir.
make<TH1F>(
"mcdudw",
"MC Truth U Slope", 100, -0.2, 0.2);
541 fHmcdvdw = dir.
make<TH1F>(
"mcdvdw",
"MV Truth V Slope", 100, -0.2, 0.2);
549 fHmcendx = dir.
make<TH1F>(
"mcxend",
"MC X End Position",
551 fHmcendy = dir.
make<TH1F>(
"mcyend",
"MC Y End Position",
553 fHmcendz = dir.
make<TH1F>(
"mczend",
"MC Z End Position",
555 fHmctheta = dir.
make<TH1F>(
"mctheta",
"MC Theta", 20, 0., 3.142);
556 fHmcphi = dir.
make<TH1F>(
"mcphi",
"MC Phi", 10, -3.142, 3.142);
557 fHmctheta_xz = dir.
make<TH1F>(
"mctheta_xz",
"MC Theta_xz", 40, -3.142, 3.142);
558 fHmctheta_yz = dir.
make<TH1F>(
"mctheta_yz",
"MC Theta_yz", 40, -3.142, 3.142);
559 fHmcmom = dir.
make<TH1F>(
"mcmom",
"MC Momentum", 10, 0., 10.);
562 fHmstartx = dir.
make<TH1F>(
"mxstart",
"Matched X Start Position",
564 fHmstarty = dir.
make<TH1F>(
"mystart",
"Matched Y Start Position",
566 fHmstartz = dir.
make<TH1F>(
"mzstart",
"Matched Z Start Position",
568 fHmendx = dir.
make<TH1F>(
"mxend",
"Matched X End Position",
570 fHmendy = dir.
make<TH1F>(
"myend",
"Matched Y End Position",
572 fHmendz = dir.
make<TH1F>(
"mzend",
"Matched Z End Position",
574 fHmtheta = dir.
make<TH1F>(
"mtheta",
"Matched Theta", 20, 0., 3.142);
575 fHmphi = dir.
make<TH1F>(
"mphi",
"Matched Phi", 10, -3.142, 3.142);
576 fHmtheta_xz = dir.
make<TH1F>(
"mtheta_xz",
"Matched Theta_xz", 40, -3.142, 3.142);
577 fHmtheta_yz = dir.
make<TH1F>(
"mtheta_yz",
"Matched Theta_yz", 40, -3.142, 3.142);
578 fHmmom = dir.
make<TH1F>(
"mmom",
"Matched Momentum", 10, 0., 10.);
579 fHmlen = dir.
make<TH1F>(
"mlen",
"Matched Particle Length", 10, 0., 1.1 * geom->
DetLength());
581 fHgstartx = dir.
make<TH1F>(
"gxstart",
"Good X Start Position",
583 fHgstarty = dir.
make<TH1F>(
"gystart",
"Good Y Start Position",
585 fHgstartz = dir.
make<TH1F>(
"gzstart",
"Good Z Start Position",
587 fHgendx = dir.
make<TH1F>(
"gxend",
"Good X End Position",
589 fHgendy = dir.
make<TH1F>(
"gyend",
"Good Y End Position",
591 fHgendz = dir.
make<TH1F>(
"gzend",
"Good Z End Position",
593 fHgtheta = dir.
make<TH1F>(
"gtheta",
"Good Theta", 20, 0., 3.142);
594 fHgphi = dir.
make<TH1F>(
"gphi",
"Good Phi", 10, -3.142, 3.142);
595 fHgtheta_xz = dir.
make<TH1F>(
"gtheta_xz",
"Good Theta_xz", 40, -3.142, 3.142);
596 fHgtheta_yz = dir.
make<TH1F>(
"gtheta_yz",
"Good Theta_yz", 40, -3.142, 3.142);
597 fHgmom = dir.
make<TH1F>(
"gmom",
"Good Momentum", 10, 0., 10.);
600 fHmulstartx = dir.
make<TH1F>(
"mulxstart",
"Multiplicity vs. X Start Position",
602 fHmulstarty = dir.
make<TH1F>(
"mulystart",
"Multiplicity vs. Y Start Position",
604 fHmulstartz = dir.
make<TH1F>(
"mulzstart",
"Multiplicity vs. Z Start Position",
606 fHmulendx = dir.
make<TH1F>(
"mulxend",
"Multiplicity vs. X End Position",
608 fHmulendy = dir.
make<TH1F>(
"mulyend",
"Multiplicity vs. Y End Position",
610 fHmulendz = dir.
make<TH1F>(
"mulzend",
"Multiplicity vs. Z End Position",
612 fHmultheta = dir.
make<TH1F>(
"multheta",
"Multiplicity vs. Theta", 20, 0., 3.142);
613 fHmulphi = dir.
make<TH1F>(
"mulphi",
"Multiplicity vs. Phi", 10, -3.142, 3.142);
614 fHmultheta_xz = dir.
make<TH1F>(
"multheta_xz",
"Multiplicity vs. Theta_xz", 40, -3.142, 3.142);
615 fHmultheta_yz = dir.
make<TH1F>(
"multheta_yz",
"Multiplicity vs. Theta_yz", 40, -3.142, 3.142);
616 fHmulmom = dir.
make<TH1F>(
"mulmom",
"Multiplicity vs. Momentum", 10, 0., 10.);
617 fHmullen = dir.
make<TH1F>(
"mullen",
"Multiplicity vs. Particle Length",
620 fHestartx = dir.
make<TH1F>(
"exstart",
"Efficiency vs. X Start Position",
622 fHestarty = dir.
make<TH1F>(
"eystart",
"Efficiency vs. Y Start Position",
624 fHestartz = dir.
make<TH1F>(
"ezstart",
"Efficiency vs. Z Start Position",
626 fHeendx = dir.
make<TH1F>(
"exend",
"Efficiency vs. X End Position",
628 fHeendy = dir.
make<TH1F>(
"eyend",
"Efficiency vs. Y End Position",
630 fHeendz = dir.
make<TH1F>(
"ezend",
"Efficiency vs. Z End Position",
632 fHetheta = dir.
make<TH1F>(
"etheta",
"Efficiency vs. Theta", 20, 0., 3.142);
633 fHephi = dir.
make<TH1F>(
"ephi",
"Efficiency vs. Phi", 10, -3.142, 3.142);
634 fHetheta_xz = dir.
make<TH1F>(
"etheta_xz",
"Efficiency vs. Theta_xz", 40, -3.142, 3.142);
635 fHetheta_yz = dir.
make<TH1F>(
"etheta_yz",
"Efficiency vs. Theta_yz", 40, -3.142, 3.142);
636 fHemom = dir.
make<TH1F>(
"emom",
"Efficiency vs. Momentum", 10, 0., 10.);
637 fHelen = dir.
make<TH1F>(
"elen",
"Efficiency vs. Particle Length",
650 ,
fDump(pset.get<int>(
"Dump"))
651 ,
fMinMCKE(pset.get<double>(
"MinMCKE"))
652 ,
fMinMCLen(pset.get<double>(
"MinMCLen"))
662 <<
"SeedAna configured with the following parameters:\n" 665 <<
" Dump = " <<
fDump <<
"\n" 666 <<
" MinMCKE = " <<
fMinMCKE <<
"\n" 687 std::unique_ptr<mf::LogInfo> pdump;
690 pdump = std::unique_ptr<mf::LogInfo>(
new mf::LogInfo(
"TrackAna"));
706 std::map<const recob::Seed*, int> seedmap;
718 *pdump <<
"MC Tracks\n" 719 <<
" Id pdg x y z dx dy dz p\n" 720 <<
"-------------------------------------------------------------------------------------------\n";
727 imctrk != mctrackh->end(); ++imctrk) {
735 int apdg = std::abs(pdg);
747 double mctime = mctrk.
Start().
T();
756 double plen = length(mctrk, mcdx, mcstart, mcend, mcstartmom, mcendmom);
766 double pstart = mcstartmom.Mag();
767 double pend = mcendmom.Mag();
769 << std::setw(3) << mctrk.
TrackID()
770 << std::setw(6) << mctrk.
PdgCode()
772 << std::fixed << std::setprecision(2)
773 << std::setw(10) << mcdx
775 << std::setw(3) << mctrk.
TrackID()
776 << std::setw(6) << mctrk.
PdgCode()
778 << std::fixed << std::setprecision(2)
779 << std::setw(10) << mcstart[0]
780 << std::setw(10) << mcstart[1]
781 << std::setw(10) << mcstart[2];
784 << std::fixed << std::setprecision(3)
785 << std::setw(10) << mcstartmom[0]/pstart
786 << std::setw(10) << mcstartmom[1]/pstart
787 << std::setw(10) << mcstartmom[2]/pstart;
790 *pdump << std::setw(32) <<
" ";
791 *pdump << std::setw(12) << std::fixed << std::setprecision(3) << pstart;
793 << std::setw(3) << mctrk.
TrackID()
794 << std::setw(6) << mctrk.
PdgCode()
796 << std::fixed << std::setprecision(2)
797 << std::setw(10) << mcend[0]
798 << std::setw(10) << mcend[1]
799 << std::setw(10) << mcend[2];
802 << std::fixed << std::setprecision(3)
803 << std::setw(10) << mcendmom[0]/pend
804 << std::setw(10) << mcendmom[1]/pend
805 << std::setw(10) << mcendmom[2]/pend;
808 *pdump << std::setw(32)<<
" ";
809 *pdump << std::setw(12) << std::fixed << std::setprecision(3) << pend <<
"\n";
815 std::ostringstream ostr;
816 ostr <<
"MC" << (
fIgnoreSign ?
"All" : (pdg > 0 ?
"Pos" :
"Neg")) << std::abs(pdg);
821 double mctheta_xz = std::atan2(mcstartmom.X(), mcstartmom.Z());
822 double mctheta_yz = std::atan2(mcstartmom.Y(), mcstartmom.Z());
824 mchists.fHmcstartx->Fill(mcstart.X());
825 mchists.fHmcstarty->Fill(mcstart.Y());
826 mchists.fHmcstartz->Fill(mcstart.Z());
827 mchists.fHmcendx->Fill(mcend.X());
828 mchists.fHmcendy->Fill(mcend.Y());
829 mchists.fHmcendz->Fill(mcend.Z());
830 mchists.fHmctheta->Fill(mcstartmom.Theta());
831 mchists.fHmcphi->Fill(mcstartmom.Phi());
832 mchists.fHmctheta_xz->Fill(mctheta_xz);
833 mchists.fHmctheta_yz->Fill(mctheta_yz);
834 mchists.fHmcmom->Fill(mcstartmom.Mag());
835 mchists.fHmclen->Fill(plen);
844 int nseed = seedh->size();
845 for(
int i = 0; i < nseed; ++i) {
848 if(seedmap.count(&seed) == 0)
863 double dirmag = dir.Mag();
864 double diryz = std::sqrt(dir.Y()*dir.Y() + dir.Z()*dir.Z());
866 double sinth = dir.X() / dirmag;
867 double costh = diryz / dirmag;
871 sinphi = -dir.Y() / diryz;
872 cosphi = dir.Z() / diryz;
877 rot(0,1) = sinth * sinphi;
879 rot(2,1) = -costh * sinphi;
880 rot(0,2) = -sinth * cosphi;
882 rot(2,2) = costh * cosphi;
886 int itraj = mcmatch(mctrk, seed);
891 TVector3 mcpos = mctrk[itraj].Position().Vect() - pos;
892 TVector3 mcmom = mctrk[itraj].Momentum().Vect();
898 TVector3 mcmoml = rot * mcmom;
899 TVector3 mcposl = rot * mcpos;
903 double costh = mcmoml.Z() / mcmoml.Mag();
905 double u = mcposl.X();
906 double v = mcposl.Y();
907 double w = mcposl.Z();
909 double pu = mcmoml.X();
910 double pv = mcmoml.Y();
911 double pw = mcmoml.Z();
913 double dudw = pu / pw;
914 double dvdw = pv / pw;
916 double u0 = u - w * dudw;
917 double v0 = v - w * dvdw;
918 double uv0 = std::sqrt(u0*u0 + v0*v0);
922 mchists.fHduvcosth->Fill(costh, uv0);
927 mchists.fHmcdudw->Fill(dudw);
928 mchists.fHmcdvdw->Fill(dvdw);
930 mchists.fHcosth->Fill(costh);
935 mchists.fHmcu->Fill(u0);
936 mchists.fHmcv->Fill(v0);
937 mchists.fHmcw->Fill(w);
949 mchists.fHmstartx->Fill(mcstart.X());
950 mchists.fHmstarty->Fill(mcstart.Y());
951 mchists.fHmstartz->Fill(mcstart.Z());
952 mchists.fHmendx->Fill(mcend.X());
953 mchists.fHmendy->Fill(mcend.Y());
954 mchists.fHmendz->Fill(mcend.Z());
955 mchists.fHmtheta->Fill(mcstartmom.Theta());
956 mchists.fHmphi->Fill(mcstartmom.Phi());
957 mchists.fHmtheta_xz->Fill(mctheta_xz);
958 mchists.fHmtheta_yz->Fill(mctheta_yz);
959 mchists.fHmmom->Fill(mcstartmom.Mag());
960 mchists.fHmlen->Fill(plen);
970 mchists.fHgstartx->Fill(mcstart.X());
971 mchists.fHgstarty->Fill(mcstart.Y());
972 mchists.fHgstartz->Fill(mcstart.Z());
973 mchists.fHgendx->Fill(mcend.X());
974 mchists.fHgendy->Fill(mcend.Y());
975 mchists.fHgendz->Fill(mcend.Z());
976 mchists.fHgtheta->Fill(mcstartmom.Theta());
977 mchists.fHgphi->Fill(mcstartmom.Phi());
978 mchists.fHgtheta_xz->Fill(mctheta_xz);
979 mchists.fHgtheta_yz->Fill(mctheta_yz);
980 mchists.fHgmom->Fill(mcstartmom.Mag());
981 mchists.fHglen->Fill(plen);
996 int nseed = seedh->size();
998 if(nseed > 0 && pdump != 0) {
999 *pdump <<
"\nReconstructed Seeds\n" 1000 <<
" MCid x y z dx dy dz p\n" 1001 <<
"-------------------------------------------------------------------------------------------\n";
1004 for(
int i = 0; i < nseed; ++i) {
1015 double mdir = dir.Mag();
1020 double dpos = bdist(pos);
1021 double theta_xz = std::atan2(dir.X(), dir.Z());
1022 double theta_yz = std::atan2(dir.Y(), dir.Z());
1027 int mcid = seedmap[&
seed];
1028 *pdump << std::setw(15) << mcid
1030 << std::fixed << std::setprecision(2)
1031 << std::setw(10) << pos[0]
1032 << std::setw(10) << pos[1]
1033 << std::setw(10) << pos[2]
1035 << std::fixed << std::setprecision(3)
1036 << std::setw(10) << dir[0]
1037 << std::setw(10) << dir[1]
1038 << std::setw(10) << dir[2]
1048 rhists.
fHx->Fill(pos.X());
1049 rhists.
fHy->Fill(pos.Y());
1050 rhists.
fHz->Fill(pos.Z());
1051 rhists.
fHdist->Fill(dpos);
1052 rhists.
fHtheta->Fill(dir.Theta());
1053 rhists.
fHphi->Fill(dir.Phi());
1068 <<
"SeedAna statistics:\n" 1075 const MCHists& mchists = i->second;
1093 const MCHists& mchists = i->second;
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
TFileDirectory mkdir(std::string const &dir, std::string const &descr="")
virtual double ConvertXToTicks(double X, int p, int t, int c) const =0
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)
geo::Length_t DetLength(geo::TPCID const &tpcid) const
Returns the length of the active volume of the specified TPC.
EDAnalyzer(Table< Config > const &config)
Class def header for mctrack data container.
std::map< int, RecoHists > fRecoHistMap
const TLorentzVector & Momentum() const
SeedAna(fhicl::ParameterSet const &pset)
T * make(ARGS...args) const
std::map< int, MCHists > fMCHistMap
void analyze(const art::Event &evt)
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
const MCStep & Start() const
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
unsigned int TrackID() const
void GetDirection(double *Dir, double *Err) const
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception