All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sbndcode/sbndcode/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
27 #include "larcore/CoreUtils/ServiceUtil.h" // lar::providerFrom()
36 
37 // Utility libraries
38 #include "messagefacility/MessageLogger/MessageLogger.h"
39 #include "fhiclcpp/ParameterSet.h"
40 #include "fhiclcpp/types/Table.h"
41 #include "fhiclcpp/types/Atom.h"
42 #include "cetlib/pow.h" // cet::sum_of_squares()
43 
48 
49 // c++
50 #include <iostream>
51 #include <stdio.h>
52 #include <sstream>
53 #include <vector>
54 #include <map>
55 #include <utility>
56 #include <cmath>
57 #include <memory>
58 
59 // ROOT
60 #include "TVector3.h"
61 #include "TGeoManager.h"
62 
63 
64 namespace sbnd{
65 
66 
67  struct matchCand {
69  double t0;
70  double dca;
71  double extrapLen;
72  };
73 
74 
75  class CRTT0MatchAlg {
76  public:
77 
78  struct Config {
79  using Name = fhicl::Name;
80  using Comment = fhicl::Comment;
81 
82  fhicl::Atom<double> MinTrackLength {
83  Name("MinTrackLength"),
84  Comment(""),
85  20.0
86  };
87 
88  fhicl::Atom<double> TrackDirectionFrac {
89  Name("TrackDirectionFrac"),
90  Comment(""),
91  0.5
92  };
93 
94  fhicl::Atom<int> TSMode {
95  Name("TSMode"),
96  Comment(""),
97  1 /* Value for SBND */
98  };
99 
100  fhicl::Atom<double> TimeCorrection {
101  Name("TimeCorrection"),
102  Comment(""),
103  0.
104  };
105 
106  fhicl::Atom<double> DistanceLimit {
107  Name("DistanceLimit"),
108  Comment(""),
109  100.
110  };
111 
112  fhicl::Atom<art::InputTag> TPCTrackLabel {
113  Name("TPCTrackLabel"),
114  Comment("")
115  };
116 
117 
118  fhicl::Atom<int> DirMethod {
119  Name("DirMethod"),
120  Comment("1=endpoints (default), 2=average; must use endpoints if applying SCE position corrections"),
121  1
122  };
123 
124  fhicl::Atom<bool> SCEposCorr {
125  Name("SCEposCorr"),
126  Comment("true=do correction before extrapolating track (default), false=skip correction"),
127  true
128  };
129 
130  fhicl::Atom<bool> DCAuseBox {
131  Name("DCAuseBox"),
132  Comment("false = distance to point (default), true = distance to box edge"),
133  false
134  };
135 
136  fhicl::Atom<bool> DCAoverLength {
137  Name("DCAoverLength"),
138  Comment("false = use DCA to select closest CRT hit (default), true = use DCA/extrapolation_length"),
139  false
140  };
141 
142  fhicl::Atom<double> DoverLLimit {
143  Name("DoverLLimit"),
144  Comment(""),
145  1.
146  };
147 
148  fhicl::Atom<double> PEcut {
149  Name("PEcut"),
150  Comment("Only consider CRT hits with PE values larger than this"),
151  0.0
152  };
153 
154  fhicl::Atom<double> MaxUncert {
155  Name("MaxUncert"),
156  Comment("Only consider CRT hits with position uncertainties below this value (cm)"),
157  1000.0
158  };
159 
160  /* fhicl::Atom<double> DistEndpointAVedge { */
161  /* Name("DistEndpointAVedge"), */
162  /* Comment("Max distance allowed from track endpoint to edge of FV along track extrapolation to CRT hit (cm)"), */
163  /* 200.0 */
164  /* }; */
165 
166  };
167 
168 
169  CRTT0MatchAlg(const Config& config);
170  CRTT0MatchAlg(const Config& config, geo::GeometryCore const *GeometryService, spacecharge::SpaceCharge const* SCE);
171 
172  CRTT0MatchAlg(const fhicl::ParameterSet& pset) :
173  CRTT0MatchAlg(fhicl::Table<Config>(pset, {})()) {}
174 
175  CRTT0MatchAlg(const fhicl::ParameterSet& pset, geo::GeometryCore const *GeometryService, spacecharge::SpaceCharge const* SCE) :
176  CRTT0MatchAlg(fhicl::Table<Config>(pset, {})(), GeometryService, SCE) {}
177 
178  CRTT0MatchAlg();
179 
180  void reconfigure(const Config& config);
181 
182 
183 
184  // Utility function that determines the possible x range of a track
185  std::pair<double, double> TrackT0Range(detinfo::DetectorPropertiesData const& detProp,
186  double startX, double endX, int driftDirection, std::pair<double, double> xLimits);
187 
188  // Calculate the distance of closest approach (DCA) between the end of a track and a crt hit
190  TVector3 trackPos, TVector3 trackDir, sbn::crt::CRTHit crtHit, int driftDirection, double t0);
191 
192  std::pair<TVector3, TVector3> TrackDirectionAverage(recob::Track track, double frac);
193  std::pair<TVector3, TVector3> TrackDirection(detinfo::DetectorPropertiesData const& detProp,recob::Track track, double frac, double CRTtime, int driftDirection);
194  std::pair<TVector3, TVector3> TrackDirectionAverageFromPoints(recob::Track track, double frac);
195 
196  // Keeping ClosestCRTHit function for backwards compatibility
197  // *** use GetClosestCRTHit instead
198  std::pair<sbn::crt::CRTHit, double> ClosestCRTHit(detinfo::DetectorPropertiesData const& detProp,
199  recob::Track tpcTrack, std::pair<double, double> t0MinMax, std::vector<sbn::crt::CRTHit> crtHits, int driftDirection);
200  std::pair<sbn::crt::CRTHit, double> ClosestCRTHit(detinfo::DetectorPropertiesData const& detProp,
201  recob::Track tpcTrack, std::vector<sbn::crt::CRTHit> crtHits, const art::Event& event);
202  std::pair<sbn::crt::CRTHit, double> ClosestCRTHit(detinfo::DetectorPropertiesData const& detProp,
203  recob::Track tpcTrack, std::vector<art::Ptr<recob::Hit>> hits, std::vector<sbn::crt::CRTHit> crtHits);
204 
205  // Return the closest CRT hit to a TPC track and the DCA
207  recob::Track tpcTrack, std::pair<double, double> t0MinMax, std::vector<sbn::crt::CRTHit> crtHits, int driftDirection);
208 
210  recob::Track tpcTrack, std::vector<sbn::crt::CRTHit> crtHits, const art::Event& event);
211 
213  recob::Track tpcTrack, std::vector<art::Ptr<recob::Hit>> hits, std::vector<sbn::crt::CRTHit> crtHits);
214 
215  // Match track to T0 from CRT hits
217  recob::Track tpcTrack, std::vector<sbn::crt::CRTHit> crtHits, const art::Event& event);
219  recob::Track tpcTrack, std::vector<art::Ptr<recob::Hit>> hits, std::vector<sbn::crt::CRTHit> crtHits);
220 
221  // Match track to T0 from CRT hits, also return the DCA
222  std::pair<double, double> T0AndDCAFromCRTHits(detinfo::DetectorPropertiesData const& detProp,
223  recob::Track tpcTrack, std::vector<sbn::crt::CRTHit> crtHits, const art::Event& event);
224  std::pair<double, double> T0AndDCAFromCRTHits(detinfo::DetectorPropertiesData const& detProp,
225  recob::Track tpcTrack, std::vector<art::Ptr<recob::Hit>> hits, std::vector<sbn::crt::CRTHit> crtHits);
226 
227 
228  private:
229 
232 
236  int fTSMode;
242  double fDoverLLimit;
243  double fPEcut;
244  double fMaxUncert;
245  // double fDistEndpointAVedge;
246 
247  art::InputTag fTPCTrackLabel;
248 
249  };
250 
251 
252 }
253 #endif
std::pair< TVector3, TVector3 > TrackDirectionAverageFromPoints(recob::Track track, double frac)
matchCand GetClosestCRTHit(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::pair< double, double > t0MinMax, std::vector< sbn::crt::CRTHit > crtHits, int driftDirection)
Utilities related to art service access.
Declaration of signal hit object.
process_name use argoneut_mc_hitfinder track
std::pair< double, double > TrackT0Range(detinfo::DetectorPropertiesData const &detProp, double startX, double endX, int driftDirection, std::pair< double, double > xLimits)
std::pair< double, double > T0AndDCAFromCRTHits(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< sbn::crt::CRTHit > crtHits, const art::Event &event)
CRTT0MatchAlg(const fhicl::ParameterSet &pset)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
Access the description of detector geometry.
double DistOfClosestApproach(detinfo::DetectorPropertiesData const &detProp, TVector3 trackPos, TVector3 trackDir, sbn::crt::CRTHit crtHit, int driftDirection, double t0)
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)
object containing MC truth information necessary for making RawDigits and doing back tracking ...
art framework interface to geometry description for auxiliary detectors
BEGIN_PROLOG vertical distance to the surface Name
Description of geometry of one entire detector.
Provides recob::Track data product.
double T0FromCRTHits(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< sbn::crt::CRTHit > crtHits, const art::Event &event)
std::pair< TVector3, TVector3 > TrackDirectionAverage(recob::Track track, double frac)
stream1 can override from command line with o or output services user sbnd
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: