Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-30 08:08:59

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