Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:22:34

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 // This example is provided by the Geant4-DNA collaboration
0027 // Any report or published results obtained using the Geant4-DNA software 
0028 // shall cite the following Geant4-DNA collaboration publication:
0029 // Med. Phys. 37 (2010) 4692-4708
0030 // The Geant4-DNA web site is available at http://geant4-dna.org
0031 // 
0032 // If you use this example, please cite the following publication:
0033 // Rad. Prot. Dos. 133 (2009) 2-11
0034 //
0035 #include "PrimaryGeneratorAction.hh"
0036 #include "G4SystemOfUnits.hh"
0037 #include "G4Event.hh"
0038 #include "G4ParticleTable.hh"
0039 #include "Randomize.hh"
0040 
0041 PrimaryGeneratorAction::PrimaryGeneratorAction()
0042 {
0043   fParticleGun  = new G4ParticleGun(1);
0044 }
0045 
0046 PrimaryGeneratorAction::~PrimaryGeneratorAction()
0047 {
0048   delete fParticleGun;
0049 }
0050 
0051 void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
0052 {
0053   G4int numEvent;
0054   numEvent=anEvent->GetEventID()+1;
0055   G4double x0,y0,z0,theta,phi,xMom0,yMom0,zMom0,e0;
0056 
0057   // INITIAL BEAM POSITION
0058   
0059   z0=-10000*mm;
0060   x0=10*mm;
0061   y0=10*mm;
0062 
0063   G4double sizeMax = 0.5*micrometer; // INITIAL BEAM POSITION UNIFORMLY SPREAD ON A DISK
0064   while (! (std::sqrt(x0*x0+y0*y0)<= sizeMax) )
0065   {
0066     x0 = CLHEP::RandFlat::shoot(-sizeMax,sizeMax);
0067     y0 = CLHEP::RandFlat::shoot(-sizeMax,sizeMax);
0068   }
0069   
0070   // INITIAL BEAM ENERGY
0071   
0072   e0= G4RandGauss::shoot(3*MeV,5.0955e-5*MeV); // AIFIRA ENERGY RESOLUTION
0073 
0074   // INITIAL BEAM DIVERGENCE
0075 
0076   do {
0077        theta=std::acos(1-G4UniformRand()*(1.0-std::cos(1.1e-6)))*rad;
0078      } 
0079   while(theta>1.1e-6*rad);
0080 
0081   phi=CLHEP::twopi*G4UniformRand()*rad;
0082 
0083   xMom0=std::sin(theta)*std::cos(phi);
0084   yMom0=std::sin(theta)*std::sin(phi);
0085   zMom0=std::cos(theta);
0086 
0087   // VERBOSE
0088   
0089   G4cout 
0090   << "-> Event # " << numEvent 
0091   << " generated " 
0092   << G4endl;
0093   
0094 /*
0095   G4cout 
0096   << "-> Event # " << numEvent 
0097   << " : THETA from Z axis (mrad) = " << theta*1000 
0098   << " -- PHI (deg) = " << phi*180/CLHEP::pi 
0099   << " -- x0 (um) = " << x0/micrometer 
0100   << " -- y0 (um) = " << y0/micrometer 
0101   << " -- z0 (m) = " << z0/m 
0102   << " -- e0 (MeV) = " << e0/MeV 
0103   << G4endl;
0104 */
0105 
0106   fParticleGun->SetParticleEnergy(e0);
0107 
0108   fParticleGun->SetParticleMomentumDirection(G4ThreeVector(xMom0,yMom0,zMom0));
0109 
0110   fParticleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
0111   
0112   G4ParticleDefinition* particle=
0113     G4ParticleTable::GetParticleTable()->FindParticle("alpha");
0114   
0115   fParticleGun->SetParticleDefinition(particle);
0116   
0117   fParticleGun->GeneratePrimaryVertex(anEvent);
0118 
0119 }