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