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