2 // Author: Matevz Tadel 2007
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 **************************************************************************/
10 #include "AliEveTrackCounterEditor.h"
11 #include "AliEveTrackCounter.h"
12 #include "AliEveEventManager.h"
14 #include "TGedEditor.h"
15 #include "TVirtualPad.h"
18 // Cleanup these includes:
20 #include "TGNumberEntry.h"
21 #include "TGComboBox.h"
27 #include "TEveManager.h"
30 #include "TSystem.h" // File input/output for track-count status.
32 //______________________________________________________________________________
33 // GUI editor for AliEveTrackCounter.
36 ClassImp(AliEveTrackCounterEditor)
38 //______________________________________________________________________________
39 AliEveTrackCounterEditor::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),
49 MakeTitle("AliEveTrackCounter");
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));
71 TGHorizontalFrame* f = new TGHorizontalFrame(this);
72 TGLabel* lab = new TGLabel(f, "Status:");
73 f->AddFrame(lab, new TGLayoutHints(kLHintsLeft, 1, 5, 1, 2));
75 fInfoLabel = new TGLabel(f);
76 f->AddFrame(fInfoLabel, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 9, 1, 2));
82 TGHorizontalFrame* f = new TGHorizontalFrame(this, 210, 20, kFixedWidth);
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));
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()");
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()");
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()");
108 TGHorizontalFrame* f = new TGHorizontalFrame(this, 210, 20, kFixedWidth);
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));
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()");
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()");
125 AddFrame(f, new TGLayoutHints(kLHintsLeft, 0, 0, 4, 0));
128 TGHorizontalFrame* f = new TGHorizontalFrame(this, 210, 20, kFixedWidth);
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));
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()");
141 AddFrame(f, new TGLayoutHints(kLHintsLeft, 0, 0, 0, 0));
144 AliEveEventManager::GetMaster()->Connect("NewEventLoaded()",
145 "AliEveTrackCounterEditor", this, "UpdateModel()");
148 AliEveTrackCounterEditor::~AliEveTrackCounterEditor()
152 AliEveEventManager::GetMaster()->Disconnect("NewEventLoaded()", this);
155 /******************************************************************************/
157 void AliEveTrackCounterEditor::UpdateModel()
159 if (fGedEditor && fM && fGedEditor->GetModel() == fM->GetEditorObject())
161 SetModel(fM->GetEditorObject());
165 //______________________________________________________________________________
166 void AliEveTrackCounterEditor::SetModel(TObject* obj)
170 fM = dynamic_cast<AliEveTrackCounter*>(obj);
172 fClickAction->Select(fM->fClickAction, kFALSE);
173 fInfoLabel->SetText(Form("All: %3d; Primaries: %3d", fM->fAllTracks, fM->fGoodTracks));
174 fEventId->SetNumber(fM->GetEventId());
177 /******************************************************************************/
179 //______________________________________________________________________________
180 void AliEveTrackCounterEditor::DoPrev()
184 AliEveEventManager::GetMaster()->PrevEvent();
187 //______________________________________________________________________________
188 void AliEveTrackCounterEditor::DoNext()
192 AliEveEventManager::GetMaster()->NextEvent();
195 //______________________________________________________________________________
196 void AliEveTrackCounterEditor::DoSetEvent()
198 // Slot for SetEvent.
199 AliEveEventManager::GetMaster()->GotoEvent((Int_t) fEventId->GetNumber());
202 /******************************************************************************/
204 //______________________________________________________________________________
205 void AliEveTrackCounterEditor::DoPrintReport()
207 // Slot for PrintReport.
209 fM->OutputEventTracks();
212 //______________________________________________________________________________
213 void AliEveTrackCounterEditor::DoFileReport()
215 // Slot for FileReport.
217 TString file(Form("ev-report-%03d.txt", fM->GetEventId()));
218 if (gSystem->AccessPathName(file) == kFALSE)
221 new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
223 Form("Event record for event %d already exist.\n Replace?", fM->GetEventId()),
224 kMBIconQuestion, kMBYes | kMBNo, &ret);
228 FILE* out = fopen(file, "w");
230 fM->OutputEventTracks(out);
233 Error("AliEveTrackCounterEditor::DoFileReport",
234 "Can not open file '%s' for writing.", file.Data());
238 //______________________________________________________________________________
239 void AliEveTrackCounterEditor::DoShowHistos()
241 // Slot for ShowHistos.
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);
248 Int_t nn; // fscanf return value
250 for (Int_t i=0; i<1000; ++i)
252 TString file(Form("ev-report-%03d.txt", i));
253 if (gSystem->AccessPathName(file) == kFALSE)
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; }
260 for (Int_t t=0; t<ntr; ++t)
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; }
275 if (gPad == 0 || gPad->GetCanvas()->IsEditable() == kFALSE) {
276 c = new TCanvas("Scanwas", "Scanning Results", 800, 600);
278 c = gPad->GetCanvas();
283 c->cd(1); hcnt->Draw();
284 c->cd(2); hchg->Draw();
285 c->cd(3); hpt ->Draw();
286 c->cd(4); heta->Draw();
292 /******************************************************************************/
294 //______________________________________________________________________________
295 void AliEveTrackCounterEditor::DoClickAction(Int_t mode)
297 // Slot for ClickAction.
299 fM->SetClickAction(mode);