First pass of changes required for visualization of event-embedding.
[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"
f76c9e9b 13
12365217 14#include "TGedEditor.h"
f76c9e9b 15#include "TVirtualPad.h"
16#include "TColor.h"
17
18// Cleanup these includes:
19#include "TGLabel.h"
20#include "TGNumberEntry.h"
21#include "TGComboBox.h"
22#include "TGMsgBox.h"
23
24#include "TH1F.h"
25
26#include "TCanvas.h"
27#include "TEveManager.h"
28
29#include "TROOT.h"
30#include "TSystem.h" // File input/output for track-count status.
31
32//______________________________________________________________________________
33// GUI editor for AliEveTrackCounter.
34//
35
36ClassImp(AliEveTrackCounterEditor)
37
38//______________________________________________________________________________
39AliEveTrackCounterEditor::AliEveTrackCounterEditor(const TGWindow *p, Int_t width, Int_t height,
40 UInt_t options, Pixel_t back) :
41 TGedFrame(p, width, height, options | kVerticalFrame, back),
42 fM(0),
43 fClickAction (0),
44 fInfoLabel (0),
45 fEventId (0)
46{
47 // Constructor.
48
49 MakeTitle("AliEveTrackCounter");
50
51 Int_t labelW = 42;
52
53 { // ClickAction
54 TGHorizontalFrame* f = new TGHorizontalFrame(this);
55 TGLabel* lab = new TGLabel(f, "Click:");
56 f->AddFrame(lab, new TGLayoutHints(kLHintsLeft|kLHintsBottom, 1, 10, 1, 2));
57 fClickAction = new TGComboBox(f);
58 fClickAction->AddEntry("Print", 0);
59 fClickAction->AddEntry("Toggle", 1);
60 TGListBox* lb = fClickAction->GetListBox();
61 lb->Resize(lb->GetWidth(), 2*16);
62 fClickAction->Resize(70, 20);
63 fClickAction->Connect("Selected(Int_t)", "AliEveTrackCounterEditor", this,
64 "DoClickAction(Int_t)");
65 f->AddFrame(fClickAction, new TGLayoutHints(kLHintsLeft, 1, 2, 1, 1));
66
67 AddFrame(f);
68 }
69
70 { // Status
71 TGHorizontalFrame* f = new TGHorizontalFrame(this);
72 TGLabel* lab = new TGLabel(f, "Status:");
73 f->AddFrame(lab, new TGLayoutHints(kLHintsLeft, 1, 5, 1, 2));
74
75 fInfoLabel = new TGLabel(f);
76 f->AddFrame(fInfoLabel, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 9, 1, 2));
77
78 AddFrame(f);
79 }
80
81 {
82 TGHorizontalFrame* f = new TGHorizontalFrame(this, 210, 20, kFixedWidth);
83
84 TGHorizontalFrame* g = new TGHorizontalFrame(f, labelW, 0, kFixedWidth);
85 TGLabel* l = new TGLabel(g, "Event:");
86 g->AddFrame(l, new TGLayoutHints(kLHintsLeft, 0,0,4,0));
87 f->AddFrame(g);
88
89 TGTextButton* b;
90
91 b = new TGTextButton(f, "Prev");
92 f->AddFrame(b, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 0, 0));
93 b->Connect("Clicked()", "AliEveTrackCounterEditor", this, "DoPrev()");
94
95 fEventId = new TGNumberEntry(f, 0, 3, -1,TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative,
96 TGNumberFormat::kNELLimitMinMax, 0, 10000);
97 f->AddFrame(fEventId, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 0, 0));
98 fEventId->Connect("ValueSet(Long_t)", "AliEveTrackCounterEditor", this, "DoSetEvent()");
99
100 b = new TGTextButton(f, "Next");
101 f->AddFrame(b, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 0, 0));
102 b->Connect("Clicked()", "AliEveTrackCounterEditor", this, "DoNext()");
103
104 AddFrame(f);
105 }
106
107 {
108 TGHorizontalFrame* f = new TGHorizontalFrame(this, 210, 20, kFixedWidth);
109
110 TGHorizontalFrame* g = new TGHorizontalFrame(f, labelW, 0, kFixedWidth);
111 TGLabel* l = new TGLabel(g, "Report:");
112 g->AddFrame(l, new TGLayoutHints(kLHintsLeft, 0,0,4,0));
113 f->AddFrame(g);
114
115 TGTextButton* b;
116
117 b = new TGTextButton(f, "Print");
118 f->AddFrame(b, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 0, 0));
119 b->Connect("Clicked()", "AliEveTrackCounterEditor", this, "DoPrintReport()");
120
121 b = new TGTextButton(f, "File");
122 f->AddFrame(b, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 0, 0));
123 b->Connect("Clicked()", "AliEveTrackCounterEditor", this, "DoFileReport()");
124
125 AddFrame(f, new TGLayoutHints(kLHintsLeft, 0, 0, 4, 0));
126 }
127 {
128 TGHorizontalFrame* f = new TGHorizontalFrame(this, 210, 20, kFixedWidth);
129
130 TGHorizontalFrame* g = new TGHorizontalFrame(f, labelW, 0, kFixedWidth);
131 TGLabel* l = new TGLabel(g, "Histos:");
132 g->AddFrame(l, new TGLayoutHints(kLHintsLeft, 0,0,4,0));
133 f->AddFrame(g);
134
135 TGTextButton* b;
136
137 b = new TGTextButton(f, "Show");
138 f->AddFrame(b, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 0, 0));
139 b->Connect("Clicked()", "AliEveTrackCounterEditor", this, "DoShowHistos()");
140
141 AddFrame(f, new TGLayoutHints(kLHintsLeft, 0, 0, 0, 0));
142 }
143
4d62585e 144 AliEveEventManager::GetMaster()->Connect("NewEventLoaded()",
12365217 145 "AliEveTrackCounterEditor", this, "UpdateModel()");
146}
147
148AliEveTrackCounterEditor::~AliEveTrackCounterEditor()
149{
150 // Destructor.
151
4d62585e 152 AliEveEventManager::GetMaster()->Disconnect("NewEventLoaded()", this);
f76c9e9b 153}
154
155/******************************************************************************/
156
12365217 157void AliEveTrackCounterEditor::UpdateModel()
158{
159 if (fGedEditor && fM && fGedEditor->GetModel() == fM->GetEditorObject())
160 {
161 SetModel(fM->GetEditorObject());
162 }
163}
164
f76c9e9b 165//______________________________________________________________________________
166void AliEveTrackCounterEditor::SetModel(TObject* obj)
167{
168 // Set model object.
169
170 fM = dynamic_cast<AliEveTrackCounter*>(obj);
171
172 fClickAction->Select(fM->fClickAction, kFALSE);
173 fInfoLabel->SetText(Form("All: %3d; Primaries: %3d", fM->fAllTracks, fM->fGoodTracks));
174 fEventId->SetNumber(fM->GetEventId());
175}
176
177/******************************************************************************/
178
179//______________________________________________________________________________
180void AliEveTrackCounterEditor::DoPrev()
181{
182 // Slot for Prev.
183
4d62585e 184 AliEveEventManager::GetMaster()->PrevEvent();
f76c9e9b 185}
186
187//______________________________________________________________________________
188void AliEveTrackCounterEditor::DoNext()
189{
190 // Slot for Next.
191
4d62585e 192 AliEveEventManager::GetMaster()->NextEvent();
f76c9e9b 193}
194
195//______________________________________________________________________________
196void AliEveTrackCounterEditor::DoSetEvent()
197{
198 // Slot for SetEvent.
4d62585e 199 AliEveEventManager::GetMaster()->GotoEvent((Int_t) fEventId->GetNumber());
f76c9e9b 200}
201
202/******************************************************************************/
203
204//______________________________________________________________________________
205void AliEveTrackCounterEditor::DoPrintReport()
206{
207 // Slot for PrintReport.
208
209 fM->OutputEventTracks();
210}
211
212//______________________________________________________________________________
213void AliEveTrackCounterEditor::DoFileReport()
214{
215 // Slot for FileReport.
216
217 TString file(Form("ev-report-%03d.txt", fM->GetEventId()));
218 if (gSystem->AccessPathName(file) == kFALSE)
219 {
220 Int_t ret;
221 new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
222 "File Exist",
223 Form("Event record for event %d already exist.\n Replace?", fM->GetEventId()),
224 kMBIconQuestion, kMBYes | kMBNo, &ret);
225 if (ret == kMBNo)
226 return;
227 }
228 FILE* out = fopen(file, "w");
229 if (out) {
230 fM->OutputEventTracks(out);
231 fclose(out);
232 } else {
233 Error("AliEveTrackCounterEditor::DoFileReport",
234 "Can not open file '%s' for writing.", file.Data());
235 }
236}
237
238//______________________________________________________________________________
239void AliEveTrackCounterEditor::DoShowHistos()
240{
241 // Slot for ShowHistos.
242
243 TH1F* hcnt = new TH1F("cnt", "Primeries per event", 41, -0.5, 40.5);
244 TH1F* hchg = new TH1F("chg", "Primary charge", 3, -1.5, 1.5);
245 TH1F* hpt = new TH1F("pt", "pT distribution", 40, 0.0, 8.0);
246 TH1F* heta = new TH1F("eta", "eta distribution", 40, -1.0, 1.0);
247
248 Int_t nn; // fscanf return value
249
250 for (Int_t i=0; i<1000; ++i)
251 {
252 TString file(Form("ev-report-%03d.txt", i));
253 if (gSystem->AccessPathName(file) == kFALSE)
254 {
255 Int_t ev, ntr;
256 FILE* f = fopen(file, "read");
257 nn = fscanf(f, "Event = %d Ntracks = %d", &ev, &ntr);
258 if (nn != 2) { printf("SAFR1 %d\n", nn); fclose(f); return; }
259 hcnt->Fill(ntr);
260 for (Int_t t=0; t<ntr; ++t)
261 {
262 Int_t id, chg;
263 Float_t pt, eta;
264 nn = fscanf(f, "%d: chg=%d pt=%f eta=%f", &id, &chg, &pt, &eta);
265 if (nn != 4) { printf("SAFR2 %d\n", nn); fclose(f); return; }
266 hchg->Fill(chg);
267 hpt ->Fill(pt);
268 heta->Fill(eta);
269 }
270 fclose(f);
271 }
272 }
273
274 TCanvas* c;
275 if (gPad == 0 || gPad->GetCanvas()->IsEditable() == kFALSE) {
276 c = new TCanvas("Scanwas", "Scanning Results", 800, 600);
277 } else {
278 c = gPad->GetCanvas();
279 c->Clear();
280 }
281 c->Divide(2, 2);
282
283 c->cd(1); hcnt->Draw();
284 c->cd(2); hchg->Draw();
285 c->cd(3); hpt ->Draw();
286 c->cd(4); heta->Draw();
287
288 c->Modified();
289 c->Update();
290}
291
292/******************************************************************************/
293
294//______________________________________________________________________________
295void AliEveTrackCounterEditor::DoClickAction(Int_t mode)
296{
297 // Slot for ClickAction.
298
299 fM->SetClickAction(mode);
300}