]>
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 | ||
111 | delete[] destination.fValues; | |
112 | destination.fN = fN; | |
113 | destination.fSize = fSize; | |
114 | destination.fDimension = fDimension; | |
115 | ||
116 | if ( fN > 0 ) | |
117 | { | |
118 | destination.fValues = new Double_t[fN]; | |
119 | for ( Int_t i = 0; i < fN; ++i ) | |
120 | { | |
121 | destination.fValues[i] = fValues[i]; | |
122 | } | |
123 | } | |
124 | } | |
125 | ||
126 | //_____________________________________________________________________________ | |
127 | Int_t | |
128 | AliMUONCalibParamND::Index(Int_t i, Int_t j) const | |
129 | { | |
130 | /// Compute the 1D index of the internal storage from the pair (i,j) | |
131 | /// Returns -1 if the (i,j) pair is invalid | |
132 | ||
133 | if ( i >= 0 && i < Size() && j >= 0 && j < Dimension() ) | |
134 | { | |
135 | return i + Size()*j; | |
136 | } | |
137 | return -1; | |
138 | } | |
139 | ||
140 | //_____________________________________________________________________________ | |
141 | void | |
142 | AliMUONCalibParamND::Print(Option_t* opt) const | |
143 | { | |
144 | /// Output this object to stdout. | |
145 | /// If opt=="full", then all channels are printed, | |
146 | /// if opt=="mean#", only the mean and sigma value are printed for j-th dimension | |
147 | /// otherwise only the general characteristics are printed. | |
148 | ||
149 | TString sopt(opt); | |
150 | sopt.ToUpper(); | |
151 | cout << Form("AliMUONCalibParamND Id=(%d,%d) Size=%d Dimension=%d",ID0(), | |
152 | ID1(),Size(),Dimension()) << endl; | |
153 | if ( sopt.Contains("FULL") ) | |
154 | { | |
155 | for ( Int_t i = 0; i < Size(); ++i ) | |
156 | { | |
157 | cout << Form("CH %3d",i); | |
158 | for ( Int_t j = 0; j < Dimension(); ++j ) | |
159 | { | |
160 | cout << Form(" %g",ValueAsDouble(i,j)); | |
161 | } | |
162 | cout << endl; | |
163 | } | |
164 | } | |
165 | if ( sopt.Contains("MEAN") ) | |
166 | { | |
167 | Int_t j(0); | |
168 | sscanf(sopt.Data(),"MEAN%d",&j); | |
169 | ||
170 | Double_t mean(0); | |
171 | Double_t v2(0); | |
172 | ||
173 | Int_t n = Size(); | |
174 | ||
175 | for ( Int_t i = 0; i < Size(); ++i ) | |
176 | { | |
177 | Float_t v = ValueAsDouble(i,j); | |
178 | mean += v; | |
179 | v2 += v*v; | |
180 | } | |
181 | mean /= n; | |
182 | float sigma = 0; | |
183 | if ( n > 1 ) sigma = TMath::Sqrt( (v2-n*mean*mean)/(n-1) ); | |
184 | cout << Form(" Mean(j=%d)=%g Sigma(j=%d)=%g",j,mean,j,sigma) << endl; | |
185 | } | |
186 | ||
187 | } | |
188 | ||
189 | //_____________________________________________________________________________ | |
190 | void | |
191 | AliMUONCalibParamND::SetValueAsDouble(Int_t i, Int_t j, Double_t value) | |
192 | { | |
193 | /// Set one value as a double, after checking that the indices are correct. | |
194 | ||
195 | Int_t ix = Index(i,j); | |
196 | ||
197 | if ( ix < 0 ) | |
198 | { | |
199 | AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)", | |
200 | i,j,Size()-1,Dimension()-1)); | |
201 | } | |
202 | else | |
203 | { | |
204 | fValues[ix]=value; | |
205 | } | |
206 | } | |
207 | ||
208 | ||
209 | //_____________________________________________________________________________ | |
210 | void | |
211 | AliMUONCalibParamND::SetValueAsFloat(Int_t i, Int_t j, Float_t value) | |
212 | { | |
213 | /// Set one value as a float, after checking that the indices are correct. | |
214 | SetValueAsDouble(i,j,static_cast<Double_t>(value)); | |
215 | } | |
216 | ||
217 | //_____________________________________________________________________________ | |
218 | void | |
219 | AliMUONCalibParamND::SetValueAsInt(Int_t i, Int_t j, Int_t value) | |
220 | { | |
221 | /// Set one value as an int. | |
222 | ||
223 | SetValueAsFloat(i,j,static_cast<Float_t>(value)); | |
224 | } | |
225 | ||
226 | //_____________________________________________________________________________ | |
227 | Double_t | |
228 | AliMUONCalibParamND::ValueAsDouble(Int_t i, Int_t j) const | |
229 | { | |
230 | /// Return the value as a double (which it is), after checking indices. | |
231 | ||
232 | Int_t ix = Index(i,j); | |
233 | ||
234 | if ( ix < 0 ) | |
235 | { | |
236 | AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)", | |
237 | i,j,Size()-1,Dimension()-1)); | |
238 | return 0.0; | |
239 | } | |
240 | else | |
241 | { | |
242 | return fValues[ix]; | |
243 | } | |
244 | } | |
245 | ||
246 | //_____________________________________________________________________________ | |
247 | Float_t | |
248 | AliMUONCalibParamND::ValueAsFloat(Int_t i, Int_t j) const | |
249 | { | |
250 | /// Return the value as a float | |
251 | return static_cast<Float_t>(ValueAsDouble(i,j)); | |
252 | } | |
253 | ||
254 | //_____________________________________________________________________________ | |
255 | Int_t | |
256 | AliMUONCalibParamND::ValueAsInt(Int_t i, Int_t j) const | |
257 | { | |
258 | /// Return the value as an int, by rounding the internal float value. | |
259 | ||
260 | Float_t v = ValueAsFloat(i,j); | |
261 | return TMath::Nint(v); | |
262 | } |