All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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/Comment.h"
17 #include "fhiclcpp/types/Name.h"
18 #include "fhiclcpp/types/Table.h"
19 
22 
23 // ROOT & C++
24 #include <memory>
25 #include <utility>
26 #include <vector>
27 
28 namespace detinfo {
29  class DetectorPropertiesData;
30 }
31 
32 namespace pma {
33  class PMAlgVertexing;
34 }
35 
37 public:
38  struct Config {
39  using Name = fhicl::Name;
40  using Comment = fhicl::Comment;
41 
42  fhicl::Atom<double> MinTrackLength{
43  Name("MinTrackLength"),
44  Comment("min. length of tracks used to find vtx candidates (short tracks attached later)")};
45 
46  fhicl::Atom<bool> FindKinks{Name("FindKinks"),
47  Comment("detect significant kinks on long tracks")};
48 
49  fhicl::Atom<double> KinkMinDeg{Name("KinkMinDeg"), Comment("min. angle [deg] in XY of a kink")};
50 
51  fhicl::Atom<double> KinkMinStd{
52  Name("KinkMinStd"),
53  Comment("threshold in no. of stdev of all segment angles needed to tag a kink")};
54  };
55 
56  PMAlgVertexing(const Config& config);
57 
58  PMAlgVertexing(const fhicl::ParameterSet& pset) : PMAlgVertexing(fhicl::Table<Config>(pset, {})())
59  {}
60 
61  ~PMAlgVertexing(); // delete last produced tracks (if not passed to output)
62 
63  void
65  {
66  cleanTracks();
67  }
68 
69  /// Copy input tracks, find 3D vertices, connect tracks, break them or flip if needed,
70  /// reoptimize track structures. Result is returned as a collection of new tracks, that
71  /// replaces content of trk_input (old tracks are deleted).
72  /// Vertices can be accessed with getVertices function.
74 
75  /// Copy input tracks, use provided 3D vertices to connect tracks, break tracks or flip if
76  /// needed, reoptimize track structures. Result is returned as a collection of new tracks,
77  /// that replaces content of trk_input (old tracks are deleted).
78  /// Input vertices that were actually associated to tracks are copied to the output
79  /// collection (use getVertices function).
80  size_t run(pma::TrkCandidateColl& trk_input, const std::vector<TVector3>& vtx_input);
81 
82  std::vector<std::pair<TVector3, std::vector<std::pair<size_t, bool>>>> getVertices(
84  bool onlyBranching = false) const;
85 
86  std::vector<std::pair<TVector3, size_t>> getKinks(const pma::TrkCandidateColl& tracks) const;
87 
88 private:
89  bool
90  has(const std::vector<size_t>& v, size_t idx) const
91  {
92  for (auto c : v)
93  if (c == idx) return true;
94  return false;
95  }
96 
97  std::vector<pma::VtxCandidate> firstPassCandidates() const;
98  std::vector<pma::VtxCandidate> secondPassCandidates() const;
100  std::vector<pma::VtxCandidate>& candidates);
101 
102  /// Get dQ/dx sequence to detect various features.
103  std::vector<std::pair<double, double>> getdQdx(const pma::Track3D& trk) const;
104 
105  /// Get convolution value.
106  double convolute(size_t idx, size_t len, double* adc, double const* shape) const;
107 
108  /// Check if colinear in 3D and dQ/dx with no significant step.
109  bool isSingleParticle(pma::Track3D* trk1, pma::Track3D* trk2) const;
110 
111  /// Find elastic scattering vertices on tracks, merge back tracks that were split
112  /// during vertex finding. 3D angle between two tracks and dQ/dx is checked.
113  void mergeBrokenTracks(pma::TrkCandidateColl& trk_input) const;
114 
115  /// Split track and add vertex and reoptimize when dQ/dx step detected.
116  void splitMergedTracks(pma::TrkCandidateColl& trk_input) const;
117 
118  /// Remove penalty on the angle if kink detected and reopt track.
120  pma::TrkCandidateColl& trk_input) const;
121 
124  void cleanTracks();
125 
126  void sortTracks(const pma::TrkCandidateColl& trk_input);
127  void collectTracks(pma::TrkCandidateColl& result);
128 
129  // Parameters used in the algorithm
130 
131  double fMinTrackLength; // min. length of tracks used to find vtx candidates
132  // (short tracks attached later)
133 
134  bool fFindKinks; // detect significant kinks on long tracks (need min. 5 nodes
135  // to collect angle stats)
136  double fKinkMinDeg; // min. angle [deg] in XY of a kink
137  double fKinkMinStd; // threshold in no. of stdev of all segment angles needed to tag a kink
138 
139  // just to remember:
140  //double fInputVtxDist2D; // use vtx given at input if dist. [cm] to track in all 2D projections is below this max. value
141  //double fInputVtxDistY; // use vtx given at input if dist. [cm] to track in 3D-Y is below this max. value
142 };
143 
144 #endif
Vertex finding helper for the Projection Matching Algorithm.
pma::TrkCandidateColl fEmTracks
pma::TrkCandidateColl fShortTracks
size_t run(const detinfo::DetectorPropertiesData &detProp, pma::TrkCandidateColl &trk_input)
ClusterModuleLabel join with tracks
std::vector< pma::VtxCandidate > firstPassCandidates() const
std::vector< std::pair< TVector3, size_t > > getKinks(const pma::TrkCandidateColl &tracks) const
std::vector< pma::VtxCandidate > secondPassCandidates() const
void collectTracks(pma::TrkCandidateColl &result)
fhicl::Atom< double > MinTrackLength
std::vector< std::pair< TVector3, std::vector< std::pair< size_t, bool > > > > getVertices(const pma::TrkCandidateColl &tracks, bool onlyBranching=false) const
PMAlgVertexing(const Config &config)
fhicl::Atom< bool > FindKinks
std::vector< std::pair< double, double > > getdQdx(const pma::Track3D &trk) const
Get dQ/dx sequence to detect various features.
pma::TrkCandidateColl fOutTracks
BEGIN_PROLOG vertical distance to the surface Name
fhicl::Atom< double > KinkMinStd
pma::TrkCandidateColl fExcludedTracks
Track finding helper for the Projection Matching Algorithm.
size_t makeVertices(detinfo::DetectorPropertiesData const &detProp, std::vector< pma::VtxCandidate > &candidates)
double convolute(size_t idx, size_t len, double *adc, double const *shape) const
Get convolution value.
void sortTracks(const pma::TrkCandidateColl &trk_input)
PMAlgVertexing(const fhicl::ParameterSet &pset)
bool isSingleParticle(pma::Track3D *trk1, pma::Track3D *trk2) const
Check if colinear in 3D and dQ/dx with no significant step.
void splitMergedTracks(pma::TrkCandidateColl &trk_input) const
Split track and add vertex and reoptimize when dQ/dx step detected.
fhicl::Atom< double > KinkMinDeg
void findKinksOnTracks(const detinfo::DetectorPropertiesData &detProp, pma::TrkCandidateColl &trk_input) const
Remove penalty on the angle if kink detected and reopt track.
bool has(const std::vector< size_t > &v, size_t idx) const
auto const detProp
void mergeBrokenTracks(pma::TrkCandidateColl &trk_input) const