Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:52

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 // G4AdjointPrimaryGeneratorAction
0027 //
0028 // Class description:
0029 //
0030 // This class represents the PrimaryGeneratorAction that is used during
0031 // the entire adjoint simulation.
0032 // It uses the class G4AdjointPrimaryGenerator to generate randomly
0033 // adjoint primary particles on a user selected adjoint source
0034 // (External surface of a volume or Sphere).
0035 // The spectrum of the primary  adjoint particles is set as 1/E with
0036 // user defined max and min energy.
0037 // The weight of the primary is set according to ReverseMC theory as
0038 // w=log(Emax/Emin)*E*adjoint_source_area*pi/n, with E the energy of
0039 // the particle, n the number of adjoint primary particles of same type
0040 // that will be generated during the simulation.
0041 // Different types of adjoint particles are generated event after event
0042 // in order to cover all the type of primaries and secondaries needed
0043 // for the simulation. For example if reverse e- ionisation, brem,
0044 // photo electric effect, and compton are considered both adjoint gamma
0045 // and adjoint e- will be considered alternatively as adjoint primary.
0046 // The user can decide to consider/neglect some type of particle by
0047 // using the macro commands "/adjoint/ConsiderAsPrimary" and
0048 // "/adjoint/NeglectAsPrimary". If  an adjoint primary or its secondary
0049 // has reached the external surface, in the next event a fwd primary
0050 // particle equivalent to the last generated adjoint primary is
0051 // generated with the same position, energy but opposite direction
0052 // and the forward tracking phase starts.
0053 
0054 // --------------------------------------------------------------------
0055 //   Class Name:     G4AdjointPrimaryGeneratorAction
0056 //       Author:     L. Desorgher, 2007-2009
0057 // Organisation:     SpaceIT GmbH
0058 //     Contract:     ESA contract 21435/08/NL/AT
0059 //     Customer:     ESA/ESTEC
0060 // --------------------------------------------------------------------
0061 #ifndef G4AdjointPrimaryGeneratorAction_hh
0062 #define G4AdjointPrimaryGeneratorAction_hh 1
0063 
0064 #include "G4ThreeVector.hh"
0065 #include "G4VUserPrimaryGeneratorAction.hh"
0066 #include "globals.hh"
0067 
0068 #include <iterator>
0069 #include <map>
0070 #include <vector>
0071 
0072 class G4AdjointPosOnPhysVolGenerator;
0073 class G4ParticleGun;
0074 class G4Event;
0075 class G4AdjointPrimaryGenerator;
0076 class G4ParticleDefinition;
0077 
0078 // --------------------------------------------------------------------
0079 
0080 class G4AdjointPrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction
0081 {
0082   public:
0083     G4AdjointPrimaryGeneratorAction();
0084     ~G4AdjointPrimaryGeneratorAction() override;
0085 
0086     G4AdjointPrimaryGeneratorAction(const G4AdjointPrimaryGeneratorAction&) = delete;
0087     G4AdjointPrimaryGeneratorAction& operator=(const G4AdjointPrimaryGeneratorAction&) = delete;
0088 
0089     void GeneratePrimaries(G4Event*) override;
0090     void SetEmin(G4double val);
0091     void SetEmax(G4double val);
0092     void SetEminIon(G4double val);
0093     void SetEmaxIon(G4double val);
0094     void SetSphericalAdjointPrimarySource(G4double radius, G4ThreeVector pos);
0095     void SetAdjointPrimarySourceOnAnExtSurfaceOfAVolume(const G4String& volume_name);
0096     void ConsiderParticleAsPrimary(const G4String& particle_name);
0097     void NeglectParticleAsPrimary(const G4String& particle_name);
0098     void SetPrimaryIon(G4ParticleDefinition* adjointIon, G4ParticleDefinition* fwdIon);
0099     void UpdateListOfPrimaryParticles();
0100 
0101     inline void SetRndmFlag(const G4String& val) { rndmFlag = val; }
0102     inline size_t GetNbOfAdjointPrimaryTypes() { return ListOfPrimaryAdjParticles.size(); }
0103     inline std::vector<G4ParticleDefinition*>* GetListOfPrimaryFwdParticles()
0104     {
0105       return &ListOfPrimaryFwdParticles;
0106     }
0107     inline const G4String& GetPrimaryIonName() { return ion_name; }
0108     inline void SetNbPrimaryFwdGammasPerEvent(G4int nb) { nb_fwd_gammas_per_event = nb; }
0109     inline void SetNbAdjointPrimaryGammasPerEvent(G4int nb)
0110     {
0111       nb_adj_primary_gammas_per_event = nb;
0112     }
0113     inline void SetNbAdjointPrimaryElectronsPerEvent(G4int nb)
0114     {
0115       nb_adj_primary_electrons_per_event = nb;
0116     }
0117     inline G4ParticleDefinition* GetLastGeneratedFwdPrimaryParticle()
0118     {
0119       return ListOfPrimaryFwdParticles[index_particle];
0120     }
0121 
0122   private:  // methods
0123     G4double ComputeEnergyDistWeight(G4double energy, G4double E1, G4double E2);
0124 
0125   private:  // attributes
0126     G4String rndmFlag;  // flag for a rndm impact point
0127 
0128     // The generator of primary vertex except for weight
0129     G4AdjointPrimaryGenerator* theAdjointPrimaryGenerator = nullptr;
0130 
0131     // Emin and Emax energies of the adjoint source
0132     //---------------------------------------------
0133     G4double Emin = 0.0;
0134     G4double Emax = 0.0;
0135     G4double EminIon = 0.0;
0136     G4double EmaxIon = 0.0;
0137 
0138     // List of type of primary adjoint and forward  particle used in the
0139     // simulation
0140     //------------------------------------------------------------------
0141     std::vector<G4ParticleDefinition*> ListOfPrimaryFwdParticles;
0142     std::vector<G4ParticleDefinition*> ListOfPrimaryAdjParticles;
0143     std::map<G4String, G4bool> PrimariesConsideredInAdjointSim;
0144     // if true considered if false not considered
0145 
0146     std::size_t index_particle = 100000;
0147 
0148     G4ThreeVector pos, direction, p;
0149 
0150     G4String type_of_adjoint_source;  // Spherical ExtSurfaceOfAVolume
0151     G4double radius_spherical_source = 0.0;
0152     G4ThreeVector center_spherical_source;
0153     G4int nb_fwd_gammas_per_event = 1;
0154     G4int nb_adj_primary_gammas_per_event = 1;
0155     G4int nb_adj_primary_electrons_per_event = 1;
0156 
0157     // For simulation with ions
0158     //--------------------------
0159     G4ParticleDefinition* fwd_ion = nullptr;
0160     G4ParticleDefinition* adj_ion = nullptr;
0161     G4String ion_name = "not_defined";
0162 };
0163 
0164 #endif