Compare commits

...

3 Commits

Author SHA1 Message Date
Gitea db15a03619 Handle command line arguments 2018-04-03 00:51:12 +02:00
Gitea e59de3c504 Modified to use command line parameters 2018-04-03 00:50:20 +02:00
Gitea 1b640dec8b Store command line arguments 2018-04-03 00:49:44 +02:00
5 changed files with 137 additions and 9 deletions

View File

@ -15,11 +15,13 @@
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4ThreeVector.hh"
#include "Parameters.hh"
class MedtechPrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction
{
public:
MedtechPrimaryGeneratorAction();
MedtechPrimaryGeneratorAction(int energy);
virtual ~MedtechPrimaryGeneratorAction();
virtual void GeneratePrimaries(G4Event* anEvent);

36
include/Parameters.hh Normal file
View File

@ -0,0 +1,36 @@
//
// Parameters.hh
// medtech
//
// Created by Baranyai David on 2018. 04. 03..
//
#ifndef Parameters_hh
#define Parameters_hh
#include <stdio.h>
class Parameters
{
private:
/* Here will be the instance stored. */
static Parameters* instance;
/* Private constructor to prevent instancing. */
Parameters();
int ParticleEnergy;
int pgundegree;
public:
/* Static access method. */
static Parameters* getInstance();
int GetParticleEnergy();
int GetDegree();
void SetParticleEnergy(int);
void SetDegree(int);
};
#endif /* Parameters_hh */

View File

@ -14,13 +14,36 @@
#include "G4UImanager.hh"
#include "G4VisExecutive.hh"
#include "G4UIExecutive.hh"
#include "QGSP_BERT.hh"
#include "MedtechDetectorConstruction.hh"
#include "MedtechActionInitialization.hh"
#include "Parameters.hh"
int main(int argc,char** argv)
{
//parameter from command line
Parameters *param = Parameters::getInstance();
int NoE=0;
if (argc==2) NoE=atoi(argv[1]);
for(int i=1; i < argc-1; i++)
{
if(!strcmp("-n", argv[i]))
{
NoE = atoi(argv[i+1]);
}
else if(!strcmp("-p", argv[i]))
{
param -> SetParticleEnergy(atoi(argv[i+1]));
}
else if(!strcmp("-d", argv[i]))
{
param -> SetDegree(atoi(argv[i+1]));
}
}
//parameters from command line
#ifdef G4MULTITHREADED
G4MTRunManager* runManager = new G4MTRunManager;
@ -31,21 +54,28 @@ int main(int argc,char** argv)
G4RunManager* runManager = new G4RunManager;
#endif
runManager -> SetUserInitialization(new QGSP_BERT());
runManager -> SetUserInitialization(new MedtechDetectorConstruction());
runManager -> SetUserInitialization(new MedtechActionInitialization());
G4VisManager* visManager = new G4VisExecutive;
visManager->Initialize();
G4UImanager* UImanager = G4UImanager::GetUIpointer();
if (argc==2) {
if (NoE!=0)
{
//batch mode
runManager->Initialize();
runManager->BeamOn(NoE);
}
else {
else
{
//interactive mode
G4UIExecutive* ui = 0;
if ( argc == 1 ) {
ui = new G4UIExecutive(argc, argv);
}
UImanager->ApplyCommand("/control/macroPath macros"); //Need to set, macros moved to that folder
ui = new G4UIExecutive(argc, argv);
UImanager -> ApplyCommand("/control/macroPath macros"); //Need to set, macros moved to that folder
UImanager -> ApplyCommand("/control/execute gui.mac");
ui->SessionStart();
delete ui;
}

View File

@ -9,6 +9,8 @@
MedtechPrimaryGeneratorAction::MedtechPrimaryGeneratorAction()
{
Parameters *param = Parameters::getInstance();
G4int numberOfParticles = 1;
particleGun = new G4ParticleGun(numberOfParticles);
G4ParticleTable *particleTable = G4ParticleTable::GetParticleTable();
@ -16,7 +18,19 @@ MedtechPrimaryGeneratorAction::MedtechPrimaryGeneratorAction()
particleGun -> SetParticleDefinition(particle);
particleGun -> SetParticlePosition(G4ThreeVector(1,1,1));
particleGun -> SetParticleMomentumDirection(G4ThreeVector(0, 0, 4*m));
particleGun -> SetParticleEnergy(6*MeV);
particleGun -> SetParticleEnergy(param -> GetParticleEnergy() *MeV);
}
MedtechPrimaryGeneratorAction::MedtechPrimaryGeneratorAction(int energy)
{
G4int numberOfParticles = 1;
particleGun = new G4ParticleGun(numberOfParticles);
G4ParticleTable *particleTable = G4ParticleTable::GetParticleTable();
G4ParticleDefinition *particle = particleTable -> FindParticle("e-");
particleGun -> SetParticleDefinition(particle);
particleGun -> SetParticlePosition(G4ThreeVector(1,1,1));
particleGun -> SetParticleMomentumDirection(G4ThreeVector(0, 0, 4*m));
particleGun -> SetParticleEnergy(energy*MeV);
}
MedtechPrimaryGeneratorAction::~MedtechPrimaryGeneratorAction()

46
src/Parameters.cc Normal file
View File

@ -0,0 +1,46 @@
//
// Parameters.cc
// medtech
//
// Created by Baranyai David on 2018. 04. 03..
//
#include "Parameters.hh"
Parameters* Parameters::getInstance()
{
if (instance == 0)
{
instance = new Parameters();
}
return instance;
}
Parameters::Parameters() : ParticleEnergy(6), pgundegree(90)
{
}
/* Null, because instance will be initialized on demand. */
Parameters* Parameters::instance = 0;
int Parameters::GetParticleEnergy()
{
return ParticleEnergy;
}
int Parameters::GetDegree()
{
return pgundegree;
}
void Parameters::SetDegree(int d)
{
pgundegree = d;
}
void Parameters::SetParticleEnergy(int p)
{
ParticleEnergy = p;
}