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() :
45 fUseLHCClockPhase(kFALSE)
52 //_________________________________________________________
54 AliTOFRunParams::AliTOFRunParams(Int_t nPoints, Int_t nRuns) :
57 fTimestamp(new UInt_t[nPoints]),
58 fT0(new Float_t[nPoints]),
59 fTOFResolution(new Float_t[nPoints]),
60 fT0Spread(new Float_t[nPoints]),
62 fRunNb(new UInt_t[nRuns]),
63 fRunFirstPoint(new UInt_t[nRuns]),
64 fRunLastPoint(new UInt_t[nRuns]),
65 fUseLHCClockPhase(kFALSE)
68 * standard constructor
72 //_________________________________________________________
74 AliTOFRunParams::~AliTOFRunParams()
80 if (fTimestamp) delete [] fTimestamp;
81 if (fT0) delete [] fT0;
82 if (fTOFResolution) delete [] fTOFResolution;
83 if (fT0Spread) delete [] fT0Spread;
84 if (fRunNb) delete [] fRunNb;
85 if (fRunFirstPoint) delete [] fRunFirstPoint;
86 if (fRunLastPoint) delete [] fRunLastPoint;
89 //_________________________________________________________
91 AliTOFRunParams::AliTOFRunParams(const AliTOFRunParams &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]),
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]),
101 fRunLastPoint(new UInt_t[source.fNRuns]),
102 fUseLHCClockPhase(source.fUseLHCClockPhase)
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];
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];
123 //_________________________________________________________
126 AliTOFRunParams::operator=(const AliTOFRunParams &source)
132 if (this == &source) return *this;
133 TObject::operator=(source);
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];
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];
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];
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];
170 fUseLHCClockPhase = source.fUseLHCClockPhase;
175 //_________________________________________________________
178 AliTOFRunParams::EvalT0(UInt_t timestamp)
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
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];
195 /* interpolate value */
197 for (ipoint = 0; ipoint < fNPoints - 1; ipoint++)
198 if (timestamp >= fTimestamp[ipoint] && timestamp < fTimestamp[ipoint + 1])
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]);
206 //_________________________________________________________
209 AliTOFRunParams::EvalTOFResolution(UInt_t timestamp)
212 * eval TOF resolution
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
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];
226 /* interpolate value */
228 for (ipoint = 0; ipoint < fNPoints - 1; ipoint++)
229 if (timestamp >= fTimestamp[ipoint] && timestamp < fTimestamp[ipoint + 1])
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]);
237 //_________________________________________________________
240 AliTOFRunParams::EvalT0Spread(UInt_t timestamp)
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
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];
257 /* interpolate value */
259 for (ipoint = 0; ipoint < fNPoints - 1; ipoint++)
260 if (timestamp >= fTimestamp[ipoint] && timestamp < fTimestamp[ipoint + 1])
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]);
268 //_________________________________________________________
271 AliTOFRunParams::Average(Float_t *data, Int_t first, Int_t last)
277 if (first < 0) first = 0;
278 if (last >= fNPoints) last = fNPoints - 1;
281 for (Int_t i = first; i <= last; i++) {
285 if (npt <= 0) return 0.;
291 //_________________________________________________________
294 AliTOFRunParams::Average(Float_t *data, UInt_t runNb)
301 1. no measurement -> 0.
302 2. no runNb structure -> average over all points
303 3. runNb not found -> average over all points
305 if (fNPoints <= 0 || !fT0 || !fTimestamp) return 0.;
306 if (fNRuns <= 0 || !fRunNb || !fRunFirstPoint || !fRunLastPoint) return Average(data, 0, fNPoints - 1);
309 /* search for runNb */
311 Bool_t gotRunNb = kFALSE;
312 for (Int_t irun = 0; irun < fNRuns; irun++) {
313 if (fRunNb[irun] == runNb) {
319 if (!gotRunNb) return Average(data, 0, fNPoints - 1);
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);
328 //_________________________________________________________
331 AliTOFRunParams::DrawGraph(Float_t *data, Option_t* option)
337 if (fNPoints == 0 || !data || !fTimestamp) return NULL;
340 for (Int_t i = 0; i < fNPoints; i++)
341 ts[i] = fTimestamp[i];
343 TGraph *graph = new TGraph(fNPoints, ts, data);
348 //_________________________________________________________
351 AliTOFRunParams::DrawCorrelationGraph(Float_t *datax, Float_t *datay, Option_t* option)
357 if (fNPoints == 0 || !datax || !datay) return NULL;
359 TGraph *graph = new TGraph(fNPoints, datax, datay);