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
15#include "Framework/Logger.h"
23
24using namespace o2::tpc;
25using namespace o2::framework;
26
27//________________________________________________________
29{
30 pc.inputs().get<o2::tpc::CorrMapParam*>("tpcCorrPar");
31 const auto lumiMode = getLumiScaleMode();
32 if (lumiMode != LumiScaleMode::NoCorrection && lumiMode != LumiScaleMode::StaticMapOnly) {
33 pc.inputs().get<o2::gpu::TPCFastTransform*>("tpcCorrMap");
34 }
35 if (lumiMode != LumiScaleMode::NoCorrection) {
36 pc.inputs().get<o2::gpu::TPCFastTransform*>("tpcCorrMapRef");
37 }
38 const int maxDumRep = 5;
39 int dumRep = 0;
40 o2::ctp::LumiInfo lumiObj;
41 static o2::ctp::LumiInfo lumiPrev;
42
44 // check if tpcScaler is valid and CTP fallback is allowed
45 if (tpcScaler == -1.f) {
46 const bool canUseCTPScaling = mCorrMap && mCorrMapRef && mCorrMap->isIDCSet() && mCorrMapRef->isIDCSet() && mCorrMap->isLumiSet() && mCorrMapRef->isLumiSet();
47 if (canUseCTPScaling) {
48 LOGP(info, "Invalid TPC scaler value {} received for IDC-based scaling! Using CTP fallback", tpcScaler);
50 setMeanLumi(mCorrMap->getLumi(), false);
51 setMeanLumiRef(mCorrMapRef->getLumi());
53 } else if (mCorrMap) {
54 // CTP scaling is not possible, dont do any scaling to avoid applying wrong corrections
55 const float storedIDC = mCorrMap->getIDC();
56 LOGP(warning, "Invalid TPC scaler value {} received for IDC-based scaling! CTP fallback not possible, using stored IDC of {} from the map to avoid applying wrong corrections", tpcScaler, storedIDC);
57 setInstLumi(storedIDC);
58 }
59 } else {
61 // reset back to normal operation
62 LOGP(info, "Valid TPC scaler value {} received, switching back to IDC-based scaling", tpcScaler);
64 setMeanLumi(mCorrMap->getIDC(), false);
65 setMeanLumiRef(mCorrMapRef->getIDC());
67 }
68 // correct IDC received
69 setInstLumi(tpcScaler);
70 }
71 }
72
74 if (pc.inputs().get<gsl::span<char>>("CTPLumi").size() == sizeof(o2::ctp::LumiInfo)) {
75 lumiPrev = lumiObj = pc.inputs().get<o2::ctp::LumiInfo>("CTPLumi");
76 } else {
77 if (dumRep < maxDumRep && lumiPrev.nHBFCounted == 0 && lumiPrev.nHBFCountedFV0 == 0) {
78 LOGP(alarm, "Previous TF lumi used to substitute dummy input is empty, warning {} of {}", ++dumRep, maxDumRep);
79 }
80 lumiObj = lumiPrev;
81 }
82 setInstLumiCTP(mInstLumiCTPFactor * (mLumiCTPSource == 0 ? lumiObj.getLumi() : lumiObj.getLumiAlt()));
85 }
86 }
87
89}
90
91//________________________________________________________
92void CorrectionMapsLoader::requestCCDBInputs(std::vector<InputSpec>& inputs, const CorrectionMapsGloOpts& gloOpts)
93{
94 LOGP(info, "Requesting CCDB inputs for TPC correction maps with lumiType={} and lumiMode={}", static_cast<int>(gloOpts.lumiType), static_cast<int>(gloOpts.lumiMode));
95 if (gloOpts.lumiMode == LumiScaleMode::Linear) {
96 addInput(inputs, {"tpcCorrMap", "TPC", "CorrMap", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMap), {}, 1)}); // time-dependent
97 addInput(inputs, {"tpcCorrMapRef", "TPC", "CorrMapRef", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMapRef), {}, 0)}); // load once
98 } else if (gloOpts.lumiMode == LumiScaleMode::DerivativeMap) {
99 addInput(inputs, {"tpcCorrMap", "TPC", "CorrMap", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMap), {}, 1)}); // time-dependent
100 addInput(inputs, {"tpcCorrMapRef", "TPC", "CorrMapRef", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrDerivMap), {}, 1)}); // time-dependent
101 } else if (gloOpts.lumiMode == LumiScaleMode::DerivativeMapMC) {
102 // for MC corrections
103 addInput(inputs, {"tpcCorrMap", "TPC", "CorrMap", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMapMC), {}, 1)}); // time-dependent
104 addInput(inputs, {"tpcCorrMapRef", "TPC", "CorrMapRef", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrDerivMapMC), {}, 1)}); // time-dependent
105 } else if (gloOpts.lumiMode == LumiScaleMode::NoCorrection) {
106 // no correction maps needed — a dummy map is created at runtime
107 } else if (gloOpts.lumiMode == LumiScaleMode::StaticMapOnly) {
108 addInput(inputs, {"tpcCorrMapRef", "TPC", "CorrMapRef", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMapRef), {}, 0)}); // load once
109 } else {
110 LOG(fatal) << "Correction mode unknown! Choose either 0 (default) or 1 (derivative map) for flag corrmap-lumi-mode.";
111 }
112
113 if (gloOpts.requestCTPLumi) {
114 addInput(inputs, {"CTPLumi", "CTP", "LUMI", 0, Lifetime::Timeframe});
115 }
116
117 addInput(inputs, {"tpcCorrPar", "TPC", "CorrMapParam", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CorrMapParam), {}, 0)}); // load once
118}
119
120//________________________________________________________
121void CorrectionMapsLoader::addInput(std::vector<InputSpec>& inputs, InputSpec&& isp)
122{
123 if (std::find(inputs.begin(), inputs.end(), isp) == inputs.end()) {
124 inputs.emplace_back(isp);
125 }
126}
127
128//________________________________________________________
129void CorrectionMapsLoader::addOption(std::vector<ConfigParamSpec>& options, ConfigParamSpec&& osp)
130{
131 if (std::find(options.begin(), options.end(), osp) == options.end()) {
132 options.emplace_back(osp);
133 }
134}
135
136//________________________________________________________
138{
139 if (matcher == ConcreteDataMatcher("TPC", "CorrMap", 0)) {
143 if (getMeanLumiOverride() != 0) {
146 LOGP(info, "CorrMap mean lumi rate is overridden to {}", mCorrMap->getLumi());
149 LOGP(info, "CorrMap mean IDC rate is overridden to {}", mCorrMap->getIDC());
150 }
151 }
152 float mapMeanRate = 0;
154 mapMeanRate = mCorrMap->getLumi();
156 mapMeanRate = mCorrMap->getIDC();
157 }
159 checkMeanScaleConsistency(mapMeanRate, mCorrMap->getCTP2IDCFallBackThreshold());
160 }
161 if (getMeanLumiOverride() == 0 && mapMeanRate > 0.) {
162 setMeanLumi(mapMeanRate, false);
163 }
164 LOGP(debug, "MeanLumiOverride={} MeanLumiMap={} -> meanLumi = {}", getMeanLumiOverride(), mapMeanRate, getMeanLumi());
166 return true;
167 }
168 if (matcher == ConcreteDataMatcher("TPC", "CorrMapRef", 0)) {
172 if (getMeanLumiRefOverride() != 0) {
175 LOGP(info, "CorrMapRef mean lumi rate is overridden to {}", mCorrMapRef->getLumi());
178 LOGP(info, "CorrMapRef mean IDC rate is overridden to {}", mCorrMapRef->getIDC());
179 }
180 }
181 float mapRefMeanRate = 0;
183 mapRefMeanRate = mCorrMapRef->getLumi();
185 mapRefMeanRate = mCorrMapRef->getIDC();
186 }
188 checkMeanScaleConsistency(mapRefMeanRate, mCorrMapRef->getCTP2IDCFallBackThreshold());
189 }
190 if (getMeanLumiRefOverride() == 0) {
191 setMeanLumiRef(mapRefMeanRate);
192 }
193 LOGP(debug, "MeanLumiRefOverride={} MeanLumiMap={} -> meanLumi = {}", getMeanLumiRefOverride(), mapRefMeanRate, getMeanLumiRef());
195 return true;
196 }
197 if (matcher == ConcreteDataMatcher("TPC", "CorrMapParam", 0)) {
198 const auto& par = o2::tpc::CorrMapParam::Instance();
199 mMeanLumiOverride = par.lumiMean; // negative value switches off corrections !!!
200 mMeanLumiRefOverride = par.lumiMeanRef;
201 mInstCTPLumiOverride = par.lumiInst;
202 mInstLumiCTPFactor = par.lumiInstFactor;
203 mLumiCTPSource = par.ctpLumiSource;
204
205 if (mMeanLumiOverride != 0.) {
207 }
208 if (mMeanLumiRefOverride != 0.) {
210 }
211 if (mInstCTPLumiOverride != 0.) {
214 setInstLumi(getInstLumiCTP(), false);
215 }
216 }
218 int scaleType = static_cast<int>(getLumiScaleType());
219 const std::array<std::string, 3> lumiS{"OFF", "CTP", "TPC scaler"};
220 if (scaleType >= lumiS.size()) {
221 LOGP(fatal, "Wrong corrmap-lumi-mode provided!");
222 }
223
224 LOGP(info, "TPC correction map params updated: SP corrections: {} (corr.map scaling type={}, override values: lumiMean={} lumiRefMean={} lumiScaleMode={}), CTP Lumi: source={} lumiInstOverride={} , LumiInst scale={} ",
225 canUseCorrections() ? "ON" : "OFF",
227 }
228 return false;
229}
230
231//________________________________________________________
233{
235 LOGP(fatal, "TPC correction lumi scaling mode is not set");
236 }
237 const auto& inputRouts = ic.services().get<const o2::framework::DeviceSpec>().inputs;
238 bool foundCTP = false;
239 for (const auto& route : inputRouts) {
240 if (route.matcher == InputSpec{"CTPLumi", "CTP", "LUMI", 0, Lifetime::Timeframe}) {
241 foundCTP = true;
242 }
243 }
244 setLumiCTPAvailable(foundCTP);
245 if ((getLumiScaleType() == LumiScaleType::CTPLumi && !foundCTP) || (getLumiScaleType() == LumiScaleType::TPCScaler && !idcsAvailable)) {
246 LOGP(fatal, "Lumi scaling source {}({}) is not available for TPC correction", static_cast<int>(getLumiScaleType()), getLumiScaleType() == LumiScaleType::CTPLumi ? "CTP" : "TPCScaler");
247 }
248}
249
250void CorrectionMapsLoader::checkMeanScaleConsistency(float meanLumi, float threshold) const
251{
253 if (meanLumi < threshold) {
254 LOGP(fatal, "CTP Lumi scaling source is requested, but the map mean scale {} is below the threshold {}", meanLumi, threshold);
255 }
257 if (meanLumi > threshold) {
258 LOGP(fatal, "IDC scaling source is requested, but the map mean scale {} is above the threshold {}", meanLumi, threshold);
259 }
260 }
261}
CDB Type definitions for TPC.
Implementation of the parameter class for the CorrectionMapsLoader options.
Helper class to access load maps from CCDB.
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.
o2::gpu::TPCFastTransform * mCorrMap
void setMeanLumiRef(float v, bool report=false)
void setLumiScaleType(tpc::LumiScaleType v)
tpc::LumiScaleType getLumiScaleType() const
void setInstLumi(float v, bool report=false)
void setCorrMapRef(o2::gpu::TPCFastTransform *m)
void setMeanLumi(float v, bool report=false)
o2::gpu::TPCFastTransform * mCorrMapRef
void setCorrMap(o2::gpu::TPCFastTransform *m)
tpc::LumiScaleMode getLumiScaleMode() const
void setLumi(float l)
Set Lumi info.
void setCTP2IDCFallBackThreshold(float v)
bool accountCCDBInputs(const o2::framework::ConcreteDataMatcher &matcher, void *obj)
void extractCCDBInputs(o2::framework::ProcessingContext &pc, float tpcScaler=-1.f)
void init(o2::framework::InitContext &ic, bool idcsAvailable)
static void addOption(std::vector< o2::framework::ConfigParamSpec > &options, o2::framework::ConfigParamSpec &&osp)
static void requestCCDBInputs(std::vector< o2::framework::InputSpec > &inputs, const o2::tpc::CorrectionMapsGloOpts &gloOpts)
void checkMeanScaleConsistency(float meanLumi, float threshold) const
static void addInput(std::vector< o2::framework::InputSpec > &inputs, o2::framework::InputSpec &&isp)
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
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:168
@ DerivativeMap
map(lumi) = mean_map + lumiScale * (derivativeMap) where derivativeMap = (mean_map_A - mean_map_B)
@ Linear
map(lumi) = (mean_map - referenceMap) * lumiScale + referenceMap
@ NoCorrection
no corrections at all
@ StaticMapOnly
use only static map instead of main map
@ DerivativeMapMC
same DerivativeMap, but for MC
const std::unordered_map< CDBType, const std::string > CDBTypeMap
Storage name in CCDB for each calibration and parameter type.
Definition CDBTypes.h:96
@ TPCScaler
use TPC scaler for scaling
@ CTPLumi
use CTP luminosity for scaling
@ 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
LumiScaleType lumiType
what estimator to used for corrections scaling: 0: no scaling, 1: CTP, 2: IDC
bool requestCTPLumi
request CTP Lumi regardless of what is used for corrections scaling
LumiScaleMode lumiMode
what corrections method to use: 0: classical scaling, 1: Using of the derivative map,...
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"