forked from AliceO2Group/O2Physics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtableReader_withAssoc.cxx
More file actions
3936 lines (3549 loc) · 222 KB
/
tableReader_withAssoc.cxx
File metadata and controls
3936 lines (3549 loc) · 222 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.
//
// Contact: iarsene@cern.ch, i.c.arsene@fys.uio.no
// Configurable workflow for running several DQ or other PWG analyses
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <numeric>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <string>
#include <memory>
#include <utility>
#include <TH1F.h>
#include <TH3F.h>
#include <THashList.h>
#include <TList.h>
#include <TString.h>
#include <TObjString.h>
#include "CCDB/BasicCCDBManager.h"
#include "DataFormatsParameters/GRPObject.h"
#include "Framework/AnalysisHelpers.h"
#include "Framework/Configurable.h"
#include "Framework/OutputObjHeader.h"
#include "Framework/runDataProcessing.h"
#include "Framework/AnalysisTask.h"
#include "Framework/AnalysisDataModel.h"
#include "Framework/ASoAHelpers.h"
#include "PWGDQ/DataModel/ReducedInfoTables.h"
#include "PWGDQ/Core/VarManager.h"
#include "PWGDQ/Core/HistogramManager.h"
#include "PWGDQ/Core/MixingHandler.h"
#include "PWGDQ/Core/AnalysisCut.h"
#include "PWGDQ/Core/AnalysisCompositeCut.h"
#include "PWGDQ/Core/HistogramsLibrary.h"
#include "PWGDQ/Core/CutsLibrary.h"
#include "PWGDQ/Core/MixingLibrary.h"
#include "DataFormatsParameters/GRPMagField.h"
#include "Field/MagneticField.h"
#include "TGeoGlobalMagField.h"
#include "DetectorsBase/Propagator.h"
#include "DetectorsBase/GeometryManager.h"
#include "Common/Core/TableHelper.h"
#include "ITSMFTBase/DPLAlpideParam.h"
#include "Common/CCDB/EventSelectionParams.h"
using std::cout;
using std::endl;
using std::string;
using namespace o2;
using namespace o2::framework;
using namespace o2::framework::expressions;
using namespace o2::aod;
// Some definitions
namespace o2::aod
{
namespace dqanalysisflags
{
DECLARE_SOA_COLUMN(MixingHash, mixingHash, int); //! Hash used in event mixing
DECLARE_SOA_BITMAP_COLUMN(IsEventSelected, isEventSelected, 8); //! Event decision
DECLARE_SOA_BITMAP_COLUMN(IsBarrelSelected, isBarrelSelected, 32); //! Barrel track decisions
DECLARE_SOA_COLUMN(BarrelAmbiguityInBunch, barrelAmbiguityInBunch, int8_t); //! Barrel track in-bunch ambiguity
DECLARE_SOA_COLUMN(BarrelAmbiguityOutOfBunch, barrelAmbiguityOutOfBunch, int8_t); //! Barrel track out of bunch ambiguity
DECLARE_SOA_BITMAP_COLUMN(IsMuonSelected, isMuonSelected, 32); //! Muon track decisions (joinable to ReducedMuonsAssoc)
DECLARE_SOA_COLUMN(MuonAmbiguityInBunch, muonAmbiguityInBunch, int8_t); //! Muon track in-bunch ambiguity
DECLARE_SOA_COLUMN(MuonAmbiguityOutOfBunch, muonAmbiguityOutOfBunch, int8_t); //! Muon track out of bunch ambiguity
DECLARE_SOA_BITMAP_COLUMN(IsBarrelSelectedPrefilter, isBarrelSelectedPrefilter, 32); //! Barrel prefilter decisions (joinable to ReducedTracksAssoc)
// Bcandidate columns for ML analysis of B->Jpsi+K
DECLARE_SOA_COLUMN(massBcandidate, MBcandidate, float);
DECLARE_SOA_COLUMN(MassDileptonCandidate, massDileptonCandidate, float);
DECLARE_SOA_COLUMN(deltamassBcandidate, deltaMBcandidate, float);
DECLARE_SOA_COLUMN(pTBcandidate, PtBcandidate, float);
DECLARE_SOA_COLUMN(EtaBcandidate, etaBcandidate, float);
DECLARE_SOA_COLUMN(LxyBcandidate, lxyBcandidate, float);
DECLARE_SOA_COLUMN(LxyzBcandidate, lxyzBcandidate, float);
DECLARE_SOA_COLUMN(LzBcandidate, lzBcandidate, float);
DECLARE_SOA_COLUMN(TauxyBcandidate, tauxyBcandidate, float);
DECLARE_SOA_COLUMN(TauzBcandidate, tauzBcandidate, float);
DECLARE_SOA_COLUMN(CosPBcandidate, cosPBcandidate, float);
DECLARE_SOA_COLUMN(Chi2Bcandidate, chi2Bcandidate, float);
DECLARE_SOA_COLUMN(PINassoc, pINassoc, float);
DECLARE_SOA_COLUMN(Etaassoc, etaassoc, float);
DECLARE_SOA_COLUMN(Ptpair, ptpair, float);
DECLARE_SOA_COLUMN(Etapair, etapair, float);
DECLARE_SOA_COLUMN(PINleg1, pINleg1, float);
DECLARE_SOA_COLUMN(Etaleg1, etaleg1, float);
DECLARE_SOA_COLUMN(PINleg2, pINleg2, float);
DECLARE_SOA_COLUMN(Etaleg2, etaleg2, float);
DECLARE_SOA_COLUMN(TPCnsigmaKaassoc, tpcnsigmaKaassoc, float);
DECLARE_SOA_COLUMN(TPCnsigmaPiassoc, tpcnsigmaPiassoc, float);
DECLARE_SOA_COLUMN(TPCnsigmaPrassoc, tpcnsigmaPrassoc, float);
DECLARE_SOA_COLUMN(TOFnsigmaKaassoc, tofnsigmaKaassoc, float);
DECLARE_SOA_COLUMN(TPCnsigmaElleg1, tpcnsigmaElleg1, float);
DECLARE_SOA_COLUMN(TPCnsigmaPileg1, tpcnsigmaPileg1, float);
DECLARE_SOA_COLUMN(TPCnsigmaPrleg1, tpcnsigmaPrleg1, float);
DECLARE_SOA_COLUMN(TPCnsigmaElleg2, tpcnsigmaElleg2, float);
DECLARE_SOA_COLUMN(TPCnsigmaPileg2, tpcnsigmaPileg2, float);
DECLARE_SOA_COLUMN(TPCnsigmaPrleg2, tpcnsigmaPrleg2, float);
DECLARE_SOA_COLUMN(DCAXYassoc, dcaXYassoc, float);
DECLARE_SOA_COLUMN(DCAZassoc, dcaZassoc, float);
DECLARE_SOA_COLUMN(DCAXYleg1, dcaXYleg1, float);
DECLARE_SOA_COLUMN(DCAZleg1, dcaZleg1, float);
DECLARE_SOA_COLUMN(DCAXYleg2, dcaXYleg2, float);
DECLARE_SOA_COLUMN(DCAZleg2, dcaZleg2, float);
DECLARE_SOA_COLUMN(ITSClusterMapassoc, itsClusterMapassoc, uint8_t);
DECLARE_SOA_COLUMN(ITSClusterMapleg1, itsClusterMapleg1, uint8_t);
DECLARE_SOA_COLUMN(ITSClusterMapleg2, itsClusterMapleg2, uint8_t);
DECLARE_SOA_COLUMN(ITSChi2assoc, itsChi2assoc, float);
DECLARE_SOA_COLUMN(ITSChi2leg1, itsChi2leg1, float);
DECLARE_SOA_COLUMN(ITSChi2leg2, itsChi2leg2, float);
DECLARE_SOA_COLUMN(TPCNclsassoc, tpcNclsassoc, float);
DECLARE_SOA_COLUMN(TPCNclsleg1, tpcNclsleg1, float);
DECLARE_SOA_COLUMN(TPCNclsleg2, tpcNclsleg2, float);
DECLARE_SOA_COLUMN(TPCChi2assoc, tpcChi2assoc, float);
DECLARE_SOA_COLUMN(TPCChi2leg1, tpcChi2leg1, float);
DECLARE_SOA_COLUMN(TPCChi2leg2, tpcChi2leg2, float);
DECLARE_SOA_BITMAP_COLUMN(IsJpsiFromBSelected, isJpsiFromBSelected, 32);
// Candidate columns for prompt-non-prompt JPsi separation
DECLARE_SOA_COLUMN(Massee, massJPsi2ee, float);
DECLARE_SOA_COLUMN(Ptee, ptJPsi2ee, float);
DECLARE_SOA_COLUMN(Lxyee, lxyJPsi2ee, float);
DECLARE_SOA_COLUMN(LxyeePoleMass, lxyJPsi2eePoleMass, float);
DECLARE_SOA_COLUMN(Lzee, lzJPsi2ee, float);
DECLARE_SOA_COLUMN(AmbiguousInBunchPairs, AmbiguousJpsiPairsInBunch, bool);
DECLARE_SOA_COLUMN(AmbiguousOutOfBunchPairs, AmbiguousJpsiPairsOutOfBunch, bool);
} // namespace dqanalysisflags
DECLARE_SOA_TABLE(EventCuts, "AOD", "DQANAEVCUTSA", dqanalysisflags::IsEventSelected); //! joinable to ReducedEvents
DECLARE_SOA_TABLE(MixingHashes, "AOD", "DQANAMIXHASHA", dqanalysisflags::MixingHash); //! joinable to ReducedEvents
DECLARE_SOA_TABLE(BarrelTrackCuts, "AOD", "DQANATRKCUTSA", dqanalysisflags::IsBarrelSelected); //! joinable to ReducedTracksAssoc
DECLARE_SOA_TABLE(BarrelAmbiguities, "AOD", "DQBARRELAMBA", dqanalysisflags::BarrelAmbiguityInBunch, dqanalysisflags::BarrelAmbiguityOutOfBunch); //! joinable to ReducedBarrelTracks
DECLARE_SOA_TABLE(MuonTrackCuts, "AOD", "DQANAMUONCUTSA", dqanalysisflags::IsMuonSelected); //! joinable to ReducedMuonsAssoc
DECLARE_SOA_TABLE(MuonAmbiguities, "AOD", "DQMUONAMBA", dqanalysisflags::MuonAmbiguityInBunch, dqanalysisflags::MuonAmbiguityOutOfBunch); //! joinable to ReducedMuonTracks
DECLARE_SOA_TABLE(Prefilter, "AOD", "DQPREFILTERA", dqanalysisflags::IsBarrelSelectedPrefilter); //! joinable to ReducedTracksAssoc
DECLARE_SOA_TABLE(BmesonCandidates, "AOD", "DQBMESONSA",
dqanalysisflags::massBcandidate, dqanalysisflags::MassDileptonCandidate, dqanalysisflags::deltamassBcandidate, dqanalysisflags::pTBcandidate, dqanalysisflags::EtaBcandidate,
dqanalysisflags::LxyBcandidate, dqanalysisflags::LxyzBcandidate, dqanalysisflags::LzBcandidate,
dqanalysisflags::TauxyBcandidate, dqanalysisflags::TauzBcandidate, dqanalysisflags::CosPBcandidate, dqanalysisflags::Chi2Bcandidate,
dqanalysisflags::PINassoc, dqanalysisflags::Etaassoc, dqanalysisflags::Ptpair, dqanalysisflags::Etapair,
dqanalysisflags::PINleg1, dqanalysisflags::Etaleg1, dqanalysisflags::PINleg2, dqanalysisflags::Etaleg2,
dqanalysisflags::TPCnsigmaKaassoc, dqanalysisflags::TPCnsigmaPiassoc, dqanalysisflags::TPCnsigmaPrassoc, dqanalysisflags::TOFnsigmaKaassoc,
dqanalysisflags::TPCnsigmaElleg1, dqanalysisflags::TPCnsigmaPileg1, dqanalysisflags::TPCnsigmaPrleg1,
dqanalysisflags::TPCnsigmaElleg2, dqanalysisflags::TPCnsigmaPileg2, dqanalysisflags::TPCnsigmaPrleg2,
dqanalysisflags::DCAXYassoc, dqanalysisflags::DCAZassoc, dqanalysisflags::DCAXYleg1, dqanalysisflags::DCAZleg1, dqanalysisflags::DCAXYleg2, dqanalysisflags::DCAZleg2,
dqanalysisflags::ITSClusterMapassoc, dqanalysisflags::ITSClusterMapleg1, dqanalysisflags::ITSClusterMapleg2,
dqanalysisflags::ITSChi2assoc, dqanalysisflags::ITSChi2leg1, dqanalysisflags::ITSChi2leg2,
dqanalysisflags::TPCNclsassoc, dqanalysisflags::TPCNclsleg1, dqanalysisflags::TPCNclsleg2,
dqanalysisflags::TPCChi2assoc, dqanalysisflags::TPCChi2leg1, dqanalysisflags::TPCChi2leg2,
dqanalysisflags::IsJpsiFromBSelected, dqanalysisflags::IsBarrelSelected);
DECLARE_SOA_TABLE(JPsieeCandidates, "AOD", "DQPSEUDOPROPER", dqanalysisflags::Massee, dqanalysisflags::Ptee, dqanalysisflags::Lxyee, dqanalysisflags::LxyeePoleMass, dqanalysisflags::Lzee, dqanalysisflags::AmbiguousInBunchPairs, dqanalysisflags::AmbiguousOutOfBunchPairs);
} // namespace o2::aod
// Declarations of various short names
using MyEvents = soa::Join<aod::ReducedEvents, aod::ReducedEventsExtended>;
using MyEventsMultExtra = soa::Join<aod::ReducedEvents, aod::ReducedEventsExtended, aod::ReducedEventsMultPV, aod::ReducedEventsMultAll>;
using MyEventsMultExtraQVector = soa::Join<aod::ReducedEvents, aod::ReducedEventsExtended, aod::ReducedEventsMultPV, aod::ReducedEventsMultAll, aod::ReducedEventsQvectorCentr, aod::ReducedEventsQvectorCentrExtra>;
using MyEventsZdc = soa::Join<aod::ReducedEvents, aod::ReducedEventsExtended, aod::ReducedZdcs>;
using MyEventsMultExtraZdc = soa::Join<aod::ReducedEvents, aod::ReducedEventsExtended, aod::ReducedEventsMultPV, aod::ReducedEventsMultAll, aod::ReducedZdcs>;
using MyEventsSelected = soa::Join<aod::ReducedEvents, aod::ReducedEventsExtended, aod::EventCuts>;
using MyEventsMultExtraSelected = soa::Join<aod::ReducedEvents, aod::ReducedEventsExtended, aod::ReducedEventsMultPV, aod::ReducedEventsMultAll, aod::EventCuts>;
using MyEventsVtxCovSelectedMultExtra = soa::Join<aod::ReducedEvents, aod::ReducedEventsExtended, aod::ReducedEventsVtxCov, aod::EventCuts, aod::ReducedEventsMultPV, aod::ReducedEventsMultAll>;
using MyEventsHashSelected = soa::Join<aod::ReducedEvents, aod::ReducedEventsExtended, aod::EventCuts, aod::MixingHashes>;
using MyEventsVtxCov = soa::Join<aod::ReducedEvents, aod::ReducedEventsExtended, aod::ReducedEventsVtxCov>;
using MyEventsVtxCovSelected = soa::Join<aod::ReducedEvents, aod::ReducedEventsExtended, aod::ReducedEventsVtxCov, aod::EventCuts>;
using MyEventsVtxCovSelectedQvector = soa::Join<aod::ReducedEvents, aod::ReducedEventsExtended, aod::ReducedEventsMultPV, aod::ReducedEventsMultAll, aod::ReducedEventsVtxCov, aod::EventCuts, aod::ReducedEventsQvectorCentr, aod::ReducedEventsQvectorCentrExtra>;
using MyEventsVtxCovSelectedQvectorWithHash = soa::Join<aod::ReducedEvents, aod::ReducedEventsExtended, aod::ReducedEventsMultPV, aod::ReducedEventsMultAll, aod::ReducedEventsVtxCov, aod::EventCuts, aod::ReducedEventsQvectorCentr, aod::ReducedEventsQvectorCentrExtra, aod::MixingHashes>;
using MyEventsVtxCovZdcSelected = soa::Join<aod::ReducedEvents, aod::ReducedEventsExtended, aod::ReducedEventsVtxCov, aod::ReducedZdcs, aod::EventCuts>;
using MyEventsVtxCovZdcSelectedMultExtra = soa::Join<aod::ReducedEvents, aod::ReducedEventsExtended, aod::ReducedEventsVtxCov, aod::ReducedZdcs, aod::EventCuts, aod::ReducedEventsMultPV, aod::ReducedEventsMultAll>;
using MyEventsQvector = soa::Join<aod::ReducedEvents, aod::ReducedEventsExtended, aod::ReducedEventsQvector>;
using MyEventsHashSelectedQvector = soa::Join<aod::ReducedEvents, aod::ReducedEventsExtended, aod::EventCuts, aod::MixingHashes, aod::ReducedEventsQvector>;
using MyEventsQvectorCentr = soa::Join<aod::ReducedEvents, aod::ReducedEventsExtended, aod::ReducedEventsQvectorCentr, aod::ReducedEventsMultPV, aod::ReducedEventsMultAll>;
using MyEventsQvectorCentrSelected = soa::Join<aod::ReducedEvents, aod::ReducedEventsExtended, aod::ReducedEventsQvectorCentr, aod::ReducedEventsMultPV, aod::ReducedEventsMultAll, aod::EventCuts>;
using MyBarrelTracks = soa::Join<aod::ReducedTracks, aod::ReducedTracksBarrel, aod::ReducedTracksBarrelPID>;
using MyBarrelTracksWithAmbiguities = soa::Join<aod::ReducedTracks, aod::ReducedTracksBarrel, aod::ReducedTracksBarrelPID, aod::BarrelAmbiguities>;
using MyBarrelTracksWithCov = soa::Join<aod::ReducedTracks, aod::ReducedTracksBarrel, aod::ReducedTracksBarrelCov, aod::ReducedTracksBarrelPID>;
using MyBarrelTracksWithCovWithAmbiguities = soa::Join<aod::ReducedTracks, aod::ReducedTracksBarrel, aod::ReducedTracksBarrelCov, aod::ReducedTracksBarrelPID, aod::BarrelAmbiguities>;
using MyBarrelTracksWithCovWithAmbiguitiesWithColl = soa::Join<aod::ReducedTracks, aod::ReducedTracksBarrel, aod::ReducedTracksBarrelCov, aod::ReducedTracksBarrelPID, aod::BarrelAmbiguities, aod::ReducedTracksBarrelInfo>;
using MyDielectronCandidates = soa::Join<aod::Dielectrons, aod::DielectronsExtra>;
using MyDitrackCandidates = soa::Join<aod::Ditracks, aod::DitracksExtra>;
using MyDimuonCandidates = soa::Join<aod::Dimuons, aod::DimuonsExtra>;
using MyMuonTracks = soa::Join<aod::ReducedMuons, aod::ReducedMuonsExtra>;
using MyMuonTracksWithCov = soa::Join<aod::ReducedMuons, aod::ReducedMuonsExtra, aod::ReducedMuonsCov>;
using MyMuonTracksWithCovWithAmbiguities = soa::Join<aod::ReducedMuons, aod::ReducedMuonsExtra, aod::ReducedMuonsCov, aod::MuonAmbiguities>;
using MyMuonTracksSelectedWithColl = soa::Join<aod::ReducedMuons, aod::ReducedMuonsExtra, aod::ReducedMuonsInfo, aod::MuonTrackCuts>;
// bit maps used for the Fill functions of the VarManager
constexpr static uint32_t gkEventFillMap = VarManager::ObjTypes::ReducedEvent | VarManager::ObjTypes::ReducedEventExtended;
constexpr static uint32_t gkEventFillMapWithZdc = VarManager::ObjTypes::ReducedEvent | VarManager::ObjTypes::ReducedEventExtended | VarManager::ReducedZdc;
constexpr static uint32_t gkEventFillMapWithCov = VarManager::ObjTypes::ReducedEvent | VarManager::ObjTypes::ReducedEventExtended | VarManager::ObjTypes::ReducedEventVtxCov;
constexpr static uint32_t gkEventFillMapWithCovFlow = VarManager::ObjTypes::ReducedEvent | VarManager::ObjTypes::ReducedEventExtended | VarManager::ObjTypes::ReducedEventVtxCov | VarManager::ObjTypes::ReducedEventQvector;
constexpr static uint32_t gkEventFillMapWithCovZdc = VarManager::ObjTypes::ReducedEvent | VarManager::ObjTypes::ReducedEventExtended | VarManager::ObjTypes::ReducedEventVtxCov | VarManager::ReducedZdc;
constexpr static uint32_t gkEventFillMapWithMultExtra = VarManager::ObjTypes::ReducedEvent | VarManager::ObjTypes::ReducedEventExtended | VarManager::ObjTypes::ReducedEventMultExtra;
// New fillmap
constexpr static uint32_t gkEventFillMapWithMultExtraWithQVector = VarManager::ObjTypes::ReducedEvent | VarManager::ObjTypes::ReducedEventExtended | VarManager::ObjTypes::ReducedEventMultExtra | VarManager::ObjTypes::CollisionQvect;
constexpr static uint32_t gkEventFillMapWithMultExtraZdc = VarManager::ObjTypes::ReducedEvent | VarManager::ObjTypes::ReducedEventExtended | VarManager::ObjTypes::ReducedEventMultExtra | VarManager::ReducedZdc;
constexpr static uint32_t gkEventFillMapWithCovZdcMultExtra = VarManager::ObjTypes::ReducedEvent | VarManager::ObjTypes::ReducedEventExtended | VarManager::ObjTypes::ReducedEventVtxCov | VarManager::ReducedZdc | VarManager::ReducedEventMultExtra;
constexpr static uint32_t gkEventFillMapWithQvectorCentr = VarManager::ObjTypes::ReducedEvent | VarManager::ObjTypes::ReducedEventExtended | VarManager::ObjTypes::CollisionQvect | VarManager::ObjTypes::ReducedEventMultExtra;
// constexpr static uint32_t gkEventFillMapWithQvector = VarManager::ObjTypes::ReducedEvent | VarManager::ObjTypes::ReducedEventExtended | VarManager::ObjTypes::ReducedEventQvector;
// constexpr static uint32_t gkEventFillMapWithCovQvector = VarManager::ObjTypes::ReducedEvent | VarManager::ObjTypes::ReducedEventExtended | VarManager::ObjTypes::ReducedEventVtxCov | VarManager::ObjTypes::ReducedEventQvector;
constexpr static uint32_t gkTrackFillMap = VarManager::ObjTypes::ReducedTrack | VarManager::ObjTypes::ReducedTrackBarrel | VarManager::ObjTypes::ReducedTrackBarrelPID;
constexpr static uint32_t gkTrackFillMapWithCov = VarManager::ObjTypes::ReducedTrack | VarManager::ObjTypes::ReducedTrackBarrel | VarManager::ObjTypes::ReducedTrackBarrelCov | VarManager::ObjTypes::ReducedTrackBarrelPID;
constexpr static uint32_t gkTrackFillMapWithCovWithColl = VarManager::ObjTypes::ReducedTrack | VarManager::ObjTypes::ReducedTrackBarrel | VarManager::ObjTypes::ReducedTrackBarrelCov | VarManager::ObjTypes::ReducedTrackBarrelPID | VarManager::ObjTypes::ReducedTrackCollInfo;
// constexpr static uint32_t gkMuonFillMap = VarManager::ObjTypes::ReducedMuon | VarManager::ObjTypes::ReducedMuonExtra;
constexpr static uint32_t gkMuonFillMapWithCov = VarManager::ObjTypes::ReducedMuon | VarManager::ObjTypes::ReducedMuonExtra | VarManager::ObjTypes::ReducedMuonCov;
// constexpr static uint32_t gkMuonFillMapWithColl = VarManager::ObjTypes::ReducedMuon | VarManager::ObjTypes::ReducedMuonExtra | VarManager::ObjTypes::ReducedMuonCollInfo;
constexpr static int pairTypeEE = VarManager::kDecayToEE;
constexpr static int pairTypeMuMu = VarManager::kDecayToMuMu;
// constexpr static int pairTypeEMu = VarManager::kElectronMuon;
// Global function used to define needed histogram classes
void DefineHistograms(HistogramManager* histMan, TString histClasses, const char* histGroups); // defines histograms for all tasks
template <typename TMap>
void PrintBitMap(TMap map, int nbits)
{
for (int i = 0; i < nbits; i++) {
cout << ((map & (TMap(1) << i)) > 0 ? "1" : "0");
}
}
// Analysis task that produces event decisions (analysis cut, in bunch pileup and split collision check) and the Hash table used in event mixing
struct AnalysisEventSelection {
Produces<aod::EventCuts> eventSel;
Produces<aod::MixingHashes> hash;
OutputObj<THashList> fOutputList{"output"};
// TODO: Provide the mixing variables and binning directly via configurables (e.g. vectors of float)
Configurable<string> fConfigMixingVariables{"cfgMixingVars", "", "Mixing configs separated by a comma, default no mixing"};
Configurable<string> fConfigEventCuts{"cfgEventCuts", "eventStandard", "Event selection"};
Configurable<string> fConfigEventCutsJSON{"cfgEventCutsJSON", "", "Additional event cuts specified in JSON format"};
Configurable<std::string> fConfigAddEventHistogram{"cfgAddEventHistogram", "", "Comma separated list of histograms"};
Configurable<std::string> fConfigAddJSONHistograms{"cfgAddJSONHistograms", "", "Add event histograms defined via JSON formatting (see HistogramsLibrary)"};
Configurable<bool> fConfigQA{"cfgQA", true, "If true, QA histograms will be created and filled"};
Configurable<int> fConfigITSROFrameStartBorderMargin{"cfgITSROFrameStartBorderMargin", -1, "Number of bcs at the start of ITS RO Frame border. Take from CCDB if -1"};
Configurable<int> fConfigITSROFrameEndBorderMargin{"cfgITSROFrameEndBorderMargin", -1, "Number of bcs at the end of ITS RO Frame border. Take from CCDB if -1"};
Configurable<float> fConfigSplitCollisionsDeltaZ{"cfgSplitCollisionsDeltaZ", 1.0, "maximum delta-z (cm) between two collisions to consider them as split candidates"};
Configurable<unsigned int> fConfigSplitCollisionsDeltaBC{"cfgSplitCollisionsDeltaBC", 100, "maximum delta-BC between two collisions to consider them as split candidates; do not apply if value is negative"};
Configurable<bool> fConfigCheckSplitCollisions{"cfgCheckSplitCollisions", false, "If true, run the split collision check and fill histograms"};
Configurable<bool> fConfigRunZorro{"cfgRunZorro", false, "Enable event selection with zorro [WARNING: under debug, do not enable!]"};
Configurable<string> fConfigCcdbUrl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
Configurable<int64_t> fConfigNoLaterThan{"ccdb-no-later-than", std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(), "latest acceptable timestamp of creation for the object"};
HistogramManager* fHistMan = nullptr;
MixingHandler* fMixHandler = nullptr;
AnalysisCompositeCut* fEventCut;
Service<o2::ccdb::BasicCCDBManager> fCCDB;
o2::ccdb::CcdbApi fCCDBApi;
std::map<int64_t, bool> fSelMap; // key: reduced event global index, value: event selection decision
std::map<uint64_t, std::vector<int64_t>> fBCCollMap; // key: global BC, value: vector of reduced event global indices
int fCurrentRun;
void init(o2::framework::InitContext& context)
{
LOG(info) << "Starting initialization of AnalysisEventSelection (idstoreh)";
bool isAnyProcessEnabled = context.mOptions.get<bool>("processSkimmed") || context.mOptions.get<bool>("processSkimmedWithZdc") || context.mOptions.get<bool>("processSkimmedWithMultExtra") || context.mOptions.get<bool>("processSkimmedWithMultExtraZdc") || context.mOptions.get<bool>("processSkimmedWithQvectorCentr");
bool isDummyEnabled = context.mOptions.get<bool>("processDummy");
if (isDummyEnabled) {
if (isAnyProcessEnabled) {
LOG(fatal) << "You have enabled both the dummy process and at least one normal process function! Check your config!";
}
return;
}
if (!isAnyProcessEnabled) {
return;
}
VarManager::SetDefaultVarNames();
fEventCut = new AnalysisCompositeCut(true);
TString eventCutStr = fConfigEventCuts.value;
if (eventCutStr != "") {
AnalysisCut* cut = dqcuts::GetAnalysisCut(eventCutStr.Data());
if (cut != nullptr) {
fEventCut->AddCut(cut);
}
}
// Additional cuts via JSON
TString eventCutJSONStr = fConfigEventCutsJSON.value;
if (eventCutJSONStr != "") {
std::vector<AnalysisCut*> jsonCuts = dqcuts::GetCutsFromJSON(eventCutJSONStr.Data());
for (auto& cutIt : jsonCuts) {
fEventCut->AddCut(cutIt);
}
}
VarManager::SetUseVars(AnalysisCut::fgUsedVars); // provide the list of required variables so that VarManager knows what to fill
if (fConfigQA) {
fHistMan = new HistogramManager("analysisHistos", "", VarManager::kNVars);
fHistMan->SetUseDefaultVariableNames(kTRUE);
fHistMan->SetDefaultVarNames(VarManager::fgVariableNames, VarManager::fgVariableUnits);
DefineHistograms(fHistMan, "Event_BeforeCuts;Event_AfterCuts;", fConfigAddEventHistogram.value.data());
if (fConfigCheckSplitCollisions) {
DefineHistograms(fHistMan, "SameBunchCorrelations;OutOfBunchCorrelations;", "");
}
// Additional histograms via JSON
dqhistograms::AddHistogramsFromJSON(fHistMan, fConfigAddJSONHistograms.value.c_str());
VarManager::SetUseVars(fHistMan->GetUsedVars());
fOutputList.setObject(fHistMan->GetMainHistogramList());
}
TString mixVarsString = fConfigMixingVariables.value;
std::unique_ptr<TObjArray> objArray(mixVarsString.Tokenize(","));
if (objArray->GetEntries() > 0) {
fMixHandler = new MixingHandler("mixingHandler", "mixing handler");
fMixHandler->Init();
for (int iVar = 0; iVar < objArray->GetEntries(); ++iVar) {
dqmixing::SetUpMixing(fMixHandler, objArray->At(iVar)->GetName());
}
}
fCurrentRun = -1;
fCCDB->setURL(fConfigCcdbUrl.value);
fCCDB->setCaching(true);
fCCDB->setLocalObjectValidityChecking();
fCCDB->setCreatedNotAfter(fConfigNoLaterThan.value);
fCCDBApi.init(fConfigCcdbUrl.value);
LOG(info) << "Initialization of AnalysisEventSelection finished (idstoreh)";
}
template <uint32_t TEventFillMap, typename TEvents>
void runEventSelection(TEvents const& events)
{
if (events.size() > 0 && events.begin().runNumber() != fCurrentRun) {
std::map<string, string> metadataRCT, header;
header = fCCDBApi.retrieveHeaders(Form("RCT/Info/RunInformation/%i", events.begin().runNumber()), metadataRCT, -1);
uint64_t sor = std::atol(header["SOR"].c_str());
uint64_t eor = std::atol(header["EOR"].c_str());
VarManager::SetSORandEOR(sor, eor);
auto alppar = fCCDB->getForTimeStamp<o2::itsmft::DPLAlpideParam<0>>("ITS/Config/AlpideParam", events.begin().timestamp());
EventSelectionParams* par = fCCDB->getForTimeStamp<EventSelectionParams>("EventSelection/EventSelectionParams", events.begin().timestamp());
int itsROFrameStartBorderMargin = fConfigITSROFrameStartBorderMargin < 0 ? par->fITSROFrameStartBorderMargin : fConfigITSROFrameStartBorderMargin;
int itsROFrameEndBorderMargin = fConfigITSROFrameEndBorderMargin < 0 ? par->fITSROFrameEndBorderMargin : fConfigITSROFrameEndBorderMargin;
VarManager::SetITSROFBorderselection(alppar->roFrameBiasInBC, alppar->roFrameLengthInBC, itsROFrameStartBorderMargin, itsROFrameEndBorderMargin);
fCurrentRun = events.begin().runNumber();
}
fSelMap.clear();
fBCCollMap.clear();
for (auto& event : events) {
// Reset the fValues array and fill event observables
VarManager::ResetValues(0, VarManager::kNEventWiseVariables);
VarManager::FillEvent<TEventFillMap>(event);
bool decision = false;
// Fill histograms in the class Event, before cuts
if (fConfigQA) {
fHistMan->FillHistClass("Event_BeforeCuts", VarManager::fgValues);
}
// Apply event cuts and fill histograms after selection
if (fEventCut->IsSelected(VarManager::fgValues)) {
if (fConfigRunZorro) {
if (event.tag_bit(56)) { // This is the bit used for the software trigger event selections [TO BE DONE: find a more clear way to use it]
if (fConfigQA) {
fHistMan->FillHistClass("Event_AfterCuts", VarManager::fgValues);
}
decision = true;
}
} else {
if (fConfigQA) {
fHistMan->FillHistClass("Event_AfterCuts", VarManager::fgValues);
}
decision = true;
}
}
// fill the event decision map
fSelMap[event.globalIndex()] = decision;
// Fill the BC map of events
if (fBCCollMap.find(event.globalBC()) == fBCCollMap.end()) {
std::vector<int64_t> evIndices = {event.globalIndex()};
fBCCollMap[event.globalBC()] = evIndices;
} else {
auto& evIndices = fBCCollMap[event.globalBC()];
evIndices.push_back(event.globalIndex());
}
// create the mixing hash and publish it into the hash table
if (fMixHandler != nullptr) {
int hh = fMixHandler->FindEventCategory(VarManager::fgValues);
hash(hh);
}
}
}
template <uint32_t TEventFillMap, typename TEvents>
void publishSelections(TEvents const& events)
{
// Create a map for collisions which are candidate of being split
// key: event global index, value: whether pileup event is a possible splitting
std::map<int64_t, bool> collisionSplittingMap;
if (fConfigCheckSplitCollisions) {
// Reset the fValues array and fill event observables
VarManager::ResetValues(0, VarManager::kNEventWiseVariables);
// loop over the BC map, get the collision vectors and make in-bunch and out of bunch 2-event correlations
for (auto bc1It = fBCCollMap.begin(); bc1It != fBCCollMap.end(); ++bc1It) {
uint64_t bc1 = bc1It->first;
auto bc1Events = bc1It->second;
// same bunch event correlations, if more than 1 collisions in this bunch
if (bc1Events.size() > 1) {
for (auto ev1It = bc1Events.begin(); ev1It != bc1Events.end(); ++ev1It) {
auto ev1 = events.rawIteratorAt(*ev1It);
for (auto ev2It = std::next(ev1It); ev2It != bc1Events.end(); ++ev2It) {
auto ev2 = events.rawIteratorAt(*ev2It);
// compute 2-event quantities and mark the candidate split collisions
VarManager::FillTwoEvents(ev1, ev2);
if (TMath::Abs(VarManager::fgValues[VarManager::kTwoEvDeltaZ]) < fConfigSplitCollisionsDeltaZ) { // this is a possible collision split
collisionSplittingMap[*ev1It] = true;
collisionSplittingMap[*ev2It] = true;
}
if (fConfigQA) {
fHistMan->FillHistClass("SameBunchCorrelations", VarManager::fgValues);
}
} // end second event loop
} // end first event loop
} // end if BC1 events > 1
// loop over the following BCs in the TF
for (auto bc2It = std::next(bc1It); bc2It != fBCCollMap.end(); ++bc2It) {
uint64_t bc2 = bc2It->first;
if ((bc2 > bc1 ? bc2 - bc1 : bc1 - bc2) > fConfigSplitCollisionsDeltaBC) {
break;
}
auto bc2Events = bc2It->second;
// loop over events in the first BC
for (auto ev1It : bc1Events) {
auto ev1 = events.rawIteratorAt(ev1It);
// loop over events in the second BC
for (auto ev2It : bc2Events) {
auto ev2 = events.rawIteratorAt(ev2It);
// compute 2-event quantities and mark the candidate split collisions
VarManager::FillTwoEvents(ev1, ev2);
if (TMath::Abs(VarManager::fgValues[VarManager::kTwoEvDeltaZ]) < fConfigSplitCollisionsDeltaZ) { // this is a possible collision split
collisionSplittingMap[ev1It] = true;
collisionSplittingMap[ev2It] = true;
}
if (fConfigQA) {
fHistMan->FillHistClass("OutOfBunchCorrelations", VarManager::fgValues);
}
}
}
}
}
}
// publish the table
uint8_t evSel = static_cast<uint8_t>(0);
for (auto& event : events) {
evSel = 0;
if (fSelMap[event.globalIndex()]) { // event passed the user cuts
evSel |= (static_cast<uint8_t>(1) << 0);
}
std::vector<int64_t> sameBunchEvents = fBCCollMap[event.globalBC()];
if (sameBunchEvents.size() > 1) { // event with in-bunch pileup
evSel |= (static_cast<uint8_t>(1) << 1);
}
if (collisionSplittingMap.find(event.globalIndex()) != collisionSplittingMap.end()) { // event with possible fake in-bunch pileup (collision splitting)
evSel |= (static_cast<uint8_t>(1) << 2);
}
eventSel(evSel);
}
}
void processSkimmed(MyEvents const& events)
{
runEventSelection<gkEventFillMap>(events);
publishSelections<gkEventFillMap>(events);
}
void processSkimmedWithZdc(MyEventsZdc const& events)
{
runEventSelection<gkEventFillMapWithZdc>(events);
publishSelections<gkEventFillMapWithZdc>(events);
}
void processSkimmedWithMultExtra(MyEventsMultExtra const& events)
{
runEventSelection<gkEventFillMapWithMultExtra>(events);
publishSelections<gkEventFillMapWithMultExtra>(events);
}
void processSkimmedWithMultExtraZdc(MyEventsMultExtraZdc const& events)
{
runEventSelection<gkEventFillMapWithMultExtraZdc>(events);
publishSelections<gkEventFillMapWithMultExtraZdc>(events);
}
void processSkimmedWithQvectorCentr(MyEventsQvectorCentr const& events)
{
runEventSelection<gkEventFillMapWithQvectorCentr>(events);
publishSelections<gkEventFillMapWithQvectorCentr>(events);
}
void processDummy(MyEvents&)
{
// do nothing
}
PROCESS_SWITCH(AnalysisEventSelection, processSkimmed, "Run event selection on DQ skimmed events", false);
PROCESS_SWITCH(AnalysisEventSelection, processSkimmedWithZdc, "Run event selection on DQ skimmed events, with ZDC", false);
PROCESS_SWITCH(AnalysisEventSelection, processSkimmedWithMultExtra, "Run event selection on DQ skimmed events, with mult extra", false);
PROCESS_SWITCH(AnalysisEventSelection, processSkimmedWithMultExtraZdc, "Run event selection on DQ skimmed events, with mult extra and ZDC", false);
PROCESS_SWITCH(AnalysisEventSelection, processSkimmedWithQvectorCentr, "Run event selection on DQ skimmed events, with Q-vector", false);
PROCESS_SWITCH(AnalysisEventSelection, processDummy, "Dummy function", false);
};
// Produces a table with barrel track decisions (joinable to the ReducedTracksAssociations)
// Here one should add all the track cuts needed through the workflow (e.g. cuts for same-even pairing, electron prefiltering, track for dilepton-track correlations)
struct AnalysisTrackSelection {
Produces<aod::BarrelTrackCuts> trackSel;
Produces<aod::BarrelAmbiguities> trackAmbiguities;
OutputObj<THashList> fOutputList{"output"};
Configurable<string> fConfigCuts{"cfgTrackCuts", "jpsiO2MCdebugCuts2", "Comma separated list of barrel track cuts"};
Configurable<std::string> fConfigCutsJSON{"cfgBarrelTrackCutsJSON", "", "Additional list of barrel track cuts in JSON format"};
Configurable<string> fConfigAddTrackHistogram{"cfgAddTrackHistogram", "", "Comma separated list of histograms"};
Configurable<std::string> fConfigAddJSONHistograms{"cfgAddJSONHistograms", "", "Histograms in JSON format"};
Configurable<bool> fConfigQA{"cfgQA", false, "If true, fill QA histograms"};
Configurable<bool> fConfigPublishAmbiguity{"cfgPublishAmbiguity", true, "If true, publish ambiguity table and fill QA histograms"};
Configurable<string> fConfigCcdbUrl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
Configurable<string> fConfigCcdbPathTPC{"ccdb-path-tpc", "Users/z/zhxiong/TPCPID/PostCalib", "base path to the ccdb object"};
Configurable<int64_t> fConfigNoLaterThan{"ccdb-no-later-than", std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(), "latest acceptable timestamp of creation for the object"};
Configurable<bool> fConfigComputeTPCpostCalib{"cfgTPCpostCalib", false, "If true, compute TPC post-calibrated n-sigmas"};
Configurable<std::string> grpmagPath{"grpmagPath", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object"};
// Track related options
Configurable<bool> fPropTrack{"cfgPropTrack", true, "Propgate tracks to associated collision to recalculate DCA and momentum vector"};
Service<o2::ccdb::BasicCCDBManager> fCCDB;
o2::ccdb::CcdbApi fCCDBApi;
HistogramManager* fHistMan;
std::vector<AnalysisCompositeCut*> fTrackCuts;
int fCurrentRun; // current run kept to detect run changes and trigger loading params from CCDB
std::map<int64_t, std::vector<int64_t>> fNAssocsInBunch; // key: track global index, value: vector of global index for events associated in-bunch (events that have in-bunch pileup or splitting)
std::map<int64_t, std::vector<int64_t>> fNAssocsOutOfBunch; // key: track global index, value: vector of global index for events associated out-of-bunch (events that have no in-bunch pileup)
void init(o2::framework::InitContext& context)
{
LOG(info) << "Starting initialization of AnalysisTrackSelection (idstoreh)";
if (context.mOptions.get<bool>("processDummy")) {
return;
}
VarManager::SetDefaultVarNames();
fCurrentRun = 0;
TString cutNamesStr = fConfigCuts.value;
if (!cutNamesStr.IsNull()) {
std::unique_ptr<TObjArray> objArray(cutNamesStr.Tokenize(","));
for (int icut = 0; icut < objArray->GetEntries(); ++icut) {
fTrackCuts.push_back(dqcuts::GetCompositeCut(objArray->At(icut)->GetName()));
}
}
// Extra cuts via JSON
TString addTrackCutsStr = fConfigCutsJSON.value;
if (addTrackCutsStr != "") {
std::vector<AnalysisCut*> addTrackCuts = dqcuts::GetCutsFromJSON(addTrackCutsStr.Data());
for (auto& t : addTrackCuts) {
fTrackCuts.push_back(reinterpret_cast<AnalysisCompositeCut*>(t));
}
}
VarManager::SetUseVars(AnalysisCut::fgUsedVars); // provide the list of required variables so that VarManager knows what to fill
if (fConfigQA) {
fHistMan = new HistogramManager("analysisHistos", "aa", VarManager::kNVars);
fHistMan->SetUseDefaultVariableNames(kTRUE);
fHistMan->SetDefaultVarNames(VarManager::fgVariableNames, VarManager::fgVariableUnits);
// set one histogram directory for each defined track cut
TString histDirNames = "TrackBarrel_BeforeCuts;";
for (auto& cut : fTrackCuts) {
histDirNames += Form("TrackBarrel_%s;", cut->GetName());
}
if (fConfigPublishAmbiguity) {
histDirNames += "TrackBarrel_AmbiguityInBunch;TrackBarrel_AmbiguityOutOfBunch;";
}
DefineHistograms(fHistMan, histDirNames.Data(), fConfigAddTrackHistogram.value.data()); // define all histograms
dqhistograms::AddHistogramsFromJSON(fHistMan, fConfigAddJSONHistograms.value.c_str()); // ad-hoc histograms via JSON
VarManager::SetUseVars(fHistMan->GetUsedVars()); // provide the list of required variables so that VarManager knows what to fill
fOutputList.setObject(fHistMan->GetMainHistogramList());
}
fCCDB->setURL(fConfigCcdbUrl.value);
fCCDB->setCaching(true);
fCCDB->setLocalObjectValidityChecking();
fCCDB->setCreatedNotAfter(fConfigNoLaterThan.value);
fCCDBApi.init(fConfigCcdbUrl.value);
LOG(info) << "Initialization of AnalysisTrackSelection finished (idstoreh)";
}
template <uint32_t TEventFillMap, uint32_t TTrackFillMap, typename TEvents, typename TTracks>
void runTrackSelection(ReducedTracksAssoc const& assocs, TEvents const& events, TTracks const& tracks)
{
fNAssocsInBunch.clear();
fNAssocsOutOfBunch.clear();
if (events.size() > 0 && fCurrentRun != events.begin().runNumber()) {
if (fConfigComputeTPCpostCalib) {
auto calibList = fCCDB->getForTimeStamp<TList>(fConfigCcdbPathTPC.value, events.begin().timestamp());
VarManager::SetCalibrationObject(VarManager::kTPCElectronMean, calibList->FindObject("mean_map_electron"));
VarManager::SetCalibrationObject(VarManager::kTPCElectronSigma, calibList->FindObject("sigma_map_electron"));
VarManager::SetCalibrationObject(VarManager::kTPCPionMean, calibList->FindObject("mean_map_pion"));
VarManager::SetCalibrationObject(VarManager::kTPCPionSigma, calibList->FindObject("sigma_map_pion"));
VarManager::SetCalibrationObject(VarManager::kTPCProtonMean, calibList->FindObject("mean_map_proton"));
VarManager::SetCalibrationObject(VarManager::kTPCProtonSigma, calibList->FindObject("sigma_map_proton"));
}
o2::parameters::GRPMagField* grpmag = fCCDB->getForTimeStamp<o2::parameters::GRPMagField>(grpmagPath, events.begin().timestamp());
if (grpmag != nullptr) {
VarManager::SetMagneticField(grpmag->getNominalL3Field());
} else {
LOGF(fatal, "GRP object is not available in CCDB at timestamp=%llu", events.begin().timestamp());
}
std::map<string, string> metadataRCT, header;
header = fCCDBApi.retrieveHeaders(Form("RCT/Info/RunInformation/%i", events.begin().runNumber()), metadataRCT, -1);
uint64_t sor = std::atol(header["SOR"].c_str());
uint64_t eor = std::atol(header["EOR"].c_str());
VarManager::SetSORandEOR(sor, eor);
fCurrentRun = events.begin().runNumber();
}
trackSel.reserve(assocs.size());
trackAmbiguities.reserve(tracks.size());
uint32_t filterMap = static_cast<uint32_t>(0);
int iCut = 0;
for (auto& assoc : assocs) {
// if the event from this association is not selected, reject also the association
auto event = assoc.template reducedevent_as<TEvents>();
if (!event.isEventSelected_bit(0)) {
trackSel(0);
continue;
}
VarManager::ResetValues(0, VarManager::kNBarrelTrackVariables);
// fill event information which might be needed in histograms/cuts that combine track and event properties
VarManager::FillEvent<TEventFillMap>(event);
auto track = assoc.template reducedtrack_as<TTracks>();
filterMap = static_cast<uint32_t>(0);
VarManager::FillTrack<TTrackFillMap>(track);
// compute quantities which depend on the associated collision, such as DCA
if (fPropTrack) {
VarManager::FillTrackCollision<TTrackFillMap>(track, event);
}
if (fConfigQA) {
fHistMan->FillHistClass("TrackBarrel_BeforeCuts", VarManager::fgValues);
}
iCut = 0;
for (auto cut = fTrackCuts.begin(); cut != fTrackCuts.end(); cut++, iCut++) {
if ((*cut)->IsSelected(VarManager::fgValues)) {
filterMap |= (static_cast<uint32_t>(1) << iCut);
if (fConfigQA) {
fHistMan->FillHistClass(Form("TrackBarrel_%s", (*cut)->GetName()), VarManager::fgValues);
}
}
} // end loop over cuts
// publish the decisions
trackSel(filterMap);
// count the number of associations per track
if (fConfigPublishAmbiguity && filterMap > 0) {
// for this track, count the number of associated collisions with in-bunch pileup and out of bunch associations
if (event.isEventSelected_bit(1)) {
if (fNAssocsInBunch.find(track.globalIndex()) == fNAssocsInBunch.end()) {
std::vector<int64_t> evVector = {event.globalIndex()};
fNAssocsInBunch[track.globalIndex()] = evVector;
} else {
auto& evVector = fNAssocsInBunch[track.globalIndex()];
evVector.push_back(event.globalIndex());
}
} else {
if (fNAssocsOutOfBunch.find(track.globalIndex()) == fNAssocsOutOfBunch.end()) {
std::vector<int64_t> evVector = {event.globalIndex()};
fNAssocsOutOfBunch[track.globalIndex()] = evVector;
} else {
auto& evVector = fNAssocsOutOfBunch[track.globalIndex()];
evVector.push_back(event.globalIndex());
}
}
}
} // end loop over associations
if (fConfigPublishAmbiguity) {
// QA the collision-track associations
if (fConfigQA) {
for (auto& [trackIdx, evIndices] : fNAssocsInBunch) {
if (evIndices.size() == 1) {
continue;
}
auto track = tracks.rawIteratorAt(trackIdx);
VarManager::ResetValues(0, VarManager::kNBarrelTrackVariables);
VarManager::FillTrack<TTrackFillMap>(track);
// Exceptionally, set the VarManager ambiguity number here, to be used in histograms
VarManager::fgValues[VarManager::kBarrelNAssocsInBunch] = static_cast<float>(evIndices.size());
fHistMan->FillHistClass("TrackBarrel_AmbiguityInBunch", VarManager::fgValues);
} // end loop over in-bunch ambiguous tracks
for (auto& [trackIdx, evIndices] : fNAssocsOutOfBunch) {
if (evIndices.size() == 1) {
continue;
}
auto track = tracks.rawIteratorAt(trackIdx);
VarManager::ResetValues(0, VarManager::kNBarrelTrackVariables);
VarManager::FillTrack<TTrackFillMap>(track);
// Exceptionally, set the VarManager ambiguity number here
VarManager::fgValues[VarManager::kBarrelNAssocsOutOfBunch] = static_cast<float>(evIndices.size());
fHistMan->FillHistClass("TrackBarrel_AmbiguityOutOfBunch", VarManager::fgValues);
} // end loop over out-of-bunch ambiguous tracks
}
// publish the ambiguity table
for (auto& track : tracks) {
int8_t nInBunch = 0;
if (fNAssocsInBunch.find(track.globalIndex()) != fNAssocsInBunch.end()) {
nInBunch = fNAssocsInBunch[track.globalIndex()].size();
}
int8_t nOutOfBunch = 0;
if (fNAssocsOutOfBunch.find(track.globalIndex()) != fNAssocsOutOfBunch.end()) {
nOutOfBunch = fNAssocsOutOfBunch[track.globalIndex()].size();
}
trackAmbiguities(nInBunch, nOutOfBunch);
}
} // end if (fConfigPublishAmbiguity)
} // end runTrackSelection()
void processSkimmed(ReducedTracksAssoc const& assocs, MyEventsSelected const& events, MyBarrelTracks const& tracks)
{
runTrackSelection<gkEventFillMap, gkTrackFillMap>(assocs, events, tracks);
}
void processSkimmedWithMultExtra(ReducedTracksAssoc const& assocs, MyEventsMultExtraSelected const& events, MyBarrelTracks const& tracks)
{
runTrackSelection<gkEventFillMapWithMultExtra, gkTrackFillMap>(assocs, events, tracks);
}
void processSkimmedWithCov(ReducedTracksAssoc const& assocs, MyEventsVtxCovSelected const& events, MyBarrelTracksWithCov const& tracks)
{
runTrackSelection<gkEventFillMapWithCov, gkTrackFillMapWithCov>(assocs, events, tracks);
}
void processDummy(MyEvents&)
{
// do nothing
}
PROCESS_SWITCH(AnalysisTrackSelection, processSkimmed, "Run barrel track selection on DQ skimmed track associations", false);
PROCESS_SWITCH(AnalysisTrackSelection, processSkimmedWithMultExtra, "Run barrel track selection on DQ skimmed track associations, with extra multiplicity tables", false);
PROCESS_SWITCH(AnalysisTrackSelection, processSkimmedWithCov, "Run barrel track selection on DQ skimmed tracks w/ cov matrix associations", false);
PROCESS_SWITCH(AnalysisTrackSelection, processDummy, "Dummy function", false);
};
// Produces a table with muon decisions (joinable to the ReducedMuonsAssociations)
// Here one should add all the track cuts needed through the workflow (e.g. cuts for same-event pairing, track for dilepton-track correlations)
struct AnalysisMuonSelection {
Produces<aod::MuonTrackCuts> muonSel;
Produces<aod::MuonAmbiguities> muonAmbiguities;
OutputObj<THashList> fOutputList{"output"};
Configurable<string> fConfigCuts{"cfgMuonCuts", "muonQualityCuts", "Comma separated list of muon cuts"};
Configurable<std::string> fConfigCutsJSON{"cfgMuonCutsJSON", "", "Additional list of muon cuts in JSON format"};
Configurable<bool> fConfigQA{"cfgQA", false, "If true, fill QA histograms"};
Configurable<std::string> fConfigAddMuonHistogram{"cfgAddMuonHistogram", "", "Comma separated list of histograms"};
Configurable<std::string> fConfigAddJSONHistograms{"cfgAddJSONHistograms", "", "Histograms in JSON format"};
Configurable<bool> fConfigPublishAmbiguity{"cfgPublishAmbiguity", true, "If true, publish ambiguity table and fill QA histograms"};
Configurable<string> fConfigCcdbUrl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
Configurable<std::string> grpmagPath{"grpmagPath", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object"};
Configurable<int64_t> fConfigNoLaterThan{"ccdb-no-later-than", std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(), "latest acceptable timestamp of creation for the object"};
Configurable<std::string> fConfigGeoPath{"geoPath", "GLO/Config/GeometryAligned", "Path of the geometry file"};
Service<o2::ccdb::BasicCCDBManager> fCCDB;
HistogramManager* fHistMan;
std::vector<AnalysisCompositeCut*> fMuonCuts;
int fCurrentRun; // current run kept to detect run changes and trigger loading params from CCDB
std::map<int64_t, std::vector<int64_t>> fNAssocsInBunch; // key: muon global index, value: vector of global index for events associated in-bunch (events that have in-bunch pileup or splitting)
std::map<int64_t, std::vector<int64_t>> fNAssocsOutOfBunch; // key: muon global index, value: vector of global index for events associated out-of-bunch (events that have no in-bunch pileup)
void init(o2::framework::InitContext& context)
{
LOG(info) << "Starting initialization of AnalysisMuonSelection (idstoreh)";
if (context.mOptions.get<bool>("processDummy")) {
return;
}
VarManager::SetDefaultVarNames();
fCurrentRun = 0;
TString cutNamesStr = fConfigCuts.value;
if (!cutNamesStr.IsNull()) {
std::unique_ptr<TObjArray> objArray(cutNamesStr.Tokenize(","));
for (int icut = 0; icut < objArray->GetEntries(); ++icut) {
fMuonCuts.push_back(dqcuts::GetCompositeCut(objArray->At(icut)->GetName()));
}
}
// extra cuts from JSON
TString addCutsStr = fConfigCutsJSON.value;
if (addCutsStr != "") {
std::vector<AnalysisCut*> addCuts = dqcuts::GetCutsFromJSON(addCutsStr.Data());
for (auto& t : addCuts) {
fMuonCuts.push_back(reinterpret_cast<AnalysisCompositeCut*>(t));
}
}
VarManager::SetUseVars(AnalysisCut::fgUsedVars); // provide the list of required variables so that VarManager knows what to fill
if (fConfigQA) {
fHistMan = new HistogramManager("analysisHistos", "aa", VarManager::kNVars);
fHistMan->SetUseDefaultVariableNames(kTRUE);
fHistMan->SetDefaultVarNames(VarManager::fgVariableNames, VarManager::fgVariableUnits);
// set one histogram directory for each defined track cut
TString histDirNames = "TrackMuon_BeforeCuts;";
for (auto& cut : fMuonCuts) {
histDirNames += Form("TrackMuon_%s;", cut->GetName());
}
if (fConfigPublishAmbiguity) {
histDirNames += "TrackMuon_AmbiguityInBunch;TrackMuon_AmbiguityOutOfBunch;";
}
DefineHistograms(fHistMan, histDirNames.Data(), fConfigAddMuonHistogram.value.data()); // define all histograms
dqhistograms::AddHistogramsFromJSON(fHistMan, fConfigAddJSONHistograms.value.c_str()); // ad-hoc histograms via JSON
VarManager::SetUseVars(fHistMan->GetUsedVars()); // provide the list of required variables so that VarManager knows what to fill
fOutputList.setObject(fHistMan->GetMainHistogramList());
}
fCCDB->setURL(fConfigCcdbUrl.value);
fCCDB->setCaching(true);
fCCDB->setLocalObjectValidityChecking();
fCCDB->setCreatedNotAfter(fConfigNoLaterThan.value);
if (!o2::base::GeometryManager::isGeometryLoaded()) {
fCCDB->get<TGeoManager>(fConfigGeoPath);
}
LOG(info) << "Initialization of AnalysisMuonSelection finished (idstoreh)";
}
template <uint32_t TEventFillMap, uint32_t TMuonFillMap, typename TEvents, typename TMuons>
void runMuonSelection(ReducedMuonsAssoc const& assocs, TEvents const& events, TMuons const& muons)
{
fNAssocsInBunch.clear();
fNAssocsOutOfBunch.clear();
if (events.size() > 0 && fCurrentRun != events.begin().runNumber()) {
o2::parameters::GRPMagField* grpmag = fCCDB->getForTimeStamp<o2::parameters::GRPMagField>(grpmagPath, events.begin().timestamp());
if (grpmag != nullptr) {
o2::base::Propagator::initFieldFromGRP(grpmag);
VarManager::SetMagneticField(grpmag->getNominalL3Field());
} else {
LOGF(fatal, "GRP object is not available in CCDB at timestamp=%llu", events.begin().timestamp());
}
fCurrentRun = events.begin().runNumber();
}
muonSel.reserve(assocs.size());
muonAmbiguities.reserve(muons.size());
uint32_t filterMap = static_cast<uint32_t>(0);
int iCut = 0;
for (auto& assoc : assocs) {
auto event = assoc.template reducedevent_as<TEvents>();
if (!event.isEventSelected_bit(0)) {
muonSel(0);
continue;
}
VarManager::ResetValues(0, VarManager::kNMuonTrackVariables);
// fill event information which might be needed in histograms/cuts that combine track and event properties
VarManager::FillEvent<TEventFillMap>(event);
auto track = assoc.template reducedmuon_as<TMuons>();
filterMap = static_cast<uint32_t>(0);
VarManager::FillTrack<TMuonFillMap>(track);
if (fConfigQA) {
fHistMan->FillHistClass("TrackMuon_BeforeCuts", VarManager::fgValues);
}
iCut = 0;
for (auto cut = fMuonCuts.begin(); cut != fMuonCuts.end(); cut++, iCut++) {
if ((*cut)->IsSelected(VarManager::fgValues)) {
filterMap |= (static_cast<uint32_t>(1) << iCut);
if (fConfigQA) {
fHistMan->FillHistClass(Form("TrackMuon_%s", (*cut)->GetName()), VarManager::fgValues);
}
}
} // end loop over cuts
muonSel(filterMap);
// count the number of associations per track
if (fConfigPublishAmbiguity && filterMap > 0) {
if (event.isEventSelected_bit(1)) {
if (fNAssocsInBunch.find(track.globalIndex()) == fNAssocsInBunch.end()) {
std::vector<int64_t> evVector = {event.globalIndex()};
fNAssocsInBunch[track.globalIndex()] = evVector;
} else {
auto& evVector = fNAssocsInBunch[track.globalIndex()];
evVector.push_back(event.globalIndex());
}
} else {
if (fNAssocsOutOfBunch.find(track.globalIndex()) == fNAssocsOutOfBunch.end()) {
std::vector<int64_t> evVector = {event.globalIndex()};
fNAssocsOutOfBunch[track.globalIndex()] = evVector;
} else {
auto& evVector = fNAssocsOutOfBunch[track.globalIndex()];
evVector.push_back(event.globalIndex());
}
}
} // end if (fConfigPublishAmbiguity)
} // end loop over assocs
if (fConfigPublishAmbiguity) {
// QA the collision-track associations
if (fConfigQA) {
for (auto& [trackIdx, evIndices] : fNAssocsInBunch) {
if (evIndices.size() == 1) {
continue;
}
auto track = muons.rawIteratorAt(trackIdx);
VarManager::ResetValues(0, VarManager::kNMuonTrackVariables);
VarManager::FillTrack<TMuonFillMap>(track);
VarManager::fgValues[VarManager::kMuonNAssocsInBunch] = static_cast<float>(evIndices.size());
fHistMan->FillHistClass("TrackMuon_AmbiguityInBunch", VarManager::fgValues);
} // end loop over in-bunch ambiguous tracks
for (auto& [trackIdx, evIndices] : fNAssocsOutOfBunch) {
if (evIndices.size() == 1) {
continue;
}
auto track = muons.rawIteratorAt(trackIdx);
VarManager::ResetValues(0, VarManager::kNMuonTrackVariables);
VarManager::FillTrack<TMuonFillMap>(track);
VarManager::fgValues[VarManager::kMuonNAssocsOutOfBunch] = static_cast<float>(evIndices.size());
fHistMan->FillHistClass("TrackMuon_AmbiguityOutOfBunch", VarManager::fgValues);
} // end loop over out-of-bunch ambiguous tracks
}
// publish the ambiguity table
for (auto& track : muons) {
int8_t nInBunch = 0;
if (fNAssocsInBunch.find(track.globalIndex()) != fNAssocsInBunch.end()) {
nInBunch = fNAssocsInBunch[track.globalIndex()].size();
}
int8_t nOutOfBunch = 0;
if (fNAssocsOutOfBunch.find(track.globalIndex()) != fNAssocsOutOfBunch.end()) {
nOutOfBunch = fNAssocsOutOfBunch[track.globalIndex()].size();
}
muonAmbiguities(nInBunch, nOutOfBunch);
}
}
}
void processSkimmed(ReducedMuonsAssoc const& assocs, MyEventsVtxCovSelected const& events, MyMuonTracksWithCov const& muons)
{
runMuonSelection<gkEventFillMapWithCov, gkMuonFillMapWithCov>(assocs, events, muons);
}
void processDummy(MyEvents&)
{
// do nothing
}
PROCESS_SWITCH(AnalysisMuonSelection, processSkimmed, "Run muon selection on DQ skimmed muons", false);
PROCESS_SWITCH(AnalysisMuonSelection, processDummy, "Dummy function", false);
};
// Run the prefilter selection (e.g. electron prefiltering for photon conversions)
// This takes uses a sample of tracks selected with loose cuts (fConfigPrefilterTrackCut) and combines them