Skip to content

Commit e53b7cf

Browse files
authored
[PWGCF] JCorran/Tasks: Added custom centrality binning for SPC analysis (#18784)
1 parent 8a6e896 commit e53b7cf

1 file changed

Lines changed: 61 additions & 3 deletions

File tree

‎PWGCF/JCorran/Tasks/flowJSPCAnalysis.cxx‎

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "Common/DataModel/TrackSelectionTables.h"
2828

2929
#include <Framework/AnalysisDataModel.h>
30+
#include <Framework/AnalysisHelpers.h>
3031
#include <Framework/AnalysisTask.h>
3132
#include <Framework/Configurable.h>
3233
#include <Framework/HistogramRegistry.h>
@@ -35,12 +36,14 @@
3536
#include <Framework/runDataProcessing.h>
3637

3738
#include <TFormula.h>
39+
#include <TTree.h>
3840

3941
#include <sys/types.h>
4042

4143
#include <algorithm>
4244
#include <array>
4345
#include <bit>
46+
#include <cstddef>
4447
#include <cstdint>
4548
#include <experimental/type_traits>
4649
#include <iterator>
@@ -64,6 +67,9 @@ using MyTracks = soa::Join<aod::Tracks, aod::TracksExtra, aod::TracksDCA, aod::J
6467

6568
struct flowJSPCAnalysis {
6669
HistogramRegistry spcHistograms{"SPCResults", {}, OutputObjHandlingPolicy::AnalysisObject, true, true};
70+
// One entry. Branch centBinEdges is the edge list; Centrality_i runs from centBinEdges[i] to centBinEdges[i + 1].
71+
OutputObj<TTree> centBinEdgeTree{"CentralityBinEdges", OutputObjHandlingPolicy::AnalysisObject};
72+
std::vector<float> centBinEdges;
6773
FlowJSPCAnalysis spcAnalysis;
6874
FlowJSPCAnalysis::JQVectorsT jqvecs;
6975
template <class T>
@@ -95,6 +101,10 @@ struct flowJSPCAnalysis {
95101
Configurable<int> cfgMultMin{"cfgMultMin", 10, "Minimum number of particles required for the event to have."};
96102
} cfgEventCuts;
97103

104+
// false: FlowJHistManager bins 0,5,10,20,30,40,50,60,70,100. true: cfgCustomCentBinEdges (at most 9 bins).
105+
Configurable<bool> cfgUseCustomCentBins{"cfgUseCustomCentBins", false, "Use cfgCustomCentBinEdges instead of the default centrality bins."};
106+
Configurable<std::vector<float>> cfgCustomCentBinEdges{"cfgCustomCentBinEdges", {0.f, 100.f}, "last edge inclusive, e.g. [0,100] or [0,20,40,60,100]"};
107+
98108
O2_DEFINE_CONFIGURABLE(cfgTrackBitMask, uint16_t, 0, "Track selection bitmask to use as defined in the filterCorrelations.cxx task");
99109
O2_DEFINE_CONFIGURABLE(cfgMultCorrelationsMask, uint16_t, 0, "Selection bitmask for the multiplicity correlations. This should match the filter selection cfgEstimatorBitMask.")
100110
O2_DEFINE_CONFIGURABLE(cfgMultCutFormula, std::string, "", "Multiplicity correlations cut formula. A result greater than zero results in accepted event. Parameters: [cFT0C] FT0C centrality, [mFV0A] V0A multiplicity, [mGlob] global track multiplicity, [mPV] PV track multiplicity, [cFT0M] FT0M centrality")
@@ -112,12 +122,50 @@ struct flowJSPCAnalysis {
112122
uint32_t mNhUse = FlowJSPCAnalysis::NhFull;
113123
uint32_t mNkUse = FlowJSPCAnalysis::NkFull;
114124

125+
// Bin index for cfgCustomCentBinEdges. Lower edges are inclusive; the last edge is inclusive. -1 if outside.
126+
int getCustomCentBin(float cValue) const
127+
{
128+
const auto& edges = cfgCustomCentBinEdges.value;
129+
const int nEdges = static_cast<int>(edges.size());
130+
if (nEdges < 2 || cValue < edges.front() || cValue > edges.back()) { // o2-linter: disable=magic-number (minimum edge count)
131+
return -1;
132+
}
133+
for (int i = 1; i < nEdges - 1; ++i) {
134+
if (cValue < edges[i]) {
135+
return i - 1;
136+
}
137+
}
138+
return nEdges - 2;
139+
}
140+
115141
void init(InitContext const&)
116142
{
143+
if (cfgUseCustomCentBins.value) {
144+
const auto& edges = cfgCustomCentBinEdges.value;
145+
if (edges.size() < 2 || edges.size() > 10) { // o2-linter: disable=magic-number (2 to 10 edges, at most 9 bins)
146+
LOGF(fatal, "cfgCustomCentBinEdges must contain 2 to 10 edges (at most 9 bins), got %zu.", edges.size());
147+
}
148+
for (std::size_t i = 1; i < edges.size(); ++i) {
149+
if (!(edges[i] > edges[i - 1])) {
150+
LOGF(fatal, "cfgCustomCentBinEdges must be strictly increasing.");
151+
}
152+
}
153+
LOGF(info, "Custom centrality bins in use (%zu bins).", edges.size() - 1);
154+
}
155+
117156
// Add histomanager here
118157
spcAnalysis.setHistRegistry(&spcHistograms);
119158
spcAnalysis.createHistos();
120159

160+
if (cfgUseCustomCentBins.value) {
161+
centBinEdges.assign(cfgCustomCentBinEdges.value.begin(), cfgCustomCentBinEdges.value.end());
162+
} else {
163+
centBinEdges = {0.f, 5.f, 10.f, 20.f, 30.f, 40.f, 50.f, 60.f, 70.f, 100.f};
164+
}
165+
centBinEdgeTree.setObject(new TTree("CentralityBinEdges", "Centrality bin edges"));
166+
centBinEdgeTree->Branch("centBinEdges", &centBinEdges);
167+
centBinEdgeTree->Fill();
168+
121169
spcObservables.setSPCObservables(cfgWhichSPC);
122170
spcAnalysis.setFullCorrSet(spcObservables.harmonicArray);
123171
spcAnalysis.qVectorGrid(cfgWhichSPC, mNhUse, mNkUse);
@@ -156,10 +204,20 @@ struct flowJSPCAnalysis {
156204
return;
157205

158206
float cent = collision.multiplicity();
159-
if (cent < 0. || cent > 100.) {
160-
return;
207+
int cBin = -1;
208+
if (!cfgUseCustomCentBins.value) {
209+
if (cent < 0. || cent > 100.) { // o2-linter: disable=magic-number (full centrality range)
210+
return;
211+
}
212+
cBin = histManager.getCentBin(cent);
213+
} else {
214+
cBin = getCustomCentBin(cent);
215+
// LOGF(info, "Centrality bin is %d for centrality %f", cBin, cent);
216+
if (cBin < 0 || cBin > 8) { // o2-linter: disable=magic-number (SPC histogram slots are 0-8)
217+
LOGF(info, "Centrality bin %d is out of range", cBin);
218+
return;
219+
}
161220
}
162-
int cBin = histManager.getCentBin(cent);
163221
spcHistograms.fill(HIST("FullCentrality"), cent);
164222
int nTracks = tracks.size();
165223

0 commit comments

Comments
 (0)