]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONCalibParamNF.cxx
remove print
[u/mrichter/AliRoot.git] / MUON / AliMUONCalibParamNF.cxx
CommitLineData
3eec0a69 1/**************************************************************************
2* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3* *
4* Author: The ALICE Off-line Project. *
5* Contributors are mentioned in the code where appropriate. *
6* *
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**************************************************************************/
15
16// $Id$
17
18#include "AliMUONCalibParamNF.h"
19
20#include "AliLog.h"
21
22#include "Riostream.h"
23#include "TMath.h"
24#include "TString.h"
25
3abf324d 26#include <limits.h>
27
3d1463c8 28//-----------------------------------------------------------------------------
3eec0a69 29/// \class AliMUONCalibParamNF
30///
31/// Handle the case of N floating point parameters per channel.
32///
33/// \author Laurent Aphecetche
3d1463c8 34//-----------------------------------------------------------------------------
3eec0a69 35
36/// \cond CLASSIMP
37ClassImp(AliMUONCalibParamNF)
38/// \endcond
39
40//_____________________________________________________________________________
41AliMUONCalibParamNF::AliMUONCalibParamNF()
42: AliMUONVCalibParam(),
43 fDimension(0),
44 fSize(0),
45 fN(0),
46 fValues(0x0)
47{
48/// Default constructor.
49}
50
51//_____________________________________________________________________________
a1546c3a 52AliMUONCalibParamNF::AliMUONCalibParamNF(Int_t dimension, Int_t theSize,
53 Int_t id0, Int_t id1,
54 Float_t fillWithValue)
55: AliMUONVCalibParam(id0,id1),
3eec0a69 56 fDimension(dimension),
57 fSize(theSize),
58 fN(fSize*fDimension),
59 fValues(0x0)
60{
61/// Normal constructor, where theSize specifies the number of channels handled
62/// by this object, and fillWithValue the default value assigned to each
63/// channel.
64
65 if ( fN > 0 )
66 {
67 fValues = new Float_t[fN];
68 for ( Int_t i = 0; i < fN; ++i )
69 {
70 fValues[i] = fillWithValue;
71 }
72 }
73}
74
75
76//_____________________________________________________________________________
77AliMUONCalibParamNF::AliMUONCalibParamNF(const AliMUONCalibParamNF& other)
78: AliMUONVCalibParam(),
79fDimension(0),
80fSize(0),
81fN(0),
82fValues(0x0)
83{
84/// Copy constructor.
85
86 other.CopyTo(*this);
87}
88
89//_____________________________________________________________________________
90AliMUONCalibParamNF&
91AliMUONCalibParamNF::operator=(const AliMUONCalibParamNF& other)
92{
93/// Assignment operator
94
95 other.CopyTo(*this);
96 return *this;
97}
98
99//_____________________________________________________________________________
100AliMUONCalibParamNF::~AliMUONCalibParamNF()
101{
102/// Destructor
103
104 delete[] fValues;
105}
106
107//_____________________________________________________________________________
108void
109AliMUONCalibParamNF::CopyTo(AliMUONCalibParamNF& destination) const
110{
111/// Copy *this to destination
112
ee22bfe9 113 TObject::Copy(destination);
a1546c3a 114
3eec0a69 115 delete[] destination.fValues;
116 destination.fN = fN;
117 destination.fSize = fSize;
118 destination.fDimension = fDimension;
119
120 if ( fN > 0 )
121 {
122 destination.fValues = new Float_t[fN];
123 for ( Int_t i = 0; i < fN; ++i )
124 {
125 destination.fValues[i] = fValues[i];
126 }
127 }
128}
129
130//_____________________________________________________________________________
131Int_t
132AliMUONCalibParamNF::Index(Int_t i, Int_t j) const
133{
134/// Compute the 1D index of the internal storage from the pair (i,j)
135/// Returns -1 if the (i,j) pair is invalid
136
137 if ( i >= 0 && i < Size() && j >= 0 && j < Dimension() )
138 {
4db2bfee 139 return IndexFast(i,j);
3eec0a69 140 }
141 return -1;
142}
143
4db2bfee 144//_____________________________________________________________________________
145Int_t
146AliMUONCalibParamNF::IndexFast(Int_t i, Int_t j) const
147{
148 /// Compute the 1D index of the internal storage from the pair (i,j)
149
150 return i + Size()*j;
151}
152
3eec0a69 153//_____________________________________________________________________________
154void
155AliMUONCalibParamNF::Print(Option_t* opt) const
156{
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.
161
162 TString sopt(opt);
163 sopt.ToUpper();
a1546c3a 164 cout << Form("AliMUONCalibParamNF Id=(%d,%d) Size=%d Dimension=%d",ID0(),
165 ID1(),Size(),Dimension()) << endl;
3eec0a69 166 if ( sopt.Contains("FULL") )
167 {
168 for ( Int_t i = 0; i < Size(); ++i )
169 {
170 cout << Form("CH %3d",i);
171 for ( Int_t j = 0; j < Dimension(); ++j )
172 {
173 cout << Form(" %e",ValueAsFloat(i,j));
174 }
175 cout << endl;
176 }
177 }
178 if ( sopt.Contains("MEAN") )
179 {
180 Int_t j(0);
181 sscanf(sopt.Data(),"MEAN%d",&j);
182
183 Float_t mean(0);
184 Float_t v2(0);
185
186 Int_t n = Size();
187
188 for ( Int_t i = 0; i < Size(); ++i )
189 {
190 Float_t v = ValueAsFloat(i,j);
191 mean += v;
192 v2 += v*v;
193 }
194 mean /= n;
195 float sigma = 0;
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;
198 }
199
200}
201
202//_____________________________________________________________________________
203void
204AliMUONCalibParamNF::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
205{
206/// Set one value as a float, after checking that the indices are correct.
207
208 Int_t ix = Index(i,j);
209
210 if ( ix < 0 )
211 {
212 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
213 i,j,Size()-1,Dimension()-1));
214 }
215 else
216 {
217 fValues[ix]=value;
218 }
219}
220
4db2bfee 221//_____________________________________________________________________________
222void
223AliMUONCalibParamNF::SetValueAsFloatFast(Int_t i, Int_t j, Float_t value)
224{
225 /// Set one value as a float, w/o checking that the indices are correct.
226
227 fValues[IndexFast(i,j)] = value;
228}
229
3eec0a69 230//_____________________________________________________________________________
231void
232AliMUONCalibParamNF::SetValueAsInt(Int_t i, Int_t j, Int_t value)
233{
234/// Set one value as an int.
235
236 SetValueAsFloat(i,j,static_cast<Float_t>(value));
237}
238
4db2bfee 239//_____________________________________________________________________________
240void
241AliMUONCalibParamNF::SetValueAsIntFast(Int_t i, Int_t j, Int_t value)
242{
243 /// Set one value as an int.
244
245 SetValueAsFloatFast(i,j,static_cast<Float_t>(value));
246}
247
3eec0a69 248//_____________________________________________________________________________
249Float_t
250AliMUONCalibParamNF::ValueAsFloat(Int_t i, Int_t j) const
251{
252/// Return the value as a float (which it is), after checking indices.
253
254 Int_t ix = Index(i,j);
255
256 if ( ix < 0 )
257 {
258 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
259 i,j,Size()-1,Dimension()-1));
260 return 0.0;
261 }
262 else
263 {
264 return fValues[ix];
265 }
266}
267
4db2bfee 268//_____________________________________________________________________________
269Float_t
270AliMUONCalibParamNF::ValueAsFloatFast(Int_t i, Int_t j) const
271{
272 /// Return the value as a float (which it is), after checking indices.
273
274 return fValues[IndexFast(i,j)];
275}
276
3eec0a69 277//_____________________________________________________________________________
278Int_t
279AliMUONCalibParamNF::ValueAsInt(Int_t i, Int_t j) const
280{
281/// Return the value as an int, by rounding the internal float value.
282
283 Float_t v = ValueAsFloat(i,j);
3abf324d 284
285 if ( v >= Float_t(INT_MAX) ) {
286 AliErrorStream()
287 << "Cannot convert value " << v << " to Int_t." << endl;
288 return 0;
289 }
290
3eec0a69 291 return TMath::Nint(v);
292}
4db2bfee 293
294//_____________________________________________________________________________
295Int_t
296AliMUONCalibParamNF::ValueAsIntFast(Int_t i, Int_t j) const
297{
298 /// Return the value as an int, by rounding the internal float value.
299
300 Float_t v = ValueAsFloatFast(i,j);
301 return TMath::Nint(v);
302}