Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-kleiner committed Jan 12, 2024
1 parent 8ed5bbf commit bad9c30
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class TPCFastSpaceChargeCorrectionHelper
void initInverse(o2::gpu::TPCFastSpaceChargeCorrection& correction, bool prn);

/// initialise inverse transformation from linear combination of several input corrections
void initInverse(std::vector<o2::gpu::TPCFastSpaceChargeCorrection*>& corrections, const std::vector<float> scaling, bool prn);
void initInverse(std::vector<o2::gpu::TPCFastSpaceChargeCorrection*>& corrections, const std::vector<float>& scaling, bool prn);

private:
/// geometry initialization
Expand Down
10 changes: 5 additions & 5 deletions Detectors/TPC/calibration/src/CorrectionMapsLoader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ void CorrectionMapsLoader::extractCCDBInputs(ProcessingContext& pc)
auto mshapescaler = pc.inputs().get<dataformats::Pair<float, float>>("mshape");
float potential = mshapescaler.first;
float deltaPotPos = mshapescaler.second;
setMShapeScaler(potential);
// setMShapeScaler(potential);
setMShapeScaler(1); // not needed or as some custom scaling
if (potential != 0) {
LOGP(info, "Recalculating M-shape correction map for z position of delta potential {}", deltaPotPos);
// update analytical map!
Expand All @@ -81,11 +82,10 @@ void CorrectionMapsLoader::extractCCDBInputs(ProcessingContext& pc)
o2::tpc::SpaceCharge<double>::setNThreads(nthreads);
const Side side = Side::A;
int field = 5;
o2::tpc::SpaceCharge<double> sc = o2::tpc::SpaceCharge<double>(field, 257, 257, 45);
o2::tpc::SpaceCharge<double> sc = o2::tpc::SpaceCharge<double>(field, 129, 129, 5);

float deltaPot = 100;
sc.setIFCChargeUpFallingPot(deltaPot, deltaPotPos, 0, 250, 0, side); // 1/x
sc.setIFCChargeUpRisingPot(deltaPot, deltaPotPos, 0, 0, 0, side);
sc.setIFCChargeUpFallingPot(potential, deltaPotPos, 0, 250, 0, side);
sc.setIFCChargeUpRisingPot(potential, deltaPotPos, 0, 0, 0, side);

sc.poissonSolver(side);
sc.calcEField(side);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ void TPCFastSpaceChargeCorrectionHelper::initInverse(o2::gpu::TPCFastSpaceCharge
initInverse(corr, std::vector<float>{1}, prn);
}

void TPCFastSpaceChargeCorrectionHelper::initInverse(std::vector<o2::gpu::TPCFastSpaceChargeCorrection*>& corrections, const std::vector<float> scaling, bool prn)
void TPCFastSpaceChargeCorrectionHelper::initInverse(std::vector<o2::gpu::TPCFastSpaceChargeCorrection*>& corrections, const std::vector<float>& scaling, bool prn)
{
/// initialise inverse transformation
TStopwatch watch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void createTPCSpaceChargeCorrectionAnalytical(
const int debug = 0)
{
// initialize space-charge object
spaceCharge = std::make_unique<SC>();
spaceCharge = std::make_unique<SC>(5, 129, 129, 5);

// default analytical formulas for distortions and corrections
AnalyticalDistCorr<double> formula;
Expand All @@ -223,17 +223,45 @@ void createTPCSpaceChargeCorrectionAnalytical(
formula.mDlZFormula = mDistZ;
*/

spaceCharge->setDistortionsCorrectionsAnalytical(formula);
spaceCharge->setUseAnalyticalDistCorr(true);
// spaceCharge->setDistortionsCorrectionsAnalytical(formula);
// spaceCharge->setUseAnalyticalDistCorr(true);

// dumping the space-charge object to file to apply it during the TPC digitizer simulation
TFile fSC("distortions_analytical.root", "RECREATE");
spaceCharge->dumpAnalyticalCorrectionsDistortions(fSC);
// TFile fSC("distortions_analytical.root", "RECREATE");
// spaceCharge->dumpAnalyticalCorrectionsDistortions(fSC);

float deltaPot = 100;
float deltaPotPos = 240;
int nthreads = 10;
spaceCharge->setIFCChargeUpFallingPot(deltaPot, deltaPotPos, 0, 250, 0, Side::A); // 1/x
spaceCharge->setIFCChargeUpRisingPot(deltaPot, deltaPotPos, 0, 0, 0, Side::A);

spaceCharge->poissonSolver(Side::A);
spaceCharge->calcEField(Side::A);
const auto numEFields = spaceCharge->getElectricFieldsInterpolator(Side::A);
spaceCharge->calcGlobalCorrections(numEFields);

std::function<void(int, double, double, double, double&, double&, double&)> getCorrections = [&spaceCharge = spaceCharge](const int roc, double x, double y, double z, double& dx, double& dy, double& dz) {
Side side = roc < 18 ? Side::A : Side::C;
if (side == Side::A) {
spaceCharge->getCorrections(x, y, z, side, dx, dy, dz);
} else {
dx = 1.2;
dy = 1.2;
dz = 1.2;
}
};

TPCFastSpaceChargeCorrectionHelper::instance()->setNthreadsToMaximum();
std::unique_ptr<TPCFastSpaceChargeCorrection> spCorrection = TPCFastSpaceChargeCorrectionHelper::instance()->createFromLocalCorrection(getLocalSpaceChargeCorrection);
TPCFastSpaceChargeCorrectionHelper::instance()->setNthreads(nthreads);
const int nKnotsY = 5;
const int nKnotsZ = 5;
std::unique_ptr<TPCFastSpaceChargeCorrection> spCorrection = TPCFastSpaceChargeCorrectionHelper::instance()->createFromGlobalCorrection(getCorrections, nKnotsY, nKnotsZ);
std::unique_ptr<TPCFastTransform> fastTransform(TPCFastTransformHelperO2::instance()->create(0, *spCorrection));

// TPCFastSpaceChargeCorrectionHelper::instance()->setNthreadsToMaximum();
// std::unique_ptr<TPCFastSpaceChargeCorrection> spCorrection = TPCFastSpaceChargeCorrectionHelper::instance()->createFromLocalCorrection(getLocalSpaceChargeCorrection);
// std::unique_ptr<TPCFastTransform> fastTransform(TPCFastTransformHelperO2::instance()->create(0, *spCorrection));

fastTransform->writeToFile(outputFileName, "ccdb_object");

if (debug > 0) {
Expand Down Expand Up @@ -397,8 +425,8 @@ void debugInterpolation(utils::TreeStreamRedirector& pcstream,
const o2::gpu::TPCFastTransformGeo& geo,
TPCFastTransform* fastTransform)
{
for (int slice = 0; slice < geo.getNumberOfSlices(); slice += 1) {
// for (int slice = 21; slice < 22; slice += 1) {
// for (int slice = 0; slice < geo.getNumberOfSlices(); slice += 1) {
for (int slice = 17; slice < 18; slice += 1) {
std::cout << "debug slice " << slice << " ... " << std::endl;
const o2::gpu::TPCFastTransformGeo::SliceInfo& sliceInfo = geo.getSliceInfo(slice);

Expand Down
53 changes: 26 additions & 27 deletions Detectors/TPC/workflow/src/TPCScalerSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TPCScalerSpec : public Task
o2::base::GRPGeomHelper::instance().setRequest(mCCDBRequest);
mIonDriftTimeMS = ic.options().get<float>("ion-drift-time");
mMaxTimeWeightsMS = ic.options().get<float>("max-time-for-weights");
mVShapeScalingFac = ic.options().get<float>("v-shape-scaling-factor");
mMShapeScalingFac = ic.options().get<float>("m-shape-scaling-factor");
mEnableWeights = !(ic.options().get<bool>("disableWeights"));
}

Expand All @@ -54,24 +54,23 @@ class TPCScalerSpec : public Task
pc.inputs().get<TTree*>("tpcscaler");
}

if (mEnableWeights) {
if (mEnableWeights && mEnableIDCs) {
if (pc.inputs().isValid("tpcscalerw")) {
pc.inputs().get<TPCScalerWeights*>("tpcscalerw");
}
}
if (mEnableMShape && pc.inputs().isValid("vshape")) {
pc.inputs().get<TTree*>("vshape");
}

if (pc.services().get<o2::framework::TimingInfo>().runNumber != mTPCScaler.getRun()) {
LOGP(error, "Run number {} of processed data and run number {} of loaded TPC scaler doesnt match!", pc.services().get<o2::framework::TimingInfo>().runNumber, mTPCScaler.getRun());
if (mEnableMShape && pc.inputs().isValid("mshape")) {
pc.inputs().get<TTree*>("mshape");
}

const auto orbitResetTimeMS = o2::base::GRPGeomHelper::instance().getOrbitResetTimeMS();
const auto firstTFOrbit = pc.services().get<o2::framework::TimingInfo>().firstTForbit;
const double timestamp = orbitResetTimeMS + firstTFOrbit * o2::constants::lhc::LHCOrbitMUS * 0.001;

if (mEnableIDCs) {
if (pc.services().get<o2::framework::TimingInfo>().runNumber != mTPCScaler.getRun()) {
LOGP(error, "Run number {} of processed data and run number {} of loaded TPC scaler doesnt match!", pc.services().get<o2::framework::TimingInfo>().runNumber, mTPCScaler.getRun());
}
float scalerA = mTPCScaler.getMeanScaler(timestamp, o2::tpc::Side::A);
float scalerC = mTPCScaler.getMeanScaler(timestamp, o2::tpc::Side::C);
float meanScaler = (scalerA + scalerC) / 2;
Expand All @@ -80,16 +79,14 @@ class TPCScalerSpec : public Task
}

if (mEnableMShape) {
// 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: {} with VShapeScalingFac: {}", vshapescaler, long(timestamp), firstTFOrbit, mVShapeScalingFac);
// // pc.outputs().snapshot(Output{header::gDataOriginTPC, "TPCMShapeScaler"}, vshapescaler);
double tsMiddleTF = timestamp + o2::base::GRPGeomHelper::instance().getNHBFPerTF() / 2 * o2::constants::lhc::LHCOrbitMUS * 0.001;
const auto scalers = mVShapeTPCScaler.getScaler(tsMiddleTF);
float vshapescaler = mVShapeScalingFac * scalers.first;
if (pc.services().get<o2::framework::TimingInfo>().runNumber != mMShapeTPCScaler.getRun()) {
LOGP(error, "Run number {} of processed data and run number {} of loaded TPC M-shape scaler doesnt match!", pc.services().get<o2::framework::TimingInfo>().runNumber, mMShapeTPCScaler.getRun());
}
const auto scalers = mMShapeTPCScaler.getScaler(timestamp);
float mshapescaler = mMShapeScalingFac * scalers.first;
float zPos = scalers.first;
LOGP(info, "Publishing TPC V-shape scaler: {} for timestamp {}, firstTFOrbit: {} with VShapeScalingFac: {}", vshapescaler, long(timestamp), firstTFOrbit, mVShapeScalingFac);
pc.outputs().snapshot(Output{header::gDataOriginTPC, "TPCMShapeScaler"}, dataformats::Pair<float, float>{vshapescaler, zPos});
LOGP(info, "Publishing TPC M-shape scaler: {} for timestamp {}, firstTFOrbit: {} with MShapeScalingFac: {}", mshapescaler, long(timestamp), firstTFOrbit, mMShapeScalingFac);
pc.outputs().snapshot(Output{header::gDataOriginTPC, "TPCMShapeScaler"}, dataformats::Pair<float, float>{mshapescaler, zPos});
}
}

Expand Down Expand Up @@ -121,9 +118,9 @@ class TPCScalerSpec : public Task
if (mIonDriftTimeMS == -1) {
overWriteIntegrationTime();
}
} else if (matcher == ConcreteDataMatcher(o2::header::gDataOriginTPC, "VSHAPESCALERCCDB", 0)) {
LOGP(info, "Updating V-shape TPC scaler");
mVShapeTPCScaler.setFromTree(*((TTree*)obj));
} else if (matcher == ConcreteDataMatcher(o2::header::gDataOriginTPC, "MSHAPESCALERCCDB", 0)) {
LOGP(info, "Updating M-shape TPC scaler");
mMShapeTPCScaler.setFromTree(*((TTree*)obj));
}
}

Expand All @@ -136,8 +133,8 @@ class TPCScalerSpec : public Task
float mIonDriftTimeMS{-1}; ///< ion drift time
float mMaxTimeWeightsMS{500}; ///< maximum integration time when weights are used
TPCScaler mTPCScaler; ///< tpc scaler
float mVShapeScalingFac{0}; ///< scale v-shape scalers with this value
TPCMShapeScaler mVShapeTPCScaler; ///< TPC V-shape scalers
float mMShapeScalingFac{0}; ///< scale m-shape scalers with this value
TPCMShapeScaler mMShapeTPCScaler; ///< TPC M-shape scalers

void overWriteIntegrationTime()
{
Expand All @@ -162,20 +159,22 @@ o2::framework::DataProcessorSpec getTPCScalerSpec(bool enableIDCs, bool enableMS
inputs.emplace_back("tpcscalerw", o2::header::gDataOriginTPC, "TPCSCALERWCCDB", 0, Lifetime::Condition, ccdbParamSpec(o2::tpc::CDBTypeMap.at(o2::tpc::CDBType::CalScalerWeights), {}, 0)); // non time-dependent
}
if (enableMShape) {
LOGP(info, "Publishing V-shape scalers for V-shape distortion fluctuation correction");
inputs.emplace_back("vshape", o2::header::gDataOriginTPC, "VSHAPESCALERCCDB", 0, Lifetime::Condition, ccdbParamSpec(o2::tpc::CDBTypeMap.at(o2::tpc::CDBType::CalMShape), {}, 1)); // time-dependent
LOGP(info, "Publishing M-shape scalers for M-shape distortion fluctuation correction");
inputs.emplace_back("mshape", o2::header::gDataOriginTPC, "MSHAPESCALERCCDB", 0, Lifetime::Condition, ccdbParamSpec(o2::tpc::CDBTypeMap.at(o2::tpc::CDBType::CalMShape), {}, 1)); // time-dependent
}

auto ccdbRequest = std::make_shared<o2::base::GRPGeomRequest>(true, // orbitResetTime
enableMShape, // GRPECS=true for nHBF per TF
false, // GRPECS=true for nHBF per TF
false, // GRPLHCIF
false, // GRPMagField
false, // askMatLUT
o2::base::GRPGeomRequest::None, // geometry
inputs);

std::vector<OutputSpec> outputs;
outputs.emplace_back(o2::header::gDataOriginTPC, "TPCSCALER", 0, Lifetime::Timeframe);
if (enableIDCs) {
outputs.emplace_back(o2::header::gDataOriginTPC, "TPCSCALER", 0, Lifetime::Timeframe);
}
if (enableMShape) {
outputs.emplace_back(o2::header::gDataOriginTPC, "TPCMShapeScaler", 0, Lifetime::Timeframe);
}
Expand All @@ -188,7 +187,7 @@ o2::framework::DataProcessorSpec getTPCScalerSpec(bool enableIDCs, bool enableMS
Options{
{"ion-drift-time", VariantType::Float, -1.f, {"Overwrite ion drift time if a value >0 is provided"}},
{"max-time-for-weights", VariantType::Float, 500.f, {"Maximum possible integration time in ms when weights are used"}},
{"v-shape-scaling-factor", VariantType::Float, 1.f, {"Scale V-shape scaler with this value"}},
{"m-shape-scaling-factor", VariantType::Float, 1.f, {"Scale M-shape scaler with this value"}},
{"disableWeights", VariantType::Bool, false, {"Disable weights for TPC scalers"}}}};
}

Expand Down
3 changes: 1 addition & 2 deletions Detectors/TPC/workflow/src/tpc-scaler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
std::vector<ConfigParamSpec> options{
ConfigParamSpec{"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings"}},
{"enable-M-shape-correction", VariantType::Bool, false, {"Enable M-shape distortion correction"}},
{"disable-IDC-scalers", VariantType::Bool, false, {"Disable TPC scalers for space-charge distortion fluctuation correction"}},
{"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings"}}};
{"disable-IDC-scalers", VariantType::Bool, false, {"Disable TPC scalers for space-charge distortion fluctuation correction"}}};

std::swap(workflowOptions, options);
}
Expand Down

0 comments on commit bad9c30

Please sign in to comment.