Coverity
[u/mrichter/AliRoot.git] / EVE / EveBase / AliEveTrackCounterEditor.cxx
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"
12 #include "AliEveEventManager.h"
13 #include "AliESDEvent.h"
14
15 #include "TGedEditor.h"
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
25 #include "TGButtonGroup.h"
26
27 #include "TTree.h"
28 #include "TH1F.h"
29
30 #include "TCanvas.h"
31 #include "TLatex.h"
32 #include "TEveManager.h"
33
34 #include "TROOT.h"
35 #include "TSystem.h" // File input/output for track-count status.
36 #include "TDatime.h"
37
38 //______________________________________________________________________________
39 // GUI editor for AliEveTrackCounter.
40 //
41
42 ClassImp(AliEveTrackCounterEditor)
43
44 //______________________________________________________________________________
45 AliEveTrackCounterEditor::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),
48    fM(0), fAF(0), fDF(0),
49    fClickAction(0),
50    fInfoLabelTracks   (0),
51    fInfoLabelTracklets(0),
52    fEventId(0),
53    fEventCat(0),
54    fScanSummaryFile(0)
55 {
56    // Constructor.
57
58    MakeTitle("AliEveTrackCounter");
59
60    Int_t labelW = 42;
61
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    }
76    { // ClickAction
77       TGHorizontalFrame* f = new TGHorizontalFrame(fAF);
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
90       fAF->AddFrame(f);
91    }
92    { // fInfoLabelTracks
93       TGHorizontalFrame* f = new TGHorizontalFrame(fAF);
94       TGLabel* lab = new TGLabel(f, "Tracks:");
95       f->AddFrame(lab, new TGLayoutHints(kLHintsLeft, 1, 5, 1, 2));
96
97       fInfoLabelTracks = new TGLabel(f);
98       f->AddFrame(fInfoLabelTracks, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 9, 1, 2));
99
100       fAF->AddFrame(f);
101    }
102    { // fInfoLabelTracklets
103       TGHorizontalFrame* f = new TGHorizontalFrame(fAF);
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));
109
110       fAF->AddFrame(f);
111    }
112    {
113       TGHorizontalFrame* f = new TGHorizontalFrame(fAF, 210, 20, kFixedWidth);
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
135       fAF->AddFrame(f);
136    }
137    {
138       TGHorizontalFrame* f = new TGHorizontalFrame(fAF, 210, 20, kFixedWidth);
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
155       fAF->AddFrame(f, new TGLayoutHints(kLHintsLeft, 0, 0, 4, 0));
156    }
157    {
158       TGHorizontalFrame* f = new TGHorizontalFrame(fAF, 210, 20, kFixedWidth);
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
171       fAF->AddFrame(f, new TGLayoutHints(kLHintsLeft, 0, 0, 0, 0));
172    }
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    }
188
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()");
209 }
210
211 AliEveTrackCounterEditor::~AliEveTrackCounterEditor()
212 {
213   // Destructor.
214
215   AliEveEventManager::GetMaster()->Disconnect("NewEventLoaded()", this);
216
217   if (fScanSummaryFile) {
218     fScanSummaryFile->close();
219     delete fScanSummaryFile;
220     fScanSummaryFile = 0;
221   }
222 }
223
224 /******************************************************************************/
225
226 void AliEveTrackCounterEditor::UpdateModel()
227 {
228   TEveException e;
229   if (fGedEditor && fM && fGedEditor->GetModel() == fM->GetEditorObject(e))
230   {
231     SetModel(fM->GetEditorObject(e));
232   }
233 }
234
235 //______________________________________________________________________________
236 void AliEveTrackCounterEditor::SetModel(TObject* obj)
237 {
238    // Set model object.
239
240    fM = static_cast<AliEveTrackCounter*>(obj);
241
242    if (fM->GetActive())
243    {
244       ShowFrame(fAF); HideFrame(fDF);
245  
246       fClickAction->Select(fM->fClickAction, kFALSE);
247       fInfoLabelTracks   ->SetText(Form("All: %3d; Primaries: %3d", fM->fAllTracks,    fM->fGoodTracks));
248       fInfoLabelTracklets->SetText(Form("All: %3d; Primaries: %3d", fM->fAllTracklets, fM->fGoodTracklets));
249       fEventId->SetNumber(fM->GetEventId());
250    }
251    else
252    {
253      ShowFrame(fDF); HideFrame(fAF);
254    }
255
256    Layout();
257 }
258
259 /******************************************************************************/
260
261 void AliEveTrackCounterEditor::DoActivate()
262 {
263    // Activate track-counter
264
265    fM->SetActive(kTRUE);
266    AliEveEventManager::GetMaster()->GotoEvent(AliEveEventManager::GetMaster()->GetEventId());
267    fGedEditor->Layout();
268
269    if (fScanSummaryFile) {
270      fScanSummaryFile->close();
271      delete fScanSummaryFile;
272    }
273
274    char fname[200];
275    TDatime dat;
276    snprintf(fname, 200,"ScanSummary.%i.%i.txt", dat.GetDate(), dat.GetTime());
277    fScanSummaryFile = new ofstream(fname);
278    (*fScanSummaryFile) << "Scan summary" << std::endl;
279    (*fScanSummaryFile) << "Scan started at " << dat.GetDate() << " " << dat.GetTime() << std::endl;
280    AliESDEvent *esd = AliEveEventManager::AssertESD();
281    (*fScanSummaryFile) << "Run number " << esd->GetRunNumber() << std::endl;
282 }
283
284 void AliEveTrackCounterEditor::DoDeactivate()
285 {
286    // Deactivate track-counter.
287
288    fM->SetActive(kFALSE);
289    AliEveEventManager::GetMaster()->GotoEvent(AliEveEventManager::GetMaster()->GetEventId());
290
291    if (fScanSummaryFile) {
292      fScanSummaryFile->close();
293      delete fScanSummaryFile;
294      fScanSummaryFile = 0;
295    }
296 }
297
298 /******************************************************************************/
299
300 //______________________________________________________________________________
301 void AliEveTrackCounterEditor::DoPrev()
302 {
303    // Slot for Prev.
304
305    AliEveEventManager::GetMaster()->PrevEvent();
306 }
307
308 //______________________________________________________________________________
309 void AliEveTrackCounterEditor::DoNext()
310 {
311    // Slot for Next.
312
313    if (fScanSummaryFile) {
314      AliESDEvent *esd = AliEveEventManager::AssertESD();
315      (*fScanSummaryFile) << std::hex << std::right ;
316      fScanSummaryFile->width(5); (*fScanSummaryFile) << esd->GetPeriodNumber() << "   " ;
317      fScanSummaryFile->width(6); (*fScanSummaryFile) << esd->GetOrbitNumber() << "   ";
318      fScanSummaryFile->width(4); (*fScanSummaryFile) << esd->GetBunchCrossNumber() << "   ";
319      switch (fEventCat) {
320      case 1: (*fScanSummaryFile) << "GOOD        "; break;
321      case 2: (*fScanSummaryFile) << "SPLASH      "; break;
322      case 3: (*fScanSummaryFile) << "EMPTY       "; break;
323      case 4: (*fScanSummaryFile) << "BACKGROUND  "; break;
324      case 5: (*fScanSummaryFile) << "OTHER       "; break;
325      default: break;
326      }
327      if (fM->GetActive())
328        {
329          (*fScanSummaryFile) << std::dec;
330          fScanSummaryFile->width(5); (*fScanSummaryFile) << fM->fAllTracks << "  ";
331          fScanSummaryFile->width(5); (*fScanSummaryFile) << fM->fGoodTracks << "     ";
332          fScanSummaryFile->width(5); (*fScanSummaryFile) << fM->fAllTracklets << "  ";
333          fScanSummaryFile->width(5); (*fScanSummaryFile) << fM->fGoodTracklets << "   ";
334        }
335      if ((esd->GetPrimaryVertex()) && (esd->GetPrimaryVertex()->GetStatus()))
336        { fScanSummaryFile->width(9); (*fScanSummaryFile) << esd->GetPrimaryVertex()->GetZ(); }
337      else { (*fScanSummaryFile) << "NOVTX    "; }
338
339      (*fScanSummaryFile) << std::endl;
340    }
341
342    AliEveEventManager::GetMaster()->NextEvent();
343 }
344
345 //______________________________________________________________________________
346 void AliEveTrackCounterEditor::DoSetEvent()
347 {
348    // Slot for SetEvent.
349
350    AliEveEventManager::GetMaster()->GotoEvent((Int_t) fEventId->GetNumber());
351 }
352
353 /******************************************************************************/
354
355 //______________________________________________________________________________
356 void AliEveTrackCounterEditor::DoPrintReport()
357 {
358    // Slot for PrintReport.
359
360    fM->PrintEventTracks();
361 }
362
363 //______________________________________________________________________________
364 void AliEveTrackCounterEditor::DoFileReport()
365 {
366    // Slot for FileReport.
367
368    fM->OutputEventTracks();
369 }
370
371 //______________________________________________________________________________
372 void AliEveTrackCounterEditor::DoShowHistos()
373 {
374   // Slot for ShowHistos.
375
376   TEveUtil::Macro("make_scan_results.C");
377   TEveUtil::Macro("show_scan_results.C");
378 }
379
380 /******************************************************************************/
381
382 //______________________________________________________________________________
383 void AliEveTrackCounterEditor::DoClickAction(Int_t mode)
384 {
385    // Slot for ClickAction.
386
387    fM->SetClickAction(mode);
388 }
389
390 //______________________________________________________________________________
391 void AliEveTrackCounterEditor::DoEventCategorization(Int_t mode)
392 {
393    // Slot for ClickAction.
394
395   printf("Mode is %i\n", mode);
396   fEventCat = mode;
397 }