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 mTPCCorrMapsLoader.setCheckCTPIDCConsistency(sclOpts.checkCTPIDCconsistency);
66 }
67 ~TOFMatcherSpec() override = default;
68 void init(InitContext& ic) final;
69 void run(ProcessingContext& pc) final;
71 void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) final;
72
73 private:
74 void updateTimeDependentParams(ProcessingContext& pc);
75 std::shared_ptr<DataRequest> mDataRequest;
76 std::shared_ptr<o2::base::GRPGeomRequest> mGGCCDBRequest;
77 o2::tpc::VDriftHelper mTPCVDriftHelper{};
78 o2::tpc::CorrectionMapsLoader mTPCCorrMapsLoader{};
79 bool mUseMC = true;
80 bool mUseFIT = false;
81 bool mDoTPCRefit = false;
82 bool mStrict = false;
83 bool mPushMatchable = false;
84 float mExtraTolTRD = 0.;
85 int mNlanes = 1;
86 MatchTOF mMatcher;
87 TStopwatch mTimer;
88};
89
91{
92 mTimer.Stop();
93 mTimer.Reset();
95 if (mStrict) {
96 mMatcher.setHighPurity();
97 }
98 mTPCCorrMapsLoader.init(ic);
99 mMatcher.storeMatchable(mPushMatchable);
100 mMatcher.setExtraTimeToleranceTRD(mExtraTolTRD);
101 mMatcher.setNlanes(mNlanes);
102}
103
104void TOFMatcherSpec::updateTimeDependentParams(ProcessingContext& pc)
105{
107 mTPCVDriftHelper.extractCCDBInputs(pc);
108 mTPCCorrMapsLoader.extractCCDBInputs(pc);
109 static bool initOnceDone = false;
110 if (!initOnceDone) { // this params need to be queried only once
111 const auto bcs = o2::base::GRPGeomHelper::instance().getGRPLHCIF()->getBunchFilling().getFilledBCs();
112 for (auto bc : bcs) {
114 }
115 initOnceDone = true;
116 // put here init-once stuff
117 }
118 // we may have other params which need to be queried regularly
119 bool updateMaps = false;
120 if (mTPCCorrMapsLoader.isUpdated()) {
121 mTPCCorrMapsLoader.acknowledgeUpdate();
122 updateMaps = true;
123 }
124 mMatcher.setTPCCorrMaps(&mTPCCorrMapsLoader);
125 if (mTPCVDriftHelper.isUpdated()) {
126 LOGP(info, "Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}",
127 mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift,
128 mTPCVDriftHelper.getVDriftObject().timeOffsetCorr, mTPCVDriftHelper.getVDriftObject().refTimeOffset,
129 mTPCVDriftHelper.getSourceName());
130 mMatcher.setTPCVDrift(mTPCVDriftHelper.getVDriftObject());
131 mTPCVDriftHelper.acknowledgeUpdate();
132 updateMaps = true;
133 }
134 if (updateMaps) {
135 mTPCCorrMapsLoader.updateVDrift(mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, mTPCVDriftHelper.getVDriftObject().getTimeOffset());
136 }
137}
138
140{
142 return;
143 }
144 if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) {
145 return;
146 }
147 if (mTPCCorrMapsLoader.accountCCDBInputs(matcher, obj)) {
148 return;
149 }
150}
151
153{
154 mTimer.Start(false);
155
156 RecoContainer recoData;
157 recoData.collectData(pc, *mDataRequest.get());
158 updateTimeDependentParams(pc);
159 auto creationTime = pc.services().get<o2::framework::TimingInfo>().creation;
160
161 LOG(debug) << "isTrackSourceLoaded: TPC -> " << recoData.isTrackSourceLoaded(o2::dataformats::GlobalTrackID::Source::TPC);
162 LOG(debug) << "isTrackSourceLoaded: ITSTPC -> " << recoData.isTrackSourceLoaded(o2::dataformats::GlobalTrackID::Source::ITSTPC);
163 LOG(debug) << "isTrackSourceLoaded: TPCTRD -> " << recoData.isTrackSourceLoaded(o2::dataformats::GlobalTrackID::Source::TPCTRD);
164 LOG(debug) << "isTrackSourceLoaded: ITSTPCTRD -> " << recoData.isTrackSourceLoaded(o2::dataformats::GlobalTrackID::Source::ITSTPCTRD);
165
170 uint32_t ss = o2::globaltracking::getSubSpec(mStrict ? o2::globaltracking::MatchingType::Strict : o2::globaltracking::MatchingType::Standard);
171 mMatcher.setFIT(mUseFIT);
172
173 mMatcher.setTS(creationTime);
174
175 mMatcher.run(recoData, pc.services().get<o2::framework::TimingInfo>().firstTForbit);
176 static pmr::vector<o2::MCCompLabel> dummyMCLab;
177
178 if (isTPCused) {
179 auto& mtcInfo = pc.outputs().make<std::vector<o2::dataformats::MatchInfoTOF>>(Output{o2::header::gDataOriginTOF, "MTC_TPC", ss});
180 auto& mclabels = mUseMC ? pc.outputs().make<std::vector<o2::MCCompLabel>>(Output{o2::header::gDataOriginTOF, "MCMTC_TPC", ss}) : dummyMCLab;
181 auto& tracksTPCTOF = pc.outputs().make<std::vector<o2::dataformats::TrackTPCTOF>>(OutputRef{"tpctofTracks", ss});
183 LOG(debug) << (mDoTPCRefit ? "Refitting " : "Shifting Z for ") << nmatch << " matched TPC tracks with TOF time info";
184 mMatcher.makeConstrainedTPCTracks(mtcInfo, mclabels, tracksTPCTOF);
185 }
186
187 if (isITSTPCused) {
189 if (mUseMC) {
191 }
192 }
193
194 if (isTPCTRDused) {
196 if (mUseMC) {
198 }
199 }
200
201 if (isITSTPCTRDused) {
203 if (mUseMC) {
205 }
206 }
207
208 // TODO: TRD-matched tracks
209 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "CALIBDATA", 0}, mMatcher.getCalibVector());
210
211 if (mPushMatchable) {
212 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_0", 0}, mMatcher.getMatchedTracksPair(0));
213 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_1", 0}, mMatcher.getMatchedTracksPair(1));
214 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_2", 0}, mMatcher.getMatchedTracksPair(2));
215 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_3", 0}, mMatcher.getMatchedTracksPair(3));
216 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_4", 0}, mMatcher.getMatchedTracksPair(4));
217 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_5", 0}, mMatcher.getMatchedTracksPair(5));
218 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_6", 0}, mMatcher.getMatchedTracksPair(6));
219 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_7", 0}, mMatcher.getMatchedTracksPair(7));
220 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_8", 0}, mMatcher.getMatchedTracksPair(8));
221 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_9", 0}, mMatcher.getMatchedTracksPair(9));
222 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_10", 0}, mMatcher.getMatchedTracksPair(10));
223 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_11", 0}, mMatcher.getMatchedTracksPair(11));
224 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_12", 0}, mMatcher.getMatchedTracksPair(12));
225 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_13", 0}, mMatcher.getMatchedTracksPair(13));
226 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_14", 0}, mMatcher.getMatchedTracksPair(14));
227 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_15", 0}, mMatcher.getMatchedTracksPair(15));
228 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_16", 0}, mMatcher.getMatchedTracksPair(16));
229 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_17", 0}, mMatcher.getMatchedTracksPair(17));
230 }
231
232 mTimer.Stop();
233}
234
236{
237 LOGF(debug, "TOF matching total timing: Cpu: %.3e Real: %.3e s in %d slots",
238 mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
239}
240
241DataProcessorSpec getTOFMatcherSpec(GID::mask_t src, bool useMC, bool useFIT, bool tpcRefit, bool strict, float extratolerancetrd, bool pushMatchable, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts, int nlanes)
242{
243 uint32_t ss = o2::globaltracking::getSubSpec(strict ? o2::globaltracking::MatchingType::Strict : o2::globaltracking::MatchingType::Standard);
244 Options opts;
245 auto dataRequest = std::make_shared<DataRequest>();
246 if (strict) {
247 dataRequest->setMatchingInputStrict();
248 }
249 dataRequest->requestTracks(src, useMC);
250 dataRequest->requestClusters(GID::getSourceMask(GID::TOF), useMC);
251 if (tpcRefit && src[GID::TPC]) {
252 dataRequest->requestClusters(GID::getSourceMask(GID::TPC), false);
253 }
254 if (useFIT) {
255 dataRequest->requestFT0RecPoints(false);
256 }
257
258 auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(false, // orbitResetTime
259 true, // GRPECS=true
260 true, // GRPLHCIF
261 true, // GRPMagField
262 true, // askMatLUT
264 dataRequest->inputs,
265 true);
266 o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs);
267 o2::tpc::CorrectionMapsLoader::requestCCDBInputs(dataRequest->inputs, opts, sclOpts);
268 std::vector<OutputSpec> outputs;
269 if (GID::includesSource(GID::TPC, src)) {
270 outputs.emplace_back(o2::header::gDataOriginTOF, "MTC_TPC", ss, Lifetime::Timeframe);
271 outputs.emplace_back(OutputLabel{"tpctofTracks"}, o2::header::gDataOriginTOF, "TOFTRACKS_TPC", ss, Lifetime::Timeframe);
272 if (useMC) {
273 outputs.emplace_back(o2::header::gDataOriginTOF, "MCMTC_TPC", ss, Lifetime::Timeframe);
274 }
275 }
276 if (GID::includesSource(GID::ITSTPC, src)) {
277 outputs.emplace_back(o2::header::gDataOriginTOF, "MTC_ITSTPC", 0, Lifetime::Timeframe);
278 if (useMC) {
279 outputs.emplace_back(o2::header::gDataOriginTOF, "MCMTC_ITSTPC", 0, Lifetime::Timeframe);
280 }
281 }
282 if (GID::includesSource(GID::ITSTPCTRD, src)) {
283 outputs.emplace_back(o2::header::gDataOriginTOF, "MTC_ITSTPCTRD", 0, Lifetime::Timeframe);
284 if (useMC) {
285 outputs.emplace_back(o2::header::gDataOriginTOF, "MCMTC_ITSTPCTRD", 0, Lifetime::Timeframe);
286 }
287 }
288 if (GID::includesSource(GID::TPCTRD, src)) {
289 outputs.emplace_back(o2::header::gDataOriginTOF, "MTC_TPCTRD", ss, Lifetime::Timeframe);
290 if (useMC) {
291 outputs.emplace_back(o2::header::gDataOriginTOF, "MCMTC_TPCTRD", ss, Lifetime::Timeframe);
292 }
293 }
294 outputs.emplace_back(o2::header::gDataOriginTOF, "CALIBDATA", 0, Lifetime::Timeframe);
295
296 if (pushMatchable) {
297 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_0", 0, Lifetime::Timeframe);
298 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_1", 0, Lifetime::Timeframe);
299 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_2", 0, Lifetime::Timeframe);
300 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_3", 0, Lifetime::Timeframe);
301 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_4", 0, Lifetime::Timeframe);
302 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_5", 0, Lifetime::Timeframe);
303 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_6", 0, Lifetime::Timeframe);
304 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_7", 0, Lifetime::Timeframe);
305 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_8", 0, Lifetime::Timeframe);
306 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_9", 0, Lifetime::Timeframe);
307 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_10", 0, Lifetime::Timeframe);
308 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_11", 0, Lifetime::Timeframe);
309 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_12", 0, Lifetime::Timeframe);
310 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_13", 0, Lifetime::Timeframe);
311 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_14", 0, Lifetime::Timeframe);
312 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_15", 0, Lifetime::Timeframe);
313 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_16", 0, Lifetime::Timeframe);
314 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_17", 0, Lifetime::Timeframe);
315 }
316
317 return DataProcessorSpec{
318 "tof-matcher",
319 dataRequest->inputs,
320 outputs,
321 AlgorithmSpec{adaptFromTask<TOFMatcherSpec>(dataRequest, ggRequest, sclOpts, useMC, useFIT, tpcRefit, strict, pushMatchable, nlanes)},
322 opts};
323}
324
325} // namespace globaltracking
326} // 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)
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, fair::mq::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"