[807] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | // |
---|
| 27 | // $Id: ExN06PrimaryGeneratorAction.cc,v 1.6 2006/06/29 17:54:27 gunter Exp $ |
---|
| 28 | // GEANT4 tag $Name: $ |
---|
| 29 | // |
---|
| 30 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 31 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 32 | |
---|
| 33 | #include "ExN06PrimaryGeneratorAction.hh" |
---|
| 34 | #include "ExN06PrimaryGeneratorMessenger.hh" |
---|
| 35 | |
---|
| 36 | #include "Randomize.hh" |
---|
| 37 | |
---|
| 38 | #include "G4Event.hh" |
---|
| 39 | #include "G4ParticleGun.hh" |
---|
| 40 | #include "G4ParticleTable.hh" |
---|
| 41 | #include "G4ParticleDefinition.hh" |
---|
| 42 | |
---|
| 43 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 44 | |
---|
| 45 | ExN06PrimaryGeneratorAction::ExN06PrimaryGeneratorAction() |
---|
| 46 | { |
---|
| 47 | G4int n_particle = 1; |
---|
| 48 | particleGun = new G4ParticleGun(n_particle); |
---|
| 49 | |
---|
| 50 | //create a messenger for this class |
---|
| 51 | gunMessenger = new ExN06PrimaryGeneratorMessenger(this); |
---|
| 52 | |
---|
| 53 | //default kinematic |
---|
| 54 | // |
---|
| 55 | G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); |
---|
| 56 | G4ParticleDefinition* particle = particleTable->FindParticle("e+"); |
---|
| 57 | |
---|
| 58 | particleGun->SetParticleDefinition(particle); |
---|
| 59 | particleGun->SetParticleTime(0.0*ns); |
---|
| 60 | particleGun->SetParticlePosition(G4ThreeVector(0.0*cm,0.0*cm,0.0*cm)); |
---|
| 61 | particleGun->SetParticleMomentumDirection(G4ThreeVector(1.,0.,0.)); |
---|
| 62 | particleGun->SetParticleEnergy(500.0*keV); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 66 | |
---|
| 67 | ExN06PrimaryGeneratorAction::~ExN06PrimaryGeneratorAction() |
---|
| 68 | { |
---|
| 69 | delete particleGun; |
---|
| 70 | delete gunMessenger; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 74 | |
---|
| 75 | void ExN06PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) |
---|
| 76 | { |
---|
| 77 | particleGun->GeneratePrimaryVertex(anEvent); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 81 | |
---|
| 82 | void ExN06PrimaryGeneratorAction::SetOptPhotonPolar() |
---|
| 83 | { |
---|
| 84 | G4double angle = G4UniformRand() * 360.0*deg; |
---|
| 85 | SetOptPhotonPolar(angle); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 89 | |
---|
| 90 | void ExN06PrimaryGeneratorAction::SetOptPhotonPolar(G4double angle) |
---|
| 91 | { |
---|
| 92 | if (particleGun->GetParticleDefinition()->GetParticleName() != "opticalphoton") |
---|
| 93 | { |
---|
| 94 | G4cout << "--> warning from PrimaryGeneratorAction::SetOptPhotonPolar() :" |
---|
| 95 | "the particleGun is not an opticalphoton" << G4endl; |
---|
| 96 | return; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | G4ThreeVector normal (1., 0., 0.); |
---|
| 100 | G4ThreeVector kphoton = particleGun->GetParticleMomentumDirection(); |
---|
| 101 | G4ThreeVector product = normal.cross(kphoton); |
---|
| 102 | G4double modul2 = product*product; |
---|
| 103 | |
---|
| 104 | G4ThreeVector e_perpend (0., 0., 1.); |
---|
| 105 | if (modul2 > 0.) e_perpend = (1./std::sqrt(modul2))*product; |
---|
| 106 | G4ThreeVector e_paralle = e_perpend.cross(kphoton); |
---|
| 107 | |
---|
| 108 | G4ThreeVector polar = std::cos(angle)*e_paralle + std::sin(angle)*e_perpend; |
---|
| 109 | particleGun->SetParticlePolarization(polar); |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|