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