3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4 //*-- Copyright & copy ALICE HLT Group
6 #include "AliL3StandardIncludes.h"
8 #include "AliL3TransBit.h"
14 /**************************************************************************
15 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
17 * Author: The ALICE Off-line Project. *
18 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
30 /** \class AliL3Transbit
32 //_____________________________________________________________
33 // AliL3Transbit (taken from the offline AliROOT code,
34 // original author: Marian Ivanov, GSI Darmstadt for AliROOT)
36 // Time Projection Chamber ADC bit compresion lookup table
38 // Conversion equation:
40 // dy/dx= Int_t(1+x/fX0)
43 // y =(2**bit0) ln(1+x/fX0) / ln(1+(2**bit1-1)/fX0)
45 // where x0 is calculated in function GetOptimumX0()
47 // Example session in aliroot:
48 // Int_t b0=10; // original number of bits
49 // Int_t b1=8; // compressed
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();
57 // cout<<trans.Get0to1(x0-2)<<"\n";
58 // cout<<trans.Get1to0(x1-2)<<"\n";
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
64 // for( Int_t i=0;i<x1-1;i++) cout<<i<<"\t"<<trans.Get1to0(i+1)-trans.Get1to0(i)<<"\n"; > tabled.txt
69 ClassImp(AliL3TransBit)
70 ClassImp(AliL3TransBitV1)
71 ClassImp(AliL3TransBitV2)
73 AliL3TransBit::AliL3TransBit()
75 // default constructor
83 AliL3TransBit::~AliL3TransBit()
86 if (fTable0!=0) delete [] fTable0;
87 if (fTable1!=0) delete [] fTable1;
90 Double_t AliL3TransBitV1::FindOptimumX0()
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.)));
96 fX0 = ((x1-2)*(x1-2)/2.)/(x0-x1-1); //starting fX0
100 for(j=0;(j<50)&&(digit!=(x0-1));j++){
101 Int_t olddigit=digit;
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 )
107 // cout<<j<<"\t"<<fX0<<"\t"<<digit<<"\n";
109 // cout<<"End of iteration "<<j<<"\n";
110 //cout<<"digit..."<<digit<<"\n";
114 void AliL3TransBitV1::Update()
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.)));
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];
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;
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
142 Double_t AliL3TransBitV2::FindOptimumX0()
144 //find x0 for which derivation at xder1 is equal 1
145 const Float_t kxder1=1;
146 const Float_t kdx=0.1;
148 Float_t x0=exp(fBit0*log(2.));
149 Float_t x1=exp(fBit1*log(2.));
152 for (x=x1;( (x>1)&&(deriv<1)) ;x-=kdx)
154 deriv = (x1-1)/( log(1.+x0/x) *x *(1+kxder1/x));
161 void AliL3TransBitV2::Update()
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.)));
170 //fTable0 - conversion from bit0 coding to bit1 coding
171 if (fTable0!=0) delete fTable0;
172 fTable0= new Int_t[x0];
174 //fTable1 - conversion table from bit1 to bit0 coding
175 if (fTable1!=0) delete [] fTable1;
176 fTable1= new Int_t[x1];
181 fTable0[i] =(Int_t)rint((x1-0.501)*log(1.+Float_t(i)/fX0)/
187 for ( i=0; i<x0;i++){
190 if (old1>=0) fTable1[old1] =(old0+i)/2;
195 fTable1[old1]=(Int_t)rint((Float_t)(old0+x0)/2);