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