-
Notifications
You must be signed in to change notification settings - Fork 644
Expand file tree
/
Copy pathqaMatching.cxx
More file actions
2660 lines (2268 loc) · 123 KB
/
qaMatching.cxx
File metadata and controls
2660 lines (2268 loc) · 123 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 qaMatching.cxx
/// \brief Task to compute and evaluate DCA quantities
/// \author Nicolas Bizé <nicolas.bize@cern.ch>, SUBATECH
//
#include "PWGDQ/Core/MuonMatchingMlResponse.h"
#include "PWGDQ/Core/VarManager.h"
#include "PWGDQ/DataModel/ReducedInfoTables.h"
#include "Common/DataModel/EventSelection.h"
#include "CCDB/BasicCCDBManager.h"
#include "DataFormatsParameters/GRPMagField.h"
#include "Framework/ASoAHelpers.h"
#include "Framework/AnalysisTask.h"
#include "Framework/runDataProcessing.h"
#include "GlobalTracking/MatchGlobalFwd.h"
#include "MFTTracking/Constants.h"
#include <Math/ProbFunc.h>
#include <algorithm>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace o2;
using namespace o2::framework;
using namespace o2::aod;
using MyEvents = soa::Join<aod::Collisions, aod::EvSels>;
using MyMuons = soa::Join<aod::FwdTracks, aod::FwdTracksCov>;
using MyMuonsMC = soa::Join<aod::FwdTracks, aod::FwdTracksCov, aod::McFwdTrackLabels>;
using MyMFTs = aod::MFTTracks;
using MyMFTCovariances = aod::MFTTracksCov;
using MyMFTsMC = soa::Join<aod::MFTTracks, aod::McMFTTrackLabels>;
using MyMuon = MyMuons::iterator;
using MyMuonMC = MyMuonsMC::iterator;
using MyMFT = MyMFTs::iterator;
using MyMFTCovariance = MyMFTCovariances::iterator;
using SMatrix55 = ROOT::Math::SMatrix<double, 5, 5, ROOT::Math::MatRepSym<double, 5>>;
using SMatrix5 = ROOT::Math::SVector<Double_t, 5>;
static float chi2ToScore(float chi2, int ndf, float chi2max)
{
double p = -TMath::Log10(ROOT::Math::chisquared_cdf_c(chi2, ndf));
double pnorm = -TMath::Log10(ROOT::Math::chisquared_cdf_c(chi2max, ndf));
double result = (1.f / (p / pnorm + 1.f));
return static_cast<float>(result);
}
struct qaMatching {
template <class T, int nr, int nc>
using matrix = std::array<std::array<T, nc>, nr>;
enum MuonMatchType {
kMatchTypeTrueLeading = 0,
kMatchTypeWrongLeading = 1,
kMatchTypeDecayLeading = 2,
kMatchTypeFakeLeading = 3,
kMatchTypeTrueNonLeading = 4,
kMatchTypeWrongNonLeading = 5,
kMatchTypeDecayNonLeading = 6,
kMatchTypeFakeNonLeading = 7,
kMatchTypeUndefined
};
struct MatchingCandidate {
int64_t collisionId{-1};
int64_t globalTrackId{-1};
int64_t muonTrackId{-1};
int64_t mftTrackId{-1};
double matchScore{-1};
double matchChi2{-1};
int matchRanking{-1};
double matchScoreProd{-1};
double matchChi2Prod{-1};
int matchRankingProd{-1};
MuonMatchType matchType{kMatchTypeUndefined};
};
//// Variables for selecting muon tracks
Configurable<float> fPMchLow{"cfgPMchLow", 0.0f, ""};
Configurable<float> fPtMchLow{"cfgPtMchLow", 0.7f, ""};
Configurable<float> fEtaMchLow{"cfgEtaMchLow", -4.0f, ""};
Configurable<float> fEtaMchUp{"cfgEtaMchUp", -2.5f, ""};
Configurable<float> fRabsLow{"cfgRabsLow", 17.6f, ""};
Configurable<float> fRabsUp{"cfgRabsUp", 89.5f, ""};
Configurable<float> fSigmaPdcaUp{"cfgPdcaUp", 6.f, ""};
Configurable<float> fTrackChi2MchUp{"cfgTrackChi2MchUp", 5.f, ""};
Configurable<float> fMatchingChi2MchMidUp{"cfgMatchingChi2MchMidUp", 999.f, ""};
//// Variables for selecting mft tracks
Configurable<float> fEtaMftLow{"cfgEtaMftlow", -3.6f, ""};
Configurable<float> fEtaMftUp{"cfgEtaMftup", -2.5f, ""};
Configurable<int> fTrackNClustMftLow{"cfgTrackNClustMftLow", 7, ""};
Configurable<float> fTrackChi2MftUp{"cfgTrackChi2MftUp", 999.f, ""};
//// Variables for selecting global tracks
Configurable<float> fMatchingChi2ScoreMftMchLow{"cfgMatchingChi2ScoreMftMchLow", chi2ToScore(50.f, 5, 50.f), ""};
//// Variables for selecting tagged muons
Configurable<int> fMuonTaggingNCrossedMftPlanesLow{"cfgMuonTaggingNCrossedMftPlanesLow", 5, ""};
Configurable<float> fMuonTaggingTrackChi2MchUp{"cfgMuonTaggingTrackChi2MchUp", 5.f, ""};
Configurable<float> fMuonTaggingPMchLow{"cfgMuonTaggingPMchLow", 0.0f, ""};
Configurable<float> fMuonTaggingPtMchLow{"cfgMuonTaggingPtMchLow", 0.7f, ""};
Configurable<float> fMuonTaggingEtaMchLow{"cfgMuonTaggingEtaMchLow", -3.6f, ""};
Configurable<float> fMuonTaggingEtaMchUp{"cfgMuonTaggingEtaMchUp", -2.5f, ""};
Configurable<float> fMuonTaggingRabsLow{"cfgMuonTaggingRabsLow", 17.6f, ""};
Configurable<float> fMuonTaggingRabsUp{"cfgMuonTaggingRabsUp", 89.5f, ""};
Configurable<float> fMuonTaggingSigmaPdcaUp{"cfgMuonTaggingPdcaUp", 4.f, ""};
Configurable<float> fMuonTaggingChi2DiffLow{"cfgMuonTaggingChi2DiffLow", 100.f, ""};
/// Variables to event mixing criteria
Configurable<float> fSaveMixedMatchingParamsRate{"cfgSaveMixedMatchingParamsRate", 0.002f, ""};
Configurable<int> fEventMaxDeltaNMFT{"cfgEventMaxDeltaNMFT", 1, ""};
Configurable<float> fEventMaxDeltaVtxZ{"cfgEventMaxDeltaVtxZ", 1.f, ""};
Configurable<int> fEventMinDeltaBc{"cfgEventMinDeltaBc", 500, ""};
//// Variables for ccdb
Configurable<std::string> ccdburl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
Configurable<std::string> grpPath{"grpPath", "GLO/GRP/GRP", "Path of the grp file"};
Configurable<std::string> grpmagPath{"grpmagPath", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object"};
Configurable<std::string> geoPath{"geoPath", "GLO/Config/GeometryAligned", "Path of the geometry file"};
// CCDB connection configurables
struct : ConfigurableGroup {
Configurable<std::string> fConfigCcdbUrl{"ccdb-url-", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
Configurable<int64_t> fConfigNoLaterThan{"ccdb-no-later-than-", 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> fConfigGrpPath{"grpPath-", "GLO/GRP/GRP", "Path of the grp file"};
Configurable<std::string> fConfigGeoPath{"geoPath-", "GLO/Config/GeometryAligned", "Path of the geometry file"};
Configurable<std::string> fConfigGrpMagPath{"grpmagPath-", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object"};
} fConfigCCDB;
struct : ConfigurableGroup {
Configurable<bool> fCreatePdgMomHistograms{"cfgCreatePdgMomHistograms", false, "create matching characteristics plots with particle mom PDG codes"};
} fConfigQAs;
/// Variables for histograms configuration
Configurable<int> fNCandidatesMax{"nCandidatesMax", 5, ""};
double mBzAtMftCenter{0};
o2::globaltracking::MatchGlobalFwd mExtrap;
using MatchingFunc_t = std::function<std::tuple<double, int>(const o2::dataformats::GlobalFwdTrack& mchtrack, const o2::track::TrackParCovFwd& mfttrack)>;
std::map<std::string, MatchingFunc_t> mMatchingFunctionMap; ///< MFT-MCH Matching function
// Chi2 matching interface
static constexpr int sChi2FunctionsNum = 3;
struct : ConfigurableGroup {
std::array<Configurable<std::string>, sChi2FunctionsNum> fFunctionLabel{{
{"cfgChi2FunctionLabel_0", std::string{"ProdAll"}, "Text label identifying this chi2 matching method"},
{"cfgChi2FunctionLabel_1", std::string{"MatchXYPhiTanlMom"}, "Text label identifying this chi2 matching method"},
{"cfgChi2FunctionLabel_2", std::string{"MatchXYPhiTanl"}, "Text label identifying this chi2 matching method"},
}};
std::array<Configurable<std::string>, sChi2FunctionsNum> fFunctionName{{{"cfgChi2FunctionNames_0", std::string{"prod"}, "Name of the chi2 matching function"},
{"cfgChi2FunctionNames_1", std::string{"matchALL"}, "Name of the chi2 matching function"},
{"cfgChi2FunctionNames_2", std::string{"matchXYPhiTanl"}, "Name of the chi2 matching function"}}};
std::array<Configurable<float>, sChi2FunctionsNum> fMatchingScoreCut{{
{"cfgChi2FunctionMatchingScoreCut_0", 0.f, "Minimum score value for selecting good matches"},
{"cfgChi2FunctionMatchingScoreCut_1", 0.5f, "Minimum score value for selecting good matches"},
{"cfgChi2FunctionMatchingScoreCut_2", 0.5f, "Minimum score value for selecting good matches"},
}};
std::array<Configurable<float>, sChi2FunctionsNum> fMatchingPlaneZ{{
{"cfgChi2FunctionMatchingPlaneZ_0", static_cast<float>(o2::mft::constants::mft::LayerZCoordinate()[9]), "Z position of the matching plane"},
{"cfgChi2FunctionMatchingPlaneZ_1", static_cast<float>(o2::mft::constants::mft::LayerZCoordinate()[9]), "Z position of the matching plane"},
{"cfgChi2FunctionMatchingPlaneZ_2", static_cast<float>(o2::mft::constants::mft::LayerZCoordinate()[9]), "Z position of the matching plane"},
}};
std::array<Configurable<int>, sChi2FunctionsNum> fMatchingExtrapMethod{{
{"cfgMatchingExtrapMethod_0", static_cast<int>(0), "Method for MCH track extrapolation to maching plane"},
{"cfgMatchingExtrapMethod_1", static_cast<int>(0), "Method for MCH track extrapolation to maching plane"},
{"cfgMatchingExtrapMethod_2", static_cast<int>(0), "Method for MCH track extrapolation to maching plane"},
}};
} fConfigChi2MatchingOptions;
// ML interface
static constexpr int sMLModelsNum = 2;
struct : ConfigurableGroup {
std::array<Configurable<std::string>, sMLModelsNum> fModelLabel{{
{"cfgMLModelLabel_0", std::string{""}, "Text label identifying this group of ML models"},
{"cfgMLModelLabel_1", std::string{""}, "Text label identifying this group of ML models"},
}};
std::array<Configurable<std::vector<std::string>>, sMLModelsNum> fModelPathsCCDB{{{"cfgMLModelPathsCCDB_0", std::vector<std::string>{"Users/m/mcoquet/MLTest"}, "Paths of models on CCDB"},
{"cfgMLModelPathsCCDB_1", std::vector<std::string>{}, "Paths of models on CCDB"}}};
std::array<Configurable<std::vector<std::string>>, sMLModelsNum> fInputFeatures{{{"cfgMLInputFeatures_0", std::vector<std::string>{"chi2MCHMFT"}, "Names of ML model input features"},
{"cfgMLInputFeatures_1", std::vector<std::string>{}, "Names of ML model input features"}}};
std::array<Configurable<std::vector<std::string>>, sMLModelsNum> fModelNames{{{"cfgMLModelNames_0", std::vector<std::string>{"model.onnx"}, "ONNX file names for each pT bin (if not from CCDB full path)"},
{"cfgMLModelNames_1", std::vector<std::string>{}, "ONNX file names for each pT bin (if not from CCDB full path)"}}};
std::array<Configurable<float>, sMLModelsNum> fMatchingScoreCut{{
{"cfgMLModelMatchingScoreCut_0", 0.f, "Minimum score value for selecting good matches"},
{"cfgMLModelMatchingScoreCut_1", 0.f, "Minimum score value for selecting good matches"},
}};
std::array<Configurable<float>, sMLModelsNum> fMatchingPlaneZ{{
{"cfgMLModelMatchingPlaneZ_0", static_cast<float>(o2::mft::constants::mft::LayerZCoordinate()[9]), "Z position of the matching plane"},
{"cfgMLModelMatchingPlaneZ_1", 0.f, "Z position of the matching plane"},
}};
std::array<Configurable<int>, sMLModelsNum> fMatchingExtrapMethod{{
{"cfgMatchingExtrapMethod_0", static_cast<int>(0), "Method for MCH track extrapolation to maching plane"},
{"cfgMatchingExtrapMethod_1", static_cast<int>(0), "Method for MCH track extrapolation to maching plane"},
}};
} fConfigMlOptions;
std::vector<double> binsPtMl;
std::array<double, 1> cutValues;
std::vector<int> cutDirMl;
std::map<std::string, o2::analysis::MlResponseMFTMuonMatch<float>> matchingMlResponses;
std::map<std::string, std::string> matchingChi2Functions;
std::map<std::string, double> matchingPlanesZ;
std::map<std::string, double> matchingScoreCuts;
std::map<std::string, int> matchingExtrapMethod;
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;
o2::aod::rctsel::RCTFlagsChecker rctChecker{"CBT_muon_glo", false, false, true};
// 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>>;
struct CollisionInfo {
int64_t index{0};
uint64_t bc{0};
// z position of the collision
double zVertex{0};
// number of MFT tracks associated to the collision
int mftTracksMultiplicity{0};
// vector of MFT track indexes
std::vector<int64_t> mftTracks;
// vector of MCH(-MID) track indexes
std::vector<int64_t> mchTracks;
// matching candidates
MatchingCandidates matchingCandidates;
// vector of MFT-MCH track index pairs belonging to the same MC muon particle
std::vector<std::pair<int64_t, int64_t>> matchablePairs;
// vector of MCH track indexes that are expected to have an associated MFT track
std::vector<int64_t> taggedMuons;
};
using CollisionInfos = std::map<int64_t, CollisionInfo>;
std::unordered_map<int64_t, int32_t> mftTrackCovs;
std::vector<std::pair<int64_t, int64_t>> fMatchablePairs;
MatchingCandidates fMatchingCandidates;
std::vector<int64_t> fTaggedMuons;
using MuonPair = std::pair<std::pair<int64_t, uint64_t>, std::pair<int64_t, uint64_t>>;
using GlobalMuonPair = std::pair<std::pair<int64_t, std::vector<MatchingCandidate>>, std::pair<int64_t, std::vector<MatchingCandidate>>>;
HistogramRegistry registry{"registry", {}};
HistogramRegistry registryMatching{"registryMatching", {}};
HistogramRegistry registryMatching0{"registryMatching_0", {}};
HistogramRegistry registryMatching1{"registryMatching_1", {}};
HistogramRegistry registryMatching2{"registryMatching_2", {}};
HistogramRegistry registryMatching3{"registryMatching_3", {}};
HistogramRegistry registryMatching4{"registryMatching_4", {}};
HistogramRegistry registryMatching5{"registryMatching_5", {}};
HistogramRegistry registryMatching6{"registryMatching_6", {}};
HistogramRegistry registryMatching7{"registryMatching_7", {}};
HistogramRegistry registryMatching8{"registryMatching_8", {}};
HistogramRegistry registryMatching9{"registryMatching_9", {}};
std::vector<HistogramRegistry*> registryMatchingVec{{®istryMatching0,
®istryMatching1,
®istryMatching2,
®istryMatching3,
®istryMatching4,
®istryMatching5,
®istryMatching6,
®istryMatching7,
®istryMatching8,
®istryMatching9}};
HistogramRegistry registryDimuon{"registryDimuon", {}};
std::unordered_map<std::string, o2::framework::HistPtr> matchingHistos;
matrix<o2::framework::HistPtr, 4, 4> dimuonHistos;
struct EfficiencyPlotter {
o2::framework::HistPtr p_num;
o2::framework::HistPtr p_den;
o2::framework::HistPtr p_pdg_num;
o2::framework::HistPtr p_pdg_den;
o2::framework::HistPtr pt_num;
o2::framework::HistPtr pt_den;
o2::framework::HistPtr pt_pdg_num;
o2::framework::HistPtr pt_pdg_den;
o2::framework::HistPtr phi_num;
o2::framework::HistPtr phi_den;
o2::framework::HistPtr phi_pdg_num;
o2::framework::HistPtr phi_pdg_den;
o2::framework::HistPtr eta_num;
o2::framework::HistPtr eta_den;
o2::framework::HistPtr eta_pdg_num;
o2::framework::HistPtr eta_pdg_den;
EfficiencyPlotter(std::string path, std::string title,
HistogramRegistry& registry, bool createPdgMomHistograms)
{
AxisSpec pAxis = {100, 0, 100, "p (GeV/c)"};
AxisSpec pTAxis = {100, 0, 10, "p_{T} (GeV/c)"};
AxisSpec etaAxis = {100, -4, -2, "#eta"};
AxisSpec phiAxis = {90, -180, 180, "#phi (degrees)"};
AxisSpec motherPDGAxis{1201, -600.5, 600.5, "Direct mother PDG"};
std::string histName;
std::string histTitle;
// momentum dependence
histName = path + "p_num";
histTitle = title + " vs. p - num";
p_num = registry.add(histName.c_str(), histTitle.c_str(), {HistType::kTH1F, {pAxis}});
histName = path + "p_den";
histTitle = title + " vs. p - den";
p_den = registry.add(histName.c_str(), histTitle.c_str(), {HistType::kTH1F, {pAxis}});
if (createPdgMomHistograms) {
histName = path + "p_pdg_num";
histTitle = title + " vs. p vs pdg ID - num";
p_pdg_num = registry.add(histName.c_str(), histTitle.c_str(), {HistType::kTH2F, {pAxis, motherPDGAxis}});
histName = path + "p_pdg_den";
histTitle = title + " vs. p vs pdg ID - den";
p_pdg_den = registry.add(histName.c_str(), histTitle.c_str(), {HistType::kTH2F, {pAxis, motherPDGAxis}});
}
// pT dependence
histName = path + "pt_num";
histTitle = title + " vs. p_{T} - num";
pt_num = registry.add(histName.c_str(), histTitle.c_str(), {HistType::kTH1F, {pTAxis}});
histName = path + "pt_den";
histTitle = title + " vs. p_{T} - den";
pt_den = registry.add(histName.c_str(), histTitle.c_str(), {HistType::kTH1F, {pTAxis}});
if (createPdgMomHistograms) {
histName = path + "pt_pdg_num";
histTitle = title + " vs. p_{T} vs pdg ID - num";
pt_pdg_num = registry.add(histName.c_str(), histTitle.c_str(), {HistType::kTH2F, {pTAxis, motherPDGAxis}});
histName = path + "pt_pdg_den";
histTitle = title + " vs. p_{T} vs pdg ID - den";
pt_pdg_den = registry.add(histName.c_str(), histTitle.c_str(), {HistType::kTH2F, {pTAxis, motherPDGAxis}});
}
// eta dependence
histName = path + "eta_num";
histTitle = title + " vs. #eta - num";
eta_num = registry.add(histName.c_str(), histTitle.c_str(), {HistType::kTH1F, {etaAxis}});
histName = path + "eta_den";
histTitle = title + " vs. #eta - den";
eta_den = registry.add(histName.c_str(), histTitle.c_str(), {HistType::kTH1F, {etaAxis}});
if (createPdgMomHistograms) {
histName = path + "eta_pdg_num";
histTitle = title + " vs. #eta vs pdg ID - num";
eta_pdg_num = registry.add(histName.c_str(), histTitle.c_str(), {HistType::kTH2F, {etaAxis, motherPDGAxis}});
histName = path + "eta_pdg_den";
histTitle = title + " vs. #eta vs pdg ID - den";
eta_pdg_den = registry.add(histName.c_str(), histTitle.c_str(), {HistType::kTH2F, {etaAxis, motherPDGAxis}});
}
// phi dependence
histName = path + "phi_num";
histTitle = title + " vs. #phi - num";
phi_num = registry.add(histName.c_str(), histTitle.c_str(), {HistType::kTH1F, {phiAxis}});
histName = path + "phi_den";
histTitle = title + " vs. #phi - den";
phi_den = registry.add(histName.c_str(), histTitle.c_str(), {HistType::kTH1F, {phiAxis}});
if (createPdgMomHistograms) {
histName = path + "phi_pdg_num";
histTitle = title + " vs. #phi vs pdg ID - num";
phi_pdg_num = registry.add(histName.c_str(), histTitle.c_str(), {HistType::kTH2F, {phiAxis, motherPDGAxis}});
histName = path + "phi_pdg_den";
histTitle = title + " vs. #phi vs pdg ID - den";
phi_pdg_den = registry.add(histName.c_str(), histTitle.c_str(), {HistType::kTH2F, {phiAxis, motherPDGAxis}});
}
}
template <class T>
void Fill(const T& track, bool passed)
{
double phi = track.phi() * 180 / TMath::Pi();
std::get<std::shared_ptr<TH1>>(p_den)->Fill(track.p());
std::get<std::shared_ptr<TH1>>(pt_den)->Fill(track.pt());
std::get<std::shared_ptr<TH1>>(eta_den)->Fill(track.eta());
std::get<std::shared_ptr<TH1>>(phi_den)->Fill(phi);
if (passed) {
std::get<std::shared_ptr<TH1>>(p_num)->Fill(track.p());
std::get<std::shared_ptr<TH1>>(pt_num)->Fill(track.pt());
std::get<std::shared_ptr<TH1>>(eta_num)->Fill(track.eta());
std::get<std::shared_ptr<TH1>>(phi_num)->Fill(phi);
}
}
// Study the PDG origin of particles and their effect on the purity score
template <class T>
void Fill(const T& track, int pdgCode, bool passed)
{
double phi = track.phi() * 180 / TMath::Pi();
std::get<std::shared_ptr<TH2>>(p_pdg_den)->Fill(track.p(), pdgCode);
std::get<std::shared_ptr<TH2>>(pt_pdg_den)->Fill(track.pt(), pdgCode);
std::get<std::shared_ptr<TH2>>(eta_pdg_den)->Fill(track.eta(), pdgCode);
std::get<std::shared_ptr<TH2>>(phi_pdg_den)->Fill(phi, pdgCode);
if (passed) {
std::get<std::shared_ptr<TH2>>(p_pdg_num)->Fill(track.p(), pdgCode);
std::get<std::shared_ptr<TH2>>(pt_pdg_num)->Fill(track.pt(), pdgCode);
std::get<std::shared_ptr<TH2>>(eta_pdg_num)->Fill(track.eta(), pdgCode);
std::get<std::shared_ptr<TH2>>(phi_pdg_num)->Fill(phi, pdgCode);
}
}
};
struct MatchRankingHistos {
o2::framework::HistPtr hist;
o2::framework::HistPtr histVsP;
o2::framework::HistPtr histVsPt;
o2::framework::HistPtr histVsMcParticleDz;
o2::framework::HistPtr histVsMftTrackMult;
o2::framework::HistPtr histVsMftTrackType;
o2::framework::HistPtr histVsDeltaChi2;
o2::framework::HistPtr histVsProdRanking;
MatchRankingHistos(std::string histName, std::string histTitle, HistogramRegistry* registry)
{
AxisSpec pAxis = {100, 0, 100, "p (GeV/c)"};
AxisSpec ptAxis = {100, 0, 10, "p_{T} (GeV/c)"};
AxisSpec dzAxis = {100, 0, 50, "#Deltaz (cm)"};
AxisSpec trackMultAxis = {100, 0, 1000, "MFT track mult."};
AxisSpec trackTypeAxis = {2, 0, 2, "MFT track type"};
int matchTypeMax = static_cast<int>(kMatchTypeUndefined);
AxisSpec matchTypeAxis = {matchTypeMax, 0, static_cast<double>(matchTypeMax), "match type"};
AxisSpec dchi2Axis = {100, 0, 100, "#Delta#chi^{2}"};
AxisSpec dqAxis = {3, -1.5, 1.5, "MFT #DeltaQ"};
AxisSpec indexAxis = {6, 0, 6, "ranking index"};
AxisSpec indexProdAxis = {6, 0, 6, "ranking index (production)"};
hist = registry->add(histName.c_str(), histTitle.c_str(), {HistType::kTH1F, {indexAxis}});
histVsP = registry->add((histName + "VsP").c_str(), (histTitle + " vs. p").c_str(), {HistType::kTH2F, {pAxis, indexAxis}});
histVsPt = registry->add((histName + "VsPt").c_str(), (histTitle + " vs. p_{T}").c_str(), {HistType::kTH2F, {ptAxis, indexAxis}});
histVsMcParticleDz = registry->add((histName + "VsMcParticleDz").c_str(), (histTitle + " vs. MC particle #Deltaz").c_str(), {HistType::kTH2F, {dzAxis, indexAxis}});
histVsMftTrackMult = registry->add((histName + "VsMftTrackMult").c_str(), (histTitle + " vs. MFT track multiplicity").c_str(), {HistType::kTH2F, {trackMultAxis, indexAxis}});
histVsMftTrackType = registry->add((histName + "VsMftTrackType").c_str(), (histTitle + " vs. MFT track type").c_str(), {HistType::kTH2F, {trackTypeAxis, indexAxis}});
std::get<std::shared_ptr<TH2>>(histVsMftTrackType)->GetXaxis()->SetBinLabel(1, "Kalman");
std::get<std::shared_ptr<TH2>>(histVsMftTrackType)->GetXaxis()->SetBinLabel(2, "CA");
histVsDeltaChi2 = registry->add((histName + "VsDeltaChi2").c_str(), (histTitle + " vs. #Delta#chi^{2}").c_str(), {HistType::kTH2F, {dchi2Axis, indexAxis}});
histVsProdRanking = registry->add((histName + "VsProdRanking").c_str(), (histTitle + " vs. prod ranking").c_str(), {HistType::kTH2F, {indexProdAxis, indexAxis}});
}
};
struct MatchingPlotter {
std::unique_ptr<MatchRankingHistos> fMatchRanking;
std::unique_ptr<MatchRankingHistos> fMatchRankingGoodMCH;
std::unique_ptr<MatchRankingHistos> fMatchRankingPaired;
std::unique_ptr<MatchRankingHistos> fMatchRankingPairedGoodMCH;
//-
o2::framework::HistPtr fMissedMatches;
o2::framework::HistPtr fMissedMatchesGoodMCH;
//-
o2::framework::HistPtr fMatchRankingWrtProd;
o2::framework::HistPtr fMatchRankingWrtProdVsP;
o2::framework::HistPtr fMatchRankingWrtProdVsPt;
//-
o2::framework::HistPtr fDecayRankingGoodMatches;
o2::framework::HistPtr fDecayRankingNonLeadingMatches;
o2::framework::HistPtr fDecayRankingMissedMatches;
//-
o2::framework::HistPtr fScoreGapLeadingTrueMatches;
o2::framework::HistPtr fScoreGapNonLeadingTrueMatches;
//-
o2::framework::HistPtr fMatchType;
o2::framework::HistPtr fMatchTypeVsP;
o2::framework::HistPtr fMatchTypeVsPt;
//-
o2::framework::HistPtr fMatchScoreVsType;
o2::framework::HistPtr fMatchScoreVsTypeVsP;
o2::framework::HistPtr fMatchScoreVsTypeVsPt;
//-
o2::framework::HistPtr fMatchChi2VsType;
o2::framework::HistPtr fMatchChi2VsTypeVsP;
o2::framework::HistPtr fMatchChi2VsTypeVsPt;
//-
o2::framework::HistPtr fMatchScoreVsProd;
o2::framework::HistPtr fMatchChi2VsProd;
o2::framework::HistPtr fTrueMatchScoreVsProd;
o2::framework::HistPtr fTrueMatchChi2VsProd;
//-
EfficiencyPlotter fMatchingPurityPlotter;
EfficiencyPlotter fPairingEfficiencyPlotter;
EfficiencyPlotter fMatchingEfficiencyPlotter;
EfficiencyPlotter fFakeMatchingEfficiencyPlotter;
HistogramRegistry* registry;
MatchingPlotter(std::string path,
HistogramRegistry* reg, bool createPdgMomHistograms)
: fMatchingPurityPlotter(path + "matching-purity/", "Matching purity", *reg, createPdgMomHistograms),
fPairingEfficiencyPlotter(path + "pairing-efficiency/", "Pairing efficiency", *reg, createPdgMomHistograms),
fMatchingEfficiencyPlotter(path + "matching-efficiency/", "Matching efficiency", *reg, createPdgMomHistograms),
fFakeMatchingEfficiencyPlotter(path + "fake-matching-efficiency/", "Fake matching efficiency", *reg, createPdgMomHistograms)
{
registry = reg;
AxisSpec pAxis = {100, 0, 100, "p (GeV/c)"};
AxisSpec ptAxis = {100, 0, 10, "p_{T} (GeV/c)"};
AxisSpec dzAxis = {100, 0, 50, "#Deltaz (cm)"};
AxisSpec indexAxis = {6, 0, 6, "ranking index"};
std::string histName = path + "matchRanking";
std::string histTitle = "True match ranking";
fMatchRanking = std::make_unique<MatchRankingHistos>(path + "matchRanking", "True match ranking", registry);
fMatchRankingGoodMCH = std::make_unique<MatchRankingHistos>(path + "matchRankingGoodMCH", "True match ranking (good MCH tracks)", registry);
fMatchRankingPaired = std::make_unique<MatchRankingHistos>(path + "matchRankingPaired", "True match ranking (paired MCH tracks)", registry);
fMatchRankingPairedGoodMCH = std::make_unique<MatchRankingHistos>(path + "matchRankingPairedGoodMCH", "True match ranking (good paired MCH tracks)", registry);
//-
AxisSpec missedMatchAxis = {5, 0, 5, ""};
histName = path + "missedMatches";
histTitle = "Missed matches";
fMissedMatches = registry->add(histName.c_str(), histTitle.c_str(), {HistType::kTH1F, {missedMatchAxis}});
std::get<std::shared_ptr<TH1>>(fMissedMatches)->GetXaxis()->SetBinLabel(1, "not paired");
std::get<std::shared_ptr<TH1>>(fMissedMatches)->GetXaxis()->SetBinLabel(2, "fake MCH");
std::get<std::shared_ptr<TH1>>(fMissedMatches)->GetXaxis()->SetBinLabel(3, "not stored");
histName = path + "missedMatchesGoodMCH";
histTitle = "Missed matches - good MCH tracks";
fMissedMatchesGoodMCH = registry->add(histName.c_str(), histTitle.c_str(), {HistType::kTH1F, {missedMatchAxis}});
std::get<std::shared_ptr<TH1>>(fMissedMatchesGoodMCH)->GetXaxis()->SetBinLabel(1, "not paired");
std::get<std::shared_ptr<TH1>>(fMissedMatchesGoodMCH)->GetXaxis()->SetBinLabel(2, "fake MCH");
std::get<std::shared_ptr<TH1>>(fMissedMatchesGoodMCH)->GetXaxis()->SetBinLabel(3, "not stored");
AxisSpec decayRankingAxis = {5, 0, 5, "decay ranking"};
histName = path + "decayRankingGoodMatches";
histTitle = "Decay ranking - good matches";
fDecayRankingGoodMatches = registry->add(histName.c_str(), histTitle.c_str(), {HistType::kTH1F, {decayRankingAxis}});
histName = path + "decayRankingNonLeadingMatches";
histTitle = "Decay ranking - non-leading matches";
fDecayRankingNonLeadingMatches = registry->add(histName.c_str(), histTitle.c_str(), {HistType::kTH1F, {decayRankingAxis}});
histName = path + "decayRankingMissedMatches";
histTitle = "Decay ranking - missed matches";
fDecayRankingMissedMatches = registry->add(histName.c_str(), histTitle.c_str(), {HistType::kTH1F, {decayRankingAxis}});
AxisSpec scoreGapAxis = {100, 0, 1, "match score difference"};
histName = path + "scoreGapLeadingTrueMatches";
histTitle = "Score gap between leading and subleading matches - good matches";
fScoreGapLeadingTrueMatches = registry->add(histName.c_str(), histTitle.c_str(), {HistType::kTH1F, {scoreGapAxis}});
histName = path + "scoreGapNonLeadingTrueMatches";
histTitle = "Score gap between leading and subleading matches - non-leading matches";
fScoreGapNonLeadingTrueMatches = registry->add(histName.c_str(), histTitle.c_str(), {HistType::kTH1F, {scoreGapAxis}});
//-
AxisSpec chi2Axis = {100, 0, 100, "matching #chi^{2}/NDF"};
AxisSpec scoreAxis = {100, 0, 1, "matching score"};
int matchTypeMax = static_cast<int>(kMatchTypeUndefined);
AxisSpec matchTypeAxis = {matchTypeMax, 0, static_cast<double>(matchTypeMax), "match type"};
histName = path + "matchType";
histTitle = "Match type";
fMatchType = registry->add(histName.c_str(), histTitle.c_str(), {HistType::kTH1F, {matchTypeAxis}});
std::get<std::shared_ptr<TH1>>(fMatchType)->GetXaxis()->SetBinLabel(1, "true (leading)");
std::get<std::shared_ptr<TH1>>(fMatchType)->GetXaxis()->SetBinLabel(2, "wrong (leading)");
std::get<std::shared_ptr<TH1>>(fMatchType)->GetXaxis()->SetBinLabel(3, "decay (leading)");
std::get<std::shared_ptr<TH1>>(fMatchType)->GetXaxis()->SetBinLabel(4, "fake (leading)");
std::get<std::shared_ptr<TH1>>(fMatchType)->GetXaxis()->SetBinLabel(5, "true (non leading)");
std::get<std::shared_ptr<TH1>>(fMatchType)->GetXaxis()->SetBinLabel(6, "wrong (non leading)");
std::get<std::shared_ptr<TH1>>(fMatchType)->GetXaxis()->SetBinLabel(7, "decay (non leading)");
std::get<std::shared_ptr<TH1>>(fMatchType)->GetXaxis()->SetBinLabel(8, "fake (non leading)");
histName = path + "matchTypeVsP";
histTitle = "Match type vs. p";
fMatchTypeVsP = registry->add(histName.c_str(), histTitle.c_str(), {HistType::kTH2F, {pAxis, matchTypeAxis}});
std::get<std::shared_ptr<TH2>>(fMatchTypeVsP)->GetYaxis()->SetBinLabel(1, "true (leading)");
std::get<std::shared_ptr<TH2>>(fMatchTypeVsP)->GetYaxis()->SetBinLabel(2, "wrong (leading)");
std::get<std::shared_ptr<TH2>>(fMatchTypeVsP)->GetYaxis()->SetBinLabel(3, "decay (leading)");
std::get<std::shared_ptr<TH2>>(fMatchTypeVsP)->GetYaxis()->SetBinLabel(4, "fake (leading)");
std::get<std::shared_ptr<TH2>>(fMatchTypeVsP)->GetYaxis()->SetBinLabel(5, "true (non leading)");
std::get<std::shared_ptr<TH2>>(fMatchTypeVsP)->GetYaxis()->SetBinLabel(6, "wrong (non leading)");
std::get<std::shared_ptr<TH2>>(fMatchTypeVsP)->GetYaxis()->SetBinLabel(7, "decay (non leading)");
std::get<std::shared_ptr<TH2>>(fMatchTypeVsP)->GetYaxis()->SetBinLabel(8, "fake (non leading)");
histName = path + "matchTypeVsPt";
histTitle = "Match type vs. p_{T}";
fMatchTypeVsPt = registry->add(histName.c_str(), histTitle.c_str(), {HistType::kTH2F, {ptAxis, matchTypeAxis}});
std::get<std::shared_ptr<TH2>>(fMatchTypeVsPt)->GetYaxis()->SetBinLabel(1, "true (leading)");
std::get<std::shared_ptr<TH2>>(fMatchTypeVsPt)->GetYaxis()->SetBinLabel(2, "wrong (leading)");
std::get<std::shared_ptr<TH2>>(fMatchTypeVsPt)->GetYaxis()->SetBinLabel(3, "decay (leading)");
std::get<std::shared_ptr<TH2>>(fMatchTypeVsPt)->GetYaxis()->SetBinLabel(4, "fake (leading)");
std::get<std::shared_ptr<TH2>>(fMatchTypeVsPt)->GetYaxis()->SetBinLabel(5, "true (non leading)");
std::get<std::shared_ptr<TH2>>(fMatchTypeVsPt)->GetYaxis()->SetBinLabel(6, "wrong (non leading)");
std::get<std::shared_ptr<TH2>>(fMatchTypeVsPt)->GetYaxis()->SetBinLabel(7, "decay (non leading)");
std::get<std::shared_ptr<TH2>>(fMatchTypeVsPt)->GetYaxis()->SetBinLabel(8, "fake (non leading)");
histName = path + "matchChi2VsType";
histTitle = "Match #chi^{2} vs. match type";
fMatchChi2VsType = registry->add(histName.c_str(), histTitle.c_str(), {HistType::kTH2F, {matchTypeAxis, chi2Axis}});
std::get<std::shared_ptr<TH2>>(fMatchChi2VsType)->GetXaxis()->SetBinLabel(1, "true (leading)");
std::get<std::shared_ptr<TH2>>(fMatchChi2VsType)->GetXaxis()->SetBinLabel(2, "wrong (leading)");
std::get<std::shared_ptr<TH2>>(fMatchChi2VsType)->GetXaxis()->SetBinLabel(3, "decay (leading)");
std::get<std::shared_ptr<TH2>>(fMatchChi2VsType)->GetXaxis()->SetBinLabel(4, "fake (leading)");
std::get<std::shared_ptr<TH2>>(fMatchChi2VsType)->GetXaxis()->SetBinLabel(5, "true (non leading)");
std::get<std::shared_ptr<TH2>>(fMatchChi2VsType)->GetXaxis()->SetBinLabel(6, "wrong (non leading)");
std::get<std::shared_ptr<TH2>>(fMatchChi2VsType)->GetXaxis()->SetBinLabel(7, "decay (non leading)");
std::get<std::shared_ptr<TH2>>(fMatchChi2VsType)->GetXaxis()->SetBinLabel(8, "fake (non leading)");
histName = path + "matchChi2VsTypeVsP";
histTitle = "Match #chi^{2} vs. match type vs. p";
fMatchChi2VsTypeVsP = registry->add(histName.c_str(), histTitle.c_str(), {HistType::kTH3F, {pAxis, matchTypeAxis, chi2Axis}});
std::get<std::shared_ptr<TH3>>(fMatchChi2VsTypeVsP)->GetYaxis()->SetBinLabel(1, "true (leading)");
std::get<std::shared_ptr<TH3>>(fMatchChi2VsTypeVsP)->GetYaxis()->SetBinLabel(2, "wrong (leading)");
std::get<std::shared_ptr<TH3>>(fMatchChi2VsTypeVsP)->GetYaxis()->SetBinLabel(3, "decay (leading)");
std::get<std::shared_ptr<TH3>>(fMatchChi2VsTypeVsP)->GetYaxis()->SetBinLabel(4, "fake (leading)");
std::get<std::shared_ptr<TH3>>(fMatchChi2VsTypeVsP)->GetYaxis()->SetBinLabel(5, "true (non leading)");
std::get<std::shared_ptr<TH3>>(fMatchChi2VsTypeVsP)->GetYaxis()->SetBinLabel(6, "wrong (non leading)");
std::get<std::shared_ptr<TH3>>(fMatchChi2VsTypeVsP)->GetYaxis()->SetBinLabel(7, "decay (non leading)");
std::get<std::shared_ptr<TH3>>(fMatchChi2VsTypeVsP)->GetYaxis()->SetBinLabel(8, "fake (non leading)");
histName = path + "matchChi2VsTypeVsPt";
histTitle = "Match #chi^{2} vs. match type vs. p_{T}";
fMatchChi2VsTypeVsPt = registry->add(histName.c_str(), histTitle.c_str(), {HistType::kTH3F, {ptAxis, matchTypeAxis, chi2Axis}});
std::get<std::shared_ptr<TH3>>(fMatchChi2VsTypeVsPt)->GetYaxis()->SetBinLabel(1, "true (leading)");
std::get<std::shared_ptr<TH3>>(fMatchChi2VsTypeVsPt)->GetYaxis()->SetBinLabel(2, "wrong (leading)");
std::get<std::shared_ptr<TH3>>(fMatchChi2VsTypeVsPt)->GetYaxis()->SetBinLabel(3, "decay (leading)");
std::get<std::shared_ptr<TH3>>(fMatchChi2VsTypeVsPt)->GetYaxis()->SetBinLabel(4, "fake (leading)");
std::get<std::shared_ptr<TH3>>(fMatchChi2VsTypeVsPt)->GetYaxis()->SetBinLabel(5, "true (non leading)");
std::get<std::shared_ptr<TH3>>(fMatchChi2VsTypeVsPt)->GetYaxis()->SetBinLabel(6, "wrong (non leading)");
std::get<std::shared_ptr<TH3>>(fMatchChi2VsTypeVsPt)->GetYaxis()->SetBinLabel(7, "decay (non leading)");
std::get<std::shared_ptr<TH3>>(fMatchChi2VsTypeVsPt)->GetYaxis()->SetBinLabel(8, "fake (non leading)");
//-
histName = path + "matchScoreVsType";
histTitle = "Match score vs. match type";
fMatchScoreVsType = registry->add(histName.c_str(), histTitle.c_str(), {HistType::kTH2F, {matchTypeAxis, scoreAxis}});
std::get<std::shared_ptr<TH2>>(fMatchScoreVsType)->GetXaxis()->SetBinLabel(1, "true (leading)");
std::get<std::shared_ptr<TH2>>(fMatchScoreVsType)->GetXaxis()->SetBinLabel(2, "wrong (leading)");
std::get<std::shared_ptr<TH2>>(fMatchScoreVsType)->GetXaxis()->SetBinLabel(3, "decay (leading)");
std::get<std::shared_ptr<TH2>>(fMatchScoreVsType)->GetXaxis()->SetBinLabel(4, "fake (leading)");
std::get<std::shared_ptr<TH2>>(fMatchScoreVsType)->GetXaxis()->SetBinLabel(5, "true (non leading)");
std::get<std::shared_ptr<TH2>>(fMatchScoreVsType)->GetXaxis()->SetBinLabel(6, "wrong (non leading)");
std::get<std::shared_ptr<TH2>>(fMatchScoreVsType)->GetXaxis()->SetBinLabel(7, "decay (non leading)");
std::get<std::shared_ptr<TH2>>(fMatchScoreVsType)->GetXaxis()->SetBinLabel(8, "fake (non leading)");
histName = path + "matchScoreVsTypeVsP";
histTitle = "Match score vs. match type vs. p";
fMatchScoreVsTypeVsP = registry->add(histName.c_str(), histTitle.c_str(), {HistType::kTH3F, {pAxis, matchTypeAxis, scoreAxis}});
std::get<std::shared_ptr<TH3>>(fMatchScoreVsTypeVsP)->GetYaxis()->SetBinLabel(1, "true (leading)");
std::get<std::shared_ptr<TH3>>(fMatchScoreVsTypeVsP)->GetYaxis()->SetBinLabel(2, "wrong (leading)");
std::get<std::shared_ptr<TH3>>(fMatchScoreVsTypeVsP)->GetYaxis()->SetBinLabel(3, "decay (leading)");
std::get<std::shared_ptr<TH3>>(fMatchScoreVsTypeVsP)->GetYaxis()->SetBinLabel(4, "fake (leading)");
std::get<std::shared_ptr<TH3>>(fMatchScoreVsTypeVsP)->GetYaxis()->SetBinLabel(5, "true (non leading)");
std::get<std::shared_ptr<TH3>>(fMatchScoreVsTypeVsP)->GetYaxis()->SetBinLabel(6, "wrong (non leading)");
std::get<std::shared_ptr<TH3>>(fMatchScoreVsTypeVsP)->GetYaxis()->SetBinLabel(7, "decay (non leading)");
std::get<std::shared_ptr<TH3>>(fMatchScoreVsTypeVsP)->GetYaxis()->SetBinLabel(8, "fake (non leading)");
histName = path + "matchScoreVsTypeVsPt";
histTitle = "Match score vs. match type vs. p_{T}";
fMatchScoreVsTypeVsPt = registry->add(histName.c_str(), histTitle.c_str(), {HistType::kTH3F, {ptAxis, matchTypeAxis, scoreAxis}});
std::get<std::shared_ptr<TH3>>(fMatchScoreVsTypeVsPt)->GetYaxis()->SetBinLabel(1, "true (leading)");
std::get<std::shared_ptr<TH3>>(fMatchScoreVsTypeVsPt)->GetYaxis()->SetBinLabel(2, "wrong (leading)");
std::get<std::shared_ptr<TH3>>(fMatchScoreVsTypeVsPt)->GetYaxis()->SetBinLabel(3, "decay (leading)");
std::get<std::shared_ptr<TH3>>(fMatchScoreVsTypeVsPt)->GetYaxis()->SetBinLabel(4, "fake (leading)");
std::get<std::shared_ptr<TH3>>(fMatchScoreVsTypeVsPt)->GetYaxis()->SetBinLabel(5, "true (non leading)");
std::get<std::shared_ptr<TH3>>(fMatchScoreVsTypeVsPt)->GetYaxis()->SetBinLabel(6, "wrong (non leading)");
std::get<std::shared_ptr<TH3>>(fMatchScoreVsTypeVsPt)->GetYaxis()->SetBinLabel(7, "decay (non leading)");
std::get<std::shared_ptr<TH3>>(fMatchScoreVsTypeVsPt)->GetYaxis()->SetBinLabel(8, "fake (non leading)");
AxisSpec prodScoreAxis = {100, 0, 1, "matching score (prod)"};
histName = path + "matchScoreVsProd";
histTitle = "Match score vs. production";
fMatchScoreVsProd = registry->add(histName.c_str(), histTitle.c_str(), {HistType::kTH2F, {prodScoreAxis, scoreAxis}});
histName = path + "trueMatchScoreVsProd";
histTitle = "Match score vs. production - true match";
fTrueMatchScoreVsProd = registry->add(histName.c_str(), histTitle.c_str(), {HistType::kTH2F, {prodScoreAxis, scoreAxis}});
AxisSpec prodChi2Axis = {100, 0, 100, "matching #chi^{2}/NDF (prod)"};
histName = path + "matchChi2VsProd";
histTitle = "Match #chi^{2} vs. production";
fMatchChi2VsProd = registry->add(histName.c_str(), histTitle.c_str(), {HistType::kTH2F, {prodChi2Axis, chi2Axis}});
histName = path + "trueMatchChi2VsProd";
histTitle = "Match #chi^{2} vs. production - true match";
fTrueMatchChi2VsProd = registry->add(histName.c_str(), histTitle.c_str(), {HistType::kTH2F, {{100, 0, 10, "matching #chi^{2} (prod)"}, {100, 0, 10, "matching #chi^{2}"}}});
}
};
std::unique_ptr<MatchingPlotter> fChi2MatchingPlotter;
std::map<std::string, std::unique_ptr<HistogramRegistry>> fMatchingHistogramRegistries;
std::map<std::string, std::unique_ptr<MatchingPlotter>> fMatchingPlotters;
std::unique_ptr<MatchingPlotter> fTaggedMuonsMatchingPlotter;
std::unique_ptr<MatchingPlotter> fSelectedMuonsMatchingPlotter;
CollisionInfos fCollisionInfos;
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>(grpmagPath, metadata, ts);
o2::base::Propagator::initFieldFromGRP(grpmag);
LOGF(info, "Set field for muons");
VarManager::SetupMuonMagField();
if (!o2::base::GeometryManager::isGeometryLoaded()) {
ccdbManager->get<TGeoManager>(geoPath);
}
o2::mch::TrackExtrap::setField();
auto* fieldB = static_cast<o2::field::MagneticField*>(TGeoGlobalMagField::Instance()->GetField());
if (fieldB) {
double centerMFT[3] = {0, 0, -61.4}; // Field at center of MFT
mBzAtMftCenter = fieldB->getBz(centerMFT);
// std::cout << "fieldB: " << (void*)fieldB << std::endl;
}
}
void CreateMatchingHistosMC()
{
AxisSpec chi2Axis = {1000, 0, 1000, "chi^{2}"};
AxisSpec chi2AxisSmall = {200, 0, 100, "chi^{2}"};
AxisSpec pAxis = {1000, 0, 100, "p (GeV/c)"};
AxisSpec pTAxis = {100, 0, 10, "p_{T} (GeV/c)"};
AxisSpec etaAxis = {100, -4, -2, "#eta"};
AxisSpec phiAxis = {90, -180, 180, "#phi (degrees)"};
std::string histPath = "matching/MC/";
AxisSpec trackPositionXAtMFTAxis = {100, -15, 15, "MFT x (cm)"};
AxisSpec trackPositionYAtMFTAxis = {100, -15, 15, "MFT y (cm)"};
registry.add((histPath + "pairedMCHTracksAtMFT").c_str(), "Paired MCH tracks position at MFT end", {HistType::kTH2F, {trackPositionXAtMFTAxis, trackPositionYAtMFTAxis}});
registry.add((histPath + "pairedMFTTracksAtMFT").c_str(), "Paired MFT tracks position at MFT end", {HistType::kTH2F, {trackPositionXAtMFTAxis, trackPositionYAtMFTAxis}});
registry.add((histPath + "selectedMCHTracksAtMFT").c_str(), "Selected MCH tracks position at MFT end", {HistType::kTH2F, {trackPositionXAtMFTAxis, trackPositionYAtMFTAxis}});
registry.add((histPath + "selectedMCHTracksAtMFTTrue").c_str(), "Selected MCH tracks position at MFT end - true", {HistType::kTH2F, {trackPositionXAtMFTAxis, trackPositionYAtMFTAxis}});
registry.add((histPath + "selectedMCHTracksAtMFTFake").c_str(), "Selected MCH tracks position at MFT end - fake", {HistType::kTH2F, {trackPositionXAtMFTAxis, trackPositionYAtMFTAxis}});
fChi2MatchingPlotter = std::make_unique<MatchingPlotter>(histPath + "Prod/", ®istryMatching, fConfigQAs.fCreatePdgMomHistograms);
int registryIndex = 0;
for (const auto& [label, func] : matchingChi2Functions) {
fMatchingPlotters[label] = std::make_unique<MatchingPlotter>(histPath + label + "/", registryMatchingVec[registryIndex], fConfigQAs.fCreatePdgMomHistograms);
registryIndex += 1;
}
for (const auto& [label, response] : matchingMlResponses) {
fMatchingPlotters[label] = std::make_unique<MatchingPlotter>(histPath + label + "/", (registryMatchingVec[registryIndex]), fConfigQAs.fCreatePdgMomHistograms);
registryIndex += 1;
}
fTaggedMuonsMatchingPlotter = std::make_unique<MatchingPlotter>(histPath + "Tagged/", ®istryMatching, fConfigQAs.fCreatePdgMomHistograms);
fSelectedMuonsMatchingPlotter = std::make_unique<MatchingPlotter>(histPath + "Selected/", ®istryMatching, fConfigQAs.fCreatePdgMomHistograms);
}
void CreateDimuonHistos()
{
AxisSpec invMassAxis = {400, 1, 5, "M_{#mu^{+}#mu^{-}} (GeV/c^{2})"};
AxisSpec invMassCorrelationAxis = {400, 0, 8, "M_{#mu^{+}#mu^{-}} (GeV/c^{2})"};
AxisSpec invMassAxisFull = {5000, 0, 100, "M_{#mu^{+}#mu^{-}} (GeV/c^{2})"};
int matchTypeCombMax = (static_cast<int>(kMatchTypeTrueNonLeading) - 1) * 10 + static_cast<int>(kMatchTypeTrueNonLeading) - 1;
AxisSpec matchTypeAxis = {matchTypeCombMax + 1, 0, static_cast<double>(matchTypeCombMax + 1), "match type"};
// MCH-MID tracks with MCH acceptance cuts
registryDimuon.add("dimuon/invariantMass_MuonKine_MuonCuts", "#mu^{+}#mu^{-} invariant mass (muon cuts)", {HistType::kTH1F, {invMassAxis}});
// MCH-MID tracks with MFT acceptance cuts
registryDimuon.add("dimuon/invariantMass_MuonKine_GlobalMuonCuts", "#mu^{+}#mu^{-} invariant mass (global muon cuts)", {HistType::kTH1F, {invMassAxis}});
// MCH-MID tracks with MFT acceptance cuts vs. muon tracks match type
registryDimuon.add("dimuon/MC/invariantMass_MuonKine_GlobalMuonCuts_vs_match_type", "#mu^{+}#mu^{-} invariant mass vs. match tye (global muon cuts)", {HistType::kTH2F, {invMassAxis, matchTypeAxis}});
// MCH-MID tracks with MFT acceptance cuts, good matches
registryDimuon.add("dimuon/invariantMass_MuonKine_GlobalMuonCuts_GoodMatches", "#mu^{+}#mu^{-} invariant mass (global muon cuts, good matches)", {HistType::kTH1F, {invMassAxis}});
// MCH-MID tracks with MFT acceptance cuts, good matches + paired muons
registryDimuon.add("dimuon/MC/invariantMass_MuonKine_GlobalMuonCuts_GoodMatches_vs_match_type", "#mu^{+}#mu^{-} invariant mass vs. match tye (global muon cuts, good matches)", {HistType::kTH2F, {invMassAxis, matchTypeAxis}});
// scaled kinematics (Hiroshima method)
// MFT-MCH-MID tracks with MFT acceptance cuts
registryDimuon.add("dimuon/invariantMass_ScaledMftKine_GlobalMuonCuts", "#mu^{+}#mu^{-} invariant mass (global muon cuts, rescaled MFT)", {HistType::kTH1F, {invMassAxis}});
// MCH-MID tracks with MFT acceptance cuts vs. muon tracks match type
registryDimuon.add("dimuon/MC/invariantMass_ScaledMftKine_GlobalMuonCuts_vs_match_type", "#mu^{+}#mu^{-} invariant mass vs. match tye (global muon cuts, rescaled MFT)", {HistType::kTH2F, {invMassAxis, matchTypeAxis}});
// MFT-MCH-MID tracks with MFT acceptance cuts, good matches
registryDimuon.add("dimuon/invariantMass_ScaledMftKine_GlobalMuonCuts_GoodMatches", "#mu^{+}#mu^{-} invariant mass (global muon cuts, rescaled MFT, good matches)", {HistType::kTH1F, {invMassAxis}});
// MFT-MCH-MID tracks with MFT acceptance cuts vs. muon tracks match type, good matches
registryDimuon.add("dimuon/MC/invariantMass_ScaledMftKine_GlobalMuonCuts_GoodMatches_vs_match_type", "#mu^{+}#mu^{-} invariant mass vs. match tye (global muon cuts, rescaled MFT, good matches)", {HistType::kTH2F, {invMassAxis, matchTypeAxis}});
}
void InitMatchingFunctions()
{
using SMatrix55Std = ROOT::Math::SMatrix<double, 5>;
using SMatrix55Sym = ROOT::Math::SMatrix<double, 5, 5, ROOT::Math::MatRepSym<double, 5>>;
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::dataformats::GlobalFwdTrack& mchTrack, const o2::track::TrackParCovFwd& mftTrack) -> std::tuple<double, int> {
// Match two tracks evaluating all parameters: X,Y, phi, tanl & q/pt
SMatrix55Sym H_k, V_k;
SVector5 m_k(mftTrack.getX(), mftTrack.getY(), mftTrack.getPhi(),
mftTrack.getTanl(), mftTrack.getInvQPt()),
r_k_kminus1;
SVector5 GlobalMuonTrackParameters = mchTrack.getParameters();
SMatrix55Sym GlobalMuonTrackCovariances = mchTrack.getCovariances();
V_k(0, 0) = mftTrack.getCovariances()(0, 0);
V_k(1, 1) = mftTrack.getCovariances()(1, 1);
V_k(2, 2) = mftTrack.getCovariances()(2, 2);
V_k(3, 3) = mftTrack.getCovariances()(3, 3);
V_k(4, 4) = mftTrack.getCovariances()(4, 4);
H_k(0, 0) = 1.0;
H_k(1, 1) = 1.0;
H_k(2, 2) = 1.0;
H_k(3, 3) = 1.0;
H_k(4, 4) = 1.0;
// Covariance of residuals
SMatrix55Std invResCov = (V_k + ROOT::Math::Similarity(H_k, GlobalMuonTrackCovariances));
invResCov.Invert();
// Update Parameters
r_k_kminus1 = m_k - H_k * GlobalMuonTrackParameters; // Residuals of prediction
auto matchChi2Track = ROOT::Math::Similarity(r_k_kminus1, invResCov);
// return chi2 and NDF
return {matchChi2Track, 5};
};
//________________________________________________________________________________
mMatchingFunctionMap["matchXYPhiTanl"] = [](const o2::dataformats::GlobalFwdTrack& mchTrack, const o2::track::TrackParCovFwd& mftTrack) -> std::tuple<double, int> {
// Match two tracks evaluating positions & angles
SMatrix45 H_k;
SMatrix44 V_k;
SVector4 m_k(mftTrack.getX(), mftTrack.getY(), mftTrack.getPhi(),
mftTrack.getTanl()),
r_k_kminus1;
SVector5 GlobalMuonTrackParameters = mchTrack.getParameters();
SMatrix55Sym GlobalMuonTrackCovariances = mchTrack.getCovariances();
V_k(0, 0) = mftTrack.getCovariances()(0, 0);
V_k(1, 1) = mftTrack.getCovariances()(1, 1);
V_k(2, 2) = mftTrack.getCovariances()(2, 2);
V_k(3, 3) = mftTrack.getCovariances()(3, 3);
H_k(0, 0) = 1.0;
H_k(1, 1) = 1.0;
H_k(2, 2) = 1.0;
H_k(3, 3) = 1.0;
// Covariance of residuals
SMatrix44 invResCov = (V_k + ROOT::Math::Similarity(H_k, GlobalMuonTrackCovariances));
invResCov.Invert();
// Residuals of prediction
r_k_kminus1 = m_k - H_k * GlobalMuonTrackParameters;
auto matchChi2Track = ROOT::Math::Similarity(r_k_kminus1, invResCov);
// return chi2 and NDF
return {matchChi2Track, 4};
};
//________________________________________________________________________________
mMatchingFunctionMap["matchXY"] = [](const o2::dataformats::GlobalFwdTrack& mchTrack, const o2::track::TrackParCovFwd& mftTrack) -> std::tuple<double, int> {
// Calculate Matching Chi2 - X and Y positions
SMatrix25 H_k;
SMatrix22 V_k;
SVector2 m_k(mftTrack.getX(), mftTrack.getY()), r_k_kminus1;
SVector5 GlobalMuonTrackParameters = mchTrack.getParameters();
SMatrix55Sym GlobalMuonTrackCovariances = mchTrack.getCovariances();
V_k(0, 0) = mftTrack.getCovariances()(0, 0);
V_k(1, 1) = mftTrack.getCovariances()(1, 1);
H_k(0, 0) = 1.0;
H_k(1, 1) = 1.0;
// Covariance of residuals
SMatrix22 invResCov = (V_k + ROOT::Math::Similarity(H_k, GlobalMuonTrackCovariances));
invResCov.Invert();
// Residuals of prediction
r_k_kminus1 = m_k - H_k * GlobalMuonTrackParameters;
auto matchChi2Track = ROOT::Math::Similarity(r_k_kminus1, invResCov);
// return reduced chi2
return {matchChi2Track, 2};
};
}
void init(o2::framework::InitContext&)
{
// Load geometry
ccdbManager->setURL(ccdburl);
ccdbManager->setCaching(true);
ccdbManager->setLocalObjectValidityChecking();
fCCDBApi.init(ccdburl);
mRunNumber = 0;
if (!o2::base::GeometryManager::isGeometryLoaded()) {
LOGF(info, "Load geometry from CCDB");
ccdbManager->get<TGeoManager>(geoPath);
}
// Matching functions
InitMatchingFunctions();
for (size_t funcId = 0; funcId < sChi2FunctionsNum; funcId++) {
auto label = fConfigChi2MatchingOptions.fFunctionLabel[funcId].value;
auto funcName = fConfigChi2MatchingOptions.fFunctionName[funcId].value;
auto scoreMin = fConfigChi2MatchingOptions.fMatchingScoreCut[funcId].value;
auto matchingPlaneZ = fConfigChi2MatchingOptions.fMatchingPlaneZ[funcId].value;
auto extrapMethod = fConfigChi2MatchingOptions.fMatchingExtrapMethod[funcId].value;
if (label == "" || funcName == "")
break;
matchingChi2Functions[label] = funcName;
matchingScoreCuts[label] = scoreMin;
matchingPlanesZ[label] = matchingPlaneZ;
matchingExtrapMethod[label] = extrapMethod;
}
// Matching ML models
// 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};
o2::framework::LabeledArray<double> mycutsMl(cutValues.data(), 1, 1, std::vector<std::string>{"pT bin 0"}, std::vector<std::string>{"score"});
for (size_t modelId = 0; modelId < sMLModelsNum; modelId++) {
auto label = fConfigMlOptions.fModelLabel[modelId].value;
auto modelPaths = fConfigMlOptions.fModelPathsCCDB[modelId].value;
auto inputFeatures = fConfigMlOptions.fInputFeatures[modelId].value;
auto modelNames = fConfigMlOptions.fModelNames[modelId].value;
auto scoreMin = fConfigMlOptions.fMatchingScoreCut[modelId].value;
auto matchingPlaneZ = fConfigMlOptions.fMatchingPlaneZ[modelId].value;
auto extrapMethod = fConfigMlOptions.fMatchingExtrapMethod[modelId].value;
if (label == "" || modelPaths.empty() || inputFeatures.empty() || modelNames.empty())
break;
matchingMlResponses[label].configure(binsPtMl, mycutsMl, cutDirMl, 1);
matchingMlResponses[label].setModelPathsCCDB(modelNames, fCCDBApi, modelPaths, fConfigCCDB.fConfigNoLaterThan.value);
matchingMlResponses[label].cacheInputFeaturesIndices(inputFeatures);
matchingMlResponses[label].init();
matchingScoreCuts[label] = scoreMin;
matchingPlanesZ[label] = matchingPlaneZ;
matchingExtrapMethod[label] = extrapMethod;
}
int nTrackTypes = static_cast<int>(o2::aod::fwdtrack::ForwardTrackTypeEnum::MCHStandaloneTrack) + 1;
AxisSpec trackTypeAxis = {static_cast<int>(nTrackTypes), 0.0, static_cast<double>(nTrackTypes), "track type"};
registry.add("nTracksPerType", "Number of tracks per type", {HistType::kTH1F, {trackTypeAxis}});
AxisSpec tracksMultiplicityAxis = {10000, 0, 10000, "tracks multiplicity"};
registry.add("tracksMultiplicityMFT", "MFT tracks multiplicity", {HistType::kTH1F, {tracksMultiplicityAxis}});
registry.add("tracksMultiplicityMCH", "MCH tracks multiplicity", {HistType::kTH1F, {tracksMultiplicityAxis}});
CreateMatchingHistosMC();
CreateDimuonHistos();
}
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;
double thetaAbs = TMath::ATan(mchTrack.rAtAbsorberEnd() / 505.) * TMath::RadToDeg();
// propagate muon track to vertex