musrParticleGun.cc

Go to the documentation of this file.
00001 #include "musrParticleGun.hh"
00002 #include "Randomize.hh"
00003 #include "G4ios.hh"
00004 #include "musrParticleGunMessenger.hh"
00005 
00006 #include "G4ProcessManager.hh"
00007 #include "G4VProcess.hh"
00008 
00009 #include "G4ProcessVector.hh"
00010 
00011 musrParticleGun::musrParticleGun()
00012 {
00013   SetInitialValues();
00014   Messenger = new G4ParticleGunMessenger(this);
00015 }
00016 
00017 musrParticleGun::musrParticleGun(G4int numberofparticles)
00018 {
00019   SetInitialValues();
00020   NumberOfParticlesToBeGenerated = numberofparticles;
00021 }
00022 
00023 
00024 musrParticleGun::~musrParticleGun()
00025 {
00026   delete Messenger;
00027 }
00028 
00029 void musrParticleGun::SetInitialValues()
00030 {
00031   NumberOfParticlesToBeGenerated = 1;
00032   particle_definition = 0;
00033   G4ThreeVector zero;
00034   particle_momentum_direction = (G4ParticleMomentum)zero;
00035   particle_energy = 0.0;
00036   particle_position = zero;
00037   particle_time = 0.0;
00038   particle_polarization = zero;
00039   particle_charge = 0.0;
00040 
00041 }
00042 
00043 void musrParticleGun::SetDecayTime(G4double d)
00044 {
00045   decaytime=d;
00046 }
00047 
00048 void musrParticleGun::GeneratePrimaryVertex(G4Event* evt)
00049 {
00050   if(particle_definition==0) return;
00051 
00052   // create a new vertex
00053   G4PrimaryVertex* vertex = 
00054     new G4PrimaryVertex(particle_position,particle_time);
00055 
00056 
00057   // create new primaries and set them to the vertex
00058   G4double mass =  particle_definition->GetPDGMass();
00059   G4double energy = particle_energy + mass;
00060   G4double pmom = sqrt(energy*energy-mass*mass);
00061   G4double px = pmom*particle_momentum_direction.x();
00062   G4double py = pmom*particle_momentum_direction.y();
00063   G4double pz = pmom*particle_momentum_direction.z();
00064   for( G4int i=0; i<NumberOfParticlesToBeGenerated; i++ )
00065   {
00066 
00067 
00068     G4PrimaryParticle* particle =
00069       new G4PrimaryParticle(particle_definition,px,py,pz);
00070     particle->SetMass( mass );
00071     particle->SetCharge( particle_charge );
00072     particle->SetPolarization(particle_polarization.x(),
00073                                particle_polarization.y(),
00074                                particle_polarization.z());
00075     particle->SetProperTime(decaytime);
00076     //    G4cout<<"Muon decay time = " << decaytime/ns <<"ns. \n" <<G4endl;
00077     
00078     vertex->SetPrimary( particle );
00079 
00080 
00081   }
00082 
00083   evt->AddPrimaryVertex( vertex );
00084 }

Generated on Mon Mar 27 12:19:54 2006 for MUSR by  doxygen 1.4.6