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"
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
40 ClassImp(AliMUONCalibParamNI)
43 //_____________________________________________________________________________
44 AliMUONCalibParamNI::AliMUONCalibParamNI()
45 : AliMUONVCalibParam(),
52 /// Default constructor.
55 //_____________________________________________________________________________
56 AliMUONCalibParamNI::AliMUONCalibParamNI(Int_t dimension, Int_t theSize,
57 Int_t fillWithValue, Int_t packingFactor)
58 : AliMUONVCalibParam(),
59 fDimension(dimension),
62 fPackingFactor(packingFactor),
65 /// Normal constructor, where theSize specifies the number of channels handled
66 /// by this object, and fillWithValue the default value assigned to each
71 fValues = new Int_t[fN];
72 for ( Int_t i = 0; i < fN; ++i )
74 fValues[i] = fillWithValue;
80 //_____________________________________________________________________________
81 AliMUONCalibParamNI::AliMUONCalibParamNI(const AliMUONCalibParamNI& other)
82 : AliMUONVCalibParam(),
94 //_____________________________________________________________________________
96 AliMUONCalibParamNI::operator=(const AliMUONCalibParamNI& other)
98 /// Assignment operator
104 //_____________________________________________________________________________
105 AliMUONCalibParamNI::~AliMUONCalibParamNI()
112 //_____________________________________________________________________________
114 AliMUONCalibParamNI::CopyTo(AliMUONCalibParamNI& destination) const
116 /// Copy *this to destination
118 delete[] destination.fValues;
120 destination.fSize = fSize;
121 destination.fDimension = fDimension;
122 destination.fPackingFactor = fPackingFactor;
126 destination.fValues = new Int_t[fN];
127 for ( Int_t i = 0; i < fN; ++i )
129 destination.fValues[i] = fValues[i];
134 //_____________________________________________________________________________
136 AliMUONCalibParamNI::Index(Int_t i, Int_t j) const
138 /// Compute the 1D index of the internal storage from the pair (i,j)
139 /// Returns -1 if the (i,j) pair is invalid
141 if ( i >= 0 && i < Size() && j >= 0 && j < Dimension() )
148 //_____________________________________________________________________________
150 AliMUONCalibParamNI::Print(Option_t* opt) const
152 /// Output this object to stdout.
153 /// If opt=="full" then all channels are printed,
154 /// if opt=="mean#", only the mean and sigma value are printed for j-th dimension
155 /// otherwise only the general characteristics are printed.
159 cout << "AliMUONCalibParamNI - Size=" << Size()
160 << " Dimension=" << Dimension();
163 cout << " Packing Factor=" << fPackingFactor;
167 if ( sopt.Contains("FULL") )
169 for ( Int_t i = 0; i < Size(); ++i )
171 cout << Form("CH %3d",i);
172 for ( Int_t j = 0; j < Dimension(); ++j )
174 Int_t v = ValueAsInt(i,j);
179 cout << Form(" (%d,%d)",m,c);
183 cout << Form(" %d",v);
189 if ( sopt.Contains("MEAN") )
192 sscanf(sopt.Data(),"MEAN%d",&j);
199 for ( Int_t i = 0; i < Size(); ++i )
201 Float_t v = ValueAsFloat(i,j);
207 if ( n > 1 ) sigma = TMath::Sqrt( (v2-n*mean*mean)/(n-1) );
208 cout << Form(" Mean(j=%d)=%e Sigma(j=%d)=%e",j,mean,j,sigma) << endl;
213 //_____________________________________________________________________________
215 AliMUONCalibParamNI::SetValueAsInt(Int_t i, Int_t j, Int_t value)
217 /// Set one value as a float, after checking that the indices are correct.
219 Int_t ix = Index(i,j);
223 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
224 i,j,Size()-1,Dimension()-1));
232 //_____________________________________________________________________________
234 AliMUONCalibParamNI::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
236 /// Set one value as an int.
238 AliWarning("Float will be rounded to be stored...");
239 SetValueAsInt(i,j,TMath::Nint(value));
242 //_____________________________________________________________________________
244 AliMUONCalibParamNI::ValueAsInt(Int_t i, Int_t j) const
246 /// Return the value as an int (which it is), after checking indices.
248 Int_t ix = Index(i,j);
252 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
253 i,j,Size()-1,Dimension()-1));
262 //_____________________________________________________________________________
264 AliMUONCalibParamNI::ValueAsFloat(Int_t i, Int_t j) const
266 /// Return the value as a float
267 return static_cast<Float_t>(ValueAsInt(i,j));
270 //_____________________________________________________________________________
272 AliMUONCalibParamNI::UnpackValue(Int_t value, Int_t& a, Int_t& b) const
274 /// Unpack single value into a couple (a,b), using packingFactor
275 /// Returns false if IsPacked()==false
277 if ( !IsPacked() ) return kFALSE;
278 a = value / fPackingFactor;
279 b = value % fPackingFactor;
283 //_____________________________________________________________________________
285 AliMUONCalibParamNI::PackValues(Int_t a, Int_t b, Int_t& packedValue) const
287 /// Pack a couple (a,b) into a single value, using packingFactor
288 /// Returns false if IsPacked()==false
290 if ( !IsPacked() ) return kFALSE;
291 packedValue = a*fPackingFactor + b;
295 //_____________________________________________________________________________
297 AliMUONCalibParamNI::IsPacked() const
299 /// Whether the values we store are packed or not.
300 /// If false, Pack and Unpack methods will always return false and do nothing
301 return (fPackingFactor != 0);