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