Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions PWGCF/JCorran/Core/JFFlucAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ class JFFlucAnalysis : public TNamed
HIST_THN_PHIETAZ,
HIST_THN_PTETA,
HIST_THN_PHIETA,
// HIST_THN_VN,
// HIST_THN_VN_VN,
HIST_THN_SC_with_QC_4corr,
HIST_THN_SC_with_QC_2corr,
HIST_THN_SC_with_QC_2corr_gap,
Expand Down Expand Up @@ -152,14 +150,9 @@ class JFFlucAnalysis : public TNamed
if constexpr (std::experimental::is_detected<hasWeightNUA, const JInputClassIter>::value)
corrInv /= track.weightNUA();
pht[HIST_THN_PHIETA]->Fill(fCent, track.phi(), track.eta(), corrInv);

// if (TMath::Abs(track.eta()) < fEta_min || TMath::Abs(track.eta()) > fEta_max)
// continue;
pht[HIST_THN_PHIETAZ]->Fill(fCent, track.phi(), track.eta(), fVertex[2], corrInv);
}

// for (UInt_t iaxis = 0; iaxis < 3; iaxis++)
// fh_vertex[iaxis]->Fill(fVertex[iaxis]);
ph1[HIST_TH1_ZVERTEX]->Fill(fVertex[2]);
}

Expand Down
8 changes: 8 additions & 0 deletions PWGCF/JCorran/DataModel/JCatalyst.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ DECLARE_SOA_TABLE(JTracks, "AOD", "JTRACK", //! Reduced track table
jtrack::JCollisionId,
jtrack::Pt, jtrack::Eta, jtrack::Phi, jtrack::Sign);
using JTrack = JTracks::iterator;

namespace jweight
{
DECLARE_SOA_COLUMN(WeightNUA, weightNUA, float); //! Non-uniform acceptance weight
DECLARE_SOA_COLUMN(WeightEff, weightEff, float); //! Non-uniform efficiency weight
} // namespace jweight
DECLARE_SOA_TABLE(JWeights, "AOD", "JWEIGHT", jweight::WeightNUA, jweight::WeightEff); //! JFluc table for weights

} // namespace o2::aod

#endif // PWGCF_JCORRAN_DATAMODEL_JCATALYST_H_
7 changes: 6 additions & 1 deletion PWGCF/JCorran/Tasks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ o2physics_add_dpl_workflow(jfluc-analysis
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::JCorran
COMPONENT_NAME Analysis)

o2physics_add_dpl_workflow(jfluc-weights-loader
SOURCES jflucWeightsLoader.cxx
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::JCorran
COMPONENT_NAME Analysis)

