GENIEGenerator
Loading...
Searching...
No Matches
GNuMcMainFrame.cxx
Go to the documentation of this file.
1//____________________________________________________________________________
2/*
3 Copyright (c) 2003-2025, The GENIE Collaboration
4 For the full text of the license visit http://copyright.genie-mc.org
5
6 Costas Andreopoulos <c.andreopoulos \at cern.ch>
7 University of Liverpool
8*/
9//____________________________________________________________________________
10
11#include <iomanip>
12#include <sstream>
13#include <string>
14#include <vector>
15
16#include <TSystem.h>
17#include <TFile.h>
18#include <TTree.h>
19#include <TVirtualX.h>
20#include <TGListBox.h>
21#include <TGComboBox.h>
22#include <TGClient.h>
23#include <TGIcon.h>
24#include <TGLabel.h>
25#include <TGNumberEntry.h>
26#include <TGTextEntry.h>
27#include <TGMsgBox.h>
28#include <TGMenu.h>
29#include <TGCanvas.h>
30#include <TGTab.h>
31#include <TGFileDialog.h>
32#include <TGTextEdit.h>
33#include <TGStatusBar.h>
34#include <TGProgressBar.h>
35#include <TGColorSelect.h>
36#include <TCanvas.h>
37#include <TGraphAsymmErrors.h>
38#include <TRootEmbeddedCanvas.h>
39#include <TLorentzVector.h>
40#include <TLine.h>
41#include <TEllipse.h>
42#include <TLatex.h>
43#include <TStyle.h>
44
53
54using std::ostringstream;
55using std::setprecision;
56using std::string;
57using std::vector;
58
59using namespace genie;
60using namespace genie::masterclass;
61
63
64//______________________________________________________________________________
65GNuMcMainFrame::GNuMcMainFrame(const TGWindow * p, UInt_t w, UInt_t h) :
66TGMainFrame(p, w, h)
67{
68 this->Init();
69 this->BuildGUI(p,w,h);
70 this->BuildHelpers();
71}
72//______________________________________________________________________________
74{
75 fMain = 0;
77 fMainFrame = 0;
78 fUpperFrame = 0;
79 fLowerFrame = 0;
80 fViewerTabs = 0;
81 fFeynmanTab = 0;
82 fGHepTab = 0;
84 fGHep = 0;
85 fStatusBar = 0;
93 fExitButton = 0;
94 fViewTabWidth = 0;
96
97 fTruthDisplay = 0;
98
99 fEventFilename = "";
100 fEventFile = 0;
101 fGHepTree = 0;
102 fMCRecord = 0;
103 fNuOfEvents = 0;
104 fCurrEventNu = 0;
105
106}
107//______________________________________________________________________________
108void GNuMcMainFrame::BuildGUI(const TGWindow * p, UInt_t w, UInt_t h)
109{
110 fMain = new TGMainFrame(p,w,h);
111
112 fMain->Connect(
113 "CloseWindow()", "genie::GNuMcMainFrame", this, "Close()");
114
115 this->BuildMainFrames();
116
117 //
118 // UPPER FRAME: add image buttons frame
119 //
120
122 fUpperFrame -> AddFrame( fImgButtonGroupFrame );
123
124 this->BuildTabs();
125 this->BuildStatusBar();
126
127 // initialize
128 fMain->SetWindowName("GENIE Event Viewer");
129 fMain->MapSubwindows();
130 fMain->Resize( fMain->GetDefaultSize() );
131 fMain->MapWindow();
132}
133//______________________________________________________________________________
135{
136 fMain->Cleanup();
137 delete fMain;
138
139 delete fTruthDisplay;
140}
141//______________________________________________________________________________
143{
144 fMainFrame = new TGCompositeFrame(fMain, 1, 1, kVerticalFrame );
145 fUpperFrame = new TGCompositeFrame(fMainFrame, 3, 3, kHorizontalFrame);
146 fLowerFrame = new TGCompositeFrame(fMainFrame, 3, 3, kHorizontalFrame);
147
148 fMainFrame -> AddFrame ( fUpperFrame );
149 fMainFrame -> AddFrame ( fLowerFrame );
150 fMain -> AddFrame ( fMainFrame );
151}
152//______________________________________________________________________________
154{
155 TGGroupFrame * bf = new TGGroupFrame(
156 fUpperFrame, "Viewer Control Buttons", kHorizontalFrame);
157
159 new TGPictureButton(bf, gClient->GetPicture(Icon("open"),32,32));
161 new TGPictureButton(bf, gClient->GetPicture(Icon("next"),32,32));
163 new TGPictureButton(bf, gClient->GetPicture(Icon("exit"), 32,32),
164 "gApplication->Terminate(0)");
165
166 fFileOpenButton -> SetToolTipText( "Open event file" , 1);
167 fNextEventButton -> SetToolTipText( "Get next event" , 1);
168 fExitButton -> SetToolTipText( "Exit", 1);
169
170 fFileOpenButton -> Connect(
171 "Clicked()","genie::masterclass::GNuMcMainFrame", this,"FileOpen()");
172 fNextEventButton -> Connect(
173 "Clicked()","genie::masterclass::GNuMcMainFrame", this,"NextEvent()");
174
175 bf -> AddFrame( fFileOpenButton );
176 bf -> AddFrame( fNextEventButton );
177 bf -> AddFrame( fExitButton );
178
179 return bf;
180}
181//______________________________________________________________________________
183{
184 fViewTabWidth = 780;
185 fViewTabHeight = 300;
186
187 fViewerTabs = new TGTab(fLowerFrame, 1, 1);
188
189 this->BuildMCTruthTab ();
192
193 ULong_t hintViewerTabsLayout =
194 kLHintsTop | kLHintsExpandX | kLHintsExpandY;
196 = new TGLayoutHints(hintViewerTabsLayout, 5, 5, 10, 1);
197
199}
200//______________________________________________________________________________
202{
203// Add tab for displaying MC truth
204//
205 TGCompositeFrame * tf = 0;
206
207 unsigned int w = fViewTabWidth;
208 unsigned int h = fViewTabHeight;
209
210 // tab: Draw "Feynman" diagram
211
212 tf = fViewerTabs->AddTab( "Feynman Diagram" );
213
214 fFeynmanTab = new TGCompositeFrame(tf, w, h, kVerticalFrame);
215 fEmbeddedCanvas = new TRootEmbeddedCanvas("fEmbeddedCanvas", fFeynmanTab, w, h);
216
217 fEmbeddedCanvas -> GetCanvas() -> SetBorderMode (0);
218 fEmbeddedCanvas -> GetCanvas() -> SetFillColor (0);
219
220 ULong_t hintFeynmanTabLayout =
221 kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY;
223 new TGLayoutHints(hintFeynmanTabLayout, 5, 5, 10, 1);
224
226 tf -> AddFrame( fFeynmanTab, fFeynmanTabLayout );
227
228 // tab: Print GHEP record
229
230 tf = fViewerTabs->AddTab("GHEP Record");
231
232 fGHepTab = new TGCompositeFrame(tf, w, h, kVerticalFrame);
233
234 fGHep = new TGTextEdit(fGHepTab, w, h, kSunkenFrame | kDoubleBorder);
235 fGHep->AddLine( "GHEP:" );
236
237 ULong_t hintGHepTabLayout =
238 kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY;
240 = new TGLayoutHints(hintGHepTabLayout, 5, 5, 10, 1);
241
242 fGHepTab -> AddFrame(fGHep, fGHepTabLayout);
243 tf -> AddFrame(fGHepTab, fGHepTabLayout);
244}
245//______________________________________________________________________________
247{
248// Build tab for displaying fast simulation results of scintillator calorimeter
249// response and for controlling simulation inputs.
250//
251 TGCompositeFrame * tf = 0;
252
253 tf = fViewerTabs->AddTab("FastSim/ScintCalo");
254
255}
256//______________________________________________________________________________
258{
259// Build tab for displaying fast simulation results of Cherenkov detector
260// response and for controlling simulation inputs.
261//
262 TGCompositeFrame * tf = 0;
263
264 tf = fViewerTabs->AddTab("FastSim/Cherenkov");
265
266}
267//______________________________________________________________________________
269{
270 Int_t parts[] = { 60, 20, 20 };
271 fStatusBar = new TGStatusBar(fMain, 50, 10, kHorizontalFrame);
272 fStatusBar->SetParts(parts, 3);
273
274 ULong_t hintStatusBarLayout =
275 kLHintsBottom | kLHintsLeft | kLHintsExpandX;
277 = new TGLayoutHints(hintStatusBarLayout, 0, 0, 2, 0);
278
280}
281//______________________________________________________________________________
282const char * GNuMcMainFrame::Icon(const char * name)
283{
284 ostringstream pic;
285 pic << gSystem->Getenv("GENIE") << "/data/icons/" << name << ".xpm";
286
287 LOG("MasterClass", pINFO) << "Loading icon: " << pic.str();
288
289 return pic.str().c_str();
290}
291//______________________________________________________________________________
296//______________________________________________________________________________
298{
299 fStatusBar->SetText( "Asking for event file name...", 0);
300
301 static TString dir(".");
302 const char * kFileExt[] = {"GHEP/ROOT event files", "*.root", 0, 0};
303
304 TGFileInfo fi;
305 fi.fFileTypes = kFileExt;
306 fi.fIniDir = StrDup(dir.Data());
307
308 new TGFileDialog(gClient->GetRoot(), fMain, kFDOpen, &fi);
309
310 if( fi.fFilename ) {
311 fEventFilename = string( fi.fFilename );
312
313 ostringstream cmd;
314 cmd << "Will read events from: " << fEventFilename;
315 fStatusBar -> SetText( cmd.str().c_str(), 0 );
316
317 if(fEventFile) {
318 fEventFile->Close();
319 delete fEventFile;
320 }
321 if(fGHepTree) {
322 delete fGHepTree;
323 }
324
325 fEventFile =
326 new TFile(fEventFilename.c_str(),"READ");
327 fGHepTree =
328 dynamic_cast <TTree *> (fEventFile->Get("gtree"));
329 if(!fGHepTree) {
330 LOG("MasterClass", pFATAL)
331 << "No GHEP event tree in input file: " << fEventFilename;
332 gAbortingInErr=true;
333 exit(1);
334 }
335 fCurrEventNu = 0;
336 fNuOfEvents = fGHepTree->GetEntries();
337 LOG("MasterClass", pNOTICE)
338 << "Input GHEP event tree has " << fNuOfEvents
339 << ((fNuOfEvents==1) ? " entry." : " entries.");
340
341 NtpMCTreeHeader * thdr =
342 dynamic_cast <NtpMCTreeHeader *> ( fEventFile->Get("header") );
343 LOG("MasterClass", pNOTICE)
344 << "Input tree header: " << *thdr;
345
346 fGHepTree->SetBranchAddress("gmcrec", &fMCRecord);
347
348 }
349}
350//______________________________________________________________________________
352{
353 if(fCurrEventNu >= fNuOfEvents-1) {
354 exit(1);
355 }
356
357 fGHepTree->GetEntry(fCurrEventNu);
358 fCurrEventNu++;
359
360 EventRecord * event = fMCRecord->event;
361
362 this->ShowEvent(event);
363}
364//______________________________________________________________________________
366{
367 fTruthDisplay->DrawDiagram(event);
368 fTruthDisplay->PrintEventRecord(event);
369}
370//______________________________________________________________________________
ClassImp(GNuMcMainFrame) GNuMcMainFrame
string dir
#define pNOTICE
Definition Messenger.h:61
#define pINFO
Definition Messenger.h:62
#define pFATAL
Definition Messenger.h:56
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
Definition Messenger.h:96
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition EventRecord.h:37
Is a concrete implementation of the QELFormFactorsModelI: Form Factors for Quasi Elastic CC vN Delta ...
MINOS-style Ntuple Class to hold an output MC Tree Header.
const char * Icon(const char *name)
GNuMcMainFrame(const TGWindow *p, UInt_t w, UInt_t h)
void ShowEvent(EventRecord *ev_rec)
TRootEmbeddedCanvas * fEmbeddedCanvas
TGGroupFrame * BuildImageButtonFrame(void)
void BuildGUI(const TGWindow *p, UInt_t w, UInt_t h)
void Init(void)
THE MAIN GENIE PROJECT NAMESPACE
Definition AlgCmp.h:25
bool gAbortingInErr
Definition Messenger.cxx:34