Back to home page

EIC code displayed by LXR

 
 

    


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

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 medical/fanoCavity/src/MyKleinNishinaCompton.cc
0027 /// \brief Implementation of the MyKleinNishinaCompton class
0028 //
0029 //
0030 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0031 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0032 
0033 #include "MyKleinNishinaCompton.hh"
0034 
0035 #include "DetectorConstruction.hh"
0036 #include "MyKleinNishinaMessenger.hh"
0037 
0038 #include "G4DataVector.hh"
0039 #include "G4Electron.hh"
0040 #include "G4Gamma.hh"
0041 #include "G4ParticleChangeForGamma.hh"
0042 #include "G4PhysicalConstants.hh"
0043 #include "Randomize.hh"
0044 
0045 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0046 
0047 using namespace std;
0048 
0049 MyKleinNishinaCompton::MyKleinNishinaCompton(DetectorConstruction* det, const G4ParticleDefinition*,
0050                                              const G4String& nam)
0051   : G4KleinNishinaCompton(0, nam), fDetector(det), fMessenger(0)
0052 {
0053   fCrossSectionFactor = 1.;
0054   fMessenger = new MyKleinNishinaMessenger(this);
0055 }
0056 
0057 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0058 
0059 MyKleinNishinaCompton::~MyKleinNishinaCompton()
0060 {
0061   delete fMessenger;
0062 }
0063 
0064 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0065 
0066 G4double MyKleinNishinaCompton::CrossSectionPerVolume(const G4Material* mat,
0067                                                       const G4ParticleDefinition* part,
0068                                                       G4double GammaEnergy, G4double, G4double)
0069 {
0070   G4double xsection = G4VEmModel::CrossSectionPerVolume(mat, part, GammaEnergy);
0071 
0072   return xsection * fCrossSectionFactor;
0073 }
0074 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0075 
0076 void MyKleinNishinaCompton::SampleSecondaries(std::vector<G4DynamicParticle*>* fvect,
0077                                               const G4MaterialCutsCouple*,
0078                                               const G4DynamicParticle* aDynamicGamma, G4double,
0079                                               G4double)
0080 {
0081   // The scattered gamma energy is sampled according to Klein - Nishina formula.
0082   // The random number techniques of Butcher & Messel are used
0083   // (Nuc Phys 20(1960),15).
0084   // Note : Effects due to binding of atomic electrons are negliged.
0085 
0086   G4double gamEnergy0 = aDynamicGamma->GetKineticEnergy();
0087   G4double E0_m = gamEnergy0 / electron_mass_c2;
0088 
0089   G4ThreeVector gamDirection0 = aDynamicGamma->GetMomentumDirection();
0090 
0091   //
0092   // sample the energy rate of the scattered gamma
0093   //
0094 
0095   G4double epsilon, epsilonsq, onecost, sint2, greject;
0096 
0097   G4double eps0 = 1. / (1. + 2. * E0_m);
0098   G4double eps0sq = eps0 * eps0;
0099   G4double alpha1 = -log(eps0);
0100   G4double alpha2 = 0.5 * (1. - eps0sq);
0101 
0102   do {
0103     if (alpha1 / (alpha1 + alpha2) > G4UniformRand()) {
0104       epsilon = exp(-alpha1 * G4UniformRand());  // eps0**r
0105       epsilonsq = epsilon * epsilon;
0106     }
0107     else {
0108       epsilonsq = eps0sq + (1. - eps0sq) * G4UniformRand();
0109       epsilon = sqrt(epsilonsq);
0110     };
0111 
0112     onecost = (1. - epsilon) / (epsilon * E0_m);
0113     sint2 = onecost * (2. - onecost);
0114     greject = 1. - epsilon * sint2 / (1. + epsilonsq);
0115 
0116   } while (greject < G4UniformRand());
0117 
0118   //
0119   // scattered gamma angles. ( Z - axis along the parent gamma)
0120   //
0121 
0122   G4double cosTeta = 1. - onecost;
0123   G4double sinTeta = sqrt(sint2);
0124   G4double Phi = twopi * G4UniformRand();
0125   G4double dirx = sinTeta * cos(Phi), diry = sinTeta * sin(Phi), dirz = cosTeta;
0126 
0127   //
0128   // update G4VParticleChange for the scattered gamma
0129   //
0130   // beam regeneration trick : restore incident beam
0131 
0132   G4ThreeVector gamDirection1(dirx, diry, dirz);
0133   gamDirection1.rotateUz(gamDirection0);
0134   G4double gamEnergy1 = epsilon * gamEnergy0;
0135   fParticleChange->SetProposedKineticEnergy(gamEnergy0);
0136   fParticleChange->ProposeMomentumDirection(gamDirection0);
0137 
0138   //
0139   // kinematic of the scattered electron
0140   //
0141 
0142   G4double eKinEnergy = gamEnergy0 - gamEnergy1;
0143 
0144   if (eKinEnergy > DBL_MIN) {
0145     G4ThreeVector eDirection = gamEnergy0 * gamDirection0 - gamEnergy1 * gamDirection1;
0146     eDirection = eDirection.unit();
0147 
0148     // create G4DynamicParticle object for the electron.
0149     G4DynamicParticle* dp = new G4DynamicParticle(theElectron, eDirection, eKinEnergy);
0150     fvect->push_back(dp);
0151   }
0152 }
0153 
0154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......