How can I know that I am using a certain environment variable related to a certain data-set?

How can I know (either by typing commands in the Geant4 user interface or by reviewing the simulation code ) that I am using a certain environment variable(for example: G4RADIOACTIVEDATA) related to a certain data-set(for example: RadioactiveDecay4.0); Where in the simulation code(Is it in Main or in RunAction or in EventAction or Where?) do I specify that I will use a certain environment variable related to a certain data-set?

_Geant4 Version:_11.2.1
_Operating System:_Windows 10
_Compiler/Version:_Visual Studio 2022
_CMake Version:_3.29.0-rc2


Hi Alfredo.

The environment variables are set outside your program. Typically you set them either in your startup scripts (e.g. .login) or when you source the geant4 setup scripts.

You can set different values and run the same executable, to check the results against different versions of data files. It is why they exist.

Inside either a script that runs your application or your main program you can check whether they exist and what their value is

if ( $?G4RADIOACTIVEDATA ) then
   echo "G4RadioActiveData= " $G4RADIOACTIVEDATA
else
   echo "G4RadioActiveData:  Not set"
endif
1 Like

Dear @alfredo10110 ,

to complement John’s answer. Once you add your Radioactive Decay Physics, the class G4RadioactiveDecay looks for that environment variable. You have added G4RadioactiveDecay in your PhysicsList.

I hope this sheds some light into your question.

/Pico

1 Like

Ok, thank you very much for your reply. I have one more question: Are the scripts you are talking about the .mac files(for example: vis.mac file, init_vis.mac, run1.mac, run2.mac, etc.) included in the examples(for example: example B1) given by the Geant4 simulation toolkit?; Or is it in the CMakeLists file in which I have to check if a certain environment variable exists or not?

Thank you very much for answering. Based on what you’re telling, Does the same thing happen with the other environment variables in the remaining data-sets?, That is, for example, once I add the physics related to the PhotonEvaporation3.0 data-set, Is there a class that looks for the G4LEVELGAMMADATA environment variable?

I haven’t added G4RadioactiveDecay to my physics list yet, but I think I’ll have to add it soon because I have to do a simulation that includes a radioactive source.

You’re welcome. The geant4 setup scripts that I am referring to are the ones for your installation.

In the Installation Guide they are explained in the section on “Post-install setup” - at Postinstall Setup — Geant4 Installation Guide 11.2 documentation

Please also note in that recent release the environment variable GEANT4_DATA_DIR was introduced, and can be used to point to the root of all data directories. If you use it, you only need to use G4RADIOACTIVEDATA if you want to override the version of that data file. ( Details again in the web page referenced above.)

Yes, there is a class which will load it. But you must also register the relevant physics processes (by using a physics list which has them.)

Ok, thank you very much for the information. I have the following doubt: Do I have to create the GEANT4_DATA_DIR environment variable?, Or once I installed Geant4, Is that environment variable also created?. On the other hand, I have to say that I installed Geant4 11.2.1 in the following way: When using CMake, I only chose to install Geant4 with the GEANT4_USE_OPENGL_WIN32 option. After using CMake and Visual Studio, I created 10 environment variables related to 10 data sets (G4NDL, G4PII, RadioactiveDecay, RealSurface, etc.). Can I use Geant4 having done the environment variable configuration that I mentioned?, that is, Is the environment variable configuration I did correct?

Ok, thanks a lot, I will keep this in mind

The user must set this either directly or by calling the geant4.bat script (for windows). This is documented in the Post install section of the Installation Guide.

If those variables are indeed set and point to the correct location on disk, then yes, it’ll work.

I have more doubts. I hope you can help me. Regarding your first reply on this topic(in which 5 lines of code are shown; there is one if and two echo), How do I create the script you mention?; Can I include those 5 lines of code that you mentioned in the main file(main.cc) of my simulation? ; Would the only thing the script contain would be the 5 lines of code that you mentioned?; What extension must the script have?; Can the script have a .mac extension?. Once I do the script to check if a certain environment variable exists, and once I open my simulation’s executable file, will the Geant4 User Interface notify me that a certain environment variable exists?; In this script, can I replace echo by G4cout?

Ok, thank you very much for the information

As you’re on Windows, it’ll be easier to actually do this in C++ in the application. You can do something like:

// For the std::getenv function
#include <cstdlib>

#include <G4ios.hh>
#include <G4EnvironmentUtils.hh>

int main()
{
  // Check env var directly
  if (const char* env_p = std::getenv("G4RADIOACTIVEDATA"))
  {
    G4cout << "G4RADIOACTIVEDATA is: " << env_p << G4endl;
  }
  else
  {
    G4cout << "G4RADIOACTIVEDATA is not set" << G4endl;
  }

  // See if Geant4 can find the data through the sequence of defaults, general, specific locations
  if (const char* env_q = G4FindDataDir("G4RADIOACTIVEDATA"))
  {
    G4cout << "G4RADIOACTIVEDATA is found at: " << env_q << G4endl;
  }
  else
  {
    G4cout << "G4RADIOACTIVEDATA is not found" << G4endl;
  }

}

