Making an Application

Geant4 Version: 11.2.1
Operating System: Windows 10
Compiler/Version: g++
CMake Version: 3.29

Hello! I am very new to Geant4 but have successfully installed the program and run the B1 example. Now that everything is installed, I want to know how one actually goes about making their first application. Do I just open up a VSCode C++ file, start coding, then make a CMakeLists.txt file? I’m looking at the B1 example and there appears to be a lot of other files and two other folders (include and src). I know about the Application Developer handbook but it doesn’t really cover these steps. Is John Francis’ “Hello World” starter template adequate for this or is it better for me to build this application from the ground up? If anybody could help that would be much appreciated or direct me to some good resources that cover this. Thank you.

What many people do is to pick one of the (many!) examples, which is closest to what their own simulation need is. Then they go through and modify the chunks of code appropriately to match their geometry, their source, etc.

To follow this path, you should copy (cp -r or the Windoze equivalent) the chosen example directory to a new location with a new name, and then start messing with stuff.

Setting up an application directory from scratch, and writing the main() from scratch, is a pain for a new user. Save that for when you’re more experienced and see how all the pieces fit together.

1 Like

Thank you so much! I assume the only file you write code on is that main() file?

Nope! Go through one of the examples in detail, like B1; don’t just compile and run it. For each of the files you see in include/ and src/ (they go together in pairs), cross-reference back to the corresponding section of the Application Developers Guide, so you see why that file is there.

As you get more sophisticated in what you need in your simulation, move to the more complex examples (extended and especially advanced) and follow the same approach.

1 Like

And if I make a copy of the B1 example and start editing the code and such, I assume I would also have to change the name of the files from B1 to something else. Would I copy this name everywhere within the copied folder (such as on cc files, in and out files, etc.) and how would I go about doing this regarding the CMakelists.txt file as I’ve read that it is pretty important. Thank you so much again for your time and help and I apologize if these are very basic questions (I am in high school and am curious about this software)

If you copy the B1 example elsewhere, you can start by keeping all the filenames the same. As you transform it into your own application, you will surely want to give the classes names that are meaningful for you. So you’ll change the class names within the code, the filenames to match, and then find references to the filenames in the CMakeLists.txt file and change those to match.

1 Like

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