I want to run to use both Geant4 and root to make a gui. So i install G4UIRoot made by I. Gonzales. I add my own class which is a TransientFrame with a few buttons : Execute, Clear, Exit. Exit button is connect to function SendClose Message(). When I click on Exit it crashes and i have the following error message :
Error in : BadWindow (invalid Window parameter) (XID : 56623637, XREQ : 61).
I don’t understand it.
Here is the code for the class i add.
header file:
#ifndef G4RunText
#define G4RunText

#include <TGTextEntry.h>
#include <TGFrame.h>
#include <TGClient.h>
#include <TGButton.h>
#include <TApplication.h>

class TGTextEntry;
class TGButton;
class TGTextView;
class TGLabel;
class TGMenuBar;
class TGPopupMenu;
class TGCanvas;
class TGListTree;
class TApplication;
class G4UImanager;

class G4RunText : public TGTransientFrame {


G4RunText(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h, UInt_t options = kVerticalFrame);
virtual ~G4RunText();

void ExecuteRun();
void ExitRun();
void ClearInputTextLine() {fInputTextEntry->Clear();}

TGCompositeFrame* BuildRunButtonFrame(const TGWindow* p);
TGCompositeFrame* BuildRunInputLine(const TGWindow* w);


TGLayoutHints* fLRunButtonFrame;
TGLayoutHints* fButtonsr;
TGLayoutHints* fLRunInputEntry;
TGLayoutHints* Linputline;
TGLayoutHints* fLInputRunLabel;

TGTextEntry* fInputTextEntry;

TGCompositeFrame* fRunButtonFrame;
TGCompositeFrame* fRunInputFrame;

TGTextButton* fExecuteRunButton;
TGTextButton* fExitRunButton;
TGTextButton* fClearRunButton;

TGLabel* fInputRunLabel;

G4UImanager* UI;




source file :
#include “G4RunText.hh”
#include “G4RootMainFrame.hh”
#include “G4String.hh”
#include “G4UIcommand.hh”
#include “G4UIcommandTree.hh”
#include “G4UImanager.hh”
#include “G4UIcommand.hh”
#include “G4UIcommandStatus.hh”
#include “globals.hh”
#include <stdlib.h>
#include <TGClient.h>
#include <TRootHelpDialog.h>
#include <TGLabel.h>
#include <TGMenu.h>
#include <TGButton.h>
#include <TGTextView.h>
#include <TGCanvas.h>
#include <TGListTree.h>
#include <TGFileDialog.h>
#include <TGSplitter.h>
#include <TSystem.h>
#include <TVirtualX.h>
#include <TApplication.h>
#include <TBuffer.h>

using namespace std;

enum AliRunMessageTypes {

G4RunText::G4RunText(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h, UInt_t options) : TGTransientFrame(p, main, w, h, options)

fLRunInputEntry = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY | kLHintsTop, 10, 10, 10, 10);
fRunInputFrame = BuildRunInputLine(this);
AddFrame(fRunInputFrame, fLRunInputEntry);

fLRunButtonFrame = new TGLayoutHints(kLHintsCenterX | kLHintsBottom,
0, 0, 0, 0);
fRunButtonFrame = BuildRunButtonFrame(this);
AddFrame(fRunButtonFrame, fLRunButtonFrame);


SetWindowName(“choix du nombre d’evenements”);


if (fExecuteRunButton)
delete fExecuteRunButton;
if (fExitRunButton)
delete fExitRunButton;
if (fClearRunButton)
delete fClearRunButton;

if (fLRunInputEntry)
delete fLRunInputEntry;
if (fButtonsr)
delete fButtonsr;
if (Linputline)
delete Linputline;

delete fRunButtonFrame;
if (fRunInputFrame)
delete fRunInputFrame;

if (fInputTextEntry)
delete fInputTextEntry;



void G4RunText::ExecuteRun()
UI = G4UImanager::GetUIpointer();
G4String aCommand = "/run/beamOn ";


void G4RunText::ExitRun()
cout<<“vous devez fermer la fenetre avec la croix ou bien cliquer au prealable sur le bouton Execute”<<endl;
//delete this;

TGCompositeFrame* G4RunText::BuildRunButtonFrame(const TGWindow* p)
TGCompositeFrame *buttonr = new TGCompositeFrame(p, 100, 100, kHorizontalFrame);
fButtonsr = new TGLayoutHints(kLHintsBottom | kLHintsLeft, 2, 2, 2, 2);

fExecuteRunButton = new TGTextButton(buttonr, “&Execute”, kM_EXECUTE_RUN);
fExecuteRunButton->SetToolTipText(“Execute Events”);
fExecuteRunButton->Connect(“Clicked()”, “G4RunText”, this, “ExecuteRun()”);
buttonr->AddFrame(fExecuteRunButton, fButtonsr);

fClearRunButton = new TGTextButton(buttonr, “&Clear”, kM_CLEAR_RUN);
fClearRunButton->SetToolTipText(“Clear Text Entry Line”);
fClearRunButton->Connect(“Clicked()”, “G4RunText”, this, “ClearInputTextLine()”);
buttonr->AddFrame(fClearRunButton, fButtonsr);

fExitRunButton = new TGTextButton(buttonr, “&Exit”, kM_EXIT_RUN);
fExitRunButton->SetToolTipText(“Close Run Window”);
buttonr->AddFrame(fExitRunButton, fButtonsr);
//fExitRunButton->Connect(“Clicked()”, “G4RunText”, this, “ExitRun()”);
fExitRunButton->Connect(“Clicked()”, “G4RunText”, this, “SendCloseMessage()”);

return buttonr;

TGCompositeFrame* G4RunText::BuildRunInputLine(const TGWindow* w) {

TGCompositeFrame *inputline = new TGCompositeFrame(w, 100, 100, kVerticalFrame);

Linputline = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY | kLHintsBottom | kLHintsTop, 2, 2, 2, 2);

fInputTextEntry = new TGTextEntry(inputline, new TGTextBuffer(20));
inputline->AddFrame(fInputTextEntry, Linputline);

fInputRunLabel = new TGLabel(inputline, “Rentrez le nombre d’evenements que vous voulez simuler”);
fLInputRunLabel = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY | kLHintsBottom | kLHintsTop, 2, 2, 2, 2);

