[1199] | 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 | // |
---|
| 27 | // $Id: PhysicsTableTest.cc,v 1.6 2006/06/29 19:05:00 gunter Exp $ |
---|
[1315] | 28 | // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ |
---|
[1199] | 29 | // |
---|
| 30 | // |
---|
| 31 | // ---------------------------------------------------------------------- |
---|
| 32 | // |
---|
| 33 | // This program shows how to use the G4PhysicsTable and G4PhysicsVector. |
---|
| 34 | // |
---|
| 35 | |
---|
| 36 | #include "G4ios.hh" |
---|
| 37 | #include "G4PhysicsTable.hh" |
---|
| 38 | #include "G4PhysicsLinearVector.hh" |
---|
| 39 | #include "G4PhysicsLogVector.hh" |
---|
| 40 | #include <cmath> |
---|
| 41 | |
---|
| 42 | static const size_t PhysicsTableSize = 10; |
---|
| 43 | static const size_t PhysicsVectorSize = 10; |
---|
| 44 | |
---|
| 45 | int main() |
---|
| 46 | { |
---|
| 47 | |
---|
| 48 | // Create an empty G4PhysicsTable Object |
---|
| 49 | G4PhysicsTable* pPhysTable; |
---|
| 50 | pPhysTable = new G4PhysicsTable(); |
---|
| 51 | |
---|
| 52 | // reserve memory |
---|
| 53 | pPhysTable->reserve(PhysicsTableSize); |
---|
| 54 | |
---|
| 55 | // create PhysicsVectors and store them into the PhysicsTable |
---|
| 56 | G4PhysicsVector* pVector; |
---|
| 57 | G4double e_min = 0.0; |
---|
| 58 | G4double e_max = 1.0; |
---|
| 59 | size_t n_bin = PhysicsVectorSize; |
---|
| 60 | for (size_t i=0; i<PhysicsTableSize; i++){ |
---|
| 61 | pVector = new G4PhysicsLinearVector(e_min, e_max, n_bin); |
---|
| 62 | pVector->PutComment("PhysicsLinearVector"); |
---|
| 63 | |
---|
| 64 | // put values in PhysicsVector |
---|
| 65 | // value = std::sin(factor*energy) |
---|
| 66 | G4double factor = 0.1*G4double(i+1); |
---|
| 67 | for (size_t k=0; k<n_bin; k++){ |
---|
| 68 | G4double eVal = pVector->GetLowEdgeEnergy(k); |
---|
| 69 | pVector->PutValue(k, std::sin(factor*eVal)); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | // put PhysicsVector in PhysicsTable |
---|
| 73 | pPhysTable->push_back(pVector); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | // printout PhysicsTable |
---|
| 77 | // G4cout << *pPhysTable; |
---|
| 78 | |
---|
| 79 | // store PhysicsTable |
---|
| 80 | pPhysTable->StorePhysicsTable("testPhysTbleAscii.dat",true); |
---|
| 81 | |
---|
| 82 | // delete PhysicsTable |
---|
| 83 | pPhysTable->clearAndDestroy(); |
---|
| 84 | delete pPhysTable; |
---|
| 85 | |
---|
| 86 | // create empty PhysicsTable |
---|
| 87 | pPhysTable = new G4PhysicsTable(); |
---|
| 88 | |
---|
| 89 | // retrieve PhysicsTable |
---|
| 90 | pPhysTable->RetrievePhysicsTable("testPhysTbleAscii.dat",true); |
---|
| 91 | |
---|
| 92 | // printout PhysicsTable |
---|
| 93 | G4cout << *pPhysTable; |
---|
| 94 | |
---|
| 95 | // clear PhysicsTable |
---|
| 96 | pPhysTable->clearAndDestroy(); |
---|
| 97 | delete pPhysTable; |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | /////////////////////////////////////////////////////////// |
---|
| 101 | |
---|
| 102 | // create empty PhysicsTable |
---|
| 103 | pPhysTable = new G4PhysicsTable(); |
---|
| 104 | |
---|
| 105 | // create PhysicsVectors and store them into the PhysicsTable |
---|
| 106 | e_min = 0.1; |
---|
| 107 | e_max = 1.0e9; |
---|
| 108 | n_bin = PhysicsVectorSize; |
---|
| 109 | for (size_t j=0; j<PhysicsTableSize; j++){ |
---|
| 110 | pVector = new G4PhysicsLogVector(e_min, e_max, n_bin); |
---|
| 111 | pVector->PutComment("PhysicsLogVector"); |
---|
| 112 | |
---|
| 113 | // put values in PhysicsVector |
---|
| 114 | // value = std::log10(factor*energy) |
---|
| 115 | G4double factor = 0.1*G4double(j+1); |
---|
| 116 | for (size_t k=0; k<n_bin; k++){ |
---|
| 117 | G4double eVal = pVector->GetLowEdgeEnergy(k); |
---|
| 118 | pVector->PutValue(k, std::log10(factor*eVal)); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | // put PhysicsVector in PhysicsTable |
---|
| 122 | pPhysTable->push_back(pVector); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | // printout PhysicsTable |
---|
| 126 | // G4cout << *pPhysTable; |
---|
| 127 | |
---|
| 128 | // store PhysicsTable |
---|
| 129 | pPhysTable->StorePhysicsTable("testPhysTbleBin.dat"); |
---|
| 130 | |
---|
| 131 | // delete PhysicsTable |
---|
| 132 | pPhysTable->clearAndDestroy(); |
---|
| 133 | |
---|
| 134 | // retrieve PhysicsTable |
---|
| 135 | pPhysTable->RetrievePhysicsTable("testPhysTbleBin.dat"); |
---|
| 136 | |
---|
| 137 | // printout PhysicsTable |
---|
| 138 | G4cout << *pPhysTable; |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | return 0; |
---|
| 142 | } |
---|
| 143 | |
---|