From 05dbbb2aaa125f0c1c1f6c60e4ff8ad65e3de3c4 Mon Sep 17 00:00:00 2001 From: tubagundem Date: Mon, 30 Nov 2026 17:12:59 +0100 Subject: [PATCH] TPC_MC: dEdx transfer function correction in the simulation --- .../base/include/TPCBase/ParameterDetector.h | 2 + .../include/TPCSimulation/Detector.h | 1 + Detectors/TPC/simulation/src/Detector.cxx | 40 +++++++++++++++++-- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/Detectors/TPC/base/include/TPCBase/ParameterDetector.h b/Detectors/TPC/base/include/TPCBase/ParameterDetector.h index 9daaff9c7c9ff..3145dc8dd8e40 100644 --- a/Detectors/TPC/base/include/TPCBase/ParameterDetector.h +++ b/Detectors/TPC/base/include/TPCBase/ParameterDetector.h @@ -35,6 +35,8 @@ struct ParameterDetector : public o2::conf::ConfigurableParamHelper= 1 O2ParamDef(ParameterDetector, "TPCDetParam"); }; diff --git a/Detectors/TPC/simulation/include/TPCSimulation/Detector.h b/Detectors/TPC/simulation/include/TPCSimulation/Detector.h index d937f2054383c..e2d6d238a916a 100644 --- a/Detectors/TPC/simulation/include/TPCSimulation/Detector.h +++ b/Detectors/TPC/simulation/include/TPCSimulation/Detector.h @@ -157,6 +157,7 @@ class Detector : public o2::base::DetImpl int mElectronCounter = 0; int mStepCounter = 0; double mLastReferenceR = 0; /// #include +#include #include "DetectorsBase/SimRandom.h" using std::cout; @@ -83,6 +84,7 @@ Detector::Detector(const Detector& rhs) mHitCounter(0), mElectronCounter(0), mStepCounter(0), + mBetheBlochMin(rhs.mBetheBlochMin), mGeoFileName(rhs.mGeoFileName) { for (int i = 0; i < Sector::MAXSECTOR; ++i) { @@ -105,6 +107,26 @@ void Detector::InitializeO2Detector() { // Define the list of sensitive volumes defineSensitiveVolumes(); + + // dE/dx transfer correction: R(x) = 1 + c ln(x), x = z^2 BB / BB_min in [1, xMax] + const auto& detParam = ParameterDetector::Instance(); + if (detParam.TransferLogSlope != 0.f) { + // minimum of the Bethe-Bloch parametrisation used by the ionisation model: scan in log(bg), bg 0.1 - 1e4 + const auto& bbPar = ParameterGas::Instance().BetheBlochParam; + mBetheBlochMin = 1.e30; + for (int i = 0; i <= 4000; ++i) { + const double bg = std::pow(10., -1. + 5. * i / 4000.); + mBetheBlochMin = std::min(mBetheBlochMin, BetheBlochAleph(bg, double(bbPar[0]), double(bbPar[1]), double(bbPar[2]), double(bbPar[3]), double(bbPar[4]))); + } + const double ratioAtMax = 1. + detParam.TransferLogSlope * std::log(std::max(detParam.TransferXMax, 1.f)); + if (!(mBetheBlochMin > 0.) || !(detParam.TransferXMax >= 1.f) || !(ratioAtMax > 0.)) { + LOG(fatal) << "TPC dE/dx transfer correction: invalid settings, BB_min = " << mBetheBlochMin << ", TransferXMax = " << detParam.TransferXMax + << " (must be >= 1), R(xMax) = " << ratioAtMax << " (must be > 0)"; + } + LOG(info) << "TPC dE/dx transfer correction ON: primary-collision rate divided by R(x) = 1 + " << detParam.TransferLogSlope + << " * ln(x), x = z^2 BB / BB_min clamped to [1, " << detParam.TransferXMax << "], BB_min = " << mBetheBlochMin + << ", R(xMax) = " << ratioAtMax; + } } Bool_t Detector::ProcessHits(FairVolume* vol) @@ -240,10 +262,20 @@ Bool_t Detector::ProcessHits(FairVolume* vol) numberOfElectrons = static_cast(fMC->Edep() / static_cast(gasParam.Wion)); } else { // ---| number of primary ionisations per cm (zero-length steps give no collisions) |--- - const double primaryElectronsPerCM = - gasParam.Nprim * BetheBlochAleph(static_cast(TMath::Max(betaGamma, minBetaGamma)), gasParam.BetheBlochParam[0], - gasParam.BetheBlochParam[1], gasParam.BetheBlochParam[2], - gasParam.BetheBlochParam[3], gasParam.BetheBlochParam[4]); + // float, as before: with the transfer correction off the product is bit-identical to the previous code + const float betheBloch = BetheBlochAleph(static_cast(TMath::Max(betaGamma, minBetaGamma)), gasParam.BetheBlochParam[0], + gasParam.BetheBlochParam[1], gasParam.BetheBlochParam[2], + gasParam.BetheBlochParam[3], gasParam.BetheBlochParam[4]); + double primaryElectronsPerCM = gasParam.Nprim * betheBloch; + + // ---| optional dE/dx transfer correction: divide by R(x) = 1 + c ln(x), x = z^2 BB / BB_min in [1, xMax] (default c = 0: off) |--- + // The reconstructed truncated-mean dE/dx / input rises with the ionisation (truncated-mean statistics); + // dividing the input by R makes the reconstructed dE/dx follow the input Bethe-Bloch. + if (detParam.TransferLogSlope != 0.f) { + const double xIon = trackCharge * trackCharge * betheBloch / mBetheBlochMin; + const double xClamped = std::min(std::max(xIon, 1.), static_cast(detParam.TransferXMax)); + primaryElectronsPerCM /= 1. + detParam.TransferLogSlope * std::log(xClamped); + } // ---| mean number of collisions and random for this event |--- const double meanNcoll = stepSize * trackCharge * trackCharge * primaryElectronsPerCM;