Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:20:36

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 /// \file XrayTESdetPrimaryGeneratorAction.cc
0028 /// \brief Implementation of the PrimaryGeneratorAction class
0029 //
0030 // Authors: P.Dondero (paolo.dondero@cern.ch), R.Stanzani (ronny.stanzani@cern.ch)
0031 //
0032 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0033 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0034 
0035 
0036 #include "XrayTESdetPrimaryGeneratorAction.hh"
0037 #include "XrayTESdetDetectorConstruction.hh"
0038 
0039 #include "G4Event.hh"
0040 #include "G4ParticleGun.hh"
0041 #include "G4ThreeVector.hh"
0042 #include "G4ParticleTable.hh"
0043 #include "G4ParticleDefinition.hh"
0044 #include "Randomize.hh"
0045 #include "globals.hh"
0046 #include "G4NistManager.hh"
0047 #include "G4SystemOfUnits.hh"
0048 #include "G4PhysicalConstants.hh"
0049 
0050 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0051 
0052 XrayTESdetPrimaryGeneratorAction::XrayTESdetPrimaryGeneratorAction()
0053 {
0054   G4int n_particle = 1;
0055   fParticleGun = new G4ParticleGun(n_particle);
0056   G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
0057   G4String particleName;
0058 
0059   // setting particle type
0060    fParticleGun->SetParticleDefinition(particleTable->FindParticle(particleName="proton"));
0061 }
0062 
0063 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0064 
0065 XrayTESdetPrimaryGeneratorAction::~XrayTESdetPrimaryGeneratorAction()
0066 {
0067   delete fParticleGun;
0068 }
0069 
0070 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0071 
0072 void XrayTESdetPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
0073 {
0074   G4double ax;
0075   G4double ay;
0076   G4double az;
0077 
0078   G4double bx;
0079   G4double by;
0080   G4double bz;
0081 
0082   G4double vx;
0083   G4double vy;
0084   G4double vz;
0085 
0086   G4double energy = 0;
0087   G4double u;
0088   G4double u1;
0089 
0090   G4double theta0;
0091   G4double phi0;
0092   G4double theta1;
0093   G4double phi1;
0094 
0095   G4double ene;
0096   G4double flux;
0097   G4double r;
0098 
0099   // Radius to shot particles
0100     r = 27*cm;
0101 
0102   // Proton flux @L2 (Pamela2009), in p/cm2/s/sr [10 MeV - 10 GeV] = 0.407
0103   G4double phi = 0.379;
0104   G4double tr = 0.938;
0105   G4double T;
0106 
0107   while (true)
0108   {
0109     u = G4UniformRand();
0110     u1 = 0.268*G4UniformRand();      //max of the flux, in particles/cm2-s-GeV-sr
0111     ene = 10.*MeV + u*100000.*MeV;
0112     T = ene*0.001;
0113     flux = 1.9*std::pow(((T + phi)*(T + phi + 2*tr)), -1.39)*T*(T + 2*tr)/((1 + 0.4866*std::pow(((T + phi)*(T + phi + 2*tr)),-1.255))*(T + phi)*(T + phi + 2*tr));
0114     if (u1 <= flux)
0115     {
0116       energy = ene;
0117       break;
0118     }
0119   }
0120 
0121   theta0 = std::acos(1. - 2.*G4UniformRand());
0122   theta1 = std::acos(1. - 2.*G4UniformRand());
0123   phi0 = twopi*G4UniformRand();
0124   phi1 = twopi*G4UniformRand();
0125   ax = r*std::sin(theta0)*std::cos(phi0);
0126   ay = r*std::sin(theta0)*std::sin(phi0);
0127   az = r*std::cos(theta0) + 80*mm;
0128 
0129   bx = r*std::sin(theta1)*std::cos(phi1);
0130   by = r*std::sin(theta1)*std::sin(phi1);
0131   bz = r*std::cos(theta1) + 80*mm;
0132   vx = bx - ax;
0133   vy = by - ay;
0134   vz = bz - az;
0135 
0136   fParticleGun->SetParticleEnergy(energy);
0137   fParticleGun->SetParticlePosition(G4ThreeVector(ax, ay, az));
0138   fParticleGun->SetParticleMomentumDirection(G4ThreeVector(vx,vy,vz));
0139   fParticleGun->GeneratePrimaryVertex(anEvent);
0140 }
0141 
0142 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......