Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:16:09

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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0028 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0029 
0030 #include "PrimaryGeneratorAction.hh"
0031 
0032 #include "PrimaryGeneratorMessenger.hh"
0033 #include "DetectorConstruction.hh"
0034 
0035 #include "G4SystemOfUnits.hh"
0036 #include "G4Event.hh"
0037 #include "G4ParticleGun.hh"
0038 #include "G4ParticleTable.hh"
0039 #include "G4ParticleDefinition.hh"
0040 #include "Randomize.hh"
0041 
0042 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0043 
0044 PrimaryGeneratorAction::PrimaryGeneratorAction(DetectorConstruction* det)
0045 :Detector(det)
0046 {
0047   G4int n_particle = 1;
0048   particleGun  = new G4ParticleGun(n_particle);
0049   SetDefaultKinematic();
0050   beam = 0.*mm;
0051   
0052   //create a messenger for this class
0053   gunMessenger = new PrimaryGeneratorMessenger(this);
0054 }
0055 
0056 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0057 
0058 PrimaryGeneratorAction::~PrimaryGeneratorAction()
0059 {
0060   delete particleGun;
0061   delete gunMessenger;
0062 }
0063 
0064 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0065 
0066 void PrimaryGeneratorAction::SetDefaultKinematic()
0067 {
0068   G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
0069   G4String particleName;
0070   G4ParticleDefinition* particle
0071                     = particleTable->FindParticle(particleName="e-");
0072   particleGun->SetParticleDefinition(particle);
0073   particleGun->SetParticleMomentumDirection(G4ThreeVector(1.,0.,0.));
0074   particleGun->SetParticleEnergy(1.*GeV);
0075   G4double position = -0.5*(Detector->GetWorldSizeX());
0076   particleGun->SetParticlePosition(G4ThreeVector(position,0.*mm,0.*mm));
0077 }
0078 
0079 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0080 
0081 void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
0082 {
0083   //this function is called at the begining of event
0084   //
0085   //randomize beam, if requested.
0086   //
0087   if (beam > 0.) 
0088     {
0089       G4ThreeVector position = particleGun->GetParticlePosition();    
0090       G4double maxYZ = 0.49*(Detector->GetCalorSizeYZ());
0091       G4double x0 = position.x();
0092       G4double y0 = position.y() + (G4UniformRand()-0.5)*beam;
0093       G4double z0 = position.z() + (G4UniformRand()-0.5)*beam;
0094       if (std::abs(y0) > maxYZ) y0 = maxYZ;
0095       if (std::abs(z0) > maxYZ) z0 = maxYZ;      
0096       particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
0097       particleGun->GeneratePrimaryVertex(anEvent);
0098       particleGun->SetParticlePosition(position);      
0099     }
0100   else  particleGun->GeneratePrimaryVertex(anEvent);
0101 }
0102 
0103 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0104