Skip to content

Commit bffbe91

Browse files
author
Victor
committed
[PWGCF] DptDpt - Self configure the system type
1 parent 281b383 commit bffbe91

File tree

2 files changed

+151
-96
lines changed

2 files changed

+151
-96
lines changed

PWGCF/TableProducer/dptDptFilter.cxx

Lines changed: 115 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,20 @@ static const std::string multiplicityCentralityCorrelationsFormulaBase[11][1] =
140140
/* 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])"},
141141
/* pO Run3 */ {""}};
142142

143+
/* helpers for the system type assignment */
144+
static const std::string periodsOnSystemType[11][1] = {
145+
/* no system */ {""},
146+
/* pp Run2 */ {""},
147+
/* pPb Run2 */ {""},
148+
/* Pbp Run2 */ {""},
149+
/* PbPb Run2 */ {"LHC18q,LHC18r"},
150+
/* XeXe Run2 */ {""},
151+
/* pp Run3 */ {"LHC22o"},
152+
/* PbPb Run3 */ {"LHC23zzh"},
153+
/* NeNe Run3 */ {"LHC25af"},
154+
/* OO Run3 */ {"LHC25ae"},
155+
/* pO Run3 */ {"LHC25ad"}};
156+
143157
//============================================================================================
144158
// The DptDptFilter histogram objects
145159
// TODO: consider registering in the histogram registry
@@ -248,6 +262,43 @@ std::vector<int> partMultNeg; // multiplicity of negative particles
248262

249263
using namespace dptdptfilter;
250264

