|
| 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); |
0 commit comments