forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTPCITSMatchingSpec.cxx
More file actions
319 lines (290 loc) · 14.5 KB
/
Copy pathTPCITSMatchingSpec.cxx
File metadata and controls
319 lines (290 loc) · 14.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// @file TPCITSMatchingSpec.cxx
#include <vector>
#include "GlobalTracking/MatchTPCITS.h"
#include "GlobalTracking/MatchTPCITSParams.h"
#include "DataFormatsITSMFT/TopologyDictionary.h"
#include "DataFormatsTPC/Constants.h"
#include "Framework/DataProcessorSpec.h"
#include "Framework/Task.h"
#include "Framework/DataRefUtils.h"
#include "Framework/CCDBParamSpec.h"
#include "Framework/DeviceSpec.h"
#include <string>
#include "TStopwatch.h"
#include "Framework/ConfigParamRegistry.h"
#include "GlobalTrackingWorkflow/TPCITSMatchingSpec.h"
#include "ReconstructionDataFormats/TrackTPCITS.h"
#include "SimulationDataFormat/MCCompLabel.h"
#include "SimulationDataFormat/MCTruthContainer.h"
#include "DataFormatsITS/TrackITS.h"
#include "DataFormatsITSMFT/Cluster.h"
#include "DataFormatsITSMFT/CompCluster.h"
#include "DataFormatsITSMFT/ROFRecord.h"
#include "DataFormatsTPC/TrackTPC.h"
#include "DataFormatsTPC/ClusterNative.h"
#include "DataFormatsTPC/WorkflowHelper.h"
#include "DetectorsBase/GeometryManager.h"
#include "DetectorsBase/Propagator.h"
#include "DetectorsBase/GlobalParams.h"
#include "ITSMFTBase/DPLAlpideParam.h"
#include "ITSBase/GeometryTGeo.h"
#include "GlobalTracking/MatchTPCITSParams.h"
#include "DetectorsCommonDataFormats/DetectorNameConf.h"
#include "DataFormatsParameters/GRPECSObject.h"
#include "Headers/DataHeader.h"
#include "CommonDataFormat/BunchFilling.h"
#include "DataFormatsGlobalTracking/RecoContainer.h"
#include "ITSMFTReconstruction/ClustererParam.h"
#include "DetectorsBase/GRPGeomHelper.h"
#include "TPCCalibration/VDriftHelper.h"
#include "TPCCalibration/CorrectionMapsLoader.h"
#ifdef ENABLE_UPGRADES
#include "ITS3Reconstruction/TopologyDictionary.h"
#endif
using namespace o2::framework;
using MCLabelsCl = o2::dataformats::MCTruthContainer<o2::MCCompLabel>;
using MCLabelsTr = gsl::span<const o2::MCCompLabel>;
using GTrackID = o2::dataformats::GlobalTrackID;
namespace o2
{
namespace globaltracking
{
class TPCITSMatchingDPL : public Task
{
public:
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)
: mDataRequest(dr), mGGCCDBRequest(gr), mUseFT0(useFT0), mCalibMode(calib), mSkipTPCOnly(skipTPCOnly), mUseMC(useMC)
{
mTPCCorrMapsLoader.setLumiScaleType(sclOpts.lumiType);
mTPCCorrMapsLoader.setLumiScaleMode(sclOpts.lumiMode);
mTPCCorrMapsLoader.setCheckCTPIDCConsistency(sclOpts.checkCTPIDCconsistency);
}
~TPCITSMatchingDPL() override = default;
void init(InitContext& ic) final;
void run(ProcessingContext& pc) final;
void endOfStream(framework::EndOfStreamContext& ec) final;
void finaliseCCDB(framework::ConcreteDataMatcher& matcher, void* obj) final;
private:
void updateTimeDependentParams(ProcessingContext& pc);
std::shared_ptr<DataRequest> mDataRequest;
std::shared_ptr<o2::base::GRPGeomRequest> mGGCCDBRequest;
o2::tpc::VDriftHelper mTPCVDriftHelper{};
o2::tpc::CorrectionMapsLoader mTPCCorrMapsLoader{};
o2::globaltracking::MatchTPCITS mMatching; // matching engine
bool mUseFT0 = false;
bool mCalibMode = false;
bool mSkipTPCOnly = false; // to use only externally constrained tracks (for test only)
bool mUseMC = true;
TStopwatch mTimer;
};
void TPCITSMatchingDPL::init(InitContext& ic)
{
mTimer.Stop();
mTimer.Reset();
int lane = ic.services().get<const o2::framework::DeviceSpec>().inputTimesliceId;
int maxLanes = ic.services().get<const o2::framework::DeviceSpec>().maxInputTimeslices;
mMatching.setDebugTreeFileName(maxLanes == 1 ? "dbg_TPCITSmatch.root" : fmt::format("dbg_TPCITSmatch_{}.root", lane));
o2::base::GRPGeomHelper::instance().setRequest(mGGCCDBRequest);
mMatching.setNThreads(std::max(1, ic.options().get<int>("nthreads")));
mMatching.setUseBCFilling(!ic.options().get<bool>("ignore-bc-check"));
mMatching.setDebugFlag(ic.options().get<int>("debug-tree-flags"));
mTPCCorrMapsLoader.init(ic);
}
void TPCITSMatchingDPL::run(ProcessingContext& pc)
{
mTimer.Start(false);
RecoContainer recoData;
recoData.collectData(pc, *mDataRequest.get());
updateTimeDependentParams(pc); // Make sure this is called after recoData.collectData, which may load some conditions
static pmr::vector<o2::MCCompLabel> dummyMCLab, dummyMCLabAB;
static pmr::vector<o2::dataformats::Triplet<float, float, float>> dummyCalib;
auto& matchedTracks = pc.outputs().make<std::vector<o2::dataformats::TrackTPCITS>>(Output{"GLO", "TPCITS", 0});
auto& ABTrackletRefs = pc.outputs().make<std::vector<o2::itsmft::TrkClusRef>>(Output{"GLO", "TPCITSAB_REFS", 0});
auto& ABTrackletClusterIDs = pc.outputs().make<std::vector<int>>(Output{"GLO", "TPCITSAB_CLID", 0});
auto& matchLabels = mUseMC ? pc.outputs().make<std::vector<o2::MCCompLabel>>(Output{"GLO", "TPCITS_MC", 0}) : dummyMCLab;
auto& ABTrackletLabels = mUseMC ? pc.outputs().make<std::vector<o2::MCCompLabel>>(Output{"GLO", "TPCITSAB_MC", 0}) : dummyMCLabAB;
auto& calib = mCalibMode ? pc.outputs().make<std::vector<o2::dataformats::Triplet<float, float, float>>>(Output{"GLO", "TPCITS_VDTGL", 0}) : dummyCalib;
mMatching.run(recoData, matchedTracks, ABTrackletRefs, ABTrackletClusterIDs, matchLabels, ABTrackletLabels, calib);
static bool first = true;
if (first) {
first = false;
if (pc.services().get<const o2::framework::DeviceSpec>().inputTimesliceId == 0) {
o2::conf::ConfigurableParam::write(o2::base::NameConf::getConfigOutputFileName(pc.services().get<const o2::framework::DeviceSpec>().name, MatchTPCITSParams::Instance().getName()), MatchTPCITSParams::Instance().getName());
}
}
mTimer.Stop();
}
void TPCITSMatchingDPL::endOfStream(EndOfStreamContext& ec)
{
mMatching.end();
LOGF(info, "TPC-ITS matching total timing: Cpu: %.3e Real: %.3e s in %d slots",
mTimer.CpuTime(), mTimer.RealTime(), mTimer.Counter() - 1);
mMatching.reportTiming();
}
void TPCITSMatchingDPL::finaliseCCDB(ConcreteDataMatcher& matcher, void* obj)
{
if (o2::base::GRPGeomHelper::instance().finaliseCCDB(matcher, obj)) {
return;
}
if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) {
return;
}
if (mTPCCorrMapsLoader.accountCCDBInputs(matcher, obj)) {
return;
}
if (matcher == ConcreteDataMatcher("GLO", "ITSTPCPARAM", 0)) {
LOG(info) << "ITS-TPC Matching params updated from ccdb";
return;
}
if (matcher == ConcreteDataMatcher("ITS", "CLUSDICT", 0)) {
LOG(info) << "its cluster dictionary updated";
mMatching.setITSDictionary((const o2::itsmft::TopologyDictionary*)obj);
return;
}
if (matcher == ConcreteDataMatcher("ITS", "ALPIDEPARAM", 0)) {
LOG(info) << "ITS Alpide param updated";
const auto& par = o2::itsmft::DPLAlpideParam<o2::detectors::DetID::ITS>::Instance();
par.printKeyValues();
return;
}
if (matcher == ConcreteDataMatcher("ITS", "GEOMTGEO", 0)) {
LOG(info) << "ITS GeometryTGeo loaded from ccdb";
o2::its::GeometryTGeo::adopt((o2::its::GeometryTGeo*)obj);
return;
}
#ifdef ENABLE_UPGRADES
if (matcher == ConcreteDataMatcher("IT3", "CLUSDICT", 0)) {
LOG(info) << "it3 cluster dictionary updated";
mMatching.setIT3Dictionary((const o2::its3::TopologyDictionary*)obj);
return;
}
#endif
}
void TPCITSMatchingDPL::updateTimeDependentParams(ProcessingContext& pc)
{
o2::base::GRPGeomHelper::instance().checkUpdates(pc);
mTPCVDriftHelper.extractCCDBInputs(pc);
mTPCCorrMapsLoader.extractCCDBInputs(pc);
static bool initOnceDone = false;
if (!initOnceDone) { // this params need to be queried only once
initOnceDone = true;
pc.inputs().get<o2::globaltracking::MatchTPCITSParams*>("MatchParam");
// Note: ITS/CLUSDICT and ITS/ALPIDEPARAM are requested/loaded by the recocontainer
const auto& alpParams = o2::itsmft::DPLAlpideParam<o2::detectors::DetID::ITS>::Instance();
if (mMatching.isITSTriggered()) {
mMatching.setITSROFrameLengthMUS(alpParams.roFrameLengthTrig / 1.e3); // ITS ROFrame duration in \mus
} else {
mMatching.setITSROFrameLengthInBC(alpParams.roFrameLengthInBC); // ITS ROFrame duration in \mus
}
mMatching.setITSTimeBiasInBC(alpParams.roFrameBiasInBC);
mMatching.setSkipTPCOnly(mSkipTPCOnly);
mMatching.setITSTriggered(!o2::base::GRPGeomHelper::instance().getGRPECS()->isDetContinuousReadOut(o2::detectors::DetID::ITS));
mMatching.setNHBPerTF(o2::base::GRPGeomHelper::instance().getGRPECS()->getNHBFPerTF());
mMatching.setMCTruthOn(mUseMC);
mMatching.setUseFT0(mUseFT0);
mMatching.setVDriftCalib(mCalibMode);
if (o2::base::GRPGeomHelper::instance().getGRPECS()->getRunType() != o2::parameters::GRPECSObject::RunType::COSMICS) {
mMatching.setBunchFilling(o2::base::GRPGeomHelper::instance().getGRPLHCIF()->getBunchFilling());
} else {
mMatching.setCosmics(true);
}
if (pc.inputs().getPos("itsTGeo") >= 0) {
pc.inputs().get<o2::its::GeometryTGeo*>("itsTGeo");
}
mMatching.init();
// check consistency of material correction options
if (mMatching.getUseMatCorrFlag() == o2::base::Propagator::MatCorrType::USEMatCorrTGeo && !o2::base::GeometryManager::isGeometryLoaded()) {
LOGP(fatal, "USEMatCorrTGeo cannot work w/o full geometry request in the GRPGeomHelper");
}
}
// we may have other params which need to be queried regularly
bool updateMaps = false;
if (mTPCCorrMapsLoader.isUpdated()) {
mTPCCorrMapsLoader.acknowledgeUpdate();
updateMaps = true;
}
mMatching.setTPCCorrMaps(&mTPCCorrMapsLoader);
if (mTPCVDriftHelper.isUpdated()) {
LOGP(info, "Updating TPC fast transform map with new VDrift factor of {} wrt reference {} and DriftTimeOffset correction {} wrt {} from source {}",
mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift,
mTPCVDriftHelper.getVDriftObject().timeOffsetCorr, mTPCVDriftHelper.getVDriftObject().refTimeOffset,
mTPCVDriftHelper.getSourceName());
mMatching.setTPCVDrift(mTPCVDriftHelper.getVDriftObject());
mTPCVDriftHelper.acknowledgeUpdate();
updateMaps = true;
}
if (updateMaps) {
mTPCCorrMapsLoader.updateVDrift(mTPCVDriftHelper.getVDriftObject().corrFact, mTPCVDriftHelper.getVDriftObject().refVDrift, mTPCVDriftHelper.getVDriftObject().getTimeOffset());
}
}
DataProcessorSpec getTPCITSMatchingSpec(GTrackID::mask_t src, bool useFT0, bool calib, bool skipTPCOnly, bool useGeom, bool useMC, const o2::tpc::CorrectionMapsLoaderGloOpts& sclOpts)
{
std::vector<OutputSpec> outputs;
auto dataRequest = std::make_shared<DataRequest>();
if ((src & GTrackID::getSourcesMask("TPC-TRD,TPC-TOF,TPC-TRD-TOF")).any()) { // preliminary stage of extended workflow ?
dataRequest->setMatchingInputStrict();
}
dataRequest->inputs.emplace_back("MatchParam", "GLO", "ITSTPCPARAM", 0, Lifetime::Condition, ccdbParamSpec("GLO/Config/ITSTPCParam"));
dataRequest->requestTracks(src, useMC);
dataRequest->requestTPCClusters(false);
// Only ITS clusters labels are needed for the afterburner and request possibly for ITS3
#ifdef ENABLE_UPGRADES
if (o2::GlobalParams::Instance().withITS3) {
dataRequest->requestIT3Clusters(useMC);
} else {
dataRequest->requestITSClusters(useMC);
}
#else
dataRequest->requestITSClusters(useMC);
#endif
if (useFT0) {
dataRequest->requestFT0RecPoints(false);
}
outputs.emplace_back("GLO", "TPCITS", 0, Lifetime::Timeframe);
outputs.emplace_back("GLO", "TPCITSAB_REFS", 0, Lifetime::Timeframe); // AftetBurner ITS tracklet references (referred by GlobalTrackID::ITSAB) on cluster indices
outputs.emplace_back("GLO", "TPCITSAB_CLID", 0, Lifetime::Timeframe); // cluster indices of ITS tracklets attached by the AfterBurner
if (calib) {
outputs.emplace_back("GLO", "TPCITS_VDTGL", 0, Lifetime::Timeframe);
}
if (useMC) {
outputs.emplace_back("GLO", "TPCITS_MC", 0, Lifetime::Timeframe);
outputs.emplace_back("GLO", "TPCITSAB_MC", 0, Lifetime::Timeframe); // AfterBurner ITS tracklet MC
}
// Note: ITS/CLUSDICT and ITS/ALPIDEPARAM are requested/loaded by the recocontainer
auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(true, // orbitResetTime
true, // GRPECS=true
true, // GRPLHCIF
true, // GRPMagField
true, // askMatLUT
useGeom ? o2::base::GRPGeomRequest::Aligned : o2::base::GRPGeomRequest::None, // geometry
dataRequest->inputs,
true); // query only once all objects except mag.field
if (!useGeom) { // load ITS GeomTGeo since the full geometry is not loaded
ggRequest->addInput({"itsTGeo", "ITS", "GEOMTGEO", 0, Lifetime::Condition, ccdbParamSpec("ITS/Config/Geometry")}, dataRequest->inputs);
}
Options opts{
{"nthreads", VariantType::Int, 1, {"Number of afterburner threads"}},
{"ignore-bc-check", VariantType::Bool, false, {"Do not check match candidate against BC filling"}},
{"debug-tree-flags", VariantType::Int, 0, {"DebugFlagTypes bit-pattern for debug tree"}}};
o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs);
o2::tpc::CorrectionMapsLoader::requestCCDBInputs(dataRequest->inputs, opts, sclOpts);
return DataProcessorSpec{
"itstpc-track-matcher",
dataRequest->inputs,
outputs,
AlgorithmSpec{adaptFromTask<TPCITSMatchingDPL>(dataRequest, ggRequest, sclOpts, useFT0, calib, skipTPCOnly, useMC)},
opts};
}
} // namespace globaltracking
} // namespace o2