CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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_(0),
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}} {
53  zeroProbabilities();
54  }
55 
56  inline void setIteration(const Trackster::IterationIndex i) { iterationIndex_ = i; }
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; }
75  inline void setBarycenter(Vector value) { barycenter_ = value; }
76  inline void fillPCAVariables(Eigen::Vector3d &eigenvalues,
77  Eigen::Matrix3d &eigenvectors,
78  Eigen::Vector3d &sigmas,
79  Eigen::Vector3d &sigmasEigen,
80  size_t pcadimension,
81  PCAOrdering order) {
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;
88  if (order == PCAOrdering::ascending)
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;
96  if (order == PCAOrdering::ascending)
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  }
107  void zeroProbabilities() {
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  }
117  inline void setIdProbability(ParticleType type, float value) { id_probabilities_[int(type)] = value; }
118 
119  inline const Trackster::IterationIndex ticlIteration() const { return (IterationIndex)iterationIndex_; }
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
151  uint8_t iterationIndex_;
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
float timeError_
Definition: Trackster.h:183
math::XYZVector Vector
Definition: Trackster.h:21
ROOT::Math::Plane3D::Vector Vector
Definition: EcalHitMaker.cc:29
edm::ProductID seedID_
Definition: Trackster.h:169
std::vector< unsigned int > vertices_
Definition: Trackster.h:155
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
float float float z
Vector barycenter_
Definition: Trackster.h:193
void setRawEnergy(HcalRecHit &h, float e)
Definition: rawEnergy.h:217
T sqrt(T t)
Definition: SSEVec.h:19
std::vector< std::array< unsigned int, 2 > > edges_
Definition: Trackster.h:163
float raw_energy_
Definition: Trackster.h:187
std::vector< float > vertex_multiplicity_
Definition: Trackster.h:156
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
T perp2() const
Squared magnitude of transverse component.
std::array< float, 8 > id_probabilities_
Definition: Trackster.h:200
float regressed_energy_
Definition: Trackster.h:186
std::vector< Trackster > TracksterCollection
Definition: Trackster.h:203
std::array< float, 3 > sigmasPCA_
Definition: Trackster.h:197
Eigen::Matrix3d Matrix3d
Definition: FitResult.h:18
std::array< float, 3 > eigenvalues_
Definition: Trackster.h:194
Eigen::Vector3d Vector3d
Definition: FitResult.h:14
float raw_em_energy_
Definition: Trackster.h:188