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