From 94c93ee9070027727c6d95127ba73f8297ff4716 Mon Sep 17 00:00:00 2001 From: Marvin Hemmer Date: Thu, 30 Oct 2025 12:54:40 +0100 Subject: [PATCH 1/3] [PWGEM,PWGEM-36] Pi0Flow: Reduce CPU time for LUT - changed `lookupTable1D` from `std::vector` to `std::array` and fill with all good values when MapLevel is >= 4 for same event and background set in the config --- PWGEM/PhotonMeson/Tasks/taskPi0FlowEMC.cxx | 59 ++++++++++++---------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/PWGEM/PhotonMeson/Tasks/taskPi0FlowEMC.cxx b/PWGEM/PhotonMeson/Tasks/taskPi0FlowEMC.cxx index 321bbf007d7..8e614d63bdb 100644 --- a/PWGEM/PhotonMeson/Tasks/taskPi0FlowEMC.cxx +++ b/PWGEM/PhotonMeson/Tasks/taskPi0FlowEMC.cxx @@ -220,14 +220,14 @@ struct TaskPi0FlowEMC { o2::emcal::Geometry* emcalGeom; o2::emcal::BadChannelMap* mBadChannels; TH1D* h1SPResolution = nullptr; - // Constants for eta and phi ranges - double etaMin = -0.75, etaMax = 0.75; - int nBinsEta = 150; // 150 bins for eta + // Constants for eta and phi ranges for the look up table + static constexpr double etaMin = -0.75, etaMax = 0.75; + static constexpr int nBinsEta = 150; // 150 bins for eta - double phiMin = 1.35, phiMax = 5.75; - int nBinsPhi = 440; // (440 bins = 0.01 step size covering most regions) + static constexpr double phiMin = 1.35, phiMax = 5.75; + static constexpr int nBinsPhi = 440; // (440 bins = 0.01 step size covering most regions) - std::vector lookupTable1D; + std::array lookupTable1D; float epsilon = 1.e-8; // static constexpr @@ -437,7 +437,8 @@ struct TaskPi0FlowEMC { } if (cfgDoM02.value) { - registry.add("hSparseFlow", "THn for SP", HistType::kTHnSparseF, {thnAxisM02, thnAxisPt, thnAxisCent}); + registry.add("p3DM02Flow", " vs M_{02} vs p_T vs cent", HistType::kTProfile3D, {thnAxisM02, thnAxisPt, thnAxisCent}); + registry.add("h3DSparsePi0", "M_{02} vs p_T vs cent", HistType::kTH3D, {thnAxisM02, thnAxisPt, thnAxisCent}); } ccdb->setURL(ccdbUrl); @@ -663,28 +664,33 @@ struct TaskPi0FlowEMC { emcalGeom = o2::emcal::Geometry::GetInstanceFromRunNumber(collision.runNumber()); // Load Bad Channel map mBadChannels = ccdb->getForTimeStamp("EMC/Calib/BadChannelMap", collision.timestamp()); - lookupTable1D = std::vector(nBinsEta * nBinsPhi, -1); + lookupTable1D.fill(-1); double binWidthEta = (etaMax - etaMin) / nBinsEta; double binWidthPhi = (phiMax - phiMin) / nBinsPhi; - for (int iEta = 0; iEta < nBinsEta; ++iEta) { - double etaCenter = etaMin + (iEta + 0.5) * binWidthEta; - for (int iPhi = 0; iPhi < nBinsPhi; ++iPhi) { - double phiCenter = phiMin + (iPhi + 0.5) * binWidthPhi; - try { - // Get the cell ID - int cellID = emcalGeom->GetAbsCellIdFromEtaPhi(etaCenter, phiCenter); - - // Check conditions for the cell - if (isTooCloseToEdge(cellID, 1)) { - lookupTable1D[getIndex(iEta, iPhi)] = 2; // Edge - } else if (isCellMasked(cellID)) { - lookupTable1D[getIndex(iEta, iPhi)] = 1; // Bad - } else { - lookupTable1D[getIndex(iEta, iPhi)] = 0; // Good + if (cfgEMCalMapLevelBackground.value >= 4 && cfgEMCalMapLevelSameEvent >= 4) { + // in this case we do not want to check the clusters, so just say thery are all good. + lookupTable1D.fill(0); // good + } else { + for (int iEta = 0; iEta < nBinsEta; ++iEta) { + double etaCenter = etaMin + (iEta + 0.5) * binWidthEta; + for (int iPhi = 0; iPhi < nBinsPhi; ++iPhi) { + double phiCenter = phiMin + (iPhi + 0.5) * binWidthPhi; + try { + // Get the cell ID + int cellID = emcalGeom->GetAbsCellIdFromEtaPhi(etaCenter, phiCenter); + + // Check conditions for the cell + if (isTooCloseToEdge(cellID, 1)) { + lookupTable1D[getIndex(iEta, iPhi)] = 2; // Edge + } else if (isCellMasked(cellID)) { + lookupTable1D[getIndex(iEta, iPhi)] = 1; // Bad + } else { + lookupTable1D[getIndex(iEta, iPhi)] = 0; // Good + } + } catch (o2::emcal::InvalidPositionException& e) { + lookupTable1D[getIndex(iEta, iPhi)] = 3; // Outside geometry } - } catch (o2::emcal::InvalidPositionException& e) { - lookupTable1D[getIndex(iEta, iPhi)] = 3; // Outside geometry } } } @@ -1433,7 +1439,8 @@ struct TaskPi0FlowEMC { scalprodCand = scalprodCand / h1SPResolution->GetBinContent(h1SPResolution->FindBin(cent + epsilon)); } if (cfgDoM02.value) { - registry.fill(HIST("hSparseFlow"), photon.m02(), photon.pt(), cent, scalprodCand); + registry.fill(HIST("p3DM02Flow"), photon.m02(), photon.pt(), cent, scalprodCand); + registry.fill(HIST("h3DSparsePi0"), photon.m02(), photon.pt(), cent); } return; } // end of loop over single cluster From c3b097decf5475c76f4cdde0ea37f57a1a1c5ce4 Mon Sep 17 00:00:00 2001 From: Marvin Hemmer Date: Thu, 30 Oct 2025 13:14:08 +0100 Subject: [PATCH 2/3] [PWGEM,PWGEM-36] Pi0Flow: Reduce CPU time for LUT - Fix linter error and warning --- PWGEM/PhotonMeson/Tasks/taskPi0FlowEMC.cxx | 39 +++++++++++++--------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/PWGEM/PhotonMeson/Tasks/taskPi0FlowEMC.cxx b/PWGEM/PhotonMeson/Tasks/taskPi0FlowEMC.cxx index 8e614d63bdb..3d5962b056a 100644 --- a/PWGEM/PhotonMeson/Tasks/taskPi0FlowEMC.cxx +++ b/PWGEM/PhotonMeson/Tasks/taskPi0FlowEMC.cxx @@ -99,6 +99,13 @@ enum Harmonics { kOctagonal = 8 }; +enum class MapLevel { + kGood = 1, + kNoBad = 2, + kinEMC = 3, + kAll = 4 +}; + struct TaskPi0FlowEMC { static constexpr float MinEnergy = 0.7f; @@ -221,13 +228,13 @@ struct TaskPi0FlowEMC { o2::emcal::BadChannelMap* mBadChannels; TH1D* h1SPResolution = nullptr; // Constants for eta and phi ranges for the look up table - static constexpr double etaMin = -0.75, etaMax = 0.75; - static constexpr int nBinsEta = 150; // 150 bins for eta + static constexpr double EtaMin = -0.75, etaMax = 0.75; + static constexpr int NBinsEta = 150; // 150 bins for eta - static constexpr double phiMin = 1.35, phiMax = 5.75; - static constexpr int nBinsPhi = 440; // (440 bins = 0.01 step size covering most regions) + static constexpr double PhiMin = 1.35, phiMax = 5.75; + static constexpr int NBinsPhi = 440; // (440 bins = 0.01 step size covering most regions) - std::array lookupTable1D; + std::array lookupTable1D; float epsilon = 1.e-8; // static constexpr @@ -239,19 +246,19 @@ struct TaskPi0FlowEMC { // To access the 1D array inline int getIndex(int iEta, int iPhi) { - return iEta * nBinsPhi + iPhi; + return iEta * NBinsPhi + iPhi; } // Function to access the lookup table inline int8_t checkEtaPhi1D(double eta, double phi) { - if (eta < etaMin || eta > etaMax || phi < phiMin || phi > phiMax) { + if (eta < EtaMin || eta > etaMax || phi < PhiMin || phi > phiMax) { return 3; // Out of bounds } // Compute indices directly - int iEta = static_cast((eta - etaMin) / ((etaMax - etaMin) / nBinsEta)); - int iPhi = static_cast((phi - phiMin) / ((phiMax - phiMin) / nBinsPhi)); + int iEta = static_cast((eta - EtaMin) / ((etaMax - EtaMin) / NBinsEta)); + int iPhi = static_cast((phi - PhiMin) / ((phiMax - PhiMin) / NBinsPhi)); return lookupTable1D[getIndex(iEta, iPhi)]; } @@ -665,17 +672,17 @@ struct TaskPi0FlowEMC { // Load Bad Channel map mBadChannels = ccdb->getForTimeStamp("EMC/Calib/BadChannelMap", collision.timestamp()); lookupTable1D.fill(-1); - double binWidthEta = (etaMax - etaMin) / nBinsEta; - double binWidthPhi = (phiMax - phiMin) / nBinsPhi; + double binWidthEta = (etaMax - EtaMin) / NBinsEta; + double binWidthPhi = (phiMax - PhiMin) / NBinsPhi; - if (cfgEMCalMapLevelBackground.value >= 4 && cfgEMCalMapLevelSameEvent >= 4) { + if (cfgEMCalMapLevelBackground.value >= static_cast(MapLevel::kAll) && cfgEMCalMapLevelSameEvent >= static_cast(MapLevel::kAll)) { // in this case we do not want to check the clusters, so just say thery are all good. lookupTable1D.fill(0); // good } else { - for (int iEta = 0; iEta < nBinsEta; ++iEta) { - double etaCenter = etaMin + (iEta + 0.5) * binWidthEta; - for (int iPhi = 0; iPhi < nBinsPhi; ++iPhi) { - double phiCenter = phiMin + (iPhi + 0.5) * binWidthPhi; + for (int iEta = 0; iEta < NBinsEta; ++iEta) { + double etaCenter = EtaMin + (iEta + 0.5) * binWidthEta; + for (int iPhi = 0; iPhi < NBinsPhi; ++iPhi) { + double phiCenter = PhiMin + (iPhi + 0.5) * binWidthPhi; try { // Get the cell ID int cellID = emcalGeom->GetAbsCellIdFromEtaPhi(etaCenter, phiCenter); From 79b60da9e5ec0fbc686446bd7987418d8b9262eb Mon Sep 17 00:00:00 2001 From: Marvin Hemmer Date: Thu, 30 Oct 2025 13:15:31 +0100 Subject: [PATCH 3/3] Fix typo `kinEMC` to `kInEMC` --- PWGEM/PhotonMeson/Tasks/taskPi0FlowEMC.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PWGEM/PhotonMeson/Tasks/taskPi0FlowEMC.cxx b/PWGEM/PhotonMeson/Tasks/taskPi0FlowEMC.cxx index 3d5962b056a..44b3c616264 100644 --- a/PWGEM/PhotonMeson/Tasks/taskPi0FlowEMC.cxx +++ b/PWGEM/PhotonMeson/Tasks/taskPi0FlowEMC.cxx @@ -102,7 +102,7 @@ enum Harmonics { enum class MapLevel { kGood = 1, kNoBad = 2, - kinEMC = 3, + kInEMC = 3, kAll = 4 };