| 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 | // $Id: Sc01PrimaryGeneratorAction.cc,v 1.4 2006/12/13 15:43:44 gunter Exp $
|
|---|
| 27 | // ------------------------------------------------------------
|
|---|
| 28 | // GEANT 4 class header file
|
|---|
| 29 | //
|
|---|
| 30 | // This is a version for maximum particle set
|
|---|
| 31 | // History
|
|---|
| 32 | // first version 09 Sept. 1998 by S.Magni
|
|---|
| 33 | // ------------------------------------------------------------
|
|---|
| 34 |
|
|---|
| 35 | #include "Sc01PrimaryGeneratorAction.hh"
|
|---|
| 36 | #include "Sc01DetectorConstruction.hh"
|
|---|
| 37 |
|
|---|
| 38 | #include "G4Event.hh"
|
|---|
| 39 | #include "G4ParticleGun.hh"
|
|---|
| 40 | #include "G4ParticleTable.hh"
|
|---|
| 41 | #include "G4ParticleDefinition.hh"
|
|---|
| 42 | #include "Randomize.hh"
|
|---|
| 43 | #include "globals.hh"
|
|---|
| 44 |
|
|---|
| 45 | #include <iostream>
|
|---|
| 46 | #include <fstream>
|
|---|
| 47 |
|
|---|
| 48 | Sc01PrimaryGeneratorAction::
|
|---|
| 49 | Sc01PrimaryGeneratorAction(Sc01DetectorConstruction*det)
|
|---|
| 50 | :
|
|---|
| 51 | fDetector(det)
|
|---|
| 52 | {
|
|---|
| 53 | particleGun = new G4ParticleGun();
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | Sc01PrimaryGeneratorAction::~Sc01PrimaryGeneratorAction()
|
|---|
| 57 | {
|
|---|
| 58 | delete particleGun;
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | void Sc01PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
|
|---|
| 62 | {
|
|---|
| 63 |
|
|---|
| 64 | G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
|
|---|
| 65 | G4String particleName;
|
|---|
| 66 | G4ParticleDefinition* aParticleDefinition
|
|---|
| 67 | = particleTable->FindParticle(particleName="opticalphoton");
|
|---|
| 68 |
|
|---|
| 69 | // create a new vertex in a random position
|
|---|
| 70 |
|
|---|
| 71 | // G4ThreeVector VertexPosition (GetRandomPosition());
|
|---|
| 72 | G4ThreeVector VertexPosition (G4ThreeVector(0,0,0));
|
|---|
| 73 | G4PrimaryVertex* aVertex =
|
|---|
| 74 | new G4PrimaryVertex( VertexPosition, 0);
|
|---|
| 75 |
|
|---|
| 76 | // G4int NumberOfParticlesToBeGenerated = 10000;
|
|---|
| 77 | G4int NumberOfParticlesToBeGenerated = 1;
|
|---|
| 78 | // G4cout << " A " << NumberOfParticlesToBeGenerated
|
|---|
| 79 | // << " optical photons vertex has been generated at "
|
|---|
| 80 | // << VertexPosition << G4endl;
|
|---|
| 81 | // create new primaries and set them to the vertex
|
|---|
| 82 | for( int i=0; i<NumberOfParticlesToBeGenerated; i++ )
|
|---|
| 83 | {
|
|---|
| 84 | // G4ThreeVector m = GetRandomDirection();
|
|---|
| 85 | G4ThreeVector m(0.,1.,0.);
|
|---|
| 86 | G4PrimaryParticle* aPrimaryParticle =
|
|---|
| 87 | new G4PrimaryParticle(aParticleDefinition, m.x(), m.y(), m.z());
|
|---|
| 88 | aPrimaryParticle->SetMass (0);
|
|---|
| 89 | G4ThreeVector p = GetRandomPolarization ( m );
|
|---|
| 90 | aPrimaryParticle->SetPolarization(p.x(),p.y(),p.z());
|
|---|
| 91 | aVertex->SetPrimary( aPrimaryParticle );
|
|---|
| 92 | }
|
|---|
| 93 | anEvent->AddPrimaryVertex( aVertex );
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | G4ThreeVector Sc01PrimaryGeneratorAction::GetRandomDirection() {
|
|---|
| 97 |
|
|---|
| 98 | G4ThreeVector retval;
|
|---|
| 99 |
|
|---|
| 100 | G4double CosTheta;
|
|---|
| 101 | G4double SinTheta;
|
|---|
| 102 |
|
|---|
| 103 | G4double Phi;
|
|---|
| 104 | G4double SinPhi;
|
|---|
| 105 | G4double CosPhi;
|
|---|
| 106 |
|
|---|
| 107 | G4double rand;
|
|---|
| 108 |
|
|---|
| 109 | rand = G4UniformRand();
|
|---|
| 110 |
|
|---|
| 111 | CosTheta = 2.0*rand -1.0;
|
|---|
| 112 | SinTheta = std::sqrt (1.-CosTheta*CosTheta);
|
|---|
| 113 | rand = G4UniformRand();
|
|---|
| 114 | Phi = twopi*rand;
|
|---|
| 115 | SinPhi = std::sin (Phi);
|
|---|
| 116 | CosPhi = std::cos (Phi);
|
|---|
| 117 | retval.setX(SinTheta*CosPhi);
|
|---|
| 118 | retval.setY(SinTheta*SinPhi);
|
|---|
| 119 | retval.setZ(CosTheta);
|
|---|
| 120 |
|
|---|
| 121 | return retval;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | G4ThreeVector Sc01PrimaryGeneratorAction::GetRandomPosition()
|
|---|
| 125 | {
|
|---|
| 126 | G4double a = fDetector->GetHallSize();
|
|---|
| 127 |
|
|---|
| 128 | G4double x = ( G4UniformRand()*2 - 1 )*a;
|
|---|
| 129 | G4double y = ( G4UniformRand()*2 - 1 )*a;
|
|---|
| 130 | G4double z = ( G4UniformRand()*2 - 1 )*a;
|
|---|
| 131 |
|
|---|
| 132 | G4ThreeVector retval (x, y, z);
|
|---|
| 133 |
|
|---|
| 134 | return retval;
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | G4ThreeVector Sc01PrimaryGeneratorAction::GetRandomPolarization(G4ThreeVector Direction) {
|
|---|
| 138 | G4ThreeVector Polarization = Direction.orthogonal();
|
|---|
| 139 | G4ThreeVector retval = Polarization.unit();
|
|---|
| 140 | return retval;
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|