key4hep / key4hep-spack

A Spack recipe repository of Key4hep software.
10 stars 23 forks source link

Geant4 Qt visualization do not work properly #505

Closed atolosadelgado closed 1 year ago

atolosadelgado commented 1 year ago

Geant4 Qt visualization do not work properly. The code below shows the steps for building a dummy detector, and opening via ddsim the Geant4-Qt interface, but the detector is not displayed (just a black window instead). When LCG view release is used instead of key4hep, the steps lead to the correct display of the detector.

cd /tmp
git clone git@github.com:atolosadelgado/ARC_detector.git
source /cvmfs/sw.hsf.org/key4hep/setup.sh 
cd /tmp/ARC_detector/
cmake -B build -S . -D CMAKE_INSTALL_PREFIX=install
cmake --build build -- install
export LD_LIBRARY_PATH=$PWD/install/lib:$LD_LIBRARY_PATH
ddsim --compactFile ./compact/arc_v0.xml --runType qt --part.userParticleHandler='' --macroFile myscripts/vis.mac

Some error messages appear in the terminal when ddsim is launched, maybe related to Qt?

PersistencyIO    INFO  +++ Set Streamer to dd4hep::OpaqueDataBlock
Info in <TGeoManager::TGeoManager>: Geometry default, Detector Geometry created
Info in <TGeoNavigator::BuildCache>: --- Maximum geometry depth set to 100
XMLLoader        INFO  +++ Processing XML file: file:/tmp/atolosad/ARC_detector/compact/arc_v0.xml
Evaluator        WARN  +++ Overwriting variable: name=SENSOR_Y value=8.0*cm  Evaluator::Object : existing variable [setVariable error]
Detector         WARN  +++ Object 'SENSOR_Y' is already defined. New value will be ignored
DD4hep           WARN  ++ STD conditions NOT defined by client. NTP defaults taken.
Detector         INFO  *********** Created World volume with size:  100  100  100
Info in <TGeoManager::SetTopVolume>: Top volume is world_volume. Master volume is world_volume
Compact          INFO  ++ Converted subdetector:ARC of type ARCTYPE [tracker]
Info in <TGeoManager::CheckGeometry>: Fixing runtime shapes...
Info in <TGeoManager::CheckGeometry>: ...Nothing to fix
Info in <TGeoManager::CloseGeometry>: Counting nodes...
Info in <TGeoManager::Voxelize>: Voxelizing...
Info in <TGeoManager::CloseGeometry>: Building cache...
Info in <TGeoManager::CountLevels>: max level = 4, max placements = 3
Info in <TGeoManager::CloseGeometry>: 7 nodes/ 8 volume UID's in Detector Geometry
Info in <TGeoManager::CloseGeometry>: ----------------modeler ready----------------
Detector         INFO  +++ Patching names of anonymous shapes....
DDG4             INFO +++ Imported 20 global values to namespace:DDG4
Geant4Kernel           OutputLevel:  2
Geant4Kernel           UI:           UI
Geant4Kernel           NumEvents:    10
Geant4Kernel           NumThreads:   0
DDG4             INFO +++  List of sensitive detectors:
DDG4             INFO +++  ARC                              type:tracker       --> Sensitive type: ('Geant4TrackerWeightedAction', {'HitPositionCombination': 2, 'CollectSingleDeposits': False})
Geant4UI         INFO  +++ UI> Install Geant4 control directory:/ddg4/UI/
Geant4Kernel     INFO  ++ Registered global action UI of type dd4hep::sim::Geant4UIManager
Geant4UI         INFO  +++ MagFieldTrackingSetup> Install Geant4 control directory:/ddg4/MagFieldTrackingSetup/
Geant4UI         INFO  +++ DetectorConstructionAction> Install Geant4 control directory:/ddg4/DetectorConstructionAction/
Geant4UI         INFO  +++ ConstructSD> Install Geant4 control directory:/ddg4/ConstructSD/
Geant4Kernel     INFO  ++ Registered global action RunInit of type dd4hep::sim::Test::Geant4TestRunAction
Geant4UI         INFO  +++ RunAction> Install Geant4 control directory:/ddg4/RunAction/
DDSim.Helper.Random INFO Choosing random seed for you: 402430510
Geant4UI         INFO  +++ LcioOutput> Install Geant4 control directory:/ddg4/LcioOutput/
Geant4UI         INFO  +++ EventAction> Install Geant4 control directory:/ddg4/EventAction/
Geant4UI         INFO  +++ TrackingAction> Install Geant4 control directory:/ddg4/TrackingAction/
Geant4UI         INFO  +++ SteppingAction> Install Geant4 control directory:/ddg4/SteppingAction/
Geant4UI         INFO  +++ GeneratorAction> Install Geant4 control directory:/ddg4/GeneratorAction/
Geant4UI         INFO  +++ ParticleHandler> Install Geant4 control directory:/ddg4/ParticleHandler/
DDSim.Helper.Filter INFO ReqFilt {'edep1kev', 'edep0'}
DDSim            INFO getDetectorLists - found active detector ARC type: tracker
DDSim            INFO Setting up SD for ARC
Geant4UI         INFO  +++ ARC> Install Geant4 control directory:/ddg4/ARC/
Geant4UI         INFO  +++ ARCHandler> Install Geant4 control directory:/ddg4/ARCHandler/
DDSim.Helper.Filter INFO Adding default filter 'edep1kev' to sensitive detector for 'ARC' 
Geant4UI         INFO  +++ PhysicsList> Install Geant4 control directory:/ddg4/PhysicsList/
PhysicsList            +++ Dump of physics list component(s)
PhysicsList            +++ Extension name       FTFP_BERT
PhysicsList            +++ Transportation flag: 0
PhysicsList            +++ Program decays:      0
PhysicsList            +++ RangeCut:            0.700000
Geant4UI         INFO  +++ GlobalRangeCut> Install Geant4 control directory:/ddg4/GlobalRangeCut/
FieldSetup       INFO  Geant4 magnetic field tracking configured.
FieldSetup       INFO  G4MagIntegratorStepper:ClassicalRK4 G4Mag_EqRhs:Mag_UsualEqRhs
FieldSetup       INFO  Epsilon:[min:0.000050 mm max:0.001000 mm]
FieldSetup       INFO  Delta:[chord:0.250000 1-step:0.010000 intersect:0.001000] LargestStep 10000.000000 mm

