Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // neutron_hp -- source file 27 // J.P. Wellisch, Nov-1996 28 // A prototype of the low energy neutron transport model. 29 // 30 // P. Arce, June-2014 Conversion neutron_hp to particle_hp 31 // 32 #include "G4ParticleHPList.hh" 33 34 #include "G4HadronicException.hh" 35 36 #include <iomanip> 37 38 void G4ParticleHPList::Check(G4int i) 39 { 40 if (i < 0) { 41 throw G4HadronicException(__FILE__, __LINE__, 42 "G4ParticleHPList::Check(G4int) called with negative index"); 43 } 44 if (i > nEntries) 45 throw G4HadronicException(__FILE__, __LINE__, "Skipped some index numbers in G4ParticleHPList"); 46 if (i == nPoints) { 47 nPoints = static_cast<G4int>(1.5 * nPoints); 48 auto buff = new G4double[nPoints]; 49 for (G4int j = 0; j < nEntries; j++) 50 buff[j] = theData[j]; 51 delete[] theData; 52 theData = buff; 53 } 54 if (i == nEntries) nEntries++; 55 } 56 57 void G4ParticleHPList::Init(std::istream& aDataFile, G4int nPar, G4double unit) 58 { 59 G4int i; 60 G4double y; 61 for (i = 0; i < nPar; i++) { 62 aDataFile >> y; 63 SetValue(i, y * unit); 64 } 65 } 66 67 void G4ParticleHPList::Init(std::istream& aDataFile, G4double unit) 68 { 69 G4int total, i; 70 aDataFile >> total; 71 G4double y; 72 for (i = 0; i < total; i++) { 73 aDataFile >> y; 74 SetValue(i, y * unit); 75 } 76 } 77 78 G4double G4ParticleHPList::GetValue(G4int i) const 79 { 80 if (i < 0) i = 0; 81 if (i >= GetListLength()) i = GetListLength() - 1; 82 return theData[i]; 83 } 84 85 void G4ParticleHPList::Dump() 86 { 87 // store orginal precision 88 std::ios::fmtflags oldform = G4cout.flags(); 89 G4cout << std::setprecision(7) << std::setw(9) << theLabel << " " << theData[0] << " " 90 << theData[1] << G4endl; 91 // restore orginal precision 92 G4cout.flags(oldform); 93 } 94