Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // 23 // >> 24 // $Id: G4EnergyRangeManager.cc,v 1.8 2003/01/27 09:57:13 jwellisc Exp $ >> 25 // GEANT4 tag $Name: geant4-05-02-patch-01 $ >> 26 // 27 // Hadronic Process: Energy Range Manager 27 // Hadronic Process: Energy Range Manager 28 // original by H.P. Wellisch 28 // original by H.P. Wellisch 29 // modified by J.L. Chuma, TRIUMF, 22-Nov-199 29 // modified by J.L. Chuma, TRIUMF, 22-Nov-1996 30 // Last modified: 24-Mar-1997 30 // Last modified: 24-Mar-1997 31 // fix in the counter-hndling: H.P. Wellisch 31 // fix in the counter-hndling: H.P. Wellisch 04-Apr-97 32 // throw an exception if no model found: J.L 32 // throw an exception if no model found: J.L. Chuma 04-Apr-97 33 33 34 #include "G4EnergyRangeManager.hh" 34 #include "G4EnergyRangeManager.hh" 35 #include "Randomize.hh" 35 #include "Randomize.hh" 36 #include "G4HadronicException.hh" << 36 #include "G4NoModelFound.hh" 37 #include "G4SystemOfUnits.hh" << 37 38 << 38 G4EnergyRangeManager::G4EnergyRangeManager( 39 G4EnergyRangeManager::G4EnergyRangeManager() << 39 const G4EnergyRangeManager &right ) 40 : theHadronicInteractionCounter(0) << 40 { 41 {} << 41 if( this != &right ) 42 << 42 { 43 G4EnergyRangeManager::~G4EnergyRangeManager() << 43 for( G4int i=0; i<theHadronicInteractionCounter; ++i ) 44 {} << 44 theHadronicInteraction[i] = right.theHadronicInteraction[i]; 45 << 45 theHadronicInteractionCounter = right.theHadronicInteractionCounter; 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 } 46 } 53 } 47 } 54 theHadronicInteraction.push_back(a); << 48 55 ++theHadronicInteractionCounter; << 49 G4EnergyRangeManager & 56 } << 50 G4EnergyRangeManager::operator=( 57 << 51 const G4EnergyRangeManager &right ) 58 G4HadronicInteraction* << 52 { 59 G4EnergyRangeManager::GetHadronicInteraction(c << 53 if( this != &right ) 60 G << 54 { 61 c << 55 for( G4int i=0; i<theHadronicInteractionCounter; ++i ) 62 c << 56 theHadronicInteraction[i] = 63 { << 57 right.theHadronicInteraction[i]; 64 // VI shortcut: if only one interaction is r << 58 theHadronicInteractionCounter = 65 if(1 == theHadronicInteractionCounter) { ret << 59 right.theHadronicInteractionCounter; 66 else if(0 == theHadronicInteractionCounter) << 60 } 67 G4cout << "G4EnergyRangeManager::GetHadron << 61 return *this; 68 << "no models defined for a process" << G << 69 return nullptr; << 70 } 62 } 71 << 63 72 G4double kineticEnergy = aHadProjectile.GetK << 64 void 73 // For ions, get kinetic energy per nucleon << 65 G4EnergyRangeManager::RegisterMe( 74 if ( std::abs( aHadProjectile.GetDefinition( << 66 G4HadronicInteraction *a ) 75 kineticEnergy /= static_cast< G4double >( << 67 { >> 68 if( theHadronicInteractionCounter+1 > MAX_NUMBER_OF_MODELS ) >> 69 G4Exception( >> 70 "EnergyRangeManager::RegisterMe: TOO MANY MODELS"); >> 71 theHadronicInteraction[ theHadronicInteractionCounter++ ] = a; 76 } 72 } 77 << 73 78 G4int cou = 0, memory = 0, memor2 = 0; << 74 G4HadronicInteraction * 79 G4double emi1 = 0.0, ema1 = 0.0, emi2 = 0.0, << 75 G4EnergyRangeManager::GetHadronicInteraction( 80 << 76 const G4double kineticEnergy, 81 for (G4int i = 0; i<theHadronicInteractionCo << 77 const G4Material *aMaterial, 82 if ( theHadronicInteraction[i]->IsApplicab << 78 const G4Element *anElement ) const >> 79 { >> 80 G4int counter = GetHadronicInteractionCounter(); >> 81 if( counter == 0 ) >> 82 G4Exception("GetHadronicInteraction: NO MODELS STORED"); >> 83 >> 84 G4int cou = 0, memory = 0, memor2 = 0; >> 85 G4double emi1 = 0.0, ema1 = 0.0, emi2 = 0.0, ema2 = 0.0; >> 86 for( G4int i=0; i<counter; i++ ) { 83 G4double low = theHadronicInteraction[i 87 G4double low = theHadronicInteraction[i]->GetMinEnergy( aMaterial, anElement ); >> 88 // Work-around for particles with 0 kinetic energy, which still >> 89 // require a model to return a ParticleChange >> 90 if (low == 0.) low = -DBL_MIN; 84 G4double high = theHadronicInteraction[i 91 G4double high = theHadronicInteraction[i]->GetMaxEnergy( aMaterial, anElement ); 85 if (low <= kineticEnergy && high >= kine << 92 if( low < kineticEnergy && high >= kineticEnergy ) >> 93 { 86 ++cou; 94 ++cou; 87 emi2 = emi1; 95 emi2 = emi1; 88 ema2 = ema1; 96 ema2 = ema1; 89 emi1 = low; 97 emi1 = low; 90 ema1 = high; 98 ema1 = high; 91 memor2 = memory; 99 memor2 = memory; 92 memory = i; 100 memory = i; 93 } 101 } 94 } 102 } 95 } << 103 G4int m=-1; 96 << 104 G4double rand; 97 G4HadronicInteraction* hi = nullptr; << 105 switch ( cou ) 98 switch (cou) { << 106 { 99 case 0: << 107 case 0: 100 G4cout << "No model found out of " << th << 108 throw(new G4NoModelFound); 101 for( G4int j=0; j<theHadronicInteraction << 109 return 0; 102 G4HadronicInteraction* hint=theHadronicInter << 110 case 1: 103 G4cout << " "<< j << ". Elow= " << hint-> << 111 m = memory; 104 <<", Ehigh= " << hint->GetMaxEnergy(a << 112 break; 105 <<" " << hint->GetModelName() << G4 << 113 case 2: 106 } << 114 if( (emi2<=emi1 && ema2>=ema1) || (emi2>=emi1 && ema2<=ema1) ) 107 break; << 115 G4Exception( 108 << 116 "GetHadronicInteraction: Energy ranges of two models fully overlapping"); 109 case 1: << 117 rand = G4UniformRand(); 110 hi = theHadronicInteraction[memory]; << 118 if( emi1 < emi2 ) 111 break; << 119 { 112 << 120 if( (ema1-kineticEnergy)/(ema1-emi2)<rand ) 113 case 2: << 121 m = memor2; 114 if( (emi2<=emi1 && ema2>=ema1) || (emi2> << 122 else 115 G4cout << "Energy ranges of two models fully << 123 m = memory; 116 for( G4int j=0; j<theHadronicInteractionCoun << 124 } else { 117 G4HadronicInteraction* hint=theHadronicInt << 125 if( (ema2-kineticEnergy)/(ema2-emi1)<rand ) 118 G4cout << " "<< j << ". Elow= " << hint << 126 m = memory; 119 <<", Ehigh= " << hint->GetMaxEnergy(aMate << 127 else 120 <<" " << hint->GetModelName() << G4endl << 128 m = memor2; 121 } << 129 } 122 } else { << 130 break; 123 G4double rand = G4UniformRand(); << 131 default: 124 G4int mem; << 132 G4Exception( 125 if( emi1 < emi2 ) { << 133 "GetHadronicInteraction: More than two competing models in this energy range"); 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 } 134 } 174 } << 135 return theHadronicInteraction[m]; 175 } << 136 } 176 << 137 177 void << 138 /* end of file */ 178 G4EnergyRangeManager::BuildPhysicsTable(const << 179 { << 180 for (auto & hadi : theHadronicInteraction) { << 181 hadi->BuildPhysicsTable( aParticleType ); << 182 } << 183 } << 184 << 185 139 186 140