Skip to content

Commit b8dd0a3

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 e3186fc commit b8dd0a3

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
@@ -85,7 +85,7 @@ void Digitizer::process(const std::vector<o2::tpc::HitGroup>& hits,
8585
if (mDistortionScaleType == 1) {
8686
mSpaceCharge->distortElectron(posEle);
8787
} else if (mDistortionScaleType == 2) {
88-
mSpaceCharge->distortElectron(posEle, (mUseScaledDistortions ? nullptr : mSpaceChargeDer.get()), mLumiScaleFactor);
88+
mSpaceCharge->distortElectron(posEle, (mUseScaledDistortions ? nullptr : mSpaceChargeDer), mLumiScaleFactor);
8989
}
9090

9191
/// Remove electrons that end up more than three sigma of the hit's average diffusion away from the current sector
@@ -184,7 +184,8 @@ void Digitizer::setUseSCDistortions(const SCDistortionType& distortionType, cons
184184
{
185185
mUseSCDistortions = true;
186186
if (!mSpaceCharge) {
187-
mSpaceCharge = std::make_unique<SC>();
187+
mSpaceChargeOwned = std::make_unique<SC>();
188+
mSpaceCharge = mSpaceChargeOwned.get();
188189
}
189190
mSpaceCharge->setSCDistortionType(distortionType);
190191
if (hisInitialSCDensity) {
@@ -196,14 +197,17 @@ void Digitizer::setUseSCDistortions(const SCDistortionType& distortionType, cons
196197
void Digitizer::setUseSCDistortions(SC* spaceCharge)
197198
{
198199
mUseSCDistortions = true;
199-
mSpaceCharge.reset(spaceCharge);
200+
if (spaceCharge != mSpaceChargeOwned.get()) {
201+
mSpaceChargeOwned.reset();
202+
}
203+
mSpaceCharge = spaceCharge;
200204
mSpaceCharge->initAfterReadingFromFile();
201205
mSpaceCharge->printMetaData();
202206
}
203207

204208
void Digitizer::setSCDistortionsDerivative(SC* spaceCharge)
205209
{
206-
mSpaceChargeDer.reset(spaceCharge);
210+
mSpaceChargeDer = spaceCharge;
207211
mSpaceChargeDer->initAfterReadingFromFile();
208212
mSpaceChargeDer->printMetaData();
209213
}
@@ -212,7 +216,8 @@ void Digitizer::setUseSCDistortions(std::string_view finp)
212216
{
213217
mUseSCDistortions = true;
214218
if (!mSpaceCharge) {
215-
mSpaceCharge = std::make_unique<SC>();
219+
mSpaceChargeOwned = std::make_unique<SC>();
220+
mSpaceCharge = mSpaceChargeOwned.get();
216221
}
217222

218223
// in case analytical distortions are loaded from file they are applied
@@ -270,7 +275,7 @@ void Digitizer::recalculateDistortions()
270275
mSpaceChargeDer->calcGlobalCorrWithGlobalDistIterative(side, nullptr, 0);
271276

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

0 commit comments

Comments
 (0)