o2physics_add_dpl_workflow(flow-spc
SOURCES flowJSPCAnalysis.cxx
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::JCorran
Expand All @@ -22,4 +27,4 @@ o2physics_add_dpl_workflow(flow-spc
o2physics_add_dpl_workflow(flow-nuacreation
SOURCES flowJNUACreation.cxx
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::JCorran
COMPONENT_NAME Analysis)
COMPONENT_NAME Analysis)
119 changes: 2 additions & 117 deletions PWGCF/JCorran/Tasks/jflucAnalysisTask.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
/// \author Dong Jo Kim (djkim@jyu.fi)
/// \since Sep 2022

#include <TFile.h>
#include <TH1.h>
#include <TTree.h>
#include <deque>
#include <memory>

#include "Framework/AnalysisTask.h"
#include "Framework/ASoAHelpers.h"
Expand All @@ -35,118 +31,14 @@
#include "PWGCF/DataModel/CorrelationsDerived.h"
#include "JFFlucAnalysis.h"
#include "JFFlucAnalysisO2Hist.h"
#include "Framework/runDataProcessing.h"

using namespace o2;
using namespace o2::framework;
using namespace o2::framework::expressions;

void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
{
ConfigParamSpec optionLoadWeights{"loadWeights", VariantType::Bool, false, {"Load correction weights"}};
workflowOptions.push_back(optionLoadWeights);
}

#include "Framework/runDataProcessing.h"

#define O2_DEFINE_CONFIGURABLE(NAME, TYPE, DEFAULT, HELP) Configurable<TYPE> NAME{#NAME, DEFAULT, HELP};

namespace o2::aod
{
namespace jweight
{
DECLARE_SOA_COLUMN(WeightNUA, weightNUA, float); //! Non-uniform acceptance weight
DECLARE_SOA_COLUMN(WeightEff, weightEff, float); //! Non-uniform efficiency weight
} // namespace jweight
DECLARE_SOA_TABLE(JWeights, "AOD", "JWEIGHT", jweight::WeightNUA, jweight::WeightEff); //! JFluc table for weights
} // namespace o2::aod

// The standalone jfluc code expects the entire list of tracks for an event. At the same time, it expects weights together with other track attributes.
// This workflow creates a table of weights that can be joined with track tables.
struct jflucWeightsLoader {
O2_DEFINE_CONFIGURABLE(pathPhiWeights, std::string, "", "Local (local://) or CCDB path for the phi acceptance correction histogram");

struct Map {
Map(THnF* _ph, int _runNumber) : ph(_ph), runNumber(_runNumber) {}
~Map() { delete ph; }
THnF* ph;
int runNumber;
};
std::deque<Map> nuaCache;
TFile* pf = 0;

~jflucWeightsLoader()
{
if (pf) {
nuaCache.clear();
pf->Close();
delete pf;
}
}

Produces<aod::JWeights> output;
void init(InitContext const&)
{
if (!doprocessLoadWeights && !doprocessLoadWeightsCF)
return;
if (doprocessLoadWeights && doprocessLoadWeightsCF)
LOGF(fatal, "Only one weights loader process switch can be enabled at a time.");
if (pathPhiWeights.value.substr(0, 8) == "local://") {
pf = new TFile(pathPhiWeights.value.substr(8).c_str(), "read");
if (!pf->IsOpen()) {
delete pf;
LOGF(fatal, "NUA correction weights file not found: %s", pathPhiWeights.value.substr(8).c_str());
}
}
}

template <class CollisionT, class TrackT>
void loadWeights(CollisionT const& collision, TrackT const& tracks)
{
if (!pf)
LOGF(fatal, "NUA correction weights file has not been opened.");
for (auto& track : tracks) {
float phiWeight, effWeight;
auto m = std::find_if(nuaCache.begin(), nuaCache.end(), [&](auto& t) -> bool {
return t.runNumber == collision.runNumber();
});
if (m == nuaCache.end()) {
THnF* ph = static_cast<THnF*>(pf->Get(Form("NUAWeights_%u", collision.runNumber())));
if (ph) {
nuaCache.emplace_back(ph, collision.runNumber());
if (nuaCache.size() > 3)
nuaCache.pop_front(); // keep at most maps for 3 runs
const Double_t coords[] = {collision.multiplicity(), track.phi(), track.eta(), collision.posZ()};
auto bin = ph->GetBin(coords);
phiWeight = ph->GetBinContent(bin);
} else {
phiWeight = 1.0f;
// LOGF(error, "NUAWeights_%u not found", collision.runNumber());
}
} else {
const Double_t coords[] = {collision.multiplicity(), track.phi(), track.eta(), collision.posZ()};
auto bin = m->ph->GetBin(coords);
phiWeight = m->ph->GetBinContent(bin);
}

effWeight = 1.0f; //<--- todo

output(phiWeight, effWeight);
}
}

void processLoadWeights(aod::JCollision const& collision, aod::JTracks const& tracks)
{
loadWeights(collision, tracks);
}
PROCESS_SWITCH(jflucWeightsLoader, processLoadWeights, "Load weights histograms for derived data table", false);

void processLoadWeightsCF(aod::CFCollision const& collision, aod::CFTracks const& tracks)
{
loadWeights(collision, tracks);
}
PROCESS_SWITCH(jflucWeightsLoader, processLoadWeightsCF, "Load weights histograms for CF derived data table", true);
};

struct jflucAnalysisTask {
~jflucAnalysisTask()
{
Expand All @@ -164,7 +56,6 @@ struct jflucAnalysisTask {
Filter cftrackFilter = (aod::cftrack::pt > ptmin) && (aod::cftrack::pt < ptmax); // eta cuts done by jfluc

HistogramRegistry registry{"registry"};
// OutputObj<JFFlucAnalysis> output{JFFlucAnalysis("jflucO2")};

void init(InitContext const&)
{
Expand Down Expand Up @@ -218,11 +109,5 @@ struct jflucAnalysisTask {

WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
{
if (cfgc.options().get<bool>("loadWeights")) {
return WorkflowSpec{
adaptAnalysisTask<jflucWeightsLoader>(cfgc),
adaptAnalysisTask<jflucAnalysisTask>(cfgc)};
} else {
return WorkflowSpec{adaptAnalysisTask<jflucAnalysisTask>(cfgc)};
}
return WorkflowSpec{adaptAnalysisTask<jflucAnalysisTask>(cfgc)};
}
121 changes: 121 additions & 0 deletions PWGCF/JCorran/Tasks/jflucWeightsLoader.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// 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.
/// \author Jasper Parkkila (jparkkil@cern.ch)
/// \since May 2024

#include <TFile.h>
#include <THn.h>

#include "Framework/AnalysisTask.h"
#include "Framework/ASoAHelpers.h"
#include "Framework/RunningWorkflowInfo.h"
#include "Framework/HistogramRegistry.h"

#include "Common/DataModel/EventSelection.h"
#include "Common/Core/TrackSelection.h"
#include "Common/DataModel/TrackSelectionTables.h"
#include "Common/DataModel/Centrality.h"
#include "ReconstructionDataFormats/V0.h"

// #include "CCDB/BasicCCDBManager.h"

#include "PWGCF/JCorran/DataModel/JCatalyst.h"
#include "PWGCF/DataModel/CorrelationsDerived.h"
#include "Framework/runDataProcessing.h"

using namespace o2;
using namespace o2::framework;
using namespace o2::framework::expressions;

#define O2_DEFINE_CONFIGURABLE(NAME, TYPE, DEFAULT, HELP) Configurable<TYPE> NAME{#NAME, DEFAULT, HELP};

// The standalone jfluc code expects the entire list of tracks for an event. At the same time, it expects weights together with other track attributes.
// This workflow creates a table of weights that can be joined with track tables.
struct jflucWeightsLoader {
O2_DEFINE_CONFIGURABLE(pathPhiWeights, std::string, "", "Local (local://) or CCDB path for the phi acceptance correction histogram");

THnF* ph = 0;
TFile* pf = 0;
int runNumber = 0;

~jflucWeightsLoader()
{
if (ph)
delete ph;
if (pf) {
pf->Close();
delete pf;
}
}

Produces<aod::JWeights> output;
void init(InitContext const&)
{
if (!doprocessLoadWeights && !doprocessLoadWeightsCF)
return;
if (doprocessLoadWeights && doprocessLoadWeightsCF)
LOGF(fatal, "Only one weights loader process switch can be enabled at a time.");
if (pathPhiWeights.value.substr(0, 8) == "local://") {
pf = new TFile(pathPhiWeights.value.substr(8).c_str(), "read");
if (!pf->IsOpen()) {
delete pf;
pf = 0;
LOGF(fatal, "NUA correction weights file not found: %s", pathPhiWeights.value.substr(8).c_str());
}
}
}

template <class CollisionT, class TrackT>
void loadWeights(CollisionT const& collision, TrackT const& tracks)
{
if (!pf)
LOGF(fatal, "NUA correction weights file has not been opened.");
if (collision.runNumber() != runNumber) {
if (ph)
delete ph;
if (!(ph = static_cast<THnF*>(pf->Get(Form("NUAWeights_%d", collision.runNumber())))))
LOGF(warning, "NUA correction histogram not found for run %d.", collision.runNumber());
else
LOGF(info, "Loaded NUA correction histogram for run %d.", collision.runNumber());
runNumber = collision.runNumber();
}
for (auto& track : tracks) {
float phiWeight, effWeight;
if (ph) {
const Double_t coords[] = {collision.multiplicity(), track.phi(), track.eta(), collision.posZ()};
phiWeight = ph->GetBinContent(ph->GetBin(coords));
} else {
phiWeight = 1.0f;
}

effWeight = 1.0f; //<--- todo

output(phiWeight, effWeight);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be careful on how you will use this table
The tracks table has tracks that are not associated to collisions and that means they will not be in this output which in its turn means you will not be able to join this table to the tracks table

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the point, will be careful with this.

}
}

void processLoadWeights(aod::JCollision const& collision, aod::JTracks const& tracks)
{
loadWeights(collision, tracks);
}
PROCESS_SWITCH(jflucWeightsLoader, processLoadWeights, "Load weights histograms for derived data table", false);

void processLoadWeightsCF(aod::CFCollision const& collision, aod::CFTracks const& tracks)
{
loadWeights(collision, tracks);
}
PROCESS_SWITCH(jflucWeightsLoader, processLoadWeightsCF, "Load weights histograms for CF derived data table", true);
};

WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
{
return WorkflowSpec{adaptAnalysisTask<jflucWeightsLoader>(cfgc)};
}