Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-18 08:32:33

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 /// \file PrimaryGeneratorAction.cc
0027 /// \brief Implementation of the PrimaryGeneratorAction class
0028 
0029 #include "PrimaryGeneratorAction.hh"
0030 
0031 #include "ChemistryWorld.hh"
0032 #include "DetectorConstruction.hh"
0033 
0034 #include "G4Electron.hh"
0035 #include "G4Event.hh"
0036 #include "G4ParticleDefinition.hh"
0037 #include "G4ParticleGun.hh"
0038 #include "G4ParticleTable.hh"
0039 #include "G4SystemOfUnits.hh"
0040 #include "G4RunManager.hh"
0041 
0042 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0043 
0044 PrimaryGeneratorAction::PrimaryGeneratorAction()
0045   : G4VUserPrimaryGeneratorAction()
0046 {
0047   fpMessenger = std::make_unique<PrimaryGeneratorMessenger>(this);
0048   fParticleGun = std::make_unique<G4SingleParticleSource>();
0049   G4ParticleDefinition* particle = G4Electron::Definition();
0050   fParticleGun->SetParticleDefinition(particle);
0051   fParticleGun->SetNumberOfParticles(1000000);  // by user
0052 
0053   auto pPosDist = fParticleGun->GetPosDist();
0054   pPosDist->SetPosDisType("Plane");
0055   pPosDist->SetPosDisShape("Square");
0056   const auto* fpDetector = dynamic_cast<const DetectorConstruction*>(
0057   G4RunManager::GetRunManager()->GetUserDetectorConstruction());
0058   auto faceSiez = fpDetector->GetChemistryWorld()->GetChemistryBoundary()->halfSideLengthInY();
0059   pPosDist->SetCentreCoords(G4ThreeVector(0, 0, -faceSiez));
0060   pPosDist->SetHalfX(faceSiez);
0061   pPosDist->SetHalfY(faceSiez);
0062 
0063   auto pAngleDist = fParticleGun->GetAngDist();
0064   pAngleDist->SetParticleMomentumDirection(G4ThreeVector(0., 0., 1.));
0065 
0066   auto pEnergyDis = fParticleGun->GetEneDist();
0067   pEnergyDis->SetMonoEnergy(0.9999 * MeV);
0068 }
0069 
0070 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
0071 
0072 void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
0073 {
0074   G4ParticleDefinition* particle = fParticleGun->GetParticleDefinition();
0075   auto NumberOfParticlesToBeGenerated = fParticleGun->GetNumberOfParticles();
0076   auto pPosDist = fParticleGun->GetPosDist();
0077   auto pAngleDist = fParticleGun->GetAngDist();
0078   auto pEnDist = fParticleGun->GetEneDist();
0079   auto rnd = fParticleGun->GetBiasRndm();
0080   auto charge = particle->GetPDGCharge();
0081 
0082   for (G4int i = 0; i < NumberOfParticlesToBeGenerated; i++) {
0083     auto angle = pAngleDist->GenerateOne();
0084     auto energy = pEnDist->GenerateOne(particle);
0085     auto pos = pPosDist->GenerateOne();
0086     auto mass = particle->GetPDGMass();
0087     auto p = new G4PrimaryParticle(particle);
0088     auto vertex = new G4PrimaryVertex(pos, 0);
0089     p->SetKineticEnergy(energy);
0090     p->SetMass(mass);
0091     p->SetMomentumDirection(angle);
0092     p->SetCharge(charge);
0093     p->SetPolarization(0., 0., 0.);
0094 
0095     G4double weight = pEnDist->GetWeight() * rnd->GetBiasWeight();
0096     p->SetWeight(weight);
0097     vertex->SetPrimary(p);
0098     anEvent->AddPrimaryVertex(vertex);
0099   }
0100 }
0101 
0102 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....