forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDumpTracks.cxx
More file actions
322 lines (294 loc) · 13.8 KB
/
DumpTracks.cxx
File metadata and controls
322 lines (294 loc) · 13.8 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
320
321
322
// 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.
#include <vector>
#include <TStopwatch.h>
#include "DataFormatsGlobalTracking/RecoContainer.h"
#include "DataFormatsGlobalTracking/RecoContainerCreateTracksVariadic.h"
#include "ReconstructionDataFormats/TrackTPCITS.h"
#include "ReconstructionDataFormats/GlobalTrackID.h"
#include "CommonDataFormat/BunchFilling.h"
#include "CommonUtils/NameConf.h"
#include "DataFormatsFT0/RecPoints.h"
#include "Framework/ConfigParamRegistry.h"
#include "Framework/CCDBParamSpec.h"
#include "FT0Reconstruction/InteractionTag.h"
#include "ITSMFTBase/DPLAlpideParam.h"
#include "DetectorsCommonDataFormats/DetID.h"
#include "DetectorsBase/GRPGeomHelper.h"
#include "GlobalTrackingStudy/TrackingStudy.h"
#include "TPCBase/ParameterElectronics.h"
#include "TPCBase/ParameterDetector.h"
#include "ReconstructionDataFormats/PrimaryVertex.h"
#include "CommonUtils/TreeStreamRedirector.h"
#include "ReconstructionDataFormats/VtxTrackRef.h"
#include "TPCCalibration/VDriftHelper.h"
#include "DetectorsVertexing/PVertexerParams.h"
namespace o2::trackstudy
{
using namespace o2::framework;
using DetID = o2::detectors::DetID;
using DataRequest = o2::globaltracking::DataRequest;
using PVertex = o2::dataformats::PrimaryVertex;
using V2TRef = o2::dataformats::VtxTrackRef;
using VTIndex = o2::dataformats::VtxTrackIndex;
using GTrackID = o2::dataformats::GlobalTrackID;
using TBracket = o2::math_utils::Bracketf_t;
using timeEst = o2::dataformats::TimeStampWithError<float, float>;
class DumpTracksSpec final : public Task
{
public:
DumpTracksSpec(std::shared_ptr<DataRequest> dr, std::shared_ptr<o2::base::GRPGeomRequest> gr, GTrackID::mask_t src, bool useMC)
: mDataRequest(dr), mGGCCDBRequest(gr), mTracksSrc(src), mUseMC(useMC) {}
~DumpTracksSpec() final = default;
void init(InitContext& ic) final;
void run(ProcessingContext& pc) final;
void endOfStream(EndOfStreamContext& ec) final;
void finaliseCCDB(ConcreteDataMatcher& matcher, void* obj) final;
void process(o2::globaltracking::RecoContainer& recoData);
private:
void updateTimeDependentParams(ProcessingContext& pc);
std::shared_ptr<DataRequest> mDataRequest;
std::shared_ptr<o2::base::GRPGeomRequest> mGGCCDBRequest;
bool mUseMC{false}; ///< MC flag
std::unique_ptr<o2::utils::TreeStreamRedirector> mDBGOut;
GTrackID::mask_t mTracksSrc{};
std::vector<long> mGlobalBC;
o2::tpc::VDriftHelper mTPCVDriftHelper{};
int mBCToler = 0; // tolerance in BC for globalBC selections
int mVerbose = 0;
float mITSROFrameLengthMUS = 0; ///< ITS RO frame in mus
float mMFTROFrameLengthMUS = 0; ///< MFT RO frame in mus
float mMaxTPCDriftTimeMUS = 0;
float mTPCTDriftOffset = 0.f;
float mTPCBin2MUS = 0;
};
void DumpTracksSpec::init(InitContext& ic)
{
o2::base::GRPGeomHelper::instance().setRequest(mGGCCDBRequest);
mDBGOut = std::make_unique<o2::utils::TreeStreamRedirector>("trackStudy.root", "recreate");
mBCToler = ic.options().get<int>("bc-margin");
mVerbose = ic.options().get<int>("dump-verbosity");
auto bcstr = ic.options().get<std::string>("sel-bc");
auto bctok = o2::utils::Str::tokenize(bcstr, ',');
if (bctok.empty()) {
LOG(error) << "empty BC list is provided " << bcstr;
}
for (auto& bcs : bctok) {
try {
long bcglo = std::stol(bcs);
mGlobalBC.push_back(bcglo);
LOGP(info, "adding {} to global BCs to dump", bcglo);
} catch (...) {
LOGP(fatal, "failed to extract global BC from {}", bcstr);
}
}
}
void DumpTracksSpec::run(ProcessingContext& pc)
{
o2::globaltracking::RecoContainer recoData;
recoData.collectData(pc, *mDataRequest.get()); // select tracks of needed type, with minimal cuts, the real selected will be done in the vertexer
updateTimeDependentParams(pc); // Make sure this is called after recoData.collectData, which may load some conditions
process(recoData);
}
void DumpTracksSpec::updateTimeDependentParams(ProcessingContext& pc)
{
o2::base::GRPGeomHelper::instance().checkUpdates(pc);
mTPCVDriftHelper.extractCCDBInputs(pc);
static bool initOnceDone = false;
if (!initOnceDone) { // this params need to be queried only once
initOnceDone = true;
// put here init-once stuff
const auto& alpParamsITS = o2::itsmft::DPLAlpideParam<o2::detectors::DetID::ITS>::Instance();
mITSROFrameLengthMUS = o2::base::GRPGeomHelper::instance().getGRPECS()->isDetContinuousReadOut(o2::detectors::DetID::ITS) ? alpParamsITS.roFrameLengthInBC * o2::constants::lhc::LHCBunchSpacingMUS : alpParamsITS.roFrameLengthTrig * 1.e-3;
const auto& alpParamsMFT = o2::itsmft::DPLAlpideParam<o2::detectors::DetID::MFT>::Instance();
mMFTROFrameLengthMUS = o2::base::GRPGeomHelper::instance().getGRPECS()->isDetContinuousReadOut(o2::detectors::DetID::MFT) ? alpParamsMFT.roFrameLengthInBC * o2::constants::lhc::LHCBunchSpacingMUS : alpParamsMFT.roFrameLengthTrig * 1.e-3;
LOGP(info, "VertexTrackMatcher ITSROFrameLengthMUS:{} MFTROFrameLengthMUS:{}", mITSROFrameLengthMUS, mMFTROFrameLengthMUS);
}
// we may have other params which need to be queried regularly
// VDrift may change from time to time
if (mTPCVDriftHelper.isUpdated()) {
auto& elParam = o2::tpc::ParameterElectronics::Instance();
auto& detParam = o2::tpc::ParameterDetector::Instance();
mTPCBin2MUS = elParam.ZbinWidth;
auto& vd = mTPCVDriftHelper.getVDriftObject();
mMaxTPCDriftTimeMUS = detParam.TPClength / (vd.refVDrift * vd.corrFact);
mTPCTDriftOffset = vd.getTimeOffset();
}
}
void DumpTracksSpec::process(o2::globaltracking::RecoContainer& recoData)
{
std::vector<TBracket> selBCTF;
auto irMin = recoData.startIR;
auto irMax = irMin + o2::base::GRPGeomHelper::instance().getNHBFPerTF() * o2::constants::lhc::LHCMaxBunches;
float tBCErr = mBCToler * o2::constants::lhc::LHCBunchSpacingMUS;
LOGP(info, "TF dump for {}:{}", irMin.asString(), irMax.asString());
for (const auto& bc : mGlobalBC) {
if (bc >= irMin.toLong() && bc < irMax.toLong()) {
o2::InteractionRecord bcir(bc % o2::constants::lhc::LHCMaxBunches, bc / o2::constants::lhc::LHCMaxBunches);
float t = (bc - irMin.toLong()) * o2::constants::lhc::LHCBunchSpacingMUS;
LOGP(info, "Selected BC {}({}) -> {}({}) : {}({}) mus", bc, bcir.asString(),
t - tBCErr, (bcir - mBCToler).asString(),
t + tBCErr, (bcir + mBCToler).asString());
selBCTF.emplace_back(t - tBCErr, t + tBCErr);
}
}
if (selBCTF.empty()) {
LOGP(info, "No selections for {}:{}", irMin.asString(), irMax.asString());
return;
}
auto pvvec = recoData.getPrimaryVertices();
auto trackIndex = recoData.getPrimaryVertexMatchedTracks(); // Global ID's for associated tracks
auto vtxRefs = recoData.getPrimaryVertexMatchedTrackRefs(); // references from vertex to these track IDs
float itsBias = 0.5 * mITSROFrameLengthMUS + o2::itsmft::DPLAlpideParam<o2::detectors::DetID::ITS>::Instance().roFrameBiasInBC * o2::constants::lhc::LHCBunchSpacingNS * 1e-3; // ITS time is supplied in \mus as beginning of ROF
float mftBias = 0.5 * mMFTROFrameLengthMUS + o2::itsmft::DPLAlpideParam<o2::detectors::DetID::MFT>::Instance().roFrameBiasInBC * o2::constants::lhc::LHCBunchSpacingNS * 1e-3; // MFT time is supplied in \mus as beginning of ROF
GTrackID::Source prevSrc = GTrackID::Source(-1);
auto creator = [this, &selBCTF, itsBias, mftBias, &recoData, &prevSrc](auto& _tr, GTrackID _origID, float t0, float terr) {
const auto& PVParams = o2::vertexing::PVertexerParams::Instance();
if constexpr (isTPCTrack<decltype(_tr)>()) {
// unconstrained TPC track, with t0 = TrackTPC.getTime0+0.5*(DeltaFwd-DeltaBwd) and terr = 0.5*(DeltaFwd+DeltaBwd) in TimeBins
t0 *= this->mTPCBin2MUS;
t0 -= this->mTPCTDriftOffset;
terr *= this->mTPCBin2MUS;
} else if constexpr (isITSTrack<decltype(_tr)>()) {
t0 += itsBias;
terr *= this->mITSROFrameLengthMUS; // error is supplied as a half-ROF duration, convert to \mus
} else if constexpr (isMFTTrack<decltype(_tr)>()) { // Same for MFT
t0 += mftBias;
terr *= this->mMFTROFrameLengthMUS;
} else if constexpr (!(isMCHTrack<decltype(_tr)>() || isGlobalFwdTrack<decltype(_tr)>())) {
// for all other tracks the time is in \mus with gaussian error
terr *= PVParams.nSigmaTimeTrack; // gaussian errors must be scaled by requested n-sigma
}
terr += PVParams.timeMarginTrackTime;
TBracket tb{t0 - terr, t0 + terr};
for (const auto& stb : selBCTF) {
if (tb.isOutside(stb)) {
return false;
}
}
auto curSrc = GTrackID::Source(_origID.getSource());
if (prevSrc != curSrc) {
prevSrc = curSrc;
LOGP(info, "Dumping {} tracks", GTrackID::getSourceName(prevSrc));
}
std::string outs;
if constexpr (isGlobalFwdTrack<decltype(_tr)>() || isMFTTrack<decltype(_tr)>() || isMCHTrack<decltype(_tr)>() || isMIDTrack<decltype(_tr)>()) {
outs = fmt::format("{:>15} {:8.3f}/{:5.3f} -> ", _origID.asString(), t0, terr);
} else {
outs = fmt::format("{:>15} {:8.3f}/{:5.3f} |{}| -> ", _origID.asString(), t0, terr, ((o2::track::TrackPar)_tr).asString());
}
// contributions
auto refs = recoData.getSingleDetectorRefs(_origID);
for (auto r : refs) {
if (r.isSourceSet()) {
outs += fmt::format(" {}", r.asString());
}
}
LOG(info) << outs;
return false; // allow redundancy
};
recoData.createTracksVariadic(creator);
// print matching vertices
int pvcnt = 0;
for (const auto& pv : pvvec) {
TBracket pbv{pv.getIRMin().differenceInBCMUS(irMin), pv.getIRMax().differenceInBCMUS(irMin)};
for (const auto& stb : selBCTF) {
if (!stb.isOutside(pbv)) {
LOG(info) << "#" << pvcnt << " " << pv;
LOG(info) << "References: " << vtxRefs[pvcnt];
for (int is = 0; is < VTIndex::NSources; is++) {
int ncontrib = 0, nambig = 0;
int idMin = vtxRefs[pvcnt].getFirstEntryOfSource(is), idMax = idMin + vtxRefs[pvcnt].getEntriesOfSource(is);
for (int i = idMin; i < idMax; i++) {
if (trackIndex[i].isPVContributor()) {
ncontrib++;
} else if (trackIndex[i].isAmbiguous()) {
nambig++;
}
}
if (vtxRefs[pvcnt].getEntriesOfSource(is)) {
LOGP(info, "{} : total attached: {}, contributors: {}, ambiguous: {}", VTIndex::getSourceName(is), vtxRefs[pvcnt].getEntriesOfSource(is), ncontrib, nambig);
}
if (mVerbose < 2) {
continue;
}
std::string trIDs;
int cntT = 0;
for (int i = idMin; i < idMax; i++) {
if (mVerbose > 2 || trackIndex[i].isPVContributor()) {
trIDs += trackIndex[i].asString() + " ";
if (!((++cntT) % 15)) {
LOG(info) << trIDs;
trIDs = "";
}
}
}
if (!trIDs.empty()) {
LOG(info) << trIDs;
}
}
}
pvcnt++;
}
}
}
void DumpTracksSpec::endOfStream(EndOfStreamContext& ec)
{
mDBGOut.reset();
}
void DumpTracksSpec::finaliseCCDB(ConcreteDataMatcher& matcher, void* obj)
{
if (o2::base::GRPGeomHelper::instance().finaliseCCDB(matcher, obj)) {
return;
}
if (mTPCVDriftHelper.accountCCDBInputs(matcher, 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("MFT", "ALPIDEPARAM", 0)) {
LOG(info) << "MFT Alpide param updated";
const auto& par = o2::itsmft::DPLAlpideParam<o2::detectors::DetID::MFT>::Instance();
par.printKeyValues();
return;
}
}
DataProcessorSpec getDumpTracksSpec(GTrackID::mask_t srcTracks, GTrackID::mask_t srcClusters, bool useMC)
{
std::vector<OutputSpec> outputs;
auto dataRequest = std::make_shared<DataRequest>();
dataRequest->requestTracks(srcTracks, useMC);
dataRequest->requestClusters(srcClusters, useMC);
dataRequest->requestPrimaryVertices(useMC);
auto ggRequest = std::make_shared<o2::base::GRPGeomRequest>(false, // orbitResetTime
true, // GRPECS=true
false, // GRPLHCIF
false, // GRPMagField
false, // askMatLUT
o2::base::GRPGeomRequest::None, // geometry
dataRequest->inputs,
true);
o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs);
return DataProcessorSpec{
"tracks-dump",
dataRequest->inputs,
outputs,
AlgorithmSpec{adaptFromTask<DumpTracksSpec>(dataRequest, ggRequest, srcTracks, useMC)},
Options{
{"sel-bc", VariantType::String, "", {"Dump tracks compatible with global BC list"}},
{"bc-margin", VariantType::Int, 0, {"Apply margin in BC to selected global BCs list"}},
{"dump-verbosity", VariantType::Int, 0, {"Dump verbosity level"}}}};
}
} // namespace o2::trackstudy