All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Private Attributes | List of all members
sbnd::CRTT0MatchAlg Class Reference

#include <CRTT0MatchAlg.h>

Classes

struct  Config
 

Public Member Functions

 CRTT0MatchAlg (const Config &config)
 
 CRTT0MatchAlg (const Config &config, geo::GeometryCore const *GeometryService, spacecharge::SpaceCharge const *SCE)
 
 CRTT0MatchAlg (const fhicl::ParameterSet &pset)
 
void reconfigure (const Config &config)
 
std::pair< double, double > TrackT0Range (detinfo::DetectorPropertiesData const &detProp, double startX, double endX, int driftDirection, std::pair< double, double > xLimits)
 
double DistOfClosestApproach (detinfo::DetectorPropertiesData const &detProp, TVector3 trackPos, TVector3 trackDir, sbn::crt::CRTHit crtHit, int driftDirection, double t0)
 
std::pair< TVector3, TVector3 > TrackDirectionAverage (recob::Track track, double frac)
 
std::pair< TVector3, TVector3 > TrackDirection (detinfo::DetectorPropertiesData const &detProp, recob::Track track, double frac, double CRTtime, int driftDirection)
 
std::pair< TVector3, TVector3 > TrackDirectionAverageFromPoints (recob::Track track, double frac)
 
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)
 
std::pair< sbn::crt::CRTHit,
double > 
ClosestCRTHit (detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< sbn::crt::CRTHit > crtHits, const art::Event &event)
 
std::pair< sbn::crt::CRTHit,
double > 
ClosestCRTHit (detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< art::Ptr< recob::Hit >> hits, std::vector< sbn::crt::CRTHit > crtHits)
 
matchCand GetClosestCRTHit (detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::pair< double, double > t0MinMax, std::vector< sbn::crt::CRTHit > crtHits, int driftDirection)
 
matchCand GetClosestCRTHit (detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< sbn::crt::CRTHit > crtHits, const art::Event &event)
 
matchCand GetClosestCRTHit (detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< art::Ptr< recob::Hit >> hits, std::vector< sbn::crt::CRTHit > crtHits)
 
double T0FromCRTHits (detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< sbn::crt::CRTHit > crtHits, const art::Event &event)
 
double T0FromCRTHits (detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< art::Ptr< recob::Hit >> hits, std::vector< sbn::crt::CRTHit > crtHits)
 
std::pair< double, double > T0AndDCAFromCRTHits (detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< sbn::crt::CRTHit > crtHits, const art::Event &event)
 
std::pair< double, double > T0AndDCAFromCRTHits (detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< art::Ptr< recob::Hit >> hits, std::vector< sbn::crt::CRTHit > crtHits)
 

Private Attributes

geo::GeometryCore const * fGeometryService
 
spacecharge::SpaceCharge const * fSCE
 
double fMinTrackLength
 
double fTrackDirectionFrac
 
double fDistanceLimit
 
int fTSMode
 
double fTimeCorrection
 
int fDirMethod
 
bool fSCEposCorr
 
bool fDCAuseBox
 
bool fDCAoverLength
 
double fDoverLLimit
 
double fPEcut
 
double fMaxUncert
 
art::InputTag fTPCTrackLabel
 

Detailed Description

Definition at line 75 of file sbndcode/sbndcode/CRT/CRTUtils/CRTT0MatchAlg.h.

Constructor & Destructor Documentation

sbnd::CRTT0MatchAlg::CRTT0MatchAlg ( const Config config)

Definition at line 5 of file sbndcode/sbndcode/CRT/CRTUtils/CRTT0MatchAlg.cc.

5  : CRTT0MatchAlg(config, lar::providerFrom<geo::Geometry>(),
6 lar::providerFrom<spacecharge::SpaceChargeService>()) {}
sbnd::CRTT0MatchAlg::CRTT0MatchAlg ( const Config config,
geo::GeometryCore const *  GeometryService,
spacecharge::SpaceCharge const *  SCE 
)

Definition at line 8 of file sbndcode/sbndcode/CRT/CRTUtils/CRTT0MatchAlg.cc.

