Skip to content

Commit

Permalink
Adding option to load correction map from local macro
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-kleiner committed Dec 15, 2023
1 parent 13053ae commit afe2c25
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ class CorrectionMapsLoader : public o2::gpu::CorrectionMapsHelper
static void addOption(std::vector<o2::framework::ConfigParamSpec>& options, o2::framework::ConfigParamSpec&& osp);
static void addInput(std::vector<o2::framework::InputSpec>& 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
};

Expand Down
42 changes: 42 additions & 0 deletions Detectors/TPC/calibration/src/CorrectionMapsLoader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<std::vector<Long64_t>*>("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<o2::framework::TimingInfo>().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();
}
}

//________________________________________________________
Expand Down Expand Up @@ -107,6 +132,9 @@ void CorrectionMapsLoader::requestCCDBInputs(std::vector<InputSpec>& 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);
}

Expand All @@ -117,6 +145,8 @@ void CorrectionMapsLoader::addOptions(std::vector<ConfigParamSpec>& 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"}});
}

//________________________________________________________
Expand Down Expand Up @@ -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<Long64_t>*)obj)[0] / 1000;
LOG(info) << "orbit reset time updated to " << mOrbitResetTimeMS;
return true;
}
return false;
}

Expand All @@ -229,6 +264,11 @@ void CorrectionMapsLoader::init(o2::framework::InitContext& ic)
}
mScaleInverse = !(ic.options().get<bool>("recalculate-inverse-correction"));
mNthreadsInv = (ic.options().get<int>("nthreads-inverse-correction"));
mLocalCorrectionMapMacro = (ic.options().get<std::string>("local-correction-map-macro"));
mLocalCorrectionMapCommand = (ic.options().get<std::string>("local-correction-map-command"));
if (!mLocalCorrectionMapMacro.empty()) {
gROOT->LoadMacro(mLocalCorrectionMapMacro.data());
}
if (!mScaleInverse) {
LOGP(info, "Recalculating the inverse correction for every TF");
}
Expand All @@ -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()
Expand Down

0 comments on commit afe2c25

Please sign in to comment.