84#include <TStopwatch.h>
89#include <TGraphAsymmErrors.h>
100void GPURecoWorkflowSpec::initFunctionTPCCalib(
InitContext& ic)
104 mTPCDeadChannelMapCreator->init();
105 mTPCDeadChannelMapCreator->setSource(deadMapSource);
113 mCalibObjects.mFastTransformHelper->setCorrMap(mCalibObjects.mFastTransform.get());
114 mCalibObjects.mFastTransformHelper->setCorrMapRef(mCalibObjects.mFastTransformRef.get());
115 mCalibObjects.mFastTransformHelper->setLumiScaleType(mSpecConfig.
lumiScaleType);
116 mCalibObjects.mFastTransformHelper->setCorrMapMShape(mCalibObjects.mFastTransformMShape.get());
117 mCalibObjects.mFastTransformHelper->setLumiScaleMode(mSpecConfig.
lumiScaleMode);
119 mCalibObjects.mFastTransformHelper->enableMShapeCorrection(mSpecConfig.
enableMShape);
121 mCalibObjects.mFastTransformHelper->init(ic);
123 if (mConfParam->dEdxDisableTopologyPol) {
124 LOGP(info,
"Disabling loading of track topology correction using polynomials from CCDB");
128 if (mConfParam->dEdxDisableThresholdMap) {
129 LOGP(info,
"Disabling loading of threshold map from CCDB");
133 if (mConfParam->dEdxDisableGainMap) {
134 LOGP(info,
"Disabling loading of gain map from CCDB");
138 if (mConfParam->dEdxDisableResidualGainMap) {
139 LOGP(info,
"Disabling loading of residual gain map from CCDB");
143 if (mConfParam->dEdxDisableResidualGain) {
144 LOGP(info,
"Disabling loading of residual gain calibration from CCDB");
148 if (mConfParam->dEdxUseFullGainMap) {
149 LOGP(info,
"Using the full gain map for correcting the cluster charge during calculation of the dE/dx");
150 mCalibObjects.mdEdxCalibContainer->setUsageOfFullGainMap(
true);
153 if (mConfParam->gainCalibDisableCCDB) {
154 LOGP(info,
"Disabling loading the TPC pad gain calibration from the CCDB");
155 mUpdateGainMapCCDB =
false;
159 if (!mConfParam->dEdxPolTopologyCorrFile.empty() || !mConfParam->dEdxCorrFile.empty() || !mConfParam->dEdxSplineTopologyCorrFile.empty()) {
160 if (!mConfParam->dEdxPolTopologyCorrFile.empty()) {
161 LOGP(info,
"Loading dE/dx polynomial track topology correction from file: {}", mConfParam->dEdxPolTopologyCorrFile);
162 mCalibObjects.mdEdxCalibContainer->loadPolTopologyCorrectionFromFile(mConfParam->dEdxPolTopologyCorrFile);
164 LOGP(info,
"Disabling loading of track topology correction using polynomials from CCDB as it was already loaded from input file");
167 if (std::filesystem::exists(mConfParam->thresholdCalibFile)) {
168 LOG(info) <<
"Loading tpc zero supression map from file " << mConfParam->thresholdCalibFile;
170 mCalibObjects.mdEdxCalibContainer->setZeroSupresssionThreshold(*thresholdMap);
172 LOGP(info,
"Disabling loading of threshold map from CCDB as it was already loaded from input file");
175 if (not mConfParam->thresholdCalibFile.empty()) {
176 LOG(warn) <<
"Couldn't find tpc zero supression file " << mConfParam->thresholdCalibFile <<
". Not setting any zero supression.";
178 LOG(info) <<
"Setting default zero supression map";
179 mCalibObjects.mdEdxCalibContainer->setDefaultZeroSupresssionThreshold();
181 }
else if (!mConfParam->dEdxSplineTopologyCorrFile.empty()) {
182 LOGP(info,
"Loading dE/dx spline track topology correction from file: {}", mConfParam->dEdxSplineTopologyCorrFile);
183 mCalibObjects.mdEdxCalibContainer->loadSplineTopologyCorrectionFromFile(mConfParam->dEdxSplineTopologyCorrFile);
185 LOGP(info,
"Disabling loading of track topology correction using polynomials from CCDB as splines were loaded from input file");
188 if (!mConfParam->dEdxCorrFile.empty()) {
189 LOGP(info,
"Loading dEdx correction from file: {}", mConfParam->dEdxCorrFile);
190 mCalibObjects.mdEdxCalibContainer->loadResidualCorrectionFromFile(mConfParam->dEdxCorrFile);
192 LOGP(info,
"Disabling loading of residual gain calibration from CCDB as it was already loaded from input file");
197 if (mConfParam->dEdxPolTopologyCorrFile.empty() && mConfParam->dEdxSplineTopologyCorrFile.empty()) {
199 LOG(info) <<
"Setting default dE/dx polynomial track topology correction to allocate enough memory";
200 mCalibObjects.mdEdxCalibContainer->setDefaultPolTopologyCorrection();
204 mConfig->configCalib.dEdxCalibContainer = mCalibObjects.mdEdxCalibContainer.get();
206 if (std::filesystem::exists(mConfParam->gainCalibFile)) {
207 LOG(info) <<
"Loading tpc gain correction from file " << mConfParam->gainCalibFile;
211 LOGP(info,
"Disabling loading the TPC gain correction map from the CCDB as it was already loaded from input file");
212 mUpdateGainMapCCDB =
false;
214 if (not mConfParam->gainCalibFile.empty()) {
215 LOG(warn) <<
"Couldn't find tpc gain correction file " << mConfParam->gainCalibFile <<
". Not applying any gain correction.";
218 mCalibObjects.mTPCPadGainCalib->getGainCorrection(30, 5, 5);
220 mConfig->configCalib.tpcPadGain = mCalibObjects.mTPCPadGainCalib.get();
223 mConfig->configCalib.tpcZSLinkMapping = mTPCZSLinkMapping.get();
230 auto copyCalibsToBuffer = [
this, dEdxCalibContainer]() {
231 if (!(mdEdxCalibContainerBufferNew)) {
232 mdEdxCalibContainerBufferNew = std::make_unique<o2::tpc::CalibdEdxContainer>();
233 mdEdxCalibContainerBufferNew->cloneFromObject(*dEdxCalibContainer,
nullptr);
238 LOGP(info,
"Updating gain map from CCDB");
242 copyCalibsToBuffer();
243 const float minGain = 0;
244 const float maxGain = 2;
245 mdEdxCalibContainerBufferNew.get()->setGainMap(*gainMap, minGain, maxGain);
248 if (mUpdateGainMapCCDB && mSpecConfig.
caClusterer) {
253 LOGP(info,
"Updating residual gain map from CCDB");
254 copyCalibsToBuffer();
255 const auto* gainMapResidual =
static_cast<std::unordered_map<std::string, o2::tpc::CalDet<float>
>*>(obj);
256 const float minResidualGain = 0.7f;
257 const float maxResidualGain = 1.3f;
258 mdEdxCalibContainerBufferNew.get()->setGainMapResidual(gainMapResidual->at(
"GainMap"), minResidualGain, maxResidualGain);
260 LOGP(info,
"Updating threshold map from CCDB");
261 copyCalibsToBuffer();
262 const auto* thresholdMap =
static_cast<std::unordered_map<std::string, o2::tpc::CalDet<float>
>*>(obj);
263 mdEdxCalibContainerBufferNew.get()->setZeroSupresssionThreshold(thresholdMap->at(
"ThresholdMap"));
265 LOGP(info,
"Updating Q topology correction from CCDB");
266 copyCalibsToBuffer();
270 mdEdxCalibContainerBufferNew->setPolTopologyCorrection(calibTrackTopology);
272 LOGP(info,
"Updating residual gain correction from CCDB");
273 copyCalibsToBuffer();
275 mdEdxCalibContainerBufferNew->setResidualCorrection(*residualCorr);
277 copyCalibsToBuffer();
279 mTPCDeadChannelMapCreator->setDeadChannelMapIDCPadStatus(*padFlags);
280 mTPCDeadChannelMapCreator->finalizeDeadChannelMap();
281 mdEdxCalibContainerBufferNew.get()->setDeadChannelMap(mTPCDeadChannelMapCreator->getDeadChannelMap());
282 LOGP(info,
"Updating dead channel map with IDC pad flags: {} / {} dead pads from pad flags / total",
283 mTPCDeadChannelMapCreator->getDeadChannelMapIDC().getSum<int32_t>(), mTPCDeadChannelMapCreator->getDeadChannelMap().getSum<int32_t>());
285 copyCalibsToBuffer();
287 mTPCDeadChannelMapCreator->setDeadChannelMapFEEConfig(*fee);
288 mTPCDeadChannelMapCreator->finalizeDeadChannelMap();
289 mdEdxCalibContainerBufferNew.get()->setDeadChannelMap(mTPCDeadChannelMapCreator->getDeadChannelMap());
291 "Updating dead channel map with the FEE info (tag {}) loaded via TPCRUNINFO"
292 " for creation time {}: {} / {} dead pads from FEE info / total, with",
293 std::underlying_type_t<o2::tpc::FEEConfig::Tags>(fee->tag), mCreationForCalib,
294 mTPCDeadChannelMapCreator->getDeadChannelMapFEE().getSum<int32_t>(), mTPCDeadChannelMapCreator->getDeadChannelMap().getSum<int32_t>());
295 }
else if (mTPCVDriftHelper->accountCCDBInputs(matcher, obj)) {
296 }
else if (mCalibObjects.mFastTransformHelper->accountCCDBInputs(matcher, obj)) {
299 LOG(info) <<
"(NN CLUS) " << (mConfig->configCalib.nnClusterizerNetworks[0])->getONNXModelSize() <<
" bytes loaded for NN clusterizer: classification_c1";
302 LOG(info) <<
"(NN CLUS) " << (mConfig->configCalib.nnClusterizerNetworks[0])->getONNXModelSize() <<
" bytes loaded for NN clusterizer: classification_c2";
305 LOG(info) <<
"(NN CLUS) " << (mConfig->configCalib.nnClusterizerNetworks[1])->getONNXModelSize() <<
" bytes loaded for NN clusterizer: regression_c1";
308 LOG(info) <<
"(NN CLUS) " << (mConfig->configCalib.nnClusterizerNetworks[2])->getONNXModelSize() <<
" bytes loaded for NN clusterizer: regression_c2";
317 bool mustUpdate =
false;
334 pc.
inputs().
get<std::unordered_map<std::string, o2::tpc::CalDet<float>>*>(
"tpcthreshold");
346 pc.
inputs().
get<std::unordered_map<std::string, o2::tpc::CalDet<float>>*>(
"tpcgainresidual");
358 mTPCVDriftHelper->extractCCDBInputs(pc);
359 mCalibObjects.mFastTransformHelper->extractCCDBInputs(pc);
361 if (mTPCVDriftHelper->isUpdated() || mCalibObjects.mFastTransformHelper->isUpdated()) {
362 const auto& vd = mTPCVDriftHelper->getVDriftObject();
363 LOGP(info,
"Updating{}TPC fast transform map and/or VDrift factor of {} wrt reference {} and TDrift offset {} wrt reference {} from source {}",
364 mCalibObjects.mFastTransformHelper->isUpdated() ?
" new " :
" old ",
365 vd.corrFact, vd.refVDrift, vd.timeOffsetCorr, vd.refTimeOffset, mTPCVDriftHelper->getSourceName());
367 bool mustUpdateHelper =
false;
368 if (mTPCVDriftHelper->isUpdated() || mCalibObjects.mFastTransformHelper->isUpdatedMap()) {
369 oldCalibObjects.mFastTransform = std::move(mCalibObjects.mFastTransform);
371 mCalibObjects.mFastTransform->cloneFromObject(*mCalibObjects.mFastTransformHelper->getCorrMap(),
nullptr);
373 newCalibObjects.
fastTransform = mCalibObjects.mFastTransform.get();
374 mustUpdateHelper =
true;
376 if (mTPCVDriftHelper->isUpdated() || mCalibObjects.mFastTransformHelper->isUpdatedMapRef()) {
377 oldCalibObjects.mFastTransformRef = std::move(mCalibObjects.mFastTransformRef);
379 mCalibObjects.mFastTransformRef->cloneFromObject(*mCalibObjects.mFastTransformHelper->getCorrMapRef(),
nullptr);
382 mustUpdateHelper =
true;
384 if (mTPCVDriftHelper->isUpdated() || mCalibObjects.mFastTransformHelper->isUpdatedMapMShape()) {
385 oldCalibObjects.mFastTransformMShape = std::move(mCalibObjects.mFastTransformMShape);
387 mCalibObjects.mFastTransformMShape->cloneFromObject(*mCalibObjects.mFastTransformHelper->getCorrMapMShape(),
nullptr);
390 mustUpdateHelper =
true;
392 if (mustUpdateHelper || mCalibObjects.mFastTransformHelper->isUpdatedLumi()) {
393 oldCalibObjects.mFastTransformHelper = std::move(mCalibObjects.mFastTransformHelper);
395 mCalibObjects.mFastTransformHelper->copySettings(*oldCalibObjects.mFastTransformHelper);
396 mCalibObjects.mFastTransformHelper->setCorrMap(mCalibObjects.mFastTransform.get());
397 mCalibObjects.mFastTransformHelper->setCorrMapRef(mCalibObjects.mFastTransformRef.get());
398 mCalibObjects.mFastTransformHelper->setCorrMapMShape(mCalibObjects.mFastTransformMShape.get());
399 mCalibObjects.mFastTransformHelper->acknowledgeUpdate();
403 mTPCVDriftHelper->acknowledgeUpdate();
404 mCalibObjects.mFastTransformHelper->acknowledgeUpdate();
408 if (mdEdxCalibContainerBufferNew) {
409 oldCalibObjects.mdEdxCalibContainer = std::move(mCalibObjects.mdEdxCalibContainer);
410 mCalibObjects.mdEdxCalibContainer = std::move(mdEdxCalibContainerBufferNew);
415 if (mTPCPadGainCalibBufferNew) {
416 oldCalibObjects.mTPCPadGainCalib = std::move(mCalibObjects.mTPCPadGainCalib);
417 mCalibObjects.mTPCPadGainCalib = std::move(mTPCPadGainCalibBufferNew);
418 newCalibObjects.
tpcPadGain = mCalibObjects.mTPCPadGainCalib.get();
427 }
else if (mSpecConfig.
nnEvalMode[0] ==
"c2") {
445 (trackTune.useTPCInnerCorr || trackTune.useTPCOuterCorr ||
448 throw std::runtime_error(
"Buffer does not match span");
451 float scale = mCalibObjects.mFastTransformHelper->getInstLumiCTP();
455 auto diagInner = trackTune.getCovInnerTotal(scale);
456 auto diagOuter = trackTune.getCovOuterTotal(scale);
459 auto& trc = tpcTracks[itr];
460 if (trackTune.useTPCInnerCorr) {
461 trc.updateParams(trackTune.tpcParInner);
466 if (trackTune.useTPCOuterCorr) {
467 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.
Helper class to access correction maps.
Helper class to access load maps from CCDB.
Definition of class for writing debug informations.
Definition of the GeometryManager class.
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="")
ConcreteParserVariants< PageSize, BOUNDS_CHECKS > create(T const *buffer, size_t size)
create a raw parser depending on version of RAWDataHeader found at beginning of data
Defining PrimaryVertex 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< TPCFastTransform >::type * fastTransform
S< TPCPadGainCalib >::type * tpcPadGain
S< CorrectionMapsHelper >::type * fastTransformHelper
S< TPCFastTransform >::type * fastTransformRef
S< TPCFastTransform >::type * fastTransformMShape
bool checkCTPIDCconsistency
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"