Preparation for the next Root release
[u/mrichter/AliRoot.git] / EVE / EveBase / AliEveTrackCounterEditor.cxx
CommitLineData
f76c9e9b 1// @(#)root/eve:$Id$
2// Author: Matevz Tadel 2007
3
4/**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
7 * full copyright notice. *
8 **************************************************************************/
9
10#include "AliEveTrackCounterEditor.h"
11#include "AliEveTrackCounter.h"
12365217 12#include "AliEveEventManager.h"
f262c692 13#include "AliESDEvent.h"
f76c9e9b 14
12365217 15#include "TGedEditor.h"
f76c9e9b 16#include "TVirtualPad.h"
17#include "TColor.h"
18
19// Cleanup these includes:
20#include "TGLabel.h"
21#include "TGNumberEntry.h"
22#include "TGComboBox.h"
23#include "TGMsgBox.h"
24
f262c692 25#include "TGButtonGroup.h"
26
786d9102 27#include "TTree.h"
f76c9e9b 28#include "TH1F.h"
29
30#include "TCanvas.h"
786d9102 31#include "TLatex.h"
f76c9e9b 32#include "TEveManager.h"
33
34#include "TROOT.h"
35#include "TSystem.h" // File input/output for track-count status.
f262c692 36#include "TDatime.h"
f76c9e9b 37
38//______________________________________________________________________________
39// GUI editor for AliEveTrackCounter.
40//
41
42ClassImp(AliEveTrackCounterEditor)
43
44//______________________________________________________________________________
45AliEveTrackCounterEditor::AliEveTrackCounterEditor(const TGWindow *p, Int_t width, Int_t height,
46 UInt_t options, Pixel_t back) :
47 TGedFrame(p, width, height, options | kVerticalFrame, back),
c12be4d4 48 fM(0), fAF(0), fDF(0),
3a20f984 49 fClickAction(0),
50 fInfoLabelTracks (0),
51 fInfoLabelTracklets(0),
f262c692 52 fEventId(0),
53 fEventCat(0),
54 fScanSummaryFile(0)
f76c9e9b 55{
56 // Constructor.
57
58 MakeTitle("AliEveTrackCounter");
59
60 Int_t labelW = 42;
61
c12be4d4 62
63 // Active frame
64
65 fAF = new TGVerticalFrame(this);
66
67 { // Deactivate button
68 TGHorizontalFrame* f = new TGHorizontalFrame(fAF, 210, 20, kFixedWidth);
69
70 TGTextButton* b = new TGTextButton(f, "Deactivate");
71 f->AddFrame(b, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 0, 4));
72 b->Connect("Clicked()", "AliEveTrackCounterEditor", this, "DoDeactivate()");
73
74 fAF->AddFrame(f, new TGLayoutHints(kLHintsLeft, 0, 0, 0, 0));
75 }
f76c9e9b 76 { // ClickAction
c12be4d4 77 TGHorizontalFrame* f = new TGHorizontalFrame(fAF);
f76c9e9b 78 TGLabel* lab = new TGLabel(f, "Click:");
79 f->AddFrame(lab, new TGLayoutHints(kLHintsLeft|kLHintsBottom, 1, 10, 1, 2));
80 fClickAction = new TGComboBox(f);
81 fClickAction->AddEntry("Print", 0);
82 fClickAction->AddEntry("Toggle", 1);
83 TGListBox* lb = fClickAction->GetListBox();
84 lb->Resize(lb->GetWidth(), 2*16);
85 fClickAction->Resize(70, 20);
86 fClickAction->Connect("Selected(Int_t)", "AliEveTrackCounterEditor", this,
87 "DoClickAction(Int_t)");
88 f->AddFrame(fClickAction, new TGLayoutHints(kLHintsLeft, 1, 2, 1, 1));
89
c12be4d4 90 fAF->AddFrame(f);
f76c9e9b 91 }
3a20f984 92 { // fInfoLabelTracks
c12be4d4 93 TGHorizontalFrame* f = new TGHorizontalFrame(fAF);
3a20f984 94 TGLabel* lab = new TGLabel(f, "Tracks:");
f76c9e9b 95 f->AddFrame(lab, new TGLayoutHints(kLHintsLeft, 1, 5, 1, 2));
96
3a20f984 97 fInfoLabelTracks = new TGLabel(f);
98 f->AddFrame(fInfoLabelTracks, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 9, 1, 2));
99
c12be4d4 100 fAF->AddFrame(f);
3a20f984 101 }
102 { // fInfoLabelTracklets
c12be4d4 103 TGHorizontalFrame* f = new TGHorizontalFrame(fAF);
3a20f984 104 TGLabel* lab = new TGLabel(f, "Tracklets:");
105 f->AddFrame(lab, new TGLayoutHints(kLHintsLeft, 1, 5, 1, 2));
106
107 fInfoLabelTracklets = new TGLabel(f);
108 f->AddFrame(fInfoLabelTracklets, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 9, 1, 2));
f76c9e9b 109
c12be4d4 110 fAF->AddFrame(f);
f76c9e9b 111 }
f76c9e9b 112 {
c12be4d4 113 TGHorizontalFrame* f = new TGHorizontalFrame(fAF, 210, 20, kFixedWidth);
f76c9e9b 114
115 TGHorizontalFrame* g = new TGHorizontalFrame(f, labelW, 0, kFixedWidth);
116 TGLabel* l = new TGLabel(g, "Event:");
117 g->AddFrame(l, new TGLayoutHints(kLHintsLeft, 0,0,4,0));
118 f->AddFrame(g);
119
120 TGTextButton* b;
121
122 b = new TGTextButton(f, "Prev");
123 f->AddFrame(b, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 0, 0));
124 b->Connect("Clicked()", "AliEveTrackCounterEditor", this, "DoPrev()");
125
126 fEventId = new TGNumberEntry(f, 0, 3, -1,TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative,
127 TGNumberFormat::kNELLimitMinMax, 0, 10000);
128 f->AddFrame(fEventId, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 0, 0));
129 fEventId->Connect("ValueSet(Long_t)", "AliEveTrackCounterEditor", this, "DoSetEvent()");
130
131 b = new TGTextButton(f, "Next");
132 f->AddFrame(b, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 0, 0));
133 b->Connect("Clicked()", "AliEveTrackCounterEditor", this, "DoNext()");
134
c12be4d4 135 fAF->AddFrame(f);
f76c9e9b 136 }
f76c9e9b 137 {
c12be4d4 138 TGHorizontalFrame* f = new TGHorizontalFrame(fAF, 210, 20, kFixedWidth);
f76c9e9b 139
140 TGHorizontalFrame* g = new TGHorizontalFrame(f, labelW, 0, kFixedWidth);
141 TGLabel* l = new TGLabel(g, "Report:");
142 g->AddFrame(l, new TGLayoutHints(kLHintsLeft, 0,0,4,0));
143 f->AddFrame(g);
144
145 TGTextButton* b;
146
147 b = new TGTextButton(f, "Print");
148 f->AddFrame(b, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 0, 0));
149 b->Connect("Clicked()", "AliEveTrackCounterEditor", this, "DoPrintReport()");
150
151 b = new TGTextButton(f, "File");
152 f->AddFrame(b, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 0, 0));
153 b->Connect("Clicked()", "AliEveTrackCounterEditor", this, "DoFileReport()");
154
c12be4d4 155 fAF->AddFrame(f, new TGLayoutHints(kLHintsLeft, 0, 0, 4, 0));
f76c9e9b 156 }
157 {
c12be4d4 158 TGHorizontalFrame* f = new TGHorizontalFrame(fAF, 210, 20, kFixedWidth);
f76c9e9b 159
160 TGHorizontalFrame* g = new TGHorizontalFrame(f, labelW, 0, kFixedWidth);
161 TGLabel* l = new TGLabel(g, "Histos:");
162 g->AddFrame(l, new TGLayoutHints(kLHintsLeft, 0,0,4,0));
163 f->AddFrame(g);
164
165 TGTextButton* b;
166
167 b = new TGTextButton(f, "Show");
168 f->AddFrame(b, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 0, 0));
169 b->Connect("Clicked()", "AliEveTrackCounterEditor", this, "DoShowHistos()");
170
c12be4d4 171 fAF->AddFrame(f, new TGLayoutHints(kLHintsLeft, 0, 0, 0, 0));
f76c9e9b 172 }
f262c692 173 {
174 TGHorizontalFrame* f = new TGHorizontalFrame(fAF, 210, 20, kFixedWidth);
175
176 TGButtonGroup *fTypeSelector = new TGButtonGroup(f, "Event Categorization");
177 new TGRadioButton(fTypeSelector, "Good");
178 new TGRadioButton(fTypeSelector, "Splash");
179 new TGRadioButton(fTypeSelector, "Empty");
180 new TGRadioButton(fTypeSelector, "Background");
181 new TGRadioButton(fTypeSelector, "Unclear/Other");
182 fTypeSelector->Connect("Clicked(Int_t)", "AliEveTrackCounterEditor", this, "DoEventCategorization(Int_t)");
183
184 f->AddFrame(fTypeSelector, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 3, 2, 2));
185
186 fAF->AddFrame(f, new TGLayoutHints(kLHintsLeft, 0, 0, 0, 0));
187 }
f76c9e9b 188
c12be4d4 189 AddFrame(fAF, new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY));
190
191
192 // Disabled frame
193
194 fDF = new TGVerticalFrame(this);
195
196 { // Activate button
197 TGHorizontalFrame* f = new TGHorizontalFrame(fDF, 210, 20, kFixedWidth);
198
199 TGTextButton* b = new TGTextButton(f, "Activate");
200 f->AddFrame(b, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 0, 0));
201 b->Connect("Clicked()", "AliEveTrackCounterEditor", this, "DoActivate()");
202
203 fDF->AddFrame(f, new TGLayoutHints(kLHintsLeft, 0, 0, 0, 0));
204 }
205
206 AddFrame(fDF, new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY));
207
208 AliEveEventManager::GetMaster()->Connect("NewEventLoaded()", "AliEveTrackCounterEditor", this, "UpdateModel()");
12365217 209}
210
211AliEveTrackCounterEditor::~AliEveTrackCounterEditor()
212{
213 // Destructor.
214
4d62585e 215 AliEveEventManager::GetMaster()->Disconnect("NewEventLoaded()", this);
f262c692 216
217 if (fScanSummaryFile) {
218 fScanSummaryFile->close();
219 delete fScanSummaryFile;
220 fScanSummaryFile = 0;
221 }
f76c9e9b 222}
223
224/******************************************************************************/
225
12365217 226void AliEveTrackCounterEditor::UpdateModel()
227{
22828c05 228 if (fGedEditor && fM && fGedEditor->GetModel() == fM->GetEditorObject("TEveElement::GetEditorObject"))
12365217 229 {
22828c05 230 SetModel(fM->GetEditorObject("TEveElement::GetEditorObject"));
12365217 231 }
232}
233
f76c9e9b 234//______________________________________________________________________________
235void AliEveTrackCounterEditor::SetModel(TObject* obj)
236{
237 // Set model object.
238
239 fM = dynamic_cast<AliEveTrackCounter*>(obj);
240
c12be4d4 241 if (fM->GetActive())
242 {
243 ShowFrame(fAF); HideFrame(fDF);
244
245 fClickAction->Select(fM->fClickAction, kFALSE);
246 fInfoLabelTracks ->SetText(Form("All: %3d; Primaries: %3d", fM->fAllTracks, fM->fGoodTracks));
247 fInfoLabelTracklets->SetText(Form("All: %3d; Primaries: %3d", fM->fAllTracklets, fM->fGoodTracklets));
248 fEventId->SetNumber(fM->GetEventId());
249 }
250 else
251 {
252 ShowFrame(fDF); HideFrame(fAF);
253 }
254
255 Layout();
256}
257
258/******************************************************************************/
259
260void AliEveTrackCounterEditor::DoActivate()
261{
262 // Activate track-counter
263
264 fM->SetActive(kTRUE);
265 AliEveEventManager::GetMaster()->GotoEvent(AliEveEventManager::GetMaster()->GetEventId());
266 fGedEditor->Layout();
f262c692 267
268 if (fScanSummaryFile) {
269 fScanSummaryFile->close();
270 delete fScanSummaryFile;
271 }
272
273 char fname[200];
274 TDatime dat;
275 sprintf(fname, "ScanSummary.%i.%i.txt", dat.GetDate(), dat.GetTime());
276 fScanSummaryFile = new ofstream(fname);
277 (*fScanSummaryFile) << "Scan summary" << std::endl;
278 (*fScanSummaryFile) << "Scan started at " << dat.GetDate() << " " << dat.GetTime() << std::endl;
279 AliESDEvent *esd = AliEveEventManager::AssertESD();
280 (*fScanSummaryFile) << "Run number " << esd->GetRunNumber() << std::endl;
c12be4d4 281}
282
283void AliEveTrackCounterEditor::DoDeactivate()
284{
285 // Deactivate track-counter.
286
287 fM->SetActive(kFALSE);
288 AliEveEventManager::GetMaster()->GotoEvent(AliEveEventManager::GetMaster()->GetEventId());
f262c692 289
290 if (fScanSummaryFile) {
291 fScanSummaryFile->close();
292 delete fScanSummaryFile;
293 fScanSummaryFile = 0;
294 }
f76c9e9b 295}
296
297/******************************************************************************/
298
299//______________________________________________________________________________
300void AliEveTrackCounterEditor::DoPrev()
301{
302 // Slot for Prev.
303
4d62585e 304 AliEveEventManager::GetMaster()->PrevEvent();
f76c9e9b 305}
306
307//______________________________________________________________________________
308void AliEveTrackCounterEditor::DoNext()
309{
310 // Slot for Next.
311
f262c692 312 if (fScanSummaryFile) {
313 AliESDEvent *esd = AliEveEventManager::AssertESD();
314 (*fScanSummaryFile) << std::hex << std::right ;
315 fScanSummaryFile->width(5); (*fScanSummaryFile) << esd->GetPeriodNumber() << " " ;
316 fScanSummaryFile->width(6); (*fScanSummaryFile) << esd->GetOrbitNumber() << " ";
317 fScanSummaryFile->width(4); (*fScanSummaryFile) << esd->GetBunchCrossNumber() << " ";
318 switch (fEventCat) {
319 case 1: (*fScanSummaryFile) << "GOOD "; break;
320 case 2: (*fScanSummaryFile) << "SPLASH "; break;
321 case 3: (*fScanSummaryFile) << "EMPTY "; break;
322 case 4: (*fScanSummaryFile) << "BACKGROUND "; break;
323 case 5: (*fScanSummaryFile) << "OTHER "; break;
324 default: break;
325 }
326 if (fM->GetActive())
327 {
328 (*fScanSummaryFile) << std::dec;
329 fScanSummaryFile->width(5); (*fScanSummaryFile) << fM->fAllTracks << " ";
330 fScanSummaryFile->width(5); (*fScanSummaryFile) << fM->fGoodTracks << " ";
331 fScanSummaryFile->width(5); (*fScanSummaryFile) << fM->fAllTracklets << " ";
332 fScanSummaryFile->width(5); (*fScanSummaryFile) << fM->fGoodTracklets << " ";
333 }
334 if ((esd->GetPrimaryVertex()) && (esd->GetPrimaryVertex()->GetStatus()))
335 { fScanSummaryFile->width(9); (*fScanSummaryFile) << esd->GetPrimaryVertex()->GetZ(); }
336 else { (*fScanSummaryFile) << "NOVTX "; }
337
338 (*fScanSummaryFile) << std::endl;
339 }
340
4d62585e 341 AliEveEventManager::GetMaster()->NextEvent();
f76c9e9b 342}
343
344//______________________________________________________________________________
345void AliEveTrackCounterEditor::DoSetEvent()
346{
347 // Slot for SetEvent.
c12be4d4 348
4d62585e 349 AliEveEventManager::GetMaster()->GotoEvent((Int_t) fEventId->GetNumber());
f76c9e9b 350}
351
352/******************************************************************************/
353
354//______________________________________________________________________________
355void AliEveTrackCounterEditor::DoPrintReport()
356{
357 // Slot for PrintReport.
358
786d9102 359 fM->PrintEventTracks();
f76c9e9b 360}
361
362//______________________________________________________________________________
363void AliEveTrackCounterEditor::DoFileReport()
364{
365 // Slot for FileReport.
366
786d9102 367 fM->OutputEventTracks();
f76c9e9b 368}
369
370//______________________________________________________________________________
371void AliEveTrackCounterEditor::DoShowHistos()
372{
373 // Slot for ShowHistos.
374
c12be4d4 375 TEveUtil::Macro("make_scan_results.C");
786d9102 376 TEveUtil::Macro("show_scan_results.C");
f76c9e9b 377}
378
379/******************************************************************************/
380
381//______________________________________________________________________________
382void AliEveTrackCounterEditor::DoClickAction(Int_t mode)
383{
384 // Slot for ClickAction.
385
386 fM->SetClickAction(mode);
387}
f262c692 388
389//______________________________________________________________________________
390void AliEveTrackCounterEditor::DoEventCategorization(Int_t mode)
391{
392 // Slot for ClickAction.
393
394 printf("Mode is %i\n", mode);
395 fEventCat = mode;
396}