]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCDisplay.cxx
Acceptance data (Gines)
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCDisplay.cxx
1 // @(#) $Id$
2
3 /** \class AliHLTTPCDisplay
4 <pre>
5 //_____________________________________________________________
6 // AliHLTTPCDisplay
7 //
8 // Display class for the HLT TPC events.
9 </pre>
10 */
11 // Author: Jochen Thaeder <mailto:thaeder@kip.uni-heidelberg.de>
12 //         Anders Vestbo <mailto:vestbo@fi.uib.no>      
13 //*-- Copyright &copy ALICE HLT Group 
14
15
16 // Recent Changes:
17 // ==============
18 // - Rename and Merge of functions / Complete new arrangement in order to use the AliHLTGUI
19 // - 3D Geometry
20 //   - display padrows, cluster, tracks
21 //   - select single Tracks
22 //   - select used / unused cluster
23 // - Histogram
24 //   - display padrows
25 //   - display pads in padrows
26
27 #include "AliHLTTPCStandardIncludes.h"
28 #include <TView.h>
29 #include <TPolyMarker3D.h>
30 #include <TPolyLine3D.h>
31 #include <TH2.h>
32 #include <TTree.h>
33 #include <TNode.h>
34 #include <TGeometry.h>
35 #include <TShape.h>
36 #include <TParticle.h>
37 #include <TFile.h>
38 #include <THelix.h>
39 #include <TStyle.h>
40 #include <TGraph.h>
41 #include <TAttText.h>
42 #include <TAxis.h>
43
44
45 #ifdef use_aliroot
46 #include <TClonesArray.h>
47 #include <AliRun.h>
48 #include <AliSimDigits.h>
49 #include <AliTPCParam.h>
50 #endif
51
52 #include "AliHLTTPCLogging.h"
53 #include "AliHLTTPCDisplay.h"
54 #include "AliHLTTPCTransform.h"
55 #include "AliHLTTPCTrack.h"
56 #include "AliHLTTPCTrackArray.h"
57 #include "AliHLTTPCSpacePointData.h"
58 #include "AliHLTTPCMemHandler.h"
59 #include "AliHLTTPCDigitReaderPacked.h"
60
61 #if __GNUC__ == 3
62 using namespace std;
63 #endif
64
65 ClassImp(AliHLTTPCDisplay)
66
67 // #############################################################################
68 AliHLTTPCDisplay::AliHLTTPCDisplay(Char_t *gfile) {
69     //constructor
70     memset(fClusters,0,36*6*sizeof(AliHLTTPCSpacePointData*));
71     memset(fNcl, 0, 36*6*sizeof(UInt_t)); 
72
73     fTracks = NULL;
74     fHistrawcl = NULL;
75     fHistraw = NULL;
76     fHistpad1 = NULL;
77     fHistpad2 = NULL;
78     fHistpad3 = NULL;
79     fHistallresiduals = NULL;
80     fHistcharge = NULL;
81     fGraphresiduals = NULL;
82
83     fGeom = NULL;
84
85     fNPads = 0;
86     fNTimes = 0;
87     fMinHits = 0;
88     fPtThreshold = 0.;
89     fPad = -1;
90     fPadRow = 0;
91     fSlicePadRow = 0; 
92     fSelectTrack = -1;
93     fSelectTrackSlice = 0;
94     fSelectTrackSwitch = kFALSE;
95     fSelectCluster = 0;
96
97     fMinSlice = 0;
98     fMaxSlice = 35;
99     fSlicePair = kFALSE;
100
101     SetSliceArray();
102
103     fBackColor = 1; 
104     fLineColor = 0;
105
106     fSwitch3DCluster = kFALSE;
107     fSwitch3DTracks = kFALSE;
108     fSwitch3DPadRow = kFALSE;
109     fSwitch3DGeometry = kFALSE;
110
111     //ctor. Specify which slices you want to look at.
112     LoadGeometrie(gfile);
113 }
114
115
116 // #############################################################################
117 AliHLTTPCDisplay::~AliHLTTPCDisplay() {
118     //destructor
119     if(fTracks) delete fTracks;
120     fTracks = NULL;
121 }
122
123 // #############################################################################
124 Bool_t AliHLTTPCDisplay::LoadGeometrie(Char_t *gfile) {
125     if (gfile) {
126         TFile *file = TFile::Open(gfile);
127         if(!file) {
128             LOG(AliHLTTPCLog::kError,"AliHLTTPCDisplay::AliHLTTPCDisplay","File Open") <<"Geometry file " << gfile << " does not exist!"<<ENDLOG;
129             return kFALSE;
130         }
131         
132         fGeom = (TGeometry*)file->Get("AliceGeom");
133
134         file->Close();
135         delete file;
136     }
137     return kTRUE;
138 }
139
140 // #############################################################################
141 //                 SETTER
142 // #############################################################################
143 void AliHLTTPCDisplay::SetHistPadRowAxis() {
144     // Set Axis range of Histogramm, due to variable NPads per padrow
145
146     fNPads = AliHLTTPCTransform::GetNPads(fPadRow);
147     fHistrawcl->SetAxisRange(0,fNPads);
148     fHistraw->SetAxisRange(0,fNPads);
149     fHistrawcl->SetAxisRange(0,fNTimes,"Y");
150     fHistraw->SetAxisRange(0,fNTimes,"Y");
151 }
152
153 void AliHLTTPCDisplay::SetSliceArray() {
154     Int_t slice=0;
155     Int_t minSlice = fMinSlice; 
156     Int_t maxSlice = fMaxSlice; 
157     Int_t realslice = 0;
158
159     for (slice=0;slice<=35;slice++){
160         fSliceArray[slice] = kFALSE;
161     }
162
163     // Single Slice, or Range
164     if (minSlice > maxSlice) maxSlice += 17;
165         
166     for (slice=minSlice;slice<=maxSlice;slice++){
167         realslice = slice % 18;
168         fSliceArray[realslice] = kTRUE;
169         fSliceArray[realslice+18] = kTRUE;
170     }
171
172     // Pair of Slices
173     if (fSlicePair) {
174         minSlice = fMinSlice + 9;
175         maxSlice = fMaxSlice + 9;
176         
177         if (minSlice > maxSlice) maxSlice += 17;
178         
179         for (slice=minSlice;slice<=maxSlice;slice++){
180             realslice = slice % 18;
181             fSliceArray[realslice] = kTRUE;     
182             fSliceArray[realslice+18] = kTRUE;
183         }
184     }
185 }
186
187 // #############################################################################
188 //                 SETUP
189 // #############################################################################
190 void AliHLTTPCDisplay::SetupCluster(Int_t slice, Int_t patch, UInt_t nofClusters, AliHLTTPCSpacePointData* data)  {  
191
192     if (data && slice>=0 && slice<36 && patch>=0 && patch<AliHLTTPCTransform::GetNPatches()) {
193         if (fClusters[slice][patch]!=NULL) {
194             delete(fClusters[slice][patch]);
195             fClusters[slice][patch]=NULL;
196         }
197         Int_t arraysize=nofClusters*sizeof(AliHLTTPCSpacePointData);
198         fClusters[slice][patch] = (AliHLTTPCSpacePointData*)new Byte_t[arraysize];
199         if (fClusters[slice][patch]) {
200             memcpy(fClusters[slice][patch], data, arraysize);
201             fNcl[slice][patch]=nofClusters;
202         } else {
203             fNcl[slice][patch]=nofClusters;
204             LOG(AliHLTTPCLog::kError,"AliHLTTPCDisplay::SetupCluster","memory allocation") << "memory allocation failed "<<ENDLOG; 
205         }
206     } else LOG(AliHLTTPCLog::kError,"AliHLTTPCDisplay::SetupCluster","argument check") << "invalid argument "<<ENDLOG; 
207 }
208
209 // #############################################################################
210 void AliHLTTPCDisplay::SetupTracks(AliHLTTPCTrackArray *tracks) {
211     fTracks=tracks;
212
213     // Set USED cluster
214     Int_t ntracks = fTracks->GetNTracks();
215
216     for(Int_t j=0; j<ntracks; j++) {    
217         AliHLTTPCTrack *gtrack = fTracks->GetCheckedTrack(j); 
218         if(!gtrack) continue;
219
220         Int_t nHits = gtrack->GetNHits();
221         UInt_t *hitnum = gtrack->GetHitNumbers();
222
223         for(Int_t h=0; h<nHits; h++){
224           
225             UInt_t id=hitnum[h];
226             Int_t slice = (id>>25) & 0x7f;
227             Int_t patch = (id>>22) & 0x7;
228             UInt_t pos = id&0x3fffff;       
229                 
230             AliHLTTPCSpacePointData *points = fClusters[slice][patch];
231             
232             if(!points) {
233                 LOG(AliHLTTPCLog::kError,"AliHLTTPCDisplay::Draw3D","Clusterarray") <<"No points at slice "<<slice<<" patch "<<patch<<" pos "<<pos<<ENDLOG;
234                 continue;
235             }
236  
237             if(pos>=fNcl[slice][patch]) {
238                 LOG(AliHLTTPCLog::kError,"AliHLTTPCDisplay::Draw3D","Clusterarray") <<"Pos is too large: pos "<<pos <<" ncl "<<fNcl[slice][patch]<<ENDLOG;
239                 continue;
240             }
241             points[pos].fUsed = kTRUE;
242         }
243     }
244 }
245
246 // #############################################################################
247 void AliHLTTPCDisplay::SetupHist(){
248
249     Int_t maxpads = 150;
250     fNTimes = AliHLTTPCTransform::GetNTimeBins();
251     Float_t xyz[3];
252     AliHLTTPCTransform::RawHLT2Global(xyz, 0, 0, 0, 0);
253     LOG(AliHLTTPCLog::kError,"AliHLTTPCDisplay::ccc","") << "t="<< fNTimes  <<"maxZ="<<xyz[2] << "|" << xyz[0]<< "|"<< xyz[1]<< ENDLOG;
254
255     if ( fHistraw ){
256         delete fHistraw;
257         fHistraw = NULL;
258     }
259     if ( fHistrawcl ){
260         delete fHistrawcl;
261         fHistrawcl = NULL;
262     }
263
264     if ( fHistpad1 ){
265         delete fHistpad1;
266         fHistpad1 = NULL;
267     }
268
269     if ( fHistpad2 ){
270         delete fHistpad2;
271         fHistpad2 = NULL;
272     }
273
274     if ( fHistpad3 ){
275         delete fHistpad3;
276         fHistpad3 = NULL;
277     }
278
279     if ( fHistallresiduals){
280         delete fHistallresiduals;
281         fHistallresiduals = NULL;
282     }
283
284     if ( fHistcharge){
285         delete fHistcharge;
286         fHistcharge = NULL;
287     }
288
289     // Setup the histograms
290     Int_t padbinning = maxpads*10;
291     fHistraw = new TH2F("fHistraw","Selected PadRow with found Clusters;Pad #;Timebin #",maxpads,0,maxpads-1,fNTimes,0,fNTimes-1);
292     fHistrawcl = new TH1F("fHistrawcl","",padbinning,0,maxpads-1);
293     fHistpad1 = new TH1F ("fHistpad1","Selected Pad -1;Timebin #",fNTimes,0,fNTimes-1);
294     fHistpad2 = new TH1F ("fHistpad2","Selected Pad;Timebin #",fNTimes,0,fNTimes-1); 
295     fHistpad3 = new TH1F ("fHistpad3","Selected Pad +1;Timebin #",fNTimes,0,fNTimes-1);
296     fHistallresiduals = new TH1F ("fHistallresiduals","Residuals of all Tracks in selected slices;residuals",5000,0,100);
297     fHistcharge = new TH1F ("fHistcharge","Cluster distribution per charge;charge;#cluster",500,0,6000);
298
299     fHistraw->SetOption("COLZ"); 
300
301   
302
303     fHistallresiduals->SetTitleSize(0.03);
304     fHistallresiduals->GetXaxis()->SetLabelSize(0.03);
305     fHistallresiduals->GetXaxis()->SetTitleSize(0.03);
306     fHistallresiduals->GetYaxis()->SetLabelSize(0.03);
307     fHistallresiduals->GetYaxis()->SetTitleSize(0.03);
308
309     fHistcharge->SetTitleSize(0.03);
310     fHistcharge->GetXaxis()->SetLabelSize(0.03);
311     fHistcharge->GetXaxis()->SetTitleSize(0.03);
312     fHistcharge->GetYaxis()->SetLabelSize(0.03);
313     fHistcharge->GetYaxis()->SetTitleSize(0.03);
314
315     fHistraw->SetTitleSize(0.03);
316     fHistraw->GetXaxis()->SetLabelSize(0.03);
317     fHistraw->GetXaxis()->SetTitleSize(0.03);
318     fHistraw->GetYaxis()->SetLabelSize(0.03);
319     fHistraw->GetYaxis()->SetTitleSize(0.03);
320
321     fHistpad1->SetTitleSize(0.03);
322     fHistpad1->GetXaxis()->SetLabelSize(0.03);
323     fHistpad1->GetXaxis()->SetTitleSize(0.03);
324     fHistpad1->GetYaxis()->SetLabelSize(0.03);
325     fHistpad1->GetYaxis()->SetTitleSize(0.03);
326
327     fHistpad2->SetTitleSize(0.03);
328     fHistpad2->GetXaxis()->SetLabelSize(0.03);
329     fHistpad2->GetXaxis()->SetTitleSize(0.03);
330     fHistpad2->GetYaxis()->SetLabelSize(0.03);
331     fHistpad2->GetYaxis()->SetTitleSize(0.03);
332
333     fHistpad3->SetTitleSize(0.03);
334     fHistpad3->GetXaxis()->SetLabelSize(0.03);
335     fHistpad3->GetXaxis()->SetTitleSize(0.03);
336     fHistpad3->GetYaxis()->SetLabelSize(0.03);
337     fHistpad3->GetYaxis()->SetTitleSize(0.03);
338
339     gStyle->SetPalette(1);
340     
341     SetHistPadRowAxis();
342
343 }
344
345 // ####################################################################################################
346 void AliHLTTPCDisplay::FillPadRow(Int_t patch, ULong_t dataBlock, ULong_t dataLen){
347     AliHLTTPCDigitReaderPacked* fDigitReader = new AliHLTTPCDigitReaderPacked();
348     bool readValue = true;
349     Int_t rowOffset = 0;
350
351     // Initialize RAW DATA
352     Int_t firstRow = AliHLTTPCTransform::GetFirstRow(patch);
353     Int_t lastRow = AliHLTTPCTransform::GetLastRow(patch);
354
355     // Outer sector, patches 2, 3, 4, 5 -  start counting in patch 2 with row 0
356     if ( patch >= 2 ) rowOffset = AliHLTTPCTransform::GetFirstRow( 2 );
357
358     // Initialize block for reading packed data
359     void* tmpdataBlock = (void*) dataBlock;
360     fDigitReader->InitBlock(tmpdataBlock,dataLen,firstRow,lastRow);
361
362     readValue = fDigitReader->Next();
363
364     if (!readValue){    
365         LOG(AliHLTTPCLog::kError,"AliHLTTPCDisplay::FillPadRow","Read first value") << "No value in data block" << ENDLOG;
366         return;
367     }
368     
369     // FILL PADROW 3D --- Initialize the colorbins
370     if (fSwitch3DPadRow){
371         for (UInt_t ii=0;ii < 20;ii++){
372             fbinct[ii] = 0;
373             fcolorbin[ii] = 0;
374         }
375
376         // read number of entries in colorbin
377         while ( readValue ){ 
378
379             Int_t row = fDigitReader->GetRow() + rowOffset;
380             
381             if (row == fPadRow){    
382                 UInt_t charge = fDigitReader->GetSignal();
383                 
384                 for (UInt_t ii=0;ii < 19;ii++){
385                     if ( charge > (ii*21) && charge <= ((ii*21) + 21) ) fcolorbin[ii]++;
386                 }
387                 // larger than 19 * 21  
388                 if (charge > 399 ) fcolorbin[19]++;
389             }
390
391             // read next value
392             readValue = fDigitReader->Next();
393       
394             if(!readValue) break; //No more value
395         } 
396         //Initialize fpmarr[color][3*colorbin[ii]]  
397         fpmarr[0] = new Float_t[fcolorbin[0]*3]; 
398         fpmarr[1] = new Float_t[fcolorbin[1]*3]; 
399         fpmarr[2] = new Float_t[fcolorbin[2]*3]; 
400         fpmarr[3] = new Float_t[fcolorbin[3]*3]; 
401         fpmarr[4] = new Float_t[fcolorbin[4]*3];  
402         fpmarr[5] = new Float_t[fcolorbin[5]*3]; 
403         fpmarr[6] = new Float_t[fcolorbin[6]*3]; 
404         fpmarr[7] = new Float_t[fcolorbin[7]*3]; 
405         fpmarr[8] = new Float_t[fcolorbin[8]*3]; 
406         fpmarr[9] = new Float_t[fcolorbin[9]*3]; 
407         fpmarr[10] = new Float_t[fcolorbin[10]*3]; 
408         fpmarr[11] = new Float_t[fcolorbin[11]*3]; 
409         fpmarr[12] = new Float_t[fcolorbin[12]*3]; 
410         fpmarr[13] = new Float_t[fcolorbin[13]*3]; 
411         fpmarr[14] = new Float_t[fcolorbin[14]*3]; 
412         fpmarr[15] = new Float_t[fcolorbin[15]*3]; 
413         fpmarr[16] = new Float_t[fcolorbin[16]*3]; 
414         fpmarr[17] = new Float_t[fcolorbin[17]*3]; 
415         fpmarr[18] = new Float_t[fcolorbin[18]*3]; 
416         fpmarr[19] = new Float_t[fcolorbin[19]*3]; 
417         
418         // Rewind the raw reader and fill the polymarker3D
419         fDigitReader->InitBlock(tmpdataBlock,dataLen,firstRow,lastRow);
420         
421         readValue = fDigitReader->Next();
422     } // END if (fSwitch3DPadRow)
423
424     // -- Fill Raw Data
425     while ( readValue ){ 
426
427         Int_t row = fDigitReader->GetRow() + rowOffset;
428
429         // select padrow to fill in histogramm
430         if (row == fPadRow){    
431             UChar_t pad = fDigitReader->GetPad();
432             UShort_t time = fDigitReader->GetTime();
433             UInt_t charge = fDigitReader->GetSignal();
434             Float_t xyz[3];
435             fHistraw->Fill(pad,time,charge);
436
437             if (pad == (fPad-1) ) fHistpad1->Fill(time,charge);
438             if (pad == fPad) fHistpad2->Fill(time,charge);
439             if (pad == (fPad+1) ) fHistpad3->Fill(time,charge);
440
441             if (fSwitch3DPadRow) {
442                 // Transform raw coordinates to local coordinates
443                 AliHLTTPCTransform::RawHLT2Global(xyz, fSlicePadRow, fPadRow, pad, time);
444
445                 for (UInt_t ii=0;ii < 19;ii++){
446                     if ( charge > (ii*21) && charge <= ((ii*21) + 21) ){
447                         fpmarr[ii][fbinct[ii]] = xyz[0];
448                         fpmarr[ii][fbinct[ii]+1] = xyz[1];
449                         fpmarr[ii][fbinct[ii]+2] = xyz[2];
450                         fbinct[ii] += 3;
451                     }
452                 }
453                 // larger than 19 * 21
454                 if (charge > 399 ) {
455                     fpmarr[19][fbinct[19]] = xyz[0];
456                     fpmarr[19][fbinct[19]+1] = xyz[1];
457                     fpmarr[19][fbinct[19]+2] = xyz[2];
458                     fbinct[19] += 3;
459                 }
460             } // END if (fSwitch3DPadRow)
461         
462         }
463         
464         // read next value
465         readValue = fDigitReader->Next();
466       
467         //Check where to stop:
468         if(!readValue) break; //No more value
469     } 
470     
471     if ( fDigitReader )
472         delete fDigitReader;
473     fDigitReader = NULL;
474
475     AliHLTTPCSpacePointData *points = fClusters[fSlicePadRow][patch];
476     if(!points) return;
477     Int_t npoints = fNcl[fSlicePadRow][patch];
478     
479     Float_t xyz[3];
480     for(Int_t i=0; i<npoints; i++){
481         xyz[0] = points[i].fX;
482         xyz[1] = points[i].fY;
483         xyz[2] = points[i].fZ;
484         
485         Int_t clrow = AliHLTTPCTransform::GetPadRow(xyz[0]);
486         // select padrow to fill in histogramm
487         if (clrow == fPadRow){
488             AliHLTTPCTransform::LocHLT2Raw(xyz, fSlicePadRow, fPadRow);
489             fHistrawcl->Fill(xyz[1],xyz[2]);
490         }
491     }
492 }
493
494
495 // #############################################################################
496 void AliHLTTPCDisplay::ResetHistPadRow(){  
497     fHistraw->Reset();   
498     fHistrawcl->Reset(); 
499     fHistpad1->Reset(); 
500     fHistpad2->Reset();  
501     fHistpad3->Reset(); 
502 }
503
504 // #############################################################################
505 void AliHLTTPCDisplay::ResetHistResiduals(){  
506     fHistallresiduals->Reset();
507 }
508
509 // #############################################################################
510 void AliHLTTPCDisplay::ResetHistCharge(){  
511     fHistcharge->Reset();
512 }
513
514
515 // #############################################################################
516 //                 DRAWER
517 // #############################################################################
518 void AliHLTTPCDisplay::DrawGeomSector(Int_t sector) {  
519   Char_t fname[256];
520   Int_t realsector = sector;// % 18;
521   
522   if (realsector < 10){
523     sprintf(fname,"LS0%d",realsector);
524     fGeom->GetNode(fname)->SetLineColor(fLineColor);
525     fGeom->GetNode(fname)->Draw("same");
526     sprintf(fname,"US0%d",realsector);
527     fGeom->GetNode(fname)->SetLineColor(fLineColor); 
528     fGeom->GetNode(fname)->Draw("same");
529   }
530   else {
531     sprintf(fname,"LS%d",realsector);
532     fGeom->GetNode(fname)->SetLineColor(fLineColor);
533     fGeom->GetNode(fname)->Draw("same");
534     sprintf(fname,"US%d",realsector);
535     fGeom->GetNode(fname)->SetLineColor(fLineColor); 
536     fGeom->GetNode(fname)->Draw("same");
537   }   
538 }
539 // #############################################################################
540 void AliHLTTPCDisplay::DrawHistPadRow(){  
541     Char_t title[256];
542     sprintf(title,"Selected PadRow %d with found Clusters",fPadRow);
543
544     fHistraw->SetTitle(title);
545     fHistraw->SetStats(kFALSE);
546     fHistraw->Draw("COLZ");
547
548     fHistrawcl->SetStats(kFALSE);
549     fHistrawcl->SetMarkerStyle(28);
550     fHistrawcl->SetMarkerSize(2);
551     fHistrawcl->SetMarkerColor(1);
552     fHistrawcl->Draw("psame");
553 }
554
555 // #############################################################################
556 void AliHLTTPCDisplay::DrawHistPad1(){  
557     Char_t title[256];
558     sprintf(title,"Selected Pad %d",fPad -1);
559     fHistpad1->SetStats(kFALSE);
560     fHistpad1->SetTitle(title);
561     fHistpad1->Draw();
562 }
563
564 // #############################################################################
565 void AliHLTTPCDisplay::DrawHistPad2(){  
566     Char_t title[256];
567     sprintf(title,"Selected Pad %d",fPad);
568
569     fHistpad2->SetStats(kFALSE);
570     fHistpad2->SetTitle(title);
571     fHistpad2->Draw();
572 }
573
574 // #############################################################################
575 void AliHLTTPCDisplay::DrawHistPad3(){  
576     Char_t title[256];
577     sprintf(title,"Selected Pad %d",fPad +1);
578
579     fHistpad3->SetStats(kFALSE);
580     fHistpad3->SetTitle(title);
581     fHistpad3->Draw();
582 }
583
584 // #############################################################################
585 void AliHLTTPCDisplay::DrawHistResiduals(){  
586     if (fSwitch3DTracks){
587     
588         // Residual histogram for 1 track
589         if (fSelectTrackSwitch){
590             Char_t title[256];
591             sprintf(title,"Residuals of Track %d in Slice %d",fSelectTrack, fSelectTrackSlice );
592          
593 //          fHistresiduals->SetMarkerStyle(2);
594 //          fHistresiduals->SetStats(kFALSE);
595 //          fHistresiduals->SetTitle(title);
596 //          fHistresiduals->Draw("p");
597             fGraphresiduals->SetTitle(title);   
598             fGraphresiduals->GetXaxis()->SetTitle("z"); 
599             fGraphresiduals->GetYaxis()->SetTitle("residuals");
600             fGraphresiduals->Draw("A*");
601             
602         }
603         // Global residuals histogram
604         else{
605             fHistallresiduals->SetStats(kFALSE);
606             fHistallresiduals->Draw();
607         }
608     }
609 }
610
611 // #############################################################################
612 void AliHLTTPCDisplay::DrawHistCharge(){  
613     if (fSwitch3DCluster){
614 //      fHistcharge->SetStats(kFALSE);
615         fHistcharge->Draw();
616     }
617 }
618
619 // #############################################################################
620 void AliHLTTPCDisplay::Draw3D(){        
621     
622     TView *v = new TView(1);
623     v->SetRange(-800,-800,-800,800,800,800);
624
625     Float_t* etaRange = NULL;   // ------  STILL TO FIX
626     
627
628     //--------------------------------------------------------------------------------------------
629     // DRAW 3D CLUSTER
630     //--------------------------------------------------------------------------------------------
631     if (fSwitch3DCluster){
632         for (Int_t slice=0; slice <= 35; slice++){
633
634             UInt_t maxCharge = 0;
635             Float_t maxXYZ[3];
636             UChar_t padrow;
637
638             if (!fSliceArray[slice]) continue;
639             
640             for(Int_t p=0;p<6;p++){
641
642                 AliHLTTPCSpacePointData *points = fClusters[slice][p];
643                 if(!points) continue;
644                 Int_t npoints = fNcl[slice][p];
645                 TPolyMarker3D *pm = new TPolyMarker3D(npoints);
646         
647                 Float_t xyz[3];
648                 for(Int_t i=0; i<npoints; i++){
649                     // Used  cluster only
650                     if (fSelectCluster == 1  && points[i].fUsed == kFALSE) continue; 
651                     // Unused cluster only
652                     if (fSelectCluster == 2  && points[i].fUsed == kTRUE) continue; 
653                     
654                     xyz[0] = points[i].fX;
655                     xyz[1] = points[i].fY;
656                     xyz[2] = points[i].fZ;
657                     
658                     if ( etaRange ){              
659                         // Do this before the transform, because the tracker also uses
660                         // local coordinates when using this limit to determine 
661                         // which clusters to use for tracking
662                         Double_t pointEta = AliHLTTPCTransform::GetEta( xyz );
663                         if ( pointEta<etaRange[0] || pointEta>etaRange[1] )
664                             continue;
665                     }
666                     AliHLTTPCTransform::Local2Global(xyz,slice);
667                     
668                     pm->SetPoint(i,xyz[0],xyz[1],xyz[2]);
669                     
670                     // Fill Charge Histogram
671                     fHistcharge->Fill(points[i].fCharge);
672                     if (points[i].fCharge > maxCharge ){
673                         maxCharge = points[i].fCharge; 
674                         maxXYZ[0] = points[i].fX;
675                         maxXYZ[1] = points[i].fY;
676                         maxXYZ[2] = points[i].fZ;
677                         padrow = points[i].fPadRow;
678                     }
679                     
680                 }
681                 pm->SetMarkerSize(4);
682                 pm->SetMarkerColor(2); 
683                 pm->Draw("");
684             }       
685         
686             LOG(AliHLTTPCLog::kError,"AliHLTTPCDisplay::CHARGE","")<< "MAX CHARGE =" <<  maxCharge <<  "  slice=" << slice 
687                                                                    << " z=" << maxXYZ[0]<< " y=" << maxXYZ[1]<< " z=" << maxXYZ[2]
688
689                                                                    << ENDLOG;
690
691
692         }
693     }   // END - DRAW 3D CLUSTER 
694
695     //--------------------------------------------------------------------------------------------
696     // DRAW 3D TRACKS
697     //--------------------------------------------------------------------------------------------
698     if (fSwitch3DTracks){
699
700         Int_t ntracks = fTracks->GetNTracks();
701
702         TPolyLine3D *line = new TPolyLine3D[ntracks];
703         TPolyLine3D *lineT = new TPolyLine3D[ntracks];
704         Float_t xCl[176];
705         Float_t yCl[176];
706         Float_t zCl[176];
707
708         Float_t xT[176];
709         Float_t yT[176];
710         Float_t zT[176];
711
712         Float_t res[176];
713
714         Int_t trackcounter = 0;
715
716         for(Int_t j=0; j<ntracks; j++) {        
717
718             AliHLTTPCTrack *gtrack = fTracks->GetCheckedTrack(j); 
719             if(!gtrack) continue;
720
721             Int_t nHits = gtrack->GetNHits();
722             UInt_t *hitnum = gtrack->GetHitNumbers();
723             Int_t hitcount=0;   
724
725             Bool_t nexttrack = kFALSE;
726
727             TPolyMarker3D *pm = new TPolyMarker3D(nHits,7);
728             TPolyMarker3D *pmT = new TPolyMarker3D(nHits,7);
729
730             TPolyMarker3D *pmL = new TPolyMarker3D(1,2);
731             TPolyMarker3D *pmF = new TPolyMarker3D(1,2);
732
733             Double_t lambda = 0.;  // dipAngle lambda
734             Double_t r = 0.;       // radius
735             Double_t kappa = 0.;   // curvature = 1/R , signed
736             Double_t xyz0[3];      // startingpoint of track
737             Double_t xyzT[3];      // point on track
738             Double_t xyzC[3];      // cluster
739             Double_t s = 0.;       // length of track
740             Double_t phi0 = 0.;    // azimuthal angle of startingpoint, with respect to helix axis
741             Double_t bfield = 0;   // BField
742
743             Double_t xyzL[3];      // lastpoint of track
744             Double_t xyzF[3];      // firstpoint of track
745
746             Double_t maxZ = 0;     // range of the histogram
747             Double_t minZ =99999.; // range of the histogram
748
749             for(Int_t h=0; h<nHits; h++){
750
751                 UInt_t id=hitnum[h];
752                 Int_t slice = (id>>25) & 0x7f;
753                 Int_t patch = (id>>22) & 0x7;
754                 UInt_t pos = id&0x3fffff; 
755
756                 // select if slice should be displayed or not
757                 if (!fSliceArray[slice]) {      
758                     nexttrack = kTRUE;
759                     break;         
760                 }
761                 
762                 // select Single Track
763                 if (fSelectTrackSwitch){
764                     if(slice != fSelectTrackSlice) {
765                         nexttrack = kTRUE;
766                         break;
767                     }
768
769                     if (trackcounter != fSelectTrack && h==0){
770                         trackcounter++;  
771                         nexttrack = kTRUE;
772                         break;
773                     }
774
775                     trackcounter++;
776                 }
777
778                 // --> in the hit loop because of 'trackcounter++', otherwise wrong single track in slice will be selected
779                 if((fPtThreshold > 0) && (gtrack->GetPt()< fPtThreshold)) {     
780                     nexttrack = kTRUE;
781                     break;
782                 }
783                 
784                 // --> in the hit loop because of 'trackcounter++', otherwise wrong single track in slice will be selected
785                 if(nHits < fMinHits) {  
786                     nexttrack = kTRUE;
787                     break;
788                 }
789
790                 AliHLTTPCSpacePointData *points = fClusters[slice][patch];
791                 
792                 if(!points) {
793                     LOG(AliHLTTPCLog::kError,"AliHLTTPCDisplay::Draw3D","Clusterarray") <<"No points at slice "<<slice<<" patch "<<patch
794                                                                                         <<" pos "<<pos<<ENDLOG;
795                     continue;
796                 }
797  
798                 if(pos>=fNcl[slice][patch]) {
799                     LOG(AliHLTTPCLog::kError,"AliHLTTPCDisplay::Draw3D","Clusterarray") <<"Pos is too large: pos "<<pos <<" ncl "
800                                                                                         <<fNcl[slice][patch]<<ENDLOG;
801                     continue;
802                 }
803
804                 // set the data for the residuals
805                 if (h == 0){
806                     // -> Curvature / Radius / Phi0
807                     //kappa = gtrack->GetKappa(); 
808                     //r = gtrack->GetRadius();
809                     //phi0 = gtrack->GetPhi0();
810                     //bfield = AliHLTTPCTransform::GetBFieldValue();
811                     
812                     lambda = atan( gtrack->GetTgl() ); 
813                     
814                     bfield = 0.0029980 * 0.4; // KORRIGIERE B für =0.4 T Feld
815                     
816                     xyz0[0] = gtrack->GetFirstPointX();
817                     xyz0[1] = gtrack->GetFirstPointY();
818                     xyz0[2] = gtrack->GetFirstPointZ();
819                     
820                     xyzF[0] = gtrack->GetFirstPointX();
821                     xyzF[1] = gtrack->GetFirstPointY();
822                     xyzF[2] = gtrack->GetFirstPointZ();
823
824                     xyzL[0] = gtrack->GetLastPointX();
825                     xyzL[1] = gtrack->GetLastPointY();
826                     xyzL[2] = gtrack->GetLastPointZ();
827
828                     pmL->SetPoint(0,xyzL[0],xyzL[1],xyzL[2]);
829                     pmF->SetPoint(0,xyzF[0],xyzF[1],xyzF[2]);
830
831                     phi0 = gtrack->GetPsi() + (gtrack->GetCharge() * AliHLTTPCTransform::PiHalf() ); 
832                     
833                     if (bfield != 0.){
834                         r = gtrack->GetPt() / bfield; 
835                         kappa = - gtrack->GetCharge() * 1. / r;
836                     }
837                     else {
838                         r = 999999; // just infinity
839                         kappa = 0;
840                     }
841
842                     //Write Track Parameters for single track
843                     if (fSelectTrackSwitch){
844                         fTrackParam.id = trackcounter - 1;
845                         fTrackParam.nHits = nHits;
846                         fTrackParam.charge = gtrack->GetCharge();
847                         fTrackParam.lambda = lambda;
848                         fTrackParam.kappa = kappa;
849                         fTrackParam.radius = r;
850                         fTrackParam.slice = slice;
851                         fTrackParam.phi0 = phi0;
852                         fTrackParam.pt = gtrack->GetPt();
853                         fTrackParam.bfield = bfield;
854                         fTrackParam.xyzF[0] = gtrack->GetFirstPointX();
855                         fTrackParam.xyzF[1] = gtrack->GetFirstPointY();
856                         fTrackParam.xyzF[2] = gtrack->GetFirstPointZ();
857                         fTrackParam.xyzL[0] = gtrack->GetLastPointX();
858                         fTrackParam.xyzL[1] = gtrack->GetLastPointY();
859                         fTrackParam.xyzL[2] = gtrack->GetLastPointZ();
860                         fTrackParam.psi = gtrack->GetPsi();
861                     }
862                 }
863
864
865                 Float_t xyzCtmp[3];    // cluster tmp
866
867                 xyzCtmp[0] = points[pos].fX;
868                 xyzCtmp[1] = points[pos].fY;
869                 xyzCtmp[2] = points[pos].fZ;
870
871                 AliHLTTPCTransform::Local2Global(xyzCtmp,slice);
872                     
873                 xCl[h] = xyzCtmp[0];
874                 yCl[h] = xyzCtmp[1];
875                 zCl[h] = xyzCtmp[2];
876
877                 // FILL POLYMARKER FOR THE ORIGINAL TRACKS
878                 pm->SetPoint(h,xCl[h],yCl[h],zCl[h]);  
879
880                 xyzC[0] = (Double_t) xyzCtmp[0];
881                 xyzC[1] = (Double_t) xyzCtmp[1];
882                 xyzC[2] = (Double_t) xyzCtmp[2];
883
884                 xyzT[2] = xyzC[2];
885
886                 //calculate length
887                 s = ( xyzT[2] - xyz0[2] ) / sin(lambda);
888
889                 // calculate the corresponding coordinates on the track
890                 xyzT[0] = xyz0[0] +  r * ( cos( phi0 + (s*kappa*cos(lambda)) ) - cos( phi0 ) );
891                 xyzT[1] = xyz0[1] +  r * ( sin( phi0 + (s*kappa*cos(lambda)) ) - sin( phi0 ) );
892
893                 Double_t deltaX = ( xyzC[0] - xyzT[0] );
894                 Double_t deltaY = ( xyzC[1] - xyzT[1] );
895                 
896                 Double_t residual = sqrt( deltaX*deltaX + deltaY*deltaY );
897                 res[h] = (Float_t) residual;
898
899                 if (maxZ < fabs(xyzT[2])) maxZ = fabs(xyzT[2]);
900                 if (minZ > fabs(xyzT[2])) minZ = fabs(xyzT[2]);
901
902                 // FILL RESIDUALS HISTOGRAM
903                 fHistallresiduals->Fill(residual);
904                 
905                 // FILL ARRAYS IN ORDER TO DRAW THE TRACKPOINTS, OUT OF THE PARAMETER
906                 xT[h] = xyzT[0];
907                 yT[h] = xyzT[1];
908                 zT[h] = xyzT[2];
909
910                 // FILL POLYMARKER FOR THE NEW TRACKS
911                 pmT->SetPoint(h,xT[h],yT[h],zT[h]);
912           
913                 hitcount++;
914             }
915
916             if(nexttrack) continue;
917             if(hitcount==0) continue;
918         
919
920             if ( fGraphresiduals){
921                 delete fGraphresiduals;
922                 fGraphresiduals = NULL;
923             }
924
925             // FILL RESIDUALS GRAPH
926             fGraphresiduals = new TGraph(nHits,zT,res);
927             fGraphresiduals->GetXaxis()->SetLabelSize(0.02);
928             fGraphresiduals->GetXaxis()->SetTitleSize(0.02);
929             fGraphresiduals->GetYaxis()->SetLabelSize(0.02);
930             fGraphresiduals->GetYaxis()->SetTitleSize(0.02);
931             
932             TPolyLine3D *currentline = &(line[j]);
933             currentline = new TPolyLine3D(nHits,xCl,yCl,zCl,"");
934             currentline->SetLineColor(4);   
935             currentline->SetLineWidth(2);
936 //          currentline->Draw("same");
937
938             TPolyLine3D *currentlineT = &(lineT[j]);
939             currentlineT = new TPolyLine3D(nHits,xT,yT,zT,"");
940             currentlineT->SetLineColor(7);   
941             currentlineT->SetLineWidth(1);
942 //          currentlineT->Draw("same");
943
944             
945             //Last Point of Track
946             pmL->SetMarkerSize(3);
947             pmL->SetMarkerColor(4); 
948             pmL->Draw();
949
950             //First Point of Track
951             pmF->SetMarkerSize(3);
952             pmF->SetMarkerColor(5); 
953             pmF->Draw();
954             
955             //Original Track 
956             pm->SetMarkerSize(4);
957             pm->SetMarkerColor(6); 
958             pm->Draw();
959
960             //New Track
961             pmT->SetMarkerSize(4);
962             pmT->SetMarkerColor(3); 
963             pmT->Draw();
964
965         } // END for tracks
966
967     }   // END - DRAW 3D Tracks
968
969     //--------------------------------------------------------------------------------------------
970     // DRAW 3D GEOMETRY
971     //--------------------------------------------------------------------------------------------
972     if (fSwitch3DGeometry){
973
974         for (Int_t slice=0; slice <= 17; slice++){
975             if (!fSliceArray[slice]) continue;
976             DrawGeomSector(slice);
977         }
978     }   // END - DRAW 3D GEOMETRY
979     
980     //--------------------------------------------------------------------------------------------
981     // DRAW 3D PadRow
982     //--------------------------------------------------------------------------------------------
983     if (fSwitch3DPadRow && fSliceArray[fSlicePadRow]){
984         Int_t markercolor = 51;
985
986         for (UInt_t ii=0;ii < 20;ii++){
987             if (fcolorbin[ii]> 0){
988                 
989                 TPolyMarker3D *pm = new TPolyMarker3D(fcolorbin[ii], fpmarr[ii], 7 );
990
991                 pm->SetMarkerColor(markercolor); 
992                 pm->Draw(""); 
993             }
994
995             // in order to have the SetPalette(1), so called "pretty"
996             if (ii % 2 == 0 ) markercolor += 2;
997             else  markercolor += 3;
998         }
999     }
1000
1001     //--------------------------------------------------------------------------------------------
1002     // DRAW 3D 
1003     //--------------------------------------------------------------------------------------------
1004     v->ZoomView(0,4);
1005     v->Draw();   
1006 }
1007
1008
1009
1010