]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/misc/AliL3TransBit.cxx
Coding violation fixes.
[u/mrichter/AliRoot.git] / HLT / misc / AliL3TransBit.cxx
1 // @(#) $Id$
2
3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4 //*-- Copyright & copy ALICE HLT Group
5
6 #include "AliL3StandardIncludes.h"
7
8 #include "AliL3TransBit.h"
9
10 #if __GNUC__ == 3
11 using namespace std;
12 #endif
13
14 /**************************************************************************
15  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
16  *                                                                        *
17  * Author: The ALICE Off-line Project.                                    *
18  * Contributors are mentioned in the code where appropriate.              *
19  *                                                                        *
20  * Permission to use, copy, modify and distribute this software and its   *
21  * documentation strictly for non-commercial purposes is hereby granted   *
22  * without fee, provided that the above copyright notice appears in all   *
23  * copies and that both the copyright notice and this permission notice   *
24  * appear in the supporting documentation. The authors make no claims     *
25  * about the suitability of this software for any purpose. It is          *
26  * provided "as is" without express or implied warranty.                  *
27  **************************************************************************/
28
29
30 /** \class AliL3Transbit
31 <pre>
32 //_____________________________________________________________
33 // AliL3Transbit (taken from the offline AliROOT code,
34 // original author: Marian Ivanov, GSI Darmstadt for AliROOT)
35 //
36 // Time Projection Chamber ADC bit compresion lookup table
37 //
38 //  Conversion equation:
39 //    For AliTransBitV1
40 //    dy/dx= Int_t(1+x/fX0)
41 //
42 //    For AliTransBitV2
43 //    y  =(2**bit0) ln(1+x/fX0) / ln(1+(2**bit1-1)/fX0)
44 //
45 //    where x0 is calculated in function GetOptimumX0()
46 //
47 //  Example session in aliroot:
48 //    Int_t b0=10;  // original number of bits
49 //    Int_t b1=8;   // compressed
50 //
51 //    AliTransBitV1 trans;
52 //    Int_t x0=TMath::Nint(TMath::Exp(b0*TMath::Log(2)));
53 //    Int_t x1=TMath::Nint(TMath::Exp(b1*TMath::Log(2)));
54 //    trans.SetBits(b0,b1);
55 //    trans.FindOptimumX0();
56 //    trans.Update();
57 //    cout<<trans.Get0to1(x0-2)<<"\n";
58 //    cout<<trans.Get1to0(x1-2)<<"\n";
59 //
60 //    // to produce table
61 //    for( Int_t i=0;i<x1;i++) cout<<i<<"\t"<<trans.Get1to0(i)<<"\n"; > table1to0.txt
62 //    for( Int_t i=0;i<x0;i++) cout<<i<<"\t"<<trans.Get0to1(i)<<"\n"; > table0to1.txt
63 //
64 //    for( Int_t i=0;i<x1-1;i++) cout<<i<<"\t"<<trans.Get1to0(i+1)-trans.Get1to0(i)<<"\n"; > tabled.txt
65 //
66 </pre>
67 */
68
69 ClassImp(AliL3TransBit)
70 ClassImp(AliL3TransBitV1)
71 ClassImp(AliL3TransBitV2)
72
73 AliL3TransBit::AliL3TransBit()
74 {
75   // default constructor
76   fTable0 = 0;
77   fTable1 = 0;
78   fBit0   = 10;
79   fBit1   = 8;
80   fX0     = 0;
81 }
82
83 AliL3TransBit::~AliL3TransBit() 
84 {
85   // destructor
86   if (fTable0!=0) delete [] fTable0;
87   if (fTable1!=0) delete [] fTable1;
88 }
89
90 Double_t AliL3TransBitV1::FindOptimumX0()
91 {
92   //find x0 for which derivation at xder1 is equal 1
93   Int_t x0=(Int_t)rint(exp(fBit0*log(2.)));
94   Int_t x1=(Int_t)rint(exp(fBit1*log(2.)));
95
96   fX0 = ((x1-2)*(x1-2)/2.)/(x0-x1-1);  //starting fX0
97   Int_t digit=0;
98   Int_t j;
99   Double_t weight=1;
100   for(j=0;(j<50)&&(digit!=(x0-1));j++){  
101     Int_t olddigit=digit;
102     digit=0;
103     for (Int_t  i=0; i<x1-1;i++) digit+= Int_t(1+Double_t(i)/fX0);      
104     fX0*= (1.+weight*Double_t(digit)/Double_t(x0-1))/(1.+weight);    
105     if ( ((olddigit-(x0-1)) * (digit-(x0-1))) <0 ) 
106       weight*=0.25;
107     // cout<<j<<"\t"<<fX0<<"\t"<<digit<<"\n";
108   }
109   //  cout<<"End of iteration "<<j<<"\n";
110   //cout<<"digit..."<<digit<<"\n";  
111   return fX0;
112 }
113
114 void AliL3TransBitV1::Update()
115 {
116   //construct lookup tables for loosy compression from 
117   if (fX0<1) fX0 = FindOptimumX0();  
118   Int_t x0=(Int_t)rint(exp(fBit0*log(2.)));
119   Int_t x1=(Int_t)rint(exp(fBit1*log(2.)));
120   
121   //fTable0 - conversion from bit0 coding to bit1 coding
122   if (fTable0!=0) delete fTable0;
123   fTable0= new Int_t[x0];
124   //fTable1 - conversion table from bit1 to bit0 coding
125   if (fTable1!=0) delete [] fTable1;
126   fTable1= new Int_t[x1];
127
128   Int_t digit=0;
129   for (Int_t  i=0; i<x1-1;i++){    
130     Int_t ddig=Int_t(1+Double_t(i)/fX0);
131     for (Int_t j=0;j<ddig;j++) if ((digit+j)<x0) fTable0[digit+j] = i;    
132     fTable1[i]= digit+ddig/2;
133     digit+= ddig;
134   }
135
136   for (Int_t i=digit;i<x0-1;i++) fTable0[i]=x1-2;
137   fTable1[x1-1]=x0-1; //overflow 
138   fTable0[x0-1]=x1-1; //overflow    
139   return;
140 }
141
142 Double_t AliL3TransBitV2::FindOptimumX0()
143 {
144   //find x0 for which derivation at xder1 is equal 1
145   const Float_t kxder1=1;
146   const Float_t kdx=0.1;
147
148   Float_t x0=exp(fBit0*log(2.));
149   Float_t x1=exp(fBit1*log(2.));
150   Float_t deriv = 0;
151   Float_t x;
152   for (x=x1;( (x>1)&&(deriv<1)) ;x-=kdx)
153     {
154       deriv = (x1-1)/( log(1.+x0/x) *x *(1+kxder1/x));
155     }
156   x+=kdx/2.;
157   fX0 = x;
158   return fX0;
159 }
160
161 void AliL3TransBitV2::Update()
162 {
163   //construct lookup tables for loosy compresion from 
164   if (fX0<1) fX0 = FindOptimumX0();  
165   //Float_t x0=(Int_t)rint(exp(fBit0*log(2.)));
166   //Float_t x1=(Int_t)rint(exp(fBit1*log(2.)));
167   Int_t x0=(Int_t)rint(exp(fBit0*log(2.)));
168   Int_t x1=(Int_t)rint(exp(fBit1*log(2.)));
169   
170   //fTable0 - conversion from bit0 coding to bit1 coding
171   if (fTable0!=0) delete fTable0;
172   fTable0= new Int_t[x0];
173
174   //fTable1 - conversion table from bit1 to bit0 coding
175   if (fTable1!=0) delete [] fTable1;
176   fTable1= new Int_t[x1];
177
178   Int_t i;
179
180   for ( i=0; i<x0;i++)
181       fTable0[i] =(Int_t)rint((x1-0.501)*log(1.+Float_t(i)/fX0)/
182                                  log(1.+(x0-1)/fX0));
183
184   Int_t old0=-1;
185   Int_t old1=-1;
186   Int_t new1;
187   for ( i=0; i<x0;i++){
188       new1 = fTable0[i];
189       if (new1!=old1){
190         if (old1>=0) fTable1[old1] =(old0+i)/2;
191         old0 = i;
192         old1 = new1;
193       }
194   }
195   fTable1[old1]=(Int_t)rint((Float_t)(old0+x0)/2);
196   
197   return;
198 }