added protection
[u/mrichter/AliRoot.git] / TPC / amoreTPC-QA / src / ui / UIQA.cxx
CommitLineData
e9d4890d 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"
45af6e68 21#include <AmoreDA.h>
4a294b26 22#include <TROOT.h>
23#include <TStyle.h>
252b0bbf 24#include "AliTPCCalPad.h"
25#include "AliTPCdataQA.h"
26#include "AliTPCCalibViewer.h"
27#include "AliTPCCalibViewerGUI.h"
28#include "AliTPCPreprocessorOnline.h"
29#include "AliCDBEntry.h"
e9d4890d 30ClassImp(amore::TPC::ui::UIQA)
31
32#include <iostream>
33#include <sstream>
34#include <TCanvas.h>
35
36namespace amore {
37
38namespace TPC {
39
40namespace ui {
41
42using amore::subscriber::Subscribe;
43
45af6e68 44
45
46
e9d4890d 47UIQA::UIQA() {
48
49 Construct(); // Temporary but important!!! Do not forget to put this call in the constructor for the time being!
9d63ae25 50 fCycle=0;
e9d4890d 51}
52
53
54UIQA::~UIQA()
55{
56}
57
7fb2364f 58void UIQA::Construct() {
e9d4890d 59
7fb2364f 60
61 // The custom GUI is constructed here. gRootFrame is the container of the custom widgets.
62 //
63 // Expert monitor - AliTPCCalibViewerGUI - fViewerGUI
64 //
e9d4890d 65 fTab=new TGTab(amore::ui::gRootFrame);
66 amore::ui::gRootFrame->AddFrame(fTab);
4a294b26 67 //
252b0bbf 68 //
7fb2364f 69 //
252b0bbf 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");
4a294b26 76 fEC[0]=new TRootEmbeddedCanvas("fEC0", tempFrame, 1000, 650);
e9d4890d 77 tempFrame->AddFrame(fEC[0]);
4a294b26 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);
252b0bbf 85 //
86 //
87
88
4a294b26 89
90
e9d4890d 91 amore::ui::gRootFrame->MapSubwindows();
92 amore::ui::gRootFrame->Resize();
93 amore::ui::gRootFrame->MapWindow();
94
4a294b26 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);
252b0bbf 112 gStyle->SetFrameLineWidth(1.);
e9d4890d 113}
114
115void UIQA::SubscribeMonitorObjects() { // Before using any MonitorObject, a subscription should be made.
116
45af6e68 117 //std::ostringstream stringStream;
7fb2364f 118// The agent name acting as a source could be concatenated with all the objects it contains
45af6e68 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.
e9d4890d 120 //...
25eb8f52 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
e9d4890d 127}
128
129void 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;
e9d4890d 131 // Example of accessing a normal TObject. The name is the name of the object in the QA framework
25eb8f52 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 }
7fb2364f 150 //
4a294b26 151 if (!tpcqa) return;
7fb2364f 152
153 //
154 // Expert monitor part
155 //
156 if (tpcqa) MakeTree(tpcqa);
157 //
158 // Simple histograms
4a294b26 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 }
25eb8f52 211
e9d4890d 212 // End of access example
e9d4890d 213}
214
215void UIQA::Process() {
216
217}
218
219void UIQA::StartOfCycle() {
220
221}
222
223void UIQA::EndOfCycle() {
224
225}
226
252b0bbf 227
228 void UIQA::MakeTree(AliTPCdataQA* ped){
229 //
7fb2364f 230 // Prepare tree for expert monitor
231 //
232
233 //
234 // QA part
252b0bbf 235 //
7fb2364f 236
9d63ae25 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())));
7fb2364f 245
246 //
247 // DA part
248 //
249
252b0bbf 250 AliTPCCalPad * noise = GetNoise();
9d63ae25 251 if (noise) preprocesor->AddComponent(new AliTPCCalPad(*noise));
252b0bbf 252 AliTPCCalPad * pedestal = GetPedestal();
9d63ae25 253 if (pedestal) preprocesor->AddComponent(new AliTPCCalPad(*pedestal));
7fb2364f 254
255 //
256 // Make new tree
257 //
9d63ae25 258 char fname[10000];
259 sprintf(fname,"QAtree%d.root",fCycle);
260 preprocesor->DumpToFile(fname);
261 fCycle++;
252b0bbf 262 delete noise;
263 delete pedestal;
7fb2364f 264
265 //
266 // Update viewer
267 //
268 //
252b0bbf 269 AliTPCCalibViewer *viewer = fViewerGUI->GetViewer();
9d63ae25 270 AliTPCCalibViewer *nviewer = new AliTPCCalibViewer(fname, "calPads");
7fb2364f 271 fViewerGUI->Initialize(nviewer);
252b0bbf 272 //
273 //
274 //
9d63ae25 275 delete preprocesor;
252b0bbf 276 }
277
7fb2364f 278
252b0bbf 279 AliTPCCalPad * UIQA::GetNoise(){
7fb2364f 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
252b0bbf 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;
7fb2364f 294 //
295 //
252b0bbf 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
e9d4890d 333};
334
335};
336
337};