CMS 3D CMS Logo

Trackster.h
Go to the documentation of this file.
1 // Author: Felice Pantaleo - felice.pantaleo@cern.ch
2 // Date: 09/2018
3 
4 #ifndef DataFormats_HGCalReco_Trackster_h
5 #define DataFormats_HGCalReco_Trackster_h
6 
7 #include <array>
8 #include <vector>
11 
12 #include <Eigen/Core>
13 
14 // A Trackster is a Direct Acyclic Graph created when
15 // pattern recognition algorithms connect hits or
16 // layer clusters together in a 3D object.
17 
18 namespace ticl {
19  class Trackster {
20  public:
22 
23  enum IterationIndex { TRKEM = 0, EM, TRKHAD, HAD, MIP, SIM, SIM_CP };
24 
25  // types considered by the particle identification
26  enum class ParticleType {
27  photon = 0,
28  electron,
29  muon,
33  ambiguous,
34  unknown,
35  };
36 
37  enum class PCAOrdering { ascending = 0, descending };
38 
40  : barycenter_({0.f, 0.f, 0.f}),
42  raw_energy_(0.f),
43  time_(0.f),
44  timeError_(-1.f),
45  raw_em_energy_(0.f),
47  raw_pt_(0.f),
48  raw_em_pt_(0.f),
49  seedIndex_(-1),
50  eigenvalues_{},
51  sigmas_{},
52  sigmasPCA_{},
53  iterationIndex_(0) {}
54 
56  std::vector<unsigned int> &vertices() { return vertices_; }
57  std::vector<float> &vertex_multiplicity() { return vertex_multiplicity_; }
58  std::vector<std::array<unsigned int, 2> > &edges() { return edges_; }
59  inline void setSeed(edm::ProductID pid, int index) {
60  seedID_ = pid;
61  seedIndex_ = index;
62  }
63  inline void setTimeAndError(float t, float tError) {
64  time_ = t;
65  timeError_ = tError;
66  }
67  inline void setRegressedEnergy(float value) { regressed_energy_ = value; }
68  inline void setRawEnergy(float value) { raw_energy_ = value; }
69  inline void addToRawEnergy(float value) { raw_energy_ += value; }
70  inline void setRawEmEnergy(float value) { raw_em_energy_ = value; }
71  inline void addToRawEmEnergy(float value) { raw_em_energy_ += value; }
72  inline void setRawPt(float value) { raw_pt_ = value; }
73  inline void setRawEmPt(float value) { raw_em_pt_ = value; }
75  inline void setTrackIdx(int index) { track_idx_ = index; }
76  int trackIdx() const { return track_idx_; }
77 
81  Eigen::Vector3d &sigmasEigen,
82  size_t pcadimension,
84  int original_index = 0;
85  for (size_t i = 0; i < pcadimension; ++i) {
86  sigmas_[i] = std::sqrt(sigmas[i]);
87  // Reverse the order, since Eigen gives back the eigevalues in
88  // **increasing order** while we store them in **descreasing order**.
89  original_index = i;
91  original_index = pcadimension - i - 1;
92  eigenvalues_[i] = (float)eigenvalues[original_index];
94  eigenvectors(0, original_index), eigenvectors(1, original_index), eigenvectors(2, original_index));
95  sigmasPCA_[i] = std::sqrt(sigmasEigen[original_index]);
96  }
97  original_index = 0;
99  original_index = pcadimension - 1;
100  if (eigenvectors_[0].z() * barycenter_.z() < 0.0) {
102  eigenvectors(0, original_index), eigenvectors(1, original_index), eigenvectors(2, original_index));
103  }
104 
105  // Now also update the pt part of the Trackster, using the PCA as direction
106  raw_pt_ = std::sqrt((eigenvectors_[0].Unit() * raw_energy_).perp2());
108  }
110  for (auto &p : id_probabilities_) {
111  p = 0.f;
112  }
113  }
114  inline void setProbabilities(float *probs) {
115  for (float &p : id_probabilities_) {
116  p = *(probs++);
117  }
118  }
120 
122  inline const std::vector<unsigned int> &vertices() const { return vertices_; }
123  inline const unsigned int vertices(int index) const { return vertices_[index]; }
124  inline const std::vector<float> &vertex_multiplicity() const { return vertex_multiplicity_; }
125  inline const float vertex_multiplicity(int index) const { return vertex_multiplicity_[index]; }
126  inline const std::vector<std::array<unsigned int, 2> > &edges() const { return edges_; }
127  inline const edm::ProductID &seedID() const { return seedID_; }
128  inline const int seedIndex() const { return seedIndex_; }
129  inline const float time() const { return time_; }
130  inline const float timeError() const { return timeError_; }
131  inline const float regressed_energy() const { return regressed_energy_; }
132  inline const float raw_energy() const { return raw_energy_; }
133  inline const float raw_em_energy() const { return raw_em_energy_; }
134  inline const float raw_pt() const { return raw_pt_; }
135  inline const float raw_em_pt() const { return raw_em_pt_; }
136  inline const Vector &barycenter() const { return barycenter_; }
137  inline const std::array<float, 3> &eigenvalues() const { return eigenvalues_; }
138  inline const std::array<Vector, 3> &eigenvectors() const { return eigenvectors_; }
139  inline const Vector &eigenvectors(int index) const { return eigenvectors_[index]; }
140  inline const std::array<float, 3> &sigmas() const { return sigmas_; }
141  inline const std::array<float, 3> &sigmasPCA() const { return sigmasPCA_; }
142  inline const std::array<float, 8> &id_probabilities() const { return id_probabilities_; }
143  inline const float id_probabilities(int index) const { return id_probabilities_[index]; }
144 
145  // convenience method to return the ID probability for a certain particle type
146  inline float id_probability(ParticleType type) const {
147  // probabilities are stored in the same order as defined in the ParticleType enum
148  return id_probabilities_[(int)type];
149  }
150 
151  private:
154  float raw_energy_;
155  // -99, -1 if not available. ns units otherwise
156  float time_;
157  float timeError_;
159 
160  // trackster ID probabilities
161  std::array<float, 8> id_probabilities_;
162 
163  // The vertices of the DAG are the indices of the
164  // 2d objects in the global collection
165  std::vector<unsigned int> vertices_;
166  std::vector<float> vertex_multiplicity_;
167  float raw_pt_;
168  float raw_em_pt_;
169 
170  // Product ID of the seeding collection used to create the Trackster.
171  // For GlobalSeeding the ProductID is set to 0. For track-based seeding
172  // this is the ProductID of the track-collection used to create the
173  // seeding-regions.
175 
176  // For Global Seeding the index is fixed to one. For track-based seeding,
177  // the index is the index of the track originating the seeding region that
178  // created the trackster. For track-based seeding the pointer to the track
179  // can be cooked using the previous ProductID and this index.
181  int track_idx_ = -1;
182 
183  std::array<Vector, 3> eigenvectors_;
184  std::array<float, 3> eigenvalues_;
185  std::array<float, 3> sigmas_;
186  std::array<float, 3> sigmasPCA_;
187 
188  // The edges connect two vertices together in a directed doublet
189  // ATTENTION: order matters!
190  // A doublet generator should create edges in which:
191  // the first element is on the inner layer and
192  // the outer element is on the outer layer.
193  std::vector<std::array<unsigned int, 2> > edges_;
194 
195  // TICL iteration producing the trackster
197  };
198 
199  typedef std::vector<Trackster> TracksterCollection;
200 } // namespace ticl
201 #endif
void setSeed(edm::ProductID pid, int index)
Definition: Trackster.h:59
Eigen::Vector3d Vector3d
Definition: FitResult.h:11
float timeError_
Definition: Trackster.h:157
void setRawPt(float value)
Definition: Trackster.h:72
Eigen::Matrix3d Matrix3d
Definition: FitResult.h:15
const float raw_pt() const
Definition: Trackster.h:134
const float regressed_energy() const
Definition: Trackster.h:131
void setTrackIdx(int index)
Definition: Trackster.h:75
void setRegressedEnergy(float value)
Definition: Trackster.h:67
const std::array< float, 3 > & sigmasPCA() const
Definition: Trackster.h:141
const std::vector< unsigned int > & vertices() const
Definition: Trackster.h:122
math::XYZVectorF Vector
Definition: Trackster.h:21
const Trackster::IterationIndex ticlIteration() const
Definition: Trackster.h:121
edm::ProductID seedID_
Definition: Trackster.h:174
const Vector & barycenter() const
Definition: Trackster.h:136
std::vector< unsigned int > vertices_
Definition: Trackster.h:165
const std::vector< float > & vertex_multiplicity() const
Definition: Trackster.h:124
void setRawEnergy(float value)
Definition: Trackster.h:68
int trackIdx() const
Definition: Trackster.h:76
uint8_t iterationIndex_
Definition: Trackster.h:196
void addToRawEnergy(float value)
Definition: Trackster.h:69
void setProbabilities(float *probs)
Definition: Trackster.h:114
std::vector< std::array< unsigned int, 2 > > & edges()
Definition: Trackster.h:58
std::array< Vector, 3 > eigenvectors_
Definition: Trackster.h:183
float raw_em_pt_
Definition: Trackster.h:168
std::array< float, 3 > sigmas_
Definition: Trackster.h:185
const float timeError() const
Definition: Trackster.h:130
Vector barycenter_
Definition: Trackster.h:152
T perp2() const
Squared magnitude of transverse component.
const float raw_em_energy() const
Definition: Trackster.h:133
const std::array< Vector, 3 > & eigenvectors() const
Definition: Trackster.h:138
const std::vector< std::array< unsigned int, 2 > > & edges() const
Definition: Trackster.h:126
const float raw_energy() const
Definition: Trackster.h:132
T sqrt(T t)
Definition: SSEVec.h:19
std::vector< std::array< unsigned int, 2 > > edges_
Definition: Trackster.h:193
double f[11][100]
const Vector & eigenvectors(int index) const
Definition: Trackster.h:139
void zeroProbabilities()
Definition: Trackster.h:109
Definition: value.py:1
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< float > > XYZVectorF
spatial vector with cartesian internal representation
Definition: Vector3D.h:16
float raw_energy_
Definition: Trackster.h:154
const std::array< float, 3 > & sigmas() const
Definition: Trackster.h:140
float id_probability(ParticleType type) const
Definition: Trackster.h:146
const float id_probabilities(int index) const
Definition: Trackster.h:143
std::vector< unsigned int > & vertices()
Definition: Trackster.h:56
const unsigned int vertices(int index) const
Definition: Trackster.h:123
void setRawEmPt(float value)
Definition: Trackster.h:73
std::vector< float > vertex_multiplicity_
Definition: Trackster.h:166
const edm::ProductID & seedID() const
Definition: Trackster.h:127
std::vector< float > & vertex_multiplicity()
Definition: Trackster.h:57
std::array< float, 8 > id_probabilities_
Definition: Trackster.h:161
void setRawEmEnergy(float value)
Definition: Trackster.h:70
void fillPCAVariables(Eigen::Vector3d &eigenvalues, Eigen::Matrix3d &eigenvectors, Eigen::Vector3d &sigmas, Eigen::Vector3d &sigmasEigen, size_t pcadimension, PCAOrdering order)
Definition: Trackster.h:78
const int seedIndex() const
Definition: Trackster.h:128
float regressed_energy_
Definition: Trackster.h:153
const float time() const
Definition: Trackster.h:129
Definition: Common.h:8
void addToRawEmEnergy(float value)
Definition: Trackster.h:71
std::vector< Trackster > TracksterCollection
Definition: Trackster.h:199
void setTimeAndError(float t, float tError)
Definition: Trackster.h:63
const float vertex_multiplicity(int index) const
Definition: Trackster.h:125
std::array< float, 3 > sigmasPCA_
Definition: Trackster.h:186
void setIteration(const Trackster::IterationIndex i)
Definition: Trackster.h:55
const float raw_em_pt() const
Definition: Trackster.h:135
void setIdProbability(ParticleType type, float value)
Definition: Trackster.h:119
std::array< float, 3 > eigenvalues_
Definition: Trackster.h:184
const std::array< float, 8 > & id_probabilities() const
Definition: Trackster.h:142
const std::array< float, 3 > & eigenvalues() const
Definition: Trackster.h:137
float raw_em_energy_
Definition: Trackster.h:158
void setBarycenter(Vector value)
Definition: Trackster.h:74