-
Notifications
You must be signed in to change notification settings - Fork 650
Expand file tree
/
Copy pathCorrelationContainer.cxx
More file actions
1665 lines (1359 loc) · 64.7 KB
/
CorrelationContainer.cxx
File metadata and controls
1665 lines (1359 loc) · 64.7 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.
//
// encapsulate histogram and corrections for correlation analysis
//
// Author: Jan Fiete Grosse-Oetringhaus
#include "PWGCF/Core/CorrelationContainer.h"
#include <CommonConstants/MathConstants.h>
#include <Framework/HistogramSpec.h>
#include <Framework/Logger.h>
#include <Framework/StepTHn.h>
#include <TCanvas.h>
#include <TCollection.h>
#include <TF1.h>
#include <THn.h>
#include <TIterator.h>
#include <TList.h>
#include <TMath.h>
#include <TMathBase.h>
#include <TNamed.h>
#include <TObject.h>
#include <TString.h>
#include <Rtypes.h>
#include <RtypesCore.h>
#include <cstring>
#include <vector>
using namespace o2;
using namespace o2::framework;
using namespace o2::constants::math;
ClassImp(CorrelationContainer);
const Int_t CorrelationContainer::fgkCFSteps = 11;
CorrelationContainer::CorrelationContainer() : TNamed(),
mPairHist(nullptr),
mTriggerHist(nullptr),
mTrackHistEfficiency(nullptr),
mEventCount(nullptr),
mEtaMin(0),
mEtaMax(0),
mPtMin(0),
mPtMax(0),
mPartSpecies(-1),
mCentralityMin(0),
mCentralityMax(0),
mZVtxMin(0),
mZVtxMax(0),
mTrackEtaCut(0),
mWeightPerEvent(0),
mSkipScaleMixedEvent(kFALSE),
mCache(nullptr),
mGetMultCacheOn(kFALSE),
mGetMultCache(nullptr)
{
// Default constructor
}
CorrelationContainer::CorrelationContainer(const char* name, const char* objTitle,
const std::vector<o2::framework::AxisSpec>& correlationAxis,
const std::vector<o2::framework::AxisSpec>& efficiencyAxis,
const std::vector<o2::framework::AxisSpec>& userAxis) : TNamed(name, objTitle),
mPairHist(nullptr),
mTriggerHist(nullptr),
mTrackHistEfficiency(nullptr),
mEventCount(nullptr),
mEtaMin(0),
mEtaMax(0),
mPtMin(0),
mPtMax(0),
mPartSpecies(-1),
mCentralityMin(0),
mCentralityMax(0),
mZVtxMin(0),
mZVtxMax(0),
mTrackEtaCut(0),
mWeightPerEvent(0),
mSkipScaleMixedEvent(kFALSE),
mCache(nullptr),
mGetMultCacheOn(kFALSE),
mGetMultCache(nullptr)
{
// correlationAxis has to provide a 6 length list of AxisSpec which contain:
// delta_eta, pt_assoc, pt_trig, multiplicity/centrality, delta_phi, vertex
// Those are used for the pair histogram (all 6) and the trigger histogram (pt_trig, multiplicity/centrality, vertex)
//
// efficiencyAxis has to provide a 3 length list of AxisSpec which contains:
// eta (for efficiency), pt (for efficiency), vertex (for efficiency)
// The third axis of correlationAxis (multiplicity/centrality) is used also for the efficiency
//
// (optional) userAxis can contain optional user axes which are added to pair and trigger histogram and are
// integrated out in the helper functions (e.g. getSumOfRatios). Ranges can be set on them before calling helper functions.
if (strlen(name) == 0) {
return;
}
std::vector<o2::framework::AxisSpec> pairAxis(correlationAxis);
pairAxis.insert(pairAxis.end(), userAxis.begin(), userAxis.end());
long bins = 1;
for (const auto& axis : pairAxis) {
bins *= axis.getNbins();
}
LOGF(info, "Creating CorrelationContainer with %ld bins in the pair histogram (approx. %ld-%ld MB of memory)", bins, bins * 4 / 1024 / 1024, bins * 8 / 1024 / 1024);
mPairHist = HistFactory::createHist<StepTHnF>({"mPairHist", "d^{2}N_{ch}/d#varphid#eta", {HistType::kStepTHnF, pairAxis, fgkCFSteps}}).release();
std::vector<o2::framework::AxisSpec> triggerAxis({correlationAxis[2], correlationAxis[3], correlationAxis[5]});
triggerAxis.insert(triggerAxis.end(), userAxis.begin(), userAxis.end());
mTriggerHist = HistFactory::createHist<StepTHnF>({"mTriggerHist", "d^{2}N_{ch}/d#varphid#eta", {HistType::kStepTHnF, triggerAxis, fgkCFSteps}}).release();
mTrackHistEfficiency = HistFactory::createHist<StepTHnF>({"mTrackHistEfficiency", "Tracking efficiency", {HistType::kStepTHnF, {efficiencyAxis[0], efficiencyAxis[1], {5, -0.5, 4.5, "species"}, correlationAxis[3], efficiencyAxis[2]}, fgkCFSteps}}).release();
mEventCount = HistFactory::createHist<TH2F>({"mEventCount", ";step;centrality;count", {HistType::kTH2F, {{fgkCFSteps + 2, -2.5, -0.5 + fgkCFSteps, "step"}, correlationAxis[3]}}}).release();
}
//_____________________________________________________________________________
CorrelationContainer::CorrelationContainer(const CorrelationContainer& c) : TNamed(c),
mPairHist(nullptr),
mTriggerHist(nullptr),
mTrackHistEfficiency(nullptr),
mEtaMin(0),
mEtaMax(0),
mPtMin(0),
mPtMax(0),
mPartSpecies(-1),
mCentralityMin(0),
mCentralityMax(0),
mZVtxMin(0),
mZVtxMax(0),
mTrackEtaCut(0),
mWeightPerEvent(0),
mSkipScaleMixedEvent(kFALSE),
mCache(nullptr),
mGetMultCacheOn(kFALSE),
mGetMultCache(nullptr)
{
//
// CorrelationContainer copy constructor
//
((CorrelationContainer&)c).Copy(*this);
}
//____________________________________________________________________
CorrelationContainer::~CorrelationContainer()
{
// Destructor
if (mPairHist) {
delete mPairHist;
mPairHist = nullptr;
}
if (mTriggerHist) {
delete mTriggerHist;
mTriggerHist = nullptr;
}
if (mTrackHistEfficiency) {
delete mTrackHistEfficiency;
mTrackHistEfficiency = nullptr;
}
if (mEventCount) {
delete mEventCount;
mEventCount = nullptr;
}
if (mCache) {
delete mCache;
mCache = nullptr;
}
}
//____________________________________________________________________
CorrelationContainer& CorrelationContainer::operator=(const CorrelationContainer& c)
{
// assigment operator
if (this != &c) {
((CorrelationContainer&)c).Copy(*this);
}
return *this;
}
//____________________________________________________________________
void CorrelationContainer::Copy(TObject& c) const
{
// copy function
CorrelationContainer& target = (CorrelationContainer&)c;
if (mPairHist) {
target.mPairHist = dynamic_cast<StepTHn*>(mPairHist->Clone());
}
if (mTriggerHist) {
target.mTriggerHist = dynamic_cast<StepTHn*>(mTriggerHist->Clone());
}
if (mTrackHistEfficiency) {
target.mTrackHistEfficiency = dynamic_cast<StepTHn*>(mTrackHistEfficiency->Clone());
}
target.mEtaMin = mEtaMin;
target.mEtaMax = mEtaMax;
target.mPtMin = mPtMin;
target.mPtMax = mPtMax;
target.mPartSpecies = mPartSpecies;
target.mCentralityMin = mCentralityMin;
target.mCentralityMax = mCentralityMax;
target.mZVtxMin = mZVtxMin;
target.mZVtxMax = mZVtxMax;
target.mTrackEtaCut = mTrackEtaCut;
target.mWeightPerEvent = mWeightPerEvent;
target.mSkipScaleMixedEvent = mSkipScaleMixedEvent;
}
//____________________________________________________________________
Long64_t CorrelationContainer::Merge(TCollection* list)
{
// Merge a list of CorrelationContainer objects with this (needed for
// PROOF).
// Returns the number of merged objects (including this).
if (!list) {
return 0;
}
if (list->IsEmpty()) {
return 1;
}
TIterator* iter = list->MakeIterator();
TObject* obj = nullptr;
// collections of objects
const UInt_t kMaxLists = 4;
TList** lists = new TList*[kMaxLists];
for (UInt_t i = 0; i < kMaxLists; i++) {
lists[i] = new TList;
}
Int_t count = 0;
while ((obj = iter->Next())) {
CorrelationContainer* entry = dynamic_cast<CorrelationContainer*>(obj);
if (entry == nullptr) {
continue;
}
if (entry->mPairHist) {
lists[0]->Add(entry->mPairHist);
}
lists[1]->Add(entry->mTriggerHist);
lists[2]->Add(entry->mTrackHistEfficiency);
lists[3]->Add(entry->mEventCount);
count++;
}
if (mPairHist) {
mPairHist->Merge(lists[0]);
}
mTriggerHist->Merge(lists[1]);
mTrackHistEfficiency->Merge(lists[2]);
mEventCount->Merge(lists[3]);
for (UInt_t i = 0; i < kMaxLists; i++) {
delete lists[i];
}
delete[] lists;
return count + 1;
}
//____________________________________________________________________
void CorrelationContainer::setBinLimits(THnBase* grid)
{
// sets the bin limits in eta and pT defined by mEtaMin/Max, mPtMin/Max
if (mEtaMax > mEtaMin) {
grid->GetAxis(0)->SetRangeUser(mEtaMin, mEtaMax);
}
if (mPtMax > mPtMin) {
grid->GetAxis(1)->SetRangeUser(mPtMin, mPtMax);
}
}
//____________________________________________________________________
void CorrelationContainer::resetBinLimits(THnBase* grid, int max_dimension)
{
// resets all bin limits
if (max_dimension < 0 || max_dimension > grid->GetNdimensions()) {
max_dimension = grid->GetNdimensions();
}
for (Int_t i = 0; i < max_dimension; i++) {
if (grid->GetAxis(i)->TestBit(TAxis::kAxisRange)) {
grid->GetAxis(i)->SetRange(0, 0); // reset range
}
}
}
//____________________________________________________________________
void CorrelationContainer::countEmptyBins(CorrelationContainer::CFStep step, Float_t ptTriggerMin, Float_t ptTriggerMax)
{
// prints the number of empty bins in the track end event histograms in the given step
Int_t binBegin[4];
Int_t binEnd[4];
for (Int_t i = 0; i < 4; i++) {
binBegin[i] = 1;
binEnd[i] = mPairHist->getTHn(step)->GetAxis(i)->GetNbins();
}
if (mEtaMax > mEtaMin) {
binBegin[0] = mPairHist->getTHn(step)->GetAxis(0)->FindBin(mEtaMin);
binEnd[0] = mPairHist->getTHn(step)->GetAxis(0)->FindBin(mEtaMax);
}
if (mPtMax > mPtMin) {
binBegin[1] = mPairHist->getTHn(step)->GetAxis(1)->FindBin(mPtMin);
binEnd[1] = mPairHist->getTHn(step)->GetAxis(1)->FindBin(mPtMax);
}
if (ptTriggerMax > ptTriggerMin) {
binBegin[2] = mPairHist->getTHn(step)->GetAxis(2)->FindBin(ptTriggerMin);
binEnd[2] = mPairHist->getTHn(step)->GetAxis(2)->FindBin(ptTriggerMax);
}
// start from multiplicity 1
binBegin[3] = mPairHist->getTHn(step)->GetAxis(3)->FindBin(1);
Int_t total = 0;
Int_t count = 0;
Int_t vars[4];
for (Int_t i = 0; i < 4; i++) {
vars[i] = binBegin[i];
}
THnBase* grid = mPairHist->getTHn(step);
while (1) {
if (grid->GetBin(vars) == 0) {
LOGF(warning, "Empty bin at eta=%.2f pt=%.2f pt_lead=%.2f mult=%.1f",
grid->GetAxis(0)->GetBinCenter(vars[0]),
grid->GetAxis(1)->GetBinCenter(vars[1]),
grid->GetAxis(2)->GetBinCenter(vars[2]),
grid->GetAxis(3)->GetBinCenter(vars[3]));
count++;
}
vars[3]++;
for (Int_t i = 3; i > 0; i--) {
if (vars[i] == binEnd[i] + 1) {
vars[i] = binBegin[i];
vars[i - 1]++;
}
}
if (vars[0] == binEnd[0] + 1) {
break;
}
total++;
}
LOGF(info, "Has %d empty bins (out of %d bins)", count, total);
}
//____________________________________________________________________
void CorrelationContainer::getHistsZVtxMult(CorrelationContainer::CFStep step, Float_t ptTriggerMin, Float_t ptTriggerMax, THnBase** trackHist, TH2** eventHist)
{
// Calculates a 4d histogram with deltaphi, deltaeta, zvtx, multiplicity on track level and
// a 2d histogram on event level (as fct of zvtx, multiplicity)
// Histograms has to be deleted by the caller of the function
THnBase* sparse = mPairHist->getTHn(step);
if (mGetMultCacheOn) {
if (!mGetMultCache) {
mGetMultCache = changeToThn(sparse);
// should work but causes SEGV in ProjectionND below
}
sparse = mGetMultCache;
}
// unzoom all axes
resetBinLimits(sparse, 6);
resetBinLimits(mTriggerHist->getTHn(step), 3);
if (mPtMax > mPtMin) {
sparse->GetAxis(1)->SetRangeUser(mPtMin, mPtMax);
}
Int_t firstBin = sparse->GetAxis(2)->FindBin(ptTriggerMin);
Int_t lastBin = sparse->GetAxis(2)->FindBin(ptTriggerMax);
LOGF(info, "Using trigger pT range %d --> %d", firstBin, lastBin);
sparse->GetAxis(2)->SetRange(firstBin, lastBin);
mTriggerHist->getTHn(step)->GetAxis(0)->SetRange(firstBin, lastBin);
Int_t dimensions[] = {4, 0, 5, 3};
THnBase* tmpTrackHist = sparse->ProjectionND(4, dimensions, "E");
*eventHist = (TH2*)mTriggerHist->getTHn(step)->Projection(1, 2); // NOTE the syntax is Projection(Y, X) --> produces a histogram where x = axis 2 (vertex) and y = axis 1 (multiplicity)
// convert to THn
*trackHist = changeToThn(tmpTrackHist);
delete tmpTrackHist;
resetBinLimits(sparse, 6);
resetBinLimits(mTriggerHist->getTHn(step), 3);
}
TH2* CorrelationContainer::getPerTriggerYield(CorrelationContainer::CFStep step, Float_t ptTriggerMin, Float_t ptTriggerMax, Bool_t normalizePerTrigger)
{
// Calculate per trigger yield without considering mixed event
// Sums over all vertex bins, and respects the pT and centrality limits set in the class
//
// returns a 2D histogram: deltaphi, deltaeta
//
// Parameters:
// step: Step for which the histogram is received
// ptTriggerMin, ptTriggerMax: trigger pT range
// normalizePerTrigger: divide through number of triggers
THnBase* trackSameAll = nullptr;
TH2* eventSameAll = nullptr;
getHistsZVtxMult(step, ptTriggerMin, ptTriggerMax, &trackSameAll, &eventSameAll);
TAxis* multAxis = trackSameAll->GetAxis(3);
int multBinBegin = 1;
int multBinEnd = multAxis->GetNbins();
if (mCentralityMin < mCentralityMax) {
multBinBegin = multAxis->FindBin(mCentralityMin + 1e-4);
multBinEnd = multAxis->FindBin(mCentralityMax - 1e-4);
LOGF(info, "Using multiplicity range %d --> %d", multBinBegin, multBinEnd);
trackSameAll->GetAxis(3)->SetRange(multBinBegin, multBinEnd);
}
TAxis* vertexAxis = trackSameAll->GetAxis(2);
int vertexBinBegin = 1;
int vertexBinEnd = vertexAxis->GetNbins();
if (mZVtxMax > mZVtxMin) {
vertexBinBegin = vertexAxis->FindBin(mZVtxMin);
vertexBinEnd = vertexAxis->FindBin(mZVtxMax);
LOGF(info, "Using vertex range %d --> %d", vertexBinBegin, vertexBinEnd);
trackSameAll->GetAxis(2)->SetRange(vertexBinBegin, vertexBinEnd);
}
TH2* yield = trackSameAll->Projection(1, 0, "E");
Float_t triggers = eventSameAll->Integral(vertexBinBegin, vertexBinEnd, multBinBegin, multBinEnd);
if (normalizePerTrigger) {
LOGF(info, "Dividing %f tracks by %f triggers", yield->Integral(), triggers);
if (triggers > 0) {
yield->Scale(1.0 / triggers);
}
}
// normalizate to dphi width
Float_t normalization = yield->GetXaxis()->GetBinWidth(1);
yield->Scale(1.0 / normalization);
delete trackSameAll;
delete eventSameAll;
return yield;
}
TH2* CorrelationContainer::getSumOfRatios(CorrelationContainer* mixed, CorrelationContainer::CFStep step, Float_t ptTriggerMin, Float_t ptTriggerMax, Bool_t normalizePerTrigger, Int_t stepForMixed, Int_t* trigger)
{
// Extract 2D per trigger yield with mixed event correction. The quantity is calculated for *each* vertex bin and multiplicity bin and then a sum of ratios is performed:
// 1_N [ (same/mixed)_1 + (same/mixed)_2 + (same/mixed)_3 + ... ]
// where N is the total number of events/trigger particles and the subscript is the vertex/multiplicity bin
// where mixed is normalized such that the information about the number of pairs in same is kept
//
// returns a 2D histogram: deltaphi, deltaeta
//
// Parameters:
// mixed: CorrelationContainer containing mixed event corresponding to this object (the histograms are taken from step <stepForMixed> if defined otherwise from step <step>)
// step: Step for which the histogram is received
// ptTriggerMin, ptTriggerMax: trigger pT range
// normalizePerTrigger: divide through number of triggers
// do not add this hists to the directory
Bool_t oldStatus = TH1::AddDirectoryStatus();
TH1::AddDirectory(kFALSE);
TH2* totalTracks = nullptr;
THnBase* trackSameAll = nullptr;
THnBase* trackMixedAll = nullptr;
THnBase* trackMixedAllStep6 = nullptr;
TH2* eventSameAll = nullptr;
TH2* eventMixedAll = nullptr;
TH2* eventMixedAllStep6 = nullptr;
Long64_t totalEvents = 0;
Int_t nCorrelationFunctions = 0;
getHistsZVtxMult(step, ptTriggerMin, ptTriggerMax, &trackSameAll, &eventSameAll);
mixed->getHistsZVtxMult((stepForMixed == -1) ? step : (CFStep)stepForMixed, ptTriggerMin, ptTriggerMax, &trackMixedAll, &eventMixedAll);
// If we ask for histograms from step8 (TTR cut applied) there is a hole at 0,0; so this cannot be used for the
// mixed-event normalization. If step6 is available, the normalization factor is read out from that one.
// If step6 is not available we fallback to taking the normalization along all delta phi (WARNING requires a
// flat delta phi distribution)
if (stepForMixed == -1 && step == kCFStepBiasStudy && mixed->mTriggerHist->getTHn(kCFStepReconstructed)->GetEntries() > 0 && !mSkipScaleMixedEvent) {
LOGF(info, "Using mixed-event normalization factors from step %d", (int)kCFStepReconstructed);
mixed->getHistsZVtxMult(kCFStepReconstructed, ptTriggerMin, ptTriggerMax, &trackMixedAllStep6, &eventMixedAllStep6);
}
// Printf("%f %f %f %f", trackSameAll->GetEntries(), eventSameAll->GetEntries(), trackMixedAll->GetEntries(), eventMixedAll->GetEntries());
// TH1* normParameters = new TH1F("normParameters", "", 100, 0, 2);
// trackSameAll->Dump();
TAxis* multAxis = trackSameAll->GetAxis(3);
int multBinBegin = 1;
int multBinEnd = multAxis->GetNbins();
if (mCentralityMin < mCentralityMax) {
multBinBegin = multAxis->FindBin(mCentralityMin);
multBinEnd = multAxis->FindBin(mCentralityMax);
}
for (Int_t multBin = TMath::Max(1, multBinBegin); multBin <= TMath::Min(multAxis->GetNbins(), multBinEnd); multBin++) {
trackSameAll->GetAxis(3)->SetRange(multBin, multBin);
trackMixedAll->GetAxis(3)->SetRange(multBin, multBin);
if (trackMixedAllStep6) {
trackMixedAllStep6->GetAxis(3)->SetRange(multBin, multBin);
}
Double_t mixedNorm = 1;
Double_t mixedNormError = 0;
if (!mSkipScaleMixedEvent) {
// get mixed normalization correction factor: is independent of vertex bin if scaled with number of triggers
TH2* tracksMixed = nullptr;
if (trackMixedAllStep6) {
trackMixedAllStep6->GetAxis(2)->SetRange(0, -1);
tracksMixed = trackMixedAllStep6->Projection(1, 0, "E");
} else {
trackMixedAll->GetAxis(2)->SetRange(0, -1);
tracksMixed = trackMixedAll->Projection(1, 0, "E");
}
// Printf("%f", tracksMixed->Integral());
Float_t binWidthEta = tracksMixed->GetYaxis()->GetBinWidth(1);
if (stepForMixed == -1 && step == kCFStepBiasStudy && !trackMixedAllStep6) {
// get mixed event normalization by assuming full acceptance at deta at 0 (integrate over dphi), excluding (0, 0)
Float_t phiExclude = 0.41;
mixedNorm = tracksMixed->IntegralAndError(1, tracksMixed->GetXaxis()->FindBin(-phiExclude) - 1, tracksMixed->GetYaxis()->FindBin(-0.01), tracksMixed->GetYaxis()->FindBin(0.01), mixedNormError);
Double_t mixedNormError2 = 0;
Double_t mixedNorm2 = tracksMixed->IntegralAndError(tracksMixed->GetXaxis()->FindBin(phiExclude) + 1, tracksMixed->GetNbinsX(), tracksMixed->GetYaxis()->FindBin(-0.01), tracksMixed->GetYaxis()->FindBin(0.01), mixedNormError2);
if (mixedNormError == 0 || mixedNormError2 == 0) {
LOGF(error, "ERROR: Skipping multiplicity %d because mixed event is empty %f %f %f %f", multBin, mixedNorm, mixedNormError, mixedNorm2, mixedNormError2);
continue;
}
Int_t nBinsMixedNorm = (tracksMixed->GetXaxis()->FindBin(-phiExclude) - 1 - 1 + 1) * (tracksMixed->GetYaxis()->FindBin(0.01) - tracksMixed->GetYaxis()->FindBin(-0.01) + 1);
mixedNorm /= nBinsMixedNorm;
mixedNormError /= nBinsMixedNorm;
Int_t nBinsMixedNorm2 = (tracksMixed->GetNbinsX() - tracksMixed->GetXaxis()->FindBin(phiExclude) - 1 + 1) * (tracksMixed->GetYaxis()->FindBin(0.01) - tracksMixed->GetYaxis()->FindBin(-0.01) + 1);
mixedNorm2 /= nBinsMixedNorm2;
mixedNormError2 /= nBinsMixedNorm2;
mixedNorm = mixedNorm / mixedNormError / mixedNormError + mixedNorm2 / mixedNormError2 / mixedNormError2;
mixedNormError = TMath::Sqrt(1.0 / (1.0 / mixedNormError / mixedNormError + 1.0 / mixedNormError2 / mixedNormError2));
mixedNorm *= mixedNormError * mixedNormError;
} else {
// get mixed event normalization at (0,0)
// NOTE if variable bin size is used around (0,0) to reduce two-track effect to limited bins, the normalization gets a bit tricky here (finite bin correction and normalization are made only for fixed size bins).
// The normalization factor has to determined in a bin as large as the normal bin size, as a proxy the bin with index (1, 1) is used
Float_t binWidthPhi = tracksMixed->GetXaxis()->GetBinWidth(1);
mixedNorm = tracksMixed->IntegralAndError(tracksMixed->GetXaxis()->FindBin(-binWidthPhi + 1e-4), tracksMixed->GetXaxis()->FindBin(binWidthPhi - 1e-4), tracksMixed->GetYaxis()->FindBin(-binWidthEta + 1e-4), tracksMixed->GetYaxis()->FindBin(binWidthEta - 1e-4), mixedNormError);
Int_t nBinsMixedNorm = 4; // NOTE this is fixed on purpose, even if binning is made finer around (0,0), this corresponds to the equivalent of four "large" bins around (0,0)
mixedNorm /= nBinsMixedNorm;
mixedNormError /= nBinsMixedNorm;
if (mixedNormError == 0) {
LOGF(error, "ERROR: Skipping multiplicity %d because mixed event is empty %f %f", multBin, mixedNorm, mixedNormError);
continue;
}
}
// finite bin correction
if (mTrackEtaCut > 0) {
Double_t finiteBinCorrection = -1.0 / (2 * mTrackEtaCut) * binWidthEta / 2 + 1;
LOGF(info, "Finite bin correction: %f", finiteBinCorrection);
mixedNorm /= finiteBinCorrection;
mixedNormError /= finiteBinCorrection;
} else {
LOGF(error, "ERROR: mTrackEtaCut not set. Finite bin correction cannot be applied. Continuing anyway...");
}
Float_t triggers = eventMixedAll->Integral(1, eventMixedAll->GetNbinsX(), multBin, multBin);
// Printf("%f +- %f | %f | %f", mixedNorm, mixedNormError, triggers, mixedNorm / triggers);
if (triggers <= 0) {
LOGF(error, "ERROR: Skipping multiplicity %d because mixed event is empty", multBin);
continue;
}
mixedNorm /= triggers;
mixedNormError /= triggers;
delete tracksMixed;
} else {
LOGF(warning, "WARNING: Skipping mixed-event scaling! mSkipScaleMixedEvent IS set!");
}
if (mixedNorm <= 0) {
LOGF(error, "ERROR: Skipping multiplicity %d because mixed event is empty at (0,0)", multBin);
continue;
}
// Printf("Norm: %f +- %f", mixedNorm, mixedNormError);
// normParameters->Fill(mixedNorm);
TAxis* vertexAxis = trackSameAll->GetAxis(2);
Int_t vertexBinBegin = 1;
Int_t vertexBinEnd = vertexAxis->GetNbins();
if (mZVtxMax > mZVtxMin) {
vertexBinBegin = vertexAxis->FindBin(mZVtxMin);
vertexBinEnd = vertexAxis->FindBin(mZVtxMax);
}
for (Int_t vertexBin = vertexBinBegin; vertexBin <= vertexBinEnd; vertexBin++) {
trackSameAll->GetAxis(2)->SetRange(vertexBin, vertexBin);
trackMixedAll->GetAxis(2)->SetRange(vertexBin, vertexBin);
TH2* tracksSame = trackSameAll->Projection(1, 0, "E");
TH2* tracksMixed = trackMixedAll->Projection(1, 0, "E");
// asssume flat in dphi, gain in statistics
// TH1* histMixedproj = mixedTwoD->ProjectionY();
// histMixedproj->Scale(1.0 / mixedTwoD->GetNbinsX());
//
// for (Int_t x=1; x<=mixedTwoD->GetNbinsX(); x++)
// for (Int_t y=1; y<=mixedTwoD->GetNbinsY(); y++)
// mixedTwoD->SetBinContent(x, y, histMixedproj->GetBinContent(y));
// delete histMixedproj;
Float_t triggers2 = eventMixedAll->Integral(vertexBin, vertexBin, multBin, multBin);
if (triggers2 <= 0) {
LOGF(error, "ERROR: Skipping multiplicity %d vertex bin %d because mixed event is empty", multBin, vertexBin);
} else {
if (!mSkipScaleMixedEvent) {
tracksMixed->Scale(1.0 / triggers2 / mixedNorm);
} else if (tracksMixed->Integral() > 0) {
tracksMixed->Scale(1.0 / tracksMixed->Integral());
}
// tracksSame->Scale(tracksMixed->Integral() / tracksSame->Integral());
// new TCanvas; tracksSame->DrawClone("SURF1");
// new TCanvas; tracksMixed->DrawClone("SURF1");
// some code to judge the relative contribution of the different correlation functions to the overall uncertainty
Double_t sums[] = {0, 0, 0};
Double_t errors[] = {0, 0, 0};
Int_t checkBinYBegin = 1; // tracksSame->GetXaxis()->FindBin(-0.79);
Int_t checkBinYEnd = tracksSame->GetNbinsY(); // tracksSame->GetXaxis()->FindBin(0.79);
for (Int_t x = 1; x <= tracksSame->GetNbinsX(); x++) {
for (Int_t y = checkBinYBegin; y <= checkBinYEnd; y++) {
sums[0] += tracksSame->GetBinContent(x, y);
errors[0] += tracksSame->GetBinError(x, y);
sums[1] += tracksMixed->GetBinContent(x, y);
errors[1] += tracksMixed->GetBinError(x, y);
}
}
tracksSame->Divide(tracksMixed);
for (Int_t x = 1; x <= tracksSame->GetNbinsX(); x++) {
for (Int_t y = checkBinYBegin; y <= checkBinYEnd; y++) {
sums[2] += tracksSame->GetBinContent(x, y);
errors[2] += tracksSame->GetBinError(x, y);
}
}
for (Int_t x = 0; x < 3; x++) {
if (sums[x] > 0) {
errors[x] /= sums[x];
}
}
LOGF(info, "The correlation function %d %d has uncertainties %f %f %f (Ratio S/M %f)", multBin, vertexBin, errors[0], errors[1], errors[2], (errors[1] > 0) ? errors[0] / errors[1] : -1);
// code to draw contributions
/*
TH1* proj = tracksSame->ProjectionX("projx", tracksSame->GetYaxis()->FindBin(-1.59), tracksSame->GetYaxis()->FindBin(1.59));
proj->SetTitle(Form("Bin %d", vertexBin));
proj->SetLineColor(vertexBin);
proj->DrawCopy((vertexBin > 1) ? "SAME" : "");
*/
if (!totalTracks) {
totalTracks = (TH2*)tracksSame->Clone("totalTracks");
} else {
totalTracks->Add(tracksSame);
}
totalEvents += eventSameAll->GetBinContent(vertexBin, multBin);
// new TCanvas; tracksMixed->DrawCopy("SURF1");
}
delete tracksSame;
delete tracksMixed;
nCorrelationFunctions++;
}
}
if (totalTracks) {
Double_t sums[] = {0, 0, 0};
Double_t errors[] = {0, 0, 0};
for (Int_t x = 1; x <= totalTracks->GetNbinsX(); x++) {
for (Int_t y = 1; y <= totalTracks->GetNbinsY(); y++) {
sums[0] += totalTracks->GetBinContent(x, y);
errors[0] += totalTracks->GetBinError(x, y);
}
}
if (sums[0] > 0) {
errors[0] /= sums[0];
}
if (normalizePerTrigger) {
LOGF(info, "Dividing %f tracks by %lld events (%d correlation function(s)) (error %f)", totalTracks->Integral(), totalEvents, nCorrelationFunctions, errors[0]);
if (totalEvents > 0) {
totalTracks->Scale(1.0 / totalEvents);
}
}
if (trigger != nullptr) {
*trigger = (Int_t)totalEvents;
}
// normalizate to dphi width
Float_t normalization = totalTracks->GetXaxis()->GetBinWidth(1);
totalTracks->Scale(1.0 / normalization);
}
delete trackSameAll;
delete trackMixedAll;
delete trackMixedAllStep6;
delete eventSameAll;
delete eventMixedAll;
delete eventMixedAllStep6;
// new TCanvas; normParameters->Draw();
TH1::AddDirectory(oldStatus);
return totalTracks;
}
TH1* CorrelationContainer::getTriggersAsFunctionOfMultiplicity(CorrelationContainer::CFStep step, Float_t ptTriggerMin, Float_t ptTriggerMax)
{
// returns the distribution of triggers as function of centrality/multiplicity
resetBinLimits(mTriggerHist->getTHn(step), 3);
Int_t firstBin = mTriggerHist->getTHn(step)->GetAxis(0)->FindBin(ptTriggerMin);
Int_t lastBin = mTriggerHist->getTHn(step)->GetAxis(0)->FindBin(ptTriggerMax);
LOGF(info, "Using pT range %d --> %d", firstBin, lastBin);
mTriggerHist->getTHn(step)->GetAxis(0)->SetRange(firstBin, lastBin);
if (mZVtxMax > mZVtxMin) {
mTriggerHist->getTHn(step)->GetAxis(2)->SetRangeUser(mZVtxMin, mZVtxMax);
LOGF(info, "Restricting z-vtx: %f-%f", mZVtxMin, mZVtxMax);
}
TH1* eventHist = mTriggerHist->getTHn(step)->Projection(1);
resetBinLimits(mTriggerHist->getTHn(step), 3);
return eventHist;
}
THnBase* CorrelationContainer::getTrackEfficiencyND(EfficiencyStep step1, EfficiencyStep step2)
{
// creates a track-level efficiency by dividing step2 by step1
// in all dimensions but the particle species one
StepTHn* sourceContainer = mTrackHistEfficiency;
resetBinLimits(sourceContainer->getTHn(step1));
resetBinLimits(sourceContainer->getTHn(step2));
if (mEtaMax > mEtaMin) {
LOGF(info, "Restricted eta-range to %f %f", mEtaMin, mEtaMax);
sourceContainer->getTHn(step1)->GetAxis(0)->SetRangeUser(mEtaMin, mEtaMax);
sourceContainer->getTHn(step2)->GetAxis(0)->SetRangeUser(mEtaMin, mEtaMax);
}
Int_t dimensions[] = {0, 1, 3, 4};
THnBase* generated = sourceContainer->getTHn(step1)->ProjectionND(4, dimensions);
THnBase* measured = sourceContainer->getTHn(step2)->ProjectionND(4, dimensions);
// Printf("%d %d %f %f", step1, step2, generated->GetEntries(), measured->GetEntries());
resetBinLimits(sourceContainer->getTHn(step1));
resetBinLimits(sourceContainer->getTHn(step2));
THnBase* clone = (THnBase*)measured->Clone();
clone->Divide(measured, generated, 1, 1, "B");
delete generated;
delete measured;
return clone;
}
//____________________________________________________________________
TH1* CorrelationContainer::getTrackEfficiency(EfficiencyStep step1, EfficiencyStep step2, Int_t axis1, Int_t axis2, Int_t source, Int_t axis3)
{
// creates a track-level efficiency by dividing step2 by step1
// projected to axis1 and axis2 (optional if >= 0)
//
// source: 1 = mTrackHistEfficiency; 2 = mTrackHistEfficiency rebinned for pT,T / pT,lead binning
// cache it for efficiency (usually more than one efficiency is requested)
StepTHn* sourceContainer = nullptr;
if (source == 1 || source == 2) {
sourceContainer = mTrackHistEfficiency;
} else {
return nullptr;
}
// reset all limits and set the right ones except those in axis1, axis2 and axis3
resetBinLimits(sourceContainer->getTHn(step1));
resetBinLimits(sourceContainer->getTHn(step2));
if (mEtaMax > mEtaMin && axis1 != 0 && axis2 != 0 && axis3 != 0) {
LOGF(info, "Restricted eta-range to %f %f", mEtaMin, mEtaMax);
sourceContainer->getTHn(step1)->GetAxis(0)->SetRangeUser(mEtaMin, mEtaMax);
sourceContainer->getTHn(step2)->GetAxis(0)->SetRangeUser(mEtaMin, mEtaMax);
}
if (mPtMax > mPtMin && axis1 != 1 && axis2 != 1 && axis3 != 1) {
LOGF(info, "Restricted pt-range to %f %f", mPtMin, mPtMax);
sourceContainer->getTHn(step1)->GetAxis(1)->SetRangeUser(mPtMin, mPtMax);
sourceContainer->getTHn(step2)->GetAxis(1)->SetRangeUser(mPtMin, mPtMax);
}
if (mPartSpecies != -1 && axis1 != 2 && axis2 != 2 && axis3 != 2) {
LOGF(info, "Restricted to particle species %d", mPartSpecies);
sourceContainer->getTHn(step1)->GetAxis(2)->SetRangeUser(mPartSpecies, mPartSpecies);
sourceContainer->getTHn(step2)->GetAxis(2)->SetRangeUser(mPartSpecies, mPartSpecies);
}
if (mCentralityMax > mCentralityMin && axis1 != 3 && axis2 != 3 && axis3 != 3) {
LOGF(info, "Restricted centrality range to %f %f", mCentralityMin, mCentralityMax);
sourceContainer->getTHn(step1)->GetAxis(3)->SetRangeUser(mCentralityMin, mCentralityMax);
sourceContainer->getTHn(step2)->GetAxis(3)->SetRangeUser(mCentralityMin, mCentralityMax);
}
if (mZVtxMax > mZVtxMin && axis1 != 4 && axis2 != 4 && axis3 != 4) {
LOGF(info, "Restricted z-vtx range to %f %f", mZVtxMin, mZVtxMax);
sourceContainer->getTHn(step1)->GetAxis(4)->SetRangeUser(mZVtxMin, mZVtxMax);
sourceContainer->getTHn(step2)->GetAxis(4)->SetRangeUser(mZVtxMin, mZVtxMax);
}
TH1* measured = nullptr;
TH1* generated = nullptr;
if (axis3 >= 0) {
generated = sourceContainer->getTHn(step1)->Projection(axis1, axis2, axis3);
measured = sourceContainer->getTHn(step2)->Projection(axis1, axis2, axis3);
} else if (axis2 >= 0) {
generated = sourceContainer->getTHn(step1)->Projection(axis2, axis1); // NOTE the syntax is Projection(Y, X)
measured = sourceContainer->getTHn(step2)->Projection(axis2, axis1); // NOTE the syntax is Projection(Y, X)
} else {
generated = sourceContainer->getTHn(step1)->Projection(axis1);
measured = sourceContainer->getTHn(step2)->Projection(axis1);
}
// check for bins with less than 50 entries, print warning
Int_t binBegin[3];
Int_t binEnd[3];
binBegin[0] = 1;
binBegin[1] = 1;
binBegin[2] = 1;
binEnd[0] = generated->GetNbinsX();
binEnd[1] = generated->GetNbinsY();
binEnd[2] = generated->GetNbinsZ();
if (mEtaMax > mEtaMin) {
if (axis1 == 0) {
binBegin[0] = generated->GetXaxis()->FindBin(mEtaMin);
binEnd[0] = generated->GetXaxis()->FindBin(mEtaMax);
}
if (axis2 == 0) {
binBegin[1] = generated->GetYaxis()->FindBin(mEtaMin);
binEnd[1] = generated->GetYaxis()->FindBin(mEtaMax);
}
if (axis3 == 0) {
binBegin[2] = generated->GetZaxis()->FindBin(mEtaMin);
binEnd[2] = generated->GetZaxis()->FindBin(mEtaMax);
}
}
if (mPtMax > mPtMin) {
// TODO this is just checking up to 15 for now
Float_t ptMax = TMath::Min((Float_t)15., mPtMax);
if (axis1 == 1) {
binBegin[0] = generated->GetXaxis()->FindBin(mPtMin);
binEnd[0] = generated->GetXaxis()->FindBin(ptMax);
}
if (axis2 == 1) {
binBegin[1] = generated->GetYaxis()->FindBin(mPtMin);
binEnd[1] = generated->GetYaxis()->FindBin(ptMax);
}
if (axis3 == 1) {
binBegin[2] = generated->GetZaxis()->FindBin(mPtMin);
binEnd[2] = generated->GetZaxis()->FindBin(ptMax);
}
}
Int_t total = 0;
Int_t count = 0;
Int_t vars[3];
for (Int_t i = 0; i < 3; i++) {
vars[i] = binBegin[i];
}
const Int_t limit = 50;
while (1) {
if (generated->GetDimension() == 1 && generated->GetBinContent(vars[0]) < limit) {
LOGF(info, "Empty bin at %s=%.2f (%.2f entries)", generated->GetXaxis()->GetTitle(), generated->GetXaxis()->GetBinCenter(vars[0]), generated->GetBinContent(vars[0]));
count++;
} else if (generated->GetDimension() == 2 && generated->GetBinContent(vars[0], vars[1]) < limit) {
LOGF(info, "Empty bin at %s=%.2f %s=%.2f (%.2f entries)",
generated->GetXaxis()->GetTitle(), generated->GetXaxis()->GetBinCenter(vars[0]),
generated->GetYaxis()->GetTitle(), generated->GetYaxis()->GetBinCenter(vars[1]),
generated->GetBinContent(vars[0], vars[1]));
count++;
} else if (generated->GetDimension() == 3 && generated->GetBinContent(vars[0], vars[1], vars[2]) < limit) {
LOGF(info, "Empty bin at %s=%.2f %s=%.2f %s=%.2f (%.2f entries)",
generated->GetXaxis()->GetTitle(), generated->GetXaxis()->GetBinCenter(vars[0]),
generated->GetYaxis()->GetTitle(), generated->GetYaxis()->GetBinCenter(vars[1]),
generated->GetZaxis()->GetTitle(), generated->GetZaxis()->GetBinCenter(vars[2]),
generated->GetBinContent(vars[0], vars[1], vars[2]));
count++;
}
vars[2]++;
if (vars[2] == binEnd[2] + 1) {
vars[2] = binBegin[2];
vars[1]++;
}
if (vars[1] == binEnd[1] + 1) {
vars[1] = binBegin[1];
vars[0]++;
}
if (vars[0] == binEnd[0] + 1) {
break;
}
total++;
}
LOGF(info, "Correction has %d empty bins (out of %d bins)", count, total);
// rebin if required