Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // 27 // Hadronic Process: Energy Range Manager 28 // original by H.P. Wellisch 29 // modified by J.L. Chuma, TRIUMF, 22-Nov-199 30 // Last modified: 24-Mar-1997 31 // fix in the counter-hndling: H.P. Wellisch 32 // throw an exception if no model found: J.L 33 34 #include "G4EnergyRangeManager.hh" 35 #include "Randomize.hh" 36 #include "G4HadronicException.hh" 37 #include "G4SystemOfUnits.hh" 38 39 G4EnergyRangeManager::G4EnergyRangeManager() 40 : theHadronicInteractionCounter(0) 41 {} 42 43 G4EnergyRangeManager::~G4EnergyRangeManager() 44 {} 45 46 void G4EnergyRangeManager::RegisterMe(G4Hadron 47 { 48 if(!a) { return; } 49 if(0 < theHadronicInteractionCounter) { 50 for(G4int i=0; i<theHadronicInteractionCou 51 if(a == theHadronicInteraction[i]) { ret 52 } 53 } 54 theHadronicInteraction.push_back(a); 55 ++theHadronicInteractionCounter; 56 } 57 58 G4HadronicInteraction* 59 G4EnergyRangeManager::GetHadronicInteraction(c 60 G 61 c 62 c 63 { 64 // VI shortcut: if only one interaction is r 65 if(1 == theHadronicInteractionCounter) { ret 66 else if(0 == theHadronicInteractionCounter) 67 G4cout << "G4EnergyRangeManager::GetHadron 68 << "no models defined for a process" << G 69 return nullptr; 70 } 71 72 G4double kineticEnergy = aHadProjectile.GetK 73 // For ions, get kinetic energy per nucleon 74 if ( std::abs( aHadProjectile.GetDefinition( 75 kineticEnergy /= static_cast< G4double >( 76 } 77 78 G4int cou = 0, memory = 0, memor2 = 0; 79 G4double emi1 = 0.0, ema1 = 0.0, emi2 = 0.0, 80 81 for (G4int i = 0; i<theHadronicInteractionCo 82 if ( theHadronicInteraction[i]->IsApplicab 83 G4double low = theHadronicInteraction[i 84 G4double high = theHadronicInteraction[i 85 if (low <= kineticEnergy && high >= kine 86 ++cou; 87 emi2 = emi1; 88 ema2 = ema1; 89 emi1 = low; 90 ema1 = high; 91 memor2 = memory; 92 memory = i; 93 } 94 } 95 } 96 97 G4HadronicInteraction* hi = nullptr; 98 switch (cou) { 99 case 0: 100 G4cout << "No model found out of " << th 101 for( G4int j=0; j<theHadronicInteraction 102 G4HadronicInteraction* hint=theHadronicInter 103 G4cout << " "<< j << ". Elow= " << hint-> 104 <<", Ehigh= " << hint->GetMaxEnergy(a 105 <<" " << hint->GetModelName() << G4 106 } 107 break; 108 109 case 1: 110 hi = theHadronicInteraction[memory]; 111 break; 112 113 case 2: 114 if( (emi2<=emi1 && ema2>=ema1) || (emi2> 115 G4cout << "Energy ranges of two models fully 116 for( G4int j=0; j<theHadronicInteractionCoun 117 G4HadronicInteraction* hint=theHadronicInt 118 G4cout << " "<< j << ". Elow= " << hint 119 <<", Ehigh= " << hint->GetMaxEnergy(aMate 120 <<" " << hint->GetModelName() << G4endl 121 } 122 } else { 123 G4double rand = G4UniformRand(); 124 G4int mem; 125 if( emi1 < emi2 ) { 126 if( (ema1-kineticEnergy) < rand*(ema1-emi2 127 mem = memor2; 128 } else { 129 mem = memory; 130 } 131 } else { 132 if( (ema2-kineticEnergy) < rand*(ema2-emi1 133 mem = memory; 134 } else { 135 mem = memor2; 136 } 137 } 138 hi = theHadronicInteraction[mem]; 139 } 140 break; 141 142 default: 143 G4cout << "More than two competing model 144 for( G4int j=0; j<theHadronicInteraction 145 G4HadronicInteraction* hint=theHadronicInter 146 G4cout << " "<< j << ". Elow= " << hint-> 147 <<", Ehigh= " << hint->GetMaxEnergy(a 148 <<" " << hint->GetModelName() << G4 149 } 150 break; 151 } 152 return hi; 153 } 154 155 std::vector<G4HadronicInteraction*>& 156 G4EnergyRangeManager::GetHadronicInteractionLi 157 { 158 return theHadronicInteraction; 159 } 160 161 void G4EnergyRangeManager::Dump( G4int verbose 162 { 163 G4cout << "G4EnergyRangeManager " << this << 164 for (G4int i = 0 ; i < theHadronicInteractio 165 G4cout << " HadronicModel " << i <<":" 166 << theHadronicInteraction[i]->GetMo 167 if (verbose > 0) { 168 G4cout << " Minimum Energy " 169 << theHadronicInteraction[i]->GetMinEne 170 << "Maximum Energy " 171 << theHadronicInteraction[i]->GetMaxEne 172 << G4endl; 173 } 174 } 175 } 176 177 void 178 G4EnergyRangeManager::BuildPhysicsTable(const 179 { 180 for (auto & hadi : theHadronicInteraction) { 181 hadi->BuildPhysicsTable( aParticleType ); 182 } 183 } 184 185 186