[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 | // Rich advanced example for Geant4 |
---|
| 27 | // RichTbAnalysisManager.cc for Rich of LHCb |
---|
| 28 | // History: |
---|
| 29 | // Created: Patricia Mendez (Patricia.Mendez@cern.ch) |
---|
| 30 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 31 | #include "G4Timer.hh" |
---|
| 32 | |
---|
| 33 | #include "RichTbPrimaryGeneratorAction.hh" |
---|
| 34 | |
---|
| 35 | #include "RichTbDetectorConstruction.hh" |
---|
| 36 | #include "RichTbPrimaryGeneratorMessenger.hh" |
---|
| 37 | |
---|
| 38 | #include "G4Event.hh" |
---|
| 39 | #include "G4ParticleGun.hh" |
---|
| 40 | #include "G4ParticleTable.hh" |
---|
| 41 | #include "G4ParticleDefinition.hh" |
---|
| 42 | #include "Randomize.hh" |
---|
| 43 | #include "G4ios.hh" |
---|
| 44 | |
---|
| 45 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 46 | |
---|
| 47 | G4String RichTbPrimaryGeneratorAction::thePrimaryParticleName="proton" ; |
---|
| 48 | |
---|
| 49 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 50 | |
---|
| 51 | RichTbPrimaryGeneratorAction::RichTbPrimaryGeneratorAction( |
---|
| 52 | RichTbDetectorConstruction* RichTbDC) |
---|
| 53 | :RichTbDetector(RichTbDC),rndmFlag("off"),xvertex(0.),yvertex(0.),zvertex(0.), |
---|
| 54 | vertexdefined(false) |
---|
| 55 | { |
---|
| 56 | G4int n_particle = 1; |
---|
| 57 | particleGun = new G4ParticleGun(n_particle); |
---|
| 58 | |
---|
| 59 | //create a messenger for this class |
---|
| 60 | gunMessenger = new RichTbPrimaryGeneratorMessenger(this); |
---|
| 61 | |
---|
| 62 | // default particle kinematic |
---|
| 63 | |
---|
| 64 | G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); |
---|
| 65 | G4String particleName; |
---|
| 66 | G4ParticleDefinition* particle |
---|
| 67 | = particleTable->FindParticle(particleName="proton"); |
---|
| 68 | particleGun->SetParticleDefinition(particle); |
---|
| 69 | |
---|
| 70 | thePrimaryParticleName = particle->GetParticleName() ; |
---|
| 71 | |
---|
| 72 | particleGun->SetParticleMomentumDirection(G4ThreeVector(0.1,0.2,1.)); |
---|
| 73 | particleGun->SetParticleEnergy(100.*GeV); |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | particleGun->SetParticlePosition(G4ThreeVector(xvertex,yvertex,zvertex)); |
---|
| 77 | |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 81 | |
---|
| 82 | RichTbPrimaryGeneratorAction::~RichTbPrimaryGeneratorAction() |
---|
| 83 | { |
---|
| 84 | delete particleGun; |
---|
| 85 | delete gunMessenger; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... |
---|
| 89 | |
---|
| 90 | void RichTbPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) |
---|
| 91 | { |
---|
| 92 | //this function is called at the begining of event |
---|
| 93 | // |
---|
| 94 | thePrimaryParticleName = particleGun->GetParticleDefinition()-> |
---|
| 95 | GetParticleName() ; |
---|
| 96 | G4double x0,y0,z0 ; |
---|
| 97 | |
---|
| 98 | G4double x1,y1,z1 ; |
---|
| 99 | |
---|
| 100 | if(vertexdefined) |
---|
| 101 | { |
---|
| 102 | |
---|
| 103 | x1 = 0. ; |
---|
| 104 | y1 = 0. ; |
---|
| 105 | z1 = 1. ; |
---|
| 106 | |
---|
| 107 | x0 = xvertex ; |
---|
| 108 | y0 = yvertex ; |
---|
| 109 | z0 = zvertex ; |
---|
| 110 | } |
---|
| 111 | else |
---|
| 112 | { |
---|
| 113 | |
---|
| 114 | x1 = 0. ; |
---|
| 115 | y1 = 0. ; |
---|
| 116 | z1 = 1. ; |
---|
| 117 | |
---|
| 118 | x0 = 0. ; |
---|
| 119 | y0 = 0. ; |
---|
| 120 | z0 = 0. ; // -0.5*(RichTbDetector->GetWorldSizeZ()) ; |
---|
| 121 | } |
---|
| 122 | // G4double r0,phi0 ; |
---|
| 123 | |
---|
| 124 | particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0)); |
---|
| 125 | |
---|
| 126 | particleGun->GeneratePrimaryVertex(anEvent); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | /////////////////////////////////////////////////////////////////////// |
---|
| 130 | // |
---|
| 131 | // |
---|
| 132 | |
---|
| 133 | G4String RichTbPrimaryGeneratorAction::GetPrimaryName() |
---|
| 134 | { |
---|
| 135 | return thePrimaryParticleName ; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | void RichTbPrimaryGeneratorAction::Setxvertex(G4double x) |
---|
| 139 | { |
---|
| 140 | vertexdefined = true ; |
---|
| 141 | xvertex = x ; |
---|
| 142 | G4cout << " X coordinate of the primary vertex = " << xvertex/mm << |
---|
| 143 | " mm." << G4endl; |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | void RichTbPrimaryGeneratorAction::Setyvertex(G4double y) |
---|
| 147 | { |
---|
| 148 | vertexdefined = true ; |
---|
| 149 | yvertex = y ; |
---|
| 150 | G4cout << " Y coordinate of the primary vertex = " << yvertex/mm << |
---|
| 151 | " mm." << G4endl; |
---|
| 152 | } |
---|
| 153 | void RichTbPrimaryGeneratorAction::Setzvertex(G4double z) |
---|
| 154 | { |
---|
| 155 | vertexdefined = true ; |
---|
| 156 | zvertex = z ; |
---|
| 157 | G4cout << " Z coordinate of the primary vertex = " << zvertex/mm << |
---|
| 158 | " mm." << G4endl; |
---|
| 159 | } |
---|