PMAlgVertexing.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Class: PMAlgVertexing
3 // Author: D.Stefan (Dorota.Stefan@ncbj.gov.pl) and R.Sulej (Robert.Sulej@cern.ch), August 2015
4 //
5 // 3D vertex finding for Projection Matching Algorithm
6 //
7 // Uses collection of pma::Track3D to find vertex candidates, then joins tracks in these points
8 // and reoptimizes full structure of tracks.
9 //
10 ////////////////////////////////////////////////////////////////////////////////////////////////////
11 
12 #ifndef PMAlgVertexing_h
13 #define PMAlgVertexing_h
14 
15 #include "fhiclcpp/types/Atom.h"
16 #include "fhiclcpp/types/Table.h"
17 
20 
21 // ROOT & C++
22 #include <memory>
23 
24 namespace detinfo {
25  class DetectorPropertiesData;
26 }
27 
28 namespace pma {
29  class PMAlgVertexing;
30 }
31 
33 public:
34  struct Config {
35  using Name = fhicl::Name;
37 
38  fhicl::Atom<double> MinTrackLength{
39  Name("MinTrackLength"),
40  Comment("min. length of tracks used to find vtx candidates (short tracks attached later)")};
41 
42  fhicl::Atom<bool> FindKinks{Name("FindKinks"),
43  Comment("detect significant kinks on long tracks")};
44 
45  fhicl::Atom<double> KinkMinDeg{Name("KinkMinDeg"), Comment("min. angle [deg] in XY of a kink")};
46 
47  fhicl::Atom<double> KinkMinStd{
48  Name("KinkMinStd"),
49  Comment("threshold in no. of stdev of all segment angles needed to tag a kink")};
50  };
51 
53 
54  PMAlgVertexing(const fhicl::ParameterSet& pset) : PMAlgVertexing(fhicl::Table<Config>(pset, {})())
55  {}
56 
57  ~PMAlgVertexing(); // delete last produced tracks (if not passed to output)
58 
59  void
61  {
62  cleanTracks();
63  }
64 
65  /// Copy input tracks, find 3D vertices, connect tracks, break them or flip if needed,
66  /// reoptimize track structures. Result is returned as a collection of new tracks, that
67  /// replaces content of trk_input (old tracks are deleted).
68  /// Vertices can be accessed with getVertices function.
69  size_t run(const detinfo::DetectorPropertiesData& detProp, pma::TrkCandidateColl& trk_input);
70 
71  /// Copy input tracks, use provided 3D vertices to connect tracks, break tracks or flip if
72  /// needed, reoptimize track structures. Result is returned as a collection of new tracks,
73  /// that replaces content of trk_input (old tracks are deleted).
74  /// Input vertices that were actually associated to tracks are copied to the output
75  /// collection (use getVertices function).
76  size_t run(pma::TrkCandidateColl& trk_input, const std::vector<TVector3>& vtx_input);
77 
78  std::vector<std::pair<TVector3, std::vector<std::pair<size_t, bool>>>> getVertices(
80  bool onlyBranching = false) const;
81 
82  std::vector<std::pair<TVector3, size_t>> getKinks(const pma::TrkCandidateColl& tracks) const;
83 
84 private:
85  bool
86  has(const std::vector<size_t>& v, size_t idx) const
87  {
88  for (auto c : v)
89  if (c == idx) return true;
90  return false;
91  }
92 
93  std::vector<pma::VtxCandidate> firstPassCandidates() const;
94  std::vector<pma::VtxCandidate> secondPassCandidates() const;
95  size_t makeVertices(detinfo::DetectorPropertiesData const& detProp,
96  std::vector<pma::VtxCandidate>& candidates);
97 
98  /// Get dQ/dx sequence to detect various features.
99  std::vector<std::pair<double, double>> getdQdx(const pma::Track3D& trk) const;
100 
101  /// Get convolution value.
102  double convolute(size_t idx, size_t len, double* adc, double const* shape) const;
103 
104  /// Check if colinear in 3D and dQ/dx with no significant step.
105  bool isSingleParticle(pma::Track3D* trk1, pma::Track3D* trk2) const;
106 
107  /// Find elastic scattering vertices on tracks, merge back tracks that were split
108  /// during vertex finding. 3D angle between two tracks and dQ/dx is checked.
109  void mergeBrokenTracks(pma::TrkCandidateColl& trk_input) const;
110 
111  /// Split track and add vertex and reoptimize when dQ/dx step detected.
112  void splitMergedTracks(pma::TrkCandidateColl& trk_input) const;
113 
114  /// Remove penalty on the angle if kink detected and reopt track.
115  void findKinksOnTracks(const detinfo::DetectorPropertiesData& detProp,
116  pma::TrkCandidateColl& trk_input) const;
117 
118  pma::TrkCandidateColl fOutTracks, fShortTracks, fEmTracks;
120  void cleanTracks();
121 
122  void sortTracks(const pma::TrkCandidateColl& trk_input);
123  void collectTracks(pma::TrkCandidateColl& result);
124 
125  // Parameters used in the algorithm
126 
127  double fMinTrackLength; // min. length of tracks used to find vtx candidates
128  // (short tracks attached later)
129 
130  bool fFindKinks; // detect significant kinks on long tracks (need min. 5 nodes
131  // to collect angle stats)
132  double fKinkMinDeg; // min. angle [deg] in XY of a kink
133  double fKinkMinStd; // threshold in no. of stdev of all segment angles needed to tag a kink
134 
135  // just to remember:
136  //double fInputVtxDist2D; // use vtx given at input if dist. [cm] to track in all 2D projections is below this max. value
137  //double fInputVtxDistY; // use vtx given at input if dist. [cm] to track in 3D-Y is below this max. value
138 };
139 
140 #endif
Vertex finding helper for the Projection Matching Algorithm.
pma::TrkCandidateColl fShortTracks
static QCString result
ChannelGroupService::Name Name
int16_t adc
Definition: CRTFragment.hh:202
static Config * config
Definition: config.cpp:1054
pma::TrkCandidateColl fExcludedTracks
General LArSoft Utilities.
Track finding helper for the Projection Matching Algorithm.
Definition: tracks.py:1
#define Comment
PMAlgVertexing(const fhicl::ParameterSet &pset)
bool has(const std::vector< size_t > &v, size_t idx) const