diff --git a/PWGCF/TwoParticleCorrelations/Core/CMakeLists.txt b/PWGCF/TwoParticleCorrelations/Core/CMakeLists.txt index 557f6dbb674..a8b429afd05 100644 --- a/PWGCF/TwoParticleCorrelations/Core/CMakeLists.txt +++ b/PWGCF/TwoParticleCorrelations/Core/CMakeLists.txt @@ -16,6 +16,7 @@ o2physics_add_library(TwoPartCorrCore PIDSelectionFilterAndAnalysis.cxx EventSelectionFilterAndAnalysis.cxx FilterAndAnalysisFramework.cxx + DihadronContainer.cxx PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::PWGCFCore) o2physics_target_root_dictionary(TwoPartCorrCore @@ -25,4 +26,5 @@ o2physics_target_root_dictionary(TwoPartCorrCore PIDSelectionFilterAndAnalysis.h EventSelectionFilterAndAnalysis.h FilterAndAnalysisFramework.h + DihadronContainer.h LINKDEF TwoPartCorrLinkDef.h) diff --git a/PWGCF/TwoParticleCorrelations/Core/DihadronContainer.cxx b/PWGCF/TwoParticleCorrelations/Core/DihadronContainer.cxx new file mode 100644 index 00000000000..572fd3b25e2 --- /dev/null +++ b/PWGCF/TwoParticleCorrelations/Core/DihadronContainer.cxx @@ -0,0 +1,201 @@ +// 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 DihadronContainer.h +/// \brief minimum encapsulated container for di-hadron correlations +/// \author Zhiyong Lu (zhiyong.lu@cern.ch) +/// \since July/2026 + +#include "PWGCF/TwoParticleCorrelations/Core/DihadronContainer.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +using namespace o2; +using namespace o2::framework; + +ClassImp(DihadronContainer); + +DihadronContainer::DihadronContainer() : mCorrHist(nullptr), nCorrStep(1) +{ + // Default constructor +} + +DihadronContainer::DihadronContainer(const char* name, const char* objTitle, + const std::vector& correlationAxis, + const uint8_t nStep) : TNamed(name, objTitle), + mCorrHist(nullptr), + nCorrStep(nStep) +{ + + if (strlen(name) == 0) { + return; + } + + int64_t bins = 1; + LOGF(info, "Creating DihadronContainer:"); + for (UInt_t iAxis = 0; iAxis < correlationAxis.size(); iAxis++) { + LOGF(info, "correlationAxis[%d].getNbins() = %d", iAxis, correlationAxis[iAxis].getNbins()); + bins *= correlationAxis[iAxis].getNbins(); + } + 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); + + mCorrHist = HistFactory::createHist({"mCorrHist", "d^{2}N_{ch}/d#varphid#eta", {HistType::kStepTHnF, correlationAxis, nStep}}).release(); +} + +//_____________________________________________________________________________ +DihadronContainer::DihadronContainer(const DihadronContainer& c) : TNamed(c), + mCorrHist(nullptr), + nCorrStep(c.nCorrStep) +{ + // DihadronContainer copy constructor + if (c.mCorrHist) + mCorrHist = dynamic_cast(c.mCorrHist->Clone()); + else + mCorrHist = nullptr; +} + +//____________________________________________________________________ +DihadronContainer::~DihadronContainer() +{ + // Destructor + if (mCorrHist) { + delete mCorrHist; + mCorrHist = nullptr; + } +} + +//____________________________________________________________________ +DihadronContainer& DihadronContainer::operator=(const DihadronContainer& c) +{ + // assigment operator + if (this != &c) { + c.Copy(*this); + } + return *this; +} + +//____________________________________________________________________ +void DihadronContainer::Copy(TObject& c) const +{ + // copy function + auto target = dynamic_cast(c); + + if (mCorrHist) { + target.mCorrHist = dynamic_cast(mCorrHist->Clone()); + } + + target.nCorrStep = nCorrStep; +} + +//____________________________________________________________________ +void DihadronContainer::deepCopy(DihadronContainer* from) +{ + // copies the entries of this object's members from the object to this object + // fills using the fill function and thus allows that the objects have different binning + + for (Int_t step = 0; step < mCorrHist->getNSteps(); step++) { + LOGF(info, "Copying step %d", step); + THnBase* target = mCorrHist->getTHn(step); + THnBase* source = from->mCorrHist->getTHn(step); + + target->Reset(); + target->RebinnedAdd(source); + } +} + +//____________________________________________________________________ +Long64_t DihadronContainer::Merge(TCollection* list) +{ + // Merge a list of DihadronContainer objects with this + // Returns the number of merged objects (including this). + + if (!list) { + return 0; + } + + if (list->IsEmpty()) { + return 1; + } + + TIterator* iter = list->MakeIterator(); + TObject* obj = nullptr; + + // collections of objects + const UInt_t kMaxLists = 1; + auto lists = new TList*[kMaxLists]; + + for (UInt_t i = 0; i < kMaxLists; i++) { + lists[i] = new TList; + } + + Int_t count = 0; + while ((obj = iter->Next())) { + + auto entry = dynamic_cast(obj); + if (entry == nullptr) { + continue; + } + + if (entry->mCorrHist) { + lists[0]->Add(entry->mCorrHist); + } + + count++; + } + + if (mCorrHist) { + mCorrHist->Merge(lists[0]); + } + + for (UInt_t i = 0; i < kMaxLists; i++) { + delete lists[i]; + } + + delete[] lists; + + return count + 1; +} + +//____________________________________________________________________ +void DihadronContainer::Reset() +{ + // resets all contained histograms + + for (Int_t step = 0; step < mCorrHist->getNSteps(); step++) { + mCorrHist->getTHn(step)->Reset(); + } +} + +THnBase* DihadronContainer::changeToThn(THnBase* sparse) +{ + // change the object to THn for faster processing + + return THn::CreateHn(Form("%s_thn", sparse->GetName()), sparse->GetTitle(), sparse); +} + +ClassImp(DihadronContainer); diff --git a/PWGCF/TwoParticleCorrelations/Core/DihadronContainer.h b/PWGCF/TwoParticleCorrelations/Core/DihadronContainer.h new file mode 100644 index 00000000000..0ddfe8db4b9 --- /dev/null +++ b/PWGCF/TwoParticleCorrelations/Core/DihadronContainer.h @@ -0,0 +1,70 @@ +// 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. + +#ifndef PWGCF_TWOPARTICLECORRELATIONS_CORE_DIHADRONCONTAINER_H_ +#define PWGCF_TWOPARTICLECORRELATIONS_CORE_DIHADRONCONTAINER_H_ + +/// \file DihadronContainer.h +/// \brief minimum encapsulated container for di-hadron correlations +/// \author Zhiyong Lu (zhiyong.lu@cern.ch) +/// \since July/2026 + +#include + +#include + +#include +#include + +#include +#include + +class TH1; +class TH1F; +class TH3; +class TH3F; +class TH2F; +class TH1D; +class TH2; +class TH2D; +class TCollection; +class THnSparse; +class THnBase; +class StepTHn; + +class DihadronContainer : public TNamed +{ + public: + DihadronContainer(); + DihadronContainer(const char* name, const char* objTitle, const std::vector& correlationAxis, const uint8_t nStep = 1); + virtual ~DihadronContainer(); // NOLINT(modernize-use-override) + + StepTHn* getCorrHist() { return mCorrHist; } + void setCorrHist(StepTHn* hist) { mCorrHist = hist; } + void printCorrHist(); + + DihadronContainer(const DihadronContainer& c); + DihadronContainer& operator=(const DihadronContainer& corr); + virtual void Copy(TObject& c) const; // NOLINT: Making this override breaks compilation for unknown reason + void deepCopy(DihadronContainer* from); + + virtual Long64_t Merge(TCollection* list); + void Reset(); + THnBase* changeToThn(THnBase* sparse); + + protected: + StepTHn* mCorrHist; // container for n-dimension correlations + uint8_t nCorrStep; + + ClassDef(DihadronContainer, 2) // underlying event histogram container +}; + +#endif // PWGCF_TWOPARTICLECORRELATIONS_CORE_DIHADRONCONTAINER_H_ diff --git a/PWGCF/TwoParticleCorrelations/Core/TwoPartCorrLinkDef.h b/PWGCF/TwoParticleCorrelations/Core/TwoPartCorrLinkDef.h index c6ff9c1ac28..3bb61740aaa 100644 --- a/PWGCF/TwoParticleCorrelations/Core/TwoPartCorrLinkDef.h +++ b/PWGCF/TwoParticleCorrelations/Core/TwoPartCorrLinkDef.h @@ -50,5 +50,6 @@ #pragma link C++ class o2::analysis::PWGCF::EventSelectionFilterAndAnalysis::PileUpRejBrick + ; #pragma link C++ class o2::analysis::PWGCF::EventSelectionFilterAndAnalysis + ; #pragma link C++ class o2::analysis::PWGCF::FilterAndAnalysisFramework + ; +#pragma link C++ class DihadronContainer + ; #endif // PWGCF_TWOPARTICLECORRELATIONS_CORE_TWOPARTCORRLINKDEF_H_