From da0321f25e4dbb34f9ee52b05ba5eeedff9d2840 Mon Sep 17 00:00:00 2001 From: Emil Gorm Nielsen Date: Tue, 15 Sep 2026 23:10:44 +0200 Subject: [PATCH 1/5] FlowContainer bug cleanup --- PWGCF/GenericFramework/Core/FlowContainer.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PWGCF/GenericFramework/Core/FlowContainer.cxx b/PWGCF/GenericFramework/Core/FlowContainer.cxx index c51fe3ece8a..4578b538cc4 100644 --- a/PWGCF/GenericFramework/Core/FlowContainer.cxx +++ b/PWGCF/GenericFramework/Core/FlowContainer.cxx @@ -1237,5 +1237,5 @@ double* FlowContainer::GetMultiRebin(int& nbins) double* retBins = new double[fMultiRebin + 1]; for (int i = 0; i <= nbins; i++) retBins[i] = fMultiRebinEdges[i]; - return fMultiRebinEdges; + return retBins; } From 94a2d16c2ea701a52052b4f1480c4936749a5d27 Mon Sep 17 00:00:00 2001 From: Emil Gorm Nielsen Date: Wed, 16 Sep 2026 01:01:30 +0200 Subject: [PATCH 2/5] more linter cleanup in GFW --- PWGCF/GenericFramework/Core/GFW.cxx | 88 ++++--- PWGCF/GenericFramework/Core/GFW.h | 7 +- PWGCF/GenericFramework/Core/GFWPowerArray.cxx | 110 +++++---- PWGCF/GenericFramework/Core/GFWPowerArray.h | 18 +- PWGCF/GenericFramework/Core/GFWWeights.cxx | 215 +++++++++++++++--- PWGCF/GenericFramework/Core/GFWWeights.h | 22 +- 6 files changed, 327 insertions(+), 133 deletions(-) diff --git a/PWGCF/GenericFramework/Core/GFW.cxx b/PWGCF/GenericFramework/Core/GFW.cxx index 3faf5142531..24f8708fdab 100644 --- a/PWGCF/GenericFramework/Core/GFW.cxx +++ b/PWGCF/GenericFramework/Core/GFW.cxx @@ -9,12 +9,18 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. +/// \file GFW.cxx +/// \brief Initialize regions and calculate n-particle correlations +/// \author Emil Gorm Nielsen, NBI, emil.gorm.nielsen@cern.ch + #include "GFW.h" #include "PWGCF/GenericFramework/Core/GFWPowerArray.h" +#include + #include -#include +#include #include #include #include @@ -22,10 +28,20 @@ using std::complex; using std::pair; using std::string; -using std::vector; + +namespace +{ +constexpr std::size_t TwoParticleOrder = 2; +constexpr std::size_t ThreeParticleOrder = 3; +} // namespace GFW::GFW() : fInitialized(false) {} +void GFW::Region::PrintStructure() +{ + LOGF(info, "%s: eta [%f.. %f].", rName.c_str(), EtaMin, EtaMax); +} + GFW::~GFW() { for (auto pItr = fCumulants.begin(); pItr != fCumulants.end(); ++pItr) @@ -34,15 +50,15 @@ GFW::~GFW() void GFW::AddRegion(const string& refName, double lEtaMin, double lEtaMax, int lNpT, int BitMask) { if (lNpT < 1) { - printf("Number of pT bins cannot be less than 1! Not adding anything.\n"); + LOGF(warning, "Number of pT bins cannot be less than 1! Not adding anything."); return; } if (lEtaMin >= lEtaMax) { - printf("Eta min. cannot be more than eta max! Not adding...\n"); + LOGF(warning, "Eta min. cannot be more than eta max! Not adding..."); return; } if (refName == "") { - printf("Region must have a name!\n"); + LOGF(warning, "Region must have a name!"); return; } Region lOneRegion; @@ -56,23 +72,26 @@ void GFW::AddRegion(const string& refName, double lEtaMin, double lEtaMax, int l lOneRegion.BitMask = BitMask; // Bit mask AddRegion(lOneRegion); }; -void GFW::AddRegion(const string& refName, const vector& lNparVec, double lEtaMin, double lEtaMax, int lNpT, int BitMask) +void GFW::AddRegion(string refName, std::vector lNparVec, double lEtaMin, double lEtaMax, int lNpT, int BitMask) { - AddRegion(std::move(refName), lEtaMin, lEtaMax, lNpT, BitMask); + const auto oldSize = fRegions.size(); + AddRegion(refName, lEtaMin, lEtaMax, lNpT, BitMask); + if (fRegions.size() == oldSize) + return; (fRegions.end() - 1)->Nhar = static_cast(lNparVec.size()); (fRegions.end() - 1)->NparVec = lNparVec; (fRegions.end() - 1)->powsDefined = true; }; void GFW::AddRegion(string refName, int lNhar, int lNpar, double lEtaMin, double lEtaMax, int lNpT, int BitMask) { - vector tVec = {}; + std::vector tVec = {}; for (int i = 0; i < lNhar; i++) tVec.push_back(lNpar); AddRegion(std::move(refName), tVec, lEtaMin, lEtaMax, lNpT, BitMask); }; void GFW::AddRegion(string refName, int lNhar, int* lNparVec, double lEtaMin, double lEtaMax, int lNpT, int BitMask) { - vector tVec = {}; + std::vector tVec = {}; for (int i = 0; i < lNhar; i++) tVec.push_back(lNparVec[i]); AddRegion(std::move(refName), tVec, lEtaMin, lEtaMax, lNpT, BitMask); @@ -84,14 +103,13 @@ int GFW::CreateRegions() fCumulants.clear(); InitializePowerArrays(); if (fRegions.size() < 1) { - printf("No regions set. Skipping...\n"); + LOGF(warning, "No regions set. Skipping..."); return 0; } int nRegions = 0; for (auto pItr = fRegions.begin(); pItr != fRegions.end(); pItr++) { - GFWCumulant* lCumulant = new GFWCumulant(); - lCumulant->CreateComplexVectorArrayVarPower(pItr->Nhar, pItr->NparVec, pItr->NpT); - fCumulants.push_back(*lCumulant); + fCumulants.emplace_back(); + fCumulants.back().CreateComplexVectorArrayVarPower(pItr->Nhar, pItr->NparVec, pItr->NpT); ++nRegions; } if (nRegions) @@ -114,22 +132,24 @@ complex GFW::TwoRec(int n1, int n2, int p1, int p2, int ptbin, GFWCumula complex formula = part1 * part2 - part3; return formula; }; -complex GFW::RecursiveCorr(GFWCumulant* qpoi, GFWCumulant* qref, GFWCumulant* qol, int ptbin, vector& hars) +complex GFW::RecursiveCorr(GFWCumulant* qpoi, GFWCumulant* qref, GFWCumulant* qol, int ptbin, std::vector& hars) { - vector pows; + std::vector pows; for (int i = 0; i < static_cast(hars.size()); i++) pows.push_back(1); return RecursiveCorr(qpoi, qref, qol, ptbin, hars, pows); }; -complex GFW::RecursiveCorr(GFWCumulant* qpoi, GFWCumulant* qref, GFWCumulant* qol, int ptbin, vector& hars, vector& pows) +complex GFW::RecursiveCorr(GFWCumulant* qpoi, GFWCumulant* qref, GFWCumulant* qol, int ptbin, std::vector& hars, std::vector& pows) { + if (hars.empty() || pows.empty()) + return complex(0, 0); if ((pows.at(0) != 1) && qol) qpoi = qol; // if the power of POI is not unity, then always use overlap (if defined). // Only valid for 1 particle of interest though! - if (hars.size() < 2) + if (hars.size() < TwoParticleOrder) return qpoi->Vec(hars.at(0), pows.at(0), ptbin); - if (hars.size() < 3) + if (hars.size() < ThreeParticleOrder) return TwoRec(hars.at(0), hars.at(1), pows.at(0), pows.at(1), ptbin, qpoi, qref, qol); int harlast = hars.at(hars.size() - 1); int powlast = pows.at(pows.size() - 1); @@ -141,7 +161,7 @@ complex GFW::RecursiveCorr(GFWCumulant* qpoi, GFWCumulant* qref, GFWCumu for (int i = harSize - 1; i >= 0; i--) { // checking if current configuration is a permutation of the next one. // Need to have more than 2 harmonics though, otherwise it doesn't make sense. - if (i > 2) { // only makes sense when we have more than two harmonics remaining + if (i > static_cast(TwoParticleOrder)) { // only makes sense when we have more than two harmonics remaining if (hars.at(i) == hars.at(i - 1) && pows.at(i) == pows.at(i - 1)) { // if it is a permutation, then increase degeneracy and continue; lDegeneracy++; continue; @@ -181,30 +201,30 @@ GFW::CorrConfig GFW::GetCorrelatorConfig(string config, string head, bool ptdif) // Then make sure we don't have any double-spaces: while (s_index(config, " ") > -1) s_replace_all(config, " ", " "); - vector regs; - vector hars; + std::vector regs; + std::vector hars; int sz1 = 0; int szend = 0; string ts, ts2; CorrConfig ReturnConfig; // Fetch region descriptor if (!s_tokenize(config, ts, szend, "{")) { - printf("Could not find any harmonics!\n"); + LOGF(warning, "Could not find any harmonics!"); return ReturnConfig; } szend = 0; int counter = 0; while (s_tokenize(config, ts, szend, "{")) { counter++; - ReturnConfig.Regs.push_back(vector{}); - ReturnConfig.Hars.push_back(vector{}); + ReturnConfig.Regs.push_back(std::vector{}); + ReturnConfig.Hars.push_back(std::vector{}); ReturnConfig.Overlap.push_back(-1); // initially, assume no overlap // Check if there's a particular pT bin I should be using here. If so, store it (otherwise, it's bin 0) int ptbin = -1; int sz2 = 0; if (s_contains(ts, "(")) { if (!s_contains(ts, ")")) { - printf("Missing \")\" in the configurator. Returning...\n"); + LOGF(warning, "Missing \")\" in the configurator. Returning..."); return ReturnConfig; } sz2 = s_index(ts, "("); @@ -231,7 +251,7 @@ GFW::CorrConfig GFW::GetCorrelatorConfig(string config, string head, bool ptdif) if (ts2 == " " || ts2 == "") continue; if (ind < 0) { - printf("Could not find region named %s!\n", ts2.c_str()); + LOGF(warning, "Could not find region named %s!", ts2.c_str()); break; } if (!isOverlap) @@ -253,7 +273,7 @@ GFW::CorrConfig GFW::GetCorrelatorConfig(string config, string head, bool ptdif) return ReturnConfig; }; -complex GFW::Calculate(int poi, int ref, vector hars, int ptbin) +complex GFW::Calculate(int poi, int ref, std::vector hars, int ptbin) { GFWCumulant* qref = &fCumulants.at(ref); GFWCumulant* qpoi = &fCumulants.at(poi); @@ -305,13 +325,13 @@ complex GFW::Calculate(CorrConfig corconf, int ptbin, bool SetHarmsToZer } return retval; }; -vector>> GFW::GetHarmonicsSingleConfig(const CorrConfig& incfg) +std::vector>> GFW::GetHarmonicsSingleConfig(const CorrConfig& incfg) { - vector>> retPair; + std::vector>> retPair; for (int iR = 0; iR < static_cast(incfg.Regs.size()); iR++) { if (static_cast(incfg.Regs[iR].size()) > 1) { - retPair.push_back(make_pair(incfg.Regs[iR][0], vector{incfg.Hars[iR][0]})); // If we have a PoI, then it comes with the first harmonic - retPair.push_back(make_pair(incfg.Regs[iR][1], incfg.Hars[iR])); // Then the second is ref. with full harmonics + retPair.push_back(make_pair(incfg.Regs[iR][0], std::vector{incfg.Hars[iR][0]})); // If we have a PoI, then it comes with the first harmonic + retPair.push_back(make_pair(incfg.Regs[iR][1], incfg.Hars[iR])); // Then the second is ref. with full harmonics } else { retPair.push_back(make_pair(incfg.Regs[iR][0], incfg.Hars[iR])); // Otherwise, it's only ref with all harmonics } @@ -322,7 +342,7 @@ vector>> GFW::GetHarmonicsSingleConfig(const CorrConfig& i }; void GFW::InitializePowerArrays() { - vector>> harSets(static_cast(fRegions.size())); + std::vector>> harSets(static_cast(fRegions.size())); for (const CorrConfig& lConf : fListOfCFGs) { auto HarPerReg = GetHarmonicsSingleConfig(lConf); for (const auto& oneHar : HarPerReg) @@ -332,13 +352,13 @@ void GFW::InitializePowerArrays() for (int i = 0; i < static_cast(harSets.size()); i++) { if (fRegions[i].powsDefined) continue; // Only do if powers have not been externally defined - vector powerArray = GFWPowerArray::GetPowerArray(harSets[i]); + std::vector powerArray = GFWPowerArray::GetPowerArray(harSets[i]); fRegions[i].Nhar = static_cast(powerArray.size()); fRegions[i].NparVec = powerArray; fRegions[i].powsDefined = true; } }; -complex GFW::Calculate(int poi, vector hars) +complex GFW::Calculate(int poi, std::vector hars) { GFWCumulant* qpoi = &fCumulants.at(poi); return RecursiveCorr(qpoi, qpoi, qpoi, 0, hars); diff --git a/PWGCF/GenericFramework/Core/GFW.h b/PWGCF/GenericFramework/Core/GFW.h index 481f5ce6bff..4c03d288c6c 100644 --- a/PWGCF/GenericFramework/Core/GFW.h +++ b/PWGCF/GenericFramework/Core/GFW.h @@ -9,7 +9,7 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// \file GFW.h/.cxx +/// \file GFW.h /// \brief Class steers the initialization and calculation of n-particle correlations. Uses recursive function, all terms are calculated only once. /// \author Emil Gorm Nielsen (ack. V. Vislavicius), NBI, emil.gorm.nielsen@cern.ch @@ -19,7 +19,6 @@ #include "GFWCumulant.h" #include -#include #include #include #include @@ -39,7 +38,7 @@ class GFW { return EtaMin < a.EtaMin; }; - void PrintStructure() { printf("%s: eta [%f.. %f].", rName.c_str(), EtaMin, EtaMax); } + void PrintStructure(); }; struct CorrConfig { std::vector> Regs{}; @@ -50,6 +49,8 @@ class GFW std::string Head = ""; }; GFW(); + GFW(const GFW&) = delete; + GFW& operator=(const GFW&) = delete; ~GFW(); std::vector fRegions; std::vector fCumulants; diff --git a/PWGCF/GenericFramework/Core/GFWPowerArray.cxx b/PWGCF/GenericFramework/Core/GFWPowerArray.cxx index d8c988b111e..d5928c504df 100644 --- a/PWGCF/GenericFramework/Core/GFWPowerArray.cxx +++ b/PWGCF/GenericFramework/Core/GFWPowerArray.cxx @@ -9,108 +9,124 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. +/// \file GFWPowerArray.cxx +/// \brief Compute required powers of Q-vectors for harmonic sets +/// \author Emil Gorm Nielsen, NBI, emil.gorm.nielsen@cern.ch + #include "GFWPowerArray.h" +#include + +#include #include -#include #include +#include +#include #include #include #include -using std::string; -using std::vector; - int GFWPowerArray::getHighestHarmonic(const HarSet& inhar) { // Highest possible harmonic: sum of same-sign harmonics - int maxPos = 0, maxNeg = 0; - for (int val : inhar) + int64_t maxPos = 0, maxNeg = 0; + for (const int& val : inhar) { if (val > 0) maxPos += val; else - maxNeg += abs(val); - return maxPos > maxNeg ? maxPos : maxNeg; + maxNeg += std::abs(static_cast(val)); + if (maxPos >= std::numeric_limits::max() || maxNeg >= std::numeric_limits::max()) + throw std::overflow_error("Harmonic sum exceeds the supported range"); + } + return static_cast(std::max(maxPos, maxNeg)); }; -HarSet GFWPowerArray::TrimVec(HarSet hars, int ind) +HarSet GFWPowerArray::trimVec(const HarSet& hars, int ind) { HarSet retVec = std::move(hars); retVec.erase(retVec.begin() + ind); return retVec; }; -HarSet GFWPowerArray::AddConstant(HarSet hars, int offset) +HarSet GFWPowerArray::addConstant(const HarSet& hars, int offset) { +<<<<<<< HEAD HarSet retVec = std::move(hars); for (int& val : retVec) +======= + HarSet retVec = hars; + for (int& val : retVec) // o2-linter: disable=const-ref-in-for-loop (updates each harmonic) +>>>>>>> d563a1043 (more linter cleanup in GFW) val += offset; return retVec; }; -void GFWPowerArray::FlushVectorToMaster(HarSet& masterVector, HarSet& comVec, const int& MaxPower) +void GFWPowerArray::flushVectorToMaster(HarSet& masterVector, const HarSet& comVec, int maxPower) { - int nPartLoc = MaxPower - comVec.size() + 1; - for (auto& val : comVec) { - int absVal = abs(val); + int nPartLoc = maxPower - static_cast(comVec.size()) + 1; + for (const int& val : comVec) { + int absVal = std::abs(val); if (masterVector.at(absVal) < nPartLoc) { masterVector.at(absVal) = nPartLoc; } } }; -void GFWPowerArray::RecursiveFunction(HarSet& masterVector, HarSet hars, int offset, const int& MaxPower) +void GFWPowerArray::recursiveFunction(HarSet& masterVector, const HarSet& hars, int offset, int maxPower, std::size_t startIndex) { - HarSet compVec = AddConstant(hars, offset); - FlushVectorToMaster(masterVector, compVec, MaxPower); - for (size_t i = 0; i < hars.size(); i++) - RecursiveFunction(masterVector, TrimVec(hars, i), offset + hars.at(i), MaxPower); - ; + HarSet compVec = addConstant(hars, offset); + flushVectorToMaster(masterVector, compVec, maxPower); + for (std::size_t i = startIndex; i < hars.size(); i++) + recursiveFunction(masterVector, trimVec(hars, static_cast(i)), offset + hars.at(i), maxPower, i); }; -void GFWPowerArray::PrintVector(const HarSet& singleSet) +void GFWPowerArray::printVector(const HarSet& singleSet) { - int vcSize = static_cast(singleSet.size()); - if (!vcSize) - printf("Vector is empty!\n"); - printf("{%i", singleSet[0]); - for (int i = 1; i < vcSize; i++) - printf(", %i", singleSet[i]); - printf("}\n"); + if (singleSet.empty()) { + LOGF(info, "Vector is empty!"); + return; + } + std::string output = "{" + std::to_string(singleSet[0]); + for (std::size_t i = 1; i < singleSet.size(); i++) + output += ", " + std::to_string(singleSet[i]); + output += "}"; + LOGF(info, "%s", output.c_str()); } -HarSet GFWPowerArray::GetPowerArray(const vector& inHarmonics) +HarSet GFWPowerArray::GetPowerArray(std::vector inHarmonics) // o2-linter: disable=name/function-variable (preserve existing public API) { // First, find maximum number of particle correlations ( = max power) and maximum (sum of) harmonics - int MaxHar = 0; - int nMaxPart = 0; + int maxHar = 0; + int maxPart = 0; for (const HarSet& singleSet : inHarmonics) { int harSum = getHighestHarmonic(singleSet); - MaxHar = harSum > MaxHar ? harSum : MaxHar; + maxHar = harSum > maxHar ? harSum : maxHar; } - // Make a vector with MaxHar+1 entries (entry 0 for sum=0) - HarSet retVec = HarSet(MaxHar + 1); + // Make a vector with maxHar+1 entries (entry 0 for sum=0) + HarSet retVec = HarSet(maxHar + 1); // Then loop over all combinations and calculate max powers for (const HarSet& singleSet : inHarmonics) { + if (singleSet.size() >= static_cast(std::numeric_limits::max())) + throw std::overflow_error("Harmonic set exceeds the supported particle count"); int lNPart = static_cast(singleSet.size()); // Total number of particles correlated - RecursiveFunction(retVec, singleSet, 0, lNPart); + recursiveFunction(retVec, singleSet, 0, lNPart, 0); // Harmonic sum = 0 is a special case. In principle all 0 cases with non-zero harmonics are captured by the function above, but to calculate normalization, we set all harmonics to 0. This means that sum=0 power is the max number of harmonics/particles being correlated - nMaxPart = (lNPart > nMaxPart) ? lNPart : nMaxPart; + maxPart = (lNPart > maxPart) ? lNPart : maxPart; } // Override the sum=0 power with the number of correlated particles - if (retVec[0] < nMaxPart) - retVec[0] = nMaxPart; + if (retVec[0] < maxPart) + retVec[0] = maxPart; // Need an extra power ( = 0) for all non-zero powers - for (int& val : retVec) + for (int& val : retVec) // o2-linter: disable=const-ref-in-for-loop (increments the required powers) if (val != 0) val++; return retVec; }; -void GFWPowerArray::PowerArrayTest() +void GFWPowerArray::PowerArrayTest() // o2-linter: disable=name/function-variable (preserve existing public API) { - vector AllHars = { + std::vector allHars = { HarSet{2}, HarSet{3}, HarSet{2, 2}, HarSet{3, 3}}; - printf("Input harmonics are:\n"); - for (const HarSet& inSet : AllHars) - PrintVector(inSet); - printf("The configuration of powers must then be:\n"); - auto vc = GetPowerArray(AllHars); - PrintVector(vc); + LOGF(info, "Input harmonics are:"); + for (const HarSet& inSet : allHars) + printVector(inSet); + LOGF(info, "The configuration of powers must then be:"); + auto vc = GetPowerArray(allHars); + printVector(vc); }; diff --git a/PWGCF/GenericFramework/Core/GFWPowerArray.h b/PWGCF/GenericFramework/Core/GFWPowerArray.h index 7f83a72a3b7..0f5ee94697f 100644 --- a/PWGCF/GenericFramework/Core/GFWPowerArray.h +++ b/PWGCF/GenericFramework/Core/GFWPowerArray.h @@ -9,29 +9,29 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// \file GFWPowerArray.h/.cxx +/// \file GFWPowerArray.h /// \brief Class to compute necessary powers of Q-vectors based on input correlations /// \author Emil Gorm Nielsen, NBI, emil.gorm.nielsen@cern.ch #ifndef PWGCF_GENERICFRAMEWORK_CORE_GFWPOWERARRAY_H_ #define PWGCF_GENERICFRAMEWORK_CORE_GFWPOWERARRAY_H_ -#include +#include #include typedef std::vector HarSet; class GFWPowerArray { public: - static HarSet GetPowerArray(const std::vector& inHarmonics); - static void PowerArrayTest(); + static HarSet GetPowerArray(std::vector inHarmonics); // o2-linter: disable=name/function-variable (preserve existing public API) + static void PowerArrayTest(); // o2-linter: disable=name/function-variable (preserve existing public API) private: static int getHighestHarmonic(const HarSet& inhar); - static HarSet TrimVec(HarSet hars, int ind); - static HarSet AddConstant(HarSet hars, int offset); - static void FlushVectorToMaster(HarSet& masterVector, HarSet& comVec, const int& MaxPower); - static void RecursiveFunction(HarSet& masterVector, HarSet hars, int offset, const int& MaxPower); - static void PrintVector(const HarSet& singleSet); + static HarSet trimVec(const HarSet& hars, int ind); + static HarSet addConstant(const HarSet& hars, int offset); + static void flushVectorToMaster(HarSet& masterVector, const HarSet& comVec, int maxPower); + static void recursiveFunction(HarSet& masterVector, const HarSet& hars, int offset, int maxPower, std::size_t startIndex); + static void printVector(const HarSet& singleSet); }; #endif // PWGCF_GENERICFRAMEWORK_CORE_GFWPOWERARRAY_H_ diff --git a/PWGCF/GenericFramework/Core/GFWWeights.cxx b/PWGCF/GenericFramework/Core/GFWWeights.cxx index 7373995c3e2..ca51f112d84 100644 --- a/PWGCF/GenericFramework/Core/GFWWeights.cxx +++ b/PWGCF/GenericFramework/Core/GFWWeights.cxx @@ -9,6 +9,10 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. +/// \file GFWWeights.cxx +/// \brief Implementation of corrections for the Generic Framework +/// \author Emil Gorm Nielsen, NBI, emil.gorm.nielsen@cern.ch + #include "GFWWeights.h" #include @@ -25,7 +29,49 @@ #include +#include #include +#include + +namespace +{ +constexpr int MCGenType = 2; + +TObjArray* cloneArray(TObjArray* source) +{ + if (!source) + return 0; + TObjArray* result = new TObjArray(); + result->SetName(source->GetName()); + result->SetOwner(kTRUE); + for (int i = 0; i < source->GetEntries(); i++) { + if (!source->At(i)) + continue; + TH3D* hist = reinterpret_cast(source->At(i)->Clone()); + hist->SetDirectory(0); + result->AddAt(hist, i); + } + return result; +} + +TH3D* cloneTH3D(TH3D* source) +{ + if (!source) + return 0; + TH3D* result = reinterpret_cast(source->Clone()); + result->SetDirectory(0); + return result; +} + +TH1D* cloneTH1D(TH1D* source) +{ + if (!source) + return 0; + TH1D* result = reinterpret_cast(source->Clone()); + result->SetDirectory(0); + return result; +} +} // namespace GFWWeights::GFWWeights() : TNamed("", ""), fDataFilled(kFALSE), @@ -49,6 +95,42 @@ GFWWeights::GFWWeights(const char* name) : TNamed(name, name), fAccInt(0), fNbinsPt(0), fbinsPt(0) {} +GFWWeights::GFWWeights(const GFWWeights& other) : TNamed(other), + fDataFilled(other.fDataFilled), + fMCFilled(other.fMCFilled), + fW_data(cloneArray(other.fW_data)), + fW_mcrec(cloneArray(other.fW_mcrec)), + fW_mcgen(cloneArray(other.fW_mcgen)), + fEffInt(cloneTH3D(other.fEffInt)), + fIntEff(cloneTH1D(other.fIntEff)), + fAccInt(cloneTH3D(other.fAccInt)), + fNbinsPt(other.fNbinsPt), + fbinsPt(0) +{ + if (other.fbinsPt) { + fbinsPt = new double[fNbinsPt + 1]; + for (int i = 0; i <= fNbinsPt; i++) + fbinsPt[i] = other.fbinsPt[i]; + } +} +GFWWeights& GFWWeights::operator=(const GFWWeights& other) +{ + if (this == &other) + return *this; + GFWWeights copy(other); + TNamed::operator=(other); + std::swap(fDataFilled, copy.fDataFilled); + std::swap(fMCFilled, copy.fMCFilled); + std::swap(fW_data, copy.fW_data); + std::swap(fW_mcrec, copy.fW_mcrec); + std::swap(fW_mcgen, copy.fW_mcgen); + std::swap(fEffInt, copy.fEffInt); + std::swap(fIntEff, copy.fIntEff); + std::swap(fAccInt, copy.fAccInt); + std::swap(fNbinsPt, copy.fNbinsPt); + std::swap(fbinsPt, copy.fbinsPt); + return *this; +} GFWWeights::~GFWWeights() { delete fW_data; @@ -78,14 +160,25 @@ void GFWWeights::init(bool AddData, bool AddMC) fbinsPt[1] = 1e6; } if (AddData) { + delete fAccInt; + fAccInt = 0; + delete fW_data; fW_data = new TObjArray(); fW_data->SetName("GFWWeights_Data"); fW_data->SetOwner(kTRUE); const char* tnd = getBinName(0, 0, Form("data_%s", this->GetName())); - fW_data->Add(new TH3D(tnd, ";#varphi;#eta;v_{z}", 60, 0, TMath::TwoPi(), 64, -1.6, 1.6, 40, -10, 10)); + TH3D* hist = new TH3D(tnd, ";#varphi;#eta;v_{z}", 60, 0, TMath::TwoPi(), 64, -1.6, 1.6, 40, -10, 10); // o2-linter: disable=external-pi (ROOT histogram axis uses double-precision two pi) + hist->SetDirectory(0); + fW_data->Add(hist); fDataFilled = kTRUE; } if (AddMC) { + delete fEffInt; + delete fIntEff; + fEffInt = 0; + fIntEff = 0; + delete fW_mcrec; + delete fW_mcgen; fW_mcrec = new TObjArray(); fW_mcrec->SetName("GFWWeights_MCRec"); fW_mcgen = new TObjArray(); @@ -94,8 +187,12 @@ void GFWWeights::init(bool AddData, bool AddMC) fW_mcgen->SetOwner(kTRUE); const char* tnr = getBinName(0, 0, "mcrec"); // all integrated over cent. anyway const char* tng = getBinName(0, 0, "mcgen"); // all integrated over cent. anyway - fW_mcrec->Add(new TH3D(tnr, ";#it{p}_{T};#eta;v_{z}", fNbinsPt, 0, 20, 64, -1.6, 1.6, 40, -10, 10)); - fW_mcgen->Add(new TH3D(tng, ";#it{p}_{T};#eta;v_{z}", fNbinsPt, 0, 20, 64, -1.6, 1.6, 40, -10, 10)); + TH3D* rec = new TH3D(tnr, ";#it{p}_{T};#eta;v_{z}", fNbinsPt, 0, 20, 64, -1.6, 1.6, 40, -10, 10); + TH3D* gen = new TH3D(tng, ";#it{p}_{T};#eta;v_{z}", fNbinsPt, 0, 20, 64, -1.6, 1.6, 40, -10, 10); + rec->SetDirectory(0); + gen->SetDirectory(0); + fW_mcrec->Add(rec); + fW_mcgen->Add(gen); reinterpret_cast(fW_mcrec->At(fW_mcrec->GetEntries() - 1))->GetXaxis()->Set(fNbinsPt, fbinsPt); reinterpret_cast(fW_mcgen->At(fW_mcgen->GetEntries() - 1))->GetXaxis()->Set(fNbinsPt, fbinsPt); fMCFilled = kTRUE; @@ -114,7 +211,7 @@ void GFWWeights::fill(double phi, double eta, double vz, double pt, double /*cen tar = fW_mcrec; pf = "mcrec"; } - if (htype == 2) { + if (htype == MCGenType) { tar = fW_mcgen; pf = "mcgen"; } @@ -122,8 +219,11 @@ void GFWWeights::fill(double phi, double eta, double vz, double pt, double /*cen return; TH3D* th3 = reinterpret_cast(tar->FindObject(getBinName(0, 0, pf))); // pT bin 0, V0M bin 0, since all integrated if (!th3) { - if (!htype) - tar->Add(new TH3D(getBinName(0, 0, pf), ";#varphi;#eta;v_{z}", 60, 0, TMath::TwoPi(), 64, -1.6, 1.6, 40, -10, 10)); // 0,0 since all integrated + if (!htype) { + TH3D* hist = new TH3D(getBinName(0, 0, pf), ";#varphi;#eta;v_{z}", 60, 0, TMath::TwoPi(), 64, -1.6, 1.6, 40, -10, 10); // o2-linter: disable=external-pi (ROOT histogram axis uses double-precision two pi) + hist->SetDirectory(0); + tar->Add(hist); + } th3 = reinterpret_cast(tar->At(tar->GetEntries() - 1)); } th3->Fill(htype ? pt : phi, eta, vz, weight); @@ -134,13 +234,13 @@ double GFWWeights::getWeight(double phi, double eta, double vz, double pt, doubl const char* pf = ""; if (htype == 0) { tar = fW_data; - pf = "data"; + pf = Form("data_%s", this->GetName()); } if (htype == 1) { tar = fW_mcrec; pf = "mcrec"; } - if (htype == 2) { + if (htype == MCGenType) { tar = fW_mcgen; pf = "mcgen"; } @@ -161,6 +261,8 @@ double GFWWeights::getNUA(double phi, double eta, double vz) { if (!fAccInt) createNUA(); + if (!fAccInt) + return 1; int xind = fAccInt->GetXaxis()->FindBin(phi); int etaind = fAccInt->GetYaxis()->FindBin(eta); int vzind = fAccInt->GetZaxis()->FindBin(vz); @@ -173,6 +275,8 @@ double GFWWeights::getNUE(double pt, double eta, double vz) { if (!fEffInt) createNUE(); + if (!fEffInt) + return 1; int xind = fEffInt->GetXaxis()->FindBin(pt); int etaind = fEffInt->GetYaxis()->FindBin(eta); int vzind = fEffInt->GetZaxis()->FindBin(vz); @@ -212,7 +316,7 @@ void GFWWeights::mcToEfficiency() }; void GFWWeights::rebinNUA(int nX, int nY, int nZ) { - if (fW_data->GetEntries() < 1) + if (!fW_data || fW_data->GetEntries() < 1) return; for (int i = 0; i < fW_data->GetEntries(); i++) { reinterpret_cast(fW_data->At(i))->RebinX(nX); @@ -227,12 +331,13 @@ void GFWWeights::createNUA(bool IntegrateOverCentAndPt) return; } TH1D* h1; - if (fW_data->GetEntries() < 1) + if (!fW_data || fW_data->GetEntries() < 1) return; if (IntegrateOverCentAndPt) { if (fAccInt) delete fAccInt; fAccInt = reinterpret_cast(fW_data->At(0)->Clone("IntegratedAcceptance")); + fAccInt->SetDirectory(0); fAccInt->Sumw2(); for (int etai = 1; etai <= fAccInt->GetNbinsY(); etai++) { fAccInt->GetYaxis()->SetRange(etai, etai); @@ -258,13 +363,18 @@ void GFWWeights::createNUA(bool IntegrateOverCentAndPt) }; TH1D* GFWWeights::getdNdPhi() { + if (!fW_data || !fW_data->GetEntries()) + return 0; TH3D* temph = reinterpret_cast(fW_data->At(0)->Clone("tempH3")); TH1D* reth = reinterpret_cast(temph->Project3D("x")); reth->SetName("RetHist"); + reth->SetDirectory(0); delete temph; double max = reth->GetMaximum(); - if (max == 0) + if (max == 0) { + delete reth; return 0; + } for (int phi = 1; phi <= reth->GetNbinsX(); phi++) { if (reth->GetBinContent(phi) == 0) continue; @@ -281,7 +391,7 @@ void GFWWeights::createNUE(bool IntegrateOverCentrality) } TH3D* num = 0; TH3D* den = 0; - if (fW_mcrec->GetEntries() < 1 || fW_mcgen->GetEntries() < 1) + if (!fW_mcrec || !fW_mcgen || fW_mcrec->GetEntries() < 1 || fW_mcgen->GetEntries() < 1) return; if (IntegrateOverCentrality) { num = reinterpret_cast(fW_mcrec->At(0)); @@ -292,7 +402,9 @@ void GFWWeights::createNUE(bool IntegrateOverCentrality) den->RebinY(2); num->RebinZ(5); den->RebinZ(5); + delete fEffInt; fEffInt = reinterpret_cast(num->Clone("Efficiency_Integrated")); + fEffInt->SetDirectory(0); fEffInt->Divide(den); return; } @@ -300,13 +412,22 @@ void GFWWeights::createNUE(bool IntegrateOverCentrality) void GFWWeights::readAndMerge(const TString& filelinks, const TString& listName, bool addData, bool addRec, bool addGen) { FILE* flist = fopen(filelinks.Data(), "r"); + if (!flist) { + LOGF(warning, "Could not open file list %s!\n", filelinks.Data()); + return; + } char str[150]; int nFiles = 0; - while (fscanf(flist, "%s\n", str) == 1) + while (fscanf(flist, "%149s", str) == 1) nFiles++; - rewind(flist); + if (fseek(flist, 0, SEEK_SET) != 0) { + LOGF(warning, "Could not rewind file list %s!\n", filelinks.Data()); + fclose(flist); + return; + } if (nFiles == 0) { LOGF(info, "No files to read!\n"); + fclose(flist); return; } if (!fW_data && addData) { @@ -326,19 +447,31 @@ void GFWWeights::readAndMerge(const TString& filelinks, const TString& listName, } TFile* tf = 0; for (int i = 0; i < nFiles; i++) { - auto retVal = fscanf(flist, "%s\n", str); - (void)retVal; + if (fscanf(flist, "%149s", str) != 1) + break; tf = new TFile(str, "READ"); if (tf->IsZombie()) { LOGF(warning, "Could not open file %s!\n", str); tf->Close(); + delete tf; + continue; + } + TObject* obj = tf->Get(listName.Data()); + TList* tl = dynamic_cast(obj); + if (!tl) { + LOGF(warning, "Could not fetch list %s from %s\n", listName.Data(), str); + delete obj; + tf->Close(); + delete tf; continue; } - TList* tl = reinterpret_cast(tf->Get(listName.Data())); - GFWWeights* tw = reinterpret_cast(tl->FindObject(this->GetName())); + GFWWeights* tw = dynamic_cast(tl->FindObject(this->GetName())); if (!tw) { LOGF(warning, "Could not fetch weights object from %s\n", str); + tl->Delete(); + delete tl; tf->Close(); + delete tf; continue; } if (addData) @@ -347,9 +480,14 @@ void GFWWeights::readAndMerge(const TString& filelinks, const TString& listName, addArray(fW_mcrec, tw->getRecArray()); if (addGen) addArray(fW_mcgen, tw->getGenArray()); - tf->Close(); + tl->Remove(tw); delete tw; + tl->Delete(); + delete tl; + tf->Close(); + delete tf; } + fclose(flist); }; void GFWWeights::addArray(TObjArray* targ, TObjArray* sour) { @@ -373,15 +511,20 @@ void GFWWeights::overwriteNUA() { if (!fAccInt) createNUA(); + if (!fAccInt || !fW_data || !fW_data->GetEntries()) + return; TString ts(fW_data->At(0)->GetName()); TH3D* trash = reinterpret_cast(fW_data->RemoveAt(0)); delete trash; - fW_data->Add(reinterpret_cast(fAccInt->Clone(ts.Data()))); + TH3D* hist = reinterpret_cast(fAccInt->Clone(ts.Data())); + hist->SetDirectory(0); + fW_data->AddAt(hist, 0); delete fAccInt; + fAccInt = 0; } -Long64_t GFWWeights::Merge(TCollection* collist) +Long64_t GFWWeights::Merge(TCollection* collist) // o2-linter: disable=root/entity,name/function-variable (ROOT Merge requires this signature) { - Long64_t nmerged = 0; + Long64_t nmerged = 0; // o2-linter: disable=root/entity (matches ROOT Merge return type) if (!fW_data) { fW_data = new TObjArray(); fW_data->SetName("Weights_Data"); @@ -397,12 +540,12 @@ Long64_t GFWWeights::Merge(TCollection* collist) fW_mcgen->SetName("Weights_MCGen"); fW_mcgen->SetOwner(kTRUE); } - GFWWeights* l_w = 0; - TIter all_w(collist); - while ((l_w = (reinterpret_cast(all_w())))) { - addArray(fW_data, l_w->getDataArray()); - addArray(fW_mcrec, l_w->getRecArray()); - addArray(fW_mcgen, l_w->getGenArray()); + GFWWeights* weight = 0; + TIter allWeights(collist); + while ((weight = (reinterpret_cast(allWeights())))) { + addArray(fW_data, weight->getDataArray()); + addArray(fW_mcrec, weight->getRecArray()); + addArray(fW_mcgen, weight->getGenArray()); nmerged++; } return nmerged; @@ -433,8 +576,10 @@ TH1D* GFWWeights::getIntegratedEfficiencyHist() den->Add(reinterpret_cast(fW_mcgen->At(i))); TH1D* num1d = reinterpret_cast(num->Project3D("x")); num1d->SetName("retHist"); + num1d->SetDirectory(0); num1d->Sumw2(); TH1D* den1d = reinterpret_cast(den->Project3D("x")); + den1d->SetDirectory(0); den1d->Sumw2(); num1d->Divide(den1d); delete num; @@ -462,6 +607,8 @@ double GFWWeights::getIntegratedEfficiency(double pt) } TH1D* GFWWeights::getEfficiency(double etamin, double etamax, double vzmin, double vzmax) { + if (!fW_mcrec || !fW_mcgen || !fW_mcrec->GetEntries() || !fW_mcgen->GetEntries()) + return 0; TH3D* num = reinterpret_cast(fW_mcrec->At(0)->Clone("Numerator")); for (int i = 1; i < fW_mcrec->GetEntries(); i++) num->Add(reinterpret_cast(fW_mcrec->At(i))); @@ -478,6 +625,8 @@ TH1D* GFWWeights::getEfficiency(double etamin, double etamax, double vzmin, doub den->GetZaxis()->SetRange(vz1, vz2); TH1D* num1d = reinterpret_cast(num->Project3D("x")); TH1D* den1d = reinterpret_cast(den->Project3D("x")); + num1d->SetDirectory(0); + den1d->SetDirectory(0); delete num; delete den; num1d->Sumw2(); @@ -498,15 +647,21 @@ void GFWWeights::mergeWeights(GFWWeights* other) } void GFWWeights::setTH3D(TH3D* th3d) { + if (!th3d) + return; if (!fW_data) { fW_data = new TObjArray(); fW_data->SetName("GFWWeights_Data"); fW_data->SetOwner(kTRUE); - fW_data->Add(th3d); + TH3D* hist = reinterpret_cast(th3d->Clone()); + hist->SetDirectory(0); + fW_data->Add(hist); return; } TString ts(fW_data->At(0)->GetName()); TH3D* trash = reinterpret_cast(fW_data->RemoveAt(0)); delete trash; - fW_data->Add(reinterpret_cast(th3d->Clone(ts.Data()))); + TH3D* hist = reinterpret_cast(th3d->Clone(ts.Data())); + hist->SetDirectory(0); + fW_data->AddAt(hist, 0); } diff --git a/PWGCF/GenericFramework/Core/GFWWeights.h b/PWGCF/GenericFramework/Core/GFWWeights.h index bcec7463647..bf255a731e5 100644 --- a/PWGCF/GenericFramework/Core/GFWWeights.h +++ b/PWGCF/GenericFramework/Core/GFWWeights.h @@ -31,6 +31,8 @@ class GFWWeights : public TNamed public: GFWWeights(); explicit GFWWeights(const char* name); + GFWWeights(const GFWWeights& other); + GFWWeights& operator=(const GFWWeights& other); ~GFWWeights(); void init(bool AddData = kTRUE, bool AddM = kTRUE); void fill(double phi, double eta, double vz, double pt, double cent, int htype, double weight = 1); // htype: 0 for data, 1 for mc rec, 2 for mc gen @@ -53,25 +55,25 @@ class GFWWeights : public TNamed void setMCFilled(bool newval) { fMCFilled = newval; } void readAndMerge(const TString& filelinks, const TString& listName = "OutputList", bool addData = kTRUE, bool addRec = kTRUE, bool addGen = kTRUE); void setPtBins(int Nbins, double* bins); - Long64_t Merge(TCollection* collist); + Long64_t Merge(TCollection* collist); // o2-linter: disable=root/entity,name/function-variable (ROOT Merge requires this signature) void rebinNUA(int nX = 1, int nY = 2, int nZ = 5); void overwriteNUA(); TH1D* getdNdPhi(); TH1D* getEfficiency(double etamin, double etamax, double vzmin, double vzmax); void mergeWeights(GFWWeights* other); - void setTH3D(TH3D* th3d); + void setTH3D(TH3D* th3d); // Stores a clone of the input histogram private: bool fDataFilled; bool fMCFilled; - TObjArray* fW_data; - TObjArray* fW_mcrec; - TObjArray* fW_mcgen; - TH3D* fEffInt; //! - TH1D* fIntEff; //! - TH3D* fAccInt; //! - int fNbinsPt; //! do not store - double* fbinsPt; //! do not store + TObjArray* fW_data; // o2-linter: disable=name/function-variable (persisted ROOT member name) + TObjArray* fW_mcrec; // o2-linter: disable=name/function-variable (persisted ROOT member name) + TObjArray* fW_mcgen; // o2-linter: disable=name/function-variable (persisted ROOT member name) + TH3D* fEffInt; //! + TH1D* fIntEff; //! + TH3D* fAccInt; //! + int fNbinsPt; //! do not store + double* fbinsPt; //! do not store void addArray(TObjArray* targ, TObjArray* sour); const char* getBinName(double /*ptv*/, double /*v0mv*/, const char* pf = "") { From ea3acbac7bb6c3341c76241587770b9f13b1d959 Mon Sep 17 00:00:00 2001 From: Emil Gorm Nielsen Date: Thu, 8 Oct 2026 13:13:49 +0200 Subject: [PATCH 3/5] linter --- PWGCF/GenericFramework/Core/GFW.cxx | 13 ++-- PWGCF/GenericFramework/Core/GFW.h | 7 +- PWGCF/GenericFramework/Core/GFWPowerArray.cxx | 5 -- PWGCF/GenericFramework/Core/GFWWeights.cxx | 68 +++++++++---------- 4 files changed, 41 insertions(+), 52 deletions(-) diff --git a/PWGCF/GenericFramework/Core/GFW.cxx b/PWGCF/GenericFramework/Core/GFW.cxx index 24f8708fdab..306f1b4ffcd 100644 --- a/PWGCF/GenericFramework/Core/GFW.cxx +++ b/PWGCF/GenericFramework/Core/GFW.cxx @@ -72,7 +72,7 @@ void GFW::AddRegion(const string& refName, double lEtaMin, double lEtaMax, int l lOneRegion.BitMask = BitMask; // Bit mask AddRegion(lOneRegion); }; -void GFW::AddRegion(string refName, std::vector lNparVec, double lEtaMin, double lEtaMax, int lNpT, int BitMask) +void GFW::AddRegion(const string& refName, const std::vector& lNparVec, double lEtaMin, double lEtaMax, int lNpT, int BitMask) { const auto oldSize = fRegions.size(); AddRegion(refName, lEtaMin, lEtaMax, lNpT, BitMask); @@ -201,8 +201,6 @@ GFW::CorrConfig GFW::GetCorrelatorConfig(string config, string head, bool ptdif) // Then make sure we don't have any double-spaces: while (s_index(config, " ") > -1) s_replace_all(config, " ", " "); - std::vector regs; - std::vector hars; int sz1 = 0; int szend = 0; string ts, ts2; @@ -371,13 +369,14 @@ int GFW::FindRegionByName(const string& refName) return -1; }; // String processing: -int GFW::s_index(string& instr, const string& pattern, const int& spos) +int GFW::s_index(const string& instr, const string& pattern, const int& spos) { - return instr.find(pattern, spos); + const auto position = instr.find(pattern, spos); + return position == string::npos ? -1 : static_cast(position); }; -bool GFW::s_contains(string& instr, const string& pattern) +bool GFW::s_contains(const string& instr, const string& pattern) { - return (s_index(instr, pattern) > -1); + return instr.find(pattern) != string::npos; }; void GFW::s_replace(string& instr, const string& pattern1, const string& pattern2, const int& spos) { diff --git a/PWGCF/GenericFramework/Core/GFW.h b/PWGCF/GenericFramework/Core/GFW.h index 4c03d288c6c..78894b84c18 100644 --- a/PWGCF/GenericFramework/Core/GFW.h +++ b/PWGCF/GenericFramework/Core/GFW.h @@ -27,7 +27,8 @@ class GFW { public: struct Region { - int Nhar, NpT; + int Nhar = 0; + int NpT = 0; std::vector NparVec{}; double EtaMin = -999; double EtaMax = -999; @@ -80,8 +81,8 @@ class GFW std::complex Calculate(int poi, int ref, std::vector hars, int ptbin = 0); // For differential, need POI and reference std::complex Calculate(int poi, std::vector hars); // For integrated case // Operations on strings. Equivalent to TString operations, but one to rid of root dependence - int s_index(std::string& instr, const std::string& pattern, const int& spos = 0); - bool s_contains(std::string& instr, const std::string& pattern); + int s_index(const std::string& instr, const std::string& pattern, const int& spos = 0); + bool s_contains(const std::string& instr, const std::string& pattern); void s_replace(std::string& instr, const std::string& pattern1, const std::string& pattern2, const int& spos = 0); void s_replace_all(std::string& instr, const std::string& pattern1, const std::string& pattern2); bool s_tokenize(std::string& instr, std::string& substr, int& spos, const std::string& delim); diff --git a/PWGCF/GenericFramework/Core/GFWPowerArray.cxx b/PWGCF/GenericFramework/Core/GFWPowerArray.cxx index d5928c504df..a051a3e010e 100644 --- a/PWGCF/GenericFramework/Core/GFWPowerArray.cxx +++ b/PWGCF/GenericFramework/Core/GFWPowerArray.cxx @@ -48,13 +48,8 @@ HarSet GFWPowerArray::trimVec(const HarSet& hars, int ind) }; HarSet GFWPowerArray::addConstant(const HarSet& hars, int offset) { -<<<<<<< HEAD - HarSet retVec = std::move(hars); - for (int& val : retVec) -======= HarSet retVec = hars; for (int& val : retVec) // o2-linter: disable=const-ref-in-for-loop (updates each harmonic) ->>>>>>> d563a1043 (more linter cleanup in GFW) val += offset; return retVec; }; diff --git a/PWGCF/GenericFramework/Core/GFWWeights.cxx b/PWGCF/GenericFramework/Core/GFWWeights.cxx index ca51f112d84..b707e252764 100644 --- a/PWGCF/GenericFramework/Core/GFWWeights.cxx +++ b/PWGCF/GenericFramework/Core/GFWWeights.cxx @@ -333,33 +333,30 @@ void GFWWeights::createNUA(bool IntegrateOverCentAndPt) TH1D* h1; if (!fW_data || fW_data->GetEntries() < 1) return; - if (IntegrateOverCentAndPt) { - if (fAccInt) - delete fAccInt; - fAccInt = reinterpret_cast(fW_data->At(0)->Clone("IntegratedAcceptance")); - fAccInt->SetDirectory(0); - fAccInt->Sumw2(); - for (int etai = 1; etai <= fAccInt->GetNbinsY(); etai++) { - fAccInt->GetYaxis()->SetRange(etai, etai); + if (fAccInt) + delete fAccInt; + fAccInt = reinterpret_cast(fW_data->At(0)->Clone("IntegratedAcceptance")); + fAccInt->SetDirectory(0); + fAccInt->Sumw2(); + for (int etai = 1; etai <= fAccInt->GetNbinsY(); etai++) { + fAccInt->GetYaxis()->SetRange(etai, etai); + if (fAccInt->Integral() < 1) + continue; + for (int vzi = 1; vzi <= fAccInt->GetNbinsZ(); vzi++) { + fAccInt->GetZaxis()->SetRange(vzi, vzi); if (fAccInt->Integral() < 1) continue; - for (int vzi = 1; vzi <= fAccInt->GetNbinsZ(); vzi++) { - fAccInt->GetZaxis()->SetRange(vzi, vzi); - if (fAccInt->Integral() < 1) - continue; - h1 = reinterpret_cast(fAccInt->Project3D("x")); - double maxv = h1->GetMaximum(); - for (int phii = 1; phii <= h1->GetNbinsX(); phii++) { - fAccInt->SetBinContent(phii, etai, vzi, fAccInt->GetBinContent(phii, etai, vzi) / maxv); - fAccInt->SetBinError(phii, etai, vzi, fAccInt->GetBinError(phii, etai, vzi) / maxv); - } - delete h1; + h1 = reinterpret_cast(fAccInt->Project3D("x")); + double maxv = h1->GetMaximum(); + for (int phii = 1; phii <= h1->GetNbinsX(); phii++) { + fAccInt->SetBinContent(phii, etai, vzi, fAccInt->GetBinContent(phii, etai, vzi) / maxv); + fAccInt->SetBinError(phii, etai, vzi, fAccInt->GetBinError(phii, etai, vzi) / maxv); } - fAccInt->GetZaxis()->SetRange(1, fAccInt->GetNbinsZ()); + delete h1; } - fAccInt->GetYaxis()->SetRange(1, fAccInt->GetNbinsY()); - return; + fAccInt->GetZaxis()->SetRange(1, fAccInt->GetNbinsZ()); } + fAccInt->GetYaxis()->SetRange(1, fAccInt->GetNbinsY()); }; TH1D* GFWWeights::getdNdPhi() { @@ -393,21 +390,18 @@ void GFWWeights::createNUE(bool IntegrateOverCentrality) TH3D* den = 0; if (!fW_mcrec || !fW_mcgen || fW_mcrec->GetEntries() < 1 || fW_mcgen->GetEntries() < 1) return; - if (IntegrateOverCentrality) { - num = reinterpret_cast(fW_mcrec->At(0)); - den = reinterpret_cast(fW_mcgen->At(0)); - num->Sumw2(); - den->Sumw2(); - num->RebinY(2); - den->RebinY(2); - num->RebinZ(5); - den->RebinZ(5); - delete fEffInt; - fEffInt = reinterpret_cast(num->Clone("Efficiency_Integrated")); - fEffInt->SetDirectory(0); - fEffInt->Divide(den); - return; - } + num = reinterpret_cast(fW_mcrec->At(0)); + den = reinterpret_cast(fW_mcgen->At(0)); + num->Sumw2(); + den->Sumw2(); + num->RebinY(2); + den->RebinY(2); + num->RebinZ(5); + den->RebinZ(5); + delete fEffInt; + fEffInt = reinterpret_cast(num->Clone("Efficiency_Integrated")); + fEffInt->SetDirectory(0); + fEffInt->Divide(den); }; void GFWWeights::readAndMerge(const TString& filelinks, const TString& listName, bool addData, bool addRec, bool addGen) { From 301c0488c79c6930ce88be340f2f02352bd38998 Mon Sep 17 00:00:00 2001 From: Emil Gorm Nielsen Date: Thu, 8 Oct 2026 13:26:11 +0200 Subject: [PATCH 4/5] linter... again --- PWGCF/GenericFramework/Core/GFW.cxx | 2 +- PWGCF/GenericFramework/Core/GFW.h | 2 +- PWGCF/GenericFramework/Core/GFWPowerArray.cxx | 2 +- PWGCF/GenericFramework/Core/GFWPowerArray.h | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/PWGCF/GenericFramework/Core/GFW.cxx b/PWGCF/GenericFramework/Core/GFW.cxx index 306f1b4ffcd..2501cc23d19 100644 --- a/PWGCF/GenericFramework/Core/GFW.cxx +++ b/PWGCF/GenericFramework/Core/GFW.cxx @@ -393,7 +393,7 @@ void GFW::s_replace_all(string& instr, const string& pattern1, const string& pat lpos = s_index(instr, pattern1, lpos); } }; -bool GFW::s_tokenize(string& instr, string& subs, int& spos, const string& delim) +bool GFW::s_tokenize(const string& instr, string& subs, int& spos, const string& delim) { if (spos < 0 || spos >= static_cast(instr.size())) { spos = -1; diff --git a/PWGCF/GenericFramework/Core/GFW.h b/PWGCF/GenericFramework/Core/GFW.h index 78894b84c18..e10afffceb8 100644 --- a/PWGCF/GenericFramework/Core/GFW.h +++ b/PWGCF/GenericFramework/Core/GFW.h @@ -85,6 +85,6 @@ class GFW bool s_contains(const std::string& instr, const std::string& pattern); void s_replace(std::string& instr, const std::string& pattern1, const std::string& pattern2, const int& spos = 0); void s_replace_all(std::string& instr, const std::string& pattern1, const std::string& pattern2); - bool s_tokenize(std::string& instr, std::string& substr, int& spos, const std::string& delim); + bool s_tokenize(const std::string& instr, std::string& substr, int& spos, const std::string& delim); }; #endif // PWGCF_GENERICFRAMEWORK_CORE_GFW_H_ diff --git a/PWGCF/GenericFramework/Core/GFWPowerArray.cxx b/PWGCF/GenericFramework/Core/GFWPowerArray.cxx index a051a3e010e..38b952060cd 100644 --- a/PWGCF/GenericFramework/Core/GFWPowerArray.cxx +++ b/PWGCF/GenericFramework/Core/GFWPowerArray.cxx @@ -82,7 +82,7 @@ void GFWPowerArray::printVector(const HarSet& singleSet) output += "}"; LOGF(info, "%s", output.c_str()); } -HarSet GFWPowerArray::GetPowerArray(std::vector inHarmonics) // o2-linter: disable=name/function-variable (preserve existing public API) +HarSet GFWPowerArray::GetPowerArray(const std::vector& inHarmonics) // o2-linter: disable=name/function-variable (preserve existing public API) { // First, find maximum number of particle correlations ( = max power) and maximum (sum of) harmonics int maxHar = 0; diff --git a/PWGCF/GenericFramework/Core/GFWPowerArray.h b/PWGCF/GenericFramework/Core/GFWPowerArray.h index 0f5ee94697f..cce3945d3f5 100644 --- a/PWGCF/GenericFramework/Core/GFWPowerArray.h +++ b/PWGCF/GenericFramework/Core/GFWPowerArray.h @@ -23,8 +23,8 @@ typedef std::vector HarSet; class GFWPowerArray { public: - static HarSet GetPowerArray(std::vector inHarmonics); // o2-linter: disable=name/function-variable (preserve existing public API) - static void PowerArrayTest(); // o2-linter: disable=name/function-variable (preserve existing public API) + static HarSet GetPowerArray(const std::vector& inHarmonics); // o2-linter: disable=name/function-variable (preserve existing public API) + static void PowerArrayTest(); // o2-linter: disable=name/function-variable (preserve existing public API) private: static int getHighestHarmonic(const HarSet& inhar); From 36470c75d81adb547b6d1c3f58f1b3b54e546764 Mon Sep 17 00:00:00 2001 From: Emil Gorm Nielsen Date: Thu, 8 Oct 2026 13:57:19 +0200 Subject: [PATCH 5/5] codecheck --- PWGCF/GenericFramework/Core/FlowContainer.cxx | 41 ++++++++++--------- PWGCF/GenericFramework/Core/GFW.cxx | 13 ++++-- PWGCF/GenericFramework/Core/GFW.h | 4 +- PWGCF/GenericFramework/Core/GFWPowerArray.cxx | 8 ++-- 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/PWGCF/GenericFramework/Core/FlowContainer.cxx b/PWGCF/GenericFramework/Core/FlowContainer.cxx index 4578b538cc4..4b94468bde6 100644 --- a/PWGCF/GenericFramework/Core/FlowContainer.cxx +++ b/PWGCF/GenericFramework/Core/FlowContainer.cxx @@ -415,6 +415,10 @@ TProfile* FlowContainer::GetCorrXXVsMulti(const char* order, int l_pti) } delete rethist; } + if (!retSubset) { + LOGF(error, "Correlation profile is null"); + return nullptr; + } if (fMultiRebin > 0) { TString temp_name(retSubset->GetName()); TProfile* tempprof = dynamic_cast(retSubset->Clone("tempProfile")); @@ -525,9 +529,9 @@ TH1D* FlowContainer::GetCN2VsX(int n, bool onPt, double arg1, double arg2) corrN2 = GetHistCorrXXVsMulti(Form("%i2", n), static_cast(arg1)); corrN2->SetName(Form("Corr_%s", corrN2->GetName())); TH1D* rethist = GetCN2(corrN2); - TString* nam = new TString(corrN2->GetName()); + const TString nam(corrN2->GetName()); delete corrN2; - rethist->SetName(nam->Data()); + rethist->SetName(nam.Data()); if (onPt) { int bins = fProf->GetXaxis()->FindBin(arg1); int bins2 = fProf->GetXaxis()->FindBin(arg2); @@ -543,10 +547,10 @@ TH1D* FlowContainer::GetCN2VsX(int n, bool onPt, double arg1, double arg2) TH1D* FlowContainer::GetVN2VsX(int n, bool onPt, double arg1, double arg2) { TH1D* corrh = GetCN2VsX(n, onPt, arg1, arg2); - TString* nam = new TString(corrh->GetName()); + const TString nam(corrh->GetName()); TH1D* rethist = GetVN2(corrh); delete corrh; - rethist->SetName(nam->Data()); + rethist->SetName(nam.Data()); if (onPt) { int bins = fProf->GetXaxis()->FindBin(arg1); int bins2 = fProf->GetXaxis()->FindBin(arg2); @@ -556,7 +560,6 @@ TH1D* FlowContainer::GetVN2VsX(int n, bool onPt, double arg1, double arg2) } else { rethist->SetTitle(Form(";#it{N}_{tr};v_{%i}{2}", n)); } - delete nam; return rethist; } @@ -706,10 +709,10 @@ TH1D* FlowContainer::GetCN4VsX(int n, bool onPt, double arg1, double arg2) corrN4->SetName(Form("Corr_%s", corrN4->GetName())); } TH1D* rethist = GetCN4(corrN4, corrN2); - TString* nam = new TString(corrN4->GetName()); + const TString nam(corrN4->GetName()); delete corrN2; delete corrN4; - rethist->SetName(nam->Data()); + rethist->SetName(nam.Data()); if (onPt) { int bins = fProf->GetXaxis()->FindBin(arg1); int bins2 = fProf->GetXaxis()->FindBin(arg2); @@ -780,9 +783,9 @@ TH1D* FlowContainer::GetVN4VsX(int n, bool onPt, double arg1, double arg2) { TH1D* temph = GetCN4VsX(n, onPt, arg1, arg2); TH1D* rethist = GetVN4(temph); - TString* nam = new TString(temph->GetName()); + const TString nam(temph->GetName()); delete temph; - rethist->SetName(nam->Data()); + rethist->SetName(nam.Data()); if (onPt) { int bins = fProf->GetXaxis()->FindBin(arg1); int bins2 = fProf->GetXaxis()->FindBin(arg2); @@ -812,9 +815,9 @@ TH1D* FlowContainer::GetCN6VsX(int n, bool onPt, double arg1, double arg2) TH1D* rethist = GetCN6(corrN6, corrN4, corrN2); delete corrN2; delete corrN4; - TString* nam = new TString(corrN6->GetName()); + const TString nam(corrN6->GetName()); delete corrN6; - rethist->SetName(nam->Data()); + rethist->SetName(nam.Data()); if (onPt) { int bins = fProf->GetXaxis()->FindBin(arg1); int bins2 = fProf->GetXaxis()->FindBin(arg2); @@ -830,9 +833,9 @@ TH1D* FlowContainer::GetVN6VsX(int n, bool onPt, double arg1, double arg2) { TH1D* temph = GetCN6VsX(n, onPt, arg1, arg2); TH1D* rethist = GetVN6(temph); - TString* nam = new TString(temph->GetName()); + const TString nam(temph->GetName()); delete temph; - rethist->SetName(nam->Data()); + rethist->SetName(nam.Data()); if (onPt) { int bins = fProf->GetXaxis()->FindBin(arg1); int bins2 = fProf->GetXaxis()->FindBin(arg2); @@ -866,9 +869,9 @@ TH1D* FlowContainer::GetCN8VsX(int n, bool onPt, double arg1, double arg2) delete corrN2; delete corrN4; delete corrN6; - TString* nam = new TString(corrN8->GetName()); + const TString nam(corrN8->GetName()); delete corrN8; - rethist->SetName(nam->Data()); + rethist->SetName(nam.Data()); if (onPt) { int bins = fProf->GetXaxis()->FindBin(arg1); int bins2 = fProf->GetXaxis()->FindBin(arg2); @@ -884,9 +887,9 @@ TH1D* FlowContainer::GetVN8VsX(int n, bool onPt, double arg1, double arg2) { TH1D* temph = GetCN8VsX(n, onPt, arg1, arg2); TH1D* rethist = GetVN8(temph); - TString* nam = new TString(temph->GetName()); + const TString nam(temph->GetName()); delete temph; - rethist->SetName(nam->Data()); + rethist->SetName(nam.Data()); if (onPt) { int bins = fProf->GetXaxis()->FindBin(arg1); int bins2 = fProf->GetXaxis()->FindBin(arg2); @@ -928,7 +931,7 @@ TProfile* FlowContainer::GetRefFlowProfile(const char* order, double m1, double if (nStopBin < nStartBin) nStopBin = fProf->GetXaxis()->GetNbins(); int nBins = nStopBin - nStartBin + 1; - double* l_bins = new double[nBins + 1]; + std::vector l_bins(nBins + 1); for (int i = 0; i <= nBins; i++) l_bins[i] = i; TProfile* retpf = 0; @@ -939,7 +942,7 @@ TProfile* FlowContainer::GetRefFlowProfile(const char* order, double m1, double while (fIDName.Tokenize(l_name, l_pos)) { l_name.Append(order); int ybin = fProf->GetYaxis()->FindBin(l_name.Data()); - TProfile* tempprof = rhSubset->GetSubset(kTRUE, "tempprof", ybin, ybin, nBins, l_bins); + TProfile* tempprof = rhSubset->GetSubset(kTRUE, "tempprof", ybin, ybin, nBins, l_bins.data()); if (!retpf) retpf = dynamic_cast(tempprof->Clone("RefFlowProf")); else diff --git a/PWGCF/GenericFramework/Core/GFW.cxx b/PWGCF/GenericFramework/Core/GFW.cxx index 2501cc23d19..9a4918af00c 100644 --- a/PWGCF/GenericFramework/Core/GFW.cxx +++ b/PWGCF/GenericFramework/Core/GFW.cxx @@ -82,19 +82,23 @@ void GFW::AddRegion(const string& refName, const std::vector& lNparVec, dou (fRegions.end() - 1)->NparVec = lNparVec; (fRegions.end() - 1)->powsDefined = true; }; -void GFW::AddRegion(string refName, int lNhar, int lNpar, double lEtaMin, double lEtaMax, int lNpT, int BitMask) +void GFW::AddRegion(const string& refName, int lNhar, int lNpar, double lEtaMin, double lEtaMax, int lNpT, int BitMask) { std::vector tVec = {}; + if (lNhar > 0) + tVec.reserve(lNhar); for (int i = 0; i < lNhar; i++) tVec.push_back(lNpar); - AddRegion(std::move(refName), tVec, lEtaMin, lEtaMax, lNpT, BitMask); + AddRegion(refName, tVec, lEtaMin, lEtaMax, lNpT, BitMask); }; -void GFW::AddRegion(string refName, int lNhar, int* lNparVec, double lEtaMin, double lEtaMax, int lNpT, int BitMask) +void GFW::AddRegion(const string& refName, int lNhar, int* lNparVec, double lEtaMin, double lEtaMax, int lNpT, int BitMask) { std::vector tVec = {}; + if (lNhar > 0) + tVec.reserve(lNhar); for (int i = 0; i < lNhar; i++) tVec.push_back(lNparVec[i]); - AddRegion(std::move(refName), tVec, lEtaMin, lEtaMax, lNpT, BitMask); + AddRegion(refName, tVec, lEtaMin, lEtaMax, lNpT, BitMask); }; int GFW::CreateRegions() { @@ -135,6 +139,7 @@ complex GFW::TwoRec(int n1, int n2, int p1, int p2, int ptbin, GFWCumula complex GFW::RecursiveCorr(GFWCumulant* qpoi, GFWCumulant* qref, GFWCumulant* qol, int ptbin, std::vector& hars) { std::vector pows; + pows.reserve(hars.size()); for (int i = 0; i < static_cast(hars.size()); i++) pows.push_back(1); return RecursiveCorr(qpoi, qref, qol, ptbin, hars, pows); diff --git a/PWGCF/GenericFramework/Core/GFW.h b/PWGCF/GenericFramework/Core/GFW.h index e10afffceb8..288ea0ed634 100644 --- a/PWGCF/GenericFramework/Core/GFW.h +++ b/PWGCF/GenericFramework/Core/GFW.h @@ -57,8 +57,8 @@ class GFW std::vector fCumulants; void AddRegion(const std::string& refName, double lEtaMin, double lEtaMax, int lNpT, int BitMask); void AddRegion(const std::string& refName, const std::vector& lNparVec, double lEtaMin, double lEtaMax, int lNpT, int BitMask); // Legacy - void AddRegion(std::string refName, int lNhar, int lNpar, double lEtaMin, double lEtaMax, int lNpT, int BitMask); // Legacy support, all powers are the same - void AddRegion(std::string refName, int lNhar, int* lNparVec, double lEtaMin, double lEtaMax, int lNpT, int BitMask); // Legacy support, array instead of a vector + void AddRegion(const std::string& refName, int lNhar, int lNpar, double lEtaMin, double lEtaMax, int lNpT, int BitMask); // Legacy support, all powers are the same + void AddRegion(const std::string& refName, int lNhar, int* lNparVec, double lEtaMin, double lEtaMax, int lNpT, int BitMask); // Legacy support, array instead of a vector int CreateRegions(); void Fill(double eta, int ptin, double phi, double weight, int mask, double secondWeight = -1); void Clear(); diff --git a/PWGCF/GenericFramework/Core/GFWPowerArray.cxx b/PWGCF/GenericFramework/Core/GFWPowerArray.cxx index 38b952060cd..5ebd708f38f 100644 --- a/PWGCF/GenericFramework/Core/GFWPowerArray.cxx +++ b/PWGCF/GenericFramework/Core/GFWPowerArray.cxx @@ -19,22 +19,22 @@ #include #include +#include #include #include #include #include -#include #include int GFWPowerArray::getHighestHarmonic(const HarSet& inhar) { // Highest possible harmonic: sum of same-sign harmonics - int64_t maxPos = 0, maxNeg = 0; + std::int64_t maxPos = 0, maxNeg = 0; for (const int& val : inhar) { if (val > 0) maxPos += val; else - maxNeg += std::abs(static_cast(val)); + maxNeg += std::abs(static_cast(val)); if (maxPos >= std::numeric_limits::max() || maxNeg >= std::numeric_limits::max()) throw std::overflow_error("Harmonic sum exceeds the supported range"); } @@ -42,7 +42,7 @@ int GFWPowerArray::getHighestHarmonic(const HarSet& inhar) }; HarSet GFWPowerArray::trimVec(const HarSet& hars, int ind) { - HarSet retVec = std::move(hars); + HarSet retVec = hars; retVec.erase(retVec.begin() + ind); return retVec; };