]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONCalibParamNI.cxx
Generation of generic AOD by the test script of MUON
[u/mrichter/AliRoot.git] / MUON / AliMUONCalibParamNI.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 "AliMUONCalibParamNI.h"
19
20 #include "AliLog.h"
21
22 #include "Riostream.h"
23 #include "TMath.h"
24 #include "TString.h"
25
26 //-----------------------------------------------------------------------------
27 /// \class AliMUONCalibParamNI
28 ///
29 /// Handle the case of N integer parameters per channel.
30 ///
31 /// Almost the same class as AliMUONCalibParamNF, but for ints.
32 /// We could have played with NF to store both int and float (using casts),
33 /// but for the sake of simplicity (e.g. the Print method must know whether
34 /// it should print floats or ints), we decided to "duplicate" the class
35 /// and use the correct type.
36 ///
37 /// \author Laurent Aphecetche
38 //-----------------------------------------------------------------------------
39
40 /// \cond CLASSIMP
41 ClassImp(AliMUONCalibParamNI)
42 /// \endcond
43
44 //_____________________________________________________________________________
45 AliMUONCalibParamNI::AliMUONCalibParamNI() 
46 : AliMUONVCalibParam(),
47   fDimension(0),
48   fSize(0),
49   fN(0),
50   fPackingFactor(0),
51   fValues(0x0)
52 {
53 /// Default constructor.
54     AliDebug(1,Form("this=%p default ctor",this));
55 }
56
57 //_____________________________________________________________________________
58 AliMUONCalibParamNI::AliMUONCalibParamNI(Int_t dimension, Int_t theSize,
59                                          Int_t id0, Int_t id1,
60                                          Int_t fillWithValue, Int_t packingFactor) 
61 : AliMUONVCalibParam(id0,id1),
62   fDimension(dimension),
63   fSize(theSize),
64   fN(fSize*fDimension),
65   fPackingFactor(packingFactor),
66   fValues(0x0)
67 {
68 /// Normal constructor, where theSize specifies the number of channels handled
69 /// by this object, and fillWithValue the default value assigned to each
70 /// channel.
71
72     AliDebug(1,Form("this=%p dimension=%d theSize=%d fillWithValue=%d packingFactor=%d",
73                     this,dimension,theSize,fillWithValue,packingFactor));
74
75   if ( fN > 0 )
76   {
77     fValues = new Int_t[fN];
78     for ( Int_t i = 0; i < fN; ++i )
79     {
80       fValues[i] = fillWithValue;
81     }
82   }
83 }
84
85
86 //_____________________________________________________________________________
87 AliMUONCalibParamNI::AliMUONCalibParamNI(const AliMUONCalibParamNI& other) 
88 : AliMUONVCalibParam(),
89 fDimension(0),
90 fSize(0),
91 fN(0),
92 fPackingFactor(0),
93 fValues(0x0)
94 {
95 /// Copy constructor.
96
97   AliDebug(1,Form("this=%p copy ctor",this));
98   other.CopyTo(*this);
99 }
100
101 //_____________________________________________________________________________
102 AliMUONCalibParamNI&
103 AliMUONCalibParamNI::operator=(const AliMUONCalibParamNI& other) 
104 {
105 /// Assignment operator
106
107   other.CopyTo(*this);
108   return *this;
109 }
110
111 //_____________________________________________________________________________
112 AliMUONCalibParamNI::~AliMUONCalibParamNI()
113 {
114 /// Destructor
115
116   AliDebug(1,Form("this=%p",this));
117   delete[] fValues;
118 }
119
120 //_____________________________________________________________________________
121 void
122 AliMUONCalibParamNI::CopyTo(AliMUONCalibParamNI& destination) const
123 {
124 /// Copy *this to destination
125
126   const TObject& o = static_cast<const TObject&>(*this);
127   o.Copy(destination);
128   
129   delete[] destination.fValues;
130   destination.fN = fN;
131   destination.fSize = fSize;
132   destination.fDimension = fDimension;
133   destination.fPackingFactor = fPackingFactor;
134   
135   if ( fN > 0 )
136   {
137     destination.fValues = new Int_t[fN];
138     for ( Int_t i = 0; i < fN; ++i )
139     {
140       destination.fValues[i] = fValues[i];
141     }
142   }
143 }
144
145 //_____________________________________________________________________________
146 Int_t
147 AliMUONCalibParamNI::Index(Int_t i, Int_t j) const
148 {
149 /// Compute the 1D index of the internal storage from the pair (i,j)
150 /// Returns -1 if the (i,j) pair is invalid
151
152   if ( i >= 0 && i < Size() && j >= 0 && j < Dimension() )
153   {
154     return i + Size()*j;
155   }
156   return -1;
157 }
158
159 //_____________________________________________________________________________
160 void
161 AliMUONCalibParamNI::Print(Option_t* opt) const
162 {
163 /// Output this object to stdout.
164 /// If opt=="full" then all channels are printed, 
165 /// if opt=="mean#", only the mean and sigma value are printed for j-th dimension
166 /// otherwise only the general characteristics are printed.
167
168   TString sopt(opt);
169   sopt.ToUpper();
170   cout << "AliMUONCalibParamNI - Size=" << Size()
171     << " Dimension=" << Dimension()
172     << " Id=(" << ID0() << "," << ID1() << ")";
173   
174   if ( IsPacked() ) 
175   {
176     cout << " Packing Factor=" << fPackingFactor;
177   }
178   cout << endl;
179   
180   if ( sopt.Contains("FULL") )
181   {
182     for ( Int_t i = 0; i < Size(); ++i )
183     {
184       cout << Form("CH %3d",i);
185       for ( Int_t j = 0; j < Dimension(); ++j )
186       {
187         Int_t v = ValueAsInt(i,j);
188         if ( IsPacked() )
189         {
190           Int_t m,c;
191           UnpackValue(v,m,c);
192           cout << Form(" (%d,%d) (0x%x,0x%x)",m,c,m,c);
193         }
194         else
195         {
196           cout << Form(" %d (0x%x)",v,v);
197         }
198       }
199       cout << endl;
200     }
201   }  
202   if ( sopt.Contains("MEAN") )
203   {
204     Int_t j(0);
205     sscanf(sopt.Data(),"MEAN%d",&j);
206     
207     Float_t mean(0);
208     Float_t v2(0);
209     
210     Int_t n = Size();
211     
212     for ( Int_t i = 0; i < Size(); ++i )
213     {
214       Float_t v = ValueAsFloat(i,j);
215       mean += v;
216       v2 += v*v;
217     }
218     mean /= n;
219     float sigma = 0;
220     if ( n > 1 ) sigma = TMath::Sqrt( (v2-n*mean*mean)/(n-1) );
221     cout << Form(" Mean(j=%d)=%e Sigma(j=%d)=%e",j,mean,j,sigma) << endl;
222   }
223   
224 }
225
226 //_____________________________________________________________________________
227 void
228 AliMUONCalibParamNI::SetValueAsInt(Int_t i, Int_t j, Int_t value)
229 {
230 /// Set one value as a float, after checking that the indices are correct.
231
232   Int_t ix = Index(i,j);
233   
234   if ( ix < 0 )
235   {
236     AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
237                   i,j,Size()-1,Dimension()-1));
238   }
239   else
240   {
241     fValues[ix]=value;
242   }
243 }
244
245 //_____________________________________________________________________________
246 void
247 AliMUONCalibParamNI::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
248 {
249   /// Set one value as an int.
250
251   AliWarning("Float will be rounded to be stored...");
252   SetValueAsInt(i,j,TMath::Nint(value));
253 }
254
255 //_____________________________________________________________________________
256 Int_t
257 AliMUONCalibParamNI::ValueAsInt(Int_t i, Int_t j) const
258 {
259 /// Return the value as an int (which it is), after checking indices.
260
261   Int_t ix = Index(i,j);
262   
263   if ( ix < 0 )
264   {
265     AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
266                   i,j,Size()-1,Dimension()-1));
267     return 0;
268   }
269   else
270   {
271     return fValues[ix];
272   }
273 }
274
275 //_____________________________________________________________________________
276 Float_t
277 AliMUONCalibParamNI::ValueAsFloat(Int_t i, Int_t j) const
278 {
279   /// Return the value as a float
280   return static_cast<Float_t>(ValueAsInt(i,j));
281 }
282
283 //_____________________________________________________________________________
284 Bool_t 
285 AliMUONCalibParamNI::UnpackValue(Int_t value, Int_t& a, Int_t& b) const
286 {
287   /// Unpack single value into a couple (a,b), using packingFactor
288   /// Returns false if IsPacked()==false
289   
290   if ( !IsPacked() ) return kFALSE;
291   a = value / fPackingFactor;
292   b = value % fPackingFactor;
293   return kTRUE;
294 }
295
296 //_____________________________________________________________________________
297 Bool_t 
298 AliMUONCalibParamNI::PackValues(Int_t a, Int_t b, Int_t& packedValue) const
299 {
300   /// Pack a couple (a,b) into a single value, using packingFactor
301   /// Returns false if IsPacked()==false
302
303   if ( !IsPacked() ) return kFALSE;
304   packedValue = a*fPackingFactor + b;
305   return kTRUE;
306 }
307
308 //_____________________________________________________________________________
309 Bool_t 
310 AliMUONCalibParamNI::IsPacked() const
311 {
312   /// Whether the values we store are packed or not.
313   /// If false, Pack and Unpack methods will always return false and do nothing
314   return (fPackingFactor != 0);
315 }
316