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
21#include "Framework/Task.h"
25#include <string>
26#include "TStopwatch.h"
47#include "Headers/DataHeader.h"
54
55#ifdef ENABLE_UPGRADES
57#endif
58
59using namespace o2::framework;
61using MCLabelsTr = gsl::span<const o2::MCCompLabel>;
63
64namespace o2
65{
66namespace globaltracking
67{
68
69class TPCITSMatchingDPL : public Task
70{
71 public:
72 TPCITSMatchingDPL(std::shared_ptr<DataRequest> dr, std::shared_ptr<o2::base::GRPGeomRequest> gr, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts,
73 bool useFT0, bool calib, bool skipTPCOnly, bool useMC)
74 : mDataRequest(dr), mGGCCDBRequest(gr), mUseFT0(useFT0), mCalibMode(calib), mSkipTPCOnly(skipTPCOnly), mUseMC(useMC)
75 {
76 mTPCCorrMapsLoader.setLumiScaleType(sclOpts.lumiType);
77 mTPCCorrMapsLoader.setLumiScaleMode(sclOpts.lumiMode);
78 mTPCCorrMapsLoader.setCheckCTPIDCConsistency(sclOpts.checkCTPIDCconsistency);
79 }
80 ~TPCITSMatchingDPL() override = default;
81 void init(InitContext& ic) final;
82 void run(ProcessingContext& pc) final;
84 void finaliseCCDB(framework::ConcreteDataMatcher& matcher, void* obj) final;
85
86 private:
87 void updateTimeDependentParams(ProcessingContext& pc);
88 std::shared_ptr<DataRequest> mDataRequest;
89 std::shared_ptr<o2::base::GRPGeomRequest> mGGCCDBRequest;
90 o2::tpc::VDriftHelper mTPCVDriftHelper{};
91 o2::tpc::CorrectionMapsLoader mTPCCorrMapsLoader{};
92 o2::globaltracking::MatchTPCITS mMatching; // matching engine
93 bool mUseFT0 = false;
94 bool mCalibMode = false;
95 bool mSkipTPCOnly = false; // to use only externally constrained tracks (for test only)
96 bool mUseMC = true;
97 TStopwatch mTimer;
98};
99
101{
102 mTimer.Stop();
103 mTimer.Reset();
104 int lane = ic.services().get<const o2::framework::DeviceSpec>().inputTimesliceId;
105 int maxLanes = ic.services().get<const o2::framework::DeviceSpec>().maxInputTimeslices;
106 mMatching.setDebugTreeFileName(maxLanes == 1 ? "dbg_TPCITSmatch.root" : fmt::format("dbg_TPCITSmatch_{}.root", lane));
108 mMatching.setNThreads(std::max(1, ic.options().get<int>("nthreads")));
109 mMatching.setUseBCFilling(!ic.options().get<bool>("ignore-bc-check"));
110 mMatching.setDebugFlag(ic.options().get<int>("debug-tree-flags"));
111 mTPCCorrMapsLoader.init(ic);
112}
113
115{
116 mTimer.Start(false);
117 RecoContainer recoData;
118 recoData.collectData(pc, *mDataRequest.get());
119 updateTimeDependentParams(pc); // Make sure this is called after recoData.collectData, which may load some conditions
120
121 static pmr::vector<o2::MCCompLabel> dummyMCLab, dummyMCLabAB;
123
124 auto& matchedTracks = pc.outputs().make<std::vector<o2::dataformats::TrackTPCITS>>(Output{"GLO", "TPCITS", 0});
125 auto& ABTrackletRefs = pc.outputs().make<std::vector<o2::itsmft::TrkClusRef>>(Output{"GLO", "TPCITSAB_REFS", 0});
126 auto& ABTrackletClusterIDs = pc.outputs().make<std::vector<int>>(Output{"GLO", "TPCITSAB_CLID", 0});
127 auto& matchLabels = mUseMC ? pc.outputs().make<std::vector<o2::MCCompLabel>>(Output{"GLO", "TPCITS_MC", 0}) : dummyMCLab;
128 auto& ABTrackletLabels = mUseMC ? pc.outputs().make<std::vector<o2::MCCompLabel>>(Output{"GLO", "TPCITSAB_MC", 0}) : dummyMCLabAB;
129 auto& calib = mCalibMode ? pc.outputs().make<std::vector<o2::dataformats::Triplet<float, float, float>>>(Output{"GLO", "TPCITS_VDTGL", 0}) : dummyCalib;
130
131 mMatching.run(recoData, matchedTracks, ABTrackletRefs, ABTrackletClusterIDs, matchLabels, ABTrackletLabels, calib);
132
133 mTimer.Stop();
134}
135
137{
138 mMatching.end();
139 LOGF(info, "TPC-ITS matching total timing: Cpu: %.3e Real: %.3e s in %d slots",
140 mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
141 mMatching.reportTiming();
142}
143
145{
147 return;
148 }
149 if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) {
150 return;
151 }
152 if (mTPCCorrMapsLoader.accountCCDBInputs(matcher, obj)) {
153 return;
154 }
155 if (matcher == ConcreteDataMatcher("GLO", "ITSTPCPARAM", 0)) {
156 LOG(info) << "ITS-TPC Matching params updated from ccdb";
157 return;
158 }
159 if (matcher == ConcreteDataMatcher("ITS", "CLUSDICT", 0)) {
160 LOG(info) << "its cluster dictionary updated";
162 return;
163 }
164 if (matcher == ConcreteDataMatcher("ITS", "ALPIDEPARAM", 0)) {
165 LOG(info) << "ITS Alpide param updated";
167 par.printKeyValues();
168 return;
169 }
170 if (matcher == ConcreteDataMatcher("ITS", "GEOMTGEO", 0)) {
171 LOG(info) << "ITS GeometryTGeo loaded from ccdb";
173 return;
174 }
175#ifdef ENABLE_UPGRADES
176 if (matcher == ConcreteDataMatcher("IT3", "CLUSDICT", 0)) {
177 LOG(info) << "it3 cluster dictionary updated";
178 mMatching.setIT3Dictionary((const o2::its3::TopologyDictionary*)obj);
179 return;
180 }
181#endif
182}
183
184void TPCITSMatchingDPL::updateTimeDependentParams(ProcessingContext& pc)
185{
187 mTPCVDriftHelper.extractCCDBInputs(pc);
188 mTPCCorrMapsLoader.extractCCDBInputs(pc);
189 static bool initOnceDone = false;
190 if (!initOnceDone) { // this params need to be queried only once
191 initOnceDone = true;
193
194 // Note: ITS/CLUSDICT and ITS/ALPIDEPARAM are requested/loaded by the recocontainer
196 if (mMatching.isITSTriggered()) {
197 mMatching.setITSROFrameLengthMUS(alpParams.roFrameLengthTrig / 1.e3); // ITS ROFrame duration in \mus
198 } else {
199 mMatching.setITSROFrameLengthInBC(alpParams.roFrameLengthInBC); // ITS ROFrame duration in \mus
200 }
201 mMatching.setITSTimeBiasInBC(alpParams.roFrameBiasInBC);
202 mMatching.setSkipTPCOnly(mSkipTPCOnly);
203 mMatching.setITSTriggered(!o2::base::GRPGeomHelper::instance().getGRPECS()->isDetContinuousReadOut(o2::detectors::DetID::ITS));
204 mMatching.setNHBPerTF(o2::base::GRPGeomHelper::instance().getGRPECS()->getNHBFPerTF());
205 mMatching.setMCTruthOn(mUseMC);
206 mMatching.setUseFT0(mUseFT0);
207 mMatching.setVDriftCalib(mCalibMode);
208 if (o2::base::GRPGeomHelper::instance().getGRPECS()->getRunType() != o2::parameters::GRPECSObject::RunType::COSMICS) {
209 mMatching.setBunchFilling(o2::base::GRPGeomHelper::instance().getGRPLHCIF()->getBunchFilling());
210 } else {
211 mMatching.setCosmics(true);
212 }
213 if (pc.inputs().getPos("itsTGeo") >= 0) {
214 pc.inputs().get<o2::its::GeometryTGeo*>("itsTGeo");
215 }
216 mMatching.init();
217 // check consistency of material correction options
218 if (mMatching.getUseMatCorrFlag() == o2::base::Propagator::MatCorrType::USEMatCorrTGeo && !o2::base::GeometryManager::isGeometryLoaded()) {
219 LOGP(fatal, "USEMatCorrTGeo cannot work w/o full geometry request in the GRPGeomHelper");
220 }
221 }
222 // we may have other params which need to be queried regularly
223 bool updateMaps = false;
224 if (mTPCCorrMapsLoader.isUpdated()) {
225 mTPCCorrMapsLoader.acknowledgeUpdate();
226 updateMaps = true;
227 }
228 mMatching.setTPCCorrMaps(&mTPCCorrMapsLoader);
229
230 if (mTPCVDriftHelper.isUpdated()) {
231 LOGP(info, "Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}",
232 mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift,
233 mTPCVDriftHelper.getVDriftObject().timeOffsetCorr, mTPCVDriftHelper.getVDriftObject().refTimeOffset,
234 mTPCVDriftHelper.getSourceName());
235 mMatching.setTPCVDrift(mTPCVDriftHelper.getVDriftObject());
236 mTPCVDriftHelper.acknowledgeUpdate();
237 updateMaps = true;
238 }
239 if (updateMaps) {
240 mTPCCorrMapsLoader.updateVDrift(mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, mTPCVDriftHelper.getVDriftObject().getTimeOffset());
241 }
242}
243
244DataProcessorSpec getTPCITSMatchingSpec(GTrackID::mask_t src, bool useFT0, bool calib, bool skipTPCOnly, bool useGeom, bool useMC, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts)
245{
246 std::vector<OutputSpec> outputs;
247 auto dataRequest = std::make_shared<DataRequest>();
248 if ((src & GTrackID::getSourcesMask("TPC-TRD,TPC-TOF,TPC-TRD-TOF")).any()) { // preliminary stage of extended workflow ?
249 dataRequest->setMatchingInputStrict();
250 }
251 dataRequest->inputs.emplace_back("MatchParam", "GLO", "ITSTPCPARAM", 0, Lifetime::Condition, ccdbParamSpec("GLO/Config/ITSTPCParam"));
252
253 dataRequest->requestTracks(src, useMC);
254 dataRequest->requestTPCClusters(false);
255// Only ITS clusters labels are needed for the afterburner and request possibly for ITS3
256#ifdef ENABLE_UPGRADES
257 if (o2::GlobalParams::Instance().withITS3) {
258 dataRequest->requestIT3Clusters(useMC);
259 } else {
260 dataRequest->requestITSClusters(useMC);
261 }
262#else
263 dataRequest->requestITSClusters(useMC);
264#endif
265 if (useFT0) {
266 dataRequest->requestFT0RecPoints(false);
267 }
268 outputs.emplace_back("GLO", "TPCITS", 0, Lifetime::Timeframe);
269 outputs.emplace_back("GLO", "TPCITSAB_REFS", 0, Lifetime::Timeframe); // AftetBurner ITS tracklet references (referred by GlobalTrackID::ITSAB) on cluster indices
270 outputs.emplace_back("GLO", "TPCITSAB_CLID", 0, Lifetime::Timeframe); // cluster indices of ITS tracklets attached by the AfterBurner
271
272 if (calib) {
273 outputs.emplace_back("GLO", "TPCITS_VDTGL", 0, Lifetime::Timeframe);
274 }
275
276 if (useMC) {
277 outputs.emplace_back("GLO", "TPCITS_MC", 0, Lifetime::Timeframe);
278 outputs.emplace_back("GLO", "TPCITSAB_MC", 0, Lifetime::Timeframe); // AfterBurner ITS tracklet MC
279 }
280 // Note: ITS/CLUSDICT and ITS/ALPIDEPARAM are requested/loaded by the recocontainer
281
282 auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(true, // orbitResetTime
283 true, // GRPECS=true
284 true, // GRPLHCIF
285 true, // GRPMagField
286 true, // askMatLUT
288 dataRequest->inputs,
289 true); // query only once all objects except mag.field
290 if (!useGeom) { // load ITS GeomTGeo since the full geometry is not loaded
291 ggRequest->addInput({"itsTGeo", "ITS", "GEOMTGEO", 0, Lifetime::Condition, ccdbParamSpec("ITS/Config/Geometry")}, dataRequest->inputs);
292 }
293
294 Options opts{
295 {"nthreads", VariantType::Int, 1, {"Number of afterburner threads"}},
296 {"ignore-bc-check", VariantType::Bool, false, {"Do not check match candidate against BC filling"}},
297 {"debug-tree-flags", VariantType::Int, 0, {"DebugFlagTypes bit-pattern for debug tree"}}};
298
299 o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs);
300 o2::tpc::CorrectionMapsLoader::requestCCDBInputs(dataRequest->inputs, opts, sclOpts);
301
302 return DataProcessorSpec{
303 "itstpc-track-matcher",
304 dataRequest->inputs,
305 outputs,
306 AlgorithmSpec{adaptFromTask<TPCITSMatchingDPL>(dataRequest, ggRequest, sclOpts, useFT0, calib, skipTPCOnly, useMC)},
307 opts};
308}
309
310} // namespace globaltracking
311} // 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.
Helper class to access load maps from CCDB.
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.
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.
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 mask_t getSourcesMask(const std::string_view srcList)
static constexpr ID ITS
Definition DetID.h:63
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.
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(o2::gpu::CorrectionMapsHelper *maph)
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
void endOfStream(framework::EndOfStreamContext &ec) final
This is invoked whenever we have an EndOfStream event.
void finaliseCCDB(framework::ConcreteDataMatcher &matcher, void *obj) final
TPCITSMatchingDPL(std::shared_ptr< DataRequest > dr, std::shared_ptr< o2::base::GRPGeomRequest > gr, const o2::tpc::CorrectionMapsLoaderGloOpts &sclOpts, bool useFT0, bool calib, bool skipTPCOnly, bool useMC)
void run(ProcessingContext &pc) final
static void adopt(GeometryTGeo *raw, bool canDelete=false)
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
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
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, const o2::tpc::CorrectionMapsLoaderGloOpts &sclOpts)
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"