LArSoft  v09_90_00
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/types/Atom.h"
26 #include "fhiclcpp/types/Comment.h"
27 #include "fhiclcpp/types/Name.h"
28 #include "fhiclcpp/types/Table.h"
29 namespace fhicl {
30  class ParameterSet;
31 }
32 
33 // LArSoft includes
38 namespace detinfo {
39  class DetectorPropertiesData;
40 }
41 namespace geo {
42  class GeometryCore;
43  class TPCGeo;
44 }
45 namespace img {
46  class DataProviderAlg;
47 }
48 namespace lariov {
49  class ChannelStatusProvider;
50 }
51 
52 // ROOT & C++
53 #include <map>
54 #include <memory>
55 #include <vector>
56 class TH1F;
57 
58 namespace pma {
59  class ProjectionMatchingAlg;
60 }
61 
63 public:
64  struct Config {
65  using Name = fhicl::Name;
67 
68  fhicl::Atom<double> OptimizationEps{
69  Name("OptimizationEps"),
70  Comment("relative change of the obj.fn which stops optimization after adding a node")};
71 
72  fhicl::Atom<double> FineTuningEps{
73  Name("FineTuningEps"),
74  Comment("relative change of the obj.fn which stops fine-tuning of optimized track")};
75 
76  fhicl::Atom<double> TrkValidationDist2D{
77  Name("TrkValidationDist2D"),
78  Comment("max. distance [cm] used in the track validation in the third plane")};
79 
80  fhicl::Atom<double> HitTestingDist2D{
81  Name("HitTestingDist2D"),
82  Comment("max. distance [cm] used in testing compatibility of hits with the track")};
83 
84  fhicl::Atom<double> MinTwoViewFraction{
85  Name("MinTwoViewFraction"),
86  Comment("min. fraction of track length covered with hits from many 2D views intertwinted "
87  "with each other")};
88 
89  fhicl::Atom<double> NodeMargin3D{
90  Name("NodeMargin3D"),
91  Comment("margin in [cm] around TPC for allowed track node positions")};
92 
93  fhicl::Atom<double> HitWeightU{Name("HitWeightU"), Comment("weights used for hits in U plane")};
94 
95  fhicl::Atom<double> HitWeightV{Name("HitWeightV"), Comment("weights used for hits in V plane")};
96 
97  fhicl::Atom<double> HitWeightZ{Name("HitWeightZ"), Comment("weights used for hits in Z plane")};
98  };
99 
100  ProjectionMatchingAlg(const Config& config);
101 
103  : ProjectionMatchingAlg(fhicl::Table<Config>(pset, {})())
104  {}
105 
109  double validate_on_adc(const detinfo::DetectorPropertiesData& detProp,
110  const lariov::ChannelStatusProvider& channelStatus,
111  const pma::Track3D& trk,
112  const img::DataProviderAlg& adcImage,
113  float thr) const;
114 
120  double validate_on_adc_test(const detinfo::DetectorPropertiesData& detProp,
121  const lariov::ChannelStatusProvider& channelStatus,
122  const pma::Track3D& trk,
123  const img::DataProviderAlg& adcImage,
125  TH1F* histoPassing,
126  TH1F* histoRejected) const;
127 
132  double validate(const detinfo::DetectorPropertiesData& detProp,
133  const lariov::ChannelStatusProvider& channelStatus,
134  const pma::Track3D& trk,
135  const std::vector<art::Ptr<recob::Hit>>& hits) const;
136 
141  double validate(const detinfo::DetectorPropertiesData& detProp,
142  const lariov::ChannelStatusProvider& channelStatus,
143  const TVector3& p0,
144  const TVector3& p1,
146  unsigned int testView,
147  unsigned int tpc,
148  unsigned int cryo) const;
149 
154  double twoViewFraction(pma::Track3D& trk) const;
155 
157  unsigned int testHits(detinfo::DetectorPropertiesData const& detProp,
158  const pma::Track3D& trk,
160  double eps = 1.0) const
161  {
162  return trk.TestHits(detProp, hits, eps * fHitTestingDist2D);
163  }
164 
167  bool isContained(const pma::Track3D& trk, float margin = 0.0F) const
168  {
169  return (trk.FirstElement()->SameTPC(trk.front()->Point3D(), margin) &&
170  trk.LastElement()->SameTPC(trk.back()->Point3D(), margin));
171  }
172 
177  pma::Track3D* buildTrack(const detinfo::DetectorPropertiesData& detProp,
178  const std::vector<art::Ptr<recob::Hit>>& hits_1,
179  const std::vector<art::Ptr<recob::Hit>>& hits_2 = {}) const;
180 
184  pma::Track3D* buildMultiTPCTrack(const detinfo::DetectorPropertiesData& clockData,
185  const std::vector<art::Ptr<recob::Hit>>& hits) const;
186 
189  pma::Track3D* buildShowerSeg(const detinfo::DetectorPropertiesData& detProp,
191  const pma::Vector3D& vtx) const;
192 
197  pma::Track3D* buildSegment(const detinfo::DetectorPropertiesData& clockData,
198  const std::vector<art::Ptr<recob::Hit>>& hits_1,
199  const std::vector<art::Ptr<recob::Hit>>& hits_2 = {}) const;
200 
206  pma::Track3D* buildSegment(const detinfo::DetectorPropertiesData& clockData,
207  const std::vector<art::Ptr<recob::Hit>>& hits_1,
208  const std::vector<art::Ptr<recob::Hit>>& hits_2,
209  const geo::Point_t& point) const;
210 
213  pma::Track3D* buildSegment(const detinfo::DetectorPropertiesData& detProp,
215  const TVector3& point) const;
216 
219  void FilterOutSmallParts(const detinfo::DetectorPropertiesData& detProp,
220  double r2d,
221  const std::vector<art::Ptr<recob::Hit>>& hits_in,
223  const TVector2& vtx2d) const;
224 
225  void RemoveNotEnabledHits(pma::Track3D& trk) const;
226 
228  pma::Track3D* extendTrack(const detinfo::DetectorPropertiesData& clockData,
229  const pma::Track3D& trk,
231  bool add_nodes) const;
232 
235  void guideEndpoints(const detinfo::DetectorPropertiesData& clockData,
236  pma::Track3D& trk,
237  const std::map<unsigned int, std::vector<art::Ptr<recob::Hit>>>& hits) const;
238 
240  void guideEndpoints(const detinfo::DetectorPropertiesData& clockData,
241  pma::Track3D& trk,
242  pma::Track3D::ETrackEnd endpoint,
243  const std::map<unsigned int, std::vector<art::Ptr<recob::Hit>>>& hits) const;
244 
245  std::vector<pma::Hit3D*> trimTrackToVolume(pma::Track3D& trk, TVector3 p0, TVector3 p1) const;
246 
249  bool alignTracks(pma::Track3D& first, pma::Track3D& second) const;
250 
254  void mergeTracks(const detinfo::DetectorPropertiesData& detProp,
255  pma::Track3D& dst,
256  pma::Track3D& src,
257  bool reopt) const;
258 
266  double thr = 0.0,
267  unsigned int n = 0) const
268  {
269  trk.AutoFlip(dir, thr, n);
270  };
271 
274  double selectInitialHits(pma::Track3D& trk,
275  unsigned int view = geo::kZ,
276  unsigned int* nused = 0) const;
277 
278 private:
279  // Helpers for guideEndpoints
280  bool chkEndpointHits_(const detinfo::DetectorPropertiesData& detProp,
281  int wire,
282  int wdir,
283  double drift_x,
284  int view,
285  unsigned int tpc,
286  unsigned int cryo,
287  const pma::Track3D& trk,
288  const std::vector<art::Ptr<recob::Hit>>& hits) const;
289  bool addEndpointRef_(const detinfo::DetectorPropertiesData& detProp,
290  pma::Track3D& trk,
291  const std::map<unsigned int, std::vector<art::Ptr<recob::Hit>>>& hits,
292  std::pair<int, int> const* wires,
293  double const* xPos,
294  unsigned int tpc,
295  unsigned int cryo) const;
296 
297  // Helpers for FilterOutSmallParts
298  bool GetCloseHits_(const detinfo::DetectorPropertiesData& detProp,
299  double r2d,
300  const std::vector<art::Ptr<recob::Hit>>& hits_in,
301  std::vector<size_t>& used,
302  std::vector<art::Ptr<recob::Hit>>& hits_out) const;
303 
304  bool Has_(const std::vector<size_t>& v, size_t idx) const;
305 
306  // Make segment shorter depending on mse
307  void ShortenSeg_(const detinfo::DetectorPropertiesData& detProp,
308  pma::Track3D& trk,
309  const geo::TPCGeo& tpcgeom) const;
310 
311  // Control length of the track and number of hits which are still enabled
312  bool TestTrk_(pma::Track3D& trk, const geo::TPCGeo& tpcgeom) const;
313 
314  // Calculate good number of segments depending on the number of hits.
315  static size_t getSegCount_(size_t trk_size);
316 
317  // Parameters used in the algorithm
318 
319  double const fOptimizationEps; // relative change in the obj.function that
320  // ends optimization, then next nodes are added
321  // or track building is finished
322 
323  double const fFineTuningEps; // relative change in the obj.function that ends
324  // final tuning
325 
326  double const fTrkValidationDist2D; // max. distance [cm] used in the track
327  // validation in the "third" plane
328  double const fHitTestingDist2D; // max. distance [cm] used in testing comp. of
329  // hits with the track
330 
331  double const fMinTwoViewFraction; // min. length fraction covered with multiple 2D
332  // view hits intertwinted with each other
333 
334  // Geometry and detector properties
336 };
337 
338 #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:36
TVector3 const & Point3D() const
Definition: PmaHit3D.h:50
Planes which measure Z direction.
Definition: geo_types.h:138
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
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:100
General LArSoft Utilities.
Description of geometry of one entire detector.
Definition: GeometryCore.h:119
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
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
Namespace collecting geometry-related classes utilities.
map< int, array< map< int, double >, 2 >> Table
Definition: plot.C:18