Geant4 simulation working on linux, but not working on windows

Hello, I should compile and run a Geant4 11 simulation on my windows local machine that correctly works on laboratory machine (linux).

  1. I tried to compile the simulation, but I got the error:

fatal error C1083: Non è possibile aprire il file inclusione: 'G4UItcsh.hh':

i.e. it couldn’t open the G4UItcsh.hh' file.

  1. To avoid the error due to missing G4UItcsh.hh' ., I downloaded the header from laboratory machine
    G4UItcsh.hh (5.3 KB)

and I copied it in the directory

GEANT4 instaldir\include\Geant4

even if I don’t understand the reason because of the G4UItcsh.hh' was missing.

  1. I tried to compile again the simulation , but I got the error

error C2061: errore di sintassi: identificatore 'G4UItcsh'

i.e. syntax error of identificator G4UItcsh' in the main file in the lines:

else
     //start interactive session                                                                                                                                                                                   
    {
      G4UIsession* session = new G4UIterminal(new G4UItcsh);
      session->SessionStart();
      delete session;
    }

SimLuna.cc (3.3 KB)

  1. Even if I need the interactive session to temporanely try to compile the simulation I commented the lines of point 3, but now I get the errors and the warnings reported in the attached error log:
    error log.txt (8.3 KB)

@bmorgan maybe, you know how to make working the simulation on windows?

G4UItcsh.hh isn’t built on Windows as it’s not supported on that platform, so the application as coded can only work on Unix systems. To make it work on Windows, you can either:

  1. Rewrite the block to only support terminal sessions, but across platforms:

    #include "G4UIcsh.hh" // always available shell
    #ifndef _WIN32
    #include "G4UItcsh.hh"
    #endif
    
    else
        //start interactive session                                                                                                                                                                                   
        {
          G4UIsession* session = nullptr;
          #ifdef _WIN32
          session = new G4UIterminal(new G4UIcsh);
          #else
          session = new G4UIterminal(new G4UItcsh);
          #endif
    
          session->SessionStart();
          delete session;
       }
    

    The compilers on Windows should always define the _WIN32 macro, but I’m not a regular Windows user, so you should check. You can also add additional logic to select different sessions as explained in the relevant section of the Application Developer Manual

  2. Use the G4UIExecutive helper as shown in the examples, and described in the Application Developer Manual. This will select a “best” UI depending on how Geant4 was configured, or a UI can be selected using env vars or a control file.

Hi @bmorgan sorry for late reply but I’ve just read your message!
I used first option and it works!

I’ve one more question please.
Usually, in my simulations, I run the simulation without the macro and I can automatically see the interactive simulation by QT.
Using this simulation, running the simulation without the macro i.e.

C:\SimLuna\21nep\Build\Release>SimLuna.exe

I get

*************************************************************
 Geant4 version Name: geant4-11-00-patch-03 [MT]   (16-September-2022)
                       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/
**************************************************************

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)
  OpenGLImmediateQt (OGLIQt, OGLI)
  OpenGLStoredQt (OGLSQt, OGL, OGLS)
  Qt3D (Qt3D)

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.
PreInit>

i.e. QT doesn’t start automatically.

I searched on the forum and I found this topic Analysis of Particles Resulting From Initial Interactions - #6 by jabowen in which @mkelsey says to run the macro by the PrePrint then I tried

PreInit> /control/execute vis.mac

but I get

-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : UIMAN0123
      issued by : G4UImanager::ApplyCommand
"OGLSQt" is not compatible with your chosen session, and no fallback system found.
Error code : 1
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------


-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : UIMAN0123
      issued by : G4UImanager::ApplyCommand
Invoked command has failed - see above. Available graphics systems are (short names):
  ATree DAWNFILE HepRepFile OGL OGLI OGLIQt OGLS OGLSQt Qt3D RayTracer VRML2FILE gMocrenFile
Error code : 1
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

***** Illegal parameter (1) </vis/open OGL 600x600-0+0> *****

ps. I was able to get QT Visualization using the code

if ( ! ui ) { 
    // batch mode
    G4String command = "/control/execute ";
    G4String fileName = argv[1];
    UImanager->ApplyCommand(command+fileName);
  }
  else { 
    // interactive mode
    UImanager->ApplyCommand("/control/execute init_vis.mac");
    ui->SessionStart();
    delete ui;
  }

but if possible, I would like to know how to use it by the original code too.
Thanks

I’d suggest reviewing how things are done in the basic examples (e.g. basic/B1), and as outlined in the Application Developer Guide sections How to Set Up an Interactive Session, How to Execute a Program, and How to Visualise the Detector and Events.

