All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sbndcode/sbndcode/CosmicId/Algs/CpaCrossCosmicIdAlg.cc
Go to the documentation of this file.
1 #include "CpaCrossCosmicIdAlg.h"
2 
4 
5 namespace sbnd{
6 
8 
9  this->reconfigure(config);
10 
11 }
12 
13 
15 
16 }
17 
18 
20 
21 }
22 
23 
25 
29  fMinX = config.FiducialCuts().MinX();
30  fMinY = config.FiducialCuts().MinY();
31  fMinZ = config.FiducialCuts().MinZ();
32  fMaxX = config.FiducialCuts().MaxX();
33  fMaxY = config.FiducialCuts().MaxY();
34  fMaxZ = config.FiducialCuts().MaxZ();
35  fBeamTimeMin = config.BeamTimeLimits().BeamTimeMin();
36  fBeamTimeMax = config.BeamTimeLimits().BeamTimeMax();
37 
38  return;
39 }
40 
41 // Calculate the time by stitching tracks across the CPA
43  recob::Track t1, std::vector<recob::Track> tracks){
44 
45  std::vector<std::pair<double, std::pair<double, bool>>> matchCandidates;
46  double matchedTime = -99999;
47  std::pair<double, bool> returnVal = std::make_pair(matchedTime, false);
48 
49  TVector3 trk1Front = t1.Vertex<TVector3>();
50  TVector3 trk1Back = t1.End<TVector3>();
51  double closestX1 = std::min(std::abs(trk1Front.X()), std::abs(trk1Back.X()));
52 
53  // Loop over all tracks in other TPC
54  for(auto & track : tracks){
55 
56  TVector3 trk2Front = track.Vertex<TVector3>();
57  TVector3 trk2Back = track.End<TVector3>();
58  double closestX2 = std::min(std::abs(trk2Front.X()), std::abs(trk2Back.X()));
59 
60  // Try to match if their ends have similar x positions
61  if(std::abs(closestX1-closestX2) > fCpaXDifference) continue;
62 
63  // Find which point is closest to CPA
64  TVector3 t1Pos = trk1Front;
65  TVector3 t1PosEnd = trk1Back;
66  TVector3 t1Dir = t1.VertexDirection<TVector3>();
67  if(std::abs(trk1Back.X()) == closestX1){
68  t1Pos = trk1Back;
69  t1PosEnd = trk1Front;
70  t1Dir = t1.EndDirection<TVector3>();
71  }
72 
73  TVector3 t2Pos = trk2Front;
74  TVector3 t2PosEnd = trk2Back;
75  TVector3 t2Dir = track.VertexDirection<TVector3>();
76  if(std::abs(trk2Back.X()) == closestX2){
77  t2Pos = trk2Back;
78  t2PosEnd = trk2Front;
79  t2Dir = track.EndDirection<TVector3>();
80  }
81 
82  // Calculate the angle between the tracks
83  double trkCos = std::abs(t1Dir.Dot(t2Dir));
84  // Calculate the distance between the tracks at the middle of the CPA
85  t1Pos[0] = 0.;
86  t2Pos[0] = 0.;
87  double dist = (t1Pos-t2Pos).Mag();
88 
89  // Does the track enter and exit the fiducial volume when merged?
90  geo::Point_t mergeStart {t1PosEnd.X(), t1PosEnd.Y(), t1PosEnd.Z()};
91  geo::Point_t mergeEnd {t2PosEnd.X(), t2PosEnd.Y(), t2PosEnd.Z()};
92  bool exits = false;
93  if(!fTpcGeo.InFiducial(mergeStart, fMinX, fMinY, fMinZ, fMaxX, fMaxY, fMaxZ)
94  && !fTpcGeo.InFiducial(mergeEnd, fMinX, fMinY, fMinZ, fMaxX, fMaxY, fMaxZ)) exits = true;
95 
96  // If the distance and angle are within the acceptable limits then record candidate
97  if(dist < fCpaStitchDistance && trkCos > cos(TMath::Pi() * fCpaStitchAngle / 180.)){
98  matchCandidates.push_back(std::make_pair(trkCos, std::make_pair(closestX1, exits)));
99  }
100  }
101 
102  // Choose the candidate with the smallest angle
103  if(matchCandidates.size() > 0){
104  std::sort(matchCandidates.begin(), matchCandidates.end(), [](auto& left, auto& right){
105  return left.first < right.first;});
106  double shiftX = matchCandidates[0].second.first;
107  matchedTime = -((shiftX - fTpcGeo.CpaWidth())/detProp.DriftVelocity()); //subtract CPA width
108  returnVal = std::make_pair(matchedTime, matchCandidates[0].second.second);
109  }
110 
111  return returnVal;
112 }
113 
114 // Tag tracks as cosmics from CPA stitching t0
116  recob::Track track, std::vector<recob::Track> tracks, art::FindManyP<recob::Hit> hitAssoc){
117 
118  // Sort tracks by tpc
119  std::vector<recob::Track> tpcTracksTPC0;
120  std::vector<recob::Track> tpcTracksTPC1;
121  // Loop over the tpc tracks
122  for(auto const& tpcTrack : tracks){
123  // Work out where the associated wire hits were detected
124  std::vector<art::Ptr<recob::Hit>> hits = hitAssoc.at(tpcTrack.ID());
125  int tpc = fTpcGeo.DetectedInTPC(hits);
126  double startX = tpcTrack.Start().X();
127  double endX = tpcTrack.End().X();
128  if(tpc == 0 && !(startX>0 || endX>0)) tpcTracksTPC0.push_back(tpcTrack);
129  else if(tpc == 1 && !(startX<0 || endX<0)) tpcTracksTPC1.push_back(tpcTrack);
130  }
131 
132  std::vector<art::Ptr<recob::Hit>> hits = hitAssoc.at(track.ID());
133  int tpc = fTpcGeo.DetectedInTPC(hits);
134 
135  double stitchTime = -99999;
136  bool stitchExit = false;
137  // Try to match tracks from CPA crossers
138  if(tpc == 0){
139  std::pair<double, bool> stitchResults = T0FromCpaStitching(detProp, track, tpcTracksTPC1);
140  stitchTime = stitchResults.first;
141  stitchExit = stitchResults.second;
142  }
143  else if(tpc == 1){
144  std::pair<double, bool> stitchResults = T0FromCpaStitching(detProp, track, tpcTracksTPC0);
145  stitchTime = stitchResults.first;
146  stitchExit = stitchResults.second;
147  }
148 
149  // If tracks are stitched, get time and remove any outside of beam window
150  if(stitchTime != -99999 && (stitchTime < fBeamTimeMin || stitchTime > fBeamTimeMax || stitchExit)) return true;
151 
152  return false;
153 
154 }
155 
156 }
ClusterModuleLabel join with tracks
bool CpaCrossCosmicId(detinfo::DetectorPropertiesData const &detProp, recob::Track track, std::vector< recob::Track > tracks, art::FindManyP< recob::Hit > hitAssoc)
walls no right
Definition: selectors.fcl:105
Vector_t VertexDirection() const
process_name use argoneut_mc_hitfinder track
T abs(T value)
Point_t const & Vertex() const
std::pair< double, bool > T0FromCpaStitching(detinfo::DetectorPropertiesData const &detProp, recob::Track t1, std::vector< recob::Track > tracks)
walls no left
Definition: selectors.fcl:105
double DriftVelocity(double efield=0., double temperature=0.) const
cm/us
int DetectedInTPC(std::vector< art::Ptr< recob::Hit >> hits)
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
Vector_t EndDirection() const
Point_t const & End() const
stream1 can override from command line with o or output services user sbnd
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
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a &quot;fitted&quot; track:
bool InFiducial(geo::Point_t point, double fiducial)