Skip to content

Commit

Permalink
[PWGCF] flow-runbyrun: add a class to hold the list of weight (AliceO…
Browse files Browse the repository at this point in the history
  • Loading branch information
Luzhiyongg authored Dec 26, 2024
1 parent 54a9f6f commit 7cd2cda
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 14 deletions.
34 changes: 20 additions & 14 deletions PWGCF/Flow/Tasks/flowRunbyRun.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "GFW.h"
#include "GFWCumulant.h"
#include "GFWWeights.h"
#include "GFWWeightsList.h"
#include "FlowContainer.h"
#include "TList.h"
#include <TProfile.h>
Expand All @@ -62,6 +63,7 @@ struct FlowRunbyRun {
O2_DEFINE_CONFIGURABLE(cfgCutChi2prTPCcls, float, 2.5, "Chi2 per TPC clusters")
O2_DEFINE_CONFIGURABLE(cfgCutDCAz, float, 2.0f, "max DCA to vertex z")
O2_DEFINE_CONFIGURABLE(cfgUseNch, bool, false, "Use Nch for flow observables")
O2_DEFINE_CONFIGURABLE(cfgNbootstrap, int, 30, "Number of subsamples")
O2_DEFINE_CONFIGURABLE(cfgOutputNUAWeightsRefPt, bool, false, "NUA weights are filled in ref pt bins")
O2_DEFINE_CONFIGURABLE(cfgDynamicRunNumber, bool, false, "Add runNumber during runtime")
Configurable<std::vector<int>> cfgRunNumbers{"cfgRunNumbers", std::vector<int>{544095, 544098, 544116, 544121, 544122, 544123, 544124}, "Preconfigured run numbers"};
Expand All @@ -84,7 +86,7 @@ struct FlowRunbyRun {

// Define output
OutputObj<FlowContainer> fFC{FlowContainer("FlowContainer")};
OutputObj<TList> fWeightList{"WeightList", OutputObjHandlingPolicy::AnalysisObject, OutputObjSourceType::OutputObjSource};
OutputObj<GFWWeightsList> fGFWWeightsList{GFWWeightsList("GFWWeightsList")};
HistogramRegistry registry{"registry"};

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

TList* weightlist = new TList();
weightlist->SetOwner(true);
fWeightList.setObject(weightlist);
fGFWWeightsList->init("weightList");

// Add output histograms to the registry
runNumbers = cfgRunNumbers;
Expand All @@ -148,7 +147,7 @@ struct FlowRunbyRun {
}
fFC->SetName("FlowContainer");
fFC->SetXAxis(fPtAxis);
fFC->Initialize(oba, axisIndependent, 1);
fFC->Initialize(oba, axisIndependent, cfgNbootstrap);
delete oba;

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

void process(AodCollisions::iterator const& collision, aod::BCsWithTimestamps const&, AodTracks const& tracks)
Expand Down Expand Up @@ -277,10 +272,21 @@ struct FlowRunbyRun {
fGFW->Fill(track.eta(), 1, track.phi(), wacc * weff, 1);
}
if (cfgOutputNUAWeightsRefPt) {
if (withinPtRef)
weightsList[runNumber]->Fill(track.phi(), track.eta(), collision.posZ(), track.pt(), cent, 0);
if (withinPtRef) {
GFWWeights* weight = fGFWWeightsList->getGFWWeightsByRun(runNumber);
if (!weight) {
LOGF(fatal, "Could not find the weight for run %d", runNumber);
return;
}
weight->Fill(track.phi(), track.eta(), collision.posZ(), track.pt(), cent, 0);
}
} else {
weightsList[runNumber]->Fill(track.phi(), track.eta(), collision.posZ(), track.pt(), cent, 0);
GFWWeights* weight = fGFWWeightsList->getGFWWeightsByRun(runNumber);
if (!weight) {
LOGF(fatal, "Could not find the weight for run %d", runNumber);
return;
}
weight->Fill(track.phi(), track.eta(), collision.posZ(), track.pt(), cent, 0);
}
}

Expand Down
2 changes: 2 additions & 0 deletions PWGCF/GenericFramework/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ o2physics_add_library(GFWCore
ProfileSubset.cxx
FlowContainer.cxx
GFWWeights.cxx
GFWWeightsList.cxx
FlowPtContainer.cxx
BootstrapProfile.cxx
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore)
Expand All @@ -27,6 +28,7 @@ o2physics_target_root_dictionary(GFWCore
ProfileSubset.h
FlowContainer.h
GFWWeights.h
GFWWeightsList.h
GFWConfig.h
FlowPtContainer.h
BootstrapProfile.h
Expand Down
87 changes: 87 additions & 0 deletions PWGCF/GenericFramework/Core/GFWWeightsList.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// 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.

/// \file GFWWeightsList.cxx
/// \author Zhiyong Lu ([email protected])
/// \since Dec/25/2024
/// \brief one object to hold a list of GFWWeights objects,

#include <utility>
#include <cstdio>
#include "GFWWeightsList.h"

GFWWeightsList::GFWWeightsList() : TNamed("", ""), list(0)
{
runNumerMap.clear();
}

GFWWeightsList::GFWWeightsList(const char* name) : TNamed(name, name), list(0)
{
runNumerMap.clear();
}

GFWWeightsList::~GFWWeightsList()
{
delete list;
runNumerMap.clear();
}

void GFWWeightsList::init(const char* listName)
{
list = new TObjArray();
list->SetName(listName);
list->SetOwner(kTRUE);
}

void GFWWeightsList::addGFWWeightsByName(const char* weightName, int nPtBins, double* ptBins, bool addData, bool addMC)
{
if (!list) {
init("weightList");
}
GFWWeights* weight = new GFWWeights(weightName);
weight->SetPtBins(nPtBins, ptBins);
weight->Init(addData, addMC);
list->Add(weight);
}

GFWWeights* GFWWeightsList::getGFWWeightsByName(const char* weightName)
{
if (!list) {
printf("Error: weight list is not initialized\n");
return nullptr;
}
return reinterpret_cast<GFWWeights*>(list->FindObject(weightName));
}

void GFWWeightsList::addGFWWeightsByRun(int runNumber, int nPtBins, double* ptBins, bool addData, bool addMC)
{
if (!list) {
init("weightList");
}
GFWWeights* weight = new GFWWeights(Form("weight_%d", runNumber));
weight->SetPtBins(nPtBins, ptBins);
weight->Init(addData, addMC);
list->Add(weight);
runNumerMap.insert(std::make_pair(runNumber, weight));
}

GFWWeights* GFWWeightsList::getGFWWeightsByRun(int runNumber)
{
if (!list) {
printf("Error: weight list is not initialized\n");
return nullptr;
}
if (!runNumerMap.contains(runNumber)) {
printf("Error: weight for run %d is not found\n", runNumber);
return nullptr;
}
return runNumerMap.at(runNumber);
}
43 changes: 43 additions & 0 deletions PWGCF/GenericFramework/Core/GFWWeightsList.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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.

/// \file GFWWeightsList.h
/// \author Zhiyong Lu ([email protected])
/// \since Dec/25/2024
/// \brief one object to hold a list of GFWWeights objects,

#ifndef PWGCF_GENERICFRAMEWORK_CORE_GFWWEIGHTSLIST_H_
#define PWGCF_GENERICFRAMEWORK_CORE_GFWWEIGHTSLIST_H_
#include <map>
#include "TObjArray.h"
#include "GFWWeights.h"

class GFWWeightsList : public TNamed
{
public:
GFWWeightsList();
explicit GFWWeightsList(const char* name);
~GFWWeightsList();
void init(const char* listName);
void addGFWWeightsByName(const char* weightName, int nPtBins, double* ptBins, bool addData = kTRUE, bool addMC = kTRUE);
GFWWeights* getGFWWeightsByName(const char* weightName);
void addGFWWeightsByRun(int runNumber, int nPtBins, double* ptBins, bool addData = kTRUE, bool addMC = kTRUE);
GFWWeights* getGFWWeightsByRun(int runNumber);
TObjArray* getList() const { return list; }

private:
TObjArray* list;
std::map<int, GFWWeights*> runNumerMap;

ClassDef(GFWWeightsList, 1);
};

#endif // PWGCF_GENERICFRAMEWORK_CORE_GFWWEIGHTSLIST_H_
1 change: 1 addition & 0 deletions PWGCF/GenericFramework/Core/GenericFrameworkLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#pragma link C++ class ProfileSubset + ;
#pragma link C++ class FlowContainer + ;
#pragma link C++ class GFWWeights + ;
#pragma link C++ class GFWWeightsList + ;
#pragma link C++ class BootstrapProfile + ;
#pragma link C++ class FlowPtContainer + ;
#pragma link C++ class o2::analysis::genericframework::GFWBinningCuts + ;
Expand Down

0 comments on commit 7cd2cda

Please sign in to comment.