Hi Doctor, thank you very much for the reply. I included the code you show in your reply in the main.cc file of the basic example B1, but I couldn’t see any notification in the Geant4 User Interface about whether or not I’m using the G4RADIOACTIVEDATA environment variable; that is, neither “G4RADIOACTIVEDATA is: …” nor “G4RADIOACTIVEDATA is not set” was displayed on screen; What could be happening?; Does it matter where I type that piece of code?; It should be added that I placed this part of code just before “Job termination” section(in the main.cc file), here is where the following is written:
delete visManager;
delete runManager;
Is right what I did?, Or do I have to type that part of code somewhere else in main.cc?

I think it is convenient to add the following: When the executable file of the advanced example exp_microdosimetry is opened (without having included anything new in the main.cc file), the following important information (related to the topic) is displayed in the Geant4 user interface: “UI session starts …
THE FOLLOWING ELECTROMAGNETIC PHYSICS LIST HAS BEEN ACTIVATED: G4EmLivermorePhysics
THE FOLLOWING HADRONIC INELASTIC PHYSICS LIST HAS BEEN ACTIVATED: HadronPhysicsQGSP_BIC_HP()
THE FOLLOWING HADRONIC INELASTIC PHYSICS LIST HAS BEEN ACTIVATED: G4IonBinaryCascadePhysics()
THE FOLLOWING HADRONIC INELASTIC PHYSICS LIST HAS BEEN ACTIVATED: G4RadioactiveDecayPhysics()
Checking overlaps for volume DiaVol_phys:0 (G4Box) … OK!
Checking overlaps for volume vacblock_phys:0 (G4Box) … OK!
Checking overlaps for volume Bdl_phys:0 (G4Box) … OK!
Checking overlaps for volume SV_phys1:0 (G4Box) … OK!
Checking overlaps for volume SV_phys2:0 (G4Box) … OK!
Checking overlaps for volume SV_phys3:0 (G4Box) … OK!
Checking overlaps for volume SV_phys4:0 (G4Box) … OK!
Checking overlaps for volume AlStrip_phys:0 (G4Box) … OK!
Checking overlaps for volume GoldCylinder1_phys:0 (G4Tubs) … OK!
Checking overlaps for volume GoldCylinder2_phys:0 (G4Tubs) … OK!
Checking overlaps for volume GoldCylinder3_phys:0 (G4Tubs) … OK!
@@@ G4ParticleHPInelasticData instantiated for particle neutron data directory variable is G4NEUTRONHPDATA pointing to C:\geant4-v11.2.1\geant4-v11.2.1-install\share\Geant4\data\G4NDL4.7”

Finally I was able to realize the following: In the directory of the advanced example exp_microdosimetry there are several files,one of those files is the file exp_microdosimetry.out; opening this file, the following is shown somewhere in the file: : @@@ G4ParticleHPInelasticData instantiated for particle neutron data directory variable is G4NEUTRONHPDATA pointing to /cvmfs/geant4.cern.ch/share/data/G4NDL4.7.
Continuing with the topic, I don’t know what I have to do to check the existence of a different environment variable(for example: G4RADIOACTIVEDATA) using the advanced example exp_microdosimetry. I hope you can help me

Which UI are you using, Windows terminal/cmd or Qt? How are you starting your application, from the terminal or double clicking?

Bear in mind Geant4 will error our if it can’t find the data.

Ok Doctor, thank you very much for answering. The UI I’m using I think is Windows terminal/cmd. I am starting the application with double click. When I do this, 3 windows appear; The first window is the viewer-0(OpenGLStoredWin32).It is in this first window where one can see the geometry of the detector and the trajectories of the particles; At the top of the second window you can read Geant4. It is in this second window where a set of commands is available for the application; It is also in this second window where I can type the commands that I want. And finally, in the third window the G4 working threads that the application is using are shown. It should be added that in this third window I cannot type commands. It is in this third window where things like the following are displayed(I am using the basic example B1):
Run 0 starts on worker thread 3.
Thread-local run terminated.
Run summary.
Number of events processed: 4.
End of Local Run.
The run consists of 4 gamma of 6 MeV.
I hope the above helps.

The probable reason you’re not seeing the “G4RADIOACTIVEDATA is …” messages is due to the behaviour of G4cout. Messages streamed to this are redirected depending on the UI session type/status.

In main(), the messages are effectively going to always end up on “Standard Output” since at the start/end of main() there won’t be an active UI session (in your case, the command entry window). If you’re double clicking to start, then “Standard Output” is not going to be somewhere you’ll see it.

For this trivial case, the simplest case is to run the application from a Visual Studio Developer Terminal. There, “Standard Output” on application startup will be that Terminal and so you’ll see all the startup and shutdown messages. See the Windows section in this chapter of the Application Developers Guide.

Otherwise, the relevant code should go somewhere that’ll be run after the UI session has started.

1 Like