Project
Loading...
Searching...
No Matches
MillePedeRecord.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
13
15#include <TMath.h>
16#include "Framework/Logger.h"
17
18using namespace o2::fwdalign;
19
21
22//_____________________________________________________________________________
24 : fSize(0),
25 fNGroups(0),
26 fRunID(0),
27 fGroupID(nullptr),
28 fIndex(nullptr),
29 fValue(nullptr),
30 fWeight(1)
31{
32 SetUniqueID(0);
33}
34
35//_____________________________________________________________________________
37 : TObject(src),
38 fSize(src.fSize),
39 fNGroups(src.fNGroups),
40 fRunID(src.fRunID),
41 fGroupID(nullptr),
42 fIndex(nullptr),
43 fValue(nullptr),
44 fWeight(src.fWeight)
45{
46 fIndex = new Int_t[GetDtBufferSize()];
47 memcpy(fIndex, src.fIndex, fSize * sizeof(Int_t));
48 fValue = new Double_t[GetDtBufferSize()];
49 memcpy(fValue, src.fValue, fSize * sizeof(Double_t));
50 fGroupID = new UShort_t[GetGrBufferSize()];
51 memcpy(fGroupID, src.fGroupID, GetGrBufferSize() * sizeof(UShort_t));
52}
53
54//_____________________________________________________________________________
56{
57 if (this != &rhs) {
58 Reset();
59 for (int i = 0; i < rhs.GetSize(); i++) {
60 Double_t val;
61 Int_t ind;
62 rhs.GetIndexValue(i, ind, val);
63 AddIndexValue(ind, val);
64 }
65 fWeight = rhs.fWeight;
66 fRunID = rhs.fRunID;
67 for (int i = 0; i < rhs.GetNGroups(); i++) {
68 MarkGroup(rhs.GetGroupID(i));
69 }
70 }
71 return *this;
72}
73
74//_____________________________________________________________________________
76{
77 delete[] fIndex;
78 delete[] fValue;
79 delete[] fGroupID;
80}
81
82//_____________________________________________________________________________
84{
85 fSize = 0;
86 for (int i = fNGroups; i--;) {
87 fGroupID[i] = 0;
88 }
89 fNGroups = 0;
90 fRunID = 0;
91 fWeight = 1.;
92}
93
94//_____________________________________________________________________________
95void MillePedeRecord::Print(const Option_t*) const
96{
97 if (!fSize) {
98 LOG(info) << "No data";
99 return;
100 }
101 int cnt = 0, point = 0;
102
103 if (fNGroups) {
104 printf("Groups: ");
105 }
106 for (int i = 0; i < fNGroups; i++) {
107 printf("%4d |", GetGroupID(i));
108 }
109 printf("Run: %9d Weight: %+.2e\n", fRunID, fWeight);
110 while (cnt < fSize) {
111 Double_t resid = fValue[cnt++];
112 Double_t* derLoc = GetValue() + cnt;
113 int* indLoc = GetIndex() + cnt;
114 int nLoc = 0;
115 while (!IsWeight(cnt)) {
116 nLoc++;
117 cnt++;
118 }
119 Double_t weight = GetValue(cnt++);
120 Double_t* derGlo = GetValue() + cnt;
121 int* indGlo = GetIndex() + cnt;
122 int nGlo = 0;
123 while (!IsResidual(cnt) && cnt < fSize) {
124 nGlo++;
125 cnt++;
126 }
127
128 printf("\n*** Point#%2d | Residual = %+.4e | Weight = %+.4e\n", point++, resid, weight);
129 printf("Locals : ");
130 for (int i = 0; i < nLoc; i++) {
131 printf("[%5d] %+.4e|", indLoc[i], derLoc[i]);
132 }
133 printf("\n");
134 printf("Globals: ");
135 for (int i = 0; i < nGlo; i++) {
136 printf("[%5d] %+.4e|", indGlo[i], derGlo[i]);
137 }
138 printf("\n");
139 }
140}
141
142//_____________________________________________________________________________
143Double_t MillePedeRecord::GetGloResWProd(Int_t indx) const
144{
145 if (!fSize) {
146 LOG(info) << "No data";
147 return 0;
148 }
149 int cnt = 0;
150 double prodsum = 0.0;
151
152 while (cnt < fSize) {
153 Double_t resid = fValue[cnt++];
154 while (!IsWeight(cnt)) {
155 cnt++;
156 }
157 Double_t weight = GetValue(cnt++);
158 Double_t* derGlo = GetValue() + cnt;
159 int* indGlo = GetIndex() + cnt;
160 int nGlo = 0;
161 while (!IsResidual(cnt) && cnt < fSize) {
162 nGlo++;
163 cnt++;
164 }
165 for (int i = nGlo; i--;) {
166 if (indGlo[i] == indx) {
167 prodsum += resid * weight * derGlo[i];
168 }
169 }
170 }
171 return prodsum;
172}
173
174//_____________________________________________________________________________
175Double_t MillePedeRecord::GetGlobalDeriv(Int_t pnt, Int_t indx) const
176{
177 if (!fSize) {
178 LOG(error) << "No data";
179 return 0;
180 }
181 int cnt = 0, point = 0;
182 while (cnt < fSize) {
183 cnt++;
184 while (!IsWeight(cnt)) {
185 cnt++;
186 }
187 cnt++;
188 Double_t* derGlo = GetValue() + cnt;
189 int* indGlo = GetIndex() + cnt;
190 int nGlo = 0;
191 while (!IsResidual(cnt) && cnt < fSize) {
192 nGlo++;
193 cnt++;
194 }
195 if (pnt != point++) {
196 continue;
197 }
198 for (int i = nGlo; i--;) {
199 if (indGlo[i] == indx) {
200 return derGlo[i];
201 }
202 }
203 break;
204 }
205 return 0;
206}
207
208//_____________________________________________________________________________
209Double_t MillePedeRecord::GetLocalDeriv(Int_t pnt, Int_t indx) const
210{
211 if (!fSize) {
212 LOG(error) << "No data";
213 return 0;
214 }
215 int cnt = 0, point = 0;
216 while (cnt < fSize) {
217 cnt++;
218 Double_t* derLoc = GetValue() + cnt;
219 int* indLoc = GetIndex() + cnt;
220 int nLoc = 0;
221 while (!IsWeight(cnt)) {
222 nLoc++;
223 cnt++;
224 }
225 cnt++;
226 while (!IsResidual(cnt) && cnt < fSize) {
227 cnt++;
228 }
229 if (pnt != point++) {
230 continue;
231 }
232 for (int i = nLoc; i--;) {
233 if (indLoc[i] == indx) {
234 return derLoc[i];
235 }
236 }
237 break;
238 }
239 return 0;
240}
241
242//_____________________________________________________________________________
243Double_t MillePedeRecord::GetResidual(Int_t pnt) const
244{
245 if (!fSize) {
246 LOG(error) << "No data";
247 return 0;
248 }
249 int cnt = 0, point = 0;
250 while (cnt < fSize) {
251 Double_t resid = fValue[cnt++];
252 while (!IsWeight(cnt)) {
253 cnt++;
254 }
255 cnt++;
256 while (!IsResidual(cnt) && cnt < fSize) {
257 cnt++;
258 }
259 if (pnt != point++) {
260 continue;
261 }
262 return resid;
263 }
264 return 0;
265}
266
267//_____________________________________________________________________________
268Double_t MillePedeRecord::GetWeight(Int_t pnt) const
269{
270 if (!fSize) {
271 LOG(error) << "No data";
272 return 0;
273 }
274 int cnt = 0, point = 0;
275 while (cnt < fSize) {
276 cnt++;
277 while (!IsWeight(cnt)) {
278 cnt++;
279 }
280 if (point == pnt) {
281 return GetValue(cnt);
282 }
283 cnt++;
284 while (!IsResidual(cnt) && cnt < fSize) {
285 cnt++;
286 }
287 point++;
288 }
289 return -1;
290}
291
292//_____________________________________________________________________________
294{
295 bfsize = TMath::Max(bfsize, GetDtBufferSize());
296 Int_t* tmpI = new Int_t[bfsize];
297 memcpy(tmpI, fIndex, fSize * sizeof(Int_t));
298 delete[] fIndex;
299 fIndex = tmpI;
300
301 Double_t* tmpD = new Double_t[bfsize];
302 memcpy(tmpD, fValue, fSize * sizeof(Double_t));
303 delete[] fValue;
304 fValue = tmpD;
305
306 SetDtBufferSize(bfsize);
307}
308
309//_____________________________________________________________________________
311{
312 bfsize = TMath::Max(bfsize, GetGrBufferSize());
313 UShort_t* tmpI = new UShort_t[bfsize];
314 memcpy(tmpI, fGroupID, fNGroups * sizeof(UShort_t));
315 delete[] fGroupID;
316 fGroupID = tmpI;
317 for (int i = fNGroups; i < bfsize; i++) {
318 fGroupID[i] = 0;
319 }
320
321 SetGrBufferSize(bfsize);
322}
323
324//_____________________________________________________________________________
326{
327 id++; // groupID is stored as realID+1
328 if (fNGroups > 0 && fGroupID[fNGroups - 1] == id) {
329 return; // already there
330 }
331 if (fNGroups >= GetGrBufferSize()) {
332 ExpandGrBuffer(2 * (fNGroups + 1));
333 }
334 fGroupID[fNGroups++] = id;
335}
int32_t i
ClassImp(MillePedeRecord)
Class to store the data of single track processing.
Store residuals and local/global deriavtives from a single track processing.
MillePedeRecord & operator=(const MillePedeRecord &rhs)
assignment op-r
Int_t fSize
size of the record
void ExpandDtBuffer(Int_t bfsize)
add extra space for derivatives data
Int_t * fIndex
[fSize] index of variables
void AddIndexValue(Int_t ind, Double_t val)
add new pair of index/value
void Print(const Option_t *opt="") const override
print itself
Double_t GetGlobalDeriv(Int_t pnt, Int_t indx) const
get derivative over global variable indx at point pnt
UShort_t * fGroupID
[fNGroups] groups id's+1 (in increasing order)
Int_t fNGroups
number of groups (e.g. detectors) contributing
void MarkGroup(Int_t id)
mark the presence of the detector group
Int_t GetGroupID(Int_t i) const
Double_t GetGloResWProd(Int_t indx) const
get sum of derivative over global variable indx * res. at point * weight
Double32_t fWeight
global weight for the record
void ExpandGrBuffer(Int_t bfsize)
add extra space for groupID data
Double_t GetResidual(Int_t pnt) const
get residual at point pnt
~MillePedeRecord() override
destuctor
Bool_t IsResidual(Int_t i) const
Double_t GetLocalDeriv(Int_t pnt, Int_t indx) const
get derivative over local variable indx at point pnt
Double32_t * fValue
[fSize] array of values: derivs,residuals
Bool_t IsWeight(Int_t i) const
GLenum src
Definition glcorearb.h:1767
GLuint GLuint GLfloat weight
Definition glcorearb.h:5477
GLuint GLfloat * val
Definition glcorearb.h:1582
GLuint id
Definition glcorearb.h:650
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"