]>
Commit | Line | Data |
---|---|---|
da18abd2 | 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 | // $Id$ | |
17 | ||
18 | #include "AliMUONCalibParamND.h" | |
19 | ||
20 | #include "AliLog.h" | |
21 | ||
22 | #include "Riostream.h" | |
23 | #include "TMath.h" | |
24 | #include "TString.h" | |
25 | ||
3d1463c8 | 26 | //----------------------------------------------------------------------------- |
da18abd2 | 27 | /// \class AliMUONCalibParamND |
28 | /// | |
29 | /// Handle the case of N floating point (double precision) parameters per channel. | |
30 | /// | |
31 | /// \author Laurent Aphecetche | |
3d1463c8 | 32 | //----------------------------------------------------------------------------- |
da18abd2 | 33 | |
34 | /// \cond CLASSIMP | |
35 | ClassImp(AliMUONCalibParamND) | |
36 | /// \endcond | |
37 | ||
38 | //_____________________________________________________________________________ | |
39 | AliMUONCalibParamND::AliMUONCalibParamND() | |
40 | : AliMUONVCalibParam(), | |
41 | fDimension(0), | |
42 | fSize(0), | |
43 | fN(0), | |
44 | fValues(0x0) | |
45 | { | |
46 | /// Default constructor. | |
47 | } | |
48 | ||
49 | //_____________________________________________________________________________ | |
50 | AliMUONCalibParamND::AliMUONCalibParamND(Int_t dimension, Int_t theSize, | |
51 | Int_t id0, Int_t id1, | |
52 | Double_t fillWithValue) | |
53 | : AliMUONVCalibParam(id0,id1), | |
54 | fDimension(dimension), | |
55 | fSize(theSize), | |
56 | fN(fSize*fDimension), | |
57 | fValues(0x0) | |
58 | { | |
59 | /// Normal constructor, where theSize specifies the number of channels handled | |
60 | /// by this object, and fillWithValue the default value assigned to each | |
61 | /// channel. | |
62 | ||
63 | if ( fN > 0 ) | |
64 | { | |
65 | fValues = new Double_t[fN]; | |
66 | for ( Int_t i = 0; i < fN; ++i ) | |
67 | { | |
68 | fValues[i] = fillWithValue; | |
69 | } | |
70 | } | |
71 | } | |
72 | ||
73 | ||
74 | //_____________________________________________________________________________ | |
75 | AliMUONCalibParamND::AliMUONCalibParamND(const AliMUONCalibParamND& other) | |
76 | : AliMUONVCalibParam(), | |
77 | fDimension(0), | |
78 | fSize(0), | |
79 | fN(0), | |
80 | fValues(0x0) | |
81 | { | |
82 | /// Copy constructor. | |
83 | ||
84 | other.CopyTo(*this); | |
85 | } | |
86 | ||
87 | //_____________________________________________________________________________ | |
88 | AliMUONCalibParamND& | |
89 | AliMUONCalibParamND::operator=(const AliMUONCalibParamND& other) | |
90 | { | |
91 | /// Assignment operator | |
92 | ||
93 | other.CopyTo(*this); | |
94 | return *this; | |
95 | } | |
96 | ||
97 | //_____________________________________________________________________________ | |
98 | AliMUONCalibParamND::~AliMUONCalibParamND() | |
99 | { | |
100 | /// Destructor | |
101 | ||
102 | delete[] fValues; | |
103 | } | |
104 | ||
105 | //_____________________________________________________________________________ | |
106 | void | |
107 | AliMUONCalibParamND::CopyTo(AliMUONCalibParamND& destination) const | |
108 | { | |
109 | /// Copy *this to destination | |
110 | ||
4db2bfee | 111 | TObject::Copy(destination); |
112 | ||
da18abd2 | 113 | delete[] destination.fValues; |
114 | destination.fN = fN; | |
115 | destination.fSize = fSize; | |
116 | destination.fDimension = fDimension; | |
117 | ||
118 | if ( fN > 0 ) | |
119 | { | |
120 | destination.fValues = new Double_t[fN]; | |
121 | for ( Int_t i = 0; i < fN; ++i ) | |
122 | { | |
123 | destination.fValues[i] = fValues[i]; | |
124 | } | |
125 | } | |
126 | } | |
127 | ||
128 | //_____________________________________________________________________________ | |
129 | Int_t | |
130 | AliMUONCalibParamND::Index(Int_t i, Int_t j) const | |
131 | { | |
132 | /// Compute the 1D index of the internal storage from the pair (i,j) | |
133 | /// Returns -1 if the (i,j) pair is invalid | |
134 | ||
135 | if ( i >= 0 && i < Size() && j >= 0 && j < Dimension() ) | |
136 | { | |
4db2bfee | 137 | return IndexFast(i,j); |
da18abd2 | 138 | } |
139 | return -1; | |
140 | } | |
141 | ||
4db2bfee | 142 | //_____________________________________________________________________________ |
143 | Int_t | |
144 | AliMUONCalibParamND::IndexFast(Int_t i, Int_t j) const | |
145 | { | |
146 | /// Compute the 1D index of the internal storage from the pair (i,j) | |
147 | ||
148 | return i + Size()*j; | |
149 | } | |
150 | ||
da18abd2 | 151 | //_____________________________________________________________________________ |
152 | void | |
153 | AliMUONCalibParamND::Print(Option_t* opt) const | |
154 | { | |
155 | /// Output this object to stdout. | |
156 | /// If opt=="full", then all channels are printed, | |
157 | /// if opt=="mean#", only the mean and sigma value are printed for j-th dimension | |
158 | /// otherwise only the general characteristics are printed. | |
159 | ||
160 | TString sopt(opt); | |
161 | sopt.ToUpper(); | |
162 | cout << Form("AliMUONCalibParamND Id=(%d,%d) Size=%d Dimension=%d",ID0(), | |
163 | ID1(),Size(),Dimension()) << endl; | |
164 | if ( sopt.Contains("FULL") ) | |
165 | { | |
166 | for ( Int_t i = 0; i < Size(); ++i ) | |
167 | { | |
168 | cout << Form("CH %3d",i); | |
169 | for ( Int_t j = 0; j < Dimension(); ++j ) | |
170 | { | |
171 | cout << Form(" %g",ValueAsDouble(i,j)); | |
172 | } | |
173 | cout << endl; | |
174 | } | |
175 | } | |
176 | if ( sopt.Contains("MEAN") ) | |
177 | { | |
178 | Int_t j(0); | |
179 | sscanf(sopt.Data(),"MEAN%d",&j); | |
180 | ||
181 | Double_t mean(0); | |
182 | Double_t v2(0); | |
183 | ||
184 | Int_t n = Size(); | |
185 | ||
186 | for ( Int_t i = 0; i < Size(); ++i ) | |
187 | { | |
188 | Float_t v = ValueAsDouble(i,j); | |
189 | mean += v; | |
190 | v2 += v*v; | |
191 | } | |
192 | mean /= n; | |
193 | float sigma = 0; | |
194 | if ( n > 1 ) sigma = TMath::Sqrt( (v2-n*mean*mean)/(n-1) ); | |
195 | cout << Form(" Mean(j=%d)=%g Sigma(j=%d)=%g",j,mean,j,sigma) << endl; | |
196 | } | |
197 | ||
198 | } | |
199 | ||
200 | //_____________________________________________________________________________ | |
201 | void | |
202 | AliMUONCalibParamND::SetValueAsDouble(Int_t i, Int_t j, Double_t value) | |
203 | { | |
204 | /// Set one value as a double, after checking that the indices are correct. | |
205 | ||
206 | Int_t ix = Index(i,j); | |
207 | ||
208 | if ( ix < 0 ) | |
209 | { | |
210 | AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)", | |
211 | i,j,Size()-1,Dimension()-1)); | |
212 | } | |
213 | else | |
214 | { | |
215 | fValues[ix]=value; | |
216 | } | |
217 | } | |
218 | ||
4db2bfee | 219 | //_____________________________________________________________________________ |
220 | void | |
221 | AliMUONCalibParamND::SetValueAsDoubleFast(Int_t i, Int_t j, Double_t value) | |
222 | { | |
223 | /// Set one value as a double, w/o checking that the indices are correct. | |
224 | ||
225 | fValues[IndexFast(i,j)] = value; | |
226 | } | |
da18abd2 | 227 | |
228 | //_____________________________________________________________________________ | |
229 | void | |
230 | AliMUONCalibParamND::SetValueAsFloat(Int_t i, Int_t j, Float_t value) | |
231 | { | |
232 | /// Set one value as a float, after checking that the indices are correct. | |
233 | SetValueAsDouble(i,j,static_cast<Double_t>(value)); | |
234 | } | |
235 | ||
4db2bfee | 236 | //_____________________________________________________________________________ |
237 | void | |
238 | AliMUONCalibParamND::SetValueAsFloatFast(Int_t i, Int_t j, Float_t value) | |
239 | { | |
240 | /// Set one value as a float, after checking that the indices are correct. | |
241 | SetValueAsDoubleFast(i,j,static_cast<Double_t>(value)); | |
242 | } | |
243 | ||
da18abd2 | 244 | //_____________________________________________________________________________ |
245 | void | |
246 | AliMUONCalibParamND::SetValueAsInt(Int_t i, Int_t j, Int_t value) | |
247 | { | |
248 | /// Set one value as an int. | |
249 | ||
250 | SetValueAsFloat(i,j,static_cast<Float_t>(value)); | |
251 | } | |
252 | ||
4db2bfee | 253 | //_____________________________________________________________________________ |
254 | void | |
255 | AliMUONCalibParamND::SetValueAsIntFast(Int_t i, Int_t j, Int_t value) | |
256 | { | |
257 | /// Set one value as an int. | |
258 | ||
259 | SetValueAsFloatFast(i,j,static_cast<Float_t>(value)); | |
260 | } | |
261 | ||
da18abd2 | 262 | //_____________________________________________________________________________ |
263 | Double_t | |
264 | AliMUONCalibParamND::ValueAsDouble(Int_t i, Int_t j) const | |
265 | { | |
266 | /// Return the value as a double (which it is), after checking indices. | |
267 | ||
268 | Int_t ix = Index(i,j); | |
269 | ||
270 | if ( ix < 0 ) | |
271 | { | |
272 | AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)", | |
273 | i,j,Size()-1,Dimension()-1)); | |
274 | return 0.0; | |
275 | } | |
276 | else | |
277 | { | |
278 | return fValues[ix]; | |
279 | } | |
280 | } | |
281 | ||
4db2bfee | 282 | //_____________________________________________________________________________ |
283 | Double_t | |
284 | AliMUONCalibParamND::ValueAsDoubleFast(Int_t i, Int_t j) const | |
285 | { | |
286 | /// Return the value as a double (which it is), w/o checking indices. | |
287 | ||
288 | return fValues[IndexFast(i,j)]; | |
289 | } | |
290 | ||
da18abd2 | 291 | //_____________________________________________________________________________ |
292 | Float_t | |
293 | AliMUONCalibParamND::ValueAsFloat(Int_t i, Int_t j) const | |
294 | { | |
295 | /// Return the value as a float | |
296 | return static_cast<Float_t>(ValueAsDouble(i,j)); | |
297 | } | |
298 | ||
4db2bfee | 299 | //_____________________________________________________________________________ |
300 | Float_t | |
301 | AliMUONCalibParamND::ValueAsFloatFast(Int_t i, Int_t j) const | |
302 | { | |
303 | /// Return the value as a float | |
304 | return static_cast<Float_t>(ValueAsDoubleFast(i,j)); | |
305 | } | |
306 | ||
da18abd2 | 307 | //_____________________________________________________________________________ |
308 | Int_t | |
309 | AliMUONCalibParamND::ValueAsInt(Int_t i, Int_t j) const | |
310 | { | |
311 | /// Return the value as an int, by rounding the internal float value. | |
312 | ||
313 | Float_t v = ValueAsFloat(i,j); | |
314 | return TMath::Nint(v); | |
315 | } | |
4db2bfee | 316 | |
317 | //_____________________________________________________________________________ | |
318 | Int_t | |
319 | AliMUONCalibParamND::ValueAsIntFast(Int_t i, Int_t j) const | |
320 | { | |
321 | /// Return the value as an int, by rounding the internal float value. | |
322 | ||
323 | Float_t v = ValueAsFloatFast(i,j); | |
324 | return TMath::Nint(v); | |
325 | } |