forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMatchCosmics.cxx
More file actions
605 lines (559 loc) · 24.3 KB
/
MatchCosmics.cxx
File metadata and controls
605 lines (559 loc) · 24.3 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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
// 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 "GlobalTracking/MatchCosmics.h"
#include "DataFormatsGlobalTracking/RecoContainer.h"
#include "DataFormatsGlobalTracking/RecoContainerCreateTracksVariadic.h"
#include "GPUO2InterfaceRefit.h"
#include "ReconstructionDataFormats/GlobalTrackAccessor.h"
#include "DataFormatsITSMFT/CompCluster.h"
#include "DataFormatsITS/TrackITS.h"
#include "DataFormatsTPC/TrackTPC.h"
#include "DataFormatsTOF/Cluster.h"
#include "DataFormatsITSMFT/ROFRecord.h"
#include "DataFormatsFT0/RecPoints.h"
#include "ReconstructionDataFormats/TrackTPCITS.h"
#include "ReconstructionDataFormats/TrackTPCTOF.h"
#include "ReconstructionDataFormats/MatchInfoTOF.h"
#include "ITStracking/IOUtils.h"
#include "ITSBase/GeometryTGeo.h"
#include "TPCBase/ParameterElectronics.h"
#include "DetectorsBase/Propagator.h"
#include "TPCReconstruction/TPCFastTransformHelperO2.h"
#include "GlobalTracking/MatchTPCITS.h"
#include "CommonConstants/GeomConstants.h"
#include "DataFormatsTPC/WorkflowHelper.h"
#include "DataFormatsTPC/VDriftCorrFact.h"
#include "CorrectionMapsHelper.h"
#include <algorithm>
#include <numeric>
using namespace o2::globaltracking;
using GTrackID = o2d::GlobalTrackID;
using MatCorrType = o2::base::Propagator::MatCorrType;
//________________________________________________________
void MatchCosmics::process(const o2::globaltracking::RecoContainer& data)
{
updateTimeDependentParams();
mRecords.clear();
mWinners.clear();
mCosmicTracks.clear();
mCosmicTracksLbl.clear();
createSeeds(data);
int ntr = mSeeds.size();
// propagate to DCA to origin
const o2::math_utils::Point3D<float> v{0., 0., 0};
for (int i = 0; i < ntr; i++) {
auto& trc = mSeeds[i];
if (!o2::base::Propagator::Instance()->propagateToDCABxByBz(v, trc, mMatchParams->maxStep, mMatchParams->matCorr)) {
trc.matchID = Reject; // reject track
}
}
// sort in time bracket lower edge
std::vector<int> sortID(ntr);
std::iota(sortID.begin(), sortID.end(), 0);
std::sort(sortID.begin(), sortID.end(), [this](int a, int b) { return mSeeds[a].tBracket.getMin() < mSeeds[b].tBracket.getMin(); });
for (int i = 0; i < ntr; i++) {
for (int j = i + 1; j < ntr; j++) {
if (checkPair(sortID[i], sortID[j]) == RejTime) {
break;
}
}
}
selectWinners();
refitWinners(data);
mTFCount++;
}
//________________________________________________________
void MatchCosmics::refitWinners(const o2::globaltracking::RecoContainer& data)
{
LOG(info) << "Refitting " << mWinners.size() << " winner matches";
int count = 0;
auto tpcTBinMUSInv = 1. / mTPCTBinMUS;
const auto& tpcClusRefs = data.getTPCTracksClusterRefs();
const auto& tpcClusShMap = data.clusterShMapTPC;
const auto& tpcClusOccMap = data.occupancyMapTPC;
std::unique_ptr<o2::gpu::GPUO2InterfaceRefit> tpcRefitter;
if (data.inputsTPCclusters) {
tpcRefitter = std::make_unique<o2::gpu::GPUO2InterfaceRefit>(&data.inputsTPCclusters->clusterIndex,
mTPCCorrMapsHelper, mBz,
tpcClusRefs.data(), 0, tpcClusShMap.data(),
tpcClusOccMap.data(), tpcClusOccMap.size(), nullptr, o2::base::Propagator::Instance());
}
const auto& itsClusters = prepareITSClusters(data);
// RS FIXME: this is probably a temporary solution, since ITS tracking over boundaries will likely change the TrackITS format
std::vector<int> itsTracksROF;
const auto& itsTracksROFRec = data.getITSTracksROFRecords();
itsTracksROF.resize(data.getITSTracks().size());
for (unsigned irf = 0, cnt = 0; irf < itsTracksROFRec.size(); irf++) {
int ntr = itsTracksROFRec[irf].getNEntries();
for (int itr = 0; itr < ntr; itr++) {
itsTracksROF[cnt++] = irf;
}
}
auto refitITSTrack = [this, &data, &itsTracksROF, &itsClusters](o2::track::TrackParCov& trFit, GTrackID gidx, float& chi2, bool inward = false) {
const auto& itsTrOrig = data.getITSTrack(gidx);
int nclRefit = 0, ncl = itsTrOrig.getNumberOfClusters(), rof = itsTracksROF[gidx.getIndex()];
const auto& itsTrackClusRefs = data.getITSTracksClusterRefs();
int clEntry = itsTrOrig.getFirstClusterEntry();
const auto propagator = o2::base::Propagator::Instance();
const auto geomITS = o2::its::GeometryTGeo::Instance();
int from = ncl - 1, to = -1, step = -1;
if (inward) {
from = 0;
to = ncl;
step = 1;
}
for (int icl = from; icl != to; icl += step) { // ITS clusters are referred in layer decreasing order
const auto& clus = itsClusters[itsTrackClusRefs[clEntry + icl]];
float alpha = geomITS->getSensorRefAlpha(clus.getSensorID()), x = clus.getX();
if (!trFit.rotate(alpha) || !propagator->propagateToX(trFit, x, propagator->getNominalBz(), this->mMatchParams->maxSnp, this->mMatchParams->maxStep, this->mMatchParams->matCorr)) {
break;
}
chi2 += trFit.getPredictedChi2(clus);
if (!trFit.update(clus)) {
break;
}
nclRefit++;
}
return nclRefit == ncl ? ncl : -1;
};
for (auto winRID : mWinners) {
const auto& rec = mRecords[winRID];
int poolEntryID[2] = {rec.id0, rec.id1};
const o2::track::TrackParCov outerLegs[2] = {data.getTrackParamOut(mSeeds[rec.id0].origID), data.getTrackParamOut(mSeeds[rec.id1].origID)};
auto tOverlap = mSeeds[rec.id0].tBracket.getOverlap(mSeeds[rec.id1].tBracket);
float t0 = tOverlap.mean(), dt = tOverlap.delta() * 0.5;
auto pnt0 = outerLegs[0].getXYZGlo(), pnt1 = outerLegs[1].getXYZGlo();
int btm = 0, top = 1;
// we fit topward from bottom
if (pnt0.Y() > pnt1.Y()) {
btm = 1;
top = 0;
}
LOG(debug) << "Winner " << count++ << " Record " << winRID << " Partners:"
<< " B: " << mSeeds[poolEntryID[btm]].origID << "/" << mSeeds[poolEntryID[btm]].origID.getSourceName()
<< " U: " << mSeeds[poolEntryID[top]].origID << "/" << mSeeds[poolEntryID[top]].origID.getSourceName()
<< " | T:" << tOverlap.asString();
float chi2 = 0;
int nclTot = 0;
// Start from bottom leg inward refit
o2::track::TrackParCov trCosm(mSeeds[poolEntryID[btm]]); // copy of the btm track
// The bottom leg needs refit only if it is an unconstrained TPC track, otherwise it is already refitted as inner param
if (mSeeds[poolEntryID[btm]].origID.getSource() == GTrackID::TPC) {
const auto& tpcTrOrig = data.getTPCTrack(mSeeds[poolEntryID[btm]].origID);
trCosm = outerLegs[btm];
trCosm.resetCovariance();
// in case of cosmics, constrain the momentum
if (!mFieldON) {
trCosm.setQ2Pt(-o2::track::kMostProbablePt);
}
int retVal = tpcRefitter->RefitTrackAsTrackParCov(trCosm, tpcTrOrig.getClusterRef(), t0 * tpcTBinMUSInv, &chi2, false, false); // inward refit, reset
if (retVal < 0) { // refit failed
LOG(debug) << "Inward refit of btm TPC track failed.";
continue;
}
nclTot += retVal;
LOG(debug) << "chi2 after btm TPC refit with " << retVal << " clusters : " << chi2 << " orig.chi2 was " << tpcTrOrig.getChi2();
} else { // just collect NClusters and chi2
// since we did not refit bottom track, we just invert its conventional q/pT in case of B=0, so that after the inversion it gets correct sign
if (!mFieldON) {
trCosm.setQ2Pt(-trCosm.getQ2Pt());
}
auto gidxListBtm = data.getSingleDetectorRefs(mSeeds[poolEntryID[btm]].origID);
if (gidxListBtm[GTrackID::TPC].isIndexSet()) {
const auto& tpcTrOrig = data.getTPCTrack(gidxListBtm[GTrackID::TPC]);
nclTot += tpcTrOrig.getNClusters();
chi2 += tpcTrOrig.getChi2();
}
if (gidxListBtm[GTrackID::ITS].isIndexSet()) {
const auto& itsTrOrig = data.getITSTrack(gidxListBtm[GTrackID::ITS]);
nclTot += itsTrOrig.getNClusters();
chi2 += itsTrOrig.getChi2();
}
}
trCosm.invert();
if (!trCosm.rotate(mSeeds[poolEntryID[top]].getAlpha()) ||
!o2::base::Propagator::Instance()->PropagateToXBxByBz(trCosm, mSeeds[poolEntryID[top]].getX(), mMatchParams->maxSnp, mMatchParams->maxStep, mMatchParams->matCorr)) {
LOG(debug) << "Rotation/propagation of btm-track to top-track frame failed.";
continue;
}
// save bottom parameter at merging point
auto trCosmBtm = trCosm;
int nclBtm = nclTot;
// Continue with top leg outward refit
auto gidxListTop = data.getSingleDetectorRefs(mSeeds[poolEntryID[top]].origID);
// is there ITS sub-track?
if (gidxListTop[GTrackID::ITS].isIndexSet()) {
auto nclfit = refitITSTrack(trCosm, gidxListTop[GTrackID::ITS], chi2, false);
if (nclfit < 0) {
continue;
}
LOG(debug) << "chi2 after top ITS refit with " << nclfit << " clusters : " << chi2 << " orig.chi2 was " << data.getITSTrack(gidxListTop[GTrackID::ITS]).getChi2();
nclTot += nclfit;
} // ITS refit
//
if (gidxListTop[GTrackID::TPC].isIndexSet()) { // outward refit in TPC
// go to TPC boundary, if needed
if (trCosm.getX() * trCosm.getX() + trCosm.getY() * trCosm.getY() <= o2::constants::geom::XTPCInnerRef * o2::constants::geom::XTPCInnerRef) {
float xtogo = 0;
if (!trCosm.getXatLabR(o2::constants::geom::XTPCInnerRef, xtogo, mBz, o2::track::DirOutward) ||
!o2::base::Propagator::Instance()->PropagateToXBxByBz(trCosm, xtogo, mMatchParams->maxSnp, mMatchParams->maxStep, mMatchParams->matCorr)) {
LOG(debug) << "Propagation to inner TPC boundary X=" << xtogo << " failed";
continue;
}
}
const auto& tpcTrOrig = data.getTPCTrack(gidxListTop[GTrackID::TPC]);
int retVal = tpcRefitter->RefitTrackAsTrackParCov(trCosm, tpcTrOrig.getClusterRef(), t0 * tpcTBinMUSInv, &chi2, true, false); // outward refit, no reset
if (retVal < 0) { // refit failed
LOG(debug) << "Outward refit of top TPC track failed.";
continue;
} // outward refit in TPC
LOG(debug) << "chi2 after top TPC refit with " << retVal << " clusters : " << chi2 << " orig.chi2 was " << tpcTrOrig.getChi2();
nclTot += retVal;
}
// inward refit of top leg for evaluation in DCA
float chi2Dummy = 0;
auto trCosmTop = outerLegs[top];
if (gidxListTop[GTrackID::TPC].isIndexSet()) { // inward refit in TPC
const auto& tpcTrOrig = data.getTPCTrack(gidxListTop[GTrackID::TPC]);
int retVal = tpcRefitter->RefitTrackAsTrackParCov(trCosmTop, tpcTrOrig.getClusterRef(), t0 * tpcTBinMUSInv, &chi2Dummy, false, true); // inward refit, reset
if (retVal < 0) { // refit failed
LOG(debug) << "Outward refit of top TPC track failed.";
continue;
} // inward refit in TPC
}
// is there ITS sub-track ?
if (gidxListTop[GTrackID::ITS].isIndexSet()) {
auto nclfit = refitITSTrack(trCosmTop, gidxListTop[GTrackID::ITS], chi2Dummy, true);
if (nclfit < 0) {
continue;
}
nclTot += nclfit;
} // ITS refit
// propagate to bottom param
if (!trCosmTop.rotate(trCosmBtm.getAlpha()) ||
!o2::base::Propagator::Instance()->PropagateToXBxByBz(trCosmTop, trCosmBtm.getX(), mMatchParams->maxSnp, mMatchParams->maxStep, mMatchParams->matCorr)) {
LOG(debug) << "Rotation/propagation of top-track to bottom-track frame failed.";
continue;
}
// calculate weighted average of 2 legs and chi2
o2::track::TrackParCov::MatrixDSym5 cov5;
float chi2Match = trCosmBtm.getPredictedChi2(trCosmTop, cov5);
if (!trCosmBtm.update(trCosmTop, cov5)) {
LOG(debug) << "Top/Bottom update failed";
continue;
}
// create final track
mCosmicTracks.emplace_back(mSeeds[poolEntryID[btm]].origID, mSeeds[poolEntryID[top]].origID, trCosmBtm, trCosmTop, chi2, chi2Match, nclTot, t0, dt);
if (mUseMC) {
o2::MCCompLabel lbl[2] = {data.getTrackMCLabel(mSeeds[poolEntryID[btm]].origID), data.getTrackMCLabel(mSeeds[poolEntryID[top]].origID)};
auto& tlb = mCosmicTracksLbl.emplace_back((nclBtm > nclTot - nclBtm ? lbl[0] : lbl[1]));
tlb.setFakeFlag(lbl[0] != lbl[1]);
}
}
LOG(info) << "Validated " << mCosmicTracks.size() << " top-bottom tracks in TF# " << mTFCount;
}
//________________________________________________________
void MatchCosmics::selectWinners()
{
// select mutually best matches
int ntr = mSeeds.size(), iter = 0, nValidated = 0;
mWinners.reserve(mRecords.size() / 2); // there are 2 records per match candidate
do {
nValidated = 0;
int nRemaining = 0;
for (int i = 0; i < ntr; i++) {
if (mSeeds[i].matchID < 0 || mRecords[mSeeds[i].matchID].next == Validated) { // either have no match or already validated
continue;
}
nRemaining++;
if (validateMatch(i)) {
mWinners.push_back(mSeeds[i].matchID);
nValidated++;
continue;
}
}
LOGF(info, "iter %d Validated %d of %d remaining matches", iter, nValidated, nRemaining);
iter++;
} while (nValidated);
}
//________________________________________________________
bool MatchCosmics::validateMatch(int partner0)
{
// make sure that the best partner of seed_i has also seed_i as a best partner
auto& matchRec = mRecords[mSeeds[partner0].matchID];
auto partner1 = matchRec.id1;
auto& patnerRec = mRecords[mSeeds[partner1].matchID];
if (patnerRec.next == Validated) { // partner1 was already validated with other partner0
return false;
}
if (patnerRec.id1 == partner0) { // mutually best
// unlink winner partner0 from all other mathes
auto next0 = matchRec.next;
while (next0 > MinusOne) {
auto& nextRec = mRecords[next0];
suppressMatch(partner0, nextRec.id1);
next0 = nextRec.next;
}
matchRec.next = Validated;
// unlink winner partner1 from all other matches
auto next1 = patnerRec.next;
while (next1 > MinusOne) {
auto& nextRec = mRecords[next1];
suppressMatch(partner1, nextRec.id1);
next1 = nextRec.next;
}
patnerRec.next = Validated;
return true;
}
return false;
}
//________________________________________________________
void MatchCosmics::suppressMatch(int partner0, int partner1)
{
// suppress reference to partner0 from partner1 match record
if (mSeeds[partner1].matchID < 0 || mRecords[mSeeds[partner1].matchID].next == Validated) {
LOG(warning) << "Attempt to remove null or validated partner match " << mSeeds[partner1].matchID;
return;
}
int topID = MinusOne, next = mSeeds[partner1].matchID;
while (next > MinusOne) {
auto& matchRec = mRecords[next];
if (matchRec.id1 == partner0) {
if (topID < 0) { // best match
mSeeds[partner1].matchID = matchRec.next; // exclude best match link
} else { // not the 1st link in the chain
mRecords[topID].next = matchRec.next;
}
return;
}
topID = next;
next = matchRec.next;
}
}
//________________________________________________________
MatchCosmics::RejFlag MatchCosmics::checkPair(int i, int j)
{
// if validated with given chi2, register match
RejFlag rej = RejOther;
auto& seed0 = mSeeds[i];
auto& seed1 = mSeeds[j];
if (seed0.matchID == Reject) {
return rej;
}
if (seed1.matchID == Reject) {
return rej;
}
LOG(debug) << "Seed " << i << " [" << seed0.tBracket.getMin() << " : " << seed0.tBracket.getMax() << "] | "
<< "Seed " << j << " [" << seed1.tBracket.getMin() << " : " << seed1.tBracket.getMax() << "] | ";
LOG(debug) << seed0.origID << " | " << seed0.o2::track::TrackPar::asString();
LOG(debug) << seed1.origID << " | " << seed1.o2::track::TrackPar::asString();
if (seed1.tBracket > seed0.tBracket) {
return (rej = RejTime); // since the brackets are sorted in tmin, all following tbj will also exceed tbi
}
float chi2 = 1.e9f;
// check
// 1) crude check on tgl and q/pt (if B!=0). Note: back-to-back tracks will have mutually params (see TrackPar::invertParam)
while (1) {
auto dTgl = seed0.getTgl() + seed1.getTgl();
if (dTgl * dTgl > (mMatchParams->systSigma2[o2::track::kTgl] + seed0.getSigmaTgl2() + seed1.getSigmaTgl2()) * mMatchParams->crudeNSigma2Cut[o2::track::kTgl]) {
rej = RejTgl;
break;
}
if (mFieldON) {
auto dQ2Pt = seed0.getQ2Pt() + seed1.getQ2Pt();
if (dQ2Pt * dQ2Pt > (mMatchParams->systSigma2[o2::track::kQ2Pt] + seed0.getSigma1Pt2() + seed1.getSigma1Pt2()) * mMatchParams->crudeNSigma2Cut[o2::track::kQ2Pt]) {
rej = RejQ2Pt;
break;
}
}
o2::track::TrackParCov seed1Inv = seed1;
seed1Inv.invert();
for (int i = 0; i < o2::track::kNParams; i++) { // add systematic error
seed1Inv.updateCov(mMatchParams->systSigma2[i], o2::track::DiagMap[i]);
}
if (!seed1Inv.rotate(seed0.getAlpha()) ||
!o2::base::Propagator::Instance()->PropagateToXBxByBz(seed1Inv, seed0.getX(), mMatchParams->maxSnp, mMatchParams->maxStep, mMatchParams->matCorr)) {
rej = RejProp;
break;
}
auto dSnp = seed0.getSnp() - seed1Inv.getSnp();
if (dSnp * dSnp > (seed0.getSigmaSnp2() + seed1Inv.getSigmaSnp2()) * mMatchParams->crudeNSigma2Cut[o2::track::kSnp]) {
rej = RejSnp;
break;
}
auto dY = seed0.getY() - seed1Inv.getY();
if (dY * dY > (seed0.getSigmaY2() + seed1Inv.getSigmaY2()) * mMatchParams->crudeNSigma2Cut[o2::track::kY]) {
rej = RejY;
break;
}
bool ignoreZ = seed0.origID.getSource() == o2d::GlobalTrackID::TPC || seed1.origID.getSource() == o2d::GlobalTrackID::TPC;
if (!ignoreZ) { // cut on Z makes no sense for TPC only tracks
auto dZ = seed0.getZ() - seed1Inv.getZ();
if (dZ * dZ > (seed0.getSigmaZ2() + seed1Inv.getSigmaZ2()) * mMatchParams->crudeNSigma2Cut[o2::track::kZ]) {
rej = RejZ;
break;
}
} else { // inflate Z error
seed1Inv.setCov(250. * 250., o2::track::DiagMap[o2::track::kZ]);
seed1Inv.setCov(0., o2::track::CovarMap[o2::track::kZ][o2::track::kY]); // set all correlation terms for Z error to 0
seed1Inv.setCov(0., o2::track::CovarMap[o2::track::kZ][o2::track::kSnp]);
seed1Inv.setCov(0., o2::track::CovarMap[o2::track::kZ][o2::track::kTgl]);
seed1Inv.setCov(0., o2::track::CovarMap[o2::track::kZ][o2::track::kQ2Pt]);
}
// calculate chi2 (expensive)
chi2 = seed0.getPredictedChi2(seed1Inv);
if (chi2 > mMatchParams->crudeChi2Cut) {
rej = RejChi2;
break;
}
rej = Accept;
registerMatch(i, j, chi2);
registerMatch(j, i, chi2); // the reverse reference can be also done in a separate loop
LOG(debug) << "Chi2 = " << chi2 << " NMatches " << mRecords.size();
break;
}
#ifdef _ALLOW_DEBUG_TREES_
if (mDBGOut && ((rej == Accept && isDebugFlag(MatchTreeAccOnly)) || isDebugFlag(MatchTreeAll))) {
auto seed1I = seed1;
seed1I.invert();
if (seed1I.rotate(seed0.getAlpha()) && o2::base::Propagator::Instance()->PropagateToXBxByBz(seed1I, seed0.getX(), mMatchParams->maxSnp, mMatchParams->maxStep, mMatchParams->matCorr)) {
int rejI = int(rej);
(*mDBGOut) << "match"
<< "tf=" << mTFCount << "seed0=" << seed0 << "seed1=" << seed1I << "chi2Match=" << chi2 << "rej=" << rejI << "\n";
}
}
#endif
return rej;
}
//________________________________________________________
void MatchCosmics::registerMatch(int i, int j, float chi2)
{
/// register track index j as a match for track index i
int newRef = mRecords.size();
auto& matchRec = mRecords.emplace_back(MatchRecord{i, j, chi2, MinusOne});
auto* best = &mSeeds[i].matchID;
while (*best > MinusOne) {
auto& oldMatchRec = mRecords[*best];
if (oldMatchRec.chi2 > chi2) { // insert new match in front of the old one
matchRec.next = *best; // new record will refer to the one it is superseding
*best = newRef; // the reference on the superseded record should now refer to new one
break;
}
best = &oldMatchRec.next;
}
if (matchRec.next == MinusOne) { // did not supersed any other record
*best = newRef;
}
}
//________________________________________________________
void MatchCosmics::createSeeds(const o2::globaltracking::RecoContainer& data)
{
// Scan all inputs and create seeding tracks
mSeeds.clear();
auto creator = [this](auto& _tr, GTrackID _origID, float t0, float terr) {
if constexpr (std::is_base_of_v<o2::track::TrackParCov, std::decay_t<decltype(_tr)>>) {
if (std::abs(_tr.getQ2Pt()) > this->mQ2PtCutoff) {
return true;
}
if constexpr (isTPCTrack<decltype(_tr)>()) {
if (!this->mMatchParams->allowTPCOnly) {
return true;
}
// unconstrained TPC track, with t0 = TrackTPC.getTime0+0.5*(DeltaFwd-DeltaBwd) and terr = 0.5*(DeltaFwd+DeltaBwd) in TimeBins
t0 *= this->mTPCTBinMUS;
terr *= this->mTPCTBinMUS;
} else if (isITSTrack<decltype(_tr)>()) {
t0 += 0.5 * this->mITSROFrameLengthMUS; // time 0 is supplied as beginning of ROF in \mus
terr *= this->mITSROFrameLengthMUS; // error is supplied a half-ROF duration, convert to \mus
} else { // all other tracks are provided with time and its gaussian error in \mus
terr *= this->mMatchParams->nSigmaTError;
}
terr += this->mMatchParams->timeToleranceMUS;
mSeeds.emplace_back(TrackSeed{_tr, {t0 - terr, t0 + terr}, _origID, MinusOne});
return true;
} else {
return false;
}
};
data.createTracksVariadic(creator);
LOG(info) << "collected " << mSeeds.size() << " seeds";
}
//________________________________________________________
void MatchCosmics::updateTimeDependentParams()
{
///< update parameters depending on time (once per TF)
auto& elParam = o2::tpc::ParameterElectronics::Instance();
mTPCTBinMUS = elParam.ZbinWidth; // TPC bin in microseconds
mBz = o2::base::Propagator::Instance()->getNominalBz();
mFieldON = std::abs(mBz) > 0.01;
mQ2PtCutoff = 1.f / std::max(0.05f, mMatchParams->minSeedPt);
if (mFieldON) {
mQ2PtCutoff *= 5.00668 / std::abs(mBz);
} else {
mQ2PtCutoff = 1e9;
}
}
//________________________________________________________
void MatchCosmics::init()
{
mMatchParams = &o2::globaltracking::MatchCosmicsParams::Instance();
#ifdef _ALLOW_DEBUG_TREES_COSM
// debug streamer
if (mDBGFlags) {
mDBGOut = std::make_unique<o2::utils::TreeStreamRedirector>(mDebugTreeFileName.data(), "recreate");
}
#endif
}
//________________________________________________________
std::vector<o2::BaseCluster<float>> MatchCosmics::prepareITSClusters(const o2::globaltracking::RecoContainer& data) const
{
std::vector<o2::BaseCluster<float>> itscl;
const auto& clusITS = data.getITSClusters();
if (clusITS.size()) {
const auto& patterns = data.getITSClustersPatterns();
itscl.reserve(clusITS.size());
auto pattIt = patterns.begin();
o2::its::ioutils::convertCompactClusters(clusITS, pattIt, itscl, mITSDict);
}
return std::move(itscl);
}
//______________________________________________
void MatchCosmics::end()
{
#ifdef _ALLOW_DEBUG_TREES_COSM
mDBGOut.reset();
#endif
}
#ifdef _ALLOW_DEBUG_TREES_
//______________________________________________
void MatchCosmics::setDebugFlag(UInt_t flag, bool on)
{
///< set debug stream flag
if (on) {
mDBGFlags |= flag;
} else {
mDBGFlags &= ~flag;
}
}
//______________________________________________
void MatchCosmics::setTPCVDrift(const o2::tpc::VDriftCorrFact& v)
{
mTPCVDrift = v.refVDrift * v.corrFact;
mTPCVDriftCorrFact = v.corrFact;
mTPCVDriftRef = v.refVDrift;
mTPCDriftTimeOffset = v.getTimeOffset();
}
//______________________________________________
void MatchCosmics::setTPCCorrMaps(o2::gpu::CorrectionMapsHelper* maph)
{
mTPCCorrMapsHelper = maph;
}
#endif