I ran some tests here, but before reaching the final result, I’ll show the reasoning and the process. As I mentioned, when I run ‘source compile.sh’, I received this message:
ranulfo@ranulfo:~/Documentos/GEANT4_Tutorial/Tutorial/Aula 3$ source compile.sh
In file included from /home/ranulfo/Programas/Geant4/geant4-v11.2.1/geant4-v11.2.0-install/include/Geant4/G4VisExecutive.hh:141,
from tutorial003.cpp:79:
/home/ranulfo/Programas/Geant4/geant4-v11.2.1/geant4-v11.2.0-install/include/Geant4/G4VisExecutive.icc:292:32: error: operator '||' has no right operand
292 | G4VIS_USE_OPENGLX || G4VIS_USE_OPENGLWIN32
I changed the line in the file G4VisExecutive.icc:
#if defined G4VIS_USE_OPENGLQT || G4VIS_USE_OPENGLXM ||\
G4VIS_USE_OPENGLX || G4VIS_USE_OPENGLWIN32
fDefaultGraphicsSystemName = "OGL";
I changed the line to this:
#ifdef USE_OPENGL
fDefaultGraphicsSystemName = "OGL";
The response is this after compiling:
ranulfo@ranulfo:~/Documentos/GEANT4_Tutorial/Tutorial/Aula 3$ source compile.sh
ranulfo@ranulfo:~/Documentos/GEANT4_Tutorial/Tutorial/Aula 3$ ./tutorial003
**************************************************************
Geant4 version Name: geant4-11-02-patch-01 [MT] (16-February-2024)
Copyright : Geant4 Collaboration
References : NIM A 506 (2003), 250-303
: IEEE-TNS 53 (2006), 270-278
: NIM A 835 (2016), 186-225
WWW : http://geant4.org/
**************************************************************
G4PhysListFactory::GetReferencePhysList <Shielding> EMoption= 0
<<< Geant4 Physics List simulation engine: Shielding
<<< (Note that Shielding and Shielding_HP are equivalent!)
hInelastic Shielding : threshold between BERT and FTFP is over the interval
for pions : 3 to 6 GeV
for kaons : 3 to 6 GeV
for proton : 3 to 6 GeV
for neutron : 3 to 6 GeV
@@@ G4ParticleHPInelasticData instantiated for particle neutron data directory variable is G4NEUTRONHPDATA pointing to /home/ranulfo/Programas/Geant4/geant4-v11.2.1/geant4-v11.2.0-install/share/data/G4NDL4.7
Visualization Manager instantiating with verbosity "warnings (3)"...
Visualization Manager initialising...
Registering graphics systems...
You have successfully registered the following graphics systems.
Registered graphics systems are:
ASCIITree (ATree)
DAWNFILE (DAWNFILE)
G4HepRepFile (HepRepFile)
RayTracer (RayTracer)
VRML2FILE (VRML2FILE)
gMocrenFile (gMocrenFile)
TOOLSSG_OFFSCREEN (TSG_OFFSCREEN)
TOOLSSG_OFFSCREEN (TSG_OFFSCREEN, TSG_FILE, TSG)
OpenGLImmediateX (OGLIX, OGLI)
OpenGLStoredX (OGLSX, OGL, OGLS)
Default graphics system is: TSG_OFFSCREEN (based on batch session).
Default window size hint is: 600x600-0+0 (based on G4VisManager initialisation).
Note: Parameters specified on the command line will override these defaults.
Use "vis/open" without parameters to get these defaults.
Registering model factories...
You have successfully registered the following model factories.
Registered model factories:
generic
drawByAttribute
drawByCharge
drawByOriginVolume
drawByParticleID
drawByEncounteredVolume
Registered models:
None
Registered filter factories:
attributeFilter
chargeFilter
originVolumeFilter
particleFilter
encounteredVolumeFilter
Registered filters:
None
You have successfully registered the following user vis actions.
Run Duration User Vis Actions: none
End of Event User Vis Actions: none
End of Run User Vis Actions: none
Some /vis commands (optionally) take a string to specify colour.
"/vis/list" to see available colours.
Available UI session types: [ Qt, tcsh, csh ]
Idle>
Note that the commands are enabled:
OpenGLImmediateX (OGLIX, OGLI)
OpenGLStoredX (OGLSX, OGL, OGLS)
Which was not happening before!
When I add the command “#define G4VIS_USE_OPENGLQT”, change “csh” to “Qt” in the code, and request compilation, the response is:
ranulfo@ranulfo:~/Documentos/GEANT4_Tutorial/Tutorial/Aula 3$ source compile.sh
In file included from /home/ranulfo/Programas/Geant4/geant4-v11.2.1/geant4-v11.2.0-install/include/Geant4/G4VisExecutive.hh:141,
from tutorial003.cpp:79:
/home/ranulfo/Programas/Geant4/geant4-v11.2.1/geant4-v11.2.0-install/include/Geant4/G4VisExecutive.icc:142:10: fatal error: QtGlobal: Arquivo ou diretório inexistente
142 | #include <QtGlobal>
| ^~~~~~~~~~
compilation terminated.
ranulfo@ranulfo:~/Documentos/GEANT4_Tutorial/Tutorial/Aula 3$ ./tutorial003
**************************************************************
Geant4 version Name: geant4-11-02-patch-01 [MT] (16-February-2024)
Copyright : Geant4 Collaboration
References : NIM A 506 (2003), 250-303
: IEEE-TNS 53 (2006), 270-278
: NIM A 835 (2016), 186-225
WWW : http://geant4.org/
**************************************************************
G4PhysListFactory::GetReferencePhysList <Shielding> EMoption= 0
<<< Geant4 Physics List simulation engine: Shielding
<<< (Note that Shielding and Shielding_HP are equivalent!)
hInelastic Shielding : threshold between BERT and FTFP is over the interval
for pions : 3 to 6 GeV
for kaons : 3 to 6 GeV
for proton : 3 to 6 GeV
for neutron : 3 to 6 GeV
@@@ G4ParticleHPInelasticData instantiated for particle neutron data directory variable is G4NEUTRONHPDATA pointing to /home/ranulfo/Programas/Geant4/geant4-v11.2.1/geant4-v11.2.0-install/share/data/G4NDL4.7
Visualization Manager instantiating with verbosity "warnings (3)"...
Visualization Manager initialising...
Registering graphics systems...
You have successfully registered the following graphics systems.
Registered graphics systems are:
ASCIITree (ATree)
DAWNFILE (DAWNFILE)
G4HepRepFile (HepRepFile)
RayTracer (RayTracer)
VRML2FILE (VRML2FILE)
gMocrenFile (gMocrenFile)
TOOLSSG_OFFSCREEN (TSG_OFFSCREEN)
TOOLSSG_OFFSCREEN (TSG_OFFSCREEN, TSG_FILE, TSG)
OpenGLImmediateX (OGLIX, OGLI)
OpenGLStoredX (OGLSX, OGL, OGLS)
Default graphics system is: TSG_OFFSCREEN (based on batch session).
Default window size hint is: 600x600-0+0 (based on G4VisManager initialisation).
Note: Parameters specified on the command line will override these defaults.
Use "vis/open" without parameters to get these defaults.
Registering model factories...
You have successfully registered the following model factories.
Registered model factories:
generic
drawByAttribute
drawByCharge
drawByOriginVolume
drawByParticleID
drawByEncounteredVolume
Registered models:
None
Registered filter factories:
attributeFilter
chargeFilter
originVolumeFilter
particleFilter
encounteredVolumeFilter
Registered filters:
None
You have successfully registered the following user vis actions.
Run Duration User Vis Actions: none
End of Event User Vis Actions: none
End of Run User Vis Actions: none
Some /vis commands (optionally) take a string to specify colour.
"/vis/list" to see available colours.
Available UI session types: [ Qt, tcsh, csh ]
Idle>
Unfortunately, the graphical interface doesn’t open for me to visualize the interaction with more details.
ranulfo@ranulfo:~/Documentos/GEANT4_Tutorial/Tutorial/Aula 3$ source compile.sh
In file included from /home/ranulfo/Programas/Geant4/geant4-v11.2.1/geant4-v11.2.0-install/include/Geant4/G4VisExecutive.hh:141,
from tutorial003.cpp:79:
/home/ranulfo/Programas/Geant4/geant4-v11.2.1/geant4-v11.2.0-install/include/Geant4/G4VisExecutive.icc:142:10: fatal error: QtGlobal: Arquivo ou diretório inexistente
142 | #include <QtGlobal>
| ^~~~~~~~~~
compilation terminated.
ranulfo@ranulfo:~/Documentos/GEANT4_Tutorial/Tutorial/Aula 3$
Below is the muons.mac file I use to perform the interaction. I call it in the terminal as: ./tutorial003 muons.mac. The interaction occurs, but the graphical interface, where I can see the interaction between particles and matter in more detail, does not open.
# This is a comment and will be ignored by geant4
# Use this open statement to create an OpenGL view:
/vis/open OGLIX
# Draw geometry:
/vis/drawVolume
# Specify view angle:
/vis/viewer/set/viewpointThetaPhi 45. 45.
# Specify zoom value:
/vis/viewer/zoom 1.0
# Draw smooth trajectories at end of event, showing trajectory points
# as markers 2 pixels wide:
/vis/scene/add/trajectories smooth
/vis/modeling/trajectories/create/drawByCharge
/vis/modeling/trajectories/drawByCharge-0/default/setDrawStepPts true
/vis/modeling/trajectories/drawByCharge-0/default/setStepPtsSize 2
# To superimpose all of the events from a given run:
#/vis/scene/endOfEventAction accumulate
# Re-establish auto refreshing and verbosity:
/vis/viewer/set/autoRefresh true
# Let's ask geant4 to report more details about the simulation
# by ajusting the verbosity level for each subsystem:
/run/verbose 1
/event/verbose 1
/tracking/verbose 1
# Now we define the source. Right now it is a mono-energetic beam of muons+
# We can set either energy or momentum,
# but not both (since the mass is already defined).
# Between energy and momentum, geant4 will follow the last instruction before beamOn.
/gun/particle mu+
/gun/energy 10 MeV
/gun/position -10 0 0 m
/run/beamOn 1
Well, after all this puzzle, I believe the problem seems to be with the compiler. I tried various ways to open it. I was using the following command in the file:
# Define an environment variable G4INCLUDES that points to
# your installation path, where the includes are. It is usually
# something like: /path/to/geant4-install/include/Geant4
g++ tutorial003.cpp `geant4-config --libs` -I${G4INCLUDES} -o tutorial003
This error occurs because the compiler can’t find the QtGlobal header file, which is part of the Qt framework. This will compile the code but won’t include the necessary Qt libraries, hence the error when running ./tutorial003.
Another option was to use the following command:
g++ tutorial003.cpp `geant4-config --cflags --libs` -o tutorial003 -I/usr/include/qt5 -I/usr/include/qt -lQt5Core -lQt5Gui -lQt5Widgets
However, the response was this:
ranulfo@ranulfo:~/Documentos/GEANT4_Tutorial/Tutorial/Aula 3$ source compile.sh
tutorial003.cpp:75: warning: "G4VIS_USE_OPENGLX" redefined
75 | #define G4VIS_USE_OPENGLX
|
<command-line>: note: this is the location of the previous definition
tutorial003.cpp:76: warning: "G4VIS_USE_OPENGLQT" redefined
76 | #define G4VIS_USE_OPENGLQT
|
<command-line>: note: this is the location of the previous definition
In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/QtGlobal:1,
from /home/ranulfo/Programas/Geant4/geant4-v11.2.1/geant4-v11.2.0-install/include/Geant4/G4VisExecutive.icc:142,
from /home/ranulfo/Programas/Geant4/geant4-v11.2.1/geant4-v11.2.0-install/include/Geant4/G4VisExecutive.hh:141,
from tutorial003.cpp:79:
/usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:1281:4: error: #error "You must build your code with position independent code if Qt was built with -reduce-relocations. " "Compile your code with -fPIC (and not with -fPIE)."
1281 | # error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
| ^~~~~
The option you suggested:
# Define an environment variable G4INCLUDES that points to
# your installation path, where the includes are. It is usually
# something like: /path/to/geant4-install/include/Geant4
#g++ tutorial003.cpp `geant4-config --libs` -I${G4INCLUDES} -o tutorial003
#g++ tutorial003.cpp `geant4-config --cflags --libs` -o tutorial003 -I/usr/include/qt5 -I/usr/include/qt -lQt5Core -lQt5Gui -lQt5Widgets
g++ geant4-config --cflags --libs
The response was this:
ranulfo@ranulfo:~/Documentos/GEANT4_Tutorial/Tutorial/Aula 3$ source compile.sh
g++: error: unrecognized command-line option ‘--cflags’
g++: error: unrecognized command-line option ‘--libs’; did you mean ‘--libs=’?
The code opens a graphical interface, but it’s not interactive. I’d like to open that white window where we can zoom and do other operations. The problem seems to be related to GEANT4 not loading these libraries. I think it might be an issue with the operating system or packages. I’ve tried uninstalling and reinstalling packages, installing GEANT4, compiling in the ‘build’ folder, and tried many other things, but I keep facing the same errors. It seems to be a problem with the Qt5 packages that were disabled, among other things.
Also, I managed to open the white interaction window using a new approach. However, when I add the command “/vis/open OGL”, errors occur and the simulation doesn’t run. It’s a problem I haven’t been able to solve, even after reading documentation, watching videos, and consulting GitHub.
Another point is that when updating the operating system, packages become outdated, but GEANT4 doesn’t replace them automatically. Well, I don’t know… I guess I’m stuck in this deadlock.