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 // 080721 Create adjust_final_state method by << 27 //080721 Create adjust_final_state method by T. Koi 28 // 080801 Residual reconstruction with theNDLD << 28 //080801 Residual reconstruction with theNDLDataA,Z (A, Z, and momentum are adjusted) by T. Koi 29 // 101110 Set lower limit for gamma energy(1ke << 29 //101110 Set lower limit for gamma energy(1keV) by T. Koi 30 // P. Arce, June-2014 Conversion neutron_hp to 30 // P. Arce, June-2014 Conversion neutron_hp to particle_hp 31 // 31 // 32 32 33 #include "G4ParticleHPFinalState.hh" 33 #include "G4ParticleHPFinalState.hh" 34 34 35 #include "G4Alpha.hh" << 35 #include "G4PhysicalConstants.hh" 36 #include "G4Deuteron.hh" << 36 #include "G4SystemOfUnits.hh" 37 #include "G4Gamma.hh" << 38 #include "G4He3.hh" << 39 #include "G4IonTable.hh" 37 #include "G4IonTable.hh" >> 38 #include "G4Gamma.hh" 40 #include "G4Neutron.hh" 39 #include "G4Neutron.hh" 41 #include "G4PhysicalConstants.hh" << 42 #include "G4Proton.hh" 40 #include "G4Proton.hh" 43 #include "G4RandomDirection.hh" << 41 #include "G4Deuteron.hh" 44 #include "G4SystemOfUnits.hh" << 45 #include "G4Triton.hh" 42 #include "G4Triton.hh" >> 43 #include "G4Alpha.hh" 46 44 47 G4ParticleHPFinalState::G4ParticleHPFinalState << 45 void G4ParticleHPFinalState::adjust_final_state ( G4LorentzVector init_4p_lab ) 48 { 46 { 49 theProjectile = G4Neutron::Neutron(); << 50 theResult.Put(nullptr); << 51 fManager = G4ParticleHPManager::GetInstance( << 52 ionTable = G4IonTable::GetIonTable(); << 53 } << 54 47 55 G4ParticleHPFinalState::~G4ParticleHPFinalStat << 48 G4double minimum_energy = 1*keV; 56 { << 57 delete theResult.Get(); << 58 } << 59 49 60 void G4ParticleHPFinalState::adjust_final_stat << 50 if ( G4ParticleHPManager::GetInstance()->GetDoNotAdjustFinalState() ) return; 61 { << 62 G4double minimum_energy = 1 * keV; << 63 << 64 if (fManager->GetDoNotAdjustFinalState()) re << 65 51 66 auto nSecondaries = (G4int)theResult.Get()-> << 52 G4int nSecondaries = theResult.Get()->GetNumberOfSecondaries(); 67 53 68 G4int sum_Z = 0; << 54 G4int sum_Z = 0; 69 G4int sum_A = 0; << 55 G4int sum_A = 0; 70 G4int max_SecZ = 0; << 56 G4int max_SecZ = 0; 71 G4int max_SecA = 0; << 57 G4int max_SecA = 0; 72 G4int imaxA = -1; << 58 G4int imaxA = -1; 73 for (G4int i = 0; i < nSecondaries; ++i) { << 59 for ( int i = 0 ; i < nSecondaries ; i++ ) 74 auto ptr = theResult.Get()->GetSecondary(i << 60 { 75 sum_Z += ptr->GetAtomicNumber(); << 61 sum_Z += theResult.Get()->GetSecondary( i )->GetParticle()->GetDefinition()->GetAtomicNumber(); 76 max_SecZ = std::max(max_SecZ, ptr->GetAtom << 62 max_SecZ = std::max ( max_SecZ , theResult.Get()->GetSecondary( i )->GetParticle()->GetDefinition()->GetAtomicNumber() ); 77 sum_A += ptr->GetAtomicMass(); << 63 sum_A += theResult.Get()->GetSecondary( i )->GetParticle()->GetDefinition()->GetAtomicMass(); 78 max_SecA = std::max(max_SecA, ptr->GetAtom << 64 max_SecA = std::max ( max_SecA , theResult.Get()->GetSecondary( i )->GetParticle()->GetDefinition()->GetAtomicMass() ); 79 if (ptr->GetAtomicMass() == max_SecA) << 65 if ( theResult.Get()->GetSecondary( i )->GetParticle()->GetDefinition()->GetAtomicMass() == max_SecA ) imaxA = i; 80 imaxA = i; << 81 #ifdef G4PHPDEBUG 66 #ifdef G4PHPDEBUG 82 if (fManager->GetDEBUG()) << 67 if( getenv("G4ParticleHPDebug")) G4cout << "G4ParticleHPFinalState::adjust_final_stat SECO " << i << " " <<theResult.Get()->GetSecondary( i )->GetParticle()->GetDefinition()->GetParticleName() << G4endl; 83 G4cout << "G4ParticleHPFinalState::adjus << 84 << ptr->GetParticleName() << G4en << 85 #endif 68 #endif 86 } << 87 69 88 G4ParticleDefinition* resi_pd = nullptr; << 70 } >> 71 >> 72 G4ParticleDefinition* resi_pd = NULL; 89 73 90 G4int baseZNew = theBaseZ; << 74 G4double baseZNew = theBaseZ; 91 G4int baseANew = theBaseA; << 75 G4double baseANew = theBaseA; 92 if (theProjectile == G4Neutron::Neutron()) { << 76 if( theProjectile == G4Neutron::Neutron() ) { 93 baseANew++; << 77 baseANew ++; 94 } << 78 } else if( theProjectile == G4Proton::Proton() ) { 95 else if (theProjectile == G4Proton::Proton() << 79 baseZNew ++; 96 baseZNew++; << 80 baseANew ++; 97 baseANew++; << 81 } else if( theProjectile == G4Deuteron::Deuteron() ) { 98 } << 82 baseZNew ++; 99 else if (theProjectile == G4Deuteron::Deuter << 83 baseANew += 2; 100 baseZNew++; << 84 } else if( theProjectile == G4Triton::Triton() ) { 101 baseANew += 2; << 85 baseZNew ++; 102 } << 86 baseANew += 3; 103 else if (theProjectile == G4Triton::Triton() << 87 } else if( theProjectile == G4Alpha::Alpha() ) { 104 baseZNew++; << 88 baseZNew += 2; 105 baseANew += 3; << 89 baseANew += 4; 106 } << 90 } 107 else if (theProjectile == G4He3::He3()) { << 108 baseZNew += 2; << 109 baseANew += 3; << 110 } << 111 else if (theProjectile == G4Alpha::Alpha()) << 112 baseZNew += 2; << 113 baseANew += 4; << 114 } << 115 91 116 #ifdef G4PHPDEBUG 92 #ifdef G4PHPDEBUG 117 if (fManager->GetDEBUG()) << 93 if( getenv("G4ParticleHPDebug")) G4cout << "G4ParticleHPFinalState::adjust_final_stat BaseZ " << baseZNew << " BaseA " << baseANew << " sum_Z " << sum_Z << " sum_A " << sum_A << G4endl; 118 G4cout << "G4ParticleHPFinalState::adjust_ << 119 << baseANew << " sum_Z " << sum_Z < << 120 #endif 94 #endif 121 95 122 G4bool needOneMoreSec = false; << 96 G4bool needOneMoreSec = false; 123 G4ParticleDefinition* oneMoreSec_pd = nullpt << 97 G4ParticleDefinition* oneMoreSec_pd = NULL; 124 if (baseZNew == sum_Z && baseANew == sum_A) << 98 if ( (int)(baseZNew - sum_Z) == 0 && (int)(baseANew - sum_A) == 0 ) 125 // All secondaries are already created; << 99 { 126 resi_pd = theResult.Get()->GetSecondary(im << 100 //All secondaries are already created; 127 } << 101 resi_pd = theResult.Get()->GetSecondary( imaxA )->GetParticle()->GetDefinition(); 128 else { << 102 } 129 if (max_SecA >= baseANew - sum_A) { << 103 else 130 // Most heavy secondary is interpreted a << 104 { 131 resi_pd = theResult.Get()->GetSecondary( << 105 if ( max_SecA > int(baseANew - sum_A) ) 132 needOneMoreSec = true; << 106 { 133 } << 107 //Most heavy secondary is interpreted as residual 134 else { << 108 resi_pd = theResult.Get()->GetSecondary( imaxA )->GetParticle()->GetDefinition(); 135 // creation of residual is required << 109 needOneMoreSec = true; 136 resi_pd = ionTable->GetIon(baseZNew - su << 110 } 137 } << 111 else 138 << 112 { 139 if (needOneMoreSec) { << 113 //creation of residual is requierd 140 if (baseZNew == sum_Z && baseANew == sum << 114 resi_pd = G4IonTable::GetIonTable()->GetIon ( int(baseZNew - sum_Z) , (int)(baseANew - sum_A) , 0.0 ); 141 // In this case, one neutron is added << 115 } 142 if (baseANew - sum_A > 1) << 116 143 G4cout << "More than one neutron is << 117 if ( needOneMoreSec ) 144 << G4endl; << 118 { 145 oneMoreSec_pd = G4Neutron::Neutron(); << 119 if ( int(baseZNew - sum_Z) == 0 && (int)(baseANew - sum_A) > 0 ) 146 } << 120 { 147 else { << 121 if ( int(baseANew - sum_A) > 1 ) G4cout << "More than one neutron is required for the balance of baryon number!" << G4endl; >> 122 oneMoreSec_pd = theProjectile; >> 123 } >> 124 else >> 125 { 148 #ifdef G4PHPDEBUG 126 #ifdef G4PHPDEBUG 149 if (fManager->GetDEBUG()) << 127 if( getenv("G4ParticleHPDebug")) G4cout << this << "G4ParticleHPFinalState oneMoreSec_pd Z " << baseZNew << " - " << sum_Z << " A " << baseANew << " - " << sum_A << " projectile " << theProjectile->GetParticleName() << G4endl; 150 G4cout << this << "G4ParticleHPFinal << 151 << baseZNew << " - " << sum_Z << 152 << " A " << baseANew << " - " << 153 << theProjectile->GetParticle << 154 #endif 128 #endif 155 oneMoreSec_pd = << 129 oneMoreSec_pd = G4IonTable::GetIonTable()->GetIon ( int(baseZNew - sum_Z) , (int)(baseANew - sum_A) , 0.0 ); 156 G4IonTable::GetIonTable()->GetIon(ba << 130 if( !oneMoreSec_pd ) { 157 if (oneMoreSec_pd == nullptr) { << 131 G4cerr << this << "G4ParticleHPFinalState oneMoreSec_pd Z " << baseZNew << " - " << sum_Z << " A " << baseANew << " - " << sum_A << " projectile " << theProjectile->GetParticleName() << G4endl; 158 G4ExceptionDescription ed; << 132 G4Exception("G4ParticleHPFinalState:adjust_final_state", 159 ed << "G4ParticleHPFinalState oneMor << 133 "Warning", 160 << " A=" << baseANew << " - " << 134 JustWarning, 161 << theProjectile->GetParticle << 135 "No adjustment will be done!"); 162 G4Exception("G4ParticleHPFinalState: << 136 return; 163 ed, "No adjustment will << 137 } 164 return; << 138 } >> 139 } >> 140 >> 141 if ( resi_pd == NULL ) >> 142 { >> 143 // theNDLDataZ,A has the Z and A of used NDL file >> 144 G4double ndlZNew = theNDLDataZ; >> 145 G4double ndlANew = theNDLDataA; >> 146 if( theProjectile == G4Neutron::Neutron() ) { >> 147 ndlANew ++; >> 148 } else if( theProjectile == G4Proton::Proton() ) { >> 149 ndlZNew ++; >> 150 ndlANew ++; >> 151 } else if( theProjectile == G4Deuteron::Deuteron() ) { >> 152 ndlZNew ++; >> 153 ndlANew += 2; >> 154 } else if( theProjectile == G4Triton::Triton() ) { >> 155 ndlZNew ++; >> 156 ndlANew += 3; >> 157 } else if( theProjectile == G4Alpha::Alpha() ) { >> 158 ndlZNew += 2; >> 159 ndlANew += 4; >> 160 } >> 161 // theNDLDataZ,A has the Z and A of used NDL file >> 162 if ( (int)(ndlZNew - sum_Z) == 0 && (int)(ndlANew - sum_A) == 0 ) >> 163 { >> 164 G4int dif_Z = ( int ) ( theNDLDataZ - theBaseZ ); >> 165 G4int dif_A = ( int ) ( theNDLDataA - theBaseA ); >> 166 resi_pd = G4IonTable::GetIonTable()->GetIon ( max_SecZ - dif_Z , max_SecA - dif_A , 0.0 ); >> 167 if( !resi_pd ) { >> 168 G4cerr << "G4ParticleHPFinalState resi_pd Z " << max_SecZ << " - " << dif_Z << " A " << max_SecA << " - " << dif_A << " projectile " << theProjectile->GetParticleName() << G4endl; >> 169 G4Exception("G4ParticleHPFinalState:adjust_final_state", >> 170 "Warning", >> 171 JustWarning, >> 172 "No adjustment will be done!"); >> 173 return; >> 174 } >> 175 >> 176 for ( int i = 0 ; i < nSecondaries ; i++ ) >> 177 { >> 178 if ( theResult.Get()->GetSecondary( i )->GetParticle()->GetDefinition()->GetAtomicNumber() == max_SecZ >> 179 && theResult.Get()->GetSecondary( i )->GetParticle()->GetDefinition()->GetAtomicMass() == max_SecA ) >> 180 { >> 181 G4ThreeVector p = theResult.Get()->GetSecondary( i )->GetParticle()->GetMomentum(); >> 182 p = p * resi_pd->GetPDGMass()/ G4IonTable::GetIonTable()->GetIon ( max_SecZ , max_SecA , 0.0 )->GetPDGMass(); >> 183 theResult.Get()->GetSecondary( i )->GetParticle()->SetDefinition( resi_pd ); >> 184 theResult.Get()->GetSecondary( i )->GetParticle()->SetMomentum( p ); >> 185 } >> 186 } 165 } 187 } 166 } 188 } 167 } << 189 } 168 190 169 if (resi_pd == nullptr) { << 170 // theNDLDataZ,A has the Z and A of used << 171 G4int ndlZNew = theNDLDataZ; << 172 G4int ndlANew = theNDLDataA; << 173 if (theProjectile == G4Neutron::Neutron( << 174 ndlANew++; << 175 } << 176 else if (theProjectile == G4Proton::Prot << 177 ndlZNew++; << 178 ndlANew++; << 179 } << 180 else if (theProjectile == G4Deuteron::De << 181 ndlZNew++; << 182 ndlANew += 2; << 183 } << 184 else if (theProjectile == G4Triton::Trit << 185 ndlZNew++; << 186 ndlANew += 3; << 187 } << 188 else if (theProjectile == G4He3::He3()) << 189 ndlZNew += 2; << 190 ndlANew += 3; << 191 } << 192 else if (theProjectile == G4Alpha::Alpha << 193 ndlZNew += 2; << 194 ndlANew += 4; << 195 } << 196 // theNDLDataZ,A has the Z and A of used << 197 if (ndlZNew == sum_Z && ndlANew == sum_A << 198 G4int dif_Z = theNDLDataZ - theBaseZ; << 199 G4int dif_A = theNDLDataA - theBaseA; << 200 resi_pd = ionTable->GetIon(max_SecZ - << 201 if (resi_pd == nullptr) { << 202 G4ExceptionDescription ed; << 203 ed << "resi_pd Z=" << max_SecZ << " << 204 << max_SecA << " - " << dif_A << 205 << theProjectile->GetParticle << 206 G4Exception("G4ParticleHPFinalState: << 207 ed, "No adjustment will << 208 return; << 209 } << 210 191 211 for (G4int i = 0; i < nSecondaries; ++ << 192 G4LorentzVector secs_4p_lab( 0.0 ); 212 auto ptr = theResult.Get()->GetSecon << 193 213 if (ptr->GetDefinition()->GetAtomicN << 194 G4int n_sec = theResult.Get()->GetNumberOfSecondaries(); 214 ptr->GetDefinition()->GetAtomicM << 195 G4double fast = 0; 215 { << 196 G4double slow = 1; 216 G4ThreeVector p = ptr->GetMomentum << 197 G4int ifast = 0; 217 / ionTable->GetIon(max_SecZ, m << 198 G4int islow = 0; 218 ptr->SetDefinition(resi_pd); << 199 G4int ires = -1; 219 ptr->SetMomentum(p); << 200 220 } << 201 for ( G4int i = 0 ; i < n_sec ; i++ ) 221 } << 202 { >> 203 >> 204 //G4cout << "HP_DB " << i >> 205 // << " " << theResult.GetSecondary( i )->GetParticle()->GetDefinition()->GetParticleName() >> 206 // << " 4p " << theResult.GetSecondary( i )->GetParticle()->Get4Momentum() >> 207 // << " ke " << theResult.GetSecondary( i )->GetParticle()->Get4Momentum().e() - theResult.GetSecondary( i )->GetParticle()->GetDefinition()->GetPDGMass() >> 208 // << G4endl; >> 209 >> 210 secs_4p_lab += theResult.Get()->GetSecondary( i )->GetParticle()->Get4Momentum(); >> 211 >> 212 G4double beta = 0; >> 213 if ( theResult.Get()->GetSecondary( i )->GetParticle()->GetDefinition() != G4Gamma::Gamma() ) >> 214 { >> 215 beta = theResult.Get()->GetSecondary( i )->GetParticle()->Get4Momentum().beta(); >> 216 } >> 217 else >> 218 { >> 219 beta = 1; >> 220 } >> 221 >> 222 if ( theResult.Get()->GetSecondary( i )->GetParticle()->GetDefinition() == resi_pd ) ires = i; >> 223 >> 224 if ( slow > beta && beta != 0 ) >> 225 { >> 226 slow = beta; >> 227 islow = i; >> 228 } >> 229 >> 230 if ( fast <= beta ) >> 231 { >> 232 if ( fast != 1 ) >> 233 { >> 234 fast = beta; >> 235 ifast = i; >> 236 } >> 237 else >> 238 { >> 239 // fast is already photon then check E >> 240 G4double e = theResult.Get()->GetSecondary( i )->GetParticle()->Get4Momentum().e(); >> 241 if ( e > theResult.Get()->GetSecondary( ifast )->GetParticle()->Get4Momentum().e() ) >> 242 { >> 243 // among photons, the highest E becomes the fastest >> 244 ifast = i; >> 245 } >> 246 } >> 247 } >> 248 } >> 249 >> 250 >> 251 G4LorentzVector dif_4p = init_4p_lab - secs_4p_lab; >> 252 >> 253 //G4cout << "HP_DB dif_4p " << init_4p_lab - secs_4p_lab << G4endl; >> 254 //G4cout << "HP_DB dif_3p mag " << ( dif_4p.v() ).mag() << G4endl; >> 255 //G4cout << "HP_DB dif_e " << dif_4p.e() - ( dif_4p.v() ).mag()<< G4endl; >> 256 >> 257 G4LorentzVector p4(0); >> 258 if ( ires == -1 ) >> 259 { >> 260 // Create and Add Residual Nucleus >> 261 ires = nSecondaries; >> 262 nSecondaries += 1; >> 263 >> 264 G4DynamicParticle* res = new G4DynamicParticle ( resi_pd , dif_4p.v() ); >> 265 theResult.Get()->AddSecondary ( res ); >> 266 >> 267 p4 = res->Get4Momentum(); >> 268 if ( slow > p4.beta() ) >> 269 { >> 270 slow = p4.beta(); >> 271 islow = ires; >> 272 } >> 273 dif_4p = init_4p_lab - ( secs_4p_lab + p4 ); >> 274 } >> 275 >> 276 if ( needOneMoreSec && oneMoreSec_pd) >> 277 // >> 278 // fca: this is not a fix, this is a crash avoidance... >> 279 // fca: the baryon number is still wrong, most probably because it >> 280 // fca: should have been decreased, but since we could not create a particle >> 281 // fca: we just do not add it >> 282 // >> 283 { >> 284 nSecondaries += 1; >> 285 G4DynamicParticle* one = new G4DynamicParticle ( oneMoreSec_pd , dif_4p.v() ); >> 286 theResult.Get()->AddSecondary ( one ); >> 287 p4 = one->Get4Momentum(); >> 288 if ( slow > p4.beta() ) >> 289 { >> 290 slow = p4.beta(); >> 291 islow = nSecondaries-1; //Because the first is 0th, so the last becomes "nSecondaries-1" 222 } 292 } 223 } << 293 dif_4p = init_4p_lab - ( secs_4p_lab + p4 ); 224 } << 294 } 225 295 226 G4LorentzVector secs_4p_lab(0.0); << 296 //Which is bigger dif_p or dif_e >> 297 >> 298 if ( dif_4p.v().mag() < std::abs( dif_4p.e() ) ) >> 299 { >> 300 >> 301 // Adjust p >> 302 //if ( dif_4p.v().mag() < 1*MeV ) >> 303 if ( minimum_energy < dif_4p.v().mag() && dif_4p.v().mag() < 1*MeV ) >> 304 { >> 305 >> 306 nSecondaries += 1; >> 307 theResult.Get()->AddSecondary ( new G4DynamicParticle ( G4Gamma::Gamma() , dif_4p.v() ) ); 227 308 228 auto n_sec = (G4int)theResult.Get()->GetNumb << 229 G4double fast = 0; << 230 G4double slow = 1; << 231 G4int ifast = 0; << 232 G4int islow = 0; << 233 G4int ires = -1; << 234 << 235 for (G4int i = 0; i < n_sec; ++i) { << 236 auto ptr = theResult.Get()->GetSecondary(i << 237 secs_4p_lab += ptr->Get4Momentum(); << 238 << 239 G4double beta = 0; << 240 if (ptr->GetDefinition() != G4Gamma::Gamma << 241 beta = ptr->Get4Momentum().beta(); << 242 } << 243 else { << 244 beta = 1.0; << 245 } << 246 << 247 if (ptr->GetDefinition() == resi_pd) ires << 248 << 249 if (slow > beta && beta != 0) { << 250 slow = beta; << 251 islow = i; << 252 } << 253 << 254 if (fast <= beta) { << 255 if (fast != 1) { << 256 fast = beta; << 257 ifast = i; << 258 } << 259 else { << 260 // fast is already photon then check E << 261 G4double e = ptr->Get4Momentum().e(); << 262 if (e > theResult.Get()->GetSecondary( << 263 // among photons, the highest E beco << 264 ifast = i; << 265 } << 266 } 309 } 267 } << 310 else 268 } << 311 { >> 312 //G4cout << "HP_DB Difference in dif_p is too large (>1MeV) or too small(<1keV) to adjust, so that give up tuning" << G4endl; >> 313 } 269 314 270 G4LorentzVector dif_4p = init_4p_lab - secs_ << 315 } >> 316 else >> 317 { >> 318 >> 319 // dif_p > dif_e >> 320 // at first momentum >> 321 // Move residual momentum >> 322 >> 323 p4 = theResult.Get()->GetSecondary( ires )->GetParticle()->Get4Momentum(); >> 324 theResult.Get()->GetSecondary( ires )->GetParticle()->SetMomentum( p4.v() + dif_4p.v() ); >> 325 dif_4p = init_4p_lab - ( secs_4p_lab - p4 + theResult.Get()->GetSecondary( ires )->GetParticle()->Get4Momentum() ); >> 326 >> 327 //G4cout << "HP_DB new residual kinetic energy " << theResult.GetSecondary( ires )->GetParticle()->GetKineticEnergy() << G4endl; >> 328 >> 329 } >> 330 >> 331 G4double dif_e = dif_4p.e() - ( dif_4p.v() ).mag(); >> 332 //G4cout << "HP_DB dif_e " << dif_e << G4endl; >> 333 >> 334 if ( dif_e > 0 ) >> 335 { >> 336 >> 337 // create 2 gamma >> 338 >> 339 nSecondaries += 2; >> 340 G4double e1 = ( dif_4p.e() -dif_4p.v().mag() ) / 2; >> 341 >> 342 if ( minimum_energy < e1 ) >> 343 { >> 344 G4double costh = 2.*G4UniformRand()-1.; >> 345 G4double phi = twopi*G4UniformRand(); >> 346 G4ThreeVector dir( std::sin(std::acos(costh))*std::cos(phi), >> 347 std::sin(std::acos(costh))*std::sin(phi), >> 348 costh); >> 349 theResult.Get()->AddSecondary ( new G4DynamicParticle ( G4Gamma::Gamma() , e1*dir ) ); >> 350 theResult.Get()->AddSecondary ( new G4DynamicParticle ( G4Gamma::Gamma() , -e1*dir ) ); >> 351 } >> 352 else >> 353 { >> 354 //G4cout << "HP_DB Difference is too small(<1keV) to adjust, so that neglect it" << G4endl; >> 355 } >> 356 >> 357 } >> 358 else //dif_e < 0 >> 359 { >> 360 >> 361 // At first reduce KE of the fastest secondary; >> 362 G4double ke0 = theResult.Get()->GetSecondary( ifast )->GetParticle()->GetKineticEnergy(); >> 363 G4ThreeVector p0 = theResult.Get()->GetSecondary( ifast )->GetParticle()->GetMomentum(); >> 364 G4ThreeVector dir = ( theResult.Get()->GetSecondary( ifast )->GetParticle()->GetMomentum() ).unit(); >> 365 >> 366 //G4cout << "HP_DB ifast " << ifast << " ke0 " << ke0 << G4endl; >> 367 >> 368 if ( ke0 + dif_e > 0 ) >> 369 { >> 370 theResult.Get()->GetSecondary( ifast )->GetParticle()->SetKineticEnergy( ke0 + dif_e ); >> 371 G4ThreeVector dp = p0 - theResult.Get()->GetSecondary( ifast )->GetParticle()->GetMomentum(); >> 372 >> 373 G4ThreeVector p = theResult.Get()->GetSecondary( islow )->GetParticle()->GetMomentum(); >> 374 //theResult.GetSecondary( islow )->GetParticle()->SetMomentum( p - dif_e*dir ); >> 375 theResult.Get()->GetSecondary( islow )->GetParticle()->SetMomentum( p + dp ); >> 376 } >> 377 else >> 378 { >> 379 //G4cout << "HP_DB Difference in dif_e too large ( <0MeV ) to adjust, so that give up tuning" << G4endl; >> 380 } >> 381 >> 382 } 271 383 272 G4LorentzVector p4(0); << 273 if (ires == -1) { << 274 // Create and Add Residual Nucleus << 275 ires = nSecondaries; << 276 nSecondaries += 1; << 277 << 278 auto res = new G4DynamicParticle(resi_pd, << 279 theResult.Get()->AddSecondary(res, secID); << 280 << 281 p4 = res->Get4Momentum(); << 282 if (slow > p4.beta()) { << 283 slow = p4.beta(); << 284 islow = ires; << 285 } << 286 dif_4p = init_4p_lab - (secs_4p_lab + p4); << 287 } << 288 << 289 if (needOneMoreSec && oneMoreSec_pd != nullp << 290 // << 291 // fca: this is not a fix, this is a crash a << 292 // fca: the baryon number is still wrong, mo << 293 // fca: should have been decreased, but sinc << 294 // fca: we just do not add it << 295 // << 296 { << 297 nSecondaries += 1; << 298 auto one = new G4DynamicParticle(oneMoreSe << 299 theResult.Get()->AddSecondary(one, secID); << 300 p4 = one->Get4Momentum(); << 301 if (slow > p4.beta()) { << 302 slow = p4.beta(); << 303 islow = nSecondaries - 1; // Because th << 304 } << 305 dif_4p = init_4p_lab - (secs_4p_lab + p4); << 306 } << 307 << 308 // Which is bigger dif_p or dif_e << 309 << 310 if (dif_4p.v().mag() < std::abs(dif_4p.e())) << 311 // Adjust p << 312 if (minimum_energy < dif_4p.v().mag() && d << 313 nSecondaries += 1; << 314 theResult.Get()->AddSecondary(new G4Dyna << 315 } << 316 } << 317 else { << 318 // dif_p > dif_e << 319 // at first momentum << 320 // Move residual momentum << 321 p4 = theResult.Get()->GetSecondary(ires)-> << 322 theResult.Get()->GetSecondary(ires)->GetPa << 323 dif_4p = init_4p_lab - << 324 (secs_4p_lab - p4 + theResult.Get()->Get << 325 } << 326 << 327 G4double dif_e = dif_4p.e() - (dif_4p.v()).m << 328 << 329 if (dif_e > 0) { << 330 // create 2 gamma << 331 << 332 nSecondaries += 2; << 333 G4double e1 = (dif_4p.e() - dif_4p.v().mag << 334 << 335 if (minimum_energy < e1) { << 336 G4ThreeVector dir = G4RandomDirection(); << 337 theResult.Get()->AddSecondary(new G4Dyna << 338 theResult.Get()->AddSecondary(new G4Dyna << 339 } << 340 } << 341 else // dif_e < 0 << 342 { << 343 // At first reduce KE of the fastest secon << 344 auto ptr = theResult.Get()->GetSecondary(i << 345 G4double ke0 = ptr->GetKineticEnergy(); << 346 G4ThreeVector p0 = ptr->GetMomentum(); << 347 G4ThreeVector dir = p0.unit(); << 348 << 349 if (ke0 + dif_e > 0) { << 350 ptr->SetKineticEnergy(ke0 + dif_e); << 351 G4ThreeVector dp = p0 - theResult.Get()- << 352 G4ThreeVector p = theResult.Get()->GetSe << 353 theResult.Get()->GetSecondary(islow)->Ge << 354 } << 355 } << 356 } 384 } >> 385 357 386