[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: PhotInPrimaryGeneratorAction.cc,v 1.6 2006/06/29 16:25:21 gunter Exp $ |
---|
| 28 | // GEANT4 tag $Name: $ |
---|
| 29 | // |
---|
| 30 | |
---|
| 31 | #define debug |
---|
| 32 | |
---|
| 33 | #include "PhotInPrimaryGeneratorAction.hh" |
---|
| 34 | |
---|
| 35 | PhotInPrimaryGeneratorAction::PhotInPrimaryGeneratorAction(): |
---|
| 36 | section(1),detector(0),part("gamma"),energy(100.),oldPart("gamma"),oldEnergy(100.) |
---|
| 37 | { |
---|
| 38 | #ifdef debug |
---|
| 39 | G4cout<<"PhotInPrimaryGeneratorAction::Constructor: part="<<part<<", E="<<energy<<G4endl; |
---|
| 40 | #endif |
---|
| 41 | G4int n_particle = 1; |
---|
| 42 | particleGun = new G4ParticleGun(n_particle); // Initialization of the pointer from BODY |
---|
| 43 | |
---|
| 44 | // default particle kinematic |
---|
| 45 | G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); |
---|
| 46 | G4String particleName; |
---|
| 47 | G4ParticleDefinition* particle = particleTable->FindParticle(particleName=part); |
---|
| 48 | particleGun->SetParticleDefinition(particle); |
---|
| 49 | particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.)); |
---|
| 50 | particleGun->SetParticleEnergy(energy*GeV); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | PhotInPrimaryGeneratorAction::~PhotInPrimaryGeneratorAction() {delete particleGun;} |
---|
| 54 | |
---|
| 55 | void PhotInPrimaryGeneratorAction::SetProjectileName(G4String partName) |
---|
| 56 | { |
---|
| 57 | #ifdef debug |
---|
| 58 | G4cout<<"PhotInPrimaryGeneratorAction::SetProjectileName:Before Name="<<partName |
---|
| 59 | <<", oldName="<<part<<G4endl; |
---|
| 60 | #endif |
---|
| 61 | //@@ Make a check that such a particle exists (M.K.) |
---|
| 62 | part=partName; |
---|
| 63 | #ifdef debug |
---|
| 64 | G4cout<<"PhotInPrimaryGeneratorAction::SetProjectileName: After Name="<<part<<G4endl; |
---|
| 65 | #endif |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | void PhotInPrimaryGeneratorAction::SetProjectileEnergy(G4double partEnergy) |
---|
| 69 | { |
---|
| 70 | #ifdef debug |
---|
| 71 | G4cout<<"PhotInPrimaryGeneratorAction::SetProjectileEnergy: before E="<<energy<<G4endl; |
---|
| 72 | #endif |
---|
| 73 | energy=partEnergy; |
---|
| 74 | #ifdef debug |
---|
| 75 | G4cout<<"PhotInPrimaryGeneratorAction::SetProjectileEnergy: before E="<<energy<<G4endl; |
---|
| 76 | #endif |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | void PhotInPrimaryGeneratorAction::SetDetector(PhotInDetectorConstruction* det) |
---|
| 80 | { |
---|
| 81 | #ifdef debug |
---|
| 82 | G4cout<<"PhotInPrimaryGeneratorAction::SetDetector: is called"<<G4endl; |
---|
| 83 | #endif |
---|
| 84 | detector=det; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | void PhotInPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) |
---|
| 88 | { |
---|
| 89 | #ifdef debug |
---|
| 90 | G4cout<<"PhotInPrimaryGeneratorAction::GeneratePrimaries: "<<part<<",E="<<energy<<G4endl; |
---|
| 91 | #endif |
---|
| 92 | if(part!=oldPart || energy!=oldEnergy) |
---|
| 93 | { |
---|
| 94 | #ifdef debug |
---|
| 95 | G4cout<<"PhotInPrimaryGeneratorAction::GeneratePrimaries: part&E're redefined"<<G4endl; |
---|
| 96 | #endif |
---|
| 97 | // new particle kinematic |
---|
| 98 | G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); |
---|
| 99 | G4String particleName; |
---|
| 100 | G4ParticleDefinition* particle = particleTable->FindParticle(particleName=part); |
---|
| 101 | particleGun->SetParticleDefinition(particle); |
---|
| 102 | particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.)); |
---|
| 103 | particleGun->SetParticleEnergy(energy*GeV); |
---|
| 104 | oldPart=part; |
---|
| 105 | oldEnergy=energy; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | G4double hY=detector->GetHalfYWidth(); |
---|
| 109 | G4double hZ=detector->GetHalfZThickness(); |
---|
| 110 | if(section==1) // The section #1 is always in the center (comment or change if #ofSec!=3) |
---|
| 111 | { |
---|
| 112 | particleGun->SetParticlePosition(G4ThreeVector(0.,0.,-hZ)); |
---|
| 113 | particleGun->GeneratePrimaryVertex(anEvent); |
---|
| 114 | } |
---|
| 115 | else if(detector->IsSerial()) |
---|
| 116 | { |
---|
| 117 | particleGun->SetParticlePosition(G4ThreeVector(0.,0.,hZ*(section+section-3))); |
---|
| 118 | particleGun->GeneratePrimaryVertex(anEvent); |
---|
| 119 | } |
---|
| 120 | else |
---|
| 121 | { |
---|
| 122 | particleGun->SetParticlePosition(G4ThreeVector(0.,hY*(section+section-2),-hZ)); |
---|
| 123 | particleGun->GeneratePrimaryVertex(anEvent); |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | |
---|