]>
Commit | Line | Data |
---|---|---|
9010b535 | 1 | //$Id$ |
1a3c8f6e | 2 | |
9010b535 | 3 | // Original author: Marian Ivanov, GSI Darmstadt for AliROOT |
4 | // migrated to L3 by Anders Vestbo <mailto:vestbo@fi.uib.no> | |
5 | //*-- Copyright & copy ASV | |
1a3c8f6e | 6 | |
24dbb695 | 7 | #include "AliL3StandardIncludes.h" |
1a3c8f6e | 8 | |
9010b535 | 9 | #include "AliL3TransBit.h" |
b328544b | 10 | |
9010b535 | 11 | //_____________________________________________________________ |
12 | // AliL3Transbit (taken from the offline AliROOT code) | |
13 | // | |
14 | // Time Projection Chamber ADC bit compresion lookup table | |
15 | // | |
16 | // Conversion equation: | |
17 | // For AliTransBit_v1 | |
18 | // dy/dx= Int_t(1+x/fX0) | |
19 | // | |
20 | // For AliTransBit_v2 | |
21 | // y =(2**bit0) ln(1+x/fX0) / ln(1+(2**bit1-1)/fX0) | |
22 | // | |
23 | // where x0 is calculated in function GetOptimumX0() | |
24 | // | |
25 | // Example session in aliroot: | |
26 | // Int_t b0=10; // original number of bits | |
27 | // Int_t b1=8; // compressed | |
28 | // | |
29 | // AliTransBit_v1 trans; | |
30 | // Int_t x0=TMath::Nint(TMath::Exp(b0*TMath::Log(2))); | |
31 | // Int_t x1=TMath::Nint(TMath::Exp(b1*TMath::Log(2))); | |
32 | // trans.SetBits(b0,b1); | |
33 | // trans.FindOptimumX0(); | |
34 | // trans.Update(); | |
35 | // cout<<trans.Get0to1(x0-2)<<"\n"; | |
36 | // cout<<trans.Get1to0(x1-2)<<"\n"; | |
37 | // | |
38 | // // to produce table | |
39 | // for( Int_t i=0;i<x1;i++) cout<<i<<"\t"<<trans.Get1to0(i)<<"\n"; > table1to0.txt | |
40 | // for( Int_t i=0;i<x0;i++) cout<<i<<"\t"<<trans.Get0to1(i)<<"\n"; > table0to1.txt | |
41 | // | |
42 | // for( Int_t i=0;i<x1-1;i++) cout<<i<<"\t"<<trans.Get1to0(i+1)-trans.Get1to0(i)<<"\n"; > tabled.txt | |
43 | // | |
1a3c8f6e | 44 | |
9010b535 | 45 | ClassImp(AliL3TransBit) |
46 | ClassImp(AliL3TransBit_v1) | |
47 | ClassImp(AliL3TransBit_v2) | |
1a3c8f6e | 48 | |
9010b535 | 49 | AliL3TransBit::AliL3TransBit() |
1a3c8f6e | 50 | { |
1a3c8f6e | 51 | fTable0 = 0; |
52 | fTable1 = 0; | |
53 | fBit0 = 10; | |
54 | fBit1 = 8; | |
55 | fX0 = 0; | |
56 | } | |
57 | ||
9010b535 | 58 | AliL3TransBit::~AliL3TransBit() |
1a3c8f6e | 59 | { |
1a3c8f6e | 60 | //default destructor |
61 | if (fTable0!=0) delete [] fTable0; | |
62 | if (fTable1!=0) delete [] fTable1; | |
63 | } | |
64 | ||
9010b535 | 65 | Double_t AliL3TransBit_v1::FindOptimumX0() |
1a3c8f6e | 66 | { |
1a3c8f6e | 67 | //find x0 for which derivation at xder1 is equal 1 |
24dbb695 | 68 | Int_t x0=(Int_t)rint(exp(fBit0*log(2.))); |
69 | Int_t x1=(Int_t)rint(exp(fBit1*log(2.))); | |
1a3c8f6e | 70 | |
71 | fX0 = ((x1-2)*(x1-2)/2.)/(x0-x1-1); //starting fX0 | |
72 | Int_t digit=0; | |
73 | Int_t j; | |
74 | Double_t weight=1; | |
75 | for(j=0;(j<50)&&(digit!=(x0-1));j++){ | |
76 | Int_t olddigit=digit; | |
77 | digit=0; | |
78 | for (Int_t i=0; i<x1-1;i++) digit+= Int_t(1+Double_t(i)/fX0); | |
79 | fX0*= (1.+weight*Double_t(digit)/Double_t(x0-1))/(1.+weight); | |
80 | if ( ((olddigit-(x0-1)) * (digit-(x0-1))) <0 ) | |
81 | weight*=0.25; | |
82 | // cout<<j<<"\t"<<fX0<<"\t"<<digit<<"\n"; | |
83 | } | |
84 | // cout<<"End of iteration "<<j<<"\n"; | |
85 | //cout<<"digit..."<<digit<<"\n"; | |
86 | return fX0; | |
87 | } | |
88 | ||
9010b535 | 89 | void AliL3TransBit_v1::Update() |
1a3c8f6e | 90 | { |
9010b535 | 91 | //construct lookup tables for loosy compression from |
1a3c8f6e | 92 | if (fX0<1) fX0 = FindOptimumX0(); |
24dbb695 | 93 | Int_t x0=(Int_t)rint(exp(fBit0*log(2.))); |
94 | Int_t x1=(Int_t)rint(exp(fBit1*log(2.))); | |
1a3c8f6e | 95 | |
96 | //fTable0 - conversion from bit0 coding to bit1 coding | |
97 | if (fTable0!=0) delete fTable0; | |
98 | fTable0= new Int_t[x0]; | |
99 | //fTable1 - conversion table from bit1 to bit0 coding | |
100 | if (fTable1!=0) delete [] fTable1; | |
101 | fTable1= new Int_t[x1]; | |
9010b535 | 102 | |
1a3c8f6e | 103 | Int_t digit=0; |
104 | for (Int_t i=0; i<x1-1;i++){ | |
105 | Int_t ddig=Int_t(1+Double_t(i)/fX0); | |
106 | for (Int_t j=0;j<ddig;j++) if ((digit+j)<x0) fTable0[digit+j] = i; | |
107 | fTable1[i]= digit+ddig/2; | |
108 | digit+= ddig; | |
9010b535 | 109 | } |
110 | ||
1a3c8f6e | 111 | for (Int_t i=digit;i<x0-1;i++) fTable0[i]=x1-2; |
112 | fTable1[x1-1]=x0-1; //overflow | |
113 | fTable0[x0-1]=x1-1; //overflow | |
114 | return; | |
115 | } | |
116 | ||
9010b535 | 117 | Double_t AliL3TransBit_v2::FindOptimumX0() |
1a3c8f6e | 118 | { |
1a3c8f6e | 119 | //find x0 for which derivation at xder1 is equal 1 |
1a3c8f6e | 120 | const Float_t xder1=1; |
121 | const Float_t dx=0.1; | |
122 | ||
24dbb695 | 123 | Float_t x0=exp(fBit0*log(2.)); |
124 | Float_t x1=exp(fBit1*log(2.)); | |
1a3c8f6e | 125 | Float_t deriv = 0; |
126 | Float_t x; | |
127 | for (x=x1;( (x>1)&&(deriv<1)) ;x-=dx) | |
128 | { | |
b328544b | 129 | deriv = (x1-1)/( log(1.+x0/x) *x *(1+xder1/x)); |
1a3c8f6e | 130 | } |
131 | x+=dx/2.; | |
132 | fX0 = x; | |
133 | return fX0; | |
134 | } | |
135 | ||
9010b535 | 136 | void AliL3TransBit_v2::Update() |
1a3c8f6e | 137 | { |
1a3c8f6e | 138 | //construct lookup tables for loosy compresion from |
139 | if (fX0<1) fX0 = FindOptimumX0(); | |
24dbb695 | 140 | //Float_t x0=(Int_t)rint(exp(fBit0*log(2.))); |
141 | //Float_t x1=(Int_t)rint(exp(fBit1*log(2.))); | |
142 | Int_t x0=(Int_t)rint(exp(fBit0*log(2.))); | |
143 | Int_t x1=(Int_t)rint(exp(fBit1*log(2.))); | |
1a3c8f6e | 144 | |
145 | //fTable0 - conversion from bit0 coding to bit1 coding | |
146 | if (fTable0!=0) delete fTable0; | |
147 | fTable0= new Int_t[x0]; | |
148 | ||
149 | //fTable1 - conversion table from bit1 to bit0 coding | |
150 | if (fTable1!=0) delete [] fTable1; | |
151 | fTable1= new Int_t[x1]; | |
152 | ||
1a3c8f6e | 153 | Int_t i; |
154 | ||
155 | for ( i=0; i<x0;i++) | |
b328544b | 156 | fTable0[i] =(Int_t)rint((x1-0.501)*log(1.+Float_t(i)/fX0)/ |
157 | log(1.+(x0-1)/fX0)); | |
1a3c8f6e | 158 | |
159 | Int_t old0=-1; | |
160 | Int_t old1=-1; | |
161 | Int_t new1; | |
162 | for ( i=0; i<x0;i++){ | |
163 | new1 = fTable0[i]; | |
164 | if (new1!=old1){ | |
165 | if (old1>=0) fTable1[old1] =(old0+i)/2; | |
166 | old0 = i; | |
167 | old1 = new1; | |
168 | } | |
169 | } | |
b328544b | 170 | fTable1[old1]=(Int_t)rint((Float_t)(old0+x0)/2); |
1a3c8f6e | 171 | |
172 | return; | |
173 | } |