Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // 27 // ------------------------------------------- 27 // ------------------------------------------------------------------- 28 // 28 // 29 // GEANT4 Class file 29 // GEANT4 Class file 30 // 30 // 31 // 31 // 32 // File name: G4ComponentSAIDTotalXS 32 // File name: G4ComponentSAIDTotalXS 33 // 33 // 34 // Authors: G.Folger, V.Ivanchenko, D.Wright 34 // Authors: G.Folger, V.Ivanchenko, D.Wright 35 // 35 // 36 // Modifications: 36 // Modifications: 37 // 37 // 38 38 39 #include "G4ComponentSAIDTotalXS.hh" 39 #include "G4ComponentSAIDTotalXS.hh" 40 #include "G4PhysicsVector.hh" 40 #include "G4PhysicsVector.hh" 41 #include "G4PhysicsFreeVector.hh" << 41 #include "G4LPhysicsFreeVector.hh" 42 42 43 const G4String G4ComponentSAIDTotalXS::fnames[ 43 const G4String G4ComponentSAIDTotalXS::fnames[13] = { 44 "","pp","np","pip","pim", 44 "","pp","np","pip","pim", 45 "pin","pie", 45 "pin","pie", 46 "gp_pi0p","gp_pi+n","gn_pi-p","gn_pi0n","gp_ 46 "gp_pi0p","gp_pi+n","gn_pi-p","gn_pi0n","gp_etap","gp_etapp" 47 }; 47 }; 48 48 49 #ifdef G4MULTITHREADED 49 #ifdef G4MULTITHREADED 50 G4Mutex G4ComponentSAIDTotalXS::saidXSMutex 50 G4Mutex G4ComponentSAIDTotalXS::saidXSMutex = G4MUTEX_INITIALIZER; 51 #endif 51 #endif 52 52 53 G4ComponentSAIDTotalXS::G4ComponentSAIDTotalXS 53 G4ComponentSAIDTotalXS::G4ComponentSAIDTotalXS() 54 : G4VComponentCrossSection("xsSAID") 54 : G4VComponentCrossSection("xsSAID") 55 { 55 { 56 for(G4int i=0; i<numberOfSaidXS; ++i) { 56 for(G4int i=0; i<numberOfSaidXS; ++i) { 57 elastdata[i] = nullptr; 57 elastdata[i] = nullptr; 58 inelastdata[i] = nullptr; 58 inelastdata[i] = nullptr; 59 } 59 } 60 } 60 } 61 61 62 G4ComponentSAIDTotalXS::~G4ComponentSAIDTotalX 62 G4ComponentSAIDTotalXS::~G4ComponentSAIDTotalXS() 63 { 63 { 64 for(G4int i=0; i<numberOfSaidXS; ++i) { 64 for(G4int i=0; i<numberOfSaidXS; ++i) { 65 if(elastdata[i]) { 65 if(elastdata[i]) { 66 delete elastdata[i]; 66 delete elastdata[i]; 67 elastdata[i] = nullptr; 67 elastdata[i] = nullptr; 68 } 68 } 69 if(inelastdata[i]) { 69 if(inelastdata[i]) { 70 delete inelastdata[i]; 70 delete inelastdata[i]; 71 inelastdata[i] = nullptr; 71 inelastdata[i] = nullptr; 72 } 72 } 73 } 73 } 74 } 74 } 75 75 76 G4double 76 G4double 77 G4ComponentSAIDTotalXS::GetTotalElementCrossSe 77 G4ComponentSAIDTotalXS::GetTotalElementCrossSection( 78 const G4ParticleDefinition* part, 78 const G4ParticleDefinition* part, 79 G4double, G4int Z, G4double N) 79 G4double, G4int Z, G4double N) 80 { 80 { 81 PrintWarning(part,0,Z,G4lrint(N), 81 PrintWarning(part,0,Z,G4lrint(N), 82 "G4ComponentSAIDTotalXS::GetTotalElem 82 "G4ComponentSAIDTotalXS::GetTotalElementCrossSection", 83 "Method is not implemented"); 83 "Method is not implemented"); 84 return 0.0; 84 return 0.0; 85 } 85 } 86 86 87 G4double 87 G4double 88 G4ComponentSAIDTotalXS::GetTotalIsotopeCrossSe 88 G4ComponentSAIDTotalXS::GetTotalIsotopeCrossSection( 89 const G4ParticleDefinition* part, 89 const G4ParticleDefinition* part, 90 G4double kinEnergy, G4int Z, G4int N) 90 G4double kinEnergy, G4int Z, G4int N) 91 { 91 { 92 return GetInelasticIsotopeCrossSection(part, 92 return GetInelasticIsotopeCrossSection(part,kinEnergy,Z,N) 93 + GetElasticIsotopeCrossSection(part,kinEn 93 + GetElasticIsotopeCrossSection(part,kinEnergy,Z,N); 94 } 94 } 95 95 96 G4double 96 G4double 97 G4ComponentSAIDTotalXS::GetInelasticElementCro 97 G4ComponentSAIDTotalXS::GetInelasticElementCrossSection( 98 const G4ParticleDefinition* part, 98 const G4ParticleDefinition* part, 99 G4double, G4int Z, G4double N) 99 G4double, G4int Z, G4double N) 100 { 100 { 101 PrintWarning(part,0,Z,G4lrint(N), 101 PrintWarning(part,0,Z,G4lrint(N), 102 "G4ComponentSAIDTotalXS::GetTotalElem 102 "G4ComponentSAIDTotalXS::GetTotalElementCrossSection", 103 "Method is not implemented"); 103 "Method is not implemented"); 104 return 0.0; 104 return 0.0; 105 } 105 } 106 106 107 G4double 107 G4double 108 G4ComponentSAIDTotalXS::GetInelasticIsotopeCro 108 G4ComponentSAIDTotalXS::GetInelasticIsotopeCrossSection( 109 const G4ParticleDefinition* part, 109 const G4ParticleDefinition* part, 110 G4double kinEnergy, G4int Z, G4int N) 110 G4double kinEnergy, G4int Z, G4int N) 111 { 111 { 112 G4double cross = 0.0; 112 G4double cross = 0.0; 113 G4SAIDCrossSectionType tp = GetType(part,0,Z 113 G4SAIDCrossSectionType tp = GetType(part,0,Z,N); 114 if(saidUnknown != tp) { 114 if(saidUnknown != tp) { 115 G4int idx = G4int(tp); 115 G4int idx = G4int(tp); 116 if(!inelastdata[idx]) { Initialise(tp); } 116 if(!inelastdata[idx]) { Initialise(tp); } 117 if(inelastdata[idx]) { 117 if(inelastdata[idx]) { 118 cross = (inelastdata[idx])->Value(kinEne 118 cross = (inelastdata[idx])->Value(kinEnergy); 119 } 119 } 120 } 120 } 121 return cross; 121 return cross; 122 } 122 } 123 123 124 G4double 124 G4double 125 G4ComponentSAIDTotalXS::GetElasticElementCross 125 G4ComponentSAIDTotalXS::GetElasticElementCrossSection( 126 const G4ParticleDefinition* part, 126 const G4ParticleDefinition* part, 127 G4double, G4int Z, G4double N) 127 G4double, G4int Z, G4double N) 128 { 128 { 129 PrintWarning(part,0,Z,G4lrint(N), 129 PrintWarning(part,0,Z,G4lrint(N), 130 "G4ComponentSAIDTotalXS::GetTotalElem 130 "G4ComponentSAIDTotalXS::GetTotalElementCrossSection", 131 "Method is not implemented"); 131 "Method is not implemented"); 132 return 0.0; 132 return 0.0; 133 } 133 } 134 134 135 G4double 135 G4double 136 G4ComponentSAIDTotalXS::GetElasticIsotopeCross 136 G4ComponentSAIDTotalXS::GetElasticIsotopeCrossSection( 137 const G4ParticleDefinition* part, 137 const G4ParticleDefinition* part, 138 G4double kinEnergy, G4int Z, G4int N) 138 G4double kinEnergy, G4int Z, G4int N) 139 { 139 { 140 G4double cross = 0.0; 140 G4double cross = 0.0; 141 G4SAIDCrossSectionType tp = GetType(part,0,Z 141 G4SAIDCrossSectionType tp = GetType(part,0,Z,N); 142 if(saidUnknown != tp) { 142 if(saidUnknown != tp) { 143 G4int idx = G4int(tp); 143 G4int idx = G4int(tp); 144 if(!elastdata[idx]) { Initialise(tp); } 144 if(!elastdata[idx]) { Initialise(tp); } 145 if(elastdata[idx]) { 145 if(elastdata[idx]) { 146 cross = (elastdata[idx])->Value(kinEnerg 146 cross = (elastdata[idx])->Value(kinEnergy); 147 } 147 } 148 } 148 } 149 return cross; 149 return cross; 150 } 150 } 151 151 152 G4double 152 G4double 153 G4ComponentSAIDTotalXS::GetChargeExchangeCross 153 G4ComponentSAIDTotalXS::GetChargeExchangeCrossSection( 154 const G4ParticleDefinition* prim, 154 const G4ParticleDefinition* prim, 155 const G4ParticleDefinition* sec, 155 const G4ParticleDefinition* sec, 156 G4double kinEnergy, G4int Z, G4int N) 156 G4double kinEnergy, G4int Z, G4int N) 157 { 157 { 158 G4double cross = 0.0; 158 G4double cross = 0.0; 159 G4SAIDCrossSectionType tp = GetType(prim,sec 159 G4SAIDCrossSectionType tp = GetType(prim,sec,Z,N); 160 if(saidUnknown != tp) { 160 if(saidUnknown != tp) { 161 G4int idx = G4int(tp); 161 G4int idx = G4int(tp); 162 if(!inelastdata[idx]) { Initialise(tp); } 162 if(!inelastdata[idx]) { Initialise(tp); } 163 if(inelastdata[idx]) { 163 if(inelastdata[idx]) { 164 cross = (inelastdata[idx])->Value(kinEne 164 cross = (inelastdata[idx])->Value(kinEnergy); 165 } 165 } 166 } 166 } 167 return cross; 167 return cross; 168 } 168 } 169 169 170 void G4ComponentSAIDTotalXS::Description(std:: 170 void G4ComponentSAIDTotalXS::Description(std::ostream&) const 171 { 171 { 172 } 172 } 173 173 174 G4SAIDCrossSectionType 174 G4SAIDCrossSectionType 175 G4ComponentSAIDTotalXS::GetType(const G4Partic 175 G4ComponentSAIDTotalXS::GetType(const G4ParticleDefinition* prim, 176 const G4ParticleDefinition* sec, 176 const G4ParticleDefinition* sec, 177 G4int Z, G4int N) 177 G4int Z, G4int N) 178 { 178 { 179 G4SAIDCrossSectionType type = saidUnknown; 179 G4SAIDCrossSectionType type = saidUnknown; 180 if(1 == N && prim) { 180 if(1 == N && prim) { 181 G4int code = prim->GetPDGEncoding(); 181 G4int code = prim->GetPDGEncoding(); 182 182 183 // only gamma + N x-sections available 183 // only gamma + N x-sections available 184 if(0 == Z && sec && 22 == code) { 184 if(0 == Z && sec && 22 == code) { 185 G4int code1 = sec->GetPDGEncoding(); 185 G4int code1 = sec->GetPDGEncoding(); 186 if(-211 == code1) { type = saidGN_PI 186 if(-211 == code1) { type = saidGN_PINP; } 187 else if(111 == code1) { type = saidGN_PI 187 else if(111 == code1) { type = saidGN_PI0N; } 188 188 189 // x-sections off proton 189 // x-sections off proton 190 } else if(1 == Z) { 190 } else if(1 == Z) { 191 if(sec) { 191 if(sec) { 192 G4int code1 = sec->GetPDGEncoding(); 192 G4int code1 = sec->GetPDGEncoding(); 193 if(-211 == code) { 193 if(-211 == code) { 194 if(111 == code1) { type = saidP 194 if(111 == code1) { type = saidPINP_PI0N; } 195 else if(221 == code1) { type = saidP 195 else if(221 == code1) { type = saidPINP_ETAN; } 196 196 197 } else if(22 == code) { 197 } else if(22 == code) { 198 if(111 == code1) { type = saidG 198 if(111 == code1) { type = saidGP_PI0P; } 199 else if(211 == code1) { type = saidG 199 else if(211 == code1) { type = saidGP_PIPN; } 200 else if(221 == code1) { type = saidG 200 else if(221 == code1) { type = saidGP_ETAP; } 201 else if(331 == code1) { type = saidG 201 else if(331 == code1) { type = saidGP_ETAPP; } 202 } 202 } 203 } else { 203 } else { 204 if(2212 == code) { type = saidP 204 if(2212 == code) { type = saidPP; } 205 else if(2112 == code) { type = saidN 205 else if(2112 == code) { type = saidNP; } 206 else if(211 == code) { type = saidP 206 else if(211 == code) { type = saidPIPP; } 207 else if(-211 == code) { type = saidP 207 else if(-211 == code) { type = saidPINP; } 208 } 208 } 209 } 209 } 210 } 210 } 211 //G4cout << "G4ComponentSAIDTotalXS::Type= " 211 //G4cout << "G4ComponentSAIDTotalXS::Type= " << type << G4endl; 212 return type; 212 return type; 213 } 213 } 214 214 215 void G4ComponentSAIDTotalXS::Initialise(G4SAID 215 void G4ComponentSAIDTotalXS::Initialise(G4SAIDCrossSectionType tp) 216 { 216 { 217 G4int idx = G4int(tp); 217 G4int idx = G4int(tp); 218 #ifdef G4MULTITHREADED 218 #ifdef G4MULTITHREADED 219 G4MUTEXLOCK(&saidXSMutex); 219 G4MUTEXLOCK(&saidXSMutex); 220 if(!inelastdata[idx]) { 220 if(!inelastdata[idx]) { 221 #endif 221 #endif 222 // check environment variable 222 // check environment variable 223 // Build the complete string identifying t 223 // Build the complete string identifying the file with the data set 224 const char* path = G4FindDataDir("G4SAIDXS << 224 char* path = std::getenv("G4SAIDXSDATA"); 225 if (!path){ 225 if (!path){ 226 G4Exception("G4ComponentSAIDTotalXS::Ini 226 G4Exception("G4ComponentSAIDTotalXS::Initialise(..)","had013", 227 FatalException, 227 FatalException, 228 "Environment variable G4SAIDXSDATA is no 228 "Environment variable G4SAIDXSDATA is not defined"); 229 return; 229 return; 230 } 230 } 231 if(idx <= 4) { 231 if(idx <= 4) { 232 elastdata[idx] = new G4PhysicsFreeVector << 232 elastdata[idx] = new G4LPhysicsFreeVector(); 233 inelastdata[idx] = new G4PhysicsFreeVect << 233 inelastdata[idx] = new G4LPhysicsFreeVector(); 234 ReadData(idx,elastdata[idx],path,"_el.da 234 ReadData(idx,elastdata[idx],path,"_el.dat"); 235 ReadData(idx,inelastdata[idx],path,"_in. 235 ReadData(idx,inelastdata[idx],path,"_in.dat"); 236 } else { 236 } else { 237 inelastdata[idx] = new G4PhysicsFreeVect << 237 inelastdata[idx] = new G4LPhysicsFreeVector(); 238 ReadData(idx,inelastdata[idx],path,".dat 238 ReadData(idx,inelastdata[idx],path,".dat"); 239 } 239 } 240 #ifdef G4MULTITHREADED 240 #ifdef G4MULTITHREADED 241 } 241 } 242 G4MUTEXUNLOCK(&saidXSMutex); 242 G4MUTEXUNLOCK(&saidXSMutex); 243 #endif 243 #endif 244 } 244 } 245 245 246 void G4ComponentSAIDTotalXS::ReadData(G4int in 246 void G4ComponentSAIDTotalXS::ReadData(G4int index, 247 G4PhysicsVector* v, 247 G4PhysicsVector* v, 248 const G4String& ss1, 248 const G4String& ss1, 249 const G4String& ss2) 249 const G4String& ss2) 250 { 250 { 251 std::ostringstream ost; 251 std::ostringstream ost; 252 ost << ss1 << "/" << fnames[index] << ss2; 252 ost << ss1 << "/" << fnames[index] << ss2; 253 std::ifstream filein(ost.str().c_str()); 253 std::ifstream filein(ost.str().c_str()); 254 if (!(filein)) { 254 if (!(filein)) { 255 G4ExceptionDescription ed; 255 G4ExceptionDescription ed; 256 ed << "Data file <" << ost.str().c_str() 256 ed << "Data file <" << ost.str().c_str() 257 << "> is not opened!"; 257 << "> is not opened!"; 258 G4Exception("G4ComponentSAIDTotalXS::ReadD 258 G4Exception("G4ComponentSAIDTotalXS::ReadData(..)","had014", 259 FatalException, ed, "Check G4S 259 FatalException, ed, "Check G4SAIDXSDATA"); 260 } else { 260 } else { 261 if(GetVerboseLevel() > 1) { 261 if(GetVerboseLevel() > 1) { 262 G4cout << "File " << ost.str() 262 G4cout << "File " << ost.str() 263 << " is opened by G4ComponentSAID 263 << " is opened by G4ComponentSAIDTotalXS" << G4endl; 264 } 264 } 265 // retrieve data from DB 265 // retrieve data from DB 266 v->Retrieve(filein, true); 266 v->Retrieve(filein, true); 267 v->ScaleVector(CLHEP::MeV,CLHEP::millibarn 267 v->ScaleVector(CLHEP::MeV,CLHEP::millibarn); 268 v->FillSecondDerivatives(); << 268 v->SetSpline(true); 269 } 269 } 270 } 270 } 271 271 272 void 272 void 273 G4ComponentSAIDTotalXS::PrintWarning(const G4P 273 G4ComponentSAIDTotalXS::PrintWarning(const G4ParticleDefinition* prim, 274 const G4ParticleDefinition* sec, 274 const G4ParticleDefinition* sec, 275 G4int Z, G4int N, 275 G4int Z, G4int N, 276 const G4String& ss1, 276 const G4String& ss1, 277 const G4String& ss2) 277 const G4String& ss2) 278 { 278 { 279 G4cout << ss1 << ": " << ss2 << G4endl; 279 G4cout << ss1 << ": " << ss2 << G4endl; 280 G4cout << "For Z= " << Z << " N= " << N << " 280 G4cout << "For Z= " << Z << " N= " << N << " of "; 281 if(prim) { G4cout << prim->GetParticleName() 281 if(prim) { G4cout << prim->GetParticleName() << " "; } 282 if(sec) { G4cout << " x-section to " << sec- 282 if(sec) { G4cout << " x-section to " << sec->GetParticleName(); } 283 G4cout << G4endl; 283 G4cout << G4endl; 284 } 284 } 285 285