Skip to content

Commit

Permalink
Calculating spline object in TPCScalerSpec (crashing)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-kleiner committed Jan 13, 2024
1 parent bad9c30 commit 672f30b
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 48 deletions.
43 changes: 7 additions & 36 deletions Detectors/TPC/calibration/src/CorrectionMapsLoader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -69,43 +69,14 @@ void CorrectionMapsLoader::extractCCDBInputs(ProcessingContext& pc)
setInstLumi(mInstLumiFactor * tpcScaler, !getUseMShapeCorrection());
}
if (getUseMShapeCorrection()) {
auto mshapescaler = pc.inputs().get<dataformats::Pair<float, float>>("mshape");
float potential = mshapescaler.first;
float deltaPotPos = mshapescaler.second;
// setMShapeScaler(potential);
auto mapMShape = pc.inputs().get<o2::gpu::TPCFastTransform*>("mshape");
static int counter = 0;
LOGP(info, "Set MSHape map");
setCorrMapMShape(std::move(o2::tpc::TPCFastTransformHelperO2::instance()->create(0)));
// setCorrMapMShape(const_cast<o2::gpu::TPCFastTransform*>(mapMShape.get()));
mCorrMapMShape->rectifyAfterReadingFromFile();
setUpdatedMapMShape();
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!
const int nthreads = 5;
using namespace o2::tpc;
o2::tpc::SpaceCharge<double>::setNThreads(nthreads);
const Side side = Side::A;
int field = 5;
o2::tpc::SpaceCharge<double> sc = o2::tpc::SpaceCharge<double>(field, 129, 129, 5);

sc.setIFCChargeUpFallingPot(potential, deltaPotPos, 0, 250, 0, side);
sc.setIFCChargeUpRisingPot(potential, deltaPotPos, 0, 0, 0, side);

sc.poissonSolver(side);
sc.calcEField(side);
const auto numEFields = sc.getElectricFieldsInterpolator(side);
sc.calcGlobalCorrections(numEFields);

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

TPCFastSpaceChargeCorrectionHelper::instance()->setNthreads(nthreads);
const int nKnotsY = 4;
const int nKnotsZ = 4;
std::unique_ptr<TPCFastSpaceChargeCorrection> spCorrection = TPCFastSpaceChargeCorrectionHelper::instance()->createFromGlobalCorrection(getCorrections, nKnotsY, nKnotsZ);
std::unique_ptr<TPCFastTransform> fastTransform(TPCFastTransformHelperO2::instance()->create(0, *spCorrection));
LOGP(info, "Setting M-shape correction from calculated model");
setCorrMapMShape(std::move(fastTransform));
setUpdatedMapMShape();
}
}
// update inverse in case it is requested
if (!mScaleInverse) {
Expand Down
54 changes: 49 additions & 5 deletions Detectors/TPC/workflow/src/TPCScalerSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "TPCCalibration/TPCMShapeScaler.h"
#include "CommonDataFormat/Pair.h"
#include "TTree.h"
#include "TPCCalibration/TPCFastSpaceChargeCorrectionHelper.h"
#include "TPCSpaceCharge/SpaceCharge.h"

using namespace o2::framework;

Expand Down Expand Up @@ -82,11 +84,53 @@ class TPCScalerSpec : public Task
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 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});

float potential = 0;
float deltaPotPos = 150;
// setMShapeScaler(potential);
LOGP(info, "Recalculating M-shape correction map for z position of delta potential {}", deltaPotPos);
// update analytical map!
const int nthreads = 5;
using namespace o2::tpc;
o2::tpc::SpaceCharge<double>::setNThreads(nthreads);
const Side side = Side::A;
int field = 5;
o2::tpc::SpaceCharge<double> sc = o2::tpc::SpaceCharge<double>(field, 129, 129, 5);

if (potential != 0) {
sc.setIFCChargeUpFallingPot(potential, deltaPotPos, 0, 250, 0, side);
sc.setIFCChargeUpRisingPot(potential, deltaPotPos, 0, 0, 0, side);

sc.poissonSolver(side);
sc.calcEField(side);
const auto numEFields = sc.getElectricFieldsInterpolator(side);
sc.calcGlobalCorrections(numEFields);
}

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

