forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTracker.h
More file actions
167 lines (139 loc) · 5.02 KB
/
Tracker.h
File metadata and controls
167 lines (139 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
///
/// \file Tracker.h
/// \brief
///
#ifndef TRACKINGITSU_INCLUDE_TRACKER_H_
#define TRACKINGITSU_INCLUDE_TRACKER_H_
#include <array>
#include <chrono>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iosfwd>
#include <memory>
#include <utility>
#include <sstream>
#include "ITStracking/Configuration.h"
#include "CommonConstants/MathConstants.h"
#include "ITStracking/Definitions.h"
#include "ITStracking/ROframe.h"
#include "ITStracking/MathUtils.h"
#include "ITStracking/TimeFrame.h"
#include "ITStracking/Road.h"
#include "DataFormatsITS/TrackITS.h"
#include "SimulationDataFormat/MCCompLabel.h"
namespace o2
{
namespace gpu
{
class GPUChainITS;
}
namespace its
{
class TrackerTraits;
class Tracker
{
using LogFunc = std::function<void(const std::string& s)>;
public:
Tracker(TrackerTraits* traits);
void adoptTimeFrame(TimeFrame& tf);
void clustersToTracks(
LogFunc = [](std::string s) { std::cout << s << std::endl; }, LogFunc = [](std::string s) { std::cerr << s << std::endl; });
void clustersToTracksHybrid(
LogFunc = [](std::string s) { std::cout << s << std::endl; }, LogFunc = [](std::string s) { std::cerr << s << std::endl; });
std::vector<TrackITSExt>& getTracks();
void setParameters(const std::vector<TrackingParameters>&);
std::vector<TrackingParameters>& getParameters() { return mTrkParams; }
void getGlobalConfiguration();
void setBz(float);
void setCorrType(const o2::base::PropagatorImpl<float>::MatCorrType type);
bool isMatLUT() const;
void setNThreads(int n);
int getNThreads() const;
void printSummary() const;
private:
enum TrackerType : uint8_t { CPU = 0,
Hybrid,
NSize };
template <TrackerType>
void clusterToTracksImpl(LogFunc, LogFunc);
static constexpr const char* sTrackerNames[TrackerType::NSize] = {"CPU", "Hybrid"};
// CPU
void initialiseTimeFrame(int& iteration);
void computeTracklets(int& iteration, int& iROFslice, int& iVertex);
void computeCells(int& iteration);
void findCellsNeighbours(int& iteration);
void findRoads(int& iteration);
void findShortPrimaries();
void extendTracks(int& iteration);
// Hyrbid
void initialiseTimeFrameHybrid(int& iteration);
void computeTrackletsHybrid(int& iteration, int& iROFslice, int& iVertex);
void computeCellsHybrid(int& iteration);
void findCellsNeighboursHybrid(int& iteration);
void findRoadsHybrid(int& iteration);
void findTracksHybrid(int& iteration);
// MC interaction
void computeRoadsMClabels();
void computeTracksMClabels();
void rectifyClusterIndices();
template <typename... T>
float evaluateTask(void (Tracker::*)(T...), const char*, LogFunc logger, T&&... args);
TrackerTraits* mTraits = nullptr; /// Observer pointer, not owned by this class
TimeFrame* mTimeFrame = nullptr; /// Observer pointer, not owned by this class
std::vector<TrackingParameters> mTrkParams;
o2::gpu::GPUChainITS* mRecoChain = nullptr;
unsigned int mNumberOfDroppedTFs{0};
unsigned int mTimeFrameCounter{0};
};
inline void Tracker::setParameters(const std::vector<TrackingParameters>& trkPars)
{
mTrkParams = trkPars;
}
template <typename... T>
float Tracker::evaluateTask(void (Tracker::*task)(T...), const char* taskName, LogFunc logger, T&&... args)
{
float diff{0.f};
if constexpr (constants::DoTimeBenchmarks) {
auto start = std::chrono::high_resolution_clock::now();
(this->*task)(std::forward<T>(args)...);
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> diff_t{end - start};
diff = diff_t.count();
std::stringstream sstream;
if (taskName == nullptr) {
sstream << diff << "\t";
} else {
sstream << std::setw(2) << " - " << taskName << " completed in: " << diff << " ms";
}
logger(sstream.str());
if (mTrkParams[0].SaveTimeBenchmarks) {
std::stringstream str2file;
std::string taskNameStr(taskName);
std::transform(taskNameStr.begin(), taskNameStr.end(), taskNameStr.begin(),
[](unsigned char c) { return std::tolower(c); });
std::replace(taskNameStr.begin(), taskNameStr.end(), ' ', '_');
str2file << taskNameStr << "\t" << diff;
std::ofstream file;
file.open("its_time_benchmarks.txt", std::ios::app);
file << str2file.str() << std::endl;
file.close();
}
} else {
(this->*task)(std::forward<T>(args)...);
}
return diff;
}
} // namespace its
} // namespace o2
#endif /* TRACKINGITSU_INCLUDE_TRACKER_H_ */