**************************************************************
 Geant4 version Name: geant4-11-01-patch-02 [MT]   (15-June-2023)
                       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/
**************************************************************

Geant4UI         INFO  +++ Geant4RunManager> Install Geant4 control directory:/ddg4/Geant4RunManager/
Geant4RunManager WARN  +++ Configured run manager of type: G4RunManager.
Geant4Kernel     WARN  +++ Multi-threaded mode requested, but not supported by this compilation of Geant4.
Geant4Kernel     WARN  +++ Falling back to single threaded mode.
Geant4Exec       WARN  +++ Only 1 subdetectors present. You sure you loaded the geometry properly?
G4PhysListFactory::GetReferencePhysList <FTFP_BERT>  EMoption= 0
<<< Geant4 Physics List simulation engine: FTFP_BERT

Myphysics        INFO  Registered Geant4 physics constructor G4StepLimiterPhysics to physics list
UserInitialization INFO  +++ Executing Geant4UserActionInitialization::Build. Context:0x16e17940 Kernel:0x16dd5480 [-1]
UI               INFO  +++ Starting G4UIExecutive 'DDG4' of type qt....
Available UI session types: [ Qt, tcsh, csh ]
Geant4Converter  INFO  +++  Successfully converted geometry to Geant4.
Geant4UI         INFO  +++ ConstructGeo> Install Geant4 control directory:/ddg4/ConstructGeo/

 hInelastic FTFP_BERT : 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

### Adding tracking cuts for neutron  TimeCut(ns)= 10000  KinEnergyCut(MeV)= 0
GlobalRangeCut   INFO  +++ Set PhysicsList RangeCut to 0.700000 mm
UI               INFO  +++ Starting G4VisExecutive ....
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)
  OpenGLImmediateQt (OGLIQt, OGLI)
  OpenGLStoredQt (OGLSQt, OGL, OGLS)
  Qt3D (Qt3D)
  TOOLSSG_QT_GLES (TSG_QT_GLES, TSGQt, TSG)

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.
UI               INFO  ++ Executing UI setup: myscripts/vis.mac
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
Visualization verbosity changed to errors (2)
Visualization verbosity changed to warnings (3)
WARNING: Viewpoint direction is very close to the up vector direction.
  Change the up vector or "/vis/viewer/set/rotationStyle freeRotation".

Graphics systems deleted.
Visualization Manager deleting...

Geant4Kernel     INFO  ++ Terminate Geant4 and delete associated actions.
DDSim            INFO DDSim            INFO  Total Time:   8.41 s (User), 6.68 s (System)

Thank you for your time :) Alvaro

atolosadelgado commented 1 year ago

Update: there is a different error in lxplus9 (alma9) when the same steps are followed, :

PhysicsList            +++ Transportation flag: 0
PhysicsList            +++ Program decays:      0
PhysicsList            +++ RangeCut:            0.700000
Geant4UI         INFO  +++ GlobalRangeCut> Install Geant4 control directory:/ddg4/GlobalRangeCut/
FieldSetup       INFO  Geant4 magnetic field tracking configured.
FieldSetup       INFO  G4MagIntegratorStepper:ClassicalRK4 G4Mag_EqRhs:Mag_UsualEqRhs
FieldSetup       INFO  Epsilon:[min:0.000050 mm max:0.001000 mm]
FieldSetup       INFO  Delta:[chord:0.250000 1-step:0.010000 intersect:0.001000] LargestStep 10000.000000 mm

