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