How to produce a specific x-ray spectrum?


I’m modelling a x-ray tube with a wolfram anode and it has quite a similar spectrum like this here:

I’m generating particles with a particle gun, so I wonder how would I make the particle gun produce this specific spectrum?

1 Like

You can’t, not directly. G4ParticleGun is very, VERY simple: you give it a particle type, an energy (G4double) and a direction (G4ThreeVector). Period.

If you want a spectrum (or in this case two different spectra), use G4GeneralParticleSource, with the associated /gps/... commands. There’s a whole chapter of documentation in the Geant4 Application Developer’s Guide.


1- ParticleGun : see examples/extended/eventgenerator/particleGun, case 2
You have to changes line 89-96 of

2- GeneralParticleSource ( I am not familiar with it ) : see exemple exgps/macros/README

1 Like

Hi Marie, thanks a lot. Just to ensure, you mean the file, right? And in this, the lines

fNPoints = 16;
  const G4double xx[] = 
    { 37*keV, 39*keV, 45*keV,  51*keV,  57*keV,  69*keV,  71*keV,  75*keV, 
      83*keV, 91*keV, 97*keV, 107*keV, 125*keV, 145*keV, 159*keV, 160*keV }; 
  const G4double yy[] =
    { 0.000,  0.077,  0.380,  2.044, 5.535, 15.077, 12.443, 14.766,
     17.644, 18.518, 17.772, 14.776, 8.372,  3.217,  0.194,  0.000 };

? It looks actually quite easy and exactly what I am looking for. Do I need the entire InitFunction(), like also the slope and cumulative function calculation?

To sample y, you can use RejectAccept() or InverseCumul().
The 2 methods should give same results; InverseCumul() must be more efficient.
slope is needed for InverseCumul()

You can try this example with run2.mac. Histo 1 is the result of the sampling.

1 Like

Alright, again, thank you very much!

Hi @BenjaminW ,
you can use GPS and user defined energy histogram
like these GPS examples
Example 18 is useful for you. Or you can write energy histogram related UI cammands into a file named energy_hist.mac, and then

/gps/ene/type User
/gps/hist/type energy
#use hist for energy spectrum
/control/execute energy_hist.mac

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.