Adding track information and step information in the simulation

I am doing a simulation on HPGe detector. I have successfully build the make file using cmake command and also build the target using make -jN command. But when I am trying to run the executable file then that gives me the error:

**************************************************************
 Geant4 version Name: geant4-10-06-patch-02 [MT]   (29-May-2020)
                       Copyright : Geant4 Collaboration
                      References : NIM A 506 (2003), 250-303
                                 : IEEE-TNS 53 (2006), 270-278
                                 : NIM A 835 (2016), 186-225
                             WWW : http://geant4.org/
**************************************************************

-------- EEEE ------- G4Exception-START -------- EEEE -------
*** G4Exception : Event0101
      issued by : G4ParticleGun::SetParticleDefinition()
Null pointer is given.
*** Fatal Exception *** core dump ***
 **** Track information is not available at this moment
 **** Step information is not available at this moment

-------- EEEE -------- G4Exception-END --------- EEEE -------

*** G4Exception: Aborting execution ***
Aborted (core dumped)

I am not able to find the problem here. What should I do with this problem? It will be very helpful if anyone tells me about this.
Here is the list of files…

hpgeActionInitialization.cc  
hpgeDetectorConstruction.cc
hpgeEventAction.cc
hpgePhysicsList.cc  
hpgePrimaryGeneratorAction.cc  
hpgeRunAction.cc

I also have the header files corresponding to this and also the main.cc file and the CmakeList file.
Please let me know if I have any missing files.
Thank you.

The function SetParticleDefinition(), which you must be calling somewhere in your source code (you can use grep to find it) has been given a Null pointer*. You may want to research what “null pointer” means.

In your code, you need to pass SetParticleDefinition() a valid pointer to a particle.

1 Like

Sir,
I have tried different ways to resolve the problem along with the possible ways you have mentioned, but I could not get the results out of it. Here I have written the code for
PrimaryGeneratorAction.hh →

#ifndef hpgePrimaryGeneratorAction_h
#define hpgePrimaryGeneratorAction_h 1

#include "G4VUserPrimaryGeneratorAction.hh"

#include "globals.hh"
// #include "unit.hh"
#include "G4Types.hh"
#include "G4SystemOfUnits.hh"
#include "G4ParticleGun.hh"

class G4ParticleGun;
class G4Event;

class hpgePrimaryGeneratorAction: public G4VUserPrimaryGeneratorAction
{
public:
    hpgePrimaryGeneratorAction();
    virtual ~hpgePrimaryGeneratorAction();
    virtual void GeneratePrimaries(G4Event* );
    const G4ParticleGun *GetParticleGun() const { return fParticleGun;}
private:
    // data members
    G4ParticleGun *fParticleGun; //pointer a to G4 service class
};
#endif

And the code for
PrimaryGeneratorAction.cc →

#include "hpgePrimaryGeneratorAction.hh"

#include "G4Event.hh"
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"
#include "G4ThreeVector.hh"
#include "G4SystemOfUnits.hh"
#include "Randomize.hh"
//

hpgePrimaryGeneratorAction::hpgePrimaryGeneratorAction():
    G4VUserPrimaryGeneratorAction(),
    fParticleGun(0)
{
    G4int nofParticles = 1;
    fParticleGun = new G4ParticleGun(nofParticles);
    G4String particleName;
    // G4double energy = 1. * MeV;
    G4ThreeVector position = G4ThreeVector(0, 0, 5*cm);
    G4ThreeVector momentumDirection = G4ThreeVector(0, 0, -1 *m);
    G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
    G4ParticleDefinition *particle = particleTable->FindParticle(particleName = "gamma");
    fParticleGun->SetParticleDefinition(particle);
    fParticleGun->SetParticleEnergy(1.0 *MeV);
    fParticleGun->SetParticlePosition(position);
    fParticleGun->SetParticleMomentumDirection(momentumDirection);
}

hpgePrimaryGeneratorAction::~hpgePrimaryGeneratorAction()
{
    delete fParticleGun;
}

void hpgePrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
  // this function is called at the beginning of event

  fParticleGun->GeneratePrimaryVertex(anEvent);
}

I have the above header and source file. I can not detect any errors here. Please help me to find out and fix the problem. I have used B1, B2, B3 reference examples provided with Geant4 packages to write my code for this.
Thank you.

There’s your problem, which is multifold. You fetch a pointer from the particle table, but you don’t test whether is null or not. If you put an if (particle) test in there, you’ll discover immediately that it fails (i.e., particle==0).

But why? Because you’re doing that configuration in the PrimaryGeneratorAction constructor. When you instantiate the object, the run configuration has not yet been initialized, and therefore the particle table has not been populated yet.

If you want to keep the particle setting the way you have it, you need to move it to your GeneratePrimaries() function, which doesn’t get called until after the run is initialized. As an aside, that would also set you up for the option of switching particles between events, if you wanted or needed to do that.

An alternative, you could keep your code in the constructor, as it is, but don’t use the particle table. Since the particles themselves are global singletons, you can instantiate it yourself:

