All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sbnana/sbnanalysis/ana/SBNOscReco/CosmicIDAlgs/ApaCrossCosmicIdAlg.cc
Go to the documentation of this file.
1 #include "ApaCrossCosmicIdAlg.h"
2 
3 namespace ana {
4 
6  this->reconfigure(manager, config);
7 }
8 
9 
11  fDetectorProperties = NULL;
12 }
13 
15 
18  fGeometry = manager.GetGeometryProvider();
19  fDistanceLimit = config.DistanceLimit();
21  fBeamTimeMin = config.BeamTimeLimits().BeamTimeMin();
22  fBeamTimeMax = config.BeamTimeLimits().BeamTimeMax();
23 
24  return;
25 }
26 
27 
28 // Get the minimum distance from track to APA for different times
29 std::pair<double, double> ApaCrossCosmicIdAlg::MinApaDistance(const recob::Track &track, std::vector<double> &t0List, geo::TPCID &tpcid){
30  double crossTime = -99999;
31 
32  double minDist = 99999;
33  double startX = track.Vertex().X();
34  double endX = track.End().X();
35  geo::Point_t point = track.Vertex();
36 
37 
38  // if TPCID is invalid, return null values
39  if (!tpcid) {
40  return std::make_pair(minDist, crossTime);
41  }
42 
43  // get the TPC drift direction
44  const geo::TPCGeo &tpc = fGeometry->GetElement(tpcid);
45  int drift_direction_x = tpc.DriftDirection() == geo::driftdir::kPos ? 1 : -1;
46 
47  // get the location of the APA in the TPC -- should be the x-position downstream of the drift direction
48  double apa_X = (drift_direction_x == 1) ? tpc.MaxX() : tpc.MinX();
49 
50  // Don't try to shift tracks near the APA (may give artificially small distances)
51  if (std::abs(startX - apa_X) < fMaxApaDistance || std::abs(endX - apa_X) < fMaxApaDistance)
52  return std::make_pair(minDist, crossTime);
53 
54  // if drift direction positive use start/end with highest X
55  if (drift_direction_x == 1) {
56  point = endX < startX ? track.End() : track.Vertex();
57  }
58  else {
59  point = endX > startX ? track.End() : track.Vertex();
60  }
61 
62  // Shift track by all t0's
63  for(auto const& t0 : t0List){
64  // If particle crosses the APA before t = 0 the crossing point won't be reconstructed
65  if(t0 < 0) continue;
66  double shift = t0 * fDetectorProperties->DriftVelocity() * drift_direction_x;
67  double shiftedX = point.X() + shift;
68 
69  //Check track still in TPC
70  if (shiftedX - apa_X > fDistanceLimit) continue;
71  // Calculate distance between start/end and APA
72  double dist = std::abs(shiftedX - apa_X);
73  if(dist < minDist) {
74  minDist = dist;
75  crossTime = t0;
76  }
77  }
78 
79  return std::make_pair(minDist, crossTime);
80 
81 }
82 
83 
84 // Get time by matching tracks which cross the APA
85 double ApaCrossCosmicIdAlg::T0FromApaCross(const recob::Track &track, std::vector<art::Ptr<recob::Hit>> hits, std::map<geo::CryostatID, std::vector<double>> &t_zeros) {
86  // Determine the TPC from hit collection
88  if (tpc) {
89  // Get the minimum distance to the APA and corresponding time
90  std::pair<double, double> min = MinApaDistance(track, t_zeros.at(tpc), tpc);
91  // Check the distance is within allowed limit
92  if(min.first < fDistanceLimit) return min.second;
93  }
94 
95  return -99999;
96 
97 }
98 
99 // Get the distance from track to APA at fixed time
100 double ApaCrossCosmicIdAlg::ApaDistance(recob::Track track, double t0, std::vector<art::Ptr<recob::Hit>> hits){
101 
102  std::vector<double> t0List {t0};
103  // Determine the TPC from hit collection
105  // Get the distance to the APA at the given time
106  std::pair<double, double> min = MinApaDistance(track, t0List, tpc);
107  return min.first;
108 
109 }
110 
111 // Tag tracks with times outside the beam
112 bool ApaCrossCosmicIdAlg::ApaCrossCosmicId(const recob::Track &track, std::vector<art::Ptr<recob::Hit>> &hits, std::map<geo::CryostatID, std::vector<double>> &t_zeros) {
113  double crossTimeThrough = T0FromApaCross(track, hits, t_zeros);
114  // If the matched time is outside of the beam time then tag as a cosmic
115  if(crossTimeThrough != -99999 && (crossTimeThrough < fBeamTimeMin || crossTimeThrough > fBeamTimeMax)) return true;
116  return false;
117 }
118 
119 }
ApaCrossCosmicIdAlg(const core::ProviderManager &manager, const Config &config)
void reconfigure(const core::ProviderManager &manager, const Config &config)
CryostatGeo const & GetElement(geo::CryostatID const &cryoid) const
geo::TPCID DetectedInTPC(const std::vector< art::Ptr< recob::Hit >> &hits)
Definition: Util.cc:30
Drift towards positive values.
Definition: geo_types.h:159
double MinX() const
Returns the world x coordinate of the start of the box.
Definition: BoxBoundedGeo.h:88
const detinfo::DetectorPropertiesStandard * GetDetectorPropertiesProvider() const
Geometry information for a single TPC.
Definition: TPCGeo.h:38
std::pair< double, double > MinApaDistance(const recob::Track &track, std::vector< double > &t0List, geo::TPCID &tpcid)
double MaxX() const
Returns the world x coordinate of the end of the box.
Definition: BoxBoundedGeo.h:91
bool ApaCrossCosmicId(const recob::Track &track, std::vector< art::Ptr< recob::Hit >> &hits, std::map< geo::CryostatID, std::vector< double >> &t_zeros)
process_name use argoneut_mc_hitfinder track
process_name opflashCryoW ana
shift
Definition: fcl_checks.sh:26
const geo::GeometryCore * GetGeometryProvider() const
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
Interface to LArSoft services.
T abs(T value)
Point_t const & Vertex() const
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
DriftDirection_t DriftDirection() const
Returns an enumerator value describing the drift direction.
Definition: TPCGeo.h:144
double ApaDistance(recob::Track track, double t0, std::vector< art::Ptr< recob::Hit >> hits)
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)
Point_t const & End() const
double T0FromApaCross(const recob::Track &track, std::vector< art::Ptr< recob::Hit >> hits, std::map< geo::CryostatID, std::vector< double >> &t_zeros)
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:
The data type to uniquely identify a cryostat.
Definition: geo_types.h:190