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 };
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  : seedIndex_(0),
41  time_(0.f),
42  timeError_(-1.f),
44  raw_energy_(0.f),
45  raw_em_energy_(0.f),
46  raw_pt_(0.f),
47  raw_em_pt_(0.f),
48  barycenter_({0., 0., 0.}),
49  eigenvalues_{{0.f, 0.f, 0.f}},
50  sigmas_{{0.f, 0.f, 0.f}},
51  sigmasPCA_{{0.f, 0.f, 0.f}} {
53  }
54 
56  std::vector<unsigned int> &vertices() { return vertices_; }
57  std::vector<uint8_t> &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 setEigenValuesVectors();
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<uint8_t> &vertex_multiplicity() const { return vertex_multiplicity_; }
123  inline const uint8_t 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<uint8_t> 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
ticl::Trackster::vertex_multiplicity
const uint8_t vertex_multiplicity(int index) const
Definition: Trackster.h:123
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:188
ticl::Trackster::barycenter
const Vector & barycenter() const
Definition: Trackster.h:134
mps_fire.i
i
Definition: mps_fire.py:428
ticl::Trackster::setRawEnergy
void setRawEnergy(float value)
Definition: Trackster.h:68
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
ticl::Trackster::eigenvalues_
std::array< float, 3 > eigenvalues_
Definition: Trackster.h:194
ticl::Trackster::raw_pt_
float raw_pt_
Definition: Trackster.h:189
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
ticl::Trackster::TRKEM
Definition: Trackster.h:23
ticl::Trackster::seedID_
edm::ProductID seedID_
Definition: Trackster.h:169
ticl::Trackster::setBarycenter
void setBarycenter(Vector value)
Definition: Trackster.h:74
ticl::Trackster::ParticleType::charged_hadron
ticl::Trackster::vertices_
std::vector< unsigned int > vertices_
Definition: Trackster.h:155
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:59
ticl::Trackster::timeError
const float timeError() const
Definition: Trackster.h:128
ticl::Trackster::setEigenValuesVectors
void setEigenValuesVectors()
ticl::Trackster::EM
Definition: Trackster.h:23
ticl::Trackster::Trackster
Trackster()
Definition: Trackster.h:39
ticl::Trackster::ticlIteration
const Trackster::IterationIndex ticlIteration() const
Definition: Trackster.h:119
ticl::Trackster::addToRawEnergy
void addToRawEnergy(float value)
Definition: Trackster.h:69
ticl::Trackster::raw_pt
const float raw_pt() const
Definition: Trackster.h:132
ticl::Trackster::eigenvectors
const std::array< Vector, 3 > & eigenvectors() const
Definition: Trackster.h:136
ticl::Trackster::edges
const std::vector< std::array< unsigned int, 2 > > & edges() const
Definition: Trackster.h:124
ticl
Definition: Common.h:8
riemannFit::Vector3d
Eigen::Vector3d Vector3d
Definition: FitResult.h:14
ticl::Trackster::vertices
const std::vector< unsigned int > & vertices() const
Definition: Trackster.h:120
ticl::Trackster::barycenter_
Vector barycenter_
Definition: Trackster.h:193
ticl::Trackster::iterationIndex_
uint8_t iterationIndex_
Definition: Trackster.h:151
ticl::Trackster::time_
float time_
Definition: Trackster.h:182
ticl::Trackster::HAD
Definition: Trackster.h:23
ticl::Trackster::edges_
std::vector< std::array< unsigned int, 2 > > edges_
Definition: Trackster.h:163
ticl::Trackster::zeroProbabilities
void zeroProbabilities()
Definition: Trackster.h:107
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
ticl::Trackster::vertex_multiplicity
std::vector< uint8_t > & vertex_multiplicity()
Definition: Trackster.h:57
ticl::Trackster::raw_energy
const float raw_energy() const
Definition: Trackster.h:130
ticl::Trackster::PCAOrdering::descending
ProductID.h
ticl::Trackster::raw_energy_
float raw_energy_
Definition: Trackster.h:187
ticl::Trackster::edges
std::vector< std::array< unsigned int, 2 > > & edges()
Definition: Trackster.h:58
ticl::Trackster::setProbabilities
void setProbabilities(float *probs)
Definition: Trackster.h:112
ticl::Trackster::eigenvectors_
std::array< Vector, 3 > eigenvectors_
Definition: Trackster.h:195
ticl::Trackster::sigmas_
std::array< float, 3 > sigmas_
Definition: Trackster.h:196
ticl::Trackster::raw_em_pt_
float raw_em_pt_
Definition: Trackster.h:190
ticl::Trackster::ParticleType::photon
ticl::Trackster::id_probabilities
const float id_probabilities(int index) const
Definition: Trackster.h:141
ticl::Trackster::vertices
const unsigned int vertices(int index) const
Definition: Trackster.h:121
ticl::Trackster::ParticleType::muon
ticl::Trackster::IterationIndex
IterationIndex
Definition: Trackster.h:23
ticl::Trackster::raw_em_energy
const float raw_em_energy() const
Definition: Trackster.h:131
ticl::Trackster::MIP
Definition: Trackster.h:23
ticl::Trackster::vertex_multiplicity_
std::vector< uint8_t > vertex_multiplicity_
Definition: Trackster.h:156
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
ticl::Trackster::eigenvectors
const Vector & eigenvectors(int index) const
Definition: Trackster.h:137
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
ticl::Trackster::TRKHAD
Definition: Trackster.h:23
value
Definition: value.py:1
ticl::Trackster::seedIndex_
int seedIndex_
Definition: Trackster.h:175
ticl::Trackster::time
const float time() const
Definition: Trackster.h:127
perp2
T perp2() const
Squared magnitude of transverse component.
Definition: Basic3DVectorLD.h:130
ticl::Trackster::addToRawEmEnergy
void addToRawEmEnergy(float value)
Definition: Trackster.h:71
ticl::Trackster::setRawEmEnergy
void setRawEmEnergy(float value)
Definition: Trackster.h:70
ticl::Trackster::setTimeAndError
void setTimeAndError(float t, float tError)
Definition: Trackster.h:63
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:76
ticl::Trackster::setRawEmPt
void setRawEmPt(float value)
Definition: Trackster.h:73
ticl::Trackster::seedID
const edm::ProductID & seedID() const
Definition: Trackster.h:125
ticl::Trackster::PCAOrdering
PCAOrdering
Definition: Trackster.h:37
ticl::Trackster::sigmas
const std::array< float, 3 > & sigmas() const
Definition: Trackster.h:138
ticl::TracksterCollection
std::vector< Trackster > TracksterCollection
Definition: Trackster.h:203
ticl::Trackster::id_probability
float id_probability(ParticleType type) const
Definition: Trackster.h:144
ticl::Trackster::id_probabilities
const std::array< float, 8 > & id_probabilities() const
Definition: Trackster.h:140
relativeConstraints.value
value
Definition: relativeConstraints.py:53
ticl::Trackster::vertices
std::vector< unsigned int > & vertices()
Definition: Trackster.h:56
ticl::Trackster::eigenvalues
const std::array< float, 3 > & eigenvalues() const
Definition: Trackster.h:135
ticl::Trackster::ParticleType::neutral_pion
ticl::Trackster::setIteration
void setIteration(const Trackster::IterationIndex i)
Definition: Trackster.h:55
ticl::Trackster::raw_em_pt
const float raw_em_pt() const
Definition: Trackster.h:133
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:122
ticl::Trackster::ParticleType
ParticleType
Definition: Trackster.h:26
ticl::Trackster::timeError_
float timeError_
Definition: Trackster.h:183
ticl::Trackster::id_probabilities_
std::array< float, 8 > id_probabilities_
Definition: Trackster.h:200
riemannFit::Matrix3d
Eigen::Matrix3d Matrix3d
Definition: FitResult.h:18
ticl::Trackster::setRawPt
void setRawPt(float value)
Definition: Trackster.h:72
ticl::Trackster::sigmasPCA_
std::array< float, 3 > sigmasPCA_
Definition: Trackster.h:197
ticl::Trackster::regressed_energy
const float regressed_energy() const
Definition: Trackster.h:129
ticl::Trackster::seedIndex
const int seedIndex() const
Definition: Trackster.h:126
Vector3D.h
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
ticl::Trackster::setRegressedEnergy
void setRegressedEnergy(float value)
Definition: Trackster.h:67
edm::ProductID
Definition: ProductID.h:27
ticl::Trackster::regressed_energy_
float regressed_energy_
Definition: Trackster.h:186
ticl::Trackster
Definition: Trackster.h:19
ticl::Trackster::setIdProbability
void setIdProbability(ParticleType type, float value)
Definition: Trackster.h:117
ticl::Trackster::sigmasPCA
const std::array< float, 3 > & sigmasPCA() const
Definition: Trackster.h:139
ticl::Trackster::ParticleType::unknown
ticl::Trackster::ParticleType::electron