Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 07:51:38

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 
0027 
0028 #include "PrimaryGeneratorAction.hh"
0029 #include "PrimaryGeneratorMessenger.hh"
0030 #include "G4IAEAphspReader.hh"
0031 
0032 #include "globals.hh"
0033 #include "Randomize.hh"
0034 #include "G4SystemOfUnits.hh"
0035 #include "G4ParticleGun.hh"
0036 #include "G4ParticleTable.hh"
0037 #include "G4ParticleDefinition.hh"
0038 #include "G4Gamma.hh"
0039 #include "G4RunManager.hh"
0040 
0041 #include <vector>
0042 
0043 
0044 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0045 
0046 PrimaryGeneratorAction::PrimaryGeneratorAction(const G4int threads)
0047   :fThreads(threads)
0048 {
0049   fIAEAphspReaderName = "";
0050   fVerbose = 0;
0051   fMessenger = new PrimaryGeneratorMessenger(this);
0052   fParticleGun = new G4ParticleGun();
0053   fParticleGun->SetParticleDefinition(G4Gamma::Definition());
0054 
0055   fCounter = 0;
0056   fKinE = 50.0*MeV;
0057   fDE = 0.0;
0058   fX0 = 0.0;
0059   fY0 = 0.0;
0060   fZ0 = 0.0;
0061   fDX = 0.0;
0062   fDY = 0.0;
0063   fDZ = 0.0;
0064 }
0065 
0066 
0067 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0068 
0069 PrimaryGeneratorAction::~PrimaryGeneratorAction()
0070 {
0071   if (fVerbose > 0) G4cout << "Destroying PrimaryGeneratorAction" << G4endl;
0072   delete fParticleGun;
0073   delete fMessenger;
0074   
0075   if (fIAEAphspReader) delete fIAEAphspReader;
0076   if (fVerbose > 0) G4cout << "PrimaryGeneratorAction destroyed" << G4endl;
0077 }
0078 
0079 
0080 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0081 
0082 void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
0083 {
0084   if (fIAEAphspReader) {
0085     fIAEAphspReader->GeneratePrimaryVertex(anEvent);
0086   }
0087   
0088   else {
0089 
0090     fCounter++ ;
0091 
0092     // Simulation of beam kinetic energy
0093     G4double kinEnergy = fKinE;
0094     if(fDE > 0.0)
0095       kinEnergy = G4RandFlat::shoot(fKinE-fDE/2., fKinE+fDE/2.);
0096 
0097     fParticleGun->SetParticleEnergy(kinEnergy);
0098 
0099     // Simulation of beam position
0100     G4double x = fX0;
0101     G4double y = fY0;
0102     G4double z = fZ0;
0103     if (fDX > 0.0)
0104       x = G4RandFlat::shoot(fX0-fDX/2., fX0+fDX/2.);
0105     if (fDY > 0.0)
0106       y = G4RandFlat::shoot(fY0-fDY/2., fY0+fDY/2.);
0107     if (fDZ > 0.0)
0108       z = G4RandFlat::shoot(fZ0-fDZ/2., fZ0+fDZ/2.);
0109 
0110     fParticleGun->SetParticlePosition( G4ThreeVector(x,y,z) );
0111 
0112     // Simulation of beam direction
0113     G4double ux = 0.0;
0114     G4double uy = 0.0;
0115     G4double uz = 1.0;
0116 
0117     // Beam particles are randomly going upwards or downwards
0118     // This is done in order to let G4IAEAphspReader show how n_stat works
0119     if(G4UniformRand() < 0.5)
0120       uz = -uz;
0121 
0122     fParticleGun->SetParticleMomentumDirection( G4ThreeVector(ux,uy,uz) );
0123 
0124     if(fVerbose > 1) {
0125       G4ParticleDefinition* particle = fParticleGun->GetParticleDefinition();
0126       G4String particleName = particle->GetParticleName();
0127       G4cout << G4endl
0128          << "Event # " << fCounter
0129          << "  ParticleGun vertex:  "
0130          << "ParticleName = " << particleName
0131          << "   PDGcode = " << particle->GetPDGEncoding()
0132          << G4endl;
0133       G4cout << std::setprecision(6)
0134          << "\t\t KinEnergy (MeV) = " << kinEnergy/MeV
0135          << "   weight = " << fParticleGun->GetParticleWeight()
0136          << G4endl
0137          << "\t\t x (cm) = "  << x/cm
0138          << "  y (cm) = "   << y/cm
0139          << "  z (cm) = "   << z/cm
0140          << "    ux = " << ux << "  uy = " << uy << "  uz = " << uz
0141          << G4endl;
0142     }
0143 
0144     fParticleGun->GeneratePrimaryVertex(anEvent);
0145   }
0146 }
0147 
0148 
0149 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0150 
0151 void PrimaryGeneratorAction::SetIAEAphspReader(const G4String filename)
0152 {
0153   fIAEAphspReaderName = filename;
0154   fIAEAphspReader = new G4IAEAphspReader(filename, fThreads);
0155 }