Skip to content

Commit f5b152f

Browse files
matthias-kleinerdavidrohr
authored andcommitted
TPC dEdx: automatically loading calib objects from CCDB
- adding options for disabling loading calibrations from CCDB - using the gain map to get the original charge which was used during the zero supresison - apply residual gain map on cluster charge - smooth zero supression threshold map - disable loading of CCDB objects, when calibs are set from file - TPC clusterer: automatically loading the gain map from the CCDB
1 parent 3e156b4 commit f5b152f

9 files changed

Lines changed: 400 additions & 15 deletions

File tree

DataFormats/Detectors/TPC/include/DataFormatsTPC/CalibdEdxTrackTopologyPol.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ struct CalibdEdxTrackTopologyPolContainer {
4949
float mQTotMax{200}; ///< maximum qTot for which the correction is valid
5050
std::vector<float> mScalingFactorsqTot{}; ///< value which is used to scale the result of the polynomial for qTot (can be used for normalization)
5151
std::vector<float> mScalingFactorsqMax{}; ///< value which is used to scale the result of the polynomial for qMax (can be used for normalization)
52+
53+
ClassDefNV(CalibdEdxTrackTopologyPolContainer, 1);
5254
};
5355
#endif
5456

@@ -206,6 +208,9 @@ class CalibdEdxTrackTopologyPol : public o2::gpu::FlatObject
206208
/// sets the polynomials from an input file. The names of the objects have to be the same as in the getPolyName() function
207209
/// \param inpf file where the polynomials are stored
208210
void setPolynomialsFromFile(TFile& inpf);
211+
212+
/// setting a default topology correction which just returns 1
213+
void setDefaultPolynomials();
209214
#endif
210215

211216
/// \return returns the name of the polynomial object which can be read in with the setPolynomialsFromFile() function

DataFormats/Detectors/TPC/src/CalibdEdxTrackTopologyPol.cxx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,15 @@ void CalibdEdxTrackTopologyPol::construct()
131131
}
132132
}
133133

134+
void CalibdEdxTrackTopologyPol::setDefaultPolynomials()
135+
{
136+
for (int i = 0; i < FFits; ++i) {
137+
mCalibPolsqTot[i].setParam(0, 1);
138+
mCalibPolsqMax[i].setParam(0, 1);
139+
}
140+
construct();
141+
}
142+
134143
void CalibdEdxTrackTopologyPol::writeToFile(TFile& outf, const char* name) const
135144
{
136145
CalibdEdxTrackTopologyPolContainer cont(mMaxTanTheta, mMaxSinPhi, mThresholdMin, mThresholdMax, mQTotMin, mQTotMax);
@@ -187,6 +196,7 @@ void CalibdEdxTrackTopologyPol::setFromContainer(const CalibdEdxTrackTopologyPol
187196
mScalingFactorsqTot[i] = container.mScalingFactorsqTot[i];
188197
mScalingFactorsqMax[i] = container.mScalingFactorsqMax[i];
189198
}
199+
construct();
190200
}
191201

192202
void CalibdEdxTrackTopologyPol::loadFromFile(const char* fileName, const char* name)
@@ -196,7 +206,6 @@ void CalibdEdxTrackTopologyPol::loadFromFile(const char* fileName, const char* n
196206
inpf.GetObject(name, polTmp);
197207
if (polTmp) {
198208
setFromContainer(*polTmp);
199-
construct();
200209
delete polTmp;
201210
} else {
202211
LOGP(info, fmt::format("couldnt load object {} from input file", name));

Detectors/TPC/base/include/TPCBase/CDBInterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ enum class CDBType {
4949
CalGas, ///< DCS gas measurements
5050
CalTemperature, ///< DCS temperature measurements
5151
CalHV, ///< DCS HV measurements
52+
CalTopologyGain, ///< Q cluster topology correction
5253
///
5354
ConfigFEEPad, ///< FEE pad-by-pad configuration map
5455
///
@@ -78,6 +79,7 @@ const std::unordered_map<CDBType, const std::string> CDBTypeMap{
7879
{CDBType::CalGas, "TPC/Calib/Gas"},
7980
{CDBType::CalTemperature, "TPC/Calib/Temperature"},
8081
{CDBType::CalHV, "TPC/Calib/HV"},
82+
{CDBType::CalTopologyGain, "TPC/Calib/TopologyGain"},
8183
//
8284
{CDBType::ConfigFEEPad, "TPC/Config/FEEPad"},
8385
//

GPU/GPUTracking/DataTypes/CalibdEdxContainer.cxx

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,23 @@ void CalibdEdxContainer::loadSplineTopologyCorrectionFromFile(std::string_view f
150150
loadTopologyCorrectionFromFile(fileName, mCalibTrackTopologySpline);
151151
}
152152

153+
void CalibdEdxContainer::setPolTopologyCorrection(const CalibdEdxTrackTopologyPol& calibTrackTopology)
154+
{
155+
setTopologyCorrection(calibTrackTopology, mCalibTrackTopologyPol);
156+
}
157+
158+
void CalibdEdxContainer::setDefaultPolTopologyCorrection()
159+
{
160+
CalibdEdxTrackTopologyPol calibTrackTopology;
161+
calibTrackTopology.setDefaultPolynomials();
162+
setTopologyCorrection(calibTrackTopology, mCalibTrackTopologyPol);
163+
}
164+
165+
void CalibdEdxContainer::setSplineTopologyCorrection(const CalibdEdxTrackTopologySpline& calibTrackTopology)
166+
{
167+
setTopologyCorrection(calibTrackTopology, mCalibTrackTopologySpline);
168+
}
169+
153170
void CalibdEdxContainer::loadZeroSupresssionThresholdFromFile(std::string_view fileName, std::string_view objName, const float minCorrectionFactor, const float maxCorrectionFactor)
154171
{
155172
TFile fInp(fileName.data(), "READ");
@@ -161,10 +178,75 @@ void CalibdEdxContainer::loadZeroSupresssionThresholdFromFile(std::string_view f
161178

162179
void CalibdEdxContainer::setZeroSupresssionThreshold(const CalDet<float>& thresholdMap, const float minCorrectionFactor, const float maxCorrectionFactor)
163180
{
164-
o2::gpu::TPCPadGainCalib thresholdMapTmp(thresholdMap, minCorrectionFactor, maxCorrectionFactor, false);
181+
const auto thresholdMapProcessed = processThresholdMap(thresholdMap, maxCorrectionFactor);
182+
o2::gpu::TPCPadGainCalib thresholdMapTmp(thresholdMapProcessed, minCorrectionFactor, maxCorrectionFactor, false);
165183
mThresholdMap = thresholdMapTmp;
166184
}
167185

186+
CalDet<float> CalibdEdxContainer::processThresholdMap(const CalDet<float>& thresholdMap, const float maxThreshold, const int nPadsInRowCl, const int nPadsInPadCl) const
187+
{
188+
CalDet<float> thresholdMapProcessed(thresholdMap);
189+
190+
for (int sector = 0; sector < Mapper::NSECTORS; ++sector) {
191+
for (int region = 0; region < Mapper::NREGIONS; ++region) {
192+
const int maxRow = Mapper::ROWSPERREGION[region] - 1;
193+
for (int lrow = 0; lrow <= maxRow; ++lrow) {
194+
// find first row of the cluster
195+
const int rowStart = std::clamp(lrow - nPadsInRowCl, 0, maxRow);
196+
const int rowEnd = std::clamp(lrow + nPadsInRowCl, 0, maxRow);
197+
const int addPadsStart = Mapper::ADDITIONALPADSPERROW[region][lrow];
198+
199+
for (int pad = 0; pad < Mapper::PADSPERROW[region][lrow]; ++pad) {
200+
float sumThr = 0;
201+
int countThr = 0;
202+
// loop ove the rows from the cluster
203+
for (int rowCl = rowStart; rowCl <= rowEnd; ++rowCl) {
204+
// shift local pad in row in case current row from the cluster has more pads in the row
205+
const int addPadsCl = Mapper::ADDITIONALPADSPERROW[region][rowCl];
206+
const int diffAddPads = addPadsCl - addPadsStart;
207+
const int padClCentre = pad + diffAddPads;
208+
209+
const int maxPad = Mapper::PADSPERROW[region][rowCl] - 1;
210+
const int padStart = std::clamp(padClCentre - nPadsInPadCl, 0, maxPad);
211+
const int padEnd = std::clamp(padClCentre + nPadsInPadCl, 0, maxPad);
212+
for (int padCl = padStart; padCl <= padEnd; ++padCl) {
213+
const int globalPad = Mapper::getGlobalPadNumber(rowCl, padCl, region);
214+
// skip for current cluster position as the charge there is not effected from the thresold
215+
if (padCl == pad && rowCl == lrow) {
216+
continue;
217+
}
218+
219+
float threshold = thresholdMap.getValue(sector, globalPad);
220+
if (threshold > maxThreshold) {
221+
threshold = maxThreshold;
222+
}
223+
224+
sumThr += threshold;
225+
++countThr;
226+
}
227+
}
228+
const float meanThresold = sumThr / countThr;
229+
const int globalPad = Mapper::getGlobalPadNumber(lrow, pad, region);
230+
thresholdMapProcessed.setValue(sector, globalPad, meanThresold);
231+
}
232+
}
233+
}
234+
}
235+
return thresholdMapProcessed;
236+
}
237+
238+
void CalibdEdxContainer::setGainMap(const CalDet<float>& gainMap, const float minGain, const float maxGain)
239+
{
240+
o2::gpu::TPCPadGainCalib gainMapTmp(gainMap, minGain, maxGain, false);
241+
mGainMap = gainMapTmp;
242+
}
243+
244+
void CalibdEdxContainer::setGainMapResidual(const CalDet<float>& gainMapResidual, const float minResidualGain, const float maxResidualGain)
245+
{
246+
o2::gpu::TPCPadGainCalib gainMapResTmp(gainMapResidual, minResidualGain, maxResidualGain, false);
247+
mGainMapResidual = gainMapResTmp;
248+
}
249+
168250
void CalibdEdxContainer::setDefaultZeroSupresssionThreshold()
169251
{
170252
const float defaultVal = getMinZeroSupresssionThreshold() + (getMaxZeroSupresssionThreshold() - getMinZeroSupresssionThreshold()) / 2;
@@ -180,10 +262,15 @@ void CalibdEdxContainer::setDefaultZeroSupresssionThreshold()
180262
template <class Type>
181263
void CalibdEdxContainer::loadTopologyCorrectionFromFile(std::string_view fileName, Type*& obj)
182264
{
183-
FlatObject::startConstruction();
184-
185265
// load and set-up container
186266
Type calibTrackTopologyTmp(fileName.data());
267+
setTopologyCorrection(calibTrackTopologyTmp, obj);
268+
}
269+
270+
template <class Type>
271+
void CalibdEdxContainer::setTopologyCorrection(const Type& calibTrackTopologyTmp, Type*& obj)
272+
{
273+
FlatObject::startConstruction();
187274

188275
// get size of the flat buffer of the splines
189276
const std::size_t flatbufferSize = calibTrackTopologyTmp.getFlatBufferSize();

GPU/GPUTracking/DataTypes/CalibdEdxContainer.h

Lines changed: 94 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@
3232
namespace o2::tpc
3333
{
3434

35+
/// flags to set which corrections will be loaded from the CCDB
36+
enum class CalibsdEdx : unsigned short {
37+
CalTopologySpline = 1 << 0, ///< flag for a topology correction using splines
38+
CalTopologyPol = 1 << 1, ///< flag for a topology correction using polynomials
39+
CalThresholdMap = 1 << 2, ///< flag for using threshold map
40+
CalGainMap = 1 << 3, ///< flag for using the gain map to get the correct cluster charge
41+
CalResidualGainMap = 1 << 4, ///< flag for applying residual gain map
42+
CalTimeGain = 1 << 5, ///< flag for residual dE/dx time dependent gain correction
43+
};
44+
45+
inline CalibsdEdx operator|(CalibsdEdx a, CalibsdEdx b) { return static_cast<CalibsdEdx>(static_cast<int>(a) | static_cast<int>(b)); }
46+
47+
inline CalibsdEdx operator&(CalibsdEdx a, CalibsdEdx b) { return static_cast<CalibsdEdx>(static_cast<int>(a) & static_cast<int>(b)); }
48+
49+
inline CalibsdEdx operator~(CalibsdEdx a) { return static_cast<CalibsdEdx>(~static_cast<int>(a)); }
50+
3551
///
3652
/// This container class contains all necessary corrections for the dE/dx
3753
/// Currently it holds the residual dE/dx correction and the track topology correction, which can be either provided by 2D-splines or by 5D-polynomials.
@@ -107,13 +123,26 @@ class CalibdEdxContainer : public o2::gpu::FlatObject
107123
/// \param row global pad row
108124
GPUd() float getZeroSupressionThreshold(const int sector, const gpu::tpccf::Row row, const gpu::tpccf::Pad pad) const { return mThresholdMap.getGainCorrection(sector, row, pad); }
109125

126+
/// \return returns gain from the full gain map
127+
/// \param sector tpc sector
128+
/// \param row global pad row
129+
GPUd() float getGain(const int sector, const gpu::tpccf::Row row, const gpu::tpccf::Pad pad) const { return mGainMap.getGainCorrection(sector, row, pad); }
130+
131+
/// \return returns gain from residual gain map
132+
/// \param sector tpc sector
133+
/// \param row global pad row
134+
GPUd() float getResidualGain(const int sector, const gpu::tpccf::Row row, const gpu::tpccf::Pad pad) const { return mGainMapResidual.getGainCorrection(sector, row, pad); }
135+
110136
/// \return returns the residual dE/dx correction for the cluster charge
111137
/// \param stack ID of the GEM stack
112138
/// \param charge type of the charge (qMax or qTot)
113139
/// \param z z position
114140
/// \param tgl tracking parameter tgl
115141
GPUd() float getResidualCorrection(const StackID& stack, const ChargeType charge, const float z = 0, const float tgl = 0) const { return mCalibResidualdEdx.getCorrection(stack, charge, z, tgl); }
116142

143+
/// \return returns if the full gain map will be used during the calculation of the dE/dx to correct the cluster charge
144+
GPUd() bool isUsageOfFullGainMap() const { return mApplyFullGainMap; }
145+
117146
/// ========== FlatObject functionality, see FlatObject class for description =================
118147
#if !defined(GPUCA_GPUCODE)
119148
/// cloning a container object (use newFlatBufferPtr=nullptr for simple copy)
@@ -143,32 +172,78 @@ class CalibdEdxContainer : public o2::gpu::FlatObject
143172
/// \param fileName input file containing the correction
144173
void loadSplineTopologyCorrectionFromFile(std::string_view fileName);
145174

175+
/// set the polynomial track topology
176+
/// \param calibTrackTopology polynomial track topology correction
177+
void setPolTopologyCorrection(const CalibdEdxTrackTopologyPol& calibTrackTopology);
178+
179+
/// setting a default topology correction which just returns 1
180+
void setDefaultPolTopologyCorrection();
181+
182+
/// set the spline track topology
183+
/// \param calibTrackTopology spline track topology correction
184+
void setSplineTopologyCorrection(const CalibdEdxTrackTopologySpline& calibTrackTopology);
185+
146186
// loading the residual dE/dx correction from a file
147187
/// \param fileName input file containing the correction
148188
void loadResidualCorrectionFromFile(std::string_view fileName) { mCalibResidualdEdx.loadFromFile(fileName); }
149189

190+
/// setting the residual dEdx correction
191+
/// \param residualCorr residual gain calibration object
192+
void setResidualCorrection(const CalibdEdxCorrection& residualCorr) { mCalibResidualdEdx = residualCorr; }
193+
150194
// loading the zero supression threshold map from a file
151195
/// \param fileName input file containing the CalDet map
152196
void loadZeroSupresssionThresholdFromFile(std::string_view fileName, std::string_view objName, const float minCorrectionFactor, const float maxCorrectionFactor);
153197

154-
// loading the zero supression threshold map from a file
155-
/// \param fileName input file containing the CalDet map
198+
/// setting the zero supression threshold map from a CalDet
199+
/// \param thresholdMap CalDet containing the zero supression threshold
156200
void setZeroSupresssionThreshold(const CalDet<float>& thresholdMap) { setZeroSupresssionThreshold(thresholdMap, getMinZeroSupresssionThreshold(), getMaxZeroSupresssionThreshold()); }
157201

158-
// loading the zero supression threshold map from a file
159-
/// \param fileName input file containing the CalDet map
202+
/// setting the zero supression threshold map from a CalDet
203+
/// \param thresholdMap CalDet containing the zero supression threshold
160204
void setZeroSupresssionThreshold(const CalDet<float>& thresholdMap, const float minCorrectionFactor, const float maxCorrectionFactor);
161205

206+
/// setting the gain map map from a CalDet
207+
void setGainMap(const CalDet<float>& gainMap, const float minGain, const float maxGain);
208+
209+
/// setting the gain map map from a CalDet
210+
void setGainMapResidual(const CalDet<float>& gainMapResidual, const float minResidualGain = 0.7f, const float maxResidualGain = 1.3f);
211+
162212
/// setting default zero supression threshold map (all values are set to getMinZeroSupresssionThreshold())
163213
/// \param fileName input file containing the CalDet map
164214
void setDefaultZeroSupresssionThreshold();
215+
216+
/// returns status if the spline correction is set
217+
bool isTopologyCorrectionSplinesSet() const { return mCalibTrackTopologySpline ? true : false; }
218+
219+
/// returns status if the polynomials correction is set
220+
bool isTopologyCorrectionPolynomialsSet() const { return mCalibTrackTopologyPol ? true : false; }
221+
222+
/// set loading of a correction from CCDB
223+
/// \param calib calibration which will be loaded from CCDB
224+
void setCorrectionCCDB(const CalibsdEdx calib) { mCalibsLoad = calib | mCalibsLoad; }
225+
226+
/// disable loading of a correction from CCDB
227+
/// \param calib calibration which will not be loaded from CCDB
228+
void disableCorrectionCCDB(const CalibsdEdx calib) { mCalibsLoad = ~calib & mCalibsLoad; }
229+
230+
/// check if a correction will be loaded from CCDB
231+
/// \param calib calibration which will be loaded from CCDB
232+
bool isCorrectionCCDB(const CalibsdEdx calib) const { return ((mCalibsLoad & calib) == calib) ? true : false; }
233+
234+
/// \param applyFullGainMap if set to true the cluster charge will be corrected with the full gain map
235+
void setUsageOfFullGainMap(const bool applyFullGainMap) { mApplyFullGainMap = applyFullGainMap; }
165236
#endif // !GPUCA_GPUCODE
166237

167238
private:
168-
CalibdEdxTrackTopologySpline* mCalibTrackTopologySpline{nullptr}; ///< calibration for the track topology correction (splines)
169-
CalibdEdxTrackTopologyPol* mCalibTrackTopologyPol{nullptr}; ///< calibration for the track topology correction (polynomial)
170-
o2::gpu::TPCPadGainCalib mThresholdMap{}; ///< calibration object containing the zero supression threshold map
171-
CalibdEdxCorrection mCalibResidualdEdx{}; ///< calibration for the residual dE/dx correction
239+
CalibdEdxTrackTopologySpline* mCalibTrackTopologySpline{nullptr}; ///< calibration for the track topology correction (splines)
240+
CalibdEdxTrackTopologyPol* mCalibTrackTopologyPol{nullptr}; ///< calibration for the track topology correction (polynomial)
241+
o2::gpu::TPCPadGainCalib mThresholdMap{}; ///< calibration object containing the zero supression threshold map
242+
o2::gpu::TPCPadGainCalib mGainMap{}; ///< calibration object containing the gain map
243+
o2::gpu::TPCPadGainCalib mGainMapResidual{}; ///< calibration object containing the residual gain map
244+
CalibdEdxCorrection mCalibResidualdEdx{}; ///< calibration for the residual dE/dx correction
245+
bool mApplyFullGainMap{false}; ///< if set to true the cluster charge will be corrected with the full gain map (when the gain map was not applied during the clusterizer)
246+
CalibsdEdx mCalibsLoad{CalibsdEdx::CalTopologyPol | CalibsdEdx::CalThresholdMap | CalibsdEdx::CalGainMap | CalibsdEdx::CalResidualGainMap | CalibsdEdx::CalTimeGain}; ///< flags to set which corrections will be loaded from the CCDB and used during calculation of the dE/dx
172247

173248
#if !defined(GPUCA_GPUCODE)
174249
template <class Type>
@@ -179,6 +254,9 @@ class CalibdEdxContainer : public o2::gpu::FlatObject
179254

180255
template <class Type>
181256
void loadTopologyCorrectionFromFile(std::string_view fileName, Type*& obj);
257+
258+
template <class Type>
259+
void setTopologyCorrection(const Type& calibTrackTopologyTmp, Type*& obj);
182260
#endif
183261

184262
template <class Type>
@@ -190,6 +268,14 @@ class CalibdEdxContainer : public o2::gpu::FlatObject
190268
#if !defined(GPUCA_GPUCODE)
191269
template <class Type>
192270
void cloneFromObject(Type*& obj, const Type* objOld, char* newFlatBufferPtr, const char* oldFlatBufferPtr);
271+
272+
/// this functions 'smoothes' a CalDet by calculating for each value in a pad the average value using the neighbouring pads, but do not take into account the current pad
273+
/// \return returns 'smoothed' CalDet object
274+
/// \param thresholdMap zero supression threshold map which will be 'smoothed'
275+
/// \param maxThreshold max threshold value which will be considered for averaging
276+
/// \param nPadsInRowCl number of pads in row direction which will be taken into account (+- nPadsInRowCl)
277+
/// \param nPadsInPadCl number of pads in pad direction which will be taken into account (+- nPadsInPadCl)
278+
CalDet<float> processThresholdMap(const CalDet<float>& thresholdMap, const float maxThreshold, const int nPadsInRowCl = 2, const int nPadsInPadCl = 2) const;
193279
#endif
194280

195281
#ifndef GPUCA_ALIROOT_LIB

0 commit comments

Comments
 (0)