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