TPCFastSpaceChargeCorrectionHelper::instance()->setNthreads(nthreads);
const int nKnotsY = 4;
const int nKnotsZ = 4;
// std::unique_ptr<TPCFastSpaceChargeCorrection> spCorrection = TPCFastSpaceChargeCorrectionHelper::instance()->createFromGlobalCorrection(getCorrections, nKnotsY, nKnotsZ);
// std::unique_ptr<TPCFastTransform> fastTransform(TPCFastTransformHelperO2::instance()->create(0, *spCorrection));
std::unique_ptr<TPCFastTransform> fastTransform(TPCFastTransformHelperO2::instance()->create(0));
pc.outputs().snapshot(Output{header::gDataOriginTPC, "TPCMShapeScaler"}, *fastTransform);

// const auto scalers = mMShapeTPCScaler.getScaler(timestamp);
// float mshapescaler = mMShapeScalingFac * scalers.first;
// float zPos = scalers.first;
// LOGP(info, "Publishing TPC M-shape scaler: {} for zMax: {} timestamp {}, firstTFOrbit: {} with MShapeScalingFac: {}", mshapescaler, zPos, long(timestamp), firstTFOrbit, mMShapeScalingFac);
// pc.outputs().snapshot(Output{header::gDataOriginTPC, "TPCMShapeScaler"}, dataformats::Pair<float, float>{mshapescaler, zPos});
}
}

Expand Down
9 changes: 5 additions & 4 deletions GPU/TPCFastTransformation/CorrectionMapsHelper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ void CorrectionMapsHelper::clear()
if (mOwner) {
delete mCorrMap;
delete mCorrMapRef;
delete mCorrMapMShape;
// delete mCorrMapMShape;
}
delete mCorrMapMShape;
mCorrMap = nullptr;
mCorrMapRef = nullptr;
mCorrMapMShape = nullptr;
Expand Down Expand Up @@ -89,9 +90,9 @@ void CorrectionMapsHelper::setCorrMapRef(std::unique_ptr<TPCFastTransform>&& m)

void CorrectionMapsHelper::setCorrMapMShape(std::unique_ptr<TPCFastTransform>&& m)
{
if (!mOwner) {
throw std::runtime_error("we must not take the ownership from a unique ptr if mOwner is not set");
}
// if (!mOwner) {
// throw std::runtime_error("we must not take the ownership from a unique ptr if mOwner is not set");
// }
delete mCorrMapMShape;
mCorrMapMShape = m.release();
}
Expand Down
6 changes: 6 additions & 0 deletions GPU/TPCFastTransformation/TPCFastTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ class TPCFastTransform : public FlatObject
/// Assignment operator: disabled to avoid ambiguity. Use cloneFromObject() instead
TPCFastTransform& operator=(const TPCFastTransform&) CON_DELETE;

inline void destroy()
{
mCorrection.destroy();
FlatObject::destroy();
}

/// Destructor
#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) && defined(GPUCA_O2_LIB)
~TPCFastTransform()
Expand Down
9 changes: 6 additions & 3 deletions GPU/Utils/FlatObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "GPUCommonRtypes.h"
#include "GPUCommonLogger.h"

//#define GPUCA_GPUCODE // uncomment to test "GPU" mode
// #define GPUCA_GPUCODE // uncomment to test "GPU" mode

namespace GPUCA_NAMESPACE
{
Expand Down Expand Up @@ -132,7 +132,10 @@ T* resizeArray(T*& ptr, int oldSize, int newSize, T* newPtr = nullptr)
newPtr = new T[newSize];
}
int mcp = std::min(newSize, oldSize);
std::memmove(newPtr, ptr, mcp * sizeof(T));
if (mcp) {
assert(ptr);
std::memmove(newPtr, ptr, mcp * sizeof(T));
}
if (newSize > oldSize) {
std::memset(newPtr + mcp, 0, (newSize - oldSize) * sizeof(T));
}
Expand Down Expand Up @@ -564,7 +567,7 @@ inline void FlatObject::setFutureBufferAddress(char* futureFlatBufferPtr)
mFlatBufferContainer = nullptr;
}

#endif //GPUCA_GPUCODE_DEVICE
#endif // GPUCA_GPUCODE_DEVICE

} // namespace gpu
} // namespace GPUCA_NAMESPACE
Expand Down

0 comments on commit 672f30b

Please sign in to comment.