return inputline;



Hi Fabien,

See your modified code in attached file. :slight_smile:

ModifiedCode.txt (5.72 KB)

Hi Bertrand,
I modified my code but i have some problem :
when i compile root, all is good. But when i try to run the code i have the following error message :
[courtine@clrpc167 test]$ /home/courtine/geant4/bin/Linux-g++/Puits_ZM_test
/home/courtine/geant4/bin/Linux-g++/Puits_ZM_test: relocation error: /users_local1/geant4.6.2.p01/lib/Linux-g++/ undefined symbol: _ZN9G4RunText11CloseWindowEv

Isn’t it a probleme with cint?
If i compile the part of Geant4, i have got an error message :

[courtine@clrpc167 test]$ gmake
Using granular libraries …
Linking Puits_ZM_test …
/users_local1/geant4.6.2.p01/lib/Linux-g++/ référence indéfinie vers « G4RunText::CloseWindow() »
collect2: ld a retourné 1 code d’état d’exécution
gmake: *** [/home/courtine/geant4/bin/Linux-g++/Puits_ZM_test] Erreur 1

I don’t understand why there is a problem with the function CloseWindow!
Thanks for your help,
Thanks for your help.

Hi Fabien,

I tested your code on windows, and I don’t have neither Geant4 neither G4UIRoot, so I can’t help you on these points.
Sorry. :cry:

I tested your code in compiled mode.
Will try in interactive mode asap (quite busy today), and let you know.


Ok Bertrand,
just a few questions.
I run in mode debug=5 and i see some warning:
Info in TPluginManager::FindHandler: did not find plugin for class TSystem and uri /home/courtine/.root.mimes
Info in TPluginManager::FindHandler: did not find plugin for class TSystem and uri /users_local1/root/etc/system.rootmap
What does it mean?
Should i add something?
The code i run is more complex that i told you:
there is a class to communicate between Root and Geant4, a class which describes the main window. In this window, i add a popu menu and when i click on the menu a window appears. I think the problem is when i sut down this window. Maybe there is some check to do in the main window to assure a proper sut down of the window of the popu menu

Hi Fabien,

Your code is working on win32, compiled or interpreted, without problem…
And about :

Apparently the plugin manager is looking for “uri”.
If you take a look into $(ROOTSYS)/etc/system.rootrc, you will see the plugin library handlers. But I have no idea what is this “uri”…