**************************************************************
 Geant4 version Name: geant4-11-01-patch-02 [MT]   (15-June-2023)
                       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/
**************************************************************

Geant4UI         INFO  +++ Geant4RunManager> Install Geant4 control directory:/ddg4/Geant4RunManager/
Geant4RunManager WARN  +++ Configured run manager of type: G4RunManager.
Geant4Kernel     WARN  +++ Multi-threaded mode requested, but not supported by this compilation of Geant4.
Geant4Kernel     WARN  +++ Falling back to single threaded mode.
Geant4Exec       WARN  +++ Only 1 subdetectors present. You sure you loaded the geometry properly?
G4PhysListFactory::GetReferencePhysList <FTFP_BERT>  EMoption= 0
<<< Geant4 Physics List simulation engine: FTFP_BERT

Myphysics        INFO  Registered Geant4 physics constructor G4StepLimiterPhysics to physics list
UserInitialization INFO  +++ Executing Geant4UserActionInitialization::Build. Context:0x1a0bd520 Kernel:0x1999efe0 [-1]
UI               INFO  +++ Starting G4UIExecutive 'DDG4' of type qt....
Available UI session types: [ Qt, tcsh, csh ]
qt.qpa.xcb: could not connect to display 
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: linuxfb, minimal, offscreen, vnc, webgl, xcb.

 *** Break *** abort
atolosadelgado commented 1 year ago

Hi,

@dkonst13 and I tried to dig a bit more in this issue. We tried the following points in Alma9 (lxplus9)

LCG view4 release provide DD4hep, and the initial code I posted works and the detector can be visualized using the Geant4 Qt interface.

However if Key4hep stack (nightlies*) is used instead, an error appears in the terminal saying that openGL and EGL are disabled (same error message as in the original post)

QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled

and the Geant4 Qt interface window opens but it does not display the detector.

We found that the configuration summary of Qt in key4hep show this options:

  X11 specific:
    XLib ................................. no
    XCB Xlib ............................. no
    EGL on X11 ........................... no
    xkbcommon-x11 ........................ yes

but the LCG view4 release show this other one

  X11 specific:
    XLib ................................. yes
    XCB Xlib ............................. yes
    EGL on X11 ........................... no
    xkbcommon-x11 ........................ yes

and these flags were used for compiling Qt: -xcb -opengl

Could this be the source of the problem?

Thank you for your time.

*/cvmfs/sw-nightlies.hsf.org/key4hep/releases/latest/x86_64-almalinux9-gcc11.3.1-opt/key4hep-stack/2023-07-06-vkxwxh/setup.sh

jmcarcell commented 1 year ago

Thanks for the information, I could reproduce. Potentially fixed in https://github.com/spack/spack/pull/39718 but won't be fixed in the stack until I make another complete build. I'll close the issue once the fixed build is in cvmfs.

jmcarcell commented 1 year ago

The latest nightly should have fixed this, can you give it a try @atolosadelgado ?

atolosadelgado commented 1 year ago

Hurra!!! Both geoDisplay and Geant4-Qt visualization work now!! Thank you for fixing this!


Unrelated note: while configuring k4geo repository with the nightlies in my laptop (Alma9), I got this message, probably not important

CMake Warning (dev) at /cvmfs/sw-nightlies.hsf.org/key4hep/releases/2023-09-03/x86_64-almalinux9-gcc11.3.1-opt/cmake/3.27.4-qc4pvz/share/cmake-3.27/Modules/CMakeFindDependencyMacro.cmake:76 (find_package):
  Policy CMP0144 is not set: find_package uses upper-case <PACKAGENAME>_ROOT
  variables.  Run "cmake --help-policy CMP0144" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  Environment variable BOOST_ROOT is set to:

    /cvmfs/sw-nightlies.hsf.org/key4hep/releases/2023-09-03/x86_64-almalinux9-gcc11.3.1-opt/boost/1.83.0-vt5zkb

  For compatibility, find_package is ignoring the variable, but code in a
  .cmake module might still use it.
Call Stack (most recent call first):
  /cvmfs/sw-nightlies.hsf.org/key4hep/releases/2023-09-03/x86_64-almalinux9-gcc11.3.1-opt/dd4hep/ce7bfea294a4daa5bfeb590852fabe3ca87353c4=develop-k2ojli/cmake/DD4hepConfig.cmake:49 (FIND_DEPENDENCY)
  CMakeLists.txt:40 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.
jmcarcell commented 1 year ago

Unrelated note: while configuring k4geo repository with the nightlies in my laptop (Alma9), I got this message, probably not important

That's a harmless and unrelated warning, you can ignore it Closing since this is now working (https://github.com/spack/spack/pull/39718 plus possibly changing -system-xcb to xcb), the releases won't be fixed but the next one will have the fix.