55 double startX,
double endX,
int driftDirection, std::pair<double, double> xLimits){
58 if(driftDirection == 0)
return std::make_pair(0, 0);
64 double maxX = std::max(startX, endX);
65 double maxLimit = std::max(xLimits.first, xLimits.second);
66 double maxShift = maxLimit - maxX;
68 double minX = std::min(startX, endX);
69 double minLimit = std::min(xLimits.first, xLimits.second);
70 double minShift = minLimit - minX;
72 double t0max = maxShift/Vd;
73 double t0min = minShift/Vd;
76 return std::make_pair(std::min(t0min, t0max), std::max(t0min, t0max));
83 TVector3 trackPos, TVector3 trackDir,
sbn::crt::CRTHit crtHit,
int driftDirection,
double t0){
89 trackPos[0] += xshift;
92 geo::Point_t temppt = {trackPos.X(),trackPos.Y(),trackPos.Z()};
95 trackPos[0] += fPosOffsets.X();
96 trackPos[1] += fPosOffsets.Y();
97 trackPos[2] += fPosOffsets.Z();
100 TVector3
end = trackPos + trackDir;
120 std::vector<geo::Vector_t> validDirections;
121 for(
size_t i = 0; i < nTrackPoints; i++){
126 size_t nValidPoints = validDirections.size();
127 int endPoint = (int)floor(nValidPoints*frac);
128 double xTotStart = 0;
double yTotStart = 0;
double zTotStart = 0;
129 double xTotEnd = 0;
double yTotEnd = 0;
double zTotEnd = 0;
130 for(
int i = 0; i < endPoint; i++){
132 geo::Vector_t dirEnd = validDirections.at(nValidPoints - (i+1));
133 xTotStart += dirStart.X();
134 yTotStart += dirStart.Y();
135 zTotStart += dirStart.Z();
136 xTotEnd += dirEnd.X();
137 yTotEnd += dirEnd.Y();
138 zTotEnd += dirEnd.Z();
140 TVector3 startDir = {-xTotStart/endPoint, -yTotStart/endPoint, -zTotStart/endPoint};
141 TVector3 endDir = {xTotEnd/endPoint, yTotEnd/endPoint, zTotEnd/endPoint};
143 return std::make_pair(startDir, endDir);
150 size_t nTrackPoints = track.
NPoints();
151 int midPt = (int)floor(nTrackPoints*frac);
156 double xshift = driftDirection * CRTtime * detProp.
DriftVelocity();
157 TVector3 startPoint = {startP.X()+xshift,startP.Y(),startP.Z()};
158 TVector3 endPoint = {endP.X()+xshift,endP.Y(),endP.Z()};
159 TVector3 midPoint = {midP.X()+xshift,midP.Y(),midP.Z()};
164 fTrackPos.SetX(startPoint.X());
167 startPoint.SetX(fTrackPos.X() + fPosOffsets.X());
168 startPoint.SetY(fTrackPos.Y() + fPosOffsets.Y());
169 startPoint.SetZ(fTrackPos.Z() + fPosOffsets.Z());
171 fTrackPos.SetX(endPoint.X());
175 endPoint.SetX(fTrackPos.X() + fPosOffsets.X());
176 endPoint.SetY(fTrackPos.Y() + fPosOffsets.Y());
177 endPoint.SetZ(fTrackPos.Z() + fPosOffsets.Z());
179 fTrackPos.SetX(midPoint.X());
183 midPoint.SetX(fTrackPos.X() + fPosOffsets.X());
184 midPoint.SetY(fTrackPos.Y() + fPosOffsets.Y());
185 midPoint.SetZ(fTrackPos.Z() + fPosOffsets.Z());
188 TVector3 startDir = {midPoint.X()-startPoint.X(),midPoint.Y()-startPoint.Y(),midPoint.Z()-startPoint.Z()};
189 float norm = startDir.Mag();
190 if (norm>0) startDir *=(1.0/
norm);
191 TVector3 endDir = {midPoint.X()-endPoint.X(),midPoint.Y()-endPoint.Y(),midPoint.Z()-endPoint.Z()};
193 if (norm>0) endDir *=(1.0/
norm);
195 return std::make_pair(startDir, endDir);
204 std::vector<TVector3> validPoints;
205 for(
size_t i = 0; i < nTrackPoints; i++){
210 size_t nValidPoints = validPoints.size();
211 int endPoint = (int)floor(nValidPoints*frac);
212 TVector3 startDir = validPoints.at(0) - validPoints.at(endPoint-1);
213 TVector3 endDir = validPoints.at(nValidPoints - 1) - validPoints.at(nValidPoints - (endPoint));
215 return std::make_pair(startDir.Unit(), endDir.Unit());
224 recob::Track tpcTrack, std::vector<sbn::crt::CRTHit> crtHits,
const art::Event& event) {
225 auto tpcTrackHandle =
event.getValidHandle<std::vector<recob::Track>>(
fTPCTrackLabel);
226 art::FindManyP<recob::Hit> findManyHits(tpcTrackHandle, event,
fTPCTrackLabel);
227 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.
ID());
235 auto start = tpcTrack.
Vertex<TVector3>();
236 auto end = tpcTrack.
End<TVector3>();
241 std::pair<double, double> t0MinMax =
TrackT0Range(detProp, start.X(), end.X(), driftDirection, xLimits);
243 return ClosestCRTHit(detProp, tpcTrack, t0MinMax, crtHits, driftDirection);
247 recob::Track tpcTrack, std::pair<double, double> t0MinMax, std::vector<sbn::crt::CRTHit> crtHits,
int driftDirection) {
249 return std::make_pair(bestmatch.
thishit,bestmatch.
dca);
257 auto start = tpcTrack.
Vertex<TVector3>();
258 auto end = tpcTrack.
End<TVector3>();
263 std::pair<double, double> t0MinMax =
TrackT0Range(detProp, start.X(), end.X(), driftDirection, xLimits);
265 return GetClosestCRTHit(detProp, tpcTrack, t0MinMax, crtHits, driftDirection);
269 recob::Track tpcTrack, std::vector<sbn::crt::CRTHit> crtHits,
const art::Event& event) {
270 auto tpcTrackHandle =
event.getValidHandle<std::vector<recob::Track>>(
fTPCTrackLabel);
271 art::FindManyP<recob::Hit> findManyHits(tpcTrackHandle, event,
fTPCTrackLabel);
272 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.
ID());
278 recob::Track tpcTrack, std::pair<double, double> t0MinMax, std::vector<sbn::crt::CRTHit> crtHits,
int driftDirection) {
279 auto start = tpcTrack.
Vertex<TVector3>();
280 auto end = tpcTrack.
End<TVector3>();
285 std::vector<matchCand> t0Candidates;
290 for(
auto &crtHit : crtHits){
292 double crtTime = -99999.;
301 if (!((crtTime >= t0MinMax.first - 10. && crtTime <= t0MinMax.second + 10.)
302 || t0MinMax.first == t0MinMax.second))
continue;
304 if (crtHit.peshit<
fPEcut)
continue;
309 TVector3 crtPoint(crtHit.x_pos, crtHit.y_pos, crtHit.z_pos);
312 std::pair<TVector3, TVector3> startEndDir;
316 TVector3 startDir = startEndDir.first;
317 TVector3 endDir = startEndDir.second;
324 double xshift = driftDirection * crtTime * detProp.
DriftVelocity();
325 auto thisstart = start;
326 thisstart.SetX(start.X()+xshift);
328 thisend.SetX(end.X()+xshift);
332 geo::Point_t temppt = {thisstart.X(),thisstart.Y(),thisstart.Z()};
335 thisstart[0] += fPosOffsets.X();
336 thisstart[1] += fPosOffsets.Y();
337 thisstart[2] += fPosOffsets.Z();
338 temppt.SetX(thisend.X());
339 temppt.SetY(thisend.Y());
340 temppt.SetZ(thisend.Z());
343 thisend[0] += fPosOffsets.X();
344 thisend[1] += fPosOffsets.Y();
345 thisend[2] += fPosOffsets.Z();
351 double distS = (crtPoint-thisstart).Mag();
352 double distE = (crtPoint-thisend).Mag();
360 newmc.
dca = startDist;
362 t0Candidates.push_back(newmc);
369 t0Candidates.push_back(newmc);
377 if(t0Candidates.size() > 0){
379 bestmatch=t0Candidates[0];
382 for(
auto &thisCand : t0Candidates){
383 double this_sin_angle = thisCand.dca/thisCand.extrapLen;
384 if (bestmatch.
dca<0 ) bestmatch=thisCand;
385 else if (this_sin_angle<sin_angle && thisCand.dca>=0) bestmatch=thisCand;
389 for(
auto &thisCand : t0Candidates){
390 if (bestmatch.
dca<0 ) bestmatch=thisCand;
391 else if (thisCand.dca<bestmatch.
dca && thisCand.dca>=0) bestmatch=thisCand;
403 recob::Track tpcTrack, std::vector<sbn::crt::CRTHit> crtHits,
const art::Event& event){
404 auto tpcTrackHandle =
event.getValidHandle<std::vector<recob::Track>>(
fTPCTrackLabel);
405 art::FindManyP<recob::Hit> findManyHits(tpcTrackHandle, event,
fTPCTrackLabel);
406 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.
ID());
416 if(closestHit.
dca <0)
return -99999;
432 recob::Track tpcTrack, std::vector<sbn::crt::CRTHit> crtHits,
const art::Event& event){
433 auto tpcTrackHandle =
event.getValidHandle<std::vector<recob::Track>>(
fTPCTrackLabel);
434 art::FindManyP<recob::Hit> findManyHits(tpcTrackHandle, event,
fTPCTrackLabel);
435 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.
ID());
446 if(closestHit.
dca < 0 )
return std::make_pair(-9999., -9999.);
449 return std::make_pair(-9999., -9999.);
fhicl::Atom< bool > SCEposCorr
std::pair< double, double > XLimitsFromHits(const geo::GeometryCore *GeometryService, std::vector< art::Ptr< recob::Hit >> hits)
std::pair< TVector3, TVector3 > TrackDirectionAverageFromPoints(recob::Track track, double frac)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
geo::GeometryCore const * fGeometryService
virtual geo::Vector_t GetCalPosOffsets(geo::Point_t const &point, int const &TPCid) const =0
matchCand GetClosestCRTHit(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::pair< double, double > t0MinMax, std::vector< sbn::crt::CRTHit > crtHits, int driftDirection)
double ts1_ns
Timestamp T1 ([signal time w.r.t. Trigger time]), in UTC absolute time scale in nanoseconds from the ...
spacecharge::SpaceCharge const * fSCE
T::provider_type const * providerFrom()
Returns a constant pointer to the provider of specified service.
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
Point_t const & LocationAtPoint(size_t i) const
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
fhicl::Atom< double > DistanceLimit
geo::TPCID PositionToTPCID(geo::Point_t const &point) const
Returns the ID of the TPC at specified location.
art::InputTag fTPCTrackLabel
process_name use argoneut_mc_hitfinder track
fhicl::Atom< double > MaxUncert
fhicl::Atom< double > DoverLLimit
std::pair< double, double > TrackT0Range(detinfo::DetectorPropertiesData const &detProp, double startX, double endX, int driftDirection, std::pair< double, double > xLimits)
std::pair< double, double > T0AndDCAFromCRTHits(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< sbn::crt::CRTHit > crtHits, const art::Event &event)
void reconfigure(const Config &config)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
double ts0_ns
Timestamp T0 (from White Rabbit), in UTC absolute time scale in nanoseconds from the Epoch...
fhicl::Atom< int > DirMethod
double DistToCrtHit(sbn::crt::CRTHit hit, TVector3 start, TVector3 end)
double DistOfClosestApproach(detinfo::DetectorPropertiesData const &detProp, TVector3 trackPos, TVector3 trackDir, sbn::crt::CRTHit crtHit, int driftDirection, double t0)
std::pair< sbn::crt::CRTHit, double > ClosestCRTHit(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::pair< double, double > t0MinMax, std::vector< sbn::crt::CRTHit > crtHits, int driftDirection)
fhicl::Atom< double > TimeCorrection
fhicl::Atom< double > TrackDirectionFrac
double Length(size_t p=0) const
Access to various track properties.
PointFlags_t const & FlagsAtPoint(size_t i) const
Returns the flags for the specified trajectory point.
Point_t const & Start() const
Access to track position at different points.
A trajectory in space reconstructed from hits.
Point_t const & Vertex() const
fhicl::Atom< bool > DCAoverLength
CRTT0MatchAlg(const Config &config)
auto end(FixedBins< T, C > const &) noexcept
fhicl::Atom< double > MinTrackLength
double fTrackDirectionFrac
double DriftVelocity(double efield=0., double temperature=0.) const
cm/us
The data type to uniquely identify a TPC.
Description of geometry of one entire detector.
static constexpr HitIndex_t InvalidHitIndex
Value marking an invalid hit index.
auto norm(Vector const &v)
Return norm of the specified vector.
fhicl::Atom< double > PEcut
double SimpleDCA(sbn::crt::CRTHit hit, TVector3 start, TVector3 direction)
double T0FromCRTHits(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< sbn::crt::CRTHit > crtHits, const art::Event &event)
fhicl::Atom< int > TSMode
int DriftDirectionFromHits(const geo::GeometryCore *GeometryService, std::vector< art::Ptr< recob::Hit >> hits)
std::pair< TVector3, TVector3 > TrackDirectionAverage(recob::Track track, double frac)
fhicl::Atom< art::InputTag > TPCTrackLabel
Point_t const & End() const
stream1 can override from command line with o or output services user sbnd
Vector_t DirectionAtPoint(size_t i) const
TPCID_t TPC
Index of the TPC within its cryostat.
virtual bool EnableCalSpatialSCE() const =0
std::pair< TVector3, TVector3 > TrackDirection(detinfo::DetectorPropertiesData const &detProp, recob::Track track, double frac, double CRTtime, int driftDirection)
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
fhicl::Atom< bool > DCAuseBox