Skip to content

Commit 7cd2cda

Browse files
authored
[PWGCF] flow-runbyrun: add a class to hold the list of weight (#9129)
1 parent 54a9f6f commit 7cd2cda

File tree

5 files changed

+153
-14
lines changed

5 files changed

+153
-14
lines changed

PWGCF/Flow/Tasks/flowRunbyRun.cxx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "GFW.h"
3939
#include "GFWCumulant.h"
4040
#include "GFWWeights.h"
41+
#include "GFWWeightsList.h"
4142
#include "FlowContainer.h"
4243
#include "TList.h"
4344
#include <TProfile.h>
@@ -62,6 +63,7 @@ struct FlowRunbyRun {
6263
O2_DEFINE_CONFIGURABLE(cfgCutChi2prTPCcls, float, 2.5, "Chi2 per TPC clusters")
6364
O2_DEFINE_CONFIGURABLE(cfgCutDCAz, float, 2.0f, "max DCA to vertex z")
6465
O2_DEFINE_CONFIGURABLE(cfgUseNch, bool, false, "Use Nch for flow observables")
66+
O2_DEFINE_CONFIGURABLE(cfgNbootstrap, int, 30, "Number of subsamples")
6567
O2_DEFINE_CONFIGURABLE(cfgOutputNUAWeightsRefPt, bool, false, "NUA weights are filled in ref pt bins")
6668
O2_DEFINE_CONFIGURABLE(cfgDynamicRunNumber, bool, false, "Add runNumber during runtime")
6769
Configurable<std::vector<int>> cfgRunNumbers{"cfgRunNumbers", std::vector<int>{544095, 544098, 544116, 544121, 544122, 544123, 544124}, "Preconfigured run numbers"};
@@ -84,7 +86,7 @@ struct FlowRunbyRun {
8486

8587
// Define output
8688
OutputObj<FlowContainer> fFC{FlowContainer("FlowContainer")};
87-
OutputObj<TList> fWeightList{"WeightList", OutputObjHandlingPolicy::AnalysisObject, OutputObjSourceType::OutputObjSource};
89+
OutputObj<GFWWeightsList> fGFWWeightsList{GFWWeightsList("GFWWeightsList")};
8890
HistogramRegistry registry{"registry"};
8991

9092
// define global variables
@@ -97,7 +99,6 @@ struct FlowRunbyRun {
9799
std::vector<int> runNumbers; // vector of run numbers
98100
std::map<int, std::vector<std::shared_ptr<TH1>>> th1sList; // map of histograms for all runs
99101
std::map<int, std::vector<std::shared_ptr<TProfile>>> profilesList; // map of profiles for all runs
100-
std::map<int, GFWWeights*> weightsList; // map of weights for all runs
101102
enum OutputTH1Names {
102103
// here are TProfiles for vn-pt correlations that are not implemented in GFW
103104
hPhi = 0,
@@ -122,9 +123,7 @@ struct FlowRunbyRun {
122123
ccdb->setCaching(true);
123124
ccdb->setCreatedNotAfter(ccdbNoLaterThan.value);
124125

125-
TList* weightlist = new TList();
126-
weightlist->SetOwner(true);
127-
fWeightList.setObject(weightlist);
126+
fGFWWeightsList->init("weightList");
128127

129128
// Add output histograms to the registry
130129
runNumbers = cfgRunNumbers;
@@ -148,7 +147,7 @@ struct FlowRunbyRun {
148147
}
149148
fFC->SetName("FlowContainer");
150149
fFC->SetXAxis(fPtAxis);
151-
fFC->Initialize(oba, axisIndependent, 1);
150+
fFC->Initialize(oba, axisIndependent, cfgNbootstrap);
152151
delete oba;
153152

154153
fGFW->AddRegion("full", -0.8, 0.8, 1, 1);
@@ -230,11 +229,7 @@ struct FlowRunbyRun {
230229
o2::framework::AxisSpec axis = axisPt;
231230
int nPtBins = axis.binEdges.size() - 1;
232231
double* ptBins = &(axis.binEdges)[0];
233-
GFWWeights* weight = new GFWWeights(Form("weight_%d", runNumber));
234-
weight->SetPtBins(nPtBins, ptBins);
235-
weight->Init(true, false);
236-
fWeightList->Add(weight);
237-
weightsList.insert(std::make_pair(runNumber, weight));
232+
fGFWWeightsList->addGFWWeightsByRun(runNumber, nPtBins, ptBins, true, false);
238233
}
239234

240235
void process(AodCollisions::iterator const& collision, aod::BCsWithTimestamps const&, AodTracks const& tracks)
@@ -277,10 +272,21 @@ struct FlowRunbyRun {
277272
fGFW->Fill(track.eta(), 1, track.phi(), wacc * weff, 1);
278273
}
279274
if (cfgOutputNUAWeightsRefPt) {
280-
if (withinPtRef)
281-
weightsList[runNumber]->Fill(track.phi(), track.eta(), collision.posZ(), track.pt(), cent, 0);
275+
if (withinPtRef) {
276+
GFWWeights* weight = fGFWWeightsList->getGFWWeightsByRun(runNumber);
277+
if (!weight) {
278+
LOGF(fatal, "Could not find the weight for run %d", runNumber);
279+
return;
280+
}
281+
weight->Fill(track.phi(), track.eta(), collision.posZ(), track.pt(), cent, 0);
282+
}
282283
} else {
283-
weightsList[runNumber]->Fill(track.phi(), track.eta(), collision.posZ(), track.pt(), cent, 0);
284+
GFWWeights* weight = fGFWWeightsList->getGFWWeightsByRun(runNumber);
285+
if (!weight) {
286+
LOGF(fatal, "Could not find the weight for run %d", runNumber);
287+
return;
288+
}
289+
weight->Fill(track.phi(), track.eta(), collision.posZ(), track.pt(), cent, 0);
284290
}
285291
}
286292

PWGCF/GenericFramework/Core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ o2physics_add_library(GFWCore
1616
ProfileSubset.cxx
1717
FlowContainer.cxx
1818
GFWWeights.cxx
19+
GFWWeightsList.cxx
1920
FlowPtContainer.cxx
2021
BootstrapProfile.cxx
2122
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore)
@@ -27,6 +28,7 @@ o2physics_target_root_dictionary(GFWCore
2728
ProfileSubset.h
2829
FlowContainer.h
2930
GFWWeights.h
31+
GFWWeightsList.h
3032
GFWConfig.h
3133
FlowPtContainer.h
3234
BootstrapProfile.h
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
/// \file GFWWeightsList.cxx
13+
/// \author Zhiyong Lu (zhiyong.lu@cern.ch)
14+
/// \since Dec/25/2024
15+
/// \brief one object to hold a list of GFWWeights objects,
16+
17+
#include <utility>
18+
#include <cstdio>
19+
#include "GFWWeightsList.h"
20+
21+
GFWWeightsList::GFWWeightsList() : TNamed("", ""), list(0)
22+
{
23+
runNumerMap.clear();
24+
}
25+
26+
GFWWeightsList::GFWWeightsList(const char* name) : TNamed(name, name), list(0)
27+
{
28+
runNumerMap.clear();
29+
}
30+
31+
GFWWeightsList::~GFWWeightsList()
32+
{
33+
delete list;
34+
runNumerMap.clear();
35+
}
36+
37+
void GFWWeightsList::init(const char* listName)
38+
{
39+
list = new TObjArray();
40+
list->SetName(listName);
41+
list->SetOwner(kTRUE);
42+
}
43+
44+
void GFWWeightsList::addGFWWeightsByName(const char* weightName, int nPtBins, double* ptBins, bool addData, bool addMC)
45+
{
46+
if (!list) {
47+
init("weightList");
48+
}
49+
GFWWeights* weight = new GFWWeights(weightName);
50+
weight->SetPtBins(nPtBins, ptBins);
51+
weight->Init(addData, addMC);
52+
list->Add(weight);
53+
}
54+
55+
GFWWeights* GFWWeightsList::getGFWWeightsByName(const char* weightName)
56+
{
57+
if (!list) {
58+
printf("Error: weight list is not initialized\n");
59+
return nullptr;
60+
}
61+
return reinterpret_cast<GFWWeights*>(list->FindObject(weightName));
62+
}
63+
64+
void GFWWeightsList::addGFWWeightsByRun(int runNumber, int nPtBins, double* ptBins, bool addData, bool addMC)
65+
{
66+
if (!list) {
67+
init("weightList");
68+
}
69+
GFWWeights* weight = new GFWWeights(Form("weight_%d", runNumber));
70+
weight->SetPtBins(nPtBins, ptBins);
71+
weight->Init(addData, addMC);
72+
list->Add(weight);
73+
runNumerMap.insert(std::make_pair(runNumber, weight));
74+
}
75+
76+
GFWWeights* GFWWeightsList::getGFWWeightsByRun(int runNumber)
77+
{
78+
if (!list) {
79+
printf("Error: weight list is not initialized\n");
80+
return nullptr;
81+
}
82+
if (!runNumerMap.contains(runNumber)) {
83+
printf("Error: weight for run %d is not found\n", runNumber);
84+
return nullptr;
85+
}
86+
return runNumerMap.at(runNumber);
87+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
/// \file GFWWeightsList.h
13+
/// \author Zhiyong Lu (zhiyong.lu@cern.ch)
14+
/// \since Dec/25/2024
15+
/// \brief one object to hold a list of GFWWeights objects,
16+
17+
#ifndef PWGCF_GENERICFRAMEWORK_CORE_GFWWEIGHTSLIST_H_
18+
#define PWGCF_GENERICFRAMEWORK_CORE_GFWWEIGHTSLIST_H_
19+
#include <map>
20+
#include "TObjArray.h"
21+
#include "GFWWeights.h"
22+
23+
class GFWWeightsList : public TNamed
24+
{
25+
public:
26+
GFWWeightsList();
27+
explicit GFWWeightsList(const char* name);
28+
~GFWWeightsList();
29+
void init(const char* listName);
30+
void addGFWWeightsByName(const char* weightName, int nPtBins, double* ptBins, bool addData = kTRUE, bool addMC = kTRUE);
31+
GFWWeights* getGFWWeightsByName(const char* weightName);
32+
void addGFWWeightsByRun(int runNumber, int nPtBins, double* ptBins, bool addData = kTRUE, bool addMC = kTRUE);
33+
GFWWeights* getGFWWeightsByRun(int runNumber);
34+
TObjArray* getList() const { return list; }
35+
36+
private:
37+
TObjArray* list;
38+
std::map<int, GFWWeights*> runNumerMap;
39+
40+
ClassDef(GFWWeightsList, 1);
41+
};
42+
43+
#endif // PWGCF_GENERICFRAMEWORK_CORE_GFWWEIGHTSLIST_H_

PWGCF/GenericFramework/Core/GenericFrameworkLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#pragma link C++ class ProfileSubset + ;
2323
#pragma link C++ class FlowContainer + ;
2424
#pragma link C++ class GFWWeights + ;
25+
#pragma link C++ class GFWWeightsList + ;
2526
#pragma link C++ class BootstrapProfile + ;
2627
#pragma link C++ class FlowPtContainer + ;
2728
#pragma link C++ class o2::analysis::genericframework::GFWBinningCuts + ;

0 commit comments

Comments
 (0)