G4NeutronHPField.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 // neutron_hp -- source file
00027 // J.P. Wellisch, Nov-1996
00028 // A prototype of the low energy neutron transport model.
00029 //
00030 #include "G4NeutronHPField.hh"
00031 #include "G4HadronicException.hh"
00032 #include "G4ios.hh"
00033 
00034 
00035   G4NeutronHPField::G4NeutronHPField()
00036   {
00037     theData = new G4NeutronHPFieldPoint[100]; 
00038     nPoints=100;
00039     nEntries=0;
00040     theData->SetData(0,0,0);
00041   }
00042   
00043   G4NeutronHPField::~G4NeutronHPField(){ delete [] theData;}
00044   
00045   G4double G4NeutronHPField::GetY(G4double e, G4int j)
00046   {
00047     G4int low   = 0;
00048     G4int high  = 0;
00049     G4int i;
00050     for (i=1; i<nEntries/10; i++)
00051     {
00052       if(theData[10*i].GetX()>e) break;
00053     }
00054     if(i==(nEntries/10))
00055     {
00056       i=10*i;
00057       while (i<nEntries)
00058       {
00059         if(theData[i++].GetX()>e) break;
00060       } 
00061       if (i==nEntries)
00062       {
00063         low  = nEntries-1;
00064         high = nEntries-2;
00065       }else{
00066         low = i-1;
00067         high = i;
00068       }
00069     }else{
00070       for (G4int jj=0; jj<10; jj++)
00071       {
00072         if(theData[i].GetX()<e) break;
00073         i--;
00074       }
00075       low = i;
00076       high = i+1;
00077     }
00078     G4double x1, x2, y1, y2, x, y;
00079     x = e;
00080     x1 = theData[low] .GetX();
00081     x2 = theData[high].GetX();
00082     y1 = theData[low] .GetY(j);
00083     y2 = theData[high].GetY(j);
00084     y = x*(y2-y1)/(x2-x1);
00085     return y += y2-x2*(y2-y1)/(x2-x1);
00086   }
00087 
00088   void G4NeutronHPField::Dump()
00089   {
00090     G4cout << nEntries<<G4endl;
00091     for(G4int i=0; i<nEntries; i++)
00092     {
00093       G4cout << theData[i].GetX()<<" ";
00094       for(G4int j=0; j<theData[i].GetDepth(); j++)
00095       {
00096         G4cout << theData[i].GetY(j)<<" ";
00097       }
00098       G4cout << G4endl;
00099     }
00100   }
00101   
00102   void G4NeutronHPField::Check(G4int i)
00103   {
00104     if(i>nEntries) throw G4HadronicException(__FILE__, __LINE__, "Skipped some index numbers in G4NeutronHPField");
00105     if(i==nPoints)
00106     {
00107       nPoints += 50;
00108       G4NeutronHPFieldPoint * buff = new G4NeutronHPFieldPoint[nPoints];
00109 //      G4cout << "copying 1"<<G4endl;
00110       for (G4int j=0; j<nEntries; j++) 
00111       {
00112         buff[j] = theData[j];
00113       }
00114 //      G4cout << "copying 2"<<G4endl;
00115       delete [] theData;
00116       theData = buff;
00117     }
00118     if(i==nEntries) nEntries=i+1;
00119   }

Generated on Mon May 27 17:49:01 2013 for Geant4 by  doxygen 1.4.7