Project
Loading...
Searching...
No Matches
CorrectionMapsLoader.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
16#include "Framework/Logger.h"
27
28using namespace o2::tpc;
29using namespace o2::framework;
30
31#ifndef GPUCA_GPUCODE_DEVICE
32
33//________________________________________________________
34void CorrectionMapsLoader::updateVDrift(float vdriftCorr, float vdrifRef, float driftTimeOffset)
35{
36 o2::tpc::TPCFastTransformHelperO2::instance()->updateCalibration(*mCorrMap, 0, vdriftCorr, vdrifRef, driftTimeOffset);
37 if (mCorrMapRef) {
38 o2::tpc::TPCFastTransformHelperO2::instance()->updateCalibration(*mCorrMapRef, 0, vdriftCorr, vdrifRef, driftTimeOffset);
39 }
40 if (mCorrMapMShape) {
41 o2::tpc::TPCFastTransformHelperO2::instance()->updateCalibration(*mCorrMapMShape, 0, vdriftCorr, vdrifRef, driftTimeOffset);
42 }
43}
44
45//________________________________________________________
47{
48 pc.inputs().get<o2::tpc::CorrMapParam*>("tpcCorrPar");
49 pc.inputs().get<o2::gpu::TPCFastTransform*>("tpcCorrMap");
50 pc.inputs().get<o2::gpu::TPCFastTransform*>("tpcCorrMapRef");
51 const int maxDumRep = 5;
52 int dumRep = 0;
53 o2::ctp::LumiInfo lumiObj;
54 static o2::ctp::LumiInfo lumiPrev;
55
57 if (pc.inputs().get<gsl::span<char>>("CTPLumi").size() == sizeof(o2::ctp::LumiInfo)) {
58 lumiPrev = lumiObj = pc.inputs().get<o2::ctp::LumiInfo>("CTPLumi");
59 } else {
60 if (dumRep < maxDumRep && lumiPrev.nHBFCounted == 0 && lumiPrev.nHBFCountedFV0 == 0) {
61 LOGP(alarm, "Previous TF lumi used to substitute dummy input is empty, warning {} of {}", ++dumRep, maxDumRep);
62 }
63 lumiObj = lumiPrev;
64 }
65 setInstLumiCTP(mInstLumiCTPFactor * (mLumiCTPSource == 0 ? lumiObj.getLumi() : lumiObj.getLumiAlt()));
66 if (getLumiScaleType() == 1) {
67 setInstLumi(getInstLumiCTP());
68 }
69 }
70 if (getLumiScaleType() == 2) {
71 float tpcScaler = pc.inputs().get<float>("tpcscaler");
72 setInstLumi(tpcScaler);
73 }
75 LOGP(info, "Setting M-Shape map");
76 const auto mapMShape = pc.inputs().get<o2::gpu::TPCFastTransform*>("mshape");
77 const_cast<o2::gpu::TPCFastTransform*>(mapMShape.get())->rectifyAfterReadingFromFile();
78 mCorrMapMShape = std::unique_ptr<TPCFastTransform>(new TPCFastTransform);
79 mCorrMapMShape->cloneFromObject(*(mapMShape.get()), nullptr);
82 }
83
84 // update inverse in case it is requested
85 if (!mScaleInverse) {
87 }
89}
90
91//________________________________________________________
92void CorrectionMapsLoader::requestCCDBInputs(std::vector<InputSpec>& inputs, std::vector<o2::framework::ConfigParamSpec>& options, const CorrectionMapsLoaderGloOpts& gloOpts)
93{
94 if (gloOpts.lumiMode == 0) {
95 addInput(inputs, {"tpcCorrMap", "TPC", "CorrMap", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMap), {}, 1)}); // time-dependent
96 addInput(inputs, {"tpcCorrMapRef", "TPC", "CorrMapRef", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMapRef), {}, 0)}); // load once
97 } else if (gloOpts.lumiMode == 1) {
98 addInput(inputs, {"tpcCorrMap", "TPC", "CorrMap", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMap), {}, 1)}); // time-dependent
99 addInput(inputs, {"tpcCorrMapRef", "TPC", "CorrMapRef", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrDerivMap), {}, 1)}); // time-dependent
100 } else if (gloOpts.lumiMode == 2) {
101 // for MC corrections
102 addInput(inputs, {"tpcCorrMap", "TPC", "CorrMap", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMapMC), {}, 1)}); // time-dependent
103 addInput(inputs, {"tpcCorrMapRef", "TPC", "CorrMapRef", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrDerivMapMC), {}, 1)}); // time-dependent
104 } else {
105 LOG(fatal) << "Correction mode unknown! Choose either 0 (default) or 1 (derivative map) for flag corrmap-lumi-mode.";
106 }
107
108 if (gloOpts.requestCTPLumi) {
109 addInput(inputs, {"CTPLumi", "CTP", "LUMI", 0, Lifetime::Timeframe});
110 }
111
112 if (gloOpts.lumiType == 2) {
113 addInput(inputs, {"tpcscaler", o2::header::gDataOriginTPC, "TPCSCALER", 0, Lifetime::Timeframe});
114 }
115
116 addInput(inputs, {"tpcCorrPar", "TPC", "CorrMapParam", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CorrMapParam), {}, 0)}); // load once
117
118 if (gloOpts.enableMShapeCorrection) {
119 addInput(inputs, {"mshape", o2::header::gDataOriginTPC, "TPCMSHAPE", 0, Lifetime::Timeframe});
120 }
121 addOptions(options);
122}
123
124//________________________________________________________
125void CorrectionMapsLoader::addOptions(std::vector<ConfigParamSpec>& options)
126{
127 // these are options which should be added at the level of device using TPC corrections
128 // At the moment - nothing, all options are moved to configurable param CorrMapParam
129 addOption(options, ConfigParamSpec{"recalculate-inverse-correction", o2::framework::VariantType::Bool, false, {"recalculate the inverse correction in case lumi mode 1 or 2 is used"}});
130 addOption(options, ConfigParamSpec{"nthreads-inverse-correction", o2::framework::VariantType::Int, 4, {"Number of threads used for calculating the inverse correction (-1=all threads)"}});
131}
132
133//________________________________________________________
134void CorrectionMapsLoader::addGlobalOptions(std::vector<ConfigParamSpec>& options)
135{
136 // these are options which should be added at the workflow level, since they modify the inputs of the devices
137 addOption(options, ConfigParamSpec{"lumi-type", o2::framework::VariantType::Int, 0, {"1 = use CTP lumi for TPC correction scaling, 2 = use TPC scalers for TPC correction scaling"}});
138 addOption(options, ConfigParamSpec{"corrmap-lumi-mode", o2::framework::VariantType::Int, 0, {"scaling mode: (default) 0 = static + scale * full; 1 = full + scale * derivative; 2 = full + scale * derivative (for MC)"}});
139 addOption(options, ConfigParamSpec{"enable-M-shape-correction", o2::framework::VariantType::Bool, false, {"Enable M-shape distortion correction"}});
140 addOption(options, ConfigParamSpec{"disable-ctp-lumi-request", o2::framework::VariantType::Bool, false, {"do not request CTP lumi (regardless what is used for corrections)"}});
141 addOption(options, ConfigParamSpec{"disable-lumi-type-consistency-check", o2::framework::VariantType::Bool, false, {"disable check of selected CTP or IDC scaling source being consistent with the map"}});
142}
143
144//________________________________________________________
146{
148 tpcopt.lumiType = opts.get<int>("lumi-type");
149 tpcopt.lumiMode = opts.get<int>("corrmap-lumi-mode");
150 tpcopt.enableMShapeCorrection = opts.get<bool>("enable-M-shape-correction");
151 tpcopt.requestCTPLumi = !opts.get<bool>("disable-ctp-lumi-request");
152 tpcopt.checkCTPIDCconsistency = !opts.get<bool>("disable-lumi-type-consistency-check");
153 if (!tpcopt.requestCTPLumi && tpcopt.lumiType == 1) {
154 LOGP(fatal, "Scaling with CTP Lumi is requested but this input is disabled");
155 }
156 return tpcopt;
157}
158
159//________________________________________________________
160void CorrectionMapsLoader::addInput(std::vector<InputSpec>& inputs, InputSpec&& isp)
161{
162 if (std::find(inputs.begin(), inputs.end(), isp) == inputs.end()) {
163 inputs.emplace_back(isp);
164 }
165}
166
167//________________________________________________________
168void CorrectionMapsLoader::addOption(std::vector<ConfigParamSpec>& options, ConfigParamSpec&& osp)
169{
170 if (std::find(options.begin(), options.end(), osp) == options.end()) {
171 options.emplace_back(osp);
172 }
173}
174
175//________________________________________________________
177{
178 if (matcher == ConcreteDataMatcher("TPC", "CorrMap", 0)) {
182 if (getMeanLumiOverride() != 0) {
183 if (getLumiScaleType() == 1) {
185 LOGP(info, "CorrMap mean lumi rate is overridden to {}", mCorrMap->getLumi());
186 } else if (getLumiScaleType() == 2) {
188 LOGP(info, "CorrMap mean IDC rate is overridden to {}", mCorrMap->getIDC());
189 }
190 }
191 float mapMeanRate = 0;
192 if (getLumiScaleType() == 1) {
193 mapMeanRate = mCorrMap->getLumi();
194 } else if (getLumiScaleType() == 2) {
195 mapMeanRate = mCorrMap->getIDC();
196 }
198 checkMeanScaleConsistency(mapMeanRate, mCorrMap->getCTP2IDCFallBackThreshold());
199 }
200 if (getMeanLumiOverride() == 0 && mapMeanRate > 0.) {
201 setMeanLumi(mapMeanRate, false);
202 }
203 LOGP(debug, "MeanLumiOverride={} MeanLumiMap={} -> meanLumi = {}", getMeanLumiOverride(), mapMeanRate, getMeanLumi());
205 return true;
206 }
207 if (matcher == ConcreteDataMatcher("TPC", "CorrMapRef", 0)) {
211 if (getMeanLumiRefOverride() != 0) {
212 if (getLumiScaleType() == 1) {
214 LOGP(info, "CorrMapRef mean lumi rate is overridden to {}", mCorrMapRef->getLumi());
215 } else if (getLumiScaleType() == 2) {
217 LOGP(info, "CorrMapRef mean IDC rate is overridden to {}", mCorrMapRef->getIDC());
218 }
219 }
220 float mapRefMeanRate = 0;
221 if (getLumiScaleType() == 1) {
222 mapRefMeanRate = mCorrMapRef->getLumi();
223 } else if (getLumiScaleType() == 2) {
224 mapRefMeanRate = mCorrMapRef->getIDC();
225 }
227 checkMeanScaleConsistency(mapRefMeanRate, mCorrMapRef->getCTP2IDCFallBackThreshold());
228 }
229 if (getMeanLumiRefOverride() == 0) {
230 setMeanLumiRef(mapRefMeanRate);
231 }
232 LOGP(debug, "MeanLumiRefOverride={} MeanLumiMap={} -> meanLumi = {}", getMeanLumiRefOverride(), mapRefMeanRate, getMeanLumiRef());
234 return true;
235 }
236 if (matcher == ConcreteDataMatcher("TPC", "CorrMapParam", 0)) {
237 const auto& par = o2::tpc::CorrMapParam::Instance();
238 mMeanLumiOverride = par.lumiMean; // negative value switches off corrections !!!
239 mMeanLumiRefOverride = par.lumiMeanRef;
240 mInstCTPLumiOverride = par.lumiInst;
241 mInstLumiCTPFactor = par.lumiInstFactor;
242 mLumiCTPSource = par.ctpLumiSource;
243
244 if (mMeanLumiOverride != 0.) {
246 }
247 if (mMeanLumiRefOverride != 0.) {
249 }
250 if (mInstCTPLumiOverride != 0.) {
252 if (getLumiScaleType() == 1) {
253 setInstLumi(getInstLumiCTP(), false);
254 }
255 }
257 int scaleType = getLumiScaleType();
258 const std::array<std::string, 3> lumiS{"OFF", "CTP", "TPC scaler"};
259 if (scaleType >= lumiS.size()) {
260 LOGP(fatal, "Wrong corrmap-lumi-mode provided!");
261 }
262
263 LOGP(info, "TPC correction map params updated: SP corrections: {} (corr.map scaling type={}, override values: lumiMean={} lumiRefMean={} lumiScaleMode={}), CTP Lumi: source={} lumiInstOverride={} , LumiInst scale={} ",
264 canUseCorrections() ? "ON" : "OFF",
266 }
267 return false;
268}
269
270//________________________________________________________
272{
273 if (getLumiScaleMode() < 0) {
274 LOGP(fatal, "TPC correction lumi scaling mode is not set");
275 }
276 const auto& inputRouts = ic.services().get<const o2::framework::DeviceSpec>().inputs;
277 bool foundCTP = false, foundTPCScl = false, foundMShape = false;
278 for (const auto& route : inputRouts) {
279 if (route.matcher == InputSpec{"CTPLumi", "CTP", "LUMI", 0, Lifetime::Timeframe}) {
280 foundCTP = true;
281 } else if (route.matcher == InputSpec{"tpcscaler", o2::header::gDataOriginTPC, "TPCSCALER", 0, Lifetime::Timeframe}) {
282 foundTPCScl = true;
283 } else if (route.matcher == InputSpec{"mshape", o2::header::gDataOriginTPC, "TPCMSHAPE", 0, Lifetime::Timeframe}) {
284 foundMShape = true;
285 }
286 }
287 setLumiCTPAvailable(foundCTP);
288 enableMShapeCorrection(foundMShape);
289 if ((getLumiScaleType() == 1 && !foundCTP) || (getLumiScaleType() == 2 && !foundTPCScl)) {
290 LOGP(fatal, "Lumi scaling source {}({}) is not available for TPC correction", getLumiScaleType(), getLumiScaleType() == 1 ? "CTP" : "TPCScaler");
291 }
292
293 if ((getLumiScaleMode() == 1) || (getLumiScaleMode() == 2)) {
294 mScaleInverse = !(ic.options().get<bool>("recalculate-inverse-correction"));
295 } else {
296 mScaleInverse = true;
297 }
298 const int nthreadsInv = (ic.options().get<int>("nthreads-inverse-correction"));
300}
301
302//________________________________________________________
304{
305 setInstLumi(src.getInstLumi(), false);
306 setInstLumiCTP(src.getInstLumiCTP());
307 setMeanLumi(src.getMeanLumi(), false);
308 setLumiCTPAvailable(src.getLumiCTPAvailable());
309 setMeanLumiRef(src.getMeanLumiRef());
310 setLumiScaleType(src.getLumiScaleType());
311 setMeanLumiOverride(src.getMeanLumiOverride());
312 setMeanLumiRefOverride(src.getMeanLumiRefOverride());
313 setInstCTPLumiOverride(src.getInstCTPLumiOverride());
314 setLumiScaleMode(src.getLumiScaleMode());
315 enableMShapeCorrection(src.getUseMShapeCorrection());
316 mInstLumiCTPFactor = src.mInstLumiCTPFactor;
317 mLumiCTPSource = src.mLumiCTPSource;
318 mLumiScaleMode = src.mLumiScaleMode;
319 mScaleInverse = src.getScaleInverse();
320}
321
323{
324 if (mLumiScaleMode == 1 || mLumiScaleMode == 2) {
325 LOGP(info, "Recalculating the inverse correction");
327 std::vector<float> scaling{1, mLumiScale};
328 std::vector<o2::gpu::TPCFastSpaceChargeCorrection*> corr{&(mCorrMap->getCorrection()), &(mCorrMapRef->getCorrection())};
329 if (mCorrMapMShape) {
330 scaling.emplace_back(1);
331 corr.emplace_back(&(mCorrMapMShape->getCorrection()));
332 }
334 } else {
335 LOGP(info, "Reinitializing inverse correction with lumi scale mode {} not supported for now", mLumiScaleMode);
336 }
337}
338
339void CorrectionMapsLoader::checkMeanScaleConsistency(float meanLumi, float threshold) const
340{
341 if (getLumiScaleType() == 1) {
342 if (meanLumi < threshold) {
343 LOGP(fatal, "CTP Lumi scaling source is requested, but the map mean scale {} is below the threshold {}", meanLumi, threshold);
344 }
345 } else if (getLumiScaleType() == 2) {
346 if (meanLumi > threshold) {
347 LOGP(fatal, "IDC scaling source is requested, but the map mean scale {} is above the threshold {}", meanLumi, threshold);
348 }
349 }
350}
351
352#endif // #ifndef GPUCA_GPUCODE_DEVICE
Simple interface to the CDB manager.
Implementation of the parameter class for the CorrectionMapsLoader options.
Helper class to access load maps from CCDB.
class to create TPC fast space charge correction
class to create TPC fast transformation
std::ostringstream debug
ServiceRegistryRef services()
Definition InitContext.h:34
decltype(auto) get(R binding, int part=0) const
InputRecord & inputs()
The inputs associated with this processing context.
void setCorrMapMShape(o2::gpu::TPCFastTransform *m)
void setCorrMapRef(o2::gpu::TPCFastTransform *m)
o2::gpu::TPCFastTransform * mCorrMap
void setMeanLumiRef(float v, bool report=false)
void setInstLumi(float v, bool report=false)
void setMeanLumi(float v, bool report=false)
o2::gpu::TPCFastTransform * mCorrMapRef
void setCorrMap(std::unique_ptr< o2::gpu::TPCFastTransform > &&m)
void setLumi(float l)
Set Lumi info.
void setCTP2IDCFallBackThreshold(float v)
TPCFastSpaceChargeCorrection & getCorrection()
Gives a reference for external initialization of TPC corrections.
void extractCCDBInputs(o2::framework::ProcessingContext &pc)
void updateVDrift(float vdriftCorr, float vdrifRef, float driftTimeOffset=0)
static void addGlobalOptions(std::vector< o2::framework::ConfigParamSpec > &options)
bool accountCCDBInputs(const o2::framework::ConcreteDataMatcher &matcher, void *obj)
static void addOptions(std::vector< o2::framework::ConfigParamSpec > &options)
static void requestCCDBInputs(std::vector< o2::framework::InputSpec > &inputs, std::vector< o2::framework::ConfigParamSpec > &options, const CorrectionMapsLoaderGloOpts &gloOpts)
void init(o2::framework::InitContext &ic)
static void addOption(std::vector< o2::framework::ConfigParamSpec > &options, o2::framework::ConfigParamSpec &&osp)
std::unique_ptr< o2::gpu::TPCFastTransform > mCorrMapMShape
void checkMeanScaleConsistency(float meanLumi, float threshold) const
recalculate inverse correction
void copySettings(const CorrectionMapsLoader &src)
static CorrectionMapsLoaderGloOpts parseGlobalOptions(const o2::framework::ConfigParamRegistry &opts)
static void addInput(std::vector< o2::framework::InputSpec > &inputs, o2::framework::InputSpec &&isp)
void initInverse(o2::gpu::TPCFastSpaceChargeCorrection &correction, bool prn)
initialise inverse transformation
void setNthreads(int n)
_______________ Settings ________________________
void setNthreadsToMaximum()
sets number of threads to N cpu cores
static TPCFastSpaceChargeCorrectionHelper * instance()
Singleton.
int updateCalibration(TPCFastTransform &transform, Long_t TimeStamp, float vDriftFactor=1.f, float vDriftRef=0.f, float driftTimeOffset=0.f)
Updates the transformation with the new time stamp.
static TPCFastTransformHelperO2 * instance()
Singleton.
GLenum src
Definition glcorearb.h:1767
GLsizeiptr size
Definition glcorearb.h:659
constexpr o2::header::DataOrigin gDataOriginTPC
Definition DataHeader.h:576
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
Global TPC definitions and constants.
Definition SimTraits.h:167
const std::unordered_map< CDBType, const std::string > CDBTypeMap
Storage name in CCDB for each calibration and parameter type.
Definition CDBTypes.h:96
@ CalCorrMapMC
Cluster correction map (high IR rate distortions) for MC.
@ CalCorrMapRef
Cluster correction reference map (static distortions)
@ CalCorrMap
Cluster correction map (high IR rate distortions)
float getLumiAlt() const
Definition LumiInfo.h:34
uint32_t nHBFCounted
Definition LumiInfo.h:26
uint32_t nHBFCountedFV0
Definition LumiInfo.h:27
float getLumi() const
Definition LumiInfo.h:32
int lumiType
what estimator to used for corrections scaling: 0: no scaling, 1: CTP, 2: IDC
int lumiMode
what corrections method to use: 0: classical scaling, 1: Using of the derivative map,...
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"