G4AngularDistributionNP.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 #include "G4AngularDistributionNP.hh"
00027 #include "G4PhysicalConstants.hh"
00028 #include "G4SystemOfUnits.hh"
00029 #include "Randomize.hh"
00030 #include "G4ios.hh"
00031 
00032 // Initialization of static data arrays:
00033 #include "G4AngularDistributionNPData.hh"
00034 #include "Randomize.hh"
00035 
00036 
00037 G4double G4AngularDistributionNP::CosTheta(G4double S, G4double m_1, G4double m_2) const
00038 {
00039     G4int verboseLevel=1;
00040 
00041     G4double ek= ((S - sqr(m_1) -sqr(m_2) )/(2*m_1) - m_1 )/GeV   ;    // kinetic energy in GeV
00042 
00043     // Find energy bin
00044 
00045     G4int je1 = 0;
00046     G4int je2 = NENERGY - 1;
00047     do {
00048       G4int midBin = (je1 + je2)/2;
00049       if (ek < elab[midBin])
00050         je2 = midBin;
00051       else
00052         je1 = midBin;
00053     } while (je2 - je1 > 1);
00054     //    G4int j;
00055     //std::abs(ek-elab[je1]) < std::abs(ek-elab[je2]) ? j = je1 : j = je2;
00056     G4double delab = elab[je2] - elab[je1];
00057 
00058     // Sample the angle
00059 
00060     G4float sample = G4UniformRand();
00061     G4int ke1 = 0;
00062     G4int ke2 = NANGLE - 1;
00063     G4double dsig = sig[je2][0] - sig[je1][0];
00064     G4double rc = dsig/delab;
00065     G4double b = sig[je1][0] - rc*elab[je1];
00066     G4double sigint1 = rc*ek + b;
00067     G4double sigint2 = 0.;
00068 
00069     if (verboseLevel > 1) G4cout << "sample=" << sample << G4endl
00070                                  << ek << " " << ke1 << " " << ke2 << " "
00071                                  << sigint1 << " " << sigint2 << G4endl;
00072 
00073     do {
00074       G4int midBin = (ke1 + ke2)/2;
00075       dsig = sig[je2][midBin] - sig[je1][midBin];
00076       rc = dsig/delab;
00077       b = sig[je1][midBin] - rc*elab[je1];
00078       G4double sigint = rc*ek + b;
00079       if (sample < sigint) {
00080         ke2 = midBin;
00081         sigint2 = sigint;
00082       }
00083       else {
00084         ke1 = midBin;
00085         sigint1 = sigint;
00086       }
00087       if (verboseLevel > 1)G4cout << ke1 << " " << ke2 << " "
00088                                   << sigint1 << " " << sigint2 << G4endl;
00089     } while (ke2 - ke1 > 1);
00090 
00091     // sigint1 and sigint2 should be recoverable from above loop
00092 
00093     //    G4double dsig = sig[je2][ke1] - sig[je1][ke1];
00094     //    G4double rc = dsig/delab;
00095     //    G4double b = sig[je1][ke1] - rc*elab[je1];
00096     //    G4double sigint1 = rc*ek + b;
00097 
00098     //    G4double dsig = sig[je2][ke2] - sig[je1][ke2];
00099     //    G4double rc = dsig/delab;
00100     //    G4double b = sig[je1][ke2] - rc*elab[je1];
00101     //    G4double sigint2 = rc*ek + b;
00102 
00103     dsig = sigint2 - sigint1;
00104     rc = 1./dsig;
00105     b = ke1 - rc*sigint1;
00106     G4double kint = rc*sample + b;
00107     G4double theta = (0.5 + kint)*pi/180.;
00108 
00109     //    G4int k;
00110     //std::abs(sample-sig[j][ke1]) < std::abs(sample-sig[j][ke2]) ? k = ke1 : k = ke2;
00111     //    G4double theta = (0.5 + k)*pi/180.;
00112 
00113     if (verboseLevel > 1) {
00114       G4cout << "   energy bin " << je1 << " energy=" << elab[je1] << G4endl;
00115       G4cout << "   angle bin " << kint << " angle=" << theta/degree << G4endl;
00116     }
00117     G4double costh= std::cos(theta);
00118     return costh;
00119 }
00120 
00121 G4double G4AngularDistributionNP::Phi() const
00122 {
00123     return twopi * G4UniformRand();
00124 }

Generated on Mon May 27 17:47:39 2013 for Geant4 by  doxygen 1.4.7