LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
ProjectionMatchingAlg.h
Go to the documentation of this file.
1 // Class: ProjectionMatchingAlg
3 // Author: D.Stefan (Dorota.Stefan@ncbj.gov.pl) and R.Sulej (Robert.Sulej@cern.ch), May 2015
4 //
5 // Projection Matching Algorithm
6 // see RecoAlg/PMAlg/PmaTrack3D.h for more details.
7 //
8 // Build 3D segments and whole tracks by matching an object 2D projections to hits, simultaneously
9 // in multiple wire planes. Based on the algorithm first presented in "Precise 3D track reco..."
10 // AHEP (2013) 260820, with all the tricks that we developed later and with the work for the full-event
11 // topology optimization that is still under construction now (2015).
12 //
13 // The algorithm class provides functionality to build a track from selected hits. These
14 // can be detailed tracks or just simple segments (if the number of nodes to add is set to 0).
15 // The parameters of optimization algorithm, fixed nodes and 3D reference points can be configured here.
16 // Please, check the track making module to find a way of selecting appropriate clusteres:
17 // PMAlgTrackMaker_module.cc
18 //
20 
21 #ifndef ProjectionMatchingAlg_h
22 #define ProjectionMatchingAlg_h
23 
24 // Framework includes
25 #include "fhiclcpp/fwd.h"
26 #include "fhiclcpp/types/Atom.h"
27 #include "fhiclcpp/types/Comment.h"
28 #include "fhiclcpp/types/Name.h"
29 #include "fhiclcpp/types/Table.h"
30 
31 // LArSoft includes
37 namespace detinfo {
38  class DetectorPropertiesData;
39 }
40 namespace img {
41  class DataProviderAlg;
42 }
43 namespace lariov {
44  class ChannelStatusProvider;
45 }
46 
47 // ROOT & C++
48 #include <map>
49 #include <memory>
50 #include <vector>
51 class TH1F;
52 
53 namespace pma {
54  class ProjectionMatchingAlg;
55 }
56 
58 public:
59  struct Config {
60  using Name = fhicl::Name;
62 
63  fhicl::Atom<double> OptimizationEps{
64  Name("OptimizationEps"),
65  Comment("relative change of the obj.fn which stops optimization after adding a node")};
66 
67  fhicl::Atom<double> FineTuningEps{
68  Name("FineTuningEps"),
69  Comment("relative change of the obj.fn which stops fine-tuning of optimized track")};
70 
71  fhicl::Atom<double> TrkValidationDist2D{
72  Name("TrkValidationDist2D"),
73  Comment("max. distance [cm] used in the track validation in the third plane")};
74 
75  fhicl::Atom<double> HitTestingDist2D{
76  Name("HitTestingDist2D"),
77  Comment("max. distance [cm] used in testing compatibility of hits with the track")};
78 
79  fhicl::Atom<double> MinTwoViewFraction{
80  Name("MinTwoViewFraction"),
81  Comment("min. fraction of track length covered with hits from many 2D views intertwinted "
82  "with each other")};
83 
84  fhicl::Atom<double> NodeMargin3D{
85  Name("NodeMargin3D"),
86  Comment("margin in [cm] around TPC for allowed track node positions")};
87 
88  fhicl::Atom<double> HitWeightU{Name("HitWeightU"), Comment("weights used for hits in U plane")};
89 
90  fhicl::Atom<double> HitWeightV{Name("HitWeightV"), Comment("weights used for hits in V plane")};
91 
92  fhicl::Atom<double> HitWeightZ{Name("HitWeightZ"), Comment("weights used for hits in Z plane")};
93  };
94 
95  ProjectionMatchingAlg(const Config& config);
96 
98  : ProjectionMatchingAlg(fhicl::Table<Config>(pset, {})())
99  {}
100 
104  double validate_on_adc(const detinfo::DetectorPropertiesData& detProp,
105  const lariov::ChannelStatusProvider& channelStatus,
106  const pma::Track3D& trk,
107  const img::DataProviderAlg& adcImage,
108  float thr) const;
109 
115  double validate_on_adc_test(const detinfo::DetectorPropertiesData& detProp,
116  const lariov::ChannelStatusProvider& channelStatus,
117  const pma::Track3D& trk,
118  const img::DataProviderAlg& adcImage,
120  TH1F* histoPassing,
121  TH1F* histoRejected) const;
122 
127  double validate(const detinfo::DetectorPropertiesData& detProp,
128  const lariov::ChannelStatusProvider& channelStatus,
129  const pma::Track3D& trk,
130  const std::vector<art::Ptr<recob::Hit>>& hits) const;
131 
136  double validate(const detinfo::DetectorPropertiesData& detProp,
137  const lariov::ChannelStatusProvider& channelStatus,
138  const TVector3& p0,
139  const TVector3& p1,
141  unsigned int testView,
142  unsigned int tpc,
143  unsigned int cryo) const;
144 
149  double twoViewFraction(pma::Track3D& trk) const;
150 
152  unsigned int testHits(detinfo::DetectorPropertiesData const& detProp,
153  const pma::Track3D& trk,
155  double eps = 1.0) const
156  {
157  return trk.TestHits(detProp, hits, eps * fHitTestingDist2D);
158  }
159 
162  bool isContained(const pma::Track3D& trk, float margin = 0.0F) const
163  {
164  return (trk.FirstElement()->SameTPC(trk.front()->Point3D(), margin) &&
165  trk.LastElement()->SameTPC(trk.back()->Point3D(), margin));
166  }
167 
172  pma::Track3D* buildTrack(const detinfo::DetectorPropertiesData& detProp,
173  const std::vector<art::Ptr<recob::Hit>>& hits_1,
174  const std::vector<art::Ptr<recob::Hit>>& hits_2 = {}) const;
175 
179  pma::Track3D* buildMultiTPCTrack(const detinfo::DetectorPropertiesData& clockData,
180  const std::vector<art::Ptr<recob::Hit>>& hits) const;
181 
184  pma::Track3D* buildShowerSeg(const detinfo::DetectorPropertiesData& detProp,
186  const pma::Vector3D& vtx) const;
187 
192  pma::Track3D* buildSegment(const detinfo::DetectorPropertiesData& clockData,
193  const std::vector<art::Ptr<recob::Hit>>& hits_1,
194  const std::vector<art::Ptr<recob::Hit>>& hits_2 = {}) const;
195 
201  pma::Track3D* buildSegment(const detinfo::DetectorPropertiesData& clockData,
202  const std::vector<art::Ptr<recob::Hit>>& hits_1,
203  const std::vector<art::Ptr<recob::Hit>>& hits_2,
204  const geo::Point_t& point) const;
205 
208  pma::Track3D* buildSegment(const detinfo::DetectorPropertiesData& detProp,
210  const TVector3& point) const;
211 
214  void FilterOutSmallParts(const detinfo::DetectorPropertiesData& detProp,
215  double r2d,
216  const std::vector<art::Ptr<recob::Hit>>& hits_in,
218  const TVector2& vtx2d) const;
219 
220  void RemoveNotEnabledHits(pma::Track3D& trk) const;
221 
223  pma::Track3D* extendTrack(const detinfo::DetectorPropertiesData& clockData,
224  const pma::Track3D& trk,
226  bool add_nodes) const;
227 
230  void guideEndpoints(const detinfo::DetectorPropertiesData& clockData,
231  pma::Track3D& trk,
232  const std::map<unsigned int, std::vector<art::Ptr<recob::Hit>>>& hits) const;
233 
235  void guideEndpoints(const detinfo::DetectorPropertiesData& clockData,
236  pma::Track3D& trk,
237  pma::Track3D::ETrackEnd endpoint,
238  const std::map<unsigned int, std::vector<art::Ptr<recob::Hit>>>& hits) const;
239 
240  std::vector<pma::Hit3D*> trimTrackToVolume(pma::Track3D& trk, TVector3 p0, TVector3 p1) const;
241 
244  bool alignTracks(pma::Track3D& first, pma::Track3D& second) const;
245 
249  void mergeTracks(const detinfo::DetectorPropertiesData& detProp,
250  pma::Track3D& dst,
251  pma::Track3D& src,
252  bool reopt) const;
253 
261  double thr = 0.0,
262  unsigned int n = 0) const
263  {
264  trk.AutoFlip(dir, thr, n);
265  };
266 
269  double selectInitialHits(pma::Track3D& trk,
270  unsigned int view = geo::kZ,
271  unsigned int* nused = 0) const;
272 
273 private:
274  // Helpers for guideEndpoints
275  bool chkEndpointHits_(const detinfo::DetectorPropertiesData& detProp,
276  int wire,
277  int wdir,
278  double drift_x,
279  int view,
280  unsigned int tpc,
281  unsigned int cryo,
282  const pma::Track3D& trk,
283  const std::vector<art::Ptr<recob::Hit>>& hits) const;
284  bool addEndpointRef_(const detinfo::DetectorPropertiesData& detProp,
285  pma::Track3D& trk,
286  const std::map<unsigned int, std::vector<art::Ptr<recob::Hit>>>& hits,
287  std::pair<int, int> const* wires,
288  double const* xPos,
289  unsigned int tpc,
290  unsigned int cryo) const;
291 
292  // Helpers for FilterOutSmallParts
293  bool GetCloseHits_(const detinfo::DetectorPropertiesData& detProp,
294  double r2d,
295  const std::vector<art::Ptr<recob::Hit>>& hits_in,
296  std::vector<size_t>& used,
297  std::vector<art::Ptr<recob::Hit>>& hits_out) const;
298 
299  bool Has_(const std::vector<size_t>& v, size_t idx) const;
300 
301  // Make segment shorter depending on mse
302  void ShortenSeg_(const detinfo::DetectorPropertiesData& detProp,
303  pma::Track3D& trk,
304  const geo::TPCGeo& tpcgeom) const;
305 
306  // Control length of the track and number of hits which are still enabled
307  bool TestTrk_(pma::Track3D& trk, const geo::TPCGeo& tpcgeom) const;
308 
309  // Calculate good number of segments depending on the number of hits.
310  static size_t getSegCount_(size_t trk_size);
311 
312  // Parameters used in the algorithm
313 
314  double const fOptimizationEps; // relative change in the obj.function that
315  // ends optimization, then next nodes are added
316  // or track building is finished
317 
318  double const fFineTuningEps; // relative change in the obj.function that ends
319  // final tuning
320 
321  double const fTrkValidationDist2D; // max. distance [cm] used in the track
322  // validation in the "third" plane
323  double const fHitTestingDist2D; // max. distance [cm] used in testing comp. of
324  // hits with the track
325 
326  double const fMinTwoViewFraction; // min. length fraction covered with multiple 2D
327  // view hits intertwinted with each other
328 
329  // Geometry and detector properties
332 };
333 
334 #endif
void AutoFlip(pma::Track3D::EDirection dir, double thr=0.0, unsigned int n=0)
Definition: PmaTrack3D.cxx:662
Implementation of the Projection Matching Algorithm.
ProjectionMatchingAlg(const fhicl::ParameterSet &pset)
geo::GeometryCore const * fGeom
Declaration of signal hit object.
pma::Hit3D const * front() const
Definition: PmaTrack3D.h:87
unsigned int TestHits(detinfo::DetectorPropertiesData const &detProp, const std::vector< art::Ptr< recob::Hit >> &hits, double dist=0.4) const
Count close 2D hits.
Definition: PmaTrack3D.cxx:845
Geometry information for a single TPC.
Definition: TPCGeo.h:33
TVector3 const & Point3D() const
Definition: PmaHit3D.h:50
Planes which measure Z direction.
Definition: geo_types.h:134
recob::tracking::Vector_t Vector3D
Definition: Utilities.h:34
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
void hits()
Definition: readHits.C:15
pma::Node3D * FirstElement() const
Definition: PmaTrack3D.h:275
unsigned int testHits(detinfo::DetectorPropertiesData const &detProp, const pma::Track3D &trk, const std::vector< art::Ptr< recob::Hit >> &hits, double eps=1.0) const
Count the number of hits that are closer than eps * fHitTestingDist2D to the track 2D projection...
pma::Node3D * LastElement() const
Definition: PmaTrack3D.h:276
bool isContained(const pma::Track3D &trk, float margin=0.0F) const
Interface for a class providing readout channel mapping to geometry.
void autoFlip(pma::Track3D &trk, pma::Track3D::EDirection dir=Track3D::kForward, double thr=0.0, unsigned int n=0) const
parameter set interface
bool SameTPC(const TVector3 &p3d, float margin=0.0F) const
Check if p3d is in the same TPC as the node.
Definition: PmaNode3D.cxx:103
General LArSoft Utilities.
Description of the physical geometry of one entire detector.
Definition: GeometryCore.h:91
Definition of data types for geometry description.
Filters for channels, events, etc.
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:180
Implementation of the Projection Matching Algorithm.
TDirectory * dir
Definition: macro.C:5
geo::WireReadoutGeom const * fWireReadoutGeom
pma::Hit3D const * back() const
Definition: PmaTrack3D.h:88
Char_t n[5]
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:82
map< int, array< map< int, double >, 2 >> Table
Definition: plot.C:18