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  : iterationIndex_(0),
41  seedIndex_(-1),
42  time_(0.f),
43  timeError_(-1.f),
45  raw_energy_(0.f),
46  raw_em_energy_(0.f),
47  raw_pt_(0.f),
48  raw_em_pt_(0.f),
49  barycenter_({0., 0., 0.}),
50  eigenvalues_{{0.f, 0.f, 0.f}},
51  sigmas_{{0.f, 0.f, 0.f}},
52  sigmasPCA_{{0.f, 0.f, 0.f}} {
54  }
55 
57  std::vector<unsigned int> &vertices() { return vertices_; }
58  std::vector<float> &vertex_multiplicity() { return vertex_multiplicity_; }
59  std::vector<std::array<unsigned int, 2> > &edges() { return edges_; }
60  inline void setSeed(edm::ProductID pid, int index) {
61  seedID_ = pid;
62  seedIndex_ = index;
63  }
64  inline void setTimeAndError(float t, float tError) {
65  time_ = t;
66  timeError_ = tError;
67  }
68  inline void setRegressedEnergy(float value) { regressed_energy_ = value; }
69  inline void setRawEnergy(float value) { raw_energy_ = value; }
70  inline void addToRawEnergy(float value) { raw_energy_ += value; }
71  inline void setRawEmEnergy(float value) { raw_em_energy_ = value; }
72  inline void addToRawEmEnergy(float value) { raw_em_energy_ += value; }
73  inline void setRawPt(float value) { raw_pt_ = value; }
74  inline void setRawEmPt(float value) { raw_em_pt_ = value; }
79  Eigen::Vector3d &sigmasEigen,
80  size_t pcadimension,
82  int original_index = 0;
83  for (size_t i = 0; i < pcadimension; ++i) {
84  sigmas_[i] = std::sqrt(sigmas[i]);
85  // Reverse the order, since Eigen gives back the eigevalues in
86  // **increasing order** while we store them in **descreasing order**.
87  original_index = i;
89  original_index = pcadimension - i - 1;
90  eigenvalues_[i] = (float)eigenvalues[original_index];
92  eigenvectors(0, original_index), eigenvectors(1, original_index), eigenvectors(2, original_index));
93  sigmasPCA_[i] = std::sqrt(sigmasEigen[original_index]);
94  }
95  original_index = 0;
97  original_index = pcadimension - 1;
98  if (eigenvectors_[0].z() * barycenter_.z() < 0.0) {
100  eigenvectors(0, original_index), eigenvectors(1, original_index), eigenvectors(2, original_index));
101  }
102 
103  // Now also update the pt part of the Trackster, using the PCA as direction
104  raw_pt_ = std::sqrt((eigenvectors_[0].Unit() * raw_energy_).perp2());
106  }
108  for (auto &p : id_probabilities_) {
109  p = 0.f;
110  }
111  }
112  inline void setProbabilities(float *probs) {
113  for (float &p : id_probabilities_) {
114  p = *(probs++);
115  }
116  }
118 
120  inline const std::vector<unsigned int> &vertices() const { return vertices_; }
121  inline const unsigned int vertices(int index) const { return vertices_[index]; }
122  inline const std::vector<float> &vertex_multiplicity() const { return vertex_multiplicity_; }
123  inline const float vertex_multiplicity(int index) const { return vertex_multiplicity_[index]; }
124  inline const std::vector<std::array<unsigned int, 2> > &edges() const { return edges_; }
125  inline const edm::ProductID &seedID() const { return seedID_; }
126  inline const int seedIndex() const { return seedIndex_; }
127  inline const float time() const { return time_; }
128  inline const float timeError() const { return timeError_; }
129  inline const float regressed_energy() const { return regressed_energy_; }
130  inline const float raw_energy() const { return raw_energy_; }
131  inline const float raw_em_energy() const { return raw_em_energy_; }
132  inline const float raw_pt() const { return raw_pt_; }
133  inline const float raw_em_pt() const { return raw_em_pt_; }
134  inline const Vector &barycenter() const { return barycenter_; }
135  inline const std::array<float, 3> &eigenvalues() const { return eigenvalues_; }
136  inline const std::array<Vector, 3> &eigenvectors() const { return eigenvectors_; }
137  inline const Vector &eigenvectors(int index) const { return eigenvectors_[index]; }
138  inline const std::array<float, 3> &sigmas() const { return sigmas_; }
139  inline const std::array<float, 3> &sigmasPCA() const { return sigmasPCA_; }
140  inline const std::array<float, 8> &id_probabilities() const { return id_probabilities_; }
141  inline const float id_probabilities(int index) const { return id_probabilities_[index]; }
142 
143  // convenience method to return the ID probability for a certain particle type
144  inline float id_probability(ParticleType type) const {
145  // probabilities are stored in the same order as defined in the ParticleType enum
146  return id_probabilities_[(int)type];
147  }
148 
149  private:
150  // TICL iteration producing the trackster
152 
153  // The vertices of the DAG are the indices of the
154  // 2d objects in the global collection
155  std::vector<unsigned int> vertices_;
156  std::vector<float> vertex_multiplicity_;
157 
158  // The edges connect two vertices together in a directed doublet
159  // ATTENTION: order matters!
160  // A doublet generator should create edges in which:
161  // the first element is on the inner layer and
162  // the outer element is on the outer layer.
163  std::vector<std::array<unsigned int, 2> > edges_;
164 
165  // Product ID of the seeding collection used to create the Trackster.
166  // For GlobalSeeding the ProductID is set to 0. For track-based seeding
167  // this is the ProductID of the track-collection used to create the
168  // seeding-regions.
170 
171  // For Global Seeding the index is fixed to one. For track-based seeding,
172  // the index is the index of the track originating the seeding region that
173  // created the trackster. For track-based seeding the pointer to the track
174  // can be cooked using the previous ProductID and this index.
176 
177  // We also need the pointer to the original seeding region ??
178  // something like:
179  // int seedingRegionIdx;
180 
181  // -99, -1 if not available. ns units otherwise
182  float time_;
183  float timeError_;
184 
185  // regressed energy
187  float raw_energy_;
189  float raw_pt_;
190  float raw_em_pt_;
191 
192  // PCA Variables
194  std::array<float, 3> eigenvalues_;
195  std::array<Vector, 3> eigenvectors_;
196  std::array<float, 3> sigmas_;
197  std::array<float, 3> sigmasPCA_;
198 
199  // trackster ID probabilities
200  std::array<float, 8> id_probabilities_;
201  };
202 
203  typedef std::vector<Trackster> TracksterCollection;
204 } // namespace ticl
205 #endif
void setSeed(edm::ProductID pid, int index)
Definition: Trackster.h:60
float timeError_
Definition: Trackster.h:183
void setRawPt(float value)
Definition: Trackster.h:73
math::XYZVector Vector
Definition: Trackster.h:21
const float raw_pt() const
Definition: Trackster.h:132
const float regressed_energy() const
Definition: Trackster.h:129
void setRegressedEnergy(float value)
Definition: Trackster.h:68
const std::array< float, 3 > & sigmasPCA() const
Definition: Trackster.h:139
const std::vector< unsigned int > & vertices() const
Definition: Trackster.h:120
const Trackster::IterationIndex ticlIteration() const
Definition: Trackster.h:119
edm::ProductID seedID_
Definition: Trackster.h:169
const Vector & barycenter() const
Definition: Trackster.h:134
std::vector< unsigned int > vertices_
Definition: Trackster.h:155
const std::vector< float > & vertex_multiplicity() const
Definition: Trackster.h:122
void setRawEnergy(float value)
Definition: Trackster.h:69
uint8_t iterationIndex_
Definition: Trackster.h:151
void addToRawEnergy(float value)
Definition: Trackster.h:70
void setProbabilities(float *probs)
Definition: Trackster.h:112
std::vector< std::array< unsigned int, 2 > > & edges()
Definition: Trackster.h:59
std::array< Vector, 3 > eigenvectors_
Definition: Trackster.h:195
float raw_em_pt_
Definition: Trackster.h:190
std::array< float, 3 > sigmas_
Definition: Trackster.h:196
const float timeError() const
Definition: Trackster.h:128
Vector barycenter_
Definition: Trackster.h:193
T perp2() const
Squared magnitude of transverse component.
const float raw_em_energy() const
Definition: Trackster.h:131
const std::array< Vector, 3 > & eigenvectors() const
Definition: Trackster.h:136
const std::vector< std::array< unsigned int, 2 > > & edges() const
Definition: Trackster.h:124
const float raw_energy() const
Definition: Trackster.h:130
T sqrt(T t)
Definition: SSEVec.h:19
std::vector< std::array< unsigned int, 2 > > edges_
Definition: Trackster.h:163
double f[11][100]
const Vector & eigenvectors(int index) const
Definition: Trackster.h:137
void zeroProbabilities()
Definition: Trackster.h:107
Definition: value.py:1
float raw_energy_
Definition: Trackster.h:187
const std::array< float, 3 > & sigmas() const
Definition: Trackster.h:138
float id_probability(ParticleType type) const
Definition: Trackster.h:144
const float id_probabilities(int index) const
Definition: Trackster.h:141
std::vector< unsigned int > & vertices()
Definition: Trackster.h:57
const unsigned int vertices(int index) const
Definition: Trackster.h:121
void setRawEmPt(float value)
Definition: Trackster.h:74
std::vector< float > vertex_multiplicity_
Definition: Trackster.h:156
const edm::ProductID & seedID() const
Definition: Trackster.h:125
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
std::vector< float > & vertex_multiplicity()
Definition: Trackster.h:58
std::array< float, 8 > id_probabilities_
Definition: Trackster.h:200
void setRawEmEnergy(float value)
Definition: Trackster.h:71
void fillPCAVariables(Eigen::Vector3d &eigenvalues, Eigen::Matrix3d &eigenvectors, Eigen::Vector3d &sigmas, Eigen::Vector3d &sigmasEigen, size_t pcadimension, PCAOrdering order)
Definition: Trackster.h:76
const int seedIndex() const
Definition: Trackster.h:126
float regressed_energy_
Definition: Trackster.h:186
const float time() const
Definition: Trackster.h:127
Definition: Common.h:8
void addToRawEmEnergy(float value)
Definition: Trackster.h:72
std::vector< Trackster > TracksterCollection
Definition: Trackster.h:203
void setTimeAndError(float t, float tError)
Definition: Trackster.h:64
const float vertex_multiplicity(int index) const
Definition: Trackster.h:123
std::array< float, 3 > sigmasPCA_
Definition: Trackster.h:197
void setIteration(const Trackster::IterationIndex i)
Definition: Trackster.h:56
const float raw_em_pt() const
Definition: Trackster.h:133
Eigen::Matrix3d Matrix3d
Definition: FitResult.h:18
void setIdProbability(ParticleType type, float value)
Definition: Trackster.h:117
std::array< float, 3 > eigenvalues_
Definition: Trackster.h:194
const std::array< float, 8 > & id_probabilities() const
Definition: Trackster.h:140
const std::array< float, 3 > & eigenvalues() const
Definition: Trackster.h:135
Eigen::Vector3d Vector3d
Definition: FitResult.h:14
float raw_em_energy_
Definition: Trackster.h:188
void setBarycenter(Vector value)
Definition: Trackster.h:75