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.
unsigned short int uint16_t
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual sector
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder int32_t
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
Global TPC definitions and constants.
void setFromMap(const o2::tpc::CalDet< bool > &)
setting the stored values from CalDet