Project
Loading...
Searching...
No Matches
Track.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16
18
19#include <iostream>
20#include <fmt/format.h>
21
22namespace o2
23{
24namespace mid
25{
26
27void Track::setCovarianceParameters(float xErr2, float yErr2, float slopeXErr2, float slopeYErr2, float covXSlopeX, float covYSlopeY)
28{
29 mCovarianceParameters[static_cast<int>(CovarianceParamIndex::VarX)] = xErr2;
30 mCovarianceParameters[static_cast<int>(CovarianceParamIndex::VarY)] = yErr2;
31 mCovarianceParameters[static_cast<int>(CovarianceParamIndex::VarSlopeX)] = slopeXErr2;
32 mCovarianceParameters[static_cast<int>(CovarianceParamIndex::VarSlopeY)] = slopeYErr2;
33 mCovarianceParameters[static_cast<int>(CovarianceParamIndex::CovXSlopeX)] = covXSlopeX;
34 mCovarianceParameters[static_cast<int>(CovarianceParamIndex::CovYSlopeY)] = covYSlopeY;
35}
36
37void Track::setDirection(float xDir, float yDir, float zDir)
38{
39 mDirection = {xDir, yDir, zDir};
40}
41
42void Track::setPosition(float xPos, float yPos, float zPos)
43{
44 mPosition = {xPos, yPos, zPos};
45}
46
47int Track::getClusterMatched(int chamber) const
48{
49 if (chamber < 0 || chamber > 3) {
50 std::cerr << "Error: chamber must be in range [0, 3]\n";
51 return 0;
52 }
53 return mClusterMatched[chamber];
54}
55
56void Track::setClusterMatched(int chamber, int id)
57{
58 if (chamber < 0 || chamber > 3) {
59 std::cerr << "Error: chamber must be in range [0, 3]\n";
60 return;
61 }
62 mClusterMatched[chamber] = id;
63}
64
65bool Track::propagateToZ(float zPosition)
66{
67 // Nothing to be done if we're already at zPosition
68 // Notice that the z position is typically the z of the cluster,
69 // which is provided in float precision as well.
70 // So it is typically a well defined value, hence the strict equality
71 if (mPosition[2] == zPosition) {
72 return false;
73 }
74
75 // Propagate the track position parameters
76 float dZ = zPosition - mPosition[2];
77 float newX = mPosition[0] + mDirection[0] * dZ;
78 float newY = mPosition[1] + mDirection[1] * dZ;
79 setPosition(newX, newY, zPosition);
80
81 // Propagate the covariance matrix
82 std::array<float, 6> newCovParams;
83 float dZ2 = dZ * dZ;
84 for (int idx = 0; idx < 2; ++idx) {
85 int slopeIdx = idx + 2;
86 int covIdx = idx + 4;
87 // s_x^2 -> s_x^2 + 2*cov(x,slopeX)*dZ + s_slopeX^2*dZ^2
88 newCovParams[idx] =
89 mCovarianceParameters[idx] + 2. * mCovarianceParameters[covIdx] * dZ + mCovarianceParameters[slopeIdx] * dZ2;
90 // cov(x,slopeX) -> cov(x,slopeX) + s_slopeX^2*dZ
91 newCovParams[covIdx] = mCovarianceParameters[covIdx] + mCovarianceParameters[slopeIdx] * dZ;
92 // s_slopeX^2 -> s_slopeX^2
93 newCovParams[slopeIdx] = mCovarianceParameters[slopeIdx];
94 }
95
96 mCovarianceParameters.swap(newCovParams);
97
98 return true;
99}
100
101bool Track::isCompatible(const Track& track, float chi2Cut) const
102{
103 if (track.mPosition[2] != mPosition[2]) {
104 Track copyTrack(track);
105 copyTrack.propagateToZ(mPosition[2]);
106 return isCompatible(copyTrack, chi2Cut);
107 }
108
109 // // method 1: chi2 calculation accounting for covariance between slope and position.
110 // // This is the full calculation. However, if we have two parallel tracks with same x
111 // // but different ( > Nsigmas) y position, the algorithm will return true since the
112 // // difference in one of the parameters is compensated by the similarity of the others.
113 // // This is probably not what we need.
114 // double chi2 = 0.;
115 // double pos1[2] = { getPosition().x(), getPosition().y() };
116 // double dir1[2] = { getDirection().x(), getDirection().y() };
117 // double pos2[2] = { track.getPosition().x(), track.getPosition().y() };
118 // double dir2[2] = { track.getDirection().x(), track.getDirection().y() };
119 //
120 // for (int icoor = 0; icoor < 2; ++icoor) {
121 // double diffPos = pos1[icoor] - pos2[icoor];
122 // double diffSlope = dir1[icoor] - dir2[icoor];
123 // double varPos = mCovarianceParameters[icoor] + track.mCovarianceParameters[icoor];
124 // double varSlope = mCovarianceParameters[icoor + 2] + track.mCovarianceParameters[icoor + 2];
125 // double cov = mCovarianceParameters[icoor + 4] + track.mCovarianceParameters[icoor + 4];
126 // chi2 += (diffPos * diffPos * varSlope + diffSlope * diffSlope * varPos - 2. * diffPos * diffSlope * cov) /
127 // (varPos * varSlope - cov * cov);
128 // }
129 //
130 // return (chi2 / 4.) < chi2Cut;
131
132 // method 2: apply the cut on each parameter
133 // This method avoids the issue of method 1
134 // but it does not account for covariances between position and slope
135 // so the compatibility varies with the z position where it is evaluated
136 // double p1[4] = {mPosition[0], mPosition[1], mDirection[0], mDirection[1]};
137 // double p2[4] = {track.mPosition[0], track.mPosition[1], track.mDirection[0],
138 // track.mDirection[1]};
139 // for (int ipar = 0; ipar < 4; ++ipar) {
140 // double diff = p1[ipar] - p2[ipar];
141 // if (diff * diff / (mCovarianceParameters[ipar] + track.mCovarianceParameters[ipar]) > chi2Cut) {
142 // return false;
143 // };
144 // }
145
146 // method 3: check compatibility in x and y separately,
147 // accounting for covariances between position and slope
148 for (int icoor = 0; icoor < 2; ++icoor) {
149 double diffPos = mPosition[icoor] - track.mPosition[icoor];
150 double diffSlope = mDirection[icoor] - track.mDirection[icoor];
151 double varPos = mCovarianceParameters[icoor] + track.mCovarianceParameters[icoor];
152 double varSlope = mCovarianceParameters[icoor + 2] + track.mCovarianceParameters[icoor + 2];
153 double cov = mCovarianceParameters[icoor + 4] + track.mCovarianceParameters[icoor + 4];
154 double chi2 = (diffPos * diffPos * varSlope + diffSlope * diffSlope * varPos - 2. * diffPos * diffSlope * cov) /
155 (varPos * varSlope - cov * cov);
156 if (chi2 / 2. > chi2Cut) {
157 return false;
158 }
159 }
160
161 return true;
162}
163
164void Track::setEfficiencyWord(int pos, int mask, int value)
165{
166 mEfficiencyWord &= ~(mask << pos);
167 mEfficiencyWord |= (value << pos);
168}
169
170std::ostream& operator<<(std::ostream& stream, const Track& track)
171{
172 stream << "Position: (" << track.mPosition[0] << ", " << track.mPosition[1] << ", " << track.mPosition[2] << ")";
173 stream << " Direction: (" << track.mDirection[0] << ", " << track.mDirection[1] << ", " << track.mDirection[2] << ")";
174 stream << " Covariance (X, Y, SlopeX, SlopeY, X-SlopeX, Y-SlopeY): (";
175 for (int ival = 0; ival < 6; ++ival) {
176 stream << track.mCovarianceParameters[ival];
177 stream << ((ival == 5) ? ")" : ", ");
178 }
179 stream << fmt::format(" chi2/ndf: {:g}/{:d}", track.getChi2(), track.getNDF());
180 stream << fmt::format(" hitMap: 0x{:x} deId: {:d} columnId: {:d} lineId: {:d} effFlag {:d}", track.getHitMap(), track.getFiredDEId(), track.getFiredColumnId(), track.getFiredLineId(), track.getEfficiencyFlag());
181 return stream;
182}
183
184} // namespace mid
185} // namespace o2
Reconstructed MID track.
uint16_t pos
Definition RawData.h:3
This class defines the MID track.
Definition Track.h:30
int getFiredLineId() const
Gets the fired line ID.
Definition Track.h:165
int getFiredColumnId() const
Gets the fired column ID.
Definition Track.h:162
void setClusterMatched(int chamber, int id)
Definition Track.cxx:56
float getChi2() const
Returns the chi2 of the track.
Definition Track.h:114
bool propagateToZ(float zPosition)
Definition Track.cxx:65
int getClusterMatched(int chamber) const
Definition Track.cxx:47
bool isCompatible(const Track &track, float chi2Cut) const
Definition Track.cxx:101
void setDirection(float xDir, float yDir, float zDir)
Definition Track.cxx:37
void setCovarianceParameters(float xErr2, float yErr2, float slopeXErr2, float slopeYErr2, float covXSlopeX, float covYSlopeY)
Definition Track.cxx:27
@ VarX
Variance on X position.
@ VarY
Variance on Y position.
@ CovXSlopeX
Covariance on X position and slope.
@ CovYSlopeY
Covariance on Y position and slope.
uint8_t getHitMap() const
Gets hit map.
Definition Track.h:141
void setPosition(float xPos, float yPos, float zPos)
Definition Track.cxx:42
void setEfficiencyWord(uint32_t efficiencyWord)
set efficiency word (public function)
Definition Track.h:192
int getEfficiencyFlag() const
Definition Track.h:177
int getNDF() const
Returns the number of degrees of freedom of the track.
Definition Track.h:118
int getFiredDEId() const
Gets the fired Detection Element ID.
Definition Track.h:156
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLuint GLuint stream
Definition glcorearb.h:1806
GLint GLuint mask
Definition glcorearb.h:291
GLuint id
Definition glcorearb.h:650
std::ostream & operator<<(std::ostream &os, const Cluster &data)
Definition Cluster.cxx:27
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...