Skip to content

Commit

Permalink
Adding V-shape correction, fixing timestamp in time series
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-kleiner committed Dec 8, 2023
1 parent 618a89c commit 70e0076
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 40 deletions.
2 changes: 2 additions & 0 deletions Detectors/TPC/base/include/TPCBase/CDBTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ enum class CDBType {
CalCorrMapRef, ///< Cluster correction reference map (static distortions)
CalCorrMapMC, ///< Cluster correction map (high IR rate distortions) for MC
CalCorrDerivMapMC, ///< Cluster correction reference map (static distortions) for MC
CalCorrMapVShape, ///< Cluster correction map for V-shape distortions
///
CalCorrDerivMap, ///< Cluster correction map (derivative map)
///
Expand Down Expand Up @@ -135,6 +136,7 @@ const std::unordered_map<CDBType, const std::string> CDBTypeMap{
// correction maps
{CDBType::CalCorrMap, "TPC/Calib/CorrectionMapV2"},
{CDBType::CalCorrMapRef, "TPC/Calib/CorrectionMapRefV2"},
{CDBType::CalCorrMapVShape, "TPC/Calib/CorrectionMapVShapeV2"},
// correction maps for MC
{CDBType::CalCorrMapMC, "TPC/Calib/CorrectionMapMCV2"},
{CDBType::CalCorrDerivMapMC, "TPC/Calib/CorrectionMapDerivativeMCV2"},
Expand Down
28 changes: 26 additions & 2 deletions Detectors/TPC/calibration/src/CorrectionMapsLoader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ void CorrectionMapsLoader::updateVDrift(float vdriftCorr, float vdrifRef, float
if (mCorrMapRef) {
o2::tpc::TPCFastTransformHelperO2::instance()->updateCalibration(*mCorrMapRef, 0, vdriftCorr, vdrifRef, driftTimeOffset);
}
if (mCorrMapVShape) {
o2::tpc::TPCFastTransformHelperO2::instance()->updateCalibration(*mCorrMapVShape, 0, vdriftCorr, vdrifRef, driftTimeOffset);
}
}

//________________________________________________________
Expand All @@ -57,10 +60,15 @@ void CorrectionMapsLoader::extractCCDBInputs(ProcessingContext& pc)
}
lumiObj = lumiPrev;
}
setInstLumi(mInstLumiFactor * (mCTPLumiSource == 0 ? lumiObj.getLumi() : lumiObj.getLumiAlt()));
setInstLumi(mInstLumiFactor * (mCTPLumiSource == 0 ? lumiObj.getLumi() : lumiObj.getLumiAlt()), !getUseVShapeCorrection());
} else if (getLumiScaleType() == 2 && mInstLumiOverride <= 0.) {
float tpcScaler = pc.inputs().get<float>("tpcscaler");
setInstLumi(mInstLumiFactor * tpcScaler);
setInstLumi(mInstLumiFactor * tpcScaler, !getUseVShapeCorrection());
}
if (getUseVShapeCorrection()) {
float vshapescaler = pc.inputs().get<float>("vshape");
setVShapeScaler(vshapescaler);
pc.inputs().get<o2::gpu::TPCFastTransform*>("tpcCorrMapVShape");
}
}

Expand All @@ -87,6 +95,11 @@ void CorrectionMapsLoader::requestCCDBInputs(std::vector<InputSpec>& inputs, std
addInput(inputs, {"tpcscaler", o2::header::gDataOriginTPC, "TPCSCALER", 0, Lifetime::Timeframe});
}

if (gloOpts.enableVShapeCorrection) {
addInput(inputs, {"vshape", o2::header::gDataOriginTPC, "TPCVShapeScaler", 0, Lifetime::Timeframe});
addInput(inputs, {"tpcCorrMapVShape", o2::header::gDataOriginTPC, "CorrMapVShape", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMapVShape), {}, 0)}); // load once
}

addInput(inputs, {"tpcCorrPar", "TPC", "CorrMapParam", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CorrMapParam), {}, 0)}); // load once

