]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/qaGui/AliTRDqaGuiClustersStack.cxx
Fix from Alex for FPE in TRD: ALIROOT-5503 and tracklet calibration: PWGPP-2
[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     fFileName (0x0),
59     fGPanel (0),
60     fGCanvas (0),
61     fGSelectSM (0),
62     fGSelectStack (0),
63     fGSelectView (0),
64     fGPrevSM (0),
65     fGPrevStack (0),
66     fGNextSM (0),
67     fGNextStack (0),
68     fGPlay (0)
69 {
70   //
71   // Default constructor
72   //
73
74   for (Int_t i = 0; i < 6; i++) {
75     fCanvasList[i] = 0x0;
76     fHistList[i]   = 0x0;
77   }
78
79   //strncpy(fFileName,"",256);
80
81 }
82
83 //////////////////////////////////////////////////////////////////////////////////
84 AliTRDqaGuiClustersStack::AliTRDqaGuiClustersStack(TGWindow *parent) 
85   : TGCompositeFrame(parent, 720, 500),
86     fIdxSM (0),
87     fIdxStack (0),
88     fView (0),
89     fFileName (0x0),
90     fGPanel (0),
91     fGCanvas (0),
92     fGSelectSM (0),
93     fGSelectStack (0),
94     fGSelectView (0),
95     fGPrevSM (0),
96     fGPrevStack (0),
97     fGNextSM (0),
98     fGNextStack (0),
99     fGPlay (0)
100 {
101   //
102   // Main constructor
103   //
104   
105   fIdxSM = 0;
106   fIdxStack = 0;
107
108   // steering panel 
109   
110   SetLayoutManager(new TGVerticalLayout(this));
111
112   fGPanel = new TGHorizontalFrame(this);
113
114   // fGLabel = new TGLabel(fGPanel, "Current Stack: ");
115   fGPrevSM = new TGTextButton(fGPanel, "Prev SM");
116   fGPrevStack = new TGTextButton(fGPanel, "Prev Stack");
117
118   fGNextSM = new TGTextButton(fGPanel, "Next SM");
119   fGNextStack = new TGTextButton(fGPanel, "Next Stack");
120
121   fGSelectSM = new TGComboBox(fGPanel);
122   for(int i=0; i<fgknSM; i++) fGSelectSM->AddEntry(Form("SM %d", i), i);
123   fGSelectSM->Resize(100, (Int_t)(fGPrevSM->GetHeight()*1.4));
124   fGSelectSM->Select(fIdxSM);
125
126   fGSelectStack = new TGComboBox(fGPanel);
127   for(int i=0; i<fgknStack; i++) fGSelectStack->AddEntry(Form("Stack %d", i), i);
128   fGSelectStack->Resize(100, (Int_t)(fGPrevSM->GetHeight()*1.4));
129   fGSelectStack->Select(fIdxStack);
130
131   fGPlay = new TGTextButton(fGPanel, "PLAY");
132
133   fGSelectView = new TGComboBox(fGPanel);
134   fGSelectView->AddEntry("amplitude",0);
135   fGSelectView->AddEntry("time -- signal MPV", 1);
136   fGSelectView->AddEntry("time -- total charge", 2);
137   fGSelectView->AddEntry("time -- nClusters", 3);
138   fGSelectView->Resize(150, (Int_t)(fGPrevSM->GetHeight()*1.4));
139   fGSelectView->Select(0);
140
141   TGLayoutHints *hint = new TGLayoutHints(kLHintsNormal, 5, 5, 5, 5);
142   
143   // fGPanel->AddFrame(fGLabel, hint);
144   fGPanel->AddFrame(fGPrevSM, hint);
145   fGPanel->AddFrame(fGPrevStack, hint);
146
147   fGPanel->AddFrame(fGSelectSM, hint);
148   fGPanel->AddFrame(fGSelectStack, hint);
149
150   fGPanel->AddFrame(fGNextStack, hint);
151   fGPanel->AddFrame(fGNextSM, hint);
152
153   fGPanel->AddFrame(fGPlay, hint);
154
155   fGPanel->AddFrame(fGSelectView, hint);
156   
157
158   AddFrame(fGPanel);
159
160   // panel logic
161   fGPrevStack->Connect("Clicked()", "AliTRDqaGuiClustersStack", this, "PreviusStack()");
162   fGNextStack->Connect("Clicked()", "AliTRDqaGuiClustersStack", this, "NextStack()");
163   fGPrevSM->Connect("Clicked()", "AliTRDqaGuiClustersStack", this, "PreviusSM()");
164   fGNextSM->Connect("Clicked()", "AliTRDqaGuiClustersStack", this, "NextSM()");
165
166   fGSelectSM->Connect("Selected(Int_t)", "AliTRDqaGuiClustersStack", this, "SelectSM(Int_t)");
167   fGSelectStack->Connect("Selected(Int_t)", "AliTRDqaGuiClustersStack", this, "SelectStack(Int_t)");
168   fGSelectView->Connect("Selected(Int_t)", "AliTRDqaGuiClustersStack", this, "SelectView(Int_t)");
169   
170   //fGPlay->Connect("Clicked()", "AliTRDqaGuiClustersStack", this, "Play()");
171
172   // histograms
173   /**/
174   fGCanvas = new TGCompositeFrame(this);
175   fGCanvas->SetLayoutManager(new TGMatrixLayout(fGCanvas,2,3,1,1));
176
177   for(Int_t i=0; i<fgknCh; i++) {
178     fCanvasList[i] = new TRootEmbeddedCanvas(Form("L%d",i), fGCanvas, 320, 300);
179     fGCanvas->AddFrame(fCanvasList[i]);
180     fCanvasList[i]->GetCanvas()->SetRightMargin(0.05);
181   }
182   
183   for(Int_t i=0; i<4; i++) {
184     fHistList[i] = 0;
185   }
186
187   AddFrame(fGCanvas);
188   /**/
189 }
190
191 //////////////////////////////////////////////////////////////////////////////////
192
193 void AliTRDqaGuiClustersStack::SetQAFile(const char *filename) {
194   //
195   // Sets a file with histograms
196   //
197   
198   //strncpy(fFileName,filename,256);
199   fFileName = filename;
200
201   for(Int_t i=0; i<fgknCh; i++) {
202     if (fHistList[i]) delete fHistList[i];
203     fHistList[i] = 0;
204   }
205   
206   TFile *file = new TFile(filename);
207   file->cd("TRD/RecPoints");
208   
209   // const char *opt[2] = {"colz", ""};
210   if (fView == 0) CreateHistAmplitude();
211   if (fView == 1) CreateHistTimeMPV();
212   if (fView == 2 || fView == 3) CreateHistTimeCharge();
213   
214   for(Int_t i=0; i<fgknCh; i++) {
215     fCanvasList[i]->GetCanvas()->cd();
216     if (fHistList[i]) fHistList[i]->Draw(); //opt[i]);
217     fCanvasList[i]->GetCanvas()->Update();
218   }
219
220   // style
221   //  for(Int_t i=0; i<fgknCh; i++) {
222   //   TPaveText *title = (TPaveText*)fCanvasList[i]->GetCanvas()->FindObject("title");
223   //  title->SetX1NDC(0.7);
224   //  title->SetX2NDC(0.95);
225   // }
226 }
227
228 //////////////////////////////////////////////////////////////////////////////////
229
230 void AliTRDqaGuiClustersStack::SetStack(Int_t idxStack) {
231   //
232   // sets active stack
233   // 
234
235   fIdxStack = idxStack; 
236   fGSelectSM->Select(fIdxSM, 0); 
237   fGSelectStack->Select(fIdxStack, 0);
238   SetQAFile(fFileName);
239 }
240
241 //////////////////////////////////////////////////////////////////////////////////
242
243 void AliTRDqaGuiClustersStack::SetSM(Int_t idxSM) {
244   //
245   // sets active super module
246   //
247
248   fIdxSM = idxSM; 
249   fGSelectSM->Select(fIdxSM, 0); 
250   fGSelectStack->Select(fIdxStack, 0); 
251   SetQAFile(fFileName);
252 }
253
254 //////////////////////////////////////////////////////////////////////////////////
255
256 void AliTRDqaGuiClustersStack::SetView(Int_t idxView) {
257   //
258   // sets active data type
259   //
260   
261   fView = idxView;
262   fGSelectView->Select(idxView);
263   SetQAFile(fFileName);
264 }
265
266 //////////////////////////////////////////////////////////////////////////////////
267
268 void AliTRDqaGuiClustersStack::CreateHistTimeMPV() {
269   //
270   // builds histograms of the Most Probable Value distribution 
271   // chamber-by-chamber from a 2D distribution
272   //
273   
274
275   TH2D *fData = (TH2D*)gDirectory->Get(Form("qaTRD_recPoints_sigTime_sm%d", fIdxSM));
276   if (!fData) return;
277
278   Int_t nBins = fData->GetYaxis()->GetNbins();
279   Double_t min = fData->GetYaxis()->GetXmin();
280   Double_t max = fData->GetYaxis()->GetXmax();
281   
282   for(Int_t i=0; i<fgknCh; i++) {
283     
284     //printf("I = %d\n", i);
285
286     Int_t det = fgknCh * fIdxStack + i;
287     fHistList[i] = new TH1D(Form("det%d",det), Form("Det = %d;time bin; MPV",det), nBins, min, max);
288     
289     // fill the histograms;
290     for(Int_t j=1; j<nBins+2; j++) {
291
292       Double_t c = fHistList[i]->GetBinCenter(j);
293       Int_t bin = fData->FindBin(det, c);
294       Double_t value = fData->GetBinContent(bin);
295       fHistList[i]->SetBinContent(j, value);
296       // printf("..j=%d c=%lf bin=%d value=%lf\n", j, c, bin, value);  
297     }
298   }
299 }
300
301 //////////////////////////////////////////////////////////////////////////////////
302
303 void AliTRDqaGuiClustersStack::CreateHistAmplitude() {
304   //
305   // builds histograms with amplitude
306   // 
307   
308   //Info("createHist", "start");
309
310   TH2D *fData = (TH2D*)gDirectory->Get("qaTRD_recPoints_amp");
311   if (!fData) return;
312
313   Int_t nBins = fData->GetYaxis()->GetNbins();
314   Double_t min = fData->GetYaxis()->GetXmin();
315   Double_t max = fData->GetYaxis()->GetXmax();
316   
317   for(Int_t i=0; i<fgknCh; i++) {
318     
319     //printf("I = %d\n", i);
320     //if (fHistList[i]) delete fHistList[i];
321
322     Int_t det = fgknCh * fgknStack * fIdxSM + fgknCh * fIdxStack + i;
323     fHistList[i] = new TH1D(Form("det%d",det), Form("Det = %d;amplidtude",det), nBins, min, max);
324     
325     // fill the histograms;
326     for(Int_t j=1; j<nBins+2; j++) {
327       //printf("..j=%d\n", j);
328       Double_t c = fHistList[i]->GetBinCenter(j);
329       Int_t bin = fData->FindBin(det, c);
330       Double_t value = fData->GetBinContent(bin);
331       fHistList[i]->SetBinContent(j, value);
332     }
333   }
334 }
335
336 //////////////////////////////////////////////////////////////////////////////////
337
338 void AliTRDqaGuiClustersStack::CreateHistTimeCharge() {
339   //
340   // builds histograms with time-charge distribution
341   //
342
343   TH3D *fData = (TH3D*)gDirectory->Get("qaTRD_recPoints_sigTime");
344   if (!fData) return;
345
346   Int_t nBins = fData->GetYaxis()->GetNbins();
347   //Int_t nBinsCharge = fData->GetZaxis()->GetNbins();
348   Double_t min = fData->GetYaxis()->GetXmin();
349   Double_t max = fData->GetYaxis()->GetXmax();
350   
351   for(Int_t i=0; i<fgknCh; i++) {
352     
353     //printf("I = %d\n", i);
354     //if (fHistList[i]) delete fHistList[i];
355
356     Int_t det = fgknCh * fgknStack * fIdxSM + fgknCh * fIdxStack + i;
357     const char *yaxis[2] = {"total charge", "number of clusters"};
358     fHistList[i] = new TH1D(Form("det%d",det), Form("Det = %d;time bin;%s",det,yaxis[fView-2]), nBins, min, max);
359     
360     // fill the histograms;
361     for(Int_t j=1; j<nBins+1; j++) {
362       
363       Double_t charge = 0;
364       Double_t ncls = 0;
365       for(Int_t k=0; k<201; k++) { // needs more robust loop
366         Int_t bin = fData->FindBin(det, fHistList[i]->GetBinCenter(j), k);
367         Double_t v = fData->GetBinContent(bin);
368         charge += k * v;
369         ncls += v;
370       }
371       // if (ncls > 1)
372       if (fView == 2)
373         fHistList[i]->SetBinContent(j, charge);
374
375       if (fView == 3)
376         fHistList[i]->SetBinContent(j, ncls);
377     }
378   }
379 }
380
381 //////////////////////////////////////////////////////////////////////////////////