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 <TMap.h>
17#include <TObjString.h>
18#include "TStopwatch.h"
25#include "Framework/Task.h"
29#include "TPCFastTransformPOD.h"
30
31// from Tracks
40
41// from TOF
45#include "TOFBase/Utils.h"
46
47using namespace o2::framework;
48// using MCLabelsTr = gsl::span<const o2::MCCompLabel>;
49// using GID = o2::dataformats::GlobalTrackID;
50// using DetID = o2::detectors::DetID;
51
53using MatchOutputType = std::vector<o2::dataformats::MatchInfoTOF>;
55
56namespace o2
57{
58namespace globaltracking
59{
60
61class TOFMatcherSpec : public Task
62{
63 public:
64 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) {}
65 ~TOFMatcherSpec() override = default;
66 void init(InitContext& ic) final;
67 void run(ProcessingContext& pc) final;
69 void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) final;
70
71 private:
72 void updateTimeDependentParams(ProcessingContext& pc);
73 void storeConfigs(ProcessingContext& pc);
74 std::shared_ptr<DataRequest> mDataRequest;
75 std::shared_ptr<o2::base::GRPGeomRequest> mGGCCDBRequest;
76 o2::tpc::VDriftHelper mTPCVDriftHelper{};
77 const o2::gpu::TPCFastTransformPOD* mTPCCorrMaps = nullptr;
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 bool mRequestCTPLumi = false;
86 MatchTOF mMatcher;
87 TStopwatch mTimer;
88};
89
91{
92 mTimer.Stop();
93 mTimer.Reset();
95 if (mStrict) {
96 mMatcher.setHighPurity();
97 }
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 auto const& raw = pc.inputs().get<const char*>("corrMap");
108 mTPCCorrMaps = &o2::gpu::TPCFastTransformPOD::get(raw);
109 float lumiCTP = mRequestCTPLumi ? pc.inputs().get<float>("lumiCTP") : 0;
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 mMatcher.setTPCCorrMaps(mTPCCorrMaps, lumiCTP);
120 if (mTPCVDriftHelper.isUpdated()) {
121 LOGP(info, "Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}",
122 mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift,
123 mTPCVDriftHelper.getVDriftObject().timeOffsetCorr, mTPCVDriftHelper.getVDriftObject().refTimeOffset,
124 mTPCVDriftHelper.getSourceName());
125 mMatcher.setTPCVDrift(mTPCVDriftHelper.getVDriftObject());
126 mTPCVDriftHelper.acknowledgeUpdate();
127 }
128}
129
131{
133 return;
134 }
135 if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) {
136 return;
137 }
138}
139
141{
142 mTimer.Start(false);
143
144 RecoContainer recoData;
145 recoData.collectData(pc, *mDataRequest.get());
146 updateTimeDependentParams(pc);
147 storeConfigs(pc);
148 auto creationTime = pc.services().get<o2::framework::TimingInfo>().creation;
149
150 LOG(debug) << "isTrackSourceLoaded: TPC -> " << recoData.isTrackSourceLoaded(o2::dataformats::GlobalTrackID::Source::TPC);
151 LOG(debug) << "isTrackSourceLoaded: ITSTPC -> " << recoData.isTrackSourceLoaded(o2::dataformats::GlobalTrackID::Source::ITSTPC);
152 LOG(debug) << "isTrackSourceLoaded: TPCTRD -> " << recoData.isTrackSourceLoaded(o2::dataformats::GlobalTrackID::Source::TPCTRD);
153 LOG(debug) << "isTrackSourceLoaded: ITSTPCTRD -> " << recoData.isTrackSourceLoaded(o2::dataformats::GlobalTrackID::Source::ITSTPCTRD);
154
159 uint32_t ss = o2::globaltracking::getSubSpec(mStrict ? o2::globaltracking::MatchingType::Strict : o2::globaltracking::MatchingType::Standard);
160 mMatcher.setFIT(mUseFIT);
161
162 mMatcher.setTS(creationTime);
163
164 mMatcher.run(recoData, pc.services().get<o2::framework::TimingInfo>().firstTForbit);
165 static pmr::vector<o2::MCCompLabel> dummyMCLab;
166
167 if (isTPCused) {
168 auto& mtcInfo = pc.outputs().make<std::vector<o2::dataformats::MatchInfoTOF>>(Output{o2::header::gDataOriginTOF, "MTC_TPC", ss});
169 auto& mclabels = mUseMC ? pc.outputs().make<std::vector<o2::MCCompLabel>>(Output{o2::header::gDataOriginTOF, "MCMTC_TPC", ss}) : dummyMCLab;
170 auto& tracksTPCTOF = pc.outputs().make<std::vector<o2::dataformats::TrackTPCTOF>>(OutputRef{"tpctofTracks", ss});
172 LOG(debug) << (mDoTPCRefit ? "Refitting " : "Shifting Z for ") << nmatch << " matched TPC tracks with TOF time info";
173 mMatcher.makeConstrainedTPCTracks(mtcInfo, mclabels, tracksTPCTOF);
174 }
175
176 if (isITSTPCused) {
178 if (mUseMC) {
180 }
181 }
182
183 if (isTPCTRDused) {
185 if (mUseMC) {
187 }
188 }
189
190 if (isITSTPCTRDused) {
192 if (mUseMC) {
194 }
195 }
196
197 // TODO: TRD-matched tracks
198 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "CALIBDATA", 0}, mMatcher.getCalibVector());
199
200 if (mPushMatchable) {
201 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_0", 0}, mMatcher.getMatchedTracksPair(0));
202 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_1", 0}, mMatcher.getMatchedTracksPair(1));
203 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_2", 0}, mMatcher.getMatchedTracksPair(2));
204 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_3", 0}, mMatcher.getMatchedTracksPair(3));
205 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_4", 0}, mMatcher.getMatchedTracksPair(4));
206 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_5", 0}, mMatcher.getMatchedTracksPair(5));
207 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_6", 0}, mMatcher.getMatchedTracksPair(6));
208 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_7", 0}, mMatcher.getMatchedTracksPair(7));
209 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_8", 0}, mMatcher.getMatchedTracksPair(8));
210 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_9", 0}, mMatcher.getMatchedTracksPair(9));
211 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_10", 0}, mMatcher.getMatchedTracksPair(10));
212 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_11", 0}, mMatcher.getMatchedTracksPair(11));
213 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_12", 0}, mMatcher.getMatchedTracksPair(12));
214 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_13", 0}, mMatcher.getMatchedTracksPair(13));
215 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_14", 0}, mMatcher.getMatchedTracksPair(14));
216 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_15", 0}, mMatcher.getMatchedTracksPair(15));
217 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_16", 0}, mMatcher.getMatchedTracksPair(16));
218 pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MATCHABLES_17", 0}, mMatcher.getMatchedTracksPair(17));
219 }
220
221 mTimer.Stop();
222}
223
224void TOFMatcherSpec::storeConfigs(ProcessingContext& pc)
225{
226 static bool first = true;
227 if (first) {
228 first = false;
230 const auto& conf = MatchTOFParams::Instance();
232 TMap md;
233 md.SetOwnerKeyValue();
234 md.Add(new TObjString(conf.getName().c_str()), new TObjString(o2::conf::ConfigurableParam::asJSON(conf.getName()).c_str()));
235 pc.outputs().snapshot(Output{"META", "TOFMATCHER", 0}, md);
236 }
237 }
238}
239
241{
242 LOGF(debug, "TOF matching total timing: Cpu: %.3e Real: %.3e s in %d slots",
243 mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
244}
245
246DataProcessorSpec getTOFMatcherSpec(GID::mask_t src, bool useMC, bool useFIT, bool tpcRefit, bool strict, float extratolerancetrd, bool pushMatchable, bool requestCTPLumi, int nlanes)
247{
248 uint32_t ss = o2::globaltracking::getSubSpec(strict ? o2::globaltracking::MatchingType::Strict : o2::globaltracking::MatchingType::Standard);
249 Options opts;
250 auto dataRequest = std::make_shared<DataRequest>();
251 if (strict) {
252 dataRequest->setMatchingInputStrict();
253 }
254 dataRequest->requestTracks(src, useMC);
255 dataRequest->requestClusters(GID::getSourceMask(GID::TOF), useMC);
256 if (tpcRefit && src[GID::TPC]) {
257 dataRequest->requestClusters(GID::getSourceMask(GID::TPC), false);
258 }
259 if (useFIT) {
260 dataRequest->requestFT0RecPoints(false);
261 }
262
263 auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(false, // orbitResetTime
264 true, // GRPECS=true
265 true, // GRPLHCIF
266 true, // GRPMagField
267 true, // askMatLUT
269 dataRequest->inputs,
270 true);
271 o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs);
272 dataRequest->inputs.emplace_back("corrMap", o2::header::gDataOriginTPC, "TPCCORRMAP", 0, Lifetime::Timeframe);
273 if (requestCTPLumi) {
274 dataRequest->inputs.emplace_back("lumiCTP", o2::header::gDataOriginCTP, "LUMICTP", 0, Lifetime::Timeframe);
275 }
276 std::vector<OutputSpec> outputs;
277 if (GID::includesSource(GID::TPC, src)) {
278 outputs.emplace_back(o2::header::gDataOriginTOF, "MTC_TPC", ss, Lifetime::Timeframe);
279 outputs.emplace_back(OutputLabel{"tpctofTracks"}, o2::header::gDataOriginTOF, "TOFTRACKS_TPC", ss, Lifetime::Timeframe);
280 if (useMC) {
281 outputs.emplace_back(o2::header::gDataOriginTOF, "MCMTC_TPC", ss, Lifetime::Timeframe);
282 }
283 }
284 if (GID::includesSource(GID::ITSTPC, src)) {
285 outputs.emplace_back(o2::header::gDataOriginTOF, "MTC_ITSTPC", 0, Lifetime::Timeframe);
286 if (useMC) {
287 outputs.emplace_back(o2::header::gDataOriginTOF, "MCMTC_ITSTPC", 0, Lifetime::Timeframe);
288 }
289 }
290 if (GID::includesSource(GID::ITSTPCTRD, src)) {
291 outputs.emplace_back(o2::header::gDataOriginTOF, "MTC_ITSTPCTRD", 0, Lifetime::Timeframe);
292 if (useMC) {
293 outputs.emplace_back(o2::header::gDataOriginTOF, "MCMTC_ITSTPCTRD", 0, Lifetime::Timeframe);
294 }
295 }
296 if (GID::includesSource(GID::TPCTRD, src)) {
297 outputs.emplace_back(o2::header::gDataOriginTOF, "MTC_TPCTRD", ss, Lifetime::Timeframe);
298 if (useMC) {
299 outputs.emplace_back(o2::header::gDataOriginTOF, "MCMTC_TPCTRD", ss, Lifetime::Timeframe);
300 }
301 }
302 outputs.emplace_back(o2::header::gDataOriginTOF, "CALIBDATA", 0, Lifetime::Timeframe);
303
304 if (pushMatchable) {
305 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_0", 0, Lifetime::Timeframe);
306 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_1", 0, Lifetime::Timeframe);
307 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_2", 0, Lifetime::Timeframe);
308 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_3", 0, Lifetime::Timeframe);
309 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_4", 0, Lifetime::Timeframe);
310 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_5", 0, Lifetime::Timeframe);
311 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_6", 0, Lifetime::Timeframe);
312 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_7", 0, Lifetime::Timeframe);
313 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_8", 0, Lifetime::Timeframe);
314 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_9", 0, Lifetime::Timeframe);
315 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_10", 0, Lifetime::Timeframe);
316 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_11", 0, Lifetime::Timeframe);
317 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_12", 0, Lifetime::Timeframe);
318 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_13", 0, Lifetime::Timeframe);
319 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_14", 0, Lifetime::Timeframe);
320 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_15", 0, Lifetime::Timeframe);
321 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_16", 0, Lifetime::Timeframe);
322 outputs.emplace_back(o2::header::gDataOriginTOF, "MATCHABLES_17", 0, Lifetime::Timeframe);
323 }
324 outputs.emplace_back("META", "TOFMATCHER", 0, Lifetime::Sporadic);
325
326 return DataProcessorSpec{
327 "tof-matcher",
328 dataRequest->inputs,
329 outputs,
330 AlgorithmSpec{adaptFromTask<TOFMatcherSpec>(dataRequest, ggRequest, useMC, useFIT, tpcRefit, strict, pushMatchable, nlanes, requestCTPLumi)},
331 opts};
332}
333
334} // namespace globaltracking
335} // 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:120
static std::string asJSON(std::string const &keyOnly="")
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
size_t inputTimesliceId
The time pipelining id of this particular device.
Definition DeviceSpec.h:68
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"