Import Geant4 9.3.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-09 16:15:05 +02:00
parent b79225fb37
commit 74cad5e589
3877 changed files with 234205 additions and 167127 deletions
@@ -0,0 +1,252 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4AdjointPrimaryGeneratorAction.cc,v 1.2 2009/11/18 18:02:06 gcosmo Exp $
// GEANT4 tag $Name: geant4-09-03 $
//
/////////////////////////////////////////////////////////////////////////////
// Class Name: G4AdjointCrossSurfChecker
// Author: L. Desorgher
// Organisation: SpaceIT GmbH
// Contract: ESA contract 21435/08/NL/AT
// Customer: ESA/ESTEC
/////////////////////////////////////////////////////////////////////////////
#include "G4AdjointPrimaryGeneratorAction.hh"
#include "G4Event.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"
#include "G4ParticleTable.hh"
#include "G4AdjointSimManager.hh"
#include "G4AdjointPrimaryGenerator.hh"
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
G4AdjointPrimaryGeneratorAction::G4AdjointPrimaryGeneratorAction()
{
theAdjointPrimaryGenerator= new G4AdjointPrimaryGenerator();
PrimariesConsideredInAdjointSim[G4String("e-")]=false;
PrimariesConsideredInAdjointSim[G4String("gamma")]=false;
PrimariesConsideredInAdjointSim[G4String("proton")]=false;
PrimariesConsideredInAdjointSim[G4String("ion")]=false;
ListOfPrimaryFwdParticles.clear();
ListOfPrimaryAdjParticles.clear();
last_generated_part_was_adjoint=false;
index_particle=100000;
ion_name="not_defined";
fwd_ion = 0;
adj_ion = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
G4AdjointPrimaryGeneratorAction::~G4AdjointPrimaryGeneratorAction()
{
delete theAdjointPrimaryGenerator;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
void G4AdjointPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
if ( !last_generated_part_was_adjoint ) {
index_particle++;
if (index_particle >= ListOfPrimaryAdjParticles.size()) index_particle =0;
G4double E1=Emin;
G4double E2=Emax;
if (!ListOfPrimaryAdjParticles[index_particle]) UpdateListOfPrimaryParticles();//ion has not been created yet
if (ListOfPrimaryAdjParticles[index_particle]->GetParticleName() == "adj_proton") {
E1=EminIon;
E2=EmaxIon;
}
if (ListOfPrimaryAdjParticles[index_particle]->GetParticleType() == "adjoint_nucleus") {
G4int A= ListOfPrimaryAdjParticles[index_particle]->GetAtomicMass();
E1=EminIon*A;
E2=EmaxIon*A;
}
theAdjointPrimaryGenerator->GenerateAdjointPrimaryVertex(anEvent,
ListOfPrimaryAdjParticles[index_particle],
E1,E2);
G4PrimaryVertex* aPrimVertex = anEvent->GetPrimaryVertex();
p=aPrimVertex->GetPrimary()->GetMomentum();
pos=aPrimVertex->GetPosition();
G4double pmag=p.mag();
G4double m0=ListOfPrimaryAdjParticles[index_particle]->GetPDGMass();
G4double ekin=std::sqrt( m0*m0 + pmag*pmag) -m0;
//The factor pi is to normalise the weight to the directional flux
G4double adjoint_source_area = G4AdjointSimManager::GetInstance()->GetAdjointSourceArea();
G4double adjoint_weight = ComputeEnergyDistWeight(ekin,E1,E2)*adjoint_source_area*pi;
aPrimVertex->SetWeight(adjoint_weight);
last_generated_part_was_adjoint =true;
G4AdjointSimManager::GetInstance()->SetAdjointTrackingMode(true);
G4AdjointSimManager::GetInstance()->RegisterAdjointPrimaryWeight(adjoint_weight);
}
else {
//fwd particle equivalent to the last generated adjoint particle ios generated
G4PrimaryVertex* aPrimVertex = new G4PrimaryVertex();
aPrimVertex->SetPosition(pos.x(),pos.y(),pos.z());
aPrimVertex->SetT0(0.);
G4PrimaryParticle* aPrimParticle = new G4PrimaryParticle(ListOfPrimaryFwdParticles[index_particle],
-p.x(),-p.y(),-p.z());
aPrimVertex->SetPrimary(aPrimParticle);
anEvent->AddPrimaryVertex(aPrimVertex);
last_generated_part_was_adjoint =false;
G4AdjointSimManager::GetInstance()->SetAdjointTrackingMode(false);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
void G4AdjointPrimaryGeneratorAction::SetEmin(G4double val)
{
Emin=val;
EminIon=val;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
void G4AdjointPrimaryGeneratorAction::SetEmax(G4double val)
{
Emax=val;
EmaxIon=val;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
void G4AdjointPrimaryGeneratorAction::SetEminIon(G4double val)
{
EminIon=val;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
void G4AdjointPrimaryGeneratorAction::SetEmaxIon(G4double val)
{
EmaxIon=val;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
G4double G4AdjointPrimaryGeneratorAction::ComputeEnergyDistWeight(G4double E ,G4double E1, G4double E2)
{
// We generate N numbers of primaries with a 1/E energy law distribution.
// We have therefore an energy distribution function
// f(E)=C/E (1)
// with C a constant that is such that
// N=Integral(f(E),E1,E2)=C.std::log(E2/E1) (2)
// Therefore from (2) we get
// C=N/ std::log(E2/E1) (3)
// and
// f(E)=N/ std::log(E2/E1)/E (4)
//For the adjoint simulation we need a energy distribution f'(E)=1..
//To get that we need therefore to apply a weight to the primary
// W=1/f(E)=E*std::log(E2/E1)/N
//
return std::log(E2/E1)*E/G4AdjointSimManager::GetInstance()->GetNbEvtOfLastRun();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
void G4AdjointPrimaryGeneratorAction::SetSphericalAdjointPrimarySource(G4double radius, G4ThreeVector center_pos)
{
radius_spherical_source = radius;
center_spherical_source = center_pos;
type_of_adjoint_source ="Spherical";
theAdjointPrimaryGenerator->SetSphericalAdjointPrimarySource(radius,center_pos);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
void G4AdjointPrimaryGeneratorAction::SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(const G4String& volume_name)
{
type_of_adjoint_source ="ExternalSurfaceOfAVolume";
theAdjointPrimaryGenerator->SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(volume_name);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
void G4AdjointPrimaryGeneratorAction::ConsiderParticleAsPrimary(const G4String& particle_name)
{
if (PrimariesConsideredInAdjointSim.find(particle_name) != PrimariesConsideredInAdjointSim.end()){
PrimariesConsideredInAdjointSim[particle_name]=true;
}
UpdateListOfPrimaryParticles();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
void G4AdjointPrimaryGeneratorAction::NeglectParticleAsPrimary(const G4String& particle_name)
{
if (PrimariesConsideredInAdjointSim.find(particle_name) != PrimariesConsideredInAdjointSim.end()){
PrimariesConsideredInAdjointSim[particle_name]= false;
}
UpdateListOfPrimaryParticles();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
void G4AdjointPrimaryGeneratorAction::UpdateListOfPrimaryParticles()
{
G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
ListOfPrimaryFwdParticles.clear();
ListOfPrimaryAdjParticles.clear();
std::map<G4String, G4bool>::iterator iter;
for( iter = PrimariesConsideredInAdjointSim.begin(); iter != PrimariesConsideredInAdjointSim.end(); ++iter ) {
if(iter->second) {
G4String fwd_particle_name = iter->first;
if ( fwd_particle_name != "ion") {
G4String adj_particle_name = G4String("adj_") + fwd_particle_name;
ListOfPrimaryFwdParticles.push_back(theParticleTable->FindParticle(fwd_particle_name));
ListOfPrimaryAdjParticles.push_back(theParticleTable->FindParticle(adj_particle_name));
}
else {
if (fwd_ion ){
ion_name=fwd_ion->GetParticleName();
G4String adj_ion_name=G4String("adj_") +ion_name;
ListOfPrimaryFwdParticles.push_back(fwd_ion);
ListOfPrimaryAdjParticles.push_back(adj_ion);
}
else {
ListOfPrimaryFwdParticles.push_back(0);
ListOfPrimaryAdjParticles.push_back(0);
}
}
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
void G4AdjointPrimaryGeneratorAction::SetPrimaryIon(G4ParticleDefinition* adjointIon, G4ParticleDefinition* fwdIon)
{
fwd_ion = fwdIon;
adj_ion = adjointIon;
UpdateListOfPrimaryParticles();
}
+491
View File
@@ -0,0 +1,491 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4AdjointSimManager.cc,v 1.2 2009/11/18 18:02:06 gcosmo Exp $
// GEANT4 tag $Name: geant4-09-03 $
//
/////////////////////////////////////////////////////////////////////////////
// Class Name: G4AdjointCrossSurfChecker
// Author: L. Desorgher
// Organisation: SpaceIT GmbH
// Contract: ESA contract 21435/08/NL/AT
// Customer: ESA/ESTEC
/////////////////////////////////////////////////////////////////////////////
#include "G4AdjointSimManager.hh"
#include "G4Run.hh"
#include "G4RunManager.hh"
#include "G4UserEventAction.hh"
#include "G4VUserPrimaryGeneratorAction.hh"
#include "G4UserTrackingAction.hh"
#include "G4UserSteppingAction.hh"
#include "G4UserStackingAction.hh"
#include "G4UserRunAction.hh"
#include "G4AdjointPrimaryGeneratorAction.hh"
#include "G4AdjointSteppingAction.hh"
#include "G4AdjointStackingAction.hh"
#include "G4AdjointSimMessenger.hh"
#include "G4AdjointCrossSurfChecker.hh"
#include "G4ParticleTable.hh"
#include "G4PhysicsLogVector.hh"
////////////////////////////////////////////////////////////////////////////////
//
G4AdjointSimManager* G4AdjointSimManager::instance = 0;
////////////////////////////////////////////////////////////////////////////////
//
G4AdjointSimManager::G4AdjointSimManager()
{
//Create adjoint actions;
//----------------------
theAdjointRunAction = 0;
theAdjointPrimaryGeneratorAction = new G4AdjointPrimaryGeneratorAction();
theAdjointSteppingAction = new G4AdjointSteppingAction();
theAdjointEventAction = 0;
theAdjointTrackingAction = 0;
theAdjointStackingAction = new G4AdjointStackingAction();
//Create messenger
//----------------
theMessenger = new G4AdjointSimMessenger(this);
user_action_already_defined=false;
use_user_StackingAction = false;
fUserTrackingAction= 0;
fUserEventAction= 0;
fUserSteppingAction= 0;
fUserPrimaryGeneratorAction= 0;
fUserRunAction= 0;
fUserStackingAction= 0;
adjoint_sim_mode = false;
normalisation_mode=3;
nb_nuc=1.;
welcome_message =true;
/*electron_last_weight_vector = new G4PhysicsLogVector(1.e-20,1.e20,400);
proton_last_weight_vector = new G4PhysicsLogVector(1.e-20,1.e20,400);
gamma_last_weight_vector = new G4PhysicsLogVector(1.e-20,1.e20,400);*/
}
////////////////////////////////////////////////////////////////////////////////
//
G4AdjointSimManager::~G4AdjointSimManager()
{
if (theAdjointRunAction) delete theAdjointRunAction;
if (theAdjointPrimaryGeneratorAction) delete theAdjointPrimaryGeneratorAction;
if (theAdjointSteppingAction) delete theAdjointSteppingAction;
if (theAdjointEventAction) delete theAdjointEventAction;
if (theAdjointTrackingAction) delete theAdjointTrackingAction;
if (theAdjointStackingAction) delete theAdjointStackingAction;
if (theMessenger) delete theMessenger;
}
////////////////////////////////////////////////////////////////////////////////
//
G4AdjointSimManager* G4AdjointSimManager::GetInstance()
{
if (instance == 0) instance = new G4AdjointSimManager;
return instance;
}
////////////////////////////////////////////////////////////////////////////////
//
void G4AdjointSimManager::RunAdjointSimulation(G4int nb_evt)
{
if (welcome_message) {
G4cout<<"****************************************************************"<<std::endl;
G4cout<<"*** Geant4 Reverse/Adjoint Monte Carlo mode ***"<<std::endl;
G4cout<<"*** Author: L.Desorgher ***"<<std::endl;
G4cout<<"*** Company: SpaceIT GmbH, Bern, Switzerland ***"<<std::endl;
G4cout<<"*** Sponsored by: ESA/ESTEC contract contract 21435/08/NL/AT ***"<<std::endl;
G4cout<<"****************************************************************"<<std::endl;
welcome_message=false;
}
//Replace the user defined actions by the adjoint actions
//---------------------------------------------------------
SetAdjointPrimaryRunAndStackingActions();
SetRestOfAdjointActions();
//Update the list of primaries
//-----------------------------
theAdjointPrimaryGeneratorAction->UpdateListOfPrimaryParticles();
adjoint_sim_mode=true;
ID_of_last_particle_that_reach_the_ext_source=0;
//Make the run
//------------
nb_evt_of_last_run =nb_evt;
G4RunManager::GetRunManager()->BeamOn(theAdjointPrimaryGeneratorAction->GetNbOfAdjointPrimaryTypes()*2*nb_evt);
//Restore the user defined actions
//--------------------------------
ResetRestOfUserActions();
ResetUserPrimaryRunAndStackingActions();
adjoint_sim_mode=false;
/*
//Register the weight vector
//--------------------------
std::ofstream FileOutputElectronWeight("ElectronWeight.txt", std::ios::out);
FileOutputElectronWeight<<std::setiosflags(std::ios::scientific);
FileOutputElectronWeight<<std::setprecision(6);
G4bool aBool = electron_last_weight_vector->Store(FileOutputElectronWeight, true);
FileOutputElectronWeight.close();
std::ofstream FileOutputProtonWeight("ProtonWeight.txt", std::ios::out);
FileOutputProtonWeight<<std::setiosflags(std::ios::scientific);
FileOutputProtonWeight<<std::setprecision(6);
aBool = proton_last_weight_vector->Store(FileOutputProtonWeight, true);
FileOutputProtonWeight.close();
std::ofstream FileOutputGammaWeight("GammaWeight.txt", std::ios::out);
FileOutputGammaWeight<<std::setiosflags(std::ios::scientific);
FileOutputGammaWeight<<std::setprecision(6);
aBool = gamma_last_weight_vector->Store(FileOutputGammaWeight, true);
FileOutputGammaWeight.close();
*/
}
////////////////////////////////////////////////////////////////////////////////
//
void G4AdjointSimManager::SetRestOfAdjointActions()
{
G4RunManager* theRunManager = G4RunManager::GetRunManager();
if (!user_action_already_defined) DefineUserActions();
//Replace the user action by the adjoint actions
//-------------------------------------------------
theRunManager->SetUserAction(theAdjointEventAction);
theRunManager->SetUserAction(theAdjointSteppingAction);
theRunManager->SetUserAction(theAdjointTrackingAction);
}
////////////////////////////////////////////////////////////////////////////////
//
void G4AdjointSimManager::SetAdjointPrimaryRunAndStackingActions()
{
G4RunManager* theRunManager = G4RunManager::GetRunManager();
if (!user_action_already_defined) DefineUserActions();
//Replace the user action by the adjoint actions
//-------------------------------------------------
theRunManager->SetUserAction(theAdjointRunAction);
theRunManager->SetUserAction(theAdjointPrimaryGeneratorAction);
theRunManager->SetUserAction(theAdjointStackingAction);
if (use_user_StackingAction) theAdjointStackingAction->SetUserFwdStackingAction(fUserStackingAction);
else theAdjointStackingAction->SetUserFwdStackingAction(0);
}
////////////////////////////////////////////////////////////////////////////////
//
void G4AdjointSimManager::ResetRestOfUserActions()
{
G4RunManager* theRunManager = G4RunManager::GetRunManager();
//Restore the user defined actions
//-------------------------------
theRunManager->SetUserAction(fUserEventAction);
theRunManager->SetUserAction(fUserSteppingAction);
theRunManager->SetUserAction(fUserTrackingAction);
}
////////////////////////////////////////////////////////////////////////////////
//
void G4AdjointSimManager::ResetUserPrimaryRunAndStackingActions()
{
G4RunManager* theRunManager = G4RunManager::GetRunManager();
//Restore the user defined actions
//-------------------------------
theRunManager->SetUserAction(fUserRunAction);
theRunManager->SetUserAction(fUserPrimaryGeneratorAction);
theRunManager->SetUserAction(fUserStackingAction);
}
////////////////////////////////////////////////////////////////////////////////
//
void G4AdjointSimManager::DefineUserActions()
{
G4RunManager* theRunManager = G4RunManager::GetRunManager();
fUserTrackingAction= const_cast<G4UserTrackingAction* >( theRunManager->GetUserTrackingAction() );
fUserEventAction= const_cast<G4UserEventAction* >( theRunManager->GetUserEventAction() );
fUserSteppingAction= const_cast<G4UserSteppingAction* >( theRunManager->GetUserSteppingAction() );
fUserPrimaryGeneratorAction= const_cast<G4VUserPrimaryGeneratorAction* >( theRunManager->GetUserPrimaryGeneratorAction() );
fUserRunAction= const_cast<G4UserRunAction*>( theRunManager->GetUserRunAction() );
fUserStackingAction= const_cast<G4UserStackingAction* >( theRunManager->GetUserStackingAction() );
user_action_already_defined=true;
}
///////////////////////////////////////////////////////////////////////////////
//
void G4AdjointSimManager::SetAdjointTrackingMode(G4bool aBool)
{
adjoint_tracking_mode = aBool;
if (adjoint_tracking_mode) {
SetRestOfAdjointActions();
theAdjointStackingAction->SetAdjointMode(true);
theAdjointStackingAction->SetKillTracks(false);
}
else {
ResetRestOfUserActions();
theAdjointStackingAction->SetAdjointMode(false);
if (GetDidAdjParticleReachTheExtSource()){
theAdjointStackingAction->SetKillTracks(false);
RegisterAtEndOfAdjointTrack();
}
else theAdjointStackingAction->SetKillTracks(true);
}
}
///////////////////////////////////////////////////////////////////////////////
//
G4bool G4AdjointSimManager::GetDidAdjParticleReachTheExtSource()
{
return theAdjointSteppingAction->GetDidAdjParticleReachTheExtSource();
}
///////////////////////////////////////////////////////////////////////////////
//
std::vector<G4ParticleDefinition*> G4AdjointSimManager::GetListOfPrimaryFwdParticles()
{
return theAdjointPrimaryGeneratorAction->GetListOfPrimaryFwdParticles();
}
///////////////////////////////////////////////////////////////////////////////
//
void G4AdjointSimManager::RegisterAtEndOfAdjointTrack()
{
last_pos = theAdjointSteppingAction->GetLastPosition();
last_direction = theAdjointSteppingAction->GetLastMomentum();
last_direction /=last_direction.mag();
last_cos_th = last_direction.z();
G4ParticleDefinition* aPartDef= theAdjointSteppingAction->GetLastPartDef();
last_fwd_part_name= aPartDef->GetParticleName();
last_fwd_part_name.remove(0,4);
last_fwd_part_PDGEncoding=G4ParticleTable::GetParticleTable()->FindParticle(last_fwd_part_name)->GetPDGEncoding();
std::vector<G4ParticleDefinition*> aList = theAdjointPrimaryGeneratorAction->GetListOfPrimaryFwdParticles();
last_fwd_part_index=-1;
size_t i=0;
while(i<aList.size() && last_fwd_part_index<0) {
if (aList[i]->GetParticleName() == last_fwd_part_name) last_fwd_part_index=i;
i++;
}
last_ekin = theAdjointSteppingAction->GetLastEkin();
last_ekin_nuc = last_ekin;
if (aPartDef->GetParticleType() == "adjoint_nucleus") {
nb_nuc=double(aPartDef->GetBaryonNumber());
last_ekin_nuc /=nb_nuc;
}
last_weight = theAdjointSteppingAction->GetLastWeight();
/* G4PhysicsLogVector* theWeightVector=0;
if (last_fwd_part_name =="e-") theWeightVector=electron_last_weight_vector;
else if (last_fwd_part_name =="gamma") theWeightVector=gamma_last_weight_vector;
else if (last_fwd_part_name =="proton") theWeightVector=proton_last_weight_vector;
if (theWeightVector){
size_t ind = size_t(std::log10(last_weight/theAdjointPrimaryWeight)*10. + 200);
G4double low_val =theWeightVector->GetLowEdgeEnergy(ind);
G4bool aBool = true;
G4double bin_weight = theWeightVector->GetValue(low_val, aBool)+1.;
theWeightVector->PutValue(ind, bin_weight);
}
*/
/*if ((last_weight/theAdjointPrimaryWeight)>1.) last_weight*=1000. ;
else if ( (last_weight/theAdjointPrimaryWeight)>0.1) last_weight*=100. ;
else if ( (last_weight/theAdjointPrimaryWeight)>0.01) last_weight*=10. ;*/
//G4cout <<"Last Weight "<<last_weight<<'\t'<<theAdjointPrimaryWeight<<'\t'<<last_weight/theAdjointPrimaryWeight<<std::endl;
/*if (last_weight/theAdjointPrimaryWeight >10.) {
G4cout<<"Warning a weight increase by a factor : "<<last_weight/theAdjointPrimaryWeight<<std::endl;
}
*/
ID_of_last_particle_that_reach_the_ext_source++;
}
///////////////////////////////////////////////////////////////////////////////
//
G4bool G4AdjointSimManager::DefineSphericalExtSource(G4double radius, G4ThreeVector pos)
{
G4double area;
return G4AdjointCrossSurfChecker::GetInstance()->AddaSphericalSurface("ExternalSource", radius, pos, area);
}
///////////////////////////////////////////////////////////////////////////////
//
G4bool G4AdjointSimManager::DefineSphericalExtSourceWithCentreAtTheCentreOfAVolume(G4double radius, const G4String& volume_name)
{
G4double area;
G4ThreeVector center;
return G4AdjointCrossSurfChecker::GetInstance()->AddaSphericalSurfaceWithCenterAtTheCenterOfAVolume( "ExternalSource", radius, volume_name,center, area);
}
///////////////////////////////////////////////////////////////////////////////
//
G4bool G4AdjointSimManager::DefineExtSourceOnTheExtSurfaceOfAVolume(const G4String& volume_name)
{
G4double area;
return G4AdjointCrossSurfChecker::GetInstance()->AddanExtSurfaceOfAvolume( "ExternalSource", volume_name,area);
}
///////////////////////////////////////////////////////////////////////////////
//
void G4AdjointSimManager::SetExtSourceEmax(G4double Emax)
{
theAdjointSteppingAction->SetExtSourceEMax(Emax);
}
///////////////////////////////////////////////////////////////////////////////
//
G4bool G4AdjointSimManager::DefineSphericalAdjointSource(G4double radius, G4ThreeVector pos)
{
G4double area;
G4bool aBool = G4AdjointCrossSurfChecker::GetInstance()->AddaSphericalSurface("AdjointSource", radius, pos, area);
theAdjointPrimaryGeneratorAction->SetSphericalAdjointPrimarySource(radius, pos);
area_of_the_adjoint_source=area;
return aBool;
}
///////////////////////////////////////////////////////////////////////////////
//
G4bool G4AdjointSimManager::DefineSphericalAdjointSourceWithCentreAtTheCentreOfAVolume(G4double radius, const G4String& volume_name)
{
G4double area;
G4ThreeVector center;
G4bool aBool = G4AdjointCrossSurfChecker::GetInstance()->AddaSphericalSurfaceWithCenterAtTheCenterOfAVolume( "AdjointSource", radius, volume_name,center, area);
theAdjointPrimaryGeneratorAction->SetSphericalAdjointPrimarySource(radius, center);
area_of_the_adjoint_source=area;
return aBool;
}
///////////////////////////////////////////////////////////////////////////////
//
G4bool G4AdjointSimManager::DefineAdjointSourceOnTheExtSurfaceOfAVolume(const G4String& volume_name)
{
G4double area;
G4bool aBool = G4AdjointCrossSurfChecker::GetInstance()->AddanExtSurfaceOfAvolume( "AdjointSource", volume_name,area);
area_of_the_adjoint_source=area;
if (aBool) {
theAdjointPrimaryGeneratorAction->SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(volume_name);
}
return aBool;
}
///////////////////////////////////////////////////////////////////////////////
//
void G4AdjointSimManager::SetAdjointSourceEmin(G4double Emin)
{
theAdjointPrimaryGeneratorAction->SetEmin(Emin);
}
///////////////////////////////////////////////////////////////////////////////
//
void G4AdjointSimManager::SetAdjointSourceEmax(G4double Emax)
{
theAdjointPrimaryGeneratorAction->SetEmax(Emax);
}
///////////////////////////////////////////////////////////////////////////////
//
void G4AdjointSimManager::ConsiderParticleAsPrimary(const G4String& particle_name)
{
theAdjointPrimaryGeneratorAction->ConsiderParticleAsPrimary(particle_name);
}
///////////////////////////////////////////////////////////////////////////////
//
void G4AdjointSimManager::NeglectParticleAsPrimary(const G4String& particle_name)
{
theAdjointPrimaryGeneratorAction->NeglectParticleAsPrimary(particle_name);
}
///////////////////////////////////////////////////////////////////////////////
//
/*void G4AdjointSimManager::SetPrimaryIon(G4int Z, G4int A)
{
theAdjointPrimaryGeneratorAction->SetPrimaryIon(Z, A);
}
*/
///////////////////////////////////////////////////////////////////////////////
//
void G4AdjointSimManager::SetPrimaryIon(G4ParticleDefinition* adjointIon, G4ParticleDefinition* fwdIon)
{
theAdjointPrimaryGeneratorAction->SetPrimaryIon(adjointIon, fwdIon);
}
///////////////////////////////////////////////////////////////////////////////
//
const G4String& G4AdjointSimManager::GetPrimaryIonName()
{
return theAdjointPrimaryGeneratorAction->GetPrimaryIonName();
}
///////////////////////////////////////////////////////////////////////////////
//
void G4AdjointSimManager::RegisterAdjointPrimaryWeight(G4double aWeight)
{
theAdjointPrimaryWeight = aWeight;
theAdjointSteppingAction->SetPrimWeight(aWeight);
}
///////////////////////////////////////////////////////////////////////////////
//
void G4AdjointSimManager::SetAdjointEventAction(G4UserEventAction* anAction)
{
theAdjointEventAction = anAction;
}
///////////////////////////////////////////////////////////////////////////////
//
void G4AdjointSimManager::SetAdjointSteppingAction(G4UserSteppingAction* anAction)
{
theAdjointSteppingAction->SetUserAdjointSteppingAction(anAction);
}
///////////////////////////////////////////////////////////////////////////////
//
void G4AdjointSimManager::SetAdjointStackingAction(G4UserStackingAction* anAction)
{
theAdjointStackingAction->SetUserAdjointStackingAction(anAction);
}
///////////////////////////////////////////////////////////////////////////////
//
void G4AdjointSimManager::SetAdjointTrackingAction(G4UserTrackingAction* anAction)
{
theAdjointTrackingAction=anAction;
}
///////////////////////////////////////////////////////////////////////////////
//
void G4AdjointSimManager::SetAdjointRunAction(G4UserRunAction* anAction)
{
theAdjointRunAction=anAction;
}
///////////////////////////////////////////////////////////////////////////////
//
+250
View File
@@ -0,0 +1,250 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4AdjointSimMessenger.cc,v 1.2 2009/11/18 18:02:06 gcosmo Exp $
// GEANT4 tag $Name: geant4-09-03 $
//
/////////////////////////////////////////////////////////////////////////////
// Class Name: G4AdjointCrossSurfChecker
// Author: L. Desorgher
// Organisation: SpaceIT GmbH
// Contract: ESA contract 21435/08/NL/AT
// Customer: ESA/ESTEC
/////////////////////////////////////////////////////////////////////////////
#include "G4AdjointSimMessenger.hh"
#include "G4AdjointSimManager.hh"
#include "G4UIdirectory.hh"
#include "G4UIcmdWithABool.hh"
#include "G4UIcmdWithAnInteger.hh"
#include "G4UIcmdWithADoubleAndUnit.hh"
#include "G4UIcmdWithADouble.hh"
#include "G4UIcmdWithoutParameter.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UnitsTable.hh"
#include "G4UIcmdWith3VectorAndUnit.hh"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
G4AdjointSimMessenger::G4AdjointSimMessenger(G4AdjointSimManager* pAdjointRunManager)
: theAdjointRunManager(pAdjointRunManager)
{
AdjointSimDir = new G4UIdirectory("/adjoint/");
AdjointSimDir->SetGuidance("Control of the adjoint or reverse monte carlo simulation");
//Start and adjoint Run
//---------------------
beamOnCmd = new G4UIcommand("/adjoint/start_run",this);
beamOnCmd->SetGuidance("Start an adjoint Run.");
beamOnCmd->SetGuidance("Default number of events to be processed is 1.");
beamOnCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
G4UIparameter* p1 = new G4UIparameter("numberOfEvent",'i',true);
p1->SetDefaultValue(1);
p1->SetParameterRange("numberOfEvent >= 0");
beamOnCmd->SetParameter(p1);
//Commands to define parameters relative to the external source
//------------------------------------------------------------
G4UIparameter* pos_x_par = new G4UIparameter("X",'d',true);
G4UIparameter* pos_y_par = new G4UIparameter("Y",'d',true);
G4UIparameter* pos_z_par = new G4UIparameter("Z",'d',true);
G4UIparameter* radius_par = new G4UIparameter("R",'d',true);
radius_par->SetParameterRange("R >= 0");
G4UIparameter* unit_par = new G4UIparameter("unit",'s',true);
DefineSpherExtSourceCmd = new G4UIcommand("/adjoint/DefineSphericalExtSource",this);
DefineSpherExtSourceCmd->SetGuidance("Define a spherical external source.");
DefineSpherExtSourceCmd->SetParameter(pos_x_par);
DefineSpherExtSourceCmd->SetParameter(pos_y_par);
DefineSpherExtSourceCmd->SetParameter(pos_z_par);
DefineSpherExtSourceCmd->SetParameter(radius_par);
DefineSpherExtSourceCmd->SetParameter(unit_par);
G4UIparameter* phys_vol_name_par = new G4UIparameter("phys_vol_name",'s',true);
DefineSpherExtSourceCenteredOnAVolumeCmd= new G4UIcommand("/adjoint/DefineSphericalExtSourceCenteredOnAVolume",this);
DefineSpherExtSourceCenteredOnAVolumeCmd->SetGuidance("Define a spherical external source with the center located at the center of a physical volume");
DefineSpherExtSourceCenteredOnAVolumeCmd->SetParameter(phys_vol_name_par);
DefineSpherExtSourceCenteredOnAVolumeCmd->SetParameter(radius_par);
DefineSpherExtSourceCenteredOnAVolumeCmd->SetParameter(unit_par);
DefineExtSourceOnAVolumeExtSurfaceCmd= new G4UIcmdWithAString("/adjoint/DefineExtSourceOnExtSurfaceOfAVolume",this);
DefineExtSourceOnAVolumeExtSurfaceCmd->SetGuidance("Set the external source on the external surface of a physical volume");
DefineExtSourceOnAVolumeExtSurfaceCmd->SetParameterName("phys_vol_name",false);
setExtSourceEMaxCmd = new G4UIcmdWithADoubleAndUnit("/adjoint/SetExtSourceEmax",this);
setExtSourceEMaxCmd->SetGuidance("Set the maximum energy of the external source");
setExtSourceEMaxCmd->SetParameterName("Emax",false);
setExtSourceEMaxCmd->SetUnitCategory("Energy");
setExtSourceEMaxCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
//Commands to define the adjoint source
//------------------------------------------------------------
DefineSpherAdjSourceCmd = new G4UIcommand("/adjoint/DefineSphericalAdjSource",this);
DefineSpherAdjSourceCmd->SetGuidance("Define a spherical adjoint source.");
DefineSpherAdjSourceCmd->SetParameter(pos_x_par);
DefineSpherAdjSourceCmd->SetParameter(pos_y_par);
DefineSpherAdjSourceCmd->SetParameter(pos_z_par);
DefineSpherAdjSourceCmd->SetParameter(radius_par);
DefineSpherAdjSourceCmd->SetParameter(unit_par);
DefineSpherAdjSourceCenteredOnAVolumeCmd= new G4UIcommand("/adjoint/DefineSphericalAdjSourceCenteredOnAVolume",this);
DefineSpherAdjSourceCenteredOnAVolumeCmd->SetGuidance("Define a spherical adjoint source with the center located at the center of a physical volume");
DefineSpherAdjSourceCenteredOnAVolumeCmd->SetParameter(phys_vol_name_par);
DefineSpherAdjSourceCenteredOnAVolumeCmd->SetParameter(radius_par);
DefineSpherAdjSourceCenteredOnAVolumeCmd->SetParameter(unit_par);
DefineAdjSourceOnAVolumeExtSurfaceCmd= new G4UIcmdWithAString("/adjoint/DefineAdjSourceOnExtSurfaceOfAVolume",this);
DefineAdjSourceOnAVolumeExtSurfaceCmd->SetGuidance("Set the adjoint source on the external surface of physical volume");
DefineAdjSourceOnAVolumeExtSurfaceCmd->SetParameterName("phys_vol_name",false);
setAdjSourceEminCmd = new G4UIcmdWithADoubleAndUnit("/adjoint/SetAdjSourceEmin",this);
setAdjSourceEminCmd->SetGuidance("Set the minimum energy of the adjoint source");
setAdjSourceEminCmd->SetParameterName("Emin",false);
setAdjSourceEminCmd->SetUnitCategory("Energy");
setAdjSourceEminCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
setAdjSourceEmaxCmd = new G4UIcmdWithADoubleAndUnit("/adjoint/SetAdjSourceEmax",this);
setAdjSourceEmaxCmd->SetGuidance("Set the maximum energy of the adjoint source");
setAdjSourceEmaxCmd->SetParameterName("Emax",false);
setAdjSourceEmaxCmd->SetUnitCategory("Energy");
setAdjSourceEmaxCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
ConsiderParticleAsPrimaryCmd = new G4UIcmdWithAString("/adjoint/ConsiderAsPrimary",this);
ConsiderParticleAsPrimaryCmd->SetGuidance("Set the selected particle as primary");
ConsiderParticleAsPrimaryCmd->SetParameterName("particle",false);
ConsiderParticleAsPrimaryCmd->SetCandidates("e- gamma proton ion");
NeglectParticleAsPrimaryCmd= new G4UIcmdWithAString("/adjoint/NeglectAsPrimary",this);
NeglectParticleAsPrimaryCmd->SetGuidance("Remove the selected particle from the lits of primaries");
NeglectParticleAsPrimaryCmd->SetParameterName("particle",false);
NeglectParticleAsPrimaryCmd->SetCandidates("e- gamma proton ion");
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
G4AdjointSimMessenger::~G4AdjointSimMessenger()
{
delete beamOnCmd;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
void G4AdjointSimMessenger::SetNewValue(G4UIcommand* command,G4String newValue)
{
if( command==beamOnCmd )
{
G4int nev;
const char* nv = (const char*)newValue;
std::istringstream is(nv);
is >> nev ;
theAdjointRunManager->RunAdjointSimulation(nev);
}
else if ( command==DefineSpherExtSourceCmd){
G4double x,y,z,r;
G4String unit;
const char* nv = (const char*)newValue;
std::istringstream is(nv);
is >> x>>y>>z>>r>>unit;
x*=G4UnitDefinition::GetValueOf(unit);
y*=G4UnitDefinition::GetValueOf(unit);
z*=G4UnitDefinition::GetValueOf(unit);
r*=G4UnitDefinition::GetValueOf(unit);
theAdjointRunManager->DefineSphericalExtSource(r,G4ThreeVector(x,y,z));
}
else if ( command==DefineSpherExtSourceCenteredOnAVolumeCmd){
G4double r;
G4String vol_name, unit;
const char* nv = (const char*)newValue;
std::istringstream is(nv);
is >>vol_name>>r>>unit;
r*=G4UnitDefinition::GetValueOf(unit);
theAdjointRunManager->DefineSphericalExtSourceWithCentreAtTheCentreOfAVolume(r,vol_name);
}
else if ( command==DefineExtSourceOnAVolumeExtSurfaceCmd){
theAdjointRunManager->DefineExtSourceOnTheExtSurfaceOfAVolume(newValue);
}
else if ( command== setExtSourceEMaxCmd){
theAdjointRunManager->SetExtSourceEmax(setExtSourceEMaxCmd->GetNewDoubleValue(newValue));
}
else if ( command==DefineSpherAdjSourceCmd){
G4double x,y,z,r;
G4String unit;
const char* nv = (const char*)newValue;
std::istringstream is(nv);
is >> x>>y>>z>>r>>unit;
x*=G4UnitDefinition::GetValueOf(unit);
y*=G4UnitDefinition::GetValueOf(unit);
z*=G4UnitDefinition::GetValueOf(unit);
r*=G4UnitDefinition::GetValueOf(unit);
theAdjointRunManager->DefineSphericalAdjointSource(r,G4ThreeVector(x,y,z));
}
else if ( command==DefineSpherAdjSourceCenteredOnAVolumeCmd){
G4double r;
G4String vol_name, unit;
const char* nv = (const char*)newValue;
std::istringstream is(nv);
is >>vol_name>>r>>unit;
r*=G4UnitDefinition::GetValueOf(unit);
theAdjointRunManager->DefineSphericalAdjointSourceWithCentreAtTheCentreOfAVolume(r,vol_name);
}
else if ( command==DefineAdjSourceOnAVolumeExtSurfaceCmd){
theAdjointRunManager->DefineAdjointSourceOnTheExtSurfaceOfAVolume(newValue);
}
else if ( command== setAdjSourceEminCmd){
theAdjointRunManager->SetAdjointSourceEmin(setAdjSourceEminCmd->GetNewDoubleValue(newValue));
}
else if ( command== setAdjSourceEmaxCmd){
theAdjointRunManager->SetAdjointSourceEmax(setAdjSourceEmaxCmd->GetNewDoubleValue(newValue));
}
else if ( command==ConsiderParticleAsPrimaryCmd){
theAdjointRunManager->ConsiderParticleAsPrimary(newValue);
}
else if ( command==NeglectParticleAsPrimaryCmd){
theAdjointRunManager->NeglectParticleAsPrimary(newValue);
}
}
+24 -6
View File
@@ -24,8 +24,8 @@
// ********************************************************************
//
//
// $Id: G4RunManagerKernel.cc,v 1.43 2008/07/10 09:27:19 gcosmo Exp $
// GEANT4 tag $Name: geant4-09-02 $
// $Id: G4RunManagerKernel.cc,v 1.47 2009/11/13 23:13:40 asaim Exp $
// GEANT4 tag $Name: geant4-09-03 $
//
//
@@ -82,6 +82,21 @@ G4RunManagerKernel::G4RunManagerKernel()
}
fRunManagerKernel = this;
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
if(particleTable->entries()>0)
{
// No particle should be registered beforehand
G4cerr<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<G4endl;
G4cerr<<" G4RunManagerKernel fatal exception"<<G4endl;
G4cerr<<" -- Following particles have already been registered"<<G4endl;
G4cerr<<" before G4RunManagerKernel is instantiated."<<G4endl;
for(int i=0;i<particleTable->entries();i++)
{ G4cerr<<" "<<particleTable->GetParticle(i)->GetParticleName()<<G4endl; }
G4cerr<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<G4endl;
G4Exception("G4RunManagerKernel::G4RunManagerKernel()","StaticParticleDefinition",
FatalException,"Particles have already been instantiated before G4RunManagerKernel.");
}
// construction of Geant4 kernel classes
eventManager = new G4EventManager();
defaultRegion = new G4Region("DefaultRegionForTheWorld"); // deleted by store
@@ -263,6 +278,8 @@ void G4RunManagerKernel::InitializePhysics()
if(numberOfParallelWorld>0) physicsList->UseCoupledTransportation();
physicsList->Construct();
if(verboseLevel>1) G4cout << "physicsList->CheckParticleList() start." << G4endl;
physicsList->CheckParticleList();
if(verboseLevel>1) G4cout << "physicsList->setCut() start." << G4endl;
physicsList->SetCuts();
CheckRegions();
@@ -443,7 +460,7 @@ void G4RunManagerKernel::DumpRegion(G4Region* region) const
size_t nRootLV = region->GetNumberOfRootVolumes();
std::vector<G4LogicalVolume*>::iterator lvItr = region->GetRootLogicalVolumeIterator();
for(size_t j=0;j<nRootLV;j++)
{ G4cout << (*lvItr)->GetName() << " "; }
{ G4cout << (*lvItr)->GetName() << " "; lvItr++; }
G4cout << G4endl;
G4cout << " Pointers : G4VUserRegionInformation[" << region->GetUserInformation()
@@ -475,9 +492,10 @@ void G4RunManagerKernel::DumpRegion(G4Region* region) const
G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts());
}
G4cout << " Production cuts : "
<< " gamma " << G4BestUnit(cuts->GetProductionCut("gamma"),"Length")
<< " e- " << G4BestUnit(cuts->GetProductionCut("e-"),"Length")
<< " e+ " << G4BestUnit(cuts->GetProductionCut("e+"),"Length")
<< " gamma " << G4BestUnit(cuts->GetProductionCut("gamma"),"Length")
<< " e- " << G4BestUnit(cuts->GetProductionCut("e-"),"Length")
<< " e+ " << G4BestUnit(cuts->GetProductionCut("e+"),"Length")
<< " proton " << G4BestUnit(cuts->GetProductionCut("proton"),"Length")
<< G4endl;
}
}
+43 -19
View File
@@ -24,8 +24,8 @@
// ********************************************************************
//
//
// $Id: G4UserPhysicsListMessenger.cc,v 1.28 2007/05/30 10:34:54 gcosmo Exp $
// GEANT4 tag $Name: geant4-09-02 $
// $Id: G4UserPhysicsListMessenger.cc,v 1.30 2009/10/20 07:07:51 kurasige Exp $
// GEANT4 tag $Name: geant4-09-03 $
//
//
//---------------------------------------------------------------
@@ -67,6 +67,15 @@ G4UserPhysicsListMessenger::G4UserPhysicsListMessenger(G4VUserPhysicsList* pPart
verboseCmd->SetParameterName("level",true);
verboseCmd->SetDefaultValue(0);
verboseCmd->SetRange("level >=0 && level <=3");
// /run/setCut command
setCutCmd = new G4UIcmdWithADoubleAndUnit("/run/setCut",this);
setCutCmd->SetGuidance("Set default cut value ");
setCutCmd->SetParameterName("cut",false);
setCutCmd->SetDefaultValue(1.0);
setCutCmd->SetRange("cut >0.0");
setCutCmd->SetDefaultUnit("mm");
setCutCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
// /run/particle/setCut command
setPCutCmd = new G4UIcmdWithADoubleAndUnit("/run/particle/setCut",this);
@@ -78,15 +87,22 @@ G4UserPhysicsListMessenger::G4UserPhysicsListMessenger(G4VUserPhysicsList* pPart
setPCutCmd->SetRange("cut >0.0");
setPCutCmd->SetDefaultUnit("mm");
setPCutCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
// /run/setCut command
setCutCmd = new G4UIcmdWithADoubleAndUnit("/run/setCut",this);
setCutCmd->SetGuidance("Set default cut value ");
setCutCmd->SetParameterName("cut",false);
setCutCmd->SetDefaultValue(1.0);
setCutCmd->SetRange("cut >0.0");
setCutCmd->SetDefaultUnit("mm");
setCutCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
// /run/setCutForAGivenParticle command
setCutForAGivenParticleCmd = new G4UIcommand("/run/setCutForAGivenParticle",this) ;
setCutForAGivenParticleCmd->SetGuidance("Set a cut value to a specific particle") ;
setCutForAGivenParticleCmd->SetGuidance("Usage: /run/setCutForAGivenParticle gamma 1. mm") ;
param = new G4UIparameter("particleName",'s',false) ;
param->SetParameterCandidates("e- e+ gamma proton");
setCutForAGivenParticleCmd->SetParameter(param) ;
param = new G4UIparameter("cut",'d',false) ;
param->SetDefaultValue("1.") ;
param->SetParameterRange("cut>0.0") ;
setCutForAGivenParticleCmd->SetParameter(param) ;
param = new G4UIparameter("unit",'s',false) ;
param->SetDefaultValue("mm") ;
setCutForAGivenParticleCmd->SetParameter(param) ;
setCutForAGivenParticleCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
// /run/setCutForRegion command
setCutRCmd = new G4UIcommand("/run/setCutForRegion",this);
@@ -186,7 +202,8 @@ G4UserPhysicsListMessenger::~G4UserPhysicsListMessenger()
{
delete setPCutCmd;
delete setCutCmd;
delete setCutRCmd;
delete setCutRCmd;
delete setCutForAGivenParticleCmd;
delete verboseCmd;
delete dumpListCmd;
delete addProcManCmd;
@@ -201,17 +218,24 @@ G4UserPhysicsListMessenger::~G4UserPhysicsListMessenger()
void G4UserPhysicsListMessenger::SetNewValue(G4UIcommand * command,G4String newValue)
{
if( command==setCutCmd || command==setPCutCmd ){
if( command==setCutCmd ){
G4double newCut = setCutCmd->GetNewDoubleValue(newValue);
thePhysicsList->SetDefaultCutValue(newCut);
thePhysicsList->SetCutsWithDefault();
} else if( command==setPCutCmd ){
G4cout << "Please use /run/setCut command instead. This command will be removed" << G4endl;
G4double newCut = setCutCmd->GetNewDoubleValue(newValue);
thePhysicsList->SetDefaultCutValue(newCut);
thePhysicsList->SetCutsWithDefault();
} else if( command==setCutForAGivenParticleCmd ){
G4String particleName, unit ; G4double cut ;
std::istringstream str (newValue) ;
str >> particleName >> cut >> unit ;
thePhysicsList->SetCutValue(cut*G4UIcommand::ValueOf(unit), particleName) ;
} else if( command==setCutRCmd ){
//G4Tokenizer next( newValue );
//G4String rName = G4String(next());
//G4String cValue = G4String(next())+" "+G4String(next());
//G4double newCut = setCutCmd->GetNewDoubleValue(cValue);
//thePhysicsList->SetCutsForRegion(newCut,rName);
std::istringstream is(newValue);
char regName[50];
G4double cVal;
@@ -280,7 +304,7 @@ G4String G4UserPhysicsListMessenger::GetCurrentValue(G4UIcommand * command)
G4String candidates("none");
G4ParticleTable::G4PTblDicIterator *piter = (G4ParticleTable::GetParticleTable())->GetIterator();
if( command==setCutCmd || command==setPCutCmd ){
if( command==setCutCmd ) {
cv = setCutCmd->ConvertToString( thePhysicsList->GetDefaultCutValue(), "mm" );
} else if( command==verboseCmd ){
+149 -9
View File
@@ -24,8 +24,8 @@
// ********************************************************************
//
//
// $Id: G4VUserPhysicsList.cc,v 1.64 2008/05/09 13:00:42 kurasige Exp $
// GEANT4 tag $Name: geant4-09-02 $
// $Id: G4VUserPhysicsList.cc,v 1.71 2009/08/09 14:31:46 kurasige Exp $
// GEANT4 tag $Name: geant4-09-03 $
//
//
// ------------------------------------------------------------
@@ -67,13 +67,15 @@
////////////////////////////////////////////////////////
G4VUserPhysicsList::G4VUserPhysicsList()
:verboseLevel(1),
: fDisableCheckParticleList(false),
verboseLevel(1),
fRetrievePhysicsTable(false),
fStoredInAscii(true),
fIsCheckedForRetrievePhysicsTable(false),
fIsRestoredCutValues(false),
directoryPhysicsTable("."),
fDisplayThreshold(0),
fIsPhysicsTableBuilt(false),
useCoupledTransportation(false)
{
// default cut value (1.0mm)
@@ -153,10 +155,14 @@ void G4VUserPhysicsList::AddProcessManager(G4ParticleDefinition* newParticle,
} else {
// no process manager has been registered yet
newManager = new G4ProcessManager(newParticle);
G4Exception("G4VUserPhysicsList::AddProcessManager","Error in GenericIon",
RunMustBeAborted,"GenericIon has no ProcessMamanger");
}
} else {
// "GenericIon" does not exist
newManager = new G4ProcessManager(newParticle);
G4Exception("G4VUserPhysicsList::AddProcessManager","No GenericIon",
RunMustBeAborted,"GenericIon does not exist");
}
} else {
@@ -179,13 +185,118 @@ void G4VUserPhysicsList::AddProcessManager(G4ParticleDefinition* newParticle,
newManager->DumpInfo();
}
#endif
if (newParticle->GetParticleType() == "nucleus") {
if ( fIsPhysicsTableBuilt
&& (newParticle->GetParticleType() == "nucleus")) {
PreparePhysicsTable(newParticle);
BuildPhysicsTable(newParticle);
}
}
////////////////////////////////////////////////////////
void G4VUserPhysicsList::CheckParticleList()
{
// skip if fDisableCheckParticleList is set
if (fDisableCheckParticleList) return;
bool isElectron = false;
bool isPositron = false;
bool isGamma = false;
bool isProton = false;
bool isGenericIon = false;
bool isAnyIon = false;
bool isAnyChargedBaryon = false;
bool isEmProc = false;
// loop over all particles in G4ParticleTable
theParticleIterator->reset();
while( (*theParticleIterator)() ){
G4ParticleDefinition* particle = theParticleIterator->value();
G4String name = particle->GetParticleName();
// check if any EM process exists
if (!isEmProc) {
G4ProcessVector* list = particle->GetProcessManager()->GetProcessList();
for (int idx=0; idx<list->size(); idx++){
isEmProc = ((*list)[idx])->GetProcessType() == fElectromagnetic;
if (isEmProc) break;
}
}
if ( name == "e-") isElectron = true;
else if ( name == "e+") isPositron = true;
else if ( name == "gamma") isGamma = true;
else if ( name == "GenericIon") isGenericIon = true;
else if ( name == "proton") isProton = true;
else if ( particle->GetParticleType() == "nucleus") isAnyIon = true;
else if ( particle->GetParticleType() == "baryon") {
if ( particle->GetPDGCharge() != 0.0 ) isAnyChargedBaryon = true;
}
}
if (!isEmProc) return;
// RULE 1
// e+, e- and gamma should exist
// if one of them exist
bool isEmBasic = isElectron || isPositron || isGamma;
bool isMissingEmBasic = !isElectron || !isPositron || !isGamma;
if (isEmBasic && isMissingEmBasic) {
G4String missingName="";
if (!isElectron) missingName += "e- ";
if (!isPositron) missingName += "e+ ";
if (!isGamma) missingName += "gamma ";
#ifdef G4VERBOSE
if (verboseLevel >0){
G4cout << "G4VUserPhysicsList::CheckParticleList: ";
G4cout << missingName << " do not exist " << G4endl;
G4cout << " These particle are necessary for basic EM processes" << G4endl;
}
#endif
missingName += " should be created ";
G4Exception("G4VUserPhysicsList::CheckParticleList","Missing EM basic particle",
FatalException, missingName);
}
// RULE 2
// proton should exist
// if any other charged baryon exist
if (!isProton && isAnyChargedBaryon) {
G4String missingName="proton ";
#ifdef G4VERBOSE
if (verboseLevel >0){
G4cout << "G4VUserPhysicsList::CheckParticleList: ";
G4cout << missingName << " does not exist "<< G4endl;
G4cout << " Proton is necessary for EM baryon processes" << G4endl;
}
#endif
missingName += " should be created ";
G4Exception("G4VUserPhysicsList::CheckParticleList","Missing Proton",
FatalException, missingName);
}
// RULE 3
// GenericIonn should exist
// if any other ion exist
if (!isGenericIon && isAnyIon) {
G4String missingName="GenericIon ";
#ifdef G4VERBOSE
if (verboseLevel >0){
G4cout << "G4VUserPhysicsList::CheckParticleList: ";
G4cout << missingName << " does not exist "<< G4endl;
G4cout << " GenericIon should be created if any ion is necessary" << G4endl;
}
#endif
missingName += " should be created ";
G4Exception("G4VUserPhysicsList::CheckParticleList","Missing GenericIon",
FatalException, missingName);
}
}
////////////////////////////////////////////////////////
void G4VUserPhysicsList::InitializeProcessManager()
{
@@ -202,7 +313,7 @@ void G4VUserPhysicsList::InitializeProcessManager()
}
}
////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
void G4VUserPhysicsList::RemoveProcessManager()
{
// loop over all particles in G4ParticleTable
@@ -262,7 +373,7 @@ void G4VUserPhysicsList::AddTransportation()
// Error !! no process manager
G4String particleName = particle->GetParticleName();
G4Exception("G4VUserPhysicsList::AddTransportation","No process manager",
RunMustBeAborted, particleName );
FatalException, particleName );
} else {
// add transportation with ordering = ( -1, "first", "first" )
pmanager ->AddProcess(theTransportationProcess);
@@ -276,7 +387,7 @@ void G4VUserPhysicsList::AddTransportation()
// Error !! no process manager
G4String particleName = particle->GetParticleName();
G4Exception("G4VUserPhysicsList::AddTransportation","No process manager",
RunMustBeAborted, particleName );
FatalException, particleName );
} else {
// add transportation with ordering = ( -1, "first", "first" )
pmanager ->AddProcess(theTransportationProcess);
@@ -358,6 +469,7 @@ void G4VUserPhysicsList::SetCutsWithDefault()
SetCutValue(cut, "gamma");
SetCutValue(cut, "e-");
SetCutValue(cut, "e+");
SetCutValue(cut, "proton");
// dump Cut values if verboseLevel==3
if (verboseLevel>2) {
@@ -373,6 +485,7 @@ void G4VUserPhysicsList::SetCutsForRegion(G4double aCut, const G4String& rname)
SetCutValue(aCut, "gamma", rname);
SetCutValue(aCut, "e-", rname);
SetCutValue(aCut, "e+", rname);
SetCutValue(aCut, "proton", rname);
}
@@ -449,6 +562,10 @@ void G4VUserPhysicsList::BuildPhysicsTable()
BuildPhysicsTable(particle);
}
}
// Set flag
fIsPhysicsTableBuilt = true;
}
///////////////////////////////////////////////////////////////
void G4VUserPhysicsList::BuildPhysicsTable(G4ParticleDefinition* particle)
@@ -486,7 +603,22 @@ void G4VUserPhysicsList::BuildPhysicsTable(G4ParticleDefinition* particle)
// Rebuild the physics tables for every process for this particle type
// if particle is not ShortLived
if(!particle->IsShortLived()) {
G4ProcessVector* pVector = particle->GetProcessManager()->GetProcessList();
G4ProcessManager* pManager = particle->GetProcessManager();
if (!pManager) {
G4cerr << "G4VUserPhysicsList::BuildPhysicsTable : No Process Manager for "
<< particle->GetParticleName() <<G4endl;
G4cerr << particle->GetParticleName() << " should be created in your PhysicsList" <<G4endl;
G4Exception("G4VUserPhysicsList::BuildPhysicsTable","No process manager",
FatalException, particle->GetParticleName() );
}
G4ProcessVector* pVector = pManager->GetProcessList();
if (!pVector) {
G4cerr << "G4VUserPhysicsList::BuildPhysicsTable : No Process Vector for "
<< particle->GetParticleName() <<G4endl;
G4cerr << particle->GetParticleName() << " should be created in your PhysicsList" <<G4endl;
G4Exception("G4VUserPhysicsList::BuildPhysicsTable","No process Vector",
FatalException, particle->GetParticleName() );
}
for (G4int j=0; j < pVector->size(); ++j) {
(*pVector)[j]->BuildPhysicsTable(*particle);
}
@@ -505,10 +637,17 @@ void G4VUserPhysicsList::PreparePhysicsTable(G4ParticleDefinition* particle)
<< particle->GetParticleName() <<G4endl;
G4cerr << particle->GetParticleName() << " should be created in your PhysicsList" <<G4endl;
G4Exception("G4VUserPhysicsList::PreparePhysicsTable","No process manager",
RunMustBeAborted, particle->GetParticleName() );
FatalException, particle->GetParticleName() );
}
G4ProcessVector* pVector = pManager->GetProcessList();
if (!pVector) {
G4cerr << "G4VUserPhysicsList::PreparePhysicsTable : No Process Vector for "
<< particle->GetParticleName() <<G4endl;
G4cerr << particle->GetParticleName() << " should be created in your PhysicsList" <<G4endl;
G4Exception("G4VUserPhysicsList::PreparePhysicsTable","No process Vector",
FatalException, particle->GetParticleName() );
}
for (G4int j=0; j < pVector->size(); ++j) {
(*pVector)[j]->PreparePhysicsTable(*particle);
}
@@ -689,6 +828,7 @@ void G4VUserPhysicsList::SetApplyCuts(G4bool value, const G4String& name)
theParticleTable->FindParticle("gamma")->SetApplyCutsFlag(value);
theParticleTable->FindParticle("e-")->SetApplyCutsFlag(value);
theParticleTable->FindParticle("e+")->SetApplyCutsFlag(value);
theParticleTable->FindParticle("proton")->SetApplyCutsFlag(value);
} else {
theParticleTable->FindParticle(name)->SetApplyCutsFlag(value);
}