forked from AliceO2Group/O2Physics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrangenessBuilderModule.h
More file actions
2564 lines (2309 loc) · 134 KB
/
strangenessBuilderModule.h
File metadata and controls
2564 lines (2309 loc) · 134 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 strangenessBuilderModule.h
/// \brief strangeness builder module
/// \author ALICE
// simple checkers, but ensure 8 bit integers
#define BITSET(var, nbit) ((var) |= (static_cast<uint8_t>(1) << static_cast<uint8_t>(nbit)))
#ifndef PWGLF_UTILS_STRANGENESSBUILDERMODULE_H_
#define PWGLF_UTILS_STRANGENESSBUILDERMODULE_H_
#include "TableHelper.h"
#include "PWGLF/DataModel/LFStrangenessTables.h"
#include "PWGLF/Utils/strangenessBuilderHelper.h"
#include "Common/Core/TPCVDriftManager.h"
#include "DataFormatsCalibration/MeanVertexObject.h"
#include "DataFormatsParameters/GRPMagField.h"
#include "Framework/AnalysisDataModel.h"
#include "Framework/AnalysisHelpers.h"
#include "Framework/Configurable.h"
#include "Framework/HistogramRegistry.h"
#include "Framework/HistogramSpec.h"
#include <array>
#include <cmath>
#include <cstdlib>
#include <memory>
#include <string>
//__________________________________________
// strangeness builder module
namespace o2
{
namespace pwglf
{
namespace strangenessbuilder // avoid polluting other namespaces
{
// statics necessary for the configurables in this namespace
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}};
// 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 = 0,
selK0Short,
selLambda,
selAntiLambda };
enum CascPreSelection : uint8_t { selXiMinus = 0,
selXiPlus,
selOmegaMinus,
selOmegaPlus };
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}};
struct products : o2::framework::ProducesGroup {
//__________________________________________________
// V0 tables
o2::framework::Produces<aod::V0Indices> v0indices; // standard part of V0Datas
o2::framework::Produces<aod::V0CoresBase> v0cores; // standard part of V0Datas
o2::framework::Produces<aod::V0Covs> v0covs; // for decay chain reco
//__________________________________________________
// cascade tables
o2::framework::Produces<aod::CascIndices> cascidx; // standard part of CascDatas
o2::framework::Produces<aod::KFCascIndices> kfcascidx; // standard part of KFCascDatas
o2::framework::Produces<aod::TraCascIndices> tracascidx; // standard part of TraCascDatas
o2::framework::Produces<aod::StoredCascCores> cascdata; // standard part of CascDatas
o2::framework::Produces<aod::StoredKFCascCores> kfcascdata; // standard part of KFCascDatas
o2::framework::Produces<aod::StoredTraCascCores> tracascdata; // standard part of TraCascDatas
o2::framework::Produces<aod::CascCovs> casccovs; // for decay chain reco
o2::framework::Produces<aod::KFCascCovs> kfcasccovs; // for decay chain reco
o2::framework::Produces<aod::TraCascCovs> tracasccovs; // for decay chain reco
//__________________________________________________
// interlink tables
o2::framework::Produces<aod::V0DataLink> v0dataLink; // de-refs V0s -> V0Data
o2::framework::Produces<aod::CascDataLink> cascdataLink; // de-refs Cascades -> CascData
o2::framework::Produces<aod::KFCascDataLink> kfcascdataLink; // de-refs Cascades -> KFCascData
o2::framework::Produces<aod::TraCascDataLink> tracascdataLink; // de-refs Cascades -> TraCascData
//__________________________________________________
// secondary auxiliary tables
o2::framework::Produces<aod::V0TrackXs> v0trackXs; // for decay chain reco
o2::framework::Produces<aod::CascTrackXs> cascTrackXs; // for decay chain reco
//__________________________________________________
// further auxiliary / optional if desired
o2::framework::Produces<aod::CascBBs> cascbb;
o2::framework::Produces<aod::V0DauCovs> v0daucovs; // covariances of daughter tracks
o2::framework::Produces<aod::V0DauCovIUs> v0daucovIUs; // covariances of daughter tracks
o2::framework::Produces<aod::V0TraPosAtDCAs> v0dauPositions; // auxiliary debug information
o2::framework::Produces<aod::V0TraPosAtIUs> v0dauPositionsIU; // auxiliary debug information
o2::framework::Produces<aod::V0Ivanovs> v0ivanovs; // information for Marian's tests
//__________________________________________________
// MC information: V0
o2::framework::Produces<aod::McV0Labels> v0labels; // MC labels for V0s
o2::framework::Produces<aod::V0MCCores> v0mccores; // mc info storage
o2::framework::Produces<aod::V0CoreMCLabels> v0CoreMCLabels; // interlink V0Cores -> V0MCCores
o2::framework::Produces<aod::V0MCCollRefs> v0mccollref; // references collisions from V0MCCores
// MC information: Cascades
o2::framework::Produces<aod::McCascLabels> casclabels; // MC labels for cascades
o2::framework::Produces<aod::McKFCascLabels> kfcasclabels; // MC labels for KF cascades
o2::framework::Produces<aod::McTraCascLabels> tracasclabels; // MC labels for tracked cascades
o2::framework::Produces<aod::McCascBBTags> bbtags; // bb tags (inv structure tagging in mc)
o2::framework::Produces<aod::CascMCCores> cascmccores; // mc info storage
o2::framework::Produces<aod::CascCoreMCLabels> cascCoreMClabels; // interlink CascCores -> CascMCCores
o2::framework::Produces<aod::CascMCCollRefs> cascmccollrefs; // references MC collisions from MC cascades
//__________________________________________________
// cascade interlinks
// FIXME: commented out until strangederivedbuilder adjusted accordingly
// o2::framework::Produces<aod::CascToTraRefs> cascToTraRefs; // cascades -> tracked
// o2::framework::Produces<aod::CascToKFRefs> cascToKFRefs; // cascades -> KF
// o2::framework::Produces<aod::TraToCascRefs> traToCascRefs; // tracked -> cascades
// o2::framework::Produces<aod::KFToCascRefs> kfToCascRefs; // KF -> cascades
//__________________________________________________
// Findable tags
o2::framework::Produces<aod::V0FoundTags> v0FoundTag;
o2::framework::Produces<aod::CascFoundTags> cascFoundTag;
};
// strangenessBuilder: 1st-order configurables
struct coreConfigurables : o2::framework::ConfigurableGroup {
o2::framework::Configurable<o2::framework::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
// first order deduplication implementation
// more algorithms to be added as necessary
o2::framework::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)
o2::framework::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"};
o2::framework::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"};
};
// strangenessBuilder: V0 building options
struct v0Configurables : o2::framework::ConfigurableGroup {
std::string prefix = "v0BuilderOpts";
o2::framework::Configurable<bool> generatePhotonCandidates{"generatePhotonCandidates", false, "generate gamma conversion candidates (V0s using TPC-only tracks)"};
o2::framework::Configurable<bool> moveTPCOnlyTracks{"moveTPCOnlyTracks", true, "if dealing with TPC-only tracks, move them according to TPC drift / time info"};
// baseline conditionals of V0 building
o2::framework::Configurable<int> minCrossedRows{"minCrossedRows", 50, "minimum TPC crossed rows for daughter tracks"};
o2::framework::Configurable<float> dcanegtopv{"dcanegtopv", .1, "DCA Neg To PV"};
o2::framework::Configurable<float> dcapostopv{"dcapostopv", .1, "DCA Pos To PV"};
o2::framework::Configurable<double> v0cospa{"v0cospa", 0.95, "V0 CosPA"}; // double -> N.B. dcos(x)/dx = 0 at x=0)
o2::framework::Configurable<float> dcav0dau{"dcav0dau", 1.0, "DCA V0 Daughters"};
o2::framework::Configurable<float> v0radius{"v0radius", 0.9, "v0radius"};
o2::framework::Configurable<float> maxDaughterEta{"maxDaughterEta", 5.0, "Maximum daughter eta (in abs value)"};
// MC builder options
o2::framework::Configurable<bool> mc_populateV0MCCoresSymmetric{"mc_populateV0MCCoresSymmetric", false, "populate V0MCCores table for derived data analysis, keep V0MCCores joinable with V0Cores"};
o2::framework::Configurable<bool> mc_populateV0MCCoresAsymmetric{"mc_populateV0MCCoresAsymmetric", true, "populate V0MCCores table for derived data analysis, create V0Cores -> V0MCCores interlink. Saves only labeled V0s."};
o2::framework::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!"};
o2::framework::Configurable<float> mc_rapidityWindow{"mc_rapidityWindow", 0.5, "rapidity window to save non-recoed candidates"};
o2::framework::Configurable<bool> mc_keepOnlyPhysicalPrimary{"mc_keepOnlyPhysicalPrimary", false, "Keep only physical primary generated V0s if not recoed"};
o2::framework::Configurable<bool> mc_addGeneratedK0Short{"mc_addGeneratedK0Short", true, "add V0MCCore entry for generated, not-recoed K0Short"};
o2::framework::Configurable<bool> mc_addGeneratedLambda{"mc_addGeneratedLambda", true, "add V0MCCore entry for generated, not-recoed Lambda"};
o2::framework::Configurable<bool> mc_addGeneratedAntiLambda{"mc_addGeneratedAntiLambda", true, "add V0MCCore entry for generated, not-recoed AntiLambda"};
o2::framework::Configurable<bool> mc_addGeneratedGamma{"mc_addGeneratedGamma", false, "add V0MCCore entry for generated, not-recoed Gamma"};
o2::framework::Configurable<bool> mc_addGeneratedGammaMakeCollinear{"mc_addGeneratedGammaMakeCollinear", true, "when adding findable gammas, mark them as collinear"};
o2::framework::Configurable<bool> mc_findableDetachedV0{"mc_findableDetachedV0", false, "if true, generate findable V0s that have collisionId -1. Caution advised."};
};
// strangenessBuilder: cascade building options
struct cascadeConfigurables : o2::framework::ConfigurableGroup {
std::string prefix = "cascadeBuilderOpts";
o2::framework::Configurable<bool> useCascadeMomentumAtPrimVtx{"useCascadeMomentumAtPrimVtx", false, "use cascade momentum at PV"};
// conditionals
o2::framework::Configurable<int> minCrossedRows{"minCrossedRows", 50, "minimum TPC crossed rows for daughter tracks"};
o2::framework::Configurable<float> dcabachtopv{"dcabachtopv", .05, "DCA Bach To PV"};
o2::framework::Configurable<float> cascradius{"cascradius", 0.9, "cascradius"};
o2::framework::Configurable<float> casccospa{"casccospa", 0.95, "casccospa"};
o2::framework::Configurable<float> dcacascdau{"dcacascdau", 1.0, "DCA cascade Daughters"};
o2::framework::Configurable<float> lambdaMassWindow{"lambdaMassWindow", .010, "Distance from Lambda mass (does not apply to KF path)"};
o2::framework::Configurable<float> maxDaughterEta{"maxDaughterEta", 5.0, "Maximum daughter eta (in abs value)"};
// KF building specific
o2::framework::Configurable<bool> kfTuneForOmega{"kfTuneForOmega", false, "if enabled, take main cascade properties from Omega fit instead of Xi fit (= default)"};
o2::framework::Configurable<int> kfConstructMethod{"kfConstructMethod", 2, "KF Construct Method"};
o2::framework::Configurable<bool> kfUseV0MassConstraint{"kfUseV0MassConstraint", true, "KF: use Lambda mass constraint"};
o2::framework::Configurable<bool> kfUseCascadeMassConstraint{"kfUseCascadeMassConstraint", false, "KF: use Cascade mass constraint - WARNING: not adequate for inv mass analysis of Xi"};
o2::framework::Configurable<bool> kfDoDCAFitterPreMinimV0{"kfDoDCAFitterPreMinimV0", true, "KF: do DCAFitter pre-optimization before KF fit to include material corrections for V0"};
o2::framework::Configurable<bool> kfDoDCAFitterPreMinimCasc{"kfDoDCAFitterPreMinimCasc", true, "KF: do DCAFitter pre-optimization before KF fit to include material corrections for Xi"};
// MC builder options
o2::framework::Configurable<bool> mc_populateCascMCCoresSymmetric{"mc_populateCascMCCoresSymmetric", false, "populate CascMCCores table for derived data analysis, keep CascMCCores joinable with CascCores"};
o2::framework::Configurable<bool> mc_populateCascMCCoresAsymmetric{"mc_populateCascMCCoresAsymmetric", true, "populate CascMCCores table for derived data analysis, create CascCores -> CascMCCores interlink. Saves only labeled Cascades."};
o2::framework::Configurable<bool> mc_addGeneratedXiMinus{"mc_addGeneratedXiMinus", true, "add CascMCCore entry for generated, not-recoed XiMinus"};
o2::framework::Configurable<bool> mc_addGeneratedXiPlus{"mc_addGeneratedXiPlus", true, "add CascMCCore entry for generated, not-recoed XiPlus"};
o2::framework::Configurable<bool> mc_addGeneratedOmegaMinus{"mc_addGeneratedOmegaMinus", true, "add CascMCCore entry for generated, not-recoed OmegaMinus"};
o2::framework::Configurable<bool> mc_addGeneratedOmegaPlus{"mc_addGeneratedOmegaPlus", true, "add CascMCCore entry for generated, not-recoed OmegaPlus"};
o2::framework::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!"};
o2::framework::Configurable<float> mc_rapidityWindow{"mc_rapidityWindow", 0.5, "rapidity window to save non-recoed candidates"};
o2::framework::Configurable<bool> mc_keepOnlyPhysicalPrimary{"mc_keepOnlyPhysicalPrimary", false, "Keep only physical primary generated cascades if not recoed"};
o2::framework::Configurable<bool> mc_findableDetachedCascade{"mc_findableDetachedCascade", false, "if true, generate findable cascades that have collisionId -1. Caution advised."};
};
// preselection options
struct preSelectOpts : o2::framework::ConfigurableGroup {
std::string prefix = "preSelectOpts";
o2::framework::Configurable<bool> preselectOnlyDesiredV0s{"preselectOnlyDesiredV0s", false, "preselect only V0s with compatible TPC PID and mass info"};
o2::framework::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
o2::framework::Configurable<o2::framework::LabeledArray<float>> lifetimeCut{"lifetimeCut", {defaultLifetimeCuts[0], 4, {"lifetimeCutK0S", "lifetimeCutLambda", "lifetimeCutXi", "lifetimeCutOmega"}}, "Lifetime cut for V0s and cascades (cm)"};
// mass preselection options
o2::framework::Configurable<float> massCutPhoton{"massCutPhoton", 0.3, "Photon max mass"};
o2::framework::Configurable<o2::framework::LabeledArray<float>> massCutK0{"massCutK0", {defaultK0MassWindowParameters[0], 4, {"constant", "linear", "expoConstant", "expoRelax"}}, "mass parameters for K0"};
o2::framework::Configurable<o2::framework::LabeledArray<float>> massCutLambda{"massCutLambda", {defaultLambdaWindowParameters[0], 4, {"constant", "linear", "expoConstant", "expoRelax"}}, "mass parameters for Lambda"};
o2::framework::Configurable<o2::framework::LabeledArray<float>> massCutXi{"massCutXi", {defaultXiMassWindowParameters[0], 4, {"constant", "linear", "expoConstant", "expoRelax"}}, "mass parameters for Xi"};
o2::framework::Configurable<o2::framework::LabeledArray<float>> massCutOm{"massCutOm", {defaultOmMassWindowParameters[0], 4, {"constant", "linear", "expoConstant", "expoRelax"}}, "mass parameters for Omega"};
o2::framework::Configurable<float> massWindownumberOfSigmas{"massWindownumberOfSigmas", 20, "number of sigmas around mass peaks to keep"};
o2::framework::Configurable<float> massWindowSafetyMargin{"massWindowSafetyMargin", 0.001, "Extra mass window safety margin (in GeV/c2)"};
// TPC PID preselection options
o2::framework::Configurable<float> maxTPCpidNsigma{"maxTPCpidNsigma", 5.0, "Maximum TPC PID N sigma (in abs value)"};
};
class BuilderModule
{
public:
BuilderModule()
{
// constructor
}
// mass windows
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"));
}
int nEnabledTables = 0;
// helper object
o2::pwglf::strangenessBuilderHelper straHelper;
// for handling TPC-only tracks (photons)
int mRunNumber;
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;
//*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*
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
// declaration of structs here
// (N.B.: will be invisible to the outside, create your own copies)
o2::pwglf::strangenessbuilder::coreConfigurables baseOpts;
o2::pwglf::strangenessbuilder::v0Configurables v0BuilderOpts;
o2::pwglf::strangenessbuilder::cascadeConfigurables cascadeBuilderOpts;
o2::pwglf::strangenessbuilder::preSelectOpts preSelectOpts;
template <typename TBaseConfigurables, typename TV0Configurables, typename TCascadeConfigurables, typename TPreSelOpts, typename THistoRegistry, typename TInitContext>
void init(TBaseConfigurables const& inputBaseOpts, TV0Configurables const& inputV0BuilderOpts, TCascadeConfigurables const& inputCascadeBuilderOpts, TPreSelOpts const& inputPreSelectOpts, THistoRegistry& histos, TInitContext& context)
{
// read in configurations from the task where it's used
// could be grouped even further, but should work
baseOpts = inputBaseOpts;
v0BuilderOpts = inputV0BuilderOpts;
cascadeBuilderOpts = inputCascadeBuilderOpts;
preSelectOpts = inputPreSelectOpts;
baseOpts.mEnabledTables.resize(nTables, 0);
LOGF(info, "Checking if strangeness building is required");
auto& workflows = context.services().template get<o2::framework::RunningWorkflowInfo const>();
nEnabledTables = 0;
TString listOfRequestors[nTables];
for (int i = 0; i < nTables; i++) {
int f = baseOpts.enabledTables->get(tableNames[i].c_str(), "enable");
if (f == 1) {
baseOpts.mEnabledTables[i] = 1;
listOfRequestors[i] = "manual enabling";
}
if (f == -1) {
// autodetect this table in other devices
for (o2::framework::DeviceSpec const& device : workflows.devices) {
// Step 1: check if this device subscribed to the V0data table
for (auto const& input : device.inputs) {
if (o2::framework::DataSpecUtils::partialMatch(input.matcher, o2::header::DataOrigin("AOD"))) {
auto&& [origin, description, version] = o2::framework::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()));
baseOpts.mEnabledTables[i] = 1;
nEnabledTables++;
}
}
}
}
}
}
if (nEnabledTables == 0) {
LOGF(info, "Strangeness building not required. Will suppress all functionality, including logs, from this point forward.");
return;
}
// setup bookkeeping histogram
auto h = histos.template add<TH1>("hTableBuildingStatistics", "hTableBuildingStatistics", o2::framework::kTH1D, {{nTablesConst, -0.5f, static_cast<float>(nTablesConst)}});
auto h2 = histos.template add<TH1>("hInputStatistics", "hInputStatistics", o2::framework::kTH1D, {{nTablesConst, -0.5f, static_cast<float>(nTablesConst)}});
h2->SetTitle("Input table sizes");
if (v0BuilderOpts.generatePhotonCandidates.value == true) {
auto hDeduplicationStatistics = histos.template add<TH1>("hDeduplicationStatistics", "hDeduplicationStatistics", o2::framework::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.template add<TH1>("hPreselectionV0s", "hPreselectionV0s", o2::framework::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.template add<TH1>("hPreselectionCascades", "hPreselectionCascades", o2::framework::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 (baseOpts.mc_findableMode.value > 0) {
// save statistics of findable candidate processing
auto hFindable = histos.template add<TH1>("hFindableStatistics", "hFindableStatistics", o2::framework::kTH1D, {{6, -0.5f, 5.5f}});
hFindable->SetTitle(Form("Findable mode: %i", static_cast<int>(baseOpts.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.template add<TH1>("hPrimaryV0s", "hPrimaryV0s", o2::framework::kTH1D, {{2, -0.5f, 1.5f}});
hPrimaryV0s->GetXaxis()->SetBinLabel(1, "All V0s");
hPrimaryV0s->GetXaxis()->SetBinLabel(2, "Primary V0s");
mRunNumber = 0;
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());
if (baseOpts.mEnabledTables[i] == false) {
h->SetBinContent(i + 1, -1); // mark disabled tables, distinguish from zero counts
}
}
LOGF(info, "*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*");
LOGF(info, " Strangeness builder: basic configuration listing");
LOGF(info, "*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*");
if (baseOpts.mc_findableMode.value == 1) {
LOGF(info, " ===> findable mode 1 is enabled: complement reco-ed with non-found findable");
}
if (baseOpts.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 (baseOpts.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, "*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*+-+*");
// 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;
}
// 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, typename TCCDB>
bool initCCDB(TCCDB& ccdb, 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();
// Fetch magnetic field from ccdb for current collision
auto magneticField = o2::base::Propagator::Instance()->getNominalBz();
LOG(info) << "Configuring for timestamp " << timestamp << " with magnetic field of " << magneticField << " kG";
// Set magnetic field value once known
straHelper.fitter.setBz(magneticField);
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 THistoRegistry, typename TCollisions, typename TMCCollisions, typename TV0s, typename TCascades, typename TTracks, typename TMCParticles>
void prepareBuildingLists(THistoRegistry& histos, 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 (baseOpts.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 (baseOpts.mc_findableMode.value < 2) {
// keep all unless de-duplication active
ao2dV0toV0List.resize(v0s.size(), -1); // -1 means keep, -2 means do not keep
if (baseOpts.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)) {
continue;
}
}
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)) {
continue;
}
}
} // 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 && baseOpts.deduplicationAlgorithm.value == 1) {
ao2dV0toV0List[v0tableGrouped[iV0].V0Ids[ic]] = -1; // keep best only
}
if (bestDCADaughtersIndex == ic && baseOpts.deduplicationAlgorithm.value == 2) {
ao2dV0toV0List[v0tableGrouped[iV0].V0Ids[ic]] = -1; // keep best only
}
if (bestDCADaughtersIndex == ic && bestPointingAngleIndex == ic && baseOpts.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);
}
}
}
// any mode other than 0 will require mcParticles
if constexpr (soa::is_table<TMCCollisions>) {
if (baseOpts.mc_findableMode.value > 0) {
// for search if existing or not
int v0ListReconstructedSize = v0List.size();
// find extra candidates, step 1: find subset of tracks that interest
std::vector<trackEntry> positiveTrackArray;
std::vector<trackEntry> negativeTrackArray;
// vector elements: track index, origin index [, mc collision id, pdg code]
int dummy = -1; // unnecessary in this path
for (const auto& track : tracks) {
if (!track.has_mcParticle()) {
continue; // skip this, it's trouble
}
auto particle = track.template mcParticle_as<TMCParticles>();
int originParticleIndex = getOriginatingParticle(particle, dummy, v0BuilderOpts.mc_treatPiToMuDecays);
if (originParticleIndex < 0) {
continue; // skip this, it's trouble (2)
}
auto originParticle = mcParticles.rawIteratorAt(originParticleIndex);
bool trackIsInteresting = false;
if (
(originParticle.pdgCode() == 310 && v0BuilderOpts.mc_addGeneratedK0Short.value > 0) ||
(originParticle.pdgCode() == 3122 && v0BuilderOpts.mc_addGeneratedLambda.value > 0) ||
(originParticle.pdgCode() == -3122 && v0BuilderOpts.mc_addGeneratedAntiLambda.value > 0) ||
(originParticle.pdgCode() == 22 && v0BuilderOpts.mc_addGeneratedGamma.value > 0)) {
trackIsInteresting = true;
}
if (!trackIsInteresting) {
continue; // skip this, it's uninteresting
}
currentTrackEntry.globalId = static_cast<int>(track.globalIndex());
currentTrackEntry.originId = originParticleIndex;
currentTrackEntry.mcCollisionId = originParticle.mcCollisionId();
currentTrackEntry.pdgCode = originParticle.pdgCode();
// now separate according to particle species
if (track.sign() < 0) {
negativeTrackArray.push_back(currentTrackEntry);