8  {
9 
10 
11  this->reconfigure(config);
12  fGeometryService = GeometryService;
13  fSCE = SCE;
14 }
sbnd::CRTT0MatchAlg::CRTT0MatchAlg ( const fhicl::ParameterSet &  pset)
inline

Definition at line 172 of file sbndcode/sbndcode/CRT/CRTUtils/CRTT0MatchAlg.h.

172  :
173  CRTT0MatchAlg(fhicl::Table<Config>(pset, {})()) {}

Member Function Documentation

std::pair< sbn::crt::CRTHit, double > sbnd::CRTT0MatchAlg::ClosestCRTHit ( detinfo::DetectorPropertiesData const &  detProp,
recob::Track  tpcTrack,
std::pair< double, double >  t0MinMax,
std::vector< sbn::crt::CRTHit crtHits,
int  driftDirection 
)

Definition at line 246 of file sbndcode/sbndcode/CRT/CRTUtils/CRTT0MatchAlg.cc.

247  {
248  matchCand bestmatch = GetClosestCRTHit(detProp, tpcTrack,t0MinMax,crtHits,driftDirection);
249  return std::make_pair(bestmatch.thishit,bestmatch.dca);
250 
251 }
matchCand GetClosestCRTHit(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::pair< double, double > t0MinMax, std::vector< sbn::crt::CRTHit > crtHits, int driftDirection)
auto const detProp
std::pair< sbn::crt::CRTHit, double > sbnd::CRTT0MatchAlg::ClosestCRTHit ( detinfo::DetectorPropertiesData const &  detProp,
recob::Track  tpcTrack,
std::vector< sbn::crt::CRTHit crtHits,
const art::Event &  event 
)

Definition at line 223 of file sbndcode/sbndcode/CRT/CRTUtils/CRTT0MatchAlg.cc.

224  {
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());
228  return ClosestCRTHit(detProp, tpcTrack, hits, crtHits);
229 }
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)
auto const detProp
std::pair< sbn::crt::CRTHit, double > sbnd::CRTT0MatchAlg::ClosestCRTHit ( detinfo::DetectorPropertiesData const &  detProp,
recob::Track  tpcTrack,
std::vector< art::Ptr< recob::Hit >>  hits,
std::vector< sbn::crt::CRTHit crtHits 
)

Definition at line 232 of file sbndcode/sbndcode/CRT/CRTUtils/CRTT0MatchAlg.cc.

233  {
234 
235  auto start = tpcTrack.Vertex<TVector3>();
236  auto end = tpcTrack.End<TVector3>();
237  // Get the drift direction from the TPC
238  int driftDirection = TPCGeoUtil::DriftDirectionFromHits(fGeometryService, hits);
239  std::pair<double, double> xLimits = TPCGeoUtil::XLimitsFromHits(fGeometryService, hits);
240  // Get the allowed t0 range
241  std::pair<double, double> t0MinMax = TrackT0Range(detProp, start.X(), end.X(), driftDirection, xLimits);
242 
243  return ClosestCRTHit(detProp, tpcTrack, t0MinMax, crtHits, driftDirection);
244 }
std::pair< double, double > XLimitsFromHits(const geo::GeometryCore *GeometryService, std::vector< art::Ptr< recob::Hit >> hits)
std::pair< double, double > TrackT0Range(detinfo::DetectorPropertiesData const &detProp, double startX, double endX, int driftDirection, std::pair< double, double > xLimits)
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)
Point_t const & Vertex() const
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
int DriftDirectionFromHits(const geo::GeometryCore *GeometryService, std::vector< art::Ptr< recob::Hit >> hits)
Point_t const & End() const
auto const detProp
double sbnd::CRTT0MatchAlg::DistOfClosestApproach ( detinfo::DetectorPropertiesData const &  detProp,
TVector3  trackPos,
TVector3  trackDir,
sbn::crt::CRTHit  crtHit,
int  driftDirection,
double  t0 
)

Definition at line 82 of file sbndcode/sbndcode/CRT/CRTUtils/CRTT0MatchAlg.cc.

