700 std::unique_ptr<mf::LogInfo> pdump;
703 pdump = std::make_unique<mf::LogInfo>(
"TrackAna");
715 std::vector<std::pair<const sim::MCTrack*, int>> selected_mctracks;
721 if (mc && mctrackh.
isValid()) {
723 selected_mctracks.reserve(mctrackh->size());
728 *pdump <<
"MC Tracks\n" 729 <<
" Id pdg x y z dx dy dz " 731 <<
"--------------------------------------------------------------------------------" 740 imctrk != mctrackh->end();
763 double mctime = mctrk.
Start().
T();
764 double mcdx = mctime * 1.e-3 * detProp.DriftVelocity();
772 double plen = length(detProp, mctrk, mcdx, mcstart, mcend, mcstartmom, mcendmom);
781 selected_mctracks.push_back(std::make_pair(&mctrk, -1));
786 double pstart = mcstartmom.Mag();
787 double pend = mcendmom.Mag();
788 *pdump <<
"\nOffset" << std::setw(3) << mctrk.
TrackID() << std::setw(6)
789 << mctrk.
PdgCode() <<
" " << std::fixed << std::setprecision(2)
790 << std::setw(10) << mcdx <<
"\nStart " << std::setw(3) << mctrk.
TrackID()
791 << std::setw(6) << mctrk.
PdgCode() <<
" " << std::fixed
792 << std::setprecision(2) << std::setw(10) << mcstart.X() << std::setw(10)
793 << mcstart.Y() << std::setw(10) << mcstart.Z();
795 *pdump <<
" " << std::fixed << std::setprecision(3) << std::setw(10)
796 << mcstartmom[0] / pstart << std::setw(10) << mcstartmom[1] / pstart
797 << std::setw(10) << mcstartmom[2] / pstart;
800 *pdump << std::setw(32) <<
" ";
801 *pdump << std::setw(12) << std::fixed << std::setprecision(3) << pstart;
802 *pdump <<
"\nEnd " << std::setw(3) << mctrk.
TrackID() << std::setw(6)
803 << mctrk.
PdgCode() <<
" " << std::fixed << std::setprecision(2)
804 << std::setw(10) << mcend.X() << std::setw(10) << mcend.Y() << std::setw(10)
807 *pdump <<
" " << std::fixed << std::setprecision(3) << std::setw(10)
808 << mcendmom[0] / pend << std::setw(10) << mcendmom[1] / pend
809 << std::setw(10) << mcendmom[2] / pend;
812 *pdump << std::setw(32) <<
" ";
813 *pdump << std::setw(12) << std::fixed << std::setprecision(3) << pend
814 <<
"\nLength: " << plen <<
"\n";
820 std::ostringstream ostr;
826 double mctheta_xz = std::atan2(mcstartmom.X(), mcstartmom.Z());
827 double mctheta_yz = std::atan2(mcstartmom.Y(), mcstartmom.Z());
828 double mcmom = mcstartmom.Mag();
830 double mcke = mcmom * mcmom / (std::hypot(mcmom, mcmass) + mcmass);
832 mchists.fHmcstartx->Fill(mcstart.X());
833 mchists.fHmcstarty->Fill(mcstart.Y());
834 mchists.fHmcstartz->Fill(mcstart.Z());
835 mchists.fHmcendx->Fill(mcend.X());
836 mchists.fHmcendy->Fill(mcend.Y());
837 mchists.fHmcendz->Fill(mcend.Z());
838 mchists.fHmctheta->Fill(mcstartmom.Theta());
839 mchists.fHmcphi->Fill(mcstartmom.Phi());
840 mchists.fHmctheta_xz->Fill(mctheta_xz);
841 mchists.fHmctheta_yz->Fill(mctheta_yz);
842 mchists.fHmcmom->Fill(mcmom);
843 mchists.fHmcmoml->Fill(mcmom);
844 mchists.fHmcke->Fill(mcke);
845 mchists.fHmckel->Fill(mcke);
846 mchists.fHmclen->Fill(plen);
847 mchists.fHmclens->Fill(plen);
865 std::vector<art::Ptr<recob::Hit>> allhits;
867 allhits.reserve(hith->size());
868 for (
unsigned int i = 0; i < hith->size(); ++i) {
869 allhits.emplace_back(hith, i);
882 mf::LogDebug(
"TrackAna") <<
"TrackAna read " << trackvh->size()
883 <<
" vectors of Stitched PtrVectorsof tracks.";
890 *pdump <<
"\nReconstructed Tracks\n" 891 <<
" Id MCid x y z dx dy dz " 893 <<
"--------------------------------------------------------------------------------" 899 int ntrack = trackh->size();
900 for (
int i = 0; i < ntrack; ++i) {
906 std::vector<art::Ptr<recob::Hit>> trackhits;
907 tkhit_find.get(i, trackhits);
917 TVector3 pos = track.
Vertex<TVector3>();
919 TVector3
end = track.
End<TVector3>();
923 double dpos = bdist(pos);
924 double dend = bdist(end);
925 double tlen = length(track);
926 double theta_xz = std::atan2(dir.X(), dir.Z());
927 double theta_yz = std::atan2(dir.Y(), dir.Z());
932 rhists.fHstartx->Fill(pos.X());
933 rhists.fHstarty->Fill(pos.Y());
934 rhists.fHstartz->Fill(pos.Z());
935 rhists.fHstartd->Fill(dpos);
936 rhists.fHendx->Fill(end.X());
937 rhists.fHendy->Fill(end.Y());
938 rhists.fHendz->Fill(end.Z());
939 rhists.fHendd->Fill(dend);
940 rhists.fHtheta->Fill(dir.Theta());
941 rhists.fHphi->Fill(dir.Phi());
942 rhists.fHtheta_xz->Fill(theta_xz);
943 rhists.fHtheta_yz->Fill(theta_yz);
947 rhists.fHmom->Fill(mom);
948 rhists.fHmoml->Fill(mom);
949 rhists.fHlen->Fill(tlen);
950 rhists.fHlens->Fill(tlen);
958 for (
int swap = 0;
swap < 2; ++
swap) {
968 int start_point = (
swap == 0 ? 0 : ntraj - 1);
974 rot(1, 0) = -rot(1, 0);
975 rot(2, 0) = -rot(2, 0);
976 rot(1, 1) = -rot(1, 1);
977 rot(2, 1) = -rot(2, 1);
978 rot(1, 2) = -rot(1, 2);
979 rot(2, 2) = -rot(2, 2);
981 pos = track.
End<TVector3>();
983 end = track.
Vertex<TVector3>();
989 theta_xz = std::atan2(dir.X(), dir.Z());
990 theta_yz = std::atan2(dir.Y(), dir.Z());
1001 for (
unsigned int imc = 0; imc < selected_mctracks.size(); ++imc) {
1002 const sim::MCTrack& mctrk = *selected_mctracks[imc].first;
1007 throw cet::exception(
"TrackAna") <<
"no particle with ID=" << pdg <<
"\n";
1008 const MCHists& mchists = iMCHistMap->second;
1012 double mctime = mctrk.
Start().
T();
1013 double mcdx = mctime * 1.e-3 * detProp.DriftVelocity();
1020 TVector3 mcstartmom;
1022 double plen = length(detProp, mctrk, mcdx, mcstart, mcend, mcstartmom, mcendmom);
1026 TVector3 mcpos{mcstart.X() - pos[0], mcstart.Y() - pos[1], mcstart.Z() - pos[2]};
1031 TVector3 mcmoml = rot * mcstartmom;
1032 TVector3 mcposl = rot * mcpos;
1034 double colinearity = mcmoml.Z() / mcmoml.Mag();
1036 double u = mcposl.X();
1037 double v = mcposl.Y();
1038 double w = mcposl.Z();
1040 double pu = mcmoml.X();
1041 double pv = mcmoml.Y();
1042 double pw = mcmoml.Z();
1044 double dudw = pu / pw;
1045 double dvdw = pv / pw;
1047 double u0 = u - w * dudw;
1048 double v0 = v - w * dvdw;
1049 double uv0 = std::hypot(u0, v0);
1051 mchists.fHduvcosth->Fill(colinearity, uv0);
1057 mchists.fHmcdudw->Fill(dudw);
1058 mchists.fHmcdvdw->Fill(dvdw);
1059 mchists.fHdudwpull->Fill(dudw / std::sqrt(cov(2, 2)));
1060 mchists.fHdvdwpull->Fill(dvdw / std::sqrt(cov(3, 3)));
1062 mchists.fHcosth->Fill(colinearity);
1067 mchists.fHmcu->Fill(u0);
1068 mchists.fHmcv->Fill(v0);
1069 mchists.fHmcw->Fill(w);
1070 mchists.fHupull->Fill(u0 / std::sqrt(cov(0, 0)));
1071 mchists.fHvpull->Fill(v0 / std::sqrt(cov(1, 1)));
1077 double mctheta_xz = std::atan2(mcstartmom.X(), mcstartmom.Z());
1078 double mctheta_yz = std::atan2(mcstartmom.Y(), mcstartmom.Z());
1079 double mcmom = mcstartmom.Mag();
1081 double mcke = mcmom * mcmom / (std::hypot(mcmom, mcmass) + mcmass);
1083 mchists.fHstartdx->Fill(pos.X() - mcstart.X());
1084 mchists.fHstartdy->Fill(pos.Y() - mcstart.Y());
1085 mchists.fHstartdz->Fill(pos.Z() - mcstart.Z());
1086 mchists.fHenddx->Fill(end.X() - mcend.X());
1087 mchists.fHenddy->Fill(end.Y() - mcend.Y());
1088 mchists.fHenddz->Fill(end.Z() - mcend.Z());
1089 mchists.fHlvsl->Fill(plen, tlen);
1090 mchists.fHdl->Fill(tlen - plen);
1091 mchists.fHpvsp->Fill(mcmom, mom);
1092 double dp = mom - mcmom;
1093 mchists.fHdp->Fill(dp);
1094 mchists.fHppull->Fill(dp / std::sqrt(cov(4, 4)));
1096 mchists.fHpvspc->Fill(mcmom, mom);
1097 mchists.fHdpc->Fill(dp);
1098 mchists.fHppullc->Fill(dp / std::sqrt(cov(4, 4)));
1112 std::set<int> tkidset;
1113 tkidset.insert(mcid);
1115 clockData, tkidset, trackhits, allhits,
geo::k3D);
1117 mchists.fHHitEff->Fill(hiteff);
1118 mchists.fHHitPurity->Fill(hitpurity);
1122 mchists.fHgstartx->Fill(mcstart.X());
1123 mchists.fHgstarty->Fill(mcstart.Y());
1124 mchists.fHgstartz->Fill(mcstart.Z());
1125 mchists.fHgendx->Fill(mcend.X());
1126 mchists.fHgendy->Fill(mcend.Y());
1127 mchists.fHgendz->Fill(mcend.Z());
1128 mchists.fHgtheta->Fill(mcstartmom.Theta());
1129 mchists.fHgphi->Fill(mcstartmom.Phi());
1130 mchists.fHgtheta_xz->Fill(mctheta_xz);
1131 mchists.fHgtheta_yz->Fill(mctheta_yz);
1132 mchists.fHgmom->Fill(mcmom);
1133 mchists.fHgmoml->Fill(mcmom);
1134 mchists.fHgke->Fill(mcke);
1135 mchists.fHgkel->Fill(mcke);
1136 mchists.fHglen->Fill(plen);
1137 mchists.fHglens->Fill(plen);
1140 selected_mctracks[imc].second = i;
1144 float KE = ptkl->
E() - ptkl->
Mass();
1145 std::string KEUnits =
" GeV";
1152 << evt.
run() <<
"." << evt.
event() <<
" Match MCTkID " << std::setw(6)
1153 << mctrk.
TrackID() <<
" Origin " << mctrk.
Origin() <<
" PDG" << std::setw(5)
1154 << mctrk.
PdgCode() <<
" KE" << std::setw(4) << (int)KE << KEUnits
1155 <<
" RecoTrkID " << track.
ID() <<
" hitEff " << std::setprecision(2)
1156 << hiteff <<
" hitPur " << hitpurity;
1158 for (
unsigned short ipl = 0; ipl < wireReadoutGeom.Nplanes(); ++ipl) {
1160 auto const& plane = wireReadoutGeom.
Plane(planeID);
1161 auto const sWire = plane.NearestWireID(mcstart).Wire;
1162 auto const sTick = detProp.ConvertXToTicks(mcstart.X(), planeID);
1163 auto const eWire = plane.NearestWireID(mcend).Wire;
1164 auto const eTick = detProp.ConvertXToTicks(mcend.X(), planeID);
1166 <<
" Wire:Tick in Pln " << ipl <<
" W:T " << sWire <<
":" << sTick
1167 <<
" - " << eWire <<
":" << eTick;
1179 TVector3 pos = track.
Vertex<TVector3>();
1181 TVector3 end = track.
End<TVector3>();
1187 *pdump <<
"\nOffset" << std::setw(3) << track.
ID() << std::setw(6) << mcid <<
" " 1188 << std::fixed << std::setprecision(2) << std::setw(10) << trackdx <<
"\nStart " 1189 << std::setw(3) << track.
ID() << std::setw(6) << mcid <<
" " << std::fixed
1190 << std::setprecision(2) << std::setw(10) << pos[0] << std::setw(10) << pos[1]
1191 << std::setw(10) << pos[2];
1193 *pdump <<
" " << std::fixed << std::setprecision(3) << std::setw(10) << dir[0]
1194 << std::setw(10) << dir[1] << std::setw(10) << dir[2];
1197 *pdump << std::setw(32) <<
" ";
1198 *pdump << std::setw(12) << std::fixed << std::setprecision(3) << pstart;
1199 *pdump <<
"\nEnd " << std::setw(3) << track.
ID() << std::setw(6) << mcid <<
" " 1200 << std::fixed << std::setprecision(2) << std::setw(10) << end[0] << std::setw(10)
1201 << end[1] << std::setw(10) << end[2];
1203 *pdump <<
" " << std::fixed << std::setprecision(3) << std::setw(10) << enddir[0]
1204 << std::setw(10) << enddir[1] << std::setw(10) << enddir[2];
1207 *pdump << std::setw(32) <<
" ";
1208 *pdump << std::setw(12) << std::fixed << std::setprecision(3) << pend
1209 <<
"\nLength: " << tlen <<
"\n";
1217 for (
unsigned int imc = 0; imc < selected_mctracks.size(); ++imc) {
1218 if (selected_mctracks[imc].
second >= 0)
continue;
1219 const sim::MCTrack& mctrk = *selected_mctracks[imc].first;
1221 float KE = ptkl->
E() - ptkl->
Mass();
1222 std::string KEUnits =
" GeV";
1230 TVector3 mcstartmom, mcendmom;
1231 double mcdx = mctrk.
Start().
T() * 1.e-3 * detProp.DriftVelocity();
1232 double plen = length(detProp, mctrk, mcdx, mcstart, mcend, mcstartmom, mcendmom);
1234 << evt.
run() <<
"." << evt.
event() <<
" NoMat MCTkID " << std::setw(6) << mctrk.
TrackID()
1235 <<
" Origin " << mctrk.
Origin() <<
" PDG" << std::setw(5) << mctrk.
PdgCode() <<
" KE" 1236 << std::setw(4) << (int)KE << KEUnits <<
" Length " << std::fixed << std::setprecision(1)
1240 for (
unsigned short ipl = 0; ipl < wireReadoutGeom.Nplanes(); ++ipl) {
1242 auto const& plane = wireReadoutGeom.
Plane(planeID);
1243 auto const sWire = plane.NearestWireID(mcstart).Wire;
1244 auto const sTick = detProp.ConvertXToTicks(mcstart.X(), planeID);
1245 auto const eWire = plane.NearestWireID(mcend).Wire;
1246 auto const eTick = detProp.ConvertXToTicks(mcend.X(), planeID);
1247 mf::LogVerbatim(
"TrackAna") <<
" Wire:Tick in Pln " << ipl <<
" W:T " << sWire <<
":" 1248 << sTick <<
" - " << eWire <<
":" << eTick;
double E(const int i=0) const
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
simb::Origin_t Origin() const
double EndMomentum() const
double VertexMomentum() const
const simb::MCParticle * TrackIdToParticle_P(int id) const
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
The data type to uniquely identify a Plane.
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
constexpr auto abs(T v)
Returns the absolute value of the argument.
Vector_t VertexDirection() const
Access to track direction at different points.
const SMatrixSym55 & VertexCovariance() const
Access to covariance matrices.
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
std::string fStitchModuleLabel
std::map< int, MCHists > fMCHistMap
3-dimensional objects, potentially hits, clusters, prongs, etc.
Rotation_t GlobalToLocalRotationAtPoint(size_t p) const
bool isValid() const noexcept
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
double HitCollectionPurity(detinfo::DetectorClocksData const &clockData, std::set< int > const &trackIds, std::vector< art::Ptr< recob::Hit >> const &hits) const
void anaStitch(const art::Event &evt, detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp)
Point_t const & Vertex() const
Access to track position at different points.
const SMatrixSym55 & EndCovariance() const
Access to covariance matrices.
std::string fMCTrackModuleLabel
EventNumber_t event() const
PlaneID_t Plane
Index of the plane within its TPC.
const TLorentzVector & Momentum() const
simb::Origin_t fOriginValue
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
Vector_t EndDirection() const
Access to track direction at different points.
std::map< int, RecoHists > fRecoHistMap
void swap(lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &a, lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &b)
Point_t const & End() const
Access to track position at different points.
const MCStep & Start() const
std::string fTrackModuleLabel
unsigned int TrackID() const
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