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#if !defined(GPUCA_STANDALONE)
16#include "TFile.h"
17#include "TPCBase/CalDet.h"
18#include "Framework/Logger.h"
19#include "clusterFinderDefs.h"
20#endif
21#include "CalibdEdxContainer.h"
22
23using namespace o2::gpu;
24using namespace o2::tpc;
25
26#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
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#endif
53
54void CalibdEdxContainer::moveBufferTo(char* newFlatBufferPtr)
55{
56 char* oldFlatBufferPtr = mFlatBufferPtr;
57 FlatObject::moveBufferTo(newFlatBufferPtr);
58 char* currFlatBufferPtr = mFlatBufferPtr;
59 mFlatBufferPtr = oldFlatBufferPtr;
60 setActualBufferAddress(currFlatBufferPtr);
61}
62
64{
65 if (mCalibTrackTopologySpline) {
66 mCalibTrackTopologySpline->destroy();
67 }
68 if (mCalibTrackTopologyPol) {
69 mCalibTrackTopologyPol->destroy();
70 }
71 mCalibTrackTopologySpline = nullptr;
72 mCalibTrackTopologyPol = nullptr;
74}
75
76void CalibdEdxContainer::setActualBufferAddress(char* actualFlatBufferPtr)
77{
78 FlatObject::setActualBufferAddress(actualFlatBufferPtr);
79 if (mCalibTrackTopologyPol) {
80 setActualBufferAddress(mCalibTrackTopologyPol);
81 } else if (mCalibTrackTopologySpline) {
82 setActualBufferAddress(mCalibTrackTopologySpline);
83 } else {
84 mCalibTrackTopologyPol = nullptr;
85 mCalibTrackTopologySpline = nullptr;
86 }
87}
88
89template <class Type>
91{
92 // set the pointer to the new location of the buffer
93 obj = reinterpret_cast<Type*>(mFlatBufferPtr);
94
95 // set buffer of the spline container class to the correct position
96 obj->setActualBufferAddress(mFlatBufferPtr + sizeOfCalibdEdxTrackTopologyObj<Type>());
97}
98
99void CalibdEdxContainer::setFutureBufferAddress(char* futureFlatBufferPtr)
100{
101 if (mCalibTrackTopologyPol) {
102 setFutureBufferAddress(mCalibTrackTopologyPol, futureFlatBufferPtr);
103 } else if (mCalibTrackTopologySpline) {
104 setFutureBufferAddress(mCalibTrackTopologySpline, futureFlatBufferPtr);
105 } else {
106 mCalibTrackTopologyPol = nullptr;
107 mCalibTrackTopologySpline = nullptr;
108 }
109 FlatObject::setFutureBufferAddress(futureFlatBufferPtr);
110}
111
112template <class Type>
113void CalibdEdxContainer::setFutureBufferAddress(Type*& obj, char* futureFlatBufferPtr)
114{
115 // set pointer of the polynomial container to correct new flat buffer
116 char* distBuffer = FlatObject::relocatePointer(mFlatBufferPtr, futureFlatBufferPtr, obj->getFlatBufferPtr());
117 obj->setFutureBufferAddress(distBuffer);
118
119 // set member to correct new flat buffer
120 obj = FlatObject::relocatePointer(mFlatBufferPtr, futureFlatBufferPtr, obj);
121}
122
123#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
124
126{
127 if (mCalibTrackTopologyPol) {
128 return mCalibTrackTopologyPol->getMinThreshold();
129 } else {
130 const float minThr = 0;
131 LOGP(info, "Topology correction not set! Returning default min threshold of: {}", minThr);
132 return minThr;
133 }
134}
135
137{
138 if (mCalibTrackTopologyPol) {
139 return mCalibTrackTopologyPol->getMaxThreshold();
140 } else {
141 const float maxThr = 1;
142 LOGP(info, "Topology correction not set! Returning default max threshold of: {}", maxThr);
143 return maxThr;
144 }
145}
146
148{
149 loadTopologyCorrectionFromFile(fileName, mCalibTrackTopologyPol);
150}
151
153{
154 loadTopologyCorrectionFromFile(fileName, mCalibTrackTopologySpline);
155}
156
158{
159 setTopologyCorrection(calibTrackTopology, mCalibTrackTopologyPol);
160 mCalibTrackTopologySpline = nullptr;
161}
162
164{
165 CalibdEdxTrackTopologyPol calibTrackTopology;
166 calibTrackTopology.setDefaultPolynomials();
167 setTopologyCorrection(calibTrackTopology, mCalibTrackTopologyPol);
168 mCalibTrackTopologySpline = nullptr;
169}
170
172{
173 setTopologyCorrection(calibTrackTopology, mCalibTrackTopologySpline);
174 mCalibTrackTopologyPol = nullptr;
175}
176
177void CalibdEdxContainer::loadZeroSupresssionThresholdFromFile(std::string_view fileName, std::string_view objName, const float minCorrectionFactor, const float maxCorrectionFactor)
178{
179 TFile fInp(fileName.data(), "READ");
180 CalDet<float>* threshold = nullptr;
181 fInp.GetObject(objName.data(), threshold);
182 setZeroSupresssionThreshold(*threshold, minCorrectionFactor, maxCorrectionFactor);
183 delete threshold;
184}
185
186void CalibdEdxContainer::setZeroSupresssionThreshold(const CalDet<float>& thresholdMap, const float minCorrectionFactor, const float maxCorrectionFactor)
187{
188 const auto thresholdMapProcessed = processThresholdMap(thresholdMap, maxCorrectionFactor);
189 o2::gpu::TPCPadGainCalib thresholdMapTmp(thresholdMapProcessed, minCorrectionFactor, maxCorrectionFactor, false);
190 mThresholdMap = thresholdMapTmp;
191}
192
193CalDet<float> CalibdEdxContainer::processThresholdMap(const CalDet<float>& thresholdMap, const float maxThreshold, const int32_t nPadsInRowCl, const int32_t nPadsInPadCl) const
194{
195 CalDet<float> thresholdMapProcessed(thresholdMap);
196
197 for (uint32_t sector = 0; sector < Mapper::NSECTORS; ++sector) {
198 for (uint32_t region = 0; region < Mapper::NREGIONS; ++region) {
199 const int32_t maxRow = Mapper::ROWSPERREGION[region] - 1;
200 for (int32_t lrow = 0; lrow <= maxRow; ++lrow) {
201 // find first row of the cluster
202 const int32_t rowStart = std::clamp(lrow - nPadsInRowCl, 0, maxRow);
203 const int32_t rowEnd = std::clamp(lrow + nPadsInRowCl, 0, maxRow);
204 const int32_t addPadsStart = Mapper::ADDITIONALPADSPERROW[region][lrow];
205
206 for (uint32_t pad = 0; pad < Mapper::PADSPERROW[region][lrow]; ++pad) {
207 float sumThr = 0;
208 int32_t countThr = 0;
209 // loop ove the rows from the cluster
210 for (int32_t rowCl = rowStart; rowCl <= rowEnd; ++rowCl) {
211 // shift local pad in row in case current row from the cluster has more pads in the row
212 const int32_t addPadsCl = Mapper::ADDITIONALPADSPERROW[region][rowCl];
213 const int32_t diffAddPads = addPadsCl - addPadsStart;
214 const int32_t padClCentre = pad + diffAddPads;
215
216 const int32_t maxPad = Mapper::PADSPERROW[region][rowCl] - 1;
217 const int32_t padStart = std::clamp(padClCentre - nPadsInPadCl, 0, maxPad);
218 const int32_t padEnd = std::clamp(padClCentre + nPadsInPadCl, 0, maxPad);
219 for (int32_t padCl = padStart; padCl <= padEnd; ++padCl) {
220 const int32_t globalPad = Mapper::getGlobalPadNumber(rowCl, padCl, region);
221 // skip for current cluster position as the charge there is not effected from the thresold
222 if (padCl == pad && rowCl == lrow) {
223 continue;
224 }
225
226 float threshold = thresholdMap.getValue(sector, globalPad);
227 if (threshold > maxThreshold) {
228 threshold = maxThreshold;
229 }
230
231 sumThr += threshold;
232 ++countThr;
233 }
234 }
235 const float meanThresold = sumThr / countThr;
236 const int32_t globalPad = Mapper::getGlobalPadNumber(lrow, pad, region);
237 thresholdMapProcessed.setValue(sector, globalPad, meanThresold);
238 }
239 }
240 }
241 }
242 return thresholdMapProcessed;
243}
244
246{
247 mDeadChannelMap.setFromMap(deadMap);
248}
249
250void CalibdEdxContainer::setGainMap(const CalDet<float>& gainMap, const float minGain, const float maxGain)
251{
252 o2::gpu::TPCPadGainCalib gainMapTmp(gainMap, minGain, maxGain, false);
253 mGainMap = gainMapTmp;
254}
255
256void CalibdEdxContainer::setGainMapResidual(const CalDet<float>& gainMapResidual, const float minResidualGain, const float maxResidualGain)
257{
258 o2::gpu::TPCPadGainCalib gainMapResTmp(gainMapResidual, minResidualGain, maxResidualGain, false);
259 mGainMapResidual = gainMapResTmp;
260}
261
263{
265 mThresholdMap.setMinCorrectionFactor(defaultVal - 0.1f);
266 mThresholdMap.setMaxCorrectionFactor(defaultVal + 0.1f);
267 for (int32_t sector = 0; sector < o2::tpc::constants::MAXSECTOR; ++sector) {
268 for (uint16_t globPad = 0; globPad < TPC_PADS_IN_SECTOR; ++globPad) {
269 mThresholdMap.setGainCorrection(sector, globPad, defaultVal);
270 }
271 }
272}
273
274template <class Type>
275void CalibdEdxContainer::loadTopologyCorrectionFromFile(std::string_view fileName, Type*& obj)
276{
277 // load and set-up container
278 Type calibTrackTopologyTmp(fileName.data());
279 setTopologyCorrection(calibTrackTopologyTmp, obj);
280}
281
282template <class Type>
283void CalibdEdxContainer::setTopologyCorrection(const Type& calibTrackTopologyTmp, Type*& obj)
284{
286
287 // get size of the flat buffer of the splines
288 const std::size_t flatbufferSize = calibTrackTopologyTmp.getFlatBufferSize();
289
290 // size of the dEdx container without taking flat buffer into account
291 const std::size_t objSize = sizeOfCalibdEdxTrackTopologyObj<Type>();
292
293 // create mFlatBuffer with correct size
294 const std::size_t totalSize = flatbufferSize + objSize;
296
297 // setting member of CalibdEdxTrackTopologyPol to correct buffer address
298 obj = reinterpret_cast<Type*>(mFlatBufferPtr);
299
300 // deep copy of CalibdEdxTrackTopologyPol to buffer without moving the flat buffer to correct address
301 obj->cloneFromObject(calibTrackTopologyTmp, nullptr);
302
303 // seting the buffer of the splines to current buffer
304 obj->moveBufferTo(objSize + mFlatBufferPtr);
305}
306
307#endif
Definition of container class for dE/dx corrections.
void setFutureBufferAddress(char *futureFlatBufferPtr)
Definition FlatObject.h:557
void destroy()
_______________ Utilities _______________________________________________
Definition FlatObject.h:349
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:285
void setActualBufferAddress(char *actualFlatBufferPtr)
_____________ Methods for moving the class with its external buffer to another location _____________...
Definition FlatObject.h:547
void startConstruction()
_____________ Construction _________
Definition FlatObject.h:342
void moveBufferTo(char *newBufferPtr)
Definition FlatObject.h:396
void finishConstruction(int32_t flatBufferSize)
Definition FlatObject.h:358
void cloneFromObject(const FlatObject &obj, char *newFlatBufferPtr)
Definition FlatObject.h:373
const T getValue(const int sec, const int globalPadInSector) const
Definition CalDet.h:154
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_PADS_IN_SECTOR
constexpr int MAXSECTOR
Definition Constants.h:28
Global TPC definitions and constants.
Definition SimTraits.h:167
void setFromMap(const o2::tpc::CalDet< bool > &)
setting the stored values from CalDet