83  {
84 
85  //double minDist = 99999;
86 
87  // Convert the t0 into an x shift
88  double xshift = driftDirection* t0 * detProp.DriftVelocity();
89  trackPos[0] += xshift;
90 
92  geo::Point_t temppt = {trackPos.X(),trackPos.Y(),trackPos.Z()};
94  geo::Vector_t fPosOffsets = fSCE->GetCalPosOffsets(temppt,tpcid.TPC);
95  trackPos[0] += fPosOffsets.X();
96  trackPos[1] += fPosOffsets.Y();
97  trackPos[2] += fPosOffsets.Z();
98  }
99 
100  TVector3 end = trackPos + trackDir;
101 
102  // calculate distance of closest approach (DCA)
103  // default is the distance to the point specified by the CRT hit (Simple DCA)
104  // useBox is the distance to the closest edge of the rectangle with the CRT hit at the center and the sides defined
105  // the position uncertainties on the CRT hits.
106  double thisdca;
107 
108  if (fDCAuseBox) thisdca = CRTCommonUtils::DistToCrtHit(crtHit, trackPos, end);
109  else thisdca = CRTCommonUtils::SimpleDCA(crtHit, trackPos, trackDir);
110  return thisdca;
111 
112 } // CRTT0MatchAlg::DistToOfClosestApproach()
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:164
virtual geo::Vector_t GetCalPosOffsets(geo::Point_t const &point, int const &TPCid) const =0
geo::TPCID PositionToTPCID(geo::Point_t const &point) const
Returns the ID of the TPC at specified location.
double DistToCrtHit(sbn::crt::CRTHit hit, TVector3 start, TVector3 end)
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
double SimpleDCA(sbn::crt::CRTHit hit, TVector3 start, TVector3 direction)
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:406
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.
Definition: geo_vectors.h:184
auto const detProp
matchCand sbnd::CRTT0MatchAlg::GetClosestCRTHit ( detinfo::DetectorPropertiesData const &  detProp,
recob::Track  tpcTrack,
std::pair< double, double >  t0MinMax,
std::vector< sbn::crt::CRTHit crtHits,
int  driftDirection 
)

Definition at line 277 of file sbndcode/sbndcode/CRT/CRTUtils/CRTT0MatchAlg.cc.

