Update from Alberica. Addition of VZERO equalized signals and ZNC.
[u/mrichter/AliRoot.git] / MUON / AliMUONCalibParamND.cxx
CommitLineData
da18abd2 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 "AliMUONCalibParamND.h"
19
20#include "AliLog.h"
21
22#include "Riostream.h"
23#include "TMath.h"
24#include "TString.h"
25
3d1463c8 26//-----------------------------------------------------------------------------
da18abd2 27/// \class AliMUONCalibParamND
28///
29/// Handle the case of N floating point (double precision) parameters per channel.
30///
31/// \author Laurent Aphecetche
3d1463c8 32//-----------------------------------------------------------------------------
da18abd2 33
b80faac0 34using std::cout;
35using std::endl;
da18abd2 36/// \cond CLASSIMP
37ClassImp(AliMUONCalibParamND)
38/// \endcond
39
40//_____________________________________________________________________________
41AliMUONCalibParamND::AliMUONCalibParamND()
42: AliMUONVCalibParam(),
43 fDimension(0),
44 fSize(0),
45 fN(0),
46 fValues(0x0)
47{
48/// Default constructor.
49}
50
51//_____________________________________________________________________________
52AliMUONCalibParamND::AliMUONCalibParamND(Int_t dimension, Int_t theSize,
53 Int_t id0, Int_t id1,
54 Double_t fillWithValue)
55: AliMUONVCalibParam(id0,id1),
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 Double_t[fN];
68 for ( Int_t i = 0; i < fN; ++i )
69 {
70 fValues[i] = fillWithValue;
71 }
72 }
73}
74
75
76//_____________________________________________________________________________
77AliMUONCalibParamND::AliMUONCalibParamND(const AliMUONCalibParamND& other)
78: AliMUONVCalibParam(),
79fDimension(0),
80fSize(0),
81fN(0),
82fValues(0x0)
83{
84/// Copy constructor.
85
86 other.CopyTo(*this);
87}
88
89//_____________________________________________________________________________
90AliMUONCalibParamND&
91AliMUONCalibParamND::operator=(const AliMUONCalibParamND& other)
92{
93/// Assignment operator
94
95 other.CopyTo(*this);
96 return *this;
97}
98
99//_____________________________________________________________________________
100AliMUONCalibParamND::~AliMUONCalibParamND()
101{
102/// Destructor
103
104 delete[] fValues;
105}
106
107//_____________________________________________________________________________
108void
109AliMUONCalibParamND::CopyTo(AliMUONCalibParamND& destination) const
110{
111/// Copy *this to destination
112
4db2bfee 113 TObject::Copy(destination);
114
da18abd2 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 Double_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
132AliMUONCalibParamND::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);
da18abd2 140 }
141 return -1;
142}
143
144//_____________________________________________________________________________
4db2bfee 145Int_t
146AliMUONCalibParamND::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
153//_____________________________________________________________________________
da18abd2 154void
155AliMUONCalibParamND::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();
164 cout << Form("AliMUONCalibParamND Id=(%d,%d) Size=%d Dimension=%d",ID0(),
165 ID1(),Size(),Dimension()) << endl;
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(" %g",ValueAsDouble(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 Double_t mean(0);
184 Double_t v2(0);
185
186 Int_t n = Size();
187
188 for ( Int_t i = 0; i < Size(); ++i )
189 {
190 Float_t v = ValueAsDouble(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)=%g Sigma(j=%d)=%g",j,mean,j,sigma) << endl;
198 }
199
200}
201
202//_____________________________________________________________________________
203void
204AliMUONCalibParamND::SetValueAsDouble(Int_t i, Int_t j, Double_t value)
205{
206 /// Set one value as a double, 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
223AliMUONCalibParamND::SetValueAsDoubleFast(Int_t i, Int_t j, Double_t value)
224{
225 /// Set one value as a double, w/o checking that the indices are correct.
226
227 fValues[IndexFast(i,j)] = value;
228}
da18abd2 229
230//_____________________________________________________________________________
231void
232AliMUONCalibParamND::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
233{
234 /// Set one value as a float, after checking that the indices are correct.
235 SetValueAsDouble(i,j,static_cast<Double_t>(value));
236}
237
238//_____________________________________________________________________________
239void
4db2bfee 240AliMUONCalibParamND::SetValueAsFloatFast(Int_t i, Int_t j, Float_t value)
241{
242 /// Set one value as a float, after checking that the indices are correct.
243 SetValueAsDoubleFast(i,j,static_cast<Double_t>(value));
244}
245
246//_____________________________________________________________________________
247void
da18abd2 248AliMUONCalibParamND::SetValueAsInt(Int_t i, Int_t j, Int_t value)
249{
250/// Set one value as an int.
251
252 SetValueAsFloat(i,j,static_cast<Float_t>(value));
253}
254
255//_____________________________________________________________________________
4db2bfee 256void
257AliMUONCalibParamND::SetValueAsIntFast(Int_t i, Int_t j, Int_t value)
258{
259 /// Set one value as an int.
260
261 SetValueAsFloatFast(i,j,static_cast<Float_t>(value));
262}
263
264//_____________________________________________________________________________
da18abd2 265Double_t
266AliMUONCalibParamND::ValueAsDouble(Int_t i, Int_t j) const
267{
268 /// Return the value as a double (which it is), after checking indices.
269
270 Int_t ix = Index(i,j);
271
272 if ( ix < 0 )
273 {
274 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
275 i,j,Size()-1,Dimension()-1));
276 return 0.0;
277 }
278 else
279 {
280 return fValues[ix];
281 }
282}
283
284//_____________________________________________________________________________
4db2bfee 285Double_t
286AliMUONCalibParamND::ValueAsDoubleFast(Int_t i, Int_t j) const
287{
288 /// Return the value as a double (which it is), w/o checking indices.
289
290 return fValues[IndexFast(i,j)];
291}
292
293//_____________________________________________________________________________
da18abd2 294Float_t
295AliMUONCalibParamND::ValueAsFloat(Int_t i, Int_t j) const
296{
297/// Return the value as a float
298 return static_cast<Float_t>(ValueAsDouble(i,j));
299}
300
301//_____________________________________________________________________________
4db2bfee 302Float_t
303AliMUONCalibParamND::ValueAsFloatFast(Int_t i, Int_t j) const
304{
305 /// Return the value as a float
306 return static_cast<Float_t>(ValueAsDoubleFast(i,j));
307}
308
309//_____________________________________________________________________________
da18abd2 310Int_t
311AliMUONCalibParamND::ValueAsInt(Int_t i, Int_t j) const
312{
313/// Return the value as an int, by rounding the internal float value.
314
315 Float_t v = ValueAsFloat(i,j);
316 return TMath::Nint(v);
317}
4db2bfee 318
319//_____________________________________________________________________________
320Int_t
321AliMUONCalibParamND::ValueAsIntFast(Int_t i, Int_t j) const
322{
323 /// Return the value as an int, by rounding the internal float value.
324
325 Float_t v = ValueAsFloatFast(i,j);
326 return TMath::Nint(v);
327}