[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: G4DNACrossSectionDataSetTest.cc,v 1.2 2006/06/29 19:43:55 gunter Exp $ |
---|
| 28 | // GEANT4 tag $Name: geant4-09-03-cand-01 $ |
---|
| 29 | // |
---|
| 30 | // Author: Riccardo Capra <capra@ge.infn.it> |
---|
| 31 | // |
---|
| 32 | // History: |
---|
| 33 | // ----------- |
---|
| 34 | // 30 Jun 2005 RC Created |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | #include "G4DNACrossSectionDataSet.hh" |
---|
| 38 | #include "G4LogLogInterpolation.hh" |
---|
| 39 | #include <fstream> |
---|
| 40 | #include <unistd.h> |
---|
| 41 | |
---|
| 42 | #define EnergyUMIS 2 //eV |
---|
| 43 | #define DataUMIS 3 //barn |
---|
| 44 | |
---|
| 45 | int main(int argc, char **argv) |
---|
| 46 | { |
---|
| 47 | const char *inFile; |
---|
| 48 | |
---|
| 49 | if (argc>2) |
---|
| 50 | { |
---|
| 51 | G4cout << "Syntax: " << argv[0] << " [filename]" << G4endl; |
---|
| 52 | G4cout << G4endl; |
---|
| 53 | G4cout << "(!) NOTE: some files will be written in this directory (pattern: G4DNACrossSectionDataSetTestFile*.dat)" << G4endl; |
---|
| 54 | return 0; |
---|
| 55 | } |
---|
| 56 | else if (argc==2) |
---|
| 57 | inFile=argv[1]; |
---|
| 58 | else |
---|
| 59 | { |
---|
| 60 | inFile="G4DNACrossSectionDataSetTestFile"; |
---|
| 61 | std::ofstream out("./G4DNACrossSectionDataSetTestFile.dat"); |
---|
| 62 | out << "1.00000000e+05 8.14416702e+02 6.76315789e+02 4.88340749e+02 8.39880339e+01 7.89635115e-02 2.06314024e+03\n" |
---|
| 63 | "2.00000000e+05 5.28359350e+02 4.63221618e+02 3.44771389e+02 7.30146866e+01 2.52677590e-01 1.40961972e+03\n\n" |
---|
| 64 | " 3.00000000e+05 3.95840046e+02 3.53745700e+02 2.65748336e+02\t5.98188864e+01 4.09845238e-01 1.07556281e+03\n" |
---|
| 65 | "4.00000000e+05 3.19343880e+02 2.88487842e+02 2.17686875e+02 5.03590031e+01 5.32869987e-01 8.76410470e+02\r\n" |
---|
| 66 | "5.00000000e+05 2.69156735e+02 2.44940828e+02 1.85347963e+02 4.34715722e+01 6.24418579e-01 7.43541517e+02\n" |
---|
| 67 | "1.00000000e+06 1.55452794e+02 1.43970277e+02 1.09881243e+02 2.64352725e+01 8.10553505e-01 4.36550140e+02 \n" |
---|
| 68 | "1.50000000e+06 1.11668214e+02 1.04282494e+02 7.98560948e+01\t1.93490562e+01 8.14261386e-01 3.15970120e+02\n" |
---|
| 69 | "2.00000000e+06 8.80312507e+01 8.26279732e+01 6.33649352e+01 1.54081437e+01 7.71586134e-01 2.50203889e+02\n" |
---|
| 70 | " 2.50000000e+06 7.30696756e+01 6.88018974e+01 5.28437021e+01 1.28756775e+01 7.19674081e-01 2.08310627e+02\n\r" |
---|
| 71 | "3.00000000e+06 6.26612557e+01 5.91740007e+01 4.55044481e+01 1.11003552e+01 6.69053959e-01 1.79109114e+02\n" |
---|
| 72 | " 3.50000000e+06 5.50134904e+01 5.20584986e+01 4.00630585e+01 9.78183471e+00 6.23068350e-01 1.57539951e+02\n" |
---|
| 73 | "4.00000000e+06 4.91088724e+01 4.65679165e+01 3.58555442e+01 8.76079088e+00 5.82043180e-01 1.40875167e+02\n\n # comment\n" |
---|
| 74 | "4.50000000e+06 4.44233138e+01 4.21789727e+01 3.25041581e+01 7.94478293e+00 5.45740594e-01 1.27596968e+02\n#comment\r\n" |
---|
| 75 | "5.00000000e+06 4.05969944e+01 3.85988273e+01 2.97569104e+01 7.27564958e+00 5.13600786e-01 1.16741982e+02\n" |
---|
| 76 | "6.00000000e+06 3.47166562e+01 3.30808108e+01 2.55256187e+01 6.24407052e+00 4.59695847e-01 1.00026852e+02\n" |
---|
| 77 | "7.00000000e+06 3.03909338e+01 2.90156224e+01 2.24051103e+01 5.48359988e+00 4.16287624e-01 8.77115540e+01\n" |
---|
| 78 | "8.00000000e+06 2.70812879e+01 2.58941898e+01 2.00065525e+01\t4.89722388e+00 3.80739730e-01 7.82599938e+01\n" |
---|
| 79 | "9.00000000e+06 2.44599065e+01 2.34131260e+01 1.80955062e+01 4.43069001e+00 3.51212438e-01 7.07504411e+01\n" |
---|
| 80 | "1.00000000e+07 2.23229847e+01 2.13902553e+01 1.65394526e+01 4.05000347e+00 3.26180582e-01 6.46288766e+01 #comment \n" |
---|
| 81 | "1.10000000e+07 2.05485697e+01 1.97086000e+01 1.52450755e+01 3.73311927e+00 3.04729195e-01 5.95400936e+01#comment\n" |
---|
| 82 | "1.20000000e+07 1.90475083e+01 1.82869443e+01 1.41492895e+01 3.46491210e+00 2.86140746e-01 5.52347951e+01\n" |
---|
| 83 | "1.30000000e+07 1.77638183e+01 1.70693653e+01 1.32099385e+01 3.23474125e+00 \t 2.69857202e-01 5.15477205e+01 \n" |
---|
| 84 | " 1.40000000e+07 1.66514478e+01 1.60114678e+01 1.23958510e+01 3.03496833e+00 2.55467589e-01 4.83492025e+01\n" |
---|
| 85 | "1.50000000e+07 1.56760259e+01 1.50837486e+01 1.16792471e+01 2.85979032e+00 2.42653835e-01 4.55414657e+01\n" |
---|
| 86 | "1.60000000e+07 1.48138030e+01 1.42630410e+01 1.10462104e+01 2.70486989e+00 2.31166719e-01 4.30590910e+01 \n\n"; |
---|
| 87 | |
---|
| 88 | if (!out.good()) |
---|
| 89 | { |
---|
| 90 | G4cout << argv[0] << ": Failed to create \"./G4DNACrossSectionDataSetTestFile.dat\" file" << G4endl; |
---|
| 91 | return 0; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | out.close(); |
---|
| 95 | setenv("G4LEDATA", ".", 1); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | G4LogLogInterpolation *algorithm(new G4LogLogInterpolation); |
---|
| 99 | |
---|
| 100 | G4DNACrossSectionDataSet dataset(algorithm, EnergyUMIS, DataUMIS); |
---|
| 101 | |
---|
| 102 | G4cout << argv[0] << ": G4DNACrossSectionDataSet::Load: " << G4endl; |
---|
| 103 | |
---|
| 104 | try |
---|
| 105 | { |
---|
| 106 | if (!dataset.LoadData(inFile)) |
---|
| 107 | { |
---|
| 108 | G4cout << " - Failed with false" << G4endl; |
---|
| 109 | return 0; |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | catch (...) |
---|
| 113 | { |
---|
| 114 | G4cout << " - Failed with exception" << G4endl; |
---|
| 115 | return 0; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | if (argc==1) |
---|
| 119 | unlink("./G4DNACrossSectionDataSetTestFile.dat"); |
---|
| 120 | |
---|
| 121 | G4cout << " - Passed" << G4endl; |
---|
| 122 | |
---|
| 123 | G4cout << argv[0] << ": G4DNACrossSectionDataSet::PrintData: " << G4endl; |
---|
| 124 | dataset.PrintData(); |
---|
| 125 | |
---|
| 126 | setenv("G4LEDATA", ".", 1); |
---|
| 127 | G4cout << argv[0] << ": G4DNACrossSectionDataSet::Save: " << G4endl; |
---|
| 128 | try |
---|
| 129 | { |
---|
| 130 | if (!dataset.SaveData("G4DNACrossSectionDataSetTestFile-2")) |
---|
| 131 | { |
---|
| 132 | G4cout << " - Failed with false" << G4endl; |
---|
| 133 | return 0; |
---|
| 134 | } |
---|
| 135 | } |
---|
| 136 | catch (...) |
---|
| 137 | { |
---|
| 138 | G4cout << " - Failed with exception" << G4endl; |
---|
| 139 | return 0; |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | G4DNACrossSectionDataSet dataset2(algorithm->Clone(), EnergyUMIS, DataUMIS); |
---|
| 143 | try |
---|
| 144 | { |
---|
| 145 | if (!dataset2.LoadData("G4DNACrossSectionDataSetTestFile-2")) |
---|
| 146 | { |
---|
| 147 | G4cout << " - Failed with file missing" << G4endl; |
---|
| 148 | return 0; |
---|
| 149 | } |
---|
| 150 | } |
---|
| 151 | catch (...) |
---|
| 152 | { |
---|
| 153 | G4cout << " - Failed with file missing" << G4endl; |
---|
| 154 | return 0; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | unlink("./G4DNACrossSectionDataSetTestFile-2.dat"); |
---|
| 158 | |
---|
| 159 | G4cout << " - Passed" << G4endl; |
---|
| 160 | |
---|
| 161 | G4cout << argv[0] << ": Comparing data:" << G4endl; |
---|
| 162 | |
---|
| 163 | size_t n(dataset.NumberOfComponents()); |
---|
| 164 | |
---|
| 165 | if (n!=dataset2.NumberOfComponents()) |
---|
| 166 | { |
---|
| 167 | G4cout << " - Failed different number of components" << G4endl; |
---|
| 168 | return 0; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | while (n>0) |
---|
| 172 | { |
---|
| 173 | n--; |
---|
| 174 | |
---|
| 175 | const G4DataVector &e(dataset.GetComponent(n)->GetEnergies(0)); |
---|
| 176 | const G4DataVector &e2(dataset2.GetComponent(n)->GetEnergies(0)); |
---|
| 177 | const G4DataVector &d(dataset.GetComponent(n)->GetData(0)); |
---|
| 178 | const G4DataVector &d2(dataset2.GetComponent(n)->GetData(0)); |
---|
| 179 | |
---|
| 180 | if (e.size()!=e2.size() || d.size()!=d2.size() || e.size()!=d.size()) |
---|
| 181 | { |
---|
| 182 | G4cout << " - Failed different number of rows" << G4endl; |
---|
| 183 | return 0; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | size_t m(e.size()); |
---|
| 187 | |
---|
| 188 | while (m>0) |
---|
| 189 | { |
---|
| 190 | m--; |
---|
| 191 | |
---|
| 192 | if (e[m]!=e2[m]) |
---|
| 193 | { |
---|
| 194 | G4cout << " - Failed different energies (line " << (m+1) << " - " << e[m] << ", " << e2[m] << ")" << G4endl; |
---|
| 195 | return 0; |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | if (d[m]!=d2[m]) |
---|
| 199 | { |
---|
| 200 | G4cout << " - Failed different data (line " << (m+1) << ", column " << (n+2) << " - " << d[m] << ", " << d2[m] << ")" << G4endl; |
---|
| 201 | return 0; |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | G4cout << " - Passed" << G4endl; |
---|
| 207 | G4cout << G4endl; |
---|
| 208 | G4cout << "(!) NOTE: Files G4DNACrossSectionDataSetTestFile*.dat were written and removed from this directory" << G4endl; |
---|
| 209 | |
---|
| 210 | return 0; |
---|
| 211 | } |
---|