20 #include "canvas/Persistency/Common/FindManyP.h" 42 #include "CoreUtils/ServiceUtil.h" 44 #include "nug4/MagneticFieldServices/MagneticFieldService.h" 45 #include "Geant4/G4ThreeVector.hh" 98 int KalmanFit( std::vector<TPCCluster> &TPCClusters,
99 std::vector<int> &TPCClusterlist,
100 std::vector<float> &trackparatend,
104 std::set<int> &unused_TPCClusters,
106 std::vector<TVector3>& trajpts);
149 consumes<std::vector<gar::rec::Track>>(patrecTag);
150 consumes<art::Assns<gar::rec::TPCCluster, gar::rec::Track>>(patrecTag);
156 produces<std::vector<gar::rec::Track>>();
157 produces<art::Assns<gar::rec::TPCCluster, gar::rec::Track>>();
158 produces<std::vector<gar::rec::TrackIoniz>>();
159 produces<art::Assns<rec::TrackIoniz, rec::Track>>();
160 produces<std::vector<gar::rec::TrackTrajectory>>();
161 produces<art::Assns<rec::TrackTrajectory, rec::Track>>();
170 std::unique_ptr< std::vector<gar::rec::Track> > trkCol(
new std::vector<gar::rec::Track>);
171 std::unique_ptr< art::Assns<gar::rec::TPCCluster,gar::rec::Track> > TPCClusterTrkAssns(new ::art::Assns<gar::rec::TPCCluster,gar::rec::Track>);
172 std::unique_ptr< std::vector<rec::TrackIoniz> > ionCol(
new std::vector<rec::TrackIoniz>);
173 std::unique_ptr< art::Assns<rec::TrackIoniz,rec::Track> > ionTrkAssns(new ::art::Assns<rec::TrackIoniz,rec::Track>);
174 std::unique_ptr< std::vector<rec::TrackTrajectory> > trajCol(
new std::vector<rec::TrackTrajectory>);
175 std::unique_ptr< art::Assns<rec::TrackTrajectory,rec::Track> > trajTrkAssns(new ::art::Assns<rec::TrackTrajectory,rec::Track>);
180 auto const& patrecTracks = *patrecTrackHandle;
187 auto const *magFieldService = gar::providerFrom<mag::MagneticFieldService>();
188 G4ThreeVector zerovec(0,0,0);
189 G4ThreeVector magfield = magFieldService->FieldAtPoint(zerovec);
191 double xtpccent =
euclid->TPCXCent();
192 double ytpccent =
euclid->TPCYCent();
193 double ztpccent =
euclid->TPCZCent();
194 TVector3 tpccent(xtpccent,ytpccent,ztpccent);
195 TVector3 xhat(1,0,0);
197 const art::FindManyP<gar::rec::TPCCluster> TPCClustersFromPatRecTracks(patrecTrackHandle,e,
fPatRecLabel);
199 for (
size_t itrack = 0; itrack < patrecTracks.size(); ++itrack)
201 std::vector<gar::rec::TPCCluster> TPCClusters;
202 for (
size_t iTPCCluster=0; iTPCCluster < TPCClustersFromPatRecTracks.at(itrack).size(); ++iTPCCluster)
204 TPCClusters.push_back(*TPCClustersFromPatRecTracks.at(itrack).at(iTPCCluster));
212 ionCol->push_back(trackions);
213 trajCol->push_back(tracktraj);
214 auto const trackpointer = trackPtrMaker(trkCol->size()-1);
215 auto const ionizpointer = ionizPtrMaker(ionCol->size()-1);
216 auto const trajpointer = trajPtrMaker(trajCol->size()-1);
217 for (
size_t iTPCCluster=0; iTPCCluster<TPCClusters.size(); ++iTPCCluster)
219 TPCClusterTrkAssns->addSingle(TPCClustersFromPatRecTracks.at(itrack).at(iTPCCluster),trackpointer);
221 ionTrkAssns->addSingle(ionizpointer, trackpointer);
222 trajTrkAssns->addSingle(trajpointer, trackpointer);
247 std::vector<int> hlf;
248 std::vector<int> hlb;
263 if (hlf.size() == 0)
return 1;
264 std::vector<float> tparend(6);
266 float chisqforwards = 0;
267 float lengthforwards = 0;
268 std::set<int> unused_TPCClusters;
269 std::vector<std::pair<float,float>> dSigdXs_FWD;
270 std::vector<TVector3> trajpts_FWD;
272 int retcode =
KalmanFit(TPCClusters,hlf,tparend,chisqforwards,lengthforwards,covmatend,unused_TPCClusters,dSigdXs_FWD,trajpts_FWD);
273 if (retcode != 0)
return 1;
277 std::vector<float> tparbeg(6);
279 float chisqbackwards = 0;
280 float lengthbackwards = 0;
281 std::vector<std::pair<float,float>> dSigdXs_BAK;
282 std::vector<TVector3> trajpts_BAK;
284 retcode =
KalmanFit(TPCClusters,hlb,tparbeg,chisqbackwards,lengthbackwards,covmatbeg,unused_TPCClusters,dSigdXs_BAK,trajpts_BAK);
285 if (retcode != 0)
return 1;
287 size_t nTPCClusters=0;
288 if (TPCClusters.size()>unused_TPCClusters.size())
289 { nTPCClusters = TPCClusters.size()-unused_TPCClusters.size(); }
303 trackions.
setData(dSigdXs_FWD,dSigdXs_BAK);
304 tracktraj.
setData(trajpts_FWD,trajpts_BAK);
321 std::vector<int> &TPCClusterlist,
322 std::vector<float> &trackparatend,
326 std::set<int> &unused_TPCClusters,
328 std::vector<TVector3>& trajpts)
333 size_t nTPCClusters = TPCClusterlist.size();
336 for (
size_t i=0; i<5; ++i) trackparatend[i] = 0;
337 for (
size_t i=0; i<25; ++i) covmat[i] = 0;
342 float curvature_init=0.1;
344 float lambda_init = 0;
348 float x_other_end = 0;
367 float xpos = xpos_init;
372 P[0][0] = TMath::Sq(1);
373 P[1][1] = TMath::Sq(1);
374 P[2][2] = TMath::Sq(.5);
375 P[3][3] = TMath::Sq(.5);
376 P[4][4] = TMath::Sq(.5);
401 parvec[0] = ypos_init;
402 parvec[1] = zpos_init;
403 parvec[2] = curvature_init;
404 parvec[3] = phi_init;
405 parvec[4] = lambda_init;
406 TVectorF predstep(5);
422 for (
int i=0;i<5;++i) I[i][i] = 1;
424 for (
size_t iTPCCluster=1; iTPCCluster<nTPCClusters; ++iTPCCluster)
427 float xh = TPCClusters[TPCClusterlist[iTPCCluster]].Position()[0];
428 float yh = TPCClusters[TPCClusterlist[iTPCCluster]].Position()[1];
429 float zh = TPCClusters[TPCClusterlist[iTPCCluster]].Position()[2];
434 std::cout <<
"Adding a new TPCCluster: " << xh <<
" " << yh <<
" " << zh <<
std::endl;
438 float curvature = parvec[2];
439 float phi = parvec[3];
440 float lambda = parvec[4];
450 float slope = TMath::Tan(lambda);
476 float dx = dxnum/dxdenom;
477 if (dx == 0) dx = 1
E-3;
487 F[0][3] = dx*slope*TMath::Cos(phi);
488 F[0][4] = dx*TMath::Sin(phi)*(-1.0-slope*slope);
492 F[1][3] = -dx*slope*TMath::Sin(phi);
493 F[1][4] = dx*TMath::Cos(phi)*(-1.0-slope*slope);
502 F[3][4] = dx*curvature*(-1.0-slope*slope);
517 std::cout <<
"x: " << xpos <<
" dx: " << dx <<
std::endl;
518 std::cout <<
" Parvec: y " << parvec[0] <<
" z " << parvec[1] <<
" c " << parvec[2] <<
" phi " << parvec[3] <<
" lambda " << parvec[4] <<
std::endl;
522 predstep[0] += slope*dx*TMath::Sin(phi);
523 predstep[1] += slope*dx*TMath::Cos(phi);
524 predstep[3] += slope*dx*curvature;
528 std::cout <<
" Predstep: y " << predstep[0] <<
" z " << predstep[1] <<
" c " << predstep[2] <<
" phi " << predstep[3] <<
" lambda " << predstep[4] <<
std::endl;
535 std::cout <<
"PPred Matrix: " <<
std::endl;
539 ytilde[0] = yh - predstep[0];
540 ytilde[1] = zh - predstep[1];
541 float ydistsq = ytilde.Norm2Sqr();
542 if (ydistsq > roadsq)
544 unused_TPCClusters.insert(iTPCCluster);
552 TVector3 trajPerp(0.0, predstep[0],predstep[1]);
553 float rTrj = trajPerp.Mag();
554 TVector3 trajStepPerp(0.0, sin(predstep[3]),cos(predstep[3]));
555 impactAngle = trajPerp.Dot(trajStepPerp) / rTrj;
556 impactAngle = acos(
abs(impactAngle));
557 float IROC_OROC_boundary = (
euclid->GetIROCOuterRadius() +
euclid->GetOROCInnerRadius())/2.0;
558 bool In_CROC = rTrj <=
euclid->GetIROCInnerRadius();
559 bool In_IROC =
euclid->GetIROCInnerRadius() < rTrj && rTrj <= IROC_OROC_boundary;
560 bool InIOROC = IROC_OROC_boundary < rTrj && rTrj <=
euclid->GetOROCPadHeightChangeRadius();
561 bool InOOROC =
euclid->GetOROCPadHeightChangeRadius() < rTrj;
562 float typicalResidual = 1.0;
565 }
else if (In_IROC) {
567 }
else if (InIOROC) {
569 }
else if (InOOROC) {
573 chisquared += ytilde.Norm2Sqr()/TMath::Sq(typicalResidual);
576 std::cout <<
"ytilde (residuals): " <<
std::endl;
596 std::cout <<
"Inverted S Matrix: " <<
std::endl;
607 float yprev = parvec[0];
608 float zprev = parvec[1];
609 parvec = predstep + K*ytilde;
613 trajpts.emplace_back(xpos,parvec[0],parvec[1]);
615 float d_length = TMath::Sqrt( dx*dx + TMath::Sq(parvec[0]-yprev) + TMath::Sq(parvec[1]-zprev) );
619 float valSig = TPCClusters[TPCClusterlist[iTPCCluster]].Signal();
622 std::pair pushme = std::make_pair(valSig,d_length);
623 dSigdXs.push_back( pushme );
628 if (dSigdXs.size()>0) dSigdXs.pop_back();
632 for (
size_t i=0; i<5; ++i)
634 trackparatend[i] = parvec[i];
636 trackparatend[5] =
xpos;
639 std::cout <<
"Track params at end (y, z, curv, phi, lambda) " << trackparatend[0] <<
" " << trackparatend[1] <<
" " <<
640 trackparatend[2] <<
" " << trackparatend[3] <<
" " << trackparatend[4] <<
std::endl;
655 for (
size_t i=0; i<5; ++i)
657 for (
size_t j=0; j<5; ++j)
659 covmat[icov] = P[i][j];
void setNTPCClusters(const size_t nTPCClusters)
void setLengthForwards(const float lengthforwards)
float fSortTransWeight
for use in hit sorting algorithm #1 – transverse distance weight factor
std::string fPatRecLabel
input patrec tracks and associations
float fKalCurvStepUncSq
constant uncertainty term on each step of the Kalman fit – squared, for curvature ...
void setCovMatBeg(const float *covmatbeg)
float fTPCClusterResid__IROC_b
EDProducer(fhicl::ParameterSet const &pset)
int KalmanFitBothWays(std::vector< gar::rec::TPCCluster > &TPCClusters, TrackPar &trackpar, TrackIoniz &trackions, TrackTrajectory &tracktraj)
float fKalPhiStepUncSq
constant uncertainty term on each step of the Kalman fit – squared, for phi
float fRoadYZinFit
cut in cm for dropping TPCClusters from tracks in fit
std::pair< float, std::string > P
void setLengthBackwards(const float lengthbackwards)
float fSortDistBack
for use in hit sorting algorithm #1 – how far to go back before raising the distance figure of merit...
int KalmanFit(std::vector< TPCCluster > &TPCClusters, std::vector< int > &TPCClusterlist, std::vector< float > &trackparatend, float &chisquared, float &length, float *covmat, std::set< int > &unused_TPCClusters, std::vector< std::pair< float, float >> &dSigdX, std::vector< TVector3 > &trajpts)
art::ServiceHandle< geo::GeometryGAr > euclid
int fDumpTracks
0: do not print out tracks, 1: print out tracks
float fTPCClusterResid__CROC_b
parameters to estimate residuals in YZ plane
float fTPCClusterResid_IOROC_b
void setTrackParametersBegin(const float *tparbeg)
int fSortAlg
which hit sorting alg to use. 1: old, 2: greedy distance sort
tpctrackfit2 & operator=(tpctrackfit2 const &)=delete
float fMinIonizGapCut
Don't compute dEdx for this dx or larger.
unsigned int fMinNumTPCClusters
minimum number of TPCClusters to define a track
#define DEFINE_ART_MODULE(klass)
void setXEnd(const float xend)
void setTrackParametersEnd(const float *tparend)
float fSortDistCut
distance cut to pass to hit sorter #2
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
int fPrintLevel
debug printout: 0: none, 1: just track parameters and residuals, 2: all
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
void setChisqBackwards(const float chisqbackwards)
float fTPCClusterResid__CROC_m
void setData(std::vector< TVector3 > ForwardTrajectory, std::vector< TVector3 > BackwardTrajectory)
float fKalCovZYMeasure
constant uncertainty term on measurement in Kalman (the R matrix)
float fTPCClusterResolYZ
pad size in cm in YZ to determine step size
gar::rec::Track CreateTrack()
void produce(art::Event &e) override
float fTPCClusterResid__IROC_m
General GArSoft Utilities.
void setCovMatEnd(const float *covmatend)
void sort_TPCClusters_along_track(const std::vector< gar::rec::TPCCluster > &TPCClusters, std::vector< int > &hlf, std::vector< int > &hlb, int printlevel, float &lengthforwards, float &lengthbackwards, float sorttransweight, float sortdistback)
float fTPCClusterResid_OOROC_m
void sort_TPCClusters_along_track2(const std::vector< gar::rec::TPCCluster > &TPCClusters, std::vector< int > &hlf, std::vector< int > &hlb, int printlevel, float &lengthforwards, float &lengthbackwards, float dcut)
void setXBeg(const float xbeg)
void setData(std::vector< std::pair< float, float >> dSigdX_FWD, std::vector< std::pair< float, float >> dSigdX_BAK)
float fTPCClusterResolX
drift direction contribution to determine step size (resolution of a TPCCluster)
void setChisqForwards(const float chisqforwards)
float fTPCClusterResid_OOROC_b
unsigned int fInitialTPNTPCClusters
number of TPCClusters to use for initial trackpar estimate, if present
art framework interface to geometry description
void setTime(const double time)
float fKalLambdaStepUncSq
constant uncertainty term on each step of the Kalman fit – squared, for lambda
cet::coded_exception< error, detail::translate > exception
tpctrackfit2(fhicl::ParameterSet const &p)
QTextStream & endl(QTextStream &s)
float fTPCClusterResid_IOROC_m
int initial_trackpar_estimate(const std::vector< gar::rec::TPCCluster > &TPCClusters, std::vector< int > &TPCClusterlist, float &curvature_init, float &lambda_init, float &phi_init, float &xpos, float &ypos, float &zpos, float &x_other_end, unsigned int initialtpnTPCClusters, int printlevel)