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