Skip to content

Commit 40defa1

Browse files
authored
PWFCF: minor fixed here and there (#8076)
1 parent c5dfb83 commit 40defa1

1 file changed

Lines changed: 68 additions & 56 deletions

File tree

PWGCF/MultiparticleCorrelations/Core/MuPa-MemberFunctions.h

Lines changed: 68 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ void DefaultBinning()
880880
void InitializeFixedLengthBins(eAsFunctionOf AFO)
881881
{
882882
// This is a helper function to suppress code bloat in DefaultBinning().
883-
// In merely initalize res.fResultsProFixedLengthBins[...] from corresponding configurables + a few other minor thingies.
883+
// It merely initalizes res.fResultsProFixedLengthBins[...] from corresponding configurables + a few other minor thingies.
884884

885885
if (tc.fVerbose) {
886886
LOGF(info, "\033[1;32m%s\033[0m", __FUNCTION__);
@@ -891,16 +891,17 @@ void InitializeFixedLengthBins(eAsFunctionOf AFO)
891891

892892
switch (AFO) {
893893
case AFO_MULTIPLICITY:
894-
lFixedLength_bins = (vector<float>)cf_res.cfFixedLength_mult_bins;
894+
// lFixedLength_bins = (vector<float>)cf_res.cfFixedLength_mult_bins; // this works as well, but it requires casting
895+
lFixedLength_bins = cf_res.cfFixedLength_mult_bins.value;
895896
break;
896897
case AFO_CENTRALITY:
897-
lFixedLength_bins = (vector<float>)cf_res.cfFixedLength_cent_bins;
898+
lFixedLength_bins = cf_res.cfFixedLength_cent_bins.value;
898899
break;
899900
case AFO_PT:
900-
lFixedLength_bins = (vector<float>)cf_res.cfFixedLength_pt_bins;
901+
lFixedLength_bins = cf_res.cfFixedLength_pt_bins.value;
901902
break;
902903
case AFO_ETA:
903-
lFixedLength_bins = (vector<float>)cf_res.cfFixedLength_eta_bins;
904+
lFixedLength_bins = cf_res.cfFixedLength_eta_bins.value;
904905
break;
905906
// ...
906907
default:
@@ -930,7 +931,7 @@ void InitializeFixedLengthBins(eAsFunctionOf AFO)
930931
void InitializeVariableLengthBins(eAsFunctionOf AFO)
931932
{
932933
// This is a helper function to suppress code bloat in DefaultBinning().
933-
// In merely initalize res.fResultsProVariableLengthBins[...] from corresponding configurables + a few other minor thingies.
934+
// It merely initalizes res.fResultsProVariableLengthBins[...] from corresponding configurables + a few other minor thingies.
934935

935936
if (tc.fVerbose) {
936937
LOGF(info, "\033[1;32m%s\033[0m", __FUNCTION__);
@@ -941,16 +942,17 @@ void InitializeVariableLengthBins(eAsFunctionOf AFO)
941942

942943
switch (AFO) {
943944
case AFO_MULTIPLICITY:
944-
lVariableLength_bins = (vector<float>)cf_res.cfVariableLength_mult_bins;
945+
// lVariableLength_bins = (vector<float>)cf_res.cfVariableLength_mult_bins; // this works as well, but it requires casting
946+
lVariableLength_bins = cf_res.cfVariableLength_mult_bins.value;
945947
break;
946948
case AFO_CENTRALITY:
947-
lVariableLength_bins = (vector<float>)cf_res.cfVariableLength_cent_bins;
949+
lVariableLength_bins = cf_res.cfVariableLength_cent_bins.value;
948950
break;
949951
case AFO_PT:
950-
lVariableLength_bins = (vector<float>)cf_res.cfVariableLength_pt_bins;
952+
lVariableLength_bins = cf_res.cfVariableLength_pt_bins.value;
951953
break;
952954
case AFO_ETA:
953-
lVariableLength_bins = (vector<float>)cf_res.cfVariableLength_eta_bins;
955+
lVariableLength_bins = cf_res.cfVariableLength_eta_bins.value;
954956
break;
955957
// ...
956958
default:
@@ -2417,8 +2419,7 @@ void BookNestedLoopsHistograms()
24172419
nl.fNestedLoopsPro[k][n][v]->SetTitle(Form("#LT#LTcos[%s(%s)]#GT#GT", 1 == n + 1 ? "" : Form("%d", n + 1), oVariable[k].Data()));
24182420
nl.fNestedLoopsPro[k][n][v]->SetStats(kFALSE);
24192421
nl.fNestedLoopsPro[k][n][v]->Sumw2();
2420-
nl.fNestedLoopsPro[k][n][v]->GetXaxis()->SetTitle(
2421-
res.fResultsProXaxisTitle[v].Data());
2422+
nl.fNestedLoopsPro[k][n][v]->GetXaxis()->SetTitle(res.fResultsProXaxisTitle[v].Data());
24222423

24232424
/*
24242425
if(fUseFixedNumberOfRandomlySelectedTracks && 1==v) // just a warning
@@ -6651,7 +6652,8 @@ void SetDiffWeightsHist(TH1D* const hist, eDiffWeights whichDiffWeight, Int_t bi
66516652
pw.fDiffWeightsHist[whichDiffWeight][bin]->GetYaxis()->SetTitle(sWeights[whichDiffWeight].Data());
66526653
pw.fDiffWeightsHist[whichDiffWeight][bin]->SetFillColor(eFillColor);
66536654
pw.fDiffWeightsHist[whichDiffWeight][bin]->SetLineColor(eColor);
6654-
pw.fWeightsList->Add(pw.fDiffWeightsHist[whichDiffWeight][bin]);
6655+
pw.fWeightsList->Add(pw.fDiffWeightsHist[whichDiffWeight][bin]); // This is working at the moment, because I am fetching all weights in Preprocess(), which is called after init()
6656+
// But if eventually it will be possible to fetch run number programatically in init(), I will have to re-think this line.
66556657

66566658
// Flag:
66576659
if (!pw.fUseDiffWeights[whichDiffWeight]) // yes, set it only once to kTRUE, for all bins
@@ -6690,6 +6692,9 @@ TH1D* GetHistogramWithWeights(const char* filePath, const char* runNumber, const
66906692
// Nevertheless, I could switch to enums and make it more general, i.e. I could introduce additional data members and configurables,
66916693
// for the names of histograms with weights. Like I did it in void GetHistogramWithCustomNUA(const char* filePath, eNUAPDF variable)
66926694

6695+
// TBI 20241021 Strictly speaking, I do not need to pass here first 2 arguments, "filePath" and "runNumber", because they are initialized at call from data members.
6696+
// But since this function is called only once, it's not an important performance loss. But re-think the design here eventually.
6697+
66936698
// a) Return value;
66946699
// b) Basic protection for arguments;
66956700
// c) Determine from filePath if the file in on a local machine, or in AliEn, or in CCDB;
@@ -6865,7 +6870,7 @@ TH1D* GetHistogramWithWeights(const char* filePath, const char* runNumber, const
68656870
LOGF(fatal, "\033[1;31m%s at line %d\033[0m", __FUNCTION__, __LINE__);
68666871
}
68676872
hist->SetDirectory(0);
6868-
hist->SetTitle(Form("%s, %s", filePath, runNumber));
6873+
hist->SetTitle(Form("%s, %s", filePath, runNumber)); // I have to do it here, because only here I have "filePath" av
68696874

68706875
} else {
68716876
// Differential weights:
@@ -6886,17 +6891,57 @@ TH1D* GetHistogramWithWeights(const char* filePath, const char* runNumber, const
68866891
listWithRuns->ls();
68876892
LOGF(fatal, "\033[1;31m%s at line %d\033[0m", __FUNCTION__, __LINE__);
68886893
}
6889-
hist->SetDirectory(0);
68906894

6895+
// *) insanity check for differential weights => check if boundaries of current bin are the same as bin boundaries for which these weights were calculated.
6896+
// This way I ensure that weights correspond to same kinematic cuts and binning as in current analysis.
6897+
// Current example format which was set in MakeWeights.C: someString(s), min < kinematic-variable-name < max
6898+
// Algorithm: IFS is " " and I take (N-1)th and (N-5)th entry:
6899+
TObjArray* oa = TString(hist->GetTitle()).Tokenize(" ");
6900+
if (!oa) {
6901+
LOGF(fatal, "in function \033[1;31m%s at line %d \n hist->GetTitle() = %s\033[0m", __FUNCTION__, __LINE__, hist->GetTitle());
6902+
}
6903+
Int_t nEntries = oa->GetEntries();
6904+
6905+
// I need to figure out corresponding variable from results histograms and its formatting:
6906+
eAsFunctionOf AFO = eAsFunctionOf_N;
6907+
const char* lVariableName = "";
68916908
if (TString(variable).EqualTo("phipt")) {
6892-
hist->SetTitle(Form("%s, %.2f < p_{T} < %.2f", filePath, res.fResultsProVariableLengthBins[AFO_PT]->At(bin), res.fResultsProVariableLengthBins[AFO_PT]->At(bin + 1)));
6909+
AFO = AFO_PT;
6910+
lVariableName = FancyFormatting("Pt");
6911+
} else if (TString(variable).EqualTo("phieta")) {
6912+
AFO = AFO_ETA;
6913+
lVariableName = FancyFormatting("Eta");
6914+
} else {
6915+
LOGF(fatal, "\033[1;31m%s at line %d : name = %s is not supported yet. \033[0m", __FUNCTION__, __LINE__, static_cast<string>(variable));
68936916
}
6894-
if (TString(variable).EqualTo("phieta")) {
6895-
hist->SetTitle(Form("%s, %.2f < #eta < %.2f", filePath, res.fResultsProVariableLengthBins[AFO_ETA]->At(bin), res.fResultsProVariableLengthBins[AFO_ETA]->At(bin + 1)));
6917+
6918+
// Get min and max value for bin, stored locally:
6919+
Float_t min = res.fResultsPro[AFO]->GetBinLowEdge(bin + 1);
6920+
Float_t max = res.fResultsPro[AFO]->GetBinLowEdge(bin + 2);
6921+
if (min > max) {
6922+
LOGF(fatal, "\033[1;33m min = %f, max = %f, res.fResultsPro[AFO]->GetName() = %s\033[0m", min, max, res.fResultsPro[AFO]->GetName());
6923+
}
6924+
6925+
// Compare with min and max value store in external weights.root file using MakeWeights.C:
6926+
if (!(TMath::Abs(TString(oa->At(nEntries - 1)->GetName()).Atof() - max) < 1.e-6)) {
6927+
LOGF(info, "\033[1;33m hist->GetTitle() = %s, res.fResultsPro[AFO]->GetName() = %s\033[0m", hist->GetTitle(), res.fResultsPro[AFO]->GetName());
6928+
LOGF(fatal, "in function \033[1;31m%s at line %d : mismatch in upper bin boundaries \n from title = %f , local = %f\033[0m", __FUNCTION__, __LINE__, TString(oa->At(nEntries - 1)->GetName()).Atof(), max);
68966929
}
6930+
if (!(TMath::Abs(TString(oa->At(nEntries - 5)->GetName()).Atof() - min) < 1.e-6)) {
6931+
LOGF(info, "\033[1;33m hist->GetTitle() = %s, res.fResultsPro[AFO]->GetName() = %s\033[0m", hist->GetTitle(), res.fResultsPro[AFO]->GetName());
6932+
LOGF(fatal, "in function \033[1;31m%s at line %d : mismatch in lower bin boundaries \n from title = %f , local = %f\033[0m", __FUNCTION__, __LINE__, TString(oa->At(nEntries - 5)->GetName()).Atof(), min);
6933+
}
6934+
delete oa; // yes, otherwise it's a memory leak
6935+
6936+
// *) final settings and cosmetics:
6937+
hist->SetDirectory(0);
6938+
hist->SetTitle(Form("%s, %.2f < %s < %.2f", filePath, min, lVariableName, max));
68976939

68986940
} // else
68996941

6942+
// TBI 20241021 if I need to split hist title across two lines, use this technique:
6943+
// hist->SetTitle(Form("#splitline{#scale[0.6]{%s}}{#scale[0.4]{%s}}",hist->GetTitle(),filePath));
6944+
69006945
return hist;
69016946

69026947
} // TH1D* GetHistogramWithWeights(const char* filePath, const char* runNumber, const char* variable, Int_t bin = -1)
@@ -7517,12 +7562,12 @@ void GetParticleWeights()
75177562
// *) check if particles in this pt bin survive particle cuts in pt. If not, skip this bin, because for that pt bin weights are simply not available:
75187563
if (!(res.fResultsPro[AFO_PT]->GetBinLowEdge(b + 2) > pc.fdParticleCuts[ePt][eMin])) {
75197564
// this branch protects against the case when I am e.g. in pt bin [0.0,0.2], and pt cut is 0.2 < pt < 5.0
7520-
LOGF(info, "\033[1;32m%s at line %d : you are requesting phi(pt) weight for pt bin = %d from (%f,%f), which is outside (below) pt phase space = (%f,%f). Skipping this bin. \033[0m", __FUNCTION__, __LINE__, b, res.fResultsPro[AFO_PT]->GetBinLowEdge(b + 1), res.fResultsPro[AFO_PT]->GetBinLowEdge(b + 2), pc.fdParticleCuts[ePt][eMin], pc.fdParticleCuts[ePt][eMax]);
7565+
LOGF(info, "\033[1;33m%s at line %d : you are requesting phi(pt) weight for pt bin = %d from (%f,%f), which is outside (below) pt phase space = (%f,%f). Skipping this bin. \033[0m", __FUNCTION__, __LINE__, b, res.fResultsPro[AFO_PT]->GetBinLowEdge(b + 1), res.fResultsPro[AFO_PT]->GetBinLowEdge(b + 2), pc.fdParticleCuts[ePt][eMin], pc.fdParticleCuts[ePt][eMax]);
75217566
continue;
75227567
}
75237568
if (!(res.fResultsPro[AFO_PT]->GetBinLowEdge(b + 1) < pc.fdParticleCuts[ePt][eMax])) {
75247569
// this branch protects against the case when I am e.g. in pt bin [5.0,10.0], and pt cut is 0.2 < pt < 5.0
7525-
LOGF(info, "\033[1;32m%s at line %d : you are requesting phi(pt) weight for pt bin = %d from (%f,%f), which is outside (above) pt phase space = (%f,%f). Skipping this bin. \033[0m", __FUNCTION__, __LINE__, b, res.fResultsPro[AFO_PT]->GetBinLowEdge(b + 1), res.fResultsPro[AFO_PT]->GetBinLowEdge(b + 2), pc.fdParticleCuts[ePt][eMin], pc.fdParticleCuts[ePt][eMax]);
7570+
LOGF(info, "\033[1;33m%s at line %d : you are requesting phi(pt) weight for pt bin = %d from (%f,%f), which is outside (above) pt phase space = (%f,%f). Skipping this bin. \033[0m", __FUNCTION__, __LINE__, b, res.fResultsPro[AFO_PT]->GetBinLowEdge(b + 1), res.fResultsPro[AFO_PT]->GetBinLowEdge(b + 2), pc.fdParticleCuts[ePt][eMin], pc.fdParticleCuts[ePt][eMax]);
75267571
continue;
75277572
}
75287573

@@ -7532,23 +7577,6 @@ void GetParticleWeights()
75327577
LOGF(fatal, "\033[1;31m%s at line %d : phiptWeights is NULL. Check the external file %s with particle weights\033[0m", __FUNCTION__, __LINE__, pw.fFileWithWeights.Data());
75337578
}
75347579

7535-
// *) insanity check for differential weights => check if boundaries of current bin b are the same as bin boundaries for which these weights were calculated.
7536-
// This way I ensure that weights correspond to same kinematic cuts and binning as in current analysis.
7537-
// Current example format: <somePath>/weightsO2.root, 0.20 < p_{T} < 0.30
7538-
// Algorithm: IFS is " ", and I take (N-1)th and (N-5)th entry:
7539-
TObjArray* oa = TString(phiptWeights->GetTitle()).Tokenize(" ");
7540-
if (!oa) {
7541-
LOGF(fatal, "in function \033[1;31m%s at line %d \n phiptWeights->GetTitle() = %s\033[0m", __FUNCTION__, __LINE__, phiptWeights->GetTitle());
7542-
}
7543-
Int_t nEntries = oa->GetEntries();
7544-
if (!(TMath::Abs(TString(oa->At(nEntries - 1)->GetName()).Atof() - res.fResultsPro[AFO_PT]->GetBinLowEdge(b + 2)) < 1.e-6)) {
7545-
LOGF(fatal, "in function \033[1;31m%s at line %d : mismatch in upper bin boundaries \n from title = %f , local = %f\033[0m", __FUNCTION__, __LINE__, TString(oa->At(nEntries - 1)->GetName()).Atof(), res.fResultsPro[AFO_PT]->GetBinLowEdge(b + 2));
7546-
}
7547-
if (!(TMath::Abs(TString(oa->At(nEntries - 5)->GetName()).Atof() - res.fResultsPro[AFO_PT]->GetBinLowEdge(b + 1)) < 1.e-6)) {
7548-
LOGF(fatal, "in function \033[1;31m%s at line %d : mismatch in lower bin boundaries \n from title = %f , local = %f\033[0m", __FUNCTION__, __LINE__, TString(oa->At(nEntries - 5)->GetName()).Atof(), res.fResultsPro[AFO_PT]->GetBinLowEdge(b + 1));
7549-
}
7550-
delete oa; // yes, otherwise it's a memory leak
7551-
75527580
// *) okay, just use this histogram with weights:
75537581
SetDiffWeightsHist(phiptWeights, wPHIPT, b);
75547582
}
@@ -7563,12 +7591,12 @@ void GetParticleWeights()
75637591
// *) check if particles in this eta bin survive particle cuts in eta. If not, skip this bin, because for that eta bin weights are simply not available:
75647592
if (!(res.fResultsPro[AFO_ETA]->GetBinLowEdge(b + 2) > pc.fdParticleCuts[eEta][eMin])) {
75657593
// this branch protects against the case when I am e.g. in eta bin [-1.0,-0.8], and eta cut is -0.8 < eta < 0.8
7566-
LOGF(info, "\033[1;32m%s at line %d : you are requesting phi(eta) weight for eta bin = %d from (%f,%f), which is outside (below) eta phase space = (%f,%f). Skipping this bin. \033[0m", __FUNCTION__, __LINE__, b, res.fResultsPro[AFO_ETA]->GetBinLowEdge(b + 1), res.fResultsPro[AFO_ETA]->GetBinLowEdge(b + 2), pc.fdParticleCuts[eEta][eMin], pc.fdParticleCuts[eEta][eMax]);
7594+
LOGF(info, "\033[1;33m%s at line %d : you are requesting phi(eta) weight for eta bin = %d from (%f,%f), which is outside (below) eta phase space = (%f,%f). Skipping this bin. \033[0m", __FUNCTION__, __LINE__, b, res.fResultsPro[AFO_ETA]->GetBinLowEdge(b + 1), res.fResultsPro[AFO_ETA]->GetBinLowEdge(b + 2), pc.fdParticleCuts[eEta][eMin], pc.fdParticleCuts[eEta][eMax]);
75677595
continue;
75687596
}
75697597
if (!(res.fResultsPro[AFO_ETA]->GetBinLowEdge(b + 1) < pc.fdParticleCuts[eEta][eMax])) {
75707598
// this branch protects against the case when I am e.g. in eta bin [0.8,1.0], and eta cut is 0.8 < eta < 1.0
7571-
LOGF(info, "\033[1;32m%s at line %d : you are requesting phi(eta) weight for eta bin = %d from (%f,%f), which is outside (above) eta phase space = (%f,%f). Skipping this bin. \033[0m", __FUNCTION__, __LINE__, b, res.fResultsPro[AFO_ETA]->GetBinLowEdge(b + 1), res.fResultsPro[AFO_ETA]->GetBinLowEdge(b + 2), pc.fdParticleCuts[eEta][eMin], pc.fdParticleCuts[eEta][eMax]);
7599+
LOGF(info, "\033[1;33m%s at line %d : you are requesting phi(eta) weight for eta bin = %d from (%f,%f), which is outside (above) eta phase space = (%f,%f). Skipping this bin. \033[0m", __FUNCTION__, __LINE__, b, res.fResultsPro[AFO_ETA]->GetBinLowEdge(b + 1), res.fResultsPro[AFO_ETA]->GetBinLowEdge(b + 2), pc.fdParticleCuts[eEta][eMin], pc.fdParticleCuts[eEta][eMax]);
75727600
continue;
75737601
}
75747602

@@ -7578,23 +7606,6 @@ void GetParticleWeights()
75787606
LOGF(fatal, "\033[1;31m%s at line %d : phietaWeights is NULL. Check the external file %s with particle weights\033[0m", __FUNCTION__, __LINE__, pw.fFileWithWeights.Data());
75797607
}
75807608

7581-
// *) insanity check for differential weights => check if boundaries of current bin b are the same as bin boundaries for which these weights were calculated.
7582-
// This way I ensure that weights correspond to same kinematic cuts and binning as in current analysis.
7583-
// Current example format: <somePath>/weightsO2.root, -0.8 < #eta < -0.4
7584-
// Algorithm: IFS is " ", and I take (N-1)th and (N-5)th entry:
7585-
TObjArray* oa = TString(phietaWeights->GetTitle()).Tokenize(" ");
7586-
if (!oa) {
7587-
LOGF(fatal, "in function \033[1;31m%s at line %d \n phietaWeights->GetTitle() = %s\033[0m", __FUNCTION__, __LINE__, phietaWeights->GetTitle());
7588-
}
7589-
Int_t nEntries = oa->GetEntries();
7590-
if (!(TMath::Abs(TString(oa->At(nEntries - 1)->GetName()).Atof() - res.fResultsPro[AFO_ETA]->GetBinLowEdge(b + 2)) < 1.e-6)) {
7591-
LOGF(fatal, "in function \033[1;31m%s at line %d : mismatch in upper bin boundaries \n from title = %f , local = %f\033[0m", __FUNCTION__, __LINE__, TString(oa->At(nEntries - 1)->GetName()).Atof(), res.fResultsPro[AFO_ETA]->GetBinLowEdge(b + 2));
7592-
}
7593-
if (!(TMath::Abs(TString(oa->At(nEntries - 5)->GetName()).Atof() - res.fResultsPro[AFO_ETA]->GetBinLowEdge(b + 1)) < 1.e-6)) {
7594-
LOGF(fatal, "in function \033[1;31m%s at line %d : mismatch in lower bin boundaries \n from title = %f , local = %f\033[0m", __FUNCTION__, __LINE__, TString(oa->At(nEntries - 5)->GetName()).Atof(), res.fResultsPro[AFO_ETA]->GetBinLowEdge(b + 1));
7595-
}
7596-
delete oa; // yes, otherwise it's a memory leak
7597-
75987609
// *) okay, just use this histogram with weights:
75997610
SetDiffWeightsHist(phietaWeights, wPHIETA, b);
76007611
} // for(Int_t b=0; b<nEtaBins; b++) {
@@ -8769,6 +8780,7 @@ void Steer(T1 const& collision, T2 const& tracks)
87698780
if (tc.fDryRun) {
87708781
EventCounter(eFill);
87718782
EventCounter(ePrint);
8783+
Preprocess(collision); // yes, so that e.g. I can only test if the weights were correctly fetched from external file and initialized locally into data members
87728784
return;
87738785
}
87748786

0 commit comments

Comments
 (0)