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