-
Notifications
You must be signed in to change notification settings - Fork 797
Expand file tree
/
Copy pathAliAnalysisTaskAO2Dconverter.cxx
More file actions
4609 lines (4085 loc) · 189 KB
/
AliAnalysisTaskAO2Dconverter.cxx
File metadata and controls
4609 lines (4085 loc) · 189 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(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
* *
* Author: The ALICE Off-line Project. *
* Contributors are mentioned in the code where appropriate. *
* *
* Permission to use, copy, modify and distribute this software and its *
* documentation strictly for non-commercial purposes is hereby granted *
* without fee, provided that the above copyright notice appears in all *
* copies and that both the copyright notice and this permission notice *
* appear in the supporting documentation. The authors make no claims *
* about the suitability of this software for any purpose. It is *
* provided "as is" without express or implied warranty. *
**************************************************************************/
/* AliAnalysisTaskAO2Dconverter
*
* Convert Run 2 ESDs to Run 3 AODs (AO2D.root).
*/
#include <algorithm>
#include <TFile.h>
#include <TDirectory.h>
#include <TChain.h>
#include <TTree.h>
#include <TMath.h>
#include <Math/SMatrix.h>
#include <TTimeStamp.h>
#include <TClonesArray.h>
#include <TRandom.h>
#include <TH2.h>
#include <TSystem.h>
#include "AliAnalysisTask.h"
#include "AliAnalysisManager.h"
#include "AliCDBManager.h"
#include "AliCDBEntry.h"
#include "AliVEvent.h"
#include "AliESDEvent.h"
#include "AliAODEvent.h"
#include "AliVVertex.h"
#include "AliESDVertex.h"
#include "AliAODVertex.h"
#include "AliCentrality.h"
#include "AliDAQ.h"
#include "AliGRPObject.h"
#include "AliVMultiplicity.h"
#include "AliEMCALGeometry.h"
#include "AliEMCALTriggerDataGrid.h"
#include "AliEMCALTriggerPatchInfo.h"
#include "AliAnalysisTaskAO2Dconverter.h"
#include "AliVHeader.h"
#include "AliV0ReaderV1.h"
#include "COMMON/MULTIPLICITY/AliMultSelection.h"
#include "limits.h"
#include "AliESDCaloCells.h"
#include "AliESDCaloTrigger.h"
#include "AliESDHeader.h"
#include "AliESDtrack.h"
#include "AliESDMuonTrack.h"
#include "AliESDMuonCluster.h"
#include "AliESDZDC.h"
#include "AliESDVZERO.h"
#include "AliESDv0.h"
#include "AliESDcascade.h"
#include "AliESDPmdTrack.h"
#include "AliESDFMD.h"
#include "AliAODForwardMult.h"
#include "AliForwardMultiplicityTask.h"
#include "AliMCEvent.h"
#include "AliMCEventHandler.h"
#include "AliPIDResponse.h"
#include "AliAODMCParticle.h"
#include "AliAODMCHeader.h"
#include "AliGenCocktailEventHeader.h"
#include "AliGenDPMjetEventHeader.h"
#include "AliGenEpos3EventHeader.h"
#include "AliGenEposEventHeader.h"
#include "AliGenEventHeader.h"
#include "AliGenEventHeaderTunedPbPb.h"
#include "AliGenGeVSimEventHeader.h"
#include "AliGenHepMCEventHeader.h"
#include "AliGenHerwigEventHeader.h"
#include "AliGenHijingEventHeader.h"
#include "AliGenPythiaEventHeader.h"
#include "AliGenToyEventHeader.h"
#include "AliTriggerAnalysis.h"
#include "AliOADBContainer.h"
#include "AliMathBase.h"
#include "AliLog.h"
#include "AliProdInfo.h"
#include "RVersion.h"
#include "ARVersion.h"
// #include "APVersion.h"
ClassImp(AliAnalysisTaskAO2Dconverter);
const TString AliAnalysisTaskAO2Dconverter::TreeName[kTrees] = {
"O2collision_001",
"DbgEventExtra",
"O2track",
"O2trackcov",
"O2trackextra_002", // 002 add tpc findable minus pid clusters
"O2fwdtrack",
"O2fwdtrackcov",
"O2calo",
"O2calotrigger",
"O2zdc_001", // changed to std::vector format with lots of dynamic columns
"O2fv0a",
"O2fv0c",
"O2ft0",
"O2fdd_001",
"O2v0_002", // 002 added the V0Type (standard or photon)
"O2run2otfv0", // on the fly V0s for photon conversions
"O2cascade_001",
"O2tof",
"O2mcparticle_001",
"O2mccollision_001",
"O2mctracklabel",
"O2mcfwdtracklabel",
"O2mccalolabel_001", // changed the mask column to std::vector for the amplitude fraction
"O2mccollisionlabel",
"O2bc_001",
"O2run2bcinfo_001",
"O2origin",
"O2hmpid_001", // now stores the position of the extrapolated track and HMPID cluster, cluster size, track
"O2hf2prong",
"O2hf3prong",
"O2hfcascade",
"O2hfdstar",
"O2hepmcxsection",
"O2hepmcpdfinfo",
"O2hepmcheavyion",
"O2run2trackextra_001",
"O2pmd",
"O2pidtpcel",
"O2pidtpcmu",
"O2pidtpcpi",
"O2pidtpcka",
"O2pidtpcpr",
"O2pidtpcde",
"O2pidtpctr",
"O2pidtpche",
"O2pidtpcal",
"O2centrun2v0m",
"O2centrun2v0a",
"O2centrun2cl0",
"O2centrun2cl1",
"O2centrun2remu5",
"O2centrun2remu8",
"O2fmd"
};
const TString AliAnalysisTaskAO2Dconverter::TreeTitle[kTrees] = {
"Collision tree",
"Collision extra",
"Barrel tracks Parameters",
"Barrel tracks Covariance",
"Barrel tracks Extra",
"Forward tracks Parameters",
"Forward tracks Covariances",
"Calorimeter cells",
"Calorimeter triggers",
"ZDC",
"FV0A",
"FV0C",
"FT0",
"FDD",
"V0s",
"V0s on the fly",
"Cascades",
"TOF hits",
"Kinematics",
"MC collisions",
"MC track labels",
"MC fwd track labels",
"MC calo labels",
"MC collision labels",
"BC info",
"Run 2 BC Info",
"DF ids",
"HMPID info",
"HF 2 prong candidates",
"HF 3 prong candidates",
"HF cascade candidates",
"HF D* candidates",
"O2 HepMc Cross Sections",
"O2 HepMc Pdf Info",
"O2 HepMc Heavy Ion",
"Barrel tracks Extra Run2",
"PMD info",
"packed TPC PID for electrons",
"packed TPC PID for muons",
"packed TPC PID for pions",
"packed TPC PID for kaons",
"packed TPC PID for protons",
"packed TPC PID for deuterons",
"packed TPC PID for tritons",
"packed TPC PID for helium",
"packed TPC PID for alpha",
"V0M Centrality",
"V0A Centrality",
"CL0 Centrality",
"CL1 Centrality",
"RefMult 0.5 Centrality",
"RefMult 0.8 Centrality",
"FMD info"
};
const TClass *AliAnalysisTaskAO2Dconverter::Generator[kGenerators] = {AliGenEventHeader::Class(), AliGenCocktailEventHeader::Class(), AliGenDPMjetEventHeader::Class(), AliGenEpos3EventHeader::Class(), AliGenEposEventHeader::Class(), AliGenEventHeaderTunedPbPb::Class(), AliGenGeVSimEventHeader::Class(), AliGenHepMCEventHeader::Class(), AliGenHerwigEventHeader::Class(), AliGenHijingEventHeader::Class(), AliGenPythiaEventHeader::Class(), AliGenToyEventHeader::Class()};
namespace
{
// Helper function
ULong64_t GetGlobalBC(AliVHeader *header)
{
return ((ULong64_t)header->GetBunchCrossNumber() +
(ULong64_t)header->GetOrbitNumber() * 3564 +
(ULong64_t)header->GetPeriodNumber() * 16777216 * 3564);
}
// Initialize the precision masks used to truncate the corresponding float data members
// By default no truncation
UInt_t mCollisionPosition = 0xFFFFFFFF; // Position in x,y,z
UInt_t mCollisionPositionCov = 0xFFFFFFFF; // Covariance matrix and chi2
UInt_t mTrackX = 0xFFFFFFFF;
UInt_t mTrackAlpha = 0xFFFFFFFF;
UInt_t mtrackSnp = 0xFFFFFFFF;
UInt_t mTrackTgl = 0xFFFFFFFF;
UInt_t mTrack1Pt = 0xFFFFFFFF; // Including the momentun at the inner wall of TPC
UInt_t mTrackCovDiag = 0xFFFFFFFF; // Including the chi2
UInt_t mTrackCovOffDiag = 0xFFFFFFFF;
UInt_t mTrackSignal = 0xFFFFFFFF; // PID signals and track length
UInt_t mTrackPosEMCAL = 0xFFFFFFFF;
UInt_t mTracklets = 0xFFFFFFFF; // tracklet members
UInt_t mMcParticleW = 0xFFFFFFFF; // Precision for weight
UInt_t mMcParticlePos = 0xFFFFFFFF; // Precision for (x,y,z,t)
UInt_t mMcParticleMom = 0xFFFFFFFF; // Precision for (Px,Py,Pz,E)
UInt_t mCaloAmp = 0xFFFFFFFF;
UInt_t mCaloTime = 0xFFFFFFFF;
UInt_t mMuonTr1P = 0xFFFFFFFF;
UInt_t mMuonTrThetaX = 0xFFFFFFFF;
UInt_t mMuonTrThetaY = 0xFFFFFFFF;
UInt_t mMuonTrZmu = 0xFFFFFFFF;
UInt_t mMuonTrBend = 0xFFFFFFFF;
UInt_t mMuonTrNonBend = 0xFFFFFFFF;
UInt_t mMuonTrCov = 0xFFFFFFFF; // Covariance matrix and chi2
UInt_t mMuonCl = 0xFFFFFFFF; // Position and charge
UInt_t mMuonClErr = 0xFFFFFFFF;
UInt_t mV0Time = 0xFFFFFFFF;
UInt_t mADTime = 0xFFFFFFFF;
UInt_t mT0Time = 0xFFFFFFFF;
UInt_t mV0Amplitude = 0xFFFFFFFF;
UInt_t mADAmplitude = 0xFFFFFFFF;
UInt_t mT0Amplitude = 0xFFFFFFFF;
UInt_t mV0otfLength = 0xFFFFFFFF;
UInt_t mV0otfMass = 0xFFFFFFFF;
UInt_t mV0otfMomentum = 0xFFFFFFFF;
UInt_t mPMDPositionPrecision = 0xFFFFFFFF;
UInt_t mPMDEnergyPrecision = 0xFFFFFFFF;
UInt_t mPMDProbabilityPrecision = 0xFFFFFFFF;
UInt_t mFMD = 0xFFFFFFFF;
// No compression for ZDC for the moment
} // namespace
AliAnalysisTaskAO2Dconverter::AliAnalysisTaskAO2Dconverter(const char* name)
: AliAODRelabelInterface(name),
fTrackFilter(Form("AO2Dconverter%s", name), Form("fTrackFilter%s", name)),
fCollSystem(0),
fEventCuts(),
fConversionCuts(),
fConversionCut(""),
fTriggerAnalysis(),
fInputGammas(NULL),
fConversionGammas(NULL),
fPreviousV0ReaderPerformsAODRelabeling(0),
collision(),
eventextra(),
bc(),
run2bcinfo(),
origin(),
tracks(),
hmpids(),
mccollision(),
mctracklabel(),
mcfwdtracklabel(),
mccalolabel(),
mccollisionlabel(),
mcparticle(),
hepMcCrossSections(),
hepMcPdfInfo(),
hepMcHeavyIon(),
#ifdef USE_TOF_CLUST
tofClusters(),
#endif
calo(),
calotrigger(),
fwdtracks(),
zdc(),
fv0a(),
fv0c(),
ft0(),
fdd(),
v0s(),
otfv0s(),
cascs(),
hf2Prong(),
hf3Prong(),
hfCascades(),
hfDStar(),
pmdInfo(),
fmdInfo(),
fMetaData()
{
DefineInput(0, TChain::Class());
DefineOutput(1, TList::Class());
for (Int_t i = 0; i < kTrees; i++)
{
fTreeStatus[i] = kTRUE;
}
} // AliAnalysisTaskAO2Dconverter::AliAnalysisTaskAO2Dconverter(const char* name)
AliAnalysisTaskAO2Dconverter::~AliAnalysisTaskAO2Dconverter()
{
if (fOutputList) {
fOutputList->Delete();
delete fOutputList;
}
if(fConversionGammas){
fConversionGammas->Delete();// Clear Objects
delete fConversionGammas;
fConversionGammas=0x0;
}
} // AliAnalysisTaskAO2Dconverter::~AliAnalysisTaskAO2Dconverter()
//________________________________________________________________________
void AliAnalysisTaskAO2Dconverter::Init()
{
// Initialize function to be called once before analysis
if(fConversionGammas != NULL){
delete fConversionGammas;
fConversionGammas=NULL;
}
if(fConversionGammas == NULL){
fConversionGammas = new TClonesArray("AliAODConversionPhoton",100);
}
fConversionGammas->Delete();//Reset the TClonesArray
}
void AliAnalysisTaskAO2Dconverter::NotifyRun(){
const char* oadbfilename = Form("%s/COMMON/PHYSICSSELECTION/data/physicsSelection.root", AliAnalysisManager::GetOADBPath());
TFile* oadb = TFile::Open(oadbfilename);
if(!oadb->IsOpen()) AliFatal(Form("Cannot open OADB file %s", oadbfilename));
AliOADBContainer* triggerContainer = (AliOADBContainer*) oadb->Get("trigAnalysis");
if (!triggerContainer) AliFatal("Cannot fetch OADB container for trigger analysis");
AliOADBTriggerAnalysis* oadbTriggerAnalysis = (AliOADBTriggerAnalysis*) triggerContainer->GetObject(fCurrentRunNumber, "Default");
fTriggerAnalysis.SetParameters(oadbTriggerAnalysis);
fTriggerAnalysis.ApplyPileupCuts(kTRUE);
//read PHOS trigger bad map
if (fUsePHOSBadMap){
AliOADBContainer phosBadmapContainer(Form("phosTriggerBadMap"));
phosBadmapContainer.InitFromFile(Form("%s/PHOS/PHOSTrigBadMaps.root", AliAnalysisManager::GetOADBPath()),
"phosTriggerBadMap");
TObjArray *maps = (TObjArray*)phosBadmapContainer.GetObject(fCurrentRunNumber,"phosTriggerBadMap");
if(!maps){
AliFatal(Form("Can not read PHOS Trigger Bad map for run %d. \n",fCurrentRunNumber)) ;
}
else{
for(Int_t mod=0; mod<5;mod++){
if(fPHOSBadMap[mod])
delete fPHOSBadMap[mod] ;
TH2I * h = (TH2I*)maps->At(mod) ;
if(h)
fPHOSBadMap[mod]=new TH2I(*h) ;
}
}
}
AliCDBManager *cdb = AliCDBManager::Instance();
if(cdb->IsDefaultStorageSet() && cdb->GetRun() > 0) {
// CDB manage initialized
// Get GRP
AliCDBEntry *en = cdb->Get("GRP/GRP/Data");
if(en) {
fGRP = static_cast<AliGRPObject *>(en->GetObject());
}
}
}
void AliAnalysisTaskAO2Dconverter::UserCreateOutputObjects()
{
// Setting active/inactive containers based on the TaskMode
switch (fTaskMode)
{
case kStandard:
DisableTree(kMcParticle);
DisableTree(kMcCollision);
DisableTree(kMcTrackLabel);
DisableTree(kMcFwdTrackLabel);
DisableTree(kMcCaloLabel);
DisableTree(kMcCollisionLabel);
DisableTree(kHepMcCrossSections);
DisableTree(kHepMcPdfInfo);
DisableTree(kHepMcHeavyIon);
break;
default:
break;
}
// Set the truncation
if (fTruncate)
{
mCollisionPosition = 0xFFFFFFF0; // 19 bits mantissa
mCollisionPositionCov = 0xFFFFE000; // 10 bits mantissa
mTrackX = 0xFFFFFFF0; // 19 bits
mTrackAlpha = 0xFFFFFFF0; // 19 bits
mtrackSnp = 0xFFFFFF00; // 15 bits
mTrackTgl = 0xFFFFFF00; // 15 bits
mTrack1Pt = 0xFFFFFC00; // 13 bits
mTrackCovDiag = 0xFFFFFF00; // 15 bits
mTrackCovOffDiag = 0xFFFF0000; // 7 bits
mTrackSignal = 0xFFFFFF00; // 15 bits
mTrackPosEMCAL = 0xFFFFFF00; // 15 bits;
mTracklets = 0xFFFFFF00; // 15 bits
mMcParticleW = 0xFFFFFFF0; // 19 bits
mMcParticlePos = 0xFFFFFFF0; // 19 bits
mMcParticleMom = 0xFFFFFFF0; // 19 bits
mCaloAmp = 0xFFFFFF00; // 15 bits
mCaloTime = 0xFFFFFF00; // 15 bits
mMuonTr1P = 0xFFFFFC00; // 13 bits
mMuonTrThetaX = 0xFFFFFF00; // 15 bits
mMuonTrThetaY = 0xFFFFFF00; // 15 bits
mMuonTrZmu = 0xFFFFFFF0; // 19 bits
mMuonTrBend = 0xFFFFFFF0; // 19 bits
mMuonTrNonBend = 0xFFFFFFF0; // 19 bits
mMuonTrCov = 0xFFFF0000; // 7 bits
mMuonCl = 0xFFFFFF00; // 15 bits
mMuonClErr = 0xFFFF0000; // 7 bits
mV0Time = 0xFFFFF000; // 11 bits
mADTime = 0xFFFFF000; // 11 bits
mT0Time = 0xFFFFFF00; // 15 bits
mV0Amplitude = 0xFFFFF000; // 11 bits
mADAmplitude = 0xFFFFF000; // 11 bits
mT0Amplitude = 0xFFFFF000; // 11 bits
mV0otfLength = 0xFFFFF000; // 11 bits
mV0otfMass = 0xFFFFF000; // 11 bits but saved in MeV!
mV0otfMomentum = 0xFFFFFC00; // 13 bits
mPMDPositionPrecision = 0xFFFFF000; // 11 bits
mPMDEnergyPrecision = 0xFFFFF000; // 11 bits
mPMDProbabilityPrecision = 0xFFFFF000; // 11 bits
}
// create output objects
OpenFile(1); // Here we have the histograms
/// Option compress is used to specify the compression level and algorithm:
///
/// compress = 100 * algorithm + level
///
/// Level | Explanation
/// ------|-------------
/// 0 | objects written to this file will not be compressed.
/// 1 | minimal compression level but fast.
/// ... | ....
/// 9 | maximal compression level but slower and might use more memory.
/// algorithm = 1 : ZLIB compression algorithm is used (default)
/// algorithm = 2 : LZMA compression algorithm is used
/// algorithm = 4 : LZ4 compression algorithm is used
/// algorithm = 5 : ZSTD compression algorithm is used
/// So fCompress = 409 is LZ4 algorithm level 9
fOutputFile = TFile::Open("AO2D.root", "RECREATE", "O2 AOD", fCompress); // File to store the trees of time frames
fOutputFile->Print();
// create the list of output histograms
fOutputList = new TList();
fOutputList->SetOwner();
// Add centrality histogram
fCentralityHist = new TH1F("centrality", TString::Format("Centrality %s", fCentralityMethod.Data()),
100, 0.0, 100.0);
fCentralityINT7 = new TH1F("centralityINT7", TString::Format("Centrality %s INT7", fCentralityMethod.Data()),
100, 0.0, 100.0);
fHistPileupEvents = new TH1I("puEvents", "Pileup events", 2, 0, 2);
fHistIsCollision = new TH1I("fHistIsCollision", "Number of actual events", 2, 0, 2);
fNSigmaElectron = new TH1F("fNSigmaElectron", ";N#sigma_{e};#it{counts}", 100, -10, 10.);
fDedxVsP = new TH2F("fDedxVsP", ";#it{p} (GeV/#it{c});d#it{E}/d#it{x} (a.u.)", 1000, 0., 10., 990, 10., 1000.);
fHistPileupEvents->SetStats(0);
fOutputList->Add(fCentralityHist);
fOutputList->Add(fCentralityINT7);
fOutputList->Add(fHistPileupEvents);
fOutputList->Add(fHistIsCollision);
fOutputList->Add(fNSigmaElectron);
fOutputList->Add(fDedxVsP);
if (fSkipTPCPileup || fSkipPileup || fUseEventCuts)
fEventCuts.AddQAplotsToList(fOutputList);
if (fSkipTPCPileup)
fEventCuts.SetRejectTPCPileupWithITSTPCnCluCorr(true);
fConversionCuts.SetIsHeavyIon(fCollSystem);
fConversionCuts.SetFillCutHistograms("",true);
fConversionCuts.InitializeCutsFromCutString(fConversionCut);
fOutputList->Add(fConversionCuts.GetCutHistograms());
PostData(1, fOutputList);
if (!fStoreHF) {
DisableTree(kHF2Prong);
DisableTree(kHF3Prong);
DisableTree(kHFCascade);
DisableTree(kHFDStar);
}
} // void AliAnalysisTaskAO2Dconverter::UserCreateOutputObjects()
void AliAnalysisTaskAO2Dconverter::UserExec(Option_t *)
{
// Initialisation
const char *kPileupRejType[2] = {"PU_rej", "PU_TPC_rej"};
fVEvent = InputEvent();
fESD = dynamic_cast<AliESDEvent *>(fVEvent);
fAOD = dynamic_cast<AliAODEvent *>(fVEvent);
if (!fESD && !fAOD)
{
::Fatal("AliAnalysisTaskAO2Dconverter::UserExec", "Something is wrong with the event handler");
}
// Check if correctly initialized
if(!fConversionGammas)Init();
// populate meta data only once
if (fMetaData.GetEntries() == 0) {
fMetaData.Add(new TObjString("DataType"), new TObjString((fTaskMode == kStandard) ? "RAW" : "MC"));
fMetaData.Add(new TObjString("Run"), new TObjString("2"));
TString converterVersion("aliroot ");
converterVersion += ALIROOT_VERSION;
converterVersion += ":";
converterVersion += ALIROOT_REVISION;
// TODO include above does not work?
// converterVersion += "; aliphysics "
// converterVersion += ALIPHYSICS_VERSION;
// converterVersion += ":";
// converterVersion += ALIPHYSICS_REVISION;
converterVersion += "; root ";
converterVersion += ROOT_RELEASE;
fMetaData.Add(new TObjString("Run2ConverterVersion"), new TObjString(converterVersion));
auto userInfo = fInputHandler->GetUserInfo();
AliProdInfo prodInfo(userInfo);
fMetaData.Add(new TObjString("ProducerAliRootVersion"), new TObjString(prodInfo.GetAlirootVersion()));
fMetaData.Add(new TObjString("ProducerROOTVersion"), new TObjString(prodInfo.GetRootVersion()));
fMetaData.Add(new TObjString("RecoPassName"), new TObjString(prodInfo.GetRecoPassName()));
fMetaData.Add(new TObjString("AnchorProduction"), new TObjString(prodInfo.GetAnchorProduction()));
fMetaData.Add(new TObjString("AnchorPassName"), new TObjString(prodInfo.GetAnchorPassName()));
fMetaData.Add(new TObjString("LPMProductionTag"), new TObjString(prodInfo.GetTag(AliProdInfo::kProdTag)));
}
// This call is necessary to initialize event cuts according to the current run number
bool alieventcut = fEventCuts.AcceptEvent(fVEvent);
// In case of ESD we skip events like in the AOD filtering, for AOD this is not needed
// We can use event cuts to avoid cases where we have zero reconstructed tracks
bool skip_event = false;
if (fESD && (fUseEventCuts || fSkipPileup || fSkipTPCPileup))
{
skip_event = !alieventcut && fUseEventCuts;
}
// Skip pileup events if requested
if (fESD && fSkipPileup && !fEventCuts.PassedCut(AliEventCuts::kPileUp))
{
fHistPileupEvents->Fill(kPileupRejType[0], 1);
skip_event = true;
}
// Check for TPC pileup events if requested, but don't skip event since it may affect physics
if (fESD && fSkipTPCPileup && !fEventCuts.PassedCut(AliEventCuts::kTPCPileUp))
{
fHistPileupEvents->Fill(kPileupRejType[1], 1);
//skip_event = true;
}
if (fTaskMode == kStandard)
if (fESD && (fESD->GetHeader()->GetEventType() != 7)) // check for PHYSICS events
skip_event = true;
if (skip_event)
{
return;
}
if (!fTfInitialized)
{
ULong64_t tfId = GetGlobalBC(fVEvent->GetHeader());
if (tfId == 0)
{
// The time stamp of the event is not set, for example in MC
// Try the AliEn job ID
TString alienPID(gSystem->Getenv("ALIEN_PROC_ID"));
if (alienPID.Length() > 0)
{
tfId = alienPID.Atoll() * 1000 + fTFCount;
}
else
{
// Fallback:
// Use the time period from 2020/11/01 in seconds (similar to what we did in the DAQ LDCs)
TTimeStamp ts0(2020, 11, 1, 0, 0, 0);
TTimeStamp ts1;
tfId = ts1.GetSec() - ts0.GetSec();
tfId *= 1000 + fTFCount;
}
}
// Make globally unique TF id (across all data-taking)
// The longest fill in Run 2 was 38 hours, which needs 43 bits. We reserve the values up to 1e13 which corresponds to 69 hours.
// Run numbers in Run 2 were < 300k, which needs 19 bits
// To make the number human-readable, we avoid a bit shift, but use a multiplication
Int_t runNumber = fVEvent->GetRunNumber();
if (runNumber > 0)
tfId += (ULong64_t)(runNumber) * 10000000000000L;
InitTF(tfId);
}
// Centrality QA
Float_t centrality = -999;
if (fESD) {
// Get multiplicity selection
AliMultSelection *multSelection = (AliMultSelection *)fESD->FindListObject("MultSelection");
if (!multSelection)
AliFatal("MultSelection not found in input event");
centrality = multSelection->GetMultiplicityPercentile(fCentralityMethod);
// get V0 Reader
if (fTreeStatus[kOTFV0s]) {
TString cutnumberEvent = "00000003";
if(fCollSystem==1)
cutnumberEvent = "10000003";
else if(fCollSystem==2)
cutnumberEvent = "80000003";
else if(fCollSystem==29)//UPC
cutnumberEvent = "100c0003";
TString V0ReaderName = Form("V0ReaderV1_%s_%s",cutnumberEvent.Data(),fConversionCut.Data());
AliV0ReaderV1* fV0Reader = (AliV0ReaderV1*)AliAnalysisManager::GetAnalysisManager()->GetTask(V0ReaderName.Data());
if(!fV0Reader){
AliFatal("Error: No V0 Reader");
}
// get the conversion gammas from V0Reader
fConversionGammas = fV0Reader->GetReconstructedGammas(); // Gammas from default Cut
}
}
else if (fAOD) {
AliCentrality* centralityObj = fAOD->GetCentrality();
if (centralityObj) centrality = centralityObj->GetCentralityPercentile(fCentralityMethod);
if (fTreeStatus[kOTFV0s]) {
if(!(AliAnalysisTaskAO2Dconverter::GetAODConversionGammas())){
AliFatal("Could not receive AODConversionGammas!");
}
}
}
// Fill centrality QA plots
fCentralityHist->Fill(centrality);
fHistIsCollision->Fill(0.1);
if ((fInputHandler->IsEventSelected() & AliVEvent::kINT7) != 0)
fCentralityINT7->Fill(centrality);
// Selection of events with at least two contributors (GMI)
// Can this be done using the physics selection? (PH)
const AliVVertex *pvtx = fVEvent->GetPrimaryVertex();
if (!pvtx)
{
::Fatal("AliAnalysisTaskAO2Dconverter::UserExec", "Vertex not defined");
}
// Now fill the content of the TF
FillEventInTF();
// Finish the current TF and initialize a new one, if the size is above the limit
if (fBytes > fMaxBytes)
{
AliInfo(Form("Total size of output trees: %lu bytes\n", fBytes));
fBytes = 0; // Reset the byte counter
fTfInitialized = false;
FinishTF();
}
//---------------------------------------------------------------------------
//Posting data
PostData(1, fOutputList);
} // void AliAnalysisTaskAO2Dconverter::UserExec(Option_t *)
void AliAnalysisTaskAO2Dconverter::FinishTaskOutput()
{
// called at the end of the event loop on the worker
FinishTF();
fOutputFile->Write(); // Do not close the file since this is then re-opened and overwritten by the framework
AliInfo(Form("Total size of output trees: %lu bytes\n", fBytes));
// write meta data
fOutputFile->WriteObject(&fMetaData, "metaData");
}
void AliAnalysisTaskAO2Dconverter::Terminate(Option_t *)
{
// called at the END of the analysis AFTER merging. In grid this is NOT called on the workers
}
AliAnalysisTaskAO2Dconverter *AliAnalysisTaskAO2Dconverter::AddTask(TString suffix)
{
AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
if (!mgr)
{
return nullptr;
}
// get the input event handler, again via a static method.
// this handler is part of the managing system and feeds events
// to your task
if (!mgr->GetInputEventHandler())
{
return nullptr;
}
// AliAODInputHandler* aodH = new AliAODInputHandler();
// aodH->AddFriend((char*)"AliAODGammaConversion.root");
// mgr->SetInputEventHandler(aodH);
// by default, a file is open for writing. here, we get the filename
TString fileName = "qa.root";
if (!suffix.IsNull())
fileName += ":" + suffix; // create a subfolder in the file
// now we create an instance of your task
AliAnalysisTaskAO2Dconverter *task = new AliAnalysisTaskAO2Dconverter((TString("AO2D converter") + suffix).Data());
if (!task){
return nullptr;
}
// add your task to the manager
mgr->AddTask(task);
// your task needs input: here we connect the manager to your task
mgr->ConnectInput(task, 0, mgr->GetCommonInputContainer());
// same for the output
mgr->ConnectOutput(task, 1, mgr->CreateContainer("QAlist", TList::Class(), AliAnalysisManager::kOutputContainer, fileName.Data()));
// we need to register an unconnected output container to register the output file in the lego system
mgr->CreateContainer("AO2D", TTree::Class(), AliAnalysisManager::kOutputContainer, "AO2D.root");
// for (Int_t i = 0; i < kTrees; i++)
// mgr->ConnectOutput(task, 2 + i, mgr->CreateContainer(TreeName[i], TTree::Class(), AliAnalysisManager::kOutputContainer, fileName.Data()));
// in the end, this macro returns a pointer to your task. this will be convenient later on
// when you will run your analysis in an analysis train on grid
return task;
} // AliAnalysisTaskAO2Dconverter *AliAnalysisTaskAO2Dconverter::AddTask(TString suffix)
////////////////////////////////////////////////////////////
TTree *AliAnalysisTaskAO2Dconverter::CreateTree(TreeIndex t)
{
if (!fTreeStatus[t])
return 0x0;
// Create the tree in the corresponding (TF) directory
if (!fOutputDir)
AliFatal("No Root subdir|");
fOutputDir->cd();
AliInfo(Form("Creating tree %s\n", TreeName[t].Data()));
fTree[t] = new TTree(TreeName[t], TreeTitle[t]);
fTree[t]->SetAutoFlush(0);
return fTree[t];
} // TTree* AliAnalysisTaskAO2Dconverter::CreateTree(TreeIndex t)
void AliAnalysisTaskAO2Dconverter::Prune()
{
if (fPruneList.IsNull() || fPruneList.IsWhitespace())
return;
TObjArray *arr = fPruneList.Tokenize(" ");
for (Int_t i = 0; i < arr->GetEntries(); i++)
{
Bool_t found = kFALSE;
for (Int_t j = 0; j < kTrees; j++)
{
if (!fTreeStatus[j])
continue;
TObjArray *branches = fTree[j]->GetListOfBranches();
for (Int_t k = 0; k < branches->GetEntries(); k++)
{
TString bname = branches->At(k)->GetName();
if (!bname.EqualTo(arr->At(i)->GetName()))
continue;
fTree[j]->SetBranchStatus(bname, 0);
found = kTRUE;
}
}
if (!found)
AliFatal(Form("Did not find Branch %s", arr->At(i)->GetName()));
}
fPruneList = "";
} // void AliAnalysisTaskAO2Dconverter::Prune()
void AliAnalysisTaskAO2Dconverter::FillTree(TreeIndex t)
{
if (!fTreeStatus[t])
return;
Int_t nbytes = fTree[t]->Fill();
if (nbytes > 0)
fBytes += nbytes;
} // void AliAnalysisTaskAO2Dconverter::FillTree(TreeIndex t)
void AliAnalysisTaskAO2Dconverter::WriteTree(TreeIndex t)
{
if (!fTreeStatus[t])
return;
// Write the tree in the corrsponding (TF) directory
if (!fOutputDir)
AliFatal("No Root subdir|");
fOutputDir->cd();
AliInfo(Form("Writing tree %s\n", TreeName[t].Data()));
fTree[t]->Write();
} // void AliAnalysisTaskAO2Dconverter::WriteTree(TreeIndex t)
void AliAnalysisTaskAO2Dconverter::InitTF(ULong64_t tfId)
{
Printf("Initializing TF %lld", tfId);
// Reset the event count
fTFCount++;
fCollisionCount = 0;
fBCCount = 0;
fTfInitialized = true;
// Reset the offsets
fOffsetMuTrackID = 0;
fOffsetTrack = 0;
fOffsetV0 = 0;
fOffsetLabel = 0;
fOffsetHF2Prong = 0;
// Reset the content of eventextra
for (auto i = 0; i < kTrees; ++i)
{
eventextra.fStart[i] = 0;
eventextra.fNentries[i] = 0;
}
// Create the output directory for the current time frame
fOutputDir = fOutputFile->mkdir(Form("DF_%llu", tfId));
// Associate branches for origin table
TTree* tOrigin = CreateTree(kOrigin);
if (fTreeStatus[kOrigin]) {
tOrigin->Branch("fDataframeID", &origin.fDataframeID, "fDataframeID/l");
origin.fDataframeID = tfId;
FillTree(kOrigin);
}
// Associate branches for fEventTree
TTree *tEvents = CreateTree(kEvents);
if (fTreeStatus[kEvents])
{
tEvents->Branch("fIndexBCs", &collision.fIndexBCs, "fIndexBCs/I");
tEvents->Branch("fPosX", &collision.fPosX, "fPosX/F");
tEvents->Branch("fPosY", &collision.fPosY, "fPosY/F");
tEvents->Branch("fPosZ", &collision.fPosZ, "fPosZ/F");
tEvents->Branch("fCovXX", &collision.fCovXX, "fCovXX/F");
tEvents->Branch("fCovXY", &collision.fCovXY, "fCovXY/F");
tEvents->Branch("fCovYY", &collision.fCovYY, "fCovYY/F");
tEvents->Branch("fCovXZ", &collision.fCovXZ, "fCovXZ/F");
tEvents->Branch("fCovYZ", &collision.fCovYZ, "fCovYZ/F");
tEvents->Branch("fCovZZ", &collision.fCovZZ, "fCovZZ/F");
tEvents->Branch("fFlags", &collision.fFlags, "fFlags/s");
tEvents->Branch("fChi2", &collision.fChi2, "fChi2/F");
tEvents->Branch("fNumContrib", &collision.fN, "fNumContrib/s");
tEvents->Branch("fCollisionTime", &collision.fCollisionTime, "fCollisionTime/F");
tEvents->Branch("fCollisionTimeRes", &collision.fCollisionTimeRes, "fCollisionTimeRes/F");
tEvents->SetBasketSize("*", fBasketSizeEvents);
}
// optionally, add centrality
TTree *tCentV0M = CreateTree(kCentV0M);
if (fTreeStatus[kCentV0M])
{
tCentV0M->Branch("fCentRun2V0M", &collision.fCentV0M, "fCentRun2V0M/F");
tCentV0M->SetBasketSize("*", fBasketSizeEvents);
}
TTree *tCentV0A = CreateTree(kCentV0A);
if (fTreeStatus[kCentV0A])
{
tCentV0A->Branch("fCentRun2V0A", &collision.fCentV0A, "fCentRun2V0A/F");
tCentV0A->SetBasketSize("*", fBasketSizeEvents);
}
TTree *tCentCL0 = CreateTree(kCentCL0);
if (fTreeStatus[kCentCL0])
{
tCentCL0->Branch("fCentRun2CL0", &collision.fCentCL0, "fCentRun2CL0/F");
tCentCL0->SetBasketSize("*", fBasketSizeEvents);
}
TTree *tCentCL1 = CreateTree(kCentCL1);
if (fTreeStatus[kCentCL1])
{
tCentCL1->Branch("fCentRun2CL1", &collision.fCentCL1, "fCentRun2CL1/F");
tCentCL1->SetBasketSize("*", fBasketSizeEvents);
}
TTree *tCentRefMult5 = CreateTree(kCentRefMult5);
if (fTreeStatus[kCentRefMult5])
{
tCentRefMult5->Branch("fCentRun2RefMult5", &collision.fCentRefMult05, "fCentRun2RefMult5/F");
tCentRefMult5->SetBasketSize("*", fBasketSizeEvents);
}
TTree *tCentRefMult8 = CreateTree(kCentRefMult8);
if (fTreeStatus[kCentRefMult8])
{
tCentRefMult8->Branch("fCentRun2RefMult8", &collision.fCentRefMult08, "fCentRun2RefMult8/F");
tCentRefMult8->SetBasketSize("*", fBasketSizeEvents);
}
// Extra information for debugging for event table
TTree *tEventsExtra = CreateTree(kEventsExtra);
if (fTreeStatus[kEventsExtra])
{
TString sstart = TString::Format("fStart[%d]/I", kTrees);
TString sentries = TString::Format("fNentries[%d]/I", kTrees);
tEventsExtra->Branch("fStart", eventextra.fStart, sstart.Data());
tEventsExtra->Branch("fNentries", eventextra.fNentries, sentries.Data());
tEventsExtra->SetBasketSize("*", fBasketSizeEvents);
}
// Associate branches for fEventTree
TTree *tBC = CreateTree(kBC);
if (fTreeStatus[kBC])
{
tBC->Branch("fRunNumber", &bc.fRunNumber, "fRunNumber/I");
tBC->Branch("fGlobalBC", &bc.fGlobalBC, "fGlobalBC/l");
tBC->Branch("fTriggerMask", &bc.fTriggerMask, "fTriggerMask/l");
tBC->Branch("fInputMask", &bc.fInputMask, "fInputMask/l");
tBC->SetBasketSize("*", fBasketSizeEvents);
}
// Associate branches for Run 2 BC info
TTree* tRun2BCInfo = CreateTree(kRun2BCInfo);
if (fTreeStatus[kRun2BCInfo]) {
tRun2BCInfo->Branch("fEventCuts", &run2bcinfo.fEventCuts, "fEventCuts/i");
tRun2BCInfo->Branch("fTriggerMaskNext50", &run2bcinfo.fTriggerMaskNext50, "fTriggerMaskNext50/l");
tRun2BCInfo->Branch("fL0TriggerInputMask", &run2bcinfo.fL0TriggerInputMask, "fL0TriggerInputMask/i");
tRun2BCInfo->Branch("fSPDClustersL0", &run2bcinfo.fSPDClustersL0, "fSPDClustersL0/s");
tRun2BCInfo->Branch("fSPDClustersL1", &run2bcinfo.fSPDClustersL1, "fSPDClustersL1/s");
tRun2BCInfo->Branch("fSPDFiredChipsL0", &run2bcinfo.fSPDFiredChipsL0, "fSPDFiredChipsL0/s");
tRun2BCInfo->Branch("fSPDFiredChipsL1", &run2bcinfo.fSPDFiredChipsL1, "fSPDFiredChipsL1/s");
tRun2BCInfo->Branch("fSPDFiredFastOrL0", &run2bcinfo.fSPDFiredFastOrL0, "fSPDFiredFastOrL0/s");
tRun2BCInfo->Branch("fSPDFiredFastOrL1", &run2bcinfo.fSPDFiredFastOrL1, "fSPDFiredFastOrL1/s");
tRun2BCInfo->Branch("fV0TriggerChargeA", &run2bcinfo.fV0TriggerChargeA, "fV0TriggerChargeA/s");
tRun2BCInfo->Branch("fV0TriggerChargeC", &run2bcinfo.fV0TriggerChargeC, "fV0TriggerChargeC/s");
tRun2BCInfo->Branch("fNTPCClusters", &run2bcinfo.fNTPCClusters, "fNTPCClusters/i");
tRun2BCInfo->Branch("fNSDDSSDClusters", &run2bcinfo.fNSDDSSDClusters, "fNSDDSSDClusters/i");
tRun2BCInfo->SetBasketSize("*", fBasketSizeEvents);
}
// Associate branches for the three track trees
TTree* tTracks = CreateTree(kTracks);
if (fTreeStatus[kTracks]) {
tTracks->Branch("fIndexCollisions", &tracks.fIndexCollisions, "fIndexCollisions/I");
tTracks->Branch("fTrackType", &tracks.fTrackType, "fTrackType/b");
tTracks->Branch("fX", &tracks.fX, "fX/F");
tTracks->Branch("fAlpha", &tracks.fAlpha, "fAlpha/F");
tTracks->Branch("fY", &tracks.fY, "fY/F");
tTracks->Branch("fZ", &tracks.fZ, "fZ/F");
tTracks->Branch("fSnp", &tracks.fSnp, "fSnp/F");
tTracks->Branch("fTgl", &tracks.fTgl, "fTgl/F");
tTracks->Branch("fSigned1Pt", &tracks.fSigned1Pt, "fSigned1Pt/F");
tTracks->SetBasketSize("*", fBasketSizeTracks);
}
TTree* tTracksCov = CreateTree(kTracksCov);