Hi,
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?
Hi,
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?
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 PrimaryGeneratorAction2.cc
2- GeneralParticleSource ( I am not familiar with it ) : see exemple exgps/macros/README
Hi Marie, thanks a lot. Just to ensure, you mean the file PrimaryGeneratorAction2.cc, 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.
Alright, again, thank you very much!
Hi @BenjaminW ,
you can use GPS and user defined energy histogram
like these GPS examples https://hurel.hanyang.ac.kr/Geant4/Geant4_GPS/reat.space.qinetiq.com/gps/examples/examples.html.
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.