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