Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-31 07:50:08

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 //  =============== Begin Documentation Comments ===============
0029 //!
0030 //! \file       FFPrimaryGeneratorAction.cc
0031 //! \author     B. Wendt (brycen.linn.wendt@cern.ch)
0032 //! \date       June 06, 2014
0033 //!
0034 //! \brief      Implementation of the FFPrimaryGeneratorAction class
0035 //!
0036 //! \details    Generates 4.5 MeV neutrons from the solid volume defined in
0037 //!             FFDetectorConstruction as "NeturonSource" and shoots them off
0038 //!             in a isotropically sampled direction
0039 //!
0040 //  ================ End Documentation Comments ================
0041 //
0042 //  Modified:
0043 //
0044 //  23-06-14                                              BWendt
0045 //  Implemented "GetNeutronSourceCenter()" and added code to correctly sample
0046 //  the neutron starting location
0047 //
0048 // -------------------------------------------------------------
0049 
0050 #include "FFPrimaryGeneratorAction.hh"
0051 
0052 #include "G4Event.hh"
0053 #include "G4LogicalVolume.hh"
0054 #include "G4LogicalVolumeStore.hh"
0055 #include "G4Neutron.hh"
0056 #include "G4ParticleGun.hh"
0057 #include "G4PhysicalVolumeStore.hh"
0058 #include "G4SystemOfUnits.hh"
0059 #include "G4Tubs.hh"
0060 #include "G4VPhysicalVolume.hh"
0061 #include "Randomize.hh"
0062 #include "globals.hh"
0063 
0064 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0065 FFPrimaryGeneratorAction::FFPrimaryGeneratorAction()
0066   : G4VUserPrimaryGeneratorAction(),
0067 #ifndef NDEBUG
0068     fEventNumber(0),
0069 #endif  // NDEBUG
0070     fH2OPhysical(NULL),
0071     fNeutronPhysical(NULL),
0072     fNeutronSolid(NULL),
0073     fParticleGun(new G4ParticleGun(1)),
0074     fTankPhysical(NULL)
0075 {
0076   fParticleGun->SetParticleDefinition(G4Neutron::Definition());
0077   fParticleGun->SetParticleEnergy(4.5 * MeV);
0078 }
0079 
0080 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0081 void FFPrimaryGeneratorAction::GeneratePrimaries(G4Event* event)
0082 {
0083 #ifndef NDEBUG
0084   G4cout << "Shooting event " << ++fEventNumber << G4endl;
0085 #endif  // NDEBUG
0086   const G4ThreeVector sourceCenter = GetNeutronSourceCenter();
0087 
0088   // Sample the neutron source location
0089   const G4double radius = fNeutronSolid->GetOuterRadius();
0090   const G4double z = fNeutronSolid->GetZHalfLength() * 2;
0091   G4ThreeVector randomLocation;
0092   randomLocation.setRThetaPhi(radius * std::sqrt(G4UniformRand()), G4UniformRand() * 180 * deg, 0);
0093   randomLocation.setZ(z * (G4UniformRand() - 0.5));
0094   G4ThreeVector location(randomLocation.x() + sourceCenter.x(),
0095                          randomLocation.y() + sourceCenter.y(),
0096                          randomLocation.z() + sourceCenter.z());
0097 #ifndef NDEBUG
0098   G4cout << "Emission Location: r: " << location << G4endl;
0099 #endif  // NDEBUG
0100 
0101   // Sample the neutron emission direction
0102   G4ThreeVector direction;
0103   direction.setRThetaPhi(1.0, std::acos(G4UniformRand() * 2 - 1),
0104                          (G4UniformRand() * 2 - 1) * 180 * deg);
0105 #ifndef NDEBUG
0106   G4cout << "Emission Direction: r: " << direction << G4endl;
0107 #endif  // NDEBUG
0108 
0109   // Load the event
0110   fParticleGun->SetParticlePosition(location);
0111   fParticleGun->SetParticleMomentumDirection(direction);
0112   fParticleGun->GeneratePrimaryVertex(event);
0113 }
0114 
0115 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0116 G4ThreeVector FFPrimaryGeneratorAction::GetNeutronSourceCenter(void)
0117 {
0118   // Get the dimensions of the neutron source
0119   if (fNeutronSolid == NULL) {
0120     G4LogicalVolume* temp = G4LogicalVolumeStore::GetInstance()->GetVolume("NeutronSource");
0121     if (temp != NULL) {
0122       fNeutronSolid = dynamic_cast<G4Tubs*>(temp->GetSolid());
0123     }
0124 
0125     if (fNeutronSolid == NULL) {
0126       G4Exception(
0127         "FFPrimaryGeneratorAction::"
0128         "GeneratePrimaries(G4Event*)",
0129         "Neutron source solid volume not found", EventMustBeAborted, "This run will be aborted");
0130     }
0131   }
0132 
0133   // Get the position of the neutron source within the water
0134   if (fNeutronPhysical == NULL) {
0135     fNeutronPhysical = G4PhysicalVolumeStore::GetInstance()->GetVolume("NeutronSource");
0136   }
0137 
0138   if (fNeutronPhysical == NULL) {
0139     G4Exception("FFPrimaryGeneratorAction::GetNeutronSourceCenter(void)",
0140                 "Neutron source physical volume not found", EventMustBeAborted,
0141                 "This run will be aborted");
0142   }
0143 
0144   // Get the position of the water within the tank
0145   if (fH2OPhysical == NULL) {
0146     fH2OPhysical = G4PhysicalVolumeStore::GetInstance()->GetVolume("Tank_H2O");
0147 
0148     if (fH2OPhysical == NULL) {
0149       G4Exception(
0150         "FFPrimaryGeneratorAction::"
0151         "GetNeutronSourceCenter(void)",
0152         "Tank H2O physical volume not found", EventMustBeAborted, "This run will be aborted");
0153     }
0154   }
0155 
0156   // Get the position of the tank within the world
0157   if (fTankPhysical == NULL) {
0158     fTankPhysical = G4PhysicalVolumeStore::GetInstance()->GetVolume("Tank_Wall");
0159 
0160     if (fTankPhysical == NULL) {
0161       G4Exception(
0162         "FFPrimaryGeneratorAction::"
0163         "GetNeutronSourceCenter(void)",
0164         "Tank physical volume not found", EventMustBeAborted, "This run will be aborted");
0165     }
0166   }
0167 
0168   return fNeutronPhysical->GetTranslation() + fH2OPhysical->GetTranslation()
0169          + fTankPhysical->GetTranslation();
0170 }
0171 
0172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0173 FFPrimaryGeneratorAction::~FFPrimaryGeneratorAction()
0174 {
0175   delete fParticleGun;
0176 }