source: trunk/source/materials/test/testExternalDEDXTable.cc @ 1239

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

nvx fichiers dans CVS

File size: 8.8 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// Anton.Lechner@cern.ch
28//
29// Environment variable TESTTARGET must be specified (see GNUmakefile)
30//
31//
32// The following functions of the class G4ExtDEDXTable are tested:
33//       IsApplicable()
34//       AddPhysicsVector()
35//       RemovePhysicsVector()
36//       GetPhysicsVector()
37//       StorePhysicsTable()
38//       RetrievePhysicsTable()
39//
40// Note: This test creates a file "usertable.dat". You may want to delete it
41//       after running the test.
42
43#include "globals.hh"
44#include "G4ExtDEDXTable.hh"
45#include "G4LPhysicsFreeVector.hh"
46
47
48void Test(const G4String& fileName) {
49
50  // ########################################################################
51  // # Creating physics vectors
52  // ########################################################################
53
54  G4double factor = MeV * cm2 / (0.001 * g);
55
56  G4double E[31] = {.025,.03,.04,.05,.06,.07,.08,.09,.1,.15,.2,.25,.3,
57                    .4,.5,.6,.7,.8,.9,1,1.5,2,2.5,3,4,5,6,7,8,9,10};
58
59  // Lithium ions in hydrogen
60  G4double H_3[31]={8.31,8.919,9.838,10.46,10.87,11.14,11.3,11.4,11.43,
61                    11.21,10.73,10.21,9.696,8.773,7.989,7.326,6.761,6.275,
62                    5.853,5.485,4.175,3.377,2.843,2.46,1.948,1.62,1.393,
63                    1.225,1.095,0.9921,0.9082};
64
65  G4LPhysicsFreeVector* physVecZ3MatH = 
66                 new G4LPhysicsFreeVector(31, E[0] * MeV, E[30] * MeV);
67  physVecZ3MatH -> SetSpline(true);
68
69  for(size_t i = 0; i < 31; i++) {
70    physVecZ3MatH -> PutValues(i, E[i] * MeV, H_3[i] * factor);
71  }
72
73  // Lithium ions in tissue
74  G4double A_3[31]={2.748,2.992,3.386,3.674,3.877,4.016,4.108,4.166,4.2,
75                    4.186,4.059,3.906,3.751,3.458,3.2,2.974,2.777,2.603,
76                    2.449,2.313,1.807,1.485,1.263,1.1,0.8801,0.7372,0.6368,
77                    0.5623,0.5046,0.4586,0.4209}; 
78
79  G4LPhysicsFreeVector* physVecZ3MatTissue = 
80                 new G4LPhysicsFreeVector(31, E[0] * MeV, E[30] * MeV);
81  physVecZ3MatTissue -> SetSpline(true);
82
83  for(size_t i = 0; i < 31; i++) {
84      physVecZ3MatTissue -> PutValues(i, E[i] * MeV, A_3[i] * factor);
85  }
86
87  // ########################################################################
88  // # Test 1:
89  // ########################################################################
90
91  G4ExtDEDXTable* tableA = new G4ExtDEDXTable();
92
93  G4cout << G4endl << "##### Testing AddPhysicsVector() #####" 
94         << G4endl;
95
96  G4cout << "***Stopping power of hydrogen for Li ions***" << G4endl;
97
98  G4cout << "  Vector not available. Is applicable: "; 
99  if( tableA -> IsApplicable(3, "G4_H") ) 
100     G4cout << "Yes. Test failed" << G4endl; 
101  else 
102     G4cout << "No. Test passed" << G4endl; 
103
104  G4cout << "  Adding vector. Success: "; 
105  if( tableA -> AddPhysicsVector(physVecZ3MatH, 3, "G4_H", 1) )
106     G4cout << "Yes. Test passed" << G4endl; 
107  else 
108     G4cout << "No. Test failed" << G4endl; 
109
110  G4cout << "  Vector added. Is applicable: "; 
111  if( tableA -> IsApplicable(3, "G4_H") ) 
112     G4cout << "Yes. Test passed" << G4endl; 
113  else 
114     G4cout << "No. Test failed" << G4endl; 
115
116  G4cout << "  Vector added. Is applicable: "; 
117  if( tableA -> IsApplicable(3, 1) ) 
118     G4cout << "Yes. Test passed" << G4endl; 
119  else 
120     G4cout << "No. Test failed" << G4endl; 
121
122  G4cout << "***Stopping power of tissue for Li ions***" << G4endl;
123 
124  G4cout << "  Vector not available. Is applicable: "; 
125  if( tableA -> IsApplicable(3, "G4_A-150_TISSUE") ) 
126     G4cout << "Yes. Test failed" << G4endl; 
127  else 
128     G4cout << "No. Test passed" << G4endl; 
129
130  G4cout << "  Adding vector. Success: "; 
131  if( tableA -> AddPhysicsVector(physVecZ3MatTissue, 3, "G4_A-150_TISSUE") )
132     G4cout << "Yes. Test passed" << G4endl; 
133  else 
134     G4cout << "No. Test failed" << G4endl; 
135
136  G4cout << "  Vector added. Is applicable: "; 
137  if( tableA -> IsApplicable(3, "G4_A-150_TISSUE") ) 
138     G4cout << "Yes. Test passed" << G4endl; 
139  else 
140     G4cout << "No. Test failed" << G4endl; 
141
142  // ########################################################################
143  // # Test 2:
144  // ########################################################################
145
146  G4cout << G4endl << "##### Testing GetPhysicsVector() #####" 
147         << G4endl;
148
149  G4PhysicsVector* vector = 0;
150
151  vector = tableA -> GetPhysicsVector(3, "G4_H");
152
153  G4cout << "  Vector retrieved. Found: "; 
154  if( physVecZ3MatH == vector ) 
155     G4cout << "Yes. Test passed" << G4endl; 
156  else 
157     G4cout << "No. Test failed" << G4endl; 
158
159  vector = tableA -> GetPhysicsVector(3, 1);
160
161  G4cout << "  Vector retrieved. Found: ";
162  if( physVecZ3MatH == vector) 
163     G4cout << "Yes. Test passed" << G4endl; 
164  else 
165     G4cout << "No. Test failed" << G4endl; 
166
167  vector = tableA -> GetPhysicsVector(3, "G4_A-150_TISSUE");
168 
169  G4cout << "  Vector retrieved. Found: ";
170  if( physVecZ3MatTissue == vector) 
171     G4cout << "Yes. Test passed" << G4endl; 
172  else 
173     G4cout << "No. Test failed" << G4endl; 
174
175
176  // ########################################################################
177  // # Test 3:
178  // ########################################################################
179
180  G4cout << G4endl << "##### Testing StorePhysicsTable() #####" 
181         << G4endl;
182
183  G4cout << "  Storing table: ";
184  if( tableA -> StorePhysicsTable(fileName) ) 
185     G4cout << " Test passed" << G4endl;
186  else 
187     G4cout << " Test failed" << G4endl; 
188
189  // ########################################################################
190  // # Test 4:
191  // ########################################################################
192
193  G4cout << G4endl << "##### Testing RemovePhysicsVector() #####" 
194         << G4endl;
195
196  G4cout << "  Removing vector. Success "; 
197  if( tableA -> RemovePhysicsVector(3, "G4_H") )
198     G4cout << "Yes. Test passed" << G4endl; 
199  else 
200     G4cout << "No. Test failed" << G4endl; 
201
202  G4cout << "  Vector was removed. Is applicable: "; 
203  if( tableA -> IsApplicable(3, "G4_H") ) 
204     G4cout << "Yes. Test failed" << G4endl; 
205  else 
206     G4cout << "No. Test passed" << G4endl; 
207
208  G4cout << "  Vector was removed. Is applicable: "; 
209  if( tableA -> IsApplicable(3, 1) ) 
210     G4cout << "Yes. Test failed" << G4endl; 
211  else 
212     G4cout << "No. Test passed" << G4endl; 
213
214  delete tableA;
215
216  // ########################################################################
217  // # Test 5:
218  // ########################################################################
219
220  G4ExtDEDXTable* tableB = new G4ExtDEDXTable();
221
222  G4cout << G4endl << "##### Testing RetrievePhysicsTable() #####" 
223         << G4endl;
224
225  G4cout << "  Vector not available. Is applicable: "; 
226  if( tableB -> IsApplicable(3, "G4_H") ) 
227     G4cout << "Yes. Test failed" << G4endl; 
228  else 
229     G4cout << "No. Test passed" << G4endl; 
230
231  G4cout << "  Retrieving table: ";
232  if( tableB -> RetrievePhysicsTable(fileName) ) 
233     G4cout << "Test passed" << G4endl;
234  else 
235     G4cout << "Test failed" << G4endl;
236
237  G4cout << "  Vector added. Is applicable: "; 
238  if( tableB -> IsApplicable(3, "G4_H") ) 
239     G4cout << "Yes. Test passed" << G4endl; 
240  else 
241     G4cout << "No. Test failed" << G4endl; 
242
243  G4cout << "  Vector added. Is applicable: "; 
244  if( tableB -> IsApplicable(3, 1) ) 
245     G4cout << "Yes. Test passed" << G4endl; 
246  else 
247     G4cout << "No. Test failed" << G4endl; 
248
249  G4cout << G4endl;
250
251  delete tableB;
252}
253
254
255int main() { 
256
257
258  Test("usertable.dat");
259
260  return EXIT_SUCCESS;
261} 
262
Note: See TracBrowser for help on using the repository browser.