Message: RE: Generating 2 particles with different energies Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None RE: Generating 2 particles with different energies 

Forum: Particles
Re: None Generating 2 particles with different energies (Adam)
Re: None RE: Generating 2 particles with different energies (Makoto Asai)
Re: None RE: Generating 2 particles with different energies (Adam)
Date: 11 Jun, 2007
From: Makoto Asai <Makoto Asai>

 I identified several problems in your code, which I note below. In summary, 
your primary generator action shoots four primaries, two for each energy of 
"e1" and "e2", and all of these four go to the same direction.

 On the other hand, I do not see any direct reason you got "The result was 
thousands of tracks which led to a segmentation fault". How could you notice 
you got thousands of primary tracks? And, even just thousands of primaries 
do not cause any issue to the Geant4 kernel (e.g. CMS at CERN had already 
been simulated events with 10 thousand primaries in each event). I suspect
you miss-identified secondaries as primaries. You might say there cannot be
such number of secondaries, but see item 3) below. You are shooting energetic
primaries.

 I believe there still exists another problem in your code which lead to the
segmentation fault. Please use debugger to identify the location where you 
got the segmentation fault (after fixing these issues). 

1)  I guess it is intentional that
> void ExN02PrimaryGeneratorAction::GeneratePointsInVolume() {
is not invoked from 
> void ExN02PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
Thus, primaries are all starting from the origin.

2) 
> void ExN02PrimaryGeneratorAction::GenerateIsotropicFlux()
is invoked just once and thus
> particleGun->SetParticleMomentum(particle_momentum_direction); }
is set once. It means that both of your primaries are directed to the
same direction. Is this OK?

3)
>   G4double Q = 2.4578;
>   G4double me = 0.511;
> 
>   G4double y;
> 
>   e1 = G4UniformRand() * Q;
>   y = G4UniformRand();
Proper unit must be multiplied to "Q", "me" and "y".

