Message: 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

Question How to assign discrete values of energy to primary particles from a text file? 

Forum: Particles
Date: 06 Jan, 2015
From: Amit Kumar <Amit Kumar>

Hello all

I want to set few discrete values (let 5 values) of energy to primary beams from a text file energy.txt, it has a single column of integer energies. I have added following lines in constructor of Primary generator action

int energy[5]; FILE *f1 = fopen("energy.txt, "r");

for (int i=0;i<5;i++) {fscanf(f1,"%d\n",&energy[i];)}

fclose(f1);

and following lines in Generate primaries method of Primary generator action

int j = y%5;

// here y is taking event ID from Event action class using GetEventID()

particleGun->SetParticleEnergy(energy[j]);

But I am getting Segmentation fault while running the programme

please let me know how this fault is coming and what is the best way of assigning discrete values of energy from a text file?

Any kind of assistance will be appreciated

Thanks

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

1 Idea: Re: How to assign discrete values of energy to primary particles from a text file?   (C Mos - 06 Jan, 2015)
(_ 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: "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 ]