1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUONCalibParamNI.h"
22 #include "Riostream.h"
26 //-----------------------------------------------------------------------------
27 /// \class AliMUONCalibParamNI
29 /// Handle the case of N integer parameters per channel.
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.
37 /// \author Laurent Aphecetche
38 //-----------------------------------------------------------------------------
43 ClassImp(AliMUONCalibParamNI)
46 //_____________________________________________________________________________
47 AliMUONCalibParamNI::AliMUONCalibParamNI()
48 : AliMUONVCalibParam(),
55 /// Default constructor.
56 AliDebug(1,Form("this=%p default ctor",this));
59 //_____________________________________________________________________________
60 AliMUONCalibParamNI::AliMUONCalibParamNI(Int_t dimension, Int_t theSize,
62 Int_t fillWithValue, Int_t packingFactor)
63 : AliMUONVCalibParam(id0,id1),
64 fDimension(dimension),
67 fPackingFactor(packingFactor),
70 /// Normal constructor, where theSize specifies the number of channels handled
71 /// by this object, and fillWithValue the default value assigned to each
74 // AliDebug(1,Form("this=%p dimension=%d theSize=%d fillWithValue=%d packingFactor=%d",
75 // this,dimension,theSize,fillWithValue,packingFactor));
79 fValues = new Int_t[fN];
80 for ( Int_t i = 0; i < fN; ++i )
82 fValues[i] = fillWithValue;
88 //_____________________________________________________________________________
89 AliMUONCalibParamNI::AliMUONCalibParamNI(const AliMUONCalibParamNI& other)
90 : AliMUONVCalibParam(),
99 AliDebug(1,Form("this=%p copy ctor",this));
103 //_____________________________________________________________________________
105 AliMUONCalibParamNI::operator=(const AliMUONCalibParamNI& other)
107 /// Assignment operator
113 //_____________________________________________________________________________
114 AliMUONCalibParamNI::~AliMUONCalibParamNI()
118 AliDebug(1,Form("this=%p",this));
122 //_____________________________________________________________________________
124 AliMUONCalibParamNI::CopyTo(AliMUONCalibParamNI& destination) const
126 /// Copy *this to destination
128 const TObject& o = static_cast<const TObject&>(*this);
131 delete[] destination.fValues;
133 destination.fSize = fSize;
134 destination.fDimension = fDimension;
135 destination.fPackingFactor = fPackingFactor;
139 destination.fValues = new Int_t[fN];
140 for ( Int_t i = 0; i < fN; ++i )
142 destination.fValues[i] = fValues[i];
147 //_____________________________________________________________________________
149 AliMUONCalibParamNI::Index(Int_t i, Int_t j) const
151 /// Compute the 1D index of the internal storage from the pair (i,j)
152 /// Returns -1 if the (i,j) pair is invalid
154 if ( i >= 0 && i < Size() && j >= 0 && j < Dimension() )
156 return IndexFast(i,j);
161 //_____________________________________________________________________________
163 AliMUONCalibParamNI::IndexFast(Int_t i, Int_t j) const
165 /// Compute the 1D index of the internal storage from the pair (i,j)
170 //_____________________________________________________________________________
172 AliMUONCalibParamNI::Print(Option_t* opt) const
174 /// Output this object to stdout.
175 /// If opt=="full" then all channels are printed,
176 /// if opt=="mean#", only the mean and sigma value are printed for j-th dimension
177 /// otherwise only the general characteristics are printed.
181 cout << "AliMUONCalibParamNI - Size=" << Size()
182 << " Dimension=" << Dimension()
183 << " Id=(" << ID0() << "," << ID1() << ")";
187 cout << " Packing Factor=" << fPackingFactor;
191 if ( sopt.Contains("FULL") )
193 for ( Int_t i = 0; i < Size(); ++i )
195 cout << Form("CH %3d",i);
196 for ( Int_t j = 0; j < Dimension(); ++j )
198 Int_t v = ValueAsInt(i,j);
203 cout << Form(" (%d,%d) (0x%x,0x%x)",m,c,m,c);
207 cout << Form(" %d (0x%x)",v,v);
213 if ( sopt.Contains("MEAN") )
216 sscanf(sopt.Data(),"MEAN%d",&j);
223 for ( Int_t i = 0; i < Size(); ++i )
225 Float_t v = ValueAsFloat(i,j);
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;
237 //_____________________________________________________________________________
239 AliMUONCalibParamNI::SetValueAsInt(Int_t i, Int_t j, Int_t value)
241 /// Set one value as a float, after checking that the indices are correct.
243 Int_t ix = Index(i,j);
247 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
248 i,j,Size()-1,Dimension()-1));
256 //_____________________________________________________________________________
258 AliMUONCalibParamNI::SetValueAsIntFast(Int_t i, Int_t j, Int_t value)
260 /// Set one value as a float, w/o checking that the indices are correct.
262 fValues[IndexFast(i,j)] = value;
265 //_____________________________________________________________________________
267 AliMUONCalibParamNI::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
269 /// Set one value as an int.
271 AliWarning("Float will be rounded to be stored...");
272 SetValueAsInt(i,j,TMath::Nint(value));
275 //_____________________________________________________________________________
277 AliMUONCalibParamNI::SetValueAsFloatFast(Int_t i, Int_t j, Float_t value)
279 /// Set one value as an int.
281 AliWarning("Float will be rounded to be stored...");
282 SetValueAsIntFast(i,j,TMath::Nint(value));
286 //_____________________________________________________________________________
288 AliMUONCalibParamNI::ValueAsInt(Int_t i, Int_t j) const
290 /// Return the value as an int (which it is), after checking indices.
292 Int_t ix = Index(i,j);
296 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
297 i,j,Size()-1,Dimension()-1));
306 //_____________________________________________________________________________
308 AliMUONCalibParamNI::ValueAsIntFast(Int_t i, Int_t j) const
310 /// Return the value as an int (which it is), w/o checking indices.
312 return fValues[IndexFast(i,j)];
315 //_____________________________________________________________________________
317 AliMUONCalibParamNI::ValueAsFloat(Int_t i, Int_t j) const
319 /// Return the value as a float
320 return static_cast<Float_t>(ValueAsInt(i,j));
323 //_____________________________________________________________________________
325 AliMUONCalibParamNI::ValueAsFloatFast(Int_t i, Int_t j) const
327 /// Return the value as a float
328 return static_cast<Float_t>(ValueAsIntFast(i,j));
331 //_____________________________________________________________________________
333 AliMUONCalibParamNI::UnpackValue(Int_t value, Int_t& a, Int_t& b) const
335 /// Unpack single value into a couple (a,b), using packingFactor
336 /// Returns false if IsPacked()==false
338 if ( !IsPacked() ) return kFALSE;
339 a = value / fPackingFactor;
340 b = value % fPackingFactor;
344 //_____________________________________________________________________________
346 AliMUONCalibParamNI::PackValues(Int_t a, Int_t b, Int_t& packedValue) const
348 /// Pack a couple (a,b) into a single value, using packingFactor
349 /// Returns false if IsPacked()==false
351 if ( !IsPacked() ) return kFALSE;
352 packedValue = a*fPackingFactor + b;
356 //_____________________________________________________________________________
358 AliMUONCalibParamNI::IsPacked() const
360 /// Whether the values we store are packed or not.
361 /// If false, Pack and Unpack methods will always return false and do nothing
362 return (fPackingFactor != 0);