File indexing completed on 2025-01-31 09:21:47
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 #pragma once
0045
0046 #include "G4VUserPrimaryGeneratorAction.hh"
0047 #include <G4String.hh>
0048 #include <G4ios.hh>
0049 #include <map>
0050 #include <utility>
0051 class G4GenericMessenger;
0052 class G4VPrimaryGenerator;
0053 class G4Event;
0054
0055 class PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction
0056 {
0057 public:
0058 PrimaryGeneratorAction();
0059 virtual ~PrimaryGeneratorAction();
0060 void GeneratePrimaries(G4Event*) final;
0061 inline void SetGenerator(G4String genname)
0062 {
0063 std::map<G4String, G4VPrimaryGenerator*>::iterator pos =
0064 gentypeMap.find(genname);
0065 if(pos != gentypeMap.end())
0066 {
0067 fcurrentGenerator = pos->second;
0068 fcurrentGeneratorName = genname;
0069 }
0070 else
0071 {
0072 G4cout << "Primary Generator: " << genname << " is not a valid Option"
0073 << G4endl;
0074 G4cout << "Valid Options are: ";
0075 #if(G4VERSION_NUMBER > 1072)
0076 for(auto [genType, generator] : gentypeMap)
0077 {
0078 G4cout << genType << " ";
0079 }
0080 G4cout << G4endl;
0081 #else
0082 for(std::map<G4String, G4VPrimaryGenerator*>::iterator ii =
0083 gentypeMap.begin();
0084 ii != gentypeMap.end(); ++ii)
0085 {
0086 G4cout << (*ii).first << " ";
0087 }
0088 G4cout << G4endl;
0089 #endif
0090 }
0091 }
0092 inline G4VPrimaryGenerator* GetGenerator() const { return fcurrentGenerator; }
0093 inline G4String GetGeneratorName() const { return fcurrentGeneratorName; }
0094 inline void Print()
0095 {
0096 G4cout << "===================================================" << G4endl;
0097 G4cout << " Primary Generator: " << fcurrentGeneratorName << G4endl;
0098 G4cout << "===================================================" << G4endl;
0099 }
0100
0101 private:
0102
0103 void DefineCommands();
0104 G4VPrimaryGenerator* fcurrentGenerator = nullptr;
0105 G4String fcurrentGeneratorName{ "particleGun" };
0106 PrimaryGeneratorAction& operator=(const PrimaryGeneratorAction& right);
0107 PrimaryGeneratorAction(const PrimaryGeneratorAction&);
0108 std::map<G4String, G4VPrimaryGenerator*> gentypeMap;
0109
0110 G4GenericMessenger* fMessenger = nullptr;
0111 };