source: trunk/source/processes/electromagnetic/utils/test/testG4AllTables.cc @ 1199

Last change on this file since 1199 was 1199, checked in by garnier, 15 years ago

nvx fichiers dans CVS

File size: 5.1 KB
Line 
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//
28//
29// -------------------------------------------------------------
30//      GEANT4
31// test for EnergyLoss Range InverseRange Lambda and other Tables,
32// A. Bagulya 14 May 2009
33//
34// -------------------------------------------------------------
35
36//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
37//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
38
39#include "globals.hh"
40#include "G4PhysicsVector.hh"
41#include "G4PhysicsTable.hh"
42#include <fstream>
43#include <iostream>
44#include <iomanip>
45#include <string>
46
47int main(int argc,char** argv)
48{
49  // Control on input
50
51  if(argc < 2) {
52    G4cout << "Input parameters are not specified! Exit" << G4endl;
53    exit(1);
54  }
55
56
57  std::string path = "/home/bagoulia/geant4/examples/extended/electromagnetic/TestEm3/";
58  std::string dir1 = "physdata_100bins/";
59  std::string ff   = argv[1];
60  std::string fName1 = path + dir1 + ff;
61
62   std::ifstream in1;
63   in1.open(fName1.c_str());
64   if( !in1.is_open()) {
65     G4cout << "Input file<" << fName1 << "> does not exist! Exit" << G4endl;
66     exit(1);
67   }
68
69   G4PhysicsTable* t1 = new G4PhysicsTable();
70   t1->RetrievePhysicsTable(fName1, true);
71
72   G4PhysicsVector* V1 = (*t1)(1);
73   
74   //   V1->SetSpline(true);
75   std::string d_st = "physdata_";
76   std::string num_bins = argv[2];
77   G4int n_spl = atoi(argv[3]);
78   std::string s_spl = "spl";
79   std::string d_m;
80   if (n_spl) d_m = "bins_spl/";
81   else d_m = "bins/";
82
83   std::string dir2 = d_st + num_bins + d_m;
84   std::string fName2 = path + dir2 + ff;
85
86   std::ifstream in2;
87   in2.open(fName2.c_str());
88
89   if( !in2.is_open()) {
90     G4cout << "Input file<" << fName2 << "> does not exist! Exit" << G4endl;
91     exit(1);
92   }
93
94   G4double n = V1->GetVectorLength();
95   G4double diff_max = 0.0;
96   G4double e, y1, y2, diff;
97
98   G4cout << "n = " << n <<G4endl;
99
100   G4PhysicsTable* t2 = new G4PhysicsTable();
101   t2->RetrievePhysicsTable(fName2, true);
102 
103   G4PhysicsVector* V2 = (*t2)(1); 
104
105   std::string d_out = "data/";
106   std::string typeFile = ".out";
107   std::string c = "_";
108   std::string bi = "bins";
109 
110   std::string asciiFileName;
111   if (n_spl) {
112     V2->SetSpline(true);
113     asciiFileName = d_out + ff + c + num_bins + bi + c + s_spl + typeFile;
114   } else {
115     asciiFileName = d_out + ff + c + num_bins + bi + typeFile;
116   }
117
118   std::ofstream asciiFile;
119   asciiFile.open(asciiFileName.c_str(), std::ios::out);
120   if(asciiFile.is_open()) {
121     asciiFile << " Energy(Mev) ||    Y1    ||    Y2      ||  Diff " << G4endl;
122   } else {
123     G4cout << "ERROR file <" << asciiFileName << "> is not opened" << G4endl;
124     exit(1);
125   } 
126
127     G4bool b;
128   for (G4int i = 0; i < n; i++) {
129     e = V1->GetLowEdgeEnergy(i); 
130     y1 = (*V1)[i];
131     y2 = V2->GetValue(e, b);
132     diff = std::fabs((1.0 - y2/y1)*100);
133     if (diff > diff_max) diff_max = diff;
134
135      asciiFile << std::setprecision(5)
136                << std::setiosflags(std::ios::right);
137      asciiFile << e;
138      asciiFile << "    ";
139      asciiFile << std::setiosflags(std::ios::right);
140      asciiFile << y1;
141      asciiFile << "    ";
142      asciiFile << std::setiosflags(std::ios::right);
143      asciiFile << y2;
144      asciiFile << "    ";
145      asciiFile << std::setiosflags(std::ios::right);
146      asciiFile << diff
147                << G4endl;
148
149   }
150   G4cout << "diff_max = " << diff_max << G4endl;
151
152    delete V1;
153    delete V2;
154    exit(0);
155}
156
157//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
158
Note: See TracBrowser for help on using the repository browser.