# Problem with GeneralParticleSource user defined histogram

**URL:** <https://geant4-forum.web.cern.ch/t/problem-with-generalparticlesource-user-defined-histogram/6793>\
**Category:** Particles, Track, Event, Run and Biasing\
**Created:** [December 17, 2021, 7:38pm UTC](https://geant4-forum.web.cern.ch/t/problem-with-generalparticlesource-user-defined-histogram/6793 "2021-12-17T19:38:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alon\_Lifshits](https://geant4-forum.web.cern.ch/letter_avatar_proxy/v4/letter/a/58956e/32.png) [@Alon\_Lifshits](https://geant4-forum.web.cern.ch/u/Alon_Lifshits)\
**Post date:** [December 17, 2021, 7:38pm UTC](https://geant4-forum.web.cern.ch/t/problem-with-generalparticlesource-user-defined-histogram/6793/1 "2021-12-17T19:38:04Z")

</div>

Hi everyone.  
I have a strange problem with the GPS user defined histogram. It seems like at some point there is division by zero somewhere during the run. I tried changing the energies to lower values and suddenly at some point I stopped getting the error.

Any ideas how I can fix this?

Terminal error log:  
ZMxpvInfiniteVector thrown:  
ZMxpvInfiniteVector: Attempt to divide vector by 0 – will produce infinities and/or NANs  
at line 299 in file /root/Downloads/2.4.4.0/CLHEP/Vector/src/ThreeVector.cc  
terminate called after throwing an instance of ‘ZMxpvInfiniteVector’  
what(): ZMxpvInfiniteVector: Attempt to divide vector by 0 – will produce infinities and/or NANs  
Abort (core dumped)

Run file:

# Change the default number of workers (in multi-threading mode)

/run/numberOfThreads 4

# 

# Initialize kernel

/run/initialize

# 

/gps/ene/type User  
/gps/hist/type energy  
/gps/hist/point 2212.38938053096 0.415246215397869  
/gps/hist/point 210176.991150443 0.415246215397869  
/gps/hist/point 418141.592920354 0.275016223772348  
/gps/hist/point 626106.194690266 0.0789319898472974  
/gps/hist/point 834070.796460178 0.0310448734222262  
/gps/hist/point 1042035.39823009 0.0265197142861716  
/gps/hist/point 1250000 0.039559705636263  
/gps/hist/point 1457964.60176991 0.0420309146381671  
/gps/hist/point 1665929.20353982 0.0292983858775098  
/gps/hist/point 1873893.80530974 0.0189140797158606  
/gps/hist/point 2081858.40707965 0.0114152905380548  
/gps/hist/point 2289823.00884956 0.00683177812085869  
/gps/hist/point 2497787.61061947 0.00700646029735413  
/gps/hist/point 2705752.21238938 0.00677452394797838  
/gps/hist/point 2913716.81415929 0.00430041493335176  
/gps/hist/point 3121681.41592921 0.00336911790123036  
/gps/hist/point 3329646.01769912 0.00205056213886734  
/gps/hist/point 3537610.61946903 0.000961447481121346  
/gps/hist/point 3745575.22123894 0.000728302047469481

/tracking/verbose 0  
/gps/particle mu1-  
/gps/direction 0 0 1  
/gps/position 0 0 -1000  
/vis/viewer/zoom 1

/run/beamOn 1000

---

<div class="post-metadata">

**Author:** ![mksharma\_iitk](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/mksharma_iitk/32/2080_2.png) [@mksharma\_iitk](https://geant4-forum.web.cern.ch/u/mksharma_iitk)\
**Post date:** [December 20, 2021, 5:32pm UTC](https://geant4-forum.web.cern.ch/t/problem-with-generalparticlesource-user-defined-histogram/6793/2 "2021-12-20T17:32:38Z")

</div>

Not sure, may be something related to the position or the direction vector you defined. I suggest simplifying your example and rule out the options one by one. Use monoenergetic distribution, then isotropic etc. Similarly then simplifying your `/hist/point` spectra. Also, one trick you may want to do is save the spectra in a separate file and call it in your `mac`. This will make your mac tidy; see [here](https://geant4-forum.web.cern.ch/t/how-to-implement-multiple-sources-via-gps-in-macro/6562/4).

Also, what if you define the particle type, position, biasing in the same sequence as [here](https://geant4-forum.web.cern.ch/t/how-to-implement-multiple-sources-via-gps-in-macro/6562/4)? Does that change anything. There are examples in [Book For Application Developers](https://indico.cern.ch/event/647154/contributions/2714212/attachments/1529029/2397032/BookForApplicationDevelopers.pdf).

---

<div class="post-metadata">

**Author:** ![Alon\_Lifshits](https://geant4-forum.web.cern.ch/letter_avatar_proxy/v4/letter/a/58956e/32.png) [@Alon\_Lifshits](https://geant4-forum.web.cern.ch/u/Alon_Lifshits)\
**Post date:** [December 20, 2021, 8:36pm UTC](https://geant4-forum.web.cern.ch/t/problem-with-generalparticlesource-user-defined-histogram/6793/3 "2021-12-20T20:36:46Z")

</div>

Hi, Thanks for the reply.  
The trick with the spectra is great, looks way better now. I tried changing the direction, and it seems that as soon as the particles begin interacting with the detector, the problems begin. Changing the energy didn’t changing anything. I’ll try changing some more parameters and see if perhaps that helps.
