musrPrimaryGeneratorAction.cc

Go to the documentation of this file.
00001 #include "musrPrimaryGeneratorAction.hh"
00002 #include "musrDetectorConstruction.hh"
00003 #include "musrPrimaryGeneratorMessenger.hh"
00004 #include "G4Event.hh"
00005 #include "G4ParticleGun.hh"
00006 #include "G4ParticleTable.hh"
00007 #include "G4ParticleDefinition.hh"
00008 #include "Randomize.hh"
00009 #include "G4ios.hh"
00010 #include "musrParticleGun.hh"
00011 #include "G4UnitsTable.hh"
00012 #include "globals.hh"
00013 #include "G4Gamma.hh"
00014 #include "G4ThreeVector.hh"
00015 #include "G4RunManager.hh"
00016 #include "time.h"
00017 #include <iomanip>
00018 
00019 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
00020  
00021 musrPrimaryGeneratorAction::musrPrimaryGeneratorAction(
00022                                             musrDetectorConstruction* musrDC)
00023   :musrDetector(musrDC),rndmFlag("off"),xvertex(0.),yvertex(0.),zvertex(0.), 
00024  xyvertexdefined(false), zvertexdefined(false),pxanglevertex(0.),pyanglevertex(0.),pvertexdefined(false),
00025    pMomentum(0.),pMomentumdefined(false),TheSetWidth(0.),Widthdefined(false)
00026 {
00027   G4int n_particle = 1;
00028   particleGun  = new musrParticleGun(n_particle);
00029   
00030   //create a messenger for this class
00031   gunMessenger = new musrPrimaryGeneratorMessenger(this);
00032 
00033   // default particle kinematic
00034 
00035   G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
00036   G4ParticleDefinition* particle= particleTable->FindParticle("mu+");
00037   particleGun->SetParticleDefinition(particle);
00038 
00039 } 
00040 
00041 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
00042 
00043 musrPrimaryGeneratorAction::~musrPrimaryGeneratorAction()
00044 {
00045   delete particleGun;
00046   delete gunMessenger;
00047 }
00048 
00049 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
00050 
00051 void musrPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
00052 {
00053  
00054 
00055 
00056  //this function is called at the begining of event
00057   // 
00058 
00059 
00060     G4double tau=0.000002197;
00061     G4double rnddecaytime = -tau*log(1-G4UniformRand());
00062     decaytime = rnddecaytime*s;
00063     particleGun->SetDecayTime(decaytime);
00064 
00065 
00066   //Set the initial particle position
00067      const double stdFWHMfactor=sqrt(2*log(2));
00068      G4double TheWidth;
00069 
00070      if(Widthdefined)
00071        {
00072     TheWidth=TheSetWidth;
00073        }
00074      else
00075        {
00076     TheWidth=40.*mm;
00077        }
00078 
00079 
00080     G4double xbeamwidthFWHM = TheWidth;
00081     G4double ybeamwidthFWHM = TheWidth;
00082 
00083     G4double x0,y0,z0 ;
00084 
00085 
00086     G4double xstdposition =  xbeamwidthFWHM/(2*stdFWHMfactor);
00087     G4double ystdposition =  ybeamwidthFWHM/(2*stdFWHMfactor);
00088     G4RandGauss* jRndGauss = new G4RandGauss(theEngine, 0, xstdposition);
00089     G4double xrndposition = jRndGauss->shoot(0, xstdposition);
00090     G4double yrndposition = jRndGauss->shoot(0, ystdposition);
00091     G4double xposition = xrndposition*mm;
00092     G4double yposition = yrndposition*mm;
00093 
00094 
00095     // temporary lines
00096     //          xposition = xbeamwidthFWHM/2.0;
00097     //  yposition = ybeamwidthFWHM/2.0;
00098 
00099 
00100 
00101         //      G4cout<<"Initial muon position = " << xposition <<", " 
00102         //    << yposition << "mm \n" <<G4endl;
00103 
00104 
00105 
00106   if(xyvertexdefined)
00107   {
00108     x0 = xvertex ;
00109     y0 = yvertex ;
00110   }
00111   else
00112   {
00113     x0 = xposition ;
00114     y0 = yposition ;
00115   }
00116 
00117 
00118   if(zvertexdefined)
00119   {
00120     z0 = zvertex ;
00121   }
00122   else
00123   {
00124     z0 = 0.*mm ;
00125   }
00126 
00127 
00128   //Set the initial particle momentum
00129 
00130   G4double pxangle0,pyangle0 ;
00131 
00132   if(pvertexdefined)
00133   {
00134     pxangle0 = pxanglevertex ;
00135     pyangle0 = pyanglevertex ;
00136   }
00137   else
00138   {
00139     pxangle0 = 0.*deg ;
00140     pyangle0 = 0.*deg ;
00141   }
00142 
00143   G4double myMomentum;
00144 
00145   if(pMomentumdefined)
00146     {
00147     myMomentum=pMomentum;      
00148     }
00149   else
00150     {
00151       myMomentum=0.0;
00152     }
00153 
00154 
00155   particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
00156 
00157 
00158 
00159     G4double xpitch = sin(pxangle0);
00160     G4double ypitch = sin(pyangle0);
00161     G4double zpitch = sqrt(1-(sin(pxangle0)*sin(pxangle0)
00162                            +sin(pyangle0)*sin(pyangle0)));
00163 
00164     // Then orient the spin relative to the beam pitch
00165 
00166 
00167   //longitudinal
00168     particleGun->SetParticlePolarization(G4ThreeVector(xpitch,ypitch,-zpitch));
00169 
00170   //transverse
00171   //     particleGun->SetParticlePolarization(G4ThreeVector(zpitch,0,-xpitch));
00172 
00173 
00174   G4double energy = sqrt(1e6*myMomentum*myMomentum+11163.82428)-105.659; 
00175   particleGun->SetParticleEnergy(energy*MeV);
00176   particleGun->SetParticleMomentumDirection(G4ThreeVector(xpitch,ypitch,zpitch));  particleGun->GeneratePrimaryVertex(anEvent);
00177 
00178 
00179 
00180 }
00181 
00183 //
00184 //
00185 
00186 
00187 void musrPrimaryGeneratorAction::Setxvertex(G4double x)
00188 {
00189   xyvertexdefined = true ;
00190   xvertex = x ;
00191 
00192 }
00193 
00194 void musrPrimaryGeneratorAction::Setyvertex(G4double y)
00195 {
00196   xyvertexdefined = true ;
00197   yvertex = y ;
00198 
00199 }
00200 void musrPrimaryGeneratorAction::Setzvertex(G4double z)
00201 {
00202   zvertexdefined = true ;
00203   zvertex = z ;
00204 
00205 }
00206 
00207 void musrPrimaryGeneratorAction::Setpxanglevertex(G4double px)
00208 {
00209   pvertexdefined = true ;
00210   pxanglevertex = px ;
00211 
00212 }
00213 
00214 void musrPrimaryGeneratorAction::Setpyanglevertex(G4double py)
00215 {
00216   pvertexdefined = true ;
00217   pyanglevertex = py ;
00218 
00219 }
00220 void musrPrimaryGeneratorAction::SetMomentum(G4double p)
00221 {
00222   pMomentumdefined = true ;
00223   pMomentum = p ;
00224 
00225 }
00226 
00227 
00228 void musrPrimaryGeneratorAction::SetBeamWidth(G4double w)
00229 {
00230   Widthdefined = true;
00231   TheSetWidth=w;
00232 G4cout<< "FWHM beam width set to "<< TheSetWidth <<"mm" <<G4endl;
00233 
00234 }

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