AliRoot Core  edcc906 (edcc906)
AliMUONCalibParamNI.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 "AliMUONCalibParamNI.h"
19 
20 #include "AliLog.h"
21 
22 #include "Riostream.h"
23 #include "TMath.h"
24 #include "TString.h"
25 
26 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
39 
40 using std::cout;
41 using std::endl;
43 ClassImp(AliMUONCalibParamNI)
45 
46 //_____________________________________________________________________________
49  fDimension(0),
50  fSize(0),
51  fN(0),
52  fPackingFactor(0),
53  fValues(0x0)
54 {
56  AliDebug(1,Form("this=%p default ctor",this));
57 }
58 
59 //_____________________________________________________________________________
60 AliMUONCalibParamNI::AliMUONCalibParamNI(Int_t dimension, Int_t theSize,
61  Int_t id0, Int_t id1,
62  Int_t fillWithValue, Int_t packingFactor)
63 : AliMUONVCalibParam(id0,id1),
64  fDimension(dimension),
65  fSize(theSize),
66  fN(fSize*fDimension),
67  fPackingFactor(packingFactor),
68  fValues(0x0)
69 {
73 
74 // AliDebug(1,Form("this=%p dimension=%d theSize=%d fillWithValue=%d packingFactor=%d",
75 // this,dimension,theSize,fillWithValue,packingFactor));
76 
77  if ( fN > 0 )
78  {
79  fValues = new Int_t[fN];
80  for ( Int_t i = 0; i < fN; ++i )
81  {
82  fValues[i] = fillWithValue;
83  }
84  }
85 }
86 
87 
88 //_____________________________________________________________________________
91 fDimension(0),
92 fSize(0),
93 fN(0),
95 fValues(0x0)
96 {
98 
99  AliDebug(1,Form("this=%p copy ctor",this));
100  other.CopyTo(*this);
101 }
102 
103 //_____________________________________________________________________________
106 {
108 
109  other.CopyTo(*this);
110  return *this;
111 }
112 
113 //_____________________________________________________________________________
115 {
117 
118  AliDebug(1,Form("this=%p",this));
119  delete[] fValues;
120 }
121 
122 //_____________________________________________________________________________
123 void
125 {
127 
128  const TObject& o = static_cast<const TObject&>(*this);
129  o.Copy(destination);
130 
131  delete[] destination.fValues;
132  destination.fN = fN;
133  destination.fSize = fSize;
134  destination.fDimension = fDimension;
135  destination.fPackingFactor = fPackingFactor;
136 
137  if ( fN > 0 )
138  {
139  destination.fValues = new Int_t[fN];
140  for ( Int_t i = 0; i < fN; ++i )
141  {
142  destination.fValues[i] = fValues[i];
143  }
144  }
145 }
146 
147 //_____________________________________________________________________________
148 Int_t
149 AliMUONCalibParamNI::Index(Int_t i, Int_t j) const
150 {
153 
154  if ( i >= 0 && i < Size() && j >= 0 && j < Dimension() )
155  {
156  return IndexFast(i,j);
157  }
158  return -1;
159 }
160 
161 //_____________________________________________________________________________
162 Int_t
163 AliMUONCalibParamNI::IndexFast(Int_t i, Int_t j) const
164 {
166 
167  return i + Size()*j;
168 }
169 
170 //_____________________________________________________________________________
171 void
172 AliMUONCalibParamNI::Print(Option_t* opt) const
173 {
178 
179  TString sopt(opt);
180  sopt.ToUpper();
181  cout << "AliMUONCalibParamNI - Size=" << Size()
182  << " Dimension=" << Dimension()
183  << " Id=(" << ID0() << "," << ID1() << ")";
184 
185  if ( IsPacked() )
186  {
187  cout << " Packing Factor=" << fPackingFactor;
188  }
189  cout << endl;
190 
191  if ( sopt.Contains("FULL") )
192  {
193  for ( Int_t i = 0; i < Size(); ++i )
194  {
195  cout << Form("CH %3d",i);
196  for ( Int_t j = 0; j < Dimension(); ++j )
197  {
198  Int_t v = ValueAsInt(i,j);
199  if ( IsPacked() )
200  {
201  Int_t m,c;
202  UnpackValue(v,m,c);
203  cout << Form(" (%d,%d) (0x%x,0x%x)",m,c,m,c);
204  }
205  else
206  {
207  cout << Form(" %d (0x%x)",v,v);
208  }
209  }
210  cout << endl;
211  }
212  }
213  if ( sopt.Contains("MEAN") )
214  {
215  Int_t j(0);
216  sscanf(sopt.Data(),"MEAN%d",&j);
217 
218  Float_t mean(0);
219  Float_t v2(0);
220 
221  Int_t n = Size();
222 
223  for ( Int_t i = 0; i < Size(); ++i )
224  {
225  Float_t v = ValueAsFloat(i,j);
226  mean += v;
227  v2 += v*v;
228  }
229  mean /= n;
230  float sigma = 0;
231  if ( n > 1 ) sigma = TMath::Sqrt( (v2-n*mean*mean)/(n-1) );
232  cout << Form(" Mean(j=%d)=%e Sigma(j=%d)=%e",j,mean,j,sigma) << endl;
233  }
234 
235 }
236 
237 //_____________________________________________________________________________
238 void
239 AliMUONCalibParamNI::SetValueAsInt(Int_t i, Int_t j, Int_t value)
240 {
242 
243  Int_t ix = Index(i,j);
244 
245  if ( ix < 0 )
246  {
247  AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
248  i,j,Size()-1,Dimension()-1));
249  }
250  else
251  {
252  fValues[ix]=value;
253  }
254 }
255 
256 //_____________________________________________________________________________
257 void
258 AliMUONCalibParamNI::SetValueAsIntFast(Int_t i, Int_t j, Int_t value)
259 {
261 
262  fValues[IndexFast(i,j)] = value;
263 }
264 
265 //_____________________________________________________________________________
266 void
267 AliMUONCalibParamNI::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
268 {
270 
271  AliWarning("Float will be rounded to be stored...");
272  SetValueAsInt(i,j,TMath::Nint(value));
273 }
274 
275 //_____________________________________________________________________________
276 void
277 AliMUONCalibParamNI::SetValueAsFloatFast(Int_t i, Int_t j, Float_t value)
278 {
280 
281  AliWarning("Float will be rounded to be stored...");
282  SetValueAsIntFast(i,j,TMath::Nint(value));
283 }
284 
285 
286 //_____________________________________________________________________________
287 Int_t
288 AliMUONCalibParamNI::ValueAsInt(Int_t i, Int_t j) const
289 {
291 
292  Int_t ix = Index(i,j);
293 
294  if ( ix < 0 )
295  {
296  AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
297  i,j,Size()-1,Dimension()-1));
298  return 0;
299  }
300  else
301  {
302  return fValues[ix];
303  }
304 }
305 
306 //_____________________________________________________________________________
307 Int_t
308 AliMUONCalibParamNI::ValueAsIntFast(Int_t i, Int_t j) const
309 {
311 
312  return fValues[IndexFast(i,j)];
313 }
314 
315 //_____________________________________________________________________________
316 Float_t
317 AliMUONCalibParamNI::ValueAsFloat(Int_t i, Int_t j) const
318 {
320  return static_cast<Float_t>(ValueAsInt(i,j));
321 }
322 
323 //_____________________________________________________________________________
324 Float_t
326 {
328  return static_cast<Float_t>(ValueAsIntFast(i,j));
329 }
330 
331 //_____________________________________________________________________________
332 Bool_t
333 AliMUONCalibParamNI::UnpackValue(Int_t value, Int_t& a, Int_t& b) const
334 {
337 
338  if ( !IsPacked() ) return kFALSE;
339  a = value / fPackingFactor;
340  b = value % fPackingFactor;
341  return kTRUE;
342 }
343 
344 //_____________________________________________________________________________
345 Bool_t
346 AliMUONCalibParamNI::PackValues(Int_t a, Int_t b, Int_t& packedValue) const
347 {
350 
351  if ( !IsPacked() ) return kFALSE;
352  packedValue = a*fPackingFactor + b;
353  return kTRUE;
354 }
355 
356 //_____________________________________________________________________________
357 Bool_t
359 {
362  return (fPackingFactor != 0);
363 }
364 
TBrowser b
Definition: RunAnaESD.C:12
Int_t IndexFast(Int_t i, Int_t j) const
virtual void SetValueAsFloatFast(Int_t i, Int_t j, Float_t value)
virtual Float_t ValueAsFloat(Int_t i, Int_t j=0) const
Int_t fDimension
dimension of this object
#define AliWarning(message)
Definition: AliLog.h:541
Container of calibration values for a given number of channels.
virtual Int_t Size() const
Return size - the number of float pair we hold.
Implementation of AliMUONVCalibParam for tuples of ints.
virtual Int_t ValueAsIntFast(Int_t i, Int_t j=0) const
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 Int_t ID0() const
First id of this object.
virtual Int_t ID1() const
Second id of this object (might not be required)
Int_t * fValues
The values array.
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 Print(Option_t *opt="") const
virtual Bool_t UnpackValue(Int_t value, Int_t &a, Int_t &b) const
Unpack a value into a couple (a,b). Returns false if IsPacked()==kFALSE.
virtual Bool_t IsPacked() const
whether or not the value we store are packed, e.g. as v = a*cste + b
virtual Int_t ValueAsInt(Int_t i, Int_t j=0) const
#define AliDebug(logLevel, message)
Definition: AliLog.h:300
Int_t Index(Int_t i, Int_t j) const
void CopyTo(AliMUONCalibParamNI &destination) const
virtual Bool_t PackValues(Int_t a, Int_t b, Int_t &packedValue) const
Pack (a,b) as a single int. Returns false if IsPacked()==kFALSE.
Int_t fPackingFactor
packing factor, i.e. value = a*fPackingFactor + b
Int_t fSize
The number of float pair we hold.
virtual Int_t Dimension() const
Return dimension.
#define AliError(message)
Definition: AliLog.h:591
virtual void SetValueAsIntFast(Int_t i, Int_t j, Int_t value)
Same as above but w/o bound checkings.
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 fN
The total number of floats we hold (fDimension*fSize)
AliMUONCalibParamNI & operator=(const AliMUONCalibParamNI &other)