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