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 //-----------------------------------------------------------------------------
35 ClassImp(AliMUONCalibParamND)
38 //_____________________________________________________________________________
39 AliMUONCalibParamND::AliMUONCalibParamND()
40 : AliMUONVCalibParam(),
46 /// Default constructor.
49 //_____________________________________________________________________________
50 AliMUONCalibParamND::AliMUONCalibParamND(Int_t dimension, Int_t theSize,
52 Double_t fillWithValue)
53 : AliMUONVCalibParam(id0,id1),
54 fDimension(dimension),
59 /// Normal constructor, where theSize specifies the number of channels handled
60 /// by this object, and fillWithValue the default value assigned to each
65 fValues = new Double_t[fN];
66 for ( Int_t i = 0; i < fN; ++i )
68 fValues[i] = fillWithValue;
74 //_____________________________________________________________________________
75 AliMUONCalibParamND::AliMUONCalibParamND(const AliMUONCalibParamND& other)
76 : AliMUONVCalibParam(),
87 //_____________________________________________________________________________
89 AliMUONCalibParamND::operator=(const AliMUONCalibParamND& other)
91 /// Assignment operator
97 //_____________________________________________________________________________
98 AliMUONCalibParamND::~AliMUONCalibParamND()
105 //_____________________________________________________________________________
107 AliMUONCalibParamND::CopyTo(AliMUONCalibParamND& destination) const
109 /// Copy *this to destination
111 TObject::Copy(destination);
113 delete[] destination.fValues;
115 destination.fSize = fSize;
116 destination.fDimension = fDimension;
120 destination.fValues = new Double_t[fN];
121 for ( Int_t i = 0; i < fN; ++i )
123 destination.fValues[i] = fValues[i];
128 //_____________________________________________________________________________
130 AliMUONCalibParamND::Index(Int_t i, Int_t j) const
132 /// Compute the 1D index of the internal storage from the pair (i,j)
133 /// Returns -1 if the (i,j) pair is invalid
135 if ( i >= 0 && i < Size() && j >= 0 && j < Dimension() )
137 return IndexFast(i,j);
142 //_____________________________________________________________________________
144 AliMUONCalibParamND::IndexFast(Int_t i, Int_t j) const
146 /// Compute the 1D index of the internal storage from the pair (i,j)
151 //_____________________________________________________________________________
153 AliMUONCalibParamND::Print(Option_t* opt) const
155 /// Output this object to stdout.
156 /// If opt=="full", then all channels are printed,
157 /// if opt=="mean#", only the mean and sigma value are printed for j-th dimension
158 /// otherwise only the general characteristics are printed.
162 cout << Form("AliMUONCalibParamND Id=(%d,%d) Size=%d Dimension=%d",ID0(),
163 ID1(),Size(),Dimension()) << endl;
164 if ( sopt.Contains("FULL") )
166 for ( Int_t i = 0; i < Size(); ++i )
168 cout << Form("CH %3d",i);
169 for ( Int_t j = 0; j < Dimension(); ++j )
171 cout << Form(" %g",ValueAsDouble(i,j));
176 if ( sopt.Contains("MEAN") )
179 sscanf(sopt.Data(),"MEAN%d",&j);
186 for ( Int_t i = 0; i < Size(); ++i )
188 Float_t v = ValueAsDouble(i,j);
194 if ( n > 1 ) sigma = TMath::Sqrt( (v2-n*mean*mean)/(n-1) );
195 cout << Form(" Mean(j=%d)=%g Sigma(j=%d)=%g",j,mean,j,sigma) << endl;
200 //_____________________________________________________________________________
202 AliMUONCalibParamND::SetValueAsDouble(Int_t i, Int_t j, Double_t value)
204 /// Set one value as a double, after checking that the indices are correct.
206 Int_t ix = Index(i,j);
210 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
211 i,j,Size()-1,Dimension()-1));
219 //_____________________________________________________________________________
221 AliMUONCalibParamND::SetValueAsDoubleFast(Int_t i, Int_t j, Double_t value)
223 /// Set one value as a double, w/o checking that the indices are correct.
225 fValues[IndexFast(i,j)] = value;
228 //_____________________________________________________________________________
230 AliMUONCalibParamND::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
232 /// Set one value as a float, after checking that the indices are correct.
233 SetValueAsDouble(i,j,static_cast<Double_t>(value));
236 //_____________________________________________________________________________
238 AliMUONCalibParamND::SetValueAsFloatFast(Int_t i, Int_t j, Float_t value)
240 /// Set one value as a float, after checking that the indices are correct.
241 SetValueAsDoubleFast(i,j,static_cast<Double_t>(value));
244 //_____________________________________________________________________________
246 AliMUONCalibParamND::SetValueAsInt(Int_t i, Int_t j, Int_t value)
248 /// Set one value as an int.
250 SetValueAsFloat(i,j,static_cast<Float_t>(value));
253 //_____________________________________________________________________________
255 AliMUONCalibParamND::SetValueAsIntFast(Int_t i, Int_t j, Int_t value)
257 /// Set one value as an int.
259 SetValueAsFloatFast(i,j,static_cast<Float_t>(value));
262 //_____________________________________________________________________________
264 AliMUONCalibParamND::ValueAsDouble(Int_t i, Int_t j) const
266 /// Return the value as a double (which it is), after checking indices.
268 Int_t ix = Index(i,j);
272 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
273 i,j,Size()-1,Dimension()-1));
282 //_____________________________________________________________________________
284 AliMUONCalibParamND::ValueAsDoubleFast(Int_t i, Int_t j) const
286 /// Return the value as a double (which it is), w/o checking indices.
288 return fValues[IndexFast(i,j)];
291 //_____________________________________________________________________________
293 AliMUONCalibParamND::ValueAsFloat(Int_t i, Int_t j) const
295 /// Return the value as a float
296 return static_cast<Float_t>(ValueAsDouble(i,j));
299 //_____________________________________________________________________________
301 AliMUONCalibParamND::ValueAsFloatFast(Int_t i, Int_t j) const
303 /// Return the value as a float
304 return static_cast<Float_t>(ValueAsDoubleFast(i,j));
307 //_____________________________________________________________________________
309 AliMUONCalibParamND::ValueAsInt(Int_t i, Int_t j) const
311 /// Return the value as an int, by rounding the internal float value.
313 Float_t v = ValueAsFloat(i,j);
314 return TMath::Nint(v);
317 //_____________________________________________________________________________
319 AliMUONCalibParamND::ValueAsIntFast(Int_t i, Int_t j) const
321 /// Return the value as an int, by rounding the internal float value.
323 Float_t v = ValueAsFloatFast(i,j);
324 return TMath::Nint(v);