]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/misc/AliL3TransBit.cxx
Taking into account the dE/dx crossing points in the TPC (Yu.Belikov)
[u/mrichter/AliRoot.git] / HLT / misc / AliL3TransBit.cxx
CommitLineData
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 11using 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:
39// For AliTransBit_v1
40// dy/dx= Int_t(1+x/fX0)
41//
42// For AliTransBit_v2
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// AliTransBit_v1 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//
3e87ef69 66</pre>
67*/
1a3c8f6e 68
9010b535 69ClassImp(AliL3TransBit)
70ClassImp(AliL3TransBit_v1)
71ClassImp(AliL3TransBit_v2)
1a3c8f6e 72
9010b535 73AliL3TransBit::AliL3TransBit()
1a3c8f6e 74{
1a3c8f6e 75 fTable0 = 0;
76 fTable1 = 0;
77 fBit0 = 10;
78 fBit1 = 8;
79 fX0 = 0;
80}
81
9010b535 82AliL3TransBit::~AliL3TransBit()
1a3c8f6e 83{
1a3c8f6e 84 //default destructor
85 if (fTable0!=0) delete [] fTable0;
86 if (fTable1!=0) delete [] fTable1;
87}
88
9010b535 89Double_t AliL3TransBit_v1::FindOptimumX0()
1a3c8f6e 90{
1a3c8f6e 91 //find x0 for which derivation at xder1 is equal 1
24dbb695 92 Int_t x0=(Int_t)rint(exp(fBit0*log(2.)));
93 Int_t x1=(Int_t)rint(exp(fBit1*log(2.)));
1a3c8f6e 94
95 fX0 = ((x1-2)*(x1-2)/2.)/(x0-x1-1); //starting fX0
96 Int_t digit=0;
97 Int_t j;
98 Double_t weight=1;
99 for(j=0;(j<50)&&(digit!=(x0-1));j++){
100 Int_t olddigit=digit;
101 digit=0;
102 for (Int_t i=0; i<x1-1;i++) digit+= Int_t(1+Double_t(i)/fX0);
103 fX0*= (1.+weight*Double_t(digit)/Double_t(x0-1))/(1.+weight);
104 if ( ((olddigit-(x0-1)) * (digit-(x0-1))) <0 )
105 weight*=0.25;
106 // cout<<j<<"\t"<<fX0<<"\t"<<digit<<"\n";
107 }
108 // cout<<"End of iteration "<<j<<"\n";
109 //cout<<"digit..."<<digit<<"\n";
110 return fX0;
111}
112
9010b535 113void AliL3TransBit_v1::Update()
1a3c8f6e 114{
9010b535 115 //construct lookup tables for loosy compression from
1a3c8f6e 116 if (fX0<1) fX0 = FindOptimumX0();
24dbb695 117 Int_t x0=(Int_t)rint(exp(fBit0*log(2.)));
118 Int_t x1=(Int_t)rint(exp(fBit1*log(2.)));
1a3c8f6e 119
120 //fTable0 - conversion from bit0 coding to bit1 coding
121 if (fTable0!=0) delete fTable0;
122 fTable0= new Int_t[x0];
123 //fTable1 - conversion table from bit1 to bit0 coding
124 if (fTable1!=0) delete [] fTable1;
125 fTable1= new Int_t[x1];
9010b535 126
1a3c8f6e 127 Int_t digit=0;
128 for (Int_t i=0; i<x1-1;i++){
129 Int_t ddig=Int_t(1+Double_t(i)/fX0);
130 for (Int_t j=0;j<ddig;j++) if ((digit+j)<x0) fTable0[digit+j] = i;
131 fTable1[i]= digit+ddig/2;
132 digit+= ddig;
9010b535 133 }
134
1a3c8f6e 135 for (Int_t i=digit;i<x0-1;i++) fTable0[i]=x1-2;
136 fTable1[x1-1]=x0-1; //overflow
137 fTable0[x0-1]=x1-1; //overflow
138 return;
139}
140
9010b535 141Double_t AliL3TransBit_v2::FindOptimumX0()
1a3c8f6e 142{
1a3c8f6e 143 //find x0 for which derivation at xder1 is equal 1
1a3c8f6e 144 const Float_t xder1=1;
145 const Float_t dx=0.1;
146
24dbb695 147 Float_t x0=exp(fBit0*log(2.));
148 Float_t x1=exp(fBit1*log(2.));
1a3c8f6e 149 Float_t deriv = 0;
150 Float_t x;
151 for (x=x1;( (x>1)&&(deriv<1)) ;x-=dx)
152 {
b328544b 153 deriv = (x1-1)/( log(1.+x0/x) *x *(1+xder1/x));
1a3c8f6e 154 }
155 x+=dx/2.;
156 fX0 = x;
157 return fX0;
158}
159
9010b535 160void AliL3TransBit_v2::Update()
1a3c8f6e 161{
1a3c8f6e 162 //construct lookup tables for loosy compresion from
163 if (fX0<1) fX0 = FindOptimumX0();
24dbb695 164 //Float_t x0=(Int_t)rint(exp(fBit0*log(2.)));
165 //Float_t x1=(Int_t)rint(exp(fBit1*log(2.)));
166 Int_t x0=(Int_t)rint(exp(fBit0*log(2.)));
167 Int_t x1=(Int_t)rint(exp(fBit1*log(2.)));
1a3c8f6e 168
169 //fTable0 - conversion from bit0 coding to bit1 coding
170 if (fTable0!=0) delete fTable0;
171 fTable0= new Int_t[x0];
172
173 //fTable1 - conversion table from bit1 to bit0 coding
174 if (fTable1!=0) delete [] fTable1;
175 fTable1= new Int_t[x1];
176
1a3c8f6e 177 Int_t i;
178
179 for ( i=0; i<x0;i++)
b328544b 180 fTable0[i] =(Int_t)rint((x1-0.501)*log(1.+Float_t(i)/fX0)/
181 log(1.+(x0-1)/fX0));
1a3c8f6e 182
183 Int_t old0=-1;
184 Int_t old1=-1;
185 Int_t new1;
186 for ( i=0; i<x0;i++){
187 new1 = fTable0[i];
188 if (new1!=old1){
189 if (old1>=0) fTable1[old1] =(old0+i)/2;
190 old0 = i;
191 old1 = new1;
192 }
193 }
b328544b 194 fTable1[old1]=(Int_t)rint((Float_t)(old0+x0)/2);
1a3c8f6e 195
196 return;
197}