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#include "TPCFastTransformPOD.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, bool useMC, bool useFIT, bool tpcRefit, bool strict, bool pushMatchable, int lanes = 1, bool requestCTPLumi = false) : mDataRequest(dr), mGGCCDBRequest(gr), mUseMC(useMC), mUseFIT(useFIT), mDoTPCRefit(tpcRefit), mStrict(strict), mPushMatchable(pushMatchable), mNlanes(lanes), mRequestCTPLumi(requestCTPLumi) {}
63 ~TOFMatcherSpec() override = default;
64 void init(InitContext& ic) final;
65 void run(ProcessingContext& pc) final;
67 void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) final;
68
69 private:
70 void updateTimeDependentParams(ProcessingContext& pc);
71 std::shared_ptr<DataRequest> mDataRequest;
72 std::shared_ptr<o2::base::GRPGeomRequest> mGGCCDBRequest;
73 o2::tpc::VDriftHelper mTPCVDriftHelper{};
74 const o2::gpu::TPCFastTransformPOD* mTPCCorrMaps = nullptr;
75 bool mUseMC = true;
76 bool mUseFIT = false;
77 bool mDoTPCRefit = false;
78 bool mStrict = false;
79 bool mPushMatchable = false;
80 float mExtraTolTRD = 0.;
81 int mNlanes = 1;
82 bool mRequestCTPLumi = false;
83 MatchTOF mMatcher;
84 TStopwatch mTimer;
85};
86
88{
89 mTimer.Stop();
90 mTimer.Reset();
92 if (mStrict) {
93 mMatcher.setHighPurity();
94 }
95 mMatcher.storeMatchable(mPushMatchable);
96 mMatcher.setExtraTimeToleranceTRD(mExtraTolTRD);
97 mMatcher.setNlanes(mNlanes);
98}
99
100void TOFMatcherSpec::updateTimeDependentParams(ProcessingContext& pc)
101{
103 mTPCVDriftHelper.extractCCDBInputs(pc);
104 auto const& raw = pc.inputs().get<const char*>("corrMap");
105 mTPCCorrMaps = &o2::gpu::TPCFastTransformPOD::get(raw);
106 float lumiCTP = mRequestCTPLumi ? pc.inputs().get<float>("lumiCTP") : 0;
107 static bool initOnceDone = false;
108 if (!initOnceDone) { // this params need to be queried only once
109 const auto bcs = o2::base::GRPGeomHelper::instance().getGRPLHCIF()->getBunchFilling().getFilledBCs();
110 for (auto bc : bcs) {
112 }
113 initOnceDone = true;
114 // put here init-once stuff
115 }
116 mMatcher.setTPCCorrMaps(mTPCCorrMaps, lumiCTP);
117 if (mTPCVDriftHelper.isUpdated()) {
118 LOGP(info, "Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}",
119 mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift,
120 mTPCVDriftHelper.getVDriftObject().timeOffsetCorr, mTPCVDriftHelper.getVDriftObject().refTimeOffset,
121 mTPCVDriftHelper.getSourceName());
122 mMatcher.setTPCVDrift(mTPCVDriftHelper.getVDriftObject());
123 mTPCVDriftHelper.acknowledgeUpdate();
124 }
125}
126
128{
130 return;
131 }
132 if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) {
133 return;
134 }
135}
136
138{
139 mTimer.Start(false);
140
141 RecoContainer recoData;
142 recoData.collectData(pc, *mDataRequest.get());
143 updateTimeDependentParams(pc);
144 auto creationTime = pc.services().get<o2::framework::TimingInfo>().creation;
145
146 LOG(debug) << "isTrackSourceLoaded: TPC -> " << recoData.isTrackSourceLoaded(o2::dataformats::GlobalTrackID::Source::TPC);
147 LOG(debug) << "isTrackSourceLoaded: ITSTPC -> " << recoData.isTrackSourceLoaded(o2::dataformats::GlobalTrackID::Source::ITSTPC);
148 LOG(debug) << "isTrackSourceLoaded: TPCTRD -> " << recoData.isTrackSourceLoaded(o2::dataformats::GlobalTrackID::Source::TPCTRD);
149 LOG(debug) << "isTrackSourceLoaded: ITSTPCTRD -> " << recoData.isTrackSourceLoaded(o2::dataformats::GlobalTrackID::Source::ITSTPCTRD);
150
155 uint32_t ss = o2::globaltracking::getSubSpec(mStrict ? o2::globaltracking::MatchingType::Strict : o2::globaltracking::MatchingType::Standard);
156 mMatcher.setFIT(mUseFIT);
157
158 mMatcher.setTS(creationTime);
159
160 mMatcher.run(recoData, pc.services().get<o2::framework::TimingInfo>().firstTForbit);
161 static pmr::vector<o2::MCCompLabel> dummyMCLab;
162
163 if (isTPCused) {
164 auto& mtcInfo = pc.outputs().make<std::vector<o2::dataformats::MatchInfoTOF>>(Output{o2::header::gDataOriginTOF, "MTC_TPC", ss});
165 auto& mclabels = mUseMC ? pc.outputs().make<std::vector<o2::MCCompLabel>>(Output{o2::header::gDataOriginTOF, "MCMTC_TPC", ss}) : dummyMCLab;
166 auto& tracksTPCTOF = pc.outputs().make<std::vector<o2::dataformats::TrackTPCTOF>>(OutputRef{"tpctofTracks", ss});
168 LOG(debug) << (mDoTPCRefit ? "Refitting " : "Shifting Z for ") << nmatch << " matched TPC tracks with TOF time info";
169 mMatcher.makeConstrainedTPCTracks(mtcInfo, mclabels, tracksTPCTOF);
170 }
171
172 if (isITSTPCused) {
174 if (mUseMC) {
176 }
177 }
178
179 if (isTPCTRDused) {
181 if (mUseMC) {
183 }
184 }
185
186 if (isITSTPCTRDused) {
188 if (mUseMC) {
190 }
191 }
192
193 // TODO: TRD-matched tracks
194 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "CALIBDATA", 0}, mMatcher.getCalibVector());
195
196 if (mPushMatchable) {
197 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_0", 0}, mMatcher.getMatchedTracksPair(0));
198 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_1", 0}, mMatcher.getMatchedTracksPair(1));
199 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_2", 0}, mMatcher.getMatchedTracksPair(2));
200 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_3", 0}, mMatcher.getMatchedTracksPair(3));
201 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_4", 0}, mMatcher.getMatchedTracksPair(4));
202 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_5", 0}, mMatcher.getMatchedTracksPair(5));
203 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_6", 0}, mMatcher.getMatchedTracksPair(6));
204 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_7", 0}, mMatcher.getMatchedTracksPair(7));
205 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_8", 0}, mMatcher.getMatchedTracksPair(8));
206 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_9", 0}, mMatcher.getMatchedTracksPair(9));
207 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_10", 0}, mMatcher.getMatchedTracksPair(10));
208 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_11", 0}, mMatcher.getMatchedTracksPair(11));
209 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_12", 0}, mMatcher.getMatchedTracksPair(12));
210 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_13", 0}, mMatcher.getMatchedTracksPair(13));
211 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_14", 0}, mMatcher.getMatchedTracksPair(14));
212 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_15", 0}, mMatcher.getMatchedTracksPair(15));
213 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_16", 0}, mMatcher.getMatchedTracksPair(16));
214 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_17", 0}, mMatcher.getMatchedTracksPair(17));
215 }
216
217 static bool first = true;
218 if (first) {
219 first = false;
220 if (pc.services().get<const o2::framework::DeviceSpec>().inputTimesliceId == 0) {
222 }
223 }
224
225 mTimer.Stop();
226}
227
229{
230 LOGF(debug, "TOF matching total timing: Cpu: %.3e Real: %.3e s in %d slots",
231 mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
232}
233
234DataProcessorSpec getTOFMatcherSpec(GID::mask_t src, bool useMC, bool useFIT, bool tpcRefit, bool strict, float extratolerancetrd, bool pushMatchable, bool requestCTPLumi, int nlanes)
235{
236 uint32_t ss = o2::globaltracking::getSubSpec(strict ? o2::globaltracking::MatchingType::Strict : o2::globaltracking::MatchingType::Standard);
237 Options opts;
238 auto dataRequest = std::make_shared<DataRequest>();
239 if (strict) {
240 dataRequest->setMatchingInputStrict();
241 }
242 dataRequest->requestTracks(src, useMC);
243 dataRequest->requestClusters(GID::getSourceMask(GID::TOF), useMC);
244 if (tpcRefit && src[GID::TPC]) {
245 dataRequest->requestClusters(GID::getSourceMask(GID::TPC), false);
246 }
247 if (useFIT) {
248 dataRequest->requestFT0RecPoints(false);
249 }
250
251 auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(false, // orbitResetTime
252 true, // GRPECS=true
253 true, // GRPLHCIF
254 true, // GRPMagField
255 true, // askMatLUT
257 dataRequest->inputs,
258 true);
259 o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs);
260 dataRequest->inputs.emplace_back("corrMap", o2::header::gDataOriginTPC, "TPCCORRMAP", 0, Lifetime::Timeframe);
261 if (requestCTPLumi) {
262 dataRequest->inputs.emplace_back("lumiCTP", o2::header::gDataOriginCTP, "LUMICTP", 0, Lifetime::Timeframe);
263 }
264 std::vector<OutputSpec> outputs;
265 if (GID::includesSource(GID::TPC, src)) {
266 outputs.emplace_back(o2::header::gDataOriginTOF, "MTC_TPC", ss, Lifetime::Timeframe);
267 outputs.emplace_back(OutputLabel{"tpctofTracks"}, o2::header::gDataOriginTOF, "TOFTRACKS_TPC", ss, Lifetime::Timeframe);
268 if (useMC) {
269 outputs.emplace_back(o2::header::gDataOriginTOF, "MCMTC_TPC", ss, Lifetime::Timeframe);
270 }
271 }
272 if (GID::includesSource(GID::ITSTPC, src)) {
273 outputs.emplace_back(o2::header::gDataOriginTOF, "MTC_ITSTPC", 0, Lifetime::Timeframe);
274 if (useMC) {
275 outputs.emplace_back(o2::header::gDataOriginTOF, "MCMTC_ITSTPC", 0, Lifetime::Timeframe);
276 }
277 }
278 if (GID::includesSource(GID::ITSTPCTRD, src)) {
279 outputs.emplace_back(o2::header::gDataOriginTOF, "MTC_ITSTPCTRD", 0, Lifetime::Timeframe);
280 if (useMC) {
281 outputs.emplace_back(o2::header::gDataOriginTOF, "MCMTC_ITSTPCTRD", 0, Lifetime::Timeframe);
282 }
283 }
284 if (GID::includesSource(GID::TPCTRD, src)) {
285 outputs.emplace_back(o2::header::gDataOriginTOF, "MTC_TPCTRD", ss, Lifetime::Timeframe);
286 if (useMC) {
287 outputs.emplace_back(o2::header::gDataOriginTOF, "MCMTC_TPCTRD", ss, Lifetime::Timeframe);
288 }
289 }
290 outputs.emplace_back(o2::header::gDataOriginTOF, "CALIBDATA", 0, Lifetime::Timeframe);
291
292 if (pushMatchable) {
293 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_0", 0, Lifetime::Timeframe);
294 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_1", 0, Lifetime::Timeframe);
295 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_2", 0, Lifetime::Timeframe);
296 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_3", 0, Lifetime::Timeframe);
297 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_4", 0, Lifetime::Timeframe);
298 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_5", 0, Lifetime::Timeframe);
299 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_6", 0, Lifetime::Timeframe);
300 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_7", 0, Lifetime::Timeframe);
301 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_8", 0, Lifetime::Timeframe);
302 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_9", 0, Lifetime::Timeframe);
303 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_10", 0, Lifetime::Timeframe);
304 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_11", 0, Lifetime::Timeframe);
305 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_12", 0, Lifetime::Timeframe);
306 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_13", 0, Lifetime::Timeframe);
307 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_14", 0, Lifetime::Timeframe);
308 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_15", 0, Lifetime::Timeframe);
309 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_16", 0, Lifetime::Timeframe);
310 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_17", 0, Lifetime::Timeframe);
311 }
312
313 return DataProcessorSpec{
314 "tof-matcher",
315 dataRequest->inputs,
316 outputs,
317 AlgorithmSpec{adaptFromTask<TOFMatcherSpec>(dataRequest, ggRequest, useMC, useFIT, tpcRefit, strict, pushMatchable, nlanes, requestCTPLumi)},
318 opts};
319}
320
321} // namespace globaltracking
322} // namespace o2
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
o2::raw::RawFileWriter * raw
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.
POD correction map.
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)
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.
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:111
void makeConstrainedTPCTracks(MtcInfo &mtcCont, MCInfo &MCCont, CTrack &trcCont)
Definition MatchTOF.h:163
std::vector< o2::MCCompLabel > & getMatchedTOFLabelsVector(trkType index)
get vector of TOF labels of matched tracks
Definition MatchTOF.h:150
void setFIT(bool value=true)
Definition MatchTOF.h:155
std::vector< o2::dataformats::CalibInfoTOF > & getCalibVector()
Definition MatchTOF.h:146
std::vector< o2::dataformats::MatchInfoTOFReco > & getMatchedTracksPair(int sec)
Definition MatchTOF.h:148
void setHighPurity(bool value=true)
print settings
Definition MatchTOF.h:100
std::vector< o2::dataformats::MatchInfoTOF > & getMatchedTrackVector(trkType index)
Definition MatchTOF.h:145
void setTS(unsigned long creationTime)
Definition MatchTOF.h:190
void setTPCCorrMaps(const o2::gpu::TPCFastTransformPOD *maph, float lumi)
Definition MatchTOF.cxx:258
void storeMatchable(bool val=true)
Definition MatchTOF.h:196
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:198
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, bool useMC, bool useFIT, bool tpcRefit, bool strict, bool pushMatchable, int lanes=1, bool requestCTPLumi=false)
static void addInteractionBC(int bc, bool fromCollisonCotext=false)
Definition Utils.cxx:52
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 gDataOriginCTP
Definition DataHeader.h:564
constexpr o2::header::DataOrigin gDataOriginTPC
Definition DataHeader.h:576
constexpr o2::header::DataOrigin gDataOriginTOF
Definition DataHeader.h:575
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
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, bool requestCTPLumi, 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)
float refTimeOffset
additive time offset reference (\mus)
float refVDrift
reference vdrift for which factor was extracted
float timeOffsetCorr
additive time offset correction (\mus)
float corrFact
drift velocity correction factor (multiplicative)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"