LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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
27 #include "fhiclcpp/types/Atom.h"
28 
29 // LArSoft includes
37 
39 
42 
43 // ROOT & C++
44 #include "TH1F.h"
45 #include <memory>
46 
47 namespace pma
48 {
49  class ProjectionMatchingAlg;
50 }
51 
53 {
54 public:
55 
56  struct Config {
57  using Name = fhicl::Name;
59 
61  Name("OptimizationEps"),
62  Comment("relative change of the obj.fn which stops optimization after adding a node")
63  };
64 
66  Name("FineTuningEps"),
67  Comment("relative change of the obj.fn which stops fine-tuning of optimized track")
68  };
69 
71  Name("TrkValidationDist2D"),
72  Comment("max. distance [cm] used in the track validation in the third plane")
73  };
74 
76  Name("HitTestingDist2D"),
77  Comment("max. distance [cm] used in testing compatibility of hits with the track")
78  };
79 
81  Name("MinTwoViewFraction"),
82  Comment("min. fraction of track length covered with hits from many 2D views intertwinted with each other")
83  };
84 
86  Name("NodeMargin3D"),
87  Comment("margin in [cm] around TPC for allowed track node positions")
88  };
89 
91  Name("HitWeightU"),
92  Comment("weights used for hits in U plane")
93  };
94 
96  Name("HitWeightV"),
97  Comment("weights used for hits in V plane")
98  };
99 
101  Name("HitWeightZ"),
102  Comment("weights used for hits in Z plane")
103  };
104  };
105 
106  ProjectionMatchingAlg(const Config& config);
107 
109  ProjectionMatchingAlg(fhicl::Table<Config>(pset, {})())
110  {}
111 
114  double validate_on_adc(const pma::Track3D& trk,
115  const img::DataProviderAlg & adcImage, float thr) const;
116 
121  double validate_on_adc_test(const pma::Track3D& trk,
122  const img::DataProviderAlg & adcImage,
124  TH1F * histoPassing, TH1F * histoRejected) const;
125 
129  double validate(const pma::Track3D& trk,
130  const std::vector< art::Ptr<recob::Hit> >& hits) const;
131 
135  double validate(const TVector3& p0, const TVector3& p1,
137  unsigned int testView, unsigned int tpc, unsigned int cryo) const;
138 
143  double twoViewFraction(pma::Track3D& trk) const;
144 
146  unsigned int testHits(const pma::Track3D& trk,
148  double eps = 1.0) const
149  { return trk.TestHits(hits, eps * fHitTestingDist2D); }
150 
153  bool isContained(const pma::Track3D& trk, float margin = 0.0F) const
154  {
155  return (trk.FirstElement()->SameTPC(trk.front()->Point3D(), margin) &&
156  trk.LastElement()->SameTPC(trk.back()->Point3D(), margin));
157  }
158 
162  const std::vector< art::Ptr<recob::Hit> >& hits_1,
163  const std::vector< art::Ptr<recob::Hit> >& hits_2 = std::vector< art::Ptr<recob::Hit> >()) const;
164 
168 
172  const pma::Vector3D & vtx) const;
173 
178  const std::vector< art::Ptr<recob::Hit> >& hits_1,
179  const std::vector< art::Ptr<recob::Hit> >& hits_2 = std::vector< art::Ptr<recob::Hit> >()) const;
180 
186  const std::vector< art::Ptr<recob::Hit> >& hits_1,
187  const std::vector< art::Ptr<recob::Hit> >& hits_2,
188  const TVector3& point) const;
189 
194  const TVector3& point) const;
195 
198  void FilterOutSmallParts(
199  double r2d,
200  const std::vector< art::Ptr<recob::Hit> >& hits_in,
201  std::vector< art::Ptr<recob::Hit> >& hits_out,
202  const TVector2& vtx2d) const;
203 
204  void RemoveNotEnabledHits(pma::Track3D& trk) const;
205 
208  const pma::Track3D& trk,
210  bool add_nodes) const;
211 
213  void guideEndpoints(pma::Track3D& trk,
214  const std::map< unsigned int, std::vector< art::Ptr<recob::Hit> > >& hits) const;
215 
218  const std::map< unsigned int, std::vector< art::Ptr<recob::Hit> > >& hits) const;
219 
220  std::vector< pma::Hit3D* > trimTrackToVolume(pma::Track3D& trk, TVector3 p0, TVector3 p1) const;
221 
224  bool alignTracks(pma::Track3D& first, pma::Track3D& second) const;
225 
228  void mergeTracks(pma::Track3D& dst, pma::Track3D& src, bool reopt) const;
229 
237  double thr = 0.0, unsigned int n = 0) const { trk.AutoFlip(dir, thr, n); };
238 
241  double selectInitialHits(pma::Track3D& trk, unsigned int view = geo::kZ, unsigned int* nused = 0) const;
242 
243 private:
244 
245  // Helpers for guideEndpoints
246  bool chkEndpointHits(int wire, int wdir, double drift_x, int view,
247  unsigned int tpc, unsigned int cryo,
248  const pma::Track3D& trk,
249  const std::vector< art::Ptr<recob::Hit> >& hits) const;
250  bool addEndpointRef(pma::Track3D& trk,
251  const std::map< unsigned int, std::vector< art::Ptr<recob::Hit> > >& hits,
252  std::pair<int, int> const * wires, double const * xPos,
253  unsigned int tpc, unsigned int cryo) const;
254 
255  // Helpers for FilterOutSmallParts
256  bool GetCloseHits(
257  double r2d,
258  const std::vector< art::Ptr<recob::Hit> >& hits_in,
259  std::vector<size_t>& used,
260  std::vector< art::Ptr<recob::Hit> >& hits_out) const;
261 
262  bool Has(const std::vector<size_t>& v, size_t idx) const;
263 
264  // Make segment shorter depending on mse
265  void ShortenSeg(pma::Track3D& trk, const geo::TPCGeo& tpcgeom) const;
266 
267  // Control length of the track and number of hits which are still enabled
268  bool TestTrk(pma::Track3D& trk, const geo::TPCGeo& tpcgeom) const;
269 
270  // Calculate good number of segments depending on the number of hits.
271  static size_t getSegCount(size_t trk_size);
272 
273 
274  // Parameters used in the algorithm
275 
276  double fOptimizationEps; // relative change in the obj.function that ends optimization,
277  // then next nodes are added or track building is finished
278 
279  double fFineTuningEps; // relative change in the obj.function that ends final tuning
280 
281  double fTrkValidationDist2D; // max. distance [cm] used in the track validation in the "third" plane
282  double fHitTestingDist2D; // max. distance [cm] used in testing comp. of hits with the track
283 
284  double fMinTwoViewFraction; // min. length fraction covered with multiple 2D view hits intertwinted with each other
285 
286  // Geometry and detector properties
289 };
290 
291 #endif
unsigned int testHits(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...
unsigned int TestHits(const std::vector< art::Ptr< recob::Hit > > &hits, double dist=0.4) const
Count close 2D hits.
Definition: PmaTrack3D.cxx:811
pma::Track3D * buildShowerSeg(const std::vector< art::Ptr< recob::Hit > > &hits, const pma::Vector3D &vtx) const
Build a shower segment from sets of hits and attached to the provided vertex.
pma::Node3D * LastElement(void) const
Definition: PmaTrack3D.h:234
void AutoFlip(pma::Track3D::EDirection dir, double thr=0.0, unsigned int n=0)
Definition: PmaTrack3D.cxx:630
detinfo::DetectorProperties const * fDetProp
Implementation of the Projection Matching Algorithm.
ProjectionMatchingAlg(const fhicl::ParameterSet &pset)
void guideEndpoints(pma::Track3D &trk, const std::map< unsigned int, std::vector< art::Ptr< recob::Hit > > > &hits) const
Add 3D reference points to clean endpoints of a track (both need to be in the same TPC)...
bool addEndpointRef(pma::Track3D &trk, const std::map< unsigned int, std::vector< art::Ptr< recob::Hit > > > &hits, std::pair< int, int > const *wires, double const *xPos, unsigned int tpc, unsigned int cryo) const
geo::GeometryCore const * fGeom
Declaration of signal hit object.
Geometry information for a single TPC.
Definition: TPCGeo.h:37
Planes which measure Z direction.
Definition: geo_types.h:79
bool GetCloseHits(double r2d, const std::vector< art::Ptr< recob::Hit > > &hits_in, std::vector< size_t > &used, std::vector< art::Ptr< recob::Hit > > &hits_out) const
recob::tracking::Vector_t Vector3D
Definition: Utilities.h:29
pma::Track3D * buildMultiTPCTrack(const std::vector< art::Ptr< recob::Hit > > &hits) const
as far as hits origin from at least two wire planes.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
double selectInitialHits(pma::Track3D &trk, unsigned int view=geo::kZ, unsigned int *nused=0) const
void hits()
Definition: readHits.C:15
bool alignTracks(pma::Track3D &first, pma::Track3D &second) const
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
pma::Track3D * buildSegment(const std::vector< art::Ptr< recob::Hit > > &hits_1, const std::vector< art::Ptr< recob::Hit > > &hits_2=std::vector< art::Ptr< recob::Hit > >()) const
bool chkEndpointHits(int wire, int wdir, double drift_x, int view, unsigned int tpc, unsigned int cryo, const pma::Track3D &trk, const std::vector< art::Ptr< recob::Hit > > &hits) const
pma::Track3D * buildTrack(const std::vector< art::Ptr< recob::Hit > > &hits_1, const std::vector< art::Ptr< recob::Hit > > &hits_2=std::vector< art::Ptr< recob::Hit > >()) const
wire planes; number of segments used to create the track depends on the number of hits...
pma::Hit3D *& back()
Definition: PmaTrack3D.h:74
bool SameTPC(const TVector3 &p3d, float margin=0.0F) const
Check if p3d is in the same TPC as the node.
Definition: PmaNode3D.cxx:83
Description of geometry of one entire detector.
void ShortenSeg(pma::Track3D &trk, const geo::TPCGeo &tpcgeom) const
Encapsulate the geometry of a wire.
bool Has(const std::vector< size_t > &v, size_t idx) const
double validate_on_adc_test(const pma::Track3D &trk, const img::DataProviderAlg &adcImage, const std::vector< art::Ptr< recob::Hit > > &hits, TH1F *histoPassing, TH1F *histoRejected) const
TVector3 const & Point3D(void) const
Definition: PmaHit3D.h:48
double validate_on_adc(const pma::Track3D &trk, const img::DataProviderAlg &adcImage, float thr) const
Implementation of the Projection Matching Algorithm.
static size_t getSegCount(size_t trk_size)
Encapsulate the construction of a single detector plane.
void FilterOutSmallParts(double r2d, const std::vector< art::Ptr< recob::Hit > > &hits_in, std::vector< art::Ptr< recob::Hit > > &hits_out, const TVector2 &vtx2d) const
TDirectory * dir
Definition: macro.C:5
pma::Track3D * extendTrack(const pma::Track3D &trk, const std::vector< art::Ptr< recob::Hit > > &hits, bool add_nodes) const
Add more hits to an existing track, reoptimize, optionally add more nodes.
ProjectionMatchingAlg(const Config &config)
std::vector< pma::Hit3D * > trimTrackToVolume(pma::Track3D &trk, TVector3 p0, TVector3 p1) const
Char_t n[5]
void RemoveNotEnabledHits(pma::Track3D &trk) const
double twoViewFraction(pma::Track3D &trk) const
pma::Hit3D *& front()
Definition: PmaTrack3D.h:72
double validate(const pma::Track3D &trk, const std::vector< art::Ptr< recob::Hit > > &hits) const
pma::Node3D * FirstElement(void) const
Definition: PmaTrack3D.h:233
bool TestTrk(pma::Track3D &trk, const geo::TPCGeo &tpcgeom) const
art framework interface to geometry description
Encapsulate the construction of a single detector plane.
void mergeTracks(pma::Track3D &dst, pma::Track3D &src, bool reopt) const