Вы находитесь на странице: 1из 43

Geant4

Anders Hjalmarsson
anders.hjalmarsson@physics.uu.se
What is Geant4

• Geant4 successor of Geant3

• Geant4 is a software using an Object-Oriented environment (C++)


C++
Data types Data types Geant4 Geant4 write to standard output:

int G4int G4double a = 20;


long G4long G4cout << a << G4endl;
float G4float
double G4double Geant4 write to file:
. G4bool
. G4complex std::ofstream outFile(“output.txt”);
. G4String G4double a = 30;
outFile << a << G4endl;
C++ object

An object is an instance that can be created, stored and manipulated.

Object in C++ belong to a class

A class is a data type, like int or double, that is defined by the programmer.

Classes are not part of standard C++

Mostly classes consists of a header file (.h) and a source file (.cpp)
Class Clock header file
#ifndef Clock_h
#define Clock_h 1

class Clock
{
public:
Clock();
Clock(int hour, int min, int sec);
~Clock();
void SetTime(int hour, int min ,int sec);
int ReadHour();
int ReadMin();
int ReadSec();
void WriteTime(bool wSec = true);
private:
int h;
int m;
int s;
};
#endif
Class Clock source file
#include "Clock.h" int Clock::ReadHour()
#include <iostream> {
#include <iomanip> return h;
}
Clock::Clock() : h(0), m(0), s(0) int Clock::ReadMin()
{;} {
return m;
Clock::Clock(int hour, int min, int sec); }
{ int Clock::ReadSec()
h = hour; {
m = min; return s;
s = sec; }
} void Clock::WriteTime(bool wSec)
{
Clock::~Clock() std::cout<<setw(2)<<setfill('0')<<t
{;} <<':'<<setw(2)<<setfill('0')<<m;
if(wSec)
void Clock::SetTime(int hour, int min, int sec) std:cout<<':'<<setw(2)<<setfill('0')<<s;
{ std::cout<<endl;
h = hour; m = min; s = sec }
}
What is Geant4 (cont.)

• Geant4 successor of Geant3

• Geant4 is a software using an Object-Oriented environment (C++)

• Many requirements taken into account, from heavy ion physics to


medical applications

• A large degree of flexibility is provided


Flexibility
• Many types of geometrical descriptions

 CGS (Constructive Solid Geometry)


 BREP (Boundary Represented Solids)
 Boolean Solids

• Many physic models, e.g

 EM processes
 Photon/lepton – hadron processes
 Optical photon processes
 Decay processes
 You can add more
What is Geant4 (cont.)

• Geant4 successor of Geant3

• Geant4 is a software using an Object-Oriented environment (C++)

• Many requirements taken into account, from heavy ion physics to


medical applications

• A large degree of flexibility is provided

• Toolkit
The Geant4 toolkit
You have to build the application
The Geant4 toolkit
You have to build the application

Define
• Geometry
G4double x = 5.0*cm;
G4double y = 5.0*cm;
G4double z = 10.0*cm;
G4Box *detectorS = new G4Box(“detectorS“, x/2, y/2, z/2);
The Geant4 toolkit
You have to build the application

Define
• Geometry
G4double x = 5.0*cm;
G4double y = 5.0*cm;
G4double z = 10.0*cm;
G4Box *detectorS = new G4Box(“detectorS“, x/2, y/2, z/2);
The Geant4 toolkit
You have to build the application