278  {
279  auto start = tpcTrack.Vertex<TVector3>();
280  auto end = tpcTrack.End<TVector3>();
281 
282 
283  // ====================== Matching Algorithm ========================== //
284  // std::vector<std::pair<sbn::crt::CRTHit, double>> t0Candidates;
285  std::vector<matchCand> t0Candidates;
286 
287 
288 
289  // Loop over all the CRT hits
290  for(auto &crtHit : crtHits){
291  // Check if hit is within the allowed t0 range
292  double crtTime = -99999.; // units are us
293  if (fTSMode == 1) {
294  crtTime = ((double)(int)crtHit.ts1_ns) * 1e-3 + fTimeCorrection;
295  }
296  else {
297  crtTime = ((double)(int)crtHit.ts0_ns) * 1e-3 + fTimeCorrection;
298  }
299  // if (crtTime>3000) std::cout << "crt hit times " << crtTime << std::endl;
300  // If track is stitched then try all hits
301  if (!((crtTime >= t0MinMax.first - 10. && crtTime <= t0MinMax.second + 10.)
302  || t0MinMax.first == t0MinMax.second)) continue;
303  // cut on CRT hit PE value
304  if (crtHit.peshit<fPEcut) continue;
305  if (crtHit.x_err>fMaxUncert) continue;
306  if (crtHit.y_err>fMaxUncert) continue;
307  if (crtHit.z_err>fMaxUncert) continue;
308 
309  TVector3 crtPoint(crtHit.x_pos, crtHit.y_pos, crtHit.z_pos);
310 
311  //Calculate Track direction
312  std::pair<TVector3, TVector3> startEndDir;
313  // dirmethod=2 is original algorithm, dirmethod=1 is simple algorithm for which SCE corrections are possible
314  if (fDirMethod==2) startEndDir = TrackDirectionAverage(tpcTrack, fTrackDirectionFrac);
315  else startEndDir = TrackDirection(detProp, tpcTrack, fTrackDirectionFrac, crtTime, driftDirection);
316  TVector3 startDir = startEndDir.first;
317  TVector3 endDir = startEndDir.second;
318 
319  // Calculate the distance between the crossing point and the CRT hit, SCE corrections are done inside but dropped
320  double startDist = DistOfClosestApproach(detProp, start, startDir, crtHit, driftDirection, crtTime);
321  double endDist = DistOfClosestApproach(detProp, end, endDir, crtHit, driftDirection, crtTime);
322 
323 
324  double xshift = driftDirection * crtTime * detProp.DriftVelocity();
325  auto thisstart = start;
326  thisstart.SetX(start.X()+xshift);
327  auto thisend = end;
328  thisend.SetX(end.X()+xshift);
329 
330  // repeat SCE correction for endpoints
332  geo::Point_t temppt = {thisstart.X(),thisstart.Y(),thisstart.Z()};
334  geo::Vector_t fPosOffsets = fSCE->GetCalPosOffsets(temppt,tpcid.TPC);
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());
341  tpcid = fGeometryService->PositionToTPCID(temppt);
342  fPosOffsets = fSCE->GetCalPosOffsets(temppt,tpcid.TPC);
343  thisend[0] += fPosOffsets.X();
344  thisend[1] += fPosOffsets.Y();
345  thisend[2] += fPosOffsets.Z();
346  }
347 
348 
349  matchCand newmc = makeNULLmc();
350  if (startDist<fDistanceLimit || endDist<fDistanceLimit) {
351  double distS = (crtPoint-thisstart).Mag();
352  double distE = (crtPoint-thisend).Mag();
353  // std::cout << " distS " << distS << " distE " << distE << std::endl;
354  // std::cout << "startdis " << startDist << " endDist " << endDist << " dca " << std::endl;
355  // std::cout << " doL start " << startDist/distS << " doL end " << endDist/distE << std::endl;
356 
357  if (distS < distE){
358  newmc.thishit = crtHit;
359  newmc.t0= crtTime;
360  newmc.dca = startDist;
361  newmc.extrapLen = distS;
362  t0Candidates.push_back(newmc);
363  }
364  else{
365  newmc.thishit = crtHit;
366  newmc.t0= crtTime;
367  newmc.dca = endDist;
368  newmc.extrapLen = distE;
369  t0Candidates.push_back(newmc);
370  }
371  }
372  }
373 
374 
375  // std::cout << " found " << t0Candidates.size() << " candidates" << std::endl;
376  matchCand bestmatch = makeNULLmc();
377  if(t0Candidates.size() > 0){
378  // Find candidate with shortest DCA or DCA/L value
379  bestmatch=t0Candidates[0];
380  double sin_angle = bestmatch.dca/bestmatch.extrapLen;
381  if (fDCAoverLength) { // Use dca/extrapLen to judge best
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;
386  }
387  }
388  else { // use Dca to judge best
389  for(auto &thisCand : t0Candidates){
390  if (bestmatch.dca<0 ) bestmatch=thisCand;
391  else if (thisCand.dca<bestmatch.dca && thisCand.dca>=0) bestmatch=thisCand;
392  }
393  }
394  }
395 
396  // std::cout << "best match has dca of " << bestmatch.dca << std::endl;
397  return bestmatch;
398 
399 }
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:164
virtual geo::Vector_t GetCalPosOffsets(geo::Point_t const &point, int const &TPCid) const =0
geo::TPCID PositionToTPCID(geo::Point_t const &point) const
Returns the ID of the TPC at specified location.
double DistOfClosestApproach(detinfo::DetectorPropertiesData const &detProp, TVector3 trackPos, TVector3 trackDir, sbn::crt::CRTHit crtHit, int driftDirection, double t0)
Point_t const & Vertex() const
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
std::pair< TVector3, TVector3 > TrackDirectionAverage(recob::Track track, double frac)
do i e
Point_t const & End() const
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:406
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.
Definition: geo_vectors.h:184
auto const detProp
matchCand sbnd::CRTT0MatchAlg::GetClosestCRTHit ( detinfo::DetectorPropertiesData const &  detProp,
recob::Track  tpcTrack,
std::vector< sbn::crt::CRTHit crtHits,
const art::Event &  event 
)

