From afe2c25bf5ae33043f11c7c7022b09cf435720f4 Mon Sep 17 00:00:00 2001 From: Matthias Kleiner Date: Fri, 15 Dec 2023 16:35:51 +0100 Subject: [PATCH] Adding option to load correction map from local macro --- .../TPCCalibration/CorrectionMapsLoader.h | 9 ++-- .../calibration/src/CorrectionMapsLoader.cxx | 42 +++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/Detectors/TPC/calibration/include/TPCCalibration/CorrectionMapsLoader.h b/Detectors/TPC/calibration/include/TPCCalibration/CorrectionMapsLoader.h index f99b2f5de0a33..00a02fa464710 100644 --- a/Detectors/TPC/calibration/include/TPCCalibration/CorrectionMapsLoader.h +++ b/Detectors/TPC/calibration/include/TPCCalibration/CorrectionMapsLoader.h @@ -72,9 +72,12 @@ class CorrectionMapsLoader : public o2::gpu::CorrectionMapsHelper static void addOption(std::vector& options, o2::framework::ConfigParamSpec&& osp); static void addInput(std::vector& inputs, o2::framework::InputSpec&& isp); - float mInstLumiFactor = 1.0; // multiplicative factor for inst. lumi - int mCTPLumiSource = 0; // 0: main, 1: alternative CTP lumi source - int mNthreadsInv = 1; // number of threads used for calculating the inverse correction + float mInstLumiFactor = 1.0; // multiplicative factor for inst. lumi + int mCTPLumiSource = 0; // 0: main, 1: alternative CTP lumi source + int mNthreadsInv = 1; // number of threads used for calculating the inverse correction + std::string mLocalCorrectionMapMacro = ""; // path for local macro for creating the correction map + std::string mLocalCorrectionMapCommand = ""; // gSystem->Exec command which will be executed + long mOrbitResetTimeMS{}; #endif }; diff --git a/Detectors/TPC/calibration/src/CorrectionMapsLoader.cxx b/Detectors/TPC/calibration/src/CorrectionMapsLoader.cxx index 77b3e4aeefbe4..4b51215c8b2f2 100644 --- a/Detectors/TPC/calibration/src/CorrectionMapsLoader.cxx +++ b/Detectors/TPC/calibration/src/CorrectionMapsLoader.cxx @@ -24,6 +24,8 @@ #include "Framework/ConfigParamRegistry.h" #include "DataFormatsCTP/LumiInfo.h" #include "TPCCalibration/TPCFastSpaceChargeCorrectionHelper.h" +#include "TROOT.h" +#include "TSystem.h" using namespace o2::tpc; using namespace o2::framework; @@ -75,6 +77,29 @@ void CorrectionMapsLoader::extractCCDBInputs(ProcessingContext& pc) if (!mScaleInverse) { updateInverse(); } + + // in case local macro is requested overwrite map with map from macro and set scalers to 0 + if (!mLocalCorrectionMapMacro.empty()) { + pc.inputs().get*>("orbitReset"); + LOGP(info, "Loading correction map from local macro: {}", mLocalCorrectionMapMacro); + setInstLumi(0, false); + setMeanLumi(0, false); + updateLumiScale(false); + setVShapeScaler(0); + const auto firstTFOrbit = pc.services().get().firstTForbit; + const double timestamp = mOrbitResetTimeMS + firstTFOrbit * o2::constants::lhc::LHCOrbitMUS * 0.001; + + if (!mLocalCorrectionMapCommand.empty()) { + const std::string execCommand = fmt::format("{} {}", mLocalCorrectionMapCommand, timestamp); + gSystem->Exec(execCommand.data()); + } + + auto corrMapMacro = (o2::gpu::TPCFastTransform*)(gROOT->ProcessLine(fmt::format("getMap({})", timestamp).data())); + + setCorrMap(corrMapMacro); + mCorrMap->rectifyAfterReadingFromFile(); + setUpdatedMap(); + } } //________________________________________________________ @@ -107,6 +132,9 @@ void CorrectionMapsLoader::requestCCDBInputs(std::vector& inputs, std addInput(inputs, {"tpcCorrPar", "TPC", "CorrMapParam", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CorrMapParam), {}, 0)}); // load once + // TODO: request only if local macro is used + addInput(inputs, {"orbitReset", "CTP", "ORBITRESET", 0, Lifetime::Condition, ccdbParamSpec("CTP/Calib/OrbitReset")}); + addOptions(options); } @@ -117,6 +145,8 @@ void CorrectionMapsLoader::addOptions(std::vector& options) // At the moment - nothing, all options are moved to configurable param CorrMapParam addOption(options, ConfigParamSpec{"recalculate-inverse-correction", o2::framework::VariantType::Bool, false, {"Recalculate the inverse correction in case linear scaling of corrections is used"}}); addOption(options, ConfigParamSpec{"nthreads-inverse-correction", o2::framework::VariantType::Int, -1, {"Number of threads used for calculating the inverse correction (-1=all threads)"}}); + addOption(options, ConfigParamSpec{"local-correction-map-command", o2::framework::VariantType::String, "", {"Command which is executed before the local macro is executed with gSystem->Exec"}}); + addOption(options, ConfigParamSpec{"local-correction-map-macro", o2::framework::VariantType::String, "", {"Path to local root macro returning a correction map"}}); } //________________________________________________________ @@ -210,6 +240,11 @@ bool CorrectionMapsLoader::accountCCDBInputs(const ConcreteDataMatcher& matcher, LOGP(info, "TPC correction map params updated (corr.map scaling type={}): override values: lumiMean={} lumiRefMean={} lumiInst={} lumiScaleMode={}, LumiInst scale={}, CTP Lumi source={}", lumiS[scaleType], mMeanLumiOverride, mMeanLumiRefOverride, mInstLumiOverride, mLumiScaleMode, mInstLumiFactor, mCTPLumiSource); } + if (matcher == ConcreteDataMatcher("CTP", "ORBITRESET", 0)) { + mOrbitResetTimeMS = (*(std::vector*)obj)[0] / 1000; + LOG(info) << "orbit reset time updated to " << mOrbitResetTimeMS; + return true; + } return false; } @@ -229,6 +264,11 @@ void CorrectionMapsLoader::init(o2::framework::InitContext& ic) } mScaleInverse = !(ic.options().get("recalculate-inverse-correction")); mNthreadsInv = (ic.options().get("nthreads-inverse-correction")); + mLocalCorrectionMapMacro = (ic.options().get("local-correction-map-macro")); + mLocalCorrectionMapCommand = (ic.options().get("local-correction-map-command")); + if (!mLocalCorrectionMapMacro.empty()) { + gROOT->LoadMacro(mLocalCorrectionMapMacro.data()); + } if (!mScaleInverse) { LOGP(info, "Recalculating the inverse correction for every TF"); } @@ -252,6 +292,8 @@ void CorrectionMapsLoader::copySettings(const CorrectionMapsLoader& src) mLumiScaleMode = src.mLumiScaleMode; mScaleInverse = src.getScaleInverse(); mNthreadsInv = src.mNthreadsInv; + mLocalCorrectionMapMacro = src.mLocalCorrectionMapMacro; + mLocalCorrectionMapCommand = src.mLocalCorrectionMapCommand; } void CorrectionMapsLoader::updateInverse()