265+
/* we need this for the time being from TableHelper.h */
266+
/// 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.
267+
/// @param initContext initContext of the init function
268+
/// @param taskName name of the task to check for
269+
/// @param optName name of the option to check for
270+
/// @param value value of the option to set
271+
/// @param verbose if true, print debug messages
272+
template <>
273+
bool o2::common::core::getTaskOptionValue(o2::framework::InitContext& initContext, const std::string& taskName, const std::string& optName, o2::framework::LabeledArray<std::string>& value, const bool verbose)
274+
{
275+
if (verbose) {
276+
LOG(info) << "Checking for option '" << optName << "' in task '" << taskName << "'";
277+
}
278+
const auto& workflows = initContext.services().get<o2::framework::RunningWorkflowInfo const>();
279+
int deviceCounter = 0;
280+
bool found = false;
281+
for (auto const& device : workflows.devices) {
282+
if (verbose) {
283+
LOG(info) << " Device " << deviceCounter++ << " " << device.name;
284+
}
285+
if (device.name == taskName) { // Found the mother task
286+
int optionCounter = 0;
287+
for (o2::framework::ConfigParamSpec const& option : device.options) {
288+
if (verbose) {
289+
LOG(info) << " Option " << optionCounter++ << " " << option.name << " of type " << static_cast<int>(option.type) << " = '" << option.defaultValue.asString() << "'";
290+
}
291+
if (option.name == optName) {
292+
value = option.defaultValue.get<o2::framework::LabeledArray<std::string>>();
293+
return true;
294+
}
295+
}
296+
return found;
297+
}
298+
}
299+
return false;
300+
}
301+
251302
//////////////////////////////////////////////////////////////////////////////
252303
// Multiplicity in principle for on the fly generated events
253304
//////////////////////////////////////////////////////////////////////////////
@@ -416,68 +467,65 @@ struct Multiplicity {
416467
template <typename CollisionObject, typename TrackListObject>
417468
inline void storeMultiplicitiesAndCentralities(CollisionObject const& collision, TrackListObject const& tracks)
418469
{
419-
/* only do it if we are tracking the centrality / multiplicity correlations */
420-
if (useCentralityMultiplicityCorrelationsExclusion) {
421-
int nGlobalTracks = 0;
422-
for (auto const& track : tracks) {
423-
if (track.isGlobalTrack()) {
424-
nGlobalTracks++;
425-
}
470+
int nGlobalTracks = 0;
471+
for (auto const& track : tracks) {
472+
if (track.isGlobalTrack()) {
473+
nGlobalTracks++;
426474
}
427-
for (CentMultCorrelationsParams ipar = CentMultCorrelationsMT0A; ipar < CentMultCorrelationsNOOFPARAMS; ++ipar) {
428-
switch (ipar) {
429-
case CentMultCorrelationsMT0A:
430-
collisionMultiplicityCentralityObservables[ipar] = collision.multFT0A();
431-
break;
432-
case CentMultCorrelationsMT0C:
433-
collisionMultiplicityCentralityObservables[ipar] = collision.multFT0C();
434-
break;
435-
case CentMultCorrelationsMT0M:
436-
collisionMultiplicityCentralityObservables[ipar] = collision.multFT0M();
437-
break;
438-
case CentMultCorrelationsMV0A:
439-
collisionMultiplicityCentralityObservables[ipar] = collision.multFV0A();
440-
break;
441-
case CentMultCorrelationsMV0C:
442-
collisionMultiplicityCentralityObservables[ipar] = collision.multFV0C();
443-
break;
444-
case CentMultCorrelationsMV0M:
445-
collisionMultiplicityCentralityObservables[ipar] = collision.multFV0M();
446-
break;
447-
case CentMultCorrelationsMNGLTRK:
448-
collisionMultiplicityCentralityObservables[ipar] = nGlobalTracks;
449-
break;
450-
case CentMultCorrelationsMNPVC:
451-
collisionMultiplicityCentralityObservables[ipar] = collision.multNTracksPV();
452-
break;
453-
case CentMultCorrelationsCT0A:
454-
if constexpr (framework::has_type_v<aod::cent::CentFT0A, typename CollisionObject::all_columns>) {
455-
collisionMultiplicityCentralityObservables[ipar] = collision.centFT0A();
456-
}
457-
break;
458-
case CentMultCorrelationsCT0C:
459-
if constexpr (framework::has_type_v<aod::cent::CentFT0C, typename CollisionObject::all_columns>) {
460-
collisionMultiplicityCentralityObservables[ipar] = collision.centFT0C();
461-
}
462-
break;
463-
case CentMultCorrelationsCT0M:
464-
if constexpr (framework::has_type_v<aod::cent::CentFT0M, typename CollisionObject::all_columns>) {
465-
collisionMultiplicityCentralityObservables[ipar] = collision.centFT0M();
466-
}
467-
break;
468-
case CentMultCorrelationsCV0A:
469-
if constexpr (framework::has_type_v<aod::cent::CentFV0A, typename CollisionObject::all_columns>) {
470-
collisionMultiplicityCentralityObservables[ipar] = collision.centFV0A();
471-
}
472-
break;
473-
case CentMultCorrelationsCNTPV:
474-
if constexpr (framework::has_type_v<aod::cent::CentNTPV, typename CollisionObject::all_columns>) {
475-
collisionMultiplicityCentralityObservables[ipar] = collision.centNTPV();
476-
}
477-
break;
478-
default:
479-
break;
480-
}
475+
}
476+
for (CentMultCorrelationsParams ipar = CentMultCorrelationsMT0A; ipar < CentMultCorrelationsNOOFPARAMS; ++ipar) {
477+
switch (ipar) {
478+
case CentMultCorrelationsMT0A:
479+
collisionMultiplicityCentralityObservables[ipar] = collision.multFT0A();
480+
break;
481+
case CentMultCorrelationsMT0C:
482+
collisionMultiplicityCentralityObservables[ipar] = collision.multFT0C();
483+
break;
484+
case CentMultCorrelationsMT0M:
485+
collisionMultiplicityCentralityObservables[ipar] = collision.multFT0M();
486+
break;
487+
case CentMultCorrelationsMV0A:
488+
collisionMultiplicityCentralityObservables[ipar] = collision.multFV0A();
489+
break;
490+
case CentMultCorrelationsMV0C:
491+
collisionMultiplicityCentralityObservables[ipar] = collision.multFV0C();
492+
break;
493+
case CentMultCorrelationsMV0M:
494+
collisionMultiplicityCentralityObservables[ipar] = collision.multFV0M();
495+
break;
496+
case CentMultCorrelationsMNGLTRK:
497+
collisionMultiplicityCentralityObservables[ipar] = nGlobalTracks;
498+
break;
499+
case CentMultCorrelationsMNPVC:
500+
collisionMultiplicityCentralityObservables[ipar] = collision.multNTracksPV();
501+
break;
502+
case CentMultCorrelationsCT0A:
503+
if constexpr (framework::has_type_v<aod::cent::CentFT0A, typename CollisionObject::all_columns>) {
504+
collisionMultiplicityCentralityObservables[ipar] = collision.centFT0A();
505+
}
506+
break;
507+
case CentMultCorrelationsCT0C:
508+
if constexpr (framework::has_type_v<aod::cent::CentFT0C, typename CollisionObject::all_columns>) {
509+
collisionMultiplicityCentralityObservables[ipar] = collision.centFT0C();
510+
}
511+
break;
512+
case CentMultCorrelationsCT0M:
513+
if constexpr (framework::has_type_v<aod::cent::CentFT0M, typename CollisionObject::all_columns>) {
514+
collisionMultiplicityCentralityObservables[ipar] = collision.centFT0M();
515+
}
516+
break;
517+
case CentMultCorrelationsCV0A:
518+
if constexpr (framework::has_type_v<aod::cent::CentFV0A, typename CollisionObject::all_columns>) {
519+
collisionMultiplicityCentralityObservables[ipar] = collision.centFV0A();
520+
}
521+
break;
522+
case CentMultCorrelationsCNTPV:
523+
if constexpr (framework::has_type_v<aod::cent::CentNTPV, typename CollisionObject::all_columns>) {
524+
collisionMultiplicityCentralityObservables[ipar] = collision.centNTPV();
525+
}
526+
break;
527+
default:
528+
break;
481529
}
482530
}
483531
}
@@ -515,7 +563,7 @@ struct DptDptFilter {
515563
Configurable<float> maxOccupancy{"maxOccupancy", 1e6f, "Maximum allowed occupancy. Depends on the occupancy estimation"};
516564
} occupancySelection;
517565
} cfgEventSelection;
518-
Configurable<std::string> cfgSystem{"cfgSystem", "PbPb", "System: Auto, pp, PbPb, Pbp, pPb, XeXe, ppRun3, PbPbRun3. Default PbPb"};
566+
Configurable<LabeledArray<std::string>> 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"};
519567
Configurable<std::string> cfgDataType{"cfgDataType", "data", "Data type: data, datanoevsel, MC, FastMC, OnTheFlyMC. Default data"};
520568
Configurable<std::string> 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"};
521569
Configurable<float> cfgOverallMinP{"cfgOverallMinP", 0.0f, "The overall minimum momentum for the analysis. Default: 0.0"};
@@ -588,8 +636,8 @@ struct DptDptFilter {
588636
triggerSelectionFlags = getTriggerSelection(cfgEventSelection.triggSel.value.c_str());
589637
traceCollId0 = cfgTraceCollId0;
590638

591-
/* if the system type is not known at this time, we have to put the initialization somewhere else */
592-
fSystem = getSystemType(cfgSystem.value.c_str());
639+
/* get the system type */
640+
fSystem = getSystemType(cfgSystemForPeriod.value);
593641
fLhcRun = multRunForSystemMap.at(fSystem);
594642
fDataType = getDataType(cfgDataType);
595643

@@ -1151,10 +1199,10 @@ struct DptDptFilterTracks {
11511199
tpcExcluder.setCuts(pLowCut, pUpCut, nLowCut, nUpCut);
11521200

11531201
/* self configure system type and data type */
1154-
/* if the system type is not known at this time, we have to put the initialization somewhere else */
1202+
o2::framework::LabeledArray<std::string> 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"}};
1203+
getTaskOptionValue(initContext, "dpt-dpt-filter", "cfgSystem", tmpArray, false);
1204+
fSystem = getSystemType(tmpArray);
11551205
std::string tmpstr;
1156-
getTaskOptionValue(initContext, "dpt-dpt-filter", "cfgSystem", tmpstr, false);
1157-
fSystem = getSystemType(tmpstr);
11581206
getTaskOptionValue(initContext, "dpt-dpt-filter", "cfgDataType", tmpstr, false);
11591207
fDataType = getDataType(tmpstr);
11601208

PWGCF/TableProducer/dptDptFilter.h

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,25 @@ enum SystemType {
8686
SystemNoOfSystems ///< number of handled systems
8787
};
8888

89+
/// @brief SystemType prefix increment operator
90+
/// @param ipar value
91+
/// @return the incremented value
92+
inline SystemType& operator++(SystemType& ipar)
93+
{
94+
return ipar = static_cast<SystemType>(static_cast<int>(ipar) + 1);
95+
}
96+
97+
/// @brief SystemType postfix increment operator
98+
/// @param ipar the value
99+
/// @param empty
100+
/// @return the same value
101+
inline SystemType operator++(SystemType& ipar, int)
102+
{
103+
SystemType iparTmp(ipar);
104+
++ipar;
105+
return iparTmp;
106+
}
107+
89108
/// \std::map systemInternalCodesMap
90109
/// \brief maps system names to internal system codes
91110
static const std::map<std::string_view, int> systemInternalCodesMap{
@@ -856,40 +875,28 @@ inline std::bitset<32> getTriggerSelection(std::string_view const& triggstr)
856875
return flags;
857876
}
858877

859-
inline SystemType getSytemTypeFromMetaData()
878+
inline SystemType getSystemType(auto const& periodsForSysType)
860879
{
861880
auto period = metadataInfo.get("LPMProductionTag");
862881
auto anchoredPeriod = metadataInfo.get("AnchorProduction");
882+
bool checkAnchor = anchoredPeriod.length() > 0;
863883

864-
if (period == "LHC25ad" || anchoredPeriod == "LHC25ad") {
865-
LOGF(info, "Configuring for p-O (anchored to) LHC25ad period");
866-
return SystemPORun3;
867-
} else if (period == "LHC25ae" || anchoredPeriod == "LHC25ae") {
868-
LOGF(info, "Configuring for O-O (anchored to) LHC25ae period");
869-
return SystemOORun3;
870-
} else if (period == "LHC25af" || anchoredPeriod == "LHC25af") {
871-
LOGF(info, "Configuring for Ne-Ne (anchored to) LHC25af period");
872-
return SystemNeNeRun3;
873-
} else {
874-
LOGF(fatal, "DptDptCorrelations::getSystemTypeFromMetadata(). No automatic system type configuration for %s period", period.c_str());
875-
}
876-
return SystemPbPb;
877-
}
878-
879-
inline SystemType getSystemType(std::string_view const& sysstr)
880-
{
881-
/* we have to figure out how extract the system type */
882-
if (sysstr == "Auto") {
883-
/* special treatment for self configuration */
884-
/* TODO: expand it to all systems */
885-
return getSytemTypeFromMetaData();
886-
} else {
887-
if (systemInternalCodesMap.contains(sysstr)) {
888-
return static_cast<SystemType>(systemInternalCodesMap.at(sysstr));
889-
} else {
890-
LOGF(fatal, "DptDptCorrelations::getSystemType(). Wrong system type: %s", sysstr.data());
884+
for (SystemType sT = SystemNoSystem; sT < SystemNoOfSystems; ++sT) {
885+
const std::string& periods = periodsForSysType[static_cast<int>(sT)][0];
886+
auto contains = [periods](auto const& period) {
887+
if (periods.find(period) != std::string::npos) {
888+
return true;
889+
}
890+
return false;
891+
};
892+
if (periods.length() > 0) {
893+
if (contains(period) || (checkAnchor && contains(anchoredPeriod))) {
894+
LOGF(info, "DptDptCorrelations::getSystemType(). Assigned system type %s for period %s", systemExternalNamesMap.at(static_cast<int>(sT)).data(), period.c_str());
895+
return sT;
896+
}
891897
}
892898
}
899+
LOGF(fatal, "DptDptCorrelations::getSystemType(). No system type for period: %s", period.c_str());
893900
return SystemPbPb;
894901
}
895902

@@ -954,11 +961,11 @@ inline OccupancyEstimationType getOccupancyEstimator(const std::string_view& est
954961
/// @return the expression TFormula
955962
inline TFormula* getExclusionFormula(std::string_view formula)
956963
{
964+
collisionMultiplicityCentralityObservables.resize(CentMultCorrelationsNOOFPARAMS);
957965
if (formula.length() != 0) {
958966
useCentralityMultiplicityCorrelationsExclusion = true;
959967
TFormula* f = new TFormula("Exclussion expression", formula.data());
960968
int nParameters = f->GetNpar();
961-
collisionMultiplicityCentralityObservables.resize(CentMultCorrelationsNOOFPARAMS);
962969
observableIndexForCentralityMultiplicityParameter.resize(nParameters);
963970
LOGF(info, "Configuring outliers exclusion with the formula %s which has %d parameters", formula.data(), nParameters);
964971
for (int iPar = 0; iPar < nParameters; ++iPar) {

0 commit comments

Comments
 (0)