Definition at line 268 of file sbndcode/sbndcode/CRT/CRTUtils/CRTT0MatchAlg.cc.

269  {
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());
273  return GetClosestCRTHit(detProp, tpcTrack, hits, crtHits);
274 }
matchCand GetClosestCRTHit(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::pair< double, double > t0MinMax, std::vector< sbn::crt::CRTHit > crtHits, int driftDirection)
auto const detProp
matchCand sbnd::CRTT0MatchAlg::GetClosestCRTHit ( detinfo::DetectorPropertiesData const &  detProp,
recob::Track  tpcTrack,
std::vector< art::Ptr< recob::Hit >>  hits,
std::vector< sbn::crt::CRTHit crtHits 
)

Definition at line 254 of file sbndcode/sbndcode/CRT/CRTUtils/CRTT0MatchAlg.cc.

255  {
256 
257  auto start = tpcTrack.Vertex<TVector3>();
258  auto end = tpcTrack.End<TVector3>();
259  // Get the drift direction from the TPC
260  int driftDirection = TPCGeoUtil::DriftDirectionFromHits(fGeometryService, hits);
261  std::pair<double, double> xLimits = TPCGeoUtil::XLimitsFromHits(fGeometryService, hits);
262  // Get the allowed t0 range
263  std::pair<double, double> t0MinMax = TrackT0Range(detProp, start.X(), end.X(), driftDirection, xLimits);
264 
265  return GetClosestCRTHit(detProp, tpcTrack, t0MinMax, crtHits, driftDirection);
266 }
std::pair< double, double > XLimitsFromHits(const geo::GeometryCore *GeometryService, std::vector< art::Ptr< recob::Hit >> hits)
matchCand GetClosestCRTHit(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::pair< double, double > t0MinMax, std::vector< sbn::crt::CRTHit > crtHits, int driftDirection)
std::pair< double, double > TrackT0Range(detinfo::DetectorPropertiesData const &detProp, double startX, double endX, int driftDirection, std::pair< double, double > xLimits)
Point_t const & Vertex() const
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
int DriftDirectionFromHits(const geo::GeometryCore *GeometryService, std::vector< art::Ptr< recob::Hit >> hits)
Point_t const & End() const
auto const detProp
void sbnd::CRTT0MatchAlg::reconfigure ( const Config config)

Definition at line 20 of file sbndcode/sbndcode/CRT/CRTUtils/CRTT0MatchAlg.cc.

20  {
21 
22  fMinTrackLength = config.MinTrackLength();
23  fTrackDirectionFrac = config.TrackDirectionFrac();
24  fDistanceLimit = config.DistanceLimit();
25  fTSMode = config.TSMode();
26  fTimeCorrection = config.TimeCorrection();
27  fTPCTrackLabel = config.TPCTrackLabel();
28  fSCEposCorr = config.SCEposCorr();
29  fDirMethod = config.DirMethod();
30  fDCAuseBox = config.DCAuseBox();
31  fDCAoverLength = config.DCAoverLength();
32  fDoverLLimit = config.DoverLLimit();
33  fPEcut = config.PEcut();
34  fMaxUncert = config.MaxUncert();
35  // fDistEndpointAVedge = config.DistEndpointAVedge();
36 
37  return;
38 
39 }
std::pair< double, double > sbnd::CRTT0MatchAlg::T0AndDCAFromCRTHits ( detinfo::DetectorPropertiesData const &  detProp,
recob::Track  tpcTrack,
std::vector< sbn::crt::CRTHit crtHits,
const art::Event &  event 
)

Definition at line 431 of file sbndcode/sbndcode/CRT/CRTUtils/CRTT0MatchAlg.cc.