These walk through the various ways of setting UI/Vis up, but in short, you probably want to use G4UIExecutive and G4VisExecutive as these should set up all available sessions/drivers. Note that in this case, your CMakeLists.txt script should find Geant4 as:

find_package(Geant4 REQUIRED ui_all vis_all)

so all the compile/link flags enable everything.

In the case of G4UIExecutive it will select “best” session at runtime, to Qt if available, falling back to terminal otherwise. The session can also be selected as documented in How to Set Up an Interactive Session.

Hi @bmorgan thank you.

This morning, to make the simulation working by QT I defined a flag to choose the interactive way ie.


 G4UIExecutive* ui = 0;
  if ( argc == 1 ) {
    ui = new G4UIExecutive(argc, argv);
  }
if (uicsh_vis){

  if (argc>=3) {
    for (int ia=2;ia<argc;ia++){
      // split an alias=value string and call /control/alias                                                                                                                                                       
      char* alias=argv[ia];
      char* value=strchr(alias,'=');
      if (value!=NULL) {
        value[0]='\0';value++;
        char cmd[1024];
        snprintf(cmd,1024,"/control/alias %s %s",alias,value);
        //printf("%s\n",cmd);                                                                                                                                                                                      
        UImanager->ApplyCommand(cmd);
      }
    }
  }
  if(argc>1)
    // execute an argument macro file if exist                                                                                                                                                                     
    {
      G4String command = "/control/execute ";
      G4String fileName = argv[1];
      UImanager->ApplyCommand(command+fileName);
    }
 else
    //start interactive session                                                                                                                                                                                   
    {
      G4UIsession* session = nullptr;
      #ifdef _WIN32
      session = new G4UIterminal(new G4UIcsh);
      #else
      session = new G4UIterminal(new G4UItcsh);
      #endif

      session->SessionStart();
      delete session;
   }
}
else if (ui_vis){
	if ( ! ui ) { 
    // batch mode
    G4String command = "/control/execute ";
    G4String fileName = argv[1];
    UImanager->ApplyCommand(command+fileName);
  }
  else { 
    // interactive mode
    UImanager->ApplyCommand("/control/execute init_vis.mac");
    ui->SessionStart();
    delete ui;
  }
}

but you said that

then could I just keep G4UIExecutive without G4UIcsh and, in this case, if QT is not available, it would select other visualisation method?

  1. Given that on laboratory machine QT is not available, then other visualization method is needed (G4UItcsh) how to start the visualization by G4UItcsh?

G4UItcsh is not a “visualization method.” It is a simple shell based (specifically, tcsh) interface to let you type commands. For visualization, you may have your version of Geant4 compiled with OpenGL, in which case you may be able to use /vis/open OGL to get a visualization window. You will obviously NOT get the Qt interface, since you don’t have Qt installed.

As @mkelsey notes, what UI and what Vis drivers are available depends both on how you built Geant4 itself, but also on how you configure your application. It’s this later case that was outline above. By finding Geant4 in CMake via:

find_package(Geant4 REQUIRED ui_all vis_all)

this tells CMake to set up compiling and linking of the application with all UI and Vis drivers available in the found install. The second part to this is in the use of G4UIexecutive and G4VisExecutive in the application’s main() program, as shown in the basic and other examples.

Think of these as “builders” that construct and make available the interface/drivers. A given application can only have one UI at a time, so G4UIexecutive constructs the “best” available given what’s available in the install: Qt, then Xm/Xt, then terminal with G4tcsh if available, or G4csh otherwise. Multiple vis drivers can however be loaded, and that’s what G4VisExecutive does, with the log message:

You have successfully registered the following graphics systems.
Registered graphics systems are:

showing what’s available in this build of the application. This may not show every single driver available from the Geant4 install compiled/linked to, but it should do if you use CMake and find Geant4 with the ui_all vis_all component arguments to find_package.

TLDR; yes, I suggest you use the G4UIexecutive/G4VisExecutive pairing as this together with the find_package call as outline will enable all available drivers in the application.

Thank you the both @mkelsey and @bmorgan
As I wrote, I modified the code to choose if use G4UItcsh or VIS (i.e. the one working with QT) and I’m able to use QT now.

In the original code, only G4UItcsh was implemented …then how could the developer get eps images like this one:

Right, that’s visualisation though - whilst there can only be one UI session at a time, it is possible (IIRC) to have multiple vis drivers open. E.g. visualize in G4UIQt with OpenGL, but write out either that view or a totally separate one with gl2ps or DAWN. That’s really a question for the Visualisation category though.

Thank you for the info @bmorgan

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.