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