Project
Loading...
Searching...
No Matches
Tracker.h
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.
15
16#ifndef O2_MFT_TRACKER_H_
17#define O2_MFT_TRACKER_H_
18
19#include "MFTTracking/ROframe.h"
21#include "MFTTracking/Cluster.h"
23
24#include "MathUtils/Utils.h"
25#include "MathUtils/Cartesian.h"
32
33namespace o2
34{
35namespace mft
36{
37
40typedef std::function<bool(const ROFRecord&)> ROFFilter;
41
42class T;
43
44template <typename T>
45class Tracker : public TrackerConfig
46{
47
48 public:
49 Tracker(bool useMC);
50 ~Tracker();
51
52 Tracker(const Tracker&) = delete;
53 Tracker& operator=(const Tracker&) = delete;
54
55 void setBz(Float_t bz);
56 const Float_t getBz() const { return mBz; }
57
58 auto& getTrackLabels() { return mTrackLabels; }
59
61 {
62 mTrackLabels.clear();
63 }
64
66 {
67 if (!mFullClusterScan) {
68 clearSorting();
69 sortClusters(rofData);
70 }
73 };
74
77 bool fitTracks(ROframe<T>&);
78 void computeTracksMClabels(const std::vector<T>&);
79
80 void configure(const MFTTrackingParam& trkParam, int trackerID);
81 void initializeFinder();
82 int getTrackerID() const { return mTrackerID; }
83
84 private:
85 void findTracksLTF(ROframe<T>&);
86 void findTracksCA(ROframe<T>&);
87 void findTracksLTFfcs(ROframe<T>&);
88 void findTracksCAfcs(ROframe<T>&);
89 void computeCellsInRoad(ROframe<T>&);
90 void runForwardInRoad();
91 void runBackwardInRoad(ROframe<T>&);
92 void updateCellStatusInRoad();
93
94 void sortClusters(ROframe<T>& rof)
95 {
96 Int_t nClsInLayer, binPrevIndex, clsMinIndex, clsMaxIndex, jClsLayer;
97 // sort the clusters in R-Phi
98 for (Int_t iLayer = 0; iLayer < constants::mft::LayersNumber; ++iLayer) {
99 if (rof.getClustersInLayer(iLayer).size() == 0) {
100 continue;
101 }
102 // sort clusters in layer according to the bin index
103 sort(rof.getClustersInLayer(iLayer).begin(), rof.getClustersInLayer(iLayer).end(),
104 [](Cluster& c1, Cluster& c2) { return c1.indexTableBin < c2.indexTableBin; });
105 // find the cluster local index range in each bin
106 // index = element position in the vector
107 nClsInLayer = rof.getClustersInLayer(iLayer).size();
108 binPrevIndex = rof.getClustersInLayer(iLayer).at(0).indexTableBin;
109 clsMinIndex = 0;
110 for (jClsLayer = 1; jClsLayer < nClsInLayer; ++jClsLayer) {
111 if (rof.getClustersInLayer(iLayer).at(jClsLayer).indexTableBin == binPrevIndex) {
112 continue;
113 }
114
115 clsMaxIndex = jClsLayer - 1;
116
117 mClusterBinIndexRange[iLayer][binPrevIndex] = std::pair<Int_t, Int_t>(clsMinIndex, clsMaxIndex);
118
119 binPrevIndex = rof.getClustersInLayer(iLayer).at(jClsLayer).indexTableBin;
120 clsMinIndex = jClsLayer;
121 } // clusters
122
123 // last cluster
124 clsMaxIndex = jClsLayer - 1;
125
126 mClusterBinIndexRange[iLayer][binPrevIndex] = std::pair<Int_t, Int_t>(clsMinIndex, clsMaxIndex);
127 } // layers
128 }
129
130 void clearSorting()
131 {
132 for (Int_t iLayer = 0; iLayer < constants::mft::LayersNumber; ++iLayer) {
133 for (Int_t iBin = 0; iBin <= mRPhiBins + 1; ++iBin) {
134 mClusterBinIndexRange[iLayer][iBin] = std::pair<Int_t, Int_t>(0, -1);
135 }
136 }
137 }
138
139 const Int_t isDiskFace(Int_t layer) const { return (layer % 2); }
140 const Float_t getDistanceToSeed(const Cluster&, const Cluster&, const Cluster&) const;
141 void getBinClusterRange(const ROframe<T>&, const Int_t, const Int_t, Int_t&, Int_t&) const;
142 const Float_t getCellDeviation(const Cell&, const Cell&) const;
143 const Bool_t getCellsConnect(const Cell&, const Cell&) const;
144 void addCellToCurrentTrackCA(const Int_t, const Int_t, ROframe<T>&);
145 void addCellToCurrentRoad(ROframe<T>&, const Int_t, const Int_t, const Int_t, const Int_t, Int_t&);
146
147 int mTrackerID = 0;
148 Float_t mBz;
149 std::vector<MCCompLabel> mTrackLabels;
150 std::unique_ptr<o2::mft::TrackFitter<T>> mTrackFitter = nullptr;
151
152 Int_t mMaxCellLevel = 0;
153
154 bool mUseMC = false;
155
157 struct TrackElement {
158 TrackElement() = default;
159 TrackElement(Int_t la, Int_t id)
160 {
161 layer = la;
162 idInLayer = id;
163 };
164 Int_t layer;
165 Int_t idInLayer;
166 };
167
169 Road mRoad;
170};
171
172//_________________________________________________________________________________________________
173template <typename T>
174inline const Float_t Tracker<T>::getDistanceToSeed(const Cluster& cluster1, const Cluster& cluster2, const Cluster& cluster) const
175{
176 // the seed is between "cluster1" and "cluster2" and cuts the plane
177 // of the "cluster" at a distance dR from it
178 Float_t dxSeed, dySeed, dzSeed, invdzSeed, dz, dR2, xSeed, ySeed;
179 dxSeed = cluster2.getX() - cluster1.getX();
180 dySeed = cluster2.getY() - cluster1.getY();
181 dzSeed = cluster2.getZ() - cluster1.getZ();
182 dz = cluster.getZ() - cluster1.getZ();
183 invdzSeed = dz / dzSeed;
184 xSeed = cluster1.getX() + dxSeed * invdzSeed;
185 ySeed = cluster1.getY() + dySeed * invdzSeed;
186 dR2 = (cluster.getX() - xSeed) * (cluster.getX() - xSeed) + (cluster.getY() - ySeed) * (cluster.getY() - ySeed);
187 return dR2;
188}
189
190//_________________________________________________________________________________________________
191template <typename T>
192inline void Tracker<T>::getBinClusterRange(const ROframe<T>& event, const Int_t layer, const Int_t bin, Int_t& clsMinIndex, Int_t& clsMaxIndex) const
193{
194 const auto& pair = getClusterBinIndexRange(layer, bin);
195 clsMinIndex = pair.first;
196 clsMaxIndex = pair.second;
197}
198
199//_________________________________________________________________________________________________
200template <typename T>
201inline const Float_t Tracker<T>::getCellDeviation(const Cell& cell1, const Cell& cell2) const
202{
203 Float_t cell1dx = cell1.getX2() - cell1.getX1();
204 Float_t cell1dy = cell1.getY2() - cell1.getY1();
205 Float_t cell1dz = cell1.getZ2() - cell1.getZ1();
206
207 Float_t cell2dx = cell2.getX2() - cell2.getX1();
208 Float_t cell2dy = cell2.getY2() - cell2.getY1();
209 Float_t cell2dz = cell2.getZ2() - cell2.getZ1();
210
211 Float_t cell1mod = std::sqrt(cell1dx * cell1dx + cell1dy * cell1dy + cell1dz * cell1dz);
212 Float_t cell2mod = std::sqrt(cell2dx * cell2dx + cell2dy * cell2dy + cell2dz * cell2dz);
213
214 Float_t cosAngle = (cell1dx * cell2dx + cell1dy * cell2dy + cell1dz * cell2dz) / (cell1mod * cell2mod);
215 if (std::abs(cosAngle) < o2::constants::math::Almost1) {
216 return std::acos(cosAngle);
217 } else {
218 return cosAngle > 0 ? 0. : -o2::constants::math::PI;
219 }
220}
221
222//_________________________________________________________________________________________________
223template <typename T>
224inline const Bool_t Tracker<T>::getCellsConnect(const Cell& cell1, const Cell& cell2) const
225{
226 Float_t cell1x2 = cell1.getX2();
227 Float_t cell1y2 = cell1.getY2();
228 Float_t cell2x1 = cell2.getX1();
229 Float_t cell2y1 = cell2.getY1();
230 Float_t dx = cell1x2 - cell2x1;
231 Float_t dy = cell1y2 - cell2y1;
232 Float_t dr2 = dx * dx + dy * dy;
233
235 return kFALSE;
236 }
237 return kTRUE;
238}
239
240//_________________________________________________________________________________________________
241template <typename T>
242inline void Tracker<T>::computeTracksMClabels(const std::vector<T>& tracks)
243{
245 for (auto& track : tracks) {
246 MCCompLabel maxOccurrencesValue{-1, -1, -1, false};
247 int count{0};
248 bool isFakeTrack{false};
249 auto nClusters = track.getNumberOfPoints();
250 for (int iCluster = 0; iCluster < nClusters; ++iCluster) {
251 const MCCompLabel& currentLabel = track.getMCCompLabels()[iCluster];
252 if (currentLabel == maxOccurrencesValue) {
253 ++count;
254 } else {
255 if (count != 0) { // only in the first iteration count can be 0 at this point
256 --count;
257 }
258 if (count == 0) {
259 maxOccurrencesValue = currentLabel;
260 count = 1;
261 }
262 }
263 }
264 count = 0;
265 for (int iCluster = 0; iCluster < nClusters; ++iCluster) {
266 if (track.getMCCompLabels()[iCluster] == maxOccurrencesValue) {
267 count++;
268 }
269 }
270
271 auto labelratio = 1.0 * count / nClusters;
272 if (labelratio < mTrueTrackMCThreshold) {
273 isFakeTrack = true;
274 maxOccurrencesValue.setFakeFlag();
275 }
276 mTrackLabels.emplace_back(maxOccurrencesValue);
277 }
278}
279
280} // namespace mft
281} // namespace o2
282
283#endif /* O2_MFT_TRACKER_H_ */
General auxilliary methods.
A simple structure for the MFT cluster, used by the standalone track finder.
Header of the General Run Parameters object.
Class to delimit start and end IR of certain time period.
Definition of a class to fit a track to a set of clusters.
Definition of the ITSMFT ROFrame (trigger) record.
Definition of a container to keep Monte Carlo truth external to simulation objects.
The main container for the standalone track finding within a read-out-frame.
int nClusters
HMPID cluster implementation.
Definition Cluster.h:27
std::vector< Cluster > & getClustersInLayer(Int_t layerId)
Definition ROframe.h:56
std::array< std::array< std::pair< Int_t, Int_t >, constants::index_table::MaxRPhiBins >, constants::mft::LayersNumber > mClusterBinIndexRange
bool mFullClusterScan
Special track finder for TED shots and cosmics, with full scan of the clusters.
Tracker(const Tracker &)=delete
void findLTFTracks(ROframe< T > &)
Definition Tracker.cxx:240
void setBz(Float_t bz)
Definition Tracker.cxx:39
auto & getTrackLabels()
Definition Tracker.h:58
const Float_t getBz() const
Definition Tracker.h:56
void clearTracks()
Definition Tracker.h:60
void findCATracks(ROframe< T > &)
Definition Tracker.cxx:251
void findTracks(ROframe< T > &rofData)
Definition Tracker.h:65
Tracker & operator=(const Tracker &)=delete
void initializeFinder()
Definition Tracker.cxx:113
int getTrackerID() const
Definition Tracker.h:82
void configure(const MFTTrackingParam &trkParam, int trackerID)
Definition Tracker.cxx:48
void computeTracksMClabels(const std::vector< T > &)
Definition Tracker.h:242
bool fitTracks(ROframe< T > &)
Definition Tracker.cxx:1091
struct _cl_event * event
Definition glcorearb.h:2982
GLint GLsizei count
Definition glcorearb.h:399
GLenum GLuint GLint GLint layer
Definition glcorearb.h:1310
GLuint id
Definition glcorearb.h:650
constexpr float PI
constexpr float Almost1
constexpr Int_t LayersNumber
Definition Constants.h:37
constexpr Float_t Resolution
Definition Constants.h:43
std::function< bool(const ROFRecord &)> ROFFilter
Definition Tracker.h:40
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::array< std::vector< ROFRecord >, NEvTypes > rofData