Project
Loading...
Searching...
No Matches
Spline1DSpec.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
16
17#include "Spline1DSpec.h"
18
19#include <iostream>
20#include <algorithm>
21
22#if !defined(GPUCA_STANDALONE) // code invisible on GPU and in the standalone compilation
23#include "Spline1DHelper.h"
24#include "TFile.h"
25#include "GPUCommonMath.h"
27#endif
28
29using namespace std;
30using namespace o2::gpu;
31
32template <class DataT>
33void Spline1DContainer<DataT, FlatObject>::recreate(int32_t nYdim, int32_t numberOfKnots)
34{
37
38 if (numberOfKnots < 2) {
39 numberOfKnots = 2;
40 }
41
42 std::vector<int32_t> knots(numberOfKnots);
43 for (int32_t i = 0; i < numberOfKnots; i++) {
44 knots[i] = i;
45 }
46 recreate(nYdim, numberOfKnots, knots.data());
47}
48
49template <class DataT>
50void Spline1DContainer<DataT, FlatObject>::recreate(int32_t nYdim, int32_t numberOfKnots, const int32_t inputKnots[])
51{
62
63 this->mYdim = (nYdim >= 0) ? nYdim : 0;
64
65 std::vector<int32_t> knotU;
66
67 { // sort knots
68 std::vector<int32_t> tmp;
69 for (int32_t i = 0; i < numberOfKnots; i++) {
70 tmp.push_back(inputKnots[i]);
71 }
72 std::sort(tmp.begin(), tmp.end());
73
74 knotU.push_back(0); // first knot at 0
75
76 for (uint32_t i = 1; i < tmp.size(); ++i) {
77 int32_t u = tmp[i] - tmp[0];
78 if (knotU.back() < u) { // remove duplicated knots
79 knotU.push_back(u);
80 }
81 }
82 if (knotU.back() < 1) { // there is only one knot at u=0, add the second one at u=1
83 knotU.push_back(1);
84 }
85 }
86
87 this->mNumberOfKnots = knotU.size();
88 this->mUmax = knotU.back();
89 this->mXmin = 0.;
90 this->mXtoUscale = 1.;
91
92 const int32_t uToKnotMapOffset = this->mNumberOfKnots * sizeof(Knot<DataT>);
93 int32_t parametersOffset = uToKnotMapOffset + (this->mUmax + 1) * sizeof(int32_t);
94 int32_t bufferSize = parametersOffset;
95 if (this->mYdim > 0) {
96 parametersOffset = this->alignSize(bufferSize, this->getParameterAlignmentBytes());
97 bufferSize = parametersOffset + this->getSizeOfParameters();
98 }
99
101
102 this->mUtoKnotMap = reinterpret_cast<int32_t*>(this->mFlatBufferPtr + uToKnotMapOffset);
103 this->mParameters = reinterpret_cast<DataT*>(this->mFlatBufferPtr + parametersOffset);
104
105 for (int32_t i = 0; i < this->getNumberOfParameters(); i++) {
106 this->mParameters[i] = 0;
107 }
108
109 Knot<DataT>* s = getKnots();
110
111 for (int32_t i = 0; i < this->mNumberOfKnots; i++) {
112 s[i].u = knotU[i];
113 }
114
115 for (int32_t i = 0; i < this->mNumberOfKnots - 1; i++) {
116 s[i].Li = 1. / (s[i + 1].u - s[i].u); // do division in double
117 }
118
119 s[this->mNumberOfKnots - 1].Li = 0.; // the value will not be used, we define it for consistency
120
121 // Set up the map (integer U) -> (knot index)
122
123 int32_t* map = getUtoKnotMap();
124
125 const int32_t iKnotMax = this->mNumberOfKnots - 2;
126
127 //
128 // With iKnotMax=nKnots-2 we map the U==Umax coordinate to the last [nKnots-2, nKnots-1] segment.
129 // This trick allows one to avoid a special condition for this edge case.
130 // Any U from [0,Umax] is mapped to some knot_i such, that the next knot_i+1 always exist
131 //
132
133 for (int32_t u = 0, iKnot = 0; u <= this->mUmax; u++) {
134 if ((knotU[iKnot + 1] == u) && (iKnot < iKnotMax)) {
135 iKnot = iKnot + 1;
136 }
137 map[u] = iKnot;
138 }
139}
140
141template <class DataT>
143{
144 printf(" Spline 1D: \n");
145 printf(" mNumberOfKnots = %d \n", this->mNumberOfKnots);
146 printf(" mUmax = %d\n", this->mUmax);
147 printf(" mUtoKnotMap = %p \n", (void*)this->mUtoKnotMap);
148 printf(" knots: ");
149 for (int32_t i = 0; i < this->mNumberOfKnots; i++) {
150 printf("%d ", (int32_t)getKnot(i).u);
151 }
152 printf("\n");
153}
154
155#if !defined(GPUCA_STANDALONE)
156
157template <class DataT>
159 double xMin, double xMax,
160 std::function<void(double x, double f[])> F,
161 int32_t nAxiliaryDataPoints)
162{
165 helper.approximateFunction(*this, xMin, xMax, F, nAxiliaryDataPoints);
166}
167
168template <class DataT>
170{
172 return FlatObject::writeToFile(*this, outf, name);
173}
174
175template <class DataT>
177{
179 return FlatObject::readFromFile<Spline1DContainer<DataT, FlatObject>>(inpf, name);
180}
181
182template <class DataT>
184{
186}
187
188#endif
189
190template <class DataT>
192{
194 const char* oldFlatBufferPtr = obj.mFlatBufferPtr;
195 FlatObject::cloneFromObject(obj, newFlatBufferPtr);
196 this->mYdim = obj.mYdim;
197 this->mNumberOfKnots = obj.mNumberOfKnots;
198 this->mUmax = obj.mUmax;
199 this->mXmin = obj.mXmin;
200 this->mXtoUscale = obj.mXtoUscale;
201 this->mUtoKnotMap = FlatObject::relocatePointer(oldFlatBufferPtr, this->mFlatBufferPtr, obj.mUtoKnotMap);
202 this->mParameters = FlatObject::relocatePointer(oldFlatBufferPtr, this->mFlatBufferPtr, obj.mParameters);
203}
204
205template <class DataT>
207{
209 char* oldFlatBufferPtr = this->mFlatBufferPtr;
210 FlatObject::moveBufferTo(newFlatBufferPtr);
211 char* currFlatBufferPtr = this->mFlatBufferPtr;
212 this->mFlatBufferPtr = oldFlatBufferPtr;
213 setActualBufferAddress(currFlatBufferPtr);
214}
215
216template <class DataT>
217template <class OtherFlatBase>
219{
222 this->mYdim = src.getYdimensions();
223 this->mNumberOfKnots = src.getNumberOfKnots();
224 this->mUmax = src.getUmax();
225 this->mXmin = src.getXmin();
226 this->mXtoUscale = src.getXtoUscale();
227 this->mFlatBufferSize = src.getFlatBufferSize();
228 this->mUtoKnotMap = nullptr;
229 this->mParameters = nullptr;
230}
231
232template <class DataT>
234{
235 this->mNumberOfKnots = 0;
236 this->mUmax = 0;
237 this->mYdim = 0;
238 this->mXmin = 0.;
239 this->mXtoUscale = 1.;
240 this->mUtoKnotMap = nullptr;
241 this->mParameters = nullptr;
243}
244
245template <class DataT>
247{
249 FlatObject::setActualBufferAddress(actualFlatBufferPtr);
250
251 const int32_t uToKnotMapOffset = this->mNumberOfKnots * sizeof(Knot<DataT>);
252 this->mUtoKnotMap = reinterpret_cast<int32_t*>(this->mFlatBufferPtr + uToKnotMapOffset);
253 int32_t parametersOffset = uToKnotMapOffset + (this->mUmax + 1) * sizeof(int32_t);
254 if (this->mYdim > 0) {
255 parametersOffset = this->alignSize(parametersOffset, this->getParameterAlignmentBytes());
256 }
257 mParameters = reinterpret_cast<DataT*>(this->mFlatBufferPtr + parametersOffset);
258}
259
260template <class DataT>
262{
264 this->mUtoKnotMap = FlatObject::relocatePointer(this->mFlatBufferPtr, futureFlatBufferPtr, this->mUtoKnotMap);
265 this->mParameters = FlatObject::relocatePointer(this->mFlatBufferPtr, futureFlatBufferPtr, this->mParameters);
266 FlatObject::setFutureBufferAddress(futureFlatBufferPtr);
267}
268
275
276// Explicit instantiations for NoFlatObject (used by TPCFastTransformPOD)
281// importFrom instantiation for the FlatObject -> NoFlatObject conversion used in create()
284// importFrom for FlatObject container (FlatObject -> FlatObject, e.g. when using as a copy tool)
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
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
Definition of Spline1DHelper class.
templateClassImp(o2::gpu::Spline1DContainer)
Definition of Spline1DSpec class.
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
static int32_t writeToFile(T &obj, TFile &outf, const char *name)
write a child class object to the file
Definition FlatObject.h:492
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
void approximateFunction(Spline1DContainer< DataT, FlatObject > &spline, double xMin, double xMax, std::function< void(double x, double f[])> F, int32_t nAuxiliaryDataPoints=4)
Create best-fit spline parameters for a function F.
static int32_t test(const bool draw=0, const bool drawDataPoints=1)
Test the Spline1D class functionality.
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint const GLchar * name
Definition glcorearb.h:781
GLdouble f
Definition glcorearb.h:310
size_t alignSize(size_t sizeBytes)
align size to given diven number of bytes
TCanvas * drawDataPoints(TMultiGraph *mg, double min, double max)