forked from AliceO2Group/O2Physics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataCreationCharmReso.h
More file actions
1667 lines (1624 loc) · 96 KB
/
DataCreationCharmReso.h
File metadata and controls
1667 lines (1624 loc) · 96 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 DataCreationCharmReso.h
/// \brief utility functions for charm-hadron resonance derived data creators
///
/// \author Luca Aglietta <luca.aglietta@cern.ch>, UniTO Turin
/// \author Fabrizio Grosa <fabrizio.grosa@cern.ch>, CERN
#ifndef PWGHF_D2H_CORE_DATACREATIONCHARMRESO_H_
#define PWGHF_D2H_CORE_DATACREATIONCHARMRESO_H_
#include "PWGHF/Core/CentralityEstimation.h"
#include "PWGHF/Core/DecayChannels.h"
#include "PWGHF/Utils/utilsEvSelHf.h"
#include "PWGHF/Utils/utilsMcMatching.h"
#include "Common/Core/RecoDecay.h"
#include "Common/Core/trackUtilities.h"
#include <CCDB/BasicCCDBManager.h>
#include <DCAFitter/DCAFitterN.h>
#include <DetectorsBase/MatLayerCylSet.h>
#include <DetectorsBase/Propagator.h>
#include <Framework/HistogramRegistry.h>
#include <Framework/HistogramSpec.h>
#include <Framework/O2DatabasePDGPlugin.h>
#include <TPDGCode.h>
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdint>
#include <map>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <vector>
namespace o2::analysis
{
namespace hf_charm_reso
{
// event types
enum EventType : uint8_t {
Processed = 0,
NoDV0Selected,
DV0Selected,
NEventType
};
enum BachelorType : uint8_t {
K0s = 0,
Lambda,
AntiLambda,
Track,
NBachelorTypes
};
enum DMesonType : uint8_t {
Dplus = 1,
Dstar,
D0,
NDMesonType
};
enum PairingType : uint8_t {
V0Only,
TrackOnly,
V0AndTrack,
NPairingType
};
enum D0Sel : uint8_t {
SelectedD0 = 0,
SelectedD0Bar,
ND0Sel
};
// Helper structs to pass D and V0 informations
struct HfResoCandidateV0 {
std::array<float, 3> pos = {0.f, 0.f, 0.f};
std::array<float, 3> mom = {0.f, 0.f, 0.f};
std::array<float, 3> momPos = {0.f, 0.f, 0.f};
std::array<float, 3> momNeg = {0.f, 0.f, 0.f};
float pT = -1.f;
float cosPA = -2.f;
float dcaV0ToPv = 1000.f;
float dcaDau = 1000.f;
float alpha = -1.f;
float eta = -999.f;
float radius = 0.f;
float mK0Short = 0.f;
float mLambda = 0.f;
uint8_t v0Type = 0u;
};
struct HfResoVarContainer {
float invMassD = 0.f;
float ptD = -1.f;
float invMassD0 = 0.f;
float invMassD0Bar = 0.f;
float invMassReso = 0.f;
float ptReso = -1.f;
int8_t signD = 0;
std::array<float, 3> pVectorProng0 = {0.f, 0.f, 0.f};
std::array<float, 3> pVectorProng1 = {0.f, 0.f, 0.f};
std::array<float, 3> pVectorProng2 = {0.f, 0.f, 0.f};
};
struct HfResoConfigV0Cuts : o2::framework::ConfigurableGroup {
std::string prefix = "v0s"; // JSON group name
o2::framework::Configurable<float> deltaMassK0s{"deltaMassK0s", 0.02, "delta mass cut for K0S"};
o2::framework::Configurable<float> deltaMassLambda{"deltaMassLambda", 0.01, "delta mass cut for Lambda"};
o2::framework::Configurable<float> etaMax{"etaMax", 0.8f, "maximum eta"};
o2::framework::Configurable<float> etaMaxDau{"etaMaxDau", 5.f, "maximum eta V0 daughters"};
o2::framework::Configurable<float> trackNclusItsCut{"trackNclusItsCut", 0, "Minimum number of ITS clusters for V0 daughter"};
o2::framework::Configurable<int> trackNCrossedRowsTpc{"trackNCrossedRowsTpc", 50, "Minimum TPC crossed rows"};
o2::framework::Configurable<float> trackNsharedClusTpc{"trackNsharedClusTpc", 1000, "Maximum number of shared TPC clusters for V0 daughter"};
o2::framework::Configurable<float> trackFracMaxindableTpcCls{"trackFracMaxindableTpcCls", 0.8f, "Maximum fraction of findable TPC clusters for V0 daughter"};
o2::framework::Configurable<float> dcaDau{"dcaDau", 1.f, "DCA V0 daughters"};
o2::framework::Configurable<float> dcaMaxDauToPv{"dcaMaxDauToPv", 0.1f, "Maximum daughter's DCA to PV"};
o2::framework::Configurable<float> dcaPv{"dcaPv", 1.f, "DCA V0 to PV"};
o2::framework::Configurable<double> cosPa{"cosPa", 0.99f, "V0 CosPA"};
o2::framework::Configurable<float> radiusMin{"radiusMin", 0.9f, "Minimum v0 radius accepted"};
o2::framework::Configurable<float> nSigmaTpc{"nSigmaTpc", 4.f, "Nsigmatpc"};
o2::framework::Configurable<float> nSigmaTofPr{"nSigmaTofPr", 4.f, "N sigma TOF for protons only"};
o2::framework::Configurable<bool> propagateV0toPV{"propagateV0toPV", false, "Enable or disable V0 propagation to V0"};
};
struct HfResoConfigSingleTrackCuts : o2::framework::ConfigurableGroup {
std::string prefix = "singleTracks"; // JSON group name
o2::framework::Configurable<int> setTrackSelections{"setTrackSelections", 2, "flag to apply track selections: 0=none; 1=global track w/o DCA selection; 2=global track; 3=only ITS quality"};
o2::framework::Configurable<float> maxEta{"maxEta", 0.8, "maximum pseudorapidity for single tracks to be paired with D mesons"};
o2::framework::Configurable<float> minPt{"minPt", 0.1, "minimum pT for single tracks to be paired with D mesons"};
o2::framework::Configurable<float> maxNsigmaTpcPi{"maxNsigmaTpcPi", -1., "maximum pion NSigma in TPC for single tracks to be paired with D mesons; set negative to reject"};
o2::framework::Configurable<float> maxNsigmaTpcKa{"maxNsigmaTpcKa", -1., "maximum kaon NSigma in TPC for single tracks to be paired with D mesons; set negative to reject"};
o2::framework::Configurable<float> maxNsigmaTpcPr{"maxNsigmaTpcPr", 3., "maximum proton NSigma in TPC for single tracks to be paired with D mesons; set negative to reject"};
};
struct HfResoConfigQaPlots : o2::framework::ConfigurableGroup {
std::string prefix = "qaPlots"; // JSON group name
o2::framework::Configurable<bool> applyCutsForQaHistograms{"applyCutsForQaHistograms", true, "flag to apply cuts to QA histograms"};
o2::framework::Configurable<float> cutMassDMin{"cutMassDMin", 1.83, "minimum mass for D0 and Dplus candidates"}; // o2-linter: disable=pdg/explicit-mass (false positive)
o2::framework::Configurable<float> cutMassDMax{"cutMassDMax", 1.92, "maximum mass for D0 and Dplus candidates"}; // o2-linter: disable=pdg/explicit-mass (false positive)
o2::framework::Configurable<float> cutMassDstarMin{"cutMassDstarMin", 0.139, "minimum mass for Dstar candidates"}; // o2-linter: disable=pdg/explicit-mass (false positive)
o2::framework::Configurable<float> cutMassDstarMax{"cutMassDstarMax", 0.175, "maximum mass for Dstar candidates"}; // o2-linter: disable=pdg/explicit-mass (false positive)
o2::framework::Configurable<float> cutMassK0sMin{"cutMassK0sMin", 0.485, "minimum mass for K0s candidates"}; // o2-linter: disable=pdg/explicit-mass (false positive)
o2::framework::Configurable<float> cutMassK0sMax{"cutMassK0sMax", 0.509, "maximum mass for K0s candidates"}; // o2-linter: disable=pdg/explicit-mass (false positive)
o2::framework::Configurable<float> cutMassLambdaMin{"cutMassLambdaMin", 1.11, "minimum mass for Lambda candidates"};
o2::framework::Configurable<float> cutMassLambdaMax{"cutMassLambdaMax", 1.12, "maximum mass for Lambda candidates"};
};
/// Helper method to add histograms to the registry
/// \param registry is the histogram registry
template <bool DoMc, DMesonType DType>
void addHistograms(o2::framework::HistogramRegistry& registry)
{
constexpr uint8_t kNBinsEvents = EventType::NEventType;
std::string labels[kNBinsEvents];
labels[EventType::Processed] = "processed";
labels[EventType::NoDV0Selected] = "without DV0 pairs";
labels[EventType::DV0Selected] = "with DV0 pairs";
const o2::framework::AxisSpec axisEvents = {kNBinsEvents, 0.5, kNBinsEvents + 0.5, ""};
registry.add("hEvents", "Events;;entries", o2::framework::HistType::kTH1D, {axisEvents});
for (auto iBin{0u}; iBin < kNBinsEvents; iBin++) {
registry.get<TH1>(HIST("hEvents"))->GetXaxis()->SetBinLabel(iBin + 1, labels[iBin].data());
}
const o2::framework::AxisSpec axisPt{50, 0.f, 50.f, "#it{p}_{T} (GeV/#it{c})"};
const o2::framework::AxisSpec axisP{100, 0.f, 10.f, "#it{p} (GeV/#it{c})"};
const o2::framework::AxisSpec axisDeDx{500, 0.f, 1000.f, ""};
const o2::framework::AxisSpec axisMassLambda{100, 1.05f, 1.35f, "inv. mass (GeV/#it{c}^{2})"};
const o2::framework::AxisSpec axisMassKzero{100, 0.35f, 0.65f, "inv. mass (GeV/#it{c}^{2})"};
const o2::framework::AxisSpec axisDeltaMassToK{500, 0.49, 1.49, "inv. mass (GeV/#it{c}^{2})"};
const o2::framework::AxisSpec axisDeltaMassToPi{500, 0.13, 1.13, "inv. mass (GeV/#it{c}^{2})"};
const o2::framework::AxisSpec axisDeltaMassToPr{500, 0.93, 1.93, "inv. mass (GeV/#it{c}^{2})"};
const o2::framework::AxisSpec axisDeltaMassToLambda{500, 1.05, 2.05, "inv. mass (GeV/#it{c}^{2})"};
const o2::framework::AxisSpec axisMassDsj{400, 0.49f, 0.89f, ""}; // Ds1 and Ds2Star legacy
registry.add("hMassVsPtK0s", "K0^{s} candidates;#it{p}_{T} (GeV/#it{c});inv. mass (#pi^{#plus}#pi^{#minus}) (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisMassKzero}});
registry.add("hMassVsPtLambda", "Lambda candidates;#it{p}_{T} (GeV/#it{c});inv. mass (p #pi^{#minus}) (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisMassLambda}});
registry.add("hdEdxVsP", "Tracks;#it{p} (GeV/#it{c});d#it{E}/d#it{x};entries", {o2::framework::HistType::kTH2D, {axisP, axisDeDx}});
if constexpr (DType == DMesonType::D0) {
const o2::framework::AxisSpec axisMassD0{200, 1.7f, 2.1f, "inv. mass (GeV/#it{c}^{2})"};
registry.add("hMassVsPtD0All", "D0 candidates (all, regardless the pairing with V0s);#it{p}_{T} (GeV/#it{c});inv. mass (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisMassD0}});
registry.add("hMassVsPtD0BarAll", "D0bar candidates (all, regardless the pairing with V0s);#it{p}_{T} (GeV/#it{c});inv. mass (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisMassD0}});
registry.add("hMassVsPtD0Paired", "D0 candidates (paired with V0s);#it{p}_{T} (GeV/#it{c});inv. mass (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisMassD0}});
registry.add("hMassVsPtD0BarPaired", "D0 candidates (paired with V0s);#it{p}_{T} (GeV/#it{c});inv. mass (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisMassD0}});
registry.add("hMassD0Pi", "D0Pi candidates; m_{D^{0}#pi^{+}} - m_{D^{0}} (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisDeltaMassToPi}});
registry.add("hMassD0K", "D0Kplus candidates; m_{D^{0}K^{+}} - m_{D^{0}} (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisDeltaMassToK}});
registry.add("hMassD0Proton", "D0Proton candidates; m_{D^{0}p} - m_{D^{0}} (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisDeltaMassToPr}});
registry.add("hMassD0Lambda", "D0Lambda candidates; m_{D^{0}#Lambda} - m_{D^{0}} (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisDeltaMassToLambda}});
} else if constexpr (DType == DMesonType::Dplus) {
const o2::framework::AxisSpec axisMassDplus{200, 1.7f, 2.1f, "inv. mass (GeV/#it{c}^{2})"};
registry.add("hMassVsPtDplusAll", "Dplus candidates (all, regardless the pairing with V0s);#it{p}_{T} (GeV/#it{c});inv. mass (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisMassDplus}});
registry.add("hMassVsPtDplusPaired", "Dplus candidates (paired with V0s);#it{p}_{T} (GeV/#it{c});inv. mass (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisMassDplus}});
registry.add("hMassDplusK0s", "DplusK0s candidates; m_{D^{+}K^{0}_{S}} (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisDeltaMassToK}});
registry.add("hMassDplusPi", "DplusPi candidates; m_{D^{+}#pi^{-}} (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisDeltaMassToPi}});
registry.add("hMassDplusK", "DplusK candidates; m_{D^{+}#pi^{-}} (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisDeltaMassToK}});
registry.add("hMassDplusProton", "DplusProton candidates; m_{D^{+}p} (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisDeltaMassToPr}});
registry.add("hMassDplusLambda", "DplusLambda candidates; m_{D^{+}#Lambda} (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisDeltaMassToLambda}});
} else if constexpr (DType == DMesonType::Dstar) {
const o2::framework::AxisSpec axisMassDstar{200, 0.139f, 0.179f, "delta inv. mass (GeV/#it{c}^{2})"}; // o2-linter: disable=pdg/explicit-mass (false positive)
registry.add("hMassVsPtDstarAll", "Dstar candidates (all, regardless the pairing with V0s);#it{p}_{T} (GeV/#it{c});inv. mass (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisMassDstar}});
registry.add("hMassVsPtDstarPaired", "Dstar candidates (paired with V0s);#it{p}_{T} (GeV/#it{c});inv. mass (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisMassDstar}});
registry.add("hMassDstarPi", "DstarPi candidates; m_{D^{*+}#pi^{-}} (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisDeltaMassToPi}});
registry.add("hMassDstarK", "DstarK candidates; m_{D^{*+}#pi^{-}} (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisDeltaMassToK}});
registry.add("hMassDstarProton", "DstarProton candidates; m_{D^{*}p} (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisDeltaMassToPr}});
registry.add("hMassDstarK0s", "DstarK0s candidates; m_{D^{*}K^{0}_{S}} (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisDeltaMassToK}});
registry.add("hMassDstarLambda", "DstarLambda candidates; m_{D^{*}#Lambda} (GeV/#it{c}^{2});entries", {o2::framework::HistType::kTH2D, {axisPt, axisDeltaMassToLambda}});
}
if constexpr (DoMc) {
// MC Rec
int const nChannels = hf_decay::hf_cand_reso::DecayChannelMain::NChannelsMain;
registry.add("hMCRecCounter", "Number of Reconstructed MC Matched candidates per channel", {o2::framework::HistType::kTH1D, {{2 * nChannels + 1, -(nChannels + 0.5), nChannels + 0.5}}});
registry.add("hMCRecDebug", "Debug of MC Reco", {o2::framework::HistType::kTH1D, {{551, -0.5, 550.5}}});
registry.add("hMCRecOrigin", "Origin of Matched particles", {o2::framework::HistType::kTH1D, {{3, -0.5, 2.5}}});
registry.add("hMCRecMassGen", "Generated inv. mass of resoncances", {o2::framework::HistType::kTH1D, {{2000, 1.8, 3.8}}});
registry.add("hMCRecCharmDau", "Charm daughter flag", {o2::framework::HistType::kTH1D, {{57, -28.5, 28.5}}});
// MC Gen
registry.add("hMCGenCounter", "Number of Generated particles; Decay Channel Flag; pT (GeV/#it{c})", {o2::framework::HistType::kTH2D, {{17, -8.5, 8.5}, {100, 0, 50}}});
registry.add("hMCGenOrigin", "Origin of Generated particles", {o2::framework::HistType::kTH1D, {{3, -0.5, 2.5}}});
}
}
/// Basic track quality selections for V0 daughters
/// \param Tr is a track
/// \param dDaughtersIds are the IDs of the D meson daughter tracks
/// \param cfgV0Cuts are the cuts to be applied to the V0
/// \param rejectPairsWithCommonDaughter is a flag to activate rejection of pairs sharing a daughter track
template <typename Tr, typename Cuts>
bool selectV0Daughter(Tr const& track, const std::array<int, 3>& dDaughtersIds, const Cuts& cfgV0Cuts, bool rejectPairsWithCommonDaughter)
{
// acceptance selection
if (std::abs(track.eta()) > cfgV0Cuts.etaMaxDau.value) {
return false;
}
// Tpc Refit
if (!(track.hasTPC())) {
return false;
}
// track quality selection
if (track.itsNCls() < cfgV0Cuts.trackNclusItsCut.value ||
track.tpcNClsFound() < cfgV0Cuts.trackNCrossedRowsTpc.value ||
track.tpcNClsCrossedRows() < cfgV0Cuts.trackNCrossedRowsTpc.value ||
track.tpcNClsCrossedRows() < cfgV0Cuts.trackFracMaxindableTpcCls.value * track.tpcNClsFindable() ||
track.tpcNClsShared() > cfgV0Cuts.trackNsharedClusTpc.value) {
return false;
}
// rejection of tracks that share a daughter with the D meson
if (rejectPairsWithCommonDaughter && std::find(dDaughtersIds.begin(), dDaughtersIds.end(), track.globalIndex()) != dDaughtersIds.end()) {
return false;
}
return true;
}
/// Utility to find which v0 daughter carries the largest fraction of the mother longitudinal momentum
/// \param momV0 is the momentum of the V0
/// \param momDau0 is the momentum of first daughter
/// \param momDau1 is the momentum of second daughter
/// \return alphaAP
float alphaAP(std::array<float, 3> const& momV0, std::array<float, 3> const& momDau0, std::array<float, 3> const& momDau1)
{
float const momTot = std::sqrt(std::pow(momV0[0], 2.) + std::pow(momV0[1], 2.) + std::pow(momV0[2], 2.));
float const lQlPos = (momDau0[0] * momV0[0] + momDau0[1] * momV0[1] + momDau0[2] * momV0[2]) / momTot;
float const lQlNeg = (momDau1[0] * momV0[0] + momDau1[1] * momV0[1] + momDau1[2] * momV0[2]) / momTot;
return (lQlPos - lQlNeg) / (lQlPos + lQlNeg);
}
/// Utility to find DCA of V0 to Primary vertex
/// \param x is the x-coordinate
/// \param y is the y-coordinate
/// \param z is the z-coordinate
/// \param px is the x-component of the momentum
/// \param py is the y-component of the momentum
/// \param pz is the z-component of the momentum
/// \param pvX is the x-coordinate of the PV
/// \param pvY is the y-coordinate of the PV
/// \param pvZ is the z-coordinate of the PV
/// \return the DCA
float calculateDCAStraightToPV(float x, float y, float z, float px, float py, float pz, float pvX, float pvY, float pvZ)
{
return std::sqrt((std::pow((pvY - y) * pz - (pvZ - z) * py, 2) + std::pow((pvX - x) * pz - (pvZ - z) * px, 2) + std::pow((pvX - x) * py - (pvY - y) * px, 2)) / (px * px + py * py + pz * pz));
}
/// Basic selection of V0 candidates
/// \param collision is the current collision
/// \param dauTracks are the v0 daughter tracks
/// \param dDaughtersIds are the IDs of the D meson daughter tracks
/// \param fitter is the DCAFitter object
/// \param cfgV0Cuts are the cuts to be applied to the V0
/// \param v0 is the V0 candidate
/// \param rejectPairsWithCommonDaughter is a flag to activate rejection of pairs sharing a daughter track
/// \return a bitmap with mass hypotesis if passes all cuts
template <typename Coll, typename Tr, typename Cuts>
bool buildAndSelectV0(const Coll& collision, const std::array<int, 3>& dDaughtersIds, const std::array<Tr, 2>& dauTracks, const Cuts& cfgV0Cuts, o2::vertexing::DCAFitterN<2>& fitter, HfResoCandidateV0& v0, bool rejectPairsWithCommonDaughter)
{
const auto& trackPos = dauTracks[0];
const auto& trackNeg = dauTracks[1];
// single-tracks selection
if (!selectV0Daughter(trackPos, dDaughtersIds, cfgV0Cuts, rejectPairsWithCommonDaughter) || !selectV0Daughter(trackNeg, dDaughtersIds, cfgV0Cuts, rejectPairsWithCommonDaughter)) {
return false;
}
// daughters DCA to V0's collision primary vertex
std::array<float, 2> dcaInfo{};
auto trackPosPar = getTrackPar(trackPos);
o2::base::Propagator::Instance()->propagateToDCABxByBz({collision.posX(), collision.posY(), collision.posZ()}, trackPosPar, 2.f, fitter.getMatCorrType(), &dcaInfo);
auto trackPosDcaXY = dcaInfo[0];
auto trackNegPar = getTrackPar(trackNeg);
o2::base::Propagator::Instance()->propagateToDCABxByBz({collision.posX(), collision.posY(), collision.posZ()}, trackNegPar, 2.f, fitter.getMatCorrType(), &dcaInfo);
auto trackNegDcaXY = dcaInfo[0];
if (std::fabs(trackPosDcaXY) < cfgV0Cuts.dcaMaxDauToPv.value || std::fabs(trackNegDcaXY) < cfgV0Cuts.dcaMaxDauToPv.value) {
return false;
}
// vertex reconstruction
auto trackPosCov = getTrackParCov(trackPos);
auto trackNegCov = getTrackParCov(trackNeg);
int nCand = 0;
try {
nCand = fitter.process(trackPosCov, trackNegCov);
} catch (...) {
return false;
}
if (nCand == 0) {
return false;
}
// compute candidate momentum from tracks propagated to decay vertex
auto& trackPosProp = fitter.getTrack(0);
auto& trackNegProp = fitter.getTrack(1);
trackPosProp.getPxPyPzGlo(v0.momPos);
trackNegProp.getPxPyPzGlo(v0.momNeg);
v0.mom = RecoDecay::pVec(v0.momPos, v0.momNeg);
v0.pT = std::hypot(v0.mom[0], v0.mom[1]);
// topological selections:
// v0 eta
v0.eta = RecoDecay::eta(v0.mom);
if (std::abs(v0.eta) > cfgV0Cuts.etaMax.value) {
return false;
}
// daughters DCA
v0.dcaDau = std::sqrt(fitter.getChi2AtPCACandidate());
if (v0.dcaDau > cfgV0Cuts.dcaDau.value) {
return false;
}
// v0 radius
const auto& vtx = fitter.getPCACandidate();
v0.radius = std::hypot(vtx[0], vtx[1]);
if (v0.radius < cfgV0Cuts.radiusMin.value) {
return false;
}
std::copy(vtx.begin(), vtx.end(), v0.pos.begin());
// v0 DCA to primary vertex
v0.dcaV0ToPv = calculateDCAStraightToPV(
vtx[0], vtx[1], vtx[2],
v0.momPos[0] + v0.momNeg[0],
v0.momPos[1] + v0.momNeg[1],
v0.momPos[2] + v0.momNeg[2],
collision.posX(), collision.posY(), collision.posZ());
if (std::abs(v0.dcaV0ToPv) > cfgV0Cuts.dcaPv.value) {
return false;
}
// v0 cosine of pointing angle
std::array<float, 3> const primVtx = {collision.posX(), collision.posY(), collision.posZ()};
v0.cosPA = RecoDecay::cpa(primVtx, vtx, v0.mom);
if (v0.cosPA < cfgV0Cuts.cosPa.value) {
return false;
}
// distinguish between K0s, and Lambda hypotesys
v0.v0Type = {BIT(BachelorType::K0s) | BIT(BachelorType::Lambda) | BIT(BachelorType::AntiLambda)};
// for lambda hypotesys define if its lambda or anti-lambda
v0.alpha = alphaAP(v0.mom, v0.momPos, v0.momNeg);
bool const matter = v0.alpha > 0;
CLRBIT(v0.v0Type, matter ? BachelorType::AntiLambda : BachelorType::Lambda);
auto massPos = matter ? o2::constants::physics::MassProton : o2::constants::physics::MassPionCharged;
auto massNeg = matter ? o2::constants::physics::MassPionCharged : o2::constants::physics::MassProton;
// mass hypotesis
v0.mLambda = RecoDecay::m(std::array{v0.momPos, v0.momNeg}, std::array{massPos, massNeg});
v0.mK0Short = RecoDecay::m(std::array{v0.momPos, v0.momNeg}, std::array{o2::constants::physics::MassPionCharged, o2::constants::physics::MassPionCharged});
if (std::fabs(v0.mK0Short - o2::constants::physics::MassK0) > cfgV0Cuts.deltaMassK0s.value) {
CLRBIT(v0.v0Type, BachelorType::K0s);
}
if (std::fabs(v0.mLambda - o2::constants::physics::MassLambda0) > cfgV0Cuts.deltaMassLambda.value) {
CLRBIT(v0.v0Type, BachelorType::Lambda);
CLRBIT(v0.v0Type, BachelorType::AntiLambda);
}
// PID
if (TESTBIT(v0.v0Type, BachelorType::K0s)) {
if ((trackPos.hasTPC() && std::fabs(trackPos.tpcNSigmaPi()) > cfgV0Cuts.nSigmaTpc.value) ||
(trackNeg.hasTPC() && std::fabs(trackNeg.tpcNSigmaPi()) > cfgV0Cuts.nSigmaTpc.value)) {
CLRBIT(v0.v0Type, BachelorType::K0s);
}
}
if (TESTBIT(v0.v0Type, BachelorType::Lambda)) {
if ((trackPos.hasTPC() && std::fabs(trackPos.tpcNSigmaPr()) > cfgV0Cuts.nSigmaTpc.value) ||
(trackPos.hasTOF() && std::fabs(trackPos.tofNSigmaPr()) > cfgV0Cuts.nSigmaTofPr.value) ||
(trackNeg.hasTPC() && std::fabs(trackNeg.tpcNSigmaPi()) > cfgV0Cuts.nSigmaTpc.value)) {
CLRBIT(v0.v0Type, BachelorType::Lambda);
}
}
if (TESTBIT(v0.v0Type, BachelorType::AntiLambda)) {
if ((trackPos.hasTPC() && std::fabs(trackPos.tpcNSigmaPi()) > cfgV0Cuts.nSigmaTpc.value) ||
(trackNeg.hasTPC() && std::fabs(trackNeg.tpcNSigmaPr()) > cfgV0Cuts.nSigmaTpc.value) ||
(trackNeg.hasTOF() && std::fabs(trackNeg.tofNSigmaPr()) > cfgV0Cuts.nSigmaTofPr.value)) {
CLRBIT(v0.v0Type, BachelorType::AntiLambda);
}
}
if (v0.v0Type == 0) {
return false;
}
return true;
}
/// Basic selection of tracks
/// \param track is the track
/// \param dDaughtersIds are the IDs of the D meson daughter tracks
/// \param cfgV0Cuts are the cuts to be applied to the track
/// \param rejectPairsWithCommonDaughter is a flag to activate rejection of pairs sharing a daughter track
/// \return true if passes all cuts
template <typename Tr, typename Cuts>
bool isTrackSelected(const Tr& track, const std::array<int, 3>& dDaughtersIds, const Cuts& cfgSingleTrackCuts, bool rejectPairsWithCommonDaughter)
{
if (rejectPairsWithCommonDaughter && std::find(dDaughtersIds.begin(), dDaughtersIds.end(), track.globalIndex()) != dDaughtersIds.end()) {
return false;
}
switch (cfgSingleTrackCuts.setTrackSelections.value) {
case 1:
if (!track.isGlobalTrackWoDCA()) {
return false;
}
break;
case 2:
if (!track.isGlobalTrack()) {
return false;
}
break;
case 3:
if (!track.isQualityTrackITS()) {
return false;
}
break;
}
if (track.pt() < cfgSingleTrackCuts.minPt.value) {
return false;
}
if (std::abs(track.eta()) > cfgSingleTrackCuts.maxEta.value) {
return false;
}
if (!track.hasTPC()) {
return false;
}
bool const isPion = std::abs(track.tpcNSigmaPi()) < cfgSingleTrackCuts.maxNsigmaTpcPi.value;
bool const isKaon = std::abs(track.tpcNSigmaKa()) < cfgSingleTrackCuts.maxNsigmaTpcKa.value;
bool const isProton = std::abs(track.tpcNSigmaPr()) < cfgSingleTrackCuts.maxNsigmaTpcPr.value;
return (isPion || isKaon || isProton); // we keep the track if is it compatible with at least one of the PID hypotheses selected
}
/// Matching of V0 candidates to MC truth
/// \param particlesMc is the table of MC particles
/// \param arrDaughtersV0 is the array of V0 daughter tracks
/// \return the MC matching flag for the V0
template <typename PParticles, typename TrIU>
int8_t getMatchingFlagV0(PParticles const& particlesMc, const std::array<TrIU, 2>& arrDaughtersV0)
{
int8_t signV0{0};
int indexRec{-1};
int flagV0{0};
indexRec = RecoDecay::getMatchedMCRec<false, true, false, true, true>(particlesMc, arrDaughtersV0, kK0, std::array{+kPiPlus, -kPiPlus}, true, &signV0, 2);
if (indexRec > -1) {
flagV0 = hf_decay::hf_cand_reso::PartialMatchMc::K0Matched;
} else {
indexRec = RecoDecay::getMatchedMCRec<false, true, false, true, true>(particlesMc, arrDaughtersV0, kLambda0, std::array{+kProton, -kPiPlus}, true, &signV0, 2);
if (indexRec > -1) {
flagV0 = signV0 * hf_decay::hf_cand_reso::PartialMatchMc::LambdaMatched;
}
}
return flagV0; // Placeholder, should return the actual flag based on matching logic
}
/// Matching of V0 candidates to MC truth
/// \param bachTrack is the track
/// \return the MC matching flag for the track
template <typename Tr>
int8_t getMatchingFlagTrack(Tr const& bachTrack)
{
auto particle = bachTrack.mcParticle();
auto pdgCode = std::abs(particle.pdgCode());
if (pdgCode == kPiPlus) {
return hf_decay::hf_cand_reso::PartialMatchMc::PionMatched;
}
if (pdgCode == kKPlus) {
return hf_decay::hf_cand_reso::PartialMatchMc::KaonMatched;
}
if (pdgCode == kProton) {
return hf_decay::hf_cand_reso::PartialMatchMc::ProtonMatched;
}
return 0;
}
/// Matching of V0 candidates to MC truth
/// \param particlesMc is the table of MC particles
/// \param indexRec is the index of the MC particle associated to the reconstructed canditate
/// \param pdg is the O2DatabasePDG service
/// \return the generated invariant mass
template <typename PParticles>
float computeInvMassGen(PParticles const& particlesMc, int indexRec, o2::framework::Service<o2::framework::O2DatabasePDG> const& pdg)
{
if (indexRec < 0) {
return -1.f;
}
auto particleReso = particlesMc.iteratorAt(indexRec);
auto dau1 = particlesMc.iteratorAt(particleReso.daughtersIds().front());
auto dau2 = particlesMc.iteratorAt(particleReso.daughtersIds().back());
std::array<std::array<double, 3>, 2> pArr = {{{dau1.px(), dau1.py(), dau1.pz()}, {dau2.px(), dau2.py(), dau2.pz()}}};
std::array<double, 2> mArr = {pdg->Mass(dau1.pdgCode()), pdg->Mass(dau2.pdgCode())};
return static_cast<float>(RecoDecay::m(pArr, mArr));
}
/// Function for filling MC reco information of DV0 candidates in the tables
/// \tparam dType is the D meson type (Dstar, Dplus or D0)
/// \param particlesMc is the table with MC particles
/// \param candCharmBach is the D meson candidate
/// \param bachelorV0 is the V0 candidate
/// \param tracks is the table with tracks
/// \param indexHfCandCharm is the index of the charm-hadron bachelor in the reduced table
/// \param indexCandV0TrBach is the index of the v0 bachelor in the reduced table
/// \param pdg is the O2DatabasePDG service
/// \param registry is the histogram registry
/// \param rowMcRecReduced is the table to be filled
template <DMesonType DType, typename PParticles, typename CCand, typename BBachV0, typename Tr, typename Table>
void fillMcRecoInfoDV0(PParticles const& particlesMc,
CCand const& candCharmBach,
BBachV0 const& bachelorV0,
Tr const& tracks,
int64_t& indexHfCandCharm,
int64_t& indexCandV0Bach,
o2::framework::Service<o2::framework::O2DatabasePDG> const& pdg,
o2::framework::HistogramRegistry& registry,
Table& rowMcRecReduced)
{
std::vector<typename Tr::iterator> vecDaughtersReso{};
int8_t sign{0}, nKinkedTracks{0}, origin{0}, flagCharmBach{0}, flagCharmBachInterm{0}, flagV0{0}, flagReso{0};
int indexRec{-1}, debugMcRec{0};
float ptGen{-1.f}, invMassGen{-1.f};
if constexpr (DType == DMesonType::Dstar) {
vecDaughtersReso.push_back(tracks.rawIteratorAt(candCharmBach.prong0Id()));
vecDaughtersReso.push_back(tracks.rawIteratorAt(candCharmBach.prong1Id()));
vecDaughtersReso.push_back(tracks.rawIteratorAt(candCharmBach.prongPiId()));
// Check if D* is matched
flagCharmBach = candCharmBach.flagMcMatchRec();
if (flagCharmBach != 0) {
SETBIT(debugMcRec, hf_decay::hf_cand_reso::PartialMatchMc::DstarMatched);
origin = candCharmBach.originMcRec();
}
// Check if D0 is matched
flagCharmBachInterm = candCharmBach.flagMcMatchRecD0();
if (flagCharmBachInterm != 0) {
SETBIT(debugMcRec, hf_decay::hf_cand_reso::PartialMatchMc::D0Matched);
}
// Check if V0 is matched
vecDaughtersReso.push_back(tracks.rawIteratorAt(bachelorV0.posTrackId()));
vecDaughtersReso.push_back(tracks.rawIteratorAt(bachelorV0.negTrackId()));
flagV0 = getMatchingFlagV0(particlesMc, std::array{vecDaughtersReso[3], vecDaughtersReso[4]});
if (flagV0 != 0) {
SETBIT(debugMcRec, std::abs(flagV0));
}
// If both D* and K0s are matched, try to match resonance
if (flagCharmBach != 0 && flagV0 == hf_decay::hf_cand_reso::PartialMatchMc::K0Matched) {
std::array<int, 5> const pdgCodesDaughters = {+kPiPlus, -kKPlus, +kPiPlus, +kPiPlus, -kPiPlus};
auto arrDaughtersReso = std::array{vecDaughtersReso[0], vecDaughtersReso[1], vecDaughtersReso[2], vecDaughtersReso[3], vecDaughtersReso[4]};
for (const auto& [decayChannelFlag, pdgCodeReso] : hf_decay::hf_cand_reso::particlesToDstarK0s) {
indexRec = RecoDecay::getMatchedMCRec<false, true, false, true, true>(particlesMc, arrDaughtersReso, pdgCodeReso, pdgCodesDaughters, true, &sign, 3, &nKinkedTracks);
if (indexRec > -1) {
flagReso = sign * decayChannelFlag;
break;
}
}
} else if (flagCharmBachInterm != 0 && flagV0 == hf_decay::hf_cand_reso::PartialMatchMc::K0Matched) {
std::array<int, 4> const pdgCodesDaughters = {+kPiPlus, -kKPlus, +kPiPlus, -kPiPlus};
auto arrDaughtersReso = std::array{vecDaughtersReso[0], vecDaughtersReso[1], vecDaughtersReso[3], vecDaughtersReso[4]};
// Peaking background of D0K0s <- Ds* with spurious soft pion
for (const auto& [decayChannelFlag, pdgCodeReso] : hf_decay::hf_cand_reso::particlesToDstarK0s) {
indexRec = RecoDecay::getMatchedMCRec<false, true, true, true, true>(particlesMc, arrDaughtersReso, pdgCodeReso, pdgCodesDaughters, true, &sign, 3, &nKinkedTracks);
if (indexRec > -1) {
flagReso = sign * decayChannelFlag;
SETBIT(debugMcRec, hf_decay::hf_cand_reso::PartialMatchMc::ResoPartlyMatched);
break;
}
}
}
// No physical channel expected in D*Lambda
if (indexRec > -1) {
auto particleReso = particlesMc.iteratorAt(indexRec);
ptGen = particleReso.pt();
invMassGen = computeInvMassGen(particlesMc, indexRec, pdg);
}
rowMcRecReduced(indexHfCandCharm, indexCandV0Bach,
flagReso, flagCharmBach,
flagCharmBachInterm, debugMcRec,
origin, ptGen, invMassGen,
nKinkedTracks);
} else if constexpr (DType == DMesonType::Dplus) {
vecDaughtersReso.push_back(tracks.rawIteratorAt(candCharmBach.prong0Id()));
vecDaughtersReso.push_back(tracks.rawIteratorAt(candCharmBach.prong1Id()));
vecDaughtersReso.push_back(tracks.rawIteratorAt(candCharmBach.prong2Id()));
// Check if D+ is matched
flagCharmBach = candCharmBach.flagMcMatchRec();
flagCharmBachInterm = candCharmBach.flagMcDecayChanRec();
if (flagCharmBach != 0) {
SETBIT(debugMcRec, hf_decay::hf_cand_reso::PartialMatchMc::DplusMatched);
origin = candCharmBach.originMcRec();
}
// Check if V0 is matched
vecDaughtersReso.push_back(tracks.rawIteratorAt(bachelorV0.posTrackId()));
vecDaughtersReso.push_back(tracks.rawIteratorAt(bachelorV0.negTrackId()));
flagV0 = getMatchingFlagV0(particlesMc, std::array{vecDaughtersReso[3], vecDaughtersReso[4]});
if (flagV0 != 0) {
SETBIT(debugMcRec, std::abs(flagV0));
}
// If both D+ and K0s are matched, try to match resonance
if (hf_decay::hf_cand_3prong::daughtersDplusMain.contains(static_cast<hf_decay::hf_cand_3prong::DecayChannelMain>(std::abs(flagCharmBach))) && flagV0 == hf_decay::hf_cand_reso::PartialMatchMc::K0Matched) {
auto arrDaughtersReso = std::array{vecDaughtersReso[0], vecDaughtersReso[1], vecDaughtersReso[2], vecDaughtersReso[3], vecDaughtersReso[4]};
auto pdgCodesDplusDaughters = hf_decay::hf_cand_3prong::daughtersDplusMain.at(static_cast<hf_decay::hf_cand_3prong::DecayChannelMain>(std::abs(flagCharmBach)));
auto pdgCodesDaughters = std::array{pdgCodesDplusDaughters[0], pdgCodesDplusDaughters[1], pdgCodesDplusDaughters[2], +kPiPlus, -kPiPlus};
for (const auto& [decayChannelFlag, pdgCodeReso] : hf_decay::hf_cand_reso::particlesToDplusK0s) {
indexRec = RecoDecay::getMatchedMCRec<false, true, false, true, true>(particlesMc, arrDaughtersReso, pdgCodeReso, pdgCodesDaughters, true, &sign, 3, &nKinkedTracks);
if (indexRec > -1) {
flagReso = sign * decayChannelFlag;
break;
}
}
// Partial matching of Dsj -> D*K0s -> (D+ pi0) (K0s) with missing neutral
if (indexRec < 0) {
for (const auto& [decayChannelFlag, pdgCodeReso] : hf_decay::hf_cand_reso::particlesToDstarK0s) {
indexRec = RecoDecay::getMatchedMCRec<false, true, true, true, true>(particlesMc, arrDaughtersReso, pdgCodeReso, pdgCodesDaughters, true, &sign, 3, &nKinkedTracks);
if (indexRec > -1) {
flagReso = sign * decayChannelFlag;
SETBIT(debugMcRec, hf_decay::hf_cand_reso::PartialMatchMc::ResoPartlyMatched);
break;
}
}
}
} else if (hf_decay::hf_cand_3prong::daughtersDplusMain.contains(static_cast<hf_decay::hf_cand_3prong::DecayChannelMain>(std::abs(flagCharmBach))) && std::abs(flagV0) == hf_decay::hf_cand_reso::PartialMatchMc::LambdaMatched) {
// Peaking background of D+Lambda <- Ds* with spurious soft pion
auto arrDaughtersReso = std::array{vecDaughtersReso[0], vecDaughtersReso[1], vecDaughtersReso[2], vecDaughtersReso[3], vecDaughtersReso[4]};
auto pdgCodesDplusDaughters = hf_decay::hf_cand_3prong::daughtersDplusMain.at(static_cast<hf_decay::hf_cand_3prong::DecayChannelMain>(std::abs(flagCharmBach)));
auto pdgCodesDaughters = std::array{pdgCodesDplusDaughters[0], pdgCodesDplusDaughters[1], pdgCodesDplusDaughters[2], +kProton, -kPiPlus};
for (const auto& [decayChannelFlag, pdgCodeReso] : hf_decay::hf_cand_reso::particlesToDplusLambda) {
indexRec = RecoDecay::getMatchedMCRec<false, true, false, true, true>(particlesMc, arrDaughtersReso, pdgCodeReso, pdgCodesDaughters, true, &sign, 3, &nKinkedTracks);
if (indexRec > -1) {
flagReso = sign * decayChannelFlag;
break;
}
}
}
if (indexRec > -1) {
auto particleReso = particlesMc.iteratorAt(indexRec);
ptGen = particleReso.pt();
invMassGen = computeInvMassGen(particlesMc, indexRec, pdg);
}
rowMcRecReduced(indexHfCandCharm, indexCandV0Bach,
flagReso, flagCharmBach,
flagCharmBachInterm, debugMcRec,
origin, ptGen, invMassGen,
nKinkedTracks);
} else if constexpr (DType == DMesonType::D0) {
vecDaughtersReso.push_back(tracks.rawIteratorAt(candCharmBach.prong0Id()));
vecDaughtersReso.push_back(tracks.rawIteratorAt(candCharmBach.prong1Id()));
// Check if D0 is matched
flagCharmBach = candCharmBach.flagMcMatchRec();
flagCharmBachInterm = candCharmBach.flagMcDecayChanRec();
if (flagCharmBach != 0) {
SETBIT(debugMcRec, hf_decay::hf_cand_reso::PartialMatchMc::D0Matched);
origin = candCharmBach.originMcRec();
}
// Check if V0 is matched
vecDaughtersReso.push_back(tracks.rawIteratorAt(bachelorV0.posTrackId()));
vecDaughtersReso.push_back(tracks.rawIteratorAt(bachelorV0.negTrackId()));
flagV0 = getMatchingFlagV0(particlesMc, std::array{vecDaughtersReso[2], vecDaughtersReso[3]});
if (flagV0 != 0) {
SETBIT(debugMcRec, std::abs(flagV0));
}
// No physical channel expected in D0 K0s
// If both D0 and Lambda are matched, try to match resonance
if (hf_decay::hf_cand_2prong::daughtersD0Main.contains(static_cast<hf_decay::hf_cand_2prong::DecayChannelMain>(std::abs(flagCharmBach))) && std::abs(flagV0) == hf_decay::hf_cand_reso::PartialMatchMc::LambdaMatched) {
auto arrDaughtersReso = std::array{vecDaughtersReso[0], vecDaughtersReso[1], vecDaughtersReso[2], vecDaughtersReso[3]};
auto pdgCodesDzeroDaughters = hf_decay::hf_cand_2prong::daughtersD0Main.at(static_cast<hf_decay::hf_cand_2prong::DecayChannelMain>(std::abs(flagCharmBach)));
auto pdgCodesDaughters = std::array{pdgCodesDzeroDaughters[0], pdgCodesDzeroDaughters[1], +kProton, -kPiPlus};
for (const auto& [decayChannelFlag, pdgCodeReso] : hf_decay::hf_cand_reso::particlesToD0Lambda) {
indexRec = RecoDecay::getMatchedMCRec<false, true, false, true, true>(particlesMc, arrDaughtersReso, pdgCodeReso, pdgCodesDaughters, true, &sign, 3, &nKinkedTracks);
if (indexRec > -1) {
flagReso = sign * decayChannelFlag;
break;
}
}
}
if (indexRec > -1) {
auto particleReso = particlesMc.iteratorAt(indexRec);
ptGen = particleReso.pt();
invMassGen = computeInvMassGen(particlesMc, indexRec, pdg);
}
rowMcRecReduced(indexHfCandCharm, indexCandV0Bach,
flagReso, flagCharmBach,
flagCharmBachInterm, debugMcRec,
origin, ptGen, invMassGen,
nKinkedTracks);
}
registry.fill(HIST("hMCRecDebug"), debugMcRec);
if (indexRec > -1) {
registry.fill(HIST("hMCRecCounter"), flagReso);
registry.fill(HIST("hMCRecOrigin"), origin);
registry.fill(HIST("hMCRecMassGen"), invMassGen);
}
if (flagCharmBach != 0) {
registry.fill(HIST("hMCRecCharmDau"), flagCharmBach);
}
}
// Function for filling MC reco information of D Track candidates in the tables
/// \tparam dType is the D meson type (Dstar, Dplus or D0)
/// \param particlesMc is the table with MC particles
/// \param candCharmBach is the D meson candidate
/// \param bachelorTrack is the bachelor track
/// \param tracks is the table with tracks
/// \param indexHfCandCharm is the index of the charm-hadron bachelor in the reduced table
/// \param indexCandTrBach is the index of the v0 bachelor in the reduced table
/// \param pdg is the O2DatabasePDG service
/// \param registry is the histogram registry
/// \param rowMcRecReduced is the table to be filled
template <DMesonType DType, typename PParticles, typename CCand, typename BBachTr, typename Tr, typename Table>
void fillMcRecoInfoDTrack(PParticles const& particlesMc,
CCand const& candCharmBach,
BBachTr const& bachelorTrack,
Tr const& tracks,
const int64_t indexHfCandCharm,
const int64_t indexCandTrBach,
o2::framework::Service<o2::framework::O2DatabasePDG> const& pdg,
o2::framework::HistogramRegistry& registry,
Table& rowMcRecReduced)
{
std::vector<typename Tr::iterator> vecDaughtersReso{};
int8_t sign{0}, nKinkedTracks{0}, origin{0}, flagCharmBach{0}, flagCharmBachInterm{0}, flagTrack{0}, flagReso{0};
int indexRec{-1};
uint16_t debugMcRec{0};
float ptGen{-1.f}, invMassGen{-1.f};
if constexpr (DType == DMesonType::Dstar) {
vecDaughtersReso.push_back(tracks.rawIteratorAt(candCharmBach.prong0Id()));
vecDaughtersReso.push_back(tracks.rawIteratorAt(candCharmBach.prong1Id()));
vecDaughtersReso.push_back(tracks.rawIteratorAt(candCharmBach.prongPiId()));
// Check if D* is matched
flagCharmBach = candCharmBach.flagMcMatchRec();
if (flagCharmBach != 0) {
SETBIT(debugMcRec, hf_decay::hf_cand_reso::PartialMatchMc::DstarMatched);
origin = candCharmBach.originMcRec();
}
// Check if D0 is matched
flagCharmBachInterm = candCharmBach.flagMcMatchRecD0();
if (flagCharmBachInterm != 0) {
SETBIT(debugMcRec, hf_decay::hf_cand_reso::PartialMatchMc::D0Matched);
}
// Check if Track is matched
flagTrack = getMatchingFlagTrack(bachelorTrack);
if (flagTrack != 0) {
SETBIT(debugMcRec, flagTrack);
}
// If both D* and Track are matched, try to match resonance
if (flagCharmBach != 0 && flagTrack == hf_decay::hf_cand_reso::PartialMatchMc::PionMatched) {
auto arrDaughtersReso = std::array{vecDaughtersReso[0], vecDaughtersReso[1], vecDaughtersReso[2], bachelorTrack};
auto pdgCodesDaughters = std::array{+kPiPlus, -kKPlus, +kPiPlus, -kPiPlus};
for (const auto& [decayChannelFlag, pdgCodeReso] : hf_decay::hf_cand_reso::particlesToDstarPi) {
indexRec = RecoDecay::getMatchedMCRec<false, true, false, true, true>(particlesMc, arrDaughtersReso, pdgCodeReso, pdgCodesDaughters, true, &sign, 3, &nKinkedTracks);
if (indexRec > -1) {
flagReso = sign * decayChannelFlag;
break;
}
}
}
// No channels in D*K+ or D*Pr
if (indexRec > -1) {
auto particleReso = particlesMc.iteratorAt(indexRec);
ptGen = particleReso.pt();
invMassGen = computeInvMassGen(particlesMc, indexRec, pdg);
}
rowMcRecReduced(indexHfCandCharm, indexCandTrBach,
flagReso, flagCharmBach,
flagCharmBachInterm, debugMcRec,
origin, ptGen, invMassGen,
nKinkedTracks);
} else if constexpr (DType == DMesonType::Dplus) {
vecDaughtersReso.push_back(tracks.rawIteratorAt(candCharmBach.prong0Id()));
vecDaughtersReso.push_back(tracks.rawIteratorAt(candCharmBach.prong1Id()));
vecDaughtersReso.push_back(tracks.rawIteratorAt(candCharmBach.prong2Id()));
// Check if D+ is matched
flagCharmBach = candCharmBach.flagMcMatchRec();
flagCharmBachInterm = candCharmBach.flagMcDecayChanRec();
if (flagCharmBach != 0) {
SETBIT(debugMcRec, hf_decay::hf_cand_reso::PartialMatchMc::DplusMatched);
origin = candCharmBach.originMcRec();
}
// Check if Track is matched
flagTrack = getMatchingFlagTrack(bachelorTrack);
if (flagTrack != 0) {
SETBIT(debugMcRec, flagTrack);
}
// If both D+ and Track are matched, try to match resonance
if (hf_decay::hf_cand_3prong::daughtersDplusMain.contains(static_cast<hf_decay::hf_cand_3prong::DecayChannelMain>(std::abs(flagCharmBach))) && flagTrack == hf_decay::hf_cand_reso::PartialMatchMc::PionMatched) {
auto arrDaughtersReso = std::array{vecDaughtersReso[0], vecDaughtersReso[1], vecDaughtersReso[2], bachelorTrack};
auto pdgCodesDplusDaughters = hf_decay::hf_cand_3prong::daughtersDplusMain.at(static_cast<hf_decay::hf_cand_3prong::DecayChannelMain>(std::abs(flagCharmBach)));
auto pdgCodesDaughters = std::array{pdgCodesDplusDaughters[0], pdgCodesDplusDaughters[1], pdgCodesDplusDaughters[2], -kPiPlus};
for (const auto& [decayChannelFlag, pdgCodeReso] : hf_decay::hf_cand_reso::particlesToDplusPi) {
indexRec = RecoDecay::getMatchedMCRec<false, true, false, true, true>(particlesMc, arrDaughtersReso, pdgCodeReso, pdgCodesDaughters, true, &sign, 3, &nKinkedTracks);
if (indexRec > -1) {
flagReso = sign * decayChannelFlag;
break;
}
}
// Partial matching of Dj -> D*Pi -> (D+ pi0) (pi) with missing neutral
if (indexRec < 0) {
for (const auto& [decayChannelFlag, pdgCodeReso] : hf_decay::hf_cand_reso::particlesToDstarPi) {
indexRec = RecoDecay::getMatchedMCRec<false, true, true, true, true>(particlesMc, arrDaughtersReso, pdgCodeReso, pdgCodesDaughters, true, &sign, 3, &nKinkedTracks);
if (indexRec > -1) {
flagReso = sign * decayChannelFlag;
SETBIT(debugMcRec, hf_decay::hf_cand_reso::PartialMatchMc::ResoPartlyMatched);
break;
}
}
}
}
// No channels in D+K+ or D+Pr
if (indexRec > -1) {
auto particleReso = particlesMc.iteratorAt(indexRec);
ptGen = particleReso.pt();
invMassGen = computeInvMassGen(particlesMc, indexRec, pdg);
}
rowMcRecReduced(indexHfCandCharm, indexCandTrBach,
flagReso, flagCharmBach,
flagCharmBachInterm, debugMcRec,
origin, ptGen, invMassGen,
nKinkedTracks);
} else if constexpr (DType == DMesonType::D0) {
vecDaughtersReso.push_back(tracks.rawIteratorAt(candCharmBach.prong0Id()));
vecDaughtersReso.push_back(tracks.rawIteratorAt(candCharmBach.prong1Id()));
// Check if D0 is matched
flagCharmBach = candCharmBach.flagMcMatchRec();
flagCharmBachInterm = candCharmBach.flagMcDecayChanRec();
if (flagCharmBach != 0) {
SETBIT(debugMcRec, hf_decay::hf_cand_reso::PartialMatchMc::D0Matched);
origin = candCharmBach.originMcRec();
}
flagTrack = getMatchingFlagTrack(bachelorTrack);
if (flagTrack != 0) {
SETBIT(debugMcRec, flagTrack);
}
if (hf_decay::hf_cand_2prong::daughtersD0Main.contains(static_cast<hf_decay::hf_cand_2prong::DecayChannelMain>(std::abs(flagCharmBach))) && flagTrack == hf_decay::hf_cand_reso::PartialMatchMc::PionMatched) {
auto arrDaughtersReso = std::array{vecDaughtersReso[0], vecDaughtersReso[1], bachelorTrack};
auto pdgCodesDzeroDaughters = hf_decay::hf_cand_2prong::daughtersD0Main.at(static_cast<hf_decay::hf_cand_2prong::DecayChannelMain>(std::abs(flagCharmBach)));
auto pdgCodesDaughters = std::array{pdgCodesDzeroDaughters[0], pdgCodesDzeroDaughters[1], +kPiPlus};
for (const auto& [decayChannelFlag, pdgCodeReso] : hf_decay::hf_cand_reso::particlesToD0Pi) {
indexRec = RecoDecay::getMatchedMCRec<false, true, false, true, true>(particlesMc, arrDaughtersReso, pdgCodeReso, pdgCodesDaughters, true, &sign, 3, &nKinkedTracks);
if (indexRec > -1) {
flagReso = sign * decayChannelFlag;
break;
}
}
// Partial matching of Dj -> D*Pi -> (D0 pi) (pi) with missing pion
if (indexRec < 0) {
for (const auto& [decayChannelFlag, pdgCodeReso] : hf_decay::hf_cand_reso::particlesToDstarPi) {
indexRec = RecoDecay::getMatchedMCRec<false, true, true, true, true>(particlesMc, arrDaughtersReso, pdgCodeReso, pdgCodesDaughters, true, &sign, 3, &nKinkedTracks);
if (indexRec > -1) {
flagReso = sign * decayChannelFlag;
SETBIT(debugMcRec, hf_decay::hf_cand_reso::PartialMatchMc::ResoPartlyMatched);
break;
}
}
}
} else if (hf_decay::hf_cand_2prong::daughtersD0Main.contains(static_cast<hf_decay::hf_cand_2prong::DecayChannelMain>(std::abs(flagCharmBach))) && flagTrack == hf_decay::hf_cand_reso::PartialMatchMc::KaonMatched) {
auto arrDaughtersReso = std::array{vecDaughtersReso[0], vecDaughtersReso[1], bachelorTrack};
auto pdgCodesDzeroDaughters = hf_decay::hf_cand_2prong::daughtersD0Main.at(static_cast<hf_decay::hf_cand_2prong::DecayChannelMain>(std::abs(flagCharmBach)));
auto pdgCodesDaughters = std::array{pdgCodesDzeroDaughters[0], pdgCodesDzeroDaughters[1], +kKPlus};
for (const auto& [decayChannelFlag, pdgCodeReso] : hf_decay::hf_cand_reso::particlesToD0Kplus) {
indexRec = RecoDecay::getMatchedMCRec<false, true, false, true, true>(particlesMc, arrDaughtersReso, pdgCodeReso, pdgCodesDaughters, true, &sign, 3, &nKinkedTracks);
if (indexRec > -1) {
flagReso = sign * decayChannelFlag;
break;
}
}
}
if (indexRec > -1) {
auto particleReso = particlesMc.iteratorAt(indexRec);
ptGen = particleReso.pt();
invMassGen = computeInvMassGen(particlesMc, indexRec, pdg);
}
rowMcRecReduced(indexHfCandCharm, indexCandTrBach,
flagReso, flagCharmBach,
flagCharmBachInterm, debugMcRec,
origin, ptGen, invMassGen,
nKinkedTracks);
}
registry.fill(HIST("hMCRecDebug"), debugMcRec);
if (indexRec > -1) {
registry.fill(HIST("hMCRecCounter"), flagReso);
registry.fill(HIST("hMCRecOrigin"), origin);
registry.fill(HIST("hMCRecMassGen"), invMassGen);
}
if (flagCharmBach != 0) {
registry.fill(HIST("hMCRecCharmDau"), flagCharmBach);
}
} // fillMcRecoInfoDTrack
// Function for derived data creation
/// \tparam dType is the D meson type (Dstar, Dplus or D0)
/// \param collision is the current collision
/// \param candsD are the D meson candidates in the current collision
/// \param bachelorV0s are the V0 candidates in the current collision
/// \param bachelorTrks are the track ids in the current collision
/// \param tracks is the track table
/// \param tracksIU is the trackIU table
/// \param particlesMc is the MC particle table
/// \param hfRejMap is the event rejection map from the HF event selection util
/// \param pdg is the O2DatabasePDG service
/// \param registry is the histogram registry
/// \param matCorr is the material correction type to be used in the track propagation
/// \param fitter is the DCAFitter object
/// \param rejectPairsWithCommonDaughter is a flag to activate rejection of pairs sharing a daughter track
/// \param rowCollisionReduced is the collision reduced table to be filled
/// \param rowCandDmesReduced is the D-meson reduced table to be filled
/// \param rowCandV0Reduced is the V0 reduced table to be filled
/// \param rowTrkReduced is the track reduced table to be filled
/// \param rowMcRecV0Reduced is the MC reco D-V0 reduced table to be filled
/// \param rowMcRecTrkReduced is the MC reco D-track reduced table to be filled
/// \param rowCandDmesMlReduced is the ML reduced table to be filled
template <bool WithMl, bool DoMc, DMesonType DType, PairingType PairType, typename Coll, typename CCands, typename Tr, typename TrIU, typename PParticles, typename BBachV0s, typename BBachTracks, typename DmesCuts, typename TrkCuts, typename V0Cuts, typename QaConfig, typename TableCollRed, typename TableCandDRed, typename TableCandV0Red, typename TableTrkRed, typename TableMcRecV0Red, typename TableMcRecTrkRed, typename TableCandDMlRed>
void runDataCreation(Coll const& collision,
CCands const& candsD,
BBachV0s const& bachelorV0s,
BBachTracks const& bachelorTrks,
Tr const& tracks,
TrIU const& tracksIU,
PParticles const& particlesMc,
o2::hf_evsel::HfCollisionRejectionMask hfRejMap,
const float bz,
o2::framework::Service<o2::framework::O2DatabasePDG> const& pdg,
o2::framework::HistogramRegistry& registry,
o2::base::Propagator::MatCorrType const& matCorr,
o2::vertexing::DCAFitterN<2>& fitter,
DmesCuts const& cfgDmesCuts,
TrkCuts const& cfgSingleTrackCuts,
V0Cuts const& cfgV0Cuts,
QaConfig const& cfgQaPlots,
bool rejectPairsWithCommonDaughter,
TableCollRed& rowCollisionReduced,
TableCandDRed& rowCandDmesReduced,
TableCandV0Red& rowCandV0Reduced,
TableTrkRed& rowTrkReduced,
TableMcRecV0Red& rowMcRecV0Reduced,
TableMcRecTrkRed& rowMcRecTrkReduced,
TableCandDMlRed& rowCandDmesMlReduced)
{
int const indexHfReducedCollision = rowCollisionReduced.lastIndex() + 1;
// std::map where the key is the V0.globalIndex() and
// the value is the V0 index in the table of the selected v0s
std::map<int64_t, int64_t> selectedV0s;
std::map<int64_t, int64_t> selectedTracks;
bool fillHfReducedCollision = false;
constexpr bool DoTracks = PairType == PairingType::TrackOnly || PairType == PairingType::V0AndTrack;
constexpr bool DoV0s = PairType == PairingType::V0Only || PairType == PairingType::V0AndTrack;
// loop on D candidates
for (const auto& candD : candsD) {
// initialize variables depending on D meson type
bool fillHfCandD = false;
std::array<float, 3> secondaryVertexD{};
std::array<int, 3> prongIdsD{};
std::array<float, 6> bdtScores = {-1.f, -1.f, -1.f, -1.f, -1.f, -1.f};
std::vector<std::decay_t<typename TrIU::iterator>> charmHadDauTracks{};
HfResoVarContainer varUtils;
varUtils.ptD = candD.pt();
if constexpr (DType == DMesonType::Dstar) {
varUtils.signD = candD.signSoftPi();
if (varUtils.signD > 0) {
varUtils.invMassD = candD.invMassDstar();
varUtils.invMassD0 = candD.invMassD0();
} else {
varUtils.invMassD = candD.invMassAntiDstar();