Started classes for modeling and compression
authorvestbo <vestbo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 25 Jan 2002 17:19:40 +0000 (17:19 +0000)
committervestbo <vestbo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 25 Jan 2002 17:19:40 +0000 (17:19 +0000)
HLT/comp/AliL3CompLinkDef.h [new file with mode: 0644]
HLT/comp/AliL3ModelTrack.cxx [new file with mode: 0644]
HLT/comp/AliL3ModelTrack.h [new file with mode: 0644]
HLT/comp/AliL3Modeller.cxx [new file with mode: 0644]
HLT/comp/AliL3Modeller.h [new file with mode: 0644]
HLT/comp/Makefile [new file with mode: 0644]
HLT/comp/rootlogon.C [new file with mode: 0644]

diff --git a/HLT/comp/AliL3CompLinkDef.h b/HLT/comp/AliL3CompLinkDef.h
new file mode 100644 (file)
index 0000000..eadd58e
--- /dev/null
@@ -0,0 +1,11 @@
+#ifdef __CINT__
+#pragma link off all globals;
+#pragma link off all classes;
+#pragma link off all functions;
+
+#pragma link C++ class AliL3Modeller; 
+#pragma link C++ class AliL3ModelTrack; 
+
+#endif
+
diff --git a/HLT/comp/AliL3ModelTrack.cxx b/HLT/comp/AliL3ModelTrack.cxx
new file mode 100644 (file)
index 0000000..cf3e3d8
--- /dev/null
@@ -0,0 +1,65 @@
+//$Id$
+
+// Author: Anders Vestbo <mailto:vestbo$fi.uib.no>
+//*-- Copyright &copy ASV
+
+#include <stream.h>
+#include <string.h>
+
+#include "AliL3ModelTrack.h"
+#include "AliL3Defs.h"
+
+ClassImp(AliL3ModelTrack)
+
+AliL3ModelTrack::AliL3ModelTrack()
+{
+  fNClusters = 0;
+  fClusters = 0;
+  fOverlap = -1;
+  fPad=0;
+  fTime=0;
+  fClusterCharge=0;
+}
+
+
+AliL3ModelTrack::~AliL3ModelTrack()
+{
+  if(fClusters)
+    delete [] fClusters;
+  if(fPad)
+    delete [] fPad;
+  if(fTime)
+    delete [] fTime;
+}
+
+void AliL3ModelTrack::Init(Int_t slice,Int_t patch)
+{
+  fNClusters = 0;
+  Int_t nrows = NumRows[patch];
+  fClusters = new ClusterComp[nrows];
+  memset((void*)fClusters,0,nrows*sizeof(ClusterComp));
+  
+  fPad = new Float_t[NRowsSlice];
+  fTime = new Float_t[NRowsSlice];
+  
+  fClusterCharge = 100;
+  
+}
+
+
+void AliL3ModelTrack::SetCluster(Float_t fpad,Float_t ftime,Float_t charge,Float_t sigmaY2,Float_t sigmaZ2)
+{
+  ClusterComp *cl = &fClusters[fNClusters];
+  if(!charge)
+    cl->fEmpty = kTRUE;
+  else
+    {
+      cl->fEmpty = kFALSE;
+      cl->fDTime = ftime - GetTimeHit(fNClusters);
+      cl->fDPad = fpad - GetPadHit(fNClusters);
+      cl->fDCharge = charge - fClusterCharge;
+    }
+  cout<<"DPad "<<fpad<<" dtime "<<ftime<<" charge "<<charge<<" sigmaY2 "<<sigmaY2<<" sigmaZ2 "<<sigmaZ2<<endl;
+  fNClusters++;
+}
+
diff --git a/HLT/comp/AliL3ModelTrack.h b/HLT/comp/AliL3ModelTrack.h
new file mode 100644 (file)
index 0000000..e39925b
--- /dev/null
@@ -0,0 +1,48 @@
+#ifndef AliL3Model_Track
+#define AliL3Model_Track
+
+#include "AliL3Track.h"
+
+
+struct ClusterComp {
+  Bool_t fEmpty;
+  Float_t fDTime;
+  Float_t fDPad;
+  Float_t fDCharge;
+  Float_t fDShape;
+};
+
+
+class AliL3ModelTrack : public AliL3Track {
+
+ private:
+  
+  Short_t fClusterCharge; //Average cluster charge
+  ClusterComp *fClusters; //!
+  Short_t fNClusters;
+  Int_t fOverlap;
+
+  //Crossing points with padrows
+  Float_t *fPad; //!
+  Float_t *fTime; //!
+  
+ public:
+  AliL3ModelTrack();
+  virtual ~AliL3ModelTrack();
+  
+  void Init(Int_t slice,Int_t patch);
+  void SetCluster(Float_t dpad,Float_t dtime,Float_t charge,Float_t sigmaY2,Float_t sigmaZ2);
+  
+  void SetPadHit(Int_t row,Float_t f) {fPad[row]=f;}
+  void SetTimeHit(Int_t row,Float_t f) {fTime[row]=f;}
+  void SetOverlap(Int_t i) {fOverlap=i;}
+  
+  Int_t GetOverlap() {return fOverlap;}
+  Float_t GetPadHit(Int_t row) {return fPad[row];}
+  Float_t GetTimeHit(Int_t row) {return fTime[row];}
+
+  ClassDef(AliL3ModelTrack,1)
+
+};
+
+#endif
diff --git a/HLT/comp/AliL3Modeller.cxx b/HLT/comp/AliL3Modeller.cxx
new file mode 100644 (file)
index 0000000..4c72c15
--- /dev/null
@@ -0,0 +1,293 @@
+//$Id$
+
+// Author: Anders Vestbo <mailto:vestbo$fi.uib.no>
+//*-- Copyright &copy ASV
+
+#include <stream.h>
+#include <iostream.h>
+#include <math.h>
+
+#include "AliL3Modeller.h"
+#include "AliL3MemHandler.h"
+#include "AliL3TrackArray.h"
+#include "AliL3ModelTrack.h"
+#include "AliL3DigitData.h"
+#include "AliL3Transform.h"
+
+#include "AliL3Defs.h"
+
+ClassImp(AliL3Modeller)
+
+AliL3Modeller::AliL3Modeller()
+{
+  fMemHandler=0;
+  fTracks=0;
+  fTransform=0;
+}
+
+
+AliL3Modeller::~AliL3Modeller()
+{
+  if(fMemHandler)
+    delete fMemHandler;
+  if(fTracks)
+    delete fTracks;
+  if(fTransform)
+    delete fTransform;
+
+}
+
+void AliL3Modeller::Init(Int_t slice,Int_t patch,Char_t *path)
+{
+  fSlice = slice;
+  fPatch = patch;
+  fPadOverlap=4;
+  fTimeOverlap=4;
+  fTransform = new AliL3Transform();
+  fTracks = new AliL3TrackArray("AliL3ModelTrack");
+  
+  AliL3MemHandler *file = new AliL3MemHandler();
+  if(!file->SetBinaryInput("tracks.raw"))
+    {
+      cerr<<"AliL3Modeller::Init : Error opening trackfile"<<endl;
+      return;
+    }
+  file->Binary2TrackArray(fTracks);
+  file->CloseBinaryInput();
+  delete file;
+  
+  fTracks->QSort();
+  for(Int_t i=0; i<fTracks->GetNTracks(); i++)
+    {
+      AliL3ModelTrack *track = (AliL3ModelTrack*)fTracks->GetCheckedTrack(i);
+      if(!track) continue;
+      track->Init(fSlice,fPatch);
+      track->Rotate(fSlice,kTRUE);
+      track->CalculateHelix();
+    }    
+  
+  CalculateCrossingPoints();
+  CheckForOverlaps();
+
+  fMemHandler = new AliL3MemHandler();
+  Char_t fname[100];
+  sprintf(fname,"%s/digits_%d_%d.raw",path,fSlice,fPatch);
+  if(!fMemHandler->SetBinaryInput(fname))
+    {
+      cerr<<"AliL3Modeller::Init : Error opening file "<<fname<<endl;
+      return;
+    }
+  UInt_t ndigits;
+  AliL3DigitRowData *digits=(AliL3DigitRowData*)fMemHandler->CompBinary2Memory(ndigits);
+  
+  SetInputData(digits);
+}
+
+void AliL3Modeller::Process()
+{
+  
+  if(!fTracks)
+    {
+      cerr<<"AliL3Modeller::Process : No tracks"<<endl;
+      return;
+    }
+  if(!fRowData)
+    {
+      cerr<<"AliL3Modeller::Process : No data "<<endl;
+      return;
+    }
+  
+  AliL3DigitRowData *rowPt = fRowData;
+  AliL3DigitData *digPt=0;
+
+  Int_t ntimes = fTransform->GetNTimeBins()+1;
+  Int_t npads = fTransform->GetNPads(NRows[fPatch][1])+1;//Max num of pads.
+  Digit *row = new Digit[(ntimes)*(npads)];
+  
+  Int_t seq_charge;
+  Int_t pad,time;
+  Short_t charge;
+  Cluster cluster;
+
+  for(Int_t i=NRows[fPatch][0]; i<=NRows[fPatch][1]; i++)
+    {
+      memset((void*)row,0,ntimes*npads*sizeof(Digit));
+      digPt = (AliL3DigitData*)rowPt->fDigitData;
+      for(UInt_t j=0; j<rowPt->fNDigit; j++)
+       {
+         pad = digPt[j].fPad;
+         time = digPt[j].fTime;
+         charge = digPt[j].fCharge;
+         row[ntimes*pad+time].fCharge = charge;
+         row[ntimes*pad+time].fUsed = kFALSE;
+       }
+      
+      for(Int_t k=0; k<fTracks->GetNTracks(); k++)
+       {
+         AliL3ModelTrack *track = (AliL3ModelTrack*)fTracks->GetCheckedTrack(k);
+         if(!track) continue;
+         if(track->GetOverlap()>=0) continue;//Track is overlapping
+         
+         Int_t hitpad = (Int_t)rint(track->GetPadHit(i));
+         Int_t hittime = (Int_t)rint(track->GetTimeHit(i));
+         cout<<"Checking track with pad "<<hitpad<<" time "<<hittime<<endl;
+         pad = hitpad;
+         time = hittime;
+         Int_t padsign=-1;
+         Int_t timesign=-1;
+         
+         memset(&cluster,0,sizeof(Cluster));
+         
+         while(1)//Process this padrow
+           {
+             seq_charge=0;
+             timesign=-1;
+             time = hittime;
+             while(1) //Process sequence on this pad:
+               {
+                 charge = row[ntimes*pad+time].fCharge;
+                 if(charge==0 && timesign==-1)
+                   {time=hittime+1; timesign=1; continue;}
+                 else if(charge==0 && timesign==1)
+                   break;
+                 //cout<<"Doing pad "<<pad<<" time "<<time<<" charge "<<charge<<endl;
+                 
+                 seq_charge += charge;
+                                                 
+                 cluster.fTime += time*charge;
+                 cluster.fPad += pad*charge;
+                 cluster.fCharge += charge;
+                 cluster.fSigmaY2 += pad*pad*charge;
+                 cluster.fSigmaZ2 += time*time*charge;
+                 
+                 row[ntimes*pad+time].fUsed = kTRUE;
+                 time += timesign;
+               }
+             cout<<"Finished on pad "<<pad<<" and time "<<time<<endl;
+             if(seq_charge)
+               pad += padsign;
+               
+             else //Nothing more on this pad, goto next pad
+               {
+                 if(padsign==-1) 
+                   {pad=hitpad+1; padsign=1; continue;}
+                 else //Nothing more in this cluster
+                   {
+                     Float_t fcharge = (Float_t)cluster.fCharge;
+                     Float_t fpad = ((Float_t)cluster.fPad/fcharge);
+                     Float_t ftime = ((Float_t)cluster.fTime/fcharge);
+                     Float_t sigmaY2,sigmaZ2;
+                     CalcClusterWidth(&cluster,sigmaY2,sigmaZ2);
+                     //cout<<"row "<<i<<" pad "<<dpad<<endl;
+                     track->SetCluster(fpad,ftime,fcharge,sigmaY2,sigmaZ2);
+                     break;
+                   } 
+               }
+             // pad += padsign;
+           }
+       }
+      fMemHandler->UpdateRowPointer(rowPt);
+      
+    }
+  delete [] row;
+  
+}
+
+void AliL3Modeller::CalculateCrossingPoints()
+{
+  cout<<"Calculating crossing points on "<<fTracks->GetNTracks()<<" tracks"<<endl;
+  if(!fTracks)
+    {
+      cerr<<"AliL3Modeller::CalculateCrossingPoints(): No tracks"<<endl;
+      return;
+    }
+  Float_t hit[3];
+  for(Int_t i=NRows[fPatch][0]; i<NRows[fPatch][1]; i++)
+    {
+      for(Int_t j=0; j<fTracks->GetNTracks(); j++)
+       {
+         AliL3ModelTrack *track = (AliL3ModelTrack*)fTracks->GetCheckedTrack(j);
+         if(!track) continue;
+         //if(!track->GetCrossingPoint(i,hit)) 
+         // fTracks->Remove(j); //Track is bending out.
+         track->CalculatePoint(fTransform->Row2X(i));
+         if(!track->IsPoint())
+           {
+             fTracks->Remove(j);
+             continue;
+           }
+         hit[1]=track->GetPointY();
+         hit[2]=track->GetPointZ();
+         fTransform->Local2Raw(hit,fSlice,i);
+         track->SetPadHit(i,hit[1]);
+         track->SetTimeHit(i,hit[2]);
+         //if(hit[1]<0 || hit[2]>445)
+         cout<<"pad "<<hit[1]<<" time "<<hit[2]<<" pt "<<track->GetPt()<<" psi "<<track->GetPsi()<<" tgl "<<track->GetTgl()<<" firstpoint "<<track->GetFirstPointX()<<" "<<track->GetFirstPointY()<<" "<<track->GetFirstPointZ()<<endl;
+         //cout<<"Crossing pad "<<hit[1]<<" time "<<hit[2]<<endl;
+       }
+    }
+  fTracks->Compress();
+  cout<<"And there are "<<fTracks->GetNTracks()<<" tracks remaining"<<endl;
+}
+
+void AliL3Modeller::CheckForOverlaps()
+{
+  //Flag the tracks that overlap
+  
+  cout<<"Checking for overlaps"<<endl;
+  
+  for(Int_t i=0; i<fTracks->GetNTracks(); i++)
+    {
+      AliL3ModelTrack *track1 = (AliL3ModelTrack*)fTracks->GetCheckedTrack(i);
+      if(!track1) continue;
+      for(Int_t j=i+1; j<fTracks->GetNTracks(); j++)
+       {
+         AliL3ModelTrack *track2 = (AliL3ModelTrack*)fTracks->GetCheckedTrack(j);
+         if(!track2) continue;
+         for(Int_t k=NRows[fPatch][0]; k<NRows[fPatch][1]; k++)
+           {
+             if(fabs(track1->GetPadHit(k)-track2->GetPadHit(k)) < fPadOverlap &&
+                fabs(track1->GetTimeHit(k)-track2->GetTimeHit(k)) < fTimeOverlap)
+               {
+                 track1->SetOverlap(j);
+                 track2->SetOverlap(i);
+               }
+           }
+       }
+    }
+  
+}
+
+
+void AliL3Modeller::CalcClusterWidth(Cluster *cl,Float_t &sigmaY2,Float_t &sigmaZ2)
+{
+  
+  Float_t padw,timew;
+  if(fPatch < 3)
+    padw = fTransform->GetPadPitchWidthLow();
+  else
+    padw = fTransform->GetPadPitchWidthUp();
+  Float_t charge = (Float_t)cl->fCharge;
+  Float_t pad = (Float_t)cl->fPad/charge;
+  Float_t time = (Float_t)cl->fTime/charge;
+  Float_t s2 = (Float_t)cl->fSigmaY2/charge - pad*pad;
+  sigmaY2 = (s2 + 1./12)*padw*padw;
+
+  if(s2 != 0)
+    {
+      sigmaY2 = sigmaY2*0.108;
+      if(fPatch<3)
+       sigmaY2 = sigmaY2*2.07;
+    }
+  
+  s2 = (Float_t)cl->fSigmaZ2/charge - time*time;
+  timew = fTransform->GetZWidth();
+  sigmaZ2 = (s2 +1./12)*timew*timew;
+  if(s2 != 0)
+    {
+      sigmaZ2 = sigmaZ2*0.169;
+      if(fPatch < 3)
+       sigmaZ2 = sigmaZ2*1.77;
+    }
+  
+}
diff --git a/HLT/comp/AliL3Modeller.h b/HLT/comp/AliL3Modeller.h
new file mode 100644 (file)
index 0000000..86ef7c0
--- /dev/null
@@ -0,0 +1,62 @@
+#ifndef AliL3_Modeller
+#define AliL3_Modeller
+
+
+#include "AliL3RootTypes.h"
+
+class AliL3TrackArray;
+class AliL3MemHandler;
+class AliL3DigitRowData;
+class AliL3Transform;
+
+struct Cluster {
+  UInt_t fCharge;
+  UInt_t fPad;
+  UInt_t fTime;
+  UInt_t fSigmaY2;
+  UInt_t fSigmaZ2;
+};
+
+struct Digit {
+  Short_t fCharge;
+  Bool_t fUsed;
+};
+
+class AliL3Modeller {
+  
+ private:
+  
+  AliL3TrackArray *fTracks; //!
+  AliL3MemHandler *fMemHandler; //!
+  AliL3DigitRowData *fRowData;//!
+
+  AliL3Transform *fTransform; //!
+  Int_t fNClusters;
+  Int_t fMaxClusters;
+  
+  Float_t fPadOverlap;
+  Float_t fTimeOverlap;
+  
+  Int_t fSlice;
+  Int_t fPatch;
+  
+  void CalcClusterWidth(Cluster *cl,Float_t &sigmaY2,Float_t &sigmaZ2);
+  
+ public:
+  
+  AliL3Modeller();
+  virtual ~AliL3Modeller();
+  
+  void Init(Int_t slice,Int_t patch,Char_t *path);
+  void Process();
+  void CheckForOverlaps();
+  void CalculateCrossingPoints();
+
+  void SetInputData(AliL3DigitRowData *digits) {fRowData = digits;}
+  
+    
+  ClassDef(AliL3Modeller,1) //Modeller class
+    
+};
+
+#endif
diff --git a/HLT/comp/Makefile b/HLT/comp/Makefile
new file mode 100644 (file)
index 0000000..41a5384
--- /dev/null
@@ -0,0 +1,50 @@
+#
+# Makefile for ROOT version of HLT code.
+#
+# Author: Anders Vestbo                       
+#
+
+CXX         = g++
+LD          = g++
+CXXFLAGS    = -O2 -Wall -fPIC -Woverloaded-virtual
+LDFLAGS     = -O2
+SOFLAGS     = -shared
+
+TOPDIR = $(HOME)/level3code
+OBJDIR = tgt_Linux
+
+SRCS   = AliL3Modeller.cxx AliL3ModelTrack.cxx
+
+DICT = AliL3CompCint.cxx
+DICTH = AliL3CompCint.h
+DICTO = $(OBJDIR)/AliL3CompCint.o
+
+HDRS = $(SRCS:.cxx=.h) AliL3CompLinkDef.h
+
+OBJS = $(patsubst %.cxx,$(OBJDIR)/%.o,$(SRCS)) $(DICTO)
+
+LEVELSO = $(LEVEL3)/lib_$(USERNAME)/libAliL3Comp.so
+
+all : $(OBJDIR) $(LEVELSO)
+
+
+$(LEVELSO) : $(OBJS)
+       $(LD) $(SOFLAGS) $(LDFLAGS) $^ -o $@
+
+$(DICT) : $(HDRS)
+       @echo "Generating dictionary..."
+       @rootcint -f $(DICT) -c -I$(ROOTSYS) -I$(TOPDIR)/src/ $(HDRS)
+
+
+$(OBJDIR)/%.o : %.cxx 
+       $(CXX) $(CXXFLAGS) -c -I$(ROOTSYS)/include -I$(TOPDIR)/src -I$(TOPDIR)/hough -o $@ $<
+
+$(OBJDIR) : 
+       test ! -e $(OBJDIR) && mkdir -p $(OBJDIR)
+
+clean :
+       rm -f $(OBJDIR)/*.o
+       rm -f $(LEVEL3)/lib_$(USERNAME)/libAliL3Comp.so
+       rm $(DICT) $(DICTH) 
+so :
+       rm -f $(LEVEL3)/lib_$(USERNAME)/libAliL3Comp.so
\ No newline at end of file
diff --git a/HLT/comp/rootlogon.C b/HLT/comp/rootlogon.C
new file mode 100644 (file)
index 0000000..0a4a8f9
--- /dev/null
@@ -0,0 +1,27 @@
+
+{
+  printf("\nWELCOME to the magic world of Level3\n\n"); 
+
+  gSystem->Load("$(ROOTSYS)/lib/libPhysics");
+  gSystem->Load("$(ROOTSYS)/lib/libEG");
+
+  if(0)
+    {
+      gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libSTEER");
+      gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libCONTAINERS");
+      gSystem->Load("$(ALICE_ROOT)/lib/tgt_$(ALICE_TARGET)/libTPC");
+      cout<<"TPC libraries loaded"<<endl;
+    }
+  if(1)
+    {
+      gSystem->Load("$(LEVEL3)/kip/MLUC/lib/linux-i386/libMLUC.so");
+      gSystem->Load("$(LEVEL3)/lib_$(USERNAME)/libAliL3");
+      gSystem->Load("$(LEVEL3)/lib_$(USERNAME)/libAliL3Hough");
+      gSystem->Load("$(LEVEL3)/lib_$(USERNAME)/libAliL3Comp");
+      cout<<"HLT libraries loaded"<<endl;
+    }
+  gROOT->LoadMacro("$(HOME)/alirootcode/XFunct.C");
+  gStyle->SetStatBorderSize(1);
+  gStyle->SetTitleBorderSize(0);
+
+}