4) In
> ExN02PrimaryGeneratorAction::ExN02PrimaryGeneratorAction(
>   G4int n_particle = 2;
should be 1 rather than 2. This constructor argument means the number
of primary particles shot by one invocation of 
>   particleGun->GeneratePrimaryVertex(anEvent);


> -----Original Message-----
> From: Adam [mailto:ax_blais@laurentian.ca] 
> Sent: Monday, June 11, 2007 5:54 AM
> To: publichypernews
> Subject: RE: Generating 2 particles with different energies
> 
> *** Discussion title: Particles
> Email replies to PublicHyperNews@slac.stanford.edu must include:
>   In-Reply-To: <"/particles/343/1/1"@geant4-hn.slac.stanford.edu>
>   Subject: ...change this to be about your reply.
> 
> Here it is:
> 
> #include "ExN02PrimaryGeneratorAction.hh"
> #include "ExN02DetectorConstruction.hh"
> 
> #include "G4Event.hh"
> #include "G4ParticleGun.hh"
> #include "G4ParticleTable.hh"
> #include "G4ParticleDefinition.hh"
> #include "G4PhysicalVolumeStore.hh"
> #include "globals.hh"
> 
> #include <cmath>
> 
> #include "G4Electron.hh"
> #include "Randomize.hh"
> 
> void ExN02PrimaryGeneratorAction::GeneratePointsInVolume() {
> 
>   G4ThreeVector RandPos;
>   G4double x=0.*cm, y=0.*cm, z=0.*cm;
>   G4double radius=304.2*cm, height=304.2*cm;
> 
>   x = radius*2.*cm;
>   y = radius*2.*cm;
>   while(((x*x)+(y*y)) > (radius*radius)) {
>     x = G4UniformRand();
>     y = G4UniformRand();
>     z = G4UniformRand();
>     x = (x*2.*radius) - radius;
>     y = (y*2.*radius) - radius;
>     z = (z*2.*height) - height;
>   }
> 
>   RandPos.setX(x);
>   RandPos.setY(y);
>   RandPos.setZ(z);
> 
>   //G4cout << "Starting position is : " << RandPos << G4endl;
> 
> particleGun->SetParticlePosition(RandPos); }
> 
> void ExN02PrimaryGeneratorAction::GenerateIsotropicFlux()
> {
>   G4double rndm, rndm2;
>   G4double px, py, pz;
>   G4double MinTheta = 0.;
>   G4double MaxTheta = pi;
>   G4double MinPhi = 0.;
>   G4double MaxPhi = twopi;
>   G4double sinphi, Phi;
> 
>   G4double sintheta, costheta, cosphi;
>   rndm = G4UniformRand();
>   costheta = std::cos(MinTheta) - rndm * (std::cos(MinTheta) 
> - std::cos(MaxTheta));
>   sintheta = std::sqrt(1. - costheta*costheta);
> 
>   rndm2 = G4UniformRand();
>   Phi = MinPhi + (MaxPhi - MinPhi) * rndm2;
>   sinphi = std::sin(Phi);
>   cosphi = std::cos(Phi);
> 
>   px = -sintheta * cosphi;
>   py = -sintheta * sinphi;
>   pz = -costheta;
> 
>  G4double ResMag = std::sqrt((px*px) + (py*py) + (pz*pz));
>   px = px/ResMag;
>   py = py/ResMag;
>   pz = pz/ResMag;
> 
>   G4ParticleMomentum particle_momentum_direction;
> 
>   particle_momentum_direction.setX(px);
>   particle_momentum_direction.setY(py);
>   particle_momentum_direction.setZ(pz);
> 
>   // particle_momentum_direction now holds unit momentum vector.
> 
>   //G4cout << "Generating isotropic vector: " << 
> particle_momentum_direction << G4endl;
> 
> particleGun->SetParticleMomentum(particle_momentum_direction); }
> 
> void ExN02PrimaryGeneratorAction::GenerateRandomEnergy()
> {
>   G4double Q = 2.4578;
>   G4double me = 0.511;
> 
>   G4double y;
> 
>   e1 = G4UniformRand() * Q;
>   y = G4UniformRand();
> 
>   while(y > 0.1091196*(((e1 + me)*(e1 + me)) * ((Q + me - 
> e1)*(Q + me - e1)))) {
>     e1 = G4UniformRand() * Q;
>     y = G4UniformRand();
>   }
> 
>   e2 = Q - e1;
> 
> G4cout << e1 << " " << y << "******************" << G4endl; }
> 
> ExN02PrimaryGeneratorAction::ExN02PrimaryGeneratorAction(
>                                                
> ExN02DetectorConstruction* myDC)
> :myDetector(myDC)
> {
>   G4int n_particle = 2;
> 
>   particleGun = new G4ParticleGun(n_particle);
>   
> particleGun->SetParticleDefinition(G4Electron::ElectronDefinition());
> 
> }
> 
> ExN02PrimaryGeneratorAction::~ExN02PrimaryGeneratorAction()
> {
>   delete particleGun;
> }
> 
> void ExN02PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
> {
>   ExN02PrimaryGeneratorAction::GenerateIsotropicFlux();
>   ExN02PrimaryGeneratorAction::GeneratePointsInVolume();
>   particleGun->SetParticleEnergy(e1);
>   particleGun->GeneratePrimaryVertex(anEvent);
>   particleGun->SetParticleEnergy(e2);
>   particleGun->GeneratePrimaryVertex(anEvent);
> }
> 
> 

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

1 None: RE: Generating 2 particles with different energies   (Adam - 11 Jun, 2007)
(_ None: RE: Generating 2 particles with different energies   (Makoto Asai - 11 Jun, 2007)
(_ None: RE: Generating 2 particles with different energies   (Adam - 11 Jun, 2007)
 Add Message Add Message
to: "RE: Generating 2 particles with different energies"

 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 ]