]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFRunParams.cxx
Fixed problem when drawing DQM histograms (F.Bellini)
[u/mrichter/AliRoot.git] / TOF / AliTOFRunParams.cxx
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"
28 #include "TGraph.h"
29
30 ClassImp(AliTOFRunParams)
31
32 //_________________________________________________________
33
34 AliTOFRunParams::AliTOFRunParams() :
35   TObject(),
36   fNPoints(0),
37   fTimestamp(NULL),
38   fT0(NULL),
39   fTOFResolution(NULL),
40   fT0Spread(NULL),
41   fNRuns(0),
42   fRunNb(NULL),
43   fRunFirstPoint(NULL),
44   fRunLastPoint(NULL)
45 {
46   /*
47    * default constructor
48    */
49 }
50
51 //_________________________________________________________
52
53 AliTOFRunParams::AliTOFRunParams(Int_t nPoints, Int_t nRuns) :
54   TObject(),
55   fNPoints(nPoints),
56   fTimestamp(new UInt_t[nPoints]),
57   fT0(new Float_t[nPoints]),
58   fTOFResolution(new Float_t[nPoints]),
59   fT0Spread(new Float_t[nPoints]),
60   fNRuns(nRuns),
61   fRunNb(new UInt_t[nRuns]),
62   fRunFirstPoint(new UInt_t[nRuns]),
63   fRunLastPoint(new UInt_t[nRuns])
64 {
65   /*
66    * standard constructor
67    */
68 }
69
70 //_________________________________________________________
71
72 AliTOFRunParams::~AliTOFRunParams()
73 {
74   /*
75    * default destructor
76    */
77
78   if (fTimestamp) delete [] fTimestamp;
79   if (fT0) delete [] fT0;
80   if (fTOFResolution) delete [] fTOFResolution;
81   if (fT0Spread) delete [] fT0Spread;
82   if (fRunNb) delete [] fRunNb;
83   if (fRunFirstPoint) delete [] fRunFirstPoint;
84   if (fRunLastPoint) delete [] fRunLastPoint;
85 }
86
87 //_________________________________________________________
88
89 AliTOFRunParams::AliTOFRunParams(const AliTOFRunParams &source) :
90   TObject(source),
91   fNPoints(source.fNPoints),
92   fTimestamp(new UInt_t[source.fNPoints]),
93   fT0(new Float_t[source.fNPoints]),
94   fTOFResolution(new Float_t[source.fNPoints]),
95   fT0Spread(new Float_t[source.fNPoints]),
96   fNRuns(source.fNRuns),
97   fRunNb(new UInt_t[source.fNRuns]),
98   fRunFirstPoint(new UInt_t[source.fNRuns]),
99   fRunLastPoint(new UInt_t[source.fNRuns])
100 {
101   /*
102    * copy constructor
103    */
104
105   for (Int_t i = 0; i < fNPoints; i++) {
106     fTimestamp[i] = source.fTimestamp[i];
107     fT0[i] = source.fT0[i];
108     fTOFResolution[i] = source.fTOFResolution[i];
109     fT0Spread[i] = source.fT0Spread[i];
110   }
111
112   for (Int_t i = 0; i < fNRuns; i++) {
113     fRunNb[i] = source.fRunNb[i];
114     fRunFirstPoint[i] = source.fRunFirstPoint[i];
115     fRunLastPoint[i] = source.fRunLastPoint[i];
116   }
117   
118 }
119
120 //_________________________________________________________
121
122 AliTOFRunParams &
123 AliTOFRunParams::operator=(const AliTOFRunParams &source)
124 {
125   /*
126    * operator=
127    */
128
129   if (this == &source) return *this;
130   TObject::operator=(source);
131   
132   if (fNPoints != source.fNPoints) {
133     if (fTimestamp) delete [] fTimestamp;
134     if (fT0) delete [] fT0;
135     if (fTOFResolution) delete [] fTOFResolution;
136     if (fT0Spread) delete [] fT0Spread;
137     fNPoints = source.fNPoints;
138     fTimestamp = new UInt_t[source.fNPoints];
139     fT0 = new Float_t[source.fNPoints];
140     fTOFResolution = new Float_t[source.fNPoints];
141     fT0Spread = new Float_t[source.fNPoints];
142   }
143
144   for (Int_t i = 0; i < fNPoints; i++) {
145     fTimestamp[i] = source.fTimestamp[i];
146     fT0[i] = source.fT0[i];
147     fTOFResolution[i] = source.fTOFResolution[i];
148     fT0Spread[i] = source.fT0Spread[i];
149   }
150
151   if (fNRuns != source.fNRuns) {
152     if (fRunNb) delete [] fRunNb;
153     if (fRunFirstPoint) delete [] fRunFirstPoint;
154     if (fRunLastPoint) delete [] fRunLastPoint;
155     fNRuns = source.fNRuns;
156     fRunNb = new UInt_t[source.fNRuns];
157     fRunFirstPoint = new UInt_t[source.fNRuns];
158     fRunLastPoint = new UInt_t[source.fNRuns];
159   }
160
161   for (Int_t i = 0; i < fNRuns; i++) {
162     fRunNb[i] = source.fRunNb[i];
163     fRunFirstPoint[i] = source.fRunFirstPoint[i];
164     fRunLastPoint[i] = source.fRunLastPoint[i];
165   }
166
167   return *this;
168 }
169
170 //_________________________________________________________
171
172 Float_t
173 AliTOFRunParams::EvalT0(UInt_t timestamp)
174 {
175   /*
176    * eval T0
177    */
178
179   /* critical cases:
180      1. no measurement -> 0.
181      2. single measurement -> single value
182      3. timestamp before first measurement -> first value
183      4. timestamp after last measurement -> last value
184   */
185   if (fNPoints <= 0 || !fT0 || !fTimestamp) return 0.;
186   if (fNPoints == 1) return fT0[0];
187   if (timestamp <= fTimestamp[0]) return fT0[0];
188   if (timestamp >= fTimestamp[fNPoints - 1]) return fT0[fNPoints - 1];
189
190   /* interpolate value */
191   Int_t ipoint;
192   for (ipoint = 0; ipoint < fNPoints - 1; ipoint++)
193     if (timestamp >= fTimestamp[ipoint] && timestamp < fTimestamp[ipoint + 1])
194       break;
195   Float_t coeff = (fT0[ipoint + 1] - fT0[ipoint]) / (Float_t)(fTimestamp[ipoint + 1] - fTimestamp[ipoint]);
196   Float_t t0 = fT0[ipoint] + coeff * (timestamp - fTimestamp[ipoint]);
197   
198   return t0;
199 }
200
201 //_________________________________________________________
202
203 Float_t
204 AliTOFRunParams::EvalTOFResolution(UInt_t timestamp)
205 {
206   /*
207    * eval TOF resolution
208    */
209
210   /* critical cases:
211      1. no measurement -> 0.
212      2. single measurement -> single value
213      3. timestamp before first measurement -> first value
214      4. timestamp after last measurement -> last value
215   */
216   if (fNPoints <= 0 || !fTOFResolution || !fTimestamp) return 0.;
217   if (fNPoints == 1) return fTOFResolution[0];
218   if (timestamp <= fTimestamp[0]) return fTOFResolution[0];
219   if (timestamp >= fTimestamp[fNPoints - 1]) return fTOFResolution[fNPoints - 1];
220
221   /* interpolate value */
222   Int_t ipoint;
223   for (ipoint = 0; ipoint < fNPoints - 1; ipoint++)
224     if (timestamp >= fTimestamp[ipoint] && timestamp < fTimestamp[ipoint + 1])
225       break;
226   Float_t coeff = (fTOFResolution[ipoint + 1] - fTOFResolution[ipoint]) / (Float_t)(fTimestamp[ipoint + 1] - fTimestamp[ipoint]);
227   Float_t reso = fTOFResolution[ipoint] + coeff * (timestamp - fTimestamp[ipoint]);
228   
229   return reso;
230 }
231
232 //_________________________________________________________
233
234 Float_t
235 AliTOFRunParams::EvalT0Spread(UInt_t timestamp)
236 {
237   /*
238    * eval T0 spread
239    */
240
241   /* critical cases:
242      1. no measurement -> 0.
243      2. single measurement -> single value
244      3. timestamp before first measurement -> first value
245      4. timestamp after last measurement -> last value
246   */
247   if (fNPoints <= 0 || !fT0Spread || !fTimestamp) return 0.;
248   if (fNPoints == 1) return fT0Spread[0];
249   if (timestamp <= fTimestamp[0]) return fT0Spread[0];
250   if (timestamp >= fTimestamp[fNPoints - 1]) return fT0Spread[fNPoints - 1];
251
252   /* interpolate value */
253   Int_t ipoint;
254   for (ipoint = 0; ipoint < fNPoints - 1; ipoint++)
255     if (timestamp >= fTimestamp[ipoint] && timestamp < fTimestamp[ipoint + 1])
256       break;
257   Float_t coeff = (fT0Spread[ipoint + 1] - fT0Spread[ipoint]) / (Float_t)(fTimestamp[ipoint + 1] - fTimestamp[ipoint]);
258   Float_t spread = fT0Spread[ipoint] + coeff * (timestamp - fTimestamp[ipoint]);
259   
260   return spread;
261 }
262
263 //_________________________________________________________
264
265 Float_t
266 AliTOFRunParams::Average(Float_t *data, Int_t first, Int_t last)
267 {
268   /*
269    * average
270    */
271
272   if (first < 0) first = 0;
273   if (last >= fNPoints) last = fNPoints - 1;
274   Float_t value = 0.;
275   Int_t npt = 0;
276   for (Int_t i = first; i <= last; i++) {
277     value += data[i];
278     npt++;
279   }
280   value /= npt;
281   return value;
282
283 }
284
285 //_________________________________________________________
286
287 Float_t
288 AliTOFRunParams::Average(Float_t *data, UInt_t runNb)
289 {
290   /*
291    * average
292    */
293
294   /* critical cases:
295      1. no measurement -> 0.
296      2. no runNb structure -> average over all points
297      3. runNb not found -> average over all points
298   */
299   if (fNPoints <= 0 || !fT0 || !fTimestamp) return 0.;
300   if (fNRuns <= 0 || !fRunNb || !fRunFirstPoint || !fRunLastPoint) return Average(data, 0, fNPoints - 1);
301
302
303   /* search for runNb */
304   UInt_t runPoint = 0;
305   Bool_t gotRunNb = kFALSE;
306   for (Int_t irun = 0; irun < fNRuns; irun++) {
307     if (fRunNb[irun] == runNb) {
308       runPoint = irun;
309       gotRunNb = kTRUE;
310       break;
311     }
312   }
313   if (!gotRunNb) return Average(data, 0, fNPoints - 1);
314
315   /* average between first and last run points */
316   UInt_t firstPoint = fRunFirstPoint[runPoint];
317   UInt_t lastPoint = fRunLastPoint[runPoint];
318   return Average(data, firstPoint, lastPoint);
319
320 }
321
322 //_________________________________________________________
323
324 TGraph *
325 AliTOFRunParams::DrawGraph(Float_t *data, Option_t* option)
326 {
327   /*
328    * draw
329    */
330
331   if (fNPoints == 0 || !data || !fTimestamp) return NULL;
332
333   Float_t ts[1000000];
334   for (Int_t i = 0; i < fNPoints; i++)
335     ts[i] = fTimestamp[i];
336
337   TGraph *graph = new TGraph(fNPoints, ts, data);
338   graph->Draw(option);
339   return graph;
340 }