alcap-org / g4sim

Simulation toolkit based on Geant4 and ROOT
http://wuchen1106.github.io/g4sim/
2 stars 2 forks source link

Histo EnergyMode assumes momentum amplitude spectrum in MeV #53

Open AndrewEdmonds11 opened 9 years ago

AndrewEdmonds11 commented 9 years ago

Hi Everyone.

I just want to highlight an important fact and a workaround I've done in case others need it.

The "histo" EnergyMode in g4sim assumes that you are passing a momentum amplitude spectrum in MeV. I was trying to use this to read in Nam's kinetic energy spectrum for protons but they obviously aren't compatible.

So I've written a script in commit 0be6cd4c4c6f301cdcf3d06409f87463e3ac8555 that converts the histograms and saves the compatible one in the same ROOT file.

There is also a script in commit 919a313ab676cc20a9a58afc39df48559de79650 that plots the initial kinetic energy spectrum from a MC run if you ever want to check that what you're putting in is what you're using.

AndrewEdmonds11 commented 9 years ago

After working with this a bit more - I'm not sure if this is good enough. I feel the bins may be a bit wide so I changed the code (not committed) to use Nam's histogram directly. Here's the diff:

--- a/src/PrimaryGeneratorAction.cc
+++ b/src/PrimaryGeneratorAction.cc
@@ -188,8 +188,8 @@ void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
        }

        if ( EnergyMode == "histo"){
-               G4double mom = EM_hist->GetRandom() * MeV;
-               G4double ekin = sqrt(mom*mom+mass*mass)-mass;
+               G4double ekin = EM_hist->GetRandom() * 1e3 * MeV;
+               //              G4double mom = sqrt(ekin*ekin + 2*ekin*mass);
                particleGun->SetParticleEnergy(ekin);
        }
        else if ( EnergyMode == "root" ){