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