Project
Loading...
Searching...
No Matches
TrackerSpec.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 <chrono>
20#include <TMap.h>
21#include <TObjString.h>
26#include "Framework/Logger.h"
27#include "Framework/Output.h"
28#include "Framework/Task.h"
36#include "MIDTracking/Tracker.h"
41
42namespace of = o2::framework;
43
44namespace o2
45{
46namespace mid
47{
49{
50 public:
51 TrackerDeviceDPL(std::shared_ptr<o2::base::GRPGeomRequest> gr, bool isMC, bool checkMasked) : mGGCCDBRequest(gr), mIsMC(isMC), mCheckMasked(checkMasked) {}
52 ~TrackerDeviceDPL() = default;
53
55 {
57 mKeepAll = !ic.options().get<bool>("mid-tracker-keep-best");
58
59 auto stop = [this]() {
60 double scaleFactor = (mNROFs == 0) ? 0. : 1.e6 / mNROFs;
61 LOG(info) << "Processing time / " << mNROFs << " ROFs: full: " << mTimer.count() * scaleFactor << " us tracking: " << mTimerTracker.count() * scaleFactor << " us hitMapBuilder: " << mTimerBuilder.count() << " us";
62 };
63 ic.services().get<of::CallbackService>().set<of::CallbackService::Id::Stop>(stop);
64 }
65
67 {
68 auto tStart = std::chrono::high_resolution_clock::now();
69 updateTimeDependentParams(pc);
70 storeConfigs(pc);
71
72 auto clusters = pc.inputs().get<gsl::span<Cluster>>("mid_clusters");
73
74 auto inROFRecords = pc.inputs().get<gsl::span<ROFRecord>>("mid_clusters_rof");
75
76 auto tAlgoStart = std::chrono::high_resolution_clock::now();
77 mTracker->process(clusters, inROFRecords);
78 mTimerTracker += std::chrono::high_resolution_clock::now() - tAlgoStart;
79
80 tAlgoStart = std::chrono::high_resolution_clock::now();
81 std::vector<Track> tracks = mTracker->getTracks();
82 mHitMapBuilder->process(tracks, clusters);
83 mTimerBuilder += std::chrono::high_resolution_clock::now() - tAlgoStart;
84
85 if (mIsMC) {
86 std::unique_ptr<const o2::dataformats::MCTruthContainer<MCClusterLabel>> labels = pc.inputs().get<const o2::dataformats::MCTruthContainer<MCClusterLabel>*>("mid_clusterlabels");
87 mTrackLabeler.process(mTracker->getClusters(), tracks, *labels);
88 pc.outputs().snapshot(of::Output{"MID", "TRACKLABELS", 0}, mTrackLabeler.getTracksLabels());
89 LOG(debug) << "Sent " << mTrackLabeler.getTracksLabels().size() << " indexed tracks.";
90 pc.outputs().snapshot(of::Output{"MID", "TRCLUSLABELS", 0}, mTrackLabeler.getTrackClustersLabels());
91 LOG(debug) << "Sent " << mTrackLabeler.getTrackClustersLabels().getIndexedSize() << " indexed track clusters.";
92 }
93
94 pc.outputs().snapshot(of::Output{"MID", "TRACKS", 0}, tracks);
95 LOG(debug) << "Sent " << tracks.size() << " tracks.";
96 pc.outputs().snapshot(of::Output{"MID", "TRACKCLUSTERS", 0}, mTracker->getClusters());
97 LOG(debug) << "Sent " << mTracker->getClusters().size() << " track clusters.";
98
99 pc.outputs().snapshot(of::Output{"MID", "TRACKROFS", 0}, mTracker->getTrackROFRecords());
100 LOG(debug) << "Sent " << mTracker->getTrackROFRecords().size() << " ROFs.";
101 pc.outputs().snapshot(of::Output{"MID", "TRCLUSROFS", 0}, mTracker->getClusterROFRecords());
102 LOG(debug) << "Sent " << mTracker->getClusterROFRecords().size() << " ROFs.";
103
104 mTimer += std::chrono::high_resolution_clock::now() - tStart;
105 mNROFs += inROFRecords.size();
106 }
107
109 {
111 return;
112 }
113 if (mCheckMasked) {
114 bool rebuildMaskedChannels = false;
115 if (matcher == of::ConcreteDataMatcher(header::gDataOriginMID, "BAD_CH_TRK", 0)) {
116 LOG(info) << "Update MID_BAD_CH_TRK";
117 mBadChannels = *static_cast<std::vector<ColumnData>*>(obj);
118 rebuildMaskedChannels = true;
119 } else if (matcher == of::ConcreteDataMatcher(header::gDataOriginMID, "REJECTLIST_TRK", 0)) {
120 LOG(info) << "Update MID_REJECTLIST_TRK";
121 mRejectList = *static_cast<std::vector<ColumnData>*>(obj);
122 rebuildMaskedChannels = true;
123 }
124 if (rebuildMaskedChannels) {
125 mHitMapBuilder->setMaskedChannels(mBadChannels, true);
126 mHitMapBuilder->setMaskedChannels(mRejectList, false);
127 }
128 }
129 }
130
131 private:
132 void updateTimeDependentParams(o2::framework::ProcessingContext& pc)
133 {
134 // Triggers finalizeCCDB
136 static bool initOnceDone = false;
137 if (!initOnceDone) {
138 initOnceDone = true;
139 auto geoTrans = createTransformationFromManager(gGeoManager);
140 mTracker = std::make_unique<Tracker>(geoTrans);
141 if (!mTracker->init(mKeepAll)) {
142 LOG(error) << "Initialization of MID tracker device failed";
143 }
144 mHitMapBuilder = std::make_unique<HitMapBuilder>(geoTrans);
145 }
146 pc.inputs().get<std::vector<ColumnData>*>("mid_bad_channels_forTracks");
147 pc.inputs().get<std::vector<ColumnData>*>("mid_rejectlist_forTracks");
148 }
149
150 void storeConfigs(of::ProcessingContext& pc)
151 {
152 static bool first = true;
153 if (first) {
154 first = false;
155 if (pc.services().get<const of::DeviceSpec>().inputTimesliceId == 0) {
156 const auto& conf = TrackerParam::Instance();
158 TMap md;
159 md.SetOwnerKeyValue();
160 md.Add(new TObjString(conf.getName().c_str()), new TObjString(o2::conf::ConfigurableParam::asJSON(conf.getName()).c_str()));
161 pc.outputs().snapshot(of::Output{"META", "MIDTRACKER", 0}, md);
162 }
163 }
164 }
165
166 bool mIsMC = false;
167 bool mKeepAll = false;
168 bool mCheckMasked = false;
169 TrackLabeler mTrackLabeler{};
170 std::shared_ptr<o2::base::GRPGeomRequest> mGGCCDBRequest;
171 std::unique_ptr<Tracker> mTracker{nullptr};
172 std::unique_ptr<HitMapBuilder> mHitMapBuilder{nullptr};
173 std::chrono::duration<double> mTimer{0};
174 std::chrono::duration<double> mTimerTracker{0};
175 std::chrono::duration<double> mTimerBuilder{0};
176 unsigned int mNROFs{0};
177 std::vector<ColumnData> mBadChannels{};
178 std::vector<ColumnData> mRejectList{};
179};
180
182{
183 std::vector<of::InputSpec> inputSpecs;
184 inputSpecs.emplace_back("mid_clusters", header::gDataOriginMID, "CLUSTERS");
185 inputSpecs.emplace_back("mid_clusters_rof", header::gDataOriginMID, "CLUSTERSROF");
186 inputSpecs.emplace_back("mid_bad_channels_forTracks", header::gDataOriginMID, "BAD_CH_TRK", 0, of::Lifetime::Condition, of::ccdbParamSpec("MID/Calib/BadChannels"));
187 inputSpecs.emplace_back("mid_rejectlist_forTracks", header::gDataOriginMID, "REJECTLIST_TRK", 0, of::Lifetime::Condition, of::ccdbParamSpec("MID/Calib/RejectList"));
188 auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(false, // orbitResetTime
189 false, // GRPECS=true
190 false, // GRPLHCIF
191 false, // GRPMagField
192 false, // askMatLUT
194 inputSpecs,
195 true);
196 std::vector<of::OutputSpec> outputSpecs{
198 of::OutputSpec{header::gDataOriginMID, "TRACKCLUSTERS"},
201
202 if (isMC) {
203 inputSpecs.emplace_back(of::InputSpec{"mid_clusterlabels", header::gDataOriginMID, "CLUSTERSLABELS"});
204
205 outputSpecs.emplace_back(of::OutputSpec{header::gDataOriginMID, "TRACKLABELS"});
206 outputSpecs.emplace_back(of::OutputSpec{header::gDataOriginMID, "TRCLUSLABELS"});
207 }
208 outputSpecs.emplace_back("META", "MIDTRACKER", 0, of::Lifetime::Sporadic);
209
211 "MIDTracker",
212 {inputSpecs},
213 {outputSpecs},
214 of::adaptFromTask<o2::mid::TrackerDeviceDPL>(ggRequest, isMC, checkMasked),
215 of::Options{{"mid-tracker-keep-best", of::VariantType::Bool, false, {"Keep only best track (default is keep all)"}}}};
216}
217} // namespace mid
218} // namespace o2
std::vector< std::string > labels
Reconstructed MID cluster.
Reconstructed MID track.
Definition of the GeometryManager class.
std::ostringstream debug
Helper for geometry and GRP related CCDB requests.
Utility to build the MID track hit maps.
Label for MID clusters.
Configurable parameters for MID tracking.
Track reconstruction algorithm for MID.
Data processor spec for MID tracker device.
Definition of the MID event record.
Definition of the Names Generator class.
Tracks labeler for MID.
void checkUpdates(o2::framework::ProcessingContext &pc)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
static std::string getConfigOutputFileName(const std::string &procName, const std::string &confName="", bool json=true)
Definition NameConf.cxx:120
static std::string asJSON(std::string const &keyOnly="")
static void write(std::string const &filename, std::string const &keyOnly="")
A container to hold and manage MC truth information/labels.
void snapshot(const Output &spec, T const &object)
ServiceRegistryRef services()
Definition InitContext.h:34
ConfigParamRegistry const & options()
Definition InitContext.h:33
decltype(auto) get(R binding, int part=0) const
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
ServiceRegistryRef services()
The services registry associated with this processing context.
const o2::dataformats::MCTruthContainer< MCClusterLabel > & getTrackClustersLabels()
Returns the cluster labels.
void process(gsl::span< const Cluster > clusters, gsl::span< const Track > tracks, const o2::dataformats::MCTruthContainer< MCClusterLabel > &inMCContainer)
const std::vector< MCCompLabel > & getTracksLabels()
Returns the tracks labels.
void run(o2::framework::ProcessingContext &pc)
void finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj)
void init(o2::framework::InitContext &ic)
TrackerDeviceDPL(std::shared_ptr< o2::base::GRPGeomRequest > gr, bool isMC, bool checkMasked)
constexpr o2::header::DataOrigin gDataOriginMID
Definition DataHeader.h:573
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
std::vector< ConfigParamSpec > Options
framework::DataProcessorSpec getTrackerSpec(bool isMC, bool checkMasked)
GeometryTransformer createTransformationFromManager(const TGeoManager *geoManager)
std::vector< Cluster > clusters
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string name
The name of the associated DataProcessorSpec.
Definition DeviceSpec.h:50
size_t inputTimesliceId
The time pipelining id of this particular device.
Definition DeviceSpec.h:68
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"