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 "AliMUONCalibParamND.h"
22 #include "Riostream.h"
26 //-----------------------------------------------------------------------------
27 /// \class AliMUONCalibParamND
29 /// Handle the case of N floating point (double precision) parameters per channel.
31 /// \author Laurent Aphecetche
32 //-----------------------------------------------------------------------------
37 ClassImp(AliMUONCalibParamND)
40 //_____________________________________________________________________________
41 AliMUONCalibParamND::AliMUONCalibParamND()
42 : AliMUONVCalibParam(),
48 /// Default constructor.
51 //_____________________________________________________________________________
52 AliMUONCalibParamND::AliMUONCalibParamND(Int_t dimension, Int_t theSize,
54 Double_t fillWithValue)
55 : AliMUONVCalibParam(id0,id1),
56 fDimension(dimension),
61 /// Normal constructor, where theSize specifies the number of channels handled
62 /// by this object, and fillWithValue the default value assigned to each
67 fValues = new Double_t[fN];
68 for ( Int_t i = 0; i < fN; ++i )
70 fValues[i] = fillWithValue;
76 //_____________________________________________________________________________
77 AliMUONCalibParamND::AliMUONCalibParamND(const AliMUONCalibParamND& other)
78 : AliMUONVCalibParam(),
89 //_____________________________________________________________________________
91 AliMUONCalibParamND::operator=(const AliMUONCalibParamND& other)
93 /// Assignment operator
99 //_____________________________________________________________________________
100 AliMUONCalibParamND::~AliMUONCalibParamND()
107 //_____________________________________________________________________________
109 AliMUONCalibParamND::CopyTo(AliMUONCalibParamND& destination) const
111 /// Copy *this to destination
113 TObject::Copy(destination);
115 delete[] destination.fValues;
117 destination.fSize = fSize;
118 destination.fDimension = fDimension;
122 destination.fValues = new Double_t[fN];
123 for ( Int_t i = 0; i < fN; ++i )
125 destination.fValues[i] = fValues[i];
130 //_____________________________________________________________________________
132 AliMUONCalibParamND::Index(Int_t i, Int_t j) const
134 /// Compute the 1D index of the internal storage from the pair (i,j)
135 /// Returns -1 if the (i,j) pair is invalid
137 if ( i >= 0 && i < Size() && j >= 0 && j < Dimension() )
139 return IndexFast(i,j);
144 //_____________________________________________________________________________
146 AliMUONCalibParamND::IndexFast(Int_t i, Int_t j) const
148 /// Compute the 1D index of the internal storage from the pair (i,j)
153 //_____________________________________________________________________________
155 AliMUONCalibParamND::Print(Option_t* opt) const
157 /// Output this object to stdout.
158 /// If opt=="full", then all channels are printed,
159 /// if opt=="mean#", only the mean and sigma value are printed for j-th dimension
160 /// otherwise only the general characteristics are printed.
164 cout << Form("AliMUONCalibParamND Id=(%d,%d) Size=%d Dimension=%d",ID0(),
165 ID1(),Size(),Dimension()) << endl;
166 if ( sopt.Contains("FULL") )
168 for ( Int_t i = 0; i < Size(); ++i )
170 cout << Form("CH %3d",i);
171 for ( Int_t j = 0; j < Dimension(); ++j )
173 cout << Form(" %g",ValueAsDouble(i,j));
178 if ( sopt.Contains("MEAN") )
181 sscanf(sopt.Data(),"MEAN%d",&j);
188 for ( Int_t i = 0; i < Size(); ++i )
190 Float_t v = ValueAsDouble(i,j);
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;
202 //_____________________________________________________________________________
204 AliMUONCalibParamND::SetValueAsDouble(Int_t i, Int_t j, Double_t value)
206 /// Set one value as a double, after checking that the indices are correct.
208 Int_t ix = Index(i,j);
212 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
213 i,j,Size()-1,Dimension()-1));
221 //_____________________________________________________________________________
223 AliMUONCalibParamND::SetValueAsDoubleFast(Int_t i, Int_t j, Double_t value)
225 /// Set one value as a double, w/o checking that the indices are correct.
227 fValues[IndexFast(i,j)] = value;
230 //_____________________________________________________________________________
232 AliMUONCalibParamND::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
234 /// Set one value as a float, after checking that the indices are correct.
235 SetValueAsDouble(i,j,static_cast<Double_t>(value));
238 //_____________________________________________________________________________
240 AliMUONCalibParamND::SetValueAsFloatFast(Int_t i, Int_t j, Float_t value)
242 /// Set one value as a float, after checking that the indices are correct.
243 SetValueAsDoubleFast(i,j,static_cast<Double_t>(value));
246 //_____________________________________________________________________________
248 AliMUONCalibParamND::SetValueAsInt(Int_t i, Int_t j, Int_t value)
250 /// Set one value as an int.
252 SetValueAsFloat(i,j,static_cast<Float_t>(value));
255 //_____________________________________________________________________________
257 AliMUONCalibParamND::SetValueAsIntFast(Int_t i, Int_t j, Int_t value)
259 /// Set one value as an int.
261 SetValueAsFloatFast(i,j,static_cast<Float_t>(value));
264 //_____________________________________________________________________________
266 AliMUONCalibParamND::ValueAsDouble(Int_t i, Int_t j) const
268 /// Return the value as a double (which it is), after checking indices.
270 Int_t ix = Index(i,j);
274 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
275 i,j,Size()-1,Dimension()-1));
284 //_____________________________________________________________________________
286 AliMUONCalibParamND::ValueAsDoubleFast(Int_t i, Int_t j) const
288 /// Return the value as a double (which it is), w/o checking indices.
290 return fValues[IndexFast(i,j)];
293 //_____________________________________________________________________________
295 AliMUONCalibParamND::ValueAsFloat(Int_t i, Int_t j) const
297 /// Return the value as a float
298 return static_cast<Float_t>(ValueAsDouble(i,j));
301 //_____________________________________________________________________________
303 AliMUONCalibParamND::ValueAsFloatFast(Int_t i, Int_t j) const
305 /// Return the value as a float
306 return static_cast<Float_t>(ValueAsDoubleFast(i,j));
309 //_____________________________________________________________________________
311 AliMUONCalibParamND::ValueAsInt(Int_t i, Int_t j) const
313 /// Return the value as an int, by rounding the internal float value.
315 Float_t v = ValueAsFloat(i,j);
316 return TMath::Nint(v);
319 //_____________________________________________________________________________
321 AliMUONCalibParamND::ValueAsIntFast(Int_t i, Int_t j) const
323 /// Return the value as an int, by rounding the internal float value.
325 Float_t v = ValueAsFloatFast(i,j);
326 return TMath::Nint(v);