forked from AliceO2Group/O2Physics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUPCCandidateProducer.cxx
More file actions
2071 lines (1910 loc) · 88.9 KB
/
UPCCandidateProducer.cxx
File metadata and controls
2071 lines (1910 loc) · 88.9 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.
/// \author Nazar Burmasov, nazar.burmasov@cern.ch
/// \author Diana Krupova, diana.krupova@cern.ch
/// \since 04.06.2024
/// \author Andrea Riffero, andrea.giovanni.riffero@cern.ch
/// \since 19.03.2026
#include "PWGUD/Core/UPCCutparHolder.h"
#include "PWGUD/Core/UPCHelpers.h"
#include "PWGUD/DataModel/UDTables.h"
#include "Common/CCDB/EventSelectionParams.h"
#include "Common/DataModel/EventSelection.h"
#include "CommonConstants/LHCConstants.h"
#include "DataFormatsFIT/Triggers.h"
#include "DataFormatsITSMFT/ROFRecord.h"
#include "Framework/AnalysisDataModel.h"
#include "Framework/AnalysisTask.h"
#include "Framework/runDataProcessing.h"
#include <algorithm>
#include <limits>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace o2::framework;
using namespace o2::framework::expressions;
struct UpcCandProducer {
bool fDoMC{false};
std::map<int32_t, int32_t> fNewPartIDs;
uint64_t fMaxBC{0}; // max BC for ITS-TPC search
Produces<o2::aod::UDMcCollisions> udMCCollisions;
Produces<o2::aod::UDMcParticles> udMCParticles;
Produces<o2::aod::UDFwdTracks> udFwdTracks;
Produces<o2::aod::UDFwdTracksExtra> udFwdTracksExtra;
Produces<o2::aod::UDFwdIndices> udFwdIndices;
Produces<o2::aod::UDFwdTracksCls> udFwdTrkClusters;
Produces<o2::aod::UDMcFwdTrackLabels> udFwdTrackLabels;
Produces<o2::aod::UDTracks> udTracks;
Produces<o2::aod::UDTracksExtra> udTracksExtra;
Produces<o2::aod::UDTracksDCA> udTracksDCA;
Produces<o2::aod::UDTracksPID> udTracksPID;
Produces<o2::aod::UDMcTrackLabels> udTrackLabels;
Produces<o2::aod::UDTracksFlags> udTracksFlags;
Produces<o2::aod::UDCollisions> eventCandidates;
Produces<o2::aod::UDCollisionsSels> eventCandidatesSels;
Produces<o2::aod::UDCollisionsSelsCent> eventCandidatesSelsCent;
Produces<o2::aod::UDCollisionsSelsFwd> eventCandidatesSelsFwd;
Produces<o2::aod::UDCollisionSelExtras> eventCandidatesSelExtras;
Produces<o2::aod::UDZdcsReduced> udZdcsReduced;
std::vector<bool> fwdSelectors;
std::vector<bool> barrelSelectors;
// skimmer flags
// choose a source of signal MC events
Configurable<int> fSignalGenID{"signalGenID", 1, "Signal generator ID"};
// load cuts
UPCCutparHolder upcCuts = UPCCutparHolder();
MutableConfigurable<UPCCutparHolder> inputCuts{"UPCCuts", {}, "UPC event cuts"};
// candidate producer flags
Configurable<int> fFilterFT0{"filterFT0", -1, "Filter candidates by FT0 TOR(central) or T0A(fwd)"};
Configurable<int> fFilterTSC{"filterTSC", -1, "Filter candidates by FT0 TSC"};
Configurable<int> fFilterTVX{"filterTVX", -1, "Filter candidates by FT0 TVX"};
Configurable<int> fFilterFV0{"filterFV0", -1, "Filter candidates by FV0A"};
Configurable<uint64_t> fBCWindowFITAmps{"bcWindowFITAmps", 20, "BC range for T0A/V0A amplitudes array [-range, +(range-1)]"};
Configurable<int> fBcWindowMCH{"bcWindowMCH", 20, "Time window for MCH-MID to MCH-only matching for Muon candidates"};
Configurable<int> fBcWindowITSTPC{"bcWindowITSTPC", 20, "Time window for TOF/ITS-TPC to ITS-TPC matching for Central candidates"};
Configurable<int> fMuonTrackTShift{"muonTrackTShift", 0, "Time shift for Muon tracks"};
Configurable<int> fBarrelTrackTShift{"barrelTrackTShift", 0, "Time shift for Central Barrel tracks"};
Configurable<uint32_t> fNFwdProngs{"nFwdProngs", 0, "Matched forward tracks per candidate"};
Configurable<uint32_t> fNBarProngs{"nBarProngs", 2, "Matched barrel tracks per candidate"};
Configurable<int> fFilterRangeFT0{"filterRangeFT0", 0, "BC range (+/-) for filtration by FT0 signals"};
Configurable<int> fSearchITSTPC{"searchITSTPC", 0, "Search for ITS-TPC tracks near candidates"};
Configurable<int> fSearchRangeITSTPC{"searchRangeITSTPC", 50, "BC range for ITS-TPC tracks search wrt TOF tracks"};
Configurable<float> fMinEtaMFT{"minEtaMFT", -3.6, "Minimum eta for MFT tracks"};
Configurable<float> fMaxEtaMFT{"maxEtaMFT", -2.5, "Maximum eta for MFT tracks"};
Configurable<bool> fRequireNoTimeFrameBorder{"requireNoTimeFrameBorder", true, "Require kNoTimeFrameBorder selection bit"};
Configurable<bool> fRequireNoITSROFrameBorder{"requireNoITSROFrameBorder", true, "Require kNoITSROFrameBorder selection bit"};
// QA histograms
HistogramRegistry histRegistry{"HistRegistry", {}, OutputObjHandlingPolicy::AnalysisObject};
using BCsWithBcSels = o2::soa::Join<o2::aod::BCs, o2::aod::BcSels, o2::aod::BCFlags>;
using ForwardTracks = o2::soa::Join<o2::aod::UDFwdTracksProp, o2::aod::UDFwdTracksCovProp>;
using BarrelTracks = o2::soa::Join<o2::aod::Tracks, o2::aod::TracksExtra, o2::aod::TracksDCA,
o2::aod::pidTPCFullEl, o2::aod::pidTPCFullMu, o2::aod::pidTPCFullPi, o2::aod::pidTPCFullKa, o2::aod::pidTPCFullPr,
o2::aod::TOFSignal, o2::aod::pidTOFbeta,
o2::aod::pidTOFFullEl, o2::aod::pidTOFFullMu, o2::aod::pidTOFFullPi, o2::aod::pidTOFFullKa, o2::aod::pidTOFFullPr>;
typedef std::pair<uint64_t, std::vector<int64_t>> BCTracksPair;
void init(InitContext&)
{
fwdSelectors.resize(upchelpers::kNFwdSels - 1, false);
barrelSelectors.resize(upchelpers::kNBarrelSels - 1, false);
upcCuts = (UPCCutparHolder)inputCuts;
const AxisSpec axisTrgCounters{10, 0.5, 10.5, ""};
histRegistry.add("hCountersTrg", "", kTH1F, {axisTrgCounters});
histRegistry.get<TH1>(HIST("hCountersTrg"))->GetXaxis()->SetBinLabel(1, "TCE");
histRegistry.get<TH1>(HIST("hCountersTrg"))->GetXaxis()->SetBinLabel(2, "ZNA");
histRegistry.get<TH1>(HIST("hCountersTrg"))->GetXaxis()->SetBinLabel(3, "ZNC");
histRegistry.get<TH1>(HIST("hCountersTrg"))->GetXaxis()->SetBinLabel(4, "TCE_ROF");
histRegistry.get<TH1>(HIST("hCountersTrg"))->GetXaxis()->SetBinLabel(5, "TCE_TF");
histRegistry.get<TH1>(HIST("hCountersTrg"))->GetXaxis()->SetBinLabel(6, "TCE_ROF_TF");
const AxisSpec axisBcDist{201, 0.5, 200.5, ""};
histRegistry.add("hDistToITSTPC", "", kTH1F, {axisBcDist});
const AxisSpec axisSelFwd{upchelpers::kNFwdSels, 0., static_cast<double>(upchelpers::kNFwdSels), ""};
histRegistry.add("MuonsSelCounter", "", kTH1F, {axisSelFwd});
histRegistry.get<TH1>(HIST("MuonsSelCounter"))->GetXaxis()->SetBinLabel(upchelpers::kFwdSelAll + 1, "All");
histRegistry.get<TH1>(HIST("MuonsSelCounter"))->GetXaxis()->SetBinLabel(upchelpers::kFwdSelPt + 1, "Pt");
histRegistry.get<TH1>(HIST("MuonsSelCounter"))->GetXaxis()->SetBinLabel(upchelpers::kFwdSelEta + 1, "Eta");
histRegistry.get<TH1>(HIST("MuonsSelCounter"))->GetXaxis()->SetBinLabel(upchelpers::kFwdSelRabs + 1, "Rabs");
histRegistry.get<TH1>(HIST("MuonsSelCounter"))->GetXaxis()->SetBinLabel(upchelpers::kFwdSelpDCA + 1, "pDCA");
histRegistry.get<TH1>(HIST("MuonsSelCounter"))->GetXaxis()->SetBinLabel(upchelpers::kFwdSelChi2 + 1, "Chi2");
const AxisSpec axisSelBar{upchelpers::kNBarrelSels, 0., static_cast<double>(upchelpers::kNBarrelSels), ""};
histRegistry.add("BarrelsSelCounter", "", kTH1F, {axisSelBar});
histRegistry.get<TH1>(HIST("BarrelsSelCounter"))->GetXaxis()->SetBinLabel(upchelpers::kBarrelSelAll + 1, "All");
histRegistry.get<TH1>(HIST("BarrelsSelCounter"))->GetXaxis()->SetBinLabel(upchelpers::kBarrelSelHasTOF + 1, "HasTOF");
histRegistry.get<TH1>(HIST("BarrelsSelCounter"))->GetXaxis()->SetBinLabel(upchelpers::kBarrelSelPt + 1, "Pt");
histRegistry.get<TH1>(HIST("BarrelsSelCounter"))->GetXaxis()->SetBinLabel(upchelpers::kBarrelSelEta + 1, "Eta");
histRegistry.get<TH1>(HIST("BarrelsSelCounter"))->GetXaxis()->SetBinLabel(upchelpers::kBarrelSelITSNCls + 1, "ITSNCls");
histRegistry.get<TH1>(HIST("BarrelsSelCounter"))->GetXaxis()->SetBinLabel(upchelpers::kBarrelSelITSChi2 + 1, "ITSChi2");
histRegistry.get<TH1>(HIST("BarrelsSelCounter"))->GetXaxis()->SetBinLabel(upchelpers::kBarrelSelTPCNCls + 1, "TPCNCls");
histRegistry.get<TH1>(HIST("BarrelsSelCounter"))->GetXaxis()->SetBinLabel(upchelpers::kBarrelSelTPCChi2 + 1, "TPCChi2");
histRegistry.get<TH1>(HIST("BarrelsSelCounter"))->GetXaxis()->SetBinLabel(upchelpers::kBarrelSelDCAXY + 1, "DCAXY");
histRegistry.get<TH1>(HIST("BarrelsSelCounter"))->GetXaxis()->SetBinLabel(upchelpers::kBarrelSelDCAZ + 1, "DCAZ");
}
template <typename T>
bool applyFwdCuts(const T& track)
{
histRegistry.fill(HIST("MuonsSelCounter"), upchelpers::kFwdSelAll, 1);
// using any cuts at all?
if (!upcCuts.getUseFwdCuts()) {
return true;
}
upchelpers::applyFwdCuts(upcCuts, track, fwdSelectors);
if (fwdSelectors[upchelpers::kFwdSelPt])
histRegistry.fill(HIST("MuonsSelCounter"), upchelpers::kFwdSelPt, 1);
if (fwdSelectors[upchelpers::kFwdSelEta])
histRegistry.fill(HIST("MuonsSelCounter"), upchelpers::kFwdSelEta, 1);
if (fwdSelectors[upchelpers::kFwdSelRabs])
histRegistry.fill(HIST("MuonsSelCounter"), upchelpers::kFwdSelRabs, 1);
if (fwdSelectors[upchelpers::kFwdSelpDCA])
histRegistry.fill(HIST("MuonsSelCounter"), upchelpers::kFwdSelpDCA, 1);
if (fwdSelectors[upchelpers::kFwdSelChi2])
histRegistry.fill(HIST("MuonsSelCounter"), upchelpers::kFwdSelChi2, 1);
bool pass = fwdSelectors[upchelpers::kFwdSelPt] &&
fwdSelectors[upchelpers::kFwdSelEta] &&
fwdSelectors[upchelpers::kFwdSelRabs] &&
fwdSelectors[upchelpers::kFwdSelpDCA] &&
fwdSelectors[upchelpers::kFwdSelChi2];
return pass;
}
template <typename T>
bool applyBarCuts(const T& track)
{
// using any cuts at all?
if (!upcCuts.getUseBarCuts())
return true;
if (upcCuts.getAmbigSwitch() == 1 && !track.isPVContributor())
return false;
if (upcCuts.getRequireTOF() && !track.hasTOF())
return false;
if (track.pt() < upcCuts.getBarPtLow())
return false;
if (track.pt() > upcCuts.getBarPtHigh())
return false;
if (track.eta() < upcCuts.getBarEtaLow())
return false;
if (track.eta() > upcCuts.getBarEtaHigh())
return false;
if (track.itsNCls() < static_cast<uint8_t>(upcCuts.getITSNClusLow()))
return false;
if (track.itsNCls() > static_cast<uint8_t>(upcCuts.getITSNClusHigh()))
return false;
if (track.itsChi2NCl() < upcCuts.getITSChi2Low())
return false;
if (track.itsChi2NCl() > upcCuts.getITSChi2High())
return false;
if (track.tpcNClsFound() < static_cast<int16_t>(upcCuts.getTPCNClsLow()))
return false;
if (track.tpcNClsFound() > static_cast<int16_t>(upcCuts.getTPCNClsHigh()))
return false;
if (track.tpcChi2NCl() < upcCuts.getTPCChi2Low())
return false;
if (track.tpcChi2NCl() > upcCuts.getTPCChi2High())
return false;
if (track.dcaZ() < upcCuts.getDcaZLow())
return false;
if (track.dcaZ() > upcCuts.getDcaZHigh())
return false;
if (upcCuts.getCheckMaxDcaXY()) {
float dca = track.dcaXY();
float maxDCA = 0.0105f + 0.0350f / pow(track.pt(), 1.1f);
if (dca > maxDCA)
return false;
}
return true;
}
auto findClosestBC(uint64_t globalBC, std::map<uint64_t, int32_t>& bcs)
{
auto it = bcs.lower_bound(globalBC);
auto bc1 = it->first;
if (it != bcs.begin())
--it;
auto bc2 = it->first;
auto dbc1 = bc1 >= globalBC ? bc1 - globalBC : globalBC - bc1;
auto dbc2 = bc2 >= globalBC ? bc2 - globalBC : globalBC - bc2;
auto bc = (dbc1 <= dbc2) ? bc1 : bc2;
return bc;
}
auto findClosestTrackBCiter(uint64_t globalBC, std::vector<BCTracksPair>& bcs)
{
auto it = std::lower_bound(bcs.begin(), bcs.end(), globalBC,
[](const BCTracksPair& p, uint64_t bc) {
return p.first < bc;
});
auto bc1 = it->first;
auto it1 = it;
if (it != bcs.begin())
--it;
auto it2 = it;
auto bc2 = it->first;
auto dbc1 = bc1 >= globalBC ? bc1 - globalBC : globalBC - bc1;
auto dbc2 = bc2 >= globalBC ? bc2 - globalBC : globalBC - bc2;
return (dbc1 <= dbc2) ? it1 : it2;
}
auto findClosestTrackBCiterNotEq(uint64_t globalBC, std::vector<BCTracksPair>& bcs)
{
auto it = std::find_if(
bcs.begin(),
bcs.end(),
[globalBC](const auto& v) {
return v.first > globalBC;
});
auto bc1 = it->first;
auto it1 = it;
if (it != bcs.begin())
--it;
if (it->first == globalBC)
--it;
auto it2 = it;
auto bc2 = it->first;
auto dbc1 = bc1 >= globalBC ? bc1 - globalBC : globalBC - bc1;
auto dbc2 = bc2 >= globalBC ? bc2 - globalBC : globalBC - bc2;
return (dbc1 <= dbc2) ? it1 : it2;
}
template <typename TBCs>
void skimMCInfo(o2::aod::McCollisions const& mcCollisions,
o2::aod::McParticles const& mcParticles,
TBCs const& /*bcs*/)
{
std::vector<int32_t> newEventIDs(mcCollisions.size(), -1);
int32_t newPartID = 0;
int32_t newEventID = 0;
int32_t nMCParticles = mcParticles.size();
// loop over MC particles to select only the ones from signal events
// and calculate new MC table IDs
for (int32_t mcPartID = 0; mcPartID < nMCParticles; mcPartID++) {
const auto& mcPart = mcParticles.iteratorAt(mcPartID);
if (!mcPart.has_mcCollision())
continue;
int32_t mcEventID = mcPart.mcCollisionId();
const auto& mcEvent = mcCollisions.iteratorAt(mcEventID);
bool isSignal = mcEvent.getSourceId() == fSignalGenID;
if (!isSignal) {
continue;
}
fNewPartIDs[mcPartID] = newPartID;
newPartID++;
if (newEventIDs[mcEventID] == -1) {
newEventIDs[mcEventID] = newEventID;
newEventID++;
}
}
std::vector<int32_t> newMotherIDs{};
// storing MC particles
for (const auto& item : fNewPartIDs) {
int32_t mcPartID = item.first;
const auto& mcPart = mcParticles.iteratorAt(mcPartID);
int32_t mcEventID = mcPart.mcCollisionId();
int32_t newEventID = newEventIDs[mcEventID];
// collecting new mother IDs
if (mcPart.has_mothers()) {
const auto& motherIDs = mcPart.mothersIds();
for (auto motherID : motherIDs) {
if (motherID >= nMCParticles) {
continue;
}
auto it = fNewPartIDs.find(motherID);
if (it != fNewPartIDs.end()) {
newMotherIDs.push_back(it->second);
}
}
}
// collecting new daughter IDs
int32_t newDaughterIDs[2] = {-1, -1};
if (mcPart.has_daughters()) {
const auto& daughterIDs = mcPart.daughtersIds();
int32_t firstDaughter = daughterIDs.front();
int32_t lastDaughter = daughterIDs.back();
if (firstDaughter >= nMCParticles || lastDaughter >= nMCParticles) {
continue;
}
auto itFirst = fNewPartIDs.find(firstDaughter);
auto itLast = fNewPartIDs.find(lastDaughter);
if (itFirst != fNewPartIDs.end() && itLast != fNewPartIDs.end()) {
newDaughterIDs[0] = fNewPartIDs.at(daughterIDs.front());
newDaughterIDs[1] = fNewPartIDs.at(daughterIDs.back());
}
}
udMCParticles(newEventID, mcPart.pdgCode(), mcPart.getHepMCStatusCode(), mcPart.flags(), newMotherIDs, newDaughterIDs,
mcPart.weight(), mcPart.px(), mcPart.py(), mcPart.pz(), mcPart.e());
newMotherIDs.clear();
}
// storing MC events
for (int32_t i = 0; i < mcCollisions.size(); i++) {
if (newEventIDs[i] == -1) {
continue;
}
const auto& mcEvent = mcCollisions.iteratorAt(i);
const auto& bc = mcEvent.bc_as<TBCs>();
udMCCollisions(bc.globalBC(), mcEvent.generatorsID(), mcEvent.posX(), mcEvent.posY(), mcEvent.posZ(),
mcEvent.t(), mcEvent.weight(), mcEvent.impactParameter());
}
newEventIDs.clear();
}
void fillFwdTracks(ForwardTracks const& tracks,
std::vector<int64_t> const& trackIDs,
int32_t candID,
uint64_t globalBC, uint64_t closestBcMCH,
const o2::aod::McFwdTrackLabels* mcTrackLabels)
{
for (auto trackID : trackIDs) {
const auto& track = tracks.iteratorAt(trackID);
double trTime = track.trackTime();
double mchmidChi2 = track.chi2MatchMCHMID();
if (track.trackType() == o2::aod::fwdtrack::ForwardTrackTypeEnum::MCHStandaloneTrack) {
trTime = (static_cast<int64_t>(globalBC) - static_cast<int64_t>(closestBcMCH)) * o2::constants::lhc::LHCBunchSpacingNS; // track time relative to MCH-MID track
mchmidChi2 = -999.; // no MID match
}
double mchmftChi2 = track.chi2MatchMCHMFT();
int64_t globalIndex = track.globalIndex();
int64_t mchIndex = track.matchMCHTrackId();
int64_t mftIndex = track.matchMFTTrackId();
udFwdTracks(candID, track.px(), track.py(), track.pz(), track.sign(), globalBC, trTime, track.trackTimeRes());
udFwdTracksExtra(track.trackType(), track.nClusters(), track.pDca(), track.rAtAbsorberEnd(), track.chi2(), mchmidChi2, mchmftChi2,
track.mchBitMap(), track.midBitMap(), track.midBoards());
udFwdIndices(candID, globalIndex, mchIndex, mftIndex);
// fill MC labels and masks if needed
if (fDoMC) {
const auto& label = mcTrackLabels->iteratorAt(trackID);
uint16_t mcMask = label.mcMask();
auto it = fNewPartIDs.find(label.mcParticleId());
// signal tracks should always have an MC particle
// background tracks have label == -1
int32_t newPartID = it != fNewPartIDs.end() ? it->second : -1;
udFwdTrackLabels(newPartID, mcMask);
}
}
}
void fillFwdClusters(const std::vector<int>& trackIds,
o2::aod::FwdTrkCls const& fwdTrkCls)
{
std::map<int, std::vector<int>> clustersPerTrack;
for (const auto& cls : fwdTrkCls) {
clustersPerTrack[cls.fwdtrackId()].push_back(cls.globalIndex());
}
int newId = 0;
for (auto trackId : trackIds) {
const auto& clusters = clustersPerTrack.at(trackId);
for (auto clsId : clusters) {
const auto& clsInfo = fwdTrkCls.iteratorAt(clsId);
udFwdTrkClusters(newId, clsInfo.x(), clsInfo.y(), clsInfo.z(), clsInfo.clInfo());
}
newId++;
}
}
void fillBarrelTracks(BarrelTracks const& tracks,
std::vector<int64_t> const& trackIDs,
int32_t candID,
uint64_t globalBC,
uint64_t closestBcITSTPC,
const o2::aod::McTrackLabels* mcTrackLabels,
std::unordered_map<int64_t, uint64_t>& /*ambBarrelTrBCs*/)
{
for (auto trackID : trackIDs) {
const auto& track = tracks.iteratorAt(trackID);
double trTime = track.trackTime() - std::round(track.trackTime() / o2::constants::lhc::LHCBunchSpacingNS) * o2::constants::lhc::LHCBunchSpacingNS;
int64_t colId = track.collisionId() >= 0 ? track.collisionId() : -1;
if (!track.hasTOF() && closestBcITSTPC != std::numeric_limits<uint64_t>::max())
trTime = (static_cast<int64_t>(globalBC) - static_cast<int64_t>(closestBcITSTPC)) * o2::constants::lhc::LHCBunchSpacingNS; // track time relative to TOF track
udTracks(candID, track.px(), track.py(), track.pz(), track.sign(), globalBC, trTime, track.trackTimeRes());
udTracksExtra(track.tpcInnerParam(), track.itsClusterSizes(), track.tpcNClsFindable(), track.tpcNClsFindableMinusFound(), track.tpcNClsFindableMinusCrossedRows(),
track.tpcNClsShared(), track.trdPattern(), track.itsChi2NCl(), track.tpcChi2NCl(), track.trdChi2(), track.tofChi2(),
track.tpcSignal(), track.tofSignal(), track.trdSignal(), track.length(), track.tofExpMom(), track.detectorMap());
udTracksPID(track.tpcNSigmaEl(), track.tpcNSigmaMu(), track.tpcNSigmaPi(), track.tpcNSigmaKa(), track.tpcNSigmaPr(),
track.beta(), track.betaerror(),
track.tofNSigmaEl(), track.tofNSigmaMu(), track.tofNSigmaPi(), track.tofNSigmaKa(), track.tofNSigmaPr());
udTracksDCA(track.dcaZ(), track.dcaXY());
udTracksFlags(colId, track.isPVContributor());
// fill MC labels and masks if needed
if (fDoMC) {
const auto& label = mcTrackLabels->iteratorAt(trackID);
uint16_t mcMask = label.mcMask();
int32_t mcPartID = label.mcParticleId();
auto it = fNewPartIDs.find(mcPartID);
// signal tracks should always have an MC particle
// background tracks have label == -1
int32_t newPartID = it != fNewPartIDs.end() ? it->second : -1;
udTrackLabels(newPartID, mcMask);
}
}
}
bool checkFT0(upchelpers::FITInfo& info, bool isCentral)
{
const uint64_t presBitNum = 16;
bool hasNoFT0 = true;
for (uint64_t ibit = presBitNum - fFilterRangeFT0; ibit <= presBitNum + fFilterRangeFT0; ibit++) {
bool check = false;
if (isCentral) {
bool isBB = TESTBIT(info.BBFT0Apf, ibit) || TESTBIT(info.BBFT0Cpf, ibit);
bool isBG = TESTBIT(info.BGFT0Apf, ibit) || TESTBIT(info.BGFT0Cpf, ibit);
check = !isBB && !isBG;
} else {
bool checkA = TESTBIT(info.BGFT0Apf, ibit);
bool checkC = TESTBIT(info.BBFT0Cpf, ibit);
check = checkA && checkC;
}
if (!check) {
hasNoFT0 = false;
break;
}
}
return hasNoFT0;
}
template <typename TBCs>
void processFITInfo(upchelpers::FITInfo& fitInfo,
uint64_t midbc,
std::vector<std::pair<uint64_t, int64_t>>& v,
TBCs const& bcs,
o2::aod::FT0s const& /*ft0s*/,
o2::aod::FDDs const& /*fdds*/,
o2::aod::FV0As const& /*fv0as*/)
{
auto it = std::find_if(v.begin(),
v.end(),
[midbc](const std::pair<uint64_t, int64_t>& p) { return p.first == midbc; });
if (it != v.end()) {
auto bcId = it->second;
auto bcEntry = bcs.iteratorAt(bcId);
if (bcEntry.has_foundFT0()) {
auto ft0 = bcEntry.foundFT0();
fitInfo.timeFT0A = ft0.timeA();
fitInfo.timeFT0C = ft0.timeC();
const auto& ampsA = ft0.amplitudeA();
const auto& ampsC = ft0.amplitudeC();
fitInfo.ampFT0A = 0.;
for (auto amp : ampsA)
fitInfo.ampFT0A += amp;
fitInfo.ampFT0C = 0.;
for (auto amp : ampsC)
fitInfo.ampFT0C += amp;
fitInfo.triggerMaskFT0 = ft0.triggerMask();
}
if (bcEntry.has_foundFV0()) {
auto fv0a = bcEntry.foundFV0();
fitInfo.timeFV0A = fv0a.time();
const auto& amps = fv0a.amplitude();
fitInfo.ampFV0A = 0.;
for (auto amp : amps)
fitInfo.ampFV0A += amp;
fitInfo.triggerMaskFV0A = fv0a.triggerMask();
}
if (bcEntry.has_foundFDD()) {
auto fdd = bcEntry.foundFDD();
fitInfo.timeFDDA = fdd.timeA();
fitInfo.timeFDDC = fdd.timeC();
const auto& ampsA = fdd.chargeA();
const auto& ampsC = fdd.chargeC();
fitInfo.ampFDDA = 0.;
for (auto amp : ampsA) {
fitInfo.ampFDDA += amp;
}
fitInfo.ampFDDC = 0.;
for (auto amp : ampsC) {
fitInfo.ampFDDC += amp;
}
fitInfo.triggerMaskFDD = fdd.triggerMask();
}
}
const uint64_t range = 16;
uint64_t left = midbc >= range ? midbc - range : 0;
uint64_t right = fMaxBC >= midbc + range ? midbc + range : fMaxBC;
std::pair<uint64_t, int64_t> dummyPair(left, 0);
auto curit = std::lower_bound(v.begin(), v.end(), dummyPair,
[](const std::pair<uint64_t, int64_t>& left, const std::pair<uint64_t, int64_t>& right) { return left.first < right.first; });
if (curit == v.end()) // no BCs with FT0 info at all
return;
uint64_t curbc = curit->first;
while (curbc <= right) {
uint64_t bit = curbc - (midbc - range);
int64_t bcGlId = curit->second;
const auto& bc = bcs.iteratorAt(bcGlId);
if (!bc.selection_bit(o2::aod::evsel::kNoBGT0A))
SETBIT(fitInfo.BGFT0Apf, bit);
if (!bc.selection_bit(o2::aod::evsel::kNoBGT0C))
SETBIT(fitInfo.BGFT0Cpf, bit);
if (bc.selection_bit(o2::aod::evsel::kIsBBT0A))
SETBIT(fitInfo.BBFT0Apf, bit);
if (bc.selection_bit(o2::aod::evsel::kIsBBT0C))
SETBIT(fitInfo.BBFT0Cpf, bit);
if (!bc.selection_bit(o2::aod::evsel::kNoBGV0A))
SETBIT(fitInfo.BGFV0Apf, bit);
if (bc.selection_bit(o2::aod::evsel::kIsBBV0A))
SETBIT(fitInfo.BBFV0Apf, bit);
if (!bc.selection_bit(o2::aod::evsel::kNoBGFDA))
SETBIT(fitInfo.BGFDDApf, bit);
if (!bc.selection_bit(o2::aod::evsel::kNoBGFDC))
SETBIT(fitInfo.BGFDDCpf, bit);
if (bc.selection_bit(o2::aod::evsel::kIsBBFDA))
SETBIT(fitInfo.BBFDDApf, bit);
if (bc.selection_bit(o2::aod::evsel::kIsBBFDC))
SETBIT(fitInfo.BBFDDCpf, bit);
++curit;
if (curit == v.end())
break;
curbc = curit->first;
}
}
template <int32_t tracksSwitch, typename TAmbTrack>
int64_t getAmbTrackId(TAmbTrack ambTrack)
{
int64_t trkId = -1;
if constexpr (tracksSwitch == 0) { // central barrel
trkId = ambTrack.trackId();
}
if constexpr (tracksSwitch == 1) { // forward tracks
trkId = ambTrack.fwdtrackId();
}
return trkId;
}
// "uncorrected" bcs
template <int32_t tracksSwitch, typename TBCs, typename TAmbTracks>
void collectAmbTrackBCs(std::unordered_map<int64_t, uint64_t>& ambTrIds,
TBCs const& bcs,
TAmbTracks ambTracks)
{
for (const auto& ambTrk : ambTracks) {
auto trkId = getAmbTrackId<tracksSwitch>(ambTrk);
const auto& bcIds = ambTrk.bcIds();
if (bcIds.size() == 0)
continue;
const auto firstBcId = static_cast<int64_t>(*bcIds.begin());
if (firstBcId < 0 || firstBcId >= static_cast<int64_t>(bcs.size())) {
LOGP(debug,
"Skipping ambiguous track {}: invalid first bcId {} (nBCs = {})",
trkId, firstBcId, bcs.size());
continue;
}
ambTrIds[trkId] = bcs.iteratorAt(firstBcId).globalBC();
}
}
void addTrack(std::vector<BCTracksPair>& v, uint64_t bc, int64_t trkId)
{
auto it = std::find_if(v.begin(), v.end(),
[bc](const BCTracksPair& element) { return element.first == bc; });
if (it != v.end())
it->second.push_back(trkId);
else
v.emplace_back(std::make_pair(bc, std::vector<int64_t>({trkId})));
}
// trackType == 0 -> hasTOF
// trackType == 1 -> hasITS and not hasTOF
template <typename TBCs>
void collectBarrelTracks(std::vector<BCTracksPair>& bcsMatchedTrIds,
int trackType,
TBCs const& /*bcs*/,
o2::aod::Collisions const& /*collisions*/,
BarrelTracks const& barrelTracks,
o2::aod::AmbiguousTracks const& /*ambBarrelTracks*/,
std::unordered_map<int64_t, uint64_t>& ambBarrelTrBCs)
{
for (const auto& trk : barrelTracks) {
if (!trk.hasTPC())
continue;
if (trackType == 0 && !trk.hasTOF())
continue;
if (trackType == 1 && !(trk.hasITS() && !trk.hasTOF()))
continue;
if (!applyBarCuts(trk))
continue;
int64_t trkId = trk.globalIndex();
int32_t nContrib = -1;
bool hasTrackBC = false;
uint64_t trackBC = 0;
if (trk.has_collision()) {
const auto& col = trk.collision();
nContrib = col.numContrib();
trackBC = col.bc_as<TBCs>().globalBC();
hasTrackBC = true;
} else {
auto ambIter = ambBarrelTrBCs.find(trkId);
if (ambIter != ambBarrelTrBCs.end()) {
trackBC = ambIter->second;
hasTrackBC = true;
}
}
if (!hasTrackBC)
continue;
int64_t tint = TMath::FloorNint(trk.trackTime() / o2::constants::lhc::LHCBunchSpacingNS + static_cast<float>(fBarrelTrackTShift));
uint64_t bc = trackBC + tint;
if (nContrib > upcCuts.getMaxNContrib())
continue;
addTrack(bcsMatchedTrIds, bc, trkId);
}
}
template <typename TBCs>
void collectForwardTracks(std::vector<BCTracksPair>& bcsMatchedTrIds,
int typeFilter,
TBCs const& /*bcs*/,
o2::aod::Collisions const& /*collisions*/,
ForwardTracks const& fwdTracks,
o2::aod::AmbiguousFwdTracks const& /*ambFwdTracks*/,
std::unordered_map<int64_t, uint64_t>& ambFwdTrBCs)
{
for (const auto& trk : fwdTracks) {
if (trk.trackType() != typeFilter)
continue;
if (!applyFwdCuts(trk))
continue;
int64_t trkId = trk.globalIndex();
int32_t nContrib = -1;
bool hasTrackBC = false;
uint64_t trackBC = 0;
auto ambIter = ambFwdTrBCs.find(trkId);
if (ambIter == ambFwdTrBCs.end()) {
if (!trk.has_collision())
continue;
const auto& col = trk.collision();
nContrib = col.numContrib();
trackBC = col.bc_as<TBCs>().globalBC();
hasTrackBC = true;
} else {
trackBC = ambIter->second;
hasTrackBC = true;
}
if (!hasTrackBC)
continue;
int64_t tint = TMath::FloorNint(trk.trackTime() / o2::constants::lhc::LHCBunchSpacingNS + static_cast<float>(fMuonTrackTShift));
uint64_t bc = trackBC + tint;
if (nContrib > upcCuts.getMaxNContrib())
continue;
addTrack(bcsMatchedTrIds, bc, trkId);
}
}
template <typename TBCs>
void collectForwardGlobalTracks(std::vector<BCTracksPair>& bcsMatchedTrIds,
int typeFilter,
TBCs const& /*bcs*/,
o2::aod::Collisions const& /*collisions*/,
ForwardTracks const& fwdTracks,
o2::aod::AmbiguousFwdTracks const& /*ambFwdTracks*/,
std::unordered_map<int64_t, uint64_t>& ambFwdTrBCs)
{
for (const auto& trk : fwdTracks) {
if (trk.trackType() != typeFilter)
continue;
if (!applyFwdCuts(trk))
continue;
int64_t trkId = trk.globalIndex();
int32_t nContrib = -1;
bool hasTrackBC = false;
uint64_t trackBC = 0;
auto ambIter = ambFwdTrBCs.find(trkId);
if (ambIter == ambFwdTrBCs.end()) {
if (!trk.has_collision())
continue;
const auto& col = trk.collision();
nContrib = col.numContrib();
trackBC = col.bc_as<TBCs>().globalBC();
const auto& bc = col.bc_as<TBCs>();
if (fRequireNoTimeFrameBorder && !bc.selection_bit(o2::aod::evsel::kNoTimeFrameBorder)) {
continue; // skip this track if the kNoTimeFrameBorder bit is required but not set
}
if (fRequireNoITSROFrameBorder && !bc.selection_bit(o2::aod::evsel::kNoITSROFrameBorder)) {
continue; // skip this track if the kNoITSROFrameBorder bit is required but not set
}
hasTrackBC = true;
} else {
trackBC = ambIter->second;
hasTrackBC = true;
}
if (!hasTrackBC)
continue;
int64_t tint = TMath::FloorNint(trk.trackTime() / o2::constants::lhc::LHCBunchSpacingNS + static_cast<float>(fMuonTrackTShift));
uint64_t bc = trackBC + tint;
if (nContrib > upcCuts.getMaxNContrib())
continue;
addTrack(bcsMatchedTrIds, bc, trkId);
}
}
int32_t searchTracks(uint64_t midbc, uint64_t range, uint32_t tracksToFind,
std::vector<int64_t>& tracks,
std::vector<BCTracksPair>& v,
std::unordered_set<int64_t>& matchedTracks,
bool skipMidBC = false)
{
uint32_t count = 0;
uint64_t left = midbc >= range ? midbc - range : 0;
uint64_t right = fMaxBC >= midbc + range ? midbc + range : fMaxBC;
BCTracksPair dummyPair(left, {});
auto curit = std::lower_bound(v.begin(), v.end(), dummyPair,
[](const BCTracksPair& left, const BCTracksPair& right) { return left.first < right.first; });
if (curit == v.end()) // no ITS-TPC tracks nearby at all -> near last BCs
return -1;
uint64_t curbc = curit->first;
while (curbc <= right) { // moving forward to midbc+range
if (skipMidBC && curbc == midbc) {
++curit;
if (curit == v.end())
break;
curbc = curit->first;
}
uint32_t size = curit->second.size();
if (size > 1) // too many tracks per BC -> possibly another event
return -2;
count += size;
if (count > tracksToFind) // too many tracks nearby
return -3;
if (matchedTracks.find(curit->second[0]) == matchedTracks.end()) {
tracks.push_back(curit->second[0]);
matchedTracks.insert(curit->second[0]);
}
++curit;
if (curit == v.end())
break;
curbc = curit->first;
}
if (count != tracksToFind)
return -4;
return 0; // found exactly tracksToFind tracks in [midbc - range, midbc + range]
}
template <typename TBCs>
void createCandidatesCentral(BarrelTracks const& barrelTracks,
o2::aod::AmbiguousTracks const& ambBarrelTracks,
TBCs const& bcs,
o2::aod::Collisions const& collisions,
o2::aod::FT0s const& ft0s,
o2::aod::FDDs const& /*fdds*/,
o2::aod::FV0As const& fv0as,
o2::aod::Zdcs const& zdcs,
const o2::aod::McTrackLabels* mcBarrelTrackLabels)
{
// pairs of global BCs and vectors of matched track IDs:
std::vector<BCTracksPair> bcsMatchedTrIdsTOF;
std::vector<BCTracksPair> bcsMatchedTrIdsITSTPC;
// trackID -> index in amb. track table
std::unordered_map<int64_t, uint64_t> ambBarrelTrBCs;
if (upcCuts.getAmbigSwitch() != 1)
collectAmbTrackBCs<0, BCsWithBcSels>(ambBarrelTrBCs, bcs, ambBarrelTracks);
collectBarrelTracks(bcsMatchedTrIdsTOF,
0,
bcs, collisions,
barrelTracks, ambBarrelTracks, ambBarrelTrBCs);
collectBarrelTracks(bcsMatchedTrIdsITSTPC,
1,
bcs, collisions,
barrelTracks, ambBarrelTracks, ambBarrelTrBCs);
std::sort(bcsMatchedTrIdsTOF.begin(), bcsMatchedTrIdsTOF.end(),
[](const auto& left, const auto& right) { return left.first < right.first; });
std::sort(bcsMatchedTrIdsITSTPC.begin(), bcsMatchedTrIdsITSTPC.end(),
[](const auto& left, const auto& right) { return left.first < right.first; });
std::map<uint64_t, int32_t> mapGlobalBcWithTOR{};
std::map<uint64_t, int32_t> mapGlobalBcWithTVX{};
std::map<uint64_t, int32_t> mapGlobalBcWithTSC{};
for (const auto& ft0 : ft0s) {
uint64_t globalBC = ft0.bc_as<TBCs>().globalBC();
int32_t globalIndex = ft0.globalIndex();
if (!(std::abs(ft0.timeA()) > 2.f && std::abs(ft0.timeC()) > 2.f))
mapGlobalBcWithTOR[globalBC] = globalIndex;
if (TESTBIT(ft0.triggerMask(), o2::fit::Triggers::bitVertex)) { // TVX
mapGlobalBcWithTVX[globalBC] = globalIndex;
}
if (TESTBIT(ft0.triggerMask(), o2::fit::Triggers::bitCen)) { // TVX & TCE
histRegistry.get<TH1>(HIST("hCountersTrg"))->Fill("TCE", 1);
}
if (TESTBIT(ft0.triggerMask(), o2::fit::Triggers::bitVertex) &&
(TESTBIT(ft0.triggerMask(), o2::fit::Triggers::bitCen) ||
TESTBIT(ft0.triggerMask(), o2::fit::Triggers::bitSCen))) { // TVX & (TSC | TCE)
mapGlobalBcWithTSC[globalBC] = globalIndex;
}
}
std::map<uint64_t, int32_t> mapGlobalBcWithV0A{};
for (const auto& fv0a : fv0as) {
if (std::abs(fv0a.time()) > 15.f)
continue;
uint64_t globalBC = fv0a.bc_as<TBCs>().globalBC();
mapGlobalBcWithV0A[globalBC] = fv0a.globalIndex();
}
std::map<uint64_t, int32_t> mapGlobalBcWithZdc{};
for (const auto& zdc : zdcs) {
if (std::abs(zdc.timeZNA()) > 2.f && std::abs(zdc.timeZNC()) > 2.f)
continue;
if (!(std::abs(zdc.timeZNA()) > 2.f))
histRegistry.get<TH1>(HIST("hCountersTrg"))->Fill("ZNA", 1);
if (!(std::abs(zdc.timeZNC()) > 2.f))
histRegistry.get<TH1>(HIST("hCountersTrg"))->Fill("ZNC", 1);
auto globalBC = zdc.bc_as<TBCs>().globalBC();
mapGlobalBcWithZdc[globalBC] = zdc.globalIndex();
}
auto nTORs = mapGlobalBcWithTOR.size();
auto nTSCs = mapGlobalBcWithTSC.size();
auto nTVXs = mapGlobalBcWithTVX.size();
auto nFV0As = mapGlobalBcWithV0A.size();
auto nZdcs = mapGlobalBcWithZdc.size();
auto nBcsWithITSTPC = bcsMatchedTrIdsITSTPC.size();
// todo: calculate position of UD collision?
float dummyX = 0.;
float dummyY = 0.;
float dummyZ = 0.;
int32_t runNumber = bcs.iteratorAt(0).runNumber();
auto updateFitInfo = [&](uint64_t globalBC, upchelpers::FITInfo& fitInfo) {
fitInfo.timeFT0A = -999.f;
fitInfo.timeFT0C = -999.f;
fitInfo.timeFV0A = -999.f;
fitInfo.ampFT0A = 0.f;
fitInfo.ampFT0C = 0.f;
fitInfo.ampFV0A = 0.f;
fitInfo.BBFT0Apf = -999;
fitInfo.BBFV0Apf = -999;
fitInfo.distClosestBcTOR = 999;
fitInfo.distClosestBcTSC = 999;
fitInfo.distClosestBcTVX = 999;
fitInfo.distClosestBcV0A = 999;
if (nTORs > 0) {
uint64_t closestBcTOR = findClosestBC(globalBC, mapGlobalBcWithTOR);
fitInfo.distClosestBcTOR = globalBC - static_cast<int64_t>(closestBcTOR);
if (std::abs(fitInfo.distClosestBcTOR) <= fFilterFT0)
return false;
auto ft0Id = mapGlobalBcWithTOR.at(closestBcTOR);
auto ft0 = ft0s.iteratorAt(ft0Id);
fitInfo.timeFT0A = ft0.timeA();
fitInfo.timeFT0C = ft0.timeC();
const auto& t0AmpsA = ft0.amplitudeA();
const auto& t0AmpsC = ft0.amplitudeC();
for (auto amp : t0AmpsA)
fitInfo.ampFT0A += amp;
for (auto amp : t0AmpsC)
fitInfo.ampFT0C += amp;
}
if (nTSCs > 0) {
uint64_t closestBcTSC = findClosestBC(globalBC, mapGlobalBcWithTSC);
fitInfo.distClosestBcTSC = globalBC - static_cast<int64_t>(closestBcTSC);
if (std::abs(fitInfo.distClosestBcTSC) <= fFilterTSC)
return false;
}
if (nTVXs > 0) {
uint64_t closestBcTVX = findClosestBC(globalBC, mapGlobalBcWithTVX);
fitInfo.distClosestBcTVX = globalBC - static_cast<int64_t>(closestBcTVX);
if (std::abs(fitInfo.distClosestBcTVX) <= fFilterTVX)
return false;
}
if (nFV0As > 0) {
uint64_t closestBcV0A = findClosestBC(globalBC, mapGlobalBcWithV0A);
fitInfo.distClosestBcV0A = globalBC - static_cast<int64_t>(closestBcV0A);
if (std::abs(fitInfo.distClosestBcV0A) <= fFilterFV0)
return false;
auto fv0aId = mapGlobalBcWithV0A.at(closestBcV0A);
auto fv0a = fv0as.iteratorAt(fv0aId);
fitInfo.timeFV0A = fv0a.time();
const auto& v0Amps = fv0a.amplitude();
for (auto amp : v0Amps)
fitInfo.ampFV0A += amp;
}
return true;
};
// candidates with TOF
int32_t candID = 0;
for (auto& pair : bcsMatchedTrIdsTOF) {
auto globalBC = pair.first;
auto& barrelTrackIDs = pair.second;
uint32_t nTOFs = barrelTrackIDs.size();
if (nTOFs > fNBarProngs) // too many tracks
continue;
auto closestBcITSTPC = std::numeric_limits<uint64_t>::max();
if (nTOFs < fNBarProngs && nBcsWithITSTPC > 0) { // adding ITS-TPC tracks
auto itClosestBcITSTPC = findClosestTrackBCiter(globalBC, bcsMatchedTrIdsITSTPC);
if (itClosestBcITSTPC == bcsMatchedTrIdsITSTPC.end())
continue;
closestBcITSTPC = itClosestBcITSTPC->first;
int64_t distClosestBcITSTPC = globalBC - static_cast<int64_t>(closestBcITSTPC);
histRegistry.fill(HIST("hDistToITSTPC"), std::abs(distClosestBcITSTPC));
if (std::abs(distClosestBcITSTPC) > fBcWindowITSTPC)
continue;
auto& itstpcTracks = itClosestBcITSTPC->second;
uint32_t nITSTPCs = itstpcTracks.size();
if ((nTOFs + nITSTPCs) != fNBarProngs)
continue;
barrelTrackIDs.insert(barrelTrackIDs.end(), itstpcTracks.begin(), itstpcTracks.end());
itClosestBcITSTPC->second.clear(); // BC is matched to BC with TOF, removing tracks, but leaving BC
}
upchelpers::FITInfo fitInfo{};
if (!updateFitInfo(globalBC, fitInfo))
continue;
if (nZdcs > 0) {
auto itZDC = mapGlobalBcWithZdc.find(globalBC);
if (itZDC != mapGlobalBcWithZdc.end()) {
const auto& zdc = zdcs.iteratorAt(itZDC->second);
float timeZNA = zdc.timeZNA();
float timeZNC = zdc.timeZNC();
float eComZNA = zdc.energyCommonZNA();
float eComZNC = zdc.energyCommonZNC();
udZdcsReduced(candID, timeZNA, timeZNC, eComZNA, eComZNC);
}
}
uint16_t numContrib = fNBarProngs;