]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONCalibParam1I.cxx
Build TGeo geometry also when running with Geant4
[u/mrichter/AliRoot.git] / MUON / AliMUONCalibParam1I.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 "AliMUONCalibParam1I.h"
19
20 #include "AliLog.h"
21 #include "Riostream.h"
22 #include "TMath.h"
23 #include "TString.h"
24
25 /// \class AliMUONCalibParam1I
26 ///
27 /// This class is implementing the AliMUONVCalibParam interface.
28 /// 
29 /// It stores a given number of integers.
30 /// 
31 /// Those integers can also be retrieved as floats if really needed 
32 /// (this is to comply with the base class).
33 /// 
34 /// You might consider just as it is, namely a C++ wrapper to 
35 /// a plain int[] array.
36 ///
37 /// \author Laurent Aphecetche
38
39 /// \cond CLASSIMP
40 ClassImp(AliMUONCalibParam1I)
41 /// \endcond
42
43 //_____________________________________________________________________________
44 AliMUONCalibParam1I::AliMUONCalibParam1I() 
45 : AliMUONVCalibParam(),
46   fSize(0),
47   fValues(0x0)
48 {
49 /// Default constructor.
50 }
51
52 //_____________________________________________________________________________
53 AliMUONCalibParam1I::AliMUONCalibParam1I(Int_t theSize, Int_t fillWithValue) 
54 : AliMUONVCalibParam(),
55   fSize(theSize),
56   fValues(0x0)
57 {
58 /// Normal constructor, where theSize specifies the number of channels handled
59 /// by this object, and fillWithValue the default value assigned to each
60 /// channel.
61
62   if ( fSize > 0 )
63   {
64     fValues = new Int_t[fSize];
65     for ( Int_t i = 0; i < fSize; ++i )
66     {
67       fValues[i] = fillWithValue;
68     }
69   }
70 }
71
72 //_____________________________________________________________________________
73 AliMUONCalibParam1I::AliMUONCalibParam1I(const AliMUONCalibParam1I& other) 
74 : AliMUONVCalibParam(other),
75 fSize(0),
76 fValues(0x0)
77 {
78 /// Copy constructor
79
80   other.CopyTo(*this);
81 }
82
83 //_____________________________________________________________________________
84 AliMUONCalibParam1I&
85 AliMUONCalibParam1I::operator=(const AliMUONCalibParam1I& other) 
86 {
87 /// Assignment operator
88
89   AliMUONVCalibParam::operator=(other);
90   other.CopyTo(*this);
91   return *this;
92 }
93
94 //_____________________________________________________________________________
95 AliMUONCalibParam1I::~AliMUONCalibParam1I()
96 {
97 /// Destructor.
98
99   delete[] fValues;
100 }
101
102 //_____________________________________________________________________________
103 void
104 AliMUONCalibParam1I::CopyTo(AliMUONCalibParam1I& destination) const
105 {
106 /// Copy this into destination.
107
108   delete[] destination.fValues;
109   destination.fSize = fSize;
110   if ( fSize > 0 )
111   {
112     destination.fValues = new Int_t[fSize];
113     for ( Int_t i = 0; i < fSize; ++i )
114     {
115       destination.fValues[i] = fValues[i];
116     }
117   }
118 }
119
120 //_____________________________________________________________________________
121 void
122 AliMUONCalibParam1I::Print(Option_t* opt) const
123 {
124 /// Output this object to stdout.
125 /// If opt=="full", then all channels are printed, 
126 /// if opt=="mean", only the mean and sigma value are printed,
127 /// otherwise only the general characteristics are printed.
128
129   TString sopt(opt);
130   sopt.ToUpper();
131   cout << "AliMUONCalibParam1I - Size=" << Size()
132     << " Dimension=" << Dimension();
133   
134   if ( sopt.Contains("FULL") )
135   {
136     cout << endl;
137     for ( Int_t i = 0; i < Size(); ++i )
138     {
139       cout << Form("CH %3d %10d",i,ValueAsInt(i)) << endl;
140     }
141   }
142   if ( sopt.Contains("MEAN") )
143   {
144     Int_t mean(0);
145     Int_t v2(0);
146     
147     Int_t n = Size();
148     
149     for ( Int_t i = 0; i < Size(); ++i )
150     {
151       Int_t v = ValueAsInt(i);
152       mean += v;
153       v2 += v*v;
154     }
155     mean /= n;
156     float sigma = 0;
157     if ( n > 1 ) sigma = TMath::Sqrt( (v2-n*mean*mean)/(n-1) );
158     cout << Form(" Mean=%d Sigma=%f",mean,sigma) << endl;
159   }
160 }
161
162 //_____________________________________________________________________________
163 void
164 AliMUONCalibParam1I::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
165 {
166 /// Set the value as a float, which is casted to an int prior to storage.
167
168   SetValueAsInt(i,j,TMath::Nint(value));
169 }
170
171 //_____________________________________________________________________________
172 void
173 AliMUONCalibParam1I::SetValueAsInt(Int_t i, Int_t j, Int_t value)
174 {
175 /// Set the value for a given channel.
176 /// (i,j) are checked for correctness before use.
177
178   if ( j != 0 || i >= fSize || i < 0 )
179   {
180     AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
181                   i,j,Size()-1,Dimension()-1));
182   }
183   else
184   {
185     fValues[i]=value;
186   }
187 }
188
189 //_____________________________________________________________________________
190 Float_t
191 AliMUONCalibParam1I::ValueAsFloat(Int_t i, Int_t j) const
192 {
193 /// Return one value as a float.
194
195   return 1.0*ValueAsInt(i,j);
196 }
197
198 //_____________________________________________________________________________
199 Int_t
200 AliMUONCalibParam1I::ValueAsInt(Int_t i, Int_t j) const
201 {
202 /// Return one value as an integer, after checking that (i,j)
203 /// are valid indices.
204
205   if ( j != 0 || i >= fSize || i < 0 )
206   {
207     AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
208                   i,j,Size()-1,Dimension()-1));
209     return 0;
210   }
211   else
212   {
213     return fValues[i];
214   }
215 }