LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
PMAlgTracking.h
Go to the documentation of this file.
1 // Class: PMAlgTracking
3 // Author: D.Stefan (Dorota.Stefan@ncbj.gov.pl),
4 // R.Sulej (Robert.Sulej@cern.ch),
5 // L.Whitehead (leigh.howard.whitehead@cern.ch), June 2016
6 //
7 // Single track reconstruction toolkit based on Projection Matching Algorithm. Uses cluster collections
8 // to find single tracks (modularized version of our original code).
9 //
11 
12 #ifndef PMAlgTracking_h
13 #define PMAlgTracking_h
14 
15 // Framework includes
18 #include "fhiclcpp/types/Atom.h"
19 #include "fhiclcpp/types/Comment.h"
20 #include "fhiclcpp/types/Name.h"
22 
23 // LArSoft includes
37 
38 namespace detinfo {
39  class DetectorProperties;
40 }
41 namespace geo {
42  class GeometryCore;
43 }
44 
45 // ROOT & C++
46 class TH1F;
47 class TVector3;
48 
49 #include <map>
50 #include <utility>
51 #include <vector>
52 
53 namespace pma {
54  typedef std::map<size_t, pma::TrkCandidateColl> tpc_track_map;
55 
56  recob::Track convertFrom(const pma::Track3D& src, unsigned int tidx, int pdg = 0);
57 
58  class PMAlgTrackingBase;
59  class PMAlgFitter;
60  class PMAlgTracker;
61  class Track3D;
62 }
63 
65 public:
66  const pma::TrkCandidateColl& result() { return fResult; }
67 
68  std::vector<std::pair<TVector3, std::vector<std::pair<size_t, bool>>>> getVertices(
69  bool onlyBranching = false) const
70  {
71  return fPMAlgVertexing.getVertices(fResult, onlyBranching);
72  }
73 
74  std::vector<std::pair<TVector3, size_t>> getKinks() const
75  {
76  return fPMAlgVertexing.getKinks(fResult);
77  }
78 
79 protected:
81  const pma::ProjectionMatchingAlg::Config& pmalgConfig,
82  const pma::PMAlgVertexing::Config& pmvtxConfig);
84 
85  void guideEndpoints(detinfo::DetectorPropertiesData const& detProp,
86  pma::TrkCandidateColl& tracks);
87 
89 
92 
94 };
95 
97 public:
98  struct Config {
99  using Name = fhicl::Name;
101 
102  fhicl::Sequence<int> TrackingOnlyPdg{
103  Name("TrackingOnlyPdg"),
104  Comment("PDG list to select which PFParticles should be reconstructed; all PFP's are used if "
105  "the list is empty or starts with 0")};
106 
107  fhicl::Sequence<int> TrackingSkipPdg{
108  Name("TrackingSkipPdg"),
109  Comment("PDG list to select which PFParticles should NOT be reconstructed, e.g. skip EM-like "
110  "if contains 11; no skipping if the list is empty or starts with 0")};
111 
112  fhicl::Atom<bool> RunVertexing{
113  Name("RunVertexing"),
114  Comment(
115  "find vertices from PFP hierarchy, join with tracks, reoptimize track-vertex structure")};
116  };
117 
118  PMAlgFitter(const std::vector<art::Ptr<recob::Hit>>& allhitlist,
119  const std::vector<recob::Cluster>& clusters,
120  const std::vector<recob::PFParticle>& pfparticles,
121  const art::FindManyP<recob::Hit>& hitsFromClusters,
122  const art::FindManyP<recob::Cluster>& clusFromPfps,
123  const art::FindManyP<recob::Vertex>& vtxFromPfps,
124  const pma::ProjectionMatchingAlg::Config& pmalgConfig,
125  const pma::PMAlgFitter::Config& pmalgFitterConfig,
126  const pma::PMAlgVertexing::Config& pmvtxConfig);
127 
128  int build(detinfo::DetectorPropertiesData const& detProp);
129 
130 private:
131  void buildTracks(detinfo::DetectorPropertiesData const& detProp);
132  void buildShowers(detinfo::DetectorPropertiesData const& detProp);
133 
134  bool has(const std::vector<int>& v, int i) const
135  {
136  for (auto c : v) {
137  if (c == i) return true;
138  }
139  return false;
140  }
141 
142  std::vector<std::vector<art::Ptr<recob::Hit>>> fCluHits;
143  std::map<int, std::vector<art::Ptr<recob::Cluster>>> fPfpClusters;
144  std::map<int, pma::Vector3D> fPfpVtx;
145  std::map<int, int> fPfpPdgCodes;
146 
147  // ******************** fcl parameters ***********************
148  std::vector<int> fTrackingOnlyPdg; // make tracks only for this pdg's when
149  // using input from PFParticles
150  std::vector<int> fTrackingSkipPdg; // skip tracks with this pdg's when using
151  // input from PFParticles
152  bool fRunVertexing; // run vertex finding
153 };
154 
156 public:
157  enum EValidationMode { kHits = 1, kAdc = 2, kCalib = 3 };
158 
159  struct Config {
160  using Name = fhicl::Name;
162 
163  fhicl::Atom<size_t> MinSeedSize1stPass{
164  Name("MinSeedSize1stPass"),
165  Comment("min. cluster size used to start building a track in the 1st pass")};
166 
167  fhicl::Atom<size_t> MinSeedSize2ndPass{
168  Name("MinSeedSize2ndPass"),
169  Comment("min. cluster size used to start building a track in the 2nd pass")};
170 
171  fhicl::Atom<float> TrackLikeThreshold{Name("TrackLikeThreshold"),
172  Comment("Threshold for track-like recognition")};
173 
174  fhicl::Atom<bool> RunVertexing{
175  Name("RunVertexing"),
176  Comment(
177  "find vertices from PFP hierarchy, join with tracks, reoptimize track-vertex structure")};
178 
179  fhicl::Atom<bool> FlipToBeam{Name("FlipToBeam"),
180  Comment("set the track direction to increasing Z values")};
181 
182  fhicl::Atom<bool> FlipDownward{
183  Name("FlipDownward"),
184  Comment("set the track direction to decreasing Y values (like cosmic rays)")};
185 
187  Name("FlipToX"),
188  Comment("set the track direction to decreasing X values (like cosmic rays in dual phase)")};
189 
190  fhicl::Atom<bool> AutoFlip_dQdx{
191  Name("AutoFlip_dQdx"),
192  Comment("set the track direction to increasing dQ/dx (overrides FlipToBeam, FlipDownward and "
193  "FlipToX if significant rise of dQ/dx at the track end)")};
194 
195  fhicl::Atom<bool> MergeWithinTPC{
196  Name("MergeWithinTPC"),
197  Comment("merge witnin single TPC; finds tracks best matching by angle and displacement")};
198 
199  fhicl::Atom<double> MergeTransverseShift{
200  Name("MergeTransverseShift"),
201  Comment("max. transverse displacement [cm] between tracks")};
202 
204  Name("MergeAngle"),
205  Comment("max. angle [degree] between tracks (nearest segments)")};
206 
207  fhicl::Atom<bool> StitchBetweenTPCs{
208  Name("StitchBetweenTPCs"),
209  Comment("stitch between TPCs; finds tracks best matching by angle and displacement")};
210 
211  fhicl::Atom<double> StitchDistToWall{
212  Name("StitchDistToWall"),
213  Comment("max. track endpoint distance [cm] to TPC boundary")};
214 
215  fhicl::Atom<double> StitchTransverseShift{
216  Name("StitchTransverseShift"),
217  Comment("max. transverse displacement [cm] between tracks")};
218 
219  fhicl::Atom<double> StitchAngle{
220  Name("StitchAngle"),
221  Comment("max. angle [degree] between tracks (nearest segments)")};
222 
223  fhicl::Atom<bool> MatchT0inAPACrossing{
224  Name("MatchT0inAPACrossing"),
225  Comment("match T0 of APA-crossing tracks using PMAlgStitcher")};
226 
227  fhicl::Atom<bool> MatchT0inCPACrossing{
228  Name("MatchT0inCPACrossing"),
229  Comment("match T0 of CPA-crossing tracks using PMAlgStitcher")};
230 
231  fhicl::Atom<std::string> Validation{Name("Validation"),
232  Comment("tracks validation mode: hits, adc, calib")};
233 
234  fhicl::Sequence<double> AdcValidationThr{
235  Name("AdcValidationThr"),
236  Comment("thresholds for not-empty pixel in the ADC track validation")};
237 
239  Name("AdcImageAlg"),
240  Comment("ADC based image used for the track validation")};
241  };
242 
243  PMAlgTracker(const std::vector<art::Ptr<recob::Hit>>& allhitlist,
244  const std::vector<recob::Wire>& wires,
245  const pma::ProjectionMatchingAlg::Config& pmalgConfig,
246  const pma::PMAlgTracker::Config& pmalgTrackerConfig,
247  const pma::PMAlgVertexing::Config& pmvtxConfig,
248  const pma::PMAlgStitching::Config& pmstitchConfig,
249  const pma::PMAlgCosmicTagger::Config& pmtaggerConfig,
250 
251  const std::vector<TH1F*>& hpassing,
252  const std::vector<TH1F*>& hrejected);
253 
254  void init(const art::FindManyP<recob::Hit>& hitsFromClusters);
255 
256  void init(const art::FindManyP<recob::Hit>& hitsFromClusters,
257  const std::vector<float>& trackLike);
258 
259  void init(const art::FindManyP<recob::Hit>& hitsFromClusters,
260  const art::FindManyP<recob::Hit>& hitsFromEmParts);
261 
262  int build(detinfo::DetectorClocksData const& clockData,
263  detinfo::DetectorPropertiesData const& detProp);
264 
265 private:
266  double collectSingleViewEnd(pma::Track3D& trk, std::vector<art::Ptr<recob::Hit>>& hits) const;
267  double collectSingleViewFront(pma::Track3D& trk, std::vector<art::Ptr<recob::Hit>>& hits) const;
268 
269  bool reassignHits_1(detinfo::DetectorPropertiesData const& detProp,
271  pma::TrkCandidateColl& tracks,
272  size_t trk_idx,
273  double dist2);
274  bool reassignSingleViewEnds_1(detinfo::DetectorPropertiesData const& detProp,
275  pma::TrkCandidateColl& tracks); // use clusters
276 
277  bool areCoLinear(pma::Track3D* trk1,
278  pma::Track3D* trk2,
279  double& dist,
280  double& cos3d,
281  bool& reverseOrder,
282  double distThr,
283  double distThrMin,
284  double distProjThr,
285  double cosThr) const;
286 
287  void freezeBranchingNodes(pma::TrkCandidateColl& tracks) const;
288  void releaseAllNodes(pma::TrkCandidateColl& tracks) const;
289 
290  bool mergeCoLinear(detinfo::DetectorPropertiesData const& detProp,
291  pma::TrkCandidateColl& tracks) const;
292  void mergeCoLinear(detinfo::DetectorClocksData const& clockData,
293  detinfo::DetectorPropertiesData const& detProp,
294  pma::tpc_track_map& tracks) const;
295 
296  double validate(detinfo::DetectorPropertiesData const& detProp,
297  pma::Track3D& trk,
298  unsigned int testView);
299 
300  void fromMaxCluster_tpc(detinfo::DetectorPropertiesData const& detProp,
301  pma::TrkCandidateColl& result,
302  size_t minBuildSize,
303  unsigned int tpc,
304  unsigned int cryo);
305 
306  size_t matchTrack(detinfo::DetectorPropertiesData const& detProp,
307  const pma::TrkCandidateColl& tracks,
308  const std::vector<art::Ptr<recob::Hit>>& hits) const;
309 
310  pma::TrkCandidate matchCluster(detinfo::DetectorPropertiesData const& detProp,
311  int first_clu_idx,
312  const std::vector<art::Ptr<recob::Hit>>& first_hits,
313  size_t minSizeCompl,
314  unsigned int tpc,
315  unsigned int cryo,
316  geo::View_t first_view);
317 
319  int first_clu_idx,
320  size_t minSizeCompl,
321  unsigned int tpc,
322  unsigned int cryo,
323  geo::View_t first_view)
324  {
325  return matchCluster(
326  detProp, first_clu_idx, fCluHits[first_clu_idx], minSizeCompl, tpc, cryo, first_view);
327  }
328 
329  int matchCluster(detinfo::DetectorPropertiesData const& detProp,
330  const pma::TrkCandidate& trk,
331  size_t minSize,
332  double fraction,
333  unsigned int preferedView,
334  unsigned int testView) const;
335 
336  bool extendTrack(detinfo::DetectorPropertiesData const& detProp,
337  pma::TrkCandidate& candidate,
339  unsigned int testView,
340  bool add_nodes);
341 
342  int maxCluster(detinfo::DetectorPropertiesData const& detProp,
343  int first_idx_tag,
344  const pma::TrkCandidateColl& candidates,
345  float xmin,
346  float xmax,
347  size_t min_clu_size,
348  geo::View_t view,
349  unsigned int tpc,
350  unsigned int cryo) const;
351 
352  int maxCluster(size_t min_clu_size, geo::View_t view, unsigned int tpc, unsigned int cryo) const;
353 
354  void listUsedClusters(detinfo::DetectorPropertiesData const& detProp) const;
355 
356  bool has(const std::vector<size_t>& v, size_t idx) const
357  {
358  for (auto c : v)
359  if (c == idx) return true;
360  return false;
361  }
362 
363  const std::vector<recob::Wire>& fWires;
364  std::vector<std::vector<art::Ptr<recob::Hit>>> fCluHits;
365  std::vector<float> fCluWeights;
366 
368  std::vector<size_t> fUsedClusters, fInitialClusters;
369  mutable std::map<unsigned int, std::vector<size_t>> fTriedClusters;
370  std::vector<geo::View_t> fAvailableViews;
372 
373  // ******************** fcl parameters **********************
374  size_t fMinSeedSize1stPass; // min. cluster size used to start building a track in the 1st pass
375  size_t fMinSeedSize2ndPass; // min. cluster size used to start building a track in the 2nd pass
376  float fTrackLikeThreshold; // trk-like threshold on cnn output
378 
379  bool fFlipToBeam; // set the track direction to increasing Z values
380  bool fFlipDownward; // set the track direction to decreasing Y values
381  bool fFlipToX; // set the track direction to decreasing X values
382  bool fAutoFlip_dQdx; // set the track direction to increasing dQ/dx
383 
384  bool fMergeWithinTPC; // merge witnin single TPC; finds tracks best matching
385  // by angle, with limits:
386  double fMergeTransverseShift; // - max. transverse displacement [cm] between
387  // tracks
388  double fMergeAngle; // - max. angle [degree] between tracks (nearest segments)
389 
390  pma::PMAlgCosmicTagger fCosmicTagger; // cosmic tagger alg
391  bool fTagCosmicTracks; // do any tagging of cosmic rays (simple or of tagger
392  // flags)
393 
394  bool fStitchBetweenTPCs; // stitch between TPCs; finds tracks best matching by
395  // angle, with limits:
396  double fStitchDistToWall; // - max. track endpoint distance [cm] to TPC boundary
397  double fStitchTransverseShift; // - max. transverse displacement [cm]
398  // between tracks
399  double fStitchAngle; // - max. angle [degree] between tracks (nearest segments)
400 
401  bool fMatchT0inAPACrossing; // match T0 of APA-crossing tracks using
402  // PMAlgStitcher
403  bool fMatchT0inCPACrossing; // match T0 of CPA-crossing tracks using
404  // PMAlgStitcher
405 
407 
408  bool fRunVertexing; // run vertex finding
409 
410  EValidationMode fValidation; // track validation mode
411  std::vector<img::DataProviderAlg> fAdcImages; // adc image making algorithms for each plane
412  std::vector<double> fAdcValidationThr; // threshold on pixel values in the adc image
413 
414  // references to the validation calibration histograms
415  const std::vector<TH1F*>& fAdcInPassingPoints;
416  const std::vector<TH1F*>& fAdcInRejectedPoints;
417 
418  // *********************** services *************************
420 };
421 
422 #endif
std::vector< std::pair< TVector3, size_t > > getKinks() const
Definition: PMAlgTracking.h:74
std::map< int, pma::Vector3D > fPfpVtx
recob::Track convertFrom(const pma::Track3D &src, unsigned int tidx, int pdg=0)
geo::GeometryCore const * fGeom
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
size_t fMinSeedSize2ndPass
Declaration of signal hit object.
double fMinTwoViewFraction
std::map< size_t, pma::TrkCandidateColl > tpc_track_map
Definition: PMAlgTracking.h:54
std::map< unsigned int, tpc_view_hitmap > cryo_tpc_view_hitmap
pma::PMAlgCosmicTagger fCosmicTagger
std::map< int, std::vector< art::Ptr< recob::Cluster > > > fPfpClusters
double fStitchTransverseShift
std::map< unsigned int, std::vector< size_t > > fTriedClusters
std::vector< double > fAdcValidationThr
std::vector< int > fTrackingOnlyPdg
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
pma::PMAlgStitching fStitcher
void hits()
Definition: readHits.C:15
std::map< int, int > fPfpPdgCodes
std::vector< std::pair< TVector3, std::vector< std::pair< size_t, bool > > > > getVertices(bool onlyBranching=false) const
Definition: PMAlgTracking.h:68
std::vector< int > fTrackingSkipPdg
const std::vector< recob::Wire > & fWires
bool has(const std::vector< size_t > &v, size_t idx) const
pma::ProjectionMatchingAlg fProjectionMatchingAlg
Definition: PMAlgTracking.h:90
double fMergeTransverseShift
Provides recob::Track data product.
General LArSoft Utilities.
Description of geometry of one entire detector.
Definition: GeometryCore.h:119
Declaration of cluster object.
std::vector< size_t > fUsedClusters
const pma::TrkCandidateColl & result()
Definition: PMAlgTracking.h:66
Definition of data types for geometry description.
bool has(const std::vector< int > &v, int i) const
std::vector< std::vector< art::Ptr< recob::Hit > > > fCluHits
std::vector< std::vector< art::Ptr< recob::Hit > > > fCluHits
Track finding helper for the Projection Matching Algorithm.
std::vector< float > fCluWeights
Implementation of the Projection Matching Algorithm.
Contains all timing reference information for the detector.
const std::vector< TH1F * > & fAdcInPassingPoints
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
const std::vector< TH1F * > & fAdcInRejectedPoints
std::vector< geo::View_t > fAvailableViews
size_t fMinSeedSize1stPass
pma::TrkCandidateColl fResult
Definition: PMAlgTracking.h:93
EValidationMode fValidation
Namespace collecting geometry-related classes utilities.
pma::PMAlgVertexing fPMAlgVertexing
Definition: PMAlgTracking.h:91
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49
pma::TrkCandidate matchCluster(detinfo::DetectorPropertiesData const &detProp, int first_clu_idx, size_t minSizeCompl, unsigned int tpc, unsigned int cryo, geo::View_t first_view)
pma::cryo_tpc_view_hitmap fHitMap
Definition: PMAlgTracking.h:88
std::vector< img::DataProviderAlg > fAdcImages