AliRoot Core  v5-06-30 (35d6c57)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMUONCalibParamND.cxx
Go to the documentation of this file.
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 
26 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
33 
34 using std::cout;
35 using std::endl;
39 
40 //_____________________________________________________________________________
43  fDimension(0),
44  fSize(0),
45  fN(0),
46  fValues(0x0)
47 {
49 }
50 
51 //_____________________________________________________________________________
52 AliMUONCalibParamND::AliMUONCalibParamND(Int_t dimension, Int_t theSize,
53  Int_t id0, Int_t id1,
54  Double_t fillWithValue)
55 : AliMUONVCalibParam(id0,id1),
56  fDimension(dimension),
57  fSize(theSize),
58  fN(fSize*fDimension),
59  fValues(0x0)
60 {
64 
65  if ( fN > 0 )
66  {
67  fValues = new Double_t[fN];
68  for ( Int_t i = 0; i < fN; ++i )
69  {
70  fValues[i] = fillWithValue;
71  }
72  }
73 }
74 
75 
76 //_____________________________________________________________________________
79 fDimension(0),
80 fSize(0),
81 fN(0),
82 fValues(0x0)
83 {
85 
86  other.CopyTo(*this);
87 }
88 
89 //_____________________________________________________________________________
92 {
94 
95  other.CopyTo(*this);
96  return *this;
97 }
98 
99 //_____________________________________________________________________________
101 {
103 
104  delete[] fValues;
105 }
106 
107 //_____________________________________________________________________________
108 void
110 {
112 
113  TObject::Copy(destination);
114 
115  delete[] destination.fValues;
116  destination.fN = fN;
117  destination.fSize = fSize;
118  destination.fDimension = fDimension;
119 
120  if ( fN > 0 )
121  {
122  destination.fValues = new Double_t[fN];
123  for ( Int_t i = 0; i < fN; ++i )
124  {
125  destination.fValues[i] = fValues[i];
126  }
127  }
128 }
129 
130 //_____________________________________________________________________________
131 Int_t
132 AliMUONCalibParamND::Index(Int_t i, Int_t j) const
133 {
136 
137  if ( i >= 0 && i < Size() && j >= 0 && j < Dimension() )
138  {
139  return IndexFast(i,j);
140  }
141  return -1;
142 }
143 
144 //_____________________________________________________________________________
145 Int_t
146 AliMUONCalibParamND::IndexFast(Int_t i, Int_t j) const
147 {
149 
150  return i + Size()*j;
151 }
152 
153 //_____________________________________________________________________________
154 void
155 AliMUONCalibParamND::Print(Option_t* opt) const
156 {
161 
162  TString sopt(opt);
163  sopt.ToUpper();
164  cout << Form("AliMUONCalibParamND Id=(%d,%d) Size=%d Dimension=%d",ID0(),
165  ID1(),Size(),Dimension()) << endl;
166  if ( sopt.Contains("FULL") )
167  {
168  for ( Int_t i = 0; i < Size(); ++i )
169  {
170  cout << Form("CH %3d",i);
171  for ( Int_t j = 0; j < Dimension(); ++j )
172  {
173  cout << Form(" %g",ValueAsDouble(i,j));
174  }
175  cout << endl;
176  }
177  }
178  if ( sopt.Contains("MEAN") )
179  {
180  Int_t j(0);
181  sscanf(sopt.Data(),"MEAN%d",&j);
182 
183  Double_t mean(0);
184  Double_t v2(0);
185 
186  Int_t n = Size();
187 
188  for ( Int_t i = 0; i < Size(); ++i )
189  {
190  Float_t v = ValueAsDouble(i,j);
191  mean += v;
192  v2 += v*v;
193  }
194  mean /= n;
195  float sigma = 0;
196  if ( n > 1 ) sigma = TMath::Sqrt( (v2-n*mean*mean)/(n-1) );
197  cout << Form(" Mean(j=%d)=%g Sigma(j=%d)=%g",j,mean,j,sigma) << endl;
198  }
199 
200 }
201 
202 //_____________________________________________________________________________
203 void
204 AliMUONCalibParamND::SetValueAsDouble(Int_t i, Int_t j, Double_t value)
205 {
207 
208  Int_t ix = Index(i,j);
209 
210  if ( ix < 0 )
211  {
212  AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
213  i,j,Size()-1,Dimension()-1));
214  }
215  else
216  {
217  fValues[ix]=value;
218  }
219 }
220 
221 //_____________________________________________________________________________
222 void
223 AliMUONCalibParamND::SetValueAsDoubleFast(Int_t i, Int_t j, Double_t value)
224 {
226 
227  fValues[IndexFast(i,j)] = value;
228 }
229 
230 //_____________________________________________________________________________
231 void
232 AliMUONCalibParamND::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
233 {
235  SetValueAsDouble(i,j,static_cast<Double_t>(value));
236 }
237 
238 //_____________________________________________________________________________
239 void
240 AliMUONCalibParamND::SetValueAsFloatFast(Int_t i, Int_t j, Float_t value)
241 {
243  SetValueAsDoubleFast(i,j,static_cast<Double_t>(value));
244 }
245 
246 //_____________________________________________________________________________
247 void
248 AliMUONCalibParamND::SetValueAsInt(Int_t i, Int_t j, Int_t value)
249 {
251 
252  SetValueAsFloat(i,j,static_cast<Float_t>(value));
253 }
254 
255 //_____________________________________________________________________________
256 void
257 AliMUONCalibParamND::SetValueAsIntFast(Int_t i, Int_t j, Int_t value)
258 {
260 
261  SetValueAsFloatFast(i,j,static_cast<Float_t>(value));
262 }
263 
264 //_____________________________________________________________________________
265 Double_t
266 AliMUONCalibParamND::ValueAsDouble(Int_t i, Int_t j) const
267 {
269 
270  Int_t ix = Index(i,j);
271 
272  if ( ix < 0 )
273  {
274  AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
275  i,j,Size()-1,Dimension()-1));
276  return 0.0;
277  }
278  else
279  {
280  return fValues[ix];
281  }
282 }
283 
284 //_____________________________________________________________________________
285 Double_t
287 {
289 
290  return fValues[IndexFast(i,j)];
291 }
292 
293 //_____________________________________________________________________________
294 Float_t
295 AliMUONCalibParamND::ValueAsFloat(Int_t i, Int_t j) const
296 {
298  return static_cast<Float_t>(ValueAsDouble(i,j));
299 }
300 
301 //_____________________________________________________________________________
302 Float_t
304 {
306  return static_cast<Float_t>(ValueAsDoubleFast(i,j));
307 }
308 
309 //_____________________________________________________________________________
310 Int_t
311 AliMUONCalibParamND::ValueAsInt(Int_t i, Int_t j) const
312 {
314 
315  Float_t v = ValueAsFloat(i,j);
316  return TMath::Nint(v);
317 }
318 
319 //_____________________________________________________________________________
320 Int_t
321 AliMUONCalibParamND::ValueAsIntFast(Int_t i, Int_t j) const
322 {
324 
325  Float_t v = ValueAsFloatFast(i,j);
326  return TMath::Nint(v);
327 }
virtual Int_t Size() const
Return size - the number of double tuples we hold.
void CopyTo(AliMUONCalibParamND &destination) const
virtual void SetValueAsInt(Int_t i, Int_t j, Int_t value)
Set one value, for channel i, dimension j. Consider value is an integer.
virtual void SetValueAsIntFast(Int_t i, Int_t j, Int_t value)
Same as above but w/o bound checkings.
Int_t fSize
The number of double tuples we hold.
Int_t IndexFast(Int_t i, Int_t j) const
Int_t fN
The total number of floats we hold (fDimension*fSize)
virtual Double_t ValueAsDoubleFast(Int_t i, Int_t j=0) const
virtual void SetValueAsDouble(Int_t i, Int_t j, Double_t value)
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
Int_t fDimension
dimension of this object
Container of calibration values for a given number of channels.
virtual void SetValueAsDoubleFast(Int_t i, Int_t j, Double_t value)
Same as above but w/o bound checking.
virtual Float_t ValueAsFloatFast(Int_t i, Int_t j=0) const
Same as above but without bound checking.
virtual Double_t ValueAsDouble(Int_t i, Int_t j=0) const
virtual Int_t ID0() const
First id of this object.
virtual Int_t ID1() const
Second id of this object (might not be required)
Implementation of AliMUONVCalibParam for tuples of double.
virtual void SetValueAsFloatFast(Int_t i, Int_t j, Float_t value)
virtual Int_t ValueAsIntFast(Int_t i, Int_t j=0) const
Same as above but w/o bound checking.
virtual void SetValueAsFloat(Int_t i, Int_t j, Float_t value)
Set one value, for channel i, dimension j. Consider value is a float.
Int_t Index(Int_t i, Int_t j) const
virtual Int_t Dimension() const
Return dimension.
Double_t * fValues
The values array.
virtual void Print(Option_t *opt="") const
virtual Int_t ValueAsInt(Int_t i, Int_t j=0) const
AliMUONCalibParamND & operator=(const AliMUONCalibParamND &other)
virtual Float_t ValueAsFloat(Int_t i, Int_t j=0) const