diff --git a/Detectors/TPC/simulation/include/TPCSimulation/Digitizer.h b/Detectors/TPC/simulation/include/TPCSimulation/Digitizer.h index 1c76dcaaeedd3..94ce8f6a9d8b1 100644 --- a/Detectors/TPC/simulation/include/TPCSimulation/Digitizer.h +++ b/Detectors/TPC/simulation/include/TPCSimulation/Digitizer.h @@ -118,10 +118,10 @@ class Digitizer /// \param nRBins number of grid points in r, must be (2**N)+1 void setUseSCDistortions(const SCDistortionType& distortionType, const TH3* hisInitialSCDensity); /// Enable the use of space-charge distortions and provide SpaceCharge object as input - /// \param spaceCharge unique pointer to spaceCharge object + /// \param spaceCharge spaceCharge object, not owned: the caller (e.g. the DPL CCDB cache) keeps it alive void setUseSCDistortions(SC* spaceCharge); - /// \param spaceCharge unique pointer to spaceCharge object + /// \param spaceCharge spaceCharge object of the derivative map, not owned: the caller keeps it alive void setSCDistortionsDerivative(SC* spaceCharge); /// Enable the use of space-charge distortions by providing global distortions and global corrections stored in a ROOT file @@ -142,20 +142,21 @@ class Digitizer void recalculateDistortions(); private: - DigitContainer mDigitContainer; ///< Container for the Digits - std::unique_ptr mSpaceCharge; ///< Handler of full distortions (static + IR dependant) - std::unique_ptr mSpaceChargeDer; ///< Handler of reference static distortions - Sector mSector = -1; ///< ID of the currently processed sector - double mEventTime = 0.f; ///< Time of the currently processed event - double mOutputDigitTimeOffset = 0; ///< Time of the first IR sampled in the digitizer - float mVDrift = 0; ///< VDrift for current timestamp - float mTDriftOffset = 0; ///< drift time additive offset in \mus - bool mIsContinuous; ///< Switch for continuous readout - bool mUseSCDistortions = false; ///< Flag to switch on the use of space-charge distortions - int mDistortionScaleType = 0; ///< type=0: no scaling of distortions, type=1 distortions without any scaling, type=2 distortions scaling with lumi - float mLumiScaleFactor = 0; ///< value used to scale the derivative map - bool mUseScaledDistortions = false; ///< whether the distortions are already scaled - ClassDefNV(Digitizer, 3); + DigitContainer mDigitContainer; ///< Container for the Digits + std::unique_ptr mSpaceChargeOwned; //!< Distortions created by the digitizer itself + SC* mSpaceCharge = nullptr; //!< Handler of full distortions (static + IR dependant), owned by mSpaceChargeOwned or by the caller + SC* mSpaceChargeDer = nullptr; //!< Handler of reference static distortions, owned by the caller + Sector mSector = -1; ///< ID of the currently processed sector + double mEventTime = 0.f; ///< Time of the currently processed event + double mOutputDigitTimeOffset = 0; ///< Time of the first IR sampled in the digitizer + float mVDrift = 0; ///< VDrift for current timestamp + float mTDriftOffset = 0; ///< drift time additive offset in \mus + bool mIsContinuous; ///< Switch for continuous readout + bool mUseSCDistortions = false; ///< Flag to switch on the use of space-charge distortions + int mDistortionScaleType = 0; ///< type=0: no scaling of distortions, type=1 distortions without any scaling, type=2 distortions scaling with lumi + float mLumiScaleFactor = 0; ///< value used to scale the derivative map + bool mUseScaledDistortions = false; ///< whether the distortions are already scaled + ClassDefNV(Digitizer, 4); }; } // namespace tpc } // namespace o2 diff --git a/Detectors/TPC/simulation/src/Digitizer.cxx b/Detectors/TPC/simulation/src/Digitizer.cxx index 49abc0a0b99af..1d646fac64d61 100644 --- a/Detectors/TPC/simulation/src/Digitizer.cxx +++ b/Detectors/TPC/simulation/src/Digitizer.cxx @@ -83,7 +83,7 @@ void Digitizer::process(const std::vector& hits, if (mDistortionScaleType == 1) { mSpaceCharge->distortElectron(posEle); } else if (mDistortionScaleType == 2) { - mSpaceCharge->distortElectron(posEle, (mUseScaledDistortions ? nullptr : mSpaceChargeDer.get()), mLumiScaleFactor); + mSpaceCharge->distortElectron(posEle, (mUseScaledDistortions ? nullptr : mSpaceChargeDer), mLumiScaleFactor); } /// Remove electrons that end up more than three sigma of the hit's average diffusion away from the current sector @@ -182,7 +182,8 @@ void Digitizer::setUseSCDistortions(const SCDistortionType& distortionType, cons { mUseSCDistortions = true; if (!mSpaceCharge) { - mSpaceCharge = std::make_unique(); + mSpaceChargeOwned = std::make_unique(); + mSpaceCharge = mSpaceChargeOwned.get(); } mSpaceCharge->setSCDistortionType(distortionType); if (hisInitialSCDensity) { @@ -194,14 +195,17 @@ void Digitizer::setUseSCDistortions(const SCDistortionType& distortionType, cons void Digitizer::setUseSCDistortions(SC* spaceCharge) { mUseSCDistortions = true; - mSpaceCharge.reset(spaceCharge); + if (spaceCharge != mSpaceChargeOwned.get()) { + mSpaceChargeOwned.reset(); + } + mSpaceCharge = spaceCharge; mSpaceCharge->initAfterReadingFromFile(); mSpaceCharge->printMetaData(); } void Digitizer::setSCDistortionsDerivative(SC* spaceCharge) { - mSpaceChargeDer.reset(spaceCharge); + mSpaceChargeDer = spaceCharge; mSpaceChargeDer->initAfterReadingFromFile(); mSpaceChargeDer->printMetaData(); } @@ -210,7 +214,8 @@ void Digitizer::setUseSCDistortions(std::string_view finp) { mUseSCDistortions = true; if (!mSpaceCharge) { - mSpaceCharge = std::make_unique(); + mSpaceChargeOwned = std::make_unique(); + mSpaceCharge = mSpaceChargeOwned.get(); } // in case analytical distortions are loaded from file they are applied @@ -268,7 +273,7 @@ void Digitizer::recalculateDistortions() mSpaceChargeDer->calcGlobalCorrWithGlobalDistIterative(side, nullptr, 0); LOGP(info, "Calculating scaled distortions with scaling factor {}", mLumiScaleFactor); - mSpaceCharge->calcGlobalDistWithGlobalCorrIterativeLinearCartesian(side, mSpaceChargeDer.get(), mLumiScaleFactor); + mSpaceCharge->calcGlobalDistWithGlobalCorrIterativeLinearCartesian(side, mSpaceChargeDer, mLumiScaleFactor); } // set new lumi of avg map mSpaceCharge->setMeanLumi(CorrMapParam::Instance().lumiInst);