]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONCalibParam2F.cxx
Adding bp/nbp info after manu Id.
[u/mrichter/AliRoot.git] / MUON / AliMUONCalibParam2F.cxx
CommitLineData
9369bbee 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
9d5f6a64 25///
5398f946 26/// \class AliMUONCalibParam2F
27/// \brief Implementation of AliMUONVCalibParam for pair of floats.
9d5f6a64 28///
5398f946 29/// Handle the case of 2 floating point parameters per channel.
9d5f6a64 30/// Conceptually, this class is the equivalent of a vector or float pairs,
31/// but it is implemented using bare Float_t[] array.
32///
5398f946 33/// \author Laurent Aphecetche
9d5f6a64 34
5398f946 35/// \cond CLASSIMP
9369bbee 36ClassImp(AliMUONCalibParam2F)
5398f946 37/// \endcond
9369bbee 38
39//_____________________________________________________________________________
40AliMUONCalibParam2F::AliMUONCalibParam2F()
41: AliMUONVCalibParam(),
42 fSize(0),
43 fN(0),
44 fValues(0x0)
45{
5398f946 46/// Default constructor.
9369bbee 47}
48
49//_____________________________________________________________________________
cab93aff 50AliMUONCalibParam2F::AliMUONCalibParam2F(Int_t theSize, Float_t fillWithValue)
9369bbee 51: AliMUONVCalibParam(),
52 fSize(theSize),
ccea41d4 53 fN(fSize*Dimension()),
54 fValues(0x0)
9369bbee 55{
5398f946 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
9369bbee 60 if ( fN > 0 )
61 {
62 fValues = new Float_t[fN];
cab93aff 63 for ( Int_t i = 0; i < fN; ++i )
64 {
65 fValues[i] = fillWithValue;
66 }
9369bbee 67 }
68}
69
884a73f1 70
9d5f6a64 71//_____________________________________________________________________________
72AliMUONCalibParam2F::AliMUONCalibParam2F(const AliMUONCalibParam2F& other)
73: AliMUONVCalibParam(),
74fSize(0),
75fN(0),
76fValues(0x0)
77{
5398f946 78/// Copy constructor.
79
9d5f6a64 80 other.CopyTo(*this);
81}
82
83//_____________________________________________________________________________
84AliMUONCalibParam2F&
85AliMUONCalibParam2F::operator=(const AliMUONCalibParam2F& other)
86{
5398f946 87/// Assignment operator
88
9d5f6a64 89 other.CopyTo(*this);
90 return *this;
884a73f1 91}
92
9369bbee 93//_____________________________________________________________________________
94AliMUONCalibParam2F::~AliMUONCalibParam2F()
95{
5398f946 96/// Destructor
97
9369bbee 98 delete[] fValues;
99}
100
9d5f6a64 101//_____________________________________________________________________________
102void
103AliMUONCalibParam2F::CopyTo(AliMUONCalibParam2F& destination) const
884a73f1 104{
5398f946 105/// Copy *this to destination
106
9d5f6a64 107 delete[] destination.fValues;
108 destination.fN = fN;
109 destination.fSize = fSize;
884a73f1 110
9d5f6a64 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}
884a73f1 120
9369bbee 121//_____________________________________________________________________________
122Int_t
123AliMUONCalibParam2F::Index(Int_t i, Int_t j) const
124{
5398f946 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
9369bbee 128 if ( i >= 0 && i < Size() && j >= 0 && j < Dimension() )
129 {
130 return i + Size()*j;
131 }
132 return -1;
133}
134
135//_____________________________________________________________________________
136void
137AliMUONCalibParam2F::Print(Option_t* opt) const
138{
5398f946 139/// Output this object to stdout.
156464c8 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.
5398f946 143
9369bbee 144 TString sopt(opt);
145 sopt.ToUpper();
146 cout << "AliMUONCalibParam2F - Size=" << Size()
156464c8 147 << " Dimension=" << Dimension();
9369bbee 148 if ( sopt.Contains("FULL") )
149 {
156464c8 150 cout << endl;
9369bbee 151 for ( Int_t i = 0; i < Size(); ++i )
152 {
156464c8 153 cout << Form("CH %3d %e %e",i,ValueAsFloat(i,0),ValueAsFloat(i,1)) << endl;
9369bbee 154 }
155 }
156464c8 156 if ( sopt.Contains("MEAN") )
157 {
158 Float_t mean(0);
159 Float_t v2(0);
160
4a46082d 161 Int_t n = Size();
156464c8 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 }
4a46082d 169 mean /= n;
156464c8 170 float sigma = 0;
4a46082d 171 if ( n > 1 ) sigma = TMath::Sqrt( (v2-n*mean*mean)/(n-1) );
156464c8 172 cout << Form(" Mean=%f Sigma=%f",mean,sigma) << endl;
173 }
174
9369bbee 175}
176
177//_____________________________________________________________________________
178void
179AliMUONCalibParam2F::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
180{
5398f946 181/// Set one value as a float, after checking that the indices are correct.
182
9369bbee 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//_____________________________________________________________________________
197void
198AliMUONCalibParam2F::SetValueAsInt(Int_t i, Int_t j, Int_t value)
199{
5398f946 200/// Set one value as an int.
201
9369bbee 202 SetValueAsFloat(i,j,static_cast<Float_t>(value));
203}
204
205//_____________________________________________________________________________
206Float_t
207AliMUONCalibParam2F::ValueAsFloat(Int_t i, Int_t j) const
208{
5398f946 209/// Return the value as a float (which it is), after checking indices.
210
9369bbee 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//_____________________________________________________________________________
226Int_t
227AliMUONCalibParam2F::ValueAsInt(Int_t i, Int_t j) const
228{
5398f946 229/// Return the value as an int, by rounding the internal float value.
230
9369bbee 231 Float_t v = ValueAsFloat(i,j);
232 return TMath::Nint(v);
233}