* show_scan_results.C
[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
14 #include "TGedEditor.h"
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 "TTree.h"
25 #include "TH1F.h"
26
27 #include "TCanvas.h"
28 #include "TLatex.h"
29 #include "TEveManager.h"
30
31 #include "TROOT.h"
32 #include "TSystem.h" // File input/output for track-count status.
33
34 //______________________________________________________________________________
35 // GUI editor for AliEveTrackCounter.
36 //
37
38 ClassImp(AliEveTrackCounterEditor)
39
40 //______________________________________________________________________________
41 AliEveTrackCounterEditor::AliEveTrackCounterEditor(const TGWindow *p, Int_t width, Int_t height,
42                                                UInt_t options, Pixel_t back) :
43    TGedFrame(p, width, height, options | kVerticalFrame, back),
44    fM(0),
45    fClickAction(0),
46    fInfoLabelTracks   (0),
47    fInfoLabelTracklets(0),
48    fEventId(0)
49 {
50    // Constructor.
51
52    MakeTitle("AliEveTrackCounter");
53
54    Int_t labelW = 42;
55
56    { // ClickAction
57       TGHorizontalFrame* f = new TGHorizontalFrame(this);
58       TGLabel* lab = new TGLabel(f, "Click:");
59       f->AddFrame(lab, new TGLayoutHints(kLHintsLeft|kLHintsBottom, 1, 10, 1, 2));
60       fClickAction = new TGComboBox(f);
61       fClickAction->AddEntry("Print", 0);
62       fClickAction->AddEntry("Toggle", 1);
63       TGListBox* lb = fClickAction->GetListBox();
64       lb->Resize(lb->GetWidth(), 2*16);
65       fClickAction->Resize(70, 20);
66       fClickAction->Connect("Selected(Int_t)", "AliEveTrackCounterEditor", this,
67                             "DoClickAction(Int_t)");
68       f->AddFrame(fClickAction, new TGLayoutHints(kLHintsLeft, 1, 2, 1, 1));
69
70       AddFrame(f);
71    }
72
73    { // fInfoLabelTracks
74       TGHorizontalFrame* f = new TGHorizontalFrame(this);
75       TGLabel* lab = new TGLabel(f, "Tracks:");
76       f->AddFrame(lab, new TGLayoutHints(kLHintsLeft, 1, 5, 1, 2));
77
78       fInfoLabelTracks = new TGLabel(f);
79       f->AddFrame(fInfoLabelTracks, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 9, 1, 2));
80
81       AddFrame(f);
82    }
83    { // fInfoLabelTracklets
84       TGHorizontalFrame* f = new TGHorizontalFrame(this);
85       TGLabel* lab = new TGLabel(f, "Tracklets:");
86       f->AddFrame(lab, new TGLayoutHints(kLHintsLeft, 1, 5, 1, 2));
87
88       fInfoLabelTracklets = new TGLabel(f);
89       f->AddFrame(fInfoLabelTracklets, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 9, 1, 2));
90
91       AddFrame(f);
92    }
93
94    {
95       TGHorizontalFrame* f = new TGHorizontalFrame(this, 210, 20, kFixedWidth);
96
97       TGHorizontalFrame* g = new TGHorizontalFrame(f, labelW, 0, kFixedWidth);
98       TGLabel* l = new TGLabel(g, "Event:");
99       g->AddFrame(l, new TGLayoutHints(kLHintsLeft, 0,0,4,0));
100       f->AddFrame(g);
101
102       TGTextButton* b;
103
104       b = new TGTextButton(f, "Prev");
105       f->AddFrame(b, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 0, 0));
106       b->Connect("Clicked()", "AliEveTrackCounterEditor", this, "DoPrev()");
107
108       fEventId = new TGNumberEntry(f, 0, 3, -1,TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative,
109                                    TGNumberFormat::kNELLimitMinMax, 0, 10000);
110       f->AddFrame(fEventId, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 0, 0));
111       fEventId->Connect("ValueSet(Long_t)", "AliEveTrackCounterEditor", this, "DoSetEvent()");
112
113       b = new TGTextButton(f, "Next");
114       f->AddFrame(b, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 0, 0));
115       b->Connect("Clicked()", "AliEveTrackCounterEditor", this, "DoNext()");
116
117       AddFrame(f);
118    }
119
120    {
121       TGHorizontalFrame* f = new TGHorizontalFrame(this, 210, 20, kFixedWidth);
122
123       TGHorizontalFrame* g = new TGHorizontalFrame(f, labelW, 0, kFixedWidth);
124       TGLabel* l = new TGLabel(g, "Report:");
125       g->AddFrame(l, new TGLayoutHints(kLHintsLeft, 0,0,4,0));
126       f->AddFrame(g);
127
128       TGTextButton* b;
129
130       b = new TGTextButton(f, "Print");
131       f->AddFrame(b, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 0, 0));
132       b->Connect("Clicked()", "AliEveTrackCounterEditor", this, "DoPrintReport()");
133
134       b = new TGTextButton(f, "File");
135       f->AddFrame(b, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 0, 0));
136       b->Connect("Clicked()", "AliEveTrackCounterEditor", this, "DoFileReport()");
137
138       AddFrame(f, new TGLayoutHints(kLHintsLeft, 0, 0, 4, 0));
139    }
140    {
141       TGHorizontalFrame* f = new TGHorizontalFrame(this, 210, 20, kFixedWidth);
142
143       TGHorizontalFrame* g = new TGHorizontalFrame(f, labelW, 0, kFixedWidth);
144       TGLabel* l = new TGLabel(g, "Histos:");
145       g->AddFrame(l, new TGLayoutHints(kLHintsLeft, 0,0,4,0));
146       f->AddFrame(g);
147
148       TGTextButton* b;
149
150       b = new TGTextButton(f, "Show");
151       f->AddFrame(b, new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 0, 0));
152       b->Connect("Clicked()", "AliEveTrackCounterEditor", this, "DoShowHistos()");
153
154       AddFrame(f, new TGLayoutHints(kLHintsLeft, 0, 0, 0, 0));
155    }
156
157   AliEveEventManager::GetMaster()->Connect("NewEventLoaded()",
158                         "AliEveTrackCounterEditor", this, "UpdateModel()");
159 }
160
161 AliEveTrackCounterEditor::~AliEveTrackCounterEditor()
162 {
163   // Destructor.
164
165   AliEveEventManager::GetMaster()->Disconnect("NewEventLoaded()", this);
166 }
167
168 /******************************************************************************/
169
170 void AliEveTrackCounterEditor::UpdateModel()
171 {
172   if (fGedEditor && fM && fGedEditor->GetModel() == fM->GetEditorObject())
173   {
174     SetModel(fM->GetEditorObject());
175   }
176 }
177
178 //______________________________________________________________________________
179 void AliEveTrackCounterEditor::SetModel(TObject* obj)
180 {
181    // Set model object.
182
183    fM = dynamic_cast<AliEveTrackCounter*>(obj);
184
185    fClickAction->Select(fM->fClickAction, kFALSE);
186    fInfoLabelTracks   ->SetText(Form("All: %3d; Primaries: %3d", fM->fAllTracks,    fM->fGoodTracks));
187    fInfoLabelTracklets->SetText(Form("All: %3d; Primaries: %3d", fM->fAllTracklets, fM->fGoodTracklets));
188    fEventId->SetNumber(fM->GetEventId());
189 }
190
191 /******************************************************************************/
192
193 //______________________________________________________________________________
194 void AliEveTrackCounterEditor::DoPrev()
195 {
196    // Slot for Prev.
197
198    AliEveEventManager::GetMaster()->PrevEvent();
199 }
200
201 //______________________________________________________________________________
202 void AliEveTrackCounterEditor::DoNext()
203 {
204    // Slot for Next.
205
206    AliEveEventManager::GetMaster()->NextEvent();
207 }
208
209 //______________________________________________________________________________
210 void AliEveTrackCounterEditor::DoSetEvent()
211 {
212    // Slot for SetEvent.
213    AliEveEventManager::GetMaster()->GotoEvent((Int_t) fEventId->GetNumber());
214 }
215
216 /******************************************************************************/
217
218 //______________________________________________________________________________
219 void AliEveTrackCounterEditor::DoPrintReport()
220 {
221    // Slot for PrintReport.
222
223    fM->PrintEventTracks();
224 }
225
226 //______________________________________________________________________________
227 void AliEveTrackCounterEditor::DoFileReport()
228 {
229    // Slot for FileReport.
230
231    fM->OutputEventTracks();
232 }
233
234 //______________________________________________________________________________
235 void AliEveTrackCounterEditor::DoShowHistos()
236 {
237   // Slot for ShowHistos.
238
239   static const TEveException kEH("AliEveTrackCounterEditor::DoShowHistos ");
240
241   TEveUtil::Macro("show_scan_results.C");
242
243   TTree* t = (TTree*) gDirectory->Get("SR");
244
245   if (t == 0)
246     throw kEH + "Tree 'SR' with scan results not found.";
247
248   TCanvas *c = 0;
249
250   //----------------------------------------------------------------------------
251   // Tracks
252   //----------------------------------------------------------------------------
253
254   c = new TCanvas("Tracks", "Track Scanning Results", 800, 600);
255   c->Divide(2, 3);
256
257   c->cd(1);
258   t->Draw("Sum$(T.fLabel & 1)");
259
260   c->cd(2);
261   t->Draw("T.GetSign()", "T.fLabel & 1");
262
263   c->cd(3);
264   t->Draw("T.GetSign()", "T.fLabel & 1");
265
266   c->cd(4);
267   t->Draw("T.Eta()", "T.fLabel & 1");
268
269   c->cd(5);
270   t->Draw("T.Phi()", "T.fLabel & 1");
271
272   c->Modified();
273   c->Update();
274
275   //----------------------------------------------------------------------------
276   // Trackelts
277   //----------------------------------------------------------------------------
278
279   c = new TCanvas("Tracklets", "Tracklet Scanning Results", 800, 600);
280   (new TLatex(0.2, 0.4, "Not yet available"))->Draw();
281
282   c->Modified();
283   c->Update();
284 }
285
286 /******************************************************************************/
287
288 //______________________________________________________________________________
289 void AliEveTrackCounterEditor::DoClickAction(Int_t mode)
290 {
291    // Slot for ClickAction.
292
293    fM->SetClickAction(mode);
294 }