Project
Loading...
Searching...
No Matches
TPCITSMatchingSpec.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 <TMap.h>
16#include <TObjString.h>
23#include "Framework/Task.h"
27#include <string>
28#include "TStopwatch.h"
49#include "Headers/DataHeader.h"
55#include "TPCFastTransformPOD.h"
56
57#ifdef ENABLE_UPGRADES
59#endif
60
61using namespace o2::framework;
63using MCLabelsTr = gsl::span<const o2::MCCompLabel>;
65
66namespace o2
67{
68namespace globaltracking
69{
70
71class TPCITSMatchingDPL : public Task
72{
73 public:
74 TPCITSMatchingDPL(std::shared_ptr<DataRequest> dr, std::shared_ptr<o2::base::GRPGeomRequest> gr,
75 bool useFT0, bool calib, bool skipTPCOnly, bool useMC, bool requestCTPLumi)
76 : mDataRequest(dr), mGGCCDBRequest(gr), mUseFT0(useFT0), mCalibMode(calib), mSkipTPCOnly(skipTPCOnly), mUseMC(useMC), mRequestCTPLumi(requestCTPLumi) {}
77 ~TPCITSMatchingDPL() override = default;
78 void init(InitContext& ic) final;
79 void run(ProcessingContext& pc) final;
81 void finaliseCCDB(framework::ConcreteDataMatcher& matcher, void* obj) final;
82
83 private:
84 void updateTimeDependentParams(ProcessingContext& pc);
85 void storeConfigs(ProcessingContext& pc);
86 std::shared_ptr<DataRequest> mDataRequest;
87 std::shared_ptr<o2::base::GRPGeomRequest> mGGCCDBRequest;
88 o2::tpc::VDriftHelper mTPCVDriftHelper{};
89 const o2::gpu::TPCFastTransformPOD* mTPCCorrMaps{};
90 o2::globaltracking::MatchTPCITS mMatching; // matching engine
91 bool mUseFT0 = false;
92 bool mCalibMode = false;
93 bool mSkipTPCOnly = false; // to use only externally constrained tracks (for test only)
94 bool mUseMC = true;
95 bool mRequestCTPLumi = false;
96 TStopwatch mTimer;
97};
98
100{
101 mTimer.Stop();
102 mTimer.Reset();
103 int lane = ic.services().get<const o2::framework::DeviceSpec>().inputTimesliceId;
104 int maxLanes = ic.services().get<const o2::framework::DeviceSpec>().maxInputTimeslices;
105 mMatching.setDebugTreeFileName(maxLanes == 1 ? "dbg_TPCITSmatch.root" : fmt::format("dbg_TPCITSmatch_{}.root", lane));
107 mMatching.setNThreads(std::max(1, ic.options().get<int>("nthreads")));
108 mMatching.setUseBCFilling(!ic.options().get<bool>("ignore-bc-check"));
109 mMatching.setDebugFlag(ic.options().get<int>("debug-tree-flags"));
110}
111
113{
114 mTimer.Start(false);
115 RecoContainer recoData;
116 recoData.collectData(pc, *mDataRequest.get());
117 updateTimeDependentParams(pc); // Make sure this is called after recoData.collectData, which may load some conditions
118 storeConfigs(pc);
119
120 static pmr::vector<o2::MCCompLabel> dummyMCLab, dummyMCLabAB;
122
123 auto& matchedTracks = pc.outputs().make<std::vector<o2::dataformats::TrackTPCITS>>(Output{"GLO", "TPCITS", 0});
124 auto& ABTrackletRefs = pc.outputs().make<std::vector<o2::itsmft::TrkClusRef>>(Output{"GLO", "TPCITSAB_REFS", 0});
125 auto& ABTrackletClusterIDs = pc.outputs().make<std::vector<int>>(Output{"GLO", "TPCITSAB_CLID", 0});
126 auto& matchLabels = mUseMC ? pc.outputs().make<std::vector<o2::MCCompLabel>>(Output{"GLO", "TPCITS_MC", 0}) : dummyMCLab;
127 auto& ABTrackletLabels = mUseMC ? pc.outputs().make<std::vector<o2::MCCompLabel>>(Output{"GLO", "TPCITSAB_MC", 0}) : dummyMCLabAB;
128 auto& calib = mCalibMode ? pc.outputs().make<std::vector<o2::dataformats::Triplet<float, float, float>>>(Output{"GLO", "TPCITS_VDTGL", 0}) : dummyCalib;
129
130 mMatching.run(recoData, matchedTracks, ABTrackletRefs, ABTrackletClusterIDs, matchLabels, ABTrackletLabels, calib);
131
132 mTimer.Stop();
133}
134
135void TPCITSMatchingDPL::storeConfigs(ProcessingContext& pc)
136{
137 static bool first = true;
138 if (first) {
139 first = false;
140 const auto& confMatch = MatchTPCITSParams::Instance();
141 const auto& confInt = ft0::InteractionTag::Instance();
145 TMap md;
146 md.SetOwnerKeyValue();
147 md.Add(new TObjString(confMatch.getName().c_str()), new TObjString(o2::conf::ConfigurableParam::asJSON(confMatch.getName()).c_str()));
148 md.Add(new TObjString(confInt.getName().c_str()), new TObjString(o2::conf::ConfigurableParam::asJSON(confInt.getName()).c_str()));
149 pc.outputs().snapshot(Output{"META", "TPCITSMATCHER", 0}, md);
150 }
151 }
152}
153
155{
156 mMatching.end();
157 LOGF(info, "TPC-ITS matching total timing: Cpu: %.3e Real: %.3e s in %d slots",
158 mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
159 mMatching.reportTiming();
160}
161
163{
165 return;
166 }
167 if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) {
168 return;
169 }
170 if (matcher == ConcreteDataMatcher("GLO", "ITSTPCPARAM", 0)) {
171 LOG(info) << "ITS-TPC Matching params updated from ccdb";
172 return;
173 }
174 if (matcher == ConcreteDataMatcher("ITS", "CLUSDICT", 0)) {
175 LOG(info) << "its cluster dictionary updated";
177 return;
178 }
179 if (matcher == ConcreteDataMatcher("ITS", "ALPIDEPARAM", 0)) {
180 LOG(info) << "ITS Alpide param updated";
182 par.printKeyValues();
183 return;
184 }
185 if (matcher == ConcreteDataMatcher("ITS", "GEOMTGEO", 0)) {
186 LOG(info) << "ITS GeometryTGeo loaded from ccdb";
188 return;
189 }
190#ifdef ENABLE_UPGRADES
191 if (matcher == ConcreteDataMatcher("IT3", "CLUSDICT", 0)) {
192 LOG(info) << "it3 cluster dictionary updated";
193 mMatching.setIT3Dictionary((const o2::its3::TopologyDictionary*)obj);
194 return;
195 }
196#endif
197}
198
199void TPCITSMatchingDPL::updateTimeDependentParams(ProcessingContext& pc)
200{
202 mTPCVDriftHelper.extractCCDBInputs(pc);
203 auto const& raw = pc.inputs().get<const char*>("corrMap");
204 mTPCCorrMaps = &o2::gpu::TPCFastTransformPOD::get(raw);
205 float lumiCTP = mRequestCTPLumi ? pc.inputs().get<float>("lumiCTP") : 0;
206
207 static bool initOnceDone = false;
208 if (!initOnceDone) { // this params need to be queried only once
209 initOnceDone = true;
211
212 // Note: ITS/CLUSDICT and ITS/ALPIDEPARAM are requested/loaded by the recocontainer
214 if (mMatching.isITSTriggered()) {
215 mMatching.setITSROFrameLengthMUS(alpParams.roFrameLengthTrig / 1.e3); // ITS ROFrame duration in \mus
216 } else {
217 mMatching.setITSROFrameLengthInBC(alpParams.roFrameLengthInBC); // ITS ROFrame duration in \mus
218 }
219 mMatching.setITSTimeBiasInBC(alpParams.roFrameBiasInBC);
220 mMatching.setSkipTPCOnly(mSkipTPCOnly);
221 mMatching.setITSTriggered(!o2::base::GRPGeomHelper::instance().getGRPECS()->isDetContinuousReadOut(o2::detectors::DetID::ITS));
222 mMatching.setNHBPerTF(o2::base::GRPGeomHelper::instance().getGRPECS()->getNHBFPerTF());
223 mMatching.setMCTruthOn(mUseMC);
224 mMatching.setUseFT0(mUseFT0);
225 mMatching.setVDriftCalib(mCalibMode);
226 if (o2::base::GRPGeomHelper::instance().getGRPECS()->getRunType() != o2::parameters::GRPECSObject::RunType::COSMICS) {
227 mMatching.setBunchFilling(o2::base::GRPGeomHelper::instance().getGRPLHCIF()->getBunchFilling());
228 } else {
229 mMatching.setCosmics(true);
230 }
231 if (pc.inputs().getPos("itsTGeo") >= 0) {
232 pc.inputs().get<o2::its::GeometryTGeo*>("itsTGeo");
233 }
234 mMatching.init();
235 // check consistency of material correction options
236 if (mMatching.getUseMatCorrFlag() == o2::base::Propagator::MatCorrType::USEMatCorrTGeo && !o2::base::GeometryManager::isGeometryLoaded()) {
237 LOGP(fatal, "USEMatCorrTGeo cannot work w/o full geometry request in the GRPGeomHelper");
238 }
239 }
240
241 mMatching.setTPCCorrMaps(mTPCCorrMaps, lumiCTP);
242
243 if (mTPCVDriftHelper.isUpdated()) {
244 LOGP(info, "Updating TPC VDrift: corrFact {} wrt refVDrift {} and DriftTimeOffset correction {} wrt {} from source {}",
245 mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift,
246 mTPCVDriftHelper.getVDriftObject().timeOffsetCorr, mTPCVDriftHelper.getVDriftObject().refTimeOffset,
247 mTPCVDriftHelper.getSourceName());
248 mMatching.setTPCVDrift(mTPCVDriftHelper.getVDriftObject());
249 mTPCVDriftHelper.acknowledgeUpdate();
250 }
251}
252
253DataProcessorSpec getTPCITSMatchingSpec(GTrackID::mask_t src, bool useFT0, bool calib, bool skipTPCOnly, bool useGeom, bool useMC, bool requestCTPLumi)
254{
255 std::vector<OutputSpec> outputs;
256 auto dataRequest = std::make_shared<DataRequest>();
257 if ((src & GTrackID::getSourcesMask("TPC-TRD,TPC-TOF,TPC-TRD-TOF")).any()) { // preliminary stage of extended workflow ?
258 dataRequest->setMatchingInputStrict();
259 }
260 dataRequest->inputs.emplace_back("MatchParam", "GLO", "ITSTPCPARAM", 0, Lifetime::Condition, ccdbParamSpec("GLO/Config/ITSTPCParam"));
261
262 dataRequest->requestTracks(src, useMC);
263 dataRequest->requestTPCClusters(false);
264// Only ITS clusters labels are needed for the afterburner and request possibly for ITS3
265#ifdef ENABLE_UPGRADES
266 if (o2::GlobalParams::Instance().withITS3) {
267 dataRequest->requestIT3Clusters(useMC);
268 } else {
269 dataRequest->requestITSClusters(useMC);
270 }
271#else
272 dataRequest->requestITSClusters(useMC);
273#endif
274 if (useFT0) {
275 dataRequest->requestFT0RecPoints(false);
276 }
277 outputs.emplace_back("GLO", "TPCITS", 0, Lifetime::Timeframe);
278 outputs.emplace_back("GLO", "TPCITSAB_REFS", 0, Lifetime::Timeframe); // AftetBurner ITS tracklet references (referred by GlobalTrackID::ITSAB) on cluster indices
279 outputs.emplace_back("GLO", "TPCITSAB_CLID", 0, Lifetime::Timeframe); // cluster indices of ITS tracklets attached by the AfterBurner
280
281 if (calib) {
282 outputs.emplace_back("GLO", "TPCITS_VDTGL", 0, Lifetime::Timeframe);
283 }
284
285 if (useMC) {
286 outputs.emplace_back("GLO", "TPCITS_MC", 0, Lifetime::Timeframe);
287 outputs.emplace_back("GLO", "TPCITSAB_MC", 0, Lifetime::Timeframe); // AfterBurner ITS tracklet MC
288 }
289 // Note: ITS/CLUSDICT and ITS/ALPIDEPARAM are requested/loaded by the recocontainer
290
291 auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(true, // orbitResetTime
292 true, // GRPECS=true
293 true, // GRPLHCIF
294 true, // GRPMagField
295 true, // askMatLUT
297 dataRequest->inputs,
298 true); // query only once all objects except mag.field
299 if (!useGeom) { // load ITS GeomTGeo since the full geometry is not loaded
300 ggRequest->addInput({"itsTGeo", "ITS", "GEOMTGEO", 0, Lifetime::Condition, ccdbParamSpec("ITS/Config/Geometry")}, dataRequest->inputs);
301 }
302
303 Options opts{
304 {"nthreads", VariantType::Int, 1, {"Number of afterburner threads"}},
305 {"ignore-bc-check", VariantType::Bool, false, {"Do not check match candidate against BC filling"}},
306 {"debug-tree-flags", VariantType::Int, 0, {"DebugFlagTypes bit-pattern for debug tree"}}};
307
308 o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs);
309 dataRequest->inputs.emplace_back("corrMap", o2::header::gDataOriginTPC, "TPCCORRMAP", 0, Lifetime::Timeframe);
310 if (requestCTPLumi) {
311 dataRequest->inputs.emplace_back("lumiCTP", o2::header::gDataOriginCTP, "LUMICTP", 0, Lifetime::Timeframe);
312 }
313
314 outputs.emplace_back("META", "TPCITSMATCHER", 0, Lifetime::Sporadic);
315
316 return DataProcessorSpec{
317 "itstpc-track-matcher",
318 dataRequest->inputs,
319 outputs,
320 AlgorithmSpec{adaptFromTask<TPCITSMatchingDPL>(dataRequest, ggRequest, useFT0, calib, skipTPCOnly, useMC, requestCTPLumi)},
321 opts};
322}
323
324} // namespace globaltracking
325} // namespace o2
Class of a TPC cluster in TPC-native coordinates (row, time)
Definition of the ITS/MFT clusterer settings.
Definition of the ITSMFT compact cluster.
gsl::span< const o2::MCCompLabel > MCLabelsTr
Wrapper container for different reconstructed object types.
Definition of the ITSMFT cluster.
Definition of the ClusterTopology class.
Definition of the Names Generator class.
Definition of the GeometryManager class.
Definition of the BuildTopologyDictionary class for ITS3.
o2::raw::RawFileWriter * raw
Header of the AggregatedRunInfo struct.
Helper for geometry and GRP related CCDB requests.
Definition of the GeometryTGeo class.
Definition of the ITSMFT ROFrame (trigger) record.
Definition of a container to keep Monte Carlo truth external to simulation objects.
Configurable params for TPC ITS matching.
Class to perform TPC ITS matching.
POD correction map.
Definition of the ITS track.
Result of refitting TPC-ITS matched track.
Helper class to extract VDrift from different sources.
Helper class to obtain TPC clusters / digits / labels from DPL.
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="")
static mask_t getSourcesMask(const std::string_view srcList)
static constexpr ID ITS
Definition DetID.h:63
void snapshot(const Output &spec, T const &object)
decltype(auto) make(const Output &spec, Args... args)
ServiceRegistryRef services()
Definition InitContext.h:34
ConfigParamRegistry const & options()
Definition InitContext.h:33
int getPos(const char *name) const
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 setDebugTreeFileName(std::string name)
get the name of output debug file
void reportTiming()
clear results of previous event reco
void setITSROFrameLengthMUS(float fums)
set ITS ROFrame duration in BC (continuous mode only)
void setTPCVDrift(const o2::tpc::VDriftCorrFact &v)
void setNHBPerTF(int n)
ITS readout mode.
void setTPCCorrMaps(const o2::gpu::TPCFastTransformPOD *maph, float lumi)
print settings
void setMCTruthOn(bool v)
request VDrift calibration
void run(const o2::globaltracking::RecoContainer &inp, pmr::vector< o2::dataformats::TrackTPCITS > &matchedTracks, pmr::vector< o2::itsmft::TrkClusRef > &ABTrackletRefs, pmr::vector< int > &ABTrackletClusterIDs, pmr::vector< o2::MCCompLabel > &matchLabels, pmr::vector< o2::MCCompLabel > &ABTrackletLabels, pmr::vector< o2::dataformats::Triplet< float, float, float > > &calib)
void setBunchFilling(const o2::BunchFilling &bf)
void setDebugFlag(UInt_t flag, bool on=true)
set the name of output debug file
void setITSDictionary(const o2::itsmft::TopologyDictionary *d)
set flag to use MC truth
void setNThreads(int n)
perform all initializations
TPCITSMatchingDPL(std::shared_ptr< DataRequest > dr, std::shared_ptr< o2::base::GRPGeomRequest > gr, bool useFT0, bool calib, bool skipTPCOnly, bool useMC, bool requestCTPLumi)
void endOfStream(framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void finaliseCCDB(framework::ConcreteDataMatcher &matcher, void *obj) final
void run(ProcessingContext &pc) final
static void adopt(GeometryTGeo *raw, bool canDelete=false)
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
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
std::vector< ConfigParamSpec > Options
framework::DataProcessorSpec getTPCITSMatchingSpec(o2::dataformats::GlobalTrackID::mask_t src, bool useFT0, bool calib, bool skipTPCOnly, bool useGeom, bool useMC, bool requestCTPLumi)
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"