- moved AliHLTDisplay files from TPCLib to TPCLib/OnlineDisplay
[u/mrichter/AliRoot.git] / HLT / TPCLib / OnlineDisplay / AliHLTTPCDisplayCharge.cxx
1 // $Id$
2
3 /** \class AliHLTTPCDisplayCharge
4 <pre>
5 //_____________________________________________________________
6 // AliHLTTPCDisplayCharge
7 //
8 // Display class for the HLT TPC-Charge 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
21 #ifdef use_aliroot
22 #include <TClonesArray.h>
23 #include <AliRun.h>
24 #include <AliSimDigits.h>
25 #include <AliTPCParam.h>
26 #endif
27
28 #include "AliHLTStdIncludes.h"
29 #include "AliHLTTPCDefinitions.h"
30 #include "AliHLTDataTypes.h"
31 #include "AliHLTTPCSpacePointData.h"
32 #include "AliHLTTPCClusterDataFormat.h"
33 #include "AliHLTTPCLogging.h"
34 #include "AliHLTTPCTransform.h"
35 #include "AliHLTTPCDigitReaderPacked.h"
36 #include "AliHLTTPCTrack.h"
37 #include "AliHLTTPCTrackArray.h"
38
39 #include "AliHLTTPCDisplayMain.h"
40 #include "AliHLTTPCDisplayCharge.h"
41
42 #if __GNUC__ >= 3
43 using namespace std;
44 #endif
45
46 ClassImp(AliHLTTPCDisplayCharge)
47
48 //____________________________________________________________________________________________________
49 AliHLTTPCDisplayCharge::AliHLTTPCDisplayCharge(AliHLTTPCDisplayMain* display) {
50     // constructor
51     fDisplay = display;
52
53     fBinX[0] = 0;      
54     fBinX[1] = 1; 
55     fTmpEvent = 0;         
56     fMaxCharge = 0;
57
58     fHistcharge = new TH1F ("fHistcharge","Cluster distribution per charge;charge;#cluster",5000,0,30000);
59     fHistcharge->SetTitleSize(0.03);
60     fHistcharge->GetXaxis()->SetLabelSize(0.03);
61     fHistcharge->GetXaxis()->SetTitleSize(0.03);
62     fHistcharge->GetYaxis()->SetLabelSize(0.03);
63     fHistcharge->GetYaxis()->SetTitleSize(0.03);
64 }
65
66 //____________________________________________________________________________________________________
67 AliHLTTPCDisplayCharge::~AliHLTTPCDisplayCharge() {
68     // destructor   
69     if ( fHistcharge){
70         delete fHistcharge;
71         fHistcharge = NULL;
72     }
73 }
74
75 //____________________________________________________________________________________________________
76 void AliHLTTPCDisplayCharge::Reset(){  
77     fHistcharge->Reset();
78 }
79
80 //____________________________________________________________________________________________________
81 void AliHLTTPCDisplayCharge::Save(){  
82   fDisplay->GetCanvasCharge()->SaveAs("HLT-ChargeView.eps"); 
83 }
84
85 //____________________________________________________________________________________________________
86 void AliHLTTPCDisplayCharge::Fill(){  
87     // Fill Charge Histogram
88
89     Int_t maxCharge = 0;
90
91     for (Int_t slice=0; slice <= 35; slice++){
92
93         Int_t currenttrack = -1;
94
95         if (fDisplay->ExistsTrackData() && fDisplay->GetSelectTrackSwitch()) currenttrack = fDisplay->GetGlobalTrack(slice);
96                 
97         if (!fDisplay->GetDisplaySlice(slice)) continue;
98         
99         for(Int_t patch=0;patch<6;patch++){
100
101             AliHLTTPCSpacePointData *points = fDisplay->GetSpacePointDataPointer(slice,patch);
102             if(!points) continue;
103           
104             for(Int_t i=0; i< fDisplay->GetNumberSpacePoints(slice,patch); i++){
105                 // Used  cluster only
106                 if (fDisplay->GetSelectCluster() == 1  && points[i].fUsed == kFALSE) continue; 
107                 // Unused cluster only
108                 if (fDisplay->GetSelectCluster() == 2  && points[i].fUsed == kTRUE) continue; 
109
110                 // if single track is selcted draw only cluster for this track
111                 if (fDisplay->GetSelectCluster() == 1 && fDisplay->GetSelectTrackSwitch() && points[i].fTrackN != currenttrack) continue;
112                 
113                 // Fill Charge Histogram
114                 fHistcharge->Fill(points[i].fCharge);
115                 if ((Int_t)points[i].fCharge > maxCharge ) maxCharge = (Int_t) points[i].fCharge; 
116             }
117
118         } // END - PATCH LOOP       
119     }  // END - SLICE LOOP
120
121     fMaxCharge = maxCharge;     
122 }
123
124 //____________________________________________________________________________________________________
125 void AliHLTTPCDisplayCharge::Draw(){
126     fDisplay->GetCanvasCharge()->cd();
127     fDisplay->GetCanvasCharge()->Clear();
128
129     // Keep Zoom
130     if (!fDisplay->GetKeepView() || (fBinX[1]>fMaxCharge)){
131         fBinX[0] = 0;
132         fBinX[1] = fMaxCharge;
133     }
134
135     fHistcharge->SetAxisRange(fBinX[0],fBinX[1]);
136
137     fHistcharge->SetStats(kFALSE);
138     fHistcharge->Draw();       
139
140     fDisplay->GetCanvasCharge()->Modified();
141     fDisplay->GetCanvasCharge()->Update();
142
143     // Keep Zoom
144     fDisplay->GetCanvasCharge()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)","AliHLTTPCDisplayCharge",(void*) this,"ExecEvent(Int_t,Int_t,Int_t,TObject*)");
145 }
146
147 //____________________________________________________________________________________________________
148 void AliHLTTPCDisplayCharge::ExecEvent(Int_t event, Int_t px, Int_t py, TObject *selected){
149    // Saves the Zoom Position of the Histogram 
150
151    // - Mouse down on Axis : StartPoint of Range
152    if (event == 1 && selected->InheritsFrom("TAxis"))
153        fTmpEvent = 1;
154
155    // - Mouse pressed on Axis : Real Zoom process not only click
156    else if (event == 21 && selected->InheritsFrom("TAxis") && fTmpEvent == 1)
157        fTmpEvent = 21;
158
159    // - Mouse pressed on Axis : Still pressed
160    else if (event == 21 && selected->InheritsFrom("TAxis") && fTmpEvent == 21) 
161        return;
162
163     // - Mouse up on Axis : End Point of Rangex
164    else if (event == 11 && selected->InheritsFrom("TAxis") && fTmpEvent == 21){
165        TAxis * axis = (TAxis*) selected;
166        
167        if (selected == fHistcharge->GetXaxis() ){
168            fBinX[0] = axis->GetFirst() -1;
169            fBinX[1] = axis->GetLast() -1;
170        }
171
172        fTmpEvent = 0; 
173    }
174    else fTmpEvent = 0;
175 }