forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatchTOF.cxx
More file actions
2173 lines (1893 loc) · 102 KB
/
MatchTOF.cxx
File metadata and controls
2173 lines (1893 loc) · 102 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
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// 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 <TTree.h>
#include <cassert>
#include <fairlogger/Logger.h>
#include "Field/MagneticField.h"
#include "Field/MagFieldFast.h"
#include "TOFBase/Geo.h"
#include "SimulationDataFormat/MCTruthContainer.h"
#include "DetectorsBase/Propagator.h"
#include "DataFormatsTPC/VDriftCorrFact.h"
#include "MathUtils/Cartesian.h"
#include "MathUtils/Utils.h"
#include "CommonConstants/MathConstants.h"
#include "CommonConstants/PhysicsConstants.h"
#include "CommonConstants/GeomConstants.h"
#include "DetectorsBase/GeometryManager.h"
#include <Math/SMatrix.h>
#include <Math/SVector.h>
#include <TFile.h>
#include <TGeoGlobalMagField.h>
#include "DataFormatsParameters/GRPObject.h"
#include "ReconstructionDataFormats/PID.h"
#include "ReconstructionDataFormats/TrackLTIntegral.h"
#include "DataFormatsGlobalTracking/TrackTuneParams.h"
#include "GlobalTracking/MatchTOF.h"
#include "TPCBase/ParameterGas.h"
#include "TPCBase/ParameterElectronics.h"
#include "TPCReconstruction/TPCFastTransformHelperO2.h"
#include "DataFormatsGlobalTracking/RecoContainer.h"
#include "DataFormatsGlobalTracking/RecoContainerCreateTracksVariadic.h"
#include "TOFBase/Utils.h"
#ifdef WITH_OPENMP
#include <omp.h>
#endif
using namespace o2::globaltracking;
using evGIdx = o2::dataformats::EvIndex<int, o2::dataformats::GlobalTrackID>;
using trkType = o2::dataformats::MatchInfoTOFReco::TrackType;
using Cluster = o2::tof::Cluster;
using GTrackID = o2::dataformats::GlobalTrackID;
using timeEst = o2::dataformats::TimeStampWithError<float, float>;
using TrackTunePar = o2::globaltracking::TrackTuneParams;
bool MatchTOF::mHasFillScheme = false;
bool MatchTOF::mFillScheme[o2::constants::lhc::LHCMaxBunches] = {0};
ClassImp(MatchTOF);
//______________________________________________
void MatchTOF::run(const o2::globaltracking::RecoContainer& inp, unsigned long firstTForbit)
{
mFirstTForbit = firstTForbit;
if (!mMatchParams) {
mMatchParams = &o2::globaltracking::MatchTOFParams::Instance();
mSigmaTimeCut = mMatchParams->nsigmaTimeCut;
}
///< running the matching
mRecoCont = &inp;
mStartIR = inp.startIR;
updateTimeDependentParams();
mTimerMatchTPC.Reset();
mTimerMatchITSTPC.Reset();
mTimerTot.Reset();
mCalibInfoTOF.clear();
for (int i = 0; i < trkType::SIZEALL; i++) {
mMatchedTracks[i].clear();
mOutTOFLabels[i].clear();
}
for (int it = 0; it < trkType::SIZE; it++) {
for (int sec = o2::constants::math::NSectors - 1; sec > -1; sec--) {
mMatchedTracksIndex[sec][it].clear();
mTracksWork[sec][it].clear();
mTrackGid[sec][it].clear();
mLTinfos[sec][it].clear();
if (mMCTruthON) {
mTracksLblWork[sec][it].clear();
}
mTracksSectIndexCache[it][sec].clear();
mTracksSeed[it][sec].clear();
}
}
for (int sec = o2::constants::math::NSectors - 1; sec > -1; sec--) {
mSideTPC[sec].clear();
mExtraTPCFwdTime[sec].clear();
}
mTimerTot.Start();
bool isPrepareTOFClusters = prepareTOFClusters();
mTimerTot.Stop();
LOGF(info, "Timing prepareTOFCluster: Cpu: %.3e s Real: %.3e s in %d slots", mTimerTot.CpuTime(), mTimerTot.RealTime(), mTimerTot.Counter() - 1);
if (!isPrepareTOFClusters) { // check cluster before of tracks to see also if MC is required
return;
}
mTimerTot.Start();
if (!prepareTPCData()) {
return;
}
mTimerTot.Stop();
LOGF(info, "Timing prepare TPC tracks: Cpu: %.3e s Real: %.3e s in %d slots", mTimerTot.CpuTime(), mTimerTot.RealTime(), mTimerTot.Counter() - 1);
mTimerTot.Start();
if (!prepareFITData()) {
return;
}
mTimerTot.Stop();
LOGF(info, "Timing prepare FIT data: Cpu: %.3e s Real: %.3e s in %d slots", mTimerTot.CpuTime(), mTimerTot.RealTime(), mTimerTot.Counter() - 1);
mTimerTot.Start();
std::array<uint32_t, 18> nMatches = {0};
// run matching (this can be multi-thread)
mTimerMatchITSTPC.Start();
for (int sec = o2::constants::math::NSectors - 1; sec > -1; sec--) {
mMatchedTracksPairsSec[sec].clear(); // new sector
}
o2::tof::Geo::Init();
if (mIsITSTPCused || mIsTPCTRDused || mIsITSTPCTRDused) {
#ifdef WITH_OPENMP
#pragma omp parallel for schedule(dynamic) num_threads(mNlanes)
#endif
for (int sec = o2::constants::math::NSectors - 1; sec > -1; sec--) {
doMatching(sec);
}
}
mTimerMatchITSTPC.Stop();
mTimerMatchTPC.Start();
if (mIsTPCused) {
#ifdef WITH_OPENMP
#pragma omp parallel for schedule(dynamic) num_threads(mNlanes)
#endif
for (int sec = o2::constants::math::NSectors - 1; sec > -1; sec--) {
doMatchingForTPC(sec);
}
}
mTimerMatchTPC.Stop();
// finalize
for (int sec = o2::constants::math::NSectors - 1; sec > -1; sec--) {
if (mStoreMatchable) {
// if MC check if good or fake matches
if (mMCTruthON) {
for (auto& matchingPair : mMatchedTracksPairsSec[sec]) {
int trkType = (int)matchingPair.getTrackType();
int itrk = matchingPair.getIdLocal();
const auto& labelsTOF = mTOFClusLabels->getLabels(matchingPair.getTOFClIndex());
const auto& labelTrack = mTracksLblWork[sec][trkType][itrk];
// we have not found the track label among those associated to the TOF cluster --> fake match! We will associate the label of the main channel, but negative
bool fake = true;
for (auto& lbl : labelsTOF) {
if (labelTrack == lbl) { // compares src, evID, trID, ignores fake flag.
fake = false;
}
}
if (fake) {
matchingPair.setFakeMatch();
}
}
} else {
for (auto& matchingPair : mMatchedTracksPairsSec[sec]) {
int bct0 = int((matchingPair.getSignal() - matchingPair.getLTIntegralOut().getTOF(0) + 5000) * Geo::BC_TIME_INPS_INV); // bc taken assuming speed of light (el) and 5 ns of margin
if (bct0 < 0) { // if negative time (it can happen at the beginng of the TF int was truncated per excess... adjusting)
bct0--;
}
float tof = matchingPair.getSignal() - bct0 * Geo::BC_TIME_INPS;
if (std::abs(tof - matchingPair.getLTIntegralOut().getTOF(2)) < 600) {
} else if (std::abs(tof - matchingPair.getLTIntegralOut().getTOF(3)) < 600) {
} else if (std::abs(tof - matchingPair.getLTIntegralOut().getTOF(4)) < 600) {
} else if (std::abs(tof - matchingPair.getLTIntegralOut().getTOF(0)) < 600) {
} else if (std::abs(tof - matchingPair.getLTIntegralOut().getTOF(1)) < 600) {
} else if (std::abs(tof - matchingPair.getLTIntegralOut().getTOF(5)) < 600) {
} else if (std::abs(tof - matchingPair.getLTIntegralOut().getTOF(6)) < 600) {
} else if (std::abs(tof - matchingPair.getLTIntegralOut().getTOF(7)) < 600) {
} else if (std::abs(tof - matchingPair.getLTIntegralOut().getTOF(8)) < 600) {
} else { // no pion, kaon, proton, electron, muon, deuteron, triton, 3He, 4He
matchingPair.setFakeMatch();
}
}
}
}
LOG(debug) << "...done. Now check the best matches";
nMatches[sec] = mMatchedTracksPairsSec[sec].size();
selectBestMatches(sec);
if (mStoreMatchable) {
for (auto& matchingPair : mMatchedTracksPairsSec[sec]) {
trkType trkTypeSplitted = trkType::TPC;
auto sourceID = matchingPair.getTrackRef().getSource();
if (sourceID == o2::dataformats::GlobalTrackID::ITSTPC) {
trkTypeSplitted = trkType::ITSTPC;
} else if (sourceID == o2::dataformats::GlobalTrackID::TPCTRD) {
trkTypeSplitted = trkType::TPCTRD;
} else if (sourceID == o2::dataformats::GlobalTrackID::ITSTPCTRD) {
trkTypeSplitted = trkType::ITSTPCTRD;
}
matchingPair.setTrackType(trkTypeSplitted);
}
}
}
std::string nMatchesStr = "Number of pairs matched per sector: ";
for (int sec = o2::constants::math::NSectors - 1; sec > -1; sec--) {
nMatchesStr += fmt::format("{} : {} ; ", sec, nMatches[sec]);
}
LOG(info) << nMatchesStr;
// re-arrange outputs from constrained/unconstrained to the 4 cases (TPC, ITS-TPC, TPC-TRD, ITS-TPC-TRD) to be implemented as soon as TPC-TRD and ITS-TPC-TRD tracks available
mIsTPCused = false;
mIsITSTPCused = false;
mIsTPCTRDused = false;
mIsITSTPCTRDused = false;
mTimerTot.Stop();
LOGF(info, "Timing Do Matching: Cpu: %.3e s Real: %.3e s in %d slots", mTimerTot.CpuTime(), mTimerTot.RealTime(), mTimerTot.Counter() - 1);
LOGF(info, "Timing Do Matching Constrained: Cpu: %.3e s Real: %.3e s in %d slots", mTimerMatchITSTPC.CpuTime(), mTimerMatchITSTPC.RealTime(), mTimerMatchITSTPC.Counter() - 1);
LOGF(info, "Timing Do Matching TPC : Cpu: %.3e s Real: %.3e s in %d slots", mTimerMatchTPC.CpuTime(), mTimerMatchTPC.RealTime(), mTimerMatchTPC.Counter() - 1);
}
//______________________________________________
void MatchTOF::setTPCVDrift(const o2::tpc::VDriftCorrFact& v)
{
mTPCVDrift = v.refVDrift * v.corrFact;
mTPCVDriftCorrFact = v.corrFact;
mTPCVDriftRef = v.refVDrift;
mTPCDriftTimeOffset = v.getTimeOffset();
}
//______________________________________________
void MatchTOF::setTPCCorrMaps(o2::gpu::CorrectionMapsHelper* maph)
{
mTPCCorrMapsHelper = maph;
}
//______________________________________________
void MatchTOF::print() const
{
///< print the settings
LOG(info) << "****** component for the matching of tracks to TOF clusters ******";
LOG(info) << "MC truth: " << (mMCTruthON ? "on" : "off");
LOG(info) << "Time tolerance: " << mTimeTolerance;
LOG(info) << "Space tolerance: " << mSpaceTolerance;
LOG(info) << "SigmaTimeCut: " << mSigmaTimeCut;
LOG(info) << "**********************************************************************";
}
//______________________________________________
void MatchTOF::printCandidatesTOF() const
{
///< print the candidates for the matching
}
//_____________________________________________________
bool MatchTOF::prepareFITData()
{
// If available, read FIT Info
if (mIsFIT) {
mFITRecPoints = mRecoCont->getFT0RecPoints();
// prepareInteractionTimes();
}
return true;
}
//______________________________________________
int MatchTOF::prepareInteractionTimes()
{
// do nothing. If you think it can be useful have a look at MatchTPCITS
return 0;
}
//______________________________________________
void MatchTOF::printGrouping(const std::vector<o2::dataformats::MatchInfoTOFReco>& origin, const std::vector<std::vector<o2::dataformats::MatchInfoTOFReco>>& grouped)
{
printf("Original vector\n");
for (const auto& seed : origin) {
printf("Pair: track=%d TOFcl=%d\n", seed.getIdLocal(), seed.getTOFClIndex());
}
printf("\nGroups\n");
int ngroups = 0;
for (const auto& gr : grouped) {
ngroups++;
printf("Group %d\n", ngroups);
for (const auto& seed : gr) {
printf("Pair: track=%d TOFcl=%d\n", seed.getIdLocal(), seed.getTOFClIndex());
}
}
}
//______________________________________________
void MatchTOF::groupingMatch(const std::vector<o2::dataformats::MatchInfoTOFReco>& origin, std::vector<std::vector<o2::dataformats::MatchInfoTOFReco>>& grouped, std::vector<std::vector<int>>& firstEls, std::vector<std::vector<int>>& secondEls)
{
grouped.clear();
firstEls.clear();
secondEls.clear();
std::vector<o2::dataformats::MatchInfoTOFReco> dummy;
std::vector<int> dummyInt;
int pos = 0;
int posInVector = 0;
std::vector<int> alreadyUsed(origin.size(), 0);
while (posInVector < origin.size()) { // go ahead if there are elements
if (alreadyUsed[posInVector]) {
posInVector++;
continue;
}
bool found = true;
grouped.push_back(dummy);
auto& trkId = firstEls.emplace_back(dummyInt);
auto& cluId = secondEls.emplace_back(dummyInt);
// first element is the seed
const auto& seed = origin[posInVector];
trkId.push_back(seed.getIdLocal());
cluId.push_back(seed.getTOFClIndex());
// remove element added to the current group
grouped[pos].push_back(seed);
alreadyUsed[posInVector] = true;
posInVector++;
while (found) {
found = false;
for (int i = posInVector; i < origin.size(); i++) {
if (alreadyUsed[i]) {
continue;
}
const auto& seed = origin[i];
int matchFirst = -1;
int matchSecond = -1;
for (const int& ind : trkId) {
if (seed.getIdLocal() == ind) {
matchFirst = ind;
break;
}
}
for (const int& ind : cluId) {
if (seed.getTOFClIndex() == ind) {
matchSecond = ind;
break;
}
}
if (matchFirst >= 0 || matchSecond >= 0) { // belong to this group
if (matchFirst < 0) {
trkId.push_back(seed.getIdLocal());
}
if (matchSecond < 0) {
cluId.push_back(seed.getTOFClIndex());
}
grouped[pos].push_back(seed);
alreadyUsed[i] = true;
found = true;
break;
}
}
}
pos++; // move to the next group
}
}
//______________________________________________
bool MatchTOF::prepareTPCData()
{
mNotPropagatedToTOF[trkType::UNCONS] = 0;
mNotPropagatedToTOF[trkType::CONSTR] = 0;
auto creator = [this](auto& trk, GTrackID gid, float time0, float terr) {
const int nclustersMin = 0;
if constexpr (isTPCTrack<decltype(trk)>()) {
if (trk.getNClusters() < nclustersMin) {
return true;
}
if (std::abs(trk.getQ2Pt()) > mMaxInvPt) {
return true;
}
this->addTPCSeed(trk, gid, time0, terr);
}
if constexpr (isTPCITSTrack<decltype(trk)>()) {
if (trk.getParamOut().getX() < o2::constants::geom::XTPCOuterRef - 1.) {
return true;
}
this->addITSTPCSeed(trk, gid, time0, terr);
}
if constexpr (isTRDTrack<decltype(trk)>()) {
this->addTRDSeed(trk, gid, time0, terr);
}
return true;
};
mRecoCont->createTracksVariadic(creator);
#ifdef WITH_OPENMP
#pragma omp parallel for schedule(dynamic) num_threads(mNlanes)
#endif
for (int sec = o2::constants::math::NSectors - 1; sec > -1; sec--) {
if (mIsTPCused) {
propagateTPCTracks(sec);
}
if (mIsITSTPCused || mIsTPCTRDused || mIsITSTPCTRDused) {
propagateConstrTracks(sec);
}
}
// re-assign tracks which change sector (no multi-threading)
std::array<float, 3> globalPos;
for (int sec = o2::constants::math::NSectors - 1; sec > -1; sec--) {
if (mIsTPCused) {
for (auto& it : mTracksSeed[trkType::UNCONS][sec]) {
auto& pair = mTracksWork[sec][trkType::UNCONS][it];
auto& trc = pair.first;
trc.getXYZGlo(globalPos);
int sector = o2::math_utils::angle2Sector(TMath::ATan2(globalPos[1], globalPos[0]));
int itnew = mTracksWork[sector][trkType::UNCONS].size();
mSideTPC[sector].push_back(mSideTPC[sec][it]);
mExtraTPCFwdTime[sector].push_back(mExtraTPCFwdTime[sec][it]);
mTracksWork[sector][trkType::UNCONS].emplace_back(pair);
mTrackGid[sector][trkType::UNCONS].emplace_back(mTrackGid[sec][trkType::UNCONS][it]);
if (mMCTruthON) {
mTracksLblWork[sector][trkType::UNCONS].emplace_back(mTracksLblWork[sec][trkType::UNCONS][it]);
}
mLTinfos[sector][trkType::UNCONS].emplace_back(mLTinfos[sec][trkType::UNCONS][it]);
mVZtpcOnly[sector].push_back(mVZtpcOnly[sec][it]);
mTracksSectIndexCache[trkType::UNCONS][sector].push_back(itnew);
}
}
for (auto& it : mTracksSeed[trkType::CONSTR][sec]) {
auto& pair = mTracksWork[sec][trkType::CONSTR][it];
auto& trc = pair.first;
trc.getXYZGlo(globalPos);
int sector = o2::math_utils::angle2Sector(TMath::ATan2(globalPos[1], globalPos[0]));
int itnew = mTracksWork[sector][trkType::CONSTR].size();
mTracksWork[sector][trkType::CONSTR].emplace_back(pair);
mTrackGid[sector][trkType::CONSTR].emplace_back(mTrackGid[sec][trkType::CONSTR][it]);
if (mMCTruthON) {
mTracksLblWork[sector][trkType::CONSTR].emplace_back(mTracksLblWork[sec][trkType::CONSTR][it]);
}
mLTinfos[sector][trkType::CONSTR].emplace_back(mLTinfos[sec][trkType::CONSTR][it]);
mTracksSectIndexCache[trkType::CONSTR][sector].push_back(itnew);
}
}
for (int it = 0; it < trkType::SIZE; it++) {
for (int sec = o2::constants::math::NSectors - 1; sec > -1; sec--) {
mMatchedTracksIndex[sec][it].resize(mTracksWork[sec][it].size());
std::fill(mMatchedTracksIndex[sec][it].begin(), mMatchedTracksIndex[sec][it].end(), -1); // initializing all to -1
}
}
if (mIsTPCused) {
LOG(debug) << "Number of UNCONSTRAINED tracks that failed to be propagated to TOF = " << mNotPropagatedToTOF[trkType::UNCONS];
// sort tracks in each sector according to their time (increasing in time)
#ifdef WITH_OPENMP
#pragma omp parallel for schedule(dynamic) num_threads(mNlanes)
#endif
for (int sec = o2::constants::math::NSectors - 1; sec > -1; sec--) {
auto& indexCache = mTracksSectIndexCache[trkType::UNCONS][sec];
LOG(debug) << "Sorting sector" << sec << " | " << indexCache.size() << " tracks";
if (!indexCache.size()) {
continue;
}
std::sort(indexCache.begin(), indexCache.end(), [this, sec](int a, int b) {
auto& trcA = mTracksWork[sec][trkType::UNCONS][a].second;
auto& trcB = mTracksWork[sec][trkType::UNCONS][b].second;
return ((trcA.getTimeStamp() - trcA.getTimeStampError()) - (trcB.getTimeStamp() - trcB.getTimeStampError()) < 0.);
});
} // loop over tracks of single sector
}
if (mIsITSTPCused || mIsTPCTRDused || mIsITSTPCTRDused) {
LOG(debug) << "Number of CONSTRAINED tracks that failed to be propagated to TOF = " << mNotPropagatedToTOF[trkType::CONSTR];
// sort tracks in each sector according to their time (increasing in time)
#ifdef WITH_OPENMP
#pragma omp parallel for schedule(dynamic) num_threads(mNlanes)
#endif
for (int sec = o2::constants::math::NSectors - 1; sec > -1; sec--) {
auto& indexCache = mTracksSectIndexCache[trkType::CONSTR][sec];
LOG(debug) << "Sorting sector" << sec << " | " << indexCache.size() << " tracks";
if (!indexCache.size()) {
continue;
}
std::sort(indexCache.begin(), indexCache.end(), [this, sec](int a, int b) {
auto& trcA = mTracksWork[sec][trkType::CONSTR][a].second;
auto& trcB = mTracksWork[sec][trkType::CONSTR][b].second;
return ((trcA.getTimeStamp() - mSigmaTimeCut * trcA.getTimeStampError()) - (trcB.getTimeStamp() - mSigmaTimeCut * trcB.getTimeStampError()) < 0.);
});
} // loop over tracks of single sector
}
if (mRecoCont->inputsTPCclusters) {
mTPCClusterIdxStruct = &mRecoCont->inputsTPCclusters->clusterIndex;
mTPCTracksArray = mRecoCont->getTPCTracks();
mTPCTrackClusIdx = mRecoCont->getTPCTracksClusterRefs();
mTPCRefitterShMap = mRecoCont->clusterShMapTPC;
mTPCRefitterOccMap = mRecoCont->occupancyMapTPC;
}
return true;
}
//______________________________________________
void MatchTOF::propagateTPCTracks(int sec)
{
auto& trkWork = mTracksWork[sec][trkType::UNCONS];
for (int it = 0; it < trkWork.size(); it++) {
o2::track::TrackParCov& trc = trkWork[it].first;
o2::track::TrackLTIntegral& intLT0 = mLTinfos[sec][trkType::UNCONS][it];
const auto& trackTune = TrackTuneParams::Instance();
if (!trackTune.sourceLevelTPC) { // correct only if TPC track was not corrected at the source level
if (trackTune.useTPCOuterCorr) {
trc.updateParams(trackTune.tpcParOuter);
}
if (trackTune.tpcCovOuterType != TrackTuneParams::AddCovType::Disable) { // only TRD-refitted track have cov.matrix already man>
trc.updateCov(mCovDiagOuter, trackTune.tpcCovOuterType == TrackTuneParams::AddCovType::WithCorrelations);
}
}
if (!propagateToRefXWithoutCov(trc, mXRef, 10, mBz)) { // we first propagate to 371 cm without considering the covariance matri
mNotPropagatedToTOF[trkType::UNCONS]++;
continue;
}
if (trc.getX() < o2::constants::geom::XTPCOuterRef - 1.) {
if (!propagateToRefXWithoutCov(trc, o2::constants::geom::XTPCOuterRef, 10, mBz) || std::abs(trc.getZ()) > Geo::MAXHZTOF) { // we check that the propagat>
mNotPropagatedToTOF[trkType::UNCONS]++;
continue;
}
}
o2::base::Propagator::Instance()->estimateLTFast(intLT0, trc);
// the "rough" propagation worked; now we can propagate considering also the cov matrix
if (!propagateToRefX(trc, mXRef, 2, intLT0)) { // || std::abs(trc.getZ()) > Geo::MAXHZTOF) { // we check that the propagation with the cov matrix w>
mNotPropagatedToTOF[trkType::UNCONS]++;
continue;
}
// printf("time0 %f -> %f (diff = %f, err = %f)\n",trackTime0, time0, trackTime0 - time0, terr);
// printf("time errors %f,%f -> %f,%f\n",(_tr.getDeltaTBwd() + 5) * mTPCTBinMUS,(_tr.getDeltaTFwd() + 5) * mTPCTBinMUS,trackTime0 - time0 + terr, ti>
std::array<float, 3> globalPos;
trc.getXYZGlo(globalPos);
int sector = o2::math_utils::angle2Sector(TMath::ATan2(globalPos[1], globalPos[0]));
if (sector == sec) {
mTracksSectIndexCache[trkType::UNCONS][sector].push_back(it);
} else {
mTracksSeed[trkType::UNCONS][sec].push_back(it); // to be moved to another sector
}
}
}
//______________________________________________
void MatchTOF::propagateConstrTracks(int sec)
{
std::array<float, 3> globalPos;
auto& trkWork = mTracksWork[sec][trkType::CONSTR];
for (int it = 0; it < trkWork.size(); it++) {
o2::track::TrackParCov& trc = trkWork[it].first;
o2::track::TrackLTIntegral& intLT0 = mLTinfos[sec][trkType::CONSTR][it];
// propagate to matching Xref
if (!propagateToRefXWithoutCov(trc, mXRef, 2, mBz)) { // we first propagate to 371 cm without considering the covariance matrix
mNotPropagatedToTOF[trkType::CONSTR]++;
continue;
}
// the "rough" propagation worked; now we can propagate considering also the cov matrix
if (!propagateToRefX(trc, mXRef, 2, intLT0) || std::abs(trc.getZ()) > Geo::MAXHZTOF) { // we check that the propagation with the cov matrix worked;>
mNotPropagatedToTOF[trkType::CONSTR]++;
continue;
}
trc.getXYZGlo(globalPos);
int sector = o2::math_utils::angle2Sector(TMath::ATan2(globalPos[1], globalPos[0]));
if (sector == sec) {
mTracksSectIndexCache[trkType::CONSTR][sector].push_back(it);
} else {
mTracksSeed[trkType::CONSTR][sec].push_back(it); // to be moved to another sector
}
}
}
//______________________________________________
void MatchTOF::addITSTPCSeed(const o2::dataformats::TrackTPCITS& _tr, o2::dataformats::GlobalTrackID srcGID, float time0, float terr)
{
mIsITSTPCused = true;
auto trc = _tr.getParamOut();
o2::track::TrackLTIntegral intLT0 = _tr.getLTIntegralOut();
timeEst ts(time0, terr);
addConstrainedSeed(trc, srcGID, intLT0, ts);
}
//______________________________________________
void MatchTOF::addConstrainedSeed(o2::track::TrackParCov& trc, o2::dataformats::GlobalTrackID srcGID, o2::track::TrackLTIntegral intLT0, timeEst timeMUS)
{
std::array<float, 3> globalPos;
trc.getXYZGlo(globalPos);
int sector = o2::math_utils::angle2Sector(TMath::ATan2(globalPos[1], globalPos[0]));
// create working copy of track param
mTracksWork[sector][trkType::CONSTR].emplace_back(std::make_pair(trc, timeMUS));
mTrackGid[sector][trkType::CONSTR].emplace_back(srcGID);
mLTinfos[sector][trkType::CONSTR].emplace_back(intLT0);
if (mMCTruthON) {
mTracksLblWork[sector][trkType::CONSTR].emplace_back(mRecoCont->getTPCITSTrackMCLabel(srcGID));
}
//delete trc; // Check: is this needed?
} //______________________________________________
void MatchTOF::addTRDSeed(const o2::trd::TrackTRD& _tr, o2::dataformats::GlobalTrackID srcGID, float time0, float terr)
{
if (srcGID.getSource() == o2::dataformats::GlobalTrackID::TPCTRD) {
mIsTPCTRDused = true;
} else if (srcGID.getSource() == o2::dataformats::GlobalTrackID::ITSTPCTRD) {
mIsITSTPCTRDused = true;
} else { // shouldn't happen
LOG(error) << "MatchTOF::addTRDSee: srcGID.getSource() = " << srcGID.getSource() << " not allowed; expected ones are: " << o2::dataformats::GlobalTrackID::TPCTRD << " and " << o2::dataformats::GlobalTrackID::ITSTPCTRD;
}
auto trc = _tr.getOuterParam();
o2::track::TrackLTIntegral intLT0 = _tr.getLTIntegralOut();
// o2::dataformats::TimeStampWithError<float, float>
timeEst ts(time0, terr + mExtraTimeToleranceTRD);
addConstrainedSeed(trc, srcGID, intLT0, ts);
}
//______________________________________________
void MatchTOF::addTPCSeed(const o2::tpc::TrackTPC& _tr, o2::dataformats::GlobalTrackID srcGID, float time0, float terr)
{
mIsTPCused = true;
std::array<float, 3> globalPos;
// create working copy of track param
timeEst timeInfo;
// set
float extraErr = 0;
if (mIsCosmics) {
extraErr = 100;
}
float trackTime0 = _tr.getTime0() * mTPCTBinMUS;
timeInfo.setTimeStampError((_tr.getDeltaTBwd() + 5) * mTPCTBinMUS + extraErr);
// timeInfo.setTimeStampError(trackTime0 - time0 + terr + extraErr);
timeInfo.setTimeStamp(trackTime0);
auto trc = _tr.getOuterParam();
trc.getXYZGlo(globalPos);
int sector = o2::math_utils::angle2Sector(TMath::ATan2(globalPos[1], globalPos[0]));
mSideTPC[sector].push_back(_tr.hasASideClustersOnly() ? 1 : (_tr.hasCSideClustersOnly() ? -1 : 0));
mExtraTPCFwdTime[sector].push_back((_tr.getDeltaTFwd() + 5) * mTPCTBinMUS + extraErr);
// mExtraTPCFwdTime[sector].push_back(time0 + terr - trackTime0 + extraErr);
mTracksWork[sector][trkType::UNCONS].emplace_back(std::make_pair(trc, timeInfo));
mTrackGid[sector][trkType::UNCONS].emplace_back(srcGID);
if (mMCTruthON) {
mTracksLblWork[sector][trkType::UNCONS].emplace_back(mRecoCont->getTPCTrackMCLabel(srcGID));
}
o2::track::TrackLTIntegral intLT0; // mTPCTracksWork.back().getLTIntegralOut(); // we get the integrated length from TPC-ITC outward propagation
// compute track length up to now
mLTinfos[sector][trkType::UNCONS].emplace_back(intLT0);
float vz0 = _tr.getZAt(0, mBz);
if (std::abs(vz0) > 9000) {
vz0 = _tr.getZ() - _tr.getX() * _tr.getTgl();
}
mVZtpcOnly[sector].push_back(vz0);
/*
const auto& trackTune = TrackTuneParams::Instance();
if (!trackTune.sourceLevelTPC) { // correct only if TPC track was not corrected at the source level
if (trackTune.useTPCOuterCorr) {
trc.updateParams(trackTune.tpcParOuter);
}
if (trackTune.tpcCovOuterType != TrackTuneParams::AddCovType::Disable) { // only TRD-refitted track have cov.matrix already manipulated
trc.updateCov(mCovDiagOuter, trackTune.tpcCovOuterType == TrackTuneParams::AddCovType::WithCorrelations);
}
}
if (!propagateToRefXWithoutCov(trc, mXRef, 10, mBz)) { // we first propagate to 371 cm without considering the covariance matri
mNotPropagatedToTOF[trkType::UNCONS]++;
return;
}
if (trc.getX() < o2::constants::geom::XTPCOuterRef - 1.) {
if (!propagateToRefX(trc, o2::constants::geom::XTPCOuterRef, 10, intLT0) || std::abs(trc.getZ()) > Geo::MAXHZTOF) { // we check that the propagation with the cov matrix worked; CHECK: can it happ
mNotPropagatedToTOF[trkType::UNCONS]++;
return;
}
}
// the "rough" propagation worked; now we can propagate considering also the cov matrix
if (!propagateToRefX(trc, mXRef, 2, intLT0)) { // || std::abs(trc.getZ()) > Geo::MAXHZTOF) { // we check that the propagation with the cov matrix worked; CHECK: can it happen that it does not if the prop>
mNotPropagatedToTOF[trkType::UNCONS]++;
return;
}
// printf("time0 %f -> %f (diff = %f, err = %f)\n",trackTime0, time0, trackTime0 - time0, terr);
// printf("time errors %f,%f -> %f,%f\n",(_tr.getDeltaTBwd() + 5) * mTPCTBinMUS,(_tr.getDeltaTFwd() + 5) * mTPCTBinMUS,trackTime0 - time0 + terr, time0 + terr - trackTime0);
trc.getXYZGlo(globalPos);
int sector = o2::math_utils::angle2Sector(TMath::ATan2(globalPos[1], globalPos[0]));
mTracksSectIndexCache[trkType::UNCONS][sector].push_back(it);
*/
// delete trc; // Check: is this needed?
}
//______________________________________________
bool MatchTOF::prepareTOFClusters()
{
mTOFClustersArrayInp = mRecoCont->getTOFClusters();
mTOFClusLabels = mRecoCont->getTOFClustersMCLabels();
mMCTruthON = mTOFClusLabels && mTOFClusLabels->getNElements();
///< prepare the tracks that we want to match to TOF
// copy the track params, propagate to reference X and build sector tables
mTOFClusWork.clear();
// mTOFClusWork.reserve(mNumOfClusters); // we cannot do this, we don't have mNumOfClusters yet
// if (mMCTruthON) {
// mTOFClusLblWork.clear();
// mTOFClusLblWork.reserve(mNumOfClusters);
// }
for (int sec = o2::constants::math::NSectors - 1; sec > -1; sec--) {
mTOFClusSectIndexCache[sec].clear();
//mTOFClusSectIndexCache[sec].reserve(100 + 1.2 * mNumOfClusters / o2::constants::math::NSectors); // we cannot do this, we don't have mNumOfClusters yet
}
mNumOfClusters = 0;
int nClusterInCurrentChunk = mTOFClustersArrayInp.size();
LOG(debug) << "nClusterInCurrentChunk = " << nClusterInCurrentChunk;
mNumOfClusters += nClusterInCurrentChunk;
mTOFClusWork.reserve(mTOFClusWork.size() + mNumOfClusters);
for (int it = 0; it < nClusterInCurrentChunk; it++) {
const Cluster& clOrig = mTOFClustersArrayInp[it];
// create working copy of track param
mTOFClusWork.emplace_back(clOrig);
auto& cl = mTOFClusWork.back();
// cache work track index
mTOFClusSectIndexCache[cl.getSector()].push_back(mTOFClusWork.size() - 1);
}
// sort clusters in each sector according to their time (increasing in time)
for (int sec = o2::constants::math::NSectors - 1; sec > -1; sec--) {
auto& indexCache = mTOFClusSectIndexCache[sec];
LOG(debug) << "Sorting sector" << sec << " | " << indexCache.size() << " TOF clusters";
if (!indexCache.size()) {
continue;
}
std::sort(indexCache.begin(), indexCache.end(), [this](int a, int b) {
auto& clA = mTOFClusWork[a];
auto& clB = mTOFClusWork[b];
return (clA.getTime() - clB.getTime()) < 0.;
});
} // loop over TOF clusters of single sector
if (mMatchedClustersIndex) {
delete[] mMatchedClustersIndex;
}
mMatchedClustersIndex = new int[mNumOfClusters];
std::fill_n(mMatchedClustersIndex, mNumOfClusters, -1); // initializing all to -1
return true;
}
//______________________________________________
void MatchTOF::doMatching(int sec)
{
trkType type = trkType::CONSTR;
///< do the real matching per sector
auto& cacheTOF = mTOFClusSectIndexCache[sec]; // array of cached TOF cluster indices for this sector; reminder: they are ordered in time!
auto& cacheTrk = mTracksSectIndexCache[type][sec]; // array of cached tracks indices for this sector; reminder: they are ordered in time!
int nTracks = cacheTrk.size(), nTOFCls = cacheTOF.size();
LOG(debug) << "Matching sector " << sec << ": number of tracks: " << nTracks << ", number of TOF clusters: " << nTOFCls;
if (!nTracks || !nTOFCls) {
return;
}
int itof0 = 0; // starting index in TOF clusters for matching of the track
int detId[2][5]; // at maximum one track can fall in 2 strips during the propagation; the second dimention of the array is the TOF det index
float deltaPos[2][3]; // at maximum one track can fall in 2 strips during the propagation; the second dimention of the array is the residuals
o2::track::TrackLTIntegral trkLTInt[2]; // Here we store the integrated track length and time for the (max 2) matched strips
int nStepsInsideSameStrip[2] = {0, 0}; // number of propagation steps in the same strip (since we have maximum 2 strips, it has dimention = 2)
float deltaPosTemp[3];
std::array<float, 3> pos;
std::array<float, 3> posBeforeProp;
float posFloat[3];
// prematching for TPC only tracks (identify BC candidate to correct z for TPC track accordingly to v_drift)
LOG(debug) << "Trying to match %d tracks" << cacheTrk.size();
for (int itrk = 0; itrk < cacheTrk.size(); itrk++) {
for (int ii = 0; ii < 2; ii++) {
detId[ii][2] = -1; // before trying to match, we need to inizialize the detId corresponding to the strip number to -1; this is the array that we will use to save the det id of the maximum 2 strips matched
nStepsInsideSameStrip[ii] = 0;
}
int nStripsCrossedInPropagation = 0; // how many strips were hit during the propagation
auto& trackWork = mTracksWork[sec][type][cacheTrk[itrk]];
auto& trefTrk = trackWork.first;
float pt = trefTrk.getPt();
auto& intLT = mLTinfos[sec][type][cacheTrk[itrk]];
float timeShift = intLT.getL() * 33.35641; // integrated time for 0.75 beta particles in ps, to take into account the t.o.f. delay with respect the interaction BC
// using beta=0.75 to cover beta range [0.59 , 1.04] also for a 8 m track lenght with a 10 ns track resolution (TRD)
// Printf("intLT (before doing anything): length = %f, time (Pion) = %f", intLT.getL(), intLT.getTOF(o2::track::PID::Pion));
float minTrkTime = (trackWork.second.getTimeStamp() - mSigmaTimeCut * trackWork.second.getTimeStampError()) * 1.E6 + timeShift; // minimum time in ps
float maxTrkTime = (trackWork.second.getTimeStamp() + mSigmaTimeCut * trackWork.second.getTimeStampError()) * 1.E6 + timeShift + 100E3; // maximum time in ps + 100 ns for slow tracks (beta->0.2)
const float sqrt12inv = 1. / sqrt(12.);
float resT = (trackWork.second.getTimeStampError() + 100E-3) * sqrt12inv;
int istep = 1; // number of steps
float step = 1.0; // step size in cm
//uncomment for local debug
/*
//trefTrk.getXYZGlo(posBeforeProp);
//float posBeforeProp[3] = {trefTrk.getX(), trefTrk.getY(), trefTrk.getZ()}; // in local ref system
//printf("Global coordinates: posBeforeProp[0] = %f, posBeforeProp[1] = %f, posBeforeProp[2] = %f\n", posBeforeProp[0], posBeforeProp[1], posBeforeProp[2]);
//Printf("Radius xy = %f", TMath::Sqrt(posBeforeProp[0]*posBeforeProp[0] + posBeforeProp[1]*posBeforeProp[1]));
//Printf("Radius xyz = %f", TMath::Sqrt(posBeforeProp[0]*posBeforeProp[0] + posBeforeProp[1]*posBeforeProp[1] + posBeforeProp[2]*posBeforeProp[2]));
*/
// initializing
for (int ii = 0; ii < 2; ii++) {
for (int iii = 0; iii < 5; iii++) {
detId[ii][iii] = -1;
}
}
int detIdTemp[5] = {-1, -1, -1, -1, -1}; // TOF detector id at the current propagation point
double reachedPoint = mXRef + istep * step;
while (propagateToRefX(trefTrk, reachedPoint, step, intLT) && nStripsCrossedInPropagation <= 2 && reachedPoint < Geo::RMAX) {
// while (o2::base::Propagator::Instance()->PropagateToXBxByBz(trefTrk, mXRef + istep * step, MAXSNP, step, 1, &intLT) && nStripsCrossedInPropagation <= 2 && mXRef + istep * step < Geo::RMAX) {
trefTrk.getXYZGlo(pos);
for (int ii = 0; ii < 3; ii++) { // we need to change the type...
posFloat[ii] = pos[ii];
}
// uncomment below only for local debug; this will produce A LOT of output - one print per propagation step
/*
Printf("posFloat[0] = %f, posFloat[1] = %f, posFloat[2] = %f", posFloat[0], posFloat[1], posFloat[2]);
Printf("radius xy = %f", TMath::Sqrt(posFloat[0]*posFloat[0] + posFloat[1]*posFloat[1]));
Printf("radius xyz = %f", TMath::Sqrt(posFloat[0]*posFloat[0] + posFloat[1]*posFloat[1] + posFloat[2]*posFloat[2]));
*/
for (int idet = 0; idet < 5; idet++) {
detIdTemp[idet] = -1;
}
Geo::getPadDxDyDz(posFloat, detIdTemp, deltaPosTemp, sec);
reachedPoint += step;
if (detIdTemp[2] == -1) {
continue;
}
// uncomment below only for local debug; this will produce A LOT of output - one print per propagation step
//Printf("detIdTemp[0] = %d, detIdTemp[1] = %d, detIdTemp[2] = %d, detIdTemp[3] = %d, detIdTemp[4] = %d", detIdTemp[0], detIdTemp[1], detIdTemp[2], detIdTemp[3], detIdTemp[4]);
// if (nStripsCrossedInPropagation == 0) { // print in case you have a useful propagation
// LOG(debug) << "*********** We have crossed a strip during propagation!*********";
// LOG(debug) << "Global coordinates: pos[0] = " << pos[0] << ", pos[1] = " << pos[1] << ", pos[2] = " << pos[2];
// LOG(debug) << "detIdTemp[0] = " << detIdTemp[0] << ", detIdTemp[1] = " << detIdTemp[1] << ", detIdTemp[2] = " << detIdTemp[2] << ", detIdTemp[3] = " << detIdTemp[3] << ", detIdTemp[4] = " << detIdTemp[4];
// LOG(debug) << "deltaPosTemp[0] = " << deltaPosTemp[0] << ", deltaPosTemp[1] = " << deltaPosTemp[1] << " deltaPosTemp[2] = " << deltaPosTemp[2];
// } else {
// LOG(debug) << "*********** We have NOT crossed a strip during propagation!*********";
// LOG(debug) << "Global coordinates: pos[0] = " << pos[0] << ", pos[1] = " << pos[1] << ", pos[2] = " << pos[2];
// LOG(debug) << "detIdTemp[0] = " << detIdTemp[0] << ", detIdTemp[1] = " << detIdTemp[1] << ", detIdTemp[2] = " << detIdTemp[2] << ", detIdTemp[3] = " << detIdTemp[3] << ", detIdTemp[4] = " << detIdTemp[4];
// LOG(debug) << "deltaPosTemp[0] = " << deltaPosTemp[0] << ", deltaPosTemp[1] = " << deltaPosTemp[1] << " deltaPosTemp[2] = " << deltaPosTemp[2];
// }
// check if after the propagation we are in a TOF strip
// we ended in a TOF strip
// LOG(debug) << "nStripsCrossedInPropagation = " << nStripsCrossedInPropagation << ", detId[nStripsCrossedInPropagation][0] = " << detId[nStripsCrossedInPropagation][0] << ", detIdTemp[0] = " << detIdTemp[0] << ", detId[nStripsCrossedInPropagation][1] = " << detId[nStripsCrossedInPropagation][1] << ", detIdTemp[1] = " << detIdTemp[1] << ", detId[nStripsCrossedInPropagation][2] = " << detId[nStripsCrossedInPropagation][2] << ", detIdTemp[2] = " << detIdTemp[2];
if (nStripsCrossedInPropagation == 0 || // we are crossing a strip for the first time...
(nStripsCrossedInPropagation >= 1 && (detId[nStripsCrossedInPropagation - 1][0] != detIdTemp[0] || detId[nStripsCrossedInPropagation - 1][1] != detIdTemp[1] || detId[nStripsCrossedInPropagation - 1][2] != detIdTemp[2]))) { // ...or we are crossing a new strip
if (nStripsCrossedInPropagation == 0) {
LOG(debug) << "We cross a strip for the first time";
}
if (nStripsCrossedInPropagation == 2) {
break; // we have already matched 2 strips, we cannot match more
}
nStripsCrossedInPropagation++;
}
//Printf("nStepsInsideSameStrip[nStripsCrossedInPropagation-1] = %d", nStepsInsideSameStrip[nStripsCrossedInPropagation - 1]);
if (nStepsInsideSameStrip[nStripsCrossedInPropagation - 1] == 0) {
// fine propagation inside the strip -> 1 mm step
trkLTInt[nStripsCrossedInPropagation - 1] = intLT;
// temporary variables since propagation can fail
int detIdTemp2[5] = {0, 0, 0, 0, 0};
float deltaPosTemp2[3] = {deltaPosTemp[0], deltaPosTemp[1], deltaPosTemp[2]};
int nstep = 0;
const int maxnstep = 50;
float xStart = trefTrk.getX();
float xStop = xStart;
trefTrk.getXYZGlo(pos);
for (int ii = 0; ii < 3; ii++) { // we need to change the type...
posFloat[ii] = pos[ii];
}
while (deltaPosTemp2[1] < -0.05 && detIdTemp2[2] != -1 && nstep < maxnstep) { // continuing propagation if dy is negative and we are still inside the strip volume
nstep++;
xStop += 0.1;
propagateToRefXWithoutCov(trefTrk, xStop, 0.1, mBz, posFloat);
Geo::getPadDxDyDz(posFloat, detIdTemp2, deltaPosTemp2, sec);
if (detIdTemp2[2] != -1) { // if propation was succesful -> update params
float dx = deltaPosTemp2[0] - deltaPosTemp[0];
float dy = deltaPosTemp2[1] - deltaPosTemp[1];
float dz = deltaPosTemp2[2] - deltaPosTemp[2];
updateTL(trkLTInt[nStripsCrossedInPropagation - 1], sqrt(dx * dx + dy * dy + dz * dz));
detIdTemp[0] = detIdTemp2[0];
detIdTemp[1] = detIdTemp2[1];
detIdTemp[2] = detIdTemp2[2];
detIdTemp[3] = detIdTemp2[3];
detIdTemp[4] = detIdTemp2[4];
deltaPosTemp[0] = deltaPosTemp2[0];
deltaPosTemp[1] = deltaPosTemp2[1];
deltaPosTemp[2] = deltaPosTemp2[2];
}
}
// adjust accordingly to DeltaY
updateTL(trkLTInt[nStripsCrossedInPropagation - 1], -deltaPosTemp[1]);
detId[nStripsCrossedInPropagation - 1][0] = detIdTemp[0];
detId[nStripsCrossedInPropagation - 1][1] = detIdTemp[1];
detId[nStripsCrossedInPropagation - 1][2] = detIdTemp[2];
detId[nStripsCrossedInPropagation - 1][3] = detIdTemp[3];
detId[nStripsCrossedInPropagation - 1][4] = detIdTemp[4];
deltaPos[nStripsCrossedInPropagation - 1][0] = deltaPosTemp[0];
deltaPos[nStripsCrossedInPropagation - 1][1] = deltaPosTemp[1];
deltaPos[nStripsCrossedInPropagation - 1][2] = deltaPosTemp[2];
// Printf("intLT (after matching to strip %d): length = %f, time (Pion) = %f", nStripsCrossedInPropagation - 1, trkLTInt[nStripsCrossedInPropagation - 1].getL(), trkLTInt[nStripsCrossedInPropagation - 1].getTOF(o2::track::PID::Pion));
nStepsInsideSameStrip[nStripsCrossedInPropagation - 1]++;
}
/* // obsolete
else { // a further propagation step in the same strip -> update info (we sum up on all matching with strip - we will divide for the number of steps a bit below)
// N.B. the integrated length and time are taken (at least for now) from the first time we crossed the strip, so here we do nothing with those
deltaPos[nStripsCrossedInPropagation - 1][0] += deltaPosTemp[0] + (detIdTemp[4] - detId[nStripsCrossedInPropagation - 1][4]) * Geo::XPAD; // residual in x
deltaPos[nStripsCrossedInPropagation - 1][1] += deltaPosTemp[1]; // residual in y
deltaPos[nStripsCrossedInPropagation - 1][2] += deltaPosTemp[2] + (detIdTemp[3] - detId[nStripsCrossedInPropagation - 1][3]) * Geo::ZPAD; // residual in z
nStepsInsideSameStrip[nStripsCrossedInPropagation - 1]++;
}
*/
}
for (Int_t imatch = 0; imatch < nStripsCrossedInPropagation; imatch++) {
// we take as residual the average of the residuals along the propagation in the same strip
deltaPos[imatch][0] /= nStepsInsideSameStrip[imatch];
deltaPos[imatch][1] /= nStepsInsideSameStrip[imatch];
deltaPos[imatch][2] /= nStepsInsideSameStrip[imatch];
}