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 "AliMUONCalibParamNF.h"
22 #include "Riostream.h"
28 //-----------------------------------------------------------------------------
29 /// \class AliMUONCalibParamNF
31 /// Handle the case of N floating point parameters per channel.
33 /// \author Laurent Aphecetche
34 //-----------------------------------------------------------------------------
37 ClassImp(AliMUONCalibParamNF)
40 //_____________________________________________________________________________
41 AliMUONCalibParamNF::AliMUONCalibParamNF()
42 : AliMUONVCalibParam(),
48 /// Default constructor.
51 //_____________________________________________________________________________
52 AliMUONCalibParamNF::AliMUONCalibParamNF(Int_t dimension, Int_t theSize,
54 Float_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 Float_t[fN];
68 for ( Int_t i = 0; i < fN; ++i )
70 fValues[i] = fillWithValue;
76 //_____________________________________________________________________________
77 AliMUONCalibParamNF::AliMUONCalibParamNF(const AliMUONCalibParamNF& other)
78 : AliMUONVCalibParam(),
89 //_____________________________________________________________________________
91 AliMUONCalibParamNF::operator=(const AliMUONCalibParamNF& other)
93 /// Assignment operator
99 //_____________________________________________________________________________
100 AliMUONCalibParamNF::~AliMUONCalibParamNF()
107 //_____________________________________________________________________________
109 AliMUONCalibParamNF::CopyTo(AliMUONCalibParamNF& 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 Float_t[fN];
123 for ( Int_t i = 0; i < fN; ++i )
125 destination.fValues[i] = fValues[i];
130 //_____________________________________________________________________________
132 AliMUONCalibParamNF::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 AliMUONCalibParamNF::IndexFast(Int_t i, Int_t j) const
148 /// Compute the 1D index of the internal storage from the pair (i,j)
153 //_____________________________________________________________________________
155 AliMUONCalibParamNF::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("AliMUONCalibParamNF 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(" %e",ValueAsFloat(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 = ValueAsFloat(i,j);
196 if ( n > 1 ) sigma = TMath::Sqrt( (v2-n*mean*mean)/(n-1) );
197 cout << Form(" Mean(j=%d)=%e Sigma(j=%d)=%e",j,mean,j,sigma) << endl;
202 //_____________________________________________________________________________
204 AliMUONCalibParamNF::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
206 /// Set one value as a float, 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 AliMUONCalibParamNF::SetValueAsFloatFast(Int_t i, Int_t j, Float_t value)
225 /// Set one value as a float, w/o checking that the indices are correct.
227 fValues[IndexFast(i,j)] = value;
230 //_____________________________________________________________________________
232 AliMUONCalibParamNF::SetValueAsInt(Int_t i, Int_t j, Int_t value)
234 /// Set one value as an int.
236 SetValueAsFloat(i,j,static_cast<Float_t>(value));
239 //_____________________________________________________________________________
241 AliMUONCalibParamNF::SetValueAsIntFast(Int_t i, Int_t j, Int_t value)
243 /// Set one value as an int.
245 SetValueAsFloatFast(i,j,static_cast<Float_t>(value));
248 //_____________________________________________________________________________
250 AliMUONCalibParamNF::ValueAsFloat(Int_t i, Int_t j) const
252 /// Return the value as a float (which it is), after checking indices.
254 Int_t ix = Index(i,j);
258 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
259 i,j,Size()-1,Dimension()-1));
268 //_____________________________________________________________________________
270 AliMUONCalibParamNF::ValueAsFloatFast(Int_t i, Int_t j) const
272 /// Return the value as a float (which it is), after checking indices.
274 return fValues[IndexFast(i,j)];
277 //_____________________________________________________________________________
279 AliMUONCalibParamNF::ValueAsInt(Int_t i, Int_t j) const
281 /// Return the value as an int, by rounding the internal float value.
283 Float_t v = ValueAsFloat(i,j);
285 if ( v >= Float_t(INT_MAX) ) {
287 << "Cannot convert value " << v << " to Int_t." << endl;
291 return TMath::Nint(v);
294 //_____________________________________________________________________________
296 AliMUONCalibParamNF::ValueAsIntFast(Int_t i, Int_t j) const
298 /// Return the value as an int, by rounding the internal float value.
300 Float_t v = ValueAsFloatFast(i,j);
301 return TMath::Nint(v);