21 fTSMode = pset.get<
int>(
"TSMode", 2);
25 fDCAuseBox = pset.get<
bool>(
"DCAuseBox",
false);
28 fPEcut = pset.get<
double>(
"PEcut", 0.0);
29 fMaxUncert = pset.get<
double>(
"MaxUncert", 1000.);
30 fTPCTrackLabel = pset.get<std::vector<art::InputTag> >(
"TPCTrackLabel", {
""});
34 fSCE = lar::providerFrom<spacecharge::SpaceChargeService>();
55 double startX,
double endX,
int driftDirection,
56 std::pair<double, double> xLimits){
59 if(driftDirection == 0)
return std::make_pair(0, 0);
67 double maxX = std::max(startX, endX);
68 double maxLimit = std::max(xLimits.first, xLimits.second);
69 double maxShift = maxLimit - maxX;
71 double minX = std::min(startX, endX);
72 double minLimit = std::min(xLimits.first, xLimits.second);
73 double minShift = minLimit - minX;
75 double t0max = maxShift/Vd;
76 double t0min = minShift/Vd;
85 return std::make_pair(std::min(t0min, t0max), std::max(t0min, t0max));
92 TVector3 trackPos, TVector3 trackDir,
99 trackPos[0] += xshift;
102 geo::Point_t temppt = {trackPos.X(),trackPos.Y(),trackPos.Z()};
105 trackPos[0] += fPosOffsets.X();
106 trackPos[1] += fPosOffsets.Y();
107 trackPos[2] += fPosOffsets.Z();
110 TVector3
end = trackPos + trackDir;
137 else thisdca =
SimpleDCA(crtHit, trackPos, trackDir);
148 std::vector<geo::Vector_t> validDirections;
149 for(
size_t i = 0; i < nTrackPoints; i++){
154 size_t nValidPoints = validDirections.size();
155 int endPoint = (int)floor(nValidPoints*frac);
156 double xTotStart = 0;
double yTotStart = 0;
double zTotStart = 0;
157 double xTotEnd = 0;
double yTotEnd = 0;
double zTotEnd = 0;
158 for(
int i = 0; i < endPoint; i++){
160 geo::Vector_t dirEnd = validDirections.at(nValidPoints - (i+1));
161 xTotStart += dirStart.X();
162 yTotStart += dirStart.Y();
163 zTotStart += dirStart.Z();
164 xTotEnd += dirEnd.X();
165 yTotEnd += dirEnd.Y();
166 zTotEnd += dirEnd.Z();
168 TVector3 startDir = {-xTotStart/endPoint, -yTotStart/endPoint, -zTotStart/endPoint};
169 TVector3 endDir = {xTotEnd/endPoint, yTotEnd/endPoint, zTotEnd/endPoint};
171 return std::make_pair(startDir, endDir);
178 double CRTtime,
int driftDirection){
180 size_t nTrackPoints = track.
NPoints();
181 int midPt = (int)floor(nTrackPoints*frac);
186 double xshift = driftDirection * CRTtime * detProp.
DriftVelocity();
187 TVector3 startPoint = {startP.X()+xshift,startP.Y(),startP.Z()};
188 TVector3 endPoint = {endP.X()+xshift,endP.Y(),endP.Z()};
189 TVector3 midPoint = {midP.X()+xshift,midP.Y(),midP.Z()};
200 fTrackPos.SetX(startPoint.X());
205 startPoint.SetX(fTrackPos.X() + fPosOffsets.X());
206 startPoint.SetY(fTrackPos.Y() + fPosOffsets.Y());
207 startPoint.SetZ(fTrackPos.Z() + fPosOffsets.Z());
212 fTrackPos.SetX(endPoint.X());
216 endPoint.SetX(fTrackPos.X() + fPosOffsets.X());
217 endPoint.SetY(fTrackPos.Y() + fPosOffsets.Y());
218 endPoint.SetZ(fTrackPos.Z() + fPosOffsets.Z());
224 fTrackPos.SetX(midPoint.X());
228 midPoint.SetX(fTrackPos.X() + fPosOffsets.X());
229 midPoint.SetY(fTrackPos.Y() + fPosOffsets.Y());
230 midPoint.SetZ(fTrackPos.Z() + fPosOffsets.Z());
236 TVector3 startDir = {midPoint.X()-startPoint.X(),midPoint.Y()-startPoint.Y(),midPoint.Z()-startPoint.Z()};
237 float norm = startDir.Mag();
238 if (norm>0) startDir *=(1.0/
norm);
244 TVector3 endDir = {midPoint.X()-endPoint.X(),midPoint.Y()-endPoint.Y(),midPoint.Z()-endPoint.Z()};
246 if (norm>0) endDir *=(1.0/
norm);
252 return std::make_pair(startDir, endDir);
261 std::vector<TVector3> validPoints;
262 for(
size_t i = 0; i < nTrackPoints; i++){
267 size_t nValidPoints = validPoints.size();
268 int endPoint = (int)floor(nValidPoints*frac);
269 TVector3 startDir = validPoints.at(0) - validPoints.at(endPoint-1);
270 TVector3 endDir = validPoints.at(nValidPoints - 1) - validPoints.at(nValidPoints - (endPoint));
272 return std::make_pair(startDir.Unit(), endDir.Unit());
281 recob::Track tpcTrack, std::vector<sbn::crt::CRTHit> crtHits,
282 const art::Event& event, uint64_t trigger_timestamp) {
284 std::vector<std::pair<sbn::crt::CRTHit, double> > crthitpair;
287 auto tpcTrackHandle =
event.getValidHandle<std::vector<recob::Track>>(trackLabel);
288 if (!tpcTrackHandle.isValid())
continue;
290 art::FindManyP<recob::Hit> findManyHits(tpcTrackHandle, event, trackLabel);
291 for (
auto const& tpcTrack : (*tpcTrackHandle)){
292 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.
ID());
294 crthitpair.push_back(
ClosestCRTHit(detProp, tpcTrack, hits, crtHits, trigger_timestamp));
309 std::vector<sbn::crt::CRTHit> crtHits, uint64_t trigger_timestamp) {
311 auto start = tpcTrack.
Vertex<TVector3>();
312 auto end = tpcTrack.
End<TVector3>();
317 std::pair<double, double> t0MinMax =
TrackT0Range(detProp, start.X(), end.X(), driftDirection, xLimits);
319 return ClosestCRTHit(detProp, tpcTrack, t0MinMax, crtHits, driftDirection, trigger_timestamp);
323 recob::Track tpcTrack, std::pair<double, double> t0MinMax,
324 std::vector<sbn::crt::CRTHit> crtHits,
int driftDirection, uint64_t trigger_timestamp) {
327 return std::make_pair(bestmatch.
thishit,bestmatch.
dca);
334 std::vector<sbn::crt::CRTHit> crtHits, uint64_t trigger_timestamp) {
336 auto start = tpcTrack.
Vertex<TVector3>();
337 auto end = tpcTrack.
End<TVector3>();
347 std::pair<double, double> t0MinMax =
TrackT0Range(detProp, start.X(), end.X(), driftDirection, xLimits);
349 return GetClosestCRTHit(detProp, tpcTrack, t0MinMax, crtHits, driftDirection, trigger_timestamp);
354 recob::Track tpcTrack, std::vector<sbn::crt::CRTHit> crtHits,
355 const art::Event& event, uint64_t trigger_timestamp) {
357 std::vector<matchCand> matchcanvec;
360 auto tpcTrackHandle =
event.getValidHandle<std::vector<recob::Track>>(trackLabel);
361 if (!tpcTrackHandle.isValid())
continue;
363 art::FindManyP<recob::Hit> findManyHits(tpcTrackHandle, event, trackLabel);
364 for (
auto const& tpcTrack : (*tpcTrackHandle)){
365 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.
ID());
366 matchcanvec.push_back(
GetClosestCRTHit(detProp, tpcTrack, hits, crtHits, trigger_timestamp));
384 recob::Track tpcTrack, std::pair<double, double> t0MinMax,
385 std::vector<sbn::crt::CRTHit> crtHits,
int driftDirection, uint64_t& trigger_timestamp) {
387 auto start = tpcTrack.
Vertex<TVector3>();
388 auto end = tpcTrack.
End<TVector3>();
392 std::vector<matchCand> t0Candidates;
396 for(
auto &crtHit : crtHits){
398 double crtTime = -99999.;
404 crtTime = double(crtHit.ts0_ns - trigger_timestamp%1
'000'000
'000)/1e3;
406 if(crtTime<-0.5e6) crtTime+=1e6;
407 else if(crtTime>0.5e6) crtTime-=1e6;
416 if (!((crtTime >= t0MinMax.first - 10. && crtTime <= t0MinMax.second + 10.)
417 || t0MinMax.first == t0MinMax.second))
continue;
430 TVector3 crtPoint(crtHit.x_pos, crtHit.y_pos, crtHit.z_pos);
435 std::pair<TVector3, TVector3> startEndDir;
439 TVector3 startDir = startEndDir.first;
440 TVector3 endDir = startEndDir.second;
447 double xshift = driftDirection * crtTime * detProp.
DriftVelocity();
448 auto thisstart = start;
449 thisstart.SetX(start.X()+xshift);
451 thisend.SetX(end.X()+xshift);
455 geo::Point_t temppt = {thisstart.X(),thisstart.Y(),thisstart.Z()};
458 thisstart[0] += fPosOffsets.X();
459 thisstart[1] += fPosOffsets.Y();
460 thisstart[2] += fPosOffsets.Z();
461 temppt.SetX(thisend.X());
462 temppt.SetY(thisend.Y());
463 temppt.SetZ(thisend.Z());
466 thisend[0] += fPosOffsets.X();
467 thisend[1] += fPosOffsets.Y();
468 thisend[2] += fPosOffsets.Z();
474 double distS = (crtPoint-thisstart).Mag();
475 double distE = (crtPoint-thisend).Mag();
486 newmc.
dca = startDist;
488 t0Candidates.push_back(newmc);
496 t0Candidates.push_back(newmc);
505 if(t0Candidates.size() > 0){
507 bestmatch=t0Candidates[0];
510 for(
auto &thisCand : t0Candidates){
511 double this_sin_angle = thisCand.dca/thisCand.extrapLen;
512 if (bestmatch.
dca<0 )bestmatch=thisCand;
513 else if (this_sin_angle<sin_angle && thisCand.dca>=0)bestmatch=thisCand;
517 for(
auto &thisCand : t0Candidates){
519 if (bestmatch.
dca<0 )bestmatch=thisCand;
520 else if (thisCand.dca<bestmatch.
dca && thisCand.dca>=0)bestmatch=thisCand;
532 recob::Track tpcTrack, std::vector<sbn::crt::CRTHit> crtHits,
533 const art::Event& event, uint64_t trigger_timestamp){
534 std::vector<double> ftime;
536 auto tpcTrackHandle =
event.getValidHandle<std::vector<recob::Track>>(trackLabel);
537 if (!tpcTrackHandle.isValid())
continue;
539 art::FindManyP<recob::Hit> findManyHits(tpcTrackHandle, event, trackLabel);
540 for (
auto const& tpcTrack : (*tpcTrackHandle)){
541 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.
ID());
542 ftime.push_back(
T0FromCRTHits(detProp, tpcTrack, hits, crtHits, trigger_timestamp));
558 std::vector<sbn::crt::CRTHit> crtHits, uint64_t& trigger_timestamp) {
563 if(closestHit.
dca <0)
return -99999;
579 recob::Track tpcTrack, std::vector<sbn::crt::CRTHit> crtHits,
580 const art::Event& event, uint64_t trigger_timestamp){
582 std::vector<std::pair<double, double> > ft0anddca;
584 auto tpcTrackHandle =
event.getValidHandle<std::vector<recob::Track>>(trackLabel);
585 if (!tpcTrackHandle.isValid())
continue;
587 art::FindManyP<recob::Hit> findManyHits(tpcTrackHandle, event, trackLabel);
588 for (
auto const& tpcTrack : (*tpcTrackHandle)){
589 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.
ID());
590 ft0anddca.push_back(
T0AndDCAFromCRTHits(detProp, tpcTrack, hits, crtHits, trigger_timestamp));
605 std::vector<sbn::crt::CRTHit> crtHits, uint64_t& trigger_timestamp) {
611 if(closestHit.
dca < 0 )
return std::make_pair(-9999., -9999.);
614 return std::make_pair(-9999., -9999.);
623 TVector3
end = start + direction;
624 double denominator = direction.Mag();
625 double numerator = (pos - start).Cross(pos - end).Mag();
626 return numerator/denominator;
662 return std::min(std::min(dist1, dist2), std::min(dist3, dist4));
671 double smallNum = 0.00001;
674 TVector3 direction1 = end1 - start1;
676 TVector3 direction2 = end2 - start2;
678 TVector3 u = direction1;
679 TVector3 v = direction2;
680 TVector3
w = start1 - start2;
687 double D = a * c - b * b;
688 double sc, sN, sD = D;
689 double tc, tN, tD = D;
699 sN = (b * e - c * d)/D;
700 tN = (a * e - b * d)/D;
713 sc = (
std::abs(sN) < smallNum ? 0.0 : sN / sD);
714 tc = (
std::abs(tN) < smallNum ? 0.0 : tN / tD);
716 TVector3 dP = w + (sc * u) - (tc * v);
726 TVector3
dir = (end - start);
727 TVector3 invDir (1./dir.X(), 1./dir.Y(), 1/dir.Z());
729 double tmin, tmax, tymin, tymax, tzmin, tzmax;
731 TVector3 enter (-99999, -99999, -99999);
732 TVector3
exit (-99999, -99999, -99999);
736 tmin = (min.X() - start.X()) * invDir.X();
737 tmax = (max.X() - start.X()) * invDir.X();
740 tmin = (max.X() - start.X()) * invDir.X();
741 tmax = (min.X() - start.X()) * invDir.X();
746 tymin = (min.Y() - start.Y()) * invDir.Y();
747 tymax = (max.Y() - start.Y()) * invDir.Y();
750 tymin = (max.Y() - start.Y()) * invDir.Y();
751 tymax = (min.Y() - start.Y()) * invDir.Y();
755 if((tmin > tymax) || (tymin > tmax))
return std::make_pair(enter, exit);
758 if(tymin > tmin) tmin = tymin;
761 if(tymax < tmax) tmax = tymax;
765 tzmin = (min.Z() - start.Z()) * invDir.Z();
766 tzmax = (max.Z() - start.Z()) * invDir.Z();
769 tzmin = (max.Z() - start.Z()) * invDir.Z();
770 tzmax = (min.Z() - start.Z()) * invDir.Z();
774 if((tmin > tzmax) || (tzmin > tmax))
return std::make_pair(enter, exit);
777 if(tzmin > tmin) tmin = tzmin;
780 if(tzmax < tmax) tmax = tzmax;
783 double xmin = start.X() + tmin * dir.X();
784 double xmax = start.X() + tmax * dir.X();
785 double ymin = start.Y() + tmin * dir.Y();
786 double ymax = start.Y() + tmax * dir.Y();
787 double zmin = start.Z() + tmin * dir.Z();
788 double zmax = start.Z() + tmax * dir.Z();
791 enter.SetXYZ(xmin, ymin, zmin);
792 exit.SetXYZ(xmax, ymax, zmax);
793 return std::make_pair(enter, exit);
float z_err
position uncertainty in z-direction (cm).
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
float x_err
position uncertainty in x-direction (cm).
virtual geo::Vector_t GetCalPosOffsets(geo::Point_t const &point, int const &TPCid) const =0
std::pair< double, double > XLimitsFromHits(const geo::GeometryCore *GeometryService, std::vector< art::Ptr< recob::Hit >> hits)
then if[["$THISISATEST"==1]]
std::vector< art::InputTag > fTPCTrackLabel
Utilities related to art service access.
std::pair< TVector3, TVector3 > TrackDirectionAverage(recob::Track track, double frac)
double ts1_ns
Timestamp T1 ([signal time w.r.t. Trigger time]), in UTC absolute time scale in nanoseconds from the ...
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
float y_err
position uncertainty in y-direction (cm).
Point_t const & LocationAtPoint(size_t i) const
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
geo::TPCID PositionToTPCID(geo::Point_t const &point) const
Returns the ID of the TPC at specified location.
process_name use argoneut_mc_hitfinder track
void reconfigure(const fhicl::ParameterSet &pset)
std::vector< std::pair< double, double > > T0AndDCAFromCRTHits(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< sbn::crt::CRTHit > crtHits, const art::Event &event, uint64_t trigger_timestamp)
int DriftDirectionFromHits(const geo::GeometryCore *GeometryService, std::vector< art::Ptr< recob::Hit >> hits)
process_name pandoraGausCryo1 vertexChargeCryo1 vertexStubCryo1 xmin
spacecharge::SpaceCharge const * fSCE
float z_pos
position in z-direction (cm).
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...
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, uint64_t trigger_timestamp)
std::vector< double > T0FromCRTHits(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< sbn::crt::CRTHit > crtHits, const art::Event &event, uint64_t trigger_timestamp)
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.
double LineSegmentDistance(TVector3 start1, TVector3 end1, TVector3 start2, TVector3 end2)
A trajectory in space reconstructed from hits.
std::pair< TVector3, TVector3 > TrackDirectionAverageFromPoints(recob::Track track, double frac)
Point_t const & Vertex() const
auto end(FixedBins< T, C > const &) noexcept
double DriftVelocity(double efield=0., double temperature=0.) const
cm/us
The data type to uniquely identify a TPC.
double DistToCrtHit(sbn::crt::CRTHit hit, TVector3 start, TVector3 end)
static constexpr HitIndex_t InvalidHitIndex
Value marking an invalid hit index.
auto norm(Vector const &v)
Return norm of the specified vector.
float y_pos
position in y-direction (cm).
geo::GeometryCore const * fGeometryService
std::pair< double, double > TrackT0Range(detinfo::DetectorPropertiesData const &detProp, double startX, double endX, int driftDirection, std::pair< double, double > xLimits)
matchCand GetClosestCRTHit(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::pair< double, double > t0MinMax, std::vector< sbn::crt::CRTHit > crtHits, int driftDirection, uint64_t &trigger_timestamp)
float x_pos
position in x-direction (cm).
double SimpleDCA(sbn::crt::CRTHit hit, TVector3 start, TVector3 direction)
double fTrackDirectionFrac
Point_t const & End() const
double DistOfClosestApproach(detinfo::DetectorPropertiesData const &detProp, TVector3 trackPos, TVector3 trackDir, sbn::crt::CRTHit crtHit, int driftDirection, double t0)
Vector_t DirectionAtPoint(size_t i) const
std::pair< TVector3, TVector3 > TrackDirection(detinfo::DetectorPropertiesData const &detProp, recob::Track track, double frac, double CRTtime, int driftDirection)
TPCID_t TPC
Index of the TPC within its cryostat.
virtual bool EnableCalSpatialSCE() const =0
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:
std::pair< TVector3, TVector3 > CubeIntersection(TVector3 min, TVector3 max, TVector3 start, TVector3 end)