]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONCalibParamNI.cxx
correct mask for V0 charge decoding in STU payload
[u/mrichter/AliRoot.git] / MUON / AliMUONCalibParamNI.cxx
CommitLineData
96fea1fd 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
3d1463c8 26//-----------------------------------------------------------------------------
96fea1fd 27/// \class AliMUONCalibParamNI
28///
29/// Handle the case of N integer parameters per channel.
30///
31/// Almost the same class as AliMUONCalibParamNF, but for ints.
32/// We could have played with NF to store both int and float (using casts),
33/// but for the sake of simplicity (e.g. the Print method must know whether
34/// it should print floats or ints), we decided to "duplicate" the class
35/// and use the correct type.
36///
37/// \author Laurent Aphecetche
3d1463c8 38//-----------------------------------------------------------------------------
96fea1fd 39
40/// \cond CLASSIMP
41ClassImp(AliMUONCalibParamNI)
42/// \endcond
43
44//_____________________________________________________________________________
45AliMUONCalibParamNI::AliMUONCalibParamNI()
46: AliMUONVCalibParam(),
47 fDimension(0),
48 fSize(0),
49 fN(0),
50 fPackingFactor(0),
51 fValues(0x0)
52{
53/// Default constructor.
a1546c3a 54 AliDebug(1,Form("this=%p default ctor",this));
96fea1fd 55}
56
57//_____________________________________________________________________________
a1546c3a 58AliMUONCalibParamNI::AliMUONCalibParamNI(Int_t dimension, Int_t theSize,
59 Int_t id0, Int_t id1,
96fea1fd 60 Int_t fillWithValue, Int_t packingFactor)
a1546c3a 61: AliMUONVCalibParam(id0,id1),
96fea1fd 62 fDimension(dimension),
63 fSize(theSize),
64 fN(fSize*fDimension),
65 fPackingFactor(packingFactor),
66 fValues(0x0)
67{
68/// Normal constructor, where theSize specifies the number of channels handled
69/// by this object, and fillWithValue the default value assigned to each
70/// channel.
71
4db2bfee 72// AliDebug(1,Form("this=%p dimension=%d theSize=%d fillWithValue=%d packingFactor=%d",
73// this,dimension,theSize,fillWithValue,packingFactor));
a1546c3a 74
96fea1fd 75 if ( fN > 0 )
76 {
77 fValues = new Int_t[fN];
78 for ( Int_t i = 0; i < fN; ++i )
79 {
80 fValues[i] = fillWithValue;
81 }
82 }
83}
84
85
86//_____________________________________________________________________________
87AliMUONCalibParamNI::AliMUONCalibParamNI(const AliMUONCalibParamNI& other)
88: AliMUONVCalibParam(),
89fDimension(0),
90fSize(0),
91fN(0),
92fPackingFactor(0),
93fValues(0x0)
94{
95/// Copy constructor.
96
a1546c3a 97 AliDebug(1,Form("this=%p copy ctor",this));
96fea1fd 98 other.CopyTo(*this);
99}
100
101//_____________________________________________________________________________
102AliMUONCalibParamNI&
103AliMUONCalibParamNI::operator=(const AliMUONCalibParamNI& other)
104{
105/// Assignment operator
106
107 other.CopyTo(*this);
108 return *this;
109}
110
111//_____________________________________________________________________________
112AliMUONCalibParamNI::~AliMUONCalibParamNI()
113{
114/// Destructor
115
a1546c3a 116 AliDebug(1,Form("this=%p",this));
96fea1fd 117 delete[] fValues;
118}
119
120//_____________________________________________________________________________
121void
122AliMUONCalibParamNI::CopyTo(AliMUONCalibParamNI& destination) const
123{
124/// Copy *this to destination
125
a1546c3a 126 const TObject& o = static_cast<const TObject&>(*this);
127 o.Copy(destination);
128
96fea1fd 129 delete[] destination.fValues;
130 destination.fN = fN;
131 destination.fSize = fSize;
132 destination.fDimension = fDimension;
133 destination.fPackingFactor = fPackingFactor;
134
135 if ( fN > 0 )
136 {
137 destination.fValues = new Int_t[fN];
138 for ( Int_t i = 0; i < fN; ++i )
139 {
140 destination.fValues[i] = fValues[i];
141 }
142 }
143}
144
145//_____________________________________________________________________________
146Int_t
147AliMUONCalibParamNI::Index(Int_t i, Int_t j) const
148{
149/// Compute the 1D index of the internal storage from the pair (i,j)
150/// Returns -1 if the (i,j) pair is invalid
151
152 if ( i >= 0 && i < Size() && j >= 0 && j < Dimension() )
153 {
4db2bfee 154 return IndexFast(i,j);
96fea1fd 155 }
156 return -1;
157}
158
4db2bfee 159//_____________________________________________________________________________
160Int_t
161AliMUONCalibParamNI::IndexFast(Int_t i, Int_t j) const
162{
163 /// Compute the 1D index of the internal storage from the pair (i,j)
164
165 return i + Size()*j;
166}
167
96fea1fd 168//_____________________________________________________________________________
169void
170AliMUONCalibParamNI::Print(Option_t* opt) const
171{
172/// Output this object to stdout.
173/// If opt=="full" then all channels are printed,
174/// if opt=="mean#", only the mean and sigma value are printed for j-th dimension
175/// otherwise only the general characteristics are printed.
176
177 TString sopt(opt);
178 sopt.ToUpper();
179 cout << "AliMUONCalibParamNI - Size=" << Size()
a1546c3a 180 << " Dimension=" << Dimension()
181 << " Id=(" << ID0() << "," << ID1() << ")";
182
96fea1fd 183 if ( IsPacked() )
184 {
185 cout << " Packing Factor=" << fPackingFactor;
186 }
187 cout << endl;
188
189 if ( sopt.Contains("FULL") )
190 {
191 for ( Int_t i = 0; i < Size(); ++i )
192 {
193 cout << Form("CH %3d",i);
194 for ( Int_t j = 0; j < Dimension(); ++j )
195 {
196 Int_t v = ValueAsInt(i,j);
197 if ( IsPacked() )
198 {
199 Int_t m,c;
200 UnpackValue(v,m,c);
a1546c3a 201 cout << Form(" (%d,%d) (0x%x,0x%x)",m,c,m,c);
96fea1fd 202 }
203 else
204 {
a1546c3a 205 cout << Form(" %d (0x%x)",v,v);
96fea1fd 206 }
207 }
208 cout << endl;
209 }
210 }
211 if ( sopt.Contains("MEAN") )
212 {
213 Int_t j(0);
214 sscanf(sopt.Data(),"MEAN%d",&j);
215
216 Float_t mean(0);
217 Float_t v2(0);
218
219 Int_t n = Size();
220
221 for ( Int_t i = 0; i < Size(); ++i )
222 {
223 Float_t v = ValueAsFloat(i,j);
224 mean += v;
225 v2 += v*v;
226 }
227 mean /= n;
228 float sigma = 0;
229 if ( n > 1 ) sigma = TMath::Sqrt( (v2-n*mean*mean)/(n-1) );
230 cout << Form(" Mean(j=%d)=%e Sigma(j=%d)=%e",j,mean,j,sigma) << endl;
231 }
232
233}
234
235//_____________________________________________________________________________
236void
237AliMUONCalibParamNI::SetValueAsInt(Int_t i, Int_t j, Int_t value)
238{
239/// Set one value as a float, after checking that the indices are correct.
240
241 Int_t ix = Index(i,j);
242
243 if ( ix < 0 )
244 {
245 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
246 i,j,Size()-1,Dimension()-1));
247 }
248 else
249 {
250 fValues[ix]=value;
251 }
252}
253
4db2bfee 254//_____________________________________________________________________________
255void
256AliMUONCalibParamNI::SetValueAsIntFast(Int_t i, Int_t j, Int_t value)
257{
258 /// Set one value as a float, w/o checking that the indices are correct.
259
260 fValues[IndexFast(i,j)] = value;
261}
262
96fea1fd 263//_____________________________________________________________________________
264void
265AliMUONCalibParamNI::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
266{
267 /// Set one value as an int.
268
269 AliWarning("Float will be rounded to be stored...");
270 SetValueAsInt(i,j,TMath::Nint(value));
271}
272
4db2bfee 273//_____________________________________________________________________________
274void
275AliMUONCalibParamNI::SetValueAsFloatFast(Int_t i, Int_t j, Float_t value)
276{
277 /// Set one value as an int.
278
279 AliWarning("Float will be rounded to be stored...");
280 SetValueAsIntFast(i,j,TMath::Nint(value));
281}
282
283
96fea1fd 284//_____________________________________________________________________________
285Int_t
286AliMUONCalibParamNI::ValueAsInt(Int_t i, Int_t j) const
287{
288/// Return the value as an int (which it is), after checking indices.
289
290 Int_t ix = Index(i,j);
291
292 if ( ix < 0 )
293 {
294 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
295 i,j,Size()-1,Dimension()-1));
296 return 0;
297 }
298 else
299 {
300 return fValues[ix];
301 }
302}
303
4db2bfee 304//_____________________________________________________________________________
305Int_t
306AliMUONCalibParamNI::ValueAsIntFast(Int_t i, Int_t j) const
307{
308 /// Return the value as an int (which it is), w/o checking indices.
309
310 return fValues[IndexFast(i,j)];
311}
312
96fea1fd 313//_____________________________________________________________________________
314Float_t
315AliMUONCalibParamNI::ValueAsFloat(Int_t i, Int_t j) const
316{
317 /// Return the value as a float
318 return static_cast<Float_t>(ValueAsInt(i,j));
319}
320
321//_____________________________________________________________________________
4db2bfee 322Float_t
323AliMUONCalibParamNI::ValueAsFloatFast(Int_t i, Int_t j) const
324{
325 /// Return the value as a float
326 return static_cast<Float_t>(ValueAsIntFast(i,j));
327}
328
329//_____________________________________________________________________________
96fea1fd 330Bool_t
331AliMUONCalibParamNI::UnpackValue(Int_t value, Int_t& a, Int_t& b) const
332{
333 /// Unpack single value into a couple (a,b), using packingFactor
334 /// Returns false if IsPacked()==false
335
336 if ( !IsPacked() ) return kFALSE;
337 a = value / fPackingFactor;
338 b = value % fPackingFactor;
339 return kTRUE;
340}
341
342//_____________________________________________________________________________
343Bool_t
344AliMUONCalibParamNI::PackValues(Int_t a, Int_t b, Int_t& packedValue) const
345{
346 /// Pack a couple (a,b) into a single value, using packingFactor
347 /// Returns false if IsPacked()==false
348
349 if ( !IsPacked() ) return kFALSE;
350 packedValue = a*fPackingFactor + b;
351 return kTRUE;
352}
353
354//_____________________________________________________________________________
355Bool_t
356AliMUONCalibParamNI::IsPacked() const
357{
358 /// Whether the values we store are packed or not.
359 /// If false, Pack and Unpack methods will always return false and do nothing
360 return (fPackingFactor != 0);
361}
362