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 // $Id: G4EnergyRangeManager.cc 71734 2013-06-21 08:53:11Z gcosmo $ 26 // 27 // 27 // Hadronic Process: Energy Range Manager 28 // Hadronic Process: Energy Range Manager 28 // original by H.P. Wellisch 29 // original by H.P. Wellisch 29 // modified by J.L. Chuma, TRIUMF, 22-Nov-199 30 // modified by J.L. Chuma, TRIUMF, 22-Nov-1996 30 // Last modified: 24-Mar-1997 31 // Last modified: 24-Mar-1997 31 // fix in the counter-hndling: H.P. Wellisch 32 // fix in the counter-hndling: H.P. Wellisch 04-Apr-97 32 // throw an exception if no model found: J.L 33 // throw an exception if no model found: J.L. Chuma 04-Apr-97 33 34 34 #include "G4EnergyRangeManager.hh" 35 #include "G4EnergyRangeManager.hh" 35 #include "Randomize.hh" 36 #include "Randomize.hh" 36 #include "G4HadronicException.hh" 37 #include "G4HadronicException.hh" 37 #include "G4SystemOfUnits.hh" << 38 38 39 39 G4EnergyRangeManager::G4EnergyRangeManager() 40 G4EnergyRangeManager::G4EnergyRangeManager() 40 : theHadronicInteractionCounter(0) 41 : theHadronicInteractionCounter(0) 41 {} << 42 { >> 43 for (G4int i = 0; i < G4EnergyRangeManager::MAX_NUMBER_OF_MODELS; i++) >> 44 theHadronicInteraction[i] = 0; >> 45 } >> 46 >> 47 >> 48 G4EnergyRangeManager::G4EnergyRangeManager(const G4EnergyRangeManager& right) >> 49 { >> 50 if (this != &right) { >> 51 theHadronicInteractionCounter = right.theHadronicInteractionCounter; >> 52 for (G4int i = 0; i < theHadronicInteractionCounter; ++i) >> 53 theHadronicInteraction[i] = right.theHadronicInteraction[i]; >> 54 } >> 55 } >> 56 >> 57 >> 58 G4EnergyRangeManager& G4EnergyRangeManager::operator=( >> 59 const G4EnergyRangeManager& right) >> 60 { >> 61 if (this != &right) { >> 62 theHadronicInteractionCounter = right.theHadronicInteractionCounter; >> 63 for (G4int i=0; i<theHadronicInteractionCounter; ++i) >> 64 theHadronicInteraction[i] = right.theHadronicInteraction[i]; >> 65 } >> 66 return *this; >> 67 } 42 68 43 G4EnergyRangeManager::~G4EnergyRangeManager() << 44 {} << 45 69 46 void G4EnergyRangeManager::RegisterMe(G4Hadron 70 void G4EnergyRangeManager::RegisterMe(G4HadronicInteraction* a) 47 { 71 { 48 if(!a) { return; } << 72 if (theHadronicInteractionCounter+1 > MAX_NUMBER_OF_MODELS) { 49 if(0 < theHadronicInteractionCounter) { << 73 throw G4HadronicException(__FILE__, __LINE__,"RegisterMe: TOO MANY MODELS"); 50 for(G4int i=0; i<theHadronicInteractionCou << 51 if(a == theHadronicInteraction[i]) { ret << 52 } << 53 } 74 } 54 theHadronicInteraction.push_back(a); << 75 theHadronicInteraction[ theHadronicInteractionCounter++ ] = a; 55 ++theHadronicInteractionCounter; << 56 } 76 } 57 77 >> 78 58 G4HadronicInteraction* 79 G4HadronicInteraction* 59 G4EnergyRangeManager::GetHadronicInteraction(c << 80 G4EnergyRangeManager::GetHadronicInteraction(const G4double kineticEnergy, 60 G << 61 c 81 const G4Material* aMaterial, 62 c 82 const G4Element* anElement) const 63 { 83 { 64 // VI shortcut: if only one interaction is r << 84 G4int counter = GetHadronicInteractionCounter(); 65 if(1 == theHadronicInteractionCounter) { ret << 85 if (counter == 0) throw G4HadronicException(__FILE__, __LINE__, 66 else if(0 == theHadronicInteractionCounter) << 86 "GetHadronicInteraction: NO MODELS STORED"); 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 87 78 G4int cou = 0, memory = 0, memor2 = 0; 88 G4int cou = 0, memory = 0, memor2 = 0; 79 G4double emi1 = 0.0, ema1 = 0.0, emi2 = 0.0, 89 G4double emi1 = 0.0, ema1 = 0.0, emi2 = 0.0, ema2 = 0.0; 80 90 81 for (G4int i = 0; i<theHadronicInteractionCo << 91 for (G4int i = 0; i < counter; i++) { 82 if ( theHadronicInteraction[i]->IsApplicab << 92 G4double low = theHadronicInteraction[i]->GetMinEnergy( aMaterial, anElement ); 83 G4double low = theHadronicInteraction[i << 93 // Work-around for particles with 0 kinetic energy, which still 84 G4double high = theHadronicInteraction[i << 94 // require a model to return a ParticleChange 85 if (low <= kineticEnergy && high >= kine << 95 if (low == 0.) low = -DBL_MIN; 86 ++cou; << 96 G4double high = theHadronicInteraction[i]->GetMaxEnergy( aMaterial, anElement ); 87 emi2 = emi1; << 97 if (low < kineticEnergy && high >= kineticEnergy) { 88 ema2 = ema1; << 98 ++cou; 89 emi1 = low; << 99 emi2 = emi1; 90 ema1 = high; << 100 ema2 = ema1; 91 memor2 = memory; << 101 emi1 = low; 92 memory = i; << 102 ema1 = high; 93 } << 103 memor2 = memory; >> 104 memory = i; 94 } 105 } 95 } 106 } 96 107 97 G4HadronicInteraction* hi = nullptr; << 108 G4int mem = -1; >> 109 G4double rand; 98 switch (cou) { 110 switch (cou) { 99 case 0: 111 case 0: 100 G4cout << "No model found out of " << th << 112 G4cout<<"G4EnergyRangeManager:GetHadronicInteraction: counter="<<counter<<", Ek=" 101 for( G4int j=0; j<theHadronicInteraction << 113 <<kineticEnergy<<", Material = "<<aMaterial->GetName()<<", Element = " 102 G4HadronicInteraction* hint=theHadronicInter << 114 <<anElement->GetName()<<G4endl; 103 G4cout << " "<< j << ". Elow= " << hint-> << 115 for( G4int j=0; j<counter; j++ ) 104 <<", Ehigh= " << hint->GetMaxEnergy(a << 116 { 105 <<" " << hint->GetModelName() << G4 << 117 G4HadronicInteraction* HInt=theHadronicInteraction[j]; 106 } << 118 G4cout<<"*"<<j<<"* low=" <<HInt->GetMinEnergy(aMaterial,anElement) 107 break; << 119 <<", high="<<HInt->GetMaxEnergy(aMaterial,anElement)<<G4endl; 108 << 120 } >> 121 throw G4HadronicException(__FILE__, __LINE__, >> 122 "GetHadronicInteraction: No Model found"); >> 123 return 0; 109 case 1: 124 case 1: 110 hi = theHadronicInteraction[memory]; << 125 mem = memory; 111 break; << 126 break; 112 << 113 case 2: 127 case 2: 114 if( (emi2<=emi1 && ema2>=ema1) || (emi2> << 128 if( (emi2<=emi1 && ema2>=ema1) || (emi2>=emi1 && ema2<=ema1) ) 115 G4cout << "Energy ranges of two models fully << 129 { 116 for( G4int j=0; j<theHadronicInteractionCoun << 130 G4cout<<"G4EnergyRangeManager:GetHadronicInteraction: counter="<<counter<<", Ek=" 117 G4HadronicInteraction* hint=theHadronicInt << 131 <<kineticEnergy<<", Material = "<<aMaterial->GetName()<<", Element = " 118 G4cout << " "<< j << ". Elow= " << hint << 132 <<anElement->GetName()<<G4endl; 119 <<", Ehigh= " << hint->GetMaxEnergy(aMate << 133 if(counter) for( G4int j=0; j<counter; j++ ) 120 <<" " << hint->GetModelName() << G4endl << 134 { 121 } << 135 G4HadronicInteraction* HInt=theHadronicInteraction[j]; 122 } else { << 136 G4cout<<"*"<<j<<"* low=" <<HInt->GetMinEnergy(aMaterial,anElement) 123 G4double rand = G4UniformRand(); << 137 <<", high="<<HInt->GetMaxEnergy(aMaterial,anElement)<<G4endl; 124 G4int mem; << 138 } 125 if( emi1 < emi2 ) { << 139 throw G4HadronicException(__FILE__, __LINE__, 126 if( (ema1-kineticEnergy) < rand*(ema1-emi2 << 140 "GetHadronicInteraction: Energy ranges of two models fully overlapping"); 127 mem = memor2; << 141 } 128 } else { << 142 rand = G4UniformRand(); 129 mem = memory; << 143 if( emi1 < emi2 ) 130 } << 144 { 131 } else { << 145 if( (ema1-kineticEnergy)/(ema1-emi2)<rand ) 132 if( (ema2-kineticEnergy) < rand*(ema2-emi1 << 146 mem = memor2; 133 mem = memory; << 147 else 134 } else { << 148 mem = memory; 135 mem = memor2; << 149 } else { 136 } << 150 if( (ema2-kineticEnergy)/(ema2-emi1)<rand ) 137 } << 151 mem = memory; 138 hi = theHadronicInteraction[mem]; << 152 else 139 } << 153 mem = memor2; 140 break; << 154 } 141 << 155 break; 142 default: 156 default: 143 G4cout << "More than two competing model << 157 throw G4HadronicException(__FILE__, __LINE__, 144 for( G4int j=0; j<theHadronicInteraction << 158 "GetHadronicInteraction: More than two competing models in this energy range"); 145 G4HadronicInteraction* hint=theHadronicInter << 146 G4cout << " "<< j << ". Elow= " << hint-> << 147 <<", Ehigh= " << hint->GetMaxEnergy(a << 148 <<" " << hint->GetModelName() << G4 << 149 } << 150 break; << 151 } 159 } 152 return hi; << 160 >> 161 return theHadronicInteraction[mem]; 153 } 162 } 154 163 155 std::vector<G4HadronicInteraction*>& << 156 G4EnergyRangeManager::GetHadronicInteractionLi << 157 { << 158 return theHadronicInteraction; << 159 } << 160 164 >> 165 #include "G4SystemOfUnits.hh" 161 void G4EnergyRangeManager::Dump( G4int verbose 166 void G4EnergyRangeManager::Dump( G4int verbose ) 162 { 167 { 163 G4cout << "G4EnergyRangeManager " << this << 168 G4cout << "G4EnergyRangeManager " << this << G4endl; 164 for (G4int i = 0 ; i < theHadronicInteractio 169 for (G4int i = 0 ; i < theHadronicInteractionCounter; i++) { 165 G4cout << " HadronicModel " << i <<":" 170 G4cout << " HadronicModel " << i <<":" 166 << theHadronicInteraction[i]->GetMo 171 << theHadronicInteraction[i]->GetModelName() << G4endl; 167 if (verbose > 0) { 172 if (verbose > 0) { 168 G4cout << " Minimum Energy " << 173 G4cout << " Minimum Energy " << theHadronicInteraction[i]->GetMinEnergy()/GeV << " [GeV], " 169 << theHadronicInteraction[i]->GetMinEne << 174 << "Maximum Energy " << theHadronicInteraction[i]->GetMaxEnergy()/GeV << " [GeV]" 170 << "Maximum Energy " << 171 << theHadronicInteraction[i]->GetMaxEne << 172 << G4endl; 175 << G4endl; 173 } 176 } 174 } 177 } 175 } 178 } 176 << 179 /* end of file */ 177 void << 178 G4EnergyRangeManager::BuildPhysicsTable(const << 179 { << 180 for (auto & hadi : theHadronicInteraction) { << 181 hadi->BuildPhysicsTable( aParticleType ); << 182 } << 183 } << 184 << 185 180 186 181