Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:11

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