9e65235777c29cd7a5ae6c2cddac1e83664dc33a
[u/mrichter/AliRoot.git] / HLT / src / AliL3Display.cxx
1 //$Id$
2
3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4 //*-- Copyright &copy ASV 
5
6 #include <TCanvas.h>
7 #include <TView.h>
8 #include <TPolyMarker3D.h>
9 #include <TPolyLine3D.h>
10 #include <TH2.h>
11 #include <TTree.h>
12 #include <TNode.h>
13 #include <TGeometry.h>
14 #include <TShape.h>
15 #include <TParticle.h>
16 #include <TFile.h>
17
18 #include "AliL3Display.h"
19 #ifdef use_aliroot
20 #include "AliRun.h"
21 #include "AliSimDigits.h"
22 #include "AliTPCParam.h"
23 #endif
24 #include "AliL3Transform.h"
25 #include "AliL3Track.h"
26 #include "AliL3TrackArray.h"
27 #include "AliL3SpacePointData.h"
28 #include "AliL3MemHandler.h"
29 #include "AliL3Logging.h"
30
31
32 //_____________________________________________________________
33 // AliL3Display
34 //
35 // Simple display class for the Level3 tracker.
36
37 ClassImp(AliL3Display)
38
39 AliL3Display::AliL3Display()
40 {
41   fGeom = NULL;
42   fTracks = NULL;
43 }
44
45 AliL3Display::AliL3Display(Int_t *slice,Char_t *gfile)
46 {
47   //Ctor. Specify which slices you want to look at.
48
49   TFile *file = new TFile(gfile);
50   if(!file) printf("NO FILE\n");
51   if(!file->IsOpen())
52     LOG(AliL3Log::kError,"AliL3Display::AliL3Display","File Open")
53       <<"Geometry file " << gfile << " does not exist"<<ENDLOG;
54   
55   fGeom = (TGeometry*)file->Get("AliceGeom");
56   fMinSlice = slice[0];
57   fMaxSlice = slice[1];
58
59   file->Close();
60   delete file;
61 }
62
63 AliL3Display::~AliL3Display()
64 {
65
66   if(fTracks)
67     delete fTracks;
68 }
69
70 void AliL3Display::Setup(Char_t *trackfile,Char_t *path)
71 {
72   //Read in the hit and track information from produced files.
73   
74   AliL3Transform::Init(path);
75   Char_t fname[256];
76   AliL3MemHandler *clusterfile[36][6];
77   for(Int_t s=fMinSlice; s<=fMaxSlice; s++)
78     {
79       for(Int_t p=0; p<6; p++)
80         {
81           clusterfile[s][p] = new AliL3MemHandler();
82           sprintf(fname,"%spoints_%d_%d.raw",path,s,p);
83           if(!clusterfile[s][p]->SetBinaryInput(fname))
84             {
85               LOG(AliL3Log::kError,"AliL3Evaluation::Setup","File Open")
86                 <<"Inputfile "<<fname<<" does not exist"<<ENDLOG; 
87               delete clusterfile[s][p];
88               clusterfile[s][p] = 0; 
89               continue;
90             }
91           fClusters[s][p] = (AliL3SpacePointData*)clusterfile[s][p]->Allocate();
92           clusterfile[s][p]->Binary2Memory(fNcl[s][p],fClusters[s][p]);
93           clusterfile[s][p]->CloseBinaryInput();
94         }
95     }
96   
97   
98   AliL3MemHandler *tfile = new AliL3MemHandler();
99   if(!tfile->SetBinaryInput(trackfile))
100     {
101       LOG(AliL3Log::kError,"AliL3Evaluation::Setup","File Open")
102         <<"Inputfile "<<trackfile<<" does not exist"<<ENDLOG; 
103       return;
104     }
105   fTracks = new AliL3TrackArray();
106   tfile->Binary2TrackArray(fTracks);
107   tfile->CloseBinaryInput();
108   delete tfile;
109
110 }
111
112 void AliL3Display::DisplayTracks(Int_t min_hits,Bool_t x3don,Float_t thr)
113 {
114   //Display the found tracks.
115
116   TCanvas *c1 = new TCanvas("c1","",700,700);
117   c1->cd();
118   
119   TView *v = new TView(1);
120   v->SetRange(-430,-560,-430,430,560,1710);
121   c1->Clear();
122   c1->SetFillColor(1);
123   c1->SetTheta(45.);
124   c1->SetPhi(0.);
125     
126   Int_t ntracks = fTracks->GetNTracks();
127   TPolyLine3D *line = new TPolyLine3D[ntracks];
128   Float_t xcl[176];
129   Float_t ycl[176];
130   Float_t zcl[176];
131   
132   for(Int_t j=0; j<ntracks; j++)
133     {
134       AliL3Track *gtrack = fTracks->GetCheckedTrack(j); 
135       if(!gtrack) continue;
136       if(gtrack->GetPt()<thr) continue;        
137       Int_t nHits = gtrack->GetNHits();
138       UInt_t *hitnum = gtrack->GetHitNumbers();
139       if(nHits < min_hits) continue;
140       TPolyMarker3D *pm = new TPolyMarker3D(nHits);
141       Int_t hitcount=0;
142       for(Int_t h=0; h<nHits; h++)
143         {
144           UInt_t id=hitnum[h];
145           Int_t slice = (id>>25) & 0x7f;
146           Int_t patch = (id>>22) & 0x7;
147           UInt_t pos = id&0x3fffff;           
148           AliL3SpacePointData *points = fClusters[slice][patch];
149           if(slice < fMinSlice || slice > fMaxSlice)
150             continue;
151
152           if(!points) {
153             LOG(AliL3Log::kError,"AliL3Display::DisplayTracks","Clusterarray")
154               <<"No points at slice "<<slice<<" patch "<<patch<<" pos "<<pos<<ENDLOG;
155             continue;
156           }
157           if(pos>=fNcl[slice][patch]) {printf("Error \n"); continue;}
158           Float_t xyz_tmp[3];
159           xyz_tmp[0] = points[pos].fX;
160           xyz_tmp[1] = points[pos].fY;
161           xyz_tmp[2] = points[pos].fZ;
162                   
163           xcl[h] = xyz_tmp[0];
164           ycl[h] = xyz_tmp[1];
165           zcl[h] = xyz_tmp[2];
166           
167           pm->SetPoint(h,xcl[h],ycl[h],zcl[h]);
168           hitcount++;
169         }
170       if(hitcount==0) continue;
171       pm->SetMarkerColor(2);
172       pm->Draw();
173       TPolyLine3D *current_line = &(line[j]);
174       current_line = new TPolyLine3D(nHits,xcl,ycl,zcl,"");
175       
176       current_line->SetLineColor(4);
177       current_line->Draw("same");
178             
179     }
180   
181   //Take this if you want black&white display for printing.
182   Char_t fname[256];
183   Int_t i;
184   Int_t color = 1;
185   c1->SetFillColor(10);
186   for(i=0; i<10; i++)
187     {
188       sprintf(fname,"LS0%d",i);
189       fGeom->GetNode(fname)->SetLineColor(color);
190       sprintf(fname,"US0%d",i);
191       fGeom->GetNode(fname)->SetLineColor(color);
192     }
193   for(i=10; i<18; i++)
194     {
195       sprintf(fname,"LS%d",i);
196       fGeom->GetNode(fname)->SetLineColor(color);
197       sprintf(fname,"US%d",i);
198       fGeom->GetNode(fname)->SetLineColor(color);
199     }
200   
201   fGeom->Draw("same");
202   
203   if(x3don) c1->x3d();
204   
205 }
206
207 void AliL3Display::DisplayClusters(Bool_t x3don)
208 {
209   //Display all clusters.
210   
211   TCanvas *c1 = new TCanvas("c1","",700,700);
212   c1->cd();
213
214   TView *v = new TView(1);
215   v->SetRange(-430,-560,-430,430,560,1710);
216   c1->Clear();
217   c1->SetFillColor(1);
218   c1->SetTheta(90.);
219   c1->SetPhi(0.);
220   
221   for(Int_t s=fMinSlice; s<=fMaxSlice; s++)
222     {
223       for(Int_t p=0;p<6;p++)
224         {
225           AliL3SpacePointData *points = fClusters[s][p];
226           if(!points) continue;
227           Int_t npoints = fNcl[s][p];
228           TPolyMarker3D *pm = new TPolyMarker3D(npoints);
229           
230           Float_t xyz[3];
231           for(Int_t i=0; i<npoints; i++)
232             {
233               
234               xyz[0] = points[i].fX;
235               xyz[1] = points[i].fY;
236               xyz[2] = points[i].fZ;
237               
238               pm->SetPoint(i,xyz[0],xyz[1],xyz[2]); 
239               
240             }
241           pm->SetMarkerColor(2);
242           pm->Draw("");
243         }
244     }
245   fGeom->Draw("same");
246   
247   if(x3don) c1->x3d(); 
248 }
249
250
251 void AliL3Display::DisplayAll(Int_t min_hits,Bool_t x3don)
252 {
253   //Display tracks & all hits.
254
255   TCanvas *c1 = new TCanvas("c1","",700,700);
256   c1->cd();
257   TView *v = new TView(1);
258   v->SetRange(-430,-560,-430,430,560,1710);
259   c1->Clear();
260   c1->SetFillColor(1);
261   c1->SetTheta(90.);
262   c1->SetPhi(0.);
263   
264   for(Int_t s=fMinSlice; s<=fMaxSlice; s++)
265     {
266       for(Int_t p=0;p<6;p++)
267         {
268           AliL3SpacePointData *points = fClusters[s][p];
269           if(!points) continue;
270           Int_t npoints = fNcl[s][p];
271           TPolyMarker3D *pm = new TPolyMarker3D(npoints);
272           
273           Float_t xyz[3];
274           for(Int_t i=0; i<npoints; i++){
275             xyz[0] = points[i].fX;
276             xyz[1] = points[i].fY;
277             xyz[2] = points[i].fZ;
278
279             pm->SetPoint(i,xyz[0],xyz[1],xyz[2]); 
280             
281           }
282           pm->SetMarkerColor(2);
283           pm->Draw("");
284         }
285     }
286   
287   Int_t ntracks = fTracks->GetNTracks();
288   TPolyLine3D *line = new TPolyLine3D[ntracks];
289   Float_t xcl[176];
290   Float_t ycl[176];
291   Float_t zcl[176];
292   
293   for(Int_t j=0; j<ntracks; j++)
294     {
295       AliL3Track *gtrack = fTracks->GetCheckedTrack(j); 
296       if(!gtrack) continue;        
297       Int_t nHits = gtrack->GetNHits();
298       UInt_t *hitnum = gtrack->GetHitNumbers();
299       if(nHits < min_hits) continue;
300       TPolyMarker3D *pm = new TPolyMarker3D(nHits);
301       Int_t hitcount=0;
302       for(Int_t h=0; h<nHits; h++)
303         {
304           UInt_t id=hitnum[h];
305           Int_t slice = (id>>25) & 0x7f;
306           Int_t patch = (id>>22) & 0x7;
307           UInt_t pos = id&0x3fffff;           
308           if(slice < fMinSlice || slice > fMaxSlice)
309             continue;
310           
311           AliL3SpacePointData *points = fClusters[slice][patch];
312           if(!points) {
313             LOG(AliL3Log::kError,"AliL3Display::DisplayTracks","Clusterarray")
314               <<"No points at slice "<<slice<<" patch "<<patch<<" pos "<<pos<<ENDLOG;
315             continue;
316           }
317           if(pos>=fNcl[slice][patch]) {printf("Error \n"); continue;}
318           xcl[h] = points[pos].fX;
319           ycl[h] = points[pos].fY;
320           zcl[h] = points[pos].fZ;
321           pm->SetPoint(h,xcl[h],ycl[h],zcl[h]);
322           hitcount++;
323         }
324       if(hitcount==0) continue;
325       pm->SetMarkerColor(3);
326       pm->Draw();
327       TPolyLine3D *current_line = &(line[j]);
328       current_line = new TPolyLine3D(nHits,xcl,ycl,zcl,"");
329       current_line->SetLineColor(4);
330       current_line->SetLineWidth(2);
331       current_line->Draw("same");
332     }
333   
334   Char_t fname[256];
335   Int_t i;
336   Int_t color = 1;
337   c1->SetFillColor(10);
338   for(i=0; i<10; i++)
339     {
340       sprintf(fname,"LS0%d",i);
341       fGeom->GetNode(fname)->SetLineColor(color);
342       sprintf(fname,"US0%d",i);
343       fGeom->GetNode(fname)->SetLineColor(color);
344     }
345   for(i=10; i<18; i++)
346     {
347       sprintf(fname,"LS%d",i);
348       fGeom->GetNode(fname)->SetLineColor(color);
349       sprintf(fname,"US%d",i);
350       fGeom->GetNode(fname)->SetLineColor(color);
351     }
352     
353   fGeom->Draw("same");
354   
355   if(x3don) c1->x3d();
356 }
357
358 void AliL3Display::DisplayClusterRow(Int_t slice,Int_t padrow,Char_t *digitsFile,Char_t *type)
359 {
360   //Display the found clusters on this row together with the raw data.
361   
362 #ifdef use_aliroot
363   TFile *file = new TFile(digitsFile);
364   AliTPCParam *param = (AliTPCParam*)file->Get("75x40_100x60");
365   TTree *TD=(TTree*)file->Get("TreeD_75x40_100x60_0");
366   AliSimDigits da, *digits=&da;
367   TD->GetBranch("Segment")->SetAddress(&digits); //Return pointer to branch segment.
368   
369   Int_t sector,row;
370   AliL3Transform::Slice2Sector(slice,padrow,sector,row);
371   Int_t npads = param->GetNPads(sector,row);
372   Int_t ntimes = param->GetMaxTBin();
373   TH2F *histdig = new TH2F("histdig","",npads,0,npads-1,ntimes,0,ntimes-1);
374   TH2F *histfast = new TH2F("histfast","",npads,0,npads-1,ntimes,0,ntimes-1);
375   TH2F *histpart = new TH2F("histpart","",npads,0,npads-1,ntimes,0,ntimes-1);
376
377   
378   Int_t sectors_by_rows=(Int_t)TD->GetEntries();
379   Int_t i;
380   for (i=0; i<sectors_by_rows; i++) {
381     if (!TD->GetEvent(i)) continue;
382     Int_t sec,ro;
383     param->AdjustSectorRow(digits->GetID(),sec,ro);
384     
385     if(sec != sector) continue;
386     if(ro < row) continue;
387     if(ro != row) break;
388     printf("sector %d row %d\n",sec,ro);
389     digits->First();
390     while (digits->Next()) {
391       Int_t it=digits->CurrentRow(), ip=digits->CurrentColumn();
392       Short_t dig = digits->GetDigit(it,ip);
393       if(dig<=param->GetZeroSup()) continue;
394       /*
395       if(it < param->GetMaxTBin()-1 && it > 0)
396         if(digits->GetDigit(it+1,ip) <= param->GetZeroSup()
397            && digits->GetDigit(it-1,ip) <= param->GetZeroSup())
398           continue;
399       */
400       histdig->Fill(ip,it,dig);
401     }
402   }
403   
404   /*file->cd();
405   AliRun *gAlice = (AliRun*)file->Get("gAlice");
406   gAlice->GetEvent(0);
407   TClonesArray *fParticles=gAlice->Particles(); 
408   TParticle *part = (TParticle*)fParticles->UncheckedAt(0);
409   AliL3Evaluate *eval = new AliL3Evaluate();
410   Float_t xyz_cross[3];
411   */
412   
413   for(Int_t p=0;p<6;p++)
414     {
415       AliL3SpacePointData *points = fClusters[slice][p];
416       if(!points) continue;
417       
418       Int_t npoints = fNcl[slice][p];     
419       Float_t xyz[3];
420       for(Int_t i=0; i<npoints; i++)
421         {
422           if(points[i].fPadRow != padrow) continue;
423           xyz[0] = points[i].fX;
424           xyz[1] = points[i].fY;
425           xyz[2] = points[i].fZ;
426           AliL3Transform::Global2Raw(xyz,sector,row);
427           histfast->Fill(xyz[1],xyz[2],1);
428           
429           
430         }
431       
432     }
433   
434   TCanvas *c1 = new TCanvas("c1","",900,900);
435   c1->cd();
436   histdig->Draw();
437   histfast->SetMarkerColor(2);
438   histfast->SetMarkerStyle(4);
439   histpart->SetMarkerColor(2);
440   histpart->SetMarkerStyle(3);
441
442   histdig->GetXaxis()->SetTitle("Pad #");
443   histdig->GetYaxis()->SetTitle("Timebin #");
444   histdig->Draw(type);
445   histfast->Draw("psame");
446   //histpart->Draw("psame");
447
448 #endif
449   return;
450 }
451