432  {
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());
436  return T0AndDCAFromCRTHits(detProp, tpcTrack, hits, crtHits);
437 }
std::pair< double, double > T0AndDCAFromCRTHits(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< sbn::crt::CRTHit > crtHits, const art::Event &event)
auto const detProp
std::pair< double, double > sbnd::CRTT0MatchAlg::T0AndDCAFromCRTHits ( detinfo::DetectorPropertiesData const &  detProp,
recob::Track  tpcTrack,
std::vector< art::Ptr< recob::Hit >>  hits,
std::vector< sbn::crt::CRTHit crtHits 
)

Definition at line 439 of file sbndcode/sbndcode/CRT/CRTUtils/CRTT0MatchAlg.cc.

440  {
441 
442  if (tpcTrack.Length() < fMinTrackLength) return std::make_pair(-9999., -9999.);
443 
444  matchCand closestHit = GetClosestCRTHit(detProp, tpcTrack, hits, crtHits);
445 
446  if(closestHit.dca < 0 ) return std::make_pair(-9999., -9999.);
447  if (closestHit.dca < fDistanceLimit && (closestHit.dca/closestHit.extrapLen) < fDoverLLimit) return std::make_pair(closestHit.t0, closestHit.dca);
448 
449  return std::make_pair(-9999., -9999.);
450 
451 
452 }
matchCand GetClosestCRTHit(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::pair< double, double > t0MinMax, std::vector< sbn::crt::CRTHit > crtHits, int driftDirection)
double Length(size_t p=0) const
Access to various track properties.
auto const detProp
double sbnd::CRTT0MatchAlg::T0FromCRTHits ( detinfo::DetectorPropertiesData const &  detProp,
recob::Track  tpcTrack,
std::vector< sbn::crt::CRTHit crtHits,
const art::Event &  event 
)

Definition at line 402 of file sbndcode/sbndcode/CRT/CRTUtils/CRTT0MatchAlg.cc.

403  {
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());
407  return T0FromCRTHits(detProp, tpcTrack, hits, crtHits);
408 }
double T0FromCRTHits(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< sbn::crt::CRTHit > crtHits, const art::Event &event)
auto const detProp
double sbnd::CRTT0MatchAlg::T0FromCRTHits ( detinfo::DetectorPropertiesData const &  detProp,
recob::Track  tpcTrack,
std::vector< art::Ptr< recob::Hit >>  hits,
std::vector< sbn::crt::CRTHit crtHits 
)

Definition at line 410 of file sbndcode/sbndcode/CRT/CRTUtils/CRTT0MatchAlg.cc.

411  {
412 
413  if (tpcTrack.Length() < fMinTrackLength) return -99999;
414 
415  matchCand closestHit = GetClosestCRTHit(detProp, tpcTrack, hits, crtHits);
416  if(closestHit.dca <0) return -99999;
417 
418  double crtTime;
419  if (fTSMode == 1) {
420  crtTime = ((double)(int)closestHit.thishit.ts1_ns) * 1e-3 + fTimeCorrection;
421  }
422  else {
423  crtTime = ((double)(int)closestHit.thishit.ts0_ns) * 1e-3 + fTimeCorrection;
424  }
425  if (closestHit.dca < fDistanceLimit && (closestHit.dca/closestHit.extrapLen) < fDoverLLimit) return crtTime;
426 
427  return -99999;
428 
429 }
matchCand GetClosestCRTHit(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::pair< double, double > t0MinMax, std::vector< sbn::crt::CRTHit > crtHits, int driftDirection)
double Length(size_t p=0) const
Access to various track properties.
do i e
auto const detProp
std::pair< TVector3, TVector3 > sbnd::CRTT0MatchAlg::TrackDirection ( detinfo::DetectorPropertiesData const &  detProp,
recob::Track  track,
double  frac,
double  CRTtime,
int  driftDirection 
)

Definition at line 148 of file sbndcode/sbndcode/CRT/CRTUtils/CRTT0MatchAlg.cc.

