]>
Commit | Line | Data |
---|---|---|
3e87ef69 | 1 | // @(#) $Id$ |
1a3c8f6e | 2 | |
3e87ef69 | 3 | // Author: Anders Vestbo <mailto:vestbo@fi.uib.no> |
4 | //*-- Copyright & copy ALICE HLT Group | |
1a3c8f6e | 5 | |
24dbb695 | 6 | #include "AliL3StandardIncludes.h" |
1a3c8f6e | 7 | |
9010b535 | 8 | #include "AliL3TransBit.h" |
b328544b | 9 | |
0bd0c1ef | 10 | #if __GNUC__ == 3 |
ada51d84 | 11 | using namespace std; |
12 | #endif | |
13 | ||
240d63be | 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 | ||
3e87ef69 | 30 | /** \class AliL3Transbit |
31 | <pre> | |
9010b535 | 32 | //_____________________________________________________________ |
3e87ef69 | 33 | // AliL3Transbit (taken from the offline AliROOT code, |
34 | // original author: Marian Ivanov, GSI Darmstadt for AliROOT) | |
9010b535 | 35 | // |
36 | // Time Projection Chamber ADC bit compresion lookup table | |
37 | // | |
38 | // Conversion equation: | |
54b54089 | 39 | // For AliTransBitV1 |
9010b535 | 40 | // dy/dx= Int_t(1+x/fX0) |
41 | // | |
54b54089 | 42 | // For AliTransBitV2 |
9010b535 | 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 | // | |
54b54089 | 51 | // AliTransBitV1 trans; |
9010b535 | 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 | // | |
3e87ef69 | 66 | </pre> |
67 | */ | |
1a3c8f6e | 68 | |
9010b535 | 69 | ClassImp(AliL3TransBit) |
54b54089 | 70 | ClassImp(AliL3TransBitV1) |
71 | ClassImp(AliL3TransBitV2) | |
1a3c8f6e | 72 | |
9010b535 | 73 | AliL3TransBit::AliL3TransBit() |
1a3c8f6e | 74 | { |
54b54089 | 75 | // default constructor |
1a3c8f6e | 76 | fTable0 = 0; |
77 | fTable1 = 0; | |
78 | fBit0 = 10; | |
79 | fBit1 = 8; | |
80 | fX0 = 0; | |
81 | } | |
82 | ||
9010b535 | 83 | AliL3TransBit::~AliL3TransBit() |
1a3c8f6e | 84 | { |
54b54089 | 85 | // destructor |
1a3c8f6e | 86 | if (fTable0!=0) delete [] fTable0; |
87 | if (fTable1!=0) delete [] fTable1; | |
88 | } | |
89 | ||
54b54089 | 90 | Double_t AliL3TransBitV1::FindOptimumX0() |
1a3c8f6e | 91 | { |
1a3c8f6e | 92 | //find x0 for which derivation at xder1 is equal 1 |
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 | 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 | ||
54b54089 | 114 | void AliL3TransBitV1::Update() |
1a3c8f6e | 115 | { |
9010b535 | 116 | //construct lookup tables for loosy compression from |
1a3c8f6e | 117 | if (fX0<1) fX0 = FindOptimumX0(); |
24dbb695 | 118 | Int_t x0=(Int_t)rint(exp(fBit0*log(2.))); |
119 | Int_t x1=(Int_t)rint(exp(fBit1*log(2.))); | |
1a3c8f6e | 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]; | |
9010b535 | 127 | |
1a3c8f6e | 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; | |
9010b535 | 134 | } |
135 | ||
1a3c8f6e | 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 | ||
54b54089 | 142 | Double_t AliL3TransBitV2::FindOptimumX0() |
1a3c8f6e | 143 | { |
1a3c8f6e | 144 | //find x0 for which derivation at xder1 is equal 1 |
54b54089 | 145 | const Float_t kxder1=1; |
146 | const Float_t kdx=0.1; | |
1a3c8f6e | 147 | |
24dbb695 | 148 | Float_t x0=exp(fBit0*log(2.)); |
149 | Float_t x1=exp(fBit1*log(2.)); | |
1a3c8f6e | 150 | Float_t deriv = 0; |
151 | Float_t x; | |
54b54089 | 152 | for (x=x1;( (x>1)&&(deriv<1)) ;x-=kdx) |
1a3c8f6e | 153 | { |
54b54089 | 154 | deriv = (x1-1)/( log(1.+x0/x) *x *(1+kxder1/x)); |
1a3c8f6e | 155 | } |
54b54089 | 156 | x+=kdx/2.; |
1a3c8f6e | 157 | fX0 = x; |
158 | return fX0; | |
159 | } | |
160 | ||
54b54089 | 161 | void AliL3TransBitV2::Update() |
1a3c8f6e | 162 | { |
1a3c8f6e | 163 | //construct lookup tables for loosy compresion from |
164 | if (fX0<1) fX0 = FindOptimumX0(); | |
24dbb695 | 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.))); | |
1a3c8f6e | 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 | ||
1a3c8f6e | 178 | Int_t i; |
179 | ||
180 | for ( i=0; i<x0;i++) | |
b328544b | 181 | fTable0[i] =(Int_t)rint((x1-0.501)*log(1.+Float_t(i)/fX0)/ |
182 | log(1.+(x0-1)/fX0)); | |
1a3c8f6e | 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 | } | |
b328544b | 195 | fTable1[old1]=(Int_t)rint((Float_t)(old0+x0)/2); |
1a3c8f6e | 196 | |
197 | return; | |
198 | } |