forked from AliceO2Group/O2Physics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobal-muon-matcher.cxx
More file actions
1851 lines (1560 loc) · 76.5 KB
/
Copy pathglobal-muon-matcher.cxx
File metadata and controls
1851 lines (1560 loc) · 76.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
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.
//
/// \file global-muon-matcher.cxx // o2-linter: disable=name/file-cpp,name/workflow-file
/// \brief Task for analysis MFT-MCH muon matching
/// \author Andrea Ferrero
///
#include "PWGDQ/Core/MuonMatchingMlResponse.h"
#include "PWGDQ/Core/VarManager.h"
#include "Common/Core/RecoDecay.h"
#include "Common/Core/fwdtrackUtilities.h"
#include "Common/DataModel/EventSelection.h"
#include "Common/DataModel/FwdTrackReAlignTables.h"
#include "Tools/ML/MlResponse.h"
#include <CCDB/BasicCCDBManager.h>
#include <CCDB/CcdbApi.h>
#include <CommonConstants/LHCConstants.h>
#include <CommonConstants/MathConstants.h>
#include <DataFormatsParameters/GRPMagField.h>
#include <DetectorsBase/GeometryManager.h>
#include <DetectorsBase/Propagator.h>
#include <Field/MagneticField.h>
#include <Framework/ASoA.h>
#include <Framework/AnalysisDataModel.h>
#include <Framework/AnalysisHelpers.h>
#include <Framework/AnalysisTask.h>
#include <Framework/Array2D.h>
#include <Framework/Configurable.h>
#include <Framework/DataTypes.h>
#include <Framework/InitContext.h>
#include <Framework/runDataProcessing.h>
#include <GPU/GPUROOTCartesianFwd.h>
#include <GlobalTracking/MatchGlobalFwd.h>
#include <MCHBase/TrackerParam.h>
#include <MCHGeometryTransformer/Transformations.h>
#include <MCHTracking/Track.h>
#include <MCHTracking/TrackExtrap.h>
#include <MCHTracking/TrackFitter.h>
#include <MCHTracking/TrackParam.h>
#include <MFTTracking/Constants.h>
#include <MathUtils/Cartesian.h>
#include <ReconstructionDataFormats/TrackFwd.h>
#include <Math/MatrixFunctions.h>
#include <Math/SMatrix.h>
#include <Math/SVector.h>
#include <TGeoGlobalMagField.h>
#include <algorithm>
#include <array>
#include <chrono>
#include <cmath>
#include <cstdint>
#include <exception>
#include <functional>
#include <iterator>
#include <map>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace o2;
using namespace o2::framework;
using namespace o2::aod;
namespace o2::aod
{
namespace globalmuonmatching
{
DECLARE_SOA_COLUMN(IsTagged, isTagged, bool); //! Whether the MCH(-MID) track passes tagging cuts
DECLARE_SOA_COLUMN(MatchRanking, matchRanking, int32_t); //! Match candidate ranking (-1 for base MCH entries)
DECLARE_SOA_COLUMN(MixedGroupIndex, mixedGroupIndex, int32_t); //! Mixed-event group index (-1 for same-event candidates)
DECLARE_SOA_INDEX_COLUMN_FULL(FwdTrackRealign, fwdTrackRealign, int, FwdTracksReAlign, ""); //! Index of ambiguous FwdTracksReAlign entry
DECLARE_SOA_SLICE_INDEX_COLUMN_FULL(Bc, bc, int32_t, BCs, ""); //! BC index slice compatible with the track time window
} // namespace globalmuonmatching
DECLARE_SOA_TABLE(GmmCandFwdTrkExtras, "AOD", "GMMCANDEXTRA", //! Extra info joinable to FwdTracksReAlign
globalmuonmatching::IsTagged,
globalmuonmatching::MatchRanking,
globalmuonmatching::MixedGroupIndex);
DECLARE_SOA_TABLE(AmbiguousFwdTracksReAlign, "AOD", "AMBIGFWDREALIGN", //! FwdTracksReAlign entries without a unique collision association
o2::soa::Index<>, globalmuonmatching::FwdTrackRealignId, globalmuonmatching::BcIdSlice);
} // namespace o2::aod
using MyEvents = soa::Join<aod::Collisions, aod::EvSels>;
using MyMuons = soa::Join<aod::FwdTracks, aod::FwdTracksCov>;
using MyMFTs = aod::MFTTracks;
using MyMFTCovariances = aod::MFTTracksCov;
using SMatrix55Sym = o2::track::SMatrix55Sym;
using SMatrix55Std = o2::track::SMatrix55Std;
using SMatrix5 = o2::track::SMatrix5;
constexpr std::array<int, 10> NDetElemCh = {4, 4, 4, 4, 18, 18, 26, 26, 26, 26};
constexpr std::array<int, 11> SNDetElemCh = {0, 4, 8, 12, 16, 34, 52, 78, 104, 130, 156};
// compute minimum difference between azimuthal angles
static float getDeltaPhi(float phi1, float phi2)
{
return RecoDecay::constrainAngle(phi1 - phi2, -o2::constants::math::PI);
}
struct GlobalMuonMatching {
static constexpr int GlobalTrackTypeMax = 2;
static constexpr int MchMidTrackType = 3;
static constexpr int NMchChambers = 10;
static constexpr int MchDetElemNumberingBase = 100;
static constexpr int NMchDetElems = 156;
static constexpr int MinRemovableTrackClusters = 10;
static constexpr int ThetaAbsBoundaryDeg = 3;
static constexpr double SlopeResolutionZ = 535.;
static constexpr float MatchingPlaneDefaultZ = -77.5;
struct MatchingCandidate {
int64_t muonTrackId{-1};
int64_t mftTrackId{-1};
double matchScore{-1};
double matchChi2{-1};
int matchRanking{-1};
int32_t mixedGroupIndex{-1};
};
struct MchTrackInfo {
int nMatchAttempts{-1};
bool isTagged{false};
// vector of MFT-MCH matching candidates
std::vector<MatchingCandidate> matchingCandidates;
// vector of vectors of MFT-MCH matching candidates from mixed events
std::vector<std::vector<MatchingCandidate>> mixedMatchingCandidates;
};
//// Variables for selecting tagged muons
struct : ConfigurableGroup {
Configurable<int> cfgMuonTaggingNCrossedMftPlanesLow{"cfgMuonTaggingNCrossedMftPlanesLow", 5, ""};
Configurable<float> cfgMuonTaggingTrackChi2MchUp{"cfgMuonTaggingTrackChi2MchUp", 5.f, ""};
Configurable<float> cfgMuonTaggingPMchLow{"cfgMuonTaggingPMchLow", 0.0f, ""};
Configurable<float> cfgMuonTaggingPtMchLow{"cfgMuonTaggingPtMchLow", 0.7f, ""};
Configurable<float> cfgMuonTaggingEtaMchLow{"cfgMuonTaggingEtaMchLow", -3.6f, ""};
Configurable<float> cfgMuonTaggingEtaMchUp{"cfgMuonTaggingEtaMchUp", -2.5f, ""};
Configurable<float> cfgMuonTaggingRabsLow{"cfgMuonTaggingRabsLow", 17.6f, ""};
Configurable<float> cfgMuonTaggingRabsUp{"cfgMuonTaggingRabsUp", 89.5f, ""};
Configurable<float> cfgMuonTaggingPdcaUp{"cfgMuonTaggingPdcaUp", 4.f, ""};
Configurable<float> cfgMuonTaggingRadiusAtMftFrontLow{"cfgMuonTaggingRadiusAtMftFrontLow", 3.f, ""};
Configurable<float> cfgMuonTaggingRadiusAtMftFrontUp{"cfgMuonTaggingRadiusAtMftFrontUp", 9.f, ""};
Configurable<float> cfgMuonTaggingRadiusAtMftBackLow{"cfgMuonTaggingRadiusAtMftBackLow", 5.f, ""};
Configurable<float> cfgMuonTaggingRadiusAtMftBackUp{"cfgMuonTaggingRadiusAtMftBackUp", 12.f, ""};
} configMuonTagging;
//// Variables for MCH realignment
struct : ConfigurableGroup {
Configurable<bool> cfgEnableMCHRealign{"cfgEnableMCHRealign", true, "Enable re-alignment of MCH clusters and tracks"};
Configurable<std::string> cfgGeoRefPath{"cfgGeoRefPath", "GLO/Config/GeometryAligned", "Path of the reference geometry file"};
Configurable<std::string> cfgGeoNewPath{"cfgGeoNewPath", "GLO/Config/GeometryAligned", "Path of the new geometry file"};
Configurable<int64_t> cfgCcdbNoLaterThanRef{"cfgCcdbNoLaterThanRef", std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(), "latest acceptable timestamp of creation for the object of reference basis"};
Configurable<int64_t> cfgCcdbNoLaterThanNew{"cfgCcdbNoLaterThanNew", std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(), "latest acceptable timestamp of creation for the object of new basis"};
Configurable<double> cfgChamberResolutionX{"cfgChamberResolutionX", 0.04, "Chamber resolution along X configuration for refit"}; // 0.4cm pp, 0.2cm PbPb
Configurable<double> cfgChamberResolutionY{"cfgChamberResolutionY", 0.04, "Chamber resolution along Y configuration for refit"}; // 0.4cm pp, 0.2cm PbPb
Configurable<double> cfgSigmaCutImprove{"cfgSigmaCutImprove", 6., "Sigma cut for track improvement"}; // 6 for pp, 4 for PbPb
} configMchRealign;
//// Variables for MFT alignment corrections
struct : ConfigurableGroup {
Configurable<bool> cfgEnableMftAlignmentCorrections{"cfgEnableMftAlignmentCorrections", true, "Enable alignment corrections for the MFT tracks"};
// slope corrections
// Configurable<float> cfgMFTAlignmentCorrXSlopeTop{"cfgMFTAlignmentCorrXSlopeTop", (-0.0006696 - 0.0005621) / 2.f, "MFT X slope correction - top half"};
// Configurable<float> cfgMFTAlignmentCorrXSlopeBottom{"cfgMFTAlignmentCorrXSlopeBottom", (0.00105 + 0.001007) / 2.f, "MFT X slope correction - bottom half"};
// Configurable<float> cfgMFTAlignmentCorrYSlopeTop{"cfgMFTAlignmentCorrYSlopeTop", (-0.002299 - 0.002442) / 2.f, "MFT Y slope correction - top half"};
// Configurable<float> cfgMFTAlignmentCorrYSlopeBottom{"cfgMFTAlignmentCorrYSlopeBottom", (-0.0005339 - 0.0006921) / 2.f, "MFT Y slope correction - bottom half"};
Configurable<float> cfgMFTAlignmentCorrXSlopeTop{"cfgMFTAlignmentCorrXSlopeTop", 0.f, "MFT X slope correction - top half"};
Configurable<float> cfgMFTAlignmentCorrXSlopeBottom{"cfgMFTAlignmentCorrXSlopeBottom", 0.f, "MFT X slope correction - bottom half"};
Configurable<float> cfgMFTAlignmentCorrYSlopeTop{"cfgMFTAlignmentCorrYSlopeTop", 0.f, "MFT Y slope correction - top half"};
Configurable<float> cfgMFTAlignmentCorrYSlopeBottom{"cfgMFTAlignmentCorrYSlopeBottom", 0.f, "MFT Y slope correction - bottom half"};
// offset corrections
Configurable<float> cfgMFTAlignmentCorrXOffsetTop{"cfgMFTAlignmentCorrXOffsetTop", 0.f, "MFT X offset correction - top half"};
Configurable<float> cfgMFTAlignmentCorrXOffsetBottom{"cfgMFTAlignmentCorrXOffsetBottom", 0.f, "MFT X offset correction - bottom half"};
Configurable<float> cfgMFTAlignmentCorrYOffsetTop{"cfgMFTAlignmentCorrYOffsetTop", 0.f, "MFT Y offset correction - top half"};
Configurable<float> cfgMFTAlignmentCorrYOffsetBottom{"cfgMFTAlignmentCorrYOffsetBottom", 0.f, "MFT Y offset correction - bottom half"};
} configMftAlignmentCorrections;
// Variables for CCDB objects access and retrieval
struct : ConfigurableGroup {
Configurable<std::string> cfgCcdbUrl{"cfgCcdbUrl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
Configurable<int64_t> cfgCcdbNoLaterThan{"cfgCcdbNoLaterThan", std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(), "latest acceptable timestamp of creation for the object"};
Configurable<std::string> cfgGrpPath{"cfgGrpPath", "GLO/GRP/GRP", "Path of the grp file"};
Configurable<std::string> cfgGeoPath{"cfgGeoPath", "GLO/Config/GeometryAligned", "Path of the geometry file"};
Configurable<std::string> cfgGrpMagPath{"cfgGrpMagPath", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object"};
} configCcdb;
// Matching strategy for the *custom* matches (production baseline is always computed).
// 0 = chi2 (runChi2Matching), 1 = ML (runMlMatching)
struct : ConfigurableGroup {
Configurable<int> cfgCustomMatchingStrategy{"cfgCustomMatchingStrategy", 0, "0=chi2, 1=ML for custom matches"};
Configurable<bool> cfgIncludeGlobalMuonsInFwdTracks{"cfgIncludeGlobalMuonsInFwdTracks", false, "Include MFT-MCH-MID global muons in GMMCANDTRK table"};
Configurable<int> cfgMaxCandidatesPerMchTrack{"cfgMaxCandidatesPerMchTrack", -1, "Maximum number of match candidates stored per MCH track (-1: no limit)"};
Configurable<bool> cfgMatchAllTracks{"cfgMatchAllTracks", false, "If true the matching is performed considering all the MFT tracks for which the covariances are available; if false the matching is performed considering only the global forward tracks stored at production"};
} configMatching;
struct : ConfigurableGroup {
Configurable<int> cfgMixingDepth{"cfgMixingDepth", -1, "Maximum number of mixed candidate groups per MCH track (-1: no limit)"};
Configurable<int64_t> cfgMinDeltaBc{"cfgMinDeltaBc", 3564, "Minimum DeltaBc between mixed collisions"};
Configurable<float> cfgMaxDeltaPhi{"cfgMaxDeltaPhi", static_cast<float>(o2::constants::math::PI / 10), "Maximum DelptaPhi between mixed MCH tracks (rad)"};
Configurable<float> cfgMaxDeltaR{"cfgMaxDeltaR", 10.f, "Maximum DeltaR between mixed MCH tracks"};
Configurable<float> cfgMaxDeltaAttempts{"cfgMaxDeltaAttempts", 0.1f, "Maximum relative difference in match attempts"};
Configurable<float> cfgMaxDeltaZ{"cfgMaxDeltaZ", 1.f, "Maximum deltaZ between mixed collisions"};
} configEventMixing;
double mBzAtMftCenter{0};
using MatchingFunc = std::function<std::tuple<double, int>(const o2::track::TrackParCovFwd& mchtrack, const o2::track::TrackParCovFwd& mfttrack)>;
std::map<std::string, MatchingFunc> mMatchingFunctionMap; ///< MFT-MCH Matching function
// Chi2 matching interface (single configurable method)
struct : ConfigurableGroup {
Configurable<std::string> cfgChi2FunctionLabel{"cfgChi2FunctionLabel", std::string{"ProdAll"}, "Text label identifying the chi2 matching method"};
Configurable<std::string> cfgChi2FunctionName{"cfgChi2FunctionName", std::string{"prod"}, "Name of the chi2 matching function"};
Configurable<float> cfgChi2FunctionMatchingPlaneZ{"cfgChi2FunctionMatchingPlaneZ", static_cast<float>(o2::mft::constants::mft::LayerZCoordinate()[9]), "Z position of the matching plane"};
} configChi2MatchingOptions;
// ML interface (single configurable model)
struct : ConfigurableGroup {
Configurable<std::string> cfgMlModelLabel{"cfgMlModelLabel", std::string{""}, "Text label identifying this ML model"};
Configurable<std::string> cfgMlModelPathCcdb{"cfgMlModelPathCcdb", "Users/m/mcoquet/MLTest", "Path of model on CCDB"};
Configurable<std::string> cfgMlModelName{"cfgMlModelName", "model.onnx", "ONNX file name (if not from CCDB full path)"};
Configurable<std::vector<std::string>> cfgMlInputFeatures{"cfgMlInputFeatures", std::vector<std::string>{"chi2MCHMFT"}, "Names of ML model input features"};
Configurable<float> cfgMlModelMatchingPlaneZ{"cfgMlModelMatchingPlaneZ", static_cast<float>(o2::mft::constants::mft::LayerZCoordinate()[9]), "Z position of the matching plane"};
} configMlOptions;
std::vector<double> binsPtMl;
std::array<double, 1> cutValues{};
std::vector<int> cutDirMl;
bool hasActiveChi2Matching{false};
std::string activeChi2FunctionName;
double activeChi2MatchingPlaneZ{0.};
bool hasActiveMlMatching{false};
o2::analysis::MlResponseMFTMuonMatch<float> activeMlResponse;
double activeMlMatchingPlaneZ{0.};
int mRunNumber{0}; // needed to detect if the run changed and trigger update of magnetic field
Service<o2::ccdb::BasicCCDBManager> ccdbManager{};
o2::ccdb::CcdbApi fCCDBApi;
// vector of all MFT-MCH(-MID) matching candidates associated to the same MCH(-MID) track,
// to be sorted in descending order with respect to the matching score
// the map key is the MCH(-MID) track global index
using MatchingCandidates = std::map<int64_t, std::vector<MatchingCandidate>>;
class TrackParExt : public o2::track::TrackParCovFwd
{
public:
TrackParExt() = default;
TrackParExt(const TrackParExt& t) = default;
explicit TrackParExt(o2::track::TrackParCovFwd const& t, int nc = -1, bool r = false)
: TrackParCovFwd(t), nClusters(nc), removable(r) {}
~TrackParExt() = default;
TrackParExt& operator=(const TrackParCovFwd& tpf)
{
o2::track::TrackParCovFwd::operator=(tpf);
return *this;
}
TrackParExt& operator=(const TrackParExt& tpe)
{
o2::track::TrackParCovFwd::operator=(tpe);
nClusters = tpe.getNClusters();
removable = tpe.isRemovable();
return *this;
}
void setNClusters(int n) { nClusters = n; }
[[nodiscard]] int getNClusters() const { return nClusters; }
void setRemovable() { removable = true; }
[[nodiscard]] bool isRemovable() const { return removable; }
[[nodiscard]] o2::track::TrackParCovFwd asTrackParCovFwd() const { return *this; }
private:
int nClusters{-1};
bool removable{false};
};
std::unordered_map<int64_t, TrackParExt> mMchTrackPars;
std::unordered_map<int64_t, TrackParExt> mMftTrackPars;
std::unordered_map<int64_t, int32_t> mftTrackCovs;
Produces<o2::aod::StoredFwdTracksReAlign> gmCandidateFwdTracks;
Produces<o2::aod::StoredFwdTrksCovReAlign> gmCandidateFwdTracksCov;
Produces<o2::aod::GmmCandFwdTrkExtras> gmCandidateFwdTrackExtras;
Produces<o2::aod::AmbiguousFwdTracksReAlign> gmAmbiguousFwdTracksReAlign;
int32_t mGmmCandFwdTrackRowIndex{0};
std::unordered_map<int64_t, std::array<int32_t, 2>> mAmbBcSliceByFwdTrackId;
bool mHasLastMchAmbiguousBcSlice{false};
std::array<int32_t, 2> mLastMchAmbiguousBcSlice{};
std::unordered_map<int64_t, MchTrackInfo> mMchTrackInfos;
std::unordered_map<int64_t, std::vector<MatchingCandidate>> mStoredMatchingCandidates;
std::unordered_map<int64_t, int32_t> mFwdTrackToGmmCandTrkIndex;
mch::TrackFitter trackFitter; // Track fitter from MCH tracking library
mch::geo::TransformationCreator transformation;
std::map<int, math_utils::Transform3D> transformRef; // reference geometry w.r.t track data
std::map<int, math_utils::Transform3D> transformNew; // new geometry
double mImproveCutChi2{0.}; // Chi2 cut for track improvement.
TGeoManager* geoNew = nullptr;
TGeoManager* geoRef = nullptr;
globaltracking::MatchGlobalFwd mMatching;
Preslice<aod::FwdTrkCls> perMuon = aod::fwdtrkcl::fwdtrackId;
template <class T>
o2::mch::TrackParam fwdToMch(const T& fwdtrack)
{
// Convert Forward Track parameters and covariances matrix to the
// MCH track format.
// Parameter conversion
const double x2 = fwdtrack.getPhi();
const double x3 = fwdtrack.getTanl();
const double x4 = fwdtrack.getInvQPt();
const auto sinX2 = std::sin(x2);
const auto cosX2 = std::cos(x2);
const double alpha1 = cosX2 / x3;
const double alpha3 = sinX2 / x3;
const double alpha4 = x4 / std::sqrt(x3 * x3 + sinX2 * sinX2);
const auto kNorm = std::sqrt(x3 * x3 + sinX2 * sinX2);
const auto kNorm3 = kNorm * kNorm * kNorm;
// Covariances matrix conversion
SMatrix55Std jacobian;
SMatrix55Sym covariances;
covariances(0, 0) = fwdtrack.getCovariances()(0, 0);
covariances(0, 1) = fwdtrack.getCovariances()(0, 1);
covariances(0, 2) = fwdtrack.getCovariances()(0, 2);
covariances(0, 3) = fwdtrack.getCovariances()(0, 3);
covariances(0, 4) = fwdtrack.getCovariances()(0, 4);
covariances(1, 1) = fwdtrack.getCovariances()(1, 1);
covariances(1, 2) = fwdtrack.getCovariances()(1, 2);
covariances(1, 3) = fwdtrack.getCovariances()(1, 3);
covariances(1, 4) = fwdtrack.getCovariances()(1, 4);
covariances(2, 2) = fwdtrack.getCovariances()(2, 2);
covariances(2, 3) = fwdtrack.getCovariances()(2, 3);
covariances(2, 4) = fwdtrack.getCovariances()(2, 4);
covariances(3, 3) = fwdtrack.getCovariances()(3, 3);
covariances(3, 4) = fwdtrack.getCovariances()(3, 4);
covariances(4, 4) = fwdtrack.getCovariances()(4, 4);
jacobian(0, 0) = 1;
jacobian(1, 2) = -sinX2 / x3;
jacobian(1, 3) = -cosX2 / (x3 * x3);
jacobian(2, 1) = 1;
jacobian(3, 2) = cosX2 / x3;
jacobian(3, 3) = -sinX2 / (x3 * x3);
jacobian(4, 2) = -x4 * sinX2 * cosX2 / kNorm3;
jacobian(4, 3) = -x3 * x4 / kNorm3;
jacobian(4, 4) = 1 / kNorm;
// jacobian*covariances*jacobian^T
covariances = ROOT::Math::Similarity(jacobian, covariances);
std::array<double, 15> cov = {covariances(0, 0), covariances(1, 0), covariances(1, 1), covariances(2, 0), covariances(2, 1), covariances(2, 2), covariances(3, 0), covariances(3, 1), covariances(3, 2), covariances(3, 3), covariances(4, 0), covariances(4, 1), covariances(4, 2), covariances(4, 3), covariances(4, 4)};
std::array<double, 5> param = {fwdtrack.getX(), alpha1, fwdtrack.getY(), alpha3, alpha4};
o2::mch::TrackParam convertedTrack(fwdtrack.getZ(), param.data(), cov.data());
return {convertedTrack};
}
o2::track::TrackParCovFwd mchToFwd(const o2::mch::TrackParam& mchParam)
{
// Convert a MCH Track parameters and covariances matrix to the
// Forward track format. Must be called after propagation though the absorber
o2::track::TrackParCovFwd convertedTrack;
// Parameter conversion
const double alpha1 = mchParam.getNonBendingSlope();
const double alpha3 = mchParam.getBendingSlope();
const double alpha4 = mchParam.getInverseBendingMomentum();
const double x2 = std::atan2(-alpha3, -alpha1);
const double x3 = -1. / std::sqrt(alpha3 * alpha3 + alpha1 * alpha1);
const double x4 = alpha4 * -x3 * std::sqrt(1 + alpha3 * alpha3);
const auto kNorm = alpha1 * alpha1 + alpha3 * alpha3;
const auto kNorm32 = kNorm * std::sqrt(kNorm);
const auto slopeLen = std::sqrt(alpha3 * alpha3 + 1);
// Covariances matrix conversion
SMatrix55Std jacobian;
SMatrix55Sym covariances;
covariances(0, 0) = mchParam.getCovariances()(0, 0);
covariances(0, 1) = mchParam.getCovariances()(0, 1);
covariances(0, 2) = mchParam.getCovariances()(0, 2);
covariances(0, 3) = mchParam.getCovariances()(0, 3);
covariances(0, 4) = mchParam.getCovariances()(0, 4);
covariances(1, 1) = mchParam.getCovariances()(1, 1);
covariances(1, 2) = mchParam.getCovariances()(1, 2);
covariances(1, 3) = mchParam.getCovariances()(1, 3);
covariances(1, 4) = mchParam.getCovariances()(1, 4);
covariances(2, 2) = mchParam.getCovariances()(2, 2);
covariances(2, 3) = mchParam.getCovariances()(2, 3);
covariances(2, 4) = mchParam.getCovariances()(2, 4);
covariances(3, 3) = mchParam.getCovariances()(3, 3);
covariances(3, 4) = mchParam.getCovariances()(3, 4);
covariances(4, 4) = mchParam.getCovariances()(4, 4);
jacobian(0, 0) = 1;
jacobian(1, 2) = 1;
jacobian(2, 1) = -alpha3 / kNorm;
jacobian(2, 3) = alpha1 / kNorm;
jacobian(3, 1) = alpha1 / kNorm32;
jacobian(3, 3) = alpha3 / kNorm32;
jacobian(4, 1) = -alpha1 * alpha4 * slopeLen / kNorm32;
jacobian(4, 3) = alpha3 * alpha4 * (1 / (std::sqrt(kNorm) * slopeLen) - slopeLen / kNorm32);
jacobian(4, 4) = slopeLen / std::sqrt(kNorm);
// jacobian*covariances*jacobian^T
covariances = ROOT::Math::Similarity(jacobian, covariances);
// Set output
convertedTrack.setX(mchParam.getNonBendingCoor());
convertedTrack.setY(mchParam.getBendingCoor());
convertedTrack.setZ(mchParam.getZ());
convertedTrack.setPhi(x2);
convertedTrack.setTanl(x3);
convertedTrack.setInvQPt(x4);
convertedTrack.setCharge(mchParam.getCharge());
convertedTrack.setCovariances(covariances);
return convertedTrack;
}
int getDetElemId(int iDetElemNumber)
{
// make sure detector number is valid
if (iDetElemNumber < SNDetElemCh[0] ||
iDetElemNumber >= SNDetElemCh[NMchChambers]) {
LOGF(fatal, "Invalid detector element number: %d", iDetElemNumber);
}
/// get det element number from ID
// get chamber and element number in chamber
int iCh = 0;
int iDet = 0;
for (int i = 1; i <= NMchChambers; i++) {
if (iDetElemNumber < SNDetElemCh[i]) {
iCh = i;
iDet = iDetElemNumber - SNDetElemCh[i - 1];
break;
}
}
// make sure detector index is valid
if (iCh <= 0 || iCh > NMchChambers || iDet >= NDetElemCh[iCh - 1]) {
LOGF(fatal, "Invalid detector element id: %d", MchDetElemNumberingBase * iCh + iDet);
}
// add number of detectors up to this chamber
return MchDetElemNumberingBase * iCh + iDet;
}
bool removeTrack(mch::Track& track)
{
// Refit track with re-aligned clusters
bool shouldRemoveTrack = false;
try {
trackFitter.fit(track, false);
} catch (std::exception const& e) {
shouldRemoveTrack = true;
return shouldRemoveTrack;
}
auto itStartingParam = std::prev(track.rend());
while (true) {
try {
trackFitter.fit(track, true, false, (itStartingParam == track.rbegin()) ? nullptr : &itStartingParam);
} catch (std::exception const&) {
shouldRemoveTrack = true;
break;
}
double worstLocalChi2 = -1.0;
track.tagRemovableClusters(0x1F, false);
auto itWorstParam = track.end();
for (auto itParam = track.begin(); itParam != track.end(); ++itParam) {
if (itParam->getLocalChi2() > worstLocalChi2) {
worstLocalChi2 = itParam->getLocalChi2();
itWorstParam = itParam;
}
}
if (worstLocalChi2 < mImproveCutChi2) {
break;
}
if (!itWorstParam->isRemovable()) {
shouldRemoveTrack = true;
track.removable();
break;
}
auto itNextParam = track.removeParamAtCluster(itWorstParam);
auto itNextToNextParam = (itNextParam == track.end()) ? itNextParam : std::next(itNextParam);
itStartingParam = track.rbegin();
if (track.getNClusters() < MinRemovableTrackClusters) {
shouldRemoveTrack = true;
break;
}
while (itNextToNextParam != track.end()) {
if (itNextToNextParam->getClusterPtr()->getChamberId() != itNextParam->getClusterPtr()->getChamberId()) {
itStartingParam = std::make_reverse_iterator(++itNextParam);
break;
}
++itNextToNextParam;
}
}
if (!shouldRemoveTrack) {
for (auto& param : track) { // o2-linter: disable=const-ref-in-for-loop (object is modified in loop)
param.setParameters(param.getSmoothParameters());
param.setCovariances(param.getSmoothCovariances());
}
}
return shouldRemoveTrack;
}
template <typename BC>
void initCcdb(BC const& bc)
{
if (mRunNumber == bc.runNumber()) {
return;
}
mRunNumber = bc.runNumber();
std::map<std::string, std::string> metadata;
auto soreor = o2::ccdb::BasicCCDBManager::getRunDuration(fCCDBApi, mRunNumber);
auto ts = soreor.first;
auto grpmag = fCCDBApi.retrieveFromTFileAny<o2::parameters::GRPMagField>(configCcdb.cfgGrpMagPath, metadata, ts);
o2::base::Propagator::initFieldFromGRP(grpmag);
LOGF(info, "Set field for muons");
VarManager::SetupMuonMagField();
if (!o2::base::GeometryManager::isGeometryLoaded()) {
ccdbManager->get<TGeoManager>(configCcdb.cfgGeoPath);
}
mch::TrackExtrap::setField();
mch::TrackExtrap::useExtrapV2();
// Load geometry information from CCDB/local
LOGF(info, "Loading reference aligned geometry from CCDB no later than %d", configMchRealign.cfgCcdbNoLaterThanRef.value);
ccdbManager->setCreatedNotAfter(configMchRealign.cfgCcdbNoLaterThanRef.value); // this timestamp has to be consistent with what has been used in reco
geoRef = ccdbManager->getForTimeStamp<TGeoManager>(configMchRealign.cfgGeoRefPath, bc.timestamp());
ccdbManager->clearCache(configMchRealign.cfgGeoRefPath);
if (geoRef != nullptr) {
transformation = mch::geo::transformationFromTGeoManager(*geoRef);
} else {
LOGF(fatal, "Reference aligned geometry object is not available in CCDB at timestamp=%llu", bc.timestamp());
}
for (int i = 0; i < NMchDetElems; i++) {
int iDEN = getDetElemId(i);
transformRef[iDEN] = transformation(iDEN);
}
LOGF(info, "Loading new aligned geometry from CCDB no later than %d", configMchRealign.cfgCcdbNoLaterThanNew.value);
ccdbManager->setCreatedNotAfter(configMchRealign.cfgCcdbNoLaterThanNew.value); // make sure this timestamp can be resolved regarding the reference one
geoNew = ccdbManager->getForTimeStamp<TGeoManager>(configMchRealign.cfgGeoNewPath, bc.timestamp());
ccdbManager->clearCache(configMchRealign.cfgGeoNewPath);
if (geoNew != nullptr) {
transformation = mch::geo::transformationFromTGeoManager(*geoNew);
} else {
LOGF(fatal, "New aligned geometry object is not available in CCDB at timestamp=%llu", bc.timestamp());
}
for (int i = 0; i < NMchDetElems; i++) {
int iDEN = getDetElemId(i);
transformNew[iDEN] = transformation(iDEN);
}
// Init magnetic field for MFT track extrapolation
auto* fieldB = dynamic_cast<o2::field::MagneticField*>(TGeoGlobalMagField::Instance()->GetField());
if (fieldB) {
std::array<double, 3> centerMft{0, 0, -61.4}; // Field at center of MFT
mBzAtMftCenter = fieldB->getBz(centerMft.data());
// std::cout << "fieldB: " << (void*)fieldB << std::endl;
}
}
void initMatchingFunctions()
{
using SVector2 = ROOT::Math::SVector<double, 2>;
using SVector4 = ROOT::Math::SVector<double, 4>;
using SVector5 = ROOT::Math::SVector<double, 5>;
using SMatrix44 = ROOT::Math::SMatrix<double, 4>;
using SMatrix45 = ROOT::Math::SMatrix<double, 4, 5>;
using SMatrix22 = ROOT::Math::SMatrix<double, 2>;
using SMatrix25 = ROOT::Math::SMatrix<double, 2, 5>;
// Define built-in matching functions
//________________________________________________________________________________
mMatchingFunctionMap["matchALL"] = [](const o2::track::TrackParCovFwd& mchTrack, const o2::track::TrackParCovFwd& mftTrack) -> std::tuple<double, int> {
// Match two tracks evaluating all parameters: X,Y, phi, tanl & q/pt
SMatrix55Sym hK, vK;
SVector5 mK(mftTrack.getX(), mftTrack.getY(), mftTrack.getPhi(),
mftTrack.getTanl(), mftTrack.getInvQPt()),
rKKminus1;
const auto& globalMuonTrackParameters = mchTrack.getParameters();
const auto& globalMuonTrackCovariances = mchTrack.getCovariances();
vK(0, 0) = mftTrack.getCovariances()(0, 0);
vK(1, 1) = mftTrack.getCovariances()(1, 1);
vK(2, 2) = mftTrack.getCovariances()(2, 2);
vK(3, 3) = mftTrack.getCovariances()(3, 3);
vK(4, 4) = mftTrack.getCovariances()(4, 4);
hK(0, 0) = 1.0;
hK(1, 1) = 1.0;
hK(2, 2) = 1.0;
hK(3, 3) = 1.0;
hK(4, 4) = 1.0;
// Covariance of residuals
SMatrix55Std invResCov = (vK + ROOT::Math::Similarity(hK, globalMuonTrackCovariances));
invResCov.Invert();
// Update Parameters
rKKminus1 = mK - hK * globalMuonTrackParameters; // Residuals of prediction
auto matchChi2Track = ROOT::Math::Similarity(rKKminus1, invResCov);
// return chi2 and NDF
return {matchChi2Track, 5};
};
//________________________________________________________________________________
mMatchingFunctionMap["matchXYPhiTanl"] = [](const o2::track::TrackParCovFwd& mchTrack, const o2::track::TrackParCovFwd& mftTrack) -> std::tuple<double, int> {
// Match two tracks evaluating positions & angles
SMatrix45 hK;
SMatrix44 vK;
SVector4 mK(mftTrack.getX(), mftTrack.getY(), mftTrack.getPhi(),
mftTrack.getTanl()),
rKKminus1;
const auto& globalMuonTrackParameters = mchTrack.getParameters();
const auto& globalMuonTrackCovariances = mchTrack.getCovariances();
vK(0, 0) = mftTrack.getCovariances()(0, 0);
vK(1, 1) = mftTrack.getCovariances()(1, 1);
vK(2, 2) = mftTrack.getCovariances()(2, 2);
vK(3, 3) = mftTrack.getCovariances()(3, 3);
hK(0, 0) = 1.0;
hK(1, 1) = 1.0;
hK(2, 2) = 1.0;
hK(3, 3) = 1.0;
// Covariance of residuals
SMatrix44 invResCov = (vK + ROOT::Math::Similarity(hK, globalMuonTrackCovariances));
invResCov.Invert();
// Residuals of prediction
rKKminus1 = mK - hK * globalMuonTrackParameters;
auto matchChi2Track = ROOT::Math::Similarity(rKKminus1, invResCov);
// return chi2 and NDF
return {matchChi2Track, 4};
};
//________________________________________________________________________________
mMatchingFunctionMap["matchXY"] = [](const o2::track::TrackParCovFwd& mchTrack, const o2::track::TrackParCovFwd& mftTrack) -> std::tuple<double, int> {
// Calculate Matching Chi2 - X and Y positions
SMatrix25 hK;
SMatrix22 vK;
SVector2 mK(mftTrack.getX(), mftTrack.getY()), rKKminus1;
const auto& globalMuonTrackParameters = mchTrack.getParameters();
const auto& globalMuonTrackCovariances = mchTrack.getCovariances();
vK(0, 0) = mftTrack.getCovariances()(0, 0);
vK(1, 1) = mftTrack.getCovariances()(1, 1);
hK(0, 0) = 1.0;
hK(1, 1) = 1.0;
// Covariance of residuals
SMatrix22 invResCov = (vK + ROOT::Math::Similarity(hK, globalMuonTrackCovariances));
invResCov.Invert();
// Residuals of prediction
rKKminus1 = mK - hK * globalMuonTrackParameters;
auto matchChi2Track = ROOT::Math::Similarity(rKKminus1, invResCov);
// return reduced chi2
return {matchChi2Track, 2};
};
}
void init(o2::framework::InitContext&)
{
// Load geometry
ccdbManager->setURL(configCcdb.cfgCcdbUrl);
ccdbManager->setCaching(true);
ccdbManager->setLocalObjectValidityChecking();
fCCDBApi.init(configCcdb.cfgCcdbUrl);
mRunNumber = 0;
// Configuration for track fitter
const auto& trackerParam = mch::TrackerParam::Instance();
trackFitter.setBendingVertexDispersion(trackerParam.bendingVertexDispersion);
trackFitter.setChamberResolution(configMchRealign.cfgChamberResolutionX.value, configMchRealign.cfgChamberResolutionY.value);
trackFitter.smoothTracks(true);
trackFitter.useChamberResolution();
mImproveCutChi2 = 2. * configMchRealign.cfgSigmaCutImprove.value * configMchRealign.cfgSigmaCutImprove.value;
// Reset matching configuration, then populate only what we need.
hasActiveChi2Matching = false;
activeChi2FunctionName.clear();
activeChi2MatchingPlaneZ = 0.;
hasActiveMlMatching = false;
activeMlMatchingPlaneZ = 0.;
if (configMatching.cfgCustomMatchingStrategy.value == 0) {
// Matching functions (custom chi2)
initMatchingFunctions();
auto label = configChi2MatchingOptions.cfgChi2FunctionLabel.value;
auto funcName = configChi2MatchingOptions.cfgChi2FunctionName.value;
auto matchingPlaneZ = configChi2MatchingOptions.cfgChi2FunctionMatchingPlaneZ.value;
if (!label.empty() && !funcName.empty()) {
hasActiveChi2Matching = true;
activeChi2FunctionName = funcName;
activeChi2MatchingPlaneZ = matchingPlaneZ;
}
} else {
// Matching ML models (custom ML)
// TODO : for now we use hard coded values since the current models use 1 pT bin
binsPtMl = {-1e-6, 1000.0};
cutValues = {0.0};
cutDirMl = {cuts_ml::CutNot};
LabeledArray<double> mycutsMl(cutValues.data(), 1, 1, std::vector<std::string>{"pT bin 0"}, std::vector<std::string>{"score"});
auto label = configMlOptions.cfgMlModelLabel.value;
auto modelPath = configMlOptions.cfgMlModelPathCcdb.value;
auto inputFeatures = configMlOptions.cfgMlInputFeatures.value;
auto modelName = configMlOptions.cfgMlModelName.value;
auto matchingPlaneZ = configMlOptions.cfgMlModelMatchingPlaneZ.value;
if (!label.empty() && !modelPath.empty() && !inputFeatures.empty() && !modelName.empty()) {
activeMlResponse.configure(binsPtMl, mycutsMl, cutDirMl, 1);
activeMlResponse.setModelPathsCCDB(std::vector<std::string>{modelName}, fCCDBApi, std::vector<std::string>{modelPath}, configCcdb.cfgCcdbNoLaterThan.value);
activeMlResponse.cacheInputFeaturesIndices(inputFeatures);
activeMlResponse.init();
hasActiveMlMatching = true;
activeMlMatchingPlaneZ = matchingPlaneZ;
}
}
}
template <class T, class C>
bool pDcaCut(const T& mchTrack, const C& collision, double nSigmaPDCA)
{
static const double sigmaPDCA23 = 80.;
static const double sigmaPDCA310 = 54.;
static const double relPRes = 0.0004;
static const double slopeRes = 0.0005;
constexpr double AbsorberEndZ = 505.;
constexpr double RadToDeg = 180. / o2::constants::math::PI;
double thetaAbs = std::atan(mchTrack.rAtAbsorberEnd() / AbsorberEndZ) * RadToDeg;
// propagate muon track to vertex
auto mchTrackAtVertex = VarManager::PropagateMuon(mchTrack, collision, VarManager::kToVertex);
// double pUncorr = mchTrack.p();
double p = mchTrackAtVertex.getP();
double pDCA = mchTrack.pDca();
double sigmaPDCA = (thetaAbs < ThetaAbsBoundaryDeg) ? sigmaPDCA23 : sigmaPDCA310;
double nrp = nSigmaPDCA * relPRes * p;
double pResEffect = sigmaPDCA / (1. - nrp / (1. + nrp));
double slopeResEffect = SlopeResolutionZ * slopeRes * p;
double sigmaPDCAWithRes = std::sqrt(pResEffect * pResEffect + slopeResEffect * slopeResEffect);
return pDCA <= nSigmaPDCA * sigmaPDCAWithRes;
}
template <class T, class C>
bool isGoodMuon(const T& mchTrack, const C& collision,
double chi2Cut,
double pCut,
double pTCut,
std::array<double, 2> etaCut,
std::array<double, 2> rAbsCut,
double nSigmaPdcaCut)
{
// chi2 cut
if (mchTrack.chi2() > chi2Cut) {
return false;
}
// momentum cut
if (mchTrack.p() < pCut) {
return false; // skip low-momentum tracks
}
// transverse momentum cut
if (mchTrack.pt() < pTCut) {
return false; // skip low-momentum tracks
}
// Eta cut
double eta = mchTrack.eta();
if ((eta < etaCut[0] || eta > etaCut[1])) {
return false;
}
// RAbs cut
double rAbs = mchTrack.rAtAbsorberEnd();
if ((rAbs < rAbsCut[0] || rAbs > rAbsCut[1])) {
return false;
}
// pDCA cut
return pDcaCut(mchTrack, collision, nSigmaPdcaCut);
}
void storeFwdTrackCovariance(const SMatrix55Sym& cov)
{
const float sigX = std::sqrt(cov(0, 0));
const float sigY = std::sqrt(cov(1, 1));
const float sigPhi = std::sqrt(cov(2, 2));
const float sigTgl = std::sqrt(cov(3, 3));
const float sig1Pt = std::sqrt(cov(4, 4));
const auto rhoXY = static_cast<int8_t>(128.f * cov(0, 1) / (sigX * sigY));
const auto rhoPhiX = static_cast<int8_t>(128.f * cov(0, 2) / (sigPhi * sigX));
const auto rhoPhiY = static_cast<int8_t>(128.f * cov(1, 2) / (sigPhi * sigY));
const auto rhoTglX = static_cast<int8_t>(128.f * cov(0, 3) / (sigTgl * sigX));
const auto rhoTglY = static_cast<int8_t>(128.f * cov(1, 3) / (sigTgl * sigY));
const auto rhoTglPhi = static_cast<int8_t>(128.f * cov(2, 3) / (sigTgl * sigPhi));
const auto rho1PtX = static_cast<int8_t>(128.f * cov(0, 4) / (sig1Pt * sigX));
const auto rho1PtY = static_cast<int8_t>(128.f * cov(1, 4) / (sig1Pt * sigY));
const auto rho1PtPhi = static_cast<int8_t>(128.f * cov(2, 4) / (sig1Pt * sigPhi));
const auto rho1PtTgl = static_cast<int8_t>(128.f * cov(3, 4) / (sig1Pt * sigTgl));
gmCandidateFwdTracksCov(sigX, sigY, sigPhi, sigTgl, sig1Pt,
rhoXY, rhoPhiY, rhoPhiX, rhoTglX, rhoTglY, rhoTglPhi, rho1PtX, rho1PtY, rho1PtPhi, rho1PtTgl);
}
bool isMchTrackTagged(int64_t mchTrackIndex) const
{
const auto it = mMchTrackInfos.find(mchTrackIndex);
return it != mMchTrackInfos.end() && it->second.isTagged;
}
template <class TMCH>
void fillBaseGmmCandFwdTrack(TMCH const& track,
TrackParExt const& trackPar,
int32_t gmmMchTrackId,
float chi2MatchMCHMFT,
float matchScoreMCHMFT,
bool isTagged)
{
const auto collisionId = track.collisionId();
bool hasBcSlice = false;
std::array<int32_t, 2> bcSlice{};
if (collisionId < 0) {
const auto ambIt = mAmbBcSliceByFwdTrackId.find(track.globalIndex());
if (ambIt != mAmbBcSliceByFwdTrackId.end()) {
bcSlice = ambIt->second;
hasBcSlice = true;
}
}
gmCandidateFwdTracks(
collisionId,
track.trackType(),
trackPar.getX(),
trackPar.getY(),
trackPar.getZ(),
trackPar.getPhi(),
trackPar.getTgl(),
trackPar.getInvQPt(),
trackPar.getNClusters(),
track.pDca(),
track.rAtAbsorberEnd(),
trackPar.isRemovable(),
trackPar.getTrackChi2(),
track.chi2MatchMCHMID(),
chi2MatchMCHMFT,
matchScoreMCHMFT,
track.matchMFTTrackId(),
gmmMchTrackId,
track.mchBitMap(),
track.midBitMap(),
track.midBoards(),
track.trackTime(),
track.trackTimeRes());
storeFwdTrackCovariance(trackPar.getCovariances());
gmCandidateFwdTrackExtras(isTagged, -1, -1);
if (hasBcSlice) {
gmAmbiguousFwdTracksReAlign(mGmmCandFwdTrackRowIndex, bcSlice.data());
}
mGmmCandFwdTrackRowIndex += 1;
mHasLastMchAmbiguousBcSlice = hasBcSlice;
if (hasBcSlice) {
mLastMchAmbiguousBcSlice = bcSlice;
}
}
template <class TMCH, class TMFT>
void fillCandidateFwdTrack(TMCH const& mchTrack,
TrackParExt const& mchPar,
int32_t gmmMchTrackId,
TMFT const& mftTrack,
TrackParExt const& mftPar,
const MatchingCandidate& candidate)
{
using o2::aod::fwdtrack::ForwardTrackTypeEnum;
using o2::aod::fwdtrackutils::propagationPoint;
constexpr uint8_t CandidateTrackType = static_cast<uint8_t>(ForwardTrackTypeEnum::GlobalForwardTrack);
auto propmuonAtMft = fwdToMch(mchPar);
o2::mch::TrackExtrap::extrapToVertex(propmuonAtMft,
mftPar.getX(),
mftPar.getY(),
mftPar.getZ(),
mftPar.getSigma2X(),
mftPar.getSigma2Y());
const auto globalMuonRefit = o2::aod::fwdtrackutils::refitGlobalMuonCov(mchToFwd(propmuonAtMft), mftPar);
const auto nClusters = static_cast<int8_t>(std::min(127, mchPar.getNClusters() + mftPar.getNClusters()));
const float chi2 = static_cast<float>(mchTrack.chi2());
const int32_t collisionId = mchTrack.collisionId();
bool hasBcSlice = false;
std::array<int32_t, 2> bcSlice{};
if (collisionId < 0) {
if (mHasLastMchAmbiguousBcSlice) {
bcSlice = mLastMchAmbiguousBcSlice;
hasBcSlice = true;
} else {
const auto ambIt = mAmbBcSliceByFwdTrackId.find(mchTrack.globalIndex());
if (ambIt != mAmbBcSliceByFwdTrackId.end()) {
bcSlice = ambIt->second;
hasBcSlice = true;
}
}
}
bool isRemovable = mchPar.isRemovable();
gmCandidateFwdTracks(
collisionId,
CandidateTrackType,
globalMuonRefit.getX(),
globalMuonRefit.getY(),
globalMuonRefit.getZ(),
globalMuonRefit.getPhi(),
globalMuonRefit.getTgl(),