]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONCalibParamNF.cxx
Adding classes AliMUONVCluster, AliMUONRawClusterV2 (Philippe P., Laurent)
[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 i + Size()*j;
139   }
140   return -1;
141 }
142
143 //_____________________________________________________________________________
144 void
145 AliMUONCalibParamNF::Print(Option_t* opt) const
146 {
147 /// Output this object to stdout.
148 /// If opt=="full", then all channels are printed, 
149 /// if opt=="mean#", only the mean and sigma value are printed for j-th dimension
150 /// otherwise only the general characteristics are printed.
151
152   TString sopt(opt);
153   sopt.ToUpper();
154   cout << Form("AliMUONCalibParamNF Id=(%d,%d) Size=%d Dimension=%d",ID0(),
155                ID1(),Size(),Dimension()) << endl;
156   if ( sopt.Contains("FULL") )
157   {
158     for ( Int_t i = 0; i < Size(); ++i )
159     {
160       cout << Form("CH %3d",i);
161       for ( Int_t j = 0; j < Dimension(); ++j )
162       {
163         cout << Form(" %e",ValueAsFloat(i,j));
164       }
165       cout << endl;
166     }
167   }  
168   if ( sopt.Contains("MEAN") )
169   {
170     Int_t j(0);
171     sscanf(sopt.Data(),"MEAN%d",&j);
172     
173     Float_t mean(0);
174     Float_t v2(0);
175     
176     Int_t n = Size();
177     
178     for ( Int_t i = 0; i < Size(); ++i )
179     {
180       Float_t v = ValueAsFloat(i,j);
181       mean += v;
182       v2 += v*v;
183     }
184     mean /= n;
185     float sigma = 0;
186     if ( n > 1 ) sigma = TMath::Sqrt( (v2-n*mean*mean)/(n-1) );
187     cout << Form(" Mean(j=%d)=%e Sigma(j=%d)=%e",j,mean,j,sigma) << endl;
188   }
189   
190 }
191
192 //_____________________________________________________________________________
193 void
194 AliMUONCalibParamNF::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
195 {
196 /// Set one value as a float, after checking that the indices are correct.
197
198   Int_t ix = Index(i,j);
199   
200   if ( ix < 0 )
201   {
202     AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
203                   i,j,Size()-1,Dimension()-1));
204   }
205   else
206   {
207     fValues[ix]=value;
208   }
209 }
210
211 //_____________________________________________________________________________
212 void
213 AliMUONCalibParamNF::SetValueAsInt(Int_t i, Int_t j, Int_t value)
214 {
215 /// Set one value as an int.
216
217   SetValueAsFloat(i,j,static_cast<Float_t>(value));
218 }
219
220 //_____________________________________________________________________________
221 Float_t
222 AliMUONCalibParamNF::ValueAsFloat(Int_t i, Int_t j) const
223 {
224 /// Return the value as a float (which it is), after checking indices.
225
226   Int_t ix = Index(i,j);
227   
228   if ( ix < 0 )
229   {
230     AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
231                   i,j,Size()-1,Dimension()-1));
232     return 0.0;
233   }
234   else
235   {
236     return fValues[ix];
237   }
238 }
239
240 //_____________________________________________________________________________
241 Int_t
242 AliMUONCalibParamNF::ValueAsInt(Int_t i, Int_t j) const
243 {
244 /// Return the value as an int, by rounding the internal float value.
245
246   Float_t v = ValueAsFloat(i,j);
247   return TMath::Nint(v);
248 }