22 #include "canvas/Persistency/Common/FindManyP.h" 44 #include "CoreUtils/ServiceUtil.h" 47 #include "Geant4/G4ThreeVector.hh" 49 #include "nug4/MagneticFieldServices/MagneticFieldService.h" 84 int DayOneFit( std::vector<TPCCluster> &TPCClusters,
85 std::vector<int> &TPCClusterlist,
86 std::vector<float> &trackparbeg,
91 std::vector<TVector3>& trajpts);
93 void updatepar(TVectorF &parvec,
float zcur,
float xh,
float yh,
float zh, TVectorF &predstep,
float &dlength);
110 consumes< std::vector<gar::rec::Track> >(patrecTag);
111 consumes< art::Assns<gar::rec::TPCCluster, gar::rec::Track> >(patrecTag);
113 produces< std::vector<gar::rec::Track> >();
114 produces< art::Assns<gar::rec::TPCCluster, gar::rec::Track> >();
115 produces<std::vector<gar::rec::TrackIoniz>>();
116 produces<art::Assns<rec::TrackIoniz, rec::Track>>();
117 produces<std::vector<gar::rec::TrackTrajectory>>();
118 produces<art::Assns<rec::TrackTrajectory, rec::Track>>();
127 std::unique_ptr< std::vector<gar::rec::Track> > trkCol(
new std::vector<gar::rec::Track>);
128 std::unique_ptr< art::Assns<gar::rec::TPCCluster,gar::rec::Track> > TPCClusterTrkAssns(new ::art::Assns<gar::rec::TPCCluster,gar::rec::Track>);
129 std::unique_ptr< std::vector<rec::TrackIoniz> > ionCol(
new std::vector<rec::TrackIoniz>);
130 std::unique_ptr< art::Assns<rec::TrackIoniz,rec::Track> > ionTrkAssns(new ::art::Assns<rec::TrackIoniz,rec::Track>);
131 std::unique_ptr< std::vector<rec::TrackTrajectory> > trajCol(
new std::vector<rec::TrackTrajectory>);
132 std::unique_ptr< art::Assns<rec::TrackTrajectory,rec::Track> > trajTrkAssns(new ::art::Assns<rec::TrackTrajectory,rec::Track>);
137 auto const& patrecTracks = *patrecTrackHandle;
144 auto const *magFieldService = gar::providerFrom<mag::MagneticFieldService>();
145 G4ThreeVector zerovec(0,0,0);
146 G4ThreeVector magfield = magFieldService->FieldAtPoint(zerovec);
153 TVector3 xhat(1,0,0);
155 const art::FindManyP<gar::rec::TPCCluster> TPCClustersFromPatRecTracks(patrecTrackHandle,e,
fPatRecLabel);
157 for (
size_t itrack = 0; itrack < patrecTracks.size(); ++itrack)
159 std::vector<gar::rec::TPCCluster> TPCClusters;
160 for (
size_t iTPCCluster=0; iTPCCluster < TPCClustersFromPatRecTracks.at(itrack).size(); ++iTPCCluster)
162 TPCClusters.push_back(*TPCClustersFromPatRecTracks.at(itrack).at(iTPCCluster));
167 if (
DayOneFitBothWays(patrecTracks.at(itrack),TPCClusters,trackparams,trackions,tracktraj) == 0)
169 trkCol->push_back(trackparams.CreateTrack());
170 ionCol->push_back(trackions);
171 trajCol->push_back(tracktraj);
172 auto const trackpointer = trackPtrMaker(trkCol->size()-1);
173 auto const ionizpointer = ionizPtrMaker(ionCol->size()-1);
174 auto const trajpointer = trajPtrMaker(trajCol->size()-1);
175 for (
size_t iTPCCluster=0; iTPCCluster<TPCClusters.size(); ++iTPCCluster)
177 TPCClusterTrkAssns->addSingle(TPCClustersFromPatRecTracks.at(itrack).at(iTPCCluster),trackpointer);
179 ionTrkAssns->addSingle(ionizpointer, trackpointer);
180 trajTrkAssns->addSingle(trajpointer, trackpointer);
193 std::vector<gar::rec::TPCCluster> &TPCClusters,
207 size_t nclus = TPCClusters.size();
208 std::vector<float> TPCClusterz;
209 for (
size_t i=0; i<nclus; ++i)
211 TPCClusterz.push_back(TPCClusters[i].Position()[2]);
213 std::vector<int> hsi(nclus);
214 TMath::Sort((
int) nclus,TPCClusterz.data(),hsi.data());
215 std::vector<int> hsib(nclus);
216 for (
size_t i=0; i<nclus; ++i)
218 hsib[nclus-i-1] = hsi[i];
221 std::vector<float> tparbeg(6);
222 for (
size_t i=0; i<5; ++i)
226 tparbeg[5] = patrectrack.
Vertex()[0];
229 float chisqforwards = 0;
230 float lengthforwards = 0;
231 std::vector<std::pair<float,float>> dSigdXs_FWD;
232 std::vector<TVector3> trajpts_FWD;
234 int retcode =
DayOneFit(TPCClusters,hsi,tparbeg,chisqforwards,lengthforwards,covmatbeg,dSigdXs_FWD,trajpts_FWD);
235 if (retcode != 0)
return 1;
238 std::vector<float> tparend(6);
239 for (
size_t i=0; i<5; ++i)
243 tparend[5] = patrectrack.
End()[0];
246 float chisqbackwards = 0;
247 float lengthbackwards = 0;
248 std::vector<std::pair<float,float>> dSigdXs_BAK;
249 std::vector<TVector3> trajpts_BAK;
251 retcode =
DayOneFit(TPCClusters,hsib,tparend,chisqbackwards,lengthbackwards,covmatend,dSigdXs_BAK,trajpts_BAK);
252 if (retcode != 0)
return 1;
254 size_t nTPCClusters=TPCClusters.size();
268 trackions.
setData(dSigdXs_FWD,dSigdXs_BAK);
269 tracktraj.
setData(trajpts_FWD,trajpts_BAK);
286 std::vector<int> &TPCClusterlist,
287 std::vector<float> &trackparbeg,
292 std::vector<TVector3>& trajpts)
297 size_t nclus = TPCClusterlist.size();
303 for (
size_t i=0;i<nclus; ++i)
305 const float *
pos = TPCClusters.at(TPCClusterlist.at(i)).Position();
306 TVector3 tvec(pos[0],pos[1],pos[2]);
307 trajpts.push_back(tvec);
309 float tvpos[3] = {trackparbeg[5],trackparbeg[0],trackparbeg[1]};
331 void dayonetrackfit::updatepar(TVectorF &parvec,
float zcur,
float xh,
float ,
float zh, TVectorF &predstep,
float &dlength)
343 float yc = parvec[0] + r*TMath::Cos(parvec[3]);
344 float zc = zcur - r*TMath::Sin(parvec[3]);
349 float phip1 = TMath::ASin((zh-zc)/r);
350 float phip2 = TMath::Pi() - phip1;
354 float tanlambda = TMath::Tan(parvec[4]);
355 if (tanlambda == 0) tanlambda = 1
E-4;
356 float phip3 = parvec[3] + (xh-parvec[1])/(r*tanlambda);
358 float dphip1n = (phip1-phip3)/TMath::TwoPi();
359 float niphi1 = nearbyint(dphip1n);
360 float dphip1a = TMath::Abs(dphip1n - niphi1);
362 float dphip2n = (phip2-phip3)/TMath::TwoPi();
363 float niphi2 = nearbyint(dphip2n);
364 float dphip2a = TMath::Abs(dphip2n - niphi2);
366 float phiex=phip1 + niphi1*TMath::TwoPi();
367 if (dphip1a > dphip2a)
369 phiex = phip2 + niphi2*TMath::TwoPi();
375 predstep[0] = yc - r*TMath::Cos(phiex);
376 predstep[1] = parvec[1] + r*tanlambda*(phiex-parvec[3]);
379 dlength = TMath::Abs( r * (phiex - parvec[3]) / TMath::Cos(parvec[4]) );
void setNTPCClusters(const size_t nTPCClusters)
void setLengthForwards(const float lengthforwards)
int fPrintLevel
debug printout: 0: none, 1: just track parameters and residuals, 2: all
void updatepar(TVectorF &parvec, float zcur, float xh, float yh, float zh, TVectorF &predstep, float &dlength)
dayonetrackfit(fhicl::ParameterSet const &p)
const float * TrackParBeg() const
void setCovMatBeg(const float *covmatbeg)
EDProducer(fhicl::ParameterSet const &pset)
static int DistXYZ(const float *trackpar, const float *Xpoint, const float *xyz, float &retDist)
int DayOneFit(std::vector< TPCCluster > &TPCClusters, std::vector< int > &TPCClusterlist, std::vector< float > &trackparbeg, float &chisquared, float &length, float *covmat, std::vector< std::pair< float, float >> &dSigdXs, std::vector< TVector3 > &trajpts)
void setLengthBackwards(const float lengthbackwards)
void setTrackParametersBegin(const float *tparbeg)
const float * Vertex() const
#define DEFINE_ART_MODULE(klass)
std::string fPatRecLabel
input patrec tracks and associations
void setXEnd(const float xend)
void setTrackParametersEnd(const float *tparend)
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
const float * TrackParEnd() const
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
void setChisqBackwards(const float chisqbackwards)
void setData(std::vector< TVector3 > ForwardTrajectory, std::vector< TVector3 > BackwardTrajectory)
const float * End() const
Interface to propagate a Track to the specific point.
void produce(art::Event &e) override
General GArSoft Utilities.
float fTPCClusterResolXY
pad size in cm in YZ to determine step size
void setCovMatEnd(const float *covmatend)
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
int DayOneFitBothWays(const gar::rec::Track &patrectrack, std::vector< gar::rec::TPCCluster > &TPCClusters, TrackPar &trackpar, TrackIoniz &trackions, TrackTrajectory &tracktraj)
void setXBeg(const float xbeg)
void setData(std::vector< std::pair< float, float >> dSigdX_FWD, std::vector< std::pair< float, float >> dSigdX_BAK)
float fTPCClusterResolZ
drift direction contribution to determine step size (resolution of a TPCCluster)
int fDumpTracks
0: do not print out tracks, 1: print out tracks
void setChisqForwards(const float chisqforwards)
void CovMatBegSymmetric(float *cmb) const
LArSoft geometry interface.
art framework interface to geometry description
void CovMatEndSymmetric(float *cme) const
void setTime(const double time)
dayonetrackfit & operator=(dayonetrackfit const &)=delete