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