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 const TObject& o = static_cast<const TObject&>(*this);
116 delete[] destination.fValues;
118 destination.fSize = fSize;
119 destination.fDimension = fDimension;
123 destination.fValues = new Float_t[fN];
124 for ( Int_t i = 0; i < fN; ++i )
126 destination.fValues[i] = fValues[i];
131 //_____________________________________________________________________________
133 AliMUONCalibParamNF::Index(Int_t i, Int_t j) const
135 /// Compute the 1D index of the internal storage from the pair (i,j)
136 /// Returns -1 if the (i,j) pair is invalid
138 if ( i >= 0 && i < Size() && j >= 0 && j < Dimension() )
140 return IndexFast(i,j);
145 //_____________________________________________________________________________
147 AliMUONCalibParamNF::IndexFast(Int_t i, Int_t j) const
149 /// Compute the 1D index of the internal storage from the pair (i,j)
154 //_____________________________________________________________________________
156 AliMUONCalibParamNF::Print(Option_t* opt) const
158 /// Output this object to stdout.
159 /// If opt=="full", then all channels are printed,
160 /// if opt=="mean#", only the mean and sigma value are printed for j-th dimension
161 /// otherwise only the general characteristics are printed.
165 cout << Form("AliMUONCalibParamNF Id=(%d,%d) Size=%d Dimension=%d",ID0(),
166 ID1(),Size(),Dimension()) << endl;
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 cout << Form(" %e",ValueAsFloat(i,j));
179 if ( sopt.Contains("MEAN") )
182 sscanf(sopt.Data(),"MEAN%d",&j);
189 for ( Int_t i = 0; i < Size(); ++i )
191 Float_t v = ValueAsFloat(i,j);
197 if ( n > 1 ) sigma = TMath::Sqrt( (v2-n*mean*mean)/(n-1) );
198 cout << Form(" Mean(j=%d)=%e Sigma(j=%d)=%e",j,mean,j,sigma) << endl;
203 //_____________________________________________________________________________
205 AliMUONCalibParamNF::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
207 /// Set one value as a float, after checking that the indices are correct.
209 Int_t ix = Index(i,j);
213 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
214 i,j,Size()-1,Dimension()-1));
222 //_____________________________________________________________________________
224 AliMUONCalibParamNF::SetValueAsFloatFast(Int_t i, Int_t j, Float_t value)
226 /// Set one value as a float, w/o checking that the indices are correct.
228 fValues[IndexFast(i,j)] = value;
231 //_____________________________________________________________________________
233 AliMUONCalibParamNF::SetValueAsInt(Int_t i, Int_t j, Int_t value)
235 /// Set one value as an int.
237 SetValueAsFloat(i,j,static_cast<Float_t>(value));
240 //_____________________________________________________________________________
242 AliMUONCalibParamNF::SetValueAsIntFast(Int_t i, Int_t j, Int_t value)
244 /// Set one value as an int.
246 SetValueAsFloatFast(i,j,static_cast<Float_t>(value));
249 //_____________________________________________________________________________
251 AliMUONCalibParamNF::ValueAsFloat(Int_t i, Int_t j) const
253 /// Return the value as a float (which it is), after checking indices.
255 Int_t ix = Index(i,j);
259 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
260 i,j,Size()-1,Dimension()-1));
269 //_____________________________________________________________________________
271 AliMUONCalibParamNF::ValueAsFloatFast(Int_t i, Int_t j) const
273 /// Return the value as a float (which it is), after checking indices.
275 return fValues[IndexFast(i,j)];
278 //_____________________________________________________________________________
280 AliMUONCalibParamNF::ValueAsInt(Int_t i, Int_t j) const
282 /// Return the value as an int, by rounding the internal float value.
284 Float_t v = ValueAsFloat(i,j);
286 if ( v >= Float_t(INT_MAX) ) {
288 << "Cannot convert value " << v << " to Int_t." << endl;
292 return TMath::Nint(v);
295 //_____________________________________________________________________________
297 AliMUONCalibParamNF::ValueAsIntFast(Int_t i, Int_t j) const
299 /// Return the value as an int, by rounding the internal float value.
301 Float_t v = ValueAsFloatFast(i,j);
302 return TMath::Nint(v);