Added the magnetic field as a static member of the AliL3Transform class,
[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 <TCanvas.h>
7 #include <TView.h>
8 #include <TPolyMarker3D.h>
9 #include <TPolyLine3D.h>
10 #include <TH2.h>
11 #include <TTree.h>
12 #include <TNode.h>
13 #include <TGeometry.h>
14 #include <TShape.h>
15 #include <TParticle.h>
16 #include <TFile.h>
17
18 #include "AliL3Display.h"
19 #ifdef use_aliroot
20 #include "AliRun.h"
21 #include "AliSimDigits.h"
22 #include "AliTPCParam.h"
23 #endif
24 #include "AliL3Transform.h"
25 #include "AliL3Track.h"
26 #include "AliL3TrackArray.h"
27 #include "AliL3SpacePointData.h"
28 #include "AliL3MemHandler.h"
29 #include "AliL3Logging.h"
30
31
32 //_____________________________________________________________
33 // AliL3Display
34 //
35 // Simple display class for the Level3 tracker.
36
37 ClassImp(AliL3Display)
38
39 AliL3Display::AliL3Display()
40 {
41   fGeom = NULL;
42   fTracks = NULL;
43 }
44
45 AliL3Display::AliL3Display(Int_t *slice)
46 {
47   //Ctor. Specify which slices you want to look at.
48
49   TFile *file = new TFile("$(LEVEL3)/GEO/alice.geom");
50   if(!file) printf("NO FILE\n");
51   if(!file->IsOpen())
52     LOG(AliL3Log::kError,"AliL3Display::AliL3Display","File Open")
53       <<"Geometry file alice.geom does not exist"<<ENDLOG;
54   
55   fGeom = (TGeometry*)file->Get("AliceGeom");
56   fMinSlice = slice[0];
57   fMaxSlice = slice[1];
58
59   file->Close();
60   delete file;
61 }
62
63 AliL3Display::~AliL3Display()
64 {
65
66   if(fTracks)
67     delete fTracks;
68 }
69
70 void AliL3Display::Setup(Char_t *trackfile,Char_t *path)
71 {
72   //Read in the hit and track information from produced files.
73   
74   AliL3Transform::Init(path);
75   Char_t fname[256];
76   AliL3MemHandler *clusterfile[36][6];
77   for(Int_t s=fMinSlice; s<=fMaxSlice; s++)
78     {
79       for(Int_t p=0; p<6; p++)
80         {
81           clusterfile[s][p] = new AliL3MemHandler();
82           sprintf(fname,"%spoints_%d_%d.raw",path,s,p);
83           if(!clusterfile[s][p]->SetBinaryInput(fname))
84             {
85               LOG(AliL3Log::kError,"AliL3Evaluation::Setup","File Open")
86                 <<"Inputfile "<<fname<<" does not exist"<<ENDLOG; 
87               delete clusterfile[s][p];
88               clusterfile[s][p] = 0; 
89               continue;
90             }
91           fClusters[s][p] = (AliL3SpacePointData*)clusterfile[s][p]->Allocate();
92           clusterfile[s][p]->Binary2Memory(fNcl[s][p],fClusters[s][p]);
93           clusterfile[s][p]->CloseBinaryInput();
94         }
95     }
96   
97   
98   AliL3MemHandler *tfile = new AliL3MemHandler();
99   if(!tfile->SetBinaryInput(trackfile))
100     {
101       LOG(AliL3Log::kError,"AliL3Evaluation::Setup","File Open")
102         <<"Inputfile "<<trackfile<<" does not exist"<<ENDLOG; 
103       return;
104     }
105   fTracks = new AliL3TrackArray();
106   tfile->Binary2TrackArray(fTracks);
107   tfile->CloseBinaryInput();
108   delete tfile;
109
110 }
111
112 void AliL3Display::DisplayTracks(Int_t min_hits)
113 {
114   //Display the found tracks.
115
116   TCanvas *c1 = new TCanvas("c1","",700,700);
117   c1->cd();
118   
119   TView *v = new TView(1);
120   v->SetRange(-430,-560,-430,430,560,1710);
121   
122   c1->Clear();
123   c1->SetFillColor(1);
124   c1->SetTheta(90.);
125   c1->SetPhi(0.);
126     
127   Int_t ntracks = fTracks->GetNTracks();
128   TPolyLine3D *line = new TPolyLine3D[ntracks];
129   Float_t xcl[176];
130   Float_t ycl[176];
131   Float_t zcl[176];
132   
133   for(Int_t j=0; j<ntracks; j++)
134     {
135       AliL3Track *gtrack = fTracks->GetCheckedTrack(j); 
136       if(!gtrack) continue;        
137       Int_t nHits = gtrack->GetNHits();
138       UInt_t *hitnum = gtrack->GetHitNumbers();
139       if(nHits < min_hits) continue;
140       TPolyMarker3D *pm = new TPolyMarker3D(nHits);
141       Int_t hitcount=0;
142       for(Int_t h=0; h<nHits; h++)
143         {
144           UInt_t id=hitnum[h];
145           Int_t slice = (id>>25) & 0x7f;
146           Int_t patch = (id>>22) & 0x7;
147           UInt_t pos = id&0x3fffff;           
148           AliL3SpacePointData *points = fClusters[slice][patch];
149           if(slice < fMinSlice || slice > fMaxSlice)
150             continue;
151
152           if(!points) {
153             LOG(AliL3Log::kError,"AliL3Display::DisplayTracks","Clusterarray")
154               <<"No points at slice "<<slice<<" patch "<<patch<<" pos "<<pos<<ENDLOG;
155             continue;
156           }
157           if(pos>=fNcl[slice][patch]) {printf("Error \n"); continue;}
158           Float_t xyz_tmp[3];
159           xyz_tmp[0] = points[pos].fX;
160           xyz_tmp[1] = points[pos].fY;
161           xyz_tmp[2] = points[pos].fZ;
162                   
163           xcl[h] = xyz_tmp[0];
164           ycl[h] = xyz_tmp[1];
165           zcl[h] = xyz_tmp[2];
166           
167           pm->SetPoint(h,xcl[h],ycl[h],zcl[h]);
168           hitcount++;
169         }
170       if(hitcount==0) continue;
171       pm->SetMarkerColor(2);
172       pm->Draw();
173       TPolyLine3D *current_line = &(line[j]);
174       current_line = new TPolyLine3D(nHits,xcl,ycl,zcl,"");
175       
176       current_line->SetLineColor(4);
177       current_line->Draw("same");
178             
179     }
180   /*
181   //Take this if you want black&white display for printing.
182   Char_t fname[256];
183   Int_t i;
184   Int_t color = 1;
185   c1->SetFillColor(10);
186   for(i=0; i<10; i++)
187     {
188       sprintf(fname,"LS0%d",i);
189       fGeom->GetNode(fname)->SetLineColor(color);
190       sprintf(fname,"US0%d",i);
191       fGeom->GetNode(fname)->SetLineColor(color);
192     }
193   for(i=10; i<18; i++)
194     {
195       sprintf(fname,"LS%d",i);
196       fGeom->GetNode(fname)->SetLineColor(color);
197       sprintf(fname,"US%d",i);
198       fGeom->GetNode(fname)->SetLineColor(color);
199     }
200   */
201   fGeom->Draw("same");
202   
203   c1->x3d();
204   
205 }
206
207 void AliL3Display::DisplayClusters()
208 {
209   //Display all clusters.
210   
211   TCanvas *c1 = new TCanvas("c1","",700,700);
212   c1->cd();
213   TView *v = new TView(1);
214   v->SetRange(-430,-560,-430,430,560,1710);
215   c1->Clear();
216   c1->SetFillColor(1);
217   c1->SetTheta(90.);
218   c1->SetPhi(0.);
219   
220   for(Int_t s=fMinSlice; s<=fMaxSlice; s++)
221     {
222       for(Int_t p=0;p<6;p++)
223         {
224           AliL3SpacePointData *points = fClusters[s][p];
225           if(!points) continue;
226           Int_t npoints = fNcl[s][p];
227           TPolyMarker3D *pm = new TPolyMarker3D(npoints);
228           
229           Float_t xyz[3];
230           for(Int_t i=0; i<npoints; i++)
231             {
232               
233               xyz[0] = points[i].fX;
234               xyz[1] = points[i].fY;
235               xyz[2] = points[i].fZ;
236               
237               pm->SetPoint(i,xyz[0],xyz[1],xyz[2]); 
238               
239             }
240           pm->SetMarkerColor(2);
241           pm->Draw("");
242         }
243     }
244   fGeom->Draw("same");
245   
246   c1->x3d(); 
247 }
248
249
250 void AliL3Display::DisplayAll(Int_t min_hits)
251 {
252   //Display tracks & all hits.
253
254   
255   TCanvas *c1 = new TCanvas("c1","",700,700);
256   c1->cd();
257   TView *v = new TView(1);
258   v->SetRange(-430,-560,-430,430,560,1710);
259   c1->Clear();
260   c1->SetFillColor(1);
261   c1->SetTheta(90.);
262   c1->SetPhi(0.);
263   
264   for(Int_t s=fMinSlice; s<=fMaxSlice; s++)
265     {
266       for(Int_t p=0;p<6;p++)
267         {
268           AliL3SpacePointData *points = fClusters[s][p];
269           if(!points) continue;
270           Int_t npoints = fNcl[s][p];
271           TPolyMarker3D *pm = new TPolyMarker3D(npoints);
272           
273           Float_t xyz[3];
274           for(Int_t i=0; i<npoints; i++){
275             xyz[0] = points[i].fX;
276             xyz[1] = points[i].fY;
277             xyz[2] = points[i].fZ;
278
279             pm->SetPoint(i,xyz[0],xyz[1],xyz[2]); 
280             
281           }
282           pm->SetMarkerColor(2);
283           pm->Draw("");
284         }
285     }
286   
287   Int_t ntracks = fTracks->GetNTracks();
288   TPolyLine3D *line = new TPolyLine3D[ntracks];
289   Float_t xcl[176];
290   Float_t ycl[176];
291   Float_t zcl[176];
292   
293   
294   for(Int_t j=0; j<ntracks; j++)
295     {
296       AliL3Track *gtrack = fTracks->GetCheckedTrack(j); 
297       if(!gtrack) continue;        
298       Int_t nHits = gtrack->GetNHits();
299       UInt_t *hitnum = gtrack->GetHitNumbers();
300       if(nHits < min_hits) continue;
301       TPolyMarker3D *pm = new TPolyMarker3D(nHits);
302       Int_t hitcount=0;
303       for(Int_t h=0; h<nHits; h++)
304         {
305           UInt_t id=hitnum[h];
306           Int_t slice = (id>>25) & 0x7f;
307           Int_t patch = (id>>22) & 0x7;
308           UInt_t pos = id&0x3fffff;           
309           if(slice < fMinSlice || slice > fMaxSlice)
310             continue;
311           
312           AliL3SpacePointData *points = fClusters[slice][patch];
313           if(!points) {
314             LOG(AliL3Log::kError,"AliL3Display::DisplayTracks","Clusterarray")
315               <<"No points at slice "<<slice<<" patch "<<patch<<" pos "<<pos<<ENDLOG;
316             continue;
317           }
318           if(pos>=fNcl[slice][patch]) {printf("Error \n"); continue;}
319           xcl[h] = points[pos].fX;
320           ycl[h] = points[pos].fY;
321           zcl[h] = points[pos].fZ;
322           pm->SetPoint(h,xcl[h],ycl[h],zcl[h]);
323           hitcount++;
324         }
325       if(hitcount==0) continue;
326       pm->SetMarkerColor(3);
327       pm->Draw();
328       TPolyLine3D *current_line = &(line[j]);
329       current_line = new TPolyLine3D(nHits,xcl,ycl,zcl,"");
330       current_line->SetLineColor(4);
331       current_line->SetLineWidth(2);
332       current_line->Draw("same");
333     }
334   
335   
336   Char_t fname[256];
337   Int_t i;
338   Int_t color = 1;
339   c1->SetFillColor(10);
340   for(i=0; i<10; i++)
341     {
342       sprintf(fname,"LS0%d",i);
343       fGeom->GetNode(fname)->SetLineColor(color);
344       sprintf(fname,"US0%d",i);
345       fGeom->GetNode(fname)->SetLineColor(color);
346     }
347   for(i=10; i<18; i++)
348     {
349       sprintf(fname,"LS%d",i);
350       fGeom->GetNode(fname)->SetLineColor(color);
351       sprintf(fname,"US%d",i);
352       fGeom->GetNode(fname)->SetLineColor(color);
353     }
354     
355   fGeom->Draw("same");
356   
357   c1->x3d();
358   
359 }
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