148  {
149 
150  size_t nTrackPoints = track.NPoints();
151  int midPt = (int)floor(nTrackPoints*frac);
152  geo::Point_t startP = track.Start();
153  geo::Point_t endP = track.End();
154  geo::Point_t midP = track.LocationAtPoint(midPt);
155 
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()};
161 
162  // Apply the shift depending on which TPC the track is in
163  geo::Point_t fTrackPos = startP;
164  fTrackPos.SetX(startPoint.X());
165  geo::TPCID tpcid = fGeometryService->PositionToTPCID(fTrackPos);
166  geo::Vector_t fPosOffsets = fSCE->GetCalPosOffsets(geo::Point_t{fTrackPos.X(),fTrackPos.Y(),fTrackPos.Z()},tpcid.TPC);
167  startPoint.SetX(fTrackPos.X() + fPosOffsets.X());
168  startPoint.SetY(fTrackPos.Y() + fPosOffsets.Y());
169  startPoint.SetZ(fTrackPos.Z() + fPosOffsets.Z());
170  fTrackPos = endP;
171  fTrackPos.SetX(endPoint.X());
172  tpcid = fGeometryService->PositionToTPCID(fTrackPos);
173  // fPosOffsets = fSCE->GetCalPosOffsets(fTrackPos,tpcid.TPC);
174  fPosOffsets = fSCE->GetCalPosOffsets(geo::Point_t{fTrackPos.X(),fTrackPos.Y(),fTrackPos.Z()},tpcid.TPC);
175  endPoint.SetX(fTrackPos.X() + fPosOffsets.X());
176  endPoint.SetY(fTrackPos.Y() + fPosOffsets.Y());
177  endPoint.SetZ(fTrackPos.Z() + fPosOffsets.Z());
178  fTrackPos = midP;
179  fTrackPos.SetX(midPoint.X());
180  tpcid = fGeometryService->PositionToTPCID(fTrackPos);
181  //fPosOffsets = fSCE->GetCalPosOffsets(fTrackPos,tpcid.TPC);
182  fPosOffsets = fSCE->GetCalPosOffsets(geo::Point_t{fTrackPos.X(),fTrackPos.Y(),fTrackPos.Z()},tpcid.TPC);
183  midPoint.SetX(fTrackPos.X() + fPosOffsets.X());
184  midPoint.SetY(fTrackPos.Y() + fPosOffsets.Y());
185  midPoint.SetZ(fTrackPos.Z() + fPosOffsets.Z());
186  }
187 
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()};
192  norm = endDir.Mag();
193  if (norm>0) endDir *=(1.0/norm);
194 
195  return std::make_pair(startDir, endDir);
196 
197  } // CRTT0MatchAlg::TrackDirection()
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:164
virtual geo::Vector_t GetCalPosOffsets(geo::Point_t const &point, int const &TPCid) const =0
Point_t const & LocationAtPoint(size_t i) const
geo::TPCID PositionToTPCID(geo::Point_t const &point) const
Returns the ID of the TPC at specified location.
Point_t const & Start() const
Access to track position at different points.
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
auto norm(Vector const &v)
Return norm of the specified vector.
Point_t const & End() const
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:406
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.
Definition: geo_vectors.h:184
auto const detProp
std::pair< TVector3, TVector3 > sbnd::CRTT0MatchAlg::TrackDirectionAverage ( recob::Track  track,
double  frac 
)

Definition at line 115 of file sbndcode/sbndcode/CRT/CRTUtils/CRTT0MatchAlg.cc.

116  {
117  // Calculate direction as an average over directions
118  size_t nTrackPoints = track.NumberTrajectoryPoints();
119  recob::TrackTrajectory trajectory = track.Trajectory();
120  std::vector<geo::Vector_t> validDirections;
121  for(size_t i = 0; i < nTrackPoints; i++){
123  validDirections.push_back(track.DirectionAtPoint(i));
124  }
125 
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++){
131  geo::Vector_t dirStart = validDirections.at(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();
139  }
140  TVector3 startDir = {-xTotStart/endPoint, -yTotStart/endPoint, -zTotStart/endPoint};
141  TVector3 endDir = {xTotEnd/endPoint, yTotEnd/endPoint, zTotEnd/endPoint};
142 
143  return std::make_pair(startDir, endDir);
144 
145 } // CRTT0MatchAlg::TrackDirectionAverage()
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:164
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
PointFlags_t const & FlagsAtPoint(size_t i) const
Returns the flags for the specified trajectory point.
A trajectory in space reconstructed from hits.
static constexpr HitIndex_t InvalidHitIndex
Value marking an invalid hit index.
Vector_t DirectionAtPoint(size_t i) const
std::pair< TVector3, TVector3 > sbnd::CRTT0MatchAlg::TrackDirectionAverageFromPoints ( recob::Track  track,
double  frac 
)

