| 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: GammaRayTelPrimaryGeneratorAction.cc,v 1.11 2007/11/09 16:33:34 flongo Exp $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-09-03-cand-01 $
|
|---|
| 29 | // ------------------------------------------------------------
|
|---|
| 30 | // GEANT 4 class implementation file
|
|---|
| 31 | // CERN Geneva Switzerland
|
|---|
| 32 | //
|
|---|
| 33 | //
|
|---|
| 34 | // ------------ GammaRayTelPrimaryGeneratorAction ------
|
|---|
| 35 | // by G.Santin, F.Longo & R.Giannitrapani (13 nov 2000)
|
|---|
| 36 | //
|
|---|
| 37 | // ************************************************************
|
|---|
| 38 |
|
|---|
| 39 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 40 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 41 |
|
|---|
| 42 | #include "G4RunManager.hh"
|
|---|
| 43 | #include "GammaRayTelPrimaryGeneratorAction.hh"
|
|---|
| 44 |
|
|---|
| 45 | #include "GammaRayTelDetectorConstruction.hh"
|
|---|
| 46 | #include "GammaRayTelPrimaryGeneratorMessenger.hh"
|
|---|
| 47 |
|
|---|
| 48 | #include "G4Event.hh"
|
|---|
| 49 | #include "G4ParticleGun.hh"
|
|---|
| 50 | #include "G4GeneralParticleSource.hh"
|
|---|
| 51 | #include "G4ParticleTable.hh"
|
|---|
| 52 | #include "G4ParticleDefinition.hh"
|
|---|
| 53 | #include "Randomize.hh"
|
|---|
| 54 |
|
|---|
| 55 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 56 |
|
|---|
| 57 | GammaRayTelPrimaryGeneratorAction::GammaRayTelPrimaryGeneratorAction()
|
|---|
| 58 | :rndmFlag("off"),nSourceType(0),nSpectrumType(0)
|
|---|
| 59 | {
|
|---|
| 60 | G4RunManager* runManager = G4RunManager::GetRunManager();
|
|---|
| 61 | GammaRayTelDetector =
|
|---|
| 62 | (GammaRayTelDetectorConstruction*)(runManager->GetUserDetectorConstruction());
|
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 | //create a messenger for this class
|
|---|
| 66 |
|
|---|
| 67 | gunMessenger = new GammaRayTelPrimaryGeneratorMessenger(this);
|
|---|
| 68 |
|
|---|
| 69 | G4int n_particle = 1;
|
|---|
| 70 |
|
|---|
| 71 | particleGun = new G4ParticleGun(n_particle);
|
|---|
| 72 | // default particle kinematic
|
|---|
| 73 |
|
|---|
| 74 | G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
|
|---|
| 75 | G4String particleName;
|
|---|
| 76 | G4ParticleDefinition* particle
|
|---|
| 77 | = particleTable->FindParticle(particleName="e-");
|
|---|
| 78 | particleGun->SetParticleDefinition(particle);
|
|---|
| 79 | particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,-1.));
|
|---|
| 80 | particleGun->SetParticleEnergy(30.*MeV);
|
|---|
| 81 | G4double position = 0.5*(GammaRayTelDetector->GetWorldSizeZ());
|
|---|
| 82 | particleGun->SetParticlePosition(G4ThreeVector(0.*cm,0.*cm,position));
|
|---|
| 83 | particleSource = new G4GeneralParticleSource();
|
|---|
| 84 |
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 88 |
|
|---|
| 89 | GammaRayTelPrimaryGeneratorAction::~GammaRayTelPrimaryGeneratorAction()
|
|---|
| 90 | {
|
|---|
| 91 | if (sourceGun)
|
|---|
| 92 | delete particleGun;
|
|---|
| 93 | else
|
|---|
| 94 | delete particleSource;
|
|---|
| 95 |
|
|---|
| 96 | delete gunMessenger;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 100 |
|
|---|
| 101 | void GammaRayTelPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
|
|---|
| 102 | {
|
|---|
| 103 | if (sourceGun)
|
|---|
| 104 | {
|
|---|
| 105 |
|
|---|
| 106 | //this function is called at the begining of event
|
|---|
| 107 | //
|
|---|
| 108 | G4double z0 = 0.5*(GammaRayTelDetector->GetWorldSizeZ());
|
|---|
| 109 | G4double x0 = 0.*cm, y0 = 0.*cm;
|
|---|
| 110 |
|
|---|
| 111 | G4ThreeVector pos0;
|
|---|
| 112 | G4ThreeVector dir0;
|
|---|
| 113 | G4ThreeVector vertex0 = G4ThreeVector(x0,y0,z0);
|
|---|
| 114 |
|
|---|
| 115 | dir0 = G4ThreeVector(0.,0.,-1.);
|
|---|
| 116 |
|
|---|
| 117 | G4double theta, phi, y, f;
|
|---|
| 118 | G4double theta0=0.;
|
|---|
| 119 | G4double phi0=0.;
|
|---|
| 120 |
|
|---|
| 121 | switch(nSourceType) {
|
|---|
| 122 | case 0:
|
|---|
| 123 | particleGun->SetParticlePosition(vertex0);
|
|---|
| 124 | particleGun->SetParticleMomentumDirection(dir0);
|
|---|
| 125 | break;
|
|---|
| 126 | case 1:
|
|---|
| 127 | // GS: Generate random position on the 4PIsphere to create a unif. distrib.
|
|---|
| 128 | // GS: on the sphere
|
|---|
| 129 | phi = G4UniformRand() * twopi;
|
|---|
| 130 | do {
|
|---|
| 131 | y = G4UniformRand()*1.0;
|
|---|
| 132 | theta = G4UniformRand() * pi;
|
|---|
| 133 | f = std::sin(theta);
|
|---|
| 134 | } while (y > f);
|
|---|
| 135 | vertex0 = G4ThreeVector(1.,0.,0.);
|
|---|
| 136 | vertex0.setMag(dVertexRadius);
|
|---|
| 137 | vertex0.setTheta(theta);
|
|---|
| 138 | vertex0.setPhi(phi);
|
|---|
| 139 | particleGun->SetParticlePosition(vertex0);
|
|---|
| 140 |
|
|---|
| 141 | dir0 = G4ThreeVector(1.,0.,0.);
|
|---|
| 142 | do {
|
|---|
| 143 | phi = G4UniformRand() * twopi;
|
|---|
| 144 | do {
|
|---|
| 145 | y = G4UniformRand()*1.0;
|
|---|
| 146 | theta = G4UniformRand() * pi;
|
|---|
| 147 | f = std::sin(theta);
|
|---|
| 148 | } while (y > f);
|
|---|
| 149 | dir0.setPhi(phi);
|
|---|
| 150 | dir0.setTheta(theta);
|
|---|
| 151 | } while (vertex0.dot(dir0) >= -0.7 * vertex0.mag());
|
|---|
| 152 | particleGun->SetParticleMomentumDirection((G4ParticleMomentum)dir0);
|
|---|
| 153 |
|
|---|
| 154 | break;
|
|---|
| 155 | case 2:
|
|---|
| 156 | // GS: Generate random position on the upper semi-sphere z>0 to create a unif. distrib.
|
|---|
| 157 | // GS: on a plane
|
|---|
| 158 | phi = G4UniformRand() * twopi;
|
|---|
| 159 | do {
|
|---|
| 160 | y = G4UniformRand()*1.0;
|
|---|
| 161 | theta = G4UniformRand() * halfpi;
|
|---|
| 162 | f = std::sin(theta) * std::cos(theta);
|
|---|
| 163 | } while (y > f);
|
|---|
| 164 | vertex0 = G4ThreeVector(1.,0.,0.);
|
|---|
| 165 |
|
|---|
| 166 | G4double xy = GammaRayTelDetector->GetWorldSizeXY();
|
|---|
| 167 | G4double z = GammaRayTelDetector->GetWorldSizeZ();
|
|---|
| 168 |
|
|---|
| 169 | if (dVertexRadius > xy*0.5)
|
|---|
| 170 | {
|
|---|
| 171 | G4cout << "vertexRadius too big " << G4endl;
|
|---|
| 172 | G4cout << "vertexRadius setted to " << xy*0.45 << G4endl;
|
|---|
| 173 | dVertexRadius = xy*0.45;
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | if (dVertexRadius > z*0.5)
|
|---|
| 177 | {
|
|---|
| 178 | G4cout << "vertexRadius too high " << G4endl;
|
|---|
| 179 | G4cout << "vertexRadius setted to " << z*0.45 << G4endl;
|
|---|
| 180 | dVertexRadius = z*0.45;
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 | vertex0.setMag(dVertexRadius);
|
|---|
| 185 | vertex0.setTheta(theta);
|
|---|
| 186 | vertex0.setPhi(phi);
|
|---|
| 187 |
|
|---|
| 188 | // GS: Get the user defined direction for the primaries and
|
|---|
| 189 | // GS: Rotate the random position according to the user defined direction for the particle
|
|---|
| 190 |
|
|---|
| 191 | dir0 = particleGun->GetParticleMomentumDirection();
|
|---|
| 192 | if (dir0.mag() > 0.001)
|
|---|
| 193 | {
|
|---|
| 194 | theta0 = dir0.theta();
|
|---|
| 195 | phi0 = dir0.phi();
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | if (theta0!=0.)
|
|---|
| 199 | {
|
|---|
| 200 | G4ThreeVector rotationAxis(1.,0.,0.);
|
|---|
| 201 | rotationAxis.setPhi(phi0+halfpi);
|
|---|
| 202 | vertex0.rotate(theta0+pi,rotationAxis);
|
|---|
| 203 | }
|
|---|
| 204 | particleGun->SetParticlePosition(vertex0);
|
|---|
| 205 | break;
|
|---|
| 206 | }
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 | G4double pEnergy;
|
|---|
| 210 |
|
|---|
| 211 | switch(nSpectrumType) {
|
|---|
| 212 | case 0:
|
|---|
| 213 | break;
|
|---|
| 214 | case 1:
|
|---|
| 215 | break;
|
|---|
| 216 | case 2:
|
|---|
| 217 | do {
|
|---|
| 218 | y = G4UniformRand()*100000.0;
|
|---|
| 219 | pEnergy = G4UniformRand() * 10. * GeV;
|
|---|
| 220 | f = std::pow(pEnergy * (1/GeV), -4.);
|
|---|
| 221 | } while (y > f);
|
|---|
| 222 |
|
|---|
| 223 | particleGun->SetParticleEnergy(pEnergy);
|
|---|
| 224 |
|
|---|
| 225 | break;
|
|---|
| 226 | case 3:
|
|---|
| 227 | break;
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | particleGun->GeneratePrimaryVertex(anEvent);
|
|---|
| 231 | }
|
|---|
| 232 | else
|
|---|
| 233 | {
|
|---|
| 234 | particleSource->GeneratePrimaryVertex(anEvent);
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
|
|---|
| 247 |
|
|---|