1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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
27 #include "AliTOFRunParams.h"
30 ClassImp(AliTOFRunParams)
32 //_________________________________________________________
34 AliTOFRunParams::AliTOFRunParams() :
51 //_________________________________________________________
53 AliTOFRunParams::AliTOFRunParams(Int_t nPoints, Int_t nRuns) :
56 fTimestamp(new UInt_t[nPoints]),
57 fT0(new Float_t[nPoints]),
58 fTOFResolution(new Float_t[nPoints]),
59 fT0Spread(new Float_t[nPoints]),
61 fRunNb(new UInt_t[nRuns]),
62 fRunFirstPoint(new UInt_t[nRuns]),
63 fRunLastPoint(new UInt_t[nRuns])
66 * standard constructor
70 //_________________________________________________________
72 AliTOFRunParams::~AliTOFRunParams()
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;
87 //_________________________________________________________
89 AliTOFRunParams::AliTOFRunParams(const AliTOFRunParams &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])
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];
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];
120 //_________________________________________________________
123 AliTOFRunParams::operator=(const AliTOFRunParams &source)
129 if (this == &source) return *this;
130 TObject::operator=(source);
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];
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];
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];
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];
170 //_________________________________________________________
173 AliTOFRunParams::EvalT0(UInt_t timestamp)
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
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];
190 /* interpolate value */
192 for (ipoint = 0; ipoint < fNPoints - 1; ipoint++)
193 if (timestamp >= fTimestamp[ipoint] && timestamp < fTimestamp[ipoint + 1])
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]);
201 //_________________________________________________________
204 AliTOFRunParams::EvalTOFResolution(UInt_t timestamp)
207 * eval TOF resolution
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
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];
221 /* interpolate value */
223 for (ipoint = 0; ipoint < fNPoints - 1; ipoint++)
224 if (timestamp >= fTimestamp[ipoint] && timestamp < fTimestamp[ipoint + 1])
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]);
232 //_________________________________________________________
235 AliTOFRunParams::EvalT0Spread(UInt_t timestamp)
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
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];
252 /* interpolate value */
254 for (ipoint = 0; ipoint < fNPoints - 1; ipoint++)
255 if (timestamp >= fTimestamp[ipoint] && timestamp < fTimestamp[ipoint + 1])
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]);
263 //_________________________________________________________
266 AliTOFRunParams::Average(Float_t *data, Int_t first, Int_t last)
272 if (first < 0) first = 0;
273 if (last >= fNPoints) last = fNPoints - 1;
276 for (Int_t i = first; i <= last; i++) {
285 //_________________________________________________________
288 AliTOFRunParams::Average(Float_t *data, UInt_t runNb)
295 1. no measurement -> 0.
296 2. no runNb structure -> average over all points
297 3. runNb not found -> average over all points
299 if (fNPoints <= 0 || !fT0 || !fTimestamp) return 0.;
300 if (fNRuns <= 0 || !fRunNb || !fRunFirstPoint || !fRunLastPoint) return Average(data, 0, fNPoints - 1);
303 /* search for runNb */
305 Bool_t gotRunNb = kFALSE;
306 for (Int_t irun = 0; irun < fNRuns; irun++) {
307 if (fRunNb[irun] == runNb) {
313 if (!gotRunNb) return Average(data, 0, fNPoints - 1);
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);
322 //_________________________________________________________
325 AliTOFRunParams::DrawGraph(Float_t *data, Option_t* option)
331 if (fNPoints == 0 || !data || !fTimestamp) return NULL;
334 for (Int_t i = 0; i < fNPoints; i++)
335 ts[i] = fTimestamp[i];
337 TGraph *graph = new TGraph(fNPoints, ts, data);