|
||||
File indexing completed on 2025-01-18 09:58:20
0001 // 0002 // ******************************************************************** 0003 // * License and Disclaimer * 0004 // * * 0005 // * The Geant4 software is copyright of the Copyright Holders of * 0006 // * the Geant4 Collaboration. It is provided under the terms and * 0007 // * conditions of the Geant4 Software License, included in the file * 0008 // * LICENSE and available at http://cern.ch/geant4/license . These * 0009 // * include a list of copyright holders. * 0010 // * * 0011 // * Neither the authors of this software system, nor their employing * 0012 // * institutes,nor the agencies providing financial support for this * 0013 // * work make any representation or warranty, express or implied, * 0014 // * regarding this software system or assume any liability for its * 0015 // * use. Please see the license in the file LICENSE and URL above * 0016 // * for the full disclaimer and the limitation of liability. * 0017 // * * 0018 // * This code implementation is the result of the scientific and * 0019 // * technical work of the GEANT4 collaboration. * 0020 // * By using, copying, modifying or distributing the software (or * 0021 // * any work based on the software) you agree to acknowledge its * 0022 // * use in resulting scientific publications, and indicate your * 0023 // * acceptance of all terms of the Geant4 Software license. * 0024 // ******************************************************************** 0025 // 0026 // G4GeneralParticleSource 0027 // 0028 // Class Description: 0029 // 0030 // The General Particle Source is designed to replace the G4ParticleGun class. 0031 // It is designed to allow specification of mutiple particle sources, each with 0032 // independent definitions of particle type, position, direction (or angular) 0033 // and energy distributions. 0034 0035 // Author: Fan Lei, QinetiQ ltd 0036 // Customer: ESA/ESTEC 0037 // Version: 2.0 0038 // History: 0039 // - 05/02/2004, F.Lei - Version 2.0. Created. 0040 // - 26/10/2004, F.Lei - Added the Multiple_vertex capability. 0041 // - 25/03/2014, A.Green - Various changes to use the new class 0042 // G4GeneralParticleSourceData, mostly just transparent wrappers 0043 // around the thread safe object. 0044 // -------------------------------------------------------------------- 0045 #ifndef G4GeneralParticleSource_hh 0046 #define G4GeneralParticleSource_hh 1 0047 0048 #include "globals.hh" 0049 #include <vector> 0050 0051 #include "G4Event.hh" 0052 #include "G4SingleParticleSource.hh" 0053 #include "G4GeneralParticleSourceMessenger.hh" 0054 #include "G4GeneralParticleSourceData.hh" 0055 0056 class G4SingleParticleSource; 0057 0058 class G4GeneralParticleSource : public G4VPrimaryGenerator 0059 { 0060 public: 0061 0062 G4GeneralParticleSource(); 0063 // Initialize variables and instantiates the messenger and 0064 // generator classes 0065 0066 ~G4GeneralParticleSource() override; 0067 // Delete messenger and others 0068 0069 void GeneratePrimaryVertex(G4Event*) override; 0070 0071 inline G4int GetNumberofSource() { return GPSData->GetSourceVectorSize(); } 0072 // Return the number of particle gun defined 0073 0074 void ListSource(); 0075 // List the particle guns defined 0076 0077 void SetCurrentSourceto(G4int) ; 0078 // Set the current gun to the specified one so its definition 0079 // can be changed 0080 0081 void SetCurrentSourceIntensity(G4double); 0082 // Change the current particle gun strength 0083 0084 inline G4SingleParticleSource* GetCurrentSource() const 0085 { return GPSData->GetCurrentSource(); } 0086 // Return the pointer to current particle gun 0087 inline G4int GetCurrentSourceIndex() const 0088 { return GPSData->GetCurrentSourceIdx(); } 0089 // Return the index of the current particle gun 0090 inline G4double GetCurrentSourceIntensity() const 0091 { return GPSData->GetIntensity(GetCurrentSourceIndex()); } 0092 // Return the strength of the current gun 0093 0094 void ClearAll(); 0095 // Remove all defined particle gun 0096 void AddaSource (G4double); 0097 // Add a new particle gun with the specified strength 0098 void DeleteaSource(G4int); 0099 // Delete the specified particle gun 0100 0101 inline void SetVerbosity(G4int i) { GPSData->SetVerbosityAllSources(i); } 0102 // Set the verbosity level. 0103 0104 inline void SetMultipleVertex(G4bool av) { GPSData->SetMultipleVertex(av); } 0105 // Set if multiple vertex per event. 0106 0107 inline void SetFlatSampling(G4bool av) 0108 { GPSData->SetFlatSampling(av); normalised = false;} 0109 // Set if flat_sampling is applied in multiple source case 0110 0111 inline void SetParticleDefinition (G4ParticleDefinition * aPDef) 0112 { GPSData->GetCurrentSource()->SetParticleDefinition(aPDef); } 0113 inline G4ParticleDefinition* GetParticleDefinition () const 0114 { return GPSData->GetCurrentSource()->GetParticleDefinition(); } 0115 // Set/Get the particle definition of the primary track 0116 0117 inline void SetParticleCharge(G4double aCharge) 0118 { GPSData->GetCurrentSource()->SetParticleCharge(aCharge); } 0119 // Set the charge state of the primary track 0120 0121 inline void SetParticlePolarization (G4ThreeVector aVal) 0122 { GPSData->GetCurrentSource()->SetParticlePolarization(aVal); } 0123 inline G4ThreeVector GetParticlePolarization () const 0124 { return GPSData->GetCurrentSource()->GetParticlePolarization(); } 0125 // Set/Get polarization state of the primary track 0126 0127 inline void SetParticleTime(G4double aTime) 0128 { GPSData->GetCurrentSource()->SetParticleTime(aTime); } 0129 inline G4double GetParticleTime() const 0130 { return GPSData->GetCurrentSource()->GetParticleTime(); } 0131 // Set/Get the Time. 0132 0133 inline void SetNumberOfParticles(G4int i) 0134 { GPSData->GetCurrentSource()->SetNumberOfParticles(i); } 0135 inline G4int GetNumberOfParticles() const 0136 { return GPSData->GetCurrentSource()->GetNumberOfParticles(); } 0137 // Set/Get the number of particles to be generated in the primary track 0138 0139 inline G4ThreeVector GetParticlePosition() const 0140 { return GPSData->GetCurrentSource()->GetParticlePosition(); } 0141 inline G4ThreeVector GetParticleMomentumDirection() const 0142 { return GPSData->GetCurrentSource()->GetParticleMomentumDirection(); } 0143 inline G4double GetParticleEnergy() const 0144 { return GPSData->GetCurrentSource()->GetParticleEnergy(); } 0145 // Get the position, direction, and energy of the current particle 0146 0147 private: 0148 0149 void IntensityNormalization(); 0150 0151 private: 0152 0153 G4bool normalised = false; 0154 // Helper Boolean, used to reduce number of locks 0155 // at run time (see GeneratePrimaryVertex) 0156 0157 G4GeneralParticleSourceMessenger* theMessenger = nullptr; 0158 // Note this is a shared resource among MT workers 0159 G4GeneralParticleSourceData* GPSData = nullptr; 0160 // Note this is a shared resource among MT workers 0161 0162 /** Andrea Dotti Feb 2015 0163 * GPS messenger design requires some explanation for what distributions 0164 * parameters are concerned : Each thread has its own GPS 0165 * since primary generation is a user action. 0166 * However to save memory the underlying structures that provide the 0167 * GPS functionalities ( the G4SPS*Distribution classes and the 0168 * G4SPSRandomGenerator class) 0169 * are shared among threads. This implies that modifying parameters of sources 0170 * requires some attention: 0171 * 1- Only one thread should change source parameters. 0172 * 2- Changing of parameters can happen only between runs, when is guaranteed 0173 * that no thread is accessing them 0174 * 2- UI commands require that even if messenger is instantiated in a thread 0175 * the commands are executed in the master (this is possible since V10.1) 0176 * The simplest solution is to use UI commands to change GPS parameters and 0177 * avoid C++ APIs. If this is inevitable a simple solution is to instantiate 0178 * an instance of G4GeneralParticleSource explicitly in the master thread 0179 * (for example in G4VUserActionInitialization::BuildForMaster() and set the 0180 * defaults parameter there). 0181 */ 0182 0183 }; 0184 0185 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |