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