Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 07:52:14

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 // gpaterno, October 2025
0027 //
0028 /// \file PrimaryGeneratorAction.cc
0029 /// \brief Implementation of the PrimaryGeneratorAction class
0030 //
0031 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0032 
0033 #include "PrimaryGeneratorAction.hh"
0034 
0035 #include "G4RunManager.hh"
0036 #include "G4Event.hh"
0037 
0038 #include "G4ParticleTable.hh"
0039 #include "G4ParticleDefinition.hh"
0040 
0041 #include "Randomize.hh"
0042 
0043 #include "G4GeneralParticleSource.hh"
0044 #include "G4ParticleGun.hh"
0045 
0046 #include "G4PhysicalConstants.hh"
0047 #include "G4SystemOfUnits.hh"
0048 #include "globals.hh"
0049 
0050 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0051 
0052 PrimaryGeneratorAction::PrimaryGeneratorAction()
0053 {
0054     //G4cout << "### PrimaryGeneratorAction instantiated ###" << G4endl;
0055     
0056     //instantiating the messenger
0057     fMessenger = new PrimaryGeneratorActionMessenger(this);
0058     
0059     //defining a Particle Gun
0060     G4int n_particle = 1;
0061     fGun = new G4ParticleGun(n_particle);
0062 
0063     //defining a GPS (used if fUseGPS==true)
0064     fGPS = new G4GeneralParticleSource(); 
0065     
0066     //default particle
0067     G4ParticleDefinition* particle = 
0068         G4ParticleTable::GetParticleTable()->FindParticle(fType);
0069     
0070     //set default values for GPS
0071     //Primary particles
0072     fGPS->SetParticleDefinition(particle);    
0073     //Position distribution
0074     G4SPSPosDistribution* vPosDist = 
0075         fGPS->GetCurrentSource()->GetPosDist();
0076     vPosDist->SetPosDisType("Plane");
0077     vPosDist->SetPosDisShape("Circle");
0078     vPosDist->SetRadius(0.5*CLHEP::mm);   
0079     vPosDist->SetCentreCoords(G4ThreeVector(0., 0., -5*CLHEP::cm));
0080     //Angular distribution
0081     G4SPSAngDistribution* vAngDist = 
0082         fGPS->GetCurrentSource()->GetAngDist();
0083     vAngDist->SetParticleMomentumDirection(G4ThreeVector(0., 0., 1.));  
0084     //Energy distribution
0085     G4SPSEneDistribution* vEneDist = 
0086         fGPS->GetCurrentSource()->GetEneDist();
0087     vEneDist->SetEnergyDisType("Mono");
0088     vEneDist->SetMonoEnergy(fEnergy);
0089     
0090     //set default values for Particle Gun
0091     fGun->SetParticleDefinition(particle);
0092     fGun->SetParticleMomentumDirection(G4ThreeVector(0., 0., 1.));
0093     fGun->SetParticleEnergy(fEnergy);
0094 }
0095 
0096 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0097 
0098 PrimaryGeneratorAction::~PrimaryGeneratorAction()
0099 {
0100     delete fGPS;
0101     delete fGun;
0102 }
0103 
0104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0105 
0106 void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
0107 {
0108     if (fUseGPS) {
0109         fGPS->GeneratePrimaryVertex(anEvent); //override default through macro
0110     } else {              
0111         //particle position
0112         G4double x = G4RandGauss::shoot(fX, fSigmaX);
0113         G4double y = G4RandGauss::shoot(fY, fSigmaY);
0114         G4double z = G4RandGauss::shoot(fZ, fSigmaZ);
0115         fGun->SetParticlePosition(G4ThreeVector(x, y, z));
0116 
0117         //time, altrnative way to take into account the bunch length
0118         G4double t = fT;
0119         if (fSigmaT != 0 && fSigmaZ == 0) {
0120             t = G4RandGauss::shoot(fT, fSigmaT);
0121         }
0122         fGun->SetParticleTime(t);
0123         
0124         //particle Type
0125         G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
0126         fGun->SetParticleDefinition(particleTable->FindParticle(fType));
0127         
0128         //particle kinetic energy
0129         G4double K = G4RandGauss::shoot(fEnergy, fEnergy*fRelSigmaEnergy);
0130         fGun->SetParticleEnergy(K);   
0131            
0132         //particle direction      
0133         G4double xp = G4RandGauss::shoot(fXp, fSigmaXp); //xp=x'=px/pz=dx/dz
0134         G4double yp = G4RandGauss::shoot(fYp, fSigmaYp); //yp=y'=py/pz=dy/dz
0135         fGun->SetParticleMomentumDirection(G4ThreeVector(xp, yp, 1.)); //automatically norm.
0136                     
0137         //generate the vertex
0138         fGun->GeneratePrimaryVertex(anEvent);                 
0139     }
0140 }
0141 
0142 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0143