From bffbe91ff0f88421d3f844a598abf6b74eb2868f Mon Sep 17 00:00:00 2001 From: Victor Date: Thu, 4 Sep 2025 23:23:27 +0200 Subject: [PATCH] [PWGCF] DptDpt - Self configure the system type --- PWGCF/TableProducer/dptDptFilter.cxx | 182 +++++++++++++++++---------- PWGCF/TableProducer/dptDptFilter.h | 65 +++++----- 2 files changed, 151 insertions(+), 96 deletions(-) diff --git a/PWGCF/TableProducer/dptDptFilter.cxx b/PWGCF/TableProducer/dptDptFilter.cxx index 4f5d3644d75..6df5ac6d5ba 100644 --- a/PWGCF/TableProducer/dptDptFilter.cxx +++ b/PWGCF/TableProducer/dptDptFilter.cxx @@ -140,6 +140,20 @@ static const std::string multiplicityCentralityCorrelationsFormulaBase[11][1] = /* OO Run3 */ {"((180.584-0.211625*[CT0C]+0.00568101*[CT0C]*[CT0C]-20.9838*sqrt([CT0C])-2.5*(32.665+1.67341*[CT0C]+0.0113878*[CT0C]*[CT0C]-6.83271*sqrt([CT0C])-0.239428*[CT0C]*sqrt([CT0C])))<=[MNGLTRK])&&((-0.0533229+0.79235*[MNPVC]+5.0*(0.031512+0.0045874*[MNPVC]-1.06374e-05*[MNPVC]*[MNPVC]+0.407526*sqrt([MNPVC])))>[MNGLTRK])&&((-0.0533229+0.79235*[MNPVC]-5.0*(0.031512+0.0045874*[MNPVC]-1.06374e-05*[MNPVC]*[MNPVC]+0.407526*sqrt([MNPVC])))<=[MNGLTRK])"}, /* pO Run3 */ {""}}; +/* helpers for the system type assignment */ +static const std::string periodsOnSystemType[11][1] = { + /* no system */ {""}, + /* pp Run2 */ {""}, + /* pPb Run2 */ {""}, + /* Pbp Run2 */ {""}, + /* PbPb Run2 */ {"LHC18q,LHC18r"}, + /* XeXe Run2 */ {""}, + /* pp Run3 */ {"LHC22o"}, + /* PbPb Run3 */ {"LHC23zzh"}, + /* NeNe Run3 */ {"LHC25af"}, + /* OO Run3 */ {"LHC25ae"}, + /* pO Run3 */ {"LHC25ad"}}; + //============================================================================================ // The DptDptFilter histogram objects // TODO: consider registering in the histogram registry @@ -248,6 +262,43 @@ std::vector partMultNeg; // multiplicity of negative particles using namespace dptdptfilter; +/* we need this for the time being from TableHelper.h */ +/// Function to check for a specific configurable from another task in the current workflow and fetch its value. Useful for tasks that need to know the value of a configurable in another task. +/// @param initContext initContext of the init function +/// @param taskName name of the task to check for +/// @param optName name of the option to check for +/// @param value value of the option to set +/// @param verbose if true, print debug messages +template <> +bool o2::common::core::getTaskOptionValue(o2::framework::InitContext& initContext, const std::string& taskName, const std::string& optName, o2::framework::LabeledArray& value, const bool verbose) +{ + if (verbose) { + LOG(info) << "Checking for option '" << optName << "' in task '" << taskName << "'"; + } + const auto& workflows = initContext.services().get(); + int deviceCounter = 0; + bool found = false; + for (auto const& device : workflows.devices) { + if (verbose) { + LOG(info) << " Device " << deviceCounter++ << " " << device.name; + } + if (device.name == taskName) { // Found the mother task + int optionCounter = 0; + for (o2::framework::ConfigParamSpec const& option : device.options) { + if (verbose) { + LOG(info) << " Option " << optionCounter++ << " " << option.name << " of type " << static_cast(option.type) << " = '" << option.defaultValue.asString() << "'"; + } + if (option.name == optName) { + value = option.defaultValue.get>(); + return true; + } + } + return found; + } + } + return false; +} + ////////////////////////////////////////////////////////////////////////////// // Multiplicity in principle for on the fly generated events ////////////////////////////////////////////////////////////////////////////// @@ -416,68 +467,65 @@ struct Multiplicity { template inline void storeMultiplicitiesAndCentralities(CollisionObject const& collision, TrackListObject const& tracks) { - /* only do it if we are tracking the centrality / multiplicity correlations */ - if (useCentralityMultiplicityCorrelationsExclusion) { - int nGlobalTracks = 0; - for (auto const& track : tracks) { - if (track.isGlobalTrack()) { - nGlobalTracks++; - } + int nGlobalTracks = 0; + for (auto const& track : tracks) { + if (track.isGlobalTrack()) { + nGlobalTracks++; } - for (CentMultCorrelationsParams ipar = CentMultCorrelationsMT0A; ipar < CentMultCorrelationsNOOFPARAMS; ++ipar) { - switch (ipar) { - case CentMultCorrelationsMT0A: - collisionMultiplicityCentralityObservables[ipar] = collision.multFT0A(); - break; - case CentMultCorrelationsMT0C: - collisionMultiplicityCentralityObservables[ipar] = collision.multFT0C(); - break; - case CentMultCorrelationsMT0M: - collisionMultiplicityCentralityObservables[ipar] = collision.multFT0M(); - break; - case CentMultCorrelationsMV0A: - collisionMultiplicityCentralityObservables[ipar] = collision.multFV0A(); - break; - case CentMultCorrelationsMV0C: - collisionMultiplicityCentralityObservables[ipar] = collision.multFV0C(); - break; - case CentMultCorrelationsMV0M: - collisionMultiplicityCentralityObservables[ipar] = collision.multFV0M(); - break; - case CentMultCorrelationsMNGLTRK: - collisionMultiplicityCentralityObservables[ipar] = nGlobalTracks; - break; - case CentMultCorrelationsMNPVC: - collisionMultiplicityCentralityObservables[ipar] = collision.multNTracksPV(); - break; - case CentMultCorrelationsCT0A: - if constexpr (framework::has_type_v) { - collisionMultiplicityCentralityObservables[ipar] = collision.centFT0A(); - } - break; - case CentMultCorrelationsCT0C: - if constexpr (framework::has_type_v) { - collisionMultiplicityCentralityObservables[ipar] = collision.centFT0C(); - } - break; - case CentMultCorrelationsCT0M: - if constexpr (framework::has_type_v) { - collisionMultiplicityCentralityObservables[ipar] = collision.centFT0M(); - } - break; - case CentMultCorrelationsCV0A: - if constexpr (framework::has_type_v) { - collisionMultiplicityCentralityObservables[ipar] = collision.centFV0A(); - } - break; - case CentMultCorrelationsCNTPV: - if constexpr (framework::has_type_v) { - collisionMultiplicityCentralityObservables[ipar] = collision.centNTPV(); - } - break; - default: - break; - } + } + for (CentMultCorrelationsParams ipar = CentMultCorrelationsMT0A; ipar < CentMultCorrelationsNOOFPARAMS; ++ipar) { + switch (ipar) { + case CentMultCorrelationsMT0A: + collisionMultiplicityCentralityObservables[ipar] = collision.multFT0A(); + break; + case CentMultCorrelationsMT0C: + collisionMultiplicityCentralityObservables[ipar] = collision.multFT0C(); + break; + case CentMultCorrelationsMT0M: + collisionMultiplicityCentralityObservables[ipar] = collision.multFT0M(); + break; + case CentMultCorrelationsMV0A: + collisionMultiplicityCentralityObservables[ipar] = collision.multFV0A(); + break; + case CentMultCorrelationsMV0C: + collisionMultiplicityCentralityObservables[ipar] = collision.multFV0C(); + break; + case CentMultCorrelationsMV0M: + collisionMultiplicityCentralityObservables[ipar] = collision.multFV0M(); + break; + case CentMultCorrelationsMNGLTRK: + collisionMultiplicityCentralityObservables[ipar] = nGlobalTracks; + break; + case CentMultCorrelationsMNPVC: + collisionMultiplicityCentralityObservables[ipar] = collision.multNTracksPV(); + break; + case CentMultCorrelationsCT0A: + if constexpr (framework::has_type_v) { + collisionMultiplicityCentralityObservables[ipar] = collision.centFT0A(); + } + break; + case CentMultCorrelationsCT0C: + if constexpr (framework::has_type_v) { + collisionMultiplicityCentralityObservables[ipar] = collision.centFT0C(); + } + break; + case CentMultCorrelationsCT0M: + if constexpr (framework::has_type_v) { + collisionMultiplicityCentralityObservables[ipar] = collision.centFT0M(); + } + break; + case CentMultCorrelationsCV0A: + if constexpr (framework::has_type_v) { + collisionMultiplicityCentralityObservables[ipar] = collision.centFV0A(); + } + break; + case CentMultCorrelationsCNTPV: + if constexpr (framework::has_type_v) { + collisionMultiplicityCentralityObservables[ipar] = collision.centNTPV(); + } + break; + default: + break; } } } @@ -515,7 +563,7 @@ struct DptDptFilter { Configurable maxOccupancy{"maxOccupancy", 1e6f, "Maximum allowed occupancy. Depends on the occupancy estimation"}; } occupancySelection; } cfgEventSelection; - Configurable cfgSystem{"cfgSystem", "PbPb", "System: Auto, pp, PbPb, Pbp, pPb, XeXe, ppRun3, PbPbRun3. Default PbPb"}; + Configurable> cfgSystemForPeriod{"cfgSystemForPeriod", {periodsOnSystemType[0], 11, 1, {SYSTEMNAME(0), SYSTEMNAME(1), SYSTEMNAME(2), SYSTEMNAME(3), SYSTEMNAME(4), SYSTEMNAME(5), SYSTEMNAME(6), SYSTEMNAME(7), SYSTEMNAME(8), SYSTEMNAME(9), SYSTEMNAME(10)}, {"Periods separated by commas"}}, "List of periods associated to each system type"}; Configurable cfgDataType{"cfgDataType", "data", "Data type: data, datanoevsel, MC, FastMC, OnTheFlyMC. Default data"}; Configurable cfgCentSpec{"cfgCentSpec", "00-10,10-20,20-30,30-40,40-50,50-60,60-70,70-80", "Centrality/multiplicity ranges in min-max separated by commas"}; Configurable cfgOverallMinP{"cfgOverallMinP", 0.0f, "The overall minimum momentum for the analysis. Default: 0.0"}; @@ -588,8 +636,8 @@ struct DptDptFilter { triggerSelectionFlags = getTriggerSelection(cfgEventSelection.triggSel.value.c_str()); traceCollId0 = cfgTraceCollId0; - /* if the system type is not known at this time, we have to put the initialization somewhere else */ - fSystem = getSystemType(cfgSystem.value.c_str()); + /* get the system type */ + fSystem = getSystemType(cfgSystemForPeriod.value); fLhcRun = multRunForSystemMap.at(fSystem); fDataType = getDataType(cfgDataType); @@ -1151,10 +1199,10 @@ struct DptDptFilterTracks { tpcExcluder.setCuts(pLowCut, pUpCut, nLowCut, nUpCut); /* self configure system type and data type */ - /* if the system type is not known at this time, we have to put the initialization somewhere else */ + o2::framework::LabeledArray tmpArray = {periodsOnSystemType[0], 11, 1, {SYSTEMNAME(0), SYSTEMNAME(1), SYSTEMNAME(2), SYSTEMNAME(3), SYSTEMNAME(4), SYSTEMNAME(5), SYSTEMNAME(6), SYSTEMNAME(7), SYSTEMNAME(8), SYSTEMNAME(9), SYSTEMNAME(10)}, {"Periods separated by commas"}}; + getTaskOptionValue(initContext, "dpt-dpt-filter", "cfgSystem", tmpArray, false); + fSystem = getSystemType(tmpArray); std::string tmpstr; - getTaskOptionValue(initContext, "dpt-dpt-filter", "cfgSystem", tmpstr, false); - fSystem = getSystemType(tmpstr); getTaskOptionValue(initContext, "dpt-dpt-filter", "cfgDataType", tmpstr, false); fDataType = getDataType(tmpstr); diff --git a/PWGCF/TableProducer/dptDptFilter.h b/PWGCF/TableProducer/dptDptFilter.h index 14a49c3bbf0..5e1a479631e 100644 --- a/PWGCF/TableProducer/dptDptFilter.h +++ b/PWGCF/TableProducer/dptDptFilter.h @@ -86,6 +86,25 @@ enum SystemType { SystemNoOfSystems ///< number of handled systems }; +/// @brief SystemType prefix increment operator +/// @param ipar value +/// @return the incremented value +inline SystemType& operator++(SystemType& ipar) +{ + return ipar = static_cast(static_cast(ipar) + 1); +} + +/// @brief SystemType postfix increment operator +/// @param ipar the value +/// @param empty +/// @return the same value +inline SystemType operator++(SystemType& ipar, int) +{ + SystemType iparTmp(ipar); + ++ipar; + return iparTmp; +} + /// \std::map systemInternalCodesMap /// \brief maps system names to internal system codes static const std::map systemInternalCodesMap{ @@ -856,40 +875,28 @@ inline std::bitset<32> getTriggerSelection(std::string_view const& triggstr) return flags; } -inline SystemType getSytemTypeFromMetaData() +inline SystemType getSystemType(auto const& periodsForSysType) { auto period = metadataInfo.get("LPMProductionTag"); auto anchoredPeriod = metadataInfo.get("AnchorProduction"); + bool checkAnchor = anchoredPeriod.length() > 0; - if (period == "LHC25ad" || anchoredPeriod == "LHC25ad") { - LOGF(info, "Configuring for p-O (anchored to) LHC25ad period"); - return SystemPORun3; - } else if (period == "LHC25ae" || anchoredPeriod == "LHC25ae") { - LOGF(info, "Configuring for O-O (anchored to) LHC25ae period"); - return SystemOORun3; - } else if (period == "LHC25af" || anchoredPeriod == "LHC25af") { - LOGF(info, "Configuring for Ne-Ne (anchored to) LHC25af period"); - return SystemNeNeRun3; - } else { - LOGF(fatal, "DptDptCorrelations::getSystemTypeFromMetadata(). No automatic system type configuration for %s period", period.c_str()); - } - return SystemPbPb; -} - -inline SystemType getSystemType(std::string_view const& sysstr) -{ - /* we have to figure out how extract the system type */ - if (sysstr == "Auto") { - /* special treatment for self configuration */ - /* TODO: expand it to all systems */ - return getSytemTypeFromMetaData(); - } else { - if (systemInternalCodesMap.contains(sysstr)) { - return static_cast(systemInternalCodesMap.at(sysstr)); - } else { - LOGF(fatal, "DptDptCorrelations::getSystemType(). Wrong system type: %s", sysstr.data()); + for (SystemType sT = SystemNoSystem; sT < SystemNoOfSystems; ++sT) { + const std::string& periods = periodsForSysType[static_cast(sT)][0]; + auto contains = [periods](auto const& period) { + if (periods.find(period) != std::string::npos) { + return true; + } + return false; + }; + if (periods.length() > 0) { + if (contains(period) || (checkAnchor && contains(anchoredPeriod))) { + LOGF(info, "DptDptCorrelations::getSystemType(). Assigned system type %s for period %s", systemExternalNamesMap.at(static_cast(sT)).data(), period.c_str()); + return sT; + } } } + LOGF(fatal, "DptDptCorrelations::getSystemType(). No system type for period: %s", period.c_str()); return SystemPbPb; } @@ -954,11 +961,11 @@ inline OccupancyEstimationType getOccupancyEstimator(const std::string_view& est /// @return the expression TFormula inline TFormula* getExclusionFormula(std::string_view formula) { + collisionMultiplicityCentralityObservables.resize(CentMultCorrelationsNOOFPARAMS); if (formula.length() != 0) { useCentralityMultiplicityCorrelationsExclusion = true; TFormula* f = new TFormula("Exclussion expression", formula.data()); int nParameters = f->GetNpar(); - collisionMultiplicityCentralityObservables.resize(CentMultCorrelationsNOOFPARAMS); observableIndexForCentralityMultiplicityParameter.resize(nParameters); LOGF(info, "Configuring outliers exclusion with the formula %s which has %d parameters", formula.data(), nParameters); for (int iPar = 0; iPar < nParameters; ++iPar) {