forked from AliceO2Group/O2Physics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrangenessbuilder.cxx
More file actions
2723 lines (2460 loc) · 142 KB
/
strangenessbuilder.cxx
File metadata and controls
2723 lines (2460 loc) · 142 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 strangenessbuilder.cxx
/// \brief Strangeness builder task
/// \author David Dobrigkeit Chinellato (david.dobrigkeit.chinellato@cern.ch)
// ========================
//
// This task produces all tables that may be necessary for
// strangeness analyses. A single device is provided to
// ensure better computing resource (memory) management.
//
// process functions:
//
// -- processRealData[Run2] .........: use this OR processMonteCarlo but NOT both
// -- processMonteCarlo[Run2] .......: use this OR processRealData but NOT both
//
// Most important configurables:
// -- enabledTables ......: key control bools to decide which tables to generate
// task will adapt algorithm to spare / spend CPU accordingly
// -- mc_findableMode ....: 0: only found (default), 1: add findable to found, 2: all findable
// When using findables, refer to FoundTag bools for checking if found
// -- v0builderopts ......: V0-specific building options (topological, deduplication, etc)
// -- cascadebuilderopts .: cascade-specific building options (topological, etc)
#include <string>
#include <vector>
#include "Framework/DataSpecUtils.h"
#include "Framework/runDataProcessing.h"
#include "Framework/AnalysisTask.h"
#include "Framework/AnalysisDataModel.h"
#include "Common/DataModel/PIDResponse.h"
#include "TableHelper.h"
#include "PWGLF/DataModel/LFStrangenessTables.h"
#include "PWGLF/DataModel/LFStrangenessPIDTables.h"
#include "PWGLF/Utils/strangenessBuilderHelper.h"
#include "CCDB/BasicCCDBManager.h"
#include "DataFormatsParameters/GRPObject.h"
#include "DataFormatsParameters/GRPMagField.h"
#include "Common/Core/TPCVDriftManager.h"
using namespace o2;
using namespace o2::framework;
static constexpr int nParameters = 1;
static const std::vector<std::string> tableNames{
"V0Indices", //.0 (standard analysis: V0Cores)
"V0CoresBase", //.1 (standard analyses: main table)
"V0Covs", //.2 (joinable with V0Cores)
"CascIndices", //.3 (standard analyses: CascData)
"KFCascIndices", //.4 (standard analyses: KFCascData)
"TraCascIndices", //.5 (standard analyses: TraCascData)
"StoredCascCores", //.6 (standard analyses: CascData, main table)
"StoredKFCascCores", //.7 (standard analyses: KFCascData, main table)
"StoredTraCascCores", //.8 (standard analyses: TraCascData, main table)
"CascCovs", //.9 (joinable with CascData)
"KFCascCovs", //.10 (joinable with KFCascData)
"TraCascCovs", //.11 (joinable with TraCascData)
"V0TrackXs", //.12 (joinable with V0Data)
"CascTrackXs", //.13 (joinable with CascData)
"CascBBs", //.14 (standard, bachelor-baryon vars)
"V0DauCovs", //.15 (requested: tracking studies)
"V0DauCovIUs", //.16 (requested: tracking studies)
"V0TraPosAtDCAs", //.17 (requested: tracking studies)
"V0TraPosAtIUs", //.18 (requested: tracking studies)
"V0Ivanovs", //.19 (requested: tracking studies)
"McV0Labels", //.20 (MC/standard analysis)
"V0MCCores", //.21 (MC, all generated desired V0s)
"V0CoreMCLabels", //.22 (MC, refs V0Cores to V0MCCores)
"V0MCCollRefs", //.23 (MC, refs V0MCCores to McCollisions)
"McCascLabels", //.24 (MC/standard analysis)
"McKFCascLabels", //.25 (MC, refs KFCascCores to CascMCCores)
"McTraCascLabels", //.26 (MC, refs TraCascCores to CascMCCores)
"McCascBBTags", //.27 (MC, joinable with CascCores, tags reco-ed)
"CascMCCores", //.28 (MC, all generated desired cascades)
"CascCoreMCLabels", //.29 (MC, refs CascCores to CascMCCores)
"CascMCCollRefs", // 30 (MC, refs CascMCCores to McCollisions)
"CascToTraRefs", //.31 (interlink CascCores -> TraCascCores)
"CascToKFRefs", //.32 (interlink CascCores -> KFCascCores)
"TraToCascRefs", //.33 (interlink TraCascCores -> CascCores)
"KFToCascRefs", //.34 (interlink KFCascCores -> CascCores)
"V0FoundTags", //.35 (tags found vs findable V0s in findable mode)
"CascFoundTags" //.36 (tags found vs findable Cascades in findable mode)
};
static constexpr int nTablesConst = 37;
static const std::vector<std::string> parameterNames{"enable"};
static const int defaultParameters[nTablesConst][nParameters]{
{-1},
{-1},
{-1},
{-1},
{-1},
{-1},
{-1},
{-1},
{-1},
{-1}, // index 9
{-1},
{-1},
{-1},
{-1},
{-1},
{-1},
{-1},
{-1},
{-1},
{-1}, // index 19
{-1},
{-1},
{-1},
{-1},
{-1},
{-1},
{-1},
{-1},
{-1},
{-1}, // index 29
{-1},
{-1},
{-1},
{-1},
{-1},
{-1},
{-1}};
// use parameters + cov mat non-propagated, aux info + (extension propagated)
using FullTracksExt = soa::Join<aod::Tracks, aod::TracksExtra, aod::TracksCov>;
using FullTracksExtIU = soa::Join<aod::TracksIU, aod::TracksExtra, aod::TracksCovIU>;
using FullTracksExtWithPID = soa::Join<aod::Tracks, aod::TracksExtra, aod::TracksCov, aod::pidTPCFullEl, aod::pidTPCFullPi, aod::pidTPCFullPr, aod::pidTPCFullKa, aod::pidTPCFullHe>;
using FullTracksExtIUWithPID = soa::Join<aod::TracksIU, aod::TracksExtra, aod::TracksCovIU, aod::pidTPCFullEl, aod::pidTPCFullPi, aod::pidTPCFullPr, aod::pidTPCFullKa, aod::pidTPCFullHe>;
using FullTracksExtLabeled = soa::Join<aod::Tracks, aod::TracksExtra, aod::TracksCov, aod::McTrackLabels>;
using FullTracksExtLabeledIU = soa::Join<aod::TracksIU, aod::TracksExtra, aod::TracksCovIU, aod::McTrackLabels>;
using FullTracksExtLabeledWithPID = soa::Join<aod::Tracks, aod::TracksExtra, aod::TracksCov, aod::pidTPCFullEl, aod::pidTPCFullPi, aod::pidTPCFullPr, aod::pidTPCFullKa, aod::pidTPCFullHe, aod::McTrackLabels>;
using FullTracksExtLabeledIUWithPID = soa::Join<aod::TracksIU, aod::TracksExtra, aod::TracksCovIU, aod::pidTPCFullEl, aod::pidTPCFullPi, aod::pidTPCFullPr, aod::pidTPCFullKa, aod::pidTPCFullHe, aod::McTrackLabels>;
using TracksWithExtra = soa::Join<aod::Tracks, aod::TracksExtra>;
// For dE/dx association in pre-selection
using TracksExtraWithPID = soa::Join<aod::TracksExtra, aod::pidTPCFullEl, aod::pidTPCFullPi, aod::pidTPCFullPr, aod::pidTPCFullKa, aod::pidTPCFullHe>;
// simple checkers, but ensure 8 bit integers
#define BITSET(var, nbit) ((var) |= (static_cast<uint8_t>(1) << static_cast<uint8_t>(nbit)))
struct StrangenessBuilder {
// helper object
o2::pwglf::strangenessBuilderHelper straHelper;
// table index : match order above
enum tableIndex { kV0Indices = 0,
kV0CoresBase,
kV0Covs,
kCascIndices,
kKFCascIndices,
kTraCascIndices,
kStoredCascCores,
kStoredKFCascCores,
kStoredTraCascCores,
kCascCovs,
kKFCascCovs,
kTraCascCovs,
kV0TrackXs,
kCascTrackXs,
kCascBBs,
kV0DauCovs,
kV0DauCovIUs,
kV0TraPosAtDCAs,
kV0TraPosAtIUs,
kV0Ivanovs,
kMcV0Labels,
kV0MCCores,
kV0CoreMCLabels,
kV0MCCollRefs,
kMcCascLabels,
kMcKFCascLabels,
kMcTraCascLabels,
kMcCascBBTags,
kCascMCCores,
kCascCoreMCLabels,
kCascMCCollRefs,
kCascToTraRefs,
kCascToKFRefs,
kTraToCascRefs,
kKFToCascRefs,
kV0FoundTags,
kCascFoundTags,
nTables };
enum V0PreSelection : uint8_t { selGamma = static_cast<uint8_t>(1) << static_cast<uint8_t>(0),
selK0Short,
selLambda,
selAntiLambda };
enum CascPreSelection : uint8_t { selXiMinus = static_cast<uint8_t>(1) << static_cast<uint8_t>(0),
selXiPlus,
selOmegaMinus,
selOmegaPlus };
struct : ProducesGroup {
//__________________________________________________
// V0 tables
Produces<aod::V0Indices> v0indices; // standard part of V0Datas
Produces<aod::V0CoresBase> v0cores; // standard part of V0Datas
Produces<aod::V0Covs> v0covs; // for decay chain reco
//__________________________________________________
// cascade tables
Produces<aod::CascIndices> cascidx; // standard part of CascDatas
Produces<aod::KFCascIndices> kfcascidx; // standard part of KFCascDatas
Produces<aod::TraCascIndices> tracascidx; // standard part of TraCascDatas
Produces<aod::StoredCascCores> cascdata; // standard part of CascDatas
Produces<aod::StoredKFCascCores> kfcascdata; // standard part of KFCascDatas
Produces<aod::StoredTraCascCores> tracascdata; // standard part of TraCascDatas
Produces<aod::CascCovs> casccovs; // for decay chain reco
Produces<aod::KFCascCovs> kfcasccovs; // for decay chain reco
Produces<aod::TraCascCovs> tracasccovs; // for decay chain reco
//__________________________________________________
// interlink tables
Produces<aod::V0DataLink> v0dataLink; // de-refs V0s -> V0Data
Produces<aod::CascDataLink> cascdataLink; // de-refs Cascades -> CascData
Produces<aod::KFCascDataLink> kfcascdataLink; // de-refs Cascades -> KFCascData
Produces<aod::TraCascDataLink> tracascdataLink; // de-refs Cascades -> TraCascData
//__________________________________________________
// secondary auxiliary tables
Produces<aod::V0TrackXs> v0trackXs; // for decay chain reco
Produces<aod::CascTrackXs> cascTrackXs; // for decay chain reco
//__________________________________________________
// further auxiliary / optional if desired
Produces<aod::CascBBs> cascbb;
Produces<aod::V0DauCovs> v0daucovs; // covariances of daughter tracks
Produces<aod::V0DauCovIUs> v0daucovIUs; // covariances of daughter tracks
Produces<aod::V0TraPosAtDCAs> v0dauPositions; // auxiliary debug information
Produces<aod::V0TraPosAtIUs> v0dauPositionsIU; // auxiliary debug information
Produces<aod::V0Ivanovs> v0ivanovs; // information for Marian's tests
//__________________________________________________
// MC information: V0
Produces<aod::McV0Labels> v0labels; // MC labels for V0s
Produces<aod::V0MCCores> v0mccores; // mc info storage
Produces<aod::V0CoreMCLabels> v0CoreMCLabels; // interlink V0Cores -> V0MCCores
Produces<aod::V0MCCollRefs> v0mccollref; // references collisions from V0MCCores
// MC information: Cascades
Produces<aod::McCascLabels> casclabels; // MC labels for cascades
Produces<aod::McKFCascLabels> kfcasclabels; // MC labels for KF cascades
Produces<aod::McTraCascLabels> tracasclabels; // MC labels for tracked cascades
Produces<aod::McCascBBTags> bbtags; // bb tags (inv structure tagging in mc)
Produces<aod::CascMCCores> cascmccores; // mc info storage
Produces<aod::CascCoreMCLabels> cascCoreMClabels; // interlink CascCores -> CascMCCores
Produces<aod::CascMCCollRefs> cascmccollrefs; // references MC collisions from MC cascades
//__________________________________________________
// cascade interlinks
// FIXME: commented out until strangederivedbuilder adjusted accordingly
// Produces<aod::CascToTraRefs> cascToTraRefs; // cascades -> tracked
// Produces<aod::CascToKFRefs> cascToKFRefs; // cascades -> KF
// Produces<aod::TraToCascRefs> traToCascRefs; // tracked -> cascades
// Produces<aod::KFToCascRefs> kfToCascRefs; // KF -> cascades
//__________________________________________________
// Findable tags
Produces<aod::V0FoundTags> v0FoundTag;
Produces<aod::CascFoundTags> cascFoundTag;
} products;
Configurable<LabeledArray<int>> enabledTables{"enabledTables",
{defaultParameters[0], nTables, nParameters, tableNames, parameterNames},
"Produce this table: -1 for autodetect; otherwise, 0/1 is false/true"};
std::vector<int> mEnabledTables; // Vector of enabled tables
// CCDB options
struct : ConfigurableGroup {
std::string prefix = "ccdb";
Configurable<std::string> ccdburl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
Configurable<std::string> grpPath{"grpPath", "GLO/GRP/GRP", "Path of the grp file"};
Configurable<std::string> grpmagPath{"grpmagPath", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object"};
Configurable<std::string> lutPath{"lutPath", "GLO/Param/MatLUT", "Path of the Lut parametrization"};
Configurable<std::string> geoPath{"geoPath", "GLO/Config/GeometryAligned", "Path of the geometry file"};
} ccdbConfigurations;
// first order deduplication implementation
// more algorithms to be added as necessary
Configurable<int> deduplicationAlgorithm{"deduplicationAlgorithm", 1, "0: disabled; 1: best pointing angle wins; 2: best DCA daughters wins; 3: best pointing and best DCA wins"};
// V0 buffer for V0s used in cascades: master switch
// exchanges CPU (generate V0s again) with memory (save pre-generated V0s)
Configurable<bool> useV0BufferForCascades{"useV0BufferForCascades", false, "store array of V0s for cascades or not. False (default): save RAM, use more CPU; true: save CPU, use more RAM"};
Configurable<int> mc_findableMode{"mc_findableMode", 0, "0: disabled; 1: add findable-but-not-found to existing V0s from AO2D; 2: reset V0s and generate only findable-but-not-found"};
// Autoconfigure process functions
Configurable<bool> autoConfigureProcess{"autoConfigureProcess", false, "if true, will configure process function switches based on metadata"};
// V0 building options
struct : ConfigurableGroup {
std::string prefix = "v0BuilderOpts";
Configurable<bool> generatePhotonCandidates{"generatePhotonCandidates", false, "generate gamma conversion candidates (V0s using TPC-only tracks)"};
Configurable<bool> moveTPCOnlyTracks{"moveTPCOnlyTracks", true, "if dealing with TPC-only tracks, move them according to TPC drift / time info"};
// baseline conditionals of V0 building
Configurable<int> minCrossedRows{"minCrossedRows", 50, "minimum TPC crossed rows for daughter tracks"};
Configurable<float> dcanegtopv{"dcanegtopv", .1, "DCA Neg To PV"};
Configurable<float> dcapostopv{"dcapostopv", .1, "DCA Pos To PV"};
Configurable<double> v0cospa{"v0cospa", 0.95, "V0 CosPA"}; // double -> N.B. dcos(x)/dx = 0 at x=0)
Configurable<float> dcav0dau{"dcav0dau", 1.0, "DCA V0 Daughters"};
Configurable<float> v0radius{"v0radius", 0.9, "v0radius"};
Configurable<float> maxDaughterEta{"maxDaughterEta", 5.0, "Maximum daughter eta (in abs value)"};
// MC builder options
Configurable<bool> mc_populateV0MCCoresSymmetric{"mc_populateV0MCCoresSymmetric", false, "populate V0MCCores table for derived data analysis, keep V0MCCores joinable with V0Cores"};
Configurable<bool> mc_populateV0MCCoresAsymmetric{"mc_populateV0MCCoresAsymmetric", true, "populate V0MCCores table for derived data analysis, create V0Cores -> V0MCCores interlink. Saves only labeled V0s."};
Configurable<bool> mc_treatPiToMuDecays{"mc_treatPiToMuDecays", true, "if true, will correctly capture pi -> mu and V0 label will still point to originating V0 decay in those cases. Nota bene: prong info will still be for the muon!"};
Configurable<float> mc_rapidityWindow{"mc_rapidityWindow", 0.5, "rapidity window to save non-recoed candidates"};
Configurable<bool> mc_keepOnlyPhysicalPrimary{"mc_keepOnlyPhysicalPrimary", false, "Keep only physical primary generated V0s if not recoed"};
Configurable<bool> mc_addGeneratedK0Short{"mc_addGeneratedK0Short", true, "add V0MCCore entry for generated, not-recoed K0Short"};
Configurable<bool> mc_addGeneratedLambda{"mc_addGeneratedLambda", true, "add V0MCCore entry for generated, not-recoed Lambda"};
Configurable<bool> mc_addGeneratedAntiLambda{"mc_addGeneratedAntiLambda", true, "add V0MCCore entry for generated, not-recoed AntiLambda"};
Configurable<bool> mc_addGeneratedGamma{"mc_addGeneratedGamma", false, "add V0MCCore entry for generated, not-recoed Gamma"};
Configurable<bool> mc_addGeneratedGammaMakeCollinear{"mc_addGeneratedGammaMakeCollinear", true, "when adding findable gammas, mark them as collinear"};
Configurable<bool> mc_findableDetachedV0{"mc_findableDetachedV0", false, "if true, generate findable V0s that have collisionId -1. Caution advised."};
} v0BuilderOpts;
// cascade building options
struct : ConfigurableGroup {
std::string prefix = "cascadeBuilderOpts";
Configurable<bool> useCascadeMomentumAtPrimVtx{"useCascadeMomentumAtPrimVtx", false, "use cascade momentum at PV"};
// conditionals
Configurable<int> minCrossedRows{"minCrossedRows", 50, "minimum TPC crossed rows for daughter tracks"};
Configurable<float> dcabachtopv{"dcabachtopv", .05, "DCA Bach To PV"};
Configurable<float> cascradius{"cascradius", 0.9, "cascradius"};
Configurable<float> casccospa{"casccospa", 0.95, "casccospa"};
Configurable<float> dcacascdau{"dcacascdau", 1.0, "DCA cascade Daughters"};
Configurable<float> lambdaMassWindow{"lambdaMassWindow", .010, "Distance from Lambda mass (does not apply to KF path)"};
Configurable<float> maxDaughterEta{"maxDaughterEta", 5.0, "Maximum daughter eta (in abs value)"};
// KF building specific
Configurable<bool> kfTuneForOmega{"kfTuneForOmega", false, "if enabled, take main cascade properties from Omega fit instead of Xi fit (= default)"};
Configurable<int> kfConstructMethod{"kfConstructMethod", 2, "KF Construct Method"};
Configurable<bool> kfUseV0MassConstraint{"kfUseV0MassConstraint", true, "KF: use Lambda mass constraint"};
Configurable<bool> kfUseCascadeMassConstraint{"kfUseCascadeMassConstraint", false, "KF: use Cascade mass constraint - WARNING: not adequate for inv mass analysis of Xi"};
Configurable<bool> kfDoDCAFitterPreMinimV0{"kfDoDCAFitterPreMinimV0", true, "KF: do DCAFitter pre-optimization before KF fit to include material corrections for V0"};
Configurable<bool> kfDoDCAFitterPreMinimCasc{"kfDoDCAFitterPreMinimCasc", true, "KF: do DCAFitter pre-optimization before KF fit to include material corrections for Xi"};
// MC builder options
Configurable<bool> mc_populateCascMCCoresSymmetric{"mc_populateCascMCCoresSymmetric", false, "populate CascMCCores table for derived data analysis, keep CascMCCores joinable with CascCores"};
Configurable<bool> mc_populateCascMCCoresAsymmetric{"mc_populateCascMCCoresAsymmetric", true, "populate CascMCCores table for derived data analysis, create CascCores -> CascMCCores interlink. Saves only labeled Cascades."};
Configurable<bool> mc_addGeneratedXiMinus{"mc_addGeneratedXiMinus", true, "add CascMCCore entry for generated, not-recoed XiMinus"};
Configurable<bool> mc_addGeneratedXiPlus{"mc_addGeneratedXiPlus", true, "add CascMCCore entry for generated, not-recoed XiPlus"};
Configurable<bool> mc_addGeneratedOmegaMinus{"mc_addGeneratedOmegaMinus", true, "add CascMCCore entry for generated, not-recoed OmegaMinus"};
Configurable<bool> mc_addGeneratedOmegaPlus{"mc_addGeneratedOmegaPlus", true, "add CascMCCore entry for generated, not-recoed OmegaPlus"};
Configurable<bool> mc_treatPiToMuDecays{"mc_treatPiToMuDecays", true, "if true, will correctly capture pi -> mu and V0 label will still point to originating V0 decay in those cases. Nota bene: prong info will still be for the muon!"};
Configurable<float> mc_rapidityWindow{"mc_rapidityWindow", 0.5, "rapidity window to save non-recoed candidates"};
Configurable<bool> mc_keepOnlyPhysicalPrimary{"mc_keepOnlyPhysicalPrimary", false, "Keep only physical primary generated cascades if not recoed"};
Configurable<bool> mc_findableDetachedCascade{"mc_findableDetachedCascade", false, "if true, generate findable cascades that have collisionId -1. Caution advised."};
} cascadeBuilderOpts;
static constexpr float defaultK0MassWindowParameters[1][4] = {{2.81882e-03, 1.14057e-03, 1.72138e-03, 5.00262e-01}};
static constexpr float defaultLambdaWindowParameters[1][4] = {{1.17518e-03, 1.24099e-04, 5.47937e-03, 3.08009e-01}};
static constexpr float defaultXiMassWindowParameters[1][4] = {{1.43210e-03, 2.03561e-04, 2.43187e-03, 7.99668e-01}};
static constexpr float defaultOmMassWindowParameters[1][4] = {{1.43210e-03, 2.03561e-04, 2.43187e-03, 7.99668e-01}};
static constexpr float defaultLifetimeCuts[1][4] = {{20, 60, 40, 20}};
// preselection options
struct : ConfigurableGroup {
std::string prefix = "preSelectOpts";
Configurable<bool> preselectOnlyDesiredV0s{"preselectOnlyDesiredV0s", false, "preselect only V0s with compatible TPC PID and mass info"};
Configurable<bool> preselectOnlyDesiredCascades{"preselectOnlyDesiredCascades", false, "preselect only Cascades with compatible TPC PID and mass info"};
// lifetime preselection options
// apply lifetime cuts to V0 and cascade candidates
// unit of measurement: centimeters
// lifetime of K0Short ~2.6844 cm, no feeddown and plenty to cut
// lifetime of Lambda ~7.9 cm but keep in mind feeddown from cascades
// lifetime of Xi ~4.91 cm
// lifetime of Omega ~2.461 cm
Configurable<LabeledArray<float>> lifetimeCut{"lifetimeCut", {defaultLifetimeCuts[0], 4, {"lifetimeCutK0S", "lifetimeCutLambda", "lifetimeCutXi", "lifetimeCutOmega"}}, "Lifetime cut for V0s and cascades (cm)"};
// mass preselection options
Configurable<float> massCutPhoton{"massCutPhoton", 0.3, "Photon max mass"};
Configurable<LabeledArray<float>> massCutK0{"massCutK0", {defaultK0MassWindowParameters[0], 4, {"constant", "linear", "expoConstant", "expoRelax"}}, "mass parameters for K0"};
Configurable<LabeledArray<float>> massCutLambda{"massCutLambda", {defaultLambdaWindowParameters[0], 4, {"constant", "linear", "expoConstant", "expoRelax"}}, "mass parameters for Lambda"};
Configurable<LabeledArray<float>> massCutXi{"massCutXi", {defaultXiMassWindowParameters[0], 4, {"constant", "linear", "expoConstant", "expoRelax"}}, "mass parameters for Xi"};
Configurable<LabeledArray<float>> massCutOm{"massCutOm", {defaultOmMassWindowParameters[0], 4, {"constant", "linear", "expoConstant", "expoRelax"}}, "mass parameters for Omega"};
Configurable<float> massWindownumberOfSigmas{"massWindownumberOfSigmas", 20, "number of sigmas around mass peaks to keep"};
Configurable<float> massWindowSafetyMargin{"massWindowSafetyMargin", 0.001, "Extra mass window safety margin (in GeV/c2)"};
// TPC PID preselection options
Configurable<float> maxTPCpidNsigma{"maxTPCpidNsigma", 5.0, "Maximum TPC PID N sigma (in abs value)"};
} preSelectOpts;
float getMassSigmaK0Short(float pt)
{
return preSelectOpts.massCutK0->get("constant") + pt * preSelectOpts.massCutK0->get("linear") + preSelectOpts.massCutK0->get("expoConstant") * TMath::Exp(-pt / preSelectOpts.massCutK0->get("expoRelax"));
}
float getMassSigmaLambda(float pt)
{
return preSelectOpts.massCutLambda->get("constant") + pt * preSelectOpts.massCutLambda->get("linear") + preSelectOpts.massCutLambda->get("expoConstant") * TMath::Exp(-pt / preSelectOpts.massCutLambda->get("expoRelax"));
}
float getMassSigmaXi(float pt)
{
return preSelectOpts.massCutXi->get("constant") + pt * preSelectOpts.massCutXi->get("linear") + preSelectOpts.massCutXi->get("expoConstant") * TMath::Exp(-pt / preSelectOpts.massCutXi->get("expoRelax"));
}
float getMassSigmaOmega(float pt)
{
return preSelectOpts.massCutOm->get("constant") + pt * preSelectOpts.massCutOm->get("linear") + preSelectOpts.massCutOm->get("expoConstant") * TMath::Exp(-pt / preSelectOpts.massCutOm->get("expoRelax"));
}
o2::ccdb::CcdbApi ccdbApi;
Service<o2::ccdb::BasicCCDBManager> ccdb;
int mRunNumber;
o2::base::MatLayerCylSet* lut = nullptr;
// for handling TPC-only tracks (photons)
o2::aod::common::TPCVDriftManager mVDriftMgr;
// for establishing CascData/KFData/TraCascData interlinks
struct {
std::vector<int> cascCoreToCascades;
std::vector<int> kfCascCoreToCascades;
std::vector<int> traCascCoreToCascades;
std::vector<int> cascadeToCascCores;
std::vector<int> cascadeToKFCascCores;
std::vector<int> cascadeToTraCascCores;
} interlinks;
//*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*
// struct to add abstraction layer between V0s, Cascades and build indices
// desirable for adding extra (findable, etc) V0s, Cascades to built list
struct trackEntry {
int globalId = -1;
int originId = -1;
int mcCollisionId = -1;
int pdgCode = -1;
};
struct v0Entry {
int globalId = -1;
int collisionId = -1;
int posTrackId = -1;
int negTrackId = -1;
int v0Type = 0;
int pdgCode = 0; // undefined if not MC - useful for faster finding
int particleId = -1; // de-reference the V0 particle if necessary
bool isCollinearV0 = false;
bool found = false;
};
struct cascadeEntry {
int globalId = -1;
int collisionId = -1;
int v0Id = -1;
int posTrackId = -1;
int negTrackId = -1;
int bachTrackId = -1;
bool found = false;
};
//*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*
// Helper struct to contain V0MCCore information prior to filling
struct mcV0info {
int label = -1;
int motherLabel = -1;
int pdgCode = 0;
int pdgCodeMother = 0;
int pdgCodePositive = 0;
int pdgCodeNegative = 0;
int mcCollision = -1;
bool isPhysicalPrimary = false;
int processPositive = -1;
int processNegative = -1;
std::array<float, 3> xyz;
std::array<float, 3> posP;
std::array<float, 3> negP;
std::array<float, 3> momentum;
};
mcV0info thisInfo;
//*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*
// Helper struct to contain CascMCCore information prior to filling
struct mcCascinfo {
int label;
int motherLabel;
int mcCollision;
int pdgCode;
int pdgCodeMother;
int pdgCodeV0;
int pdgCodePositive;
int pdgCodeNegative;
int pdgCodeBachelor;
bool isPhysicalPrimary;
int processPositive = -1;
int processNegative = -1;
int processBachelor = -1;
std::array<float, 3> xyz;
std::array<float, 3> lxyz;
std::array<float, 3> posP;
std::array<float, 3> negP;
std::array<float, 3> bachP;
std::array<float, 3> momentum;
int mcParticlePositive;
int mcParticleNegative;
int mcParticleBachelor;
};
mcCascinfo thisCascInfo;
//*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*
HistogramRegistry histos{"Histos", {}, OutputObjHandlingPolicy::AnalysisObject};
std::vector<v0Entry> v0List;
std::vector<cascadeEntry> cascadeList;
std::vector<std::size_t> sorted_v0;
std::vector<std::size_t> sorted_cascade;
// for tagging V0s used in cascades
std::vector<o2::pwglf::v0candidate> v0sFromCascades; // Vector of v0 candidates used in cascades
std::vector<int> ao2dV0toV0List; // index to relate v0s -> v0List
std::vector<int> v0Map; // index to relate v0List -> v0sFromCascades
void init(InitContext& context)
{
// setup bookkeeping histogram
auto h = histos.add<TH1>("hTableBuildingStatistics", "hTableBuildingStatistics", kTH1D, {{nTablesConst, -0.5f, static_cast<float>(nTablesConst)}});
auto h2 = histos.add<TH1>("hInputStatistics", "hInputStatistics", kTH1D, {{nTablesConst, -0.5f, static_cast<float>(nTablesConst)}});
h2->SetTitle("Input table sizes");
if (v0BuilderOpts.generatePhotonCandidates.value == true) {
auto hDeduplicationStatistics = histos.add<TH1>("hDeduplicationStatistics", "hDeduplicationStatistics", kTH1D, {{2, -0.5f, 1.5f}});
hDeduplicationStatistics->GetXaxis()->SetBinLabel(1, "AO2D V0s");
hDeduplicationStatistics->GetXaxis()->SetBinLabel(2, "Deduplicated V0s");
}
if (preSelectOpts.preselectOnlyDesiredV0s.value == true) {
auto hPreselectionV0s = histos.add<TH1>("hPreselectionV0s", "hPreselectionV0s", kTH1D, {{16, -0.5f, 15.5f}});
hPreselectionV0s->GetXaxis()->SetBinLabel(1, "Not preselected");
hPreselectionV0s->GetXaxis()->SetBinLabel(2, "#gamma");
hPreselectionV0s->GetXaxis()->SetBinLabel(3, "K^{0}_{S}");
hPreselectionV0s->GetXaxis()->SetBinLabel(4, "#gamma, K^{0}_{S}");
hPreselectionV0s->GetXaxis()->SetBinLabel(5, "#Lambda");
hPreselectionV0s->GetXaxis()->SetBinLabel(6, "#gamma, #Lambda");
hPreselectionV0s->GetXaxis()->SetBinLabel(7, "K^{0}_{S}, #Lambda");
hPreselectionV0s->GetXaxis()->SetBinLabel(8, "#gamma, K^{0}_{S}, #Lambda");
hPreselectionV0s->GetXaxis()->SetBinLabel(9, "#bar{#Lambda}");
hPreselectionV0s->GetXaxis()->SetBinLabel(10, "#gamma, #bar{#Lambda}");
hPreselectionV0s->GetXaxis()->SetBinLabel(11, "K^{0}_{S}, #bar{#Lambda}");
hPreselectionV0s->GetXaxis()->SetBinLabel(12, "#gamma, K^{0}_{S}, #bar{#Lambda}");
hPreselectionV0s->GetXaxis()->SetBinLabel(13, "#Lambda, #bar{#Lambda}");
hPreselectionV0s->GetXaxis()->SetBinLabel(14, "#gamma, #Lambda, #bar{#Lambda}");
hPreselectionV0s->GetXaxis()->SetBinLabel(15, "K^{0}_{S}, #Lambda, #bar{#Lambda}");
hPreselectionV0s->GetXaxis()->SetBinLabel(16, "#gamma, K^{0}_{S}, #Lambda, #bar{#Lambda}");
}
if (preSelectOpts.preselectOnlyDesiredCascades.value == true) {
auto hPreselectionCascades = histos.add<TH1>("hPreselectionCascades", "hPreselectionCascades", kTH1D, {{16, -0.5f, 15.5f}});
hPreselectionCascades->GetXaxis()->SetBinLabel(1, "Not preselected");
hPreselectionCascades->GetXaxis()->SetBinLabel(2, "#Xi^{-}");
hPreselectionCascades->GetXaxis()->SetBinLabel(3, "#Xi^{+}");
hPreselectionCascades->GetXaxis()->SetBinLabel(4, "#Xi^{-}, #Xi^{+}");
hPreselectionCascades->GetXaxis()->SetBinLabel(5, "#Omega^{-}");
hPreselectionCascades->GetXaxis()->SetBinLabel(6, "#Xi^{-}, #Omega^{-}");
hPreselectionCascades->GetXaxis()->SetBinLabel(7, "#Xi^{+}, #Omega^{-}");
hPreselectionCascades->GetXaxis()->SetBinLabel(8, "#Xi^{-}, #Xi^{+}, #Omega^{-}");
hPreselectionCascades->GetXaxis()->SetBinLabel(9, "#Omega^{+}");
hPreselectionCascades->GetXaxis()->SetBinLabel(10, "#Xi^{-}, #Omega^{+}");
hPreselectionCascades->GetXaxis()->SetBinLabel(11, "#Xi^{+}, #Omega^{+}");
hPreselectionCascades->GetXaxis()->SetBinLabel(12, "#Xi^{-}, #Xi^{+}, #Omega^{+}");
hPreselectionCascades->GetXaxis()->SetBinLabel(13, "#Omega^{-}, #Omega^{+}");
hPreselectionCascades->GetXaxis()->SetBinLabel(14, "#Xi^{-}, #Omega^{-}, #Omega^{+}");
hPreselectionCascades->GetXaxis()->SetBinLabel(15, "#Xi^{+}, #Omega^{-}, #Omega^{+}");
hPreselectionCascades->GetXaxis()->SetBinLabel(16, "#Xi^{-}, #Xi^{+}, #Omega^{-}, #Omega^{+}");
}
if (mc_findableMode.value > 0) {
// save statistics of findable candidate processing
auto hFindable = histos.add<TH1>("hFindableStatistics", "hFindableStatistics", kTH1D, {{6, -0.5f, 5.5f}});
hFindable->SetTitle(Form("Findable mode: %i", static_cast<int>(mc_findableMode.value)));
hFindable->GetXaxis()->SetBinLabel(1, "AO2D V0s");
hFindable->GetXaxis()->SetBinLabel(2, "V0s to be built");
hFindable->GetXaxis()->SetBinLabel(3, "V0s with collId -1");
hFindable->GetXaxis()->SetBinLabel(4, "AO2D Cascades");
hFindable->GetXaxis()->SetBinLabel(5, "Cascades to be built");
hFindable->GetXaxis()->SetBinLabel(6, "Cascades with collId -1");
}
auto hPrimaryV0s = histos.add<TH1>("hPrimaryV0s", "hPrimaryV0s", kTH1D, {{2, -0.5f, 1.5f}});
hPrimaryV0s->GetXaxis()->SetBinLabel(1, "All V0s");
hPrimaryV0s->GetXaxis()->SetBinLabel(2, "Primary V0s");
mRunNumber = 0;
mEnabledTables.resize(nTables, 0);
LOGF(info, "Configuring tables to generate");
auto& workflows = context.services().get<RunningWorkflowInfo const>();
TString listOfRequestors[nTables];
for (int i = 0; i < nTables; i++) {
// adjust bookkeeping histogram
h->GetXaxis()->SetBinLabel(i + 1, tableNames[i].c_str());
h2->GetXaxis()->SetBinLabel(i + 1, tableNames[i].c_str());
h->SetBinContent(i + 1, -1); // mark all as disabled to start
int f = enabledTables->get(tableNames[i].c_str(), "enable");
if (f == 1) {
mEnabledTables[i] = 1;
listOfRequestors[i] = "manual enabling";
}
if (f == -1) {
// autodetect this table in other devices
for (DeviceSpec const& device : workflows.devices) {
// Step 1: check if this device subscribed to the V0data table
for (auto const& input : device.inputs) {
if (device.name.compare("strangenessbuilder-initializer") == 0)
continue; // don't listen to the initializer
if (DataSpecUtils::partialMatch(input.matcher, o2::header::DataOrigin("AOD"))) {
auto&& [origin, description, version] = DataSpecUtils::asConcreteDataMatcher(input.matcher);
std::string tableNameWithVersion = tableNames[i];
if (version > 0) {
tableNameWithVersion += Form("_%03d", version);
}
if (input.matcher.binding == tableNameWithVersion) {
LOGF(info, "Device %s has subscribed to %s (version %i)", device.name, tableNames[i], version);
listOfRequestors[i].Append(Form("%s ", device.name.c_str()));
mEnabledTables[i] = 1;
}
}
}
}
}
}
LOGF(info, "*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*");
LOGF(info, " Strangeness builder: basic configuration listing");
LOGF(info, "*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*");
if (doprocessRealData) {
LOGF(info, " ===> process function enabled: processRealData");
}
if (doprocessRealDataRun2) {
LOGF(info, " ===> process function enabled: processRealDataRun2");
}
if (doprocessMonteCarlo) {
LOGF(info, " ===> process function enabled: processMonteCarlo");
}
if (doprocessMonteCarloRun2) {
LOGF(info, " ===> process function enabled: processMonteCarloRun2");
}
if (mc_findableMode.value == 1) {
LOGF(info, " ===> findable mode 1 is enabled: complement reco-ed with non-found findable");
}
if (mc_findableMode.value == 2) {
LOGF(info, " ===> findable mode 2 is enabled: re-generate all findable from scratch");
}
// list enabled tables
for (int i = 0; i < nTables; i++) {
// printout to be improved in the future
if (mEnabledTables[i]) {
LOGF(info, " -~> Table enabled: %s, requested by %s", tableNames[i], listOfRequestors[i].Data());
h->SetBinContent(i + 1, 0); // mark enabled
}
}
LOGF(info, "*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*");
// print base cuts
LOGF(info, "-~> V0 | min crossed rows ..............: %i", v0BuilderOpts.minCrossedRows.value);
LOGF(info, "-~> V0 | DCA pos track to PV ...........: %f", v0BuilderOpts.dcapostopv.value);
LOGF(info, "-~> V0 | DCA neg track to PV ...........: %f", v0BuilderOpts.dcanegtopv.value);
LOGF(info, "-~> V0 | V0 cosine of PA ...............: %f", v0BuilderOpts.v0cospa.value);
LOGF(info, "-~> V0 | DCA between V0 daughters ......: %f", v0BuilderOpts.dcav0dau.value);
LOGF(info, "-~> V0 | V0 2D decay radius ............: %f", v0BuilderOpts.v0radius.value);
LOGF(info, "-~> V0 | Maximum daughter eta ..........: %f", v0BuilderOpts.maxDaughterEta.value);
LOGF(info, "-~> Cascade | min crossed rows .........: %i", cascadeBuilderOpts.minCrossedRows.value);
LOGF(info, "-~> Cascade | DCA bach track to PV .....: %f", cascadeBuilderOpts.dcabachtopv.value);
LOGF(info, "-~> Cascade | Cascade cosine of PA .....: %f", cascadeBuilderOpts.casccospa.value);
LOGF(info, "-~> Cascade | Cascade daughter DCA .....: %f", cascadeBuilderOpts.dcacascdau.value);
LOGF(info, "-~> Cascade | Cascade radius ...........: %f", cascadeBuilderOpts.cascradius.value);
LOGF(info, "-~> Cascade | Lambda mass window .......: %f", cascadeBuilderOpts.lambdaMassWindow.value);
LOGF(info, "-~> Cascade | Maximum daughter eta .....: %f", cascadeBuilderOpts.maxDaughterEta.value);
LOGF(info, "*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*");
ccdb->setURL(ccdbConfigurations.ccdburl);
ccdb->setCaching(true);
ccdb->setLocalObjectValidityChecking();
ccdb->setFatalWhenNull(false);
// set V0 parameters in the helper
straHelper.v0selections.minCrossedRows = v0BuilderOpts.minCrossedRows;
straHelper.v0selections.dcanegtopv = v0BuilderOpts.dcanegtopv;
straHelper.v0selections.dcapostopv = v0BuilderOpts.dcapostopv;
straHelper.v0selections.v0cospa = v0BuilderOpts.v0cospa;
straHelper.v0selections.dcav0dau = v0BuilderOpts.dcav0dau;
straHelper.v0selections.v0radius = v0BuilderOpts.v0radius;
straHelper.v0selections.maxDaughterEta = v0BuilderOpts.maxDaughterEta;
// set cascade parameters in the helper
straHelper.cascadeselections.minCrossedRows = cascadeBuilderOpts.minCrossedRows;
straHelper.cascadeselections.dcabachtopv = cascadeBuilderOpts.dcabachtopv;
straHelper.cascadeselections.cascradius = cascadeBuilderOpts.cascradius;
straHelper.cascadeselections.casccospa = cascadeBuilderOpts.casccospa;
straHelper.cascadeselections.dcacascdau = cascadeBuilderOpts.dcacascdau;
straHelper.cascadeselections.lambdaMassWindow = cascadeBuilderOpts.lambdaMassWindow;
straHelper.cascadeselections.maxDaughterEta = cascadeBuilderOpts.maxDaughterEta;
}
bool verifyMask(uint8_t bitmap, uint8_t mask)
{
return (bitmap & mask) == mask;
}
// for sorting
template <typename T>
std::vector<std::size_t> sort_indices(const std::vector<T>& v, bool doSorting = false)
{
std::vector<std::size_t> idx(v.size());
std::iota(idx.begin(), idx.end(), 0);
if (doSorting) {
// do sorting only if requested (not always necessary)
std::stable_sort(idx.begin(), idx.end(),
[&v](std::size_t i1, std::size_t i2) { return v[i1].collisionId < v[i2].collisionId; });
}
return idx;
}
template <typename TCollisions>
bool initCCDB(aod::BCsWithTimestamps const& bcs, TCollisions const& collisions)
{
auto bc = collisions.size() ? collisions.begin().template bc_as<aod::BCsWithTimestamps>() : bcs.begin();
if (!bcs.size()) {
LOGF(warn, "No BC found, skipping this DF.");
return false; // signal to skip this DF
}
if (mRunNumber == bc.runNumber()) {
return true;
}
auto timestamp = bc.timestamp();
o2::parameters::GRPObject* grpo = 0x0;
o2::parameters::GRPMagField* grpmag = 0x0;
if (doprocessRealDataRun2) {
grpo = ccdb->getForTimeStamp<o2::parameters::GRPObject>(ccdbConfigurations.grpPath, timestamp);
if (!grpo) {
LOG(fatal) << "Got nullptr from CCDB for path " << ccdbConfigurations.grpPath << " of object GRPObject for timestamp " << timestamp;
}
o2::base::Propagator::initFieldFromGRP(grpo);
} else {
grpmag = ccdb->getForTimeStamp<o2::parameters::GRPMagField>(ccdbConfigurations.grpmagPath, timestamp);
if (!grpmag) {
LOG(fatal) << "Got nullptr from CCDB for path " << ccdbConfigurations.grpmagPath << " of object GRPMagField for timestamp " << timestamp;
}
o2::base::Propagator::initFieldFromGRP(grpmag);
}
// Fetch magnetic field from ccdb for current collision
auto magneticField = o2::base::Propagator::Instance()->getNominalBz();
LOG(info) << "Retrieved GRP for timestamp " << timestamp << " with magnetic field of " << magneticField << " kG";
// Set magnetic field value once known
straHelper.fitter.setBz(magneticField);
// acquire LUT for this timestamp
LOG(info) << "Loading material look-up table for timestamp: " << timestamp;
lut = o2::base::MatLayerCylSet::rectifyPtrFromFile(ccdb->getForTimeStamp<o2::base::MatLayerCylSet>(ccdbConfigurations.lutPath, timestamp));
o2::base::Propagator::Instance()->setMatLUT(lut);
straHelper.lut = lut;
LOG(info) << "Fully configured for run: " << bc.runNumber();
// mmark this run as configured
mRunNumber = bc.runNumber();
if (v0BuilderOpts.generatePhotonCandidates.value && v0BuilderOpts.moveTPCOnlyTracks.value) {
// initialize only if needed, avoid unnecessary CCDB calls
mVDriftMgr.init(&ccdb->instance());
mVDriftMgr.update(timestamp);
}
return true;
}
//__________________________________________________
void resetInterlinks()
{
interlinks.cascCoreToCascades.clear();
interlinks.kfCascCoreToCascades.clear();
interlinks.traCascCoreToCascades.clear();
interlinks.cascadeToCascCores.clear();
interlinks.cascadeToKFCascCores.clear();
interlinks.cascadeToTraCascCores.clear();
}
//__________________________________________________
void populateCascadeInterlinks()
{
// if (mEnabledTables[kCascToKFRefs]) {
// for (const auto& cascCore : interlinks.cascCoreToCascades) {
// cascToKFRefs(interlinks.cascadeToKFCascCores[cascCore]);
// histos.fill(HIST("hTableBuildingStatistics"), kCascToKFRefs);
// }
// }
// if (mEnabledTables[kCascToTraRefs]) {
// for (const auto& cascCore : interlinks.cascCoreToCascades) {
// cascToTraRefs(interlinks.cascadeToTraCascCores[cascCore]);
// histos.fill(HIST("hTableBuildingStatistics"), kCascToTraRefs);
// }
// }
// if (mEnabledTables[kKFToCascRefs]) {
// for (const auto& kfCascCore : interlinks.kfCascCoreToCascades) {
// kfToCascRefs(interlinks.cascadeToCascCores[kfCascCore]);
// histos.fill(HIST("hTableBuildingStatistics"), kKFToCascRefs);
// }
// }
// if (mEnabledTables[kTraToCascRefs]) {
// for (const auto& traCascCore : interlinks.traCascCoreToCascades) {
// traToCascRefs(interlinks.cascadeToCascCores[traCascCore]);
// histos.fill(HIST("hTableBuildingStatistics"), kTraToCascRefs);
// }
// }
}
//__________________________________________________
template <class TBCs, typename TCollisions, typename TMCCollisions, typename TV0s, typename TCascades, typename TTracks, typename TMCParticles>
void prepareBuildingLists(TCollisions const& collisions, TMCCollisions const& mcCollisions, TV0s const& v0s, TCascades const& cascades, TTracks const& tracks, TMCParticles const& mcParticles)
{
// this function prepares the v0List and cascadeList depending on
// how the task has been set up. Standard operation simply uses
// the existing V0s and Cascades from AO2D, while findable MC
// operation either complements with all findable-but-not-found
// or resets and fills with all findable.
//
// Whenever using findable candidates, they will be appropriately
// marked for posterior analysis using 'tag' variables.
//
// findable mode legend:
// 0: simple passthrough of V0s, Cascades in AO2Ds
// (in data, this is the only mode possible!)
// 1: add extra findable that haven't been found
// 2: generate only findable (no background)
// redo lists from scratch
v0List.clear();
cascadeList.clear();
sorted_v0.clear();
sorted_cascade.clear();
ao2dV0toV0List.clear();
trackEntry currentTrackEntry;
v0Entry currentV0Entry;
cascadeEntry currentCascadeEntry;
std::vector<int> bestCollisionArray; // stores McCollision -> Collision map
std::vector<int> bestCollisionNContribsArray; // stores Ncontribs for biggest coll assoc to mccoll
int collisionLessV0s = 0;
int collisionLessCascades = 0;
if (mc_findableMode.value > 0) {
if constexpr (soa::is_table<TMCCollisions>) {
// if mcCollisions exist, assemble mcColl -> bestRecoColl map here
bestCollisionArray.clear();
bestCollisionNContribsArray.clear();
bestCollisionArray.resize(mcCollisions.size(), -1); // marks not reconstructed
bestCollisionNContribsArray.resize(mcCollisions.size(), -1); // marks not reconstructed
// single loop over double loop at a small cost in memory for extra array
for (const auto& collision : collisions) {
if (collision.has_mcCollision()) {
if (collision.numContrib() > bestCollisionNContribsArray[collision.mcCollisionId()]) {
bestCollisionArray[collision.mcCollisionId()] = collision.globalIndex();
bestCollisionNContribsArray[collision.mcCollisionId()] = collision.numContrib();
}
}
} // end collision loop
} // end is_table<TMCCollisions>
} // end findable mode check
if (mc_findableMode.value < 2) {
// keep all unless de-duplication active
ao2dV0toV0List.resize(v0s.size(), -1); // -1 means keep, -2 means do not keep
if (deduplicationAlgorithm > 0 && v0BuilderOpts.generatePhotonCandidates) {
// handle duplicates explicitly: group V0s according to (p,n) indices
// will provide a list of collisionIds (in V0group), allowing for
// easy de-duplication when passing to the v0List
std::vector<o2::pwglf::V0group> v0tableGrouped = o2::pwglf::groupDuplicates(v0s);
histos.fill(HIST("hDeduplicationStatistics"), 0.0, v0s.size());
histos.fill(HIST("hDeduplicationStatistics"), 1.0, v0tableGrouped.size());
// process grouped duplicates, remove 'bad' ones
for (size_t iV0 = 0; iV0 < v0tableGrouped.size(); iV0++) {
auto pTrack = tracks.rawIteratorAt(v0tableGrouped[iV0].posTrackId);
auto nTrack = tracks.rawIteratorAt(v0tableGrouped[iV0].negTrackId);
bool isPosTPCOnly = (pTrack.hasTPC() && !pTrack.hasITS() && !pTrack.hasTRD() && !pTrack.hasTOF());
bool isNegTPCOnly = (nTrack.hasTPC() && !nTrack.hasITS() && !nTrack.hasTRD() && !nTrack.hasTOF());
// skip single copy V0s
if (v0tableGrouped[iV0].collisionIds.size() == 1) {
continue;
}
// don't try to de-duplicate if no track is TPC only
if (!isPosTPCOnly && !isNegTPCOnly) {
continue;
}
// fitness criteria defined here
float bestPointingAngle = 10; // a nonsense angle, anything's better
size_t bestPointingAngleIndex = -1;
float bestDCADaughters = 1e+3; // an excessively large DCA
size_t bestDCADaughtersIndex = -1;
for (size_t ic = 0; ic < v0tableGrouped[iV0].collisionIds.size(); ic++) {
// get track parametrizations, collisions
auto posTrackPar = getTrackParCov(pTrack);
auto negTrackPar = getTrackParCov(nTrack);
auto const& collision = collisions.rawIteratorAt(v0tableGrouped[iV0].collisionIds[ic]);
// handle TPC-only tracks properly (photon conversions)
if (v0BuilderOpts.moveTPCOnlyTracks) {
if (isPosTPCOnly) {
// Nota bene: positive is TPC-only -> this entire V0 merits treatment as photon candidate
posTrackPar.setPID(o2::track::PID::Electron);
negTrackPar.setPID(o2::track::PID::Electron);
if (!mVDriftMgr.moveTPCTrack<TBCs, TCollisions>(collision, pTrack, posTrackPar)) {
return;
}
}
if (isNegTPCOnly) {
// Nota bene: negative is TPC-only -> this entire V0 merits treatment as photon candidate
posTrackPar.setPID(o2::track::PID::Electron);
negTrackPar.setPID(o2::track::PID::Electron);
if (!mVDriftMgr.moveTPCTrack<TBCs, TCollisions>(collision, nTrack, negTrackPar)) {
return;
}
}
} // end TPC drift treatment
// process candidate with helper, generate properties for consulting
// <false>: do not apply selections: do as much as possible to preserve
// candidate at this level and do not select with topo selections
if (straHelper.buildV0Candidate<false>(v0tableGrouped[iV0].collisionIds[ic], collision.posX(), collision.posY(), collision.posZ(), pTrack, nTrack, posTrackPar, negTrackPar, true, false, true)) {
// candidate built, check pointing angle
if (straHelper.v0.pointingAngle < bestPointingAngle) {
bestPointingAngle = straHelper.v0.pointingAngle;
bestPointingAngleIndex = ic;
}
if (straHelper.v0.daughterDCA < bestDCADaughters) {
bestDCADaughters = straHelper.v0.daughterDCA;
bestDCADaughtersIndex = ic;
}
} // end build V0
} // end candidate loop
// mark de-duplicated candidates
for (size_t ic = 0; ic < v0tableGrouped[iV0].collisionIds.size(); ic++) {
ao2dV0toV0List[v0tableGrouped[iV0].V0Ids[ic]] = -2;
// algorithm 1: best pointing angle
if (bestPointingAngleIndex == ic && deduplicationAlgorithm.value == 1) {
ao2dV0toV0List[v0tableGrouped[iV0].V0Ids[ic]] = -1; // keep best only
}
if (bestDCADaughtersIndex == ic && deduplicationAlgorithm.value == 2) {
ao2dV0toV0List[v0tableGrouped[iV0].V0Ids[ic]] = -1; // keep best only
}
if (bestDCADaughtersIndex == ic && bestPointingAngleIndex == ic && deduplicationAlgorithm.value == 3) {
ao2dV0toV0List[v0tableGrouped[iV0].V0Ids[ic]] = -1; // keep best only
}
}
} // end V0 loop
} // end de-duplication process
for (const auto& v0 : v0s) {
if (ao2dV0toV0List[v0.globalIndex()] == -1) { // keep only de-duplicated
ao2dV0toV0List[v0.globalIndex()] = v0List.size(); // maps V0s to the corresponding v0List entry
currentV0Entry.globalId = v0.globalIndex();
currentV0Entry.collisionId = v0.collisionId();
currentV0Entry.posTrackId = v0.posTrackId();
currentV0Entry.negTrackId = v0.negTrackId();
currentV0Entry.v0Type = v0.v0Type();
currentV0Entry.pdgCode = 0;
currentV0Entry.particleId = -1;
currentV0Entry.isCollinearV0 = v0.isCollinearV0();
currentV0Entry.found = true;
v0List.push_back(currentV0Entry);
}
}
}