108 {
109 if( std::getenv(
"G4PHPTEST") )
G4cout <<
" G4ParticleHPContAngularPar::Sample " << anEnergy <<
" " << massCode <<
" " << angularRep <<
G4endl;
110 if ( fCache.
Get() == 0 ) cacheInit();
114 if(massCode==0)
115 {
117 }
118 else if(A==0)
119 {
122 }
123 else if(A==1)
124 {
127 }
128 else if(A==2)
129 {
131 }
132 else if(A==3)
133 {
136 }
137 else if(A==4)
138 {
140 if(Z!=2)
throw G4HadronicException(__FILE__, __LINE__,
"G4ParticleHPContAngularPar: Unknown ion case 1");
141 }
142 else
143 {
145 }
150
151 if( angularRep == 1 )
152 {
153
154
155
156
157 if ( nDiscreteEnergies != 0 )
158 {
159
160
161
162 if ( fCache.
Get()->fresh ==
true )
163 {
164
165
166 fCache.
Get()->remaining_energy = std::max ( theAngular[0].GetLabel() , theAngular[nEnergies-1].GetLabel() );
167 fCache.
Get()->fresh =
false;
168 }
169
170
171
172 if ( nDiscreteEnergies == nEnergies )
173 {
174 fCache.
Get()->remaining_energy = std::max ( fCache.
Get()->remaining_energy , theAngular[nDiscreteEnergies-1].GetLabel() );
175 }
176 else
177 {
178
179
181 for (
G4int j = nDiscreteEnergies ; j < nEnergies ; j++ )
182 {
183 cont_min = theAngular[j].
GetLabel();
184 if ( theAngular[j].GetValue(0) != 0.0 ) break;
185 }
186 fCache.
Get()->remaining_energy = std::max ( fCache.
Get()->remaining_energy , std::min ( theAngular[nDiscreteEnergies-1].GetLabel() , cont_min ) );
187 }
188
190
192 running[0] = 0.0;
193
194 for (
G4int j = 0 ; j < nDiscreteEnergies ; j++ )
195 {
197 if ( theAngular[j].GetLabel() <= fCache.
Get()->remaining_energy ) delta = theAngular[i].
GetValue(0);
198 running[j+1] = running[j] + delta;
199 }
200 G4double tot_prob_DIS = running[ nDiscreteEnergies ];
201
202 for (
G4int j = nDiscreteEnergies ; j < nEnergies ; j++ )
203 {
207 if ( theAngular[j].GetLabel() <= fCache.
Get()->remaining_energy ) delta = theAngular[j].
GetValue(0);
208
209
210
211
212
213
214 if ( theAngular[j].GetLabel() != 0 )
215 {
216 if ( j == nDiscreteEnergies ) {
217 e_low = 0.0/eV;
218 } else {
219 e_low = theAngular[j-1].
GetLabel()/eV;
220 }
221 e_high = theAngular[j].
GetLabel()/eV;
222 }
223
224
225 if ( theAngular[j].GetLabel() == 0.0 ) {
226 e_low = theAngular[j].
GetLabel()/eV;
227 if ( j != nEnergies-1 ) {
228 e_high = theAngular[j+1].
GetLabel()/eV;
229 } else {
230 e_high = theAngular[j].
GetLabel()/eV;
231 if ( theAngular[j].GetValue(0) != 0.0 ) {
232 throw G4HadronicException(__FILE__, __LINE__,
"G4ParticleHPContAngularPar: Unexpected non zero value of theAngular[nEnergies-1].GetValue(0)");
233 }
234 }
235 }
236
237 running[j+1] = running[j] + ( ( e_high - e_low ) * delta );
238 }
239 G4double tot_prob_CON = running[ nEnergies ] - running[ nDiscreteEnergies ];
240
241
242
243
244
245
246
247
248
249
250
251
252
253 random *= (tot_prob_DIS + tot_prob_CON);
254
255 if ( random <= ( tot_prob_DIS / ( tot_prob_DIS + tot_prob_CON ) ) || nDiscreteEnergies == nEnergies )
256 {
257
258 for (
G4int j = 0 ; j < nDiscreteEnergies ; j++ )
259 {
260
261 if ( random < running[ j+1 ] )
262 {
263 it = j;
264 break;
265 }
266 }
267 fsEnergy = theAngular[ it ].
GetLabel();
268
270 theStore.Init(0,fsEnergy,nAngularParameters);
271 for (
G4int j=0;j<nAngularParameters;j++)
272 {
273 theStore.SetCoeff(0,j,theAngular[it].GetValue(j));
274 }
275
276 cosTh = theStore.SampleMax(fsEnergy);
277
278 }
279 else
280 {
281
282 for (
G4int j = nDiscreteEnergies ; j < nEnergies ; j++ )
283 {
284
285 if ( random < running[ j ] )
286 {
287 it = j;
288 break;
289 }
290 }
291
294
296 if ( it != nDiscreteEnergies )
299
301 random,x1,x2,y1,y2);
302
304 theStore.Init(0,y1,nAngularParameters);
305 theStore.Init(1,y2,nAngularParameters);
306 theStore.SetManager(theManager);
307 for (
G4int j=0;j<nAngularParameters;j++)
308 {
310 if ( it == nDiscreteEnergies ) itt = it+1;
311 if ( it == 0 )
312 {
313
314
315 itt = it+1;
316 }
317 theStore.SetCoeff(0,j,theAngular[itt-1].GetValue(j));
318 theStore.SetCoeff(1,j,theAngular[itt].GetValue(j));
319 }
320
321 cosTh = theStore.SampleMax(fsEnergy);
322
323
324 }
325
326
327 if( adjustResult ) fCache.
Get()->remaining_energy -= fsEnergy;
328
329
330
331 delete[] running;
332
333 }
334 else
335 {
336
337
338
339 if ( fCache.
Get()->fresh ==
true )
340 {
341 fCache.
Get()->remaining_energy = theAngular[ nEnergies-1 ].
GetLabel();
342 fCache.
Get()->fresh =
false;
343 }
344
347 running[0]=0;
349 for(i=1; i<nEnergies; i++)
350 {
351
352
353
354
355
356
357
358
359
360
361
362
363
364 running[i]=running[i-1];
365 if ( fCache.
Get()->remaining_energy >= theAngular[i].GetLabel() )
366 {
368 theAngular[i-1].GetLabel(), theAngular[i].GetLabel(),
369 theAngular[i-1].GetValue(0), theAngular[i].GetValue(0));
371 theAngular[i-1].GetLabel(), theAngular[i].GetLabel(),
372 theAngular[i-1].GetValue(0), theAngular[i].GetValue(0));
373 }
374 }
375
376
377 if ( nEnergies == 1 || running[nEnergies-1] == 0 )
378 fCache.
Get()->currentMeanEnergy = 0.0;
379 else
380 {
381 fCache.
Get()->currentMeanEnergy = weighted/running[nEnergies-1];
382 }
383
384
385 if ( nEnergies == 1 ) it = 0;
386
387
388 if ( running[nEnergies-1] != 0 )
389 {
390 for ( i = 1 ; i < nEnergies ; i++ )
391 {
392 it = i;
393 if ( random < running [ i ] / running [ nEnergies-1 ] ) break;
394 }
395 }
396
397
398 if ( running [ nEnergies-1 ] == 0 ) it = 0;
399
400
401 if (it<nDiscreteEnergies||it==0)
402 {
403 if(it == 0)
404 {
405 fsEnergy = theAngular[it].
GetLabel();
407 theStore.Init(0,fsEnergy,nAngularParameters);
408 for(i=0;i<nAngularParameters;i++)
409 {
410 theStore.SetCoeff(0,i,theAngular[it].GetValue(i));
411 }
412
413 cosTh = theStore.SampleMax(fsEnergy);
414 }
415 else
416 {
421 random,
422 running[it-1]/running[nEnergies-1],
423 running[it]/running[nEnergies-1],
424 e1, e2);
425
427 theStore.Init(0,e1,nAngularParameters);
428 theStore.Init(1,e2,nAngularParameters);
429 for(i=0;i<nAngularParameters;i++)
430 {
431 theStore.SetCoeff(0,i,theAngular[it-1].GetValue(i));
432 theStore.SetCoeff(1,i,theAngular[it].GetValue(i));
433 }
434
435 theStore.SetManager(theManager);
436 cosTh = theStore.SampleMax(fsEnergy);
437 }
438 }
439 else
440 {
441 G4double x1 = running[it-1]/running[nEnergies-1];
442 G4double x2 = running[it]/running[nEnergies-1];
446 random,x1,x2,y1,y2);
448 theStore.Init(0,y1,nAngularParameters);
449 theStore.Init(1,y2,nAngularParameters);
450 theStore.SetManager(theManager);
451 for(i=0;i<nAngularParameters;i++)
452 {
453 theStore.SetCoeff(0,i,theAngular[it-1].GetValue(i));
454 theStore.SetCoeff(1,i,theAngular[it].GetValue(i));
455 }
456
457 cosTh = theStore.SampleMax(fsEnergy);
458 }
459 delete [] running;
460
461
462 if( adjustResult ) fCache.
Get()->remaining_energy -= fsEnergy;
463
464 }
465 }
466 else if(angularRep==2)
467 {
468
471 running[0]=0;
473 if( std::getenv(
"G4PHPTEST") )
G4cout <<
" G4ParticleHPContAngularPar::Sample nEnergies " << nEnergies <<
G4endl;
474 for(j=1; j<nEnergies; j++)
475 {
476 if(j!=0) running[j]=running[j-1];
478 theAngular[j-1].GetLabel(), theAngular[j].GetLabel(),
479 theAngular[j-1].GetValue(0), theAngular[j].GetValue(0));
481 theAngular[j-1].GetLabel(), theAngular[j].GetLabel(),
482 theAngular[j-1].GetValue(0), theAngular[j].GetValue(0));
483 if( std::getenv(
"G4PHPTEST") )
G4cout <<
" G4ParticleHPContAngularPar::Sample " << j <<
" running " << running[j]
485 }
486
487
488
489 if ( nEnergies == 1 )
490 fCache.
Get()->currentMeanEnergy = 0.0;
491 else
492 fCache.
Get()->currentMeanEnergy = weighted/running[nEnergies-1];
493
496
497
498 for(j=1; j<nEnergies; j++)
499 {
500 itt = j;
501 if(randkal<running[j]/running[nEnergies-1]) break;
502 }
503
504
506 if(itt==0) itt=1;
507 x = randkal*running[nEnergies-1];
508 x1 = running[itt-1];
509 x2 = running[itt];
511
515 x, x1,x2,y1,y2);
516 if( std::getenv(
"G4PHPTEST") )
G4cout << itt <<
" G4particleHPContAngularPar fsEnergy " << fsEnergy <<
" " << theManager.
GetInverseScheme(itt-1) <<
" x " << x <<
" " << x1 <<
" " << x2 <<
" y " << y1 <<
" " << y2 <<
G4endl;
517
521 fsEnergy, y1, y2, cLow,cHigh);
522
523 if ( compoundFraction > 1.0 ) compoundFraction = 1.0;
524
525 if( std::getenv(
"G4PHPTEST") )
G4cout << itt <<
" G4particleHPContAngularPar compoundFraction " << compoundFraction <<
" E " << fsEnergy <<
" " << theManager.
GetScheme(itt) <<
" ener " << fsEnergy <<
" y " << y1 <<
" " << y2 <<
" cLH " << cLow <<
" " << cHigh <<
G4endl;
526 delete [] running;
527
528
534 G4int targetA =
G4int(fCache.
Get()->theTargetCode-1000*targetZ);
535
536 if ( targetA == 0 )
537 targetA =
G4int ( fCache.
Get()->theTarget->GetMass()/amu_c2 + 0.5 );
538 G4double targetMass = fCache.
Get()->theTarget->GetMass();
539 G4int incidentA=
G4int(incidentMass/amu_c2 + 0.5 );
541 G4int residualA = targetA+incidentA-
A;
542 G4int residualZ = targetZ+incidentZ-Z;
545 incidentEnergy, incidentMass,
546 productEnergy, productMass,
547 residualMass, residualA, residualZ,
548 targetMass, targetA, targetZ,
549 incidentA,incidentZ,A,Z);
550 cosTh = theKallbach.Sample(anEnergy);
551 if( std::getenv(
"G4PHPTEST") )
G4cout <<
" G4ParticleHPKallbachMannSyst::Sample resulttest " << cosTh <<
G4endl;
552 }
553 else if(angularRep>10&&angularRep<16)
554 {
557 running[0]=0;
559 for(i=1; i<nEnergies; i++)
560 {
561 if(i!=0) running[i]=running[i-1];
563 theAngular[i-1].GetLabel(), theAngular[i].GetLabel(),
564 theAngular[i-1].GetValue(0), theAngular[i].GetValue(0));
566 theAngular[i-1].GetLabel(), theAngular[i].GetLabel(),
567 theAngular[i-1].GetValue(0), theAngular[i].GetValue(0));
568 }
569
570
571 if ( nEnergies == 1 )
572 fCache.
Get()->currentMeanEnergy = 0.0;
573 else
574 fCache.
Get()->currentMeanEnergy = weighted/running[nEnergies-1];
575
576
577 if ( nEnergies == 1 ) it = 0;
578
579 for(i=1; i<nEnergies; i++)
580 {
581 it = i;
582 if(random<running[i]/running[nEnergies-1]) break;
583 }
584 if(it<nDiscreteEnergies||it==0)
585 {
586 if(it==0)
587 {
588 fsEnergy = theAngular[0].
GetLabel();
591 for(
G4int j=1; j<nAngularParameters; j+=2)
592 {
593 theStore.
SetX(aCounter, theAngular[0].GetValue(j));
594 theStore.
SetY(aCounter, theAngular[0].GetValue(j+1));
595 aCounter++;
596 }
598 aMan.
Init(angularRep-10, nAngularParameters-1);
600 cosTh = theStore.
Sample();
601 }
602 else
603 {
604 fsEnergy = theAngular[it].
GetLabel();
607 aMan.
Init(angularRep-10, nAngularParameters-1);
611 for(
G4int j=1; j<nAngularParameters; j+=2)
612 {
613 theStore.
SetX(aCounter, theAngular[it].GetValue(j));
615 random,
616 running[it-1]/running[nEnergies-1],
617 running[it]/running[nEnergies-1],
618 theAngular[it-1].GetValue(j+1),
619 theAngular[it].GetValue(j+1)));
620 aCounter++;
621 }
622 cosTh = theStore.
Sample();
623 }
624 }
625 else
626 {
627 G4double x1 = running[it-1]/running[nEnergies-1];
628 G4double x2 = running[it]/running[nEnergies-1];
632 random,x1,x2,y1,y2);
636 aMan.
Init(angularRep-10, nAngularParameters-1);
637
638
639
640
641
642
643
644
645
646
647
648 {
650 for(i=0,j=1; i<nAngularParameters; i++,j+=2)
651 {
652 theBuff1.
SetX(i, theAngular[it-1].GetValue(j));
653 theBuff1.
SetY(i, theAngular[it-1].GetValue(j+1));
654 theBuff2.
SetX(i, theAngular[it].GetValue(j));
655 theBuff2.
SetY(i, theAngular[it].GetValue(j+1));
656 }
657 }
660 x1 = y1;
661 x2 = y2;
663
665 {
666 x = theBuff1.
GetX(i);
667 y1 = theBuff1.
GetY(i);
668 y2 = theBuff2.
GetY(i);
670 fsEnergy, theAngular[it-1].GetLabel(),
671 theAngular[it].GetLabel(), y1, y2);
674 }
675 cosTh = theStore.
Sample();
676 }
677 delete [] running;
678 }
679 else
680 {
681 throw G4HadronicException(__FILE__, __LINE__,
"G4ParticleHPContAngularPar::Sample: Unknown angular representation");
682 }
688 G4ThreeVector tempVector(mtot*sinth*std::cos(phi), mtot*sinth*std::sin(phi), mtot*std::cos(theta) );
690
691 return result;
692 }
double A(double temperature)
static G4Deuteron * Deuteron()
static G4Electron * Electron()
void Init(G4int aScheme, G4int aRange)
G4InterpolationScheme GetInverseScheme(G4int index)
static G4IonTable * GetIonTable()
static G4Neutron * Neutron()
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)
G4double GetValue(G4int i)
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()
void SetMomentum(const G4double x, const G4double y, const G4double z)
G4double GetTotalMomentum() const
void SetDefinition(const G4ParticleDefinition *aParticleDefinition)
void SetKineticEnergy(const G4double en)
static G4Triton * Triton()