Definition at line 199 of file sbndcode/sbndcode/CRT/CRTUtils/CRTT0MatchAlg.cc.

199  {
200 
201  // Calculate direction as an average over directions
202  size_t nTrackPoints = track.NumberTrajectoryPoints();
203  recob::TrackTrajectory trajectory = track.Trajectory();
204  std::vector<TVector3> validPoints;
205  for(size_t i = 0; i < nTrackPoints; i++){
206  if(trajectory.FlagsAtPoint(i) != recob::TrajectoryPointFlags::InvalidHitIndex) continue;
207  validPoints.push_back(track.LocationAtPoint<TVector3>(i));
208  }
209 
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));
214 
215  return std::make_pair(startDir.Unit(), endDir.Unit());
216 
217 } // CRTT0MatchAlg::TrackDirectionAverageFromPoints()
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.
PointFlags_t const & FlagsAtPoint(size_t i) const
Returns the flags for the specified trajectory point.
A trajectory in space reconstructed from hits.
static constexpr HitIndex_t InvalidHitIndex
Value marking an invalid hit index.
std::pair< double, double > sbnd::CRTT0MatchAlg::TrackT0Range ( detinfo::DetectorPropertiesData const &  detProp,
double  startX,
double  endX,
int  driftDirection,
std::pair< double, double >  xLimits 
)

Definition at line 54 of file sbndcode/sbndcode/CRT/CRTUtils/CRTT0MatchAlg.cc.

55  {
56 
57  // If track is stitched return zeros
58  if(driftDirection == 0) return std::make_pair(0, 0);
59 
60  //std::pair<double, double> result; // unused
61  double Vd = driftDirection * detProp.DriftVelocity();
62 
63  // Shift the most postive end to the most positive limit
64  double maxX = std::max(startX, endX);
65  double maxLimit = std::max(xLimits.first, xLimits.second);
66  double maxShift = maxLimit - maxX;
67  // Shift the most negative end to the most negative limit
68  double minX = std::min(startX, endX);
69  double minLimit = std::min(xLimits.first, xLimits.second);
70  double minShift = minLimit - minX;
71  // Convert to time
72  double t0max = maxShift/Vd;
73  double t0min = minShift/Vd;
74 
75  // if (t0min>2500) std::cout << " t0 min " << t0min << " t0max " << t0max << std::endl;
76  return std::make_pair(std::min(t0min, t0max), std::max(t0min, t0max));
77 
78 
79 } // CRTT0MatchAlg::TrackT0Range()
auto const detProp

Member Data Documentation

bool sbnd::CRTT0MatchAlg::fDCAoverLength
private
bool sbnd::CRTT0MatchAlg::fDCAuseBox
private
int sbnd::CRTT0MatchAlg::fDirMethod
private
double sbnd::CRTT0MatchAlg::fDistanceLimit
private
double sbnd::CRTT0MatchAlg::fDoverLLimit
private
geo::GeometryCore const* sbnd::CRTT0MatchAlg::fGeometryService
private
double sbnd::CRTT0MatchAlg::fMaxUncert
private
double sbnd::CRTT0MatchAlg::fMinTrackLength
private
double sbnd::CRTT0MatchAlg::fPEcut
private
spacecharge::SpaceCharge const* sbnd::CRTT0MatchAlg::fSCE
private
bool sbnd::CRTT0MatchAlg::fSCEposCorr
private
double sbnd::CRTT0MatchAlg::fTimeCorrection
private
art::InputTag sbnd::CRTT0MatchAlg::fTPCTrackLabel
private
double sbnd::CRTT0MatchAlg::fTrackDirectionFrac
private
int sbnd::CRTT0MatchAlg::fTSMode
private

The documentation for this class was generated from the following files: