forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalibdEdxContainer.cxx
More file actions
307 lines (265 loc) · 11.3 KB
/
Copy pathCalibdEdxContainer.cxx
File metadata and controls
307 lines (265 loc) · 11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file CalibdEdxContainer.cxx
/// \author Matthias Kleiner <mkleiner@ikf.uni-frankfurt.de>
#if !defined(GPUCA_STANDALONE)
#include "TFile.h"
#include "TPCBase/CalDet.h"
#include "Framework/Logger.h"
#include "clusterFinderDefs.h"
#endif
#include "CalibdEdxContainer.h"
using namespace o2::gpu;
using namespace o2::tpc;
#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
void CalibdEdxContainer::cloneFromObject(const CalibdEdxContainer& obj, char* newFlatBufferPtr)
{
FlatObject::cloneFromObject(obj, newFlatBufferPtr);
mCalibResidualdEdx = obj.mCalibResidualdEdx;
mThresholdMap = obj.mThresholdMap;
mGainMap = obj.mGainMap;
mGainMapResidual = obj.mGainMapResidual;
mDeadChannelMap = obj.mDeadChannelMap;
mApplyFullGainMap = obj.mApplyFullGainMap;
mCalibsLoad = obj.mCalibsLoad;
if (obj.mCalibTrackTopologyPol) {
subobjectCloneFromObject(mCalibTrackTopologyPol, obj.mCalibTrackTopologyPol);
}
if (obj.mCalibTrackTopologySpline) {
subobjectCloneFromObject(mCalibTrackTopologySpline, obj.mCalibTrackTopologySpline);
}
}
template <class Type>
void CalibdEdxContainer::subobjectCloneFromObject(Type*& obj, const Type* objOld)
{
obj = reinterpret_cast<Type*>(mFlatBufferPtr);
memset((void*)obj, 0, sizeof(*obj));
obj->cloneFromObject(*objOld, mFlatBufferPtr + sizeOfCalibdEdxTrackTopologyObj<Type>());
}
#endif
void CalibdEdxContainer::moveBufferTo(char* newFlatBufferPtr)
{
char* oldFlatBufferPtr = mFlatBufferPtr;
FlatObject::moveBufferTo(newFlatBufferPtr);
char* currFlatBufferPtr = mFlatBufferPtr;
mFlatBufferPtr = oldFlatBufferPtr;
setActualBufferAddress(currFlatBufferPtr);
}
void CalibdEdxContainer::destroy()
{
if (mCalibTrackTopologySpline) {
mCalibTrackTopologySpline->destroy();
}
if (mCalibTrackTopologyPol) {
mCalibTrackTopologyPol->destroy();
}
mCalibTrackTopologySpline = nullptr;
mCalibTrackTopologyPol = nullptr;
FlatObject::destroy();
}
void CalibdEdxContainer::setActualBufferAddress(char* actualFlatBufferPtr)
{
FlatObject::setActualBufferAddress(actualFlatBufferPtr);
if (mCalibTrackTopologyPol) {
setActualBufferAddress(mCalibTrackTopologyPol);
} else if (mCalibTrackTopologySpline) {
setActualBufferAddress(mCalibTrackTopologySpline);
} else {
mCalibTrackTopologyPol = nullptr;
mCalibTrackTopologySpline = nullptr;
}
}
template <class Type>
void CalibdEdxContainer::setActualBufferAddress(Type*& obj)
{
// set the pointer to the new location of the buffer
obj = reinterpret_cast<Type*>(mFlatBufferPtr);
// set buffer of the spline container class to the correct position
obj->setActualBufferAddress(mFlatBufferPtr + sizeOfCalibdEdxTrackTopologyObj<Type>());
}
void CalibdEdxContainer::setFutureBufferAddress(char* futureFlatBufferPtr)
{
if (mCalibTrackTopologyPol) {
setFutureBufferAddress(mCalibTrackTopologyPol, futureFlatBufferPtr);
} else if (mCalibTrackTopologySpline) {
setFutureBufferAddress(mCalibTrackTopologySpline, futureFlatBufferPtr);
} else {
mCalibTrackTopologyPol = nullptr;
mCalibTrackTopologySpline = nullptr;
}
FlatObject::setFutureBufferAddress(futureFlatBufferPtr);
}
template <class Type>
void CalibdEdxContainer::setFutureBufferAddress(Type*& obj, char* futureFlatBufferPtr)
{
// set pointer of the polynomial container to correct new flat buffer
char* distBuffer = FlatObject::relocatePointer(mFlatBufferPtr, futureFlatBufferPtr, obj->getFlatBufferPtr());
obj->setFutureBufferAddress(distBuffer);
// set member to correct new flat buffer
obj = FlatObject::relocatePointer(mFlatBufferPtr, futureFlatBufferPtr, obj);
}
#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
float CalibdEdxContainer::getMinZeroSupresssionThreshold() const
{
if (mCalibTrackTopologyPol) {
return mCalibTrackTopologyPol->getMinThreshold();
} else {
const float minThr = 0;
LOGP(info, "Topology correction not set! Returning default min threshold of: {}", minThr);
return minThr;
}
}
float CalibdEdxContainer::getMaxZeroSupresssionThreshold() const
{
if (mCalibTrackTopologyPol) {
return mCalibTrackTopologyPol->getMaxThreshold();
} else {
const float maxThr = 1;
LOGP(info, "Topology correction not set! Returning default max threshold of: {}", maxThr);
return maxThr;
}
}
void CalibdEdxContainer::loadPolTopologyCorrectionFromFile(std::string_view fileName)
{
loadTopologyCorrectionFromFile(fileName, mCalibTrackTopologyPol);
}
void CalibdEdxContainer::loadSplineTopologyCorrectionFromFile(std::string_view fileName)
{
loadTopologyCorrectionFromFile(fileName, mCalibTrackTopologySpline);
}
void CalibdEdxContainer::setPolTopologyCorrection(const CalibdEdxTrackTopologyPol& calibTrackTopology)
{
setTopologyCorrection(calibTrackTopology, mCalibTrackTopologyPol);
mCalibTrackTopologySpline = nullptr;
}
void CalibdEdxContainer::setDefaultPolTopologyCorrection()
{
CalibdEdxTrackTopologyPol calibTrackTopology;
calibTrackTopology.setDefaultPolynomials();
setTopologyCorrection(calibTrackTopology, mCalibTrackTopologyPol);
mCalibTrackTopologySpline = nullptr;
}
void CalibdEdxContainer::setSplineTopologyCorrection(const CalibdEdxTrackTopologySpline& calibTrackTopology)
{
setTopologyCorrection(calibTrackTopology, mCalibTrackTopologySpline);
mCalibTrackTopologyPol = nullptr;
}
void CalibdEdxContainer::loadZeroSupresssionThresholdFromFile(std::string_view fileName, std::string_view objName, const float minCorrectionFactor, const float maxCorrectionFactor)
{
TFile fInp(fileName.data(), "READ");
CalDet<float>* threshold = nullptr;
fInp.GetObject(objName.data(), threshold);
setZeroSupresssionThreshold(*threshold, minCorrectionFactor, maxCorrectionFactor);
delete threshold;
}
void CalibdEdxContainer::setZeroSupresssionThreshold(const CalDet<float>& thresholdMap, const float minCorrectionFactor, const float maxCorrectionFactor)
{
const auto thresholdMapProcessed = processThresholdMap(thresholdMap, maxCorrectionFactor);
o2::gpu::TPCPadGainCalib thresholdMapTmp(thresholdMapProcessed, minCorrectionFactor, maxCorrectionFactor, false);
mThresholdMap = thresholdMapTmp;
}
CalDet<float> CalibdEdxContainer::processThresholdMap(const CalDet<float>& thresholdMap, const float maxThreshold, const int32_t nPadsInRowCl, const int32_t nPadsInPadCl) const
{
CalDet<float> thresholdMapProcessed(thresholdMap);
for (uint32_t sector = 0; sector < Mapper::NSECTORS; ++sector) {
for (uint32_t region = 0; region < Mapper::NREGIONS; ++region) {
const int32_t maxRow = Mapper::ROWSPERREGION[region] - 1;
for (int32_t lrow = 0; lrow <= maxRow; ++lrow) {
// find first row of the cluster
const int32_t rowStart = std::clamp(lrow - nPadsInRowCl, 0, maxRow);
const int32_t rowEnd = std::clamp(lrow + nPadsInRowCl, 0, maxRow);
const int32_t addPadsStart = Mapper::ADDITIONALPADSPERROW[region][lrow];
for (uint32_t pad = 0; pad < Mapper::PADSPERROW[region][lrow]; ++pad) {
float sumThr = 0;
int32_t countThr = 0;
// loop ove the rows from the cluster
for (int32_t rowCl = rowStart; rowCl <= rowEnd; ++rowCl) {
// shift local pad in row in case current row from the cluster has more pads in the row
const int32_t addPadsCl = Mapper::ADDITIONALPADSPERROW[region][rowCl];
const int32_t diffAddPads = addPadsCl - addPadsStart;
const int32_t padClCentre = pad + diffAddPads;
const int32_t maxPad = Mapper::PADSPERROW[region][rowCl] - 1;
const int32_t padStart = std::clamp(padClCentre - nPadsInPadCl, 0, maxPad);
const int32_t padEnd = std::clamp(padClCentre + nPadsInPadCl, 0, maxPad);
for (int32_t padCl = padStart; padCl <= padEnd; ++padCl) {
const int32_t globalPad = Mapper::getGlobalPadNumber(rowCl, padCl, region);
// skip for current cluster position as the charge there is not effected from the thresold
if (padCl == pad && rowCl == lrow) {
continue;
}
float threshold = thresholdMap.getValue(sector, globalPad);
if (threshold > maxThreshold) {
threshold = maxThreshold;
}
sumThr += threshold;
++countThr;
}
}
const float meanThresold = sumThr / countThr;
const int32_t globalPad = Mapper::getGlobalPadNumber(lrow, pad, region);
thresholdMapProcessed.setValue(sector, globalPad, meanThresold);
}
}
}
}
return thresholdMapProcessed;
}
void CalibdEdxContainer::setDeadChannelMap(const CalDet<bool>& deadMap)
{
mDeadChannelMap.setFromMap(deadMap);
}
void CalibdEdxContainer::setGainMap(const CalDet<float>& gainMap, const float minGain, const float maxGain)
{
o2::gpu::TPCPadGainCalib gainMapTmp(gainMap, minGain, maxGain, false);
mGainMap = gainMapTmp;
}
void CalibdEdxContainer::setGainMapResidual(const CalDet<float>& gainMapResidual, const float minResidualGain, const float maxResidualGain)
{
o2::gpu::TPCPadGainCalib gainMapResTmp(gainMapResidual, minResidualGain, maxResidualGain, false);
mGainMapResidual = gainMapResTmp;
}
void CalibdEdxContainer::setDefaultZeroSupresssionThreshold()
{
const float defaultVal = getMinZeroSupresssionThreshold() + (getMaxZeroSupresssionThreshold() - getMinZeroSupresssionThreshold()) / 2;
mThresholdMap.setMinCorrectionFactor(defaultVal - 0.1f);
mThresholdMap.setMaxCorrectionFactor(defaultVal + 0.1f);
for (int32_t sector = 0; sector < o2::tpc::constants::MAXSECTOR; ++sector) {
for (uint16_t globPad = 0; globPad < TPC_REAL_PADS_IN_SECTOR; ++globPad) {
mThresholdMap.setGainCorrection(sector, globPad, defaultVal);
}
}
}
template <class Type>
void CalibdEdxContainer::loadTopologyCorrectionFromFile(std::string_view fileName, Type*& obj)
{
// load and set-up container
Type calibTrackTopologyTmp(fileName.data());
setTopologyCorrection(calibTrackTopologyTmp, obj);
}
template <class Type>
void CalibdEdxContainer::setTopologyCorrection(const Type& calibTrackTopologyTmp, Type*& obj)
{
FlatObject::startConstruction();
// get size of the flat buffer of the splines
const std::size_t flatbufferSize = calibTrackTopologyTmp.getFlatBufferSize();
// size of the dEdx container without taking flat buffer into account
const std::size_t objSize = sizeOfCalibdEdxTrackTopologyObj<Type>();
// create mFlatBuffer with correct size
const std::size_t totalSize = flatbufferSize + objSize;
FlatObject::finishConstruction(totalSize);
// setting member of CalibdEdxTrackTopologyPol to correct buffer address
obj = reinterpret_cast<Type*>(mFlatBufferPtr);
// deep copy of CalibdEdxTrackTopologyPol to buffer without moving the flat buffer to correct address
obj->cloneFromObject(calibTrackTopologyTmp, nullptr);
// seting the buffer of the splines to current buffer
obj->moveBufferTo(objSize + mFlatBufferPtr);
}
#endif