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);
118 mCalibObjects.mFastTransformHelper->enableMShapeCorrection(mSpecConfig.
enableMShape);
120 mCalibObjects.mFastTransformHelper->init(ic);
122 if (mConfParam->dEdxDisableTopologyPol) {
123 LOGP(info,
"Disabling loading of track topology correction using polynomials from CCDB");
127 if (mConfParam->dEdxDisableThresholdMap) {
128 LOGP(info,
"Disabling loading of threshold map from CCDB");
132 if (mConfParam->dEdxDisableGainMap) {
133 LOGP(info,
"Disabling loading of gain map from CCDB");
137 if (mConfParam->dEdxDisableResidualGainMap) {
138 LOGP(info,
"Disabling loading of residual gain map from CCDB");
142 if (mConfParam->dEdxDisableResidualGain) {
143 LOGP(info,
"Disabling loading of residual gain calibration from CCDB");
147 if (mConfParam->dEdxUseFullGainMap) {
148 LOGP(info,
"Using the full gain map for correcting the cluster charge during calculation of the dE/dx");
149 mCalibObjects.mdEdxCalibContainer->setUsageOfFullGainMap(
true);
152 if (mConfParam->gainCalibDisableCCDB) {
153 LOGP(info,
"Disabling loading the TPC pad gain calibration from the CCDB");
154 mUpdateGainMapCCDB =
false;
158 if (!mConfParam->dEdxPolTopologyCorrFile.empty() || !mConfParam->dEdxCorrFile.empty() || !mConfParam->dEdxSplineTopologyCorrFile.empty()) {
159 if (!mConfParam->dEdxPolTopologyCorrFile.empty()) {
160 LOGP(info,
"Loading dE/dx polynomial track topology correction from file: {}", mConfParam->dEdxPolTopologyCorrFile);
161 mCalibObjects.mdEdxCalibContainer->loadPolTopologyCorrectionFromFile(mConfParam->dEdxPolTopologyCorrFile);
163 LOGP(info,
"Disabling loading of track topology correction using polynomials from CCDB as it was already loaded from input file");
166 if (std::filesystem::exists(mConfParam->thresholdCalibFile)) {
167 LOG(info) <<
"Loading tpc zero supression map from file " << mConfParam->thresholdCalibFile;
169 mCalibObjects.mdEdxCalibContainer->setZeroSupresssionThreshold(*thresholdMap);
171 LOGP(info,
"Disabling loading of threshold map from CCDB as it was already loaded from input file");
174 if (not mConfParam->thresholdCalibFile.empty()) {
175 LOG(warn) <<
"Couldn't find tpc zero supression file " << mConfParam->thresholdCalibFile <<
". Not setting any zero supression.";
177 LOG(info) <<
"Setting default zero supression map";
178 mCalibObjects.mdEdxCalibContainer->setDefaultZeroSupresssionThreshold();
180 }
else if (!mConfParam->dEdxSplineTopologyCorrFile.empty()) {
181 LOGP(info,
"Loading dE/dx spline track topology correction from file: {}", mConfParam->dEdxSplineTopologyCorrFile);
182 mCalibObjects.mdEdxCalibContainer->loadSplineTopologyCorrectionFromFile(mConfParam->dEdxSplineTopologyCorrFile);
184 LOGP(info,
"Disabling loading of track topology correction using polynomials from CCDB as splines were loaded from input file");
187 if (!mConfParam->dEdxCorrFile.empty()) {
188 LOGP(info,
"Loading dEdx correction from file: {}", mConfParam->dEdxCorrFile);
189 mCalibObjects.mdEdxCalibContainer->loadResidualCorrectionFromFile(mConfParam->dEdxCorrFile);
191 LOGP(info,
"Disabling loading of residual gain calibration from CCDB as it was already loaded from input file");
196 if (mConfParam->dEdxPolTopologyCorrFile.empty() && mConfParam->dEdxSplineTopologyCorrFile.empty()) {
198 LOG(info) <<
"Setting default dE/dx polynomial track topology correction to allocate enough memory";
199 mCalibObjects.mdEdxCalibContainer->setDefaultPolTopologyCorrection();
203 mConfig->configCalib.dEdxCalibContainer = mCalibObjects.mdEdxCalibContainer.get();
205 if (std::filesystem::exists(mConfParam->gainCalibFile)) {
206 LOG(info) <<
"Loading tpc gain correction from file " << mConfParam->gainCalibFile;
210 LOGP(info,
"Disabling loading the TPC gain correction map from the CCDB as it was already loaded from input file");
211 mUpdateGainMapCCDB =
false;
213 if (not mConfParam->gainCalibFile.empty()) {
214 LOG(warn) <<
"Couldn't find tpc gain correction file " << mConfParam->gainCalibFile <<
". Not applying any gain correction.";
217 mCalibObjects.mTPCPadGainCalib->getGainCorrection(30, 5, 5);
219 mConfig->configCalib.tpcPadGain = mCalibObjects.mTPCPadGainCalib.get();
222 mConfig->configCalib.tpcZSLinkMapping = mTPCZSLinkMapping.get();
229 auto copyCalibsToBuffer = [
this, dEdxCalibContainer]() {
230 if (!(mdEdxCalibContainerBufferNew)) {
231 mdEdxCalibContainerBufferNew = std::make_unique<o2::tpc::CalibdEdxContainer>();
232 mdEdxCalibContainerBufferNew->cloneFromObject(*dEdxCalibContainer,
nullptr);
237 LOGP(info,
"Updating gain map from CCDB");
241 copyCalibsToBuffer();
242 const float minGain = 0;
243 const float maxGain = 2;
244 mdEdxCalibContainerBufferNew.get()->setGainMap(*gainMap, minGain, maxGain);
247 if (mUpdateGainMapCCDB && mSpecConfig.
caClusterer) {
252 LOGP(info,
"Updating residual gain map from CCDB");
253 copyCalibsToBuffer();
254 const auto* gainMapResidual =
static_cast<std::unordered_map<std::string, o2::tpc::CalDet<float>
>*>(obj);
255 const float minResidualGain = 0.7f;
256 const float maxResidualGain = 1.3f;
257 mdEdxCalibContainerBufferNew.get()->setGainMapResidual(gainMapResidual->at(
"GainMap"), minResidualGain, maxResidualGain);
259 LOGP(info,
"Updating threshold map from CCDB");
260 copyCalibsToBuffer();
261 const auto* thresholdMap =
static_cast<std::unordered_map<std::string, o2::tpc::CalDet<float>
>*>(obj);
262 mdEdxCalibContainerBufferNew.get()->setZeroSupresssionThreshold(thresholdMap->at(
"ThresholdMap"));
264 LOGP(info,
"Updating Q topology correction from CCDB");
265 copyCalibsToBuffer();
269 mdEdxCalibContainerBufferNew->setPolTopologyCorrection(calibTrackTopology);
271 LOGP(info,
"Updating residual gain correction from CCDB");
272 copyCalibsToBuffer();
274 mdEdxCalibContainerBufferNew->setResidualCorrection(*residualCorr);
276 copyCalibsToBuffer();
278 mTPCDeadChannelMapCreator->setDeadChannelMapIDCPadStatus(*padFlags);
279 mTPCDeadChannelMapCreator->finalizeDeadChannelMap();
280 mdEdxCalibContainerBufferNew.get()->setDeadChannelMap(mTPCDeadChannelMapCreator->getDeadChannelMap());
281 LOGP(info,
"Updating dead channel map with IDC pad flags: {} / {} dead pads from pad flags / total",
282 mTPCDeadChannelMapCreator->getDeadChannelMapIDC().getSum<int32_t>(), mTPCDeadChannelMapCreator->getDeadChannelMap().getSum<int32_t>());
284 copyCalibsToBuffer();
286 mTPCDeadChannelMapCreator->setDeadChannelMapFEEConfig(*fee);
287 mTPCDeadChannelMapCreator->finalizeDeadChannelMap();
288 mdEdxCalibContainerBufferNew.get()->setDeadChannelMap(mTPCDeadChannelMapCreator->getDeadChannelMap());
290 "Updating dead channel map with the FEE info (tag {}) loaded via TPCRUNINFO"
291 " for creation time {}: {} / {} dead pads from FEE info / total, with",
292 std::underlying_type_t<o2::tpc::FEEConfig::Tags>(fee->tag), mCreationForCalib,
293 mTPCDeadChannelMapCreator->getDeadChannelMapFEE().getSum<int32_t>(), mTPCDeadChannelMapCreator->getDeadChannelMap().getSum<int32_t>());
294 }
else if (mTPCVDriftHelper->accountCCDBInputs(matcher, obj)) {
295 }
else if (mCalibObjects.mFastTransformHelper->accountCCDBInputs(matcher, obj)) {
304 bool mustUpdate =
false;
321 pc.
inputs().
get<std::unordered_map<std::string, o2::tpc::CalDet<float>>*>(
"tpcthreshold");
333 pc.
inputs().
get<std::unordered_map<std::string, o2::tpc::CalDet<float>>*>(
"tpcgainresidual");
345 mTPCVDriftHelper->extractCCDBInputs(pc);
346 mCalibObjects.mFastTransformHelper->extractCCDBInputs(pc);
348 if (mTPCVDriftHelper->isUpdated() || mCalibObjects.mFastTransformHelper->isUpdated()) {
349 const auto& vd = mTPCVDriftHelper->getVDriftObject();
350 LOGP(info,
"Updating{}TPC fast transform map and/or VDrift factor of {} wrt reference {} and TDrift offset {} wrt reference {} from source {}",
351 mCalibObjects.mFastTransformHelper->isUpdated() ?
" new " :
" old ",
352 vd.corrFact, vd.refVDrift, vd.timeOffsetCorr, vd.refTimeOffset, mTPCVDriftHelper->getSourceName());
354 bool mustUpdateHelper =
false;
355 if (mTPCVDriftHelper->isUpdated() || mCalibObjects.mFastTransformHelper->isUpdatedMap()) {
356 oldCalibObjects.mFastTransform = std::move(mCalibObjects.mFastTransform);
358 mCalibObjects.mFastTransform->cloneFromObject(*mCalibObjects.mFastTransformHelper->getCorrMap(),
nullptr);
360 newCalibObjects.
fastTransform = mCalibObjects.mFastTransform.get();
361 mustUpdateHelper =
true;
363 if (mTPCVDriftHelper->isUpdated() || mCalibObjects.mFastTransformHelper->isUpdatedMapRef()) {
364 oldCalibObjects.mFastTransformRef = std::move(mCalibObjects.mFastTransformRef);
366 mCalibObjects.mFastTransformRef->cloneFromObject(*mCalibObjects.mFastTransformHelper->getCorrMapRef(),
nullptr);
369 mustUpdateHelper =
true;
371 if (mTPCVDriftHelper->isUpdated() || mCalibObjects.mFastTransformHelper->isUpdatedMapMShape()) {
372 oldCalibObjects.mFastTransformMShape = std::move(mCalibObjects.mFastTransformMShape);
374 mCalibObjects.mFastTransformMShape->cloneFromObject(*mCalibObjects.mFastTransformHelper->getCorrMapMShape(),
nullptr);
377 mustUpdateHelper =
true;
379 if (mustUpdateHelper || mCalibObjects.mFastTransformHelper->isUpdatedLumi()) {
380 oldCalibObjects.mFastTransformHelper = std::move(mCalibObjects.mFastTransformHelper);
382 mCalibObjects.mFastTransformHelper->copySettings(*oldCalibObjects.mFastTransformHelper);
383 mCalibObjects.mFastTransformHelper->setCorrMap(mCalibObjects.mFastTransform.get());
384 mCalibObjects.mFastTransformHelper->setCorrMapRef(mCalibObjects.mFastTransformRef.get());
385 mCalibObjects.mFastTransformHelper->setCorrMapMShape(mCalibObjects.mFastTransformMShape.get());
386 mCalibObjects.mFastTransformHelper->acknowledgeUpdate();
390 mTPCVDriftHelper->acknowledgeUpdate();
391 mCalibObjects.mFastTransformHelper->acknowledgeUpdate();
395 if (mdEdxCalibContainerBufferNew) {
396 oldCalibObjects.mdEdxCalibContainer = std::move(mCalibObjects.mdEdxCalibContainer);
397 mCalibObjects.mdEdxCalibContainer = std::move(mdEdxCalibContainerBufferNew);
402 if (mTPCPadGainCalibBufferNew) {
403 oldCalibObjects.mTPCPadGainCalib = std::move(mCalibObjects.mTPCPadGainCalib);
404 mCalibObjects.mTPCPadGainCalib = std::move(mTPCPadGainCalibBufferNew);
405 newCalibObjects.
tpcPadGain = mCalibObjects.mTPCPadGainCalib.get();
417 (trackTune.useTPCInnerCorr || trackTune.useTPCOuterCorr ||
420 throw std::runtime_error(
"Buffer does not match span");
423 float scale = mCalibObjects.mFastTransformHelper->getInstLumiCTP();
427 auto diagInner = trackTune.getCovInnerTotal(scale);
428 auto diagOuter = trackTune.getCovOuterTotal(scale);
431 auto& trc = tpcTracks[itr];
432 if (trackTune.useTPCInnerCorr) {
433 trc.updateParams(trackTune.tpcParInner);
438 if (trackTune.useTPCOuterCorr) {
439 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
bool checkCTPIDCconsistency
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"