136{
137
138 adjustResult = true;
140
142 auto Z =
static_cast<G4int>(massCode / 1000);
143 auto A =
static_cast<G4int>(massCode - 1000 * Z);
144 if (massCode == 0) {
146 }
150 }
154 }
157 }
160 if (Z == 2) result->SetDefinition(
G4He3::He3());
161 }
164 if (Z != 2)
166 "G4ParticleHPContAngularPar: Unknown ion case 1");
167 }
168 else {
170 }
171
176
177
178
179
180
181 if (angularRep == 1) {
182 if (nDiscreteEnergies != 0) {
183
184
185 if (fCache.
Get().fresh) {
186
187
188 fCache.
Get().remaining_energy =
189 std::max(theAngular[0].GetLabel(), theAngular[nEnergies - 1].GetLabel());
190 fCache.
Get().fresh =
false;
191 }
192
193
194
195 if (nDiscreteEnergies == nEnergies) {
196 fCache.
Get().remaining_energy =
197 std::max(fCache.
Get().remaining_energy,
198 theAngular[nDiscreteEnergies - 1].GetLabel());
199 }
200 else {
202 for (
G4int j = nDiscreteEnergies; j < nEnergies; ++j) {
203 cont_min = theAngular[j].
GetLabel();
204 if (theAngular[j].GetValue(0) != 0.0) break;
205 }
206 fCache.
Get().remaining_energy = std::max(
207 fCache.
Get().remaining_energy, std::min(theAngular[nDiscreteEnergies - 1].GetLabel(),
208 cont_min));
209 }
210
212 auto running =
new G4double[nEnergies + 1];
213 running[0] = 0.0;
214
216 for (
G4int j = 0; j < nDiscreteEnergies; ++j) {
217 delta = 0.0;
218 if (theAngular[j].GetLabel() <= fCache.
Get().remaining_energy)
220 running[j + 1] = running[j] + delta;
221 }
222
223 G4double tot_prob_DIS = std::max(running[nDiscreteEnergies], 0.0);
224
226 for (
G4int j = nDiscreteEnergies; j < nEnergies; ++j) {
227 delta1 = 0.0;
230 if (theAngular[j].GetLabel() <= fCache.
Get().remaining_energy)
232
233
234
235
236
237
238 if (theAngular[j].GetLabel() != 0) {
239 if (j == nDiscreteEnergies) {
240 e_low = 0.0 / eV;
241 }
242 else {
243 if (j < 1) j = 1;
244 e_low = theAngular[j - 1].
GetLabel() / eV;
245 }
246 e_high = theAngular[j].
GetLabel() / eV;
247 }
248
249
250
251 if (theAngular[j].GetLabel() == 0.0) {
252 e_low = theAngular[j].
GetLabel() / eV;
253 if (j != nEnergies - 1) {
254 e_high = theAngular[j + 1].
GetLabel() / eV;
255 }
256 else {
257 e_high = theAngular[j].
GetLabel() / eV;
258 }
259 }
260
261 running[j + 1] = running[j] + ((e_high - e_low) * delta1);
262 }
263 G4double tot_prob_CON = std::max(running[nEnergies] - running[nDiscreteEnergies], 0.0);
264
265
266 if (tot_prob_DIS == 0.0 && tot_prob_CON == 0.0) {
267 delete[] running;
268 return result;
269 }
270
271 random *= (tot_prob_DIS + tot_prob_CON);
272
273
274
275 if (random <= (tot_prob_DIS / (tot_prob_DIS + tot_prob_CON))
276 || nDiscreteEnergies == nEnergies)
277 {
278
279 for (
G4int j = 0; j < nDiscreteEnergies; ++j) {
280
281 if (random < running[j + 1]) {
282 it = j;
283 break;
284 }
285 }
286 fsEnergy = theAngular[it].
GetLabel();
287
289 theStore.Init(0, fsEnergy, nAngularParameters);
290 for (
G4int j = 0; j < nAngularParameters; ++j) {
291 theStore.SetCoeff(0, j, theAngular[it].GetValue(j));
292 }
293
294 cosTh = theStore.SampleMax(fsEnergy);
295
296 }
297 else {
298
299 for (
G4int j = nDiscreteEnergies; j < nEnergies; ++j) {
300
301 if (random < running[j]) {
302 it = j;
303 break;
304 }
305 }
306
307 if (it < 1) it = 1;
308
311
313 if (it != nDiscreteEnergies) y1 = theAngular[it - 1].
GetLabel();
315
317
319 theStore.Init(0, y1, nAngularParameters);
320 theStore.Init(1, y2, nAngularParameters);
321 theStore.SetManager(theManager);
323 for (
G4int j = 0; j < nAngularParameters; ++j) {
324 itt = it;
325 if (it == nDiscreteEnergies) itt = it + 1;
326
327
328 theStore.SetCoeff(0, j, theAngular[itt - 1].GetValue(j));
329 theStore.SetCoeff(1, j, theAngular[itt].GetValue(j));
330 }
331
332 cosTh = theStore.SampleMax(fsEnergy);
333
334
335 }
336
337
338
339
340 fCache.
Get().remaining_energy -= fsEnergy;
341 delete[] running;
342
343
344 }
345 else {
346
347 if (fCache.
Get().fresh) {
348 fCache.
Get().remaining_energy = theAngular[nEnergies - 1].
GetLabel();
349 fCache.
Get().fresh =
false;
350 }
351
353 auto running =
new G4double[nEnergies];
354 running[0] = 0;
356 for (i = 1; i < nEnergies; i++) {
357 running[i] = running[i - 1];
358 if (fCache.
Get().remaining_energy >= theAngular[i].GetLabel()) {
360 theManager.
GetScheme(i - 1), theAngular[i - 1].GetLabel(), theAngular[i].GetLabel(),
361 theAngular[i - 1].GetValue(0), theAngular[i].GetValue(0));
363 theManager.
GetScheme(i - 1), theAngular[i - 1].GetLabel(), theAngular[i].GetLabel(),
364 theAngular[i - 1].GetValue(0), theAngular[i].GetValue(0));
365 }
366 }
367
368
369 if (nEnergies == 1 || running[nEnergies - 1] == 0) {
370 fCache.
Get().currentMeanEnergy = 0.0;
371 }
372 else {
373 fCache.
Get().currentMeanEnergy = weighted / running[nEnergies - 1];
374 }
375
376 if (nEnergies == 1) it = 0;
377 if (running[nEnergies - 1] != 0) {
378 for (i = 1; i < nEnergies; i++) {
379 it = i;
380 if (random < running[i] / running[nEnergies - 1]) break;
381 }
382 }
383
384 if (running[nEnergies - 1] == 0) it = 0;
385 if (it < nDiscreteEnergies || it == 0) {
386 if (it == 0) {
387 fsEnergy = theAngular[it].
GetLabel();
389 theStore.Init(0, fsEnergy, nAngularParameters);
390 for (i = 0; i < nAngularParameters; i++) {
391 theStore.SetCoeff(0, i, theAngular[it].GetValue(i));
392 }
393
394 cosTh = theStore.SampleMax(fsEnergy);
395 }
396 else {
401 running[it - 1] / running[nEnergies - 1],
402 running[it] / running[nEnergies - 1], e1, e2);
403
405 theStore.Init(0, e1, nAngularParameters);
406 theStore.Init(1, e2, nAngularParameters);
407 for (i = 0; i < nAngularParameters; i++) {
408 theStore.SetCoeff(0, i, theAngular[it - 1].GetValue(i));
409 theStore.SetCoeff(1, i, theAngular[it].GetValue(i));
410 }
411
412 theStore.SetManager(theManager);
413 cosTh = theStore.SampleMax(fsEnergy);
414 }
415 }
416 else {
417 G4double x1 = running[it - 1] / running[nEnergies - 1];
418 G4double x2 = running[it] / running[nEnergies - 1];
423 theStore.Init(0, y1, nAngularParameters);
424 theStore.Init(1, y2, nAngularParameters);
425 theStore.SetManager(theManager);
426 for (i = 0; i < nAngularParameters; i++) {
427 theStore.SetCoeff(0, i, theAngular[it - 1].GetValue(i));
428 theStore.SetCoeff(1, i, theAngular[it].GetValue(i));
429 }
430
431 cosTh = theStore.SampleMax(fsEnergy);
432 }
433 delete[] running;
434
435
436
437
438
439 fCache.
Get().remaining_energy -= fsEnergy;
440
441 }
442
443 }
444 else if (angularRep == 2) {
445
447 auto running =
new G4double[nEnergies];
448 running[0] = 0;
450 for (j = 1; j < nEnergies; ++j) {
451 if (j != 0) running[j] = running[j - 1];
453 theAngular[j].GetLabel(), theAngular[j - 1].GetValue(0),
454 theAngular[j].GetValue(0));
456 theManager.
GetScheme(j - 1), theAngular[j - 1].GetLabel(), theAngular[j].GetLabel(),
457 theAngular[j - 1].GetValue(0), theAngular[j].GetValue(0));
458 }
459
460
461 if (nEnergies == 1)
462 fCache.
Get().currentMeanEnergy = 0.0;
463 else
464 fCache.
Get().currentMeanEnergy = weighted / running[nEnergies - 1];
465
468 for (j = 1; j < nEnergies; ++j) {
469 itt = j;
470 if (randkal*running[nEnergies - 1] < running[j]) break;
471 }
472
473
475 if (itt == 0) itt = 1;
476 x = randkal * running[nEnergies - 1];
477 x1 = running[itt - 1];
478 x2 = running[itt];
480
481 y1 = theAngular[itt - 1].
GetLabel();
484
485
488 compoundFraction = theInt.
Interpolate(theManager.
GetScheme(itt), fsEnergy, y1, y2, cLow, cHigh);
489
490 if (compoundFraction > 1.0)
491 compoundFraction = 1.0;
492
493 delete[] running;
494
495
499 G4double productMass = result->GetMass();
500 auto targetZ =
G4int(fCache.
Get().theTargetCode / 1000);
501 auto targetA =
G4int(fCache.
Get().theTargetCode - 1000 * targetZ);
502
503
504 if (targetA == 0) targetA =
G4int(fCache.
Get().theTarget->GetMass() / amu_c2 + 0.5);
505 G4double targetMass = fCache.
Get().theTarget->GetMass();
506 auto incidentA =
G4int(incidentMass / amu_c2 + 0.5);
508 G4int residualA = targetA + incidentA -
A;
509 G4int residualZ = targetZ + incidentZ - Z;
511
513 compoundFraction, incidentEnergy, incidentMass, productEnergy, productMass, residualMass,
514 residualA, residualZ, targetMass, targetA, targetZ, incidentA, incidentZ,
A, Z);
515 cosTh = theKallbach.Sample(anEnergy);
516
517 }
518 else if (angularRep > 10 && angularRep < 16) {
520 auto running =
new G4double[nEnergies];
521 running[0] = 0;
523 for (i = 1; i < nEnergies; ++i) {
524 if (i != 0) running[i] = running[i - 1];
526 theAngular[i].GetLabel(), theAngular[i - 1].GetValue(0),
527 theAngular[i].GetValue(0));
529 theManager.
GetScheme(i - 1), theAngular[i - 1].GetLabel(), theAngular[i].GetLabel(),
530 theAngular[i - 1].GetValue(0), theAngular[i].GetValue(0));
531 }
532
533
534 if (nEnergies == 1)
535 fCache.
Get().currentMeanEnergy = 0.0;
536 else
537 fCache.
Get().currentMeanEnergy = weighted / running[nEnergies - 1];
538
539 if (nEnergies == 1) it = 0;
540 for (i = 1; i < nEnergies; i++) {
541 it = i;
542 if (random < running[i] / running[nEnergies - 1]) break;
543 }
544
545 if (it < nDiscreteEnergies || it == 0) {
546 if (it == 0) {
547 fsEnergy = theAngular[0].
GetLabel();
550 for (
G4int j = 1; j < nAngularParameters; j += 2) {
551 theStore.
SetX(aCounter, theAngular[0].GetValue(j));
552 theStore.
SetY(aCounter, theAngular[0].GetValue(j + 1));
553 aCounter++;
554 }
556 aMan.
Init(angularRep - 10, nAngularParameters - 1);
558 cosTh = theStore.
Sample();
559 }
560 else {
561 fsEnergy = theAngular[it].
GetLabel();
564 aMan.
Init(angularRep - 10, nAngularParameters - 1);
568 for (
G4int j = 1; j < nAngularParameters; j += 2) {
569 theStore.
SetX(aCounter, theAngular[it].GetValue(j));
571 running[it - 1] / running[nEnergies - 1],
572 running[it] / running[nEnergies - 1],
573 theAngular[it - 1].GetValue(j + 1),
574 theAngular[it].GetValue(j + 1)));
575 ++aCounter;
576 }
577 cosTh = theStore.
Sample();
578 }
579 }
580 else {
581 G4double x1 = running[it - 1] / running[nEnergies - 1];
582 G4double x2 = running[it] / running[nEnergies - 1];
589 aMan.
Init(angularRep - 10, nAngularParameters - 1);
590
592 for (i = 0, j = 1; i < nAngularParameters; i++, j += 2) {
593 theBuff1.
SetX(i, theAngular[it - 1].GetValue(j));
594 theBuff1.
SetY(i, theAngular[it - 1].GetValue(j + 1));
595 theBuff2.
SetX(i, theAngular[it].GetValue(j));
596 theBuff2.
SetY(i, theAngular[it].GetValue(j + 1));
597 }
598
601 x1 = y1;
602 x2 = y2;
605 x = theBuff1.
GetX(i);
606 y1 = theBuff1.
GetY(i);
607 y2 = theBuff2.
GetY(i);
609 theAngular[it].GetLabel(), y1, y2);
612 }
613 cosTh = theStore.
Sample();
614 }
615 delete[] running;
616 }
617 else {
619 "G4ParticleHPContAngularPar::Sample: Unknown angular representation");
620 }
621
622 result->SetKineticEnergy(fsEnergy);
623
625 if(cosTh > 1.0) { cosTh = 1.0; }
626 else if (cosTh < -1.0) { cosTh = -1.0; }
627 G4double sinth = std::sqrt((1.0 - cosTh)*(1.0 + cosTh));
628 G4double mtot = result->GetTotalMomentum();
629 G4ThreeVector tempVector(mtot * sinth * std::cos(phi), mtot * sinth * std::sin(phi), mtot * cosTh);
630 result->SetMomentum(tempVector);
631 return result;
632}
static G4Deuteron * Deuteron()
static G4Electron * Electron()
void Init(G4int aScheme, G4int aRange)
G4InterpolationScheme GetInverseScheme(G4int index)
static G4IonTable * GetIonTable()
static G4double GetNuclearMass(const G4double A, const G4double Z)
G4double GetPDGMass() const
G4double GetPDGCharge() const
G4double GetWeightedBinIntegral(const G4InterpolationScheme &aScheme, const G4double x1, const G4double x2, const G4double y1, const G4double y2)
G4double GetBinIntegral(const G4InterpolationScheme &aScheme, const G4double x1, const G4double x2, const G4double y1, const G4double y2)
void SetY(G4int i, G4double x)
void SetX(G4int i, G4double e)
void SetInterpolationManager(const G4InterpolationManager &aManager)
G4double GetY(G4double x)
G4double GetX(G4int i) const
G4int GetVectorLength() const
static G4Positron * Positron()
static G4Proton * Proton()
static G4Triton * Triton()