80#include <TStopwatch.h>
85#include <TGraphAsymmErrors.h>
96void GPURecoWorkflowSpec::initFunctionTPCCalib(
InitContext& ic)
100 mTPCDeadChannelMapCreator->init();
101 mTPCDeadChannelMapCreator->setSource(deadMapSource);
107 mConfig->configCalib.fastTransform = mCalibObjects.mFastTransformBuffer.get();
109 if (mConfParam->dEdxDisableTopologyPol) {
110 LOGP(info,
"Disabling loading of track topology correction using polynomials from CCDB");
114 if (mConfParam->dEdxDisableThresholdMap) {
115 LOGP(info,
"Disabling loading of threshold map from CCDB");
119 if (mConfParam->dEdxDisableGainMap) {
120 LOGP(info,
"Disabling loading of gain map from CCDB");
124 if (mConfParam->dEdxDisableResidualGainMap) {
125 LOGP(info,
"Disabling loading of residual gain map from CCDB");
129 if (mConfParam->dEdxDisableResidualGain) {
130 LOGP(info,
"Disabling loading of residual gain calibration from CCDB");
134 if (mConfParam->dEdxUseFullGainMap) {
135 LOGP(info,
"Using the full gain map for correcting the cluster charge during calculation of the dE/dx");
136 mCalibObjects.mdEdxCalibContainer->setUsageOfFullGainMap(
true);
139 if (mConfParam->gainCalibDisableCCDB) {
140 LOGP(info,
"Disabling loading the TPC pad gain calibration from the CCDB");
141 mUpdateGainMapCCDB =
false;
145 if (!mConfParam->dEdxPolTopologyCorrFile.empty() || !mConfParam->dEdxCorrFile.empty() || !mConfParam->dEdxSplineTopologyCorrFile.empty()) {
146 if (!mConfParam->dEdxPolTopologyCorrFile.empty()) {
147 LOGP(info,
"Loading dE/dx polynomial track topology correction from file: {}", mConfParam->dEdxPolTopologyCorrFile);
148 mCalibObjects.mdEdxCalibContainer->loadPolTopologyCorrectionFromFile(mConfParam->dEdxPolTopologyCorrFile);
150 LOGP(info,
"Disabling loading of track topology correction using polynomials from CCDB as it was already loaded from input file");
153 if (std::filesystem::exists(mConfParam->thresholdCalibFile)) {
154 LOG(info) <<
"Loading tpc zero supression map from file " << mConfParam->thresholdCalibFile;
156 mCalibObjects.mdEdxCalibContainer->setZeroSupresssionThreshold(*thresholdMap);
158 LOGP(info,
"Disabling loading of threshold map from CCDB as it was already loaded from input file");
161 if (not mConfParam->thresholdCalibFile.empty()) {
162 LOG(warn) <<
"Couldn't find tpc zero supression file " << mConfParam->thresholdCalibFile <<
". Not setting any zero supression.";
164 LOG(info) <<
"Setting default zero supression map";
165 mCalibObjects.mdEdxCalibContainer->setDefaultZeroSupresssionThreshold();
167 }
else if (!mConfParam->dEdxSplineTopologyCorrFile.empty()) {
168 LOGP(info,
"Loading dE/dx spline track topology correction from file: {}", mConfParam->dEdxSplineTopologyCorrFile);
169 mCalibObjects.mdEdxCalibContainer->loadSplineTopologyCorrectionFromFile(mConfParam->dEdxSplineTopologyCorrFile);
171 LOGP(info,
"Disabling loading of track topology correction using polynomials from CCDB as splines were loaded from input file");
174 if (!mConfParam->dEdxCorrFile.empty()) {
175 LOGP(info,
"Loading dEdx correction from file: {}", mConfParam->dEdxCorrFile);
176 mCalibObjects.mdEdxCalibContainer->loadResidualCorrectionFromFile(mConfParam->dEdxCorrFile);
178 LOGP(info,
"Disabling loading of residual gain calibration from CCDB as it was already loaded from input file");
183 if (mConfParam->dEdxPolTopologyCorrFile.empty() && mConfParam->dEdxSplineTopologyCorrFile.empty()) {
185 LOG(info) <<
"Setting default dE/dx polynomial track topology correction to allocate enough memory";
186 mCalibObjects.mdEdxCalibContainer->setDefaultPolTopologyCorrection();
190 mConfig->configCalib.dEdxCalibContainer = mCalibObjects.mdEdxCalibContainer.get();
192 if (std::filesystem::exists(mConfParam->gainCalibFile)) {
193 LOG(info) <<
"Loading tpc gain correction from file " << mConfParam->gainCalibFile;
197 LOGP(info,
"Disabling loading the TPC gain correction map from the CCDB as it was already loaded from input file");
198 mUpdateGainMapCCDB =
false;
200 if (not mConfParam->gainCalibFile.empty()) {
201 LOG(warn) <<
"Couldn't find tpc gain correction file " << mConfParam->gainCalibFile <<
". Not applying any gain correction.";
204 mCalibObjects.mTPCPadGainCalib->getGainCorrection(30, 5, 5);
206 mConfig->configCalib.tpcPadGain = mCalibObjects.mTPCPadGainCalib.get();
209 mConfig->configCalib.tpcZSLinkMapping = mTPCZSLinkMapping.get();
216 auto copyCalibsToBuffer = [
this, dEdxCalibContainer]() {
217 if (!(mdEdxCalibContainerBufferNew)) {
218 mdEdxCalibContainerBufferNew = std::make_unique<o2::tpc::CalibdEdxContainer>();
219 mdEdxCalibContainerBufferNew->cloneFromObject(*dEdxCalibContainer,
nullptr);
224 LOGP(info,
"Updating gain map from CCDB");
228 copyCalibsToBuffer();
229 const float minGain = 0;
230 const float maxGain = 2;
231 mdEdxCalibContainerBufferNew.get()->setGainMap(*gainMap, minGain, maxGain);
234 if (mUpdateGainMapCCDB && mSpecConfig.
caClusterer) {
239 LOGP(info,
"Updating residual gain map from CCDB");
240 copyCalibsToBuffer();
241 const auto* gainMapResidual =
static_cast<std::unordered_map<std::string, o2::tpc::CalDet<float>
>*>(obj);
242 const float minResidualGain = 0.7f;
243 const float maxResidualGain = 1.3f;
244 mdEdxCalibContainerBufferNew.get()->setGainMapResidual(gainMapResidual->at(
"GainMap"), minResidualGain, maxResidualGain);
246 LOGP(info,
"Updating threshold map from CCDB");
247 copyCalibsToBuffer();
248 const auto* thresholdMap =
static_cast<std::unordered_map<std::string, o2::tpc::CalDet<float>
>*>(obj);
249 mdEdxCalibContainerBufferNew.get()->setZeroSupresssionThreshold(thresholdMap->at(
"ThresholdMap"));
251 LOGP(info,
"Updating Q topology correction from CCDB");
252 copyCalibsToBuffer();
256 mdEdxCalibContainerBufferNew->setPolTopologyCorrection(calibTrackTopology);
258 LOGP(info,
"Updating residual gain correction from CCDB");
259 copyCalibsToBuffer();
261 mdEdxCalibContainerBufferNew->setResidualCorrection(*residualCorr);
263 copyCalibsToBuffer();
265 mTPCDeadChannelMapCreator->setDeadChannelMapIDCPadStatus(*padFlags);
266 mTPCDeadChannelMapCreator->finalizeDeadChannelMap();
267 mdEdxCalibContainerBufferNew.get()->setDeadChannelMap(mTPCDeadChannelMapCreator->getDeadChannelMap());
268 LOGP(info,
"Updating dead channel map with IDC pad flags: {} / {} dead pads from pad flags / total",
269 mTPCDeadChannelMapCreator->getDeadChannelMapIDC().getSum<int32_t>(), mTPCDeadChannelMapCreator->getDeadChannelMap().getSum<int32_t>());
271 copyCalibsToBuffer();
273 mTPCDeadChannelMapCreator->setDeadChannelMapFEEConfig(*fee);
274 mTPCDeadChannelMapCreator->finalizeDeadChannelMap();
275 mdEdxCalibContainerBufferNew.get()->setDeadChannelMap(mTPCDeadChannelMapCreator->getDeadChannelMap());
277 "Updating dead channel map with the FEE info (tag {}) loaded via TPCRUNINFO"
278 " for creation time {}: {} / {} dead pads from FEE info / total, with",
279 std::underlying_type_t<o2::tpc::FEEConfig::Tags>(fee->tag), mCreationForCalib,
280 mTPCDeadChannelMapCreator->getDeadChannelMapFEE().getSum<int32_t>(), mTPCDeadChannelMapCreator->getDeadChannelMap().getSum<int32_t>());
281 }
else if (mTPCVDriftHelper->accountCCDBInputs(matcher, obj)) {
284 LOG(info) <<
"(NN CLUS) " << (mConfig->configCalib.nnClusterizerNetworks[0])->getONNXModelSize() <<
" bytes loaded for NN clusterizer: classification_c1";
287 LOG(info) <<
"(NN CLUS) " << (mConfig->configCalib.nnClusterizerNetworks[0])->getONNXModelSize() <<
" bytes loaded for NN clusterizer: classification_c2";
290 LOG(info) <<
"(NN CLUS) " << (mConfig->configCalib.nnClusterizerNetworks[1])->getONNXModelSize() <<
" bytes loaded for NN clusterizer: regression_c1";
293 LOG(info) <<
"(NN CLUS) " << (mConfig->configCalib.nnClusterizerNetworks[2])->getONNXModelSize() <<
" bytes loaded for NN clusterizer: regression_c2";
302 bool mustUpdate =
false;
319 pc.
inputs().
get<std::unordered_map<std::string, o2::tpc::CalDet<float>>*>(
"tpcthreshold");
331 pc.
inputs().
get<std::unordered_map<std::string, o2::tpc::CalDet<float>>*>(
"tpcgainresidual");
343 mTPCVDriftHelper->extractCCDBInputs(pc);
345 mCalibObjects.mInstLumiCTP = lumiCTP;
348 oldCalibObjects.mFastTransformBuffer = std::move(mCalibObjects.mFastTransformBuffer);
349 auto const&
raw = pc.
inputs().
get<
const char*>(
"corrMap");
350 const auto* newMap = &gpu::TPCFastTransformPOD::get(raw);
352 std::memcpy(
buffer.get(), newMap, newMap->size());
353 mCalibObjects.mFastTransformBuffer = std::move(
buffer);
354 newCalibObjects.
fastTransform = mCalibObjects.mFastTransformBuffer.get();
357 if (mTPCVDriftHelper->isUpdated()) {
359 LOGP(info,
"VDrift updated (factor {} wrt reference {} from source {}) but map already up to date", mTPCVDriftHelper->getVDriftObject().corrFact, mTPCVDriftHelper->getVDriftObject().refVDrift, mTPCVDriftHelper->getSourceName());
360 mTPCVDriftHelper->acknowledgeUpdate();
364 if (mdEdxCalibContainerBufferNew) {
365 oldCalibObjects.mdEdxCalibContainer = std::move(mCalibObjects.mdEdxCalibContainer);
366 mCalibObjects.mdEdxCalibContainer = std::move(mdEdxCalibContainerBufferNew);
371 if (mTPCPadGainCalibBufferNew) {
372 oldCalibObjects.mTPCPadGainCalib = std::move(mCalibObjects.mTPCPadGainCalib);
373 mCalibObjects.mTPCPadGainCalib = std::move(mTPCPadGainCalibBufferNew);
374 newCalibObjects.
tpcPadGain = mCalibObjects.mTPCPadGainCalib.get();
383 }
else if (mSpecConfig.
nnEvalMode[0] ==
"c2") {
401 (trackTune.useTPCInnerCorr || trackTune.useTPCOuterCorr ||
404 throw std::runtime_error(
"Buffer does not match span");
407 float scale = mCalibObjects.mInstLumiCTP;
409 LOGP(warning,
"Negative scale factor for TPC covariance correction, setting it to zero");
412 auto diagInner = trackTune.getCovInnerTotal(scale);
413 auto diagOuter = trackTune.getCovOuterTotal(scale);
416 auto& trc = tpcTracks[itr];
417 if (trackTune.useTPCInnerCorr) {
418 trc.updateParams(trackTune.tpcParInner);
423 if (trackTune.useTPCOuterCorr) {
424 trc.getParamOut().updateParams(trackTune.tpcParOuter);
Definition of the timebin from which syncronization starts.
Simple interface to the CDB manager.
Definition of container class for dE/dx corrections.
Class of a TPC cluster in TPC-native coordinates (row, time)
Container to store compressed TPC cluster data.
A const (ready only) version of MCTruthContainer.
Definition of class for writing debug informations.
Definition of the GeometryManager class.
o2::raw::RawFileWriter * raw
Helper for geometry and GRP related CCDB requests.
This file provides the structs for storing the factorized IDC values and fourier coefficients to be s...
Declarations for the wrapper for the set of cylindrical material layers.
Definition of the Names Generator class.
Class to serialize ONNX objects for ROOT snapshots of CCDB objects at runtime.
Type wrappers for enfording a specific serialization method.
Wrapper class for TPC CA Tracker algorithm.
Configurable params for tracks ad hoc tuning.
Helper class to extract VDrift from different sources.
Helper class to obtain TPC clusters / digits / labels from DPL.
Definitions of TPC Zero Suppression Data Headers.
static const TrackTuneParams & Instance()
InputRecord & inputs()
The inputs associated with this processing context.
ServiceRegistryRef services()
The services registry associated with this processing context.
static std::unique_ptr< TPCPadGainCalib > getPadGainCalibDefault()
static std::unique_ptr< TPCPadGainCalib > getPadGainCalib(const o2::tpc::CalDet< float > &in)
bool isCorrectionCCDB(const CalibsdEdx calib) const
bool isTopologyCorrectionSplinesSet() const
returns status if the spline correction is set
calibration class for the track topology correction of the dE/dx using multvariate polynomials
void setFromContainer(const CalibdEdxTrackTopologyPolContainer &container)
static Mapper & instance(const std::string mappingDir="")
Defining ITS Vertex explicitly as messageable.
std::vector< CalPad * > readCalPads(const std::string_view fileName, const std::vector< std::string > &calPadNames)
@ CalTimeGain
flag for residual dE/dx time dependent gain correction
@ CalTopologyPol
flag for a topology correction using polynomials
@ CalResidualGainMap
flag for applying residual gain map
@ CalThresholdMap
flag for using threshold map
@ CalGainMap
flag for using the gain map to get the correct cluster charge
@ FEEConfig
use fee config
@ IDCPadStatus
use idc pad status map
S< o2::tpc::CalibdEdxContainer >::type * dEdxCalibContainer
S< TPCFastTransformPOD >::type * fastTransform
S< TPCPadGainCalib >::type * tpcPadGain
std::vector< std::string > nnEvalMode
int32_t tpcDeadMapSources
uint32_t nOutputTracksTPCO2
const o2::tpc::TrackTPC * outputTracksTPCO2
simple struct to enable writing the MultivariatePolynomialCT to file
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"