Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:20:21

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 // Code developed by
0027 // Silvia Pozzi (1), silvia.pozzi@iss.it
0028 // Barbara Caccia (1), barbara.caccia@iss.it
0029 // Carlo Mancini Terracciano (2), carlo.mancini.terracciano@roma1.infn.it
0030 // (1) Istituto Superiore di Sanita' and INFN Roma, Italy
0031 // (2) Univ. La Sapienza and INFN Roma, Italy
0032 
0033 #include "DetectorConstruction.hh"
0034 #include "PrimaryGeneratorAction.hh"
0035 #include "PrimaryGeneratorMessenger.hh"
0036 
0037 #include <G4ParticleTable.hh>
0038 #include <G4Event.hh>
0039 #include <G4SystemOfUnits.hh>
0040 #include <G4ParticleGun.hh>
0041 #include <G4GeneralParticleSource.hh>
0042 #include <Randomize.hh>
0043 #include <G4RunManager.hh>
0044 #include <G4PhysicalConstants.hh>
0045 
0046 using namespace std;
0047 
0048 PrimaryGeneratorAction::PrimaryGeneratorAction()
0049 : fGun(nullptr),
0050   gunRadius(0), gunMeanEnergy(0), gunStdEnergy(0),
0051   energy(0),
0052   particle(nullptr)
0053 {
0054   priGenMessenger = new PrimaryGeneratorMessenger(this);  
0055   G4int n_particle = 1;
0056   fGun = new G4ParticleGun(n_particle);
0057 }
0058 
0059 PrimaryGeneratorAction::~PrimaryGeneratorAction()
0060 {
0061     delete priGenMessenger;
0062     delete fGun;
0063 }
0064 
0065 void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
0066 {
0067   GenerateFromRandom();
0068   
0069   fGun -> SetParticlePosition(position);
0070   fGun -> SetParticleMomentumDirection((G4ParticleMomentum)direction);
0071   fGun -> SetParticleEnergy(energy * MeV);
0072   fGun -> SetParticleDefinition(particle);
0073   // create vertex with previous specifications
0074   fGun -> GeneratePrimaryVertex(anEvent);
0075 }
0076 
0077 void PrimaryGeneratorAction::GenerateFromRandom()
0078 {
0079   DetectorConstruction* detector = (DetectorConstruction*)
0080     G4RunManager::GetRunManager() -> GetUserDetectorConstruction();
0081   
0082   G4double zPos = -(detector -> GetAccOriginPosition()) - 5.*mm; // 5mm before the target disk
0083   G4double alpha, rho, phi, sinTheta, cosTheta;
0084   
0085   sinTheta = G4RandGauss::shoot(0., 0.003);
0086   cosTheta = sqrt(1-sinTheta*sinTheta);
0087   phi = twopi * G4UniformRand();
0088   rho = gunRadius * G4UniformRand();
0089   alpha = twopi * G4UniformRand();
0090   
0091   particle = G4ParticleTable::GetParticleTable()->FindParticle("e-");
0092   direction = {sinTheta * cos(phi), sinTheta * sin(phi), cosTheta};
0093   position = {rho * sin(alpha), rho * cos(alpha), zPos};
0094   energy = G4RandGauss::shoot(gunMeanEnergy, gunStdEnergy);
0095 }
0096 
0097 void PrimaryGeneratorAction::SetGunRadius(G4double value)
0098 {
0099   gunRadius = value;
0100 }
0101 
0102 void PrimaryGeneratorAction::SetGunMeanEnergy(G4double value)
0103 {
0104   gunMeanEnergy = value;
0105 }
0106 
0107 void PrimaryGeneratorAction::SetGunStdEnergy(G4double value)
0108 {
0109   gunStdEnergy = value;
0110 }