]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONCalibParamND.cxx
Fixing error in documentation/comments.
[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
34/// \cond CLASSIMP
35ClassImp(AliMUONCalibParamND)
36/// \endcond
37
38//_____________________________________________________________________________
39AliMUONCalibParamND::AliMUONCalibParamND()
40: AliMUONVCalibParam(),
41 fDimension(0),
42 fSize(0),
43 fN(0),
44 fValues(0x0)
45{
46/// Default constructor.
47}
48
49//_____________________________________________________________________________
50AliMUONCalibParamND::AliMUONCalibParamND(Int_t dimension, Int_t theSize,
51 Int_t id0, Int_t id1,
52 Double_t fillWithValue)
53: AliMUONVCalibParam(id0,id1),
54 fDimension(dimension),
55 fSize(theSize),
56 fN(fSize*fDimension),
57 fValues(0x0)
58{
59/// Normal constructor, where theSize specifies the number of channels handled
60/// by this object, and fillWithValue the default value assigned to each
61/// channel.
62
63 if ( fN > 0 )
64 {
65 fValues = new Double_t[fN];
66 for ( Int_t i = 0; i < fN; ++i )
67 {
68 fValues[i] = fillWithValue;
69 }
70 }
71}
72
73
74//_____________________________________________________________________________
75AliMUONCalibParamND::AliMUONCalibParamND(const AliMUONCalibParamND& other)
76: AliMUONVCalibParam(),
77fDimension(0),
78fSize(0),
79fN(0),
80fValues(0x0)
81{
82/// Copy constructor.
83
84 other.CopyTo(*this);
85}
86
87//_____________________________________________________________________________
88AliMUONCalibParamND&
89AliMUONCalibParamND::operator=(const AliMUONCalibParamND& other)
90{
91/// Assignment operator
92
93 other.CopyTo(*this);
94 return *this;
95}
96
97//_____________________________________________________________________________
98AliMUONCalibParamND::~AliMUONCalibParamND()
99{
100/// Destructor
101
102 delete[] fValues;
103}
104
105//_____________________________________________________________________________
106void
107AliMUONCalibParamND::CopyTo(AliMUONCalibParamND& destination) const
108{
109/// Copy *this to destination
110
111 delete[] destination.fValues;
112 destination.fN = fN;
113 destination.fSize = fSize;
114 destination.fDimension = fDimension;
115
116 if ( fN > 0 )
117 {
118 destination.fValues = new Double_t[fN];
119 for ( Int_t i = 0; i < fN; ++i )
120 {
121 destination.fValues[i] = fValues[i];
122 }
123 }
124}
125
126//_____________________________________________________________________________
127Int_t
128AliMUONCalibParamND::Index(Int_t i, Int_t j) const
129{
130/// Compute the 1D index of the internal storage from the pair (i,j)
131/// Returns -1 if the (i,j) pair is invalid
132
133 if ( i >= 0 && i < Size() && j >= 0 && j < Dimension() )
134 {
135 return i + Size()*j;
136 }
137 return -1;
138}
139
140//_____________________________________________________________________________
141void
142AliMUONCalibParamND::Print(Option_t* opt) const
143{
144/// Output this object to stdout.
145/// If opt=="full", then all channels are printed,
146/// if opt=="mean#", only the mean and sigma value are printed for j-th dimension
147/// otherwise only the general characteristics are printed.
148
149 TString sopt(opt);
150 sopt.ToUpper();
151 cout << Form("AliMUONCalibParamND Id=(%d,%d) Size=%d Dimension=%d",ID0(),
152 ID1(),Size(),Dimension()) << endl;
153 if ( sopt.Contains("FULL") )
154 {
155 for ( Int_t i = 0; i < Size(); ++i )
156 {
157 cout << Form("CH %3d",i);
158 for ( Int_t j = 0; j < Dimension(); ++j )
159 {
160 cout << Form(" %g",ValueAsDouble(i,j));
161 }
162 cout << endl;
163 }
164 }
165 if ( sopt.Contains("MEAN") )
166 {
167 Int_t j(0);
168 sscanf(sopt.Data(),"MEAN%d",&j);
169
170 Double_t mean(0);
171 Double_t v2(0);
172
173 Int_t n = Size();
174
175 for ( Int_t i = 0; i < Size(); ++i )
176 {
177 Float_t v = ValueAsDouble(i,j);
178 mean += v;
179 v2 += v*v;
180 }
181 mean /= n;
182 float sigma = 0;
183 if ( n > 1 ) sigma = TMath::Sqrt( (v2-n*mean*mean)/(n-1) );
184 cout << Form(" Mean(j=%d)=%g Sigma(j=%d)=%g",j,mean,j,sigma) << endl;
185 }
186
187}
188
189//_____________________________________________________________________________
190void
191AliMUONCalibParamND::SetValueAsDouble(Int_t i, Int_t j, Double_t value)
192{
193 /// Set one value as a double, after checking that the indices are correct.
194
195 Int_t ix = Index(i,j);
196
197 if ( ix < 0 )
198 {
199 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
200 i,j,Size()-1,Dimension()-1));
201 }
202 else
203 {
204 fValues[ix]=value;
205 }
206}
207
208
209//_____________________________________________________________________________
210void
211AliMUONCalibParamND::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
212{
213 /// Set one value as a float, after checking that the indices are correct.
214 SetValueAsDouble(i,j,static_cast<Double_t>(value));
215}
216
217//_____________________________________________________________________________
218void
219AliMUONCalibParamND::SetValueAsInt(Int_t i, Int_t j, Int_t value)
220{
221/// Set one value as an int.
222
223 SetValueAsFloat(i,j,static_cast<Float_t>(value));
224}
225
226//_____________________________________________________________________________
227Double_t
228AliMUONCalibParamND::ValueAsDouble(Int_t i, Int_t j) const
229{
230 /// Return the value as a double (which it is), after checking indices.
231
232 Int_t ix = Index(i,j);
233
234 if ( ix < 0 )
235 {
236 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
237 i,j,Size()-1,Dimension()-1));
238 return 0.0;
239 }
240 else
241 {
242 return fValues[ix];
243 }
244}
245
246//_____________________________________________________________________________
247Float_t
248AliMUONCalibParamND::ValueAsFloat(Int_t i, Int_t j) const
249{
250/// Return the value as a float
251 return static_cast<Float_t>(ValueAsDouble(i,j));
252}
253
254//_____________________________________________________________________________
255Int_t
256AliMUONCalibParamND::ValueAsInt(Int_t i, Int_t j) const
257{
258/// Return the value as an int, by rounding the internal float value.
259
260 Float_t v = ValueAsFloat(i,j);
261 return TMath::Nint(v);
262}