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