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