addOptions(options);
Expand Down Expand Up @@ -157,6 +170,13 @@ bool CorrectionMapsLoader::accountCCDBInputs(const ConcreteDataMatcher& matcher,
setUpdatedMapRef();
return true;
}
if (matcher == ConcreteDataMatcher("TPC", "CorrMapVShape", 0)) {
LOGP(info, "Loading V-shape corrections from CCDB");
setCorrMapVShape((o2::gpu::TPCFastTransform*)obj);
mCorrMapVShape->rectifyAfterReadingFromFile();
setUpdatedMapVShape();
return true;
}
if (matcher == ConcreteDataMatcher("TPC", "CorrMapParam", 0)) {
const auto& par = o2::tpc::CorrMapParam::Instance();
mMeanLumiOverride = par.lumiMean;
Expand Down Expand Up @@ -196,6 +216,8 @@ void CorrectionMapsLoader::init(o2::framework::InitContext& ic)
break;
} else if (route.matcher == InputSpec{"tpcscaler", o2::header::gDataOriginTPC, "TPCSCALER", 0, Lifetime::Timeframe}) {
setLumiScaleType(2);
} else if (route.matcher == InputSpec{"vshape", o2::header::gDataOriginTPC, "TPCVShapeScaler", 0, Lifetime::Timeframe}) {
enableVShapeCorrection(true);
}
}
}
Expand All @@ -211,6 +233,8 @@ void CorrectionMapsLoader::copySettings(const CorrectionMapsLoader& src)
setMeanLumiRefOverride(src.getMeanLumiRefOverride());
setInstLumiOverride(src.getInstLumiOverride());
setLumiScaleMode(src.getLumiScaleMode());
enableVShapeCorrection(src.getUseVShapeCorrection());
setVShapeScaler(src.getVShapeScaler(), false);
mInstLumiFactor = src.mInstLumiFactor;
mCTPLumiSource = src.mCTPLumiSource;
mLumiScaleMode = src.mLumiScaleMode;
Expand Down
13 changes: 7 additions & 6 deletions Detectors/TPC/calibration/src/TPCVShapeScaler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ void TPCVShapeScaler::loadFromFile(const char* inpf, const char* name)
setFromTree(*tree);
}

void TPCVShapeScaler::setFromTree(TTree& TPCVShapeScalerTree)
void TPCVShapeScaler::setFromTree(TTree& tpcScalerTree)
{
TPCVShapeScaler* scalerTmp = this;
TPCVShapeScalerTree.SetBranchAddress("TPCVShapeScaler", &scalerTmp);
const int entries = TPCVShapeScalerTree.GetEntries();
tpcScalerTree.SetBranchAddress("TPCVShapeScaler", &scalerTmp);
const int entries = tpcScalerTree.GetEntries();
if (entries > 0) {
TPCVShapeScalerTree.GetEntry(0);
tpcScalerTree.GetEntry(0);
} else {
LOGP(error, "TPCVShapeScaler not found in input file");
}
TPCVShapeScalerTree.SetBranchAddress("TPCVShapeScaler", nullptr);
tpcScalerTree.SetBranchAddress("TPCVShapeScaler", nullptr);
}

float TPCVShapeScaler::getScaler(const double timestamp) const
Expand All @@ -72,11 +72,12 @@ float TPCVShapeScaler::getScaler(const double timestamp) const
const double deltaTimeLow = std::abs(mScalerA[idx - 1].first - timestamp);
const double deltaTimeUp = std::abs(mScalerA[idx].first - timestamp);

// TODO if both are OK do linear interpolation
// return closes value
if ((deltaTimeLow < deltaTimeUp) && checkDeltaTime(deltaTimeLow)) {
return mScalerA[idx - 1].second;
} else if (checkDeltaTime(deltaTimeUp)) {
return mScalerA[idx - 1].second;
return mScalerA[idx].second;
}
}

