271{
272
274 G4double t0 = std::max(tMin, lowestE);
276 if(t0 > tm) return tDelta;
277
279 Shell(Z, shell)->BindingEnergy();
280
281 if(e <= bindingEnergy) return 0.0;
282
284
285 G4double x1 = std::min(0.5,(t0 + bindingEnergy)/energy);
286 G4double x2 = std::min(0.5,(tm + bindingEnergy)/energy);
287 if(x1 >= x2) return tDelta;
288
289 if(verbose > 1) {
290 G4cout <<
"G4eIonisationSpectrum::SampleEnergy: Z= " << Z
291 << "; shell= " << shell
292 << "; E(keV)= " << e/keV
294 }
295
296
298
299
300 for (
G4int i=0; i<iMax; i++)
301 {
303 if(i<4) x /= energy;
304 p.push_back(x);
305 }
306
307 if(p[3] > 0.5) p[3] = 0.5;
308
309 G4double gLocal3 = energy/electron_mass_c2 + 1.;
310 p.push_back((2.0*gLocal3 - 1.0)/(gLocal3*gLocal3));
311
312
313
314
315 if (p[3] > 0)
316 p[iMax-1] = Function(p[3], p);
317 else
318 {
319 G4cout <<
"WARNING: G4eIonisationSpectrum::SampleSpectrum "
320 << "parameter p[3] <= 0. G4LEDATA dabatase might be corrupted for Z = "
321 << Z <<
". Please check and/or update it " <<
G4endl;
322 }
323
327 if(a1 < a2) aria1 = IntSpectrum(a1, a2, p);
331 if(a3 < a4) aria2 = IntSpectrum(a3, a4, p);
332
334 G4double amaj, fun, q, x, z1, z2, dx, dx1;
335
336
337
338 if(aria <= aria1) {
339
340 amaj = p[4];
341 for (
G4int j=5; j<iMax; j++) {
342 if(p[j] > amaj) amaj = p[j];
343 }
344
345 a1 = 1./a1;
346 a2 = 1./a2;
347
349 do {
350
352 z1 = p[1];
353 z2 = p[3];
354 dx = (p[2] - p[1]) / 3.0;
355 dx1= std::exp(std::log(p[3]/p[2]) / 16.0);
356 for (i=4; i<iMax-1; i++) {
357
358 if (i < 7) {
359 z2 = z1 + dx;
360 } else if(iMax-2 == i) {
361 z2 = p[3];
362 break;
363 } else {
364 z2 = z1*dx1;
365 }
366 if(x >= z1 && x <= z2) break;
367 z1 = z2;
368 }
369 fun = p[i] + (x - z1) * (p[i+1] - p[i])/(z2 - z1);
370
371 if(fun > amaj) {
372 G4cout <<
"WARNING in G4eIonisationSpectrum::SampleEnergy:"
373 << " Majoranta " << amaj
374 << " < " << fun
375 << " in the first aria at x= " << x
377 }
378
380
381 } while (q >= fun);
382
383
384
385 } else {
386
387 amaj = std::max(p[iMax-1], Function(0.5, p)) * factor;
388 a1 = 1./a3;
389 a2 = 1./a4;
390
391 do {
392
394 fun = Function(x, p);
395
396 if(fun > amaj) {
397 G4cout <<
"WARNING in G4eIonisationSpectrum::SampleEnergy:"
398 << " Majoranta " << amaj
399 << " < " << fun
400 << " in the second aria at x= " << x
402 }
403
405
406 } while (q >= fun);
407
408 }
409
410 p.clear();
411
413
414 if(verbose > 1) {
415 G4cout <<
"tcut(MeV)= " << tMin/MeV
416 << "; tMax(MeV)= " << tMax/MeV
417 << "; x1= " << x1
418 << "; x2= " << x2
419 << "; a1= " << a1
420 << "; a2= " << a2
421 << "; x= " << x
423 << "; e= " << e
424 << "; tDelta= " << tDelta
426 }
427
428
429 return tDelta;
430}