]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/OnlineDisplay/AliHLTTPCDisplayPadRow.cxx
Jochen Thaeder: Online Display of Heidelberg tracking ws Jan07
[u/mrichter/AliRoot.git] / HLT / TPCLib / OnlineDisplay / AliHLTTPCDisplayPadRow.cxx
1 // $Id$
2
3 /** \class AliHLTTPCDisplayPadRow
4 <pre>
5 //_____________________________________________________________
6 // AliHLTTPCDisplayPadRow
7 //
8 // Display class for the HLT TPC-PadRow events.
9 </pre>
10 */
11 // Author: Jochen Thaeder <mailto:thaeder@kip.uni-heidelberg.de>
12 //*-- Copyright &copy ALICE HLT Group 
13
14 #include <TH2.h>
15 #include <TFile.h>
16 #include <TStyle.h>
17 #include <TAttText.h>
18 #include <TAxis.h>
19 #include <TCanvas.h>
20 #include <TPolyMarker3D.h>
21
22 #ifdef use_aliroot
23 #include <TClonesArray.h>
24 #include <AliRun.h>
25 #include <AliSimDigits.h>
26 #include <AliTPCParam.h>
27 #endif
28
29 #include "AliHLTStdIncludes.h"
30 #include "AliHLTTPCDefinitions.h"
31 #include "AliHLTDataTypes.h"
32 #include "AliHLTTPCSpacePointData.h"
33 #include "AliHLTTPCClusterDataFormat.h"
34 #include "AliHLTTPCLogging.h"
35 #include "AliHLTTPCTransform.h"
36 #include "AliHLTTPCDigitReaderPacked.h"
37 #include "AliHLTTPCDigitReaderRaw.h"
38
39
40 #include "AliHLTTPCDisplayMain.h"
41 #include "AliHLTTPCDisplayPadRow.h"
42 #include "AliHLTTPCDisplayPad.h"
43
44 #if __GNUC__ >= 3
45 using namespace std;
46 #endif
47
48 ClassImp(AliHLTTPCDisplayPadRow)
49
50 //____________________________________________________________________________________________________
51 AliHLTTPCDisplayPadRow::AliHLTTPCDisplayPadRow(AliHLTTPCDisplayMain* display) {
52     // constructor
53     fDisplay = display;
54
55     fNTimes = AliHLTTPCTransform::GetNTimeBins();
56     
57     fBinX[0] = 0;      
58     fBinX[1] = fDisplay->GetNPads(); 
59     fBinY[0] = 0;
60     fBinY[1] = fNTimes -1;
61     fTmpEvent = 0;         
62
63     for (Int_t ii = 0;ii < 20; ii++)
64       fpmarr[ii] = 0;
65
66     Int_t maxpads = 150;
67     Int_t padbinning = maxpads*10;
68
69     fHistraw = new TH2F("fHistraw","Selected PadRow with found Clusters;Pad #;Timebin #",maxpads,0,maxpads-1,fNTimes,0,fNTimes-1);
70     fHistrawcl = new TH1F("fHistrawcl","cvcv;ddd;kkk",padbinning,0,maxpads-1);
71
72     fHistraw->SetOption("COLZ");    
73     fHistraw->SetTitleSize(0.03);
74     fHistraw->GetXaxis()->SetLabelSize(0.03);
75     fHistraw->GetXaxis()->SetTitleSize(0.03);
76     fHistraw->GetYaxis()->SetLabelSize(0.03);
77     fHistraw->GetYaxis()->SetTitleSize(0.03);
78
79     gStyle->SetPalette(1);
80 }
81
82 //____________________________________________________________________________________________________
83 AliHLTTPCDisplayPadRow::~AliHLTTPCDisplayPadRow() {
84     // destructor     
85     if ( fHistraw ){
86         delete fHistraw;
87         fHistraw = NULL;
88     }
89     if ( fHistrawcl ){
90         delete fHistrawcl;
91         fHistrawcl = NULL;
92     }
93     for (Int_t ii=19; ii <= 0; ii--){ // try fwd
94       if ( fpmarr[ii] ){
95         delete [] fpmarr[ii];
96         fpmarr[ii] = NULL;
97       }
98     }
99 }
100
101 //____________________________________________________________________________________________________
102 void AliHLTTPCDisplayPadRow::Reset(){  
103   fHistraw->Reset();   
104   fHistrawcl->Reset(); 
105 }
106
107 //____________________________________________________________________________________________________
108 void AliHLTTPCDisplayPadRow::Save(){  
109   fDisplay->GetCanvasCharge()->SaveAs("HLT-PadRowView.eps"); 
110 }
111
112 //____________________________________________________________________________________________________
113 //void AliHLTTPCDisplayPadRow::Fill(Int_t patch, ULong_t dataBlock, ULong_t dataLen){
114 void AliHLTTPCDisplayPadRow::Fill(){
115     // Fill PadRow Histogram
116     
117 #if defined(HAVE_TPC_MAPPING)
118     AliHLTTPCDigitReaderRaw digitReader(0);
119
120     bool readValue = true;
121     Int_t rowOffset = 0;
122     
123     Int_t padRow = fDisplay->GetPadRow();
124     Int_t slice = fDisplay->GetSlicePadRow();
125
126 #if 0
127     // Initialize RAW DATA
128     Int_t firstRow = AliHLTTPCTransform::GetFirstRow(patch);
129     Int_t lastRow = AliHLTTPCTransform::GetLastRow(patch);
130
131
132     // Outer sector, patches 2, 3, 4, 5 -  start counting in patch 2 with row 0
133     if ( patch >= 2 ) rowOffset = AliHLTTPCTransform::GetFirstRow( 2 );
134
135     // Initialize block for reading packed data
136     void* tmpdataBlock = (void*) dataBlock;
137     digitReader.InitBlock(tmpdataBlock,dataLen,firstRow,lastRow,patch,slice);
138
139     readValue = digitReader.Next();
140
141     if (!readValue){    
142         LOG(AliHLTTPCLog::kError,"AliHLTTPCDisplayPadRow::Fill","Read first value") << "No value in data block" << ENDLOG;
143         return;
144     }
145 #endif
146     if ( fDisplay->GetZeroSuppression() ){
147       for (Int_t pad=0; pad < AliHLTTPCTransform::GetNPads(padRow); pad++){
148         //      for (Int_t timeBin=fDisplay->GetTimeBinMin(); timeBin <= fDisplay->GetTimeBinMax(); timeBin++){
149         for (Int_t timeBin=0; timeBin <= fDisplay->GetNTimeBins(); timeBin++){
150
151           fHistraw->Fill(pad,timeBin,fDisplay->fRawDataZeroSuppressed[padRow][pad][timeBin]);
152         } // end time
153       }  // end pad
154       
155     }  // end - if ( fDisplay->GetZeroSuppression() ){
156
157     else {
158       for (Int_t pad=0; pad < AliHLTTPCTransform::GetNPads(padRow); pad++){
159         //      for (Int_t timeBin=fDisplay->GetTimeBinMin(); timeBin <= fDisplay->GetTimeBinMax(); timeBin++){
160         for (Int_t timeBin=0; timeBin <= fDisplay->GetNTimeBins(); timeBin++){
161           fHistraw->Fill(pad,timeBin,fDisplay->fRawData[padRow][pad][timeBin]);
162         } // end time
163       }  // end pad
164     }  // end - else of if ( fDisplay->GetZeroSuppression() ){
165
166 #if 0 
167     // FILL PADROW 3D --- Initialize the colorbins
168     if ( fDisplay->Get3DSwitchPadRow() ){
169         for (UInt_t ii=0;ii < 20;ii++){
170             fbinct[ii] = 0;
171             fcolorbin[ii] = 0;
172         }
173
174         // read number of entries in colorbin
175         while ( readValue ){ 
176             
177             Int_t row = digitReader.GetRow() + rowOffset;
178             
179             if (row == padRow){    
180                 UInt_t charge = digitReader.GetSignal();
181                 
182                 for (UInt_t ii=0;ii < 19;ii++){
183                     if ( charge > (ii*15) && charge <= ((ii*15) + 15) ) fcolorbin[ii]++;
184                 }
185                 // larger than 19 * 15  
186                 if (charge > 285 ) fcolorbin[19]++;
187             }
188
189             // read next value
190             readValue = digitReader.Next();
191       
192             if(!readValue) break; //No more value
193         } 
194
195         // Initialize fpmarr[color][3*colorbin[ii]] 
196         for (Int_t ii = 0; ii < 20; ii++) {
197           if ( fpmarr[ii] ) delete[] fpmarr[ii];
198           fpmarr[ii] = new Float_t[fcolorbin[ii]*3]; 
199         }
200
201         // Rewind the raw reader and fill the polymarker3D
202         digitReader.InitBlock(tmpdataBlock,dataLen,firstRow,lastRow,patch,slice);
203         
204         readValue = digitReader.Next();
205     } // END if (fDisplay->Get3DSwitchPadRow())
206
207     // -- Fill Raw Data
208     while ( readValue ){ 
209
210         Int_t row = digitReader.GetRow() + rowOffset;
211
212         // select padrow to fill in histogramm
213         if (row == padRow){    
214             UChar_t pad = digitReader.GetPad();
215             UShort_t time = digitReader.GetTime();
216             UInt_t charge = digitReader.GetSignal();
217             Float_t xyz[3];
218             //fHistraw->Fill(pad,time,charge);
219
220             if ( fDisplay->Get3DSwitchPadRow() ) {
221                 // Transform raw coordinates to local coordinates
222                 AliHLTTPCTransform::RawHLT2Global(xyz, slice, padRow, pad, time);
223
224                 for (UInt_t ii=0;ii < 19;ii++){
225                     if ( charge > (ii*15) && charge <= ((ii*15) + 15) ){
226                         fpmarr[ii][fbinct[ii]] = xyz[0];
227                         fpmarr[ii][fbinct[ii]+1] = xyz[1];
228                         fpmarr[ii][fbinct[ii]+2] = xyz[2];
229                         fbinct[ii] += 3;
230                     }
231                 }
232                 // larger than 19 * 15
233                 if (charge > 285 ) {
234                     fpmarr[19][fbinct[19]] = xyz[0];
235                     fpmarr[19][fbinct[19]+1] = xyz[1];
236                     fpmarr[19][fbinct[19]+2] = xyz[2];
237                     fbinct[19] += 3;
238                 }
239             } // END if (fSwitch3DPadRow)
240         
241         } // END if (row == padRow){ 
242         
243         // read next value
244         readValue = digitReader.Next();
245       
246         //Check where to stop:
247         if(!readValue) break; //No more value
248     } 
249
250 #endif
251 #if 0    
252      if (fDisplay->ExistsClusterData()){
253         AliHLTTPCSpacePointData *points = fDisplay->GetSpacePointDataPointer(slice,patch);
254         if(!points) return;
255         
256         Float_t xyz[3];
257         for(Int_t i=0; i< fDisplay->GetNumberSpacePoints(slice,patch); i++){
258             xyz[0] = points[i].fX;
259             xyz[1] = points[i].fY;
260             xyz[2] = points[i].fZ;
261         
262             // select padrow to fill in histogramm
263             if (padRow == AliHLTTPCTransform::GetPadRow(xyz[0])){
264                 AliHLTTPCTransform::LocHLT2Raw(xyz, slice, padRow);
265                 fHistrawcl->Fill(xyz[1],xyz[2]);
266             }
267         }
268      } // END if (fDisplay->ExistsClusterData()){
269 #endif
270 #else //! defined(HAVE_TPC_MAPPING)
271       HLTFatal("DigitReaderRaw not available - check your build");
272 #endif //defined(HAVE_TPC_MAPPING)
273  
274 }
275
276 //____________________________________________________________________________________________________
277 void AliHLTTPCDisplayPadRow::Draw(){
278
279     fDisplay->GetCanvasPadRow()->cd();
280     fDisplay->GetCanvasPadRow()->Clear();
281
282     if (fDisplay->GetSplitPadRow()){
283         fDisplay->GetCanvasPadRow()->Divide(1,2);
284         fDisplay->GetCanvasPadRow()->cd(1);
285     }
286   
287     Char_t title[256];
288     sprintf(title,"Selected PadRow %d with found Clusters",fDisplay->GetPadRow());
289   
290     // Keep Zoom
291     if (!fDisplay->GetKeepView() || (fBinX[1]>fDisplay->GetNPads()) || (fBinY[1]>fNTimes)){
292         fBinX[0] = 0;
293         fBinX[1] = fDisplay->GetNPads();
294         fBinY[0] = 0;
295         fBinY[1] = fNTimes - 1;
296     }
297     
298     fHistraw->SetAxisRange(fBinX[0],fBinX[1]); 
299     fHistraw->SetAxisRange(fBinY[0],fBinY[1],"Y");
300     fHistraw->SetTitle(title);
301     fHistraw->SetStats(kFALSE);
302     fHistraw->Draw("COLZ");
303     
304     if ( fDisplay->ExistsClusterData() ){
305       //cout << "XX" <<  endl;
306         fHistrawcl->SetAxisRange(fBinX[0],fBinX[1]);
307         fHistrawcl->SetAxisRange(fBinY[0],fBinY[1],"Y");
308         fHistrawcl->SetStats(kFALSE);
309         fHistrawcl->SetMarkerStyle(28);
310         fHistrawcl->SetMarkerSize(2);
311         fHistrawcl->SetMarkerColor(1);
312         fHistrawcl->Draw("psame");
313     }
314     
315     if (fDisplay->GetSplitPadRow()){
316         fDisplay->GetCanvasPadRow()->cd(2);
317         fDisplay->GetPadPointer()->fHistpad2->Draw();
318     }
319     
320     fDisplay->GetCanvasPadRow()->Modified();
321     fDisplay->GetCanvasPadRow()->Update();
322     
323     // Select Pad
324     fDisplay->GetCanvasPadRow()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)","AliHLTTPCDisplayMain",(void*) fDisplay,"ExecPadEvent(Int_t,Int_t,Int_t,TObject*)");
325     // Keep Zoom
326     fDisplay->GetCanvasPadRow()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)","AliHLTTPCDisplayPadRow",(void*) this,"ExecEvent(Int_t,Int_t,Int_t,TObject*)");
327 }
328
329 //____________________________________________________________________________________________________
330 void AliHLTTPCDisplayPadRow::Draw3D(){
331     Int_t markercolor = 51;
332     
333     for (UInt_t ii=0;ii < 20;ii++){
334         if (fcolorbin[ii]> 0){
335             
336             TPolyMarker3D* pm = new  TPolyMarker3D(fcolorbin[ii], fpmarr[ii], 7 );
337             pm->SetBit(kCanDelete);
338
339             pm->SetMarkerColor(markercolor); 
340             pm->Draw(""); 
341         }
342
343         // in order to have the SetPalette(1), so called "pretty"
344         if (ii % 2 == 0 ) markercolor += 2;
345         else  markercolor += 3;
346     }
347 }
348
349 //____________________________________________________________________________________________________
350 void AliHLTTPCDisplayPadRow::ExecEvent(Int_t event, Int_t px, Int_t py, TObject *selected){
351    // Saves the Zoom Position of the Histogram 
352
353    // - Mouse down on Axis : StartPoint of Range
354    if (event == 1 && selected->InheritsFrom("TAxis"))
355        fTmpEvent = 1;
356
357    // - Mouse pressed on Axis : Real Zoom process not only click
358    else if (event == 21 && selected->InheritsFrom("TAxis") && fTmpEvent == 1)
359        fTmpEvent = 21;
360
361    // - Mouse pressed on Axis : Still pressed
362    else if (event == 21 && selected->InheritsFrom("TAxis") && fTmpEvent == 21) 
363        return;
364
365     // - Mouse up on Axis : End Point of Rangex
366    else if (event == 11 && selected->InheritsFrom("TAxis") && fTmpEvent == 21){
367        TAxis * axis = (TAxis*) selected;
368        
369        if (selected == fHistraw->GetXaxis() || selected == fHistrawcl->GetXaxis()){ 
370            fBinX[0] = axis->GetFirst() -1;
371            fBinX[1] = axis->GetLast() -1;
372        }
373        else {
374            fBinY[0] = axis->GetFirst() -1;
375            fBinY[1] = axis->GetLast() -1;
376        }
377
378        
379        //    Reset();
380 //     Fill();
381        //   Draw();
382
383        fTmpEvent = 0; 
384    }
385    else fTmpEvent = 0;
386 }