]>
Commit | Line | Data |
---|---|---|
3eec0a69 | 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 "AliMUONCalibParamNF.h" | |
19 | ||
20 | #include "AliLog.h" | |
21 | ||
22 | #include "Riostream.h" | |
23 | #include "TMath.h" | |
24 | #include "TString.h" | |
25 | ||
26 | /// | |
27 | /// \class AliMUONCalibParamNF | |
28 | /// | |
29 | /// Handle the case of N floating point parameters per channel. | |
30 | /// | |
31 | /// \author Laurent Aphecetche | |
32 | ||
33 | /// \cond CLASSIMP | |
34 | ClassImp(AliMUONCalibParamNF) | |
35 | /// \endcond | |
36 | ||
37 | //_____________________________________________________________________________ | |
38 | AliMUONCalibParamNF::AliMUONCalibParamNF() | |
39 | : AliMUONVCalibParam(), | |
40 | fDimension(0), | |
41 | fSize(0), | |
42 | fN(0), | |
43 | fValues(0x0) | |
44 | { | |
45 | /// Default constructor. | |
46 | } | |
47 | ||
48 | //_____________________________________________________________________________ | |
49 | AliMUONCalibParamNF::AliMUONCalibParamNF(Int_t dimension, Int_t theSize, Float_t fillWithValue) | |
50 | : AliMUONVCalibParam(), | |
51 | fDimension(dimension), | |
52 | fSize(theSize), | |
53 | fN(fSize*fDimension), | |
54 | fValues(0x0) | |
55 | { | |
56 | /// Normal constructor, where theSize specifies the number of channels handled | |
57 | /// by this object, and fillWithValue the default value assigned to each | |
58 | /// channel. | |
59 | ||
60 | if ( fN > 0 ) | |
61 | { | |
62 | fValues = new Float_t[fN]; | |
63 | for ( Int_t i = 0; i < fN; ++i ) | |
64 | { | |
65 | fValues[i] = fillWithValue; | |
66 | } | |
67 | } | |
68 | } | |
69 | ||
70 | ||
71 | //_____________________________________________________________________________ | |
72 | AliMUONCalibParamNF::AliMUONCalibParamNF(const AliMUONCalibParamNF& other) | |
73 | : AliMUONVCalibParam(), | |
74 | fDimension(0), | |
75 | fSize(0), | |
76 | fN(0), | |
77 | fValues(0x0) | |
78 | { | |
79 | /// Copy constructor. | |
80 | ||
81 | other.CopyTo(*this); | |
82 | } | |
83 | ||
84 | //_____________________________________________________________________________ | |
85 | AliMUONCalibParamNF& | |
86 | AliMUONCalibParamNF::operator=(const AliMUONCalibParamNF& other) | |
87 | { | |
88 | /// Assignment operator | |
89 | ||
90 | other.CopyTo(*this); | |
91 | return *this; | |
92 | } | |
93 | ||
94 | //_____________________________________________________________________________ | |
95 | AliMUONCalibParamNF::~AliMUONCalibParamNF() | |
96 | { | |
97 | /// Destructor | |
98 | ||
99 | delete[] fValues; | |
100 | } | |
101 | ||
102 | //_____________________________________________________________________________ | |
103 | void | |
104 | AliMUONCalibParamNF::CopyTo(AliMUONCalibParamNF& destination) const | |
105 | { | |
106 | /// Copy *this to destination | |
107 | ||
108 | delete[] destination.fValues; | |
109 | destination.fN = fN; | |
110 | destination.fSize = fSize; | |
111 | destination.fDimension = fDimension; | |
112 | ||
113 | if ( fN > 0 ) | |
114 | { | |
115 | destination.fValues = new Float_t[fN]; | |
116 | for ( Int_t i = 0; i < fN; ++i ) | |
117 | { | |
118 | destination.fValues[i] = fValues[i]; | |
119 | } | |
120 | } | |
121 | } | |
122 | ||
123 | //_____________________________________________________________________________ | |
124 | Int_t | |
125 | AliMUONCalibParamNF::Index(Int_t i, Int_t j) const | |
126 | { | |
127 | /// Compute the 1D index of the internal storage from the pair (i,j) | |
128 | /// Returns -1 if the (i,j) pair is invalid | |
129 | ||
130 | if ( i >= 0 && i < Size() && j >= 0 && j < Dimension() ) | |
131 | { | |
132 | return i + Size()*j; | |
133 | } | |
134 | return -1; | |
135 | } | |
136 | ||
137 | //_____________________________________________________________________________ | |
138 | void | |
139 | AliMUONCalibParamNF::Print(Option_t* opt) const | |
140 | { | |
141 | /// Output this object to stdout. | |
142 | /// If opt=="full", then all channels are printed, | |
143 | /// if opt=="mean#", only the mean and sigma value are printed for j-th dimension | |
144 | /// otherwise only the general characteristics are printed. | |
145 | ||
146 | TString sopt(opt); | |
147 | sopt.ToUpper(); | |
148 | cout << "AliMUONCalibParamNF - Size=" << Size() | |
149 | << " Dimension=" << Dimension() << endl; | |
150 | if ( sopt.Contains("FULL") ) | |
151 | { | |
152 | for ( Int_t i = 0; i < Size(); ++i ) | |
153 | { | |
154 | cout << Form("CH %3d",i); | |
155 | for ( Int_t j = 0; j < Dimension(); ++j ) | |
156 | { | |
157 | cout << Form(" %e",ValueAsFloat(i,j)); | |
158 | } | |
159 | cout << endl; | |
160 | } | |
161 | } | |
162 | if ( sopt.Contains("MEAN") ) | |
163 | { | |
164 | Int_t j(0); | |
165 | sscanf(sopt.Data(),"MEAN%d",&j); | |
166 | ||
167 | Float_t mean(0); | |
168 | Float_t v2(0); | |
169 | ||
170 | Int_t n = Size(); | |
171 | ||
172 | for ( Int_t i = 0; i < Size(); ++i ) | |
173 | { | |
174 | Float_t v = ValueAsFloat(i,j); | |
175 | mean += v; | |
176 | v2 += v*v; | |
177 | } | |
178 | mean /= n; | |
179 | float sigma = 0; | |
180 | if ( n > 1 ) sigma = TMath::Sqrt( (v2-n*mean*mean)/(n-1) ); | |
181 | cout << Form(" Mean(j=%d)=%e Sigma(j=%d)=%e",j,mean,j,sigma) << endl; | |
182 | } | |
183 | ||
184 | } | |
185 | ||
186 | //_____________________________________________________________________________ | |
187 | void | |
188 | AliMUONCalibParamNF::SetValueAsFloat(Int_t i, Int_t j, Float_t value) | |
189 | { | |
190 | /// Set one value as a float, after checking that the indices are correct. | |
191 | ||
192 | Int_t ix = Index(i,j); | |
193 | ||
194 | if ( ix < 0 ) | |
195 | { | |
196 | AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)", | |
197 | i,j,Size()-1,Dimension()-1)); | |
198 | } | |
199 | else | |
200 | { | |
201 | fValues[ix]=value; | |
202 | } | |
203 | } | |
204 | ||
205 | //_____________________________________________________________________________ | |
206 | void | |
207 | AliMUONCalibParamNF::SetValueAsInt(Int_t i, Int_t j, Int_t value) | |
208 | { | |
209 | /// Set one value as an int. | |
210 | ||
211 | SetValueAsFloat(i,j,static_cast<Float_t>(value)); | |
212 | } | |
213 | ||
214 | //_____________________________________________________________________________ | |
215 | Float_t | |
216 | AliMUONCalibParamNF::ValueAsFloat(Int_t i, Int_t j) const | |
217 | { | |
218 | /// Return the value as a float (which it is), after checking indices. | |
219 | ||
220 | Int_t ix = Index(i,j); | |
221 | ||
222 | if ( ix < 0 ) | |
223 | { | |
224 | AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)", | |
225 | i,j,Size()-1,Dimension()-1)); | |
226 | return 0.0; | |
227 | } | |
228 | else | |
229 | { | |
230 | return fValues[ix]; | |
231 | } | |
232 | } | |
233 | ||
234 | //_____________________________________________________________________________ | |
235 | Int_t | |
236 | AliMUONCalibParamNF::ValueAsInt(Int_t i, Int_t j) const | |
237 | { | |
238 | /// Return the value as an int, by rounding the internal float value. | |
239 | ||
240 | Float_t v = ValueAsFloat(i,j); | |
241 | return TMath::Nint(v); | |
242 | } |