Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4IsotopeMagneticMomentTable.cc
Go to the documentation of this file.
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 // MODULE: G4IsotopeMagneticMomentTable.cc
29 //
30 // Date: 16/03/07
31 // Author: H.Kurashige
32 //
33 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34 //
35 // HISTORY
37 //
39 
40 #include "G4ios.hh"
41 #include "globals.hh"
42 #include "G4PhysicalConstants.hh"
43 #include "G4SystemOfUnits.hh"
44 #include <iomanip>
45 #include <fstream>
46 #include <sstream>
47 
48 const G4double G4IsotopeMagneticMomentTable::levelTolerance = 0.001;
49 // 0.1% torelance for excitation energy
50 
51 const G4double G4IsotopeMagneticMomentTable::nuclearMagneton = eplus*hbar_Planck/2./(proton_mass_c2 /c_squared);
52 // Nuclear Magneton
53 
56  :G4VIsotopeTable("MagneticMoment")
57 {
58  if ( !getenv("G4IONMAGNETICMOMENT")) {
59 #ifdef G4VERBOSE
60  if (GetVerboseLevel()>1) {
61  G4cout << "G4IsotopeMagneticMomentTable::G4IsotopeMagneticMomentTable(): "
62  << "Please setenv G4IONMAGNETICMOMENT for the magnetic moment data."
63  << G4endl;
64  G4Exception( "G4IsotopeMagneticMomentTable",
65  "File Not Found",
66  JustWarning,
67  "Please setenv G4IONMAGNETICMOMENT");
68  }
69 #endif
70  G4Exception( "G4IsotopeMagneticMomentTable",
71  "File Not Found",
72  JustWarning,
73  "Please setenv G4IONMAGNETICMOMENT");
74  return;
75  }
76 
77  G4String file = getenv("G4IONMAGNETICMOMENT");
78  std::ifstream DataFile(file);
79 
80  if (!DataFile ) {
81 #ifdef G4VERBOSE
82  if (GetVerboseLevel()>0) {
83  G4cout << "G4IsotopeMagneticMomentTable::G4IsotopeMagneticMomentTable(): "
84  << file << " is not found " << G4endl;
85  }
86 #endif
87  G4Exception( "G4IsotopeMagneticMomentTable",
88  "File Not Found",
89  JustWarning,
90  "Can not open G4IONMAGNETICMOMENT file");
91  return;
92  }
93 
94  char inputChars[80]={' '};
95 
96  while ( !DataFile.eof() ) {
97  DataFile.getline(inputChars, 80);
98  G4String inputLine = inputChars;
99  G4int ionA, ionZ, ionJ;
100  G4double ionE, ionMu, ionLife;
101  G4String ionName, ionLifeUnit;
102 
103  if (inputChars[0] != '#' && inputLine.length() != 0) {
104  std::istringstream tmpstream(inputLine);
105  tmpstream >> ionZ >> ionName >> ionA >> ionE
106  >> ionLife >> ionLifeUnit
107  >> ionJ >> ionMu;
108 
109  G4IsotopeProperty* fProperty = new G4IsotopeProperty();
110  // Set Isotope Property
111  fProperty->SetAtomicNumber(ionZ);
112  fProperty->SetAtomicMass(ionA);
113  fProperty->SetEnergy(ionE * MeV);
114  fProperty->SetiSpin(ionJ);
115  fProperty->SetMagneticMoment(ionMu*nuclearMagneton);
116 
117  fIsotopeList.push_back(fProperty);
118 
119  //if (GetVerboseLevel()>2) {
120  // fProperty->DumpInfo();
121  //}
122 
123  }
124  }
125 
126  DataFile.close();
127 }
128 
131 {
132  for (size_t i = 0 ; i< fIsotopeList.size(); i++) {
133  delete fIsotopeList[i];
134  }
135  fIsotopeList.clear();
136 }
137 
140  :G4VIsotopeTable(right),
141  fIsotopeList(0)
142 {
143 }
144 
147 {
148  return *this;
149 }
150 
153 {
154  for (size_t i = 0 ; i< fIsotopeList.size(); ++i) {
155  G4IsotopeProperty* fP = fIsotopeList[i];
156 
157  // check Z
158  if ( fP->GetAtomicNumber() > pP->GetAtomicNumber()) {
159  // Not Found
160  break;
161  }
162  if ( fP->GetAtomicNumber() < pP->GetAtomicNumber()) {
163  // next
164  continue;
165  }
166 
167  // check A
168  if ( fP->GetAtomicMass() != pP->GetAtomicMass()) {
169  // next
170  continue;
171  }
172 
173  //check E
174  if (std::fabs(fP->GetEnergy() - pP->GetEnergy()) <= fP->GetEnergy()*levelTolerance) {
175  // Found
176  return true;
177  }
178 
179  }
180  return false;
181 }
183 //
185 {
186  G4IsotopeProperty* fProperty = 0;
187  for (size_t i = 0 ; i< fIsotopeList.size(); ++i) {
188  G4IsotopeProperty* fP = fIsotopeList[i];
189 
190  // check Z
191  if ( fP->GetAtomicNumber() > Z) {
192  // Not Found
193  break;
194  }
195  if ( fP->GetAtomicNumber() < Z) {
196  // next
197  continue;
198  }
199 
200  // check A
201  if ( fP->GetAtomicMass() != A ) {
202  // next
203  continue;
204  }
205 
206  //check E
207  if (std::fabs(fP->GetEnergy() - E) <= fP->GetEnergy()*levelTolerance) {
208  // Found
209  fProperty = fP;
210  fP->DumpInfo();
211  break;
212  }
213 
214  }
215 
216  return fProperty;
217 
218 }