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