Import Geant4 11.2.0 source tree

This commit is contained in:
Gabriele Cosmo
2023-12-08 10:43:34 +01:00
parent dd1f179cda
commit 860a2b92bf
3962 changed files with 139318 additions and 164259 deletions
@@ -31,6 +31,9 @@
// to the stack. G4UserStackingAction can set the classification.
// Author: M.Asai, SLAC
// Adding sub-event parallel options : M.Asai, JLab
//
// --------------------------------------------------------------------
#ifndef G4ClassificationOfNewTrack_hh
#define G4ClassificationOfNewTrack_hh 1
@@ -46,7 +49,14 @@ enum G4ClassificationOfNewTrack
// number of waiting stacks
//----------------------------------------------------------------
fWaiting_1=11, fWaiting_2=12, fWaiting_3=13, fWaiting_4=14, fWaiting_5=15,
fWaiting_6=16, fWaiting_7=17, fWaiting_8=18, fWaiting_9=19, fWaiting_10=20
fWaiting_6=16, fWaiting_7=17, fWaiting_8=18, fWaiting_9=19, fWaiting_10=20,
//----------------------------------------------------------------
// following ENUM are available only for the sub-event parallelism
//----------------------------------------------------------------
fSubEvent_1=101, fSubEvent_2=102, fSubEvent_3=103, fSubEvent_4=104,
fSubEvent_5=105, fSubEvent_6=106, fSubEvent_7=107, fSubEvent_8=108,
fSubEvent_9=109, fSubEvent_A=110, fSubEvent_B=111, fSubEvent_C=112,
fSubEvent_D=113, fSubEvent_E=114, fSubEvent_F=115
};
#endif
+60 -3
View File
@@ -35,10 +35,14 @@
// G4Event has trajectories, hits collections, and/or digi collections.
// Author: M.Asai, SLAC
// Adding sub-event : M.Asai, JLAB
// --------------------------------------------------------------------
#ifndef G4Event_hh
#define G4Event_hh 1
#include <set>
#include <map>
#include "globals.hh"
#include "evtdefs.hh"
#include "G4Allocator.hh"
@@ -50,13 +54,14 @@
#include "G4Profiler.hh"
class G4VHitsCollection;
class G4SubEvent;
class G4Event
{
public:
using ProfilerConfig = G4ProfilerConfig<G4ProfileType::Event>;
using ProfilerConfig = G4ProfilerConfig<G4ProfileType::Event>;
public:
public:
G4Event() = default;
explicit G4Event(G4int evID);
~G4Event();
@@ -100,7 +105,7 @@ class G4Event
inline void KeepTheEvent(G4bool vl=true)
{ keepTheEvent = vl; }
inline G4bool ToBeKept() const
{ return keepTheEvent; }
{ return keepTheEvent || GetNumberOfRemainingSubEvents()>0; }
inline void KeepForPostProcessing() const
{ ++grips; }
inline void PostProcessingFinished() const
@@ -228,6 +233,58 @@ class G4Event
// Flag to keep the event until the end of run
G4bool keepTheEvent = false;
mutable G4int grips = 0;
//========================= for sub-event parallelism
// following methods should be used only within the master thread
public:
G4SubEvent* PopSubEvent(G4int);
// This method is to be invoked from G4RunManager.
// SpawnSubEvent() is internally invoked.
G4int TerminateSubEvent(G4SubEvent*);
// This method is to be invoked from G4RunManager once a sub-event is
// fully processed by a worker thread.
G4int StoreSubEvent(G4int,G4SubEvent*);
// This method is used by G4EventManager to store all the remeining sub-event
// object at the end of processing the event.
G4int SpawnSubEvent(G4SubEvent*);
// Registering sub-event when it is sent to a worker thread.
inline G4int GetNumberOfRemainingSubEvents() const
// Number of sub-events that have been sent to worker threads but not yet
// completed.
{
auto tot = (G4int)fSubEvtVector.size();
for(auto& sem : fSubEvtStackMap)
{ tot += (G4int)sem.second->size(); }
return tot;
}
void MergeSubEventResults(const G4Event* se);
private:
std::map<G4int,std::set<G4SubEvent*>*> fSubEvtStackMap;
std::set<G4SubEvent*> fSubEvtVector;
// motherEvent pointer is non-null for an event created in the worker
// thread of sub-event parallelism.
// This object and all the contained objects must be deleted by the
// responsible worker thread.
private:
G4Event* motherEvent = nullptr;
G4int subEventType = -1;
public:
void FlagAsSubEvent(G4Event* me, G4int ty)
{
motherEvent = me;
subEventType = ty;
}
G4Event* GetMotherEvent() const
{ return motherEvent; }
G4int GetSubEventType() const
{ return subEventType; }
};
extern G4EVENT_DLL G4Allocator<G4Event>*& anEventAllocator();
+15 -4
View File
@@ -38,7 +38,7 @@
#include "G4StackManager.hh"
#include "G4TrajectoryContainer.hh"
#include "G4PrimaryTransformer.hh"
class G4Event;
#include "G4Event.hh"
class G4UserEventAction;
class G4UserStackingAction;
class G4UserTrackingAction;
@@ -122,9 +122,6 @@ class G4EventManager
// which should belong to the other managers will be sent to the
// corresponding managers.
void SetNumberOfAdditionalWaitingStacks(G4int iAdd)
{ trackContainer->SetNumberOfAdditionalWaitingStacks(iAdd); }
void KeepTheCurrentEvent();
// If the current event exists, it is kept undeleted until
// the end of the current run
@@ -157,6 +154,19 @@ class G4EventManager
inline void StoreRandomNumberStatusToG4Event(G4int vl)
{ storetRandomNumberStatusToG4Event = vl; }
inline void UseSubEventParallelism()
{ subEventPara = true; }
G4SubEvent* PopSubEvent(G4int ty);
// If this method is invoked by the G4RunManager while an event is still
// in process. Null is returned if the sub-event does not have enough tracks.
// This method is Mutex-protected.
void TerminateSubEvent(const G4SubEvent* se,const G4Event* evt);
// G4Event "evt" contains the results made by the worker thread.
// The ownership of "evt" remains to the worker thread and it will be
// deleted after this method. All necessary information in "evt" must
// be copied into the corresponding master G4Event object.
private:
void DoProcessing(G4Event* anEvent);
@@ -176,6 +186,7 @@ class G4EventManager
G4PrimaryTransformer* transformer = nullptr;
G4bool tracking = false;
G4bool abortRequested = false;
G4bool subEventPara = false;
G4EvManMessenger* theMessenger = nullptr;
+48 -3
View File
@@ -42,21 +42,29 @@
// History:
// - 01/Feb/1996, Makoto Asai - Created
// - 04/Oct/2011, Pere Mato - Use of G4TrackStack with value semantics
// - 28/Aug/2023, Makoto Asai - Adding sub-event parallelism
// --------------------------------------------------------------------
#ifndef G4StackManager_hh
#define G4StackManager_hh 1
#include <map>
#include <vector>
#include "G4UserStackingAction.hh"
#include "G4StackedTrack.hh"
#include "G4TrackStack.hh"
#include "G4SmartTrackStack.hh"
#include "G4SubEventTrackStack.hh"
#include "G4ClassificationOfNewTrack.hh"
#include "G4Track.hh"
#include "G4TrackStatus.hh"
#include "G4ExceptionSeverity.hh"
#include "globals.hh"
class G4StackingMessenger;
class G4VTrajectory;
class G4Event;
class G4ParticleDefinition;
class G4StackManager
{
@@ -72,7 +80,7 @@ class G4StackManager
G4int PushOneTrack(G4Track* newTrack,
G4VTrajectory* newTrajectory = nullptr);
G4Track* PopNextTrack(G4VTrajectory** newTrajectory);
G4int PrepareNewEvent();
G4int PrepareNewEvent(G4Event* currentEvent);
void ReClassify();
// Send all tracks stored in the Urgent stack one by one to
@@ -107,6 +115,31 @@ class G4StackManager
// If the destination is fKill, the track is deleted.
// If the origin is fKill, nothing happen.
void RegisterSubEventType(G4int ty, G4int maxEnt);
// Registering a sub-event type and the capacity of the tracks to be
// stored in a G4SubEvent object of the corresponding sub-event type
void SetDefaultClassification(
G4TrackStatus, G4ClassificationOfNewTrack,
G4ExceptionSeverity es = G4ExceptionSeverity::IgnoreTheIssue);
void SetDefaultClassification(
const G4ParticleDefinition*, G4ClassificationOfNewTrack,
G4ExceptionSeverity es = G4ExceptionSeverity::IgnoreTheIssue);
// Define the default classification for a newly arriving track.
// Default can be alternated by the UserStackingAction.
// G4ExceptionSeverity can be set to warn the user if the classification
// is inproperly changed.
inline G4ClassificationOfNewTrack GetDefaultClassification()
{ return fDefaultClassification; }
public:
void ReleaseSubEvent(G4int ty);
inline std::size_t GetNSubEventTypes()
{ return subEvtTypes.size(); }
inline G4int GetSubEventType(std::size_t i)
{ return subEvtTypes[i]; }
void clear();
void ClearUrgentStack();
void ClearWaitingStack(G4int i=0);
@@ -119,8 +152,8 @@ class G4StackManager
void SetUserStackingAction(G4UserStackingAction* value);
private:
G4ClassificationOfNewTrack DefaultClassification(G4Track* aTrack);
void DefineDefaultClassification(const G4Track* aTrack);
void SortOut(G4StackedTrack&,G4ClassificationOfNewTrack);
private:
@@ -136,6 +169,18 @@ class G4StackManager
G4StackingMessenger* theMessenger = nullptr;
std::vector<G4TrackStack*> additionalWaitingStacks;
G4int numberOfAdditionalWaitingStacks = 0;
std::map<G4TrackStatus,
std::pair<G4ClassificationOfNewTrack,G4ExceptionSeverity>>
defClassTrackStatus;
std::map<const G4ParticleDefinition*,
std::pair<G4ClassificationOfNewTrack,G4ExceptionSeverity>>
defClassPartDef;
G4ClassificationOfNewTrack fDefaultClassification = fUrgent;
G4ExceptionSeverity fExceptionSeverity = G4ExceptionSeverity::IgnoreTheIssue;
std::map<G4int,G4SubEventTrackStack*> subEvtStackMap;
std::vector<G4int> subEvtTypes;
};
#endif
+79
View File
@@ -0,0 +1,79 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// Class description:
//
// This is a stack class used for transferring a sub-event.
// Author: Makoto Asai (JLAB) - 23/Aug/23
// --------------------------------------------------------------------
#ifndef G4SubEvent_hh
#define G4SubEvent_hh 1
#include <vector>
class G4Event;
#include "G4StackedTrack.hh"
#include "G4Types.hh"
class G4SubEvent : public std::vector<G4StackedTrack>
{
public:
G4SubEvent() = default;
explicit G4SubEvent(G4int ty, std::size_t maxEnt)
: fSubEventType(ty), fMaxEnt(maxEnt) {;}
~G4SubEvent();
G4SubEvent& operator=(const G4SubEvent&) = delete;
G4bool operator==(const G4SubEvent&) const = delete;
G4bool operator!=(const G4SubEvent&) const = delete;
inline void PushToStack(const G4StackedTrack& aStackedTrack)
{ push_back(aStackedTrack); }
G4StackedTrack PopFromStack();
void clearAndDestroy();
inline G4int GetSubEventType() const { return fSubEventType; }
inline std::size_t GetNTrack() const { return size(); }
inline std::size_t GetMaxNTrack() const { return fMaxEnt; }
G4double getTotalEnergy() const;
// pointer to G4Event where this sub-event belongs to
inline void SetEvent(G4Event* evt) { fpEvent = evt; }
inline G4Event* GetEvent() const { return fpEvent; }
private:
G4int fSubEventType = -1;
std::size_t fMaxEnt = 1000;
G4Event* fpEvent = nullptr;
};
#endif
@@ -0,0 +1,80 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// Class description:
//
// This is a stack class used by G4StackManager. This class object
// stores G4StackedTrack class objects into G4SubEvent
// Author: Makoto Asai (JLab) - 23/Aug/23
// --------------------------------------------------------------------
#ifndef G4SubEventTrackStack_hh
#define G4SubEventTrackStack_hh 1
#include "G4Types.hh"
#include "G4SubEvent.hh"
class G4Event;
class G4StackedTrack;
class G4SubEventTrackStack
{
public:
G4SubEventTrackStack() = default;
explicit G4SubEventTrackStack(G4int ty, std::size_t maxEnt)
: fSubEventType(ty), fMaxEnt(maxEnt) {;}
~G4SubEventTrackStack();
G4SubEventTrackStack& operator=(const G4SubEventTrackStack&) = delete;
G4bool operator==(const G4SubEventTrackStack&) const = delete;
G4bool operator!=(const G4SubEventTrackStack&) const = delete;
void PushToStack(const G4StackedTrack& aStackedTrack);
void ReleaseSubEvent();
//G4StackedTrack PopFromStack();
void PrepareNewEvent(G4Event* ev);
void clearAndDestroy();
inline G4int GetSubEventType() const { return fSubEventType; }
inline G4int GetNTrack() const
{
if(fCurrentSE==nullptr) return 0;
return (G4int)fCurrentSE->size();
}
inline std::size_t GetMaxNTrack() const { return fMaxEnt; }
inline void SetVerboseLevel(G4int val) { verboseLevel = val; }
private:
G4int fSubEventType = -1;
std::size_t fMaxEnt = 1000;
G4SubEvent* fCurrentSE = nullptr;
G4Event* fCurrentEvent = nullptr;
G4int verboseLevel = 0;
};
#endif
+11
View File
@@ -38,6 +38,7 @@
// the G4VUserPrimaryGeneratorAction concrete class
// Author: Makoto Asai (SLAC)
// Adding MergeSubEvent - Sep/11/2023 Makoto Asai (JLab)
// --------------------------------------------------------------------
#ifndef G4UserEventAction_hh
#define G4UserEventAction_hh 1
@@ -57,6 +58,16 @@ class G4UserEventAction
virtual void EndOfEventAction(const G4Event* anEvent);
// Two virtual method the user can override.
virtual void MergeSubEvent(G4Event* masterEvent, const G4Event* subEvent);
// A virtual method to merge the results of a sub-event into the master
// event. The ownership of "subEvent" and its contents blong to the
// worker thread.
// Merging trajectories and scores are taken care by G4Event and
// G4ScoringManager so the user does not need to take care of them.
// But merging hits collections and UserEventInformation must be taken
// care by this method.
// This method is invoked only for the case of sub-event parallelism.
protected:
G4EventManager* fpEventManager = nullptr; // not owned