Giter Site home page Giter Site logo

mkandemirr / g4dcp Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 91 KB

G4DCP is a new detector construction interface for creating flexible detector setups in Geant4 applications.

License: Other

CMake 6.29% C++ 93.71%
builder-design-pattern geant4-simulation detector-construction flexible-detector-setup geant4-detector-construction-pattern user-detector-construction-class

g4dcp's Introduction

Geant4 Detector Construction Pattern (G4DCP)

G4DCP is a new detector construction interface for creating flexible detector setups in Geant4 applications. The elements of G4DCP, including G4VUserDetectorConstruction, form an elegant template for detector setups. The figure below summarizes the structure of G4DCP in a UML diagram.

g4dcp

The following code sample shows examples of creating concrete component builder and component factory classes using the elements of G4DCP.

//Only relevant sections are displayed.
//Creating a concrete logical volume builder class
class UserLVBuilder : public VComponentBuilder<G4LogicalVolume> {
	protected:  
    virtual G4LogicalVolume* Build() override;
};
G4LogicalVolume* UserLVBuilder::Build()
{
//Implementation..
}
//Creating a concrete physical volume builder class
class UserPVBuilder : public VComponentBuilder<G4VPhysicalVolume> {
	protected:  
    virtual G4VPhysicalVolume* Build() override;
};
G4VPhysicalVolume* UserPVBuilder::Build()
{
//Implementation..
}
//Creating a concrete material builder class
class UserMaterialBuilder : public VComponentBuilder<G4Material> {
	protected:  
    virtual G4Material* Build() override;
};
G4Material* UserMaterialBuilder::Build()
{
//Implementation..
}
//Creating a concrete logical volume factory class. This class can be made singleton.
class UserLogicalVolumeFactory: public VComponentFactory<G4LogicalVolume>
{       
  protected:    
    virtual G4LogicalVolume* Create(const G4String& name) override;             
};
G4LogicalVolume* UserLogicalVolumeFactory::Create(const G4String& name)
{
	G4LogicalVolume* lv = G4LogicalVolumeStore::GetInstance()->GetVolume(name);
  if(lv) return lv;

  if(name=="")
  {
  	UserLVBuilder1 builder;
  	return builder.GetProduct();
   
  }else if(name=="")
  {
  	UserLVBuilder2 builder;
  	return builder.GetProduct();
  }
  .
  .
  .
  else 
  {
    return nullptr; //the Get() method in the parent class handle nullptr (look at Fig. 1).
  }
   
}
//Getting desired component object from the user detector construction class.
class UserDetectorConstruction : public G4VUserDetectorConstruction{
  G4VPhysicalVolume* Construct() override;
};
G4VPhysicalVolume* DetectorConstruction::Construct()
{
  //G4VPhysicalVolume* pv = UserPhysicalVolumeFactory::GetInstance()->Get("..");	
  //G4LogicalVolume* pv = UserLogicalVolumeFactory::GetInstance()->Get("..");	
  UserLVBuilder1 builder;
  G4LogicalVolume* lv = builder.GetProduct();
  //code for final detector construction 
}

The package structure:

g4dcp: This directory includes two class templates that are used to generate builder classes related to geometry such as G4Material, G4LogicalVolume, G4VPhysicalVolume, G4OpticalSurface and so on.

example: This directory contains a sample Geant4 application that shows how to construct a detector using G4DCP.

Tested on

  • Os: Linux (Ubuntu 22.04.2 LTS)
  • Architecture: x86_64
  • Compiler: GCC 11.3.0
  • Geant4.11.1.1

How to use G4DCP in a Geant4 application?

Copy the G4DCP directory to the project source directory, where your CMakeList.txt file is located, and add the following two lines of code to the appropriate place of your CMakeList.txt file (for help, you can examine the CMakeList.txt files in the provided example application).

before the executable target is created:

  add_subdirectory(G4DCP)

after the executable target is created:

   target_link_libraries(yourExecutableTarget g4dcp ${Geant4_LIBRARIES} )

How to run the provided example application?

  1. Go to the directory where you installed the example in your system.
 cd path/To/example
  1. Create a directory named example-build in the same directory as example.
 mkdir example-build
  1. Now go inside this build directory and run CMake to generate the Makefiles needed to build the application. Two arguments are passed to CMake. The first argument to CMake is the path to the source directory that includes the CMakeList.txt file. The second argument is the path to the build directory where the generated make files will be located. CMake will now run to configure the build and generate Makefiles.
  cd example-build
  cmake -S ../example -B .
  1. With the Makefile available, you can now build by simply running make:
 make  
  1. The application is now ready to run. If you now list the contents of your build directory, you will notice that the executable main has been created. The program can be executed in two modes: interactive and batch. To run in an interactive mode:
 ./main
  1. To run in batch mode:
  ./main run.mac

Contacts

If you have any questions or wish to notify of updates and/or modification please contact:
Mustafa Kandemir ([email protected])

Citation

@article{KANDEMIR2024109183,
title = {A custom detector construction pattern for Geant4 applications},
journal = {Computer Physics Communications},
volume = {300},
pages = {109183},
year = {2024},
issn = {0010-4655},
doi = {https://doi.org/10.1016/j.cpc.2024.109183},
url = {https://www.sciencedirect.com/science/article/pii/S0010465524001061},
author = {Mustafa Kandemir},
keywords = {G4VUserDetectorConstruction, Design pattern, Modular coding, Detector components, Geometry construction}, }

g4dcp's People

Contributors

mkandemirr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.