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