forked from AliceO2Group/O2Physics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtableMakerMC_withAssoc.cxx
More file actions
1483 lines (1341 loc) · 78 KB
/
tableMakerMC_withAssoc.cxx
File metadata and controls
1483 lines (1341 loc) · 78 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
//
// Analysis task for skimming MC AODs
// Similar to tableMaker.cxx. The written skimmed data model includes, besides the reconstructed data tables, a skimmed MC stack.
// The skimmed MC stack includes the MC truth particles corresponding to the list of user specified MC signals (see MCsignal.h)
// and the MC truth particles corresponding to the reconstructed tracks selected by the specified track cuts on reconstructed data.
#include <cstdint>
#include <iostream>
#include <map>
#include <string>
#include <memory>
#include <vector>
#include <utility>
#include <unordered_map>
#include "TList.h"
#include "Framework/AnalysisTask.h"
#include "Framework/AnalysisDataModel.h"
#include "Framework/ASoAHelpers.h"
#include "Framework/ASoA.h"
#include "Framework/DataTypes.h"
#include "Framework/runDataProcessing.h"
#include "Common/DataModel/Multiplicity.h"
#include "Common/DataModel/EventSelection.h"
#include "Common/DataModel/Centrality.h"
#include "Common/CCDB/TriggerAliases.h"
#include "PWGDQ/DataModel/ReducedInfoTables.h"
#include "PWGDQ/Core/VarManager.h"
#include "PWGDQ/Core/HistogramManager.h"
#include "PWGDQ/Core/AnalysisCut.h"
#include "PWGDQ/Core/AnalysisCompositeCut.h"
#include "PWGDQ/Core/HistogramsLibrary.h"
#include "PWGDQ/Core/CutsLibrary.h"
#include "PWGDQ/Core/MCSignal.h"
#include "PWGDQ/Core/MCSignalLibrary.h"
#include "Common/DataModel/PIDResponse.h"
#include "Common/DataModel/TrackSelectionTables.h"
#include "Common/DataModel/FwdTrackReAlignTables.h"
#include "Common/DataModel/CollisionAssociationTables.h"
#include "DataFormatsParameters/GRPMagField.h"
#include "DataFormatsParameters/GRPObject.h"
#include "Field/MagneticField.h"
#include "TGeoGlobalMagField.h"
#include "DetectorsBase/Propagator.h"
#include "DetectorsBase/GeometryManager.h"
#include "CCDB/BasicCCDBManager.h"
using std::cout;
using std::endl;
using namespace o2;
using namespace o2::framework;
using namespace o2::framework::expressions;
using namespace o2::aod;
// Declare Joins used in the various process functions
using MyBarrelTracks = soa::Join<aod::Tracks, aod::TracksExtra, aod::TracksDCA, aod::TrackSelection,
aod::pidTPCFullEl, aod::pidTPCFullMu, aod::pidTPCFullPi,
aod::pidTPCFullKa, aod::pidTPCFullPr,
aod::pidTOFFullEl, aod::pidTOFFullMu, aod::pidTOFFullPi,
aod::pidTOFFullKa, aod::pidTOFFullPr, aod::pidTOFbeta,
aod::McTrackLabels>;
using MyBarrelTracksWithDalitzBits = soa::Join<aod::Tracks, aod::TracksExtra, aod::TracksDCA, aod::TrackSelection,
aod::pidTPCFullEl, aod::pidTPCFullMu, aod::pidTPCFullPi,
aod::pidTPCFullKa, aod::pidTPCFullPr,
aod::pidTOFFullEl, aod::pidTOFFullMu, aod::pidTOFFullPi,
aod::pidTOFFullKa, aod::pidTOFFullPr, aod::pidTOFbeta,
aod::McTrackLabels, aod::DalitzBits>;
using MyBarrelTracksWithCov = soa::Join<aod::Tracks, aod::TracksExtra, aod::TracksCov, aod::TracksDCA, aod::TrackSelection,
aod::pidTPCFullEl, aod::pidTPCFullMu, aod::pidTPCFullPi,
aod::pidTPCFullKa, aod::pidTPCFullPr,
aod::pidTOFFullEl, aod::pidTOFFullMu, aod::pidTOFFullPi,
aod::pidTOFFullKa, aod::pidTOFFullPr, aod::pidTOFbeta,
aod::McTrackLabels>;
using MyMuons = soa::Join<aod::FwdTracks, aod::McFwdTrackLabels, aod::FwdTracksDCA>;
using MyMuonsWithCov = soa::Join<aod::FwdTracks, aod::FwdTracksCov, aod::McFwdTrackLabels, aod::FwdTracksDCA>;
using MyMuonsRealignWithCov = soa::Join<aod::FwdTracksReAlign, aod::FwdTrksCovReAlign, aod::McFwdTrackLabels, aod::FwdTracksDCA>;
using MyEvents = soa::Join<aod::Collisions, aod::EvSels, aod::McCollisionLabels>;
using MyEventsWithMults = soa::Join<aod::Collisions, aod::EvSels, aod::Mults, aod::MultsExtra, aod::McCollisionLabels>;
using MyEventsWithMultsAndRapidityGapFilter = soa::Join<aod::Collisions, aod::EvSels, aod::Mults, aod::MultsExtra, aod::McCollisionLabels, aod::DQRapidityGapFilter>;
using MyEventsWithCent = soa::Join<aod::Collisions, aod::EvSels, aod::CentFT0Cs, aod::CentFT0As, aod::CentFT0Ms, aod::McCollisionLabels>;
using MyEventsWithCentAndMults = soa::Join<aod::Collisions, aod::EvSels, aod::CentFT0Cs, aod::CentFT0As, aod::CentFT0Ms, aod::Mults, aod::MultsExtra, aod::McCollisionLabels>;
using MFTTrackLabeled = soa::Join<o2::aod::MFTTracks, aod::McMFTTrackLabels>;
// Declare bit maps containing information on the table joins content (used as argument in templated functions)
constexpr static uint32_t gkEventFillMap = VarManager::ObjTypes::BC | VarManager::ObjTypes::Collision;
constexpr static uint32_t gkEventFillMapWithMults = VarManager::ObjTypes::BC | VarManager::ObjTypes::Collision | VarManager::ObjTypes::CollisionMult | VarManager::ObjTypes::CollisionMultExtra;
// constexpr static uint32_t gkEventFillMapWithCent = VarManager::ObjTypes::BC | VarManager::ObjTypes::Collision | VarManager::ObjTypes::CollisionCent;
constexpr static uint32_t gkEventFillMapWithCentAndMults = VarManager::ObjTypes::BC | VarManager::ObjTypes::Collision | VarManager::ObjTypes::CollisionCent | VarManager::CollisionMult | VarManager::CollisionMultExtra;
constexpr static uint32_t gkEventFillMapWithMultsRapidityGapFilter = VarManager::ObjTypes::BC | VarManager::ObjTypes::Collision | VarManager::ObjTypes::CollisionMult | VarManager::ObjTypes::CollisionMultExtra | VarManager::ObjTypes::RapidityGapFilter;
// constexpr static uint32_t gkEventMCFillMap = VarManager::ObjTypes::CollisionMC;
// constexpr static uint32_t gkTrackFillMap = VarManager::ObjTypes::Track | VarManager::ObjTypes::TrackExtra | VarManager::ObjTypes::TrackDCA | VarManager::ObjTypes::TrackSelection | VarManager::ObjTypes::TrackPID;
constexpr static uint32_t gkTrackFillMapWithCov = VarManager::ObjTypes::Track | VarManager::ObjTypes::TrackExtra | VarManager::ObjTypes::TrackDCA | VarManager::ObjTypes::TrackSelection | VarManager::ObjTypes::TrackCov | VarManager::ObjTypes::TrackPID;
// constexpr static uint32_t gkTrackFillMapWithDalitzBits = gkTrackFillMap | VarManager::ObjTypes::DalitzBits;
// constexpr static uint32_t gkMuonFillMap = VarManager::ObjTypes::Muon;
constexpr static uint32_t gkMuonFillMapWithCov = VarManager::ObjTypes::Muon | VarManager::ObjTypes::MuonCov;
constexpr static uint32_t gkMuonRealignFillMapWithCov = VarManager::ObjTypes::MuonRealign | VarManager::ObjTypes::MuonCovRealign;
// constexpr static uint32_t gkMuonFillMapWithAmbi = VarManager::ObjTypes::Muon | VarManager::ObjTypes::AmbiMuon;
// constexpr static uint32_t gkMuonFillMapWithCovAmbi = VarManager::ObjTypes::Muon | VarManager::ObjTypes::MuonCov | VarManager::ObjTypes::AmbiMuon;
// constexpr static uint32_t gkTrackFillMapWithAmbi = VarManager::ObjTypes::Track | VarManager::ObjTypes::AmbiTrack;
constexpr static uint32_t gkMFTFillMap = VarManager::ObjTypes::TrackMFT;
constexpr static uint32_t gkMFTCovFillMap = VarManager::ObjTypes::TrackMFT | VarManager::ObjTypes::MFTCov;
template <typename TMap>
void PrintBitMap(TMap map, int nbits)
{
for (int i = 0; i < nbits; i++) {
cout << ((map & (TMap(1) << i)) > 0 ? "1" : "0");
}
}
struct TableMakerMC {
Produces<ReducedMCEvents> eventMC;
Produces<ReducedMCTracks> trackMC;
Produces<ReducedEvents> event;
Produces<ReducedEventsExtended> eventExtended;
Produces<ReducedEventsVtxCov> eventVtxCov;
Produces<ReducedEventsInfo> eventInfo;
Produces<ReducedEventsMultPV> multPV;
Produces<ReducedEventsMultAll> multAll;
Produces<ReducedMCEventLabels> eventMClabels;
Produces<ReducedTracksBarrelInfo> trackBarrelInfo;
Produces<ReducedTracks> trackBasic;
Produces<ReducedTracksBarrel> trackBarrel;
Produces<ReducedTracksBarrelCov> trackBarrelCov;
Produces<ReducedTracksBarrelPID> trackBarrelPID;
Produces<ReducedTracksAssoc> trackBarrelAssoc;
Produces<ReducedTracksBarrelLabels> trackBarrelLabels;
Produces<ReducedMuons> muonBasic;
Produces<ReducedMuonsExtra> muonExtra;
Produces<ReducedMuonsCov> muonCov;
Produces<ReducedMuonsAssoc> muonAssoc;
Produces<ReducedMuonsLabels> muonLabels; // TODO: enable this once we have fwdtrack labels
Produces<ReducedMFTs> mftTrack;
Produces<ReducedMFTsExtra> mftTrackExtra;
Produces<ReducedMFTAssoc> mftAssoc;
Produces<ReducedMFTLabels> mftLabels;
OutputObj<THashList> fOutputList{"output"};
OutputObj<TList> fStatsList{"Statistics"}; //! skimming statistics
HistogramManager* fHistMan;
Configurable<bool> fIsRun2{"cfgIsRun2", false, "Whether we analyze Run-2 or Run-3 data"};
// Event and track AnalysisCut configurables
struct : ConfigurableGroup {
Configurable<std::string> fConfigEventCuts{"cfgEventCuts", "eventStandard", "Event selection"};
Configurable<std::string> fConfigTrackCuts{"cfgBarrelTrackCuts", "jpsiPID1", "barrel track cut"};
Configurable<std::string> fConfigMuonCuts{"cfgMuonCuts", "muonQualityCuts", "Comma separated list of muon cuts"};
Configurable<std::string> fConfigEventCutsJSON{"cfgEventCutsJSON", "", "Additional event selection in JSON format"};
Configurable<std::string> fConfigTrackCutsJSON{"cfgBarrelTrackCutsJSON", "", "Additional list of barrel track cuts in JSON format"};
Configurable<std::string> fConfigMuonCutsJSON{"cfgMuonCutsJSON", "", "Additional list of muon cuts in JSON format"};
} fConfigCuts;
// MC signals to be skimmed
Configurable<std::string> fConfigMCSignals{"cfgMCsignals", "", "Comma separated list of MC signals"};
Configurable<std::string> fConfigMCSignalsJSON{"cfgMCsignalsJSON", "", "Additional list of MC signals via JSON"};
// Steer QA output
struct : ConfigurableGroup {
Configurable<bool> fConfigQA{"cfgQA", false, "If true, fill QA histograms"};
Configurable<bool> fConfigDetailedQA{"cfgDetailedQA", false, "If true, include more QA histograms (BeforeCuts classes)"};
Configurable<std::string> fConfigAddEventHistogram{"cfgAddEventHistogram", "", "Comma separated list of histograms"};
Configurable<std::string> fConfigAddTrackHistogram{"cfgAddTrackHistogram", "", "Comma separated list of histograms"};
Configurable<std::string> fConfigAddMuonHistogram{"cfgAddMuonHistogram", "", "Comma separated list of histograms"};
Configurable<std::string> fConfigAddMCTruthHistogram{"cfgAddMCTruthHistogram", "", "Comma separated list of histograms"};
Configurable<std::string> fConfigAddJSONHistograms{"cfgAddJSONHistograms", "", "Histograms in JSON format"};
} fConfigHistOutput;
// Selections to be applied as Filter on the Track and FwdTrack
/*Configurable<float> fConfigBarrelTrackMaxAbsEta{"cfgBarrelMaxAbsEta", 0.9f, "Eta absolute value cut for tracks in the barrel"};
Configurable<float> fConfigBarrelTrackMinPt{"cfgBarrelMinPt", 0.5f, "Minimum pt for tracks in the barrel"};
Configurable<float> fConfigBarrelMinTPCncls{"cfgBarrelMinTPCncls", 50.0f, "Minimum TPC cls for tracks in the barrel"};
Configurable<float> fConfigBarrelMaxTPCchi2{"cfgBarrelMaxTPCchi2", 10.0f, "Maximum TPC chi2/ndf for tracks in the barrel"};
Configurable<float> fConfigBarrelMaxITSchi2{"cfgBarrelMaxITSchi2", 36.0f, "Maximum ITS chi2/ndf for tracks in the barrel"};
Configurable<float> fConfigMuonPtLow{"cfgMuonLowPt", 1.0f, "Low pt cut for muons"};
*/
// CCDB connection configurables
struct : ConfigurableGroup {
Configurable<std::string> fConfigCcdbUrl{"ccdb-url", "http://alice-ccdb.cern.ch", "url of the ccdb repository"};
Configurable<std::string> fGeoPath{"geoPath", "GLO/Config/GeometryAligned", "Path of the geometry file"};
Configurable<std::string> fGrpMagPath{"grpmagPath", "GLO/Config/GRPMagField", "CCDB path of the GRPMagField object"};
Configurable<std::string> fGrpMagPathRun2{"grpmagPathRun2", "GLO/GRP/GRP", "CCDB path of the GRPObject (Usage for Run 2)"};
} fConfigCCDB;
struct : ConfigurableGroup {
// Track related options
Configurable<bool> fPropTrack{"cfgPropTrack", true, "Propagate tracks to primary vertex"};
// Muon related options
Configurable<bool> fPropMuon{"cfgPropMuon", true, "Propagate muon tracks through absorber (do not use if applying pairing)"};
Configurable<bool> fRefitGlobalMuon{"cfgRefitGlobalMuon", true, "Correct global muon parameters"};
Configurable<bool> fKeepBestMatch{"cfgKeepBestMatch", false, "Keep only the best match global muons in the skimming"};
Configurable<float> fMuonMatchEtaMin{"cfgMuonMatchEtaMin", -4.0f, "Definition of the acceptance of muon tracks to be matched with MFT"};
Configurable<float> fMuonMatchEtaMax{"cfgMuonMatchEtaMax", -2.5f, "Definition of the acceptance of muon tracks to be matched with MFT"};
} fConfigVariousOptions;
Service<o2::ccdb::BasicCCDBManager> fCCDB;
o2::ccdb::CcdbApi fCCDBApi;
o2::parameters::GRPObject* fGrpMagRun2 = nullptr; // for run 2, we access the GRPObject from GLO/GRP/GRP
o2::parameters::GRPMagField* fGrpMag = nullptr; // for run 3, we access GRPMagField from GLO/Config/GRPMagField
AnalysisCompositeCut* fEventCut; //! Event selection cut
std::vector<AnalysisCompositeCut*> fTrackCuts; //! Barrel track cuts
std::vector<AnalysisCompositeCut*> fMuonCuts; //! Muon track cuts
bool fDoDetailedQA = false; // Bool to set detailed QA true, if QA is set true
int fCurrentRun; // needed to detect if the run changed and trigger update of calibrations etc.
// list of MCsignal objects
std::vector<MCSignal*> fMCSignals;
std::map<uint64_t, int> fLabelsMap;
std::map<uint64_t, int> fLabelsMapReversed;
std::map<uint64_t, uint16_t> fMCFlags;
std::map<uint32_t, uint32_t> fCollIndexMap; // key: old collision index, value: skimmed collision index
std::map<uint32_t, uint32_t> fTrackIndexMap; // key: old track global index, value: new track global index
std::map<uint32_t, uint32_t> fFwdTrackIndexMap; // key: fwd-track global index, value: new fwd-track global index
std::map<uint32_t, uint32_t> fFwdTrackIndexMapReversed; // key: new fwd-track global index, value: fwd-track global index
std::map<uint32_t, uint8_t> fFwdTrackFilterMap; // key: fwd-track global index, value: fwd-track filter map
std::map<uint32_t, uint32_t> fMftIndexMap; // key: MFT tracklet global index, value: new MFT tracklet global index
std::map<uint32_t, bool> fBestMatch;
std::unordered_map<int64_t, int32_t> map_mfttrackcovs;
void init(o2::framework::InitContext& context)
{
// Check whether barrel or muon are enabled
bool isProcessBCenabled = context.mOptions.get<bool>("processPP");
bool isBarrelEnabled = (context.mOptions.get<bool>("processPP") || context.mOptions.get<bool>("processPPBarrelOnly") || context.mOptions.get<bool>("processPbPbBarrelOnly") || context.mOptions.get<bool>("processPbPbWithFilterBarrelOnly"));
bool isMuonEnabled = (context.mOptions.get<bool>("processPP") || context.mOptions.get<bool>("processPPMuonOnlyBasic") || context.mOptions.get<bool>("processPPMuonOnly") || context.mOptions.get<bool>("processPPRealignedMuonOnly") || context.mOptions.get<bool>("processPbPbMuonOnly") || context.mOptions.get<bool>("processPbPbRealignedMuonOnly")) || context.mOptions.get<bool>("processPPMuonRefit");
// Make sure at least one process function is enabled
if (!(isProcessBCenabled || isBarrelEnabled || isMuonEnabled)) {
LOG(fatal) << "No process function was enabled for TableMakerMC. Check it out!!!";
}
VarManager::SetDefaultVarNames(); // Important that this is called before DefineCuts() !!!
// Define user specified cut
DefineCuts();
fHistMan = new HistogramManager("analysisHistos", "aa", VarManager::kNVars);
fHistMan->SetUseDefaultVariableNames(kTRUE);
fHistMan->SetDefaultVarNames(VarManager::fgVariableNames, VarManager::fgVariableUnits);
// Only use detailed QA when QA is set true
if (fConfigHistOutput.fConfigQA && fConfigHistOutput.fConfigDetailedQA) {
fDoDetailedQA = true;
}
// Create the histogram class names to be added to the histogram manager
TString histClasses = "";
// Event histograms before any cuts
if (fDoDetailedQA) {
histClasses += "Event_BeforeCuts;";
}
// Event histograms after cuts and for MC truth collisions
if (fConfigHistOutput.fConfigQA) {
histClasses += "Event_AfterCuts;";
histClasses += "Event_MCTruth;";
}
if (isBarrelEnabled) {
// Barrel track histograms before cuts
if (fDoDetailedQA) {
histClasses += "TrackBarrel_BeforeCuts;";
}
// Barrel track histograms after cuts; one directory per cut
if (fConfigHistOutput.fConfigQA) {
for (auto& cut : fTrackCuts) {
histClasses += Form("TrackBarrel_%s;", cut->GetName());
}
}
}
if (isMuonEnabled) {
// Muon track histograms before cuts
if (fDoDetailedQA) {
histClasses += "Muons_BeforeCuts;";
}
// Muon track histograms after cuts; one directory per cut
if (fConfigHistOutput.fConfigQA) {
for (auto& muonCut : fMuonCuts) {
histClasses += Form("Muons_%s;", muonCut->GetName());
}
}
}
// Configure user specified MC signals and setup histogram classes
TString configNamesStr = fConfigMCSignals.value;
std::unique_ptr<TObjArray> objArray(configNamesStr.Tokenize(","));
if (objArray->GetEntries() > 0) {
// loop over MC signals and add them to the signals array
for (int isig = 0; isig < objArray->GetEntries(); ++isig) {
MCSignal* sig = o2::aod::dqmcsignals::GetMCSignal(objArray->At(isig)->GetName());
if (sig) {
fMCSignals.push_back(sig);
}
}
}
// Adding additional signals via JSON
TString addMCSignalsStr = fConfigMCSignalsJSON.value;
if (addMCSignalsStr != "") {
std::vector<MCSignal*> addMCSignals = dqmcsignals::GetMCSignalsFromJSON(addMCSignalsStr.Data());
for (auto& mcIt : addMCSignals) {
if (mcIt) {
fMCSignals.push_back(mcIt);
}
}
}
for (auto& mcIt : fMCSignals) {
if (fConfigHistOutput.fConfigQA) {
histClasses += Form("MCTruth_%s;", mcIt->GetName());
}
if (fDoDetailedQA) {
if (isBarrelEnabled) {
// in case of detailed QA, setup histogram directories for each combination of reconstructed track cuts and MC signals
for (auto& cut : fTrackCuts) {
histClasses += Form("TrackBarrel_%s_%s;", cut->GetName(), mcIt->GetName());
}
}
if (isMuonEnabled) {
// in case of detailed QA, setup histogram directories for each combination of reconstructed muon cuts and MC signals
for (auto& cut : fMuonCuts) {
histClasses += Form("Muons_%s_%s;", cut->GetName(), mcIt->GetName());
}
}
}
}
DefineHistograms(histClasses); // define all histograms
// Additional histogram via the JSON configurable
TString addHistsStr = fConfigHistOutput.fConfigAddJSONHistograms.value;
if (fConfigHistOutput.fConfigQA && addHistsStr != "") {
dqhistograms::AddHistogramsFromJSON(fHistMan, addHistsStr.Data());
}
VarManager::SetUseVars(fHistMan->GetUsedVars()); // provide the list of required variables so that VarManager knows what to fill
fOutputList.setObject(fHistMan->GetMainHistogramList());
// Setup the CCDB
fCCDB->setURL(fConfigCCDB.fConfigCcdbUrl);
fCCDB->setCaching(true);
fCCDB->setLocalObjectValidityChecking();
if (!o2::base::GeometryManager::isGeometryLoaded()) {
fCCDB->get<TGeoManager>(fConfigCCDB.fGeoPath);
}
fCCDBApi.init(fConfigCCDB.fConfigCcdbUrl.value);
}
void DefineCuts()
{
// Event cuts
fEventCut = new AnalysisCompositeCut(true);
TString eventCutStr = fConfigCuts.fConfigEventCuts.value;
fEventCut->AddCut(dqcuts::GetAnalysisCut(eventCutStr.Data()));
// Extra event cuts via JSON
TString addEvCutsStr = fConfigCuts.fConfigEventCutsJSON.value;
if (addEvCutsStr != "") {
std::vector<AnalysisCut*> addEvCuts = dqcuts::GetCutsFromJSON(addEvCutsStr.Data());
for (auto& cutIt : addEvCuts) {
fEventCut->AddCut(cutIt);
}
}
// Barrel track cuts
TString cutNamesStr = fConfigCuts.fConfigTrackCuts.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()));
}
}
// Additional Barrel track cuts via JSON
TString addTrackCutsStr = fConfigCuts.fConfigTrackCutsJSON.value;
if (addTrackCutsStr != "") {
std::vector<AnalysisCut*> addTrackCuts = dqcuts::GetCutsFromJSON(addTrackCutsStr.Data());
for (auto& t : addTrackCuts) {
fTrackCuts.push_back(reinterpret_cast<AnalysisCompositeCut*>(t));
}
}
// Muon cuts
cutNamesStr = fConfigCuts.fConfigMuonCuts.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()));
}
}
// Additional muon cuts via JSON
TString addMuonCutsStr = fConfigCuts.fConfigMuonCutsJSON.value;
if (addMuonCutsStr != "") {
std::vector<AnalysisCut*> addMuonCuts = dqcuts::GetCutsFromJSON(addMuonCutsStr.Data());
for (auto& t : addMuonCuts) {
fMuonCuts.push_back(reinterpret_cast<AnalysisCompositeCut*>(t));
}
}
VarManager::SetUseVars(AnalysisCut::fgUsedVars); // provide the list of required variables so that VarManager knows what to fill
}
Preslice<aod::TrackAssoc> trackIndicesPerCollision = aod::track_association::collisionId;
Preslice<aod::FwdTrackAssoc> fwdtrackIndicesPerCollision = aod::track_association::collisionId;
Preslice<aod::MFTTrackAssoc> mfttrackIndicesPerCollision = aod::track_association::collisionId;
void skimMCCollisions(aod::McCollisions const& mcCollisions)
{
// skim MC collisions
// NOTE: So far, all MC collisions are skimmed. In case there will be filtering based on MC collisions,
// one has to do a mapping of the old vs new indices so that the skimmed labels are properly updated.
VarManager::ResetValues(0, VarManager::kNVars);
// Loop over MC collisions
for (auto& mcCollision : mcCollisions) {
// Get MC collision information into the VarManager
VarManager::FillEvent<VarManager::ObjTypes::CollisionMC>(mcCollision);
// Fill histograms
fHistMan->FillHistClass("Event_MCTruth", VarManager::fgValues);
// Create the skimmed table entry for this collision
eventMC(mcCollision.generatorsID(), mcCollision.posX(), mcCollision.posY(), mcCollision.posZ(),
mcCollision.t(), mcCollision.weight(), mcCollision.impactParameter());
}
}
void skimMCParticles(aod::McParticles const& mcTracks, aod::McCollisions const&)
{
// Select MC particles which fulfill at least one of the user specified MC signals
// In this function we just fill a map with the labels of selected particles, not creating the tables themselves.
// The reason is that in the skims we will additionally add any MC label connected to selected reconstructed tracks
// which were not selected already via the MC signals
// Clear the label maps
fLabelsMap.clear();
fLabelsMapReversed.clear();
fMCFlags.clear();
uint16_t mcflags = static_cast<uint16_t>(0); // flags which will hold the decisions for each MC signal
int trackCounter = 0;
for (auto& mctrack : mcTracks) {
// check all the requested MC signals and fill the decision bit map
mcflags = 0;
int i = 0;
for (auto& sig : fMCSignals) {
bool checked = false;
if constexpr (soa::is_soa_filtered_v<aod::McParticles>) {
auto mctrack_raw = mcTracks.rawIteratorAt(mctrack.globalIndex());
checked = sig->CheckSignal(true, mctrack_raw);
} else {
checked = sig->CheckSignal(true, mctrack);
}
if (checked) {
mcflags |= (static_cast<uint16_t>(1) << i);
}
i++;
}
/*if ((std::abs(mctrack.pdgCode())>400 && std::abs(mctrack.pdgCode())<599) ||
(std::abs(mctrack.pdgCode())>4000 && std::abs(mctrack.pdgCode())<5999) ||
(mcflags > 0)) {
cout << ">>>>>>>>>>>>>>>>>>>>>>> track idx / pdg / process / status code / HEPMC status / primary : "
<< mctrack.globalIndex() << " / " << mctrack.pdgCode() << " / "
<< mctrack.getProcess() << " / " << mctrack.getGenStatusCode() << " / " << mctrack.getHepMCStatusCode() << " / " << mctrack.isPhysicalPrimary() << endl;
cout << ">>>>>>>>>>>>>>>>>>>>>>> track bitmap: ";
PrintBitMap(mcflags, 16);
cout << endl;
if (mctrack.has_mothers()) {
for (auto& m : mctrack.mothersIds()) {
if (m < mcTracks.size()) { // protect against bad mother indices
auto aMother = mcTracks.rawIteratorAt(m);
cout << "<<<<<< mother idx / pdg: " << m << " / " << aMother.pdgCode() << endl;
}
}
}
if (mctrack.has_daughters()) {
for (int d = mctrack.daughtersIds()[0]; d <= mctrack.daughtersIds()[1]; ++d) {
if (d < mcTracks.size()) { // protect against bad daughter indices
auto aDaughter = mcTracks.rawIteratorAt(d);
cout << "<<<<<< daughter idx / pdg: " << d << " / " << aDaughter.pdgCode() << endl;
}
}
}
}*/
// if no MC signals were matched, continue
if (mcflags == 0) {
continue;
}
// If this MC track was not already added to the map, add it now
if (fLabelsMap.find(mctrack.globalIndex()) == fLabelsMap.end()) {
fLabelsMap[mctrack.globalIndex()] = trackCounter;
fLabelsMapReversed[trackCounter] = mctrack.globalIndex();
fMCFlags[mctrack.globalIndex()] = mcflags;
trackCounter++;
// fill histograms for each of the signals, if found
if (fConfigHistOutput.fConfigQA) {
VarManager::FillTrackMC(mcTracks, mctrack);
VarManager::FillEvent<VarManager::ObjTypes::CollisionMC>(mctrack.mcCollision());
int j = 0;
for (auto signal = fMCSignals.begin(); signal != fMCSignals.end(); signal++, j++) {
if (mcflags & (static_cast<uint16_t>(1) << j)) {
fHistMan->FillHistClass(Form("MCTruth_%s", (*signal)->GetName()), VarManager::fgValues);
}
}
}
}
} // end loop over mc stack
}
template <uint32_t TEventFillMap, typename TEvents>
void skimCollisions(TEvents const& collisions, BCsWithTimestamps const& /*bcs*/)
{
// Skim reconstructed collisions which are selected by the user specified cuts
// Create a collision index map to relate between the "old" AO2D indices and the skimmed ones
fCollIndexMap.clear();
int multTPC = -1.0;
float multFV0A = -1.0;
float multFV0C = -1.0;
float multFT0A = -1.0;
float multFT0C = -1.0;
float multFDDA = -1.0;
float multFDDC = -1.0;
float multZNA = -1.0;
float multZNC = -1.0;
int multTracklets = -1.0;
int multTracksPV = -1.0;
float centFT0C = -1.0;
float centFT0A = -1.0;
float centFT0M = -1.0;
// Loop over collisions
for (const auto& collision : collisions) {
// Fill the stats event histogram with the event selection bits
for (int i = 0; i < o2::aod::evsel::kNsel; i++) {
if (collision.selection_bit(i)) {
(reinterpret_cast<TH2I*>(fStatsList->At(0)))->Fill(1.0, static_cast<float>(i));
}
}
(reinterpret_cast<TH2I*>(fStatsList->At(0)))->Fill(1.0, static_cast<float>(o2::aod::evsel::kNsel));
// apply the event filter
if constexpr ((TEventFillMap & VarManager::ObjTypes::RapidityGapFilter) > 0) {
if (!collision.eventFilter()) {
continue;
}
}
auto bc = collision.template bc_as<BCsWithTimestamps>();
// store the selection decisions
uint64_t tag = static_cast<uint64_t>(0);
// store some more information in the tag
// if the BC found by event selection does not coincide with the collision.bc(), toggle the first bit
auto bcEvSel = collision.template foundBC_as<BCsWithTimestamps>();
if (bcEvSel.globalIndex() != bc.globalIndex()) {
tag |= (static_cast<uint64_t>(1) << 0);
}
// Put the 8 first bits of the event filter in the last 8 bits of the tag
if constexpr ((TEventFillMap & VarManager::ObjTypes::RapidityGapFilter) > 0) {
tag |= (collision.eventFilter() << 56);
}
// Compute BC and event quantities and fill histograms
VarManager::ResetValues(0, VarManager::kNEventWiseVariables);
VarManager::FillBC(bc);
VarManager::FillEvent<TEventFillMap>(collision); // extract event information and place it in the fValues array
if (collision.has_mcCollision()) {
VarManager::FillEvent<VarManager::ObjTypes::CollisionMC>(collision.mcCollision());
}
if (fDoDetailedQA) {
fHistMan->FillHistClass("Event_BeforeCuts", VarManager::fgValues);
}
// fill stats information, before selections
for (int i = 0; i < o2::aod::evsel::kNsel; i++) {
if (collision.selection_bit(i)) {
(reinterpret_cast<TH2I*>(fStatsList->At(0)))->Fill(2.0, static_cast<float>(i));
}
}
(reinterpret_cast<TH2I*>(fStatsList->At(0)))->Fill(2.0, static_cast<float>(o2::aod::evsel::kNsel));
// Apply the user specified event selection
if (!fEventCut->IsSelected(VarManager::fgValues)) {
continue;
}
// fill stats information, after selections
for (int i = 0; i < o2::aod::evsel::kNsel; i++) {
if (collision.selection_bit(i)) {
(reinterpret_cast<TH2I*>(fStatsList->At(0)))->Fill(3.0, static_cast<float>(i));
}
}
(reinterpret_cast<TH2I*>(fStatsList->At(0)))->Fill(3.0, static_cast<float>(o2::aod::evsel::kNsel));
// Fill historams after event cuts
fHistMan->FillHistClass("Event_AfterCuts", VarManager::fgValues);
// create the event tables
event(tag, bc.runNumber(), collision.posX(), collision.posY(), collision.posZ(), collision.numContrib(), collision.collisionTime(), collision.collisionTimeRes());
if constexpr ((TEventFillMap & VarManager::ObjTypes::CollisionMult) > 0) {
multTPC = collision.multTPC();
multFV0C = collision.multFV0C();
multZNA = collision.multZNA();
multZNC = collision.multZNC();
multTracklets = collision.multTracklets();
multTracksPV = collision.multNTracksPV();
if constexpr ((TEventFillMap & VarManager::ObjTypes::RapidityGapFilter) > 0) {
// Use the FIT signals from the nearest BC with FIT amplitude above threshold
multFV0A = collision.newBcMultFV0A();
multFT0A = collision.newBcMultFT0A();
multFT0C = collision.newBcMultFT0C();
multFDDA = collision.newBcMultFDDA();
multFDDC = collision.newBcMultFDDC();
} else {
multFV0A = collision.multFV0A();
multFT0A = collision.multFT0A();
multFT0C = collision.multFT0C();
multFDDA = collision.multFDDA();
multFDDC = collision.multFDDC();
}
}
if constexpr ((TEventFillMap & VarManager::ObjTypes::CollisionCent) > 0) {
centFT0C = collision.centFT0C();
centFT0A = collision.centFT0A();
centFT0M = collision.centFT0M();
}
eventExtended(bc.globalBC(), collision.alias_raw(), collision.selection_raw(), bc.timestamp(), VarManager::fgValues[VarManager::kCentVZERO],
multTPC, multFV0A, multFV0C, multFT0A, multFT0C, multFDDA, multFDDC, multZNA, multZNC, multTracklets, multTracksPV, centFT0C, centFT0A, centFT0M);
eventVtxCov(collision.covXX(), collision.covXY(), collision.covXZ(), collision.covYY(), collision.covYZ(), collision.covZZ(), collision.chi2());
eventMClabels(collision.mcCollisionId(), collision.mcMask());
eventInfo(collision.globalIndex());
if constexpr ((TEventFillMap & VarManager::ObjTypes::CollisionMultExtra) > 0) {
multPV(collision.multNTracksHasITS(), collision.multNTracksHasTPC(), collision.multNTracksHasTOF(), collision.multNTracksHasTRD(),
collision.multNTracksITSOnly(), collision.multNTracksTPCOnly(), collision.multNTracksITSTPC(),
collision.multNTracksPVeta1(), collision.multNTracksPVetaHalf(), collision.trackOccupancyInTimeRange(), collision.ft0cOccupancyInTimeRange());
multAll(collision.multAllTracksTPCOnly(), collision.multAllTracksITSTPC(),
0, 0, 0.0, 0.0, 0.0, 0.0, 0, 0, 0.0, 0.0, 0.0, 0.0);
}
// add an element for this collision into the map
fCollIndexMap[collision.globalIndex()] = event.lastIndex();
}
}
template <uint32_t TTrackFillMap, typename TEvent, typename TTracks>
void skimTracks(TEvent const& collision, TTracks const& /*tracks*/, TrackAssoc const& assocs, aod::McParticles const& mcTracks)
{
// Skim the barrel track associations
// Apply track cuts for each collision association and if it passes the cuts, we skim it.
// NOTE: If selection cuts include conditions on quantities dependent on the associated collision (e.g. DCA),
// one track may pass for some association and fail for others.
// Tracks are written only once in the skims, even if they contribute to more than one association
// so in case of multiple associations, the variables depending on the collision association (e.g. DCA, secondary vertexing, etc)
// have to be recomputed at analysis time for each association.
uint64_t trackFilteringTag = static_cast<uint64_t>(0);
uint32_t trackTempFilterMap = static_cast<uint32_t>(0);
uint16_t mcflags = static_cast<uint16_t>(0);
int trackCounter = fLabelsMap.size();
// Loop over associations
for (const auto& assoc : assocs) {
auto track = assoc.template track_as<TTracks>();
// If the original collision of this track was not selected for skimming, then we skip this track.
// Normally, the filter-pp is selecting all collisions which contain the tracks which contributed to the triggering
// of an event, so this is rejecting possibly a few tracks unrelated to the trigger, originally associated with collisions distant in time.
if (fCollIndexMap.find(track.collisionId()) == fCollIndexMap.end()) {
continue;
}
trackFilteringTag = static_cast<uint64_t>(0);
trackTempFilterMap = static_cast<uint32_t>(0);
// Compute track quantities and fill histograms
VarManager::FillTrack<TTrackFillMap>(track);
if (fConfigVariousOptions.fPropTrack && (track.collisionId() != collision.globalIndex())) {
VarManager::FillTrackCollision<TTrackFillMap>(track, collision);
}
if (fDoDetailedQA) {
fHistMan->FillHistClass("TrackBarrel_BeforeCuts", VarManager::fgValues);
}
// apply track cuts and fill histograms
int i = 0;
for (auto cut = fTrackCuts.begin(); cut != fTrackCuts.end(); cut++, i++) {
if ((*cut)->IsSelected(VarManager::fgValues)) {
trackTempFilterMap |= (static_cast<uint32_t>(1) << i);
if (fConfigHistOutput.fConfigQA) {
fHistMan->FillHistClass(Form("TrackBarrel_%s", (*cut)->GetName()), VarManager::fgValues);
}
(reinterpret_cast<TH1I*>(fStatsList->At(1)))->Fill(static_cast<float>(i));
}
}
if (!trackTempFilterMap) {
continue;
}
// If this track is already present in the index map, it means it was already skimmed,
// so we just store the association and we skip the track
if (fTrackIndexMap.find(track.globalIndex()) != fTrackIndexMap.end()) {
trackBarrelAssoc(fCollIndexMap[collision.globalIndex()], fTrackIndexMap[track.globalIndex()]);
continue;
}
// store V0 and Dalitz bits selection information in the track tag
if constexpr (static_cast<bool>(TTrackFillMap & VarManager::ObjTypes::TrackV0Bits)) { // BIT0-4: V0Bits
trackFilteringTag |= static_cast<uint64_t>(track.pidbit());
for (int iv0 = 0; iv0 < 5; iv0++) {
if (track.pidbit() & (uint8_t(1) << iv0)) {
(reinterpret_cast<TH1I*>(fStatsList->At(1)))->Fill(fTrackCuts.size() + static_cast<float>(iv0));
}
}
} // end if V0Bits
if constexpr (static_cast<bool>(TTrackFillMap & VarManager::ObjTypes::DalitzBits)) {
trackFilteringTag |= (static_cast<uint64_t>(track.dalitzBits()) << VarManager::kDalitzBits); // BIT5-12: Dalitz
}
trackFilteringTag |= (static_cast<uint64_t>(trackTempFilterMap) << VarManager::kBarrelUserCutsBits); // BIT13-...: user track filters
// NOTE: The collision ID that is written in the table is the one originally assigned in the AOD.
// However, in data analysis one should loop over associations, so this one should not be used.
// In the case of Run2-like analysis, there will be no associations, so this ID will be the one originally assigned in the AO2Ds (updated for the skims)
uint32_t reducedEventIdx = fCollIndexMap[track.collisionId()];
// NOTE: trackBarrelInfo stores the index of the collision as in AO2D (for use in some cases where the analysis on skims is done
// in workflows where the original AO2Ds are also present)
trackBarrelInfo(track.collisionId(), collision.posX(), collision.posY(), collision.posZ(), track.globalIndex());
trackBasic(reducedEventIdx, trackFilteringTag, track.pt(), track.eta(), track.phi(), track.sign(), 0);
trackBarrel(track.x(), track.alpha(), track.y(), track.z(), track.snp(), track.tgl(), track.signed1Pt(),
track.tpcInnerParam(), track.flags(), track.itsClusterMap(), track.itsChi2NCl(),
track.tpcNClsFindable(), track.tpcNClsFindableMinusFound(), track.tpcNClsFindableMinusCrossedRows(),
track.tpcNClsShared(), track.tpcChi2NCl(),
track.trdChi2(), track.trdPattern(), track.tofChi2(),
track.length(), track.dcaXY(), track.dcaZ(),
track.trackTime(), track.trackTimeRes(), track.tofExpMom(),
track.detectorMap());
if constexpr (static_cast<bool>(TTrackFillMap & VarManager::ObjTypes::TrackCov)) {
trackBarrelCov(track.cYY(), track.cZY(), track.cZZ(), track.cSnpY(), track.cSnpZ(),
track.cSnpSnp(), track.cTglY(), track.cTglZ(), track.cTglSnp(), track.cTglTgl(),
track.c1PtY(), track.c1PtZ(), track.c1PtSnp(), track.c1PtTgl(), track.c1Pt21Pt2());
}
if constexpr (static_cast<bool>(TTrackFillMap & VarManager::ObjTypes::TrackPID)) {
trackBarrelPID(track.tpcSignal(),
track.tpcNSigmaEl(), track.tpcNSigmaMu(), track.tpcNSigmaPi(), track.tpcNSigmaKa(), track.tpcNSigmaPr(),
track.beta(), track.tofNSigmaEl(), track.tofNSigmaMu(), track.tofNSigmaPi(), track.tofNSigmaKa(), track.tofNSigmaPr(),
track.trdSignal());
}
fTrackIndexMap[track.globalIndex()] = trackBasic.lastIndex();
// Check whether the MCParticle corresponding to this reconstructed track was already selected for skimming
// If not, add it to the skimming map
if (!track.has_mcParticle()) {
trackBarrelLabels(-1, 0, 0); // this is the case when there is no matched MCParticle
} else {
auto mctrack = track.template mcParticle_as<aod::McParticles>();
VarManager::FillTrackMC(mcTracks, mctrack);
mcflags = 0;
int i = 0; // runs over the MC signals
int j = 0; // runs over the track cuts
// check all the specified signals and fill histograms for MC truth matched tracks
for (auto& sig : fMCSignals) {
if (sig->CheckSignal(true, mctrack)) {
mcflags |= (static_cast<uint16_t>(1) << i);
// If detailed QA is on, fill histograms for each MC signal and track cut combination
if (fDoDetailedQA) {
j = 0;
for (auto& cut : fTrackCuts) {
if (trackTempFilterMap & (uint8_t(1) << j)) {
fHistMan->FillHistClass(Form("TrackBarrel_%s_%s", cut->GetName(), sig->GetName()), VarManager::fgValues); // fill the reconstructed truth
}
j++;
}
}
}
i++;
}
// if the MC truth particle corresponding to this reconstructed track is not already written,
// add it to the skimmed stack
if (!(fLabelsMap.find(mctrack.globalIndex()) != fLabelsMap.end())) {
fLabelsMap[mctrack.globalIndex()] = trackCounter;
fLabelsMapReversed[trackCounter] = mctrack.globalIndex();
fMCFlags[mctrack.globalIndex()] = mcflags;
trackCounter++;
}
trackBarrelLabels(fLabelsMap.find(mctrack.globalIndex())->second, track.mcMask(), mcflags);
}
// write the skimmed collision - track association
trackBarrelAssoc(fCollIndexMap[collision.globalIndex()], fTrackIndexMap[track.globalIndex()]);
} // end loop over associations
} // end skimTracks
template <uint32_t TMFTFillMap, typename TEvent, typename TMFTTracks>
void skimMFT(TEvent const& collision, TMFTTracks const& /*mfts*/, MFTTrackAssoc const& mftAssocs, aod::McParticles const& mcTracks)
{
// Skim MFT tracks
// So far no cuts are applied here
uint16_t mcflags = static_cast<uint16_t>(0);
int trackCounter = fLabelsMap.size();
for (const auto& assoc : mftAssocs) {
auto track = assoc.template mfttrack_as<TMFTTracks>();
if (fConfigHistOutput.fConfigQA) {
VarManager::FillTrack<TMFTFillMap>(track);
fHistMan->FillHistClass("MftTracks", VarManager::fgValues);
}
// write the MFT track global index in the map for skimming (to make sure we have it just once)
if (fMftIndexMap.find(track.globalIndex()) == fMftIndexMap.end()) {
uint32_t reducedEventIdx = fCollIndexMap[collision.globalIndex()];
mftTrack(reducedEventIdx, static_cast<uint64_t>(0), track.pt(), track.eta(), track.phi());
// TODO: We are not writing the DCA at the moment, because this depends on the collision association
mftTrackExtra(track.mftClusterSizesAndTrackFlags(), track.sign(), 0.0, 0.0, track.nClusters());
fMftIndexMap[track.globalIndex()] = mftTrack.lastIndex();
if (!track.has_mcParticle()) {
mftLabels(-1, 0, 0); // this is the case when there is no matched MCParticle
} else {
auto mctrack = track.template mcParticle_as<aod::McParticles>();
VarManager::FillTrackMC(mcTracks, mctrack);
mcflags = 0;
int i = 0; // runs over the MC signals
// check all the specified signals and fill histograms for MC truth matched tracks
for (auto& sig : fMCSignals) {
if (sig->CheckSignal(true, mctrack)) {
mcflags |= (static_cast<uint16_t>(1) << i);
// If detailed QA is on, fill histograms for each MC signal and track cut combination
if (fDoDetailedQA) {
fHistMan->FillHistClass(Form("MFTTrack_%s", sig->GetName()), VarManager::fgValues); // fill the reconstructed truth
}
}
i++;
}
// if the MC truth particle corresponding to this reconstructed track is not already written,
// add it to the skimmed stack
if (!(fLabelsMap.find(mctrack.globalIndex()) != fLabelsMap.end())) {
fLabelsMap[mctrack.globalIndex()] = trackCounter;
fLabelsMapReversed[trackCounter] = mctrack.globalIndex();
fMCFlags[mctrack.globalIndex()] = mcflags;
trackCounter++;
}
mftLabels(fLabelsMap.find(mctrack.globalIndex())->second, track.mcMask(), mcflags);
}
}
mftAssoc(fCollIndexMap[collision.globalIndex()], fMftIndexMap[track.globalIndex()]);
}
}
template <typename TMuons>
void skimBestMuonMatches(TMuons const& muons)
{
std::unordered_map<int, std::pair<float, int>> mCandidates;
for (const auto& muon : muons) {
if (static_cast<int>(muon.trackType()) < 2) {
auto muonID = muon.matchMCHTrackId();
auto chi2 = muon.chi2MatchMCHMFT();
if (mCandidates.find(muonID) == mCandidates.end()) {
mCandidates[muonID] = {chi2, muon.globalIndex()};
} else {
if (chi2 < mCandidates[muonID].first) {
mCandidates[muonID] = {chi2, muon.globalIndex()};
}
}
}
}
for (auto& pairCand : mCandidates) {
fBestMatch[pairCand.second.second] = true;
}
}
template <uint32_t TMuonFillMap, uint32_t TMFTFillMap, typename TEvent, typename TMuons, typename TMFTTracks, typename TMFTCovs>
void skimMuons(TEvent const& collision, TMuons const& muons, FwdTrackAssoc const& muonAssocs, aod::McParticles const& mcTracks, TMFTTracks const& /*mftTracks*/, TMFTCovs const& mfCovs)
{
// Skim the fwd-tracks (muons)
// Loop over the collision-track associations, recompute track properties depending on the collision assigned, and apply track cuts for selection
// Muons are written only once, even if they constribute to more than one association,
// which means that in the case of multiple associations, the track parameters are wrong and should be computed again at analysis time.
uint8_t trackFilteringTag = static_cast<uint8_t>(0);
uint8_t trackTempFilterMap = static_cast<uint8_t>(0);
fFwdTrackIndexMapReversed.clear();
uint16_t mcflags = static_cast<uint16_t>(0);
int trackCounter = fLabelsMap.size();
uint32_t offset = muonBasic.lastIndex();
uint32_t counter = 0;
for (const auto& assoc : muonAssocs) {
// get the muon
auto muon = muons.rawIteratorAt(assoc.fwdtrackId());
if (fConfigVariousOptions.fKeepBestMatch && static_cast<int>(muon.trackType()) < 2) {
if (fBestMatch.find(muon.globalIndex()) == fBestMatch.end()) {
continue;
}
}
trackFilteringTag = uint8_t(0);
trackTempFilterMap = uint8_t(0);
if constexpr (static_cast<bool>(TMuonFillMap & VarManager::ObjTypes::MuonRealign)) {
// Check refit flag in case of realigned muons
if (static_cast<bool>(muon.isRemovable())) {
continue;
}
}
VarManager::FillTrack<TMuonFillMap>(muon);
// NOTE: If a muon is associated to multiple collisions, depending on the selections,
// it may be accepted for some associations and rejected for other
if (fConfigVariousOptions.fPropMuon) {
VarManager::FillPropagateMuon<TMuonFillMap>(muon, collision);
}
// recalculte pDca and global muon kinematics
if (static_cast<int>(muon.trackType()) < 2 && fConfigVariousOptions.fRefitGlobalMuon) {
auto muontrack = muon.template matchMCHTrack_as<TMuons>();
if (muontrack.eta() < fConfigVariousOptions.fMuonMatchEtaMin || muontrack.eta() > fConfigVariousOptions.fMuonMatchEtaMax) {
continue;
}
auto mfttrack = muon.template matchMFTTrack_as<TMFTTracks>();
VarManager::FillTrackCollision<TMuonFillMap>(muontrack, collision);
if constexpr (static_cast<bool>(TMFTFillMap & VarManager::ObjTypes::MFTCov)) {
auto const& mfttrackcov = mfCovs.rawIteratorAt(map_mfttrackcovs[mfttrack.globalIndex()]);
VarManager::FillGlobalMuonRefitCov<TMuonFillMap, TMFTFillMap>(muontrack, mfttrack, collision, mfttrackcov);
} else {
VarManager::FillGlobalMuonRefit<TMuonFillMap, TMFTFillMap>(muontrack, mfttrack, collision);
}
} else {
VarManager::FillTrackCollision<TMuonFillMap>(muon, collision);
}
if (fDoDetailedQA) {
fHistMan->FillHistClass("Muons_BeforeCuts", VarManager::fgValues);
}
// check the cuts and fill histograms for each fulfilled cut
int i = 0;
for (auto cut = fMuonCuts.begin(); cut != fMuonCuts.end(); cut++, i++) {
if ((*cut)->IsSelected(VarManager::fgValues)) {
trackTempFilterMap |= (uint8_t(1) << i);
if (fConfigHistOutput.fConfigQA) {
fHistMan->FillHistClass(Form("Muons_%s", (*cut)->GetName()), VarManager::fgValues);
}
(reinterpret_cast<TH1I*>(fStatsList->At(2)))->Fill(static_cast<float>(i));
}
}
// don't skim the muon if no cut has passed
if (!trackTempFilterMap) {
continue;
}
trackFilteringTag = trackTempFilterMap; // BIT0-7: user selection cuts
// update the index map if this is a new muon (it can already exist in the map from a different collision association)
if (fFwdTrackIndexMap.find(muon.globalIndex()) == fFwdTrackIndexMap.end()) {
counter++;
fFwdTrackIndexMap[muon.globalIndex()] = offset + counter;
fFwdTrackIndexMapReversed[offset + counter] = muon.globalIndex();
fFwdTrackFilterMap[muon.globalIndex()] = trackFilteringTag; // store here the filtering tag so we don't repeat the cuts in the second iteration
if (muon.has_matchMCHTrack() && (fFwdTrackIndexMap.find(muon.matchMCHTrackId()) == fFwdTrackIndexMap.end())) { // write also the matched MCH track
counter++;
fFwdTrackIndexMap[muon.matchMCHTrackId()] = offset + counter;
fFwdTrackIndexMapReversed[offset + counter] = muon.matchMCHTrackId();
fFwdTrackFilterMap[muon.matchMCHTrackId()] = trackFilteringTag; // store here the filtering tag so we don't repeat the cuts in the second iteration
}
if (muon.has_mcParticle()) {
auto mctrack = muon.template mcParticle_as<aod::McParticles>();
VarManager::FillTrackMC(mcTracks, mctrack);
mcflags = 0;
int i = 0; // runs over the MC signals
int j = 0; // runs over the track cuts
// check all the specified signals and fill histograms for MC truth matched tracks
for (auto& sig : fMCSignals) {
if (sig->CheckSignal(true, mctrack)) {