546 std::unique_ptr<std::vector<recob::Track>> tcol(
new std::vector<recob::Track>);
547 std::unique_ptr<art::Assns<recob::Track, recob::SpacePoint>> tspassn(
549 std::unique_ptr<art::Assns<recob::Track, recob::Hit>> thassn(
552 unsigned int tcnt = 0;
574 for (
unsigned int ii = 0; ii < mctruthListHandle->size(); ++ii) {
580 std::vector<art::PtrVector<recob::SpacePoint>> spptIn(spptListHandle->begin(),
581 spptListHandle->end());
604 for (
unsigned int ii = 0; ii < mclist.
size(); ++ii) {
606 for (
int jj = 0; jj < mc->NParticles(); ++jj) {
611 <<
"FROM MC TRUTH, the particle's pdg code is: " <<
part.PdgCode()
612 <<
" with energy = " <<
part.E() <<
", with energy = " <<
part.E()
615 <<
"\n (both in Global (not volTPC) coords)";
628 <<
" repMC, covMC are ... \n" 633 TParticlePDG*
part = TDatabasePDG::Instance()->GetParticle(
fPdg);
634 Double_t mass = part->Mass();
637 while (sppt != spptIn.end()) {
646 unsigned int nTailPoints = 0;
647 if (spacepoints.
size() < 5) {
654 <<
"\n\t found " << spacepoints.
size()
655 <<
" 3D spacepoint(s) for this element of std::vector<art:PtrVector> spacepoints. \n";
661 TPrincipal* principal =
new TPrincipal(3,
"ND");
669 std::sort(spacepointss.begin(), spacepointss.end(),
sp_sort_3dz);
670 if (!
fSortDim.compare(
"y")) std::sort(spacepointss.begin(), spacepointss.end(),
sp_sort_3dy);
671 if (!
fSortDim.compare(
"x")) std::sort(spacepointss.begin(), spacepointss.end(),
sp_sort_3dx);
673 for (
unsigned int point = 0; point < spacepointss.size(); ++point) {
674 if (point < (spacepointss.size() - nTailPoints)) {
675 principal->AddRow(spacepointss[point]->XYZ());
678 principal->MakePrincipals();
680 const TVectorD* evals = principal->GetEigenValues();
681 const TMatrixD* evecs = principal->GetEigenVectors();
682 const TVectorD* means = principal->GetMeanValues();
683 const TVectorD* sigmas = principal->GetSigmas();
685 Double_t
tmp[3], tmp2[3];
686 principal->X2P((Double_t*)(means->GetMatrixArray()), tmp);
687 principal->X2P((Double_t*)(sigmas->GetMatrixArray()), tmp2);
688 for (
unsigned int ii = 0; ii < 3; ++ii) {
691 fPCevals[ii] = (Float_t)(evals->GetMatrixArray())[ii];
696 evecs->ExtractRow(ii, 0, w);
701 Double_t tmp3[3], tmp4[3], tmp5[3];
702 principal->X2P((Double_t*)
fPC1, tmp3);
703 principal->X2P((Double_t*)
fPC2, tmp4);
704 principal->X2P((Double_t*)
fPC3, tmp5);
708 fMomStart[0] = spacepointss[spacepointss.size() - 1]->XYZ()[0] - spacepointss[0]->XYZ()[0];
709 fMomStart[1] = spacepointss[spacepointss.size() - 1]->XYZ()[1] - spacepointss[0]->XYZ()[1];
710 fMomStart[2] = spacepointss[spacepointss.size() - 1]->XYZ()[2] - spacepointss[0]->XYZ()[2];
714 TVector3 mom(dEdx *
fMomStart[0], dEdx * fMomStart[1], dEdx * fMomStart[2]);
715 double pmag2 = pow(mom.Mag() + mass, 2. - mass * mass);
716 mom.SetMag(std::sqrt(pmag2));
718 mom.SetMag(1.0 * mom.Mag());
722 bool uncontained(
false);
724 double epsMag(0.001);
728 if (spacepointss[spacepointss.size() - 1]->XYZ()[0] > (2. * geom->
DetHalfWidth() -
close) ||
729 spacepointss[spacepointss.size() - 1]->XYZ()[0] <
close ||
731 spacepointss[0]->XYZ()[0] <
close ||
732 spacepointss[spacepointss.size() - 1]->XYZ()[1] > (1. * geom->
DetHalfHeight() -
close) ||
733 (spacepointss[spacepointss.size() - 1]->XYZ()[1] < -1. * geom->
DetHalfHeight() +
close) ||
736 spacepointss[spacepointss.size() - 1]->XYZ()[2] > (geom->
DetLength() -
close) ||
737 spacepointss[spacepointss.size() - 1]->XYZ()[2] <
close ||
739 spacepointss[0]->XYZ()[2] <
close)
748 mom.SetMag(2.0 * mom.Mag());
749 MF_LOG_DEBUG(
"Track3DKalmanSPS_GenFit") <<
"Uncontained track ... ";
755 <<
"Contained track ... Run " << evt.
run() <<
" Event " << evt.
id().
event();
762 fcont = (int)(!uncontained);
765 unsigned short rePass = rePass0;
767 unsigned short tcnt1(0);
768 while (rePass <= maxPass) {
771 TVector3 momErrFit(momM[0] / 3.0, momM[1] / 3.0,
785 fitTrack.setPDG(
fPdg);
791 std::vector<unsigned int> spptSurvivedIndex;
792 std::vector<unsigned int> spptSkippedIndex;
793 unsigned int ppoint(0);
794 for (
unsigned int point = 0; point < spacepointss.size(); ++point) {
800 principal->X2P((Double_t*)(spacepointss[point]->XYZ()), tmp);
801 sep = std::sqrt(tmp[1] * tmp[1] /
fPCevals[1] + tmp[2] * tmp[2] /
fPCevals[2]);
802 if ((
std::abs(sep) >
fPerpLim) && (point < (spacepointss.size() - nTailPoints)) &&
804 spptSkippedIndex.push_back(point);
809 TVector3 one(spacepointss[point]->XYZ());
810 TVector3 two(spacepointss[ppoint]->XYZ());
811 if (rePass == 2 && uncontained) {
814 fErrScaleMHere = 0.1;
820 else if (rePass == 2 && !uncontained) {}
822 ((one - two).Mag() < epsMag ||
823 ((one - two).Mag() > 8.0 && rePass == 1) ||
824 std::abs(spacepointss[point]->XYZ()[2] - spacepointss[ppoint]->XYZ()[2]) < epsZ ||
825 std::abs(spacepointss[point]->XYZ()[0] - spacepointss[ppoint]->XYZ()[0]) > epsX)) {
826 spptSkippedIndex.push_back(point);
831 point % fDecimateHere &&
840 TVector3 spt3 = (TVector3)(spacepointss[point]->XYZ());
841 std::vector<double> err3;
842 err3.push_back(spacepointss[point]->ErrXYZ()[0]);
843 err3.push_back(spacepointss[point]->ErrXYZ()[2]);
844 err3.push_back(spacepointss[point]->ErrXYZ()[4]);
845 err3.push_back(spacepointss[point]->ErrXYZ()[5]);
863 fth[
fptsNo] = (pointer.Unit()).Angle(pointerPrev.Unit());
874 <<
"ihit xyz..." << spt3[0] <<
"," << spt3[1] <<
"," << spt3[2];
879 spptSurvivedIndex.push_back(point);
887 <<
"Bailing cuz only " <<
fptsNo <<
" spacepoints.";
891 MF_LOG_DEBUG(
"Track3DKalmanSPS_GenFit") <<
"Fitting on " <<
fptsNo <<
" spacepoints.";
904 bool skipFill =
false;
905 std::vector<TMatrixT<double>> hitMeasCov;
906 std::vector<TMatrixT<double>> hitUpdate;
907 std::vector<TMatrixT<double>> hitCov;
908 std::vector<TMatrixT<double>> hitCov7x7;
909 std::vector<TMatrixT<double>> hitState;
910 std::vector<double> hitChi2;
911 std::vector<TVector3> hitPlaneXYZ;
912 std::vector<TVector3> hitPlaneUxUyUz;
913 std::vector<TVector3> hitPlaneU;
914 std::vector<TVector3> hitPlaneV;
921 <<
"just caught a cet::exception: " << e.what()
922 <<
"\nExceptions won't be further handled; skip filling big chunks of the TTree.";
930 std::ostringstream dbgmsg;
931 dbgmsg <<
"Original plane:";
932 planeG.Print(dbgmsg);
934 dbgmsg <<
"Current (fit) reference Plane:";
937 dbgmsg <<
"Last reference Plane:";
941 dbgmsg <<
" => original hit plane (not surprisingly) not current reference Plane!";
943 MF_LOG_DEBUG(
"Track3DKalmanSPS_GenFit") << dbgmsg.str();
946 hitMeasCov = fitTrack.getHitMeasuredCov();
947 hitUpdate = fitTrack.getHitUpdate();
948 hitCov = fitTrack.getHitCov();
949 hitCov7x7 = fitTrack.getHitCov7x7();
950 hitState = fitTrack.getHitState();
951 hitChi2 = fitTrack.getHitChi2();
952 hitPlaneXYZ = fitTrack.getHitPlaneXYZ();
953 hitPlaneUxUyUz = fitTrack.getHitPlaneUxUyUz();
954 hitPlaneU = fitTrack.getHitPlaneU();
955 hitPlaneV = fitTrack.getHitPlaneV();
956 unsigned int totHits = hitState.size();
959 unsigned int jhit = 0;
960 for (
unsigned int ihit = totHits - 2 * totHits / (2 *
fNumIt);
961 ihit < (totHits - totHits / (2 *
fNumIt));
964 feth[jhit] = (Float_t)(hitMeasCov.at(ihit)[0][0]);
965 fedudw[jhit] = (Float_t)(hitMeasCov.at(ihit)[1][1]);
966 fedvdw[jhit] = (Float_t)(hitMeasCov.at(ihit)[2][2]);
967 feu[jhit] = (Float_t)(hitMeasCov.at(ihit)[3][3]);
968 fev[jhit] = (Float_t)(hitMeasCov.at(ihit)[4][4]);
969 fupdate[jhit] = (Float_t)(hitUpdate.at(ihit)[0][0]);
970 fchi2hit[jhit] = (Float_t)(hitChi2.at(ihit));
980 for (
unsigned int ii = 0; ii < 5; ii++) {
981 stREC->ExtractRow(ii, 0, dum);
983 covREC->ExtractRow(ii, 0, dum2);
984 for (
unsigned int jj = 0; jj < 5; jj++) {
985 fCov0[ii * 5 + jj] = dum2[jj];
993 nfail = fitTrack.getFailedHits();
995 ispptvec = 1 + std::distance(spptB, sppt);
1000 <<
"Track3DKalmanSPS about to do tree->Fill(). Chi2/ndf is " <<
chi2 /
ndf <<
".";
1001 fpMCMom[3] = MCMomentum.Mag();
1002 for (
int ii = 0; ii < 3; ++ii) {
1005 fpREC[ii] = hitPlaneUxUyUz.at(totHits - 2 * totHits / (2 *
fNumIt))[ii];
1006 fpRECL[ii] = hitPlaneUxUyUz.at(totHits - totHits / (2 *
fNumIt) - 1)[ii];
1010 nspptvec = (
unsigned int)spptListHandle->size();
1013 std::vector<std::vector<double>> dQdx;
1015 std::vector<TMatrixT<double>> hitCovLFP;
1016 std::vector<TVector3> hitPlaneXYZLFP;
1017 std::vector<TVector3> hitPlaneUxUyUzLFP;
1018 std::vector<TVector3> hitPlanePxPyPzLFP;
1019 std::vector<TVector3> hitPlaneULFP;
1020 std::vector<TVector3> hitPlaneVLFP;
1021 std::vector<double> pLFP;
1022 std::vector<TMatrixT<double>> c7x7LFP;
1025 for (
unsigned int ii = 0; ii < totHits / (2 *
fNumIt); ii++) {
1026 pLFP.push_back(1. / hitState.at(totHits - 2 * totHits / (2 *
fNumIt) + ii)[0][0]);
1028 c7x7LFP.push_back(hitCov7x7.at(totHits - 2 * totHits / (2 *
fNumIt) + ii));
1029 hitCovLFP.push_back(hitCov.at(totHits - 2 * totHits / (2 *
fNumIt) + ii));
1030 hitPlaneXYZLFP.push_back(hitPlaneXYZ.at(totHits - 2 * totHits / (2 *
fNumIt) + ii));
1031 hitPlaneUxUyUzLFP.push_back(
1032 hitPlaneUxUyUz.at(totHits - 2 * totHits / (2 *
fNumIt) + ii));
1033 hitPlanePxPyPzLFP.push_back(hitPlaneUxUyUzLFP.back() * pLFP.back());
1034 hitPlaneULFP.push_back(hitPlaneU.at(totHits - 2 * totHits / (2 *
fNumIt) + ii));
1035 hitPlaneVLFP.push_back(hitPlaneV.at(totHits - 2 * totHits / (2 *
fNumIt) + ii));
1041 rotationCov(hitCovLFP.back(), hitPlaneULFP.back(), hitPlaneVLFP.back());
1043 dQdxCalc(hitAssns, spacepointss, hitPlaneUxUyUzLFP.back(), hitPlaneXYZLFP.back()));
1044 fdQdx[ii] = dQdx.back().back();
1054 for (
unsigned int i = 0; i < 5; i++) {
1055 for (
unsigned int j = i; j < 5; j++) {
1056 covVtx(i, j) = hitCovLFP.front()(i, j);
1057 covEnd(i, j) = hitCovLFP.back()(i, j);
1071 if (rePass == 1) tcnt1++;
1072 if (rePass != 1 && tcnt1) tcol->pop_back();
1073 tcol->push_back(the3DTrack);
1076 for (
unsigned int ii = 0; ii < spacepointss.size(); ++ii) {
1077 hits.
insert(hits.
end(), hitAssns.at(ii).begin(), hitAssns.at(ii).end());
1088 for (
unsigned int ind = 0; ind < spptSurvivedIndex.size(); ++ind) {
1097 spacepointss.
begin() + spptSurvivedIndex[ind];
1104 for (
unsigned int ind = 0; ind < spptSkippedIndex.size(); ++ind) {
1106 spacepointss.
begin() + spptSkippedIndex[ind];
1110 std::stable_sort(spacepointss.begin(), spacepointss.end());
1111 std::stable_sort(spacepointssExcise.
begin(), spacepointssExcise.
end());
1112 std::set_union(spacepointssExcise.
begin(),
1113 spacepointssExcise.
end(),
1114 spacepointssExcise.
begin(),
1115 spacepointssExcise.
end(),
1116 spacepointssExcise.
begin());
1119 std::set_difference(spacepointss.begin(),
1121 spacepointssExcise.
begin(),
1122 spacepointssExcise.
end(),
1123 spacepointss.begin());
1124 spacepointss.erase(diffSpptIt, spacepointss.end());
1135 if (uncontained) kick = 0.5;
1136 for (
int ii = 0; ii < 3; ++ii) {
1137 mom[ii] = momM[ii] * kick;
1140 else if (uncontained) {
1141 double unstick(1.0);
1143 for (
int ii = 0; ii < 3; ++ii) {
1144 mom[ii] = momM[ii] * unstick;
1148 for (
int ii = 0; ii < 3; ++ii) {
1149 mom[ii] = 1.1 * momM[ii];
1161 evt.
put(std::move(tcol));
1163 evt.
put(std::move(tspassn));
1166 evt.
put(std::move(thassn));
TMatrixT< Double_t > * stREC
unsigned int getNDF() const
std::vector< double > fMomErr
void setMomLow(Double_t f)
std::string GetLArTPCVolumeName(TPCID const &tpcid=tpc_zero) const
Return the name of specified LAr TPC volume.
void setMaxUpdate(Double_t f)
TMatrixT< Double_t > * stMCT
static bool sp_sort_3dz(const art::Ptr< recob::SpacePoint > &h1, const art::Ptr< recob::SpacePoint > &h2)
typename data_t::iterator iterator
const GFDetPlane & getReferencePlane() const
GFDetPlane getLastPlane() const
void rotationCov(TMatrixT< Double_t > &cov, const TVector3 &u, const TVector3 &v)
std::vector< Vector_t > convertCollToVector(std::vector< Vector > const &coll)
Length_t DetHalfWidth(TPCID const &tpcid=tpc_zero) const
Returns the half width of the active volume of the specified TPC.
genf::GFAbsTrackRep * rep
void setMomHigh(Double_t f)
TrackTrajectory::Flags_t Flags_t
std::string fGenieGenModuleLabel
constexpr auto abs(T v)
Returns the absolute value of the argument.
#define MF_LOG_ERROR(category)
ROOT::Math::SMatrix< Double32_t, 5, 5, ROOT::Math::MatRepSym< Double32_t, 5 >> SMatrixSym55
std::vector< double > fPosErr
void Print(std::ostream &out=std::cout) const
const TMatrixT< Double_t > & getState() const
std::string fSpptModuleLabel
static bool sp_sort_3dy(const art::Ptr< recob::SpacePoint > &h1, const art::Ptr< recob::SpacePoint > &h2)
std::string fClusterModuleLabel
Length_t DetLength(TPCID const &tpcid=tpc_zero) const
Returns the length of the active volume of the specified TPC.
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
std::vector< double > fMomStart
void push_back(Ptr< U > const &p)
virtual TVector3 getMom(const GFDetPlane &pl)=0
static bool sp_sort_3dx(const art::Ptr< recob::SpacePoint > &h1, const art::Ptr< recob::SpacePoint > &h2)
A trajectory in space reconstructed from hits.
void setBlowUpFactor(double f)
Set the blowup factor (see blowUpCovs() )
static bool sp_sort_nsppts(const art::PtrVector< recob::SpacePoint > &h1, const art::PtrVector< recob::SpacePoint > &h2)
double energyLossBetheBloch(const double &mass, const double p)
void setNumIterations(Int_t i)
Set number of iterations for Kalman Filter.
TMatrixT< Double_t > * covREC
void processTrack(GFTrack *)
Performs fit on a GFTrack.
static GFFieldManager * getInstance()
TMatrixT< Double_t > * covMCT
std::vector< Point_t > convertCollToPoint(std::vector< Point > const &coll)
const TMatrixT< Double_t > & getCov() const
float dEdx(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const TCSlice &slc, TP3D &tp3d)
std::string ROOTobjectToString(const ROOTOBJ &obj)
Shortcut to write one ROOT object into a string.
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
iterator insert(iterator position, Ptr< U > const &p)
std::vector< double > dQdxCalc(const art::FindManyP< recob::Hit > &h, const art::PtrVector< recob::SpacePoint > &s, const TVector3 &p, const TVector3 &d)
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
genf::GFAbsTrackRep * repMC
void setInitialDirection(int d)
Sets the inital direction of the track fit (1 for inner to outer, or -1 for outer to inner)...
void init(GFAbsBField *b)
set the magntic field here. Magnetic field classes must be derived from GFAbsBField ...
EventNumber_t event() const
Length_t DetHalfHeight(TPCID const &tpcid=tpc_zero) const
Returns the half height of the active volume of the specified TPC.
void setErrorScaleSTh(Double_t f)
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
void setErrorScaleMTh(Double_t f)
cet::coded_exception< error, detail::translate > exception