Import Geant4 11.3.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2024-06-28 13:08:51 +02:00
parent f7b23877ed
commit e58e650b32
5232 changed files with 239416 additions and 244360 deletions
+65 -26
View File
@@ -35,6 +35,12 @@
#include "G4ios.hh"
#include "G4SubEvent.hh"
#include "G4Threading.hh"
#include "G4AutoLock.hh"
namespace{
G4Mutex SubEventMutex = G4MUTEX_INITIALIZER;
}
G4Allocator<G4Event>*& anEventAllocator()
{
G4ThreadLocalStatic G4Allocator<G4Event>* _instance = nullptr;
@@ -68,42 +74,52 @@ G4Event::~G4Event()
delete randomNumberStatus;
delete randomNumberStatusForProcessing;
// Following G4Exception are temporally issuing JustWarning to delete
// unprocessed tracks in sub-events. Once sub-event mechanism is completely
// implemented, G4Exception should cause FatalException.
G4int remainingSE = 0;
// TODO (PHASE-II): count remaining subevents for scoring
for(auto& sem : fSubEvtStackMap)
{
if((sem.second!=nullptr)&&!(sem.second->empty()))
{
remainingSE += sem.second->size();
for(auto& se : *(sem.second))
{
se->clearAndDestroy();
}
{ delete se; }
sem.second->clear();
}
}
if(remainingSE>0)
{
/* TODO (PHASE-II): Handle incorrect scoring
if(!scoresRecorded) {
G4ExceptionDescription ed;
ed << "Deleting G4Event (id:" << eventID << ") that still has unrecorded scores -- "
<< remainingSE << " sub-events un-processed.";
G4Exception("G4Event::~G4Event()","SubEvt0001",FatalException,ed);
} else if(remainingSE>0) {
G4ExceptionDescription ed;
ed << "Deleting G4Event (id:" << eventID << ") that still has "
<< remainingSE << " sub-events un-processed.";
G4Exception("G4Event::~G4Event()","SubEvt0001",JustWarning,ed);
G4Exception("G4Event::~G4Event()","SubEvt0002",FatalException,ed);
}
*/
if(!(fSubEvtVector.empty()))
{
for(auto& se : fSubEvtVector)
{
G4cout << "SubEvent " << se << " belongs to " << se->GetEvent()
<< " (eventID=" << se->GetEvent()->GetEventID() << ") that has "
<< se->GetNTrack() << " stacked tracks"<<G4endl;
}
G4ExceptionDescription ed;
ed << "Deleting G4Event (id:" << eventID << ") that has "
<< fSubEvtVector.size() << " sub-events still processing.";
G4Exception("G4Event::~G4Event()","SubEvt0001",JustWarning,ed);
for(auto& se : fSubEvtVector)
{
se->clearAndDestroy();
delete se;
}
G4Exception("G4Event::~G4Event()","SubEvt0003",FatalException,ed);
// TODO (PHASE-II): Handle deletion of subevents correctly
//for(auto& se : fSubEvtVector)
//{ delete se; }
//fSubEvtVector.clear();
}
if(!(fSubEventGarbageBin.empty()))
{
for(auto& se : fSubEventGarbageBin)
{ delete se; }
fSubEventGarbageBin.clear();
}
}
@@ -157,6 +173,7 @@ void G4Event::Draw() const
G4int G4Event::StoreSubEvent(G4int ty,G4SubEvent* se)
{
G4AutoLock lock(&SubEventMutex);
std::set<G4SubEvent*>* sev = nullptr;
auto ses = fSubEvtStackMap.find(ty);
if(ses==fSubEvtStackMap.end())
@@ -172,6 +189,7 @@ G4int G4Event::StoreSubEvent(G4int ty,G4SubEvent* se)
G4SubEvent* G4Event::PopSubEvent(G4int ty)
{
G4AutoLock lock(&SubEventMutex);
G4SubEvent* se = nullptr;
auto ses = fSubEvtStackMap.find(ty);
if(ses!=fSubEvtStackMap.end())
@@ -188,6 +206,9 @@ G4SubEvent* G4Event::PopSubEvent(G4int ty)
G4int G4Event::SpawnSubEvent(G4SubEvent* se)
{
// Can't use same mutex here as call by PopSubEvent but seems o.k. as only
// caller is PopSubEvent
//G4AutoLock lock(&SubEventMutex);
auto ss = fSubEvtVector.find(se);
if(ss!=fSubEvtVector.end())
{
@@ -201,8 +222,13 @@ G4int G4Event::SpawnSubEvent(G4SubEvent* se)
return (G4int)fSubEvtVector.size();
}
void G4Event::MergeSubEventResults(const G4Event* se)
void G4Event::MergeSubEventResults(const G4Event* /*se*/)
{
// TODO (PHASE-II): Handle merging of subevent trajectories
// Note:
// - scores are merged directly to the scoring manager
// - hits collections should be merged by the user event action
/*
#ifdef G4_STORE_TRAJECTORY
if(se->trajectoryContainer!=nullptr && se->trajectoryContainer->size()>0)
{
@@ -211,19 +237,21 @@ void G4Event::MergeSubEventResults(const G4Event* se)
{ trajectoryContainer->push_back(trj); }
}
#endif
// Note:
// - scores are merged directly to the scoring manager
// - hits collections should be merged by the user event action
*/
}
G4int G4Event::TerminateSubEvent(G4SubEvent* se)
{
G4AutoLock lock(&SubEventMutex);
auto ss = fSubEvtVector.find(se);
if(ss==fSubEvtVector.end())
{
G4ExceptionDescription ed;
ed << "Sub-event " << se << " of type " << se->GetSubEventType()
<< " with " << se->GetNTrack() << " tracks has never been spawned.";
<< " with " << se->GetNTrack() << " tracks of event " << se->GetEvent()->GetEventID()
<< " in event " << se->GetEvent()
<< " has never been spawned.";
G4Exception("G4Event::TerminateSubEvent","SubEvent9002",
FatalException,ed);
}
@@ -240,8 +268,19 @@ G4int G4Event::TerminateSubEvent(G4SubEvent* se)
FatalException,ed);
}
se->clearAndDestroy();
delete se;
//se->clearAndDestroy();
//delete se;
fSubEventGarbageBin.insert(se);
return (G4int)fSubEvtVector.size();
}
G4int G4Event::GetNumberOfRemainingSubEvents() const
// Number of sub-events that are either still waiting to be processed by worker
// threads or sent to worker threads but not yet completed.
{
G4AutoLock lock(&SubEventMutex);
auto tot = (G4int)fSubEvtVector.size();
for(auto& sem : fSubEvtStackMap)
{ tot += (G4int)sem.second->size(); }
return tot;
}
+29 -20
View File
@@ -43,8 +43,6 @@
#include "G4TransportationManager.hh"
#include "G4Navigator.hh"
#include "Randomize.hh"
#include "G4Profiler.hh"
#include "G4TiMemory.hh"
#include "G4GlobalFastSimulationManager.hh"
#include "G4AutoLock.hh"
@@ -90,7 +88,8 @@ G4EventManager::~G4EventManager()
fpEventManager = nullptr;
}
void G4EventManager::DoProcessing(G4Event* anEvent)
void G4EventManager::DoProcessing(G4Event* anEvent,
G4TrackVector* trackVector, G4bool IDhasAlreadySet)
{
abortRequested = false;
G4ApplicationState currentState = stateManager->GetCurrentState();
@@ -101,7 +100,7 @@ void G4EventManager::DoProcessing(G4Event* anEvent)
return;
}
currentEvent = anEvent;
stateManager->SetNewState(G4State_EventProc);
if(!subEventParaWorker) stateManager->SetNewState(G4State_EventProc);
if(storetRandomNumberStatusToG4Event > 1)
{
std::ostringstream oss;
@@ -125,6 +124,7 @@ void G4EventManager::DoProcessing(G4Event* anEvent)
{
G4cout << "=====================================" << G4endl;
G4cout << " G4EventManager::ProcessOneEvent() " << G4endl;
if(trackVector!=nullptr) G4cout << " for a sub-event" << G4endl;
G4cout << "=====================================" << G4endl;
}
#endif
@@ -139,11 +139,7 @@ void G4EventManager::DoProcessing(G4Event* anEvent)
if(sdManager != nullptr)
{ currentEvent->SetHCofThisEvent(sdManager->PrepareNewEvent()); }
if(userEventAction != nullptr) userEventAction->BeginOfEventAction(currentEvent);
#if defined(GEANT4_USE_TIMEMORY)
eventProfiler.reset(new ProfilerConfig(currentEvent));
#endif
if(!subEventParaWorker && userEventAction != nullptr) userEventAction->BeginOfEventAction(currentEvent);
#ifdef G4VERBOSE
if ( verboseLevel > 1 )
@@ -153,6 +149,10 @@ void G4EventManager::DoProcessing(G4Event* anEvent)
}
#endif
if(trackVector!=nullptr)
{
StackTracks(trackVector,IDhasAlreadySet);
}
if(!abortRequested)
{
StackTracks(transformer->GimmePrimaries(currentEvent,trackIDCounter), true);
@@ -161,8 +161,8 @@ void G4EventManager::DoProcessing(G4Event* anEvent)
#ifdef G4VERBOSE
if ( verboseLevel > 0 )
{
G4cout << trackContainer->GetNTotalTrack() << " primaries "
<< "are passed from G4EventTransformer." << G4endl;
G4cout << trackContainer->GetNTotalTrack() << " primary tracks "
<< "are passed to the stack." << G4endl;
G4cout << "!!!!!!! Now start processing an event !!!!!!!" << G4endl;
}
#endif
@@ -309,10 +309,6 @@ void G4EventManager::DoProcessing(G4Event* anEvent)
sdManager->TerminateCurrentEvent(currentEvent->GetHCofThisEvent());
}
#if defined(GEANT4_USE_TIMEMORY)
eventProfiler.reset();
#endif
// In case of sub-event parallelism, an event may not be completed at
// this point but results of sus-events may be merged later. Thus
// userEventAction->EndOfEventAction() is invoked by G4RunManager
@@ -340,7 +336,7 @@ void G4EventManager::DoProcessing(G4Event* anEvent)
}
}
stateManager->SetNewState(G4State_GeomClosed);
if(!subEventParaWorker) stateManager->SetNewState(G4State_GeomClosed);
currentEvent = nullptr;
abortRequested = false;
}
@@ -357,7 +353,7 @@ void G4EventManager::TerminateSubEvent(const G4SubEvent* se,const G4Event* evt)
G4AutoLock lock(&EventMgrMutex);
auto ev = se->GetEvent();
ev->MergeSubEventResults(evt);
userEventAction->MergeSubEvent(ev,evt);
if(!subEventParaWorker && userEventAction!=nullptr) userEventAction->MergeSubEvent(ev,evt);
#ifdef G4VERBOSE
// Capture this here because termination will delete subevent...
G4int seType = se->GetSubEventType();
@@ -441,6 +437,12 @@ void G4EventManager::SetUserAction(G4UserSteppingAction* userAction)
trackManager->SetUserAction(userAction);
}
void G4EventManager::ProcessOneEventForSERM(G4Event* anEvent)
{
G4AutoLock lock(&EventMgrMutex);
ProcessOneEvent(anEvent);
}
void G4EventManager::ProcessOneEvent(G4Event* anEvent)
{
trackIDCounter = 0;
@@ -452,13 +454,21 @@ void G4EventManager::ProcessOneEvent(G4TrackVector* trackVector,
{
static G4ThreadLocal G4String* randStat = nullptr;
if (randStat == nullptr) randStat = new G4String;
trackIDCounter = 0;
G4bool tempEvent = false;
G4bool newEvent = false;
if(anEvent == nullptr)
{
anEvent = new G4Event();
tempEvent = true;
newEvent = true;
} else {
if(evID_inSubEv != anEvent->GetEventID()) {
evID_inSubEv = anEvent->GetEventID();
newEvent = true;
}
}
if(newEvent) trackIDCounter = 0;
if (storetRandomNumberStatusToG4Event==1
|| storetRandomNumberStatusToG4Event==3)
{
@@ -467,8 +477,7 @@ void G4EventManager::ProcessOneEvent(G4TrackVector* trackVector,
(*randStat) = oss.str();
anEvent->SetRandomNumberStatus(*randStat);
}
StackTracks(trackVector,false);
DoProcessing(anEvent);
DoProcessing(anEvent,trackVector,false);
if(tempEvent) { delete anEvent; }
}
@@ -274,6 +274,12 @@ G4GeneralParticleSourceMessenger(G4GeneralParticleSource* fPtclGun)
verbosityCmd->SetParameterName("level",false);
verbosityCmd->SetRange("level>=0 && level <=2");
volChkCmd = new G4UIcmdWithABool("/gps/checkVolume",this);
volChkCmd->SetGuidance("Switch on/off the check if the vertex position is inside the world volume.");
volChkCmd->SetGuidance("By default the check is on. There is a small performance gain if this check is off,");
volChkCmd->SetGuidance("but the user has to make sure setting the vertex position inside the world.");
volChkCmd->SetParameterName("switch",true,true);
// Now extended commands
// Positional ones:
//
@@ -652,6 +658,8 @@ G4GeneralParticleSourceMessenger::~G4GeneralParticleSourceMessenger()
delete arbintCmd1;
delete verbosityCmd;
delete volChkCmd;
delete ionCmd;
delete ionLvlCmd;
delete particleCmd;
@@ -1070,6 +1078,10 @@ void G4GeneralParticleSourceMessenger::SetNewValue(G4UIcommand *command, G4Strin
// CHECKPG();
// fParticleGun->SetVerbosity(verbosityCmd->GetNewIntValue(newValues));
}
else if( command==volChkCmd )
{
fGPS->CheckInside(volChkCmd->GetNewBoolValue(newValues));
}
else if( command==particleCmd )
{
if (newValues =="ion")
@@ -1483,10 +1495,14 @@ void G4GeneralParticleSourceMessenger::SetNewValue(G4UIcommand *command, G4Strin
}
}
G4String G4GeneralParticleSourceMessenger::GetCurrentValue(G4UIcommand*)
G4String G4GeneralParticleSourceMessenger::GetCurrentValue(G4UIcommand* command)
{
G4String cv;
if( command==volChkCmd )
{ cv = volChkCmd->ConvertToString(fParticleGun->IfCheckInside()); }
else
{
// if( command==directionCmd )
// { cv = directionCmd->ConvertToString(fParticleGun->GetParticleMomentumDirection()); }
// else if( command==energyCmd )
@@ -1501,6 +1517,7 @@ G4String G4GeneralParticleSourceMessenger::GetCurrentValue(G4UIcommand*)
// { cv = numberCmd->ConvertToString(fParticleGun->GetNumberOfParticles()); }
cv = "Not implemented yet";
}
return cv;
}
+15 -1
View File
@@ -42,6 +42,7 @@
#include "G4UIcmdWith3Vector.hh"
#include "G4UIcmdWith3VectorAndUnit.hh"
#include "G4UIcmdWithAnInteger.hh"
#include "G4UIcmdWithABool.hh"
#include "G4ios.hh"
#include "G4Tokenizer.hh"
@@ -107,6 +108,7 @@ G4ParticleGunMessenger::G4ParticleGunMessenger(G4ParticleGun* fPtclGun)
positionCmd = new G4UIcmdWith3VectorAndUnit("/gun/position",this);
positionCmd->SetGuidance("Set starting position of the particle.");
positionCmd->SetGuidance(" Position must be located inside the world volume.");
positionCmd->SetParameterName("X","Y","Z",true,true);
positionCmd->SetDefaultUnit("cm");
// positionCmd->SetUnitCategory("Length");
@@ -176,12 +178,17 @@ G4ParticleGunMessenger::G4ParticleGunMessenger(G4ParticleGun* fPtclGun)
paraml->SetDefaultValue("0");
ionLvlCmd->SetParameter(paraml);
volChkCmd = new G4UIcmdWithABool("/gun/checkVolume",this);
volChkCmd->SetGuidance("Switch on/off the check if the vertex position is inside the world volume.");
volChkCmd->SetGuidance("By default the check is on. There is a small performance gain if this check is off,");
volChkCmd->SetGuidance("but the user has to make sure setting the vertex position inside the world.");
volChkCmd->SetParameterName("switch",true,true);
// Set initial value to G4ParticleGun
//
fParticleGun->SetParticleDefinition( G4Geantino::Geantino() );
fParticleGun->SetParticleMomentumDirection( G4ThreeVector(1.0,0.0,0.0) );
fParticleGun->SetParticleEnergy( 1.0*GeV );
fParticleGun->SetParticlePosition(G4ThreeVector(0.0*cm, 0.0*cm, 0.0*cm));
fParticleGun->SetParticleTime( 0.0*ns );
}
@@ -199,6 +206,7 @@ G4ParticleGunMessenger::~G4ParticleGunMessenger()
delete numberCmd;
delete ionCmd;
delete ionLvlCmd;
delete volChkCmd;
delete gunDirectory;
}
@@ -277,6 +285,10 @@ SetNewValue(G4UIcommand* command, G4String newValues)
command->CommandFailed(ed);
}
}
else if( command==volChkCmd )
{
fParticleGun->CheckInside(volChkCmd->GetNewBoolValue(newValues));
}
}
G4String G4ParticleGunMessenger::GetCurrentValue(G4UIcommand* command)
@@ -331,6 +343,8 @@ G4String G4ParticleGunMessenger::GetCurrentValue(G4UIcommand* command)
cv = "";
}
}
else if( command==volChkCmd )
{ cv = volChkCmd->ConvertToString(fParticleGun->IfCheckInside()); }
return cv;
}
+21 -1
View File
@@ -41,6 +41,9 @@
#include "G4ios.hh"
#include "Randomize.hh"
G4double G4PrimaryTransformer::kETolerance = 1.0 * CLHEP::MeV;
G4ExceptionSeverity G4PrimaryTransformer::kETSeverity = JustWarning;
G4PrimaryTransformer::G4PrimaryTransformer()
{
particleTable = G4ParticleTable::GetParticleTable();
@@ -114,7 +117,7 @@ GenerateSingleTrack( G4PrimaryParticle* primaryParticle,
if(!IsGoodForTrack(partDef))
{ // The particle cannot be converted to G4Track, check daughters
#ifdef G4VERBOSE
if(verboseLevel>2)
if(verboseLevel>1)
{
G4cout << "Primary particle (PDGcode " << primaryParticle->GetPDGcode()
<< ") --- Ignored" << G4endl;
@@ -139,6 +142,23 @@ GenerateSingleTrack( G4PrimaryParticle* primaryParticle,
<< G4endl;
}
#endif
// Check the mass of the "real" particle
// N.B. PDG code 0 is used for artificial particle such as geantino
if(primaryParticle->GetPDGcode() != 0 && kETSeverity != IgnoreTheIssue)
{
G4double pmas = partDef->GetPDGMass();
if(std::abs(pmas - primaryParticle->GetMass()) > kETolerance) {
G4ExceptionDescription ed;
ed << "Primary particle PDG=" << primaryParticle->GetPDGcode()
<< " deltaMass(MeV)=" << (std::abs(pmas - primaryParticle->GetMass()))/CLHEP::MeV
<< " is larger than the tolerance(MeV)=" << kETolerance/CLHEP::MeV
<< "\n Specified mass(MeV)=" << (primaryParticle->GetMass())/CLHEP::MeV
<< " while PDG mass(MEV)=" << pmas/CLHEP::MeV
<< "\n To change the tolerance or the exception severity,"
<< " use G4PrimaryTransformer::SetKETolerance() method.";
G4Exception("G4PrimaryParticle::Set4Momentum", "part0005", kETSeverity, ed);
}
}
auto* DP =
new G4DynamicParticle(partDef,
primaryParticle->GetMomentumDirection(),
+6
View File
@@ -32,6 +32,12 @@
#include "G4VTrajectory.hh"
#include "G4Track.hh"
G4Allocator<G4SubEvent>*& aSubEventAllocator()
{
G4ThreadLocalStatic G4Allocator<G4SubEvent>* _instance = nullptr;
return _instance;
}
G4SubEvent::~G4SubEvent()
{
clearAndDestroy();
+12
View File
@@ -66,6 +66,7 @@ void G4SubEventTrackStack::PushToStack(const G4StackedTrack& aStackedTrack)
if(fCurrentSE==nullptr)
{
fCurrentSE = new G4SubEvent(fSubEventType,fMaxEnt);
fCurrentSE->SetEvent(fCurrentEvent);
}
else if(fCurrentSE->size()==fMaxEnt)
{
@@ -78,7 +79,18 @@ void G4SubEventTrackStack::PushToStack(const G4StackedTrack& aStackedTrack)
<< " tracks is stored" << G4endl;
}
fCurrentSE = new G4SubEvent(fSubEventType,fMaxEnt);
fCurrentSE->SetEvent(fCurrentEvent);
}
// Sanity check
if(fCurrentEvent == nullptr || fCurrentSE->GetEvent() == nullptr
|| fCurrentEvent != fCurrentSE->GetEvent())
{
G4ExceptionDescription ed;
ed << "Event object is broken or storing tracks of more than one events. PANIC!!!";
G4Exception("G4SubEventTrackStack::PushToStack()","SubEvt7003",FatalException,ed);
}
fCurrentSE->PushToStack(aStackedTrack);
}
+23 -1
View File
@@ -30,18 +30,40 @@
#include "G4VPrimaryGenerator.hh"
#include "G4TransportationManager.hh"
#include "G4StateManager.hh"
#include "G4Navigator.hh"
#include "G4VPhysicalVolume.hh"
#include "G4VSolid.hh"
G4bool G4VPrimaryGenerator::CheckVertexInsideWorld(const G4ThreeVector& pos)
{
// Check can only happen if run has been initialised
//
if (G4StateManager::GetStateManager()->GetCurrentState() != G4State_Idle)
{
return true;
}
G4Navigator* navigator= G4TransportationManager::GetTransportationManager()
-> GetNavigatorForTracking();
G4VPhysicalVolume* world= navigator-> GetWorldVolume();
G4VSolid* solid = world-> GetLogicalVolume()-> GetSolid();
EInside qinside = solid-> Inside(pos);
return qinside == kInside;
}
void G4VPrimaryGenerator::SetParticlePosition(G4ThreeVector aPosition)
{
if (ifCheckInside && !CheckVertexInsideWorld(aPosition))
{
G4ExceptionDescription ed;
ed << "Invalid vertex position (" << aPosition << "). "
<< "Position MUST be located -inside- the world volume." << G4endl
<< "Gun position has NOT been changed!";
G4Exception("G4VPrimaryGenerator::SetParticlePosition",
"Event0401", JustWarning, ed);
return;
}
particle_position = aPosition;
}