Define
• Geometry
G4double x = 5.0*cm;
G4double y = 5.0*cm;
G4double z = 10.0*cm;
G4Box *detectorS = new G4Box(“detectorS“, x/2, y/2, z/2);
• Material
G4LogicalVolume* detectorL = new G4LogicalVolume(detectorS, Pb, “detector", 0, 0, 0);
The Geant4 toolkit
You have to build the application

Define
• Geometry
G4double x = 5.0*cm;
G4double y = 5.0*cm;
G4double z = 10.0*cm;
G4Box *detectorS = new G4Box(“detectorS“, x/2, y/2, z/2);
• Material
G4LogicalVolume* detectorL = new G4LogicalVolume(detectorS, Pb, “detector", 0, 0, 0);
• Place
G4ThreeVector* positionDetector = G4ThreeVector(0,0,0);
G4VPhysicalVolume* detectorP =
new G4PVPlacement(0, positionDetector, detectorL, “detector”, worldL, false,
0, false);
The Geant4 toolkit
You have to build the application

Define
• Geometry
G4double x = 5.0*cm;
G4double y = 5.0*cm;
G4double z = 10.0*cm;
G4Box *detectorS = new G4Box(“detectorS“, x/2, y/2, z/2);
• Material
G4LogicalVolume* detectorL = new G4LogicalVolume(detectorS, Pb, “detector", 0, 0, 0);
• Place
G4ThreeVector* positionDetector = G4ThreeVector(0,0,0);
G4VPhysicalVolume* detectorP =
new G4PVPlacement(0, positionDetector, detectorL, “detector”, worldL, false,
0, false);
Mandatory class
class MyDetectorConstruction : public G4VUserDetectorConstruction
Example Detector Construction
For the DetectorConstruction class two files needed
Header file
MaSDetectorConstruction.h
Source file
MaSDetectorConstruction.cpp

MaS
• On lillekis.tsl.uu.se
• In the directory
•/home//MaS/include
•/home//MaS/src
Example DC
For the DetectorConstruction class two files needed
Header file
MaSDetectorConstruction.h #ifndef MaSDetectorConstruction_h
Source file #define MaSDetectorConstruction_h 1

MaSDetectorConstruction.cpp #include "globals.hh"


#include "G4VUserDetectorConstruction.hh"

class G4VPhysicalVolume;
class G4Material;

class MaSDetectorConstruction : public G4VUserDetectorConstruction


MaS {
public:
• On lillekis.tsl.uu.se MaSDetectorConstruction();
• In the directory virtual ~MaSDetectorConstruction();
virtual G4VPhysicalVolume* Construct();
•/home//MaS/include
•/home//MaS/src private:
void DefineMaterials();
void DefineVolumes();
G4VPhysicalVolume* fWorldP;
G4Material *fWorldMaterial;
G4Material *fDetectorMaterial;
};
#endif
#ifndef MaSDetectorConstruction_h
#define MaSDetectorConstruction_h 1

Example DC #include "globals.hh"


#include "G4VUserDetectorConstruction.hh"

class G4VPhysicalVolume;
class G4Material;
Source file class MaSDetectorConstruction : public G4VUserDetectorConstruction
{
MaSDetectorConstruction.cpp public:
MaSDetectorConstruction();
virtual ~MaSDetectorConstruction();
virtual G4VPhysicalVolume* Construct();
#include "MaSDetectorConstruction.h" private:
void DefineMaterials();
void DefineVolumes();
MaSDetectorConstruction::MaSDetectorConstruction() : G4VPhysicalVolume* fWorldP;
G4VUserDetectorConstruction() G4Material *fWorldMaterial;
G4Material *fDetectorMaterial;
{} };
#endif
MaSDetectorConstruction::~MaSDetectorConstruction()
{}

G4VPhysicalVolume* MaSDetectorConstruction::Construct()
{}

void MaSDetectorConstruction::DefineMaterials()
{}

void MaSDetectorConstruction::DefineVolumes()
{}
#ifndef MaSDetectorConstruction_h
#define MaSDetectorConstruction_h 1

Example DC #include "globals.hh"


#include "G4VUserDetectorConstruction.hh"

class G4VPhysicalVolume;
class G4Material;
Source file class MaSDetectorConstruction : public G4VUserDetectorConstruction
{
MaSDetectorConstruction.cpp public:
MaSDetectorConstruction();
virtual ~MaSDetectorConstruction();
virtual G4VPhysicalVolume* Construct();
#include "MaSDetectorConstruction.h" private:
void DefineMaterials();
void DefineVolumes();
MaSDetectorConstruction::MaSDetectorConstruction() : G4VPhysicalVolume* fWorldP;
G4VUserDetectorConstruction() G4Material *fWorldMaterial;
G4Material *fDetectorMaterial;
{} };
#endif
MaSDetectorConstruction::~MaSDetectorConstruction()
{}

G4VPhysicalVolume* MaSDetectorConstruction::Construct()
{}

void MaSDetectorConstruction::DefineMaterials()
{}

void MaSDetectorConstruction::DefineVolumes()
{}
#ifndef MaSDetectorConstruction_h
#define MaSDetectorConstruction_h 1

Example DC #include "globals.hh"


#include "G4VUserDetectorConstruction.hh"

class G4VPhysicalVolume;
class G4Material;
Source file class MaSDetectorConstruction : public G4VUserDetectorConstruction
{
MaSDetectorConstruction.cpp public:
MaSDetectorConstruction();
virtual ~MaSDetectorConstruction();
virtual G4VPhysicalVolume* Construct();
G4VPhysicalVolume* MaSDetectorConstruction::Construct()
{ private:
void DefineMaterials();
G4cout<<"Construct"<<G4endl; void DefineVolumes();
DefineMaterials(); G4VPhysicalVolume* fWorldP;
G4Material *fWorldMaterial;
DefineVolumes(); G4Material *fDetectorMaterial;
return fworldP; };
#endif
}
#ifndef MaSDetectorConstruction_h
#define MaSDetectorConstruction_h 1

Example DC #include "globals.hh"


#include "G4VUserDetectorConstruction.hh"

class G4VPhysicalVolume;
class G4Material;
Source file class MaSDetectorConstruction : public G4VUserDetectorConstruction
{
MaSDetectorConstruction.cpp public:
MaSDetectorConstruction();
virtual ~MaSDetectorConstruction();
virtual G4VPhysicalVolume* Construct();
G4VPhysicalVolume* MaSDetectorConstruction::Construct()
{ private:
void DefineMaterials();
G4cout<<"Construct"<<G4endl; void DefineVolumes();
DefineMaterials(); G4VPhysicalVolume* fWorldP;
G4Material *fWorldMaterial;
DefineVolumes(); G4Material *fDetectorMaterial;
return worldP; };
#endif
}

void MaSDetectorConstruction::DefineMaterials()
{
G4NistManager* nistManager = G4NistManager::Instance();
G4bool fromIsotopes = false;

fWorldMaterial = nistManager->FindOrBuildMaterial("G4_AIR", fromIsotopes);

fDetectorMaterial = nistManager -> FindOrBuildMaterial("G4_SODIUM_IODIDE",fromIsotopes);

G4cout<< *(G4Material::GetMaterialTable()) << G4endl;


}
#include "MaSDetectorConstruction.h“

Example DC #include “G4NistManager.hh”


#include “G4Material.hh”

MaSDetectorConstruction::MaSDetectorConstruction() :
Source file G4VUserDetectorConstruction()
MaSDetectorConstruction.cpp {}

MaSDetectorConstruction::~MaSDetectorConstruction()
G4VPhysicalVolume* MaSDetectorConstruction::Construct() {}
{
G4cout<<"Construct"<<G4endl; G4VPhysicalVolume* MaSDetectorConstruction::Construct()
DefineMaterials(); {}
DefineVolumes();
return worldP; void MaSDetectorConstruction::DefineMaterials()
}
{}

void MaSDetectorConstruction::DefineVolumes()
{}

void MaSDetectorConstruction::DefineMaterials()
{
G4NistManager* nistManager = G4NistManager::Instance();
G4bool fromIsotopes = false;

fWorldMaterial = nistManager->FindOrBuildMaterial("G4_AIR", fromIsotopes);

fDetectorMaterial = nistManager -> FindOrBuildMaterial("G4_SODIUM_IODIDE",fromIsotopes);

G4cout<< *(G4Material::GetMaterialTable()) << G4endl;


}
Materials
Real world
• elements, compounds , mixtures of elements and /or compounds
• can be solids, liquids or gas
• pressures, temperatures and densities

Geant4 definitions of materials


• G4Element class
• compounds or molecules can be built by multiple G4Element to
an G4Material object
• mixtures from multiple compounds or elements to an G4Material
object
• single G4Element to form a G4Material
• G4Element from one or multiple instances of G4Isotope
• NIST material database
Materials
Requires you to set one material condition
• density

Optional
• state (default is solid or gas, density dependent)
• temperature (STP temperature = 271.15 K, default)
• pressure (STP pressure = 100 kPa = 1 atm, default)

You can define material conditions with none STP e.g.


vacuum can be the same as are with a lower density
Materials
Material of a single element
G4double density = 2.70*g/cm3;
G4double a = 15.99*g/mol;
G4Material * mAl = new G4Material(“Al”, z=13, a , density);

Material of isotopes
G4int z; G4int a;
G4Isotope* isoO16 = new G4Isotope(“O16”, z=8, a=16 , 16.0*g/mol);
G4Isotope* isoO17 = new G4Isotope(“O17”, z=8, a=17 , 17.0*g/mol);
G4Isotope* isoO18 = new G4Isotope(“O18”, z=8, a=18 , 18.0*g/mol);

G4Element* elO = new G4Element(name = “Oxygen”, symbol = ”O”, ncomponents=3);


elO -> AddIsotope(isoO16, abundance = 99.762*perCent);
elO -> AddIsotope(isoO17, abundance = 0.038*perCent);
elO -> AddIsotope(isoO18, abundance = 0.200*perCent);
Materials
Material of isotopes cont.
G4Material* mAl2O3 = new G4Material(“AluminiumOxide”, 3.95*g/cm3, 2);
mAl2O3 -> AddMaterial(mAl, 99.9*perCent);
mAl203 -> AddElement(elO, 0.1*perCent);
Materials
Material of isotopes cont.
G4Material* mAl2O3 = new G4Material(“AluminiumOxide”, 3.95*g/cm3, 2);
mAl2O3 -> AddMaterial(mAl, 99.9*perCent);
mAl203 -> AddElement(elO, 0.1*perCent);

Geant4 User’s Guide for Application Developers


Chapter 4.2.3
#ifndef MaSDetectorConstruction_h
#define MaSDetectorConstruction_h 1

Example DC #include "globals.hh"


#include "G4VUserDetectorConstruction.hh"

class G4VPhysicalVolume;
class G4Material;
Source file class MaSDetectorConstruction : public G4VUserDetectorConstruction
{
MaSDetectorConstruction.cpp public:
MaSDetectorConstruction();
virtual ~MaSDetectorConstruction();
virtual G4VPhysicalVolume* Construct();
G4VPhysicalVolume* MaSDetectorConstruction::Construct()
{ private:
void DefineMaterials();
G4cout<<"Construct"<<G4endl; void DefineVolumes();
DefineMaterials(); G4VPhysicalVolume* fWorldP;
G4Material *fWorldMaterial;
DefineVolumes(); G4Material *fDetectorMaterial;
return fWorldP; };
#endif
}
Example DC
void MaSDetectorConstruction::DefineVolumes()
{
G4double worldOutRadius = 0.5*m;
G4double worldInRadius = 0.0*m;
G4double worldLength = 2.0*m;
G4double worldStartAngle = 0.;
G4double worldSpanAngle = 360.*deg;

G4Tubs* worldS = new G4Tubs("worldS", worldInRadius, worldOutRadius, worldLength/2.,

worldStartAngle, worldSpanAngle);

G4LogicalVolume* worldL = new G4LogicalVolume(worldS, fWorldMaterial, "worldL");

fWorldP = new G4PVPlacement(0, G4ThreeVector(), worldL, "World", 0, false, 0, false);

G4double detectorX = 5.0*cm;


G4double detectorY = 5.0*cm;
G4double detectorZ = 10.0*cm;

G4Box* detectorS = new G4Box("detectorS", detectorX/2., detectorY/2., detectorZ/2.);

G4LogicalVolume* detectorL = new G4LogicalVolume(detectorS, fDetectorMaterial, "detectorL");

new G4PVPlacement(0, G4ThreeVector(0,0,0), detectorL, "detector", worldL,false,0,false);

}
#include "MaSDetectorConstruction.h“

Example DC #include “G4NistManager.hh”


#include “G4Material.hh”

#include "G4Box.hh"
void MaSDetectorConstruction::DefineVolumes() #include "G4Tubs.hh"
{ #include "G4LogicalVolume.hh"
G4double worldOutRadius = 0.5*m; #include "G4PVPlacement.hh"
G4double worldInRadius = 0.0*m;
G4double worldLength = 2.0*m; MaSDetectorConstruction::MaSDetectorConstruction() :
G4double worldStartAngle = 0.; G4VUserDetectorConstruction()
G4double worldSpanAngle = 360.*deg; {}

G4Tubs* worldS = new G4Tubs("worldS", worldInRadius, worldOutRadius, worldLength/2.,


MaSDetectorConstruction::~MaSDetectorConstruction()
{}
worldStartAngle, worldSpanAngle);
G4VPhysicalVolume* MaSDetectorConstruction::Construct()
G4LogicalVolume* worldL = new G4LogicalVolume(worldS,{}fWorldMaterial, "worldL");

fWorldP = new G4PVPlacement(0, G4ThreeVector(), worldL, "World",


void 0, false, 0, false);
MaSDetectorConstruction::DefineMaterials()
{}
G4double detectorX = 5.0*cm;
G4double detectorY = 5.0*cm; void MaSDetectorConstruction::DefineVolumes()
G4double detectorZ = 10.0*cm; {}

G4Box* detectorS = new G4Box("detectorS", detectorX/2., detectorY/2., detectorZ/2.);

G4LogicalVolume* detectorL = new G4LogicalVolume(detectorS, fDetectorMaterial, "detectorL");

new G4PVPlacement(0, G4ThreeVector(0,0,0), detectorL, "detector", worldL,false,0,false);

}
#ifndef MaSDetectorConstruction_h
#define MaSDetectorConstruction_h 1

Example DC #include "globals.hh"


#include "G4VUserDetectorConstruction.hh"

class G4VPhysicalVolume;
class G4Material;
Source file class MaSDetectorConstruction : public G4VUserDetectorConstruction
{
MaSDetectorConstruction.cpp public:
MaSDetectorConstruction();
virtual ~MaSDetectorConstruction();
#include "MaSDetectorConstruction.h“ virtual G4VPhysicalVolume* Construct();

private:
#include “G4NistManager.hh” void DefineMaterials();
#include “G4Material.hh” void DefineVolumes();
G4VPhysicalVolume* fWorldP;
G4Material *fWorldMaterial;
#include "G4Box.hh" G4Material *fDetectorMaterial;
};
#include "G4Tubs.hh" #endif
#include "G4LogicalVolume.hh"
#include "G4PVPlacement.hh"

MaSDetectorConstruction::MaSDetectorConstruction() :
G4VUserDetectorConstruction()
{}

MaSDetectorConstruction::~MaSDetectorConstruction()
{}

G4VPhysicalVolume* MaSDetectorConstruction::Construct()
{}

void MaSDetectorConstruction::DefineMaterials()
{}

void MaSDetectorConstruction::DefineVolumes()
{}
#include "MaSDetectorConstruction.h“

Example DC #include “G4NistManager.hh”


#include “G4Material.hh”

#include "G4Box.hh"
MaSDetectorConstruction::MaSDetectorConstruction() :
Source file G4VUserDetectorConstruction()
#include "G4Tubs.hh"
MaSDetectorConstruction.cpp {}
#include "G4LogicalVolume.hh"
#include "G4PVPlacement.hh"
MaSDetectorConstruction::~MaSDetectorConstruction()
MaSDetectorConstruction::MaSDetectorConstruction(): {}
MaSDetectorConstruction::MaSDetectorConstruction() :
G4VUserDetectorConstruction() G4VUserDetectorConstruction()
{ G4VPhysicalVolume* MaSDetectorConstruction::Construct()
{}
; {}
} MaSDetectorConstruction::~MaSDetectorConstruction()
void MaSDetectorConstruction::DefineMaterials()
{}
{}
G4VPhysicalVolume* MaSDetectorConstruction::Construct()
void MaSDetectorConstruction::DefineVolumes()
{}
{}
MaSDetectorConstruction::~MaSDetectorConstruction() void MaSDetectorConstruction::DefineMaterials()
{ {}
;
} void MaSDetectorConstruction::DefineVolumes()
{}
First geometry and mandatory class

DONE!!!
Example Primary Generator Action
Mandatory user class to control the generation of primary particles (source, beam).

Should not generate primary particles → invoke GeneratePrimaryVertex()


method in of primary generator to produce primary particles.

Constructor

Initialization of primary generator


Set default values

GeneratePrimaries() method

Randomize particle-by-particle value(s)


Set these values to primary generator
Invoke GeneratePrimaryVertex() method

User class inherit G4VUserPrimaryGeneratorAction


Example PGAction
For the PrimaryGeneratorAction class
MaSPrimaryGeneratorAction.h
MaSPrimaryGeneratorAction.cpp #ifndef MaSPrimaryGeneratorAction_h
#define MaSPrimaryGeneratorAction_h 1

#include "G4VUserPrimaryGeneratorAction.hh"
#include "globals.hh"
#include "Randomize.hh"

class G4ParticleGun;
class G4Event;
Initialization of primary generator;
class MaSPrimaryGeneratorAction : public
G4ParticleGun or G4VUserPrimaryGeneratorAction
G4GeneralParticleSource {
public:
MaSPrimaryGeneratorAction();
virtual ~MaSPrimaryGeneratorAction();
virtual void GeneratePrimaries(G4Event* );

private:
G4ParticleGun* fParticleGun;
};
Invoke GeneratePrimaryVertex() method #endif

GeneratePrimaryVertex() method of G4ParticleGun or G4GeneralParticleSource


#include "MaSPrimaryGeneratorAction.h"

Example PGAction
#include "G4Event.hh"
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"

#include "Randomize.hh"

MaSPrimaryGeneratorAction::MaSPrimaryGeneratorAction()
: G4VUserPrimaryGeneratorAction()
{
…;
}

MaSPrimaryGeneratorAction::~MaSPrimaryGeneratorAction()
{

}

void MaSPrimaryGeneratorAction::GeneratePrimaries(G4Event *anEvent)


{
…;
MaSPrimaryGeneratorAction::MaSPrimaryGeneratorAction() }
: G4VUserPrimaryGeneratorAction()
{
G4int nofParticles = 1;
fParticleGun = new G4ParticleGun(nofParticles);
G4ParticleDefinition* particleDefinition
= G4ParticleTable::GetParticleTable()->FindParticle("gamma");
fParticleGun->SetParticleDefinition(particleDefinition);
fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
fParticleGun->SetParticlePosition(G4ThreeVector(0., 0., -10*cm));
fParticleGun->SetParticleEnergy(661.7*keV);
}
Example PGAction
For the PrimaryGeneratorAction class
MaSPrimaryGeneratorAction.h
MaSPrimaryGeneratorAction.cpp #ifndef MaSPrimaryGeneratorAction_h
#define MaSPrimaryGeneratorAction_h 1

#include "G4VUserPrimaryGeneratorAction.hh"
#include "globals.hh"
#include "Randomize.hh"

class G4ParticleGun;
class G4Event;
Initialization of primary generator;
class MaSPrimaryGeneratorAction : public
G4ParticleGun or G4VUserPrimaryGeneratorAction
G4GeneralParticleSource {
public:
MaSPrimaryGeneratorAction();
virtual ~MaSPrimaryGeneratorAction();
virtual void GeneratePrimaries(G4Event* );

private:
G4ParticleGun* fParticleGun;
};
Invoke GeneratePrimaryVertex() method #endif

GeneratePrimaryVertex() method of G4ParticleGun or G4GeneralParticleSource


#include "MaSPrimaryGeneratorAction.h"

Example PGAction
#include "G4Event.hh"
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"

#include "Randomize.hh"

MaSPrimaryGeneratorAction::MaSPrimaryGeneratorAction()
: G4VUserPrimaryGeneratorAction()
{
…;
}

MaSPrimaryGeneratorAction::~MaSPrimaryGeneratorAction()
MaSPrimaryGeneratorAction::~MaSPrimaryGeneratorAction() {
{ …
delete fParticleGun; }
}
void MaSPrimaryGeneratorAction::GeneratePrimaries(G4Event *anEvent)
{
…;
}

void MaSPrimaryGeneratorAction::GeneratePrimaries(G4Event *anEvent)


{
fParticleGun->GeneratePrimaryVertex(anEvent);
}
G4ParticleGun vs. G4GeneralParticleSource

G4ParticleGun G4GeneralParticleSource
 Simple  Powerful
 Easy to handle  Controlled by UI commands
Use set methods to alternate event  A number of different source geometries
values  Built in randomizing of source

Primary source geometry surface or volume, use G4GeneralParticleSource


Complicated distributions, use G4GeneralParticleSource
Point source and simple distributions, use G4ParticleGun
G4ParticleGun vs. G4GeneralParticleSource

G4ParticleGun G4GeneralParticleSource
 Simple  Powerful
 Easy to handle  Controlled by UI commands
Use set methods to alternate event  A number of different source geometries
values  Built in randomizing of source

Primary source geometry surface or volume, use G4GeneralParticleSource


Complicated distributions, use G4GeneralParticleSource
Point source and simple distributions, use G4ParticleGun

More information on G4GeneralParticleSource


http://reat.space.qinetiq.com/gps/
Main
#include "MaSDetectorConstruction.h"
#include "G4PhysListFactory.hh"
#include "G4VModularPhysicsList.hh"
#include "MaSPrimaryGeneratorAction.h"

#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "QGSP_BERT_HP.hh"

#ifdef G4VIS_USE
#include "G4VisExecutive.hh"
#endif

#ifdef G4UI_USE
#include "G4UIExecutive.hh"
#endif

#include "Randomize.hh“
int main(int argc, char** argv)
{
G4RunManager * runManager = new G4RunManager;

runManager -> SetUserInitialization(new MaSDetectorConstruction());

G4PhysListFactory factory;
G4VModularPhysicsList* physicsList = factory.GetReferencePhysList("QGSP_BERT_HP");
physicsList -> SetVerboseLevel(1);
physicsList -> SetDefaultCutValue(.01*mm);
runManager -> SetUserInitialization(physicsList);

runManager -> SetUserAction(new MaSPrimaryGeneratorAction());

runManager -> Initialize();

#ifdef G4VIS_USE
G4VisManager* visManager = new G4VisExecutive;
visManager->Initialize();
#endif

G4UImanager* UImanager = G4UImanager::GetUIpointer();


if (argc != 1) {
G4String command = "/control/execute ";
G4String fileName = argv[1];
G4cout<<argv[1]<<G4endl;
UImanager->ApplyCommand(command+fileName);
}
else {
#ifdef G4UI_USE
G4UIExecutive* ui = new G4UIExecutive(argc, argv);
#ifdef G4VIS_USE
UImanager->ApplyCommand("/control/execute init_vis.mac");
#else
UImanager->ApplyCommand("/control/execute init.mac");
#endif
ui->SessionStart();
delete ui;
#endif
}

#ifdef G4VIS_USE
delete visManager;
#endif
delete runManager;
return 0;
}

Вам также может понравиться