Skip to content

Commit 8e814f0

Browse files
authored
PWGCF: JCorran: dedicated weights loader (#6256)
* Dedicated weights loader task * Simplify weights loader
1 parent 45801c8 commit 8e814f0

5 files changed

Lines changed: 137 additions & 125 deletions

File tree

PWGCF/JCorran/Core/JFFlucAnalysis.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ class JFFlucAnalysis : public TNamed
6464
HIST_THN_PHIETAZ,
6565
HIST_THN_PTETA,
6666
HIST_THN_PHIETA,
67-
// HIST_THN_VN,
68-
// HIST_THN_VN_VN,
6967
HIST_THN_SC_with_QC_4corr,
7068
HIST_THN_SC_with_QC_2corr,
7169
HIST_THN_SC_with_QC_2corr_gap,
@@ -152,14 +150,9 @@ class JFFlucAnalysis : public TNamed
152150
if constexpr (std::experimental::is_detected<hasWeightNUA, const JInputClassIter>::value)
153151
corrInv /= track.weightNUA();
154152
pht[HIST_THN_PHIETA]->Fill(fCent, track.phi(), track.eta(), corrInv);
155-
156-
// if (TMath::Abs(track.eta()) < fEta_min || TMath::Abs(track.eta()) > fEta_max)
157-
// continue;
158153
pht[HIST_THN_PHIETAZ]->Fill(fCent, track.phi(), track.eta(), fVertex[2], corrInv);
159154
}
160155

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

PWGCF/JCorran/DataModel/JCatalyst.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ DECLARE_SOA_TABLE(JTracks, "AOD", "JTRACK", //! Reduced track table
4242
jtrack::JCollisionId,
4343
jtrack::Pt, jtrack::Eta, jtrack::Phi, jtrack::Sign);
4444
using JTrack = JTracks::iterator;
45+
46+
namespace jweight
47+
{
48+
DECLARE_SOA_COLUMN(WeightNUA, weightNUA, float); //! Non-uniform acceptance weight
49+
DECLARE_SOA_COLUMN(WeightEff, weightEff, float); //! Non-uniform efficiency weight
50+
} // namespace jweight
51+
DECLARE_SOA_TABLE(JWeights, "AOD", "JWEIGHT", jweight::WeightNUA, jweight::WeightEff); //! JFluc table for weights
52+
4553
} // namespace o2::aod
4654

4755
#endif // PWGCF_JCORRAN_DATAMODEL_JCATALYST_H_

PWGCF/JCorran/Tasks/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ o2physics_add_dpl_workflow(jfluc-analysis
1414
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::JCorran
1515
COMPONENT_NAME Analysis)
1616