Expand Down
1 change: 1 addition & 0 deletions Detectors/TPC/workflow/src/RecoWorkflow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ framework::WorkflowSpec getWorkflow(CompletionPolicyData* policyData, std::vecto
cfg.runTPCTracking = true;
cfg.lumiScaleType = sclOpts.lumiType;
cfg.lumiScaleMode = sclOpts.lumiMode;
cfg.enableVShape = sclOpts.enableVShapeCorrection;
cfg.decompressTPC = decompressTPC;
cfg.decompressTPCFromROOT = decompressTPC && inputType == InputType::CompClusters;
cfg.caClusterer = caClusterer;
Expand Down
14 changes: 11 additions & 3 deletions Detectors/TPC/workflow/src/TPCScalerSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class TPCScalerSpec : public Task
{
o2::base::GRPGeomHelper::instance().setRequest(mCCDBRequest);
mIonDriftTimeMS = ic.options().get<float>("ion-drift-time");
mVShapeScalingFac = ic.options().get<float>("v-shape-scaling-factor");
}

void run(ProcessingContext& pc) final
Expand Down Expand Up @@ -70,7 +71,9 @@ class TPCScalerSpec : public Task
pc.outputs().snapshot(Output{header::gDataOriginTPC, "TPCSCALER"}, meanScaler);

if (mEnableVShape) {
float vshapescaler = 123;
double tsMiddleTF = timestamp + o2::base::GRPGeomHelper::instance().getNHBFPerTF() / 2 * o2::constants::lhc::LHCOrbitMUS * 0.001;
float vshapescaler = mVShapeScalingFac * mVShapeTPCScaler.getScaler(tsMiddleTF);
LOGP(info, "Publishing TPC V-shape scaler: {} for timestamp {} firstTFOrbit: {}", vshapescaler, long(timestamp), firstTFOrbit);
pc.outputs().snapshot(Output{header::gDataOriginTPC, "TPCVShapeScaler"}, vshapescaler);
}
}
Expand All @@ -95,6 +98,7 @@ class TPCScalerSpec : public Task
std::shared_ptr<o2::base::GRPGeomRequest> mCCDBRequest; ///< info for CCDB request
const bool mEnableVShape{}; ///< enable v shape scalers
float mIonDriftTimeMS{-1}; ///< ion drift time
float mVShapeScalingFac{0}; ///< scale v-shape scalers with this value
TPCScaler mTPCScaler; ///< tpc scaler
TPCVShapeScaler mVShapeTPCScaler; ///< TPC V-shape scalers
};
Expand All @@ -108,7 +112,7 @@ o2::framework::DataProcessorSpec getTPCScalerSpec(bool enableVShape)
}

auto ccdbRequest = std::make_shared<o2::base::GRPGeomRequest>(true, // orbitResetTime
false, // GRPECS=true for nHBF per TF
enableVShape, // GRPECS=true for nHBF per TF
false, // GRPLHCIF
false, // GRPMagField
false, // askMatLUT
Expand All @@ -117,14 +121,18 @@ o2::framework::DataProcessorSpec getTPCScalerSpec(bool enableVShape)

std::vector<OutputSpec> outputs;
outputs.emplace_back(o2::header::gDataOriginTPC, "TPCSCALER", 0, Lifetime::Timeframe);
if (enableVShape) {
outputs.emplace_back(o2::header::gDataOriginTPC, "TPCVShapeScaler", 0, Lifetime::Timeframe);
}

return DataProcessorSpec{
"tpc-scaler",
inputs,
outputs,
AlgorithmSpec{adaptFromTask<TPCScalerSpec>(ccdbRequest, enableVShape)},
Options{
{"ion-drift-time", VariantType::Float, -1.f, {"Overwrite ion drift time if a value >0 is provided"}}}};
{"ion-drift-time", VariantType::Float, -1.f, {"Overwrite ion drift time if a value >0 is provided"}},
{"v-shape-scaling-factor", VariantType::Float, 1.f, {"Scale V-shape scaler with this value"}}}};
}

} // namespace tpc
Expand Down
7 changes: 4 additions & 3 deletions Detectors/TPC/workflow/src/TPCTimeSeriesSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1288,14 +1288,15 @@ class TPCTimeSeries : public Task

