G4CrossSectionBuffer.hh

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 #ifndef G4CrossSectionBuffer_h
00027 #define G4CrossSectionBuffer_h
00028 
00029 #include <utility>
00030 #include <vector>
00031 #include <CLHEP/Units/SystemOfUnits.h>
00032 
00033 #include "G4ParticleDefinition.hh"
00034 #include "globals.hh"
00035 
00036 class G4CrossSectionBuffer
00037 {
00038   public:
00039   
00040     G4CrossSectionBuffer(const G4ParticleDefinition * aA, const G4ParticleDefinition * aB)
00041     : theA(aA), theB(aB) {}
00042     
00043     G4bool InCharge(const G4ParticleDefinition * aA, const G4ParticleDefinition * aB) const
00044     {
00045       G4bool result = false;
00046       if(aA == theA)
00047       {
00048         if(aB == theB) result = true;
00049       }
00050       else if(aA == theB)
00051       {
00052         if(aB == theA) result = true;
00053       }
00054       return result;
00055     }
00056     
00057     void push_back(G4double S, G4double x)
00058     {
00059       std::pair<G4double, G4double> aNew;
00060       aNew.first = S;
00061       aNew.second = x;
00062       theData.push_back(aNew);
00063     }
00064     G4double CrossSection(const G4KineticTrack& trk1, const G4KineticTrack& trk2) const
00065     {
00066       G4double sqrts = (trk1.Get4Momentum()+trk2.Get4Momentum()).mag();
00067       G4double x1(1), y1(0);
00068       G4double x2(2), y2(0);
00069       
00070       if(theData.size()==1) return theData[theData.size()-1].second;
00071       
00072       for(size_t i=0; i<theData.size(); i++)
00073       {
00074         if(theData[i].first>sqrts)
00075         {
00076           if(0==i)
00077           {
00078             x1 = theData[i].first;
00079             y1 = theData[i].second;
00080             x2 = theData[i+1].first;
00081             y2 = theData[i+1].second;
00082           }
00083           else if(theData.size()-1==i)
00084           {
00085             x1 = theData[theData.size()-2].first;
00086             y1 = theData[theData.size()-2].second;
00087             x2 = theData[theData.size()-1].first;
00088             y2 = theData[theData.size()-1].second;
00089           }
00090           else
00091           {
00092             x1 = theData[i-1].first;
00093             y1 = theData[i-1].second;
00094             x2 = theData[i].first;
00095             y2 = theData[i].second;
00096           }
00097           break;
00098         }
00099       }
00100       // LINLIN interpolation
00101       // G4cerr << "!!!!!! "<<sqrts<<" "<<x1<<" "<<x2<<" "<<y1<<" "<<y2<<" "<<i<<G4endl;
00102       G4double result = y1 + (sqrts-x1) * (y2-y1)/(x2-x1);
00103       if(result<0) result = 0;
00104       if(y1<0.01*CLHEP::millibarn) result = 0;
00105       return result;
00106     }
00107     
00108     void Print()
00109     {
00110       for(size_t i=0;i<theData.size(); i++)
00111       {
00112         G4cerr << "sqrts = "<<theData[i].first<<", X = "<<theData[i].second/CLHEP::millibarn<<G4endl;
00113       }
00114     }
00115   
00116   private:
00117   std::vector<std::pair<G4double, G4double> > theData;
00118   
00119   const G4ParticleDefinition * theA;
00120   const G4ParticleDefinition * theB;
00121 };
00122 
00123 #endif

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