Message: Re: How to assign discrete values of energy to primary particles from a text file? Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Idea Re: How to assign discrete values of energy to primary particles from a text file? 

Forum: Particles
Re: Question How to assign discrete values of energy to primary particles from a text file? (Amit Kumar)
Date: 06 Jan, 2015
From: C Mos <C Mos>

Hi

From what you wrote in your post I believe the error could be in the actual code you wrote. I understood you initialized your array of energies in one function and then you try to access it in another function. If so, that would explain your error, since the accessing the energy array is out of scope. You can make the energy array a member of the PrimaryGeneratorClass and then it will be accessible but _all_ your functions.

Another way to do what you want to do by using macro files is to first defined your PrimaryGenParticle class like this (I only show the constructor):

  PrimaryGeneratorAction::PrimaryGeneratorAction(){
   gpsGun       = new G4GeneralParticleSource();  //gpsGun is defined in your header file
  }

Then you can execute the following macro lines:

  #Defines the type of energy distrobution to use [DEFAULT: User]
  /gps/ene/type User

  #Sets the distrobution for energy instead of momentum [Not Sure; DEFAULT: 0]
  /gps/ene/emspec 0

  #Defines the histogram type [DEFAULT: energy]
  /gps/hist/type energy

  #--Begin Energy Distribution Histogram--#
					#
  /gps/hist/point 0.00  	0.0		#
  /gps/hist/point 1.00  	0.0		#
  /gps/hist/point 2.00  	0.0		#
  /gps/hist/point 3.00  	0.0		#
  /gps/hist/point 4.439  	0.0		#
  /gps/hist/point 5.00  	0.0		#
  #/gps/hist/point 6.00  	0.0		#
  /gps/hist/point 6.128  	0.0		#
  /gps/hist/point 7.00  	0.0		#
  /gps/hist/point 8.00  	0.0		#
  /gps/hist/point 9.00  	0.0		#
  /gps/hist/point 10.00 	0.0		#
  /gps/hist/point 11.69 	0.0		#
  /gps/hist/point 11.70 	97.0		# [DEFAULT: 97.0]
  /gps/hist/point 12.00 	0.0		#
  /gps/hist/point 13.00 	0.0		#
  /gps/hist/point 14.00 	0.0		#
  /gps/hist/point 15.00 	0.0		#
  /gps/hist/point 16.09 	0.0		#
  /gps/hist/point 16.10 	3.0		# [DEFAULT: 3.0]
  /gps/hist/point 17.00 	0.0		#
					#
  #########################################

This is a copy of one of my files. Noticed I have defined several energies. However I set all of them to zero except two. Therefore my particle generator will create particles 97% of the time with and E=11.7 MeV and 3% of the time with a 16MeV value. Please refer to GPS documentation for more info:

  http://www-zeuthen.desy.de/geant4/geant4.9.3.b01/classG4GeneralParticleSource.html

I hope this helps,

C Mos

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 Sad: Re: How to assign discrete values of energy to primary particles from a text file?   (Amit Kumar - 28 Jan, 2015)
 Add Message Add Message
to: "Re: How to assign discrete values of energy to primary particles from a text file?"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]