All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
icaruscode/icaruscode/CRT/CRTUtils/CRTT0MatchAlg.h
Go to the documentation of this file.
1 #ifndef CRTT0MATCHALG_H_SEEN
2 #define CRTT0MATCHALG_H_SEEN
3 
4 
5 ///////////////////////////////////////////////
6 // CRTT0MatchAlg.h
7 //
8 // Functions for CRT t0 matching
9 // T Brooks (tbrooks@fnal.gov), November 2018
10 ///////////////////////////////////////////////
11 
12 // framework
13 #include "art/Framework/Principal/Event.h"
14 #include "art/Framework/Core/ModuleMacros.h"
15 #include "fhiclcpp/ParameterSet.h"
16 #include "art/Framework/Principal/Handle.h"
17 #include "canvas/Persistency/Common/Ptr.h"
18 #include "canvas/Persistency/Common/PtrVector.h"
19 #include "art/Framework/Services/Registry/ServiceHandle.h"
20 #include "messagefacility/MessageLogger/MessageLogger.h"
21 #include "canvas/Persistency/Common/FindManyP.h"
22 
23 // LArSoft
35 
36 // Utility libraries
37 #include "messagefacility/MessageLogger/MessageLogger.h"
38 #include "fhiclcpp/ParameterSet.h"
39 #include "fhiclcpp/types/Table.h"
40 #include "fhiclcpp/types/Atom.h"
41 #include "cetlib/pow.h" // cet::sum_of_squares()
42 
45 //#include "icaruscode/Geometry/GeometryWrappers/TPCGeoAlg.h"
47 
48 // c++
49 #include <iostream>
50 #include <stdio.h>
51 #include <sstream>
52 #include <vector>
53 #include <map>
54 #include <utility>
55 #include <cmath>
56 #include <memory>
57 
58 // ROOT
59 #include "TVector3.h"
60 #include "TGeoManager.h"
61 
62 
63 namespace icarus{
64 
65 
66  struct matchCand {
68  double t0;
69  double dca;
70  double extrapLen;
71  };
72 
73 
74  class CRTT0MatchAlg {
75  public:
76 
77  explicit CRTT0MatchAlg(const fhicl::ParameterSet& pset);
78  CRTT0MatchAlg();
79 
80  void reconfigure(const fhicl::ParameterSet& pset);
81 
82  // Utility function that determines the possible x range of a track
83  std::pair<double, double> TrackT0Range(detinfo::DetectorPropertiesData const& detProp,
84  double startX, double endX, int driftDirection, std::pair<double, double> xLimits);
85 
86  // Calculate the distance of closest approach (DCA) between the end of a track and a crt hit
88  TVector3 trackPos, TVector3 trackDir, sbn::crt::CRTHit crtHit, int driftDirection, double t0);
89 
90  std::pair<TVector3, TVector3> TrackDirectionAverage(recob::Track track, double frac);
91 
92  std::pair<TVector3, TVector3> TrackDirection(detinfo::DetectorPropertiesData const& detProp,recob::Track track,
93  double frac, double CRTtime, int driftDirection);
94 
95  std::pair<TVector3, TVector3> TrackDirectionAverageFromPoints(recob::Track track, double frac);
96 
97  // Keeping ClosestCRTHit function for backwards compatibility
98  // *** use GetClosestCRTHit instead
99  std::pair<sbn::crt::CRTHit, double> ClosestCRTHit(detinfo::DetectorPropertiesData const& detProp,
100  recob::Track tpcTrack, std::pair<double, double> t0MinMax,
101  std::vector<sbn::crt::CRTHit> crtHits, int driftDirection, uint64_t trigger_timestamp);
102 
103  std::vector<std::pair<sbn::crt::CRTHit, double> >ClosestCRTHit(detinfo::DetectorPropertiesData const& detProp,
104  recob::Track tpcTrack, std::vector<sbn::crt::CRTHit> crtHits,
105  const art::Event& event, uint64_t trigger_timestamp);
106 
107  std::pair<sbn::crt::CRTHit, double> ClosestCRTHit(detinfo::DetectorPropertiesData const& detProp,
108  recob::Track tpcTrack, std::vector<art::Ptr<recob::Hit>> hits,
109  std::vector<sbn::crt::CRTHit> crtHits, uint64_t trigger_timestamp);
110 
111  // Return the closest CRT hit to a TPC track and the DCA
113  recob::Track tpcTrack, std::pair<double, double> t0MinMax,
114  std::vector<sbn::crt::CRTHit> crtHits, int driftDirection, uint64_t& trigger_timestamp);
115 
116  std::vector<matchCand> GetClosestCRTHit(detinfo::DetectorPropertiesData const& detProp,
117  recob::Track tpcTrack, std::vector<sbn::crt::CRTHit> crtHits,
118  const art::Event& event, uint64_t trigger_timestamp);
119 
121  recob::Track tpcTrack, std::vector<art::Ptr<recob::Hit>> hits,
122  std::vector<sbn::crt::CRTHit> crtHits, uint64_t trigger_timestamp);
123 
124  // Match track to T0 from CRT hits
125  std::vector<double> T0FromCRTHits(detinfo::DetectorPropertiesData const& detProp,
126  recob::Track tpcTrack, std::vector<sbn::crt::CRTHit> crtHits,
127  const art::Event& event, uint64_t trigger_timestamp);
128 
129  double T0FromCRTHits(detinfo::DetectorPropertiesData const& detProp,
130  recob::Track tpcTrack, std::vector<art::Ptr<recob::Hit>> hits,
131  std::vector<sbn::crt::CRTHit> crtHits, uint64_t& trigger_timestamp);
132 
133  // Match track to T0 from CRT hits, also return the DCA
134  std::vector<std::pair<double, double> > T0AndDCAFromCRTHits(detinfo::DetectorPropertiesData const& detProp,
135  recob::Track tpcTrack, std::vector<sbn::crt::CRTHit> crtHits,
136  const art::Event& event, uint64_t trigger_timestamp);
137 
138  std::pair<double, double> T0AndDCAFromCRTHits(detinfo::DetectorPropertiesData const& detProp,
139  recob::Track tpcTrack, std::vector<art::Ptr<recob::Hit>> hits,
140  std::vector<sbn::crt::CRTHit> crtHits, uint64_t& trigger_timestamp);
141 
142  // Simple distance of closest approach between infinite track and centre of hit
143  double SimpleDCA(sbn::crt::CRTHit hit, TVector3 start, TVector3 direction);
144 
145  // Minimum distance from infinite track to CRT hit assuming that hit is a 2D square
146  double DistToCrtHit(sbn::crt::CRTHit hit, TVector3 start, TVector3 end);
147 
148  // Distance between infinite line (2) and segment (1)
149  // http://geomalgorithms.com/a07-_distance.html
150  double LineSegmentDistance(TVector3 start1, TVector3 end1, TVector3 start2, TVector3 end2);
151 
152  // Intersection between axis-aligned cube and infinite line
153  // (https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-box-intersection)
154  std::pair<TVector3, TVector3> CubeIntersection(TVector3 min, TVector3 max, TVector3 start, TVector3 end);
155 
156  private:
157 
160 
164  int fTSMode;
170  double fDoverLLimit;
171  double fPEcut;
172  double fMaxUncert;
173  // double fDistEndpointAVedge;
174  std::vector<art::InputTag> fTPCTrackLabel;
175 
176  };
177 
178 
179 }
180 #endif
std::pair< TVector3, TVector3 > TrackDirectionAverage(recob::Track track, double frac)
Declaration of signal hit object.
process_name use argoneut_mc_hitfinder track
void reconfigure(const fhicl::ParameterSet &pset)
process_name hit
Definition: cheaterreco.fcl:51
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)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
Access the description of detector geometry.
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)
object containing MC truth information necessary for making RawDigits and doing back tracking ...
double LineSegmentDistance(TVector3 start1, TVector3 end1, TVector3 start2, TVector3 end2)
art framework interface to geometry description for auxiliary detectors
std::pair< TVector3, TVector3 > TrackDirectionAverageFromPoints(recob::Track track, double frac)
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
Description of geometry of one entire detector.
double DistToCrtHit(sbn::crt::CRTHit hit, TVector3 start, TVector3 end)
Provides recob::Track data product.
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)
double SimpleDCA(sbn::crt::CRTHit hit, TVector3 start, TVector3 direction)
double DistOfClosestApproach(detinfo::DetectorPropertiesData const &detProp, TVector3 trackPos, TVector3 trackDir, sbn::crt::CRTHit crtHit, int driftDirection, double t0)
std::pair< TVector3, TVector3 > TrackDirection(detinfo::DetectorPropertiesData const &detProp, recob::Track track, double frac, double CRTtime, int driftDirection)
art framework interface to geometry description
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:
std::pair< TVector3, TVector3 > CubeIntersection(TVector3 min, TVector3 max, TVector3 start, TVector3 end)