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