1 #include "Randomize.hh"
2 #include "G4ParticleTable.hh"
14 using namespace CLHEP;
17 m_particleTable = G4ParticleTable::GetParticleTable();
18 m_proton = m_particleTable->FindParticle(
"proton");
19 m_neutron = m_particleTable->FindParticle(
"neutron");
23 std::ifstream processListStream(
fileName.c_str());
25 while (getline(processListStream,
line)) {
26 std::vector<G4String> tokens;
29 m_readAndParse(
line, tokens,
"#");
32 G4String incident = tokens[0];
33 G4ParticleDefinition* incidentDef = m_particleTable->FindParticle(incident);
34 G4int incidentPDG = incidentDef->GetPDGEncoding();
35 m_knownParticles[incidentDef] =
true;
37 G4String
target = tokens[1];
42 for (
size_t i = 2;
i != tokens.size();
i++) {
43 G4String
part = tokens[
i];
44 if (m_particleTable->contains(
part)) {
45 prod.push_back(m_particleTable->FindParticle(
part)->GetPDGEncoding());
47 G4Exception(
"HadronicProcessHelper",
50 "Initialization: The reaction product list contained an unknown particle");
54 m_protonReactionMap[incidentPDG].push_back(
prod);
55 }
else if (
target ==
"neutron") {
56 m_neutronReactionMap[incidentPDG].push_back(
prod);
58 G4Exception(
"HadronicProcessHelper",
61 "Initialization: The reaction product list contained an illegal target particle");
65 processListStream.close();
73 const G4ParticleDefinition* aP = &aPart;
74 if (m_knownParticles[aP])
82 G4int pdgCode = particle->GetDefinition()->GetPDGEncoding();
86 return 24 * millibarn * element->GetN();
91 G4double totalNucleonCrossSection = 0;
93 for (std::vector<G4int>::iterator it = quarks.begin(); it != quarks.end(); it++) {
95 if (*it == 1 || *it == 2)
96 totalNucleonCrossSection += 12 * millibarn;
99 totalNucleonCrossSection += 6 * millibarn;
104 return totalNucleonCrossSection *
pow(element->GetN(), 0.7) * 1.25;
108 const G4DynamicParticle* incidentDynamicParticle,
const G4Material* material, G4ParticleDefinition*&
target) {
117 const G4ElementVector* elementVector = material->GetElementVector();
118 const G4double* numberOfAtomsPerVolume = material->GetVecNbOfAtomsPerVolume();
120 G4double numberOfProtons = 0;
121 G4double numberOfNucleons = 0;
124 for (
size_t elm = 0; elm < material->GetNumberOfElements(); elm++) {
126 numberOfProtons += numberOfAtomsPerVolume[elm] * (*elementVector)[elm]->GetZ();
128 numberOfNucleons += numberOfAtomsPerVolume[elm] * (*elementVector)[elm]->GetN();
132 if (G4UniformRand() < numberOfProtons / numberOfNucleons) {
133 m_reactionMap = &m_protonReactionMap;
136 m_reactionMap = &m_neutronReactionMap;
140 const G4int incidentPDG = incidentDynamicParticle->GetDefinition()->GetPDGEncoding();
157 for (ReactionProductList::iterator prod_it = reactionProductList->begin(); prod_it != reactionProductList->end();
159 G4int secondaries = prod_it->size();
161 if (m_reactionIsPossible(*prod_it, incidentDynamicParticle,
target)) {
163 goodReactionProductList.push_back(*prod_it);
164 if (secondaries == 2) {
166 }
else if (secondaries == 3) {
169 G4cerr <<
"ReactionProduct has unsupported number of secondaries: " << secondaries << G4endl;
177 if (goodReactionProductList.empty())
178 G4Exception(
"HadronicProcessHelper",
181 "GetFinalState: No process could be selected from the given list.");
184 G4double prob22 = 0.15;
185 G4double prob23 = 1 - prob22;
187 std::vector<G4double> probabilities;
188 std::vector<G4bool> twoToThreeFlag;
190 G4double cumulatedProbability = 0;
194 size_t numberOfReactions = goodReactionProductList.size();
195 for (
size_t i = 0;
i != numberOfReactions;
i++) {
196 if (goodReactionProductList[
i].
size() == 2) {
197 cumulatedProbability += prob22 / good22;
198 twoToThreeFlag.push_back(
false);
200 cumulatedProbability += prob23 / good23;
201 twoToThreeFlag.push_back(
true);
203 probabilities.push_back(cumulatedProbability);
207 for (std::vector<G4double>::iterator it = probabilities.begin(); it != probabilities.end(); it++) {
208 *it /= cumulatedProbability;
212 G4bool selected =
false;
218 while (!selected && tries < 100) {
220 G4double dice = G4UniformRand();
222 while (dice > probabilities[
i] &&
i < numberOfReactions)
225 if (twoToThreeFlag[
i]) {
227 if (m_phaseSpace(goodReactionProductList[
i], incidentDynamicParticle,
target) > G4UniformRand())
236 G4cerr <<
"Could not select process!!!!" << G4endl;
240 if (goodReactionProductList[
i].
size() == 2) {
245 m_checkFraction = (1.0 * m_n22) / (m_n22 + m_n23);
248 return goodReactionProductList[
i];
252 const G4DynamicParticle* incidentDynamicParticle,
253 G4ParticleDefinition*
target) {
255 G4double incidentEnergy = incidentDynamicParticle->GetTotalEnergy();
256 G4double m_1 = incidentDynamicParticle->GetDefinition()->GetPDGMass();
257 G4double m_2 =
target->GetPDGMass();
259 G4double sqrtS =
sqrt(m_1 * m_1 + m_2 * (m_2 + 2 * incidentEnergy));
261 G4double productsMass = 0;
263 for (ReactionProduct::const_iterator r_it = reactionProd.begin(); r_it != reactionProd.end(); r_it++) {
265 productsMass += m_particleTable->FindParticle(*r_it)->GetPDGMass();
268 return sqrtS - productsMass;
272 const G4DynamicParticle* aDynamicParticle,
273 G4ParticleDefinition*
target) {
274 if (m_reactionProductMass(aReaction, aDynamicParticle,
target) > 0)
280 const G4DynamicParticle* aDynamicParticle,
281 G4ParticleDefinition*
target) {
282 G4double qValue = m_reactionProductMass(aReaction, aDynamicParticle,
target);
283 G4double phi =
sqrt(1 + qValue / (2 * 0.139 *
GeV)) *
pow(qValue / (1.1 *
GeV), 3. / 2.);
284 return (phi / (1 + phi));
288 std::vector<G4String>& tokens,
289 const G4String& delimiters) {
295 while (G4String::npos !=
pos || G4String::npos != lastPos) {
297 G4String
temp =
str.substr(lastPos,
pos - lastPos);
298 while (
temp.c_str()[0] ==
' ')
300 while (
temp[
temp.size() - 1] ==
' ')
303 tokens.push_back(
temp);
305 lastPos =
str.find_first_not_of(delimiters,
pos);
307 pos =
str.find_first_of(delimiters, lastPos);