All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ProjectionMatchingAlg.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////////////////////////
2 // 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 //
19 ////////////////////////////////////////////////////////////////////////////////////////////////////
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;
66  using Comment = fhicl::Comment;
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 
102  ProjectionMatchingAlg(const fhicl::ParameterSet& pset)
103  : ProjectionMatchingAlg(fhicl::Table<Config>(pset, {})())
104  {}
105 
106  /// Calculate the fraction of the track that is close to non-empty pixel
107  /// (above thr value) in the ADC image of the testView (a view that was not
108  /// used to build the track).
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 
115  /// Calculate the fraction of the track that is closer than
116  /// fTrkValidationDist2D to any hit from hits in the testView (a view that was
117  /// not used to build the track). Creates also histograms of values in pixels
118  /// for the passing and rejected points on the track, so the threshold value
119  /// for the ADC-based calibration can be estimated.
121  const lariov::ChannelStatusProvider& channelStatus,
122  const pma::Track3D& trk,
123  const img::DataProviderAlg& adcImage,
124  const std::vector<art::Ptr<recob::Hit>>& hits,
125  TH1F* histoPassing,
126  TH1F* histoRejected) const;
127 
128  /// Calculate the fraction of the track that is closer than
129  /// fTrkValidationDist2D to any hit from hits in their plane (a plane that was
130  /// not used to build the track). Hits should be preselected, so all belong to
131  /// the same plane.
133  const lariov::ChannelStatusProvider& channelStatus,
134  const pma::Track3D& trk,
135  const std::vector<art::Ptr<recob::Hit>>& hits) const;
136 
137  /// Calculate the fraction of the 3D segment that is closer than
138  /// fTrkValidationDist2D to any hit from hits in the testPlane of TPC/Cryo.
139  /// Hits from the testPlane are preselected by this function among all
140  /// provided (so a bit slower than fn above).
142  const lariov::ChannelStatusProvider& channelStatus,
143  const TVector3& p0,
144  const TVector3& p1,
145  const std::vector<art::Ptr<recob::Hit>>& hits,
146  unsigned int testView,
147  unsigned int tpc,
148  unsigned int cryo) const;
149 
150  /// Calculate the fraction of trajectory seen by two 2D projections at least; even a
151  /// prfect track starts/stops with the hit from one 2D view, then hits from other views
152  /// come, which results with the fraction value high, but always < 1.0; wrong cluster
153  /// matchings or incomplete tracks give significantly lower values.
154  double twoViewFraction(pma::Track3D& trk) const;
155 
156  /// Count the number of hits that are closer than eps * fHitTestingDist2D to the track 2D projection.
157  unsigned int
159  const pma::Track3D& trk,
160  const std::vector<art::Ptr<recob::Hit>>& hits,
161  double eps = 1.0) const
162  {
163  return trk.TestHits(detProp, hits, eps * fHitTestingDist2D);
164  }
165 
166  /// Test if hits at the track endpoinds do not stick out of TPC which they belong to.
167  /// Here one can implement some configurable margin if needed for real data imeprfections.
168  bool
169  isContained(const pma::Track3D& trk, float margin = 0.0F) const
170  {
171  return (trk.FirstElement()->SameTPC(trk.front()->Point3D(), margin) &&
172  trk.LastElement()->SameTPC(trk.back()->Point3D(), margin));
173  }
174 
175  /// Build a track from two sets of hits from single TPC, hits should origin
176  /// from at least two
177  /// wire planes; number of segments used to create the track depends on the
178  /// number of hits.
180  const std::vector<art::Ptr<recob::Hit>>& hits_1,
181  const std::vector<art::Ptr<recob::Hit>>& hits_2 = {}) const;
182 
183  /// Build a track from sets of hits, multiple TPCs are OK (like taken from
184  /// PFParticles),
185  /// as far as hits origin from at least two wire planes.
187  const std::vector<art::Ptr<recob::Hit>>& hits) const;
188 
189  /// Build a shower segment from sets of hits and attached to the provided
190  /// vertex.
192  const std::vector<art::Ptr<recob::Hit>>& hits,
193  const pma::Vector3D& vtx) const;
194 
195  /// Build a straight segment from two sets of hits (they should origin from
196  /// two wire planes); method is intendet for short tracks or shower initial
197  /// parts, where only a few hits per plane are available and there is no
198  /// chance to see a curvature or any other features.
200  const std::vector<art::Ptr<recob::Hit>>& hits_1,
201  const std::vector<art::Ptr<recob::Hit>>& hits_2 = {}) const;
202 
203  /// Build a straight segment from two sets of hits (they should origin from
204  /// two wire planes), starting from a given point (like vertex known from
205  /// another algorithm); method is intendet for short tracks or shower initial
206  /// parts, where only a few hits per plane are available and there is no
207  /// chance to see a curvature or any other features.
209  const std::vector<art::Ptr<recob::Hit>>& hits_1,
210  const std::vector<art::Ptr<recob::Hit>>& hits_2,
211  const TVector3& point) const;
212 
213  /// Build a straight segment from set of hits (they should origin from two
214  /// wire planes at least), starting from a given point.
216  const std::vector<art::Ptr<recob::Hit>>& hits,
217  const TVector3& point) const;
218 
219  /// Get rid of small groups of hits around cascades; used to calculate cascade
220  /// starting direction using the compact core cluster.
222  double r2d,
223  const std::vector<art::Ptr<recob::Hit>>& hits_in,
224  std::vector<art::Ptr<recob::Hit>>& hits_out,
225  const TVector2& vtx2d) const;
226 
227  void RemoveNotEnabledHits(pma::Track3D& trk) const;
228 
229  /// Add more hits to an existing track, reoptimize, optionally add more nodes.
231  const pma::Track3D& trk,
232  const std::vector<art::Ptr<recob::Hit>>& hits,
233  bool add_nodes) const;
234 
235  /// Add 3D reference points to clean endpoints of a track (both need to be in
236  /// the same TPC).
237  void guideEndpoints(const detinfo::DetectorPropertiesData& clockData,
238  pma::Track3D& trk,
239  const std::map<unsigned int, std::vector<art::Ptr<recob::Hit>>>& hits) const;
240 
241  /// Add 3D reference points to clean endpoint of a track.
242  void guideEndpoints(const detinfo::DetectorPropertiesData& clockData,
243  pma::Track3D& trk,
244  pma::Track3D::ETrackEnd endpoint,
245  const std::map<unsigned int, std::vector<art::Ptr<recob::Hit>>>& hits) const;
246 
247  std::vector<pma::Hit3D*> trimTrackToVolume(pma::Track3D& trk, TVector3 p0, TVector3 p1) const;
248 
249  /// Flip tracks to get second as a continuation of first; returns false if not
250  /// possible (tracks in reversed order).
252 
253  /// Add src to dst as it was its continuation; nodes of src are added to dst
254  /// after its own nodes, hits of src are added to hits of dst, then dst is
255  /// reoptimized.
256  void mergeTracks(const detinfo::DetectorPropertiesData& detProp,
257  pma::Track3D& dst,
258  pma::Track3D& src,
259  bool reopt) const;
260 
261  /// Try to correct track direction of the stopping particle:
262  /// dir: kForward - particle stop is at the end of the track;
263  /// kBackward - particle stop is at the beginning of the track;
264  /// dQ/dx difference has to be above thr to actually flip the track;
265  /// compares dQ/dx of n hits at each end of the track (default is based on the track length).
266  void
269  double thr = 0.0,
270  unsigned int n = 0) const
271  {
272  trk.AutoFlip(dir, thr, n);
273  };
274 
275  /// Intendet to calculate dQ/dx in the initial part of EM cascade; collection
276  /// view is used by default, but it works also with other projections.
277  double selectInitialHits(pma::Track3D& trk,
278  unsigned int view = geo::kZ,
279  unsigned int* nused = 0) const;
280 
281 private:
282  // Helpers for guideEndpoints
284  int wire,
285  int wdir,
286  double drift_x,
287  int view,
288  unsigned int tpc,
289  unsigned int cryo,
290  const pma::Track3D& trk,
291  const std::vector<art::Ptr<recob::Hit>>& hits) const;
293  pma::Track3D& trk,
294  const std::map<unsigned int, std::vector<art::Ptr<recob::Hit>>>& hits,
295  std::pair<int, int> const* wires,
296  double const* xPos,
297  unsigned int tpc,
298  unsigned int cryo) const;
299 
300  // Helpers for FilterOutSmallParts
302  double r2d,
303  const std::vector<art::Ptr<recob::Hit>>& hits_in,
304  std::vector<size_t>& used,
305  std::vector<art::Ptr<recob::Hit>>& hits_out) const;
306 
307  bool Has_(const std::vector<size_t>& v, size_t idx) const;
308 
309  // Make segment shorter depending on mse
310  void ShortenSeg_(const detinfo::DetectorPropertiesData& detProp,
311  pma::Track3D& trk,
312  const geo::TPCGeo& tpcgeom) const;
313 
314  // Control length of the track and number of hits which are still enabled
315  bool TestTrk_(pma::Track3D& trk, const geo::TPCGeo& tpcgeom) const;
316 
317  // Calculate good number of segments depending on the number of hits.
318  static size_t getSegCount_(size_t trk_size);
319 
320  // Parameters used in the algorithm
321 
322  double const fOptimizationEps; // relative change in the obj.function that
323  // ends optimization, then next nodes are added
324  // or track building is finished
325 
326  double const fFineTuningEps; // relative change in the obj.function that ends
327  // final tuning
328 
329  double const fTrkValidationDist2D; // max. distance [cm] used in the track
330  // validation in the "third" plane
331  double const fHitTestingDist2D; // max. distance [cm] used in testing comp. of
332  // hits with the track
333 
334  double const fMinTwoViewFraction; // min. length fraction covered with multiple 2D
335  // view hits intertwinted with each other
336 
337  // Geometry and detector properties
339 };
340 
341 #endif
pma::Track3D * buildTrack(const detinfo::DetectorPropertiesData &detProp, const std::vector< art::Ptr< recob::Hit >> &hits_1, const std::vector< art::Ptr< recob::Hit >> &hits_2={}) const
bool addEndpointRef_(const detinfo::DetectorPropertiesData &detProp, 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
void AutoFlip(pma::Track3D::EDirection dir, double thr=0.0, unsigned int n=0)
Definition: PmaTrack3D.cxx:673
bool Has_(const std::vector< size_t > &v, size_t idx) const
Implementation of the Projection Matching Algorithm.
ProjectionMatchingAlg(const fhicl::ParameterSet &pset)
pma::Track3D * extendTrack(const detinfo::DetectorPropertiesData &clockData, 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.
geo::GeometryCore const * fGeom
Declaration of signal hit object.
pma::Hit3D const * front() const
Definition: PmaTrack3D.h:101
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:859
Geometry information for a single TPC.
Definition: TPCGeo.h:38
TVector3 const & Point3D() const
Definition: PmaHit3D.h:55
Planes which measure Z direction.
Definition: geo_types.h:132
static size_t getSegCount_(size_t trk_size)
recob::tracking::Vector_t Vector3D
bool GetCloseHits_(const detinfo::DetectorPropertiesData &detProp, 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
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
pma::Node3D * FirstElement() const
Definition: PmaTrack3D.h:343
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:348
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
double validate_on_adc_test(const detinfo::DetectorPropertiesData &detProp, const lariov::ChannelStatusProvider &channelStatus, const pma::Track3D &trk, const img::DataProviderAlg &adcImage, const std::vector< art::Ptr< recob::Hit >> &hits, TH1F *histoPassing, TH1F *histoRejected) const
void FilterOutSmallParts(const detinfo::DetectorPropertiesData &detProp, double r2d, const std::vector< art::Ptr< recob::Hit >> &hits_in, std::vector< art::Ptr< recob::Hit >> &hits_out, const TVector2 &vtx2d) const
BEGIN_PROLOG vertical distance to the surface Name
Class providing information about the quality of channels.
bool SameTPC(const TVector3 &p3d, float margin=0.0F) const
Check if p3d is in the same TPC as the node.
Definition: PmaNode3D.cxx:102
pma::Track3D * buildSegment(const detinfo::DetectorPropertiesData &clockData, const std::vector< art::Ptr< recob::Hit >> &hits_1, const std::vector< art::Ptr< recob::Hit >> &hits_2={}) const
Description of geometry of one entire detector.
Definition of data types for geometry description.
tuple dir
Definition: dropbox.py:28
double validate(const detinfo::DetectorPropertiesData &detProp, const lariov::ChannelStatusProvider &channelStatus, const pma::Track3D &trk, const std::vector< art::Ptr< recob::Hit >> &hits) const
void ShortenSeg_(const detinfo::DetectorPropertiesData &detProp, pma::Track3D &trk, const geo::TPCGeo &tpcgeom) const
bool chkEndpointHits_(const detinfo::DetectorPropertiesData &detProp, 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 * buildShowerSeg(const detinfo::DetectorPropertiesData &detProp, const std::vector< art::Ptr< recob::Hit >> &hits, const pma::Vector3D &vtx) const
void mergeTracks(const detinfo::DetectorPropertiesData &detProp, pma::Track3D &dst, pma::Track3D &src, bool reopt) const
ProjectionMatchingAlg(const Config &config)
void guideEndpoints(const detinfo::DetectorPropertiesData &clockData, pma::Track3D &trk, const std::map< unsigned int, std::vector< art::Ptr< recob::Hit >>> &hits) const
pma::Hit3D const * back() const
Definition: PmaTrack3D.h:106
std::vector< pma::Hit3D * > trimTrackToVolume(pma::Track3D &trk, TVector3 p0, TVector3 p1) const
void RemoveNotEnabledHits(pma::Track3D &trk) const
double twoViewFraction(pma::Track3D &trk) const
physics associatedGroupsWithLeft p1
bool TestTrk_(pma::Track3D &trk, const geo::TPCGeo &tpcgeom) const
auto const detProp
pma::Track3D * buildMultiTPCTrack(const detinfo::DetectorPropertiesData &clockData, const std::vector< art::Ptr< recob::Hit >> &hits) const