Skip to content

Commit abd74fe

Browse files
Luzhiyonggalibuild
andauthored
[PWGCF] create a minimum container for di-hadron correlations (#16979)
Co-authored-by: ALICE Action Bot <alibuild@cern.ch>
1 parent b33c7ae commit abd74fe

4 files changed

Lines changed: 274 additions & 0 deletions

File tree

PWGCF/TwoParticleCorrelations/Core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ o2physics_add_library(TwoPartCorrCore
1616
PIDSelectionFilterAndAnalysis.cxx
1717
EventSelectionFilterAndAnalysis.cxx
1818
FilterAndAnalysisFramework.cxx
19+
DihadronContainer.cxx
1920
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::PWGCFCore)
2021

2122
o2physics_target_root_dictionary(TwoPartCorrCore
@@ -25,4 +26,5 @@ o2physics_target_root_dictionary(TwoPartCorrCore
2526
PIDSelectionFilterAndAnalysis.h
2627
EventSelectionFilterAndAnalysis.h
2728
FilterAndAnalysisFramework.h
29+
DihadronContainer.h
2830
LINKDEF TwoPartCorrLinkDef.h)
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
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 DihadronContainer.h
13+
/// \brief minimum encapsulated container for di-hadron correlations
14+
/// \author Zhiyong Lu (zhiyong.lu@cern.ch)
15+
/// \since July/2026
16+
17+
#include "PWGCF/TwoParticleCorrelations/Core/DihadronContainer.h"
18+
19+
#include <Framework/HistogramSpec.h>
20+
#include <Framework/Logger.h>
21+
#include <Framework/StepTHn.h>
22+
23+
#include <TCollection.h>
24+
#include <THn.h>
25+
#include <TIterator.h>
26+
#include <TList.h>
27+
#include <TNamed.h>
28+
#include <TObject.h>
29+
#include <TString.h>
30+
31+
#include <Rtypes.h>
32+
#include <RtypesCore.h>
33+
34+
#include <cstdint>
35+
#include <cstring>
36+
#include <vector>
37+
38+
using namespace o2;
39+
using namespace o2::framework;
40+
41+
ClassImp(DihadronContainer);
42+
43+
DihadronContainer::DihadronContainer() : mCorrHist(nullptr), nCorrStep(1)
44+
{
45+
// Default constructor
46+
}
47+
48+
DihadronContainer::DihadronContainer(const char* name, const char* objTitle,
49+
const std::vector<o2::framework::AxisSpec>& correlationAxis,
50+
const uint8_t nStep) : TNamed(name, objTitle),
51+
mCorrHist(nullptr),
52+
nCorrStep(nStep)
53+
{
54+
55+
if (strlen(name) == 0) {
56+
return;
57+
}
58+
59+
int64_t bins = 1;
60+
LOGF(info, "Creating DihadronContainer:");
61+
for (UInt_t iAxis = 0; iAxis < correlationAxis.size(); iAxis++) {
62+
LOGF(info, "correlationAxis[%d].getNbins() = %d", iAxis, correlationAxis[iAxis].getNbins());
63+
bins *= correlationAxis[iAxis].getNbins();
64+
}
65+
LOGF(info, "DihadronContainer with %ld bins in the correlation histogram (approx. %ld-%ld MB of memory)", bins, bins * 4 / 1024 / 1024, bins * 8 / 1024 / 1024);
66+
67+
mCorrHist = HistFactory::createHist<StepTHnF>({"mCorrHist", "d^{2}N_{ch}/d#varphid#eta", {HistType::kStepTHnF, correlationAxis, nStep}}).release();
68+
}
69+
70+
//_____________________________________________________________________________
71+
DihadronContainer::DihadronContainer(const DihadronContainer& c) : TNamed(c),
72+
mCorrHist(nullptr),
73+
nCorrStep(c.nCorrStep)
74+
{
75+
// DihadronContainer copy constructor
76+
if (c.mCorrHist)
77+
mCorrHist = dynamic_cast<StepTHn*>(c.mCorrHist->Clone());
78+
else
79+
mCorrHist = nullptr;
80+
}
81+
82+
//____________________________________________________________________
83+
DihadronContainer::~DihadronContainer()
84+
{
85+
// Destructor
86+
if (mCorrHist) {
87+
delete mCorrHist;
88+
mCorrHist = nullptr;
89+
}
90+
}
91+
92+
//____________________________________________________________________
93+
DihadronContainer& DihadronContainer::operator=(const DihadronContainer& c)
94+
{
95+
// assigment operator
96+
if (this != &c) {
97+
c.Copy(*this);
98+
}
99+
return *this;
100+
}
101+
102+
//____________________________________________________________________
103+
void DihadronContainer::Copy(TObject& c) const
104+
{
105+
// copy function
106+
auto target = dynamic_cast<DihadronContainer&>(c);
107+
108+
if (mCorrHist) {
109+
target.mCorrHist = dynamic_cast<StepTHn*>(mCorrHist->Clone());
110+
}
111+
112+
target.nCorrStep = nCorrStep;
113+
}
114+
115+
//____________________________________________________________________
116+
void DihadronContainer::deepCopy(DihadronContainer* from)
117+
{
118+
// copies the entries of this object's members from the object <from> to this object
119+
// fills using the fill function and thus allows that the objects have different binning
120+
121+
for (Int_t step = 0; step < mCorrHist->getNSteps(); step++) {
122+
LOGF(info, "Copying step %d", step);
123+
THnBase* target = mCorrHist->getTHn(step);
124+
THnBase* source = from->mCorrHist->getTHn(step);
125+
126+
target->Reset();
127+
target->RebinnedAdd(source);
128+
}
129+
}
130+
131+
//____________________________________________________________________
132+
Long64_t DihadronContainer::Merge(TCollection* list)
133+
{
134+
// Merge a list of DihadronContainer objects with this
135+
// Returns the number of merged objects (including this).
136+
137+
if (!list) {
138+
return 0;
139+
}
140+
141+
if (list->IsEmpty()) {
142+
return 1;
143+
}
144+
145+
TIterator* iter = list->MakeIterator();
146+
TObject* obj = nullptr;
147+
148+
// collections of objects
149+
const UInt_t kMaxLists = 1;
150+
auto lists = new TList*[kMaxLists];
151+
152+
for (UInt_t i = 0; i < kMaxLists; i++) {
153+
lists[i] = new TList;
154+
}
155+
156+
Int_t count = 0;
157+
while ((obj = iter->Next())) {
158+
159+
auto entry = dynamic_cast<DihadronContainer*>(obj);
160+
if (entry == nullptr) {
161+
continue;
162+
}
163+
164+
if (entry->mCorrHist) {
165+
lists[0]->Add(entry->mCorrHist);
166+
}
167+
168+
count++;
169+
}
170+
171+
if (mCorrHist) {
172+
mCorrHist->Merge(lists[0]);
173+
}
174+
175+
for (UInt_t i = 0; i < kMaxLists; i++) {
176+
delete lists[i];
177+
}
178+
179+
delete[] lists;
180+
181+
return count + 1;
182+
}
183+
184+
//____________________________________________________________________
185+
void DihadronContainer::Reset()
186+
{
187+
// resets all contained histograms
188+
189+
for (Int_t step = 0; step < mCorrHist->getNSteps(); step++) {
190+
mCorrHist->getTHn(step)->Reset();
191+
}
192+
}
193+
194+
THnBase* DihadronContainer::changeToThn(THnBase* sparse)
195+
{
196+
// change the object to THn for faster processing
197+
198+
return THn::CreateHn(Form("%s_thn", sparse->GetName()), sparse->GetTitle(), sparse);
199+
}
200+
201+
ClassImp(DihadronContainer);
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
#ifndef PWGCF_TWOPARTICLECORRELATIONS_CORE_DIHADRONCONTAINER_H_
13+
#define PWGCF_TWOPARTICLECORRELATIONS_CORE_DIHADRONCONTAINER_H_
14+
15+
/// \file DihadronContainer.h
16+
/// \brief minimum encapsulated container for di-hadron correlations
17+
/// \author Zhiyong Lu (zhiyong.lu@cern.ch)
18+
/// \since July/2026
19+
20+
#include <Framework/HistogramSpec.h>
21+
22+
#include <TNamed.h>
23+
24+
#include <Rtypes.h>
25+
#include <RtypesCore.h>
26+
27+
#include <cstdint>
28+
#include <vector>
29+
30+
class TH1;
31+
class TH1F;
32+
class TH3;
33+
class TH3F;
34+
class TH2F;
35+
class TH1D;
36+
class TH2;
37+
class TH2D;
38+
class TCollection;
39+
class THnSparse;
40+
class THnBase;
41+
class StepTHn;
42+
43+
class DihadronContainer : public TNamed
44+
{
45+
public:
46+
DihadronContainer();
47+
DihadronContainer(const char* name, const char* objTitle, const std::vector<o2::framework::AxisSpec>& correlationAxis, const uint8_t nStep = 1);
48+
virtual ~DihadronContainer(); // NOLINT(modernize-use-override)
49+
50+
StepTHn* getCorrHist() { return mCorrHist; }
51+
void setCorrHist(StepTHn* hist) { mCorrHist = hist; }
52+
void printCorrHist();
53+
54+
DihadronContainer(const DihadronContainer& c);
55+
DihadronContainer& operator=(const DihadronContainer& corr);
56+
virtual void Copy(TObject& c) const; // NOLINT: Making this override breaks compilation for unknown reason
57+
void deepCopy(DihadronContainer* from);
58+
59+
virtual Long64_t Merge(TCollection* list);
60+
void Reset();
61+
THnBase* changeToThn(THnBase* sparse);
62+
63+
protected:
64+
StepTHn* mCorrHist; // container for n-dimension correlations
65+
uint8_t nCorrStep;
66+
67+
ClassDef(DihadronContainer, 2) // underlying event histogram container
68+
};
69+
70+
#endif // PWGCF_TWOPARTICLECORRELATIONS_CORE_DIHADRONCONTAINER_H_

PWGCF/TwoParticleCorrelations/Core/TwoPartCorrLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,6 @@
5050
#pragma link C++ class o2::analysis::PWGCF::EventSelectionFilterAndAnalysis::PileUpRejBrick + ;
5151
#pragma link C++ class o2::analysis::PWGCF::EventSelectionFilterAndAnalysis + ;
5252
#pragma link C++ class o2::analysis::PWGCF::FilterAndAnalysisFramework + ;
53+
#pragma link C++ class DihadronContainer + ;
5354

5455
#endif // PWGCF_TWOPARTICLECORRELATIONS_CORE_TWOPARTCORRLINKDEF_H_

0 commit comments

Comments
 (0)