Project
Loading...
Searching...
No Matches
TOFMatcherSpec.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
13
14#include <vector>
15#include <string>
16#include "TStopwatch.h"
23#include "Framework/Task.h"
27
28// from Tracks
37
38// from TOF
42#include "TOFBase/Utils.h"
43
44using namespace o2::framework;
45// using MCLabelsTr = gsl::span<const o2::MCCompLabel>;
46// using GID = o2::dataformats::GlobalTrackID;
47// using DetID = o2::detectors::DetID;
48
50using MatchOutputType = std::vector<o2::dataformats::MatchInfoTOF>;
52
53namespace o2
54{
55namespace globaltracking
56{
57
58class TOFMatcherSpec : public Task
59{
60 public:
61 TOFMatcherSpec(std::shared_ptr<DataRequest> dr, std::shared_ptr<o2::base::GRPGeomRequest> gr, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts, bool useMC, bool useFIT, bool tpcRefit, bool strict, bool pushMatchable, int lanes = 1) : mDataRequest(dr), mGGCCDBRequest(gr), mUseMC(useMC), mUseFIT(useFIT), mDoTPCRefit(tpcRefit), mStrict(strict), mPushMatchable(pushMatchable), mNlanes(lanes)
62 {
63 mTPCCorrMapsLoader.setLumiScaleType(sclOpts.lumiType);
64 mTPCCorrMapsLoader.setLumiScaleMode(sclOpts.lumiMode);
65 }
66 ~TOFMatcherSpec() override = default;
67 void init(InitContext& ic) final;
68 void run(ProcessingContext& pc) final;
70 void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) final;
71
72 private:
73 void updateTimeDependentParams(ProcessingContext& pc);
74 std::shared_ptr<DataRequest> mDataRequest;
75 std::shared_ptr<o2::base::GRPGeomRequest> mGGCCDBRequest;
76 o2::tpc::VDriftHelper mTPCVDriftHelper{};
77 o2::tpc::CorrectionMapsLoader mTPCCorrMapsLoader{};
78 bool mUseMC = true;
79 bool mUseFIT = false;
80 bool mDoTPCRefit = false;
81 bool mStrict = false;
82 bool mPushMatchable = false;
83 float mExtraTolTRD = 0.;
84 int mNlanes = 1;
85 MatchTOF mMatcher;
86 TStopwatch mTimer;
87};
88
90{
91 mTimer.Stop();
92 mTimer.Reset();
94 if (mStrict) {
95 mMatcher.setHighPurity();
96 }
97 mTPCCorrMapsLoader.init(ic);
98 mMatcher.storeMatchable(mPushMatchable);
99 mMatcher.setExtraTimeToleranceTRD(mExtraTolTRD);
100 mMatcher.setNlanes(mNlanes);
101}
102
103void TOFMatcherSpec::updateTimeDependentParams(ProcessingContext& pc)
104{
106 mTPCVDriftHelper.extractCCDBInputs(pc);
107 mTPCCorrMapsLoader.extractCCDBInputs(pc);
108 static bool initOnceDone = false;
109 if (!initOnceDone) { // this params need to be queried only once
110 const auto bcs = o2::base::GRPGeomHelper::instance().getGRPLHCIF()->getBunchFilling().getFilledBCs();
111 for (auto bc : bcs) {
113 }
114 initOnceDone = true;
115 // put here init-once stuff
116 }
117 // we may have other params which need to be queried regularly
118 bool updateMaps = false;
119 if (mTPCCorrMapsLoader.isUpdated()) {
120 mTPCCorrMapsLoader.acknowledgeUpdate();
121 updateMaps = true;
122 }
123 mMatcher.setTPCCorrMaps(&mTPCCorrMapsLoader);
124 if (mTPCVDriftHelper.isUpdated()) {
125 LOGP(info, "Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}",
126 mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift,
127 mTPCVDriftHelper.getVDriftObject().timeOffsetCorr, mTPCVDriftHelper.getVDriftObject().refTimeOffset,
128 mTPCVDriftHelper.getSourceName());
129 mMatcher.setTPCVDrift(mTPCVDriftHelper.getVDriftObject());
130 mTPCVDriftHelper.acknowledgeUpdate();
131 updateMaps = true;
132 }
133 if (updateMaps) {
134 mTPCCorrMapsLoader.updateVDrift(mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, mTPCVDriftHelper.getVDriftObject().getTimeOffset());
135 }
136}
137
139{
141 return;
142 }
143 if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) {
144 return;
145 }
146 if (mTPCCorrMapsLoader.accountCCDBInputs(matcher, obj)) {
147 return;
148 }
149}
150
152{
153 mTimer.Start(false);
154
155 RecoContainer recoData;
156 recoData.collectData(pc, *mDataRequest.get());
157 updateTimeDependentParams(pc);
158 auto creationTime = pc.services().get<o2::framework::TimingInfo>().creation;
159
160 LOG(debug) << "isTrackSourceLoaded: TPC -> " << recoData.isTrackSourceLoaded(o2::dataformats::GlobalTrackID::Source::TPC);
161 LOG(debug) << "isTrackSourceLoaded: ITSTPC -> " << recoData.isTrackSourceLoaded(o2::dataformats::GlobalTrackID::Source::ITSTPC);
162 LOG(debug) << "isTrackSourceLoaded: TPCTRD -> " << recoData.isTrackSourceLoaded(o2::dataformats::GlobalTrackID::Source::TPCTRD);
163 LOG(debug) << "isTrackSourceLoaded: ITSTPCTRD -> " << recoData.isTrackSourceLoaded(o2::dataformats::GlobalTrackID::Source::ITSTPCTRD);
164
169 uint32_t ss = o2::globaltracking::getSubSpec(mStrict ? o2::globaltracking::MatchingType::Strict : o2::globaltracking::MatchingType::Standard);
170 mMatcher.setFIT(mUseFIT);
171
172 mMatcher.setTS(creationTime);
173
174 mMatcher.run(recoData, pc.services().get<o2::framework::TimingInfo>().firstTForbit);
175 static pmr::vector<o2::MCCompLabel> dummyMCLab;
176
177 if (isTPCused) {
178 auto& mtcInfo = pc.outputs().make<std::vector<o2::dataformats::MatchInfoTOF>>(Output{o2::header::gDataOriginTOF, "MTC_TPC", ss});
179 auto& mclabels = mUseMC ? pc.outputs().make<std::vector<o2::MCCompLabel>>(Output{o2::header::gDataOriginTOF, "MCMTC_TPC", ss}) : dummyMCLab;
180 auto& tracksTPCTOF = pc.outputs().make<std::vector<o2::dataformats::TrackTPCTOF>>(OutputRef{"tpctofTracks", ss});
182 LOG(debug) << (mDoTPCRefit ? "Refitting " : "Shifting Z for ") << nmatch << " matched TPC tracks with TOF time info";
183 mMatcher.makeConstrainedTPCTracks(mtcInfo, mclabels, tracksTPCTOF);
184 }
185
186 if (isITSTPCused) {
188 if (mUseMC) {
190 }
191 }
192
193 if (isTPCTRDused) {
195 if (mUseMC) {
197 }
198 }
199
200 if (isITSTPCTRDused) {
202 if (mUseMC) {
204 }
205 }
206
207 // TODO: TRD-matched tracks
208 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "CALIBDATA", 0}, mMatcher.getCalibVector());
209
210 if (mPushMatchable) {
211 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_0", 0}, mMatcher.getMatchedTracksPair(0));
212 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_1", 0}, mMatcher.getMatchedTracksPair(1));
213 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_2", 0}, mMatcher.getMatchedTracksPair(2));
214 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_3", 0}, mMatcher.getMatchedTracksPair(3));
215 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_4", 0}, mMatcher.getMatchedTracksPair(4));
216 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_5", 0}, mMatcher.getMatchedTracksPair(5));
217 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_6", 0}, mMatcher.getMatchedTracksPair(6));
218 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_7", 0}, mMatcher.getMatchedTracksPair(7));
219 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_8", 0}, mMatcher.getMatchedTracksPair(8));
220 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_9", 0}, mMatcher.getMatchedTracksPair(9));
221 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_10", 0}, mMatcher.getMatchedTracksPair(10));
222 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_11", 0}, mMatcher.getMatchedTracksPair(11));
223 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_12", 0}, mMatcher.getMatchedTracksPair(12));
224 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_13", 0}, mMatcher.getMatchedTracksPair(13));
225 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_14", 0}, mMatcher.getMatchedTracksPair(14));
226 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_15", 0}, mMatcher.getMatchedTracksPair(15));
227 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_16", 0}, mMatcher.getMatchedTracksPair(16));
228 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_17", 0}, mMatcher.getMatchedTracksPair(17));
229 }
230
231 mTimer.Stop();
232}
233
235{
236 LOGF(debug, "TOF matching total timing: Cpu: %.3e Real: %.3e s in %d slots",
237 mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
238}
239
240DataProcessorSpec getTOFMatcherSpec(GID::mask_t src, bool useMC, bool useFIT, bool tpcRefit, bool strict, float extratolerancetrd, bool pushMatchable, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts, int nlanes)
241{
242 uint32_t ss = o2::globaltracking::getSubSpec(strict ? o2::globaltracking::MatchingType::Strict : o2::globaltracking::MatchingType::Standard);
243 Options opts;
244 auto dataRequest = std::make_shared<DataRequest>();
245 if (strict) {
246 dataRequest->setMatchingInputStrict();
247 }
248 dataRequest->requestTracks(src, useMC);
249 dataRequest->requestClusters(GID::getSourceMask(GID::TOF), useMC);
250 if (tpcRefit && src[GID::TPC]) {
251 dataRequest->requestClusters(GID::getSourceMask(GID::TPC), false);
252 }
253 if (useFIT) {
254 dataRequest->requestFT0RecPoints(false);
255 }
256
257 auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(false, // orbitResetTime
258 true, // GRPECS=true
259 true, // GRPLHCIF
260 true, // GRPMagField
261 true, // askMatLUT
263 dataRequest->inputs,
264 true);
265 o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs);
266 o2::tpc::CorrectionMapsLoader::requestCCDBInputs(dataRequest->inputs, opts, sclOpts);
267 std::vector<OutputSpec> outputs;
268 if (GID::includesSource(GID::TPC, src)) {
269 outputs.emplace_back(o2::header::gDataOriginTOF, "MTC_TPC", ss, Lifetime::Timeframe);
270 outputs.emplace_back(OutputLabel{"tpctofTracks"}, o2::header::gDataOriginTOF, "TOFTRACKS_TPC", ss, Lifetime::Timeframe);
271 if (useMC) {
272 outputs.emplace_back(o2::header::gDataOriginTOF, "MCMTC_TPC", ss, Lifetime::Timeframe);
273 }
274 }
275 if (GID::includesSource(GID::ITSTPC, src)) {
276 outputs.emplace_back(o2::header::gDataOriginTOF, "MTC_ITSTPC", 0, Lifetime::Timeframe);
277 if (useMC) {
278 outputs.emplace_back(o2::header::gDataOriginTOF, "MCMTC_ITSTPC", 0, Lifetime::Timeframe);
279 }
280 }
281 if (GID::includesSource(GID::ITSTPCTRD, src)) {
282 outputs.emplace_back(o2::header::gDataOriginTOF, "MTC_ITSTPCTRD", 0, Lifetime::Timeframe);
283 if (useMC) {
284 outputs.emplace_back(o2::header::gDataOriginTOF, "MCMTC_ITSTPCTRD", 0, Lifetime::Timeframe);
285 }
286 }
287 if (GID::includesSource(GID::TPCTRD, src)) {
288 outputs.emplace_back(o2::header::gDataOriginTOF, "MTC_TPCTRD", ss, Lifetime::Timeframe);
289 if (useMC) {
290 outputs.emplace_back(o2::header::gDataOriginTOF, "MCMTC_TPCTRD", ss, Lifetime::Timeframe);
291 }
292 }
293 outputs.emplace_back(o2::header::gDataOriginTOF, "CALIBDATA", 0, Lifetime::Timeframe);
294
295 if (pushMatchable) {
296 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_0", 0, Lifetime::Timeframe);
297 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_1", 0, Lifetime::Timeframe);
298 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_2", 0, Lifetime::Timeframe);
299 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_3", 0, Lifetime::Timeframe);
300 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_4", 0, Lifetime::Timeframe);
301 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_5", 0, Lifetime::Timeframe);
302 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_6", 0, Lifetime::Timeframe);
303 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_7", 0, Lifetime::Timeframe);
304 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_8", 0, Lifetime::Timeframe);
305 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_9", 0, Lifetime::Timeframe);
306 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_10", 0, Lifetime::Timeframe);
307 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_11", 0, Lifetime::Timeframe);
308 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_12", 0, Lifetime::Timeframe);
309 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_13", 0, Lifetime::Timeframe);
310 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_14", 0, Lifetime::Timeframe);
311 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_15", 0, Lifetime::Timeframe);
312 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_16", 0, Lifetime::Timeframe);
313 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_17", 0, Lifetime::Timeframe);
314 }
315
316 return DataProcessorSpec{
317 "tof-matcher",
318 dataRequest->inputs,
319 outputs,
320 AlgorithmSpec{adaptFromTask<TOFMatcherSpec>(dataRequest, ggRequest, sclOpts, useMC, useFIT, tpcRefit, strict, pushMatchable, nlanes)},
321 opts};
322}
323
324} // namespace globaltracking
325} // namespace o2
Helper class to access load maps from CCDB.
Wrapper container for different reconstructed object types.
Definition of the TOF cluster.
Definition of the GeometryManager class.
uint64_t bc
Definition RawEventData.h:5
Helper for geometry and GRP related CCDB requests.
Accessor for TrackParCov derived objects from multiple containers.
Global index for barrel track: provides provenance (detectors combination), index in respective array...
std::vector< o2::dataformats::MatchInfoHMP > MatchOutputType
Class to perform TOF matching to global tracks.
Definition of the Names Generator class.
Definition of the ITS track.
Result of refitting TPC-ITS matched track.
Result of refitting TPC with TOF match constraint.
Helper class to extract VDrift from different sources.
std::ostringstream debug
void checkUpdates(o2::framework::ProcessingContext &pc)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
void snapshot(const Output &spec, T const &object)
decltype(auto) make(const Output &spec, Args... args)
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
ServiceRegistryRef services()
The services registry associated with this processing context.
void setTPCVDrift(const o2::tpc::VDriftCorrFact &v)
Definition MatchTOF.cxx:249
void setExtraTimeToleranceTRD(float val)
get extra tolerance on trackTRD-TOF times comparison
Definition MatchTOF.h:113
void makeConstrainedTPCTracks(MtcInfo &mtcCont, MCInfo &MCCont, CTrack &trcCont)
Definition MatchTOF.h:165
std::vector< o2::MCCompLabel > & getMatchedTOFLabelsVector(trkType index)
get vector of TOF labels of matched tracks
Definition MatchTOF.h:152
void setFIT(bool value=true)
Definition MatchTOF.h:157
std::vector< o2::dataformats::CalibInfoTOF > & getCalibVector()
Definition MatchTOF.h:148
void setTPCCorrMaps(o2::gpu::CorrectionMapsHelper *maph)
Definition MatchTOF.cxx:258
std::vector< o2::dataformats::MatchInfoTOFReco > & getMatchedTracksPair(int sec)
Definition MatchTOF.h:150
void setHighPurity(bool value=true)
print settings
Definition MatchTOF.h:102
std::vector< o2::dataformats::MatchInfoTOF > & getMatchedTrackVector(trkType index)
Definition MatchTOF.h:147
void setTS(unsigned long creationTime)
Definition MatchTOF.h:192
void storeMatchable(bool val=true)
Definition MatchTOF.h:198
void run(const o2::globaltracking::RecoContainer &inp, unsigned long firstTForbit=0)
< perform matching for provided input
Definition MatchTOF.cxx:67
void setNlanes(int lanes)
Definition MatchTOF.h:200
void run(ProcessingContext &pc) final
void init(InitContext &ic) final
void endOfStream(framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
~TOFMatcherSpec() override=default
void finaliseCCDB(ConcreteDataMatcher &matcher, void *obj) final
TOFMatcherSpec(std::shared_ptr< DataRequest > dr, std::shared_ptr< o2::base::GRPGeomRequest > gr, const o2::tpc::CorrectionMapsLoaderGloOpts &sclOpts, bool useMC, bool useFIT, bool tpcRefit, bool strict, bool pushMatchable, int lanes=1)
static void addInteractionBC(int bc, bool fromCollisonCotext=false)
Definition Utils.cxx:52
void extractCCDBInputs(o2::framework::ProcessingContext &pc)
void updateVDrift(float vdriftCorr, float vdrifRef, float driftTimeOffset=0)
bool accountCCDBInputs(const o2::framework::ConcreteDataMatcher &matcher, void *obj)
static void requestCCDBInputs(std::vector< o2::framework::InputSpec > &inputs, std::vector< o2::framework::ConfigParamSpec > &options, const CorrectionMapsLoaderGloOpts &gloOpts)
recalculate inverse correction
void init(o2::framework::InitContext &ic)
static void requestCCDBInputs(std::vector< o2::framework::InputSpec > &inputs, bool laser=true, bool itstpcTgl=true)
void extractCCDBInputs(o2::framework::ProcessingContext &pc, bool laser=true, bool itstpcTgl=true)
const VDriftCorrFact & getVDriftObject() const
bool accountCCDBInputs(const o2::framework::ConcreteDataMatcher &matcher, void *obj)
static std::string_view getSourceName(Source s)
bool isUpdated() const
GLenum src
Definition glcorearb.h:1767
constexpr o2::header::DataOrigin gDataOriginTOF
Definition DataHeader.h:575
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > Options
framework::DataProcessorSpec getTOFMatcherSpec(o2::dataformats::GlobalTrackID::mask_t src, bool useMC, bool useFIT, bool tpcRefit, bool strict, float extratolerancetrd, bool pushMatchable, const o2::tpc::CorrectionMapsLoaderGloOpts &sclOpts, int nlanes=1)
create a processor spec
std::vector< T, o2::pmr::polymorphic_allocator< T > > vector
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
void collectData(o2::framework::ProcessingContext &pc, const DataRequest &request)
int lumiType
what estimator to used for corrections scaling: 0: no scaling, 1: CTP, 2: IDC
int lumiMode
what corrections method to use: 0: classical scaling, 1: Using of the derivative map,...
float refTimeOffset
additive time offset reference (\mus)
float refVDrift
reference vdrift for which factor was extracted
float getTimeOffset() const
float timeOffsetCorr
additive time offset correction (\mus)
float corrFact
drift velocity correction factor (multiplicative)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"