17+
o2physics_add_dpl_workflow(jfluc-weights-loader
18+
SOURCES jflucWeightsLoader.cxx
19+
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::JCorran
20+
COMPONENT_NAME Analysis)
21+
1722
o2physics_add_dpl_workflow(flow-spc
1823
SOURCES flowJSPCAnalysis.cxx
1924
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::JCorran
@@ -22,4 +27,4 @@ o2physics_add_dpl_workflow(flow-spc
2227
o2physics_add_dpl_workflow(flow-nuacreation
2328
SOURCES flowJNUACreation.cxx
2429
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::JCorran
25-
COMPONENT_NAME Analysis)
30+
COMPONENT_NAME Analysis)

PWGCF/JCorran/Tasks/jflucAnalysisTask.cxx

Lines changed: 2 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@
1212
/// \author Dong Jo Kim (djkim@jyu.fi)
1313
/// \since Sep 2022
1414

15-
#include <TFile.h>
16-
#include <TH1.h>
17-
#include <TTree.h>
1815
#include <deque>
19-
#include <memory>
2016

2117
#include "Framework/AnalysisTask.h"
2218
#include "Framework/ASoAHelpers.h"
@@ -35,118 +31,14 @@
3531
#include "PWGCF/DataModel/CorrelationsDerived.h"
3632
#include "JFFlucAnalysis.h"
3733
#include "JFFlucAnalysisO2Hist.h"
34+
#include "Framework/runDataProcessing.h"
3835

3936
using namespace o2;
4037
using namespace o2::framework;
4138
using namespace o2::framework::expressions;
4239

43-
void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
44-
{
45-
ConfigParamSpec optionLoadWeights{"loadWeights", VariantType::Bool, false, {"Load correction weights"}};
46-
workflowOptions.push_back(optionLoadWeights);
47-
}
48-
49-
#include "Framework/runDataProcessing.h"
50-
5140
#define O2_DEFINE_CONFIGURABLE(NAME, TYPE, DEFAULT, HELP) Configurable<TYPE> NAME{#NAME, DEFAULT, HELP};
5241

53-
namespace o2::aod
54-
{
55-
namespace jweight
56-
{
57-
DECLARE_SOA_COLUMN(WeightNUA, weightNUA, float); //! Non-uniform acceptance weight
58-
DECLARE_SOA_COLUMN(WeightEff, weightEff, float); //! Non-uniform efficiency weight
59-
} // namespace jweight
60-
DECLARE_SOA_TABLE(JWeights, "AOD", "JWEIGHT", jweight::WeightNUA, jweight::WeightEff); //! JFluc table for weights
61-
} // namespace o2::aod
62-
63-
// 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.
64-
// This workflow creates a table of weights that can be joined with track tables.
65-
struct jflucWeightsLoader {
66-
O2_DEFINE_CONFIGURABLE(pathPhiWeights, std::string, "", "Local (local://) or CCDB path for the phi acceptance correction histogram");
67-
68-
struct Map {
69-
Map(THnF* _ph, int _runNumber) : ph(_ph), runNumber(_runNumber) {}
70-
~Map() { delete ph; }
71-
THnF* ph;
72-
int runNumber;
73-
};
74-
std::deque<Map> nuaCache;
75-
TFile* pf = 0;
76-
77-
~jflucWeightsLoader()
78-
{
79-
if (pf) {
80-
nuaCache.clear();
81-
pf->Close();
82-
delete pf;
83-
}
84-
}
85-
86-
Produces<aod::JWeights> output;
87-
void init(InitContext const&)
88-
{
89-
if (!doprocessLoadWeights && !doprocessLoadWeightsCF)
90-
return;
91-
if (doprocessLoadWeights && doprocessLoadWeightsCF)
92-
LOGF(fatal, "Only one weights loader process switch can be enabled at a time.");
93-
if (pathPhiWeights.value.substr(0, 8) == "local://") {
94-
pf = new TFile(pathPhiWeights.value.substr(8).c_str(), "read");
95-
if (!pf->IsOpen()) {
96-
delete pf;
97-
LOGF(fatal, "NUA correction weights file not found: %s", pathPhiWeights.value.substr(8).c_str());
98-
}
99-
}
100-
}
101-
102-
template <class CollisionT, class TrackT>
103-
void loadWeights(CollisionT const& collision, TrackT const& tracks)
104-
{
105-
if (!pf)
106-
LOGF(fatal, "NUA correction weights file has not been opened.");
107-
for (auto& track : tracks) {
108-
float phiWeight, effWeight;
109-
auto m = std::find_if(nuaCache.begin(), nuaCache.end(), [&](auto& t) -> bool {
110-
return t.runNumber == collision.runNumber();
111-
});
112-
if (m == nuaCache.end()) {
113-
THnF* ph = static_cast<THnF*>(pf->Get(Form("NUAWeights_%u", collision.runNumber())));
114-
if (ph) {
115-
nuaCache.emplace_back(ph, collision.runNumber());
116-
if (nuaCache.size() > 3)
117-
nuaCache.pop_front(); // keep at most maps for 3 runs
118-
const Double_t coords[] = {collision.multiplicity(), track.phi(), track.eta(), collision.posZ()};
119-
auto bin = ph->GetBin(coords);
120-
phiWeight = ph->GetBinContent(bin);
121-
} else {
122-
phiWeight = 1.0f;
123-
// LOGF(error, "NUAWeights_%u not found", collision.runNumber());
124-
}
125-
} else {
126-
const Double_t coords[] = {collision.multiplicity(), track.phi(), track.eta(), collision.posZ()};
127-
auto bin = m->ph->GetBin(coords);
128-
phiWeight = m->ph->GetBinContent(bin);
129-
}
130-
131-
effWeight = 1.0f; //<--- todo
132-
133-
output(phiWeight, effWeight);
134-
}
135-
}
136-
137-
void processLoadWeights(aod::JCollision const& collision, aod::JTracks const& tracks)
138-
{
139-
loadWeights(collision, tracks);
140-
}
141-
PROCESS_SWITCH(jflucWeightsLoader, processLoadWeights, "Load weights histograms for derived data table", false);
142-
143-
void processLoadWeightsCF(aod::CFCollision const& collision, aod::CFTracks const& tracks)
144-
{
145-
loadWeights(collision, tracks);
146-
}
147-
PROCESS_SWITCH(jflucWeightsLoader, processLoadWeightsCF, "Load weights histograms for CF derived data table", true);
148-
};
149-
15042
struct jflucAnalysisTask {
15143
~jflucAnalysisTask()
15244
{
@@ -164,7 +56,6 @@ struct jflucAnalysisTask {
16456
Filter cftrackFilter = (aod::cftrack::pt > ptmin) && (aod::cftrack::pt < ptmax); // eta cuts done by jfluc
16557

16658
HistogramRegistry registry{"registry"};
167-
// OutputObj<JFFlucAnalysis> output{JFFlucAnalysis("jflucO2")};
16859

16960
void init(InitContext const&)
17061
{
@@ -218,11 +109,5 @@ struct jflucAnalysisTask {
218109

219110
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
220111
{
221-
if (cfgc.options().get<bool>("loadWeights")) {
222-
return WorkflowSpec{
223-
adaptAnalysisTask<jflucWeightsLoader>(cfgc),
224-
adaptAnalysisTask<jflucAnalysisTask>(cfgc)};
225-
} else {
226-
return WorkflowSpec{adaptAnalysisTask<jflucAnalysisTask>(cfgc)};
227-
}
112+
return WorkflowSpec{adaptAnalysisTask<jflucAnalysisTask>(cfgc)};
228113
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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+
/// \author Jasper Parkkila (jparkkil@cern.ch)
12+
/// \since May 2024
13+
14+
#include <TFile.h>
15+
#include <THn.h>
16+
17+
#include "Framework/AnalysisTask.h"
18+
#include "Framework/ASoAHelpers.h"
19+
#include "Framework/RunningWorkflowInfo.h"
20+
#include "Framework/HistogramRegistry.h"
21+
22+
#include "Common/DataModel/EventSelection.h"
23+
#include "Common/Core/TrackSelection.h"
24+
#include "Common/DataModel/TrackSelectionTables.h"
25+
#include "Common/DataModel/Centrality.h"
26+
#include "ReconstructionDataFormats/V0.h"
27+
28+
// #include "CCDB/BasicCCDBManager.h"
29+
30+
#include "PWGCF/JCorran/DataModel/JCatalyst.h"
31+
#include "PWGCF/DataModel/CorrelationsDerived.h"
32+
#include "Framework/runDataProcessing.h"
33+
34+
using namespace o2;
35+
using namespace o2::framework;
36+
using namespace o2::framework::expressions;
37+
38+
#define O2_DEFINE_CONFIGURABLE(NAME, TYPE, DEFAULT, HELP) Configurable<TYPE> NAME{#NAME, DEFAULT, HELP};
39+
40+
// 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.
41+
// This workflow creates a table of weights that can be joined with track tables.
42+
struct jflucWeightsLoader {
43+
O2_DEFINE_CONFIGURABLE(pathPhiWeights, std::string, "", "Local (local://) or CCDB path for the phi acceptance correction histogram");
44+
45+
THnF* ph = 0;
46+
TFile* pf = 0;
47+
int runNumber = 0;
48+
49+
~jflucWeightsLoader()
50+
{
51+
if (ph)
52+
delete ph;
53+
if (pf) {
54+
pf->Close();
55+
delete pf;
56+
}
57+
}
58+
59+
Produces<aod::JWeights> output;
60+
void init(InitContext const&)
61+
{
62+
if (!doprocessLoadWeights && !doprocessLoadWeightsCF)
63+
return;
64+
if (doprocessLoadWeights && doprocessLoadWeightsCF)
65+
LOGF(fatal, "Only one weights loader process switch can be enabled at a time.");
66+
if (pathPhiWeights.value.substr(0, 8) == "local://") {
67+
pf = new TFile(pathPhiWeights.value.substr(8).c_str(), "read");
68+
if (!pf->IsOpen()) {
69+
delete pf;
70+
pf = 0;
71+
LOGF(fatal, "NUA correction weights file not found: %s", pathPhiWeights.value.substr(8).c_str());
72+
}
73+
}
74+
}
75+
76+
template <class CollisionT, class TrackT>
77+
void loadWeights(CollisionT const& collision, TrackT const& tracks)
78+
{
79+
if (!pf)
80+
LOGF(fatal, "NUA correction weights file has not been opened.");
81+
if (collision.runNumber() != runNumber) {
82+
if (ph)
83+
delete ph;
84+
if (!(ph = static_cast<THnF*>(pf->Get(Form("NUAWeights_%d", collision.runNumber())))))
85+
LOGF(warning, "NUA correction histogram not found for run %d.", collision.runNumber());
86+
else
87+
LOGF(info, "Loaded NUA correction histogram for run %d.", collision.runNumber());
88+
runNumber = collision.runNumber();
89+
}
90+
for (auto& track : tracks) {
91+
float phiWeight, effWeight;
92+
if (ph) {
93+
const Double_t coords[] = {collision.multiplicity(), track.phi(), track.eta(), collision.posZ()};
94+
phiWeight = ph->GetBinContent(ph->GetBin(coords));
95+
} else {
96+
phiWeight = 1.0f;
97+
}
98+
99+
effWeight = 1.0f; //<--- todo
100+
101+
output(phiWeight, effWeight);
102+
}
103+
}
104+
105+
void processLoadWeights(aod::JCollision const& collision, aod::JTracks const& tracks)
106+
{
107+
loadWeights(collision, tracks);
108+
}
109+
PROCESS_SWITCH(jflucWeightsLoader, processLoadWeights, "Load weights histograms for derived data table", false);
110+
111+
void processLoadWeightsCF(aod::CFCollision const& collision, aod::CFTracks const& tracks)
112+
{
113+
loadWeights(collision, tracks);
114+
}
115+
PROCESS_SWITCH(jflucWeightsLoader, processLoadWeightsCF, "Load weights histograms for CF derived data table", true);
116+
};
117+
118+
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
119+
{
120+
return WorkflowSpec{adaptAnalysisTask<jflucWeightsLoader>(cfgc)};
121+
}

0 commit comments

Comments
 (0)