83#include <TStopwatch.h>
88#include <TGraphAsymmErrors.h>
99void GPURecoWorkflowSpec::initFunctionTPCCalib(
InitContext& ic)
103 mTPCDeadChannelMapCreator->init();
104 mTPCDeadChannelMapCreator->setSource(deadMapSource);
112 mCalibObjects.mFastTransformHelper->setCorrMap(mCalibObjects.mFastTransform.get());
113 mCalibObjects.mFastTransformHelper->setCorrMapRef(mCalibObjects.mFastTransformRef.get());
114 mCalibObjects.mFastTransformHelper->setLumiScaleType(mSpecConfig.
lumiScaleType);
115 mCalibObjects.mFastTransformHelper->setCorrMapMShape(mCalibObjects.mFastTransformMShape.get());
116 mCalibObjects.mFastTransformHelper->setLumiScaleMode(mSpecConfig.
lumiScaleMode);
117 mCalibObjects.mFastTransformHelper->enableMShapeCorrection(mSpecConfig.
enableMShape);
119 mCalibObjects.mFastTransformHelper->init(ic);
121 if (mConfParam->dEdxDisableTopologyPol) {
122 LOGP(info,
"Disabling loading of track topology correction using polynomials from CCDB");
126 if (mConfParam->dEdxDisableThresholdMap) {
127 LOGP(info,
"Disabling loading of threshold map from CCDB");
131 if (mConfParam->dEdxDisableGainMap) {
132 LOGP(info,
"Disabling loading of gain map from CCDB");
136 if (mConfParam->dEdxDisableResidualGainMap) {
137 LOGP(info,
"Disabling loading of residual gain map from CCDB");
141 if (mConfParam->dEdxDisableResidualGain) {
142 LOGP(info,
"Disabling loading of residual gain calibration from CCDB");
146 if (mConfParam->dEdxUseFullGainMap) {
147 LOGP(info,
"Using the full gain map for correcting the cluster charge during calculation of the dE/dx");
148 mCalibObjects.mdEdxCalibContainer->setUsageOfFullGainMap(
true);
151 if (mConfParam->gainCalibDisableCCDB) {
152 LOGP(info,
"Disabling loading the TPC pad gain calibration from the CCDB");
153 mUpdateGainMapCCDB =
false;
157 if (!mConfParam->dEdxPolTopologyCorrFile.empty() || !mConfParam->dEdxCorrFile.empty() || !mConfParam->dEdxSplineTopologyCorrFile.empty()) {
158 if (!mConfParam->dEdxPolTopologyCorrFile.empty()) {
159 LOGP(info,
"Loading dE/dx polynomial track topology correction from file: {}", mConfParam->dEdxPolTopologyCorrFile);
160 mCalibObjects.mdEdxCalibContainer->loadPolTopologyCorrectionFromFile(mConfParam->dEdxPolTopologyCorrFile);
162 LOGP(info,
"Disabling loading of track topology correction using polynomials from CCDB as it was already loaded from input file");
165 if (std::filesystem::exists(mConfParam->thresholdCalibFile)) {
166 LOG(info) <<
"Loading tpc zero supression map from file " << mConfParam->thresholdCalibFile;
168 mCalibObjects.mdEdxCalibContainer->setZeroSupresssionThreshold(*thresholdMap);
170 LOGP(info,
"Disabling loading of threshold map from CCDB as it was already loaded from input file");
173 if (not mConfParam->thresholdCalibFile.empty()) {
174 LOG(warn) <<
"Couldn't find tpc zero supression file " << mConfParam->thresholdCalibFile <<
". Not setting any zero supression.";
176 LOG(info) <<
"Setting default zero supression map";
177 mCalibObjects.mdEdxCalibContainer->setDefaultZeroSupresssionThreshold();
179 }
else if (!mConfParam->dEdxSplineTopologyCorrFile.empty()) {
180 LOGP(info,
"Loading dE/dx spline track topology correction from file: {}", mConfParam->dEdxSplineTopologyCorrFile);
181 mCalibObjects.mdEdxCalibContainer->loadSplineTopologyCorrectionFromFile(mConfParam->dEdxSplineTopologyCorrFile);
183 LOGP(info,
"Disabling loading of track topology correction using polynomials from CCDB as splines were loaded from input file");
186 if (!mConfParam->dEdxCorrFile.empty()) {
187 LOGP(info,
"Loading dEdx correction from file: {}", mConfParam->dEdxCorrFile);
188 mCalibObjects.mdEdxCalibContainer->loadResidualCorrectionFromFile(mConfParam->dEdxCorrFile);
190 LOGP(info,
"Disabling loading of residual gain calibration from CCDB as it was already loaded from input file");
195 if (mConfParam->dEdxPolTopologyCorrFile.empty() && mConfParam->dEdxSplineTopologyCorrFile.empty()) {
197 LOG(info) <<
"Setting default dE/dx polynomial track topology correction to allocate enough memory";
198 mCalibObjects.mdEdxCalibContainer->setDefaultPolTopologyCorrection();
202 mConfig->configCalib.dEdxCalibContainer = mCalibObjects.mdEdxCalibContainer.get();
204 if (std::filesystem::exists(mConfParam->gainCalibFile)) {
205 LOG(info) <<
"Loading tpc gain correction from file " << mConfParam->gainCalibFile;
209 LOGP(info,
"Disabling loading the TPC gain correction map from the CCDB as it was already loaded from input file");
210 mUpdateGainMapCCDB =
false;
212 if (not mConfParam->gainCalibFile.empty()) {
213 LOG(warn) <<
"Couldn't find tpc gain correction file " << mConfParam->gainCalibFile <<
". Not applying any gain correction.";
216 mCalibObjects.mTPCPadGainCalib->getGainCorrection(30, 5, 5);
218 mConfig->configCalib.tpcPadGain = mCalibObjects.mTPCPadGainCalib.get();
221 mConfig->configCalib.tpcZSLinkMapping = mTPCZSLinkMapping.get();
228 auto copyCalibsToBuffer = [
this, dEdxCalibContainer]() {
229 if (!(mdEdxCalibContainerBufferNew)) {
230 mdEdxCalibContainerBufferNew = std::make_unique<o2::tpc::CalibdEdxContainer>();
231 mdEdxCalibContainerBufferNew->cloneFromObject(*dEdxCalibContainer,
nullptr);
236 LOGP(info,
"Updating gain map from CCDB");
240 copyCalibsToBuffer();
241 const float minGain = 0;
242 const float maxGain = 2;
243 mdEdxCalibContainerBufferNew.get()->setGainMap(*gainMap, minGain, maxGain);
246 if (mUpdateGainMapCCDB && mSpecConfig.
caClusterer) {
251 LOGP(info,
"Updating residual gain map from CCDB");
252 copyCalibsToBuffer();
253 const auto* gainMapResidual =
static_cast<std::unordered_map<string, o2::tpc::CalDet<float>
>*>(obj);
254 const float minResidualGain = 0.7f;
255 const float maxResidualGain = 1.3f;
256 mdEdxCalibContainerBufferNew.get()->setGainMapResidual(gainMapResidual->at(
"GainMap"), minResidualGain, maxResidualGain);
258 LOGP(info,
"Updating threshold map from CCDB");
259 copyCalibsToBuffer();
260 const auto* thresholdMap =
static_cast<std::unordered_map<string, o2::tpc::CalDet<float>
>*>(obj);
261 mdEdxCalibContainerBufferNew.get()->setZeroSupresssionThreshold(thresholdMap->at(
"ThresholdMap"));
263 LOGP(info,
"Updating Q topology correction from CCDB");
264 copyCalibsToBuffer();
268 mdEdxCalibContainerBufferNew->setPolTopologyCorrection(calibTrackTopology);
270 LOGP(info,
"Updating residual gain correction from CCDB");
271 copyCalibsToBuffer();
273 mdEdxCalibContainerBufferNew->setResidualCorrection(*residualCorr);
275 copyCalibsToBuffer();
277 mTPCDeadChannelMapCreator->setDeadChannelMapIDCPadStatus(*padFlags);
278 mTPCDeadChannelMapCreator->finalizeDeadChannelMap();
279 mdEdxCalibContainerBufferNew.get()->setDeadChannelMap(mTPCDeadChannelMapCreator->getDeadChannelMap());
280 LOGP(info,
"Updating dead channel map with IDC pad flags: {} / {} dead pads from pad flags / total",
281 mTPCDeadChannelMapCreator->getDeadChannelMapIDC().getSum<int32_t>(), mTPCDeadChannelMapCreator->getDeadChannelMap().getSum<int32_t>());
283 copyCalibsToBuffer();
285 mTPCDeadChannelMapCreator->setDeadChannelMapFEEConfig(*fee);
286 mTPCDeadChannelMapCreator->finalizeDeadChannelMap();
287 mdEdxCalibContainerBufferNew.get()->setDeadChannelMap(mTPCDeadChannelMapCreator->getDeadChannelMap());
289 "Updating dead channel map with the FEE info (tag {}) loaded via TPCRUNINFO"
290 " for creation time {}: {} / {} dead pads from FEE info / total, with",
291 std::underlying_type_t<o2::tpc::FEEConfig::Tags>(fee->tag), mCreationForCalib,
292 mTPCDeadChannelMapCreator->getDeadChannelMapFEE().getSum<int32_t>(), mTPCDeadChannelMapCreator->getDeadChannelMap().getSum<int32_t>());
293 }
else if (mTPCVDriftHelper->accountCCDBInputs(matcher, obj)) {
294 }
else if (mCalibObjects.mFastTransformHelper->accountCCDBInputs(matcher, obj)) {
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);
345 mCalibObjects.mFastTransformHelper->extractCCDBInputs(pc);
347 if (mTPCVDriftHelper->isUpdated() || mCalibObjects.mFastTransformHelper->isUpdated()) {
348 const auto& vd = mTPCVDriftHelper->getVDriftObject();
349 LOGP(info,
"Updating{}TPC fast transform map and/or VDrift factor of {} wrt reference {} and TDrift offset {} wrt reference {} from source {}",
350 mCalibObjects.mFastTransformHelper->isUpdated() ?
" new " :
" old ",
351 vd.corrFact, vd.refVDrift, vd.timeOffsetCorr, vd.refTimeOffset, mTPCVDriftHelper->getSourceName());
353 bool mustUpdateHelper =
false;
354 if (mTPCVDriftHelper->isUpdated() || mCalibObjects.mFastTransformHelper->isUpdatedMap()) {
355 oldCalibObjects.mFastTransform = std::move(mCalibObjects.mFastTransform);
357 mCalibObjects.mFastTransform->cloneFromObject(*mCalibObjects.mFastTransformHelper->getCorrMap(),
nullptr);
359 newCalibObjects.
fastTransform = mCalibObjects.mFastTransform.get();
360 mustUpdateHelper =
true;
362 if (mTPCVDriftHelper->isUpdated() || mCalibObjects.mFastTransformHelper->isUpdatedMapRef()) {
363 oldCalibObjects.mFastTransformRef = std::move(mCalibObjects.mFastTransformRef);
365 mCalibObjects.mFastTransformRef->cloneFromObject(*mCalibObjects.mFastTransformHelper->getCorrMapRef(),
nullptr);
368 mustUpdateHelper =
true;
370 if (mTPCVDriftHelper->isUpdated() || mCalibObjects.mFastTransformHelper->isUpdatedMapMShape()) {
371 oldCalibObjects.mFastTransformMShape = std::move(mCalibObjects.mFastTransformMShape);
373 mCalibObjects.mFastTransformMShape->cloneFromObject(*mCalibObjects.mFastTransformHelper->getCorrMapMShape(),
nullptr);
376 mustUpdateHelper =
true;
378 if (mustUpdateHelper || mCalibObjects.mFastTransformHelper->isUpdatedLumi()) {
379 oldCalibObjects.mFastTransformHelper = std::move(mCalibObjects.mFastTransformHelper);
381 mCalibObjects.mFastTransformHelper->copySettings(*oldCalibObjects.mFastTransformHelper);
382 mCalibObjects.mFastTransformHelper->setCorrMap(mCalibObjects.mFastTransform.get());
383 mCalibObjects.mFastTransformHelper->setCorrMapRef(mCalibObjects.mFastTransformRef.get());
384 mCalibObjects.mFastTransformHelper->setCorrMapMShape(mCalibObjects.mFastTransformMShape.get());
385 mCalibObjects.mFastTransformHelper->acknowledgeUpdate();
389 mTPCVDriftHelper->acknowledgeUpdate();
390 mCalibObjects.mFastTransformHelper->acknowledgeUpdate();
394 if (mdEdxCalibContainerBufferNew) {
395 oldCalibObjects.mdEdxCalibContainer = std::move(mCalibObjects.mdEdxCalibContainer);
396 mCalibObjects.mdEdxCalibContainer = std::move(mdEdxCalibContainerBufferNew);
401 if (mTPCPadGainCalibBufferNew) {
402 oldCalibObjects.mTPCPadGainCalib = std::move(mCalibObjects.mTPCPadGainCalib);
403 mCalibObjects.mTPCPadGainCalib = std::move(mTPCPadGainCalibBufferNew);
404 newCalibObjects.
tpcPadGain = mCalibObjects.mTPCPadGainCalib.get();
416 (trackTune.useTPCInnerCorr || trackTune.useTPCOuterCorr ||
419 throw std::runtime_error(
"Buffer does not match span");
422 float scale = mCalibObjects.mFastTransformHelper->getInstLumiCTP();
426 auto diagInner = trackTune.getCovInnerTotal(scale);
427 auto diagOuter = trackTune.getCovOuterTotal(scale);
430 auto& trc = tpcTracks[itr];
431 if (trackTune.useTPCInnerCorr) {
432 trc.updateParams(trackTune.tpcParInner);
437 if (trackTune.useTPCOuterCorr) {
438 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.
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
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"