Skip to content

Commit aaf275e

Browse files
sawenzelclaude
andcommitted
Do not take ownership of CCDB distortion maps in the TPC digitizer
This fixes a double ownership of the TPC space-charge maps and prepares sharing them between digitizers. - setUseSCDistortions(SC*) and setSCDistortionsDerivative(SC*) took ownership of objects that the DPL CCDB cache owns and deletes itself when a newer object replaces them. - The Digitizer now owns only the maps it creates itself. - The map members are transient for ROOT I/O. https://its.cern.ch/jira/browse/O2-7309 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 56ab9f6 commit aaf275e

2 files changed

Lines changed: 28 additions & 22 deletions

File tree

‎Detectors/TPC/simulation/include/TPCSimulation/Digitizer.h‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ class Digitizer
118118
/// \param nRBins number of grid points in r, must be (2**N)+1
119119
void setUseSCDistortions(const SCDistortionType& distortionType, const TH3* hisInitialSCDensity);
120120
/// Enable the use of space-charge distortions and provide SpaceCharge object as input
121-
/// \param spaceCharge unique pointer to spaceCharge object
121+
/// \param spaceCharge spaceCharge object, not owned: the caller (e.g. the DPL CCDB cache) keeps it alive
122122
void setUseSCDistortions(SC* spaceCharge);
123123

124-
/// \param spaceCharge unique pointer to spaceCharge object
124+
/// \param spaceCharge spaceCharge object of the derivative map, not owned: the caller keeps it alive
125125
void setSCDistortionsDerivative(SC* spaceCharge);
126126

127127
/// 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
142142
void recalculateDistortions();
143143

144144
private:
145-
DigitContainer mDigitContainer; ///< Container for the Digits
146-
std::unique_ptr<SC> mSpaceCharge; ///< Handler of full distortions (static + IR dependant)
147-
std::unique_ptr<SC> mSpaceChargeDer; ///< Handler of reference static distortions
148-
Sector mSector = -1; ///< ID of the currently processed sector
149-
double mEventTime = 0.f; ///< Time of the currently processed event
150-
double mOutputDigitTimeOffset = 0; ///< Time of the first IR sampled in the digitizer
151-
float mVDrift = 0; ///< VDrift for current timestamp
152-
float mTDriftOffset = 0; ///< drift time additive offset in \mus
153-
bool mIsContinuous; ///< Switch for continuous readout
154-
bool mUseSCDistortions = false; ///< Flag to switch on the use of space-charge distortions
155-
int mDistortionScaleType = 0; ///< type=0: no scaling of distortions, type=1 distortions without any scaling, type=2 distortions scaling with lumi
156-
float mLumiScaleFactor = 0; ///< value used to scale the derivative map
157-
bool mUseScaledDistortions = false; ///< whether the distortions are already scaled
158-
ClassDefNV(Digitizer, 3);
145+
DigitContainer mDigitContainer; ///< Container for the Digits
146+
std::unique_ptr<SC> mSpaceChargeOwned; //!< Distortions created by the digitizer itself
147+
SC* mSpaceCharge = nullptr; //!< Handler of full distortions (static + IR dependant), owned by mSpaceChargeOwned or by the caller
148+
SC* mSpaceChargeDer = nullptr; //!< Handler of reference static distortions, owned by the caller
149+
Sector mSector = -1; ///< ID of the currently processed sector
150+
double mEventTime = 0.f; ///< Time of the currently processed event
151+
double mOutputDigitTimeOffset = 0; ///< Time of the first IR sampled in the digitizer
152+
float mVDrift = 0; ///< VDrift for current timestamp
153+
float mTDriftOffset = 0; ///< drift time additive offset in \mus
154+
bool mIsContinuous; ///< Switch for continuous readout
155+
bool mUseSCDistortions = false; ///< Flag to switch on the use of space-charge distortions
156+
int mDistortionScaleType = 0; ///< type=0: no scaling of distortions, type=1 distortions without any scaling, type=2 distortions scaling with lumi
157+
float mLumiScaleFactor = 0; ///< value used to scale the derivative map
158+
bool mUseScaledDistortions = false; ///< whether the distortions are already scaled
159+
ClassDefNV(Digitizer, 4);
159160
};
160161
} // namespace tpc
161162
} // namespace o2

‎Detectors/TPC/simulation/src/Digitizer.cxx‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void Digitizer::process(const std::vector<o2::tpc::HitGroup>& hits,
8383
if (mDistortionScaleType == 1) {
8484
mSpaceCharge->distortElectron(posEle);
8585
} else if (mDistortionScaleType == 2) {
86-
mSpaceCharge->distortElectron(posEle, (mUseScaledDistortions ? nullptr : mSpaceChargeDer.get()), mLumiScaleFactor);
86+
mSpaceCharge->distortElectron(posEle, (mUseScaledDistortions ? nullptr : mSpaceChargeDer), mLumiScaleFactor);
8787
}
8888

8989
/// 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
182182
{
183183
mUseSCDistortions = true;
184184
if (!mSpaceCharge) {
185-
mSpaceCharge = std::make_unique<SC>();
185+
mSpaceChargeOwned = std::make_unique<SC>();
186+
mSpaceCharge = mSpaceChargeOwned.get();
186187
}
187188
mSpaceCharge->setSCDistortionType(distortionType);
188189
if (hisInitialSCDensity) {
@@ -194,14 +195,17 @@ void Digitizer::setUseSCDistortions(const SCDistortionType& distortionType, cons
194195
void Digitizer::setUseSCDistortions(SC* spaceCharge)
195196
{
196197
mUseSCDistortions = true;
197-
mSpaceCharge.reset(spaceCharge);
198+
if (spaceCharge != mSpaceChargeOwned.get()) {
199+
mSpaceChargeOwned.reset();
200+
}
201+
mSpaceCharge = spaceCharge;
198202
mSpaceCharge->initAfterReadingFromFile();
199203
mSpaceCharge->printMetaData();
200204
}
201205

202206
void Digitizer::setSCDistortionsDerivative(SC* spaceCharge)
203207
{
204-
mSpaceChargeDer.reset(spaceCharge);
208+
mSpaceChargeDer = spaceCharge;
205209
mSpaceChargeDer->initAfterReadingFromFile();
206210
mSpaceChargeDer->printMetaData();
207211
}
@@ -210,7 +214,8 @@ void Digitizer::setUseSCDistortions(std::string_view finp)
210214
{
211215
mUseSCDistortions = true;
212216
if (!mSpaceCharge) {
213-
mSpaceCharge = std::make_unique<SC>();
217+
mSpaceChargeOwned = std::make_unique<SC>();
218+
mSpaceCharge = mSpaceChargeOwned.get();
214219
}
215220

216221
// in case analytical distortions are loaded from file they are applied
@@ -268,7 +273,7 @@ void Digitizer::recalculateDistortions()
268273
mSpaceChargeDer->calcGlobalCorrWithGlobalDistIterative(side, nullptr, 0);
269274

270275
LOGP(info, "Calculating scaled distortions with scaling factor {}", mLumiScaleFactor);
271-
mSpaceCharge->calcGlobalDistWithGlobalCorrIterativeLinearCartesian(side, mSpaceChargeDer.get(), mLumiScaleFactor);
276+
mSpaceCharge->calcGlobalDistWithGlobalCorrIterativeLinearCartesian(side, mSpaceChargeDer, mLumiScaleFactor);
272277
}
273278
// set new lumi of avg map
274279
mSpaceCharge->setMeanLumi(CorrMapParam::Instance().lumiInst);

0 commit comments

Comments
 (0)