[1316] | 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: SCPrimaryGeneratorAction.cc,v 1.8 2006/12/13 15:43:52 gunter Exp $ |
---|
[1347] | 28 | // GEANT4 tag $Name: geant4-09-04-ref-00 $ |
---|
[1316] | 29 | // |
---|
| 30 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 31 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 32 | |
---|
| 33 | #include "Randomize.hh" |
---|
| 34 | |
---|
| 35 | #include "SCPrimaryGeneratorAction.hh" |
---|
| 36 | #include "SCDetectorConstruction.hh" |
---|
| 37 | |
---|
| 38 | #include "SCSurfacePoint.hh" |
---|
| 39 | #include "G4Event.hh" |
---|
| 40 | #include "G4ParticleGun.hh" |
---|
| 41 | #include "G4ParticleTable.hh" |
---|
| 42 | #include "G4ParticleDefinition.hh" |
---|
| 43 | #include "globals.hh" |
---|
| 44 | |
---|
| 45 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 46 | SurfacePoint spoint ; |
---|
| 47 | |
---|
| 48 | SCPrimaryGeneratorAction::SCPrimaryGeneratorAction( |
---|
| 49 | SCDetectorConstruction* myDC) |
---|
| 50 | :myDetector(myDC) |
---|
| 51 | { |
---|
| 52 | G4int n_particle = 1; |
---|
| 53 | particleGun = new G4ParticleGun(n_particle); |
---|
| 54 | |
---|
| 55 | // default particle |
---|
| 56 | |
---|
| 57 | G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); |
---|
| 58 | G4ParticleDefinition* particle = particleTable->FindParticle("geantino"); |
---|
| 59 | |
---|
| 60 | particleGun->SetParticleDefinition(particle); |
---|
| 61 | |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 65 | |
---|
| 66 | SCPrimaryGeneratorAction::~SCPrimaryGeneratorAction() |
---|
| 67 | { |
---|
| 68 | delete particleGun; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 72 | |
---|
| 73 | void SCPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) |
---|
| 74 | { |
---|
| 75 | |
---|
| 76 | G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); |
---|
| 77 | G4String particleName; |
---|
| 78 | G4ParticleDefinition* aParticleDefinition |
---|
| 79 | = particleTable->FindParticle(particleName="geantino"); |
---|
| 80 | |
---|
| 81 | // create a new vertex in a random position |
---|
| 82 | |
---|
| 83 | G4int i = anEvent->GetEventID() ; |
---|
| 84 | |
---|
| 85 | G4ThreeVector VertexPosition (GetRandomPosition()); |
---|
| 86 | G4PrimaryVertex* aVertex = new G4PrimaryVertex( VertexPosition, 0); |
---|
| 87 | |
---|
| 88 | G4double u,v ; |
---|
| 89 | |
---|
| 90 | G4ThreeVector aSurfacePoint (GetSurfacePoint(u,v)) ; // point A on surface |
---|
| 91 | G4ThreeVector aNormal(1,0,0) ; // normal vector |
---|
| 92 | |
---|
| 93 | G4ThreeVector m = (aSurfacePoint-VertexPosition).unit() ; // direction |
---|
| 94 | |
---|
| 95 | G4double distance = ( aSurfacePoint - VertexPosition ).mag() ; |
---|
| 96 | G4double theta = std::acos(m.unit()*aNormal) ; |
---|
| 97 | |
---|
| 98 | spoint.SetSurfacePoint(aSurfacePoint) ; |
---|
| 99 | |
---|
| 100 | G4PrimaryParticle* aPrimaryParticle = |
---|
| 101 | new G4PrimaryParticle(aParticleDefinition, m.x(), m.y(), m.z()); |
---|
| 102 | aPrimaryParticle->SetMass (0.); |
---|
| 103 | |
---|
| 104 | aVertex->SetPrimary( aPrimaryParticle ); |
---|
| 105 | |
---|
| 106 | G4cout << "Event " << i << G4endl |
---|
| 107 | << "Vertex " << VertexPosition << " " << u << " " << v << G4endl |
---|
| 108 | << "Surface " << aSurfacePoint << G4endl |
---|
| 109 | << "Distance " << distance << G4endl |
---|
| 110 | << "Momentum " << m << G4endl |
---|
| 111 | << "Angle " << theta |
---|
| 112 | << G4endl ; |
---|
| 113 | |
---|
| 114 | anEvent->AddPrimaryVertex( aVertex ); |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | G4ThreeVector SCPrimaryGeneratorAction::GetRandomDirection() { |
---|
| 121 | |
---|
| 122 | G4ThreeVector retval; |
---|
| 123 | |
---|
| 124 | G4double CosTheta; |
---|
| 125 | G4double SinTheta; |
---|
| 126 | |
---|
| 127 | G4double Phi; |
---|
| 128 | G4double SinPhi; |
---|
| 129 | G4double CosPhi; |
---|
| 130 | |
---|
| 131 | G4double rand; |
---|
| 132 | |
---|
| 133 | rand = G4UniformRand(); |
---|
| 134 | |
---|
| 135 | CosTheta = 2.0*rand -1.0; |
---|
| 136 | SinTheta = std::sqrt (1.-CosTheta*CosTheta); |
---|
| 137 | rand = G4UniformRand(); |
---|
| 138 | Phi = twopi*rand; |
---|
| 139 | SinPhi = std::sin (Phi); |
---|
| 140 | CosPhi = std::cos (Phi); |
---|
| 141 | retval.setX(SinTheta*CosPhi); |
---|
| 142 | retval.setY(SinTheta*SinPhi); |
---|
| 143 | retval.setZ(CosTheta); |
---|
| 144 | |
---|
| 145 | return retval; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | G4ThreeVector SCPrimaryGeneratorAction::GetRandomPosition() |
---|
| 149 | { |
---|
| 150 | |
---|
| 151 | G4double a = 0.5*myDetector->GetWorldFullLength(); |
---|
| 152 | |
---|
| 153 | G4double x = ( G4UniformRand()*2 - 1 )*a; |
---|
| 154 | G4double y = ( G4UniformRand()*2 - 1 )*a; |
---|
| 155 | G4double z = ( G4UniformRand()*2 - 1 )*a; |
---|
| 156 | |
---|
| 157 | G4ThreeVector retval (x, y, z); |
---|
| 158 | |
---|
| 159 | return retval; |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | G4ThreeVector SCPrimaryGeneratorAction::GetSurfacePoint(G4double &, G4double &) |
---|
| 163 | { |
---|
| 164 | |
---|
| 165 | |
---|
| 166 | G4String val = myDetector->GetDetectorType() ; |
---|
| 167 | |
---|
| 168 | |
---|
| 169 | return myDetector->GetSolid()->GetPointOnSurface() ; |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 175 | |
---|