]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/qaGui/AliTRDqaGuiClustersStack.cxx
Updated QA version (Sylwester)
[u/mrichter/AliRoot.git] / TRD / qaGui / AliTRDqaGuiClustersStack.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id: AliTRDqaGuiClustersStack.cxx 23871 2008-02-12 11:48:20Z hristov $ */
17
18 //////////////////////////////////////////////////////////////////////////////////
19 //
20 // This class is a Graphical User Interface for the Quality Monitorig 
21 // of clusters on the stack by stack basis. 
22 // It lets display and browse throu histograms created by 
23 // the AliTRDQADataMakerRec run during the reconstruction 
24 //
25 // S. Radomski 
26 // Uni-Heidelberg
27 // Feb. 2008
28 // 
29 //////////////////////////////////////////////////////////////////////////////////
30
31 #include "AliTRDqaGuiClustersStack.h"
32
33 #include "TH1D.h"
34 #include "TH2D.h"
35 #include "TH3D.h"
36 #include "TFile.h"
37 #include "TCanvas.h"
38 #include "TString.h"
39 #include "TSystem.h"
40
41 #include "TPaveText.h"
42 #include "TGLabel.h"
43 #include "TGComboBox.h"
44 #include "TGButton.h"
45 #include "TRootEmbeddedCanvas.h"
46
47 ClassImp(AliTRDqaGuiClustersStack)
48
49 const Int_t AliTRDqaGuiClustersStack::fgknSM = 18;
50 const Int_t AliTRDqaGuiClustersStack::fgknStack = 5;
51 const Int_t AliTRDqaGuiClustersStack::fgknCh = 6;
52
53
54 AliTRDqaGuiClustersStack::AliTRDqaGuiClustersStack() 
55   : fIdxSM (0),
56     fIdxStack (0),
57     fView (0),
58     fGPanel (0),
59     fGCanvas (0),
60     fGSelectSM (0),
61     fGSelectStack (0),
62     fGSelectView (0),
63     fGPrevSM (0),
64     fGPrevStack (0),
65     fGNextSM (0),
66     fGNextStack (0),
67     fGPlay (0)
68 {
69
70 }
71 //////////////////////////////////////////////////////////////////////////////////
72
73 AliTRDqaGuiClustersStack::AliTRDqaGuiClustersStack(TGWindow *parent) 
74   : TGCompositeFrame(parent, 720, 500),
75     fIdxSM (0),
76     fIdxStack (0),
77     fView (0),
78     fGPanel (0),
79     fGCanvas (0),
80     fGSelectSM (0),
81     fGSelectStack (0),
82     fGSelectView (0),
83     fGPrevSM (0),
84     fGPrevStack (0),
85     fGNextSM (0),
86     fGNextStack (0),
87     fGPlay (0)
88 {
89   //
90   // Main constructor
91   //
92   
93   fIdxSM = 0;
94   fIdxStack = 0;
95
96   // steering panel 
97   
98   SetLayoutManager(new TGVerticalLayout(this));
99
100   fGPanel = new TGHorizontalFrame(this);
101
102   // fGLabel = new TGLabel(fGPanel, "Current Stack: ");
103   fGPrevSM = new TGTextButton(fGPanel, "Prev SM");
104   fGPrevStack = new TGTextButton(fGPanel, "Prev Stack");
105
106   fGNextSM = new TGTextButton(fGPanel, "Next SM");
107   fGNextStack = new TGTextButton(fGPanel, "Next Stack");
108
109   fGSelectSM = new TGComboBox(fGPanel);
110   for(int i=0; i<fgknSM; i++) fGSelectSM->AddEntry(Form("SM %d", i), i);
111   fGSelectSM->Resize(100, fGPrevSM->GetHeight());
112   fGSelectSM->Select(fIdxSM);
113
114   fGSelectStack = new TGComboBox(fGPanel);
115   for(int i=0; i<fgknStack; i++) fGSelectStack->AddEntry(Form("Stack %d", i), i);
116   fGSelectStack->Resize(100, fGPrevSM->GetHeight());
117   fGSelectStack->Select(fIdxStack);
118
119   fGPlay = new TGTextButton(fGPanel, "PLAY");
120
121   fGSelectView = new TGComboBox(fGPanel);
122   fGSelectView->AddEntry("amplitude",0);
123   fGSelectView->AddEntry("time -- signal MPV", 1);
124   fGSelectView->AddEntry("time -- total charge", 2);
125   fGSelectView->AddEntry("time -- nClusters", 3);
126   fGSelectView->Resize(150, fGPrevSM->GetHeight());
127   fGSelectView->Select(0);
128
129   TGLayoutHints *hint = new TGLayoutHints(kLHintsNormal, 5, 5, 5, 5);
130   
131   // fGPanel->AddFrame(fGLabel, hint);
132   fGPanel->AddFrame(fGPrevSM, hint);
133   fGPanel->AddFrame(fGPrevStack, hint);
134
135   fGPanel->AddFrame(fGSelectSM, hint);
136   fGPanel->AddFrame(fGSelectStack, hint);
137
138   fGPanel->AddFrame(fGNextStack, hint);
139   fGPanel->AddFrame(fGNextSM, hint);
140
141   fGPanel->AddFrame(fGPlay, hint);
142
143   fGPanel->AddFrame(fGSelectView, hint);
144   
145
146   AddFrame(fGPanel);
147
148   // panel logic
149   fGPrevStack->Connect("Clicked()", "AliTRDqaGuiClustersStack", this, "PreviusStack()");
150   fGNextStack->Connect("Clicked()", "AliTRDqaGuiClustersStack", this, "NextStack()");
151   fGPrevSM->Connect("Clicked()", "AliTRDqaGuiClustersStack", this, "PreviusSM()");
152   fGNextSM->Connect("Clicked()", "AliTRDqaGuiClustersStack", this, "NextSM()");
153
154   fGSelectSM->Connect("Selected(Int_t)", "AliTRDqaGuiClustersStack", this, "SelectSM(Int_t)");
155   fGSelectStack->Connect("Selected(Int_t)", "AliTRDqaGuiClustersStack", this, "SelectStack(Int_t)");
156   fGSelectView->Connect("Selected(Int_t)", "AliTRDqaGuiClustersStack", this, "SelectView(Int_t)");
157   
158   //fGPlay->Connect("Clicked()", "AliTRDqaGuiClustersStack", this, "Play()");
159
160   // histograms
161   /**/
162   fGCanvas = new TGCompositeFrame(this);
163   fGCanvas->SetLayoutManager(new TGMatrixLayout(fGCanvas,2,3,1,1));
164
165   for(Int_t i=0; i<fgknCh; i++) {
166     fCanvasList[i] = new TRootEmbeddedCanvas(Form("L%d",i), fGCanvas, 320, 300);
167     fGCanvas->AddFrame(fCanvasList[i]);
168     fCanvasList[i]->GetCanvas()->SetRightMargin(0.05);
169   }
170   
171   for(Int_t i=0; i<4; i++) {
172     fHistList[i] = 0;
173   }
174
175   AddFrame(fGCanvas);
176   /**/
177 }
178
179 //////////////////////////////////////////////////////////////////////////////////
180
181 void AliTRDqaGuiClustersStack::SetQAFile(const char *filename) {
182   //
183   // Sets a file with histograms
184   //
185   
186   strcpy(fFileName, filename);
187
188   for(Int_t i=0; i<fgknCh; i++) {
189     if (fHistList[i]) delete fHistList[i];
190     fHistList[i] = 0;
191   }
192   
193   TFile *file = new TFile(filename);
194   file->cd("TRD/RecPoints");
195   
196   // const char *opt[2] = {"colz", ""};
197   if (fView == 0) CreateHistAmplitude();
198   if (fView == 1) CreateHistTimeMPV();
199   if (fView == 2 || fView == 3) CreateHistTimeCharge();
200   
201   for(Int_t i=0; i<fgknCh; i++) {
202     fCanvasList[i]->GetCanvas()->cd();
203     if (fHistList[i]) fHistList[i]->Draw(); //opt[i]);
204     fCanvasList[i]->GetCanvas()->Update();
205   }
206
207   // style
208   //  for(Int_t i=0; i<fgknCh; i++) {
209   //   TPaveText *title = (TPaveText*)fCanvasList[i]->GetCanvas()->FindObject("title");
210   //  title->SetX1NDC(0.7);
211   //  title->SetX2NDC(0.95);
212   // }
213 }
214
215 //////////////////////////////////////////////////////////////////////////////////
216
217 void AliTRDqaGuiClustersStack::SetStack(Int_t idxStack) {
218   //
219   // sets active stack
220   // 
221
222   fIdxStack = idxStack; 
223   fGSelectSM->Select(fIdxSM, 0); 
224   fGSelectStack->Select(fIdxStack, 0);
225   SetQAFile(fFileName);
226 }
227
228 //////////////////////////////////////////////////////////////////////////////////
229
230 void AliTRDqaGuiClustersStack::SetSM(Int_t idxSM) {
231   //
232   // sets active super module
233   //
234
235   fIdxSM = idxSM; 
236   fGSelectSM->Select(fIdxSM, 0); 
237   fGSelectStack->Select(fIdxStack, 0); 
238   SetQAFile(fFileName);
239 }
240
241 //////////////////////////////////////////////////////////////////////////////////
242
243 void AliTRDqaGuiClustersStack::SetView(Int_t idxView) {
244   //
245   // sets active data type
246   //
247   
248   fView = idxView;
249   fGSelectView->Select(idxView);
250   SetQAFile(fFileName);
251 }
252
253 //////////////////////////////////////////////////////////////////////////////////
254
255 void AliTRDqaGuiClustersStack::CreateHistTimeMPV() {
256   //
257   // builds histograms of the Most Probable Value distribution 
258   // chamber-by-chamber from a 2D distribution
259   //
260   
261
262   TH2D *fData = (TH2D*)gDirectory->Get(Form("qaTRD_recPoints_sigTime_sm%d", fIdxSM));
263   if (!fData) return;
264
265   Int_t nBins = fData->GetYaxis()->GetNbins();
266   Double_t min = fData->GetYaxis()->GetXmin();
267   Double_t max = fData->GetYaxis()->GetXmax();
268   
269   for(Int_t i=0; i<fgknCh; i++) {
270     
271     //printf("I = %d\n", i);
272
273     Int_t det = fgknCh * fIdxStack + i;
274     fHistList[i] = new TH1D(Form("det%d",det), Form("Det = %d;time bin; MPV",det), nBins, min, max);
275     
276     // fill the histograms;
277     for(Int_t j=1; j<nBins+2; j++) {
278
279       Double_t c = fHistList[i]->GetBinCenter(j);
280       Int_t bin = fData->FindBin(det, c);
281       Double_t value = fData->GetBinContent(bin);
282       fHistList[i]->SetBinContent(j, value);
283       // printf("..j=%d c=%lf bin=%d value=%lf\n", j, c, bin, value);  
284     }
285   }
286 }
287
288 //////////////////////////////////////////////////////////////////////////////////
289
290 void AliTRDqaGuiClustersStack::CreateHistAmplitude() {
291   //
292   // builds histograms with amplitude
293   // 
294   
295   //Info("createHist", "start");
296
297   TH2D *fData = (TH2D*)gDirectory->Get("qaTRD_recPoints_amp");
298   if (!fData) return;
299
300   Int_t nBins = fData->GetYaxis()->GetNbins();
301   Double_t min = fData->GetYaxis()->GetXmin();
302   Double_t max = fData->GetYaxis()->GetXmax();
303   
304   for(Int_t i=0; i<fgknCh; i++) {
305     
306     //printf("I = %d\n", i);
307     //if (fHistList[i]) delete fHistList[i];
308
309     Int_t det = fgknCh * fgknStack * fIdxSM + fgknCh * fIdxStack + i;
310     fHistList[i] = new TH1D(Form("det%d",det), Form("Det = %d;amplidtude",det), nBins, min, max);
311     
312     // fill the histograms;
313     for(Int_t j=1; j<nBins+2; j++) {
314       //printf("..j=%d\n", j);
315       Double_t c = fHistList[i]->GetBinCenter(j);
316       Int_t bin = fData->FindBin(det, c);
317       Double_t value = fData->GetBinContent(bin);
318       fHistList[i]->SetBinContent(j, value);
319     }
320   }
321 }
322
323 //////////////////////////////////////////////////////////////////////////////////
324
325 void AliTRDqaGuiClustersStack::CreateHistTimeCharge() {
326   //
327   // builds histograms with time-charge distribution
328   //
329
330   TH3D *fData = (TH3D*)gDirectory->Get("qaTRD_recPoints_sigTime");
331   if (!fData) return;
332
333   Int_t nBins = fData->GetYaxis()->GetNbins();
334   //Int_t nBinsCharge = fData->GetZaxis()->GetNbins();
335   Double_t min = fData->GetYaxis()->GetXmin();
336   Double_t max = fData->GetYaxis()->GetXmax();
337   
338   for(Int_t i=0; i<fgknCh; i++) {
339     
340     //printf("I = %d\n", i);
341     //if (fHistList[i]) delete fHistList[i];
342
343     Int_t det = fgknCh * fgknStack * fIdxSM + fgknCh * fIdxStack + i;
344     const char *yaxis[2] = {"total charge", "number of clusters"};
345     fHistList[i] = new TH1D(Form("det%d",det), Form("Det = %d;time bin;%s",det,yaxis[fView-2]), nBins, min, max);
346     
347     // fill the histograms;
348     for(Int_t j=1; j<nBins+1; j++) {
349       
350       Double_t charge = 0;
351       Double_t ncls = 0;
352       for(Int_t k=0; k<201; k++) { // needs more robust loop
353         Int_t bin = fData->FindBin(det, fHistList[i]->GetBinCenter(j), k);
354         Double_t v = fData->GetBinContent(bin);
355         charge += k * v;
356         ncls += v;
357       }
358       // if (ncls > 1)
359       if (fView == 2)
360         fHistList[i]->SetBinContent(j, charge);
361
362       if (fView == 3)
363         fHistList[i]->SetBinContent(j, ncls);
364     }
365   }
366 }
367
368 //////////////////////////////////////////////////////////////////////////////////