Conversion table class for 10-8bit compression.
authorvestbo <vestbo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 16 Apr 2002 11:52:32 +0000 (11:52 +0000)
committervestbo <vestbo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 16 Apr 2002 11:52:32 +0000 (11:52 +0000)
HLT/misc/AliL3MiscLinkDef.h [new file with mode: 0644]
HLT/misc/AliTransBit.cxx [new file with mode: 0644]
HLT/misc/AliTransBit.h [new file with mode: 0644]
HLT/misc/Makefile [new file with mode: 0644]

diff --git a/HLT/misc/AliL3MiscLinkDef.h b/HLT/misc/AliL3MiscLinkDef.h
new file mode 100644 (file)
index 0000000..d5b6557
--- /dev/null
@@ -0,0 +1,12 @@
+#ifdef __CINT__
+#pragma link off all globals;
+#pragma link off all classes;
+#pragma link off all functions;
+
+#pragma link C++ class AliTransBit; 
+#pragma link C++ class AliTransBit_v1; 
+#pragma link C++ class AliTransBit_v2; 
+
+#endif
+
diff --git a/HLT/misc/AliTransBit.cxx b/HLT/misc/AliTransBit.cxx
new file mode 100644 (file)
index 0000000..8c37132
--- /dev/null
@@ -0,0 +1,205 @@
+///////////////////////////////////////////////////////////////////////////////
+//                                                                           //
+//  Time Projection Chamber ADC bit compresion lookup table                  //
+//                                                                           // 
+//
+//  Origin: Marian Ivanov , GSI Darmstadt                                   // 
+//                                                                          //
+
+//  
+/*
+  Conversion equation:  
+  For AliTransBit_v1   
+  dy/dx= Int_t(1+x/fX0)
+
+  For AliTransBit_v2    
+  y  =(2**bit0) ln(1+x/fX0) / ln(1+(2**bit1-1)/fX0)                        
+  
+  where x0 is calculated in function GetOptimumX0()
+    
+*/
+
+// Example Session                                                          // 
+/*
+
+Int_t b0=10;  // original number of bits
+  Int_t b1=8;   // compressed
+
+  AliTransBit_v1 trans;
+  Int_t x0=TMath::Nint(TMath::Exp(b0*TMath::Log(2)));
+  Int_t x1=TMath::Nint(TMath::Exp(b1*TMath::Log(2)));  
+  trans.SetBits(b0,b1);
+  trans.FindOptimumX0();
+  trans.Update();
+  cout<<trans.Get0to1(x0-2)<<"\n";
+  cout<<trans.Get1to0(x1-2)<<"\n";
+   
+  // to produce table of 
+  for( Int_t i=0;i<x1;i++) cout<<i<<"\t"<<trans.Get1to0(i)<<"\n"; > table1to0.txt
+  for( Int_t i=0;i<x0;i++) cout<<i<<"\t"<<trans.Get0to1(i)<<"\n"; > table0to1.txt
+
+  for( Int_t i=0;i<x1-1;i++) cout<<i<<"\t"<<trans.Get1to0(i+1)-trans.Get1to0(i)<<"\n"; > tabled.txt
+
+  
+
+*/
+//Begin_Html                                                                //
+/*                                                                          // 
+<img src="gif/AliTPCTransBit.gif">  
+*/
+//End_Html
+//                                                                           //
+//                                                                          //
+///////////////////////////////////////////////////////////////////////////////
+
+
+#include "AliTransBit.h"
+#include "TMath.h"
+#include "iostream.h"
+
+ClassImp(AliTransBit)
+ClassImp(AliTransBit_v1)
+ClassImp(AliTransBit_v2)
+
+
+AliTransBit::AliTransBit()
+{
+  //
+  //
+  fTable0 = 0;
+  fTable1 = 0;
+  fBit0   = 10;
+  fBit1   = 8;
+  fX0     = 0;
+}
+
+AliTransBit::~AliTransBit() 
+{
+  //
+  //default destructor
+  if (fTable0!=0) delete [] fTable0;
+  if (fTable1!=0) delete [] fTable1;
+}
+
+
+
+
+
+Double_t AliTransBit_v1::FindOptimumX0()
+{
+  //
+  //find x0 for which derivation at xder1 is equal 1
+  //
+  Int_t x0=TMath::Nint(TMath::Exp(fBit0*TMath::Log(2)));
+  Int_t x1=TMath::Nint(TMath::Exp(fBit1*TMath::Log(2)));
+
+  fX0 = ((x1-2)*(x1-2)/2.)/(x0-x1-1);  //starting fX0
+  Int_t digit=0;
+  Int_t j;
+  Double_t weight=1;
+  for(j=0;(j<50)&&(digit!=(x0-1));j++){  
+    Int_t olddigit=digit;
+    digit=0;
+    for (Int_t  i=0; i<x1-1;i++) digit+= Int_t(1+Double_t(i)/fX0);      
+    fX0*= (1.+weight*Double_t(digit)/Double_t(x0-1))/(1.+weight);    
+    if ( ((olddigit-(x0-1)) * (digit-(x0-1))) <0 ) 
+      weight*=0.25;
+    // cout<<j<<"\t"<<fX0<<"\t"<<digit<<"\n";
+  }
+  //  cout<<"End of iteration "<<j<<"\n";
+  //cout<<"digit..."<<digit<<"\n";  
+  return fX0;
+}
+
+
+void AliTransBit_v1::Update()
+{
+  //
+  //construct lookup tables for loosy compresion from 
+  if (fX0<1) fX0 = FindOptimumX0();  
+  Int_t x0=TMath::Nint(TMath::Exp(fBit0*TMath::Log(2)));
+  Int_t x1=TMath::Nint(TMath::Exp(fBit1*TMath::Log(2)));
+  
+  //fTable0 - conversion from bit0 coding to bit1 coding
+  if (fTable0!=0) delete fTable0;
+  fTable0= new Int_t[x0];
+  //fTable1 - conversion table from bit1 to bit0 coding
+  if (fTable1!=0) delete [] fTable1;
+  fTable1= new Int_t[x1];
+  //   
+  Int_t digit=0;
+  for (Int_t  i=0; i<x1-1;i++){    
+    Int_t ddig=Int_t(1+Double_t(i)/fX0);
+    for (Int_t j=0;j<ddig;j++) if ((digit+j)<x0) fTable0[digit+j] = i;    
+    fTable1[i]= digit+ddig/2;
+    digit+= ddig;
+  } 
+  for (Int_t i=digit;i<x0-1;i++) fTable0[i]=x1-2;
+  fTable1[x1-1]=x0-1; //overflow 
+  fTable0[x0-1]=x1-1; //overflow    
+  return;
+}
+
+
+Double_t AliTransBit_v2::FindOptimumX0()
+{
+  //
+  //find x0 for which derivation at xder1 is equal 1
+  //
+  const Float_t xder1=1;
+  const Float_t dx=0.1;
+
+  Float_t x0=TMath::Exp(fBit0*TMath::Log(2));
+  Float_t x1=TMath::Exp(fBit1*TMath::Log(2));
+  Float_t deriv = 0;
+  Float_t x;
+  for (x=x1;( (x>1)&&(deriv<1)) ;x-=dx)
+    {
+      deriv = (x1-1)/( TMath::Log(1.+x0/x) *x *(1+xder1/x));
+    }
+  x+=dx/2.;
+  fX0 = x;
+  return fX0;
+}
+
+
+void AliTransBit_v2::Update()
+{
+  //
+  //construct lookup tables for loosy compresion from 
+  if (fX0<1) fX0 = FindOptimumX0();  
+  //Float_t x0=TMath::Nint(TMath::Exp(fBit0*TMath::Log(2)));
+  //Float_t x1=TMath::Nint(TMath::Exp(fBit1*TMath::Log(2)));
+  Int_t x0=TMath::Nint(TMath::Exp(fBit0*TMath::Log(2)));
+  Int_t x1=TMath::Nint(TMath::Exp(fBit1*TMath::Log(2)));
+  
+  //fTable0 - conversion from bit0 coding to bit1 coding
+  if (fTable0!=0) delete fTable0;
+  fTable0= new Int_t[x0];
+
+  //fTable1 - conversion table from bit1 to bit0 coding
+  if (fTable1!=0) delete [] fTable1;
+  fTable1= new Int_t[x1];
+
+  //  
+  Int_t i;
+
+  for ( i=0; i<x0;i++)
+      fTable0[i] =TMath::Nint((x1-0.501)*TMath::Log(1.+Float_t(i)/fX0)/
+                                TMath::Log(1.+(x0-1)/fX0));
+
+  Int_t old0=-1;
+  Int_t old1=-1;
+  Int_t new1;
+  for ( i=0; i<x0;i++){
+      new1 = fTable0[i];
+      if (new1!=old1){
+       if (old1>=0) fTable1[old1] =(old0+i)/2;
+       old0 = i;
+       old1 = new1;
+      }
+  }
+  fTable1[old1]=TMath::Nint((Float_t)(old0+x0)/2);
+  
+  return;
+}
diff --git a/HLT/misc/AliTransBit.h b/HLT/misc/AliTransBit.h
new file mode 100644 (file)
index 0000000..6c99c2e
--- /dev/null
@@ -0,0 +1,60 @@
+#ifndef ALITRANSBIT_H
+#define ALITRANSBIT_H
+
+#include "AliL3RootTypes.h"
+
+class AliTransBit : public TObject {
+public:
+  AliTransBit();
+  virtual ~AliTransBit();
+  inline Int_t Get0to1(Int_t val0);
+  inline Int_t Get1to0(Int_t val1);
+  Int_t GetBit0() {return fBit0;}
+  Int_t GetBit1() {return fBit1;}
+  Double_t GetX0() {return fX0;}
+  void SetBits(Int_t bit0, Int_t bit1) {fBit0=bit0;fBit1=bit1;}
+  void SetX0(Double_t x0) {fX0=x0;}
+  virtual void Update()=0;
+  virtual Double_t FindOptimumX0()=0;
+protected:
+  Int_t  * fTable0; //! table
+  Int_t  * fTable1; //! table
+  Int_t fBit0;
+  Int_t fBit1;
+  Double_t fX0;
+  ClassDef(AliTransBit,1)  // Tclusters
+};
+
+
+class AliTransBit_v1 : public AliTransBit {
+public:
+  virtual void Update();
+  virtual Double_t FindOptimumX0();
+protected:
+  ClassDef(AliTransBit_v1,1)  // Tclusters
+};
+
+class AliTransBit_v2 : public AliTransBit {
+public:
+  virtual void Update();
+  virtual Double_t FindOptimumX0();
+protected:
+  ClassDef(AliTransBit_v2,1)  // Tclusters
+};
+
+
+Int_t AliTransBit::Get0to1(Int_t val0)
+{
+  //
+  //return compressed bit values
+  return fTable0[val0];
+}
+Int_t AliTransBit::Get1to0(Int_t val1)
+{
+  //return uncompressed bit value
+  return fTable1[val1];
+}
+
+
+#endif //ALITRANSBIT_H
diff --git a/HLT/misc/Makefile b/HLT/misc/Makefile
new file mode 100644 (file)
index 0000000..8eea133
--- /dev/null
@@ -0,0 +1,116 @@
+#$Id$
+###########################
+# Makefile for HLT code.  #
+#                         #
+# Author: Anders Vestbo   #                    
+###########################
+
+ifndef USEPACKAGE
+#USEPACKAGE = ROOT
+USEPACKAGE = ALIROOT
+endif
+
+#used if USEPACKAGE=anything else
+DEFSTR = -Dno_root
+
+CXX         = g++
+LD          = g++
+CXXFLAGS    = -O2 -Wall -fPIC
+LDFLAGS     = -O2
+SOFLAGS     = -shared
+
+ifndef TOPDIR
+TOPDIR = $(HOME)/level3code
+endif
+ifndef LIBDIR
+LIBDIR = $(LEVEL3)/lib_$(USERNAME)
+endif
+OBJDIR = lib
+
+ifeq ($(USEPACKAGE),ROOT) 
+INCLUDES = -I$(ROOTSYS)/include -I$(TOPDIR)/hough -I$(TOPDIR)/src -I$(TOPDIR)/comp
+DEFSTR = -Duse_root
+endif
+
+ifeq ($(USEPACKAGE),ALIROOT)
+INCLUDES = -I$(ROOTSYS)/include -I$(TOPDIR)/hough -I$(TOPDIR)/src -I$(TOPDIR)/comp -I$(ALICE_ROOT)/include/ -I$(ALICE_ROOT)/TPC -I$(ALICE_ROOT)/CONTAINERS -I$(ALICE_ROOT)/STEER
+DEFSTR = -Duse_aliroot
+endif
+
+#Save the particle id's
+#DEFSTR += -Ddo_mc
+
+#Use logging classes
+DEFSTR += -Duse_logging
+
+ifdef MLUCDIR
+INCLUDES += -I$(MLUCDIR)/include
+else
+INCLUDES += -I/prog/alice/level3/kip/MLUC/include
+endif
+
+SRCS   = AliTransBit.cxx
+
+DICT = AliL3MiscCint.cxx
+DICTH = AliL3MiscCint.h
+DICTO = $(OBJDIR)/AliL3MiscCint.o
+
+HDRS = $(SRCS:.cxx=.h) AliL3MiscLinkDef.h
+OBJS = $(patsubst %.cxx,$(OBJDIR)/%.o,$(SRCS)) $(DICTO)
+
+LEVELSO = $(LIBDIR)/libAliL3Misc.so
+
+all : $(OBJDIR) $(LIBDIR) $(LEVELSO) 
+
+$(LEVELSO) : $(OBJS)
+       $(LD) $(SOFLAGS) $(LDFLAGS) $^ -o $@
+
+$(DICT) : $(HDRS)
+       @echo "Generating dictionary..."
+       @rootcint -f $(DICT) -c $(INCLUDES) $(HDRS)
+
+$(OBJDIR)/%.o : %.cxx 
+       $(CXX) $(CXXFLAGS) $(DEFSTR) -c $(INCLUDES) -o $@ $<
+
+$(OBJDIR) : 
+       test ! -e $(OBJDIR) && mkdir -p $(OBJDIR)
+
+$(LIBDIR) :
+       test ! -e $(LIBDIR) && mkdir -p $(LIBDIR)
+
+clean :
+       rm -f $(OBJDIR)/*.o
+       rm -f $(LIBDIR)/libAliL3Misc.so
+       rm $(DICT) $(DICTH) 
+
+so :
+       rm -f $(LIBDIR)/libAliL3Misc.so
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+