1 Like

Hi @mkelsey ,
Thank you so much. This removes that problem. Now when I run this… I am still getting

**************************************************************
 Geant4 version Name: geant4-10-06-patch-02 [MT]   (29-May-2020)
                       Copyright : Geant4 Collaboration
                      References : NIM A 506 (2003), 250-303
                                 : IEEE-TNS 53 (2006), 270-278
                                 : NIM A 835 (2016), 186-225
                             WWW : http://geant4.org/
**************************************************************


***** Table : Nb of materials = 3 *****

 Material: G4_Galactic    density:  0.000 kg/m3   RadL: 204310101.835 pc   Nucl.Int.Length: 113427275.267 pc 
                       Imean:  21.800 eV   temperature:   2.73 K  pressure:   0.00 atm

   --->  Element: H (H)   Z =  1.0   N =     1   A =  1.008 g/mole
         --->  Isotope:    H1   Z =  1   N =   1   A =   1.01 g/mole   abundance: 99.989 %
         --->  Isotope:    H2   Z =  1   N =   2   A =   2.01 g/mole   abundance:  0.011 %
          ElmMassFraction: 100.00 %  ElmAbundance 100.00 % 


 Material: Aluminium    density:  2.702 g/cm3   RadL:   8.886 cm   Nucl.Int.Length:  38.851 cm 
                       Imean: 166.000 eV   temperature: 293.15 K  pressure:   1.00 atm

   --->  Element: Al (Al)   Z = 13.0   N =    27   A = 26.982 g/mole
         --->  Isotope:  Al27   Z = 13   N =  27   A =  26.98 g/mole   abundance: 100.000 %
          ElmMassFraction: 100.00 %  ElmAbundance 100.00 % 


 Material: Germanium    density:  5.323 g/cm3   RadL:   2.301 cm   Nucl.Int.Length:  27.431 cm 
                       Imean: 350.000 eV   temperature: 293.15 K  pressure:   1.00 atm

   --->  Element: Ge (Ge)   Z = 32.0   N =    73   A = 72.613 g/mole
         --->  Isotope:  Ge70   Z = 32   N =  70   A =  69.92 g/mole   abundance: 20.840 %
         --->  Isotope:  Ge72   Z = 32   N =  72   A =  71.92 g/mole   abundance: 27.540 %
         --->  Isotope:  Ge73   Z = 32   N =  73   A =  72.92 g/mole   abundance:  7.730 %
         --->  Isotope:  Ge74   Z = 32   N =  74   A =  73.92 g/mole   abundance: 36.280 %
         --->  Isotope:  Ge76   Z = 32   N =  76   A =  75.92 g/mole   abundance:  7.610 %
          ElmMassFraction: 100.00 %  ElmAbundance 100.00 % 



G4ParticleDefintion (other than ions and shortlived) should be created in Pre_Init state  e-

-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : PART101
      issued by : G4ParticleDefintion::G4ParticleDefintion
G4ParticleDefinition should be created in PreInit state
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

G4ParticleDefintion (other than ions and shortlived) should be created in Pre_Init state  e+

-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : PART101
      issued by : G4ParticleDefintion::G4ParticleDefintion
G4ParticleDefinition should be created in PreInit state
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

Segmentation fault (core dumped)

This gets core dumping again not specified where. What could I do about it?
But the opengl viewer did not pop up. Can you tell me whether the program is running successfully or or not? And how to write the code for opening up the viewer(any references will help)? Right now I am a newbie to this simulation.
Thank you again.

Let’s start with the warning messages. If your physics list is properly constituted, you should not be getting those warnings. They mean that “new” particles (i.e., particles not previously instantiated) are getting created after beamOn. Are you using one of the official Geant4 reference physics lists (like FTFP_BERT)? If you are creating your own physics list from scratch, did you make sure that you put all the appropriate particles into the ConstructParticle() function?

For the core dump, without a traceback nobody can help you. Are you building your own Geant4 installation, or are you using a central build on a compute farm? Can you build, or do you have access to, a “Debug” or “RelWithDebugInfo” installation (see the Geant4 Installation Guide)?

Once you have fixed your physics list, and once you are able to produce a core dump, it will be easier to isolate what’s wrong with your application and fix it.

Sir,
I build the physics list from scratch. As a newbie, I do not have confidence in my physics list.
I have gamma-ray which incidents on the germanium semiconductor crystal(detector) and produce electron and hole pairs via photoelectric effect, Compton effect and pair production inside the crystal. So, there is ionization occurred in the crystal due to gamma rays. So, can you suggest me the suitable official Geant4 reference physics list?
How should I do the debugging? Can you please suggest me a debugger? Can I use the debuggers you have mentioned?
One more thing, I am having the *.out file in every example (like exampleB1.out ) of geant4. For my program, how will I get it? should I have to compile my main.cc file with help of g++ or any other compiler? I have no idea about the output file.
Thank you sir.