Skip to content

Commit fcda4a9

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 34a7cd9 commit fcda4a9

2 files changed

Lines changed: 29 additions & 23 deletions

File tree

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

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

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

129129
/// Enable the use of space-charge distortions by providing global distortions and global corrections stored in a ROOT file
@@ -163,21 +163,22 @@ class Digitizer
163163
ULong64_t mSeedingTimeframe = 0; //!< Timeframe identifier for sector seeding
164164
bool mUseSectorSeeding = false; //!< Whether sector seeding is used
165165

166-
DigitContainer mDigitContainer; ///< Container for the Digits
167-
std::vector<float> mSignalArray; //!< Workspace for the shaped signal of one electron
168-
std::unique_ptr<SC> mSpaceCharge; ///< Handler of full distortions (static + IR dependant)
169-
std::unique_ptr<SC> mSpaceChargeDer; ///< Handler of reference static distortions
170-
Sector mSector = -1; ///< ID of the currently processed sector
171-
double mEventTime = 0.f; ///< Time of the currently processed event
172-
double mOutputDigitTimeOffset = 0; ///< Time of the first IR sampled in the digitizer
173-
float mVDrift = 0; ///< VDrift for current timestamp
174-
float mTDriftOffset = 0; ///< drift time additive offset in \mus
175-
bool mIsContinuous; ///< Switch for continuous readout
176-
bool mUseSCDistortions = false; ///< Flag to switch on the use of space-charge distortions
177-
int mDistortionScaleType = 0; ///< type=0: no scaling of distortions, type=1 distortions without any scaling, type=2 distortions scaling with lumi
178-
float mLumiScaleFactor = 0; ///< value used to scale the derivative map
179-
bool mUseScaledDistortions = false; ///< whether the distortions are already scaled
180-
ClassDefNV(Digitizer, 3);
166+
DigitContainer mDigitContainer; ///< Container for the Digits
167+
std::vector<float> mSignalArray; //!< Workspace for the shaped signal of one electron
168+
std::unique_ptr<SC> mSpaceChargeOwned; //!< Distortions created by the digitizer itself
169+
SC* mSpaceCharge = nullptr; //!< Handler of full distortions (static + IR dependant), owned by mSpaceChargeOwned or by the caller
170+
SC* mSpaceChargeDer = nullptr; //!< Handler of reference static distortions, owned by the caller
171+
Sector mSector = -1; ///< ID of the currently processed sector
172+
double mEventTime = 0.f; ///< Time of the currently processed event
173+
double mOutputDigitTimeOffset = 0; ///< Time of the first IR sampled in the digitizer
174+
float mVDrift = 0; ///< VDrift for current timestamp
175+
float mTDriftOffset = 0; ///< drift time additive offset in \mus
176+
bool mIsContinuous; ///< Switch for continuous readout
177+
bool mUseSCDistortions = false; ///< Flag to switch on the use of space-charge distortions
178+
int mDistortionScaleType = 0; ///< type=0: no scaling of distortions, type=1 distortions without any scaling, type=2 distortions scaling with lumi
179+
float mLumiScaleFactor = 0; ///< value used to scale the derivative map
180+
bool mUseScaledDistortions = false; ///< whether the distortions are already scaled
181+
ClassDefNV(Digitizer, 4);
181182
};
182183
} // namespace tpc
183184
} // namespace o2

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void Digitizer::process(const std::vector<o2::tpc::HitGroup>& hits,
140140
if (mDistortionScaleType == 1) {
141141
mSpaceCharge->distortElectron(posEle);
142142
} else if (mDistortionScaleType == 2) {
143-
mSpaceCharge->distortElectron(posEle, (mUseScaledDistortions ? nullptr : mSpaceChargeDer.get()), mLumiScaleFactor);
143+
mSpaceCharge->distortElectron(posEle, (mUseScaledDistortions ? nullptr : mSpaceChargeDer), mLumiScaleFactor);
144144
}
145145

146146
/// Remove electrons that end up more than three sigma of the hit's average diffusion away from the current sector
@@ -239,7 +239,8 @@ void Digitizer::setUseSCDistortions(const SCDistortionType& distortionType, cons
239239
{
240240
mUseSCDistortions = true;
241241
if (!mSpaceCharge) {
242-
mSpaceCharge = std::make_unique<SC>();
242+
mSpaceChargeOwned = std::make_unique<SC>();
243+
mSpaceCharge = mSpaceChargeOwned.get();
243244
}
244245
mSpaceCharge->setSCDistortionType(distortionType);
245246
if (hisInitialSCDensity) {
@@ -251,14 +252,17 @@ void Digitizer::setUseSCDistortions(const SCDistortionType& distortionType, cons
251252
void Digitizer::setUseSCDistortions(SC* spaceCharge)
252253
{
253254
mUseSCDistortions = true;
254-
mSpaceCharge.reset(spaceCharge);
255+
if (spaceCharge != mSpaceChargeOwned.get()) {
256+
mSpaceChargeOwned.reset();
257+
}
258+
mSpaceCharge = spaceCharge;
255259
mSpaceCharge->initAfterReadingFromFile();
256260
mSpaceCharge->printMetaData();
257261
}
258262

259263
void Digitizer::setSCDistortionsDerivative(SC* spaceCharge)
260264
{
261-
mSpaceChargeDer.reset(spaceCharge);
265+
mSpaceChargeDer = spaceCharge;
262266
mSpaceChargeDer->initAfterReadingFromFile();
263267
mSpaceChargeDer->printMetaData();
264268
}
@@ -267,7 +271,8 @@ void Digitizer::setUseSCDistortions(std::string_view finp)
267271
{
268272
mUseSCDistortions = true;
269273
if (!mSpaceCharge) {
270-
mSpaceCharge = std::make_unique<SC>();
274+
mSpaceChargeOwned = std::make_unique<SC>();
275+
mSpaceCharge = mSpaceChargeOwned.get();
271276
}
272277

273278
// in case analytical distortions are loaded from file they are applied
@@ -325,7 +330,7 @@ void Digitizer::recalculateDistortions()
325330
mSpaceChargeDer->calcGlobalCorrWithGlobalDistIterative(side, nullptr, 0);
326331

327332
LOGP(info, "Calculating scaled distortions with scaling factor {}", mLumiScaleFactor);
328-
mSpaceCharge->calcGlobalDistWithGlobalCorrIterativeLinearCartesian(side, mSpaceChargeDer.get(), mLumiScaleFactor);
333+
mSpaceCharge->calcGlobalDistWithGlobalCorrIterativeLinearCartesian(side, mSpaceChargeDer, mLumiScaleFactor);
329334
}
330335
// set new lumi of avg map
331336
mSpaceCharge->setMeanLumi(CorrMapParam::Instance().lumiInst);

0 commit comments

Comments
 (0)