Skip to content

Commit 2315f8e

Browse files
committed
create a minimum encapsulated container for di-hadron correlations
1 parent 0ce0e1b commit 2315f8e

4 files changed

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