]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/amoreTPC-QA/src/ui/UIQA.cxx
7288daf66e42109ce158c10cb53e7d56740d5cb4
[u/mrichter/AliRoot.git] / TPC / amoreTPC-QA / src / ui / UIQA.cxx
1 /***************************************************************************
2  *   Copyright (C) 2007 by Filimon Roukoutakis                             *
3  *   Filimon.Roukoutakis@cern.ch                                           *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 #include "UIQA.h"
21 #include <AmoreDA.h>
22 #include <TROOT.h>
23 #include <TStyle.h>
24 #include "AliTPCCalPad.h"
25 #include "AliTPCdataQA.h"
26 #include "AliTPCCalibViewer.h"
27 #include "AliTPCCalibViewerGUI.h"
28 #include "AliTPCPreprocessorOnline.h"
29 #include "AliCDBEntry.h"
30 ClassImp(amore::TPC::ui::UIQA)
31
32 #include <iostream>
33 #include <sstream>
34 #include <TCanvas.h>
35
36 namespace amore {
37
38 namespace TPC {
39
40 namespace ui {
41
42 using amore::subscriber::Subscribe;
43
44
45
46
47 UIQA::UIQA() {
48
49  Construct(); // Temporary but important!!! Do not forget to put this call in the constructor for the time being!
50  fCycle=0; 
51 }
52
53
54 UIQA::~UIQA()
55 {
56 }
57
58 void UIQA::Construct() { 
59
60
61   // The custom GUI is constructed here. gRootFrame is the container of the custom widgets.
62   //
63   // Expert monitor - AliTPCCalibViewerGUI - fViewerGUI
64   //
65  fTab=new TGTab(amore::ui::gRootFrame);
66  amore::ui::gRootFrame->AddFrame(fTab);
67  //
68  //
69  //
70  TGCompositeFrame* tabCont1 =fTab->AddTab("Expert");
71  
72  fViewerGUI = new AliTPCCalibViewerGUI(tabCont1, 1000, 600, 0);
73  tabCont1->AddFrame(fViewerGUI , new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
74  //
75   TGCompositeFrame* tempFrame=fTab->AddTab("OverThreshold");
76  fEC[0]=new TRootEmbeddedCanvas("fEC0", tempFrame, 1000, 650);
77  tempFrame->AddFrame(fEC[0]);
78  fEC[0]->GetCanvas()->Divide(3,3);
79  //
80  //
81  tempFrame=fTab->AddTab("Charge");
82  fEC[1]=new TRootEmbeddedCanvas("fEC1", tempFrame, 1000, 650);
83  tempFrame->AddFrame(fEC[1]);
84  fEC[1]->GetCanvas()->Divide(2,3);
85  //
86  //
87
88
89  
90
91  amore::ui::gRootFrame->MapSubwindows();
92  amore::ui::gRootFrame->Resize();
93  amore::ui::gRootFrame->MapWindow();
94
95  gROOT->SetStyle("Plain");
96  gStyle->SetFillColor(10);
97  gStyle->SetPadColor(10);
98  gStyle->SetCanvasColor(10);
99  gStyle->SetStatColor(10);
100  
101  gStyle->SetPalette(1,0);
102  gStyle->SetNumberContours(30);
103  gStyle->SetOptFit(111);
104  
105  gStyle->SetCanvasBorderMode(-1);
106  gStyle->SetCanvasBorderSize(1);
107  gStyle->SetCanvasColor(10);
108  
109  gStyle->SetFrameFillColor(10);
110  gStyle->SetFrameBorderSize(1);
111  gStyle->SetFrameBorderMode(-1);
112  gStyle->SetFrameLineWidth(1.);
113 }
114
115 void UIQA::SubscribeMonitorObjects() { // Before using any MonitorObject, a subscription should be made.
116
117   //std::ostringstream stringStream;
118 // The agent name acting as a source could be concatenated with all the objects it contains
119  //Subscribe(subscription.c_str()); // Here you put a series of subscriptions where the string corresponds to the object name as published in the Publisher Module. As these names are internal to the QA framework, the recommended way of having consistency between AMORE and QA is to factor-out of QA the function that represents the histogram naming convention as a separate AliRoot class/function and use it from inside QA and AMORE.
120  //...
121   amore::core::String_t sourceName="TPCQA/", subscription; 
122   subscription=sourceName+"TPCRAW";
123   Subscribe(subscription.c_str());
124   subscription=sourceName+"hist";
125   Subscribe(subscription.c_str());
126   
127 }
128
129 void UIQA::Update() { // This is executed after getting the updated contents of the subscribed MonitorObjects. Notice that the output of moInt[i] and moString[i] varies with time for a specific i because on the dqmAgent the "quality" check fails or succeeds. This is the essence of automatic data quality checks in AMORE. Try to use the moString[i] on a text widget to alert the shifter, or -depending of the value of moInt[i], 0 or 1- make part of the screen change color...
130  std::ostringstream stringStream;
131  // Example of accessing a normal TObject. The name is the name of the object in the QA framework
132
133
134  //amore::core::MonitorObjectTObject* ptr=gSubscriber->At<amore::core::MOTObj>("TPCQA/TPCRAW");
135  amore::core::MonitorObjectTObject* ptr=gSubscriber->At<amore::core::MOTObj>("TPCQA/hist");
136  AliTPCdataQA *tpcqa=0;
137  printf("Pointer - %p\n",ptr);
138  if(ptr) {
139    ptr->Object()->Print();
140  }
141  
142  ptr=gSubscriber->At<amore::core::MOTObj>("TPCQA/TPCRAW");
143  tpcqa=0;
144  printf("Pointer - %p\n",ptr);
145  if(ptr) {
146    tpcqa=(AliTPCdataQA*)ptr->Object();
147    printf("Pointertpcqa - %p\n",tpcqa);
148    tpcqa->Print();
149  }
150  //
151  if (!tpcqa) return;
152
153  //
154  // Expert monitor part
155  //
156  if (tpcqa) MakeTree(tpcqa);
157  //
158  // Simple histograms
159  //
160  // Over threshold
161  //
162
163  TCanvas *canvas  = fEC[0]->GetCanvas();
164  if (tpcqa->GetOverThreshold5()){
165    canvas->cd(1);
166    tpcqa->GetOverThreshold5()->MakeHisto1D()->Draw();
167    canvas->cd(2);
168    tpcqa->GetOverThreshold5()->MakeHisto2D(0)->Draw("colz");
169    canvas->cd(3);
170    tpcqa->GetOverThreshold5()->MakeHisto2D(1)->Draw("colz");
171  }
172  //
173  if (tpcqa->GetOverThreshold10()){
174    canvas->cd(4);
175    tpcqa->GetOverThreshold10()->MakeHisto1D()->Draw();
176    canvas->cd(5);
177    tpcqa->GetOverThreshold10()->MakeHisto2D(0)->Draw("colz");
178    canvas->cd(6);
179    tpcqa->GetOverThreshold10()->MakeHisto2D(1)->Draw("colz");
180  }
181
182  if (tpcqa->GetOverThreshold20()){
183    canvas->cd(7);
184    tpcqa->GetOverThreshold20()->MakeHisto1D()->Draw();
185    canvas->cd(8);
186    tpcqa->GetOverThreshold20()->MakeHisto2D(0)->Draw("colz");
187    canvas->cd(9);
188    tpcqa->GetOverThreshold20()->MakeHisto2D(1)->Draw("colz");
189  }
190
191  //
192  // Mean charge
193  //
194
195  canvas  = fEC[1]->GetCanvas();
196  if (tpcqa->GetMeanCharge()){
197    canvas->cd(1);
198    tpcqa->GetMeanCharge()->MakeHisto1D()->Draw();
199    canvas->cd(3);
200    tpcqa->GetMeanCharge()->MakeHisto2D(0)->Draw("colz");
201    canvas->cd(5);
202    tpcqa->GetMeanCharge()->MakeHisto2D(1)->Draw("colz");
203    //
204    canvas->cd(2);
205    tpcqa->GetMaxCharge()->MakeHisto1D()->Draw();
206    canvas->cd(4);
207    tpcqa->GetMaxCharge()->MakeHisto2D(0)->Draw("colz");
208    canvas->cd(6);
209    tpcqa->GetMaxCharge()->MakeHisto2D(1)->Draw("colz");
210  }
211
212  // End of access example
213 }
214
215 void UIQA::Process() {
216
217 }
218
219 void UIQA::StartOfCycle() {
220
221 }
222
223 void UIQA::EndOfCycle() {
224
225 }
226
227
228   void UIQA::MakeTree(AliTPCdataQA* ped){
229     //
230     // Prepare tree for expert monitor
231     //
232
233     //
234     // QA part
235     //
236  
237     AliTPCPreprocessorOnline * preprocesor = new AliTPCPreprocessorOnline;
238     if (ped->GetMaxCharge()) preprocesor->AddComponent(new AliTPCCalPad(*(ped->GetMaxCharge())));  
239     if (ped->GetMeanCharge()) preprocesor->AddComponent(new AliTPCCalPad(*(ped->GetMeanCharge())));  
240     if (ped->GetOverThreshold0()) preprocesor->AddComponent(new AliTPCCalPad(*(ped->GetOverThreshold0())));
241     if (ped->GetOverThreshold5()) preprocesor->AddComponent(new AliTPCCalPad(*(ped->GetOverThreshold5())));
242     if (ped->GetOverThreshold10()) preprocesor->AddComponent(new AliTPCCalPad(*(ped->GetOverThreshold10())));
243     if (ped->GetOverThreshold20()) preprocesor->AddComponent(new AliTPCCalPad(*(ped->GetOverThreshold20())));
244     if (ped->GetOverThreshold30()) preprocesor->AddComponent(new AliTPCCalPad(*(ped->GetOverThreshold30())));
245
246     //
247     // DA part
248     //
249
250     AliTPCCalPad * noise = GetNoise();
251     if (noise)  preprocesor->AddComponent(new AliTPCCalPad(*noise));
252     AliTPCCalPad * pedestal = GetPedestal();
253     if (pedestal)  preprocesor->AddComponent(new AliTPCCalPad(*pedestal));
254
255     //
256     // Make new tree
257     //
258     char fname[10000];
259     sprintf(fname,"QAtree%d.root",fCycle);
260     preprocesor->DumpToFile(fname);
261     fCycle++;
262     delete noise;
263     delete pedestal;
264
265     //
266     // Update viewer
267     //
268     // 
269     AliTPCCalibViewer *viewer = fViewerGUI->GetViewer();
270     AliTPCCalibViewer *nviewer = new  AliTPCCalibViewer(fname, "calPads");
271     fViewerGUI->Initialize(nviewer);    
272     //
273     //
274     //
275   delete preprocesor;
276   }
277
278
279   AliTPCCalPad *  UIQA::GetNoise(){
280     //
281     // Get noise from DAs 
282     // For the moment only get calibration param form local file 
283     //  file is exepected to be in $AMORE_SITE directory
284     // 
285
286     //
287     // GetNoise - if not in AmoreDB than from file
288     //
289     //amore::da::AmoreDA amoreDA;
290     // TObject *temp=0;
291     //amoreDA.Receive("PEDESTAL/NOISE",temp);
292     //temp->Dump();
293     // if (temp) return (AliTPCCalPad*) temp;
294     //
295     //
296     TDirectory * dir = gDirectory;
297     TFile *f = new TFile("$AMORE_SITE/PadNoise.root");
298     AliCDBEntry * entry = (AliCDBEntry*)f->Get("AliCDBEntry");
299     if (entry){
300       AliTPCCalPad * pad = ((AliTPCCalPad *)entry->GetObject()->Clone());
301       if (pad) {
302         pad->SetName("Noise");
303         pad->Print();
304         return pad;
305       }
306     }
307     f->Close();
308     dir->cd();
309     return 0;
310   }
311
312   AliTPCCalPad *  UIQA::GetPedestal(){
313     //
314     //
315     TFile f("$AMORE_SITE/Pedestal.root");
316     AliCDBEntry * entry = (AliCDBEntry*)f.Get("AliCDBEntry");
317     if (entry){
318       AliTPCCalPad * pad = ((AliTPCCalPad *)entry->GetObject()->Clone());
319       if (pad) {
320         pad->SetName("Pedestals");
321         pad->Print();
322         return pad;
323       }
324     }
325     return 0;
326   }
327   AliTPCCalPad *  UIQA::GetTime0(){
328     return 0;
329   }
330
331
332
333 };
334
335 };
336
337 };