]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONCalibParamNF.cxx
Update task for ITS tracking check and new macro for plots
[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
a1546c3a 113 const TObject& o = static_cast<const TObject&>(*this);
114 o.Copy(destination);
115
3eec0a69 116 delete[] destination.fValues;
117 destination.fN = fN;
118 destination.fSize = fSize;
119 destination.fDimension = fDimension;
120
121 if ( fN > 0 )
122 {
123 destination.fValues = new Float_t[fN];
124 for ( Int_t i = 0; i < fN; ++i )
125 {
126 destination.fValues[i] = fValues[i];
127 }
128 }
129}
130
131//_____________________________________________________________________________
132Int_t
133AliMUONCalibParamNF::Index(Int_t i, Int_t j) const
134{
135/// Compute the 1D index of the internal storage from the pair (i,j)
136/// Returns -1 if the (i,j) pair is invalid
137
138 if ( i >= 0 && i < Size() && j >= 0 && j < Dimension() )
139 {
4db2bfee 140 return IndexFast(i,j);
3eec0a69 141 }
142 return -1;
143}
144
4db2bfee 145//_____________________________________________________________________________
146Int_t
147AliMUONCalibParamNF::IndexFast(Int_t i, Int_t j) const
148{
149 /// Compute the 1D index of the internal storage from the pair (i,j)
150
151 return i + Size()*j;
152}
153
3eec0a69 154//_____________________________________________________________________________
155void
156AliMUONCalibParamNF::Print(Option_t* opt) const
157{
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.
162
163 TString sopt(opt);
164 sopt.ToUpper();
a1546c3a 165 cout << Form("AliMUONCalibParamNF Id=(%d,%d) Size=%d Dimension=%d",ID0(),
166 ID1(),Size(),Dimension()) << endl;
3eec0a69 167 if ( sopt.Contains("FULL") )
168 {
169 for ( Int_t i = 0; i < Size(); ++i )
170 {
171 cout << Form("CH %3d",i);
172 for ( Int_t j = 0; j < Dimension(); ++j )
173 {
174 cout << Form(" %e",ValueAsFloat(i,j));
175 }
176 cout << endl;
177 }
178 }
179 if ( sopt.Contains("MEAN") )
180 {
181 Int_t j(0);
182 sscanf(sopt.Data(),"MEAN%d",&j);
183
184 Float_t mean(0);
185 Float_t v2(0);
186
187 Int_t n = Size();
188
189 for ( Int_t i = 0; i < Size(); ++i )
190 {
191 Float_t v = ValueAsFloat(i,j);
192 mean += v;
193 v2 += v*v;
194 }
195 mean /= n;
196 float sigma = 0;
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;
199 }
200
201}
202
203//_____________________________________________________________________________
204void
205AliMUONCalibParamNF::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
206{
207/// Set one value as a float, after checking that the indices are correct.
208
209 Int_t ix = Index(i,j);
210
211 if ( ix < 0 )
212 {
213 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
214 i,j,Size()-1,Dimension()-1));
215 }
216 else
217 {
218 fValues[ix]=value;
219 }
220}
221
4db2bfee 222//_____________________________________________________________________________
223void
224AliMUONCalibParamNF::SetValueAsFloatFast(Int_t i, Int_t j, Float_t value)
225{
226 /// Set one value as a float, w/o checking that the indices are correct.
227
228 fValues[IndexFast(i,j)] = value;
229}
230
3eec0a69 231//_____________________________________________________________________________
232void
233AliMUONCalibParamNF::SetValueAsInt(Int_t i, Int_t j, Int_t value)
234{
235/// Set one value as an int.
236
237 SetValueAsFloat(i,j,static_cast<Float_t>(value));
238}
239
4db2bfee 240//_____________________________________________________________________________
241void
242AliMUONCalibParamNF::SetValueAsIntFast(Int_t i, Int_t j, Int_t value)
243{
244 /// Set one value as an int.
245
246 SetValueAsFloatFast(i,j,static_cast<Float_t>(value));
247}
248
3eec0a69 249//_____________________________________________________________________________
250Float_t
251AliMUONCalibParamNF::ValueAsFloat(Int_t i, Int_t j) const
252{
253/// Return the value as a float (which it is), after checking indices.
254
255 Int_t ix = Index(i,j);
256
257 if ( ix < 0 )
258 {
259 AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
260 i,j,Size()-1,Dimension()-1));
261 return 0.0;
262 }
263 else
264 {
265 return fValues[ix];
266 }
267}
268
4db2bfee 269//_____________________________________________________________________________
270Float_t
271AliMUONCalibParamNF::ValueAsFloatFast(Int_t i, Int_t j) const
272{
273 /// Return the value as a float (which it is), after checking indices.
274
275 return fValues[IndexFast(i,j)];
276}
277
3eec0a69 278//_____________________________________________________________________________
279Int_t
280AliMUONCalibParamNF::ValueAsInt(Int_t i, Int_t j) const
281{
282/// Return the value as an int, by rounding the internal float value.
283
284 Float_t v = ValueAsFloat(i,j);
3abf324d 285
286 if ( v >= Float_t(INT_MAX) ) {
287 AliErrorStream()
288 << "Cannot convert value " << v << " to Int_t." << endl;
289 return 0;
290 }
291
3eec0a69 292 return TMath::Nint(v);
293}
4db2bfee 294
295//_____________________________________________________________________________
296Int_t
297AliMUONCalibParamNF::ValueAsIntFast(Int_t i, Int_t j) const
298{
299 /// Return the value as an int, by rounding the internal float value.
300
301 Float_t v = ValueAsFloatFast(i,j);
302 return TMath::Nint(v);
303}