81#include <TStopwatch.h>
86#include <TGraphAsymmErrors.h>
97void GPURecoWorkflowSpec::initFunctionTPCCalib(
InitContext& ic)
101 mTPCDeadChannelMapCreator->init();
102 mTPCDeadChannelMapCreator->setSource(deadMapSource);
108 mConfig->configCalib.fastTransform = mCalibObjects.mFastTransformBuffer.get();
110 if (mConfParam->dEdxDisableTopologyPol) {
111 LOGP(info,
"Disabling loading of track topology correction using polynomials from CCDB");
115 if (mConfParam->dEdxDisableThresholdMap) {
116 LOGP(info,
"Disabling loading of threshold map from CCDB");
120 if (mConfParam->dEdxDisableGainMap) {
121 LOGP(info,
"Disabling loading of gain map from CCDB");
125 if (mConfParam->dEdxDisableResidualGainMap) {
126 LOGP(info,
"Disabling loading of residual gain map from CCDB");
130 if (mConfParam->dEdxDisableResidualGain) {
131 LOGP(info,
"Disabling loading of residual gain calibration from CCDB");
135 if (mConfParam->dEdxUseFullGainMap) {
136 LOGP(info,
"Using the full gain map for correcting the cluster charge during calculation of the dE/dx");
137 mCalibObjects.mdEdxCalibContainer->setUsageOfFullGainMap(
true);
140 if (mConfParam->gainCalibDisableCCDB) {
141 LOGP(info,
"Disabling loading the TPC pad gain calibration from the CCDB");
142 mUpdateGainMapCCDB =
false;
146 if (!mConfParam->dEdxPolTopologyCorrFile.empty() || !mConfParam->dEdxCorrFile.empty() || !mConfParam->dEdxSplineTopologyCorrFile.empty()) {
147 if (!mConfParam->dEdxPolTopologyCorrFile.empty()) {
148 LOGP(info,
"Loading dE/dx polynomial track topology correction from file: {}", mConfParam->dEdxPolTopologyCorrFile);
149 mCalibObjects.mdEdxCalibContainer->loadPolTopologyCorrectionFromFile(mConfParam->dEdxPolTopologyCorrFile);
151 LOGP(info,
"Disabling loading of track topology correction using polynomials from CCDB as it was already loaded from input file");
154 if (std::filesystem::exists(mConfParam->thresholdCalibFile)) {
155 LOG(info) <<
"Loading tpc zero supression map from file " << mConfParam->thresholdCalibFile;
157 mCalibObjects.mdEdxCalibContainer->setZeroSupresssionThreshold(*thresholdMap);
159 LOGP(info,
"Disabling loading of threshold map from CCDB as it was already loaded from input file");
162 if (not mConfParam->thresholdCalibFile.empty()) {
163 LOG(warn) <<
"Couldn't find tpc zero supression file " << mConfParam->thresholdCalibFile <<
". Not setting any zero supression.";
165 LOG(info) <<
"Setting default zero supression map";
166 mCalibObjects.mdEdxCalibContainer->setDefaultZeroSupresssionThreshold();
168 }
else if (!mConfParam->dEdxSplineTopologyCorrFile.empty()) {
169 LOGP(info,
"Loading dE/dx spline track topology correction from file: {}", mConfParam->dEdxSplineTopologyCorrFile);
170 mCalibObjects.mdEdxCalibContainer->loadSplineTopologyCorrectionFromFile(mConfParam->dEdxSplineTopologyCorrFile);
172 LOGP(info,
"Disabling loading of track topology correction using polynomials from CCDB as splines were loaded from input file");
175 if (!mConfParam->dEdxCorrFile.empty()) {
176 LOGP(info,
"Loading dEdx correction from file: {}", mConfParam->dEdxCorrFile);
177 mCalibObjects.mdEdxCalibContainer->loadResidualCorrectionFromFile(mConfParam->dEdxCorrFile);
179 LOGP(info,
"Disabling loading of residual gain calibration from CCDB as it was already loaded from input file");
184 if (mConfParam->dEdxPolTopologyCorrFile.empty() && mConfParam->dEdxSplineTopologyCorrFile.empty()) {
186 LOG(info) <<
"Setting default dE/dx polynomial track topology correction to allocate enough memory";
187 mCalibObjects.mdEdxCalibContainer->setDefaultPolTopologyCorrection();
191 mConfig->configCalib.dEdxCalibContainer = mCalibObjects.mdEdxCalibContainer.get();
193 if (std::filesystem::exists(mConfParam->gainCalibFile)) {
194 LOG(info) <<
"Loading tpc gain correction from file " << mConfParam->gainCalibFile;
198 LOGP(info,
"Disabling loading the TPC gain correction map from the CCDB as it was already loaded from input file");
199 mUpdateGainMapCCDB =
false;
201 if (not mConfParam->gainCalibFile.empty()) {
202 LOG(warn) <<
"Couldn't find tpc gain correction file " << mConfParam->gainCalibFile <<
". Not applying any gain correction.";
205 mCalibObjects.mTPCPadGainCalib->getGainCorrection(30, 5, 5);
207 mConfig->configCalib.tpcPadGain = mCalibObjects.mTPCPadGainCalib.get();
210 mConfig->configCalib.tpcZSLinkMapping = mTPCZSLinkMapping.get();
217 auto copyCalibsToBuffer = [
this, dEdxCalibContainer]() {
218 if (!(mdEdxCalibContainerBufferNew)) {
219 mdEdxCalibContainerBufferNew = std::make_unique<o2::tpc::CalibdEdxContainer>();
220 mdEdxCalibContainerBufferNew->cloneFromObject(*dEdxCalibContainer,
nullptr);
225 LOGP(info,
"Updating gain map from CCDB");
229 copyCalibsToBuffer();
230 const float minGain = 0;
231 const float maxGain = 2;
232 mdEdxCalibContainerBufferNew.get()->setGainMap(*gainMap, minGain, maxGain);
235 if (mUpdateGainMapCCDB && mSpecConfig.
caClusterer) {
240 LOGP(info,
"Updating residual gain map from CCDB");
241 copyCalibsToBuffer();
242 const auto* gainMapResidual =
static_cast<std::unordered_map<std::string, o2::tpc::CalDet<float>
>*>(obj);
243 const float minResidualGain = 0.7f;
244 const float maxResidualGain = 1.3f;
245 mdEdxCalibContainerBufferNew.get()->setGainMapResidual(gainMapResidual->at(
"GainMap"), minResidualGain, maxResidualGain);
247 LOGP(info,
"Updating threshold map from CCDB");
248 copyCalibsToBuffer();
249 const auto* thresholdMap =
static_cast<std::unordered_map<std::string, o2::tpc::CalDet<float>
>*>(obj);
250 mdEdxCalibContainerBufferNew.get()->setZeroSupresssionThreshold(thresholdMap->at(
"ThresholdMap"));
252 LOGP(info,
"Updating Q topology correction from CCDB");
253 copyCalibsToBuffer();
257 mdEdxCalibContainerBufferNew->setPolTopologyCorrection(calibTrackTopology);
259 LOGP(info,
"Updating residual gain correction from CCDB");
260 copyCalibsToBuffer();
262 mdEdxCalibContainerBufferNew->setResidualCorrection(*residualCorr);
264 copyCalibsToBuffer();
266 mTPCDeadChannelMapCreator->setDeadChannelMapIDCPadStatus(*padFlags);
267 mTPCDeadChannelMapCreator->finalizeDeadChannelMap();
268 mdEdxCalibContainerBufferNew.get()->setDeadChannelMap(mTPCDeadChannelMapCreator->getDeadChannelMap());
269 LOGP(info,
"Updating dead channel map with IDC pad flags: {} / {} dead pads from pad flags / total",
270 mTPCDeadChannelMapCreator->getDeadChannelMapIDC().getSum<int32_t>(), mTPCDeadChannelMapCreator->getDeadChannelMap().getSum<int32_t>());
272 copyCalibsToBuffer();
274 mTPCDeadChannelMapCreator->setDeadChannelMapFEEConfig(*fee);
275 mTPCDeadChannelMapCreator->finalizeDeadChannelMap();
276 mdEdxCalibContainerBufferNew.get()->setDeadChannelMap(mTPCDeadChannelMapCreator->getDeadChannelMap());
278 "Updating dead channel map with the FEE info (tag {}) loaded via TPCRUNINFO"
279 " for creation time {}: {} / {} dead pads from FEE info / total, with",
280 std::underlying_type_t<o2::tpc::FEEConfig::Tags>(fee->tag), mCreationForCalib,
281 mTPCDeadChannelMapCreator->getDeadChannelMapFEE().getSum<int32_t>(), mTPCDeadChannelMapCreator->getDeadChannelMap().getSum<int32_t>());
282 }
else if (mTPCVDriftHelper->accountCCDBInputs(matcher, obj)) {
285 LOG(info) <<
"(NN CLUS) " << (mConfig->configCalib.nnClusterizerNetworks[0])->getONNXModelSize() <<
" bytes loaded for NN clusterizer: classification_c1";
288 LOG(info) <<
"(NN CLUS) " << (mConfig->configCalib.nnClusterizerNetworks[0])->getONNXModelSize() <<
" bytes loaded for NN clusterizer: classification_c2";
291 LOG(info) <<
"(NN CLUS) " << (mConfig->configCalib.nnClusterizerNetworks[1])->getONNXModelSize() <<
" bytes loaded for NN clusterizer: regression_c1";
294 LOG(info) <<
"(NN CLUS) " << (mConfig->configCalib.nnClusterizerNetworks[2])->getONNXModelSize() <<
" bytes loaded for NN clusterizer: regression_c2";
303 bool mustUpdate =
false;
320 pc.
inputs().
get<std::unordered_map<std::string, o2::tpc::CalDet<float>>*>(
"tpcthreshold");
332 pc.
inputs().
get<std::unordered_map<std::string, o2::tpc::CalDet<float>>*>(
"tpcgainresidual");
344 mTPCVDriftHelper->extractCCDBInputs(pc);
346 mCalibObjects.mInstLumiCTP = lumiCTP;
349 oldCalibObjects.mFastTransformBuffer = std::move(mCalibObjects.mFastTransformBuffer);
350 auto const&
raw = pc.
inputs().
get<
const char*>(
"corrMap");
351 const auto* newMap = &gpu::TPCFastTransformPOD::get(raw);
353 std::memcpy(
buffer.get(), newMap, newMap->size());
354 mCalibObjects.mFastTransformBuffer = std::move(
buffer);
355 newCalibObjects.
fastTransform = mCalibObjects.mFastTransformBuffer.get();
358 if (mTPCVDriftHelper->isUpdated()) {
360 LOGP(info,
"VDrift updated (factor {} wrt reference {} from source {}) but map already up to date", mTPCVDriftHelper->getVDriftObject().corrFact, mTPCVDriftHelper->getVDriftObject().refVDrift, mTPCVDriftHelper->getSourceName());
361 mTPCVDriftHelper->acknowledgeUpdate();
365 if (mdEdxCalibContainerBufferNew) {
366 oldCalibObjects.mdEdxCalibContainer = std::move(mCalibObjects.mdEdxCalibContainer);
367 mCalibObjects.mdEdxCalibContainer = std::move(mdEdxCalibContainerBufferNew);
372 if (mTPCPadGainCalibBufferNew) {
373 oldCalibObjects.mTPCPadGainCalib = std::move(mCalibObjects.mTPCPadGainCalib);
374 mCalibObjects.mTPCPadGainCalib = std::move(mTPCPadGainCalibBufferNew);
375 newCalibObjects.
tpcPadGain = mCalibObjects.mTPCPadGainCalib.get();
384 }
else if (mSpecConfig.
nnEvalMode[0] ==
"c2") {
402 (trackTune.useTPCInnerCorr || trackTune.useTPCOuterCorr ||
405 throw std::runtime_error(
"Buffer does not match span");
408 float scale = mCalibObjects.mInstLumiCTP;
410 LOGP(warning,
"Negative scale factor for TPC covariance correction, setting it to zero");
413 auto diagInner = trackTune.getCovInnerTotal(scale);
414 auto diagOuter = trackTune.getCovOuterTotal(scale);
417 auto& trc = tpcTracks[itr];
418 if (trackTune.useTPCInnerCorr) {
419 trc.updateParams(trackTune.tpcParInner);
424 if (trackTune.useTPCOuterCorr) {
425 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.
Utilities for parsing of data sequences.
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"