Made display class work. Also added it to makefile.
[u/mrichter/AliRoot.git] / HLT / hough / AliL3HoughDisplay.cxx
1 //$Id$
2
3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4 //*-- Copyright &copy ASV 
5
6 #include <iostream.h>
7 #include <TCanvas.h>
8 #include <TView.h>
9 #include <TPolyMarker3D.h>
10 #include <TPolyLine3D.h>
11 #include <TNode.h>
12 #include <TGeometry.h>
13 #include <TShape.h>
14 #include <TFile.h>
15
16 #include "AliL3Transform.h"
17 #include "AliL3HoughTrack.h"
18 #include "AliL3TrackArray.h"
19 #include "AliL3HoughDisplay.h"
20 #include "AliL3MemHandler.h"
21
22 //_____________________________________________________________
23 // Display class for Hough transform code
24
25 ClassImp(AliL3HoughDisplay)
26
27
28 AliL3HoughDisplay::AliL3HoughDisplay()
29 {
30
31   fTracks = 0;
32   fDigitRowData = 0;
33   fNDigitRowData = 0;
34   fShowSlice = -1;
35   fPatch = -1;
36 }
37
38 AliL3HoughDisplay::~AliL3HoughDisplay()
39 {
40   if(fTracks)
41     delete fTracks;
42 }
43
44 void AliL3HoughDisplay::Init(Char_t *trackfile)
45 {
46   TFile *file = TFile::Open("$(LEVEL3)/GEO/alice.geom");
47   if(!file->IsOpen())
48     cerr<<"AliL3HoughDisplay::AliL3HoughDisplay : Geometry file alice.geom does not exist"<<endl;
49   fGeom = (TGeometry*)file->Get("AliceGeom");
50   file->Close();
51   
52   fTracks = new AliL3TrackArray();
53   AliL3MemHandler *tfile = new AliL3MemHandler();
54   tfile->SetBinaryInput(trackfile);
55   tfile->Binary2TrackArray(fTracks);
56   tfile->CloseBinaryInput();
57   delete tfile;
58 }
59
60
61 void AliL3HoughDisplay::GenerateHits(AliL3Track *track,Float_t *x,Float_t *y,Float_t *z,Int_t &n)
62 {
63   n=0;
64   Float_t xyz[3];
65   for(Int_t i=AliL3Transform::GetFirstRow(0); i<AliL3Transform::GetLastRow(5); i++)
66     {
67       if(track->GetCrossingPoint(i,xyz))
68         {
69           AliL3Transform::Local2Global(xyz,0);
70           x[n] = xyz[0];
71           y[n] = xyz[1];
72           z[n] = xyz[2];
73           n++;
74         }
75       else
76         break;
77     }
78 }
79
80 TPolyMarker3D *AliL3HoughDisplay::LoadDigits()
81 {
82   
83   AliL3DigitRowData *tempPt = fDigitRowData;
84   if(!tempPt)
85     {
86       cerr<<"AliL3HoughDisplay::LoadDigits : No data"<<endl;
87       return 0;
88     }
89   
90   UInt_t nrows = AliL3Transform::GetNRows(fPatch);
91   Int_t count=0;
92   for(UInt_t i=0; i<nrows; i++)
93     {
94       count += tempPt->fNDigit;
95       AliL3MemHandler::UpdateRowPointer(tempPt);
96     }
97   tempPt = fDigitRowData;
98   TPolyMarker3D *pm = new TPolyMarker3D(count);
99   Float_t xyz[3];
100   Int_t sector,row;
101   count=0;
102   for(UInt_t i=0; i<nrows; i++)
103     {
104       AliL3DigitData *digPt = tempPt->fDigitData;
105       Int_t padrow = (Int_t)tempPt->fRow;
106       for(UInt_t j=0; j<tempPt->fNDigit; j++)
107         {
108           AliL3Transform::Slice2Sector(fShowSlice,padrow,sector,row);
109           AliL3Transform::Raw2Global(xyz,sector,row,(Int_t)digPt->fPad,(Int_t)digPt->fTime);
110           pm->SetPoint(count,xyz[0],xyz[1],xyz[2]);
111           count++;
112         }
113       AliL3MemHandler::UpdateRowPointer(tempPt);
114     }
115
116   cout<<"Displaying "<<count<<" digits"<<endl;
117   return pm;
118 }
119
120 void AliL3HoughDisplay::DisplayEvent()
121 {
122   //Display the found tracks.
123   
124   if(!fTracks)
125     {
126       cerr<<"AliL3HoughDisplay::DisplayTracks() : No tracks"<<endl;
127       return;
128     }
129   
130   TCanvas *c1 = new TCanvas("c1","",700,700);
131   c1->cd();
132   
133   TView *v = new TView(1);
134   v->SetRange(-430,-560,-430,430,560,1710);
135
136   c1->Clear();
137   c1->SetFillColor(1);
138   c1->SetTheta(90.);
139   c1->SetPhi(0.);
140     
141   Int_t ntracks = fTracks->GetNTracks();
142   TPolyLine3D *line = new TPolyLine3D[ntracks];
143   
144   Int_t n;
145   Float_t x[176],y[176],z[176];
146   for(Int_t j=0; j<ntracks; j++)
147     {
148       AliL3Track *track = fTracks->GetCheckedTrack(j); 
149       if(!track) continue;        
150       track->CalculateHelix();
151       GenerateHits(track,x,y,z,n);
152       TPolyMarker3D *pm = new TPolyMarker3D(n);
153       
154       for(Int_t h=0; h<n; h++)
155         pm->SetPoint(h,x[h],y[h],z[h]);
156       
157       pm->SetMarkerColor(2);
158       pm->Draw();
159       TPolyLine3D *current_line = &(line[j]);
160       current_line = new TPolyLine3D(n,x,y,z,"");
161       current_line->SetLineColor(4);
162       current_line->Draw("same");
163       
164     }
165   
166   if(fShowSlice>=0)
167     {
168       TPolyMarker3D *pm = LoadDigits();
169       pm->SetMarkerColor(2);
170       pm->Draw("same");
171     }
172   
173   cout<<"Displaying...."<<endl;
174   fGeom->Draw("same");
175   //c1->x3d();
176 }
177