]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFRunParams.cxx
Bug fix (Sergey)
[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
29 ClassImp(AliTOFRunParams)
30
31 //_________________________________________________________
32
33 AliTOFRunParams::AliTOFRunParams() :
34   TObject(),
35   fNPoints(0),
36   fTimestamp(NULL),
37   fT0(NULL),
38   fTOFResolution(NULL),
39   fT0Spread(NULL)
40 {
41   /*
42    * default constructor
43    */
44 }
45
46 //_________________________________________________________
47
48 AliTOFRunParams::AliTOFRunParams(Int_t nPoints) :
49   TObject(),
50   fNPoints(nPoints),
51   fTimestamp(new UInt_t[nPoints]),
52   fT0(new Float_t[nPoints]),
53   fTOFResolution(new Float_t[nPoints]),
54   fT0Spread(new Float_t[nPoints])
55 {
56   /*
57    * standard constructor
58    */
59 }
60
61 //_________________________________________________________
62
63 AliTOFRunParams::~AliTOFRunParams()
64 {
65   /*
66    * default destructor
67    */
68
69   if (fTimestamp) delete [] fTimestamp;
70   if (fT0) delete [] fT0;
71   if (fTOFResolution) delete [] fTOFResolution;
72   if (fT0Spread) delete [] fT0Spread;
73 }
74
75 //_________________________________________________________
76
77 AliTOFRunParams::AliTOFRunParams(const AliTOFRunParams &source) :
78   TObject(source),
79   fNPoints(source.fNPoints),
80   fTimestamp(new UInt_t[source.fNPoints]),
81   fT0(new Float_t[source.fNPoints]),
82   fTOFResolution(new Float_t[source.fNPoints]),
83   fT0Spread(new Float_t[source.fNPoints])
84 {
85   /*
86    * copy constructor
87    */
88
89   for (Int_t i = 0; i < fNPoints; i++) {
90     fTimestamp[i] = source.fTimestamp[i];
91     fT0[i] = source.fT0[i];
92     fTOFResolution[i] = source.fTOFResolution[i];
93     fT0Spread[i] = source.fT0Spread[i];
94   }
95   
96 }
97
98 //_________________________________________________________
99
100 AliTOFRunParams &
101 AliTOFRunParams::operator=(const AliTOFRunParams &source)
102 {
103   /*
104    * operator=
105    */
106
107   if (this == &source) return *this;
108   TObject::operator=(source);
109   
110   if (fNPoints != source.fNPoints) {
111     if (fTimestamp) delete [] fTimestamp;
112     if (fT0) delete [] fT0;
113     if (fTOFResolution) delete [] fTOFResolution;
114     if (fT0Spread) delete [] fT0Spread;
115     fNPoints = source.fNPoints;
116     fTimestamp = new UInt_t[source.fNPoints];
117     fT0 = new Float_t[source.fNPoints];
118     fTOFResolution = new Float_t[source.fNPoints];
119     fT0Spread = new Float_t[source.fNPoints];
120   }
121
122   for (Int_t i = 0; i < fNPoints; i++) {
123     fTimestamp[i] = source.fTimestamp[i];
124     fT0[i] = source.fT0[i];
125     fTOFResolution[i] = source.fTOFResolution[i];
126     fT0Spread[i] = source.fT0Spread[i];
127   }
128
129   return *this;
130 }
131
132 //_________________________________________________________
133
134 Float_t
135 AliTOFRunParams::EvalT0(UInt_t timestamp)
136 {
137   /*
138    * eval T0
139    */
140
141   /* critical cases:
142      1. no measurement -> 0.
143      2. single measurement -> single value
144      3. timestamp before first measurement -> first value
145      4. timestamp after last measurement -> last value
146   */
147   if (fNPoints <= 0 || !fT0 || !fTimestamp) return 0.;
148   if (fNPoints == 1) return fT0[0];
149   if (timestamp <= fTimestamp[0]) return fT0[0];
150   if (timestamp >= fTimestamp[fNPoints - 1]) return fT0[fNPoints - 1];
151
152   /* interpolate value */
153   Int_t ipoint;
154   for (ipoint = 0; ipoint < fNPoints - 1; ipoint++)
155     if (timestamp >= fTimestamp[ipoint] && timestamp < fTimestamp[ipoint + 1])
156       break;
157   Float_t coeff = (fT0[ipoint + 1] - fT0[ipoint]) / (Float_t)(fTimestamp[ipoint + 1] - fTimestamp[ipoint]);
158   Float_t t0 = fT0[ipoint] + coeff * (timestamp - fTimestamp[ipoint]);
159   
160   return t0;
161 }
162
163 //_________________________________________________________
164
165 Float_t
166 AliTOFRunParams::EvalTOFResolution(UInt_t timestamp)
167 {
168   /*
169    * eval TOF resolution
170    */
171
172   /* critical cases:
173      1. no measurement -> 0.
174      2. single measurement -> single value
175      3. timestamp before first measurement -> first value
176      4. timestamp after last measurement -> last value
177   */
178   if (fNPoints <= 0 || !fTOFResolution || !fTimestamp) return 0.;
179   if (fNPoints == 1) return fTOFResolution[0];
180   if (timestamp <= fTimestamp[0]) return fTOFResolution[0];
181   if (timestamp >= fTimestamp[fNPoints - 1]) return fTOFResolution[fNPoints - 1];
182
183   /* interpolate value */
184   Int_t ipoint;
185   for (ipoint = 0; ipoint < fNPoints - 1; ipoint++)
186     if (timestamp >= fTimestamp[ipoint] && timestamp < fTimestamp[ipoint + 1])
187       break;
188   Float_t coeff = (fTOFResolution[ipoint + 1] - fTOFResolution[ipoint]) / (Float_t)(fTimestamp[ipoint + 1] - fTimestamp[ipoint]);
189   Float_t reso = fTOFResolution[ipoint] + coeff * (timestamp - fTimestamp[ipoint]);
190   
191   return reso;
192 }
193
194 //_________________________________________________________
195
196 Float_t
197 AliTOFRunParams::EvalT0Spread(UInt_t timestamp)
198 {
199   /*
200    * eval T0 spread
201    */
202
203   /* critical cases:
204      1. no measurement -> 0.
205      2. single measurement -> single value
206      3. timestamp before first measurement -> first value
207      4. timestamp after last measurement -> last value
208   */
209   if (fNPoints <= 0 || !fT0Spread || !fTimestamp) return 0.;
210   if (fNPoints == 1) return fT0Spread[0];
211   if (timestamp <= fTimestamp[0]) return fT0Spread[0];
212   if (timestamp >= fTimestamp[fNPoints - 1]) return fT0Spread[fNPoints - 1];
213
214   /* interpolate value */
215   Int_t ipoint;
216   for (ipoint = 0; ipoint < fNPoints - 1; ipoint++)
217     if (timestamp >= fTimestamp[ipoint] && timestamp < fTimestamp[ipoint + 1])
218       break;
219   Float_t coeff = (fT0Spread[ipoint + 1] - fT0Spread[ipoint]) / (Float_t)(fTimestamp[ipoint + 1] - fTimestamp[ipoint]);
220   Float_t spread = fT0Spread[ipoint] + coeff * (timestamp - fTimestamp[ipoint]);
221   
222   return spread;
223 }
224