]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFRunParams.cxx
Update Balance Function correction Maps (Alis Rodriguez Manso <alisrm@nikhef.nl>)
[u/mrichter/AliRoot.git] / TOF / AliTOFRunParams.cxx
CommitLineData
f04b3a69 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16// *
17// *
18// *
19// * this class defines the TOF object to be stored
20// * in OCDB on a run-by-run basis in order to have the measurement
21// * of the time evolution of T0 and of TOF resolution including
22// * average T0 uncertainty
23// *
24// *
25// *
26
27#include "AliTOFRunParams.h"
53408dc1 28#include "TGraph.h"
f04b3a69 29
30ClassImp(AliTOFRunParams)
31
32//_________________________________________________________
33
34AliTOFRunParams::AliTOFRunParams() :
35 TObject(),
36 fNPoints(0),
37 fTimestamp(NULL),
38 fT0(NULL),
39 fTOFResolution(NULL),
53408dc1 40 fT0Spread(NULL),
41 fNRuns(0),
42 fRunNb(NULL),
43 fRunFirstPoint(NULL),
3fd7a5cd 44 fRunLastPoint(NULL),
45 fUseLHCClockPhase(kFALSE)
f04b3a69 46{
47 /*
48 * default constructor
49 */
50}
51
52//_________________________________________________________
53
53408dc1 54AliTOFRunParams::AliTOFRunParams(Int_t nPoints, Int_t nRuns) :
f04b3a69 55 TObject(),
56 fNPoints(nPoints),
57 fTimestamp(new UInt_t[nPoints]),
58 fT0(new Float_t[nPoints]),
59 fTOFResolution(new Float_t[nPoints]),
53408dc1 60 fT0Spread(new Float_t[nPoints]),
61 fNRuns(nRuns),
62 fRunNb(new UInt_t[nRuns]),
63 fRunFirstPoint(new UInt_t[nRuns]),
3fd7a5cd 64 fRunLastPoint(new UInt_t[nRuns]),
65 fUseLHCClockPhase(kFALSE)
f04b3a69 66{
67 /*
68 * standard constructor
69 */
70}
71
72//_________________________________________________________
73
74AliTOFRunParams::~AliTOFRunParams()
75{
76 /*
77 * default destructor
78 */
79
80 if (fTimestamp) delete [] fTimestamp;
81 if (fT0) delete [] fT0;
82 if (fTOFResolution) delete [] fTOFResolution;
83 if (fT0Spread) delete [] fT0Spread;
53408dc1 84 if (fRunNb) delete [] fRunNb;
85 if (fRunFirstPoint) delete [] fRunFirstPoint;
86 if (fRunLastPoint) delete [] fRunLastPoint;
f04b3a69 87}
88
89//_________________________________________________________
90
91AliTOFRunParams::AliTOFRunParams(const AliTOFRunParams &source) :
92 TObject(source),
93 fNPoints(source.fNPoints),
94 fTimestamp(new UInt_t[source.fNPoints]),
95 fT0(new Float_t[source.fNPoints]),
96 fTOFResolution(new Float_t[source.fNPoints]),
53408dc1 97 fT0Spread(new Float_t[source.fNPoints]),
98 fNRuns(source.fNRuns),
99 fRunNb(new UInt_t[source.fNRuns]),
100 fRunFirstPoint(new UInt_t[source.fNRuns]),
3fd7a5cd 101 fRunLastPoint(new UInt_t[source.fNRuns]),
102 fUseLHCClockPhase(source.fUseLHCClockPhase)
f04b3a69 103{
104 /*
105 * copy constructor
106 */
107
108 for (Int_t i = 0; i < fNPoints; i++) {
109 fTimestamp[i] = source.fTimestamp[i];
110 fT0[i] = source.fT0[i];
111 fTOFResolution[i] = source.fTOFResolution[i];
112 fT0Spread[i] = source.fT0Spread[i];
113 }
53408dc1 114
115 for (Int_t i = 0; i < fNRuns; i++) {
116 fRunNb[i] = source.fRunNb[i];
117 fRunFirstPoint[i] = source.fRunFirstPoint[i];
118 fRunLastPoint[i] = source.fRunLastPoint[i];
119 }
f04b3a69 120
121}
122
123//_________________________________________________________
124
125AliTOFRunParams &
126AliTOFRunParams::operator=(const AliTOFRunParams &source)
127{
128 /*
129 * operator=
130 */
131
132 if (this == &source) return *this;
133 TObject::operator=(source);
134
135 if (fNPoints != source.fNPoints) {
136 if (fTimestamp) delete [] fTimestamp;
137 if (fT0) delete [] fT0;
138 if (fTOFResolution) delete [] fTOFResolution;
139 if (fT0Spread) delete [] fT0Spread;
140 fNPoints = source.fNPoints;
141 fTimestamp = new UInt_t[source.fNPoints];
142 fT0 = new Float_t[source.fNPoints];
143 fTOFResolution = new Float_t[source.fNPoints];
144 fT0Spread = new Float_t[source.fNPoints];
145 }
146
147 for (Int_t i = 0; i < fNPoints; i++) {
148 fTimestamp[i] = source.fTimestamp[i];
149 fT0[i] = source.fT0[i];
150 fTOFResolution[i] = source.fTOFResolution[i];
151 fT0Spread[i] = source.fT0Spread[i];
152 }
153
53408dc1 154 if (fNRuns != source.fNRuns) {
155 if (fRunNb) delete [] fRunNb;
156 if (fRunFirstPoint) delete [] fRunFirstPoint;
157 if (fRunLastPoint) delete [] fRunLastPoint;
158 fNRuns = source.fNRuns;
159 fRunNb = new UInt_t[source.fNRuns];
160 fRunFirstPoint = new UInt_t[source.fNRuns];
161 fRunLastPoint = new UInt_t[source.fNRuns];
162 }
163
164 for (Int_t i = 0; i < fNRuns; i++) {
165 fRunNb[i] = source.fRunNb[i];
166 fRunFirstPoint[i] = source.fRunFirstPoint[i];
167 fRunLastPoint[i] = source.fRunLastPoint[i];
168 }
169
3fd7a5cd 170 fUseLHCClockPhase = source.fUseLHCClockPhase;
171
f04b3a69 172 return *this;
173}
174
175//_________________________________________________________
176
177Float_t
178AliTOFRunParams::EvalT0(UInt_t timestamp)
179{
180 /*
181 * eval T0
182 */
183
184 /* critical cases:
185 1. no measurement -> 0.
186 2. single measurement -> single value
187 3. timestamp before first measurement -> first value
188 4. timestamp after last measurement -> last value
189 */
190 if (fNPoints <= 0 || !fT0 || !fTimestamp) return 0.;
191 if (fNPoints == 1) return fT0[0];
192 if (timestamp <= fTimestamp[0]) return fT0[0];
193 if (timestamp >= fTimestamp[fNPoints - 1]) return fT0[fNPoints - 1];
194
195 /* interpolate value */
196 Int_t ipoint;
197 for (ipoint = 0; ipoint < fNPoints - 1; ipoint++)
198 if (timestamp >= fTimestamp[ipoint] && timestamp < fTimestamp[ipoint + 1])
199 break;
200 Float_t coeff = (fT0[ipoint + 1] - fT0[ipoint]) / (Float_t)(fTimestamp[ipoint + 1] - fTimestamp[ipoint]);
201 Float_t t0 = fT0[ipoint] + coeff * (timestamp - fTimestamp[ipoint]);
202
203 return t0;
204}
205
206//_________________________________________________________
207
208Float_t
209AliTOFRunParams::EvalTOFResolution(UInt_t timestamp)
210{
211 /*
212 * eval TOF resolution
213 */
214
215 /* critical cases:
216 1. no measurement -> 0.
217 2. single measurement -> single value
218 3. timestamp before first measurement -> first value
219 4. timestamp after last measurement -> last value
220 */
221 if (fNPoints <= 0 || !fTOFResolution || !fTimestamp) return 0.;
222 if (fNPoints == 1) return fTOFResolution[0];
223 if (timestamp <= fTimestamp[0]) return fTOFResolution[0];
224 if (timestamp >= fTimestamp[fNPoints - 1]) return fTOFResolution[fNPoints - 1];
225
226 /* interpolate value */
227 Int_t ipoint;
228 for (ipoint = 0; ipoint < fNPoints - 1; ipoint++)
229 if (timestamp >= fTimestamp[ipoint] && timestamp < fTimestamp[ipoint + 1])
230 break;
231 Float_t coeff = (fTOFResolution[ipoint + 1] - fTOFResolution[ipoint]) / (Float_t)(fTimestamp[ipoint + 1] - fTimestamp[ipoint]);
232 Float_t reso = fTOFResolution[ipoint] + coeff * (timestamp - fTimestamp[ipoint]);
233
234 return reso;
235}
236
237//_________________________________________________________
238
239Float_t
240AliTOFRunParams::EvalT0Spread(UInt_t timestamp)
241{
242 /*
243 * eval T0 spread
244 */
245
246 /* critical cases:
247 1. no measurement -> 0.
248 2. single measurement -> single value
249 3. timestamp before first measurement -> first value
250 4. timestamp after last measurement -> last value
251 */
252 if (fNPoints <= 0 || !fT0Spread || !fTimestamp) return 0.;
253 if (fNPoints == 1) return fT0Spread[0];
254 if (timestamp <= fTimestamp[0]) return fT0Spread[0];
255 if (timestamp >= fTimestamp[fNPoints - 1]) return fT0Spread[fNPoints - 1];
256
257 /* interpolate value */
258 Int_t ipoint;
259 for (ipoint = 0; ipoint < fNPoints - 1; ipoint++)
260 if (timestamp >= fTimestamp[ipoint] && timestamp < fTimestamp[ipoint + 1])
261 break;
262 Float_t coeff = (fT0Spread[ipoint + 1] - fT0Spread[ipoint]) / (Float_t)(fTimestamp[ipoint + 1] - fTimestamp[ipoint]);
263 Float_t spread = fT0Spread[ipoint] + coeff * (timestamp - fTimestamp[ipoint]);
264
265 return spread;
266}
267
53408dc1 268//_________________________________________________________
269
270Float_t
271AliTOFRunParams::Average(Float_t *data, Int_t first, Int_t last)
272{
273 /*
274 * average
275 */
276
277 if (first < 0) first = 0;
278 if (last >= fNPoints) last = fNPoints - 1;
279 Float_t value = 0.;
280 Int_t npt = 0;
281 for (Int_t i = first; i <= last; i++) {
282 value += data[i];
283 npt++;
284 }
a44583b8 285 if (npt <= 0) return 0.;
53408dc1 286 value /= npt;
287 return value;
288
289}
290
291//_________________________________________________________
292
293Float_t
294AliTOFRunParams::Average(Float_t *data, UInt_t runNb)
295{
296 /*
297 * average
298 */
299
300 /* critical cases:
301 1. no measurement -> 0.
302 2. no runNb structure -> average over all points
303 3. runNb not found -> average over all points
304 */
305 if (fNPoints <= 0 || !fT0 || !fTimestamp) return 0.;
306 if (fNRuns <= 0 || !fRunNb || !fRunFirstPoint || !fRunLastPoint) return Average(data, 0, fNPoints - 1);
307
308
309 /* search for runNb */
310 UInt_t runPoint = 0;
311 Bool_t gotRunNb = kFALSE;
312 for (Int_t irun = 0; irun < fNRuns; irun++) {
313 if (fRunNb[irun] == runNb) {
314 runPoint = irun;
315 gotRunNb = kTRUE;
316 break;
317 }
318 }
319 if (!gotRunNb) return Average(data, 0, fNPoints - 1);
320
321 /* average between first and last run points */
322 UInt_t firstPoint = fRunFirstPoint[runPoint];
323 UInt_t lastPoint = fRunLastPoint[runPoint];
324 return Average(data, firstPoint, lastPoint);
325
326}
327
328//_________________________________________________________
329
330TGraph *
331AliTOFRunParams::DrawGraph(Float_t *data, Option_t* option)
332{
333 /*
334 * draw
335 */
336
337 if (fNPoints == 0 || !data || !fTimestamp) return NULL;
338
339 Float_t ts[1000000];
340 for (Int_t i = 0; i < fNPoints; i++)
341 ts[i] = fTimestamp[i];
342
343 TGraph *graph = new TGraph(fNPoints, ts, data);
344 graph->Draw(option);
345 return graph;
346}
584e3067 347
348//_________________________________________________________
349
350TGraph *
351AliTOFRunParams::DrawCorrelationGraph(Float_t *datax, Float_t *datay, Option_t* option)
352{
353 /*
354 * draw
355 */
356
357 if (fNPoints == 0 || !datax || !datay) return NULL;
358
359 TGraph *graph = new TGraph(fNPoints, datax, datay);
360 graph->Draw(option);
361 return graph;
362}
363