forked from AliceO2Group/O2Physics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcandidateCreator2Prong.cxx
More file actions
1056 lines (937 loc) · 60.2 KB
/
candidateCreator2Prong.cxx
File metadata and controls
1056 lines (937 loc) · 60.2 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 candidateCreator2Prong.cxx
/// \brief Reconstruction of heavy-flavour 2-prong decay candidates
///
/// \author Gian Michele Innocenti <gian.michele.innocenti@cern.ch>, CERN
/// \author Vít Kučera <vit.kucera@cern.ch>, CERN
/// \author Pengzhong Lu <pengzhong.lu@cern.ch>, GSI Darmstadt, USTC
#ifndef HomogeneousField
#define HomogeneousField // o2-linter: disable=name/macro (required by KFParticle)
#endif
#include "PWGHF/Core/CentralityEstimation.h"
#include "PWGHF/Core/DecayChannels.h"
#include "PWGHF/Core/SelectorCuts.h"
#include "PWGHF/DataModel/CandidateReconstructionTables.h"
#include "PWGHF/Utils/utilsBfieldCCDB.h"
#include "PWGHF/Utils/utilsEvSelHf.h"
#include "PWGHF/Utils/utilsMcGen.h"
#include "PWGHF/Utils/utilsMcMatching.h"
#include "PWGHF/Utils/utilsPid.h"
#include "PWGHF/Utils/utilsTrkCandHf.h"
#include "PWGLF/DataModel/mcCentrality.h"
#include "Common/Core/trackUtilities.h"
#include "Tools/KFparticle/KFUtilities.h"
#include "CommonConstants/PhysicsConstants.h"
#include "DCAFitter/DCAFitterN.h"
#include "Framework/AnalysisTask.h"
#include "Framework/HistogramRegistry.h"
#include "Framework/RunningWorkflowInfo.h"
#include "Framework/runDataProcessing.h"
#include "ReconstructionDataFormats/DCA.h"
#include <TPDGCode.h>
#include <KFPTrack.h>
#include <KFPVertex.h>
#include <KFParticle.h>
#include <KFParticleBase.h>
#include <KFVertex.h>
#include <memory>
#include <string>
#include <vector>
using namespace o2;
using namespace o2::analysis;
using namespace o2::hf_evsel;
using namespace o2::hf_trkcandsel;
using namespace o2::aod::hf_cand_2prong;
using namespace o2::hf_decay;
using namespace o2::hf_decay::hf_cand_2prong;
using namespace o2::hf_centrality;
using namespace o2::hf_occupancy;
using namespace o2::constants::physics;
using namespace o2::framework;
using namespace o2::aod::pid_tpc_tof_utils;
/// Reconstruction of heavy-flavour 2-prong decay candidates
struct HfCandidateCreator2Prong {
Produces<aod::HfCand2ProngBase> rowCandidateBase;
Produces<aod::HfProng0PidPi> rowProng0PidPi;
Produces<aod::HfProng0PidKa> rowProng0PidKa;
Produces<aod::HfProng1PidPi> rowProng1PidPi;
Produces<aod::HfProng1PidKa> rowProng1PidKa;
Produces<aod::HfCand2ProngKF> rowCandidateKF;
// vertexing
Configurable<bool> constrainKfToPv{"constrainKfToPv", true, "constraint KFParticle to PV"};
Configurable<bool> propagateToPCA{"propagateToPCA", true, "create tracks version propagated to PCA"};
Configurable<bool> useAbsDCA{"useAbsDCA", false, "Minimise abs. distance rather than chi2"};
Configurable<bool> useWeightedFinalPCA{"useWeightedFinalPCA", false, "Recalculate vertex position using track covariances, effective only if useAbsDCA is true"};
Configurable<double> maxR{"maxR", 200., "reject PCA's above this radius"};
Configurable<double> maxDZIni{"maxDZIni", 4., "reject (if>0) PCA candidate if tracks DZ exceeds threshold"};
Configurable<double> minParamChange{"minParamChange", 1.e-3, "stop iterations if largest change of any X is smaller than this"};
Configurable<double> minRelChi2Change{"minRelChi2Change", 0.9, "stop iterations is chi2/chi2old > this"};
Configurable<bool> fillHistograms{"fillHistograms", true, "do validation plots"};
// magnetic field setting from CCDB
Configurable<bool> isRun2{"isRun2", false, "enable Run 2 or Run 3 GRP objects for magnetic field"};
Configurable<std::string> ccdbUrl{"ccdbUrl", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
Configurable<std::string> ccdbPathGrp{"ccdbPathGrp", "GLO/GRP/GRP", "Path of the grp file (Run 2)"};
Configurable<std::string> ccdbPathGrpMag{"ccdbPathGrpMag", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object (Run 3)"};
HfEventSelection hfEvSel; // event selection and monitoring
o2::vertexing::DCAFitterN<2> df; // 2-prong vertex fitter
Service<o2::ccdb::BasicCCDBManager> ccdb;
using TracksWCovExtraPidPiKa = soa::Join<aod::TracksWCovExtra, aod::TracksPidPi, aod::PidTpcTofFullPi, aod::TracksPidKa, aod::PidTpcTofFullKa>;
int runNumber{0};
float toMicrometers = 10000.; // from cm to µm
double massPi{0.};
double massK{0.};
double massPiK{0.};
double massKPi{0.};
double bz{0.};
std::shared_ptr<TH1> hCandidates;
HistogramRegistry registry{"registry"};
void init(InitContext const&)
{
std::array<bool, 8> doprocessDF{doprocessPvRefitWithDCAFitterN, doprocessNoPvRefitWithDCAFitterN,
doprocessPvRefitWithDCAFitterNCentFT0C, doprocessNoPvRefitWithDCAFitterNCentFT0C,
doprocessPvRefitWithDCAFitterNCentFT0M, doprocessNoPvRefitWithDCAFitterNCentFT0M, doprocessPvRefitWithDCAFitterNUpc, doprocessNoPvRefitWithDCAFitterNUpc};
std::array<bool, 8> doprocessKF{doprocessPvRefitWithKFParticle, doprocessNoPvRefitWithKFParticle,
doprocessPvRefitWithKFParticleCentFT0C, doprocessNoPvRefitWithKFParticleCentFT0C,
doprocessPvRefitWithKFParticleCentFT0M, doprocessNoPvRefitWithKFParticleCentFT0M, doprocessPvRefitWithKFParticleUpc, doprocessNoPvRefitWithKFParticleUpc};
if ((std::accumulate(doprocessDF.begin(), doprocessDF.end(), 0) + std::accumulate(doprocessKF.begin(), doprocessKF.end(), 0)) != 1) {
LOGP(fatal, "One and only one process function must be enabled at a time.");
}
std::array<bool, 4> processesCollisions = {doprocessCollisions, doprocessCollisionsCentFT0C, doprocessCollisionsCentFT0M, doprocessCollisionsUpc};
const int nProcessesCollisions = std::accumulate(processesCollisions.begin(), processesCollisions.end(), 0);
std::array<bool, 5> processesCollisionsUpc = {doprocessPvRefitWithDCAFitterNUpc, doprocessNoPvRefitWithDCAFitterNUpc, doprocessPvRefitWithKFParticleUpc, doprocessNoPvRefitWithKFParticleUpc, doprocessCollisionsUpc};
const int nProcessesCollisionsUpc = std::accumulate(processesCollisionsUpc.begin(), processesCollisionsUpc.end(), 0);
if (nProcessesCollisions > 1) {
LOGP(fatal, "At most one process function for collision monitoring can be enabled at a time.");
}
if (nProcessesCollisions == 1) {
if ((doprocessPvRefitWithDCAFitterN || doprocessNoPvRefitWithDCAFitterN || doprocessPvRefitWithKFParticle || doprocessNoPvRefitWithKFParticle) && !doprocessCollisions) {
LOGP(fatal, "Process function for collision monitoring not correctly enabled. Did you enable \"processCollisions\"?");
}
if ((doprocessPvRefitWithDCAFitterNCentFT0C || doprocessNoPvRefitWithDCAFitterNCentFT0C || doprocessPvRefitWithKFParticleCentFT0C || doprocessNoPvRefitWithKFParticleCentFT0C) && !doprocessCollisionsCentFT0C) {
LOGP(fatal, "Process function for collision monitoring not correctly enabled. Did you enable \"processCollisionsCentFT0C\"?");
}
if ((doprocessPvRefitWithDCAFitterNCentFT0M || doprocessNoPvRefitWithDCAFitterNCentFT0M || doprocessPvRefitWithKFParticleCentFT0M || doprocessNoPvRefitWithKFParticleCentFT0M) && !doprocessCollisionsCentFT0M) {
LOGP(fatal, "Process function for collision monitoring not correctly enabled. Did you enable \"processCollisionsCentFT0M\"?");
}
}
if (nProcessesCollisionsUpc > 0 && isRun2) {
LOGP(fatal, "Process function for UPC is only available in Run 3!");
}
// histograms
registry.add("hMass2", "2-prong candidates;inv. mass (#pi K) (GeV/#it{c}^{2});entries", {HistType::kTH1F, {{500, 1.6, 2.1}}});
registry.add("hCovPVXX", "2-prong candidates;XX element of cov. matrix of prim. vtx. position (cm^{2});entries", {HistType::kTH1F, {{100, 0., 1.e-4}}});
registry.add("hCovSVXX", "2-prong candidates;XX element of cov. matrix of sec. vtx. position (cm^{2});entries", {HistType::kTH1F, {{100, 0., 0.2}}});
registry.add("hCovPVYY", "2-prong candidates;YY element of cov. matrix of prim. vtx. position (cm^{2});entries", {HistType::kTH1F, {{100, 0., 1.e-4}}});
registry.add("hCovSVYY", "2-prong candidates;YY element of cov. matrix of sec. vtx. position (cm^{2});entries", {HistType::kTH1F, {{100, 0., 0.2}}});
registry.add("hCovPVXZ", "2-prong candidates;XZ element of cov. matrix of prim. vtx. position (cm^{2});entries", {HistType::kTH1F, {{100, -1.e-4, 1.e-4}}});
registry.add("hCovSVXZ", "2-prong candidates;XZ element of cov. matrix of sec. vtx. position (cm^{2});entries", {HistType::kTH1F, {{100, -1.e-4, 0.2}}});
registry.add("hCovPVZZ", "2-prong candidates;ZZ element of cov. matrix of prim. vtx. position (cm^{2});entries", {HistType::kTH1F, {{100, 0., 1.e-4}}});
registry.add("hCovSVZZ", "2-prong candidates;ZZ element of cov. matrix of sec. vtx. position (cm^{2});entries", {HistType::kTH1F, {{100, 0., 0.2}}});
registry.add("hDcaXYProngs", "DCAxy of 2-prong candidate daughters;#it{p}_{T} (GeV/#it{c};#it{d}_{xy}) (#mum);entries", {HistType::kTH2F, {{100, 0., 20.}, {200, -500., 500.}}});
registry.add("hDcaZProngs", "DCAz of 2-prong candidate daughters;#it{p}_{T} (GeV/#it{c};#it{d}_{z}) (#mum);entries", {HistType::kTH2F, {{100, 0., 20.}, {200, -500., 500.}}});
registry.add("hVertexerType", "Use KF or DCAFitterN;Vertexer type;entries", {HistType::kTH1D, {{2, -0.5, 1.5}}}); // See o2::aod::hf_cand::VertexerType
hCandidates = registry.add<TH1>("hCandidates", "candidates counter", {HistType::kTH1D, {axisCands}});
// init HF event selection helper
hfEvSel.init(registry);
massPi = MassPiPlus;
massK = MassKPlus;
if (std::accumulate(doprocessDF.begin(), doprocessDF.end(), 0) == 1) {
registry.fill(HIST("hVertexerType"), aod::hf_cand::VertexerType::DCAFitter);
// Configure DCAFitterN
// df.setBz(bz);
df.setPropagateToPCA(propagateToPCA);
df.setMaxR(maxR);
df.setMaxDZIni(maxDZIni);
df.setMinParamChange(minParamChange);
df.setMinRelChi2Change(minRelChi2Change);
df.setUseAbsDCA(useAbsDCA);
df.setWeightedFinalPCA(useWeightedFinalPCA);
}
if (std::accumulate(doprocessKF.begin(), doprocessKF.end(), 0) == 1) {
registry.fill(HIST("hVertexerType"), aod::hf_cand::VertexerType::KfParticle);
}
ccdb->setURL(ccdbUrl);
ccdb->setCaching(true);
ccdb->setLocalObjectValidityChecking();
runNumber = 0;
/// candidate monitoring
setLabelHistoCands(hCandidates);
}
template <bool doPvRefit, bool applyUpcSel, o2::hf_centrality::CentralityEstimator centEstimator, typename Coll, typename CandType, typename TTracks, typename BCsType>
void runCreator2ProngWithDCAFitterN(Coll const&,
CandType const& rowsTrackIndexProng2,
TTracks const&,
BCsType const& bcs)
{
// loop over pairs of track indices
for (const auto& rowTrackIndexProng2 : rowsTrackIndexProng2) {
/// reject candidates not satisfying the event selections
auto collision = rowTrackIndexProng2.template collision_as<Coll>();
float centrality{-1.f};
uint32_t rejectionMask{0};
if constexpr (applyUpcSel) {
rejectionMask = hfEvSel.getHfCollisionRejectionMaskWithUpc<true, centEstimator, BCsType>(collision, centrality, ccdb, registry, bcs);
} else {
rejectionMask = hfEvSel.getHfCollisionRejectionMask<true, centEstimator, BCsType>(collision, centrality, ccdb, registry);
}
if (rejectionMask != 0) {
/// at least one event selection not satisfied --> reject the candidate
continue;
}
auto track0 = rowTrackIndexProng2.template prong0_as<TTracks>();
auto track1 = rowTrackIndexProng2.template prong1_as<TTracks>();
auto trackParVarPos1 = getTrackParCov(track0);
auto trackParVarNeg1 = getTrackParCov(track1);
/// Set the magnetic field from ccdb.
/// The static instance of the propagator was already modified in the HFTrackIndexSkimCreator,
/// but this is not true when running on Run2 data/MC already converted into AO2Ds.
auto bc = collision.template bc_as<BCsType>();
if (runNumber != bc.runNumber()) {
LOG(info) << ">>>>>>>>>>>> Current run number: " << runNumber;
initCCDB(bc, runNumber, ccdb, isRun2 ? ccdbPathGrp : ccdbPathGrpMag, nullptr, isRun2);
bz = o2::base::Propagator::Instance()->getNominalBz();
LOG(info) << ">>>>>>>>>>>> Magnetic field: " << bz;
// df.setBz(bz); /// put it outside the 'if'! Otherwise we have a difference wrt bz Configurable (< 1 permille) in Run2 conv. data
// df.print();
}
df.setBz(bz);
// reconstruct the 2-prong secondary vertex
hCandidates->Fill(SVFitting::BeforeFit);
try {
if (df.process(trackParVarPos1, trackParVarNeg1) == 0) {
continue;
}
} catch (const std::runtime_error& error) {
LOG(info) << "Run time error found: " << error.what() << ". DCAFitterN cannot work, skipping the candidate.";
hCandidates->Fill(SVFitting::Fail);
continue;
}
hCandidates->Fill(SVFitting::FitOk);
const auto& secondaryVertex = df.getPCACandidate();
auto chi2PCA = df.getChi2AtPCACandidate();
auto covMatrixPCA = df.calcPCACovMatrixFlat();
registry.fill(HIST("hCovSVXX"), covMatrixPCA[0]); // FIXME: Calculation of errorDecayLength(XY) gives wrong values without this line.
registry.fill(HIST("hCovSVYY"), covMatrixPCA[2]);
registry.fill(HIST("hCovSVXZ"), covMatrixPCA[3]);
registry.fill(HIST("hCovSVZZ"), covMatrixPCA[5]);
auto trackParVar0 = df.getTrack(0);
auto trackParVar1 = df.getTrack(1);
// get track momenta
std::array<float, 3> pvec0;
std::array<float, 3> pvec1;
trackParVar0.getPxPyPzGlo(pvec0);
trackParVar1.getPxPyPzGlo(pvec1);
// get track impact parameters
// This modifies track momenta!
auto primaryVertex = getPrimaryVertex(collision);
auto covMatrixPV = primaryVertex.getCov();
if constexpr (doPvRefit) {
/// use PV refit
/// Using it in the rowCandidateBase all dynamic columns shall take it into account
// coordinates
primaryVertex.setX(rowTrackIndexProng2.pvRefitX());
primaryVertex.setY(rowTrackIndexProng2.pvRefitY());
primaryVertex.setZ(rowTrackIndexProng2.pvRefitZ());
// covariance matrix
primaryVertex.setSigmaX2(rowTrackIndexProng2.pvRefitSigmaX2());
primaryVertex.setSigmaXY(rowTrackIndexProng2.pvRefitSigmaXY());
primaryVertex.setSigmaY2(rowTrackIndexProng2.pvRefitSigmaY2());
primaryVertex.setSigmaXZ(rowTrackIndexProng2.pvRefitSigmaXZ());
primaryVertex.setSigmaYZ(rowTrackIndexProng2.pvRefitSigmaYZ());
primaryVertex.setSigmaZ2(rowTrackIndexProng2.pvRefitSigmaZ2());
covMatrixPV = primaryVertex.getCov();
}
registry.fill(HIST("hCovPVXX"), covMatrixPV[0]);
registry.fill(HIST("hCovPVYY"), covMatrixPV[2]);
registry.fill(HIST("hCovPVXZ"), covMatrixPV[3]);
registry.fill(HIST("hCovPVZZ"), covMatrixPV[5]);
o2::dataformats::DCA impactParameter0;
o2::dataformats::DCA impactParameter1;
trackParVar0.propagateToDCA(primaryVertex, bz, &impactParameter0);
trackParVar1.propagateToDCA(primaryVertex, bz, &impactParameter1);
registry.fill(HIST("hDcaXYProngs"), track0.pt(), impactParameter0.getY() * toMicrometers);
registry.fill(HIST("hDcaXYProngs"), track1.pt(), impactParameter1.getY() * toMicrometers);
registry.fill(HIST("hDcaZProngs"), track0.pt(), impactParameter0.getZ() * toMicrometers);
registry.fill(HIST("hDcaZProngs"), track1.pt(), impactParameter1.getZ() * toMicrometers);
// get uncertainty of the decay length
double phi, theta;
getPointDirection(std::array{primaryVertex.getX(), primaryVertex.getY(), primaryVertex.getZ()}, secondaryVertex, phi, theta);
auto errorDecayLength = std::sqrt(getRotatedCovMatrixXX(covMatrixPV, phi, theta) + getRotatedCovMatrixXX(covMatrixPCA, phi, theta));
auto errorDecayLengthXY = std::sqrt(getRotatedCovMatrixXX(covMatrixPV, phi, 0.) + getRotatedCovMatrixXX(covMatrixPCA, phi, 0.));
auto indexCollision = collision.globalIndex();
uint8_t bitmapProngsContributorsPV = 0;
if (indexCollision == track0.collisionId() && track0.isPVContributor()) {
SETBIT(bitmapProngsContributorsPV, 0);
}
if (indexCollision == track1.collisionId() && track1.isPVContributor()) {
SETBIT(bitmapProngsContributorsPV, 1);
}
uint8_t nProngsContributorsPV = hf_trkcandsel::countOnesInBinary(bitmapProngsContributorsPV);
// fill candidate table rows
rowCandidateBase(indexCollision,
primaryVertex.getX(), primaryVertex.getY(), primaryVertex.getZ(),
secondaryVertex[0], secondaryVertex[1], secondaryVertex[2],
errorDecayLength, errorDecayLengthXY,
chi2PCA,
pvec0[0], pvec0[1], pvec0[2],
pvec1[0], pvec1[1], pvec1[2],
impactParameter0.getY(), impactParameter1.getY(),
std::sqrt(impactParameter0.getSigmaY2()), std::sqrt(impactParameter1.getSigmaY2()),
impactParameter0.getZ(), impactParameter1.getZ(),
std::sqrt(impactParameter0.getSigmaZ2()), std::sqrt(impactParameter1.getSigmaZ2()),
rowTrackIndexProng2.prong0Id(), rowTrackIndexProng2.prong1Id(), nProngsContributorsPV, bitmapProngsContributorsPV,
rowTrackIndexProng2.hfflag());
// fill candidate prong PID rows
fillProngPid<HfProngSpecies::Pion>(track0, rowProng0PidPi);
fillProngPid<HfProngSpecies::Kaon>(track0, rowProng0PidKa);
fillProngPid<HfProngSpecies::Pion>(track1, rowProng1PidPi);
fillProngPid<HfProngSpecies::Kaon>(track1, rowProng1PidKa);
// fill histograms
if (fillHistograms) {
// calculate invariant masses
auto arrayMomenta = std::array{pvec0, pvec1};
massPiK = RecoDecay::m(arrayMomenta, std::array{massPi, massK});
massKPi = RecoDecay::m(arrayMomenta, std::array{massK, massPi});
registry.fill(HIST("hMass2"), massPiK);
registry.fill(HIST("hMass2"), massKPi);
}
}
}
template <bool doPvRefit, bool applyUpcSel, o2::hf_centrality::CentralityEstimator centEstimator, typename Coll, typename CandType, typename TTracks, typename BCsType>
void runCreator2ProngWithKFParticle(Coll const&,
CandType const& rowsTrackIndexProng2,
TTracks const&,
BCsType const& bcs)
{
for (const auto& rowTrackIndexProng2 : rowsTrackIndexProng2) {
/// reject candidates in collisions not satisfying the event selections
auto collision = rowTrackIndexProng2.template collision_as<Coll>();
float centrality{-1.f};
uint32_t rejectionMask{0};
if constexpr (applyUpcSel) {
rejectionMask = hfEvSel.getHfCollisionRejectionMaskWithUpc<true, centEstimator, BCsType>(collision, centrality, ccdb, registry, bcs);
} else {
rejectionMask = hfEvSel.getHfCollisionRejectionMask<true, centEstimator, BCsType>(collision, centrality, ccdb, registry);
}
if (rejectionMask != 0) {
/// at least one event selection not satisfied --> reject the candidate
continue;
}
auto track0 = rowTrackIndexProng2.template prong0_as<TTracks>();
auto track1 = rowTrackIndexProng2.template prong1_as<TTracks>();
/// Set the magnetic field from ccdb.
/// The static instance of the propagator was already modified in the HFTrackIndexSkimCreator,
/// but this is not true when running on Run2 data/MC already converted into AO2Ds.
auto bc = collision.template bc_as<BCsType>();
if (runNumber != bc.runNumber()) {
LOG(info) << ">>>>>>>>>>>> Current run number: " << runNumber;
initCCDB(bc, runNumber, ccdb, isRun2 ? ccdbPathGrp : ccdbPathGrpMag, nullptr, isRun2);
bz = o2::base::Propagator::Instance()->getNominalBz();
LOG(info) << ">>>>>>>>>>>> Magnetic field: " << bz;
// df.setBz(bz); /// put it outside the 'if'! Otherwise we have a difference wrt bz Configurable (< 1 permille) in Run2 conv. data
// df.print();
}
float covMatrixPV[6];
KFParticle::SetField(bz);
KFPVertex kfpVertex = createKFPVertexFromCollision(collision);
if constexpr (doPvRefit) {
/// use PV refit
/// Using it in the rowCandidateBase all dynamic columns shall take it into account
// coordinates
kfpVertex.SetXYZ(rowTrackIndexProng2.pvRefitX(), rowTrackIndexProng2.pvRefitY(), rowTrackIndexProng2.pvRefitZ());
// covariance matrix
kfpVertex.SetCovarianceMatrix(rowTrackIndexProng2.pvRefitSigmaX2(), rowTrackIndexProng2.pvRefitSigmaXY(), rowTrackIndexProng2.pvRefitSigmaY2(), rowTrackIndexProng2.pvRefitSigmaXZ(), rowTrackIndexProng2.pvRefitSigmaYZ(), rowTrackIndexProng2.pvRefitSigmaZ2());
}
kfpVertex.GetCovarianceMatrix(covMatrixPV);
KFParticle kfpV(kfpVertex);
registry.fill(HIST("hCovPVXX"), covMatrixPV[0]);
registry.fill(HIST("hCovPVYY"), covMatrixPV[2]);
registry.fill(HIST("hCovPVXZ"), covMatrixPV[3]);
registry.fill(HIST("hCovPVZZ"), covMatrixPV[5]);
KFPTrack kfpTrack0 = createKFPTrackFromTrack(track0);
KFPTrack kfpTrack1 = createKFPTrackFromTrack(track1);
KFParticle kfPosPion(kfpTrack0, kPiPlus);
KFParticle kfNegPion(kfpTrack1, kPiPlus);
KFParticle kfPosKaon(kfpTrack0, kKPlus);
KFParticle kfNegKaon(kfpTrack1, kKPlus);
float impactParameter0XY = 0., errImpactParameter0XY = 0., impactParameter1XY = 0., errImpactParameter1XY = 0.;
if (!kfPosPion.GetDistanceFromVertexXY(kfpV, impactParameter0XY, errImpactParameter0XY)) {
registry.fill(HIST("hDcaXYProngs"), track0.pt(), impactParameter0XY * toMicrometers);
registry.fill(HIST("hDcaZProngs"), track0.pt(), std::sqrt(kfPosPion.GetDistanceFromVertex(kfpV) * kfPosPion.GetDistanceFromVertex(kfpV) - impactParameter0XY * impactParameter0XY) * toMicrometers);
} else {
registry.fill(HIST("hDcaXYProngs"), track0.pt(), -999.f);
registry.fill(HIST("hDcaZProngs"), track0.pt(), -999.f);
}
if (!kfNegPion.GetDistanceFromVertexXY(kfpV, impactParameter1XY, errImpactParameter1XY)) {
registry.fill(HIST("hDcaXYProngs"), track1.pt(), impactParameter1XY * toMicrometers);
registry.fill(HIST("hDcaZProngs"), track1.pt(), std::sqrt(kfNegPion.GetDistanceFromVertex(kfpV) * kfNegPion.GetDistanceFromVertex(kfpV) - impactParameter1XY * impactParameter1XY) * toMicrometers);
} else {
registry.fill(HIST("hDcaXYProngs"), track1.pt(), -999.f);
registry.fill(HIST("hDcaZProngs"), track1.pt(), -999.f);
}
KFParticle kfCandD0;
const KFParticle* kfDaughtersD0[2] = {&kfPosPion, &kfNegKaon};
kfCandD0.SetConstructMethod(2);
kfCandD0.Construct(kfDaughtersD0, 2);
KFParticle kfCandD0bar;
const KFParticle* kfDaughtersD0bar[2] = {&kfNegPion, &kfPosKaon};
kfCandD0bar.SetConstructMethod(2);
kfCandD0bar.Construct(kfDaughtersD0bar, 2);
auto massD0 = kfCandD0.GetMass();
auto massD0bar = kfCandD0bar.GetMass();
registry.fill(HIST("hCovSVXX"), kfCandD0.Covariance(0, 0));
registry.fill(HIST("hCovSVYY"), kfCandD0.Covariance(1, 1));
registry.fill(HIST("hCovSVXZ"), kfCandD0.Covariance(2, 0));
registry.fill(HIST("hCovSVZZ"), kfCandD0.Covariance(2, 2));
auto covMatrixSV = kfCandD0.CovarianceMatrix();
double phi, theta;
getPointDirection(std::array{kfpV.GetX(), kfpV.GetY(), kfpV.GetZ()}, std::array{kfCandD0.GetX(), kfCandD0.GetY(), kfCandD0.GetZ()}, phi, theta);
auto errorDecayLength = std::sqrt(getRotatedCovMatrixXX(covMatrixPV, phi, theta) + getRotatedCovMatrixXX(covMatrixSV, phi, theta));
auto errorDecayLengthXY = std::sqrt(getRotatedCovMatrixXX(covMatrixPV, phi, 0.) + getRotatedCovMatrixXX(covMatrixSV, phi, 0.));
float topolChi2PerNdfD0 = -999.;
KFParticle kfCandD0Topol2PV;
if (constrainKfToPv) {
kfCandD0Topol2PV = kfCandD0;
kfCandD0Topol2PV.SetProductionVertex(kfpV);
topolChi2PerNdfD0 = kfCandD0Topol2PV.GetChi2() / kfCandD0Topol2PV.GetNDF();
}
auto indexCollision = collision.globalIndex();
uint8_t bitmapProngsContributorsPV = 0;
if (indexCollision == track0.collisionId() && track0.isPVContributor()) {
SETBIT(bitmapProngsContributorsPV, 0);
}
if (indexCollision == track1.collisionId() && track1.isPVContributor()) {
SETBIT(bitmapProngsContributorsPV, 1);
}
uint8_t nProngsContributorsPV = hf_trkcandsel::countOnesInBinary(bitmapProngsContributorsPV);
// fill candidate table rows
rowCandidateBase(indexCollision,
kfpV.GetX(), kfpV.GetY(), kfpV.GetZ(),
kfCandD0.GetX(), kfCandD0.GetY(), kfCandD0.GetZ(),
errorDecayLength, errorDecayLengthXY, // TODO: much different from the DCAFitterN one
kfCandD0.GetChi2() / kfCandD0.GetNDF(), // TODO: to make sure it should be chi2 only or chi2/ndf, much different from the DCAFitterN one
kfPosPion.GetPx(), kfPosPion.GetPy(), kfPosPion.GetPz(),
kfNegKaon.GetPx(), kfNegKaon.GetPy(), kfNegKaon.GetPz(),
impactParameter0XY, impactParameter1XY,
errImpactParameter0XY, errImpactParameter1XY,
0.f, 0.f,
0.f, 0.f,
rowTrackIndexProng2.prong0Id(), rowTrackIndexProng2.prong1Id(), nProngsContributorsPV, bitmapProngsContributorsPV,
rowTrackIndexProng2.hfflag());
// fill candidate prong PID rows
fillProngPid<HfProngSpecies::Pion>(track0, rowProng0PidPi);
fillProngPid<HfProngSpecies::Kaon>(track0, rowProng0PidKa);
fillProngPid<HfProngSpecies::Pion>(track1, rowProng1PidPi);
fillProngPid<HfProngSpecies::Kaon>(track1, rowProng1PidKa);
// fill KF info
rowCandidateKF(topolChi2PerNdfD0,
massD0, massD0bar);
// fill histograms
if (fillHistograms) {
registry.fill(HIST("hMass2"), massD0);
registry.fill(HIST("hMass2"), massD0bar);
}
}
}
///////////////////////////////////
/// ///
/// No centrality selection ///
/// ///
///////////////////////////////////
/// @brief process function using DCA fitter w/ PV refit and w/o centrality selections
void processPvRefitWithDCAFitterN(soa::Join<aod::Collisions, aod::EvSels> const& collisions,
soa::Join<aod::Hf2Prongs, aod::HfPvRefit2Prong> const& rowsTrackIndexProng2,
TracksWCovExtraPidPiKa const& tracks,
aod::BCsWithTimestamps const& bcWithTimeStamps)
{
runCreator2ProngWithDCAFitterN</*doPvRefit*/ true, false, CentralityEstimator::None>(collisions, rowsTrackIndexProng2, tracks, bcWithTimeStamps);
}
PROCESS_SWITCH(HfCandidateCreator2Prong, processPvRefitWithDCAFitterN, "Run candidate creator using DCA fitter w/ PV refit and w/o centrality selections", false);
/// @brief process function using DCA fitter w/o PV refit and w/o centrality selections
void processNoPvRefitWithDCAFitterN(soa::Join<aod::Collisions, aod::EvSels> const& collisions,
aod::Hf2Prongs const& rowsTrackIndexProng2,
TracksWCovExtraPidPiKa const& tracks,
aod::BCsWithTimestamps const& bcWithTimeStamps)
{
runCreator2ProngWithDCAFitterN</*doPvRefit*/ false, false, CentralityEstimator::None>(collisions, rowsTrackIndexProng2, tracks, bcWithTimeStamps);
}
PROCESS_SWITCH(HfCandidateCreator2Prong, processNoPvRefitWithDCAFitterN, "Run candidate creator using DCA fitter w/o PV refit and w/o centrality selections", true);
/// @brief process function using KFParticle package w/ PV refit and w/o centrality selections
void processPvRefitWithKFParticle(soa::Join<aod::Collisions, aod::EvSels> const& collisions,
soa::Join<aod::Hf2Prongs, aod::HfPvRefit2Prong> const& rowsTrackIndexProng2,
TracksWCovExtraPidPiKa const& tracks,
aod::BCsWithTimestamps const& bcWithTimeStamps)
{
runCreator2ProngWithKFParticle</*doPvRefit*/ true, false, CentralityEstimator::None>(collisions, rowsTrackIndexProng2, tracks, bcWithTimeStamps);
}
PROCESS_SWITCH(HfCandidateCreator2Prong, processPvRefitWithKFParticle, "Run candidate creator using KFParticle package w/ PV refit and w/o centrality selections", false);
/// @brief process function using KFParticle package w/o PV refit and w/o centrality selections
void processNoPvRefitWithKFParticle(soa::Join<aod::Collisions, aod::EvSels> const& collisions,
aod::Hf2Prongs const& rowsTrackIndexProng2,
TracksWCovExtraPidPiKa const& tracks,
aod::BCsWithTimestamps const& bcWithTimeStamps)
{
runCreator2ProngWithKFParticle</*doPvRefit*/ false, false, CentralityEstimator::None>(collisions, rowsTrackIndexProng2, tracks, bcWithTimeStamps);
}
PROCESS_SWITCH(HfCandidateCreator2Prong, processNoPvRefitWithKFParticle, "Run candidate creator using KFParticle package w/o PV refit and w/o centrality selections", false);
/////////////////////////////////////////////
/// ///
/// with centrality selection on FT0C ///
/// ///
/////////////////////////////////////////////
/// @brief process function using DCA fitter w/ PV refit and w/ centrality selection on FT0C
void processPvRefitWithDCAFitterNCentFT0C(soa::Join<aod::Collisions, aod::EvSels, aod::CentFT0Cs> const& collisions,
soa::Join<aod::Hf2Prongs, aod::HfPvRefit2Prong> const& rowsTrackIndexProng2,
TracksWCovExtraPidPiKa const& tracks,
aod::BCsWithTimestamps const& bcWithTimeStamps)
{
runCreator2ProngWithDCAFitterN</*doPvRefit*/ true, false, CentralityEstimator::FT0C>(collisions, rowsTrackIndexProng2, tracks, bcWithTimeStamps);
}
PROCESS_SWITCH(HfCandidateCreator2Prong, processPvRefitWithDCAFitterNCentFT0C, "Run candidate creator using DCA fitter w/ PV refit and w/ centrality selection on FT0C", false);
/// @brief process function using DCA fitter w/o PV refit and w/ centrality selection FT0C
void processNoPvRefitWithDCAFitterNCentFT0C(soa::Join<aod::Collisions, aod::EvSels, aod::CentFT0Cs> const& collisions,
aod::Hf2Prongs const& rowsTrackIndexProng2,
TracksWCovExtraPidPiKa const& tracks,
aod::BCsWithTimestamps const& bcWithTimeStamps)
{
runCreator2ProngWithDCAFitterN</*doPvRefit*/ false, false, CentralityEstimator::FT0C>(collisions, rowsTrackIndexProng2, tracks, bcWithTimeStamps);
}
PROCESS_SWITCH(HfCandidateCreator2Prong, processNoPvRefitWithDCAFitterNCentFT0C, "Run candidate creator using DCA fitter w/o PV refit and w/ centrality selection FT0C", false);
/// @brief process function using KFParticle package w/ PV refit and w/ centrality selection on FT0C
void processPvRefitWithKFParticleCentFT0C(soa::Join<aod::Collisions, aod::EvSels, aod::CentFT0Cs> const& collisions,
soa::Join<aod::Hf2Prongs, aod::HfPvRefit2Prong> const& rowsTrackIndexProng2,
TracksWCovExtraPidPiKa const& tracks,
aod::BCsWithTimestamps const& bcWithTimeStamps)
{
runCreator2ProngWithKFParticle</*doPvRefit*/ true, false, CentralityEstimator::FT0C>(collisions, rowsTrackIndexProng2, tracks, bcWithTimeStamps);
}
PROCESS_SWITCH(HfCandidateCreator2Prong, processPvRefitWithKFParticleCentFT0C, "Run candidate creator using KFParticle package w/ PV refit and w/ centrality selection on FT0C", false);
/// @brief process function using KFParticle package w/o PV refit and w/o centrality selections
void processNoPvRefitWithKFParticleCentFT0C(soa::Join<aod::Collisions, aod::EvSels, aod::CentFT0Cs> const& collisions,
aod::Hf2Prongs const& rowsTrackIndexProng2,
TracksWCovExtraPidPiKa const& tracks,
aod::BCsWithTimestamps const& bcWithTimeStamps)
{
runCreator2ProngWithKFParticle</*doPvRefit*/ false, false, CentralityEstimator::FT0C>(collisions, rowsTrackIndexProng2, tracks, bcWithTimeStamps);
}
PROCESS_SWITCH(HfCandidateCreator2Prong, processNoPvRefitWithKFParticleCentFT0C, "Run candidate creator using KFParticle package w/o PV refit and w/ centrality selection on FT0C", false);
/////////////////////////////////////////////
/// ///
/// with centrality selection on FT0M ///
/// ///
/////////////////////////////////////////////
/// @brief process function using DCA fitter w/ PV refit and w/ centrality selection on FT0M
void processPvRefitWithDCAFitterNCentFT0M(soa::Join<aod::Collisions, aod::EvSels, aod::CentFT0Ms> const& collisions,
soa::Join<aod::Hf2Prongs, aod::HfPvRefit2Prong> const& rowsTrackIndexProng2,
TracksWCovExtraPidPiKa const& tracks,
aod::BCsWithTimestamps const& bcWithTimeStamps)
{
runCreator2ProngWithDCAFitterN</*doPvRefit*/ true, false, CentralityEstimator::FT0M>(collisions, rowsTrackIndexProng2, tracks, bcWithTimeStamps);
}
PROCESS_SWITCH(HfCandidateCreator2Prong, processPvRefitWithDCAFitterNCentFT0M, "Run candidate creator using DCA fitter w/ PV refit and w/ centrality selection on FT0M", false);
/// @brief process function using DCA fitter w/o PV refit and w/ centrality selection FT0M
void processNoPvRefitWithDCAFitterNCentFT0M(soa::Join<aod::Collisions, aod::EvSels, aod::CentFT0Ms> const& collisions,
aod::Hf2Prongs const& rowsTrackIndexProng2,
TracksWCovExtraPidPiKa const& tracks,
aod::BCsWithTimestamps const& bcWithTimeStamps)
{
runCreator2ProngWithDCAFitterN</*doPvRefit*/ false, false, CentralityEstimator::FT0M>(collisions, rowsTrackIndexProng2, tracks, bcWithTimeStamps);
}
PROCESS_SWITCH(HfCandidateCreator2Prong, processNoPvRefitWithDCAFitterNCentFT0M, "Run candidate creator using DCA fitter w/o PV refit and w/ centrality selection FT0M", false);
/// @brief process function using KFParticle package w/ PV refit and w/ centrality selection on FT0M
void processPvRefitWithKFParticleCentFT0M(soa::Join<aod::Collisions, aod::EvSels, aod::CentFT0Ms> const& collisions,
soa::Join<aod::Hf2Prongs, aod::HfPvRefit2Prong> const& rowsTrackIndexProng2,
TracksWCovExtraPidPiKa const& tracks,
aod::BCsWithTimestamps const& bcWithTimeStamps)
{
runCreator2ProngWithKFParticle</*doPvRefit*/ true, false, CentralityEstimator::FT0M>(collisions, rowsTrackIndexProng2, tracks, bcWithTimeStamps);
}
PROCESS_SWITCH(HfCandidateCreator2Prong, processPvRefitWithKFParticleCentFT0M, "Run candidate creator using KFParticle package w/ PV refit and w/ centrality selection on FT0M", false);
/// @brief process function using KFParticle package w/o PV refit and w/o centrality selections
void processNoPvRefitWithKFParticleCentFT0M(soa::Join<aod::Collisions, aod::EvSels, aod::CentFT0Ms> const& collisions,
aod::Hf2Prongs const& rowsTrackIndexProng2,
TracksWCovExtraPidPiKa const& tracks,
aod::BCsWithTimestamps const& bcWithTimeStamps)
{
runCreator2ProngWithKFParticle</*doPvRefit*/ false, false, CentralityEstimator::FT0M>(collisions, rowsTrackIndexProng2, tracks, bcWithTimeStamps);
}
PROCESS_SWITCH(HfCandidateCreator2Prong, processNoPvRefitWithKFParticleCentFT0M, "Run candidate creator using KFParticle package w/o PV refit and w/ centrality selection on FT0M", false);
/////////////////////////////////////////////
/// ///
/// with centrality selection on UPC ///
/// ///
/////////////////////////////////////////////
/// @brief process function using DCA fitter w/ PV refit and w/ centrality selection on UPC
void processPvRefitWithDCAFitterNUpc(soa::Join<aod::Collisions, aod::EvSels> const& collisions,
soa::Join<aod::Hf2Prongs, aod::HfPvRefit2Prong> const& rowsTrackIndexProng2,
TracksWCovExtraPidPiKa const& tracks,
aod::BCFullInfos const& bcWithTimeStamps,
aod::FT0s const& /*ft0s*/,
aod::FV0As const& /*fv0as*/,
aod::FDDs const& /*fdds*/,
aod::Zdcs const& /*zdcs*/)
{
runCreator2ProngWithDCAFitterN</*doPvRefit*/ true, true, CentralityEstimator::None>(collisions, rowsTrackIndexProng2, tracks, bcWithTimeStamps);
}
PROCESS_SWITCH(HfCandidateCreator2Prong, processPvRefitWithDCAFitterNUpc, "Run candidate creator using DCA fitter w/ PV refit and w/ centrality selection on UltraPeripheral Collision", false);
/// @brief process function using DCA fitter w/o PV refit and w/ centrality selection UPC
void processNoPvRefitWithDCAFitterNUpc(soa::Join<aod::Collisions, aod::EvSels> const& collisions,
aod::Hf2Prongs const& rowsTrackIndexProng2,
TracksWCovExtraPidPiKa const& tracks,
aod::BCFullInfos const& bcWithTimeStamps,
aod::FT0s const& /*ft0s*/,
aod::FV0As const& /*fv0as*/,
aod::FDDs const& /*fdds*/,
aod::Zdcs const& /*zdcs*/)
{
runCreator2ProngWithDCAFitterN</*doPvRefit*/ false, true, CentralityEstimator::None>(collisions, rowsTrackIndexProng2, tracks, bcWithTimeStamps);
}
PROCESS_SWITCH(HfCandidateCreator2Prong, processNoPvRefitWithDCAFitterNUpc, "Run candidate creator using DCA fitter w/o PV refit and w/ centrality selection UltraPeripheral Collision", false);
/// @brief process function using KFParticle package w/ PV refit and w/ centrality selection on UPC
void processPvRefitWithKFParticleUpc(soa::Join<aod::Collisions, aod::EvSels> const& collisions,
soa::Join<aod::Hf2Prongs, aod::HfPvRefit2Prong> const& rowsTrackIndexProng2,
TracksWCovExtraPidPiKa const& tracks,
aod::BCFullInfos const& bcWithTimeStamps,
aod::FT0s const& /*ft0s*/,
aod::FV0As const& /*fv0as*/,
aod::FDDs const& /*fdds*/,
aod::Zdcs const& /*zdcs*/)
{
runCreator2ProngWithKFParticle</*doPvRefit*/ true, true, CentralityEstimator::None>(collisions, rowsTrackIndexProng2, tracks, bcWithTimeStamps);
}
PROCESS_SWITCH(HfCandidateCreator2Prong, processPvRefitWithKFParticleUpc, "Run candidate creator using KFParticle package w/ PV refit and w/ centrality selection on UltraPeripheral Collision", false);
/// @brief process function using KFParticle package w/o PV refit and w/o centrality selections on UPC
void processNoPvRefitWithKFParticleUpc(soa::Join<aod::Collisions, aod::EvSels> const& collisions,
aod::Hf2Prongs const& rowsTrackIndexProng2,
TracksWCovExtraPidPiKa const& tracks,
aod::BCFullInfos const& bcWithTimeStamps,
aod::FT0s const& /*ft0s*/,
aod::FV0As const& /*fv0as*/,
aod::FDDs const& /*fdds*/,
aod::Zdcs const& /*zdcs*/)
{
runCreator2ProngWithKFParticle</*doPvRefit*/ false, true, CentralityEstimator::None>(collisions, rowsTrackIndexProng2, tracks, bcWithTimeStamps);
}
PROCESS_SWITCH(HfCandidateCreator2Prong, processNoPvRefitWithKFParticleUpc, "Run candidate creator using KFParticle package w/o PV refit and w/ centrality selection on UltraPeripheral Collision", false);
///////////////////////////////////////////////////////////
/// ///
/// Process functions only for collision monitoring ///
/// ///
///////////////////////////////////////////////////////////
/// @brief process function to monitor collisions - no centrality
void processCollisions(soa::Join<aod::Collisions, aod::EvSels> const& collisions, aod::BCsWithTimestamps const& /*bcWithTimeStamps*/)
{
/// loop over collisions
for (const auto& collision : collisions) {
/// bitmask with event. selection info
float centrality{-1.f};
float occupancy = getOccupancyColl(collision, OccupancyEstimator::Its);
const auto rejectionMask = hfEvSel.getHfCollisionRejectionMask<true, CentralityEstimator::None, aod::BCsWithTimestamps>(collision, centrality, ccdb, registry);
/// monitor the satisfied event selections
hfEvSel.fillHistograms(collision, rejectionMask, centrality, occupancy);
} /// end loop over collisions
}
PROCESS_SWITCH(HfCandidateCreator2Prong, processCollisions, "Collision monitoring - no centrality", true);
/// @brief process function to monitor collisions - FT0C centrality
void processCollisionsCentFT0C(soa::Join<aod::Collisions, aod::EvSels, aod::CentFT0Cs> const& collisions, aod::BCsWithTimestamps const& /*bcWithTimeStamps*/)
{
/// loop over collisions
for (const auto& collision : collisions) {
/// bitmask with event. selection info
float centrality{-1.f};
float occupancy = getOccupancyColl(collision, OccupancyEstimator::Its);
const auto rejectionMask = hfEvSel.getHfCollisionRejectionMask<true, CentralityEstimator::FT0C, aod::BCsWithTimestamps>(collision, centrality, ccdb, registry);
/// monitor the satisfied event selections
hfEvSel.fillHistograms(collision, rejectionMask, centrality, occupancy);
} /// end loop over collisions
}
PROCESS_SWITCH(HfCandidateCreator2Prong, processCollisionsCentFT0C, "Collision monitoring - FT0C centrality", false);
/// @brief process function to monitor collisions - FT0M centrality
void processCollisionsCentFT0M(soa::Join<aod::Collisions, aod::EvSels, aod::CentFT0Ms> const& collisions, aod::BCsWithTimestamps const& /*bcWithTimeStamps*/)
{
/// loop over collisions
for (const auto& collision : collisions) {
/// bitmask with event. selection info
float centrality{-1.f};
float occupancy = getOccupancyColl(collision, OccupancyEstimator::Its);
const auto rejectionMask = hfEvSel.getHfCollisionRejectionMask<true, CentralityEstimator::FT0M, aod::BCsWithTimestamps>(collision, centrality, ccdb, registry);
/// monitor the satisfied event selections
hfEvSel.fillHistograms(collision, rejectionMask, centrality, occupancy);
} /// end loop over collisions
}
PROCESS_SWITCH(HfCandidateCreator2Prong, processCollisionsCentFT0M, "Collision monitoring - FT0M centrality", false);
/// @brief process function to monitor collisions - UPC collision
void processCollisionsUpc(soa::Join<aod::Collisions, aod::EvSels> const& collisions,
aod::BCFullInfos const& bcs,
aod::FT0s const& /*ft0s*/,
aod::FV0As const& /*fv0as*/,
aod::FDDs const& /*fdds*/,
aod::Zdcs const& /*zdcs*/)
{
/// loop over collisions
for (const auto& collision : collisions) {
/// bitmask with event. selection info
float centrality{-1.f};
float occupancy = getOccupancyColl(collision, OccupancyEstimator::Its);
const auto rejectionMask = hfEvSel.getHfCollisionRejectionMaskWithUpc<true, CentralityEstimator::None, aod::BCFullInfos>(collision, centrality, ccdb, registry, bcs);
/// monitor the satisfied event selections
hfEvSel.fillHistograms(collision, rejectionMask, centrality, occupancy);
} /// end loop over collisions
}
PROCESS_SWITCH(HfCandidateCreator2Prong, processCollisionsUpc, "Collision monitoring - UPC", false);
};
/// Extends the base table with expression columns.
struct HfCandidateCreator2ProngExpressions {
Spawns<aod::HfCand2ProngExt> rowCandidateProng2;
Produces<aod::HfCand2ProngMcRec> rowMcMatchRec;
Produces<aod::HfCand2ProngMcGen> rowMcMatchGen;
// Configuration
Configurable<bool> rejectBackground{"rejectBackground", true, "Reject particles from background events"};
Configurable<bool> matchKinkedDecayTopology{"matchKinkedDecayTopology", false, "Match also candidates with tracks that decay with kinked topology"};
Configurable<bool> matchInteractionsWithMaterial{"matchInteractionsWithMaterial", false, "Match also candidates with tracks that interact with material"};
Configurable<bool> matchCorrelatedBackgrounds{"matchCorrelatedBackgrounds", false, "Match correlated background candidates"};
HfEventSelectionMc hfEvSelMc; // mc event selection and monitoring
using McCollisionsNoCents = soa::Join<aod::Collisions, aod::EvSels, aod::McCollisionLabels>;
using McCollisionsFT0Cs = soa::Join<aod::Collisions, aod::EvSels, aod::McCollisionLabels, aod::CentFT0Cs>;
using McCollisionsFT0Ms = soa::Join<aod::Collisions, aod::EvSels, aod::McCollisionLabels, aod::CentFT0Ms>;
using McCollisionsCentFT0Ms = soa::Join<aod::McCollisions, aod::McCentFT0Ms>;
using BCsInfo = soa::Join<aod::BCs, aod::Timestamps, aod::BcSels>;
Preslice<aod::McParticles> mcParticlesPerMcCollision = aod::mcparticle::mcCollisionId;
PresliceUnsorted<McCollisionsNoCents> colPerMcCollision = aod::mccollisionlabel::mcCollisionId;
PresliceUnsorted<McCollisionsFT0Cs> colPerMcCollisionFT0C = aod::mccollisionlabel::mcCollisionId;
PresliceUnsorted<McCollisionsFT0Ms> colPerMcCollisionFT0M = aod::mccollisionlabel::mcCollisionId;
HistogramRegistry registry{"registry"};
// inspect for which zPvPosMax cut was set for reconstructed
void init(InitContext& initContext)
{
std::array<bool, 3> procCollisions = {doprocessMc, doprocessMcCentFT0C, doprocessMcCentFT0M};
if (std::accumulate(procCollisions.begin(), procCollisions.end(), 0) > 1) {
LOGP(fatal, "At most one process function for collision study can be enabled at a time.");
}
const auto& workflows = initContext.services().get<RunningWorkflowInfo const>();
for (const DeviceSpec& device : workflows.devices) {
if (device.name.compare("hf-candidate-creator-2prong") == 0) {
// init HF event selection helper
hfEvSelMc.init(device, registry);
break;
}
}
}
/// Performs MC matching.
template <o2::hf_centrality::CentralityEstimator centEstimator, typename CCs, typename McCollisions>
void runCreator2ProngMc(aod::TracksWMc const& tracks,
aod::McParticles const& mcParticles,
CCs const& collInfos,
McCollisions const& mcCollisions,
BCsInfo const&)
{
rowCandidateProng2->bindExternalIndices(&tracks);
int indexRec = -1;
int8_t sign = 0;
int8_t flag = 0;
int8_t channel = 0;
int8_t origin = 0;
int8_t nKinkedTracks = 0;
int8_t nInteractionsWithMaterial = 0;
constexpr std::size_t NDaughtersResonant{2u};
// Match reconstructed candidates.
// Spawned table can be used directly
for (const auto& candidate : *rowCandidateProng2) {
flag = 0;
origin = 0;
channel = 0;
auto arrayDaughters = std::array{candidate.prong0_as<aod::TracksWMc>(), candidate.prong1_as<aod::TracksWMc>()};
// Check whether the particle is from background events. If so, reject it.
if (rejectBackground) {
bool fromBkg{false};
for (const auto& daughter : arrayDaughters) {
if (daughter.has_mcParticle()) {
auto mcParticle = daughter.mcParticle();
if (mcParticle.fromBackgroundEvent()) {
fromBkg = true;
break;
}
}
}
if (fromBkg) {
rowMcMatchRec(flag, origin, channel, -1.f, 0, 0, 0);
continue;
}
}
std::vector<int> idxBhadMothers{};
if (matchCorrelatedBackgrounds) {
indexRec = -1; // Index of the matched reconstructed candidate
constexpr int FinalStateDepth = 2;
constexpr int ResoDepth = 1;
// D0(bar) → π+ K−, π+ K− π0, π+ π−, π+ π− π0, K+ K−
for (const auto& [chn, finalState] : hf_cand_2prong::daughtersD0Main) {
std::array<int, 2> finalStateParts2Prong = std::array{finalState[0], finalState[1]};
if (finalState.size() == 3) { // o2-linter: disable=magic-number (Partly Reco 3-prong decays)
if (matchKinkedDecayTopology && matchInteractionsWithMaterial) {
indexRec = RecoDecay::getMatchedMCRec<false, false, true, true, true>(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth, &nKinkedTracks, &nInteractionsWithMaterial);
} else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) {
indexRec = RecoDecay::getMatchedMCRec<false, false, true, true, false>(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth, &nKinkedTracks);
} else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) {
indexRec = RecoDecay::getMatchedMCRec<false, false, true, false, true>(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth, nullptr, &nInteractionsWithMaterial);
} else {
indexRec = RecoDecay::getMatchedMCRec<false, false, true, false, false>(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth);
}
if (indexRec > -1) {
auto motherParticle = mcParticles.rawIteratorAt(indexRec);
std::array<int, 3> finalStateParts2ProngAll = std::array{finalState[0], finalState[1], finalState[2]};
changeFinalStatePdgSign(motherParticle.pdgCode(), +kPi0, finalStateParts2ProngAll);
if (!RecoDecay::isMatchedMCGen(mcParticles, motherParticle, Pdg::kD0, finalStateParts2ProngAll, true, &sign, FinalStateDepth)) {
indexRec = -1; // Reset indexRec if the generated decay does not match the reconstructed one does not match the reconstructed one
}
}
} else if (finalState.size() == 2) { // o2-linter: disable=magic-number (Fully Reco 2-prong decays)
if (matchKinkedDecayTopology && matchInteractionsWithMaterial) {
indexRec = RecoDecay::getMatchedMCRec<false, false, false, true, true>(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth, &nKinkedTracks, &nInteractionsWithMaterial);
} else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) {
indexRec = RecoDecay::getMatchedMCRec<false, false, false, true, false>(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth, &nKinkedTracks);
} else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) {
indexRec = RecoDecay::getMatchedMCRec<false, false, false, false, true>(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth, nullptr, &nInteractionsWithMaterial);
} else {
indexRec = RecoDecay::getMatchedMCRec<false, false, false, false, false>(mcParticles, arrayDaughters, Pdg::kD0, finalStateParts2Prong, true, &sign, FinalStateDepth);
}
} else {
LOG(fatal) << "Final state size not supported: " << finalState.size();
continue;
}
if (indexRec > -1) {
flag = sign * (1 << chn);
// Flag the resonant decay channel
std::vector<int> arrResoDaughIndex = {};
RecoDecay::getDaughters(mcParticles.rawIteratorAt(indexRec), &arrResoDaughIndex, std::array{0}, ResoDepth);
std::array<int, NDaughtersResonant> arrPDGDaugh = {};
if (arrResoDaughIndex.size() == NDaughtersResonant) {
for (auto iProng = 0u; iProng < arrResoDaughIndex.size(); ++iProng) {
auto daughI = mcParticles.rawIteratorAt(arrResoDaughIndex[iProng]);
arrPDGDaugh[iProng] = daughI.pdgCode();
}
channel = flagResonantDecay(Pdg::kD0, arrPDGDaugh);
}
break;
}
}
} else {
// D0(bar) → π± K∓
if (matchKinkedDecayTopology && matchInteractionsWithMaterial) {
indexRec = RecoDecay::getMatchedMCRec<false, false, false, true, true>(mcParticles, arrayDaughters, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign, 1, &nKinkedTracks, &nInteractionsWithMaterial);
} else if (matchKinkedDecayTopology && !matchInteractionsWithMaterial) {
indexRec = RecoDecay::getMatchedMCRec<false, false, false, true, false>(mcParticles, arrayDaughters, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign, 1, &nKinkedTracks);
} else if (!matchKinkedDecayTopology && matchInteractionsWithMaterial) {
indexRec = RecoDecay::getMatchedMCRec<false, false, false, false, true>(mcParticles, arrayDaughters, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign, 1, nullptr, &nInteractionsWithMaterial);
} else {
indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kD0, std::array{+kPiPlus, -kKPlus}, true, &sign);
}
if (indexRec > -1) {
flag = sign * (1 << DecayType::D0ToPiK);
}
// J/ψ → e+ e−
if (flag == 0) {
if (matchInteractionsWithMaterial) {
indexRec = RecoDecay::getMatchedMCRec<false, false, false, false, true>(mcParticles, arrayDaughters, Pdg::kJPsi, std::array{+kElectron, -kElectron}, true, &sign, 1, nullptr, &nInteractionsWithMaterial);
} else {
indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kJPsi, std::array{+kElectron, -kElectron}, true);
}
if (indexRec > -1) {
flag = 1 << DecayType::JpsiToEE;
}
}
// J/ψ → μ+ μ−
if (flag == 0) {
if (matchInteractionsWithMaterial) {
indexRec = RecoDecay::getMatchedMCRec<false, false, false, false, true>(mcParticles, arrayDaughters, Pdg::kJPsi, std::array{+kMuonPlus, -kMuonPlus}, true, &sign, 1, nullptr, &nInteractionsWithMaterial);
} else {
indexRec = RecoDecay::getMatchedMCRec(mcParticles, arrayDaughters, Pdg::kJPsi, std::array{+kMuonPlus, -kMuonPlus}, true);
}
if (indexRec > -1) {
flag = 1 << DecayType::JpsiToMuMu;
}
}
}
// Check whether the particle is non-prompt (from a b quark).
if (flag != 0) {
auto particle = mcParticles.rawIteratorAt(indexRec);
origin = RecoDecay::getCharmHadronOrigin(mcParticles, particle, false, &idxBhadMothers);
}
if (origin == RecoDecay::OriginType::NonPrompt) {
auto bHadMother = mcParticles.rawIteratorAt(idxBhadMothers[0]);
rowMcMatchRec(flag, origin, channel, bHadMother.pt(), bHadMother.pdgCode(), nKinkedTracks, nInteractionsWithMaterial);
} else {
rowMcMatchRec(flag, origin, channel, -1.f, 0, nKinkedTracks, nInteractionsWithMaterial);
}
}
for (const auto& mcCollision : mcCollisions) {
// Slice the particles table to get the particles for the current MC collision
const auto mcParticlesPerMcColl = mcParticles.sliceBy(mcParticlesPerMcCollision, mcCollision.globalIndex());
// Slice the collisions table to get the collision info for the current MC collision
float centrality{-1.f};
uint16_t rejectionMask{0};
int nSplitColl = 0;
if constexpr (centEstimator == CentralityEstimator::FT0C) {
const auto collSlice = collInfos.sliceBy(colPerMcCollisionFT0C, mcCollision.globalIndex());
rejectionMask = hfEvSelMc.getHfMcCollisionRejectionMask<BCsInfo, centEstimator>(mcCollision, collSlice, centrality);
} else if constexpr (centEstimator == CentralityEstimator::FT0M) {