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 //-----------------------------------------------------------------------------
39 ClassImp(AliMUONCalibParamNF)
42 //_____________________________________________________________________________
43 AliMUONCalibParamNF::AliMUONCalibParamNF()
44 : AliMUONVCalibParam(),
50 /// Default constructor.
53 //_____________________________________________________________________________
54 AliMUONCalibParamNF::AliMUONCalibParamNF(Int_t dimension, Int_t theSize,
56 Float_t fillWithValue)
57 : AliMUONVCalibParam(id0,id1),
58 fDimension(dimension),
63 /// Normal constructor, where theSize specifies the number of channels handled
64 /// by this object, and fillWithValue the default value assigned to each
69 fValues = new Float_t[fN];
70 for ( Int_t i = 0; i < fN; ++i )
72 fValues[i] = fillWithValue;
78 //_____________________________________________________________________________
79 AliMUONCalibParamNF::AliMUONCalibParamNF(const AliMUONCalibParamNF& other)
80 : AliMUONVCalibParam(),
91 //_____________________________________________________________________________
93 AliMUONCalibParamNF::operator=(const AliMUONCalibParamNF& other)
95 /// Assignment operator
101 //_____________________________________________________________________________
102 AliMUONCalibParamNF::~AliMUONCalibParamNF()
109 //_____________________________________________________________________________
111 AliMUONCalibParamNF::CopyTo(AliMUONCalibParamNF& destination) const
113 /// Copy *this to destination
115 TObject::Copy(destination);
117 delete[] destination.fValues;
119 destination.fSize = fSize;
120 destination.fDimension = fDimension;
124 destination.fValues = new Float_t[fN];
125 for ( Int_t i = 0; i < fN; ++i )
127 destination.fValues[i] = fValues[i];
132 //_____________________________________________________________________________
134 AliMUONCalibParamNF::Index(Int_t i, Int_t j) const
136 /// Compute the 1D index of the internal storage from the pair (i,j)
137 /// Returns -1 if the (i,j) pair is invalid
139 if ( i >= 0 && i < Size() && j >= 0 && j < Dimension() )
141 return IndexFast(i,j);
146 //_____________________________________________________________________________
148 AliMUONCalibParamNF::IndexFast(Int_t i, Int_t j) const
150 /// Compute the 1D index of the internal storage from the pair (i,j)
155 //_____________________________________________________________________________
157 AliMUONCalibParamNF::Print(Option_t* opt) const
159 /// Output this object to stdout.
160 /// If opt=="full", then all channels are printed,
161 /// if opt=="mean#", only the mean and sigma value are printed for j-th dimension
162 /// otherwise only the general characteristics are printed.
166 cout << Form("AliMUONCalibParamNF Id=(%d,%d) Size=%d Dimension=%d",ID0(),
167 ID1(),Size(),Dimension()) << endl;
168 if ( sopt.Contains("FULL") )
170 for ( Int_t i = 0; i < Size(); ++i )
172 cout << Form("CH %3d",i);
173 for ( Int_t j = 0; j < Dimension(); ++j )
175 cout << Form(" %e",ValueAsFloat(i,j));
180 if ( sopt.Contains("MEAN") )
183 sscanf(sopt.Data(),"MEAN%d",&j);
190 for ( Int_t i = 0; i < Size(); ++i )
192 Float_t v = ValueAsFloat(i,j);
198 if ( n > 1 ) sigma = TMath::Sqrt( (v2-n*mean*mean)/(n-1) );
199 cout << Form(" Mean(j=%d)=%e Sigma(j=%d)=%e",j,mean,j,sigma) << endl;
204 //_____________________________________________________________________________
206 AliMUONCalibParamNF::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
208 /// Set one value as a float, after checking that the indices are correct.
210 Int_t ix = Index(i,j);
214 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
215 i,j,Size()-1,Dimension()-1));
223 //_____________________________________________________________________________
225 AliMUONCalibParamNF::SetValueAsFloatFast(Int_t i, Int_t j, Float_t value)
227 /// Set one value as a float, w/o checking that the indices are correct.
229 fValues[IndexFast(i,j)] = value;
232 //_____________________________________________________________________________
234 AliMUONCalibParamNF::SetValueAsInt(Int_t i, Int_t j, Int_t value)
236 /// Set one value as an int.
238 SetValueAsFloat(i,j,static_cast<Float_t>(value));
241 //_____________________________________________________________________________
243 AliMUONCalibParamNF::SetValueAsIntFast(Int_t i, Int_t j, Int_t value)
245 /// Set one value as an int.
247 SetValueAsFloatFast(i,j,static_cast<Float_t>(value));
250 //_____________________________________________________________________________
252 AliMUONCalibParamNF::ValueAsFloat(Int_t i, Int_t j) const
254 /// Return the value as a float (which it is), after checking indices.
256 Int_t ix = Index(i,j);
260 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
261 i,j,Size()-1,Dimension()-1));
270 //_____________________________________________________________________________
272 AliMUONCalibParamNF::ValueAsFloatFast(Int_t i, Int_t j) const
274 /// Return the value as a float (which it is), after checking indices.
276 return fValues[IndexFast(i,j)];
279 //_____________________________________________________________________________
281 AliMUONCalibParamNF::ValueAsInt(Int_t i, Int_t j) const
283 /// Return the value as an int, by rounding the internal float value.
285 Float_t v = ValueAsFloat(i,j);
287 if ( v >= Float_t(INT_MAX) ) {
289 << "Cannot convert value " << v << " to Int_t." << endl;
293 return TMath::Nint(v);
296 //_____________________________________________________________________________
298 AliMUONCalibParamNF::ValueAsIntFast(Int_t i, Int_t j) const
300 /// Return the value as an int, by rounding the internal float value.
302 Float_t v = ValueAsFloatFast(i,j);
303 return TMath::Nint(v);