PMAlgTracking.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////////////////////////////
2 // 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 //
10 ///////////////////////////////////////////////////////////////////////////////////////////////////////
11 
12 #ifndef PMAlgTracking_h
13 #define PMAlgTracking_h
14 
15 // Framework includes
16 #include "canvas/Persistency/Common/FindManyP.h"
18 #include "fhiclcpp/types/Atom.h"
20 
21 // LArSoft includes
35 
36 namespace detinfo {
37  class DetectorProperties;
38 }
39 namespace geo {
40  class GeometryCore;
41 }
42 
43 // ROOT & C++
44 class TH1F;
45 class TVector3;
46 
47 namespace pma {
48  typedef std::map<size_t, pma::TrkCandidateColl> tpc_track_map;
49 
50  recob::Track convertFrom(const pma::Track3D& src, unsigned int tidx, int pdg = 0);
51 
52  class PMAlgTrackingBase;
53  class PMAlgFitter;
54  class PMAlgTracker;
55  class Track3D;
56 }
57 
59 public:
62  {
63  return fResult;
64  }
65 
66  std::vector<std::pair<TVector3, std::vector<std::pair<size_t, bool>>>>
67  getVertices(bool onlyBranching = false) const
68  {
69  return fPMAlgVertexing.getVertices(fResult, onlyBranching);
70  }
71 
72  std::vector<std::pair<TVector3, size_t>>
73  getKinks() const
74  {
75  return fPMAlgVertexing.getKinks(fResult);
76  }
77 
78 protected:
80  const pma::ProjectionMatchingAlg::Config& pmalgConfig,
81  const pma::PMAlgVertexing::Config& pmvtxConfig);
83 
84  void guideEndpoints(detinfo::DetectorPropertiesData const& detProp,
86 
88 
91 
93 };
94 
96 public:
97  struct Config {
98  using Name = fhicl::Name;
100 
101  fhicl::Sequence<int> TrackingOnlyPdg{
102  Name("TrackingOnlyPdg"),
103  Comment("PDG list to select which PFParticles should be reconstructed; all PFP's are used if "
104  "the list is empty or starts with 0")};
105 
106  fhicl::Sequence<int> TrackingSkipPdg{
107  Name("TrackingSkipPdg"),
108  Comment("PDG list to select which PFParticles should NOT be reconstructed, e.g. skip EM-like "
109  "if contains 11; no skipping if the list is empty or starts with 0")};
110 
111  fhicl::Atom<bool> RunVertexing{
112  Name("RunVertexing"),
113  Comment(
114  "find vertices from PFP hierarchy, join with tracks, reoptimize track-vertex structure")};
115  };
116 
117  PMAlgFitter(const std::vector<art::Ptr<recob::Hit>>& allhitlist,
118  const std::vector<recob::Cluster>& clusters,
119  const std::vector<recob::PFParticle>& pfparticles,
120  const art::FindManyP<recob::Hit>& hitsFromClusters,
121  const art::FindManyP<recob::Cluster>& clusFromPfps,
122  const art::FindManyP<recob::Vertex>& vtxFromPfps,
123  const pma::ProjectionMatchingAlg::Config& pmalgConfig,
124  const pma::PMAlgFitter::Config& pmalgFitterConfig,
125  const pma::PMAlgVertexing::Config& pmvtxConfig);
126 
127  int build(detinfo::DetectorPropertiesData const& detProp);
128 
129 private:
130  void buildTracks(detinfo::DetectorPropertiesData const& detProp);
131  void buildShowers(detinfo::DetectorPropertiesData const& detProp);
132 
133  bool
134  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 
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,
270  const std::vector<art::Ptr<recob::Hit>>& hits,
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::DetectorClocksData const& clockData,
291  detinfo::DetectorPropertiesData const& detProp,
292  pma::TrkCandidateColl& tracks) const;
293  void mergeCoLinear(detinfo::DetectorClocksData const& clockData,
294  detinfo::DetectorPropertiesData const& detProp,
295  pma::tpc_track_map& tracks) const;
296 
297  double validate(detinfo::DetectorPropertiesData const& detProp,
298  pma::Track3D& trk,
299  unsigned int testView);
300 
301  void fromMaxCluster_tpc(detinfo::DetectorPropertiesData const& detProp,
303  size_t minBuildSize,
304  unsigned int tpc,
305  unsigned int cryo);
306 
307  size_t matchTrack(detinfo::DetectorPropertiesData const& detProp,
308  const pma::TrkCandidateColl& tracks,
309  const std::vector<art::Ptr<recob::Hit>>& hits) const;
310 
311  pma::TrkCandidate matchCluster(detinfo::DetectorPropertiesData const& detProp,
312  int first_clu_idx,
313  const std::vector<art::Ptr<recob::Hit>>& first_hits,
314  size_t minSizeCompl,
315  unsigned int tpc,
316  unsigned int cryo,
317  geo::View_t first_view);
318 
321  int first_clu_idx,
322  size_t minSizeCompl,
323  unsigned int tpc,
324  unsigned int cryo,
325  geo::View_t first_view)
326  {
327  return matchCluster(
328  detProp, first_clu_idx, fCluHits[first_clu_idx], minSizeCompl, tpc, cryo, first_view);
329  }
330 
331  int matchCluster(detinfo::DetectorPropertiesData const& detProp,
332  const pma::TrkCandidate& trk,
333  size_t minSize,
334  double fraction,
335  unsigned int preferedView,
336  unsigned int testView,
337  unsigned int tpc,
338  unsigned int cryo) const;
339 
340  bool extendTrack(detinfo::DetectorPropertiesData const& detProp,
341  pma::TrkCandidate& candidate,
342  const std::vector<art::Ptr<recob::Hit>>& hits,
343  unsigned int testView,
344  bool add_nodes);
345 
346  int maxCluster(detinfo::DetectorPropertiesData const& detProp,
347  int first_idx_tag,
348  const pma::TrkCandidateColl& candidates,
349  float xmin,
350  float xmax,
351  size_t min_clu_size,
352  geo::View_t view,
353  unsigned int tpc,
354  unsigned int cryo) const;
355 
356  int maxCluster(size_t min_clu_size, geo::View_t view, unsigned int tpc, unsigned int cryo) const;
357 
358  void listUsedClusters(detinfo::DetectorPropertiesData const& detProp) const;
359 
360  bool
361  has(const std::vector<size_t>& v, size_t idx) const
362  {
363  for (auto c : v)
364  if (c == idx) return true;
365  return false;
366  }
367 
368  const std::vector<recob::Wire>& fWires;
369  std::vector<std::vector<art::Ptr<recob::Hit>>> fCluHits;
370  std::vector<float> fCluWeights;
371 
372  /// --------------------------------------------------------------
373  std::vector<size_t> fUsedClusters, fInitialClusters;
374  mutable std::map<unsigned int, std::vector<size_t>> fTriedClusters;
375  std::vector<geo::View_t> fAvailableViews;
376  /// --------------------------------------------------------------
377 
378  // ******************** fcl parameters **********************
379  size_t fMinSeedSize1stPass; // min. cluster size used to start building a track in the 1st pass
380  size_t fMinSeedSize2ndPass; // min. cluster size used to start building a track in the 2nd pass
381  float fTrackLikeThreshold; // trk-like threshold on cnn output
383 
384  bool fFlipToBeam; // set the track direction to increasing Z values
385  bool fFlipDownward; // set the track direction to decreasing Y values
386  bool fFlipToX; // set the track direction to decreasing X values
387  bool fAutoFlip_dQdx; // set the track direction to increasing dQ/dx
388 
389  bool fMergeWithinTPC; // merge witnin single TPC; finds tracks best matching
390  // by angle, with limits:
391  double fMergeTransverseShift; // - max. transverse displacement [cm] between
392  // tracks
393  double fMergeAngle; // - max. angle [degree] between tracks (nearest segments)
394 
395  pma::PMAlgCosmicTagger fCosmicTagger; // cosmic tagger alg
396  bool fTagCosmicTracks; // do any tagging of cosmic rays (simple or of tagger
397  // flags)
398 
399  bool fStitchBetweenTPCs; // stitch between TPCs; finds tracks best matching by
400  // angle, with limits:
401  double fStitchDistToWall; // - max. track endpoint distance [cm] to TPC boundary
402  double fStitchTransverseShift; // - max. transverse displacement [cm]
403  // between tracks
404  double fStitchAngle; // - max. angle [degree] between tracks (nearest segments)
405 
406  bool fMatchT0inAPACrossing; // match T0 of APA-crossing tracks using
407  // PMAlgStitcher
408  bool fMatchT0inCPACrossing; // match T0 of CPA-crossing tracks using
409  // PMAlgStitcher
410 
412 
413  bool fRunVertexing; // run vertex finding
414 
415  EValidationMode fValidation; // track validation mode
416  std::vector<img::DataProviderAlg> fAdcImages; // adc image making algorithms for each plane
417  std::vector<double> fAdcValidationThr; // threshold on pixel values in the adc image
418 
419  // references to the validation calibration histograms
420  const std::vector<TH1F*>& fAdcInPassingPoints;
421  const std::vector<TH1F*>& fAdcInRejectedPoints;
422 
423  // *********************** services *************************
425 };
426 
427 #endif
std::vector< std::pair< TVector3, size_t > > getKinks() const
Definition: PMAlgTracking.h:73
std::map< int, pma::Vector3D > fPfpVtx
void Validation()
Definition: Validation.cpp:272
static QCString result
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
double fMinTwoViewFraction
struct vector vector
ChannelGroupService::Name Name
std::map< size_t, pma::TrkCandidateColl > tpc_track_map
Definition: PMAlgTracking.h:48
std::map< unsigned int, tpc_view_hitmap > cryo_tpc_view_hitmap
pma::PMAlgCosmicTagger fCosmicTagger
std::map< int, std::vector< art::Ptr< recob::Cluster > > > fPfpClusters
init
Definition: train.py:42
double fStitchTransverseShift
std::map< unsigned int, std::vector< size_t > > fTriedClusters
std::vector< double > fAdcValidationThr
std::vector< int > fTrackingOnlyPdg
pma::PMAlgStitching fStitcher
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:67
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:89
double fMergeTransverseShift
General LArSoft Utilities.
Description of geometry of one entire detector.
std::vector< size_t > fUsedClusters
const pma::TrkCandidateColl & result()
Definition: PMAlgTracking.h:61
Definition of data types for geometry description.
def validate(nxgraph, desc)
Definition: graph.py:45
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
Definition: tracks.py:1
Implementation of the Projection Matching Algorithm.
Declaration of signal hit object.
#define Comment
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
Provides recob::Track data product.
std::vector< geo::View_t > fAvailableViews
size_t fMinSeedSize1stPass
pma::TrkCandidateColl fResult
Definition: PMAlgTracking.h:92
EValidationMode fValidation
LArSoft geometry interface.
Definition: ChannelGeo.h:16
pma::PMAlgVertexing fPMAlgVertexing
Definition: PMAlgTracking.h:90
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:87
std::vector< img::DataProviderAlg > fAdcImages