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 pc.inputs().get<o2::gpu::TPCFastTransform*>("tpcCorrMap");
32 pc.inputs().get<o2::gpu::TPCFastTransform*>("tpcCorrMapRef");
33 const int maxDumRep = 5;
34 int dumRep = 0;
35 o2::ctp::LumiInfo lumiObj;
36 static o2::ctp::LumiInfo lumiPrev;
37
39 // check if tpcScaler is valid and CTP fallback is allowed
40 if (tpcScaler == -1.f) {
41 const bool canUseCTPScaling = mCorrMap && mCorrMapRef && mCorrMap->isIDCSet() && mCorrMapRef->isIDCSet() && mCorrMap->isLumiSet() && mCorrMapRef->isLumiSet();
42 if (canUseCTPScaling) {
43 LOGP(info, "Invalid TPC scaler value {} received for IDC-based scaling! Using CTP fallback", tpcScaler);
45 setMeanLumi(mCorrMap->getLumi(), false);
46 setMeanLumiRef(mCorrMapRef->getLumi());
48 } else if (mCorrMap) {
49 // CTP scaling is not possible, dont do any scaling to avoid applying wrong corrections
50 const float storedIDC = mCorrMap->getIDC();
51 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);
52 setInstLumi(storedIDC);
53 }
54 } else {
56 // reset back to normal operation
57 LOGP(info, "Valid TPC scaler value {} received, switching back to IDC-based scaling", tpcScaler);
59 setMeanLumi(mCorrMap->getIDC(), false);
60 setMeanLumiRef(mCorrMapRef->getIDC());
62 }
63 // correct IDC received
64 setInstLumi(tpcScaler);
65 }
66 }
67
69 if (pc.inputs().get<gsl::span<char>>("CTPLumi").size() == sizeof(o2::ctp::LumiInfo)) {
70 lumiPrev = lumiObj = pc.inputs().get<o2::ctp::LumiInfo>("CTPLumi");
71 } else {
72 if (dumRep < maxDumRep && lumiPrev.nHBFCounted == 0 && lumiPrev.nHBFCountedFV0 == 0) {
73 LOGP(alarm, "Previous TF lumi used to substitute dummy input is empty, warning {} of {}", ++dumRep, maxDumRep);
74 }
75 lumiObj = lumiPrev;
76 }
77 setInstLumiCTP(mInstLumiCTPFactor * (mLumiCTPSource == 0 ? lumiObj.getLumi() : lumiObj.getLumiAlt()));
80 }
81 }
82
84}
85
86//________________________________________________________
87void CorrectionMapsLoader::requestCCDBInputs(std::vector<InputSpec>& inputs, const CorrectionMapsGloOpts& gloOpts)
88{
89 LOGP(info, "Requesting CCDB inputs for TPC correction maps with lumiType={} and lumiMode={}", static_cast<int>(gloOpts.lumiType), static_cast<int>(gloOpts.lumiMode));
90 if (gloOpts.lumiMode == LumiScaleMode::Linear) {
91 addInput(inputs, {"tpcCorrMap", "TPC", "CorrMap", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMap), {}, 1)}); // time-dependent
92 addInput(inputs, {"tpcCorrMapRef", "TPC", "CorrMapRef", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMapRef), {}, 0)}); // load once
93 } else if (gloOpts.lumiMode == LumiScaleMode::DerivativeMap) {
94 addInput(inputs, {"tpcCorrMap", "TPC", "CorrMap", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMap), {}, 1)}); // time-dependent
95 addInput(inputs, {"tpcCorrMapRef", "TPC", "CorrMapRef", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrDerivMap), {}, 1)}); // time-dependent
96 } else if (gloOpts.lumiMode == LumiScaleMode::DerivativeMapMC) {
97 // for MC corrections
98 addInput(inputs, {"tpcCorrMap", "TPC", "CorrMap", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMapMC), {}, 1)}); // time-dependent
99 addInput(inputs, {"tpcCorrMapRef", "TPC", "CorrMapRef", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrDerivMapMC), {}, 1)}); // time-dependent
100 } else {
101 LOG(fatal) << "Correction mode unknown! Choose either 0 (default) or 1 (derivative map) for flag corrmap-lumi-mode.";
102 }
103
104 if (gloOpts.requestCTPLumi) {
105 addInput(inputs, {"CTPLumi", "CTP", "LUMI", 0, Lifetime::Timeframe});
106 }
107
108 addInput(inputs, {"tpcCorrPar", "TPC", "CorrMapParam", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CorrMapParam), {}, 0)}); // load once
109}
110
111//________________________________________________________
112void CorrectionMapsLoader::addInput(std::vector<InputSpec>& inputs, InputSpec&& isp)
113{
114 if (std::find(inputs.begin(), inputs.end(), isp) == inputs.end()) {
115 inputs.emplace_back(isp);
116 }
117}
118
119//________________________________________________________
120void CorrectionMapsLoader::addOption(std::vector<ConfigParamSpec>& options, ConfigParamSpec&& osp)
121{
122 if (std::find(options.begin(), options.end(), osp) == options.end()) {
123 options.emplace_back(osp);
124 }
125}
126
127//________________________________________________________
129{
130 if (matcher == ConcreteDataMatcher("TPC", "CorrMap", 0)) {
134 if (getMeanLumiOverride() != 0) {
137 LOGP(info, "CorrMap mean lumi rate is overridden to {}", mCorrMap->getLumi());
140 LOGP(info, "CorrMap mean IDC rate is overridden to {}", mCorrMap->getIDC());
141 }
142 }
143 float mapMeanRate = 0;
145 mapMeanRate = mCorrMap->getLumi();
147 mapMeanRate = mCorrMap->getIDC();
148 }
150 checkMeanScaleConsistency(mapMeanRate, mCorrMap->getCTP2IDCFallBackThreshold());
151 }
152 if (getMeanLumiOverride() == 0 && mapMeanRate > 0.) {
153 setMeanLumi(mapMeanRate, false);
154 }
155 LOGP(debug, "MeanLumiOverride={} MeanLumiMap={} -> meanLumi = {}", getMeanLumiOverride(), mapMeanRate, getMeanLumi());
157 return true;
158 }
159 if (matcher == ConcreteDataMatcher("TPC", "CorrMapRef", 0)) {
163 if (getMeanLumiRefOverride() != 0) {
166 LOGP(info, "CorrMapRef mean lumi rate is overridden to {}", mCorrMapRef->getLumi());
169 LOGP(info, "CorrMapRef mean IDC rate is overridden to {}", mCorrMapRef->getIDC());
170 }
171 }
172 float mapRefMeanRate = 0;
174 mapRefMeanRate = mCorrMapRef->getLumi();
176 mapRefMeanRate = mCorrMapRef->getIDC();
177 }
179 checkMeanScaleConsistency(mapRefMeanRate, mCorrMapRef->getCTP2IDCFallBackThreshold());
180 }
181 if (getMeanLumiRefOverride() == 0) {
182 setMeanLumiRef(mapRefMeanRate);
183 }
184 LOGP(debug, "MeanLumiRefOverride={} MeanLumiMap={} -> meanLumi = {}", getMeanLumiRefOverride(), mapRefMeanRate, getMeanLumiRef());
186 return true;
187 }
188 if (matcher == ConcreteDataMatcher("TPC", "CorrMapParam", 0)) {
189 const auto& par = o2::tpc::CorrMapParam::Instance();
190 mMeanLumiOverride = par.lumiMean; // negative value switches off corrections !!!
191 mMeanLumiRefOverride = par.lumiMeanRef;
192 mInstCTPLumiOverride = par.lumiInst;
193 mInstLumiCTPFactor = par.lumiInstFactor;
194 mLumiCTPSource = par.ctpLumiSource;
195
196 if (mMeanLumiOverride != 0.) {
198 }
199 if (mMeanLumiRefOverride != 0.) {
201 }
202 if (mInstCTPLumiOverride != 0.) {
205 setInstLumi(getInstLumiCTP(), false);
206 }
207 }
209 int scaleType = static_cast<int>(getLumiScaleType());
210 const std::array<std::string, 3> lumiS{"OFF", "CTP", "TPC scaler"};
211 if (scaleType >= lumiS.size()) {
212 LOGP(fatal, "Wrong corrmap-lumi-mode provided!");
213 }
214
215 LOGP(info, "TPC correction map params updated: SP corrections: {} (corr.map scaling type={}, override values: lumiMean={} lumiRefMean={} lumiScaleMode={}), CTP Lumi: source={} lumiInstOverride={} , LumiInst scale={} ",
216 canUseCorrections() ? "ON" : "OFF",
218 }
219 return false;
220}
221
222//________________________________________________________
224{
226 LOGP(fatal, "TPC correction lumi scaling mode is not set");
227 }
228 const auto& inputRouts = ic.services().get<const o2::framework::DeviceSpec>().inputs;
229 bool foundCTP = false;
230 for (const auto& route : inputRouts) {
231 if (route.matcher == InputSpec{"CTPLumi", "CTP", "LUMI", 0, Lifetime::Timeframe}) {
232 foundCTP = true;
233 }
234 }
235 setLumiCTPAvailable(foundCTP);
236 if ((getLumiScaleType() == LumiScaleType::CTPLumi && !foundCTP) || (getLumiScaleType() == LumiScaleType::TPCScaler && !idcsAvailable)) {
237 LOGP(fatal, "Lumi scaling source {}({}) is not available for TPC correction", static_cast<int>(getLumiScaleType()), getLumiScaleType() == LumiScaleType::CTPLumi ? "CTP" : "TPCScaler");
238 }
239}
240
241void CorrectionMapsLoader::checkMeanScaleConsistency(float meanLumi, float threshold) const
242{
244 if (meanLumi < threshold) {
245 LOGP(fatal, "CTP Lumi scaling source is requested, but the map mean scale {} is below the threshold {}", meanLumi, threshold);
246 }
248 if (meanLumi > threshold) {
249 LOGP(fatal, "IDC scaling source is requested, but the map mean scale {} is above the threshold {}", meanLumi, threshold);
250 }
251 }
252}
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
@ 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"