void sendOutput(ProcessingContext& pc)
{
const long timeMS = o2::base::GRPGeomHelper::instance().getOrbitResetTimeMS() + processing_helpers::getFirstTForbit(pc) * o2::constants::lhc::LHCOrbitMUS / 1000;
mBufferDCA.mTSTPC.setStartTime(timeMS);
mBufferDCA.mTSITSTPC.setStartTime(timeMS);

pc.outputs().snapshot(Output{header::gDataOriginTPC, getDataDescriptionTimeSeries()}, mBufferDCA);
// in case of ROOT output also store the TFinfo in the TTree
if (!mDisableWriter) {
o2::dataformats::TFIDInfo tfinfo;
o2::base::TFIDInfoHelper::fillTFIDInfo(pc, tfinfo);
const long timeMS = o2::base::GRPGeomHelper::instance().getOrbitResetTimeMS() + processing_helpers::getFirstTForbit(pc) * o2::constants::lhc::LHCOrbitMUS / 1000;
mBufferDCA.mTSTPC.setStartTime(timeMS);
mBufferDCA.mTSITSTPC.setStartTime(timeMS);
pc.outputs().snapshot(Output{header::gDataOriginTPC, getDataDescriptionTPCTimeSeriesTFId()}, tfinfo);
}
}
Expand Down
1 change: 1 addition & 0 deletions GPU/GPUTracking/DataTypes/GPUDataTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ template <template <typename T> class S>
struct GPUCalibObjectsTemplate { // use only pointers on PODs or flat objects here
typename S<TPCFastTransform>::type* fastTransform = nullptr;
typename S<TPCFastTransform>::type* fastTransformRef = nullptr;
typename S<TPCFastTransform>::type* fastTransformVShape = nullptr;
typename S<CorrectionMapsHelper>::type* fastTransformHelper = nullptr;
typename S<o2::base::MatLayerCylSet>::type* matLUT = nullptr;
typename S<o2::trd::GeometryFlat>::type* trdGeometry = nullptr;
Expand Down
3 changes: 2 additions & 1 deletion GPU/TPCFastTransformation/CorrectionMapsHelper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void CorrectionMapsHelper::clear()
mInstLumi = 0.f;
mMeanLumi = 0.f;
mMeanLumiRef = 0.f;
mVShapeScaler = 0.f;
}

void CorrectionMapsHelper::setOwner(bool v)
Expand Down Expand Up @@ -97,5 +98,5 @@ void CorrectionMapsHelper::setCorrMapVShape(std::unique_ptr<TPCFastTransform>&&
//________________________________________________________
void CorrectionMapsHelper::reportScaling()
{
LOGP(info, "Map scaling update: InstLumiOverride={}, LumiScaleType={} -> instLumi={}, meanLumi={} -> LumiScale={}, lumiScaleMode={}", getInstLumiOverride(), getLumiScaleType(), getInstLumi(), getMeanLumi(), getLumiScale(), getLumiScaleMode());
LOGP(info, "Map scaling update: InstLumiOverride={}, LumiScaleType={} -> instLumi={}, meanLumi={} -> LumiScale={}, lumiScaleMode={}, mVShapeScaler={}", getInstLumiOverride(), getLumiScaleType(), getInstLumi(), getMeanLumi(), getLumiScale(), getLumiScaleMode(), getVShapeScaler());
}
28 changes: 23 additions & 5 deletions GPU/TPCFastTransformation/CorrectionMapsHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,27 @@ class CorrectionMapsHelper

GPUd() void Transform(int slice, int row, float pad, float time, float& x, float& y, float& z, float vertexTime = 0) const
{
mCorrMap->Transform(slice, row, pad, time, x, y, z, vertexTime, mCorrMapRef, mLumiScale, mLumiScaleMode);
mCorrMap->Transform(slice, row, pad, time, x, y, z, vertexTime, mCorrMapRef, mCorrMapVShape, mLumiScale, mVShapeScaler, mLumiScaleMode);
}

GPUd() void TransformXYZ(int slice, int row, float& x, float& y, float& z) const
{
mCorrMap->TransformXYZ(slice, row, x, y, z, mCorrMapRef, mLumiScale, mLumiScaleMode);
mCorrMap->TransformXYZ(slice, row, x, y, z, mCorrMapRef, mCorrMapVShape, mLumiScale, mVShapeScaler, mLumiScaleMode);
}

GPUd() void InverseTransformYZtoX(int slice, int row, float y, float z, float& x) const
{
mCorrMap->InverseTransformYZtoX(slice, row, y, z, x, mCorrMapRef, mLumiScale, mLumiScaleMode);
mCorrMap->InverseTransformYZtoX(slice, row, y, z, x, mCorrMapRef, mCorrMapVShape, mLumiScale, mVShapeScaler, mLumiScaleMode);
}

GPUd() void InverseTransformYZtoNominalYZ(int slice, int row, float y, float z, float& ny, float& nz) const
{
mCorrMap->InverseTransformYZtoNominalYZ(slice, row, y, z, ny, nz, mCorrMapRef, mLumiScale, mLumiScaleMode);
mCorrMap->InverseTransformYZtoNominalYZ(slice, row, y, z, ny, nz, mCorrMapRef, mCorrMapVShape, mLumiScale, mVShapeScaler, mLumiScaleMode);
}

GPUd() const GPUCA_NAMESPACE::gpu::TPCFastTransform* getCorrMap() const { return mCorrMap; }
GPUd() const GPUCA_NAMESPACE::gpu::TPCFastTransform* getCorrMapRef() const { return mCorrMapRef; }
GPUd() const GPUCA_NAMESPACE::gpu::TPCFastTransform* getCorrMapVShape() const { return mCorrMapVShape; }

bool getOwner() const { return mOwner; }

Expand Down Expand Up @@ -112,19 +113,31 @@ class CorrectionMapsHelper
}
}

void setVShapeScaler(float v, bool report = true)
{
mVShapeScaler = v;
if (report) {
reportScaling();
}
}

GPUd() float getInstLumi() const { return mInstLumi; }
GPUd() float getMeanLumi() const { return mMeanLumi; }
GPUd() float getMeanLumiRef() const { return mMeanLumiRef; }

GPUd() float getLumiScale() const { return mLumiScale; }
GPUd() int getLumiScaleMode() const { return mLumiScaleMode; }

GPUd() float getVShapeScaler() const { return mVShapeScaler; }

bool isUpdated() const { return mUpdatedFlags != 0; }
bool isUpdatedMap() const { return (mUpdatedFlags & UpdateFlags::MapBit) != 0; }
bool isUpdatedMapRef() const { return (mUpdatedFlags & UpdateFlags::MapRefBit) != 0; }
bool isUpdatedMapVShape() const { return (mUpdatedFlags & UpdateFlags::MapVShapeBit) != 0; }
bool isUpdatedLumi() const { return (mUpdatedFlags & UpdateFlags::LumiBit) != 0; }
void setUpdatedMap() { mUpdatedFlags |= UpdateFlags::MapBit; }
void setUpdatedMapRef() { mUpdatedFlags |= UpdateFlags::MapRefBit; }
void setUpdatedMapVShape() { mUpdatedFlags |= UpdateFlags::MapVShapeBit; }
void setUpdatedLumi() { mUpdatedFlags |= UpdateFlags::LumiBit; }

#if !defined(GPUCA_GPUCODE_DEVICE) && defined(GPUCA_NOCOMPAT)
Expand All @@ -137,6 +150,8 @@ class CorrectionMapsHelper

void setLumiScaleType(int v) { mLumiScaleType = v; }
int getLumiScaleType() const { return mLumiScaleType; }
void enableVShapeCorrection(bool v) { mEnableVShape = v; }
bool getUseVShapeCorrection() const { return mEnableVShape; }

void setMeanLumiOverride(float f) { mMeanLumiOverride = f; }
void setMeanLumiRefOverride(float f) { mMeanLumiRefOverride = f; }
Expand All @@ -151,7 +166,8 @@ class CorrectionMapsHelper
protected:
enum UpdateFlags { MapBit = 0x1,
MapRefBit = 0x2,
LumiBit = 0x4 };
LumiBit = 0x4,
MapVShapeBit = 0x10 };
bool mOwner = false; // is content of pointers owned by the helper
int mLumiScaleType = 0; // require CTP Lumi for mInstLumi
int mUpdatedFlags = 0;
Expand All @@ -163,6 +179,8 @@ class CorrectionMapsHelper
float mMeanLumiOverride = -1.f; // optional value to override mean lumi
float mMeanLumiRefOverride = -1.f; // optional value to override ref mean lumi
float mInstLumiOverride = -1.f; // optional value to override inst lumi
bool mEnableVShape = false; ///< use v shape correction
float mVShapeScaler = 0; // scaling value for V-shape distortions
GPUCA_NAMESPACE::gpu::TPCFastTransform* mCorrMap{nullptr}; // current transform
GPUCA_NAMESPACE::gpu::TPCFastTransform* mCorrMapRef{nullptr}; // reference transform
GPUCA_NAMESPACE::gpu::TPCFastTransform* mCorrMapVShape{nullptr}; // correction map for v-shape distortions on A-side
Expand Down
Loading

0 comments on commit 70e0076

Please sign in to comment.