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