Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // 23 // >> 24 // $Id: XrayFluoPlanePrimaryGeneratorAction.cc >> 25 // GEANT4 tag $Name: 27 // 26 // 28 // Author: Alfonso Mantero (Alfonso.Mantero@ge 27 // Author: Alfonso Mantero (Alfonso.Mantero@ge.infn.it) 29 // 28 // 30 // History: 29 // History: 31 // ----------- 30 // ----------- 32 // 02 Sep 2003 Alfonso Mantero created 31 // 02 Sep 2003 Alfonso Mantero created 33 // 32 // 34 // ------------------------------------------- 33 // ------------------------------------------------------------------- 35 34 36 #include "XrayFluoPlanePrimaryGeneratorAction. 35 #include "XrayFluoPlanePrimaryGeneratorAction.hh" >> 36 #include "G4DataVector.hh" 37 #include "XrayFluoPlaneDetectorConstruction.hh 37 #include "XrayFluoPlaneDetectorConstruction.hh" 38 #include "XrayFluoPlanePrimaryGeneratorMesseng 38 #include "XrayFluoPlanePrimaryGeneratorMessenger.hh" 39 #include "XrayFluoRunAction.hh" 39 #include "XrayFluoRunAction.hh" 40 #include "XrayFluoAnalysisManager.hh" << 41 #include "XrayFluoDataSet.hh" << 42 #include "G4PhysicalConstants.hh" << 43 #include "G4SystemOfUnits.hh" << 44 #include "G4UnitsTable.hh" << 45 #include "G4DataVector.hh" << 46 #include "G4Event.hh" 40 #include "G4Event.hh" 47 #include "G4ParticleGun.hh" 41 #include "G4ParticleGun.hh" 48 #include "G4ParticleTable.hh" 42 #include "G4ParticleTable.hh" 49 #include "G4ParticleDefinition.hh" 43 #include "G4ParticleDefinition.hh" 50 #include "Randomize.hh" 44 #include "Randomize.hh" >> 45 #include "XrayFluoAnalysisManager.hh" >> 46 #include "XrayFluoDataSet.hh" 51 47 52 //....oooOO0OOooo........oooOO0OOooo........oo 48 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 53 49 54 XrayFluoPlanePrimaryGeneratorAction::XrayFluoP << 50 XrayFluoPlanePrimaryGeneratorAction::XrayFluoPlanePrimaryGeneratorAction(XrayFluoPlaneDetectorConstruction* XrayFluoDC) 55 :rndmFlag("on"),beam("off"),spectrum("off"), 51 :rndmFlag("on"),beam("off"),spectrum("off"),isoVert("off") 56 { 52 { 57 53 58 XrayFluoDetector = XrayFluoDC; 54 XrayFluoDetector = XrayFluoDC; 59 55 60 G4int n_particle = 1; 56 G4int n_particle = 1; 61 particleGun = new G4ParticleGun(n_particle) 57 particleGun = new G4ParticleGun(n_particle); 62 58 63 //create a messenger for this class 59 //create a messenger for this class 64 gunMessenger = new XrayFluoPlanePrimaryGener 60 gunMessenger = new XrayFluoPlanePrimaryGeneratorMessenger(this); 65 runManager = new XrayFluoRunAction(); 61 runManager = new XrayFluoRunAction(); 66 62 67 // default particle kinematic 63 // default particle kinematic 68 64 69 G4ParticleTable* particleTable = G4ParticleT 65 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); 70 G4String particleName; 66 G4String particleName; 71 G4ParticleDefinition* particle 67 G4ParticleDefinition* particle 72 = particleTable->FindParticle(particleName 68 = particleTable->FindParticle(particleName="gamma"); 73 particleGun->SetParticleDefinition(particle) 69 particleGun->SetParticleDefinition(particle); 74 particleGun->SetParticleMomentumDirection(G4 70 particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.)); 75 71 76 72 77 particleGun->SetParticleEnergy(10.*keV); 73 particleGun->SetParticleEnergy(10.*keV); 78 G4double position = -0.5*(XrayFluoDetector-> 74 G4double position = -0.5*(XrayFluoDetector->GetWorldSizeZ()); 79 particleGun->SetParticlePosition(G4ThreeVect 75 particleGun->SetParticlePosition(G4ThreeVector(0.*cm,0.*cm,position)); 80 76 81 G4cout << "XrayFluoPlanePrimaryGeneratorActi 77 G4cout << "XrayFluoPlanePrimaryGeneratorAction created UUUUUUUUUUAAAAAAAAAAAAAAAAAAAAAAAaa" << G4endl; 82 78 83 } 79 } 84 80 85 81 86 //....oooOO0OOooo........oooOO0OOooo........oo 82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 87 83 88 XrayFluoPlanePrimaryGeneratorAction::~XrayFluo 84 XrayFluoPlanePrimaryGeneratorAction::~XrayFluoPlanePrimaryGeneratorAction() 89 { 85 { 90 delete particleGun; 86 delete particleGun; 91 delete gunMessenger; 87 delete gunMessenger; 92 delete runManager; 88 delete runManager; 93 89 94 G4cout << "XrayFluoPlanePrimaryGeneratorActi 90 G4cout << "XrayFluoPlanePrimaryGeneratorAction deleted" << G4endl; 95 91 96 } 92 } 97 93 98 //....oooOO0OOooo........oooOO0OOooo........oo 94 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 99 95 100 void XrayFluoPlanePrimaryGeneratorAction::Gene 96 void XrayFluoPlanePrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) 101 { 97 { 102 //this function is called at the begining of 98 //this function is called at the begining of event 103 // 99 // 104 G4double z0 = -0.5*(XrayFluoDetector->GetWor 100 G4double z0 = -0.5*(XrayFluoDetector->GetWorldSizeZ()); 105 G4double y0 = 0.*m, x0 = 0.*m; 101 G4double y0 = 0.*m, x0 = 0.*m; 106 G4double dX = 0.5*(XrayFluoDetector->GetWorl 102 G4double dX = 0.5*(XrayFluoDetector->GetWorldSizeXY())-(XrayFluoDetector->GetPlaneSizeXY()); 107 if (rndmFlag == "on") 103 if (rndmFlag == "on") 108 104 109 {y0 = (XrayFluoDetector->GetPlaneSizeXY()) 105 {y0 = (XrayFluoDetector->GetPlaneSizeXY())*(G4UniformRand()-0.5); 110 x0 = (XrayFluoDetector->GetPlaneSizeXY())* 106 x0 = (XrayFluoDetector->GetPlaneSizeXY())*(G4UniformRand()-0.5) + dX; 111 } 107 } 112 108 113 z0 = -1 * dX; 109 z0 = -1 * dX; 114 110 115 particleGun->SetParticleMomentumDirection(G4 111 particleGun->SetParticleMomentumDirection(G4ThreeVector(-1.,0.,1.)); 116 112 117 particleGun->SetParticlePosition(G4ThreeVect 113 particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0)); 118 114 119 //randomize starting point 115 //randomize starting point 120 if (beam == "on") 116 if (beam == "on") 121 { 117 { 122 G4double radius = 0.5 * mm; 118 G4double radius = 0.5 * mm; 123 G4double rho = radius*std::sqrt(G4Unifor 119 G4double rho = radius*std::sqrt(G4UniformRand()); 124 G4double theta = 2*pi*G4UniformRand()*ra 120 G4double theta = 2*pi*G4UniformRand()*rad; 125 G4double position = -0.5*(XrayFluoDetect 121 G4double position = -0.5*(XrayFluoDetector->GetWorldSizeZ()); 126 122 127 G4double y = rho * std::sin(theta); 123 G4double y = rho * std::sin(theta); 128 G4double x = rho * std::cos(theta); 124 G4double x = rho * std::cos(theta); 129 125 130 particleGun->SetParticlePosition(G4Three 126 particleGun->SetParticlePosition(G4ThreeVector(x,y,position)); 131 } 127 } 132 //shoot particles according to a certain spe 128 //shoot particles according to a certain spectrum 133 if (spectrum =="on") 129 if (spectrum =="on") 134 { 130 { 135 G4String particle = particleGun->GetPar 131 G4String particle = particleGun->GetParticleDefinition() 136 ->GetParticleName(); 132 ->GetParticleName(); 137 if(particle == "proton"|| particle == "a 133 if(particle == "proton"|| particle == "alpha") 138 { 134 { 139 G4DataVector* energies = runManager->GetE 135 G4DataVector* energies = runManager->GetEnergies(); 140 G4DataVector* data = runManager->GetData( 136 G4DataVector* data = runManager->GetData(); 141 137 142 G4double sum = runManager->GetDataSum(); 138 G4double sum = runManager->GetDataSum(); 143 G4double partSum = 0; 139 G4double partSum = 0; 144 G4int j = 0; 140 G4int j = 0; 145 G4double random= sum*G4UniformRand(); 141 G4double random= sum*G4UniformRand(); 146 while (partSum<random) 142 while (partSum<random) 147 { 143 { 148 partSum += (*data)[j]; 144 partSum += (*data)[j]; 149 j++; 145 j++; 150 } 146 } 151 147 152 particleGun->SetParticleEnergy((*energies) 148 particleGun->SetParticleEnergy((*energies)[j]); 153 149 154 } 150 } 155 else if (particle == "gamma") 151 else if (particle == "gamma") 156 { 152 { 157 const XrayFluoDataSet* dataSet = runManage 153 const XrayFluoDataSet* dataSet = runManager->GetGammaSet(); 158 154 159 G4int i = 0; 155 G4int i = 0; 160 G4int id = 0; 156 G4int id = 0; 161 G4double minEnergy = 0. * keV; 157 G4double minEnergy = 0. * keV; 162 G4double particleEnergy= 0.; 158 G4double particleEnergy= 0.; 163 G4double maxEnergy = 10. * keV; 159 G4double maxEnergy = 10. * keV; 164 G4double energyRange = maxEnergy - minEner 160 G4double energyRange = maxEnergy - minEnergy; 165 161 166 while ( i == 0) 162 while ( i == 0) 167 { 163 { 168 G4double random = G4UniformRand(); 164 G4double random = G4UniformRand(); 169 165 170 G4double randomNum = G4UniformRand(); 166 G4double randomNum = G4UniformRand(); //*5.0E6; 171 167 172 particleEnergy = (random*energyRange) 168 particleEnergy = (random*energyRange) + minEnergy; 173 169 174 if ((dataSet->FindValue(particleEnergy 170 if ((dataSet->FindValue(particleEnergy,id)) > randomNum) 175 { 171 { 176 i = 1; 172 i = 1; 177 173 178 } 174 } 179 } 175 } 180 particleGun->SetParticleEnergy(particleEn 176 particleGun->SetParticleEnergy(particleEnergy); 181 } 177 } 182 } 178 } 183 179 184 if (isoVert == "on") 180 if (isoVert == "on") 185 { 181 { 186 G4double rho = 1. *m; 182 G4double rho = 1. *m; 187 //theta in [0;pi/2] 183 //theta in [0;pi/2] 188 G4double theta = (pi/2)*G4UniformRand(); 184 G4double theta = (pi/2)*G4UniformRand(); 189 //phi in [-pi;pi] 185 //phi in [-pi;pi] 190 G4double phi = (G4UniformRand()*2*pi)- p 186 G4double phi = (G4UniformRand()*2*pi)- pi; 191 G4double x = rho*std::sin(theta)*std::si 187 G4double x = rho*std::sin(theta)*std::sin(phi); 192 G4double y = rho*std::sin(theta)*std::co 188 G4double y = rho*std::sin(theta)*std::cos(phi); 193 G4double z = -(rho*std::cos(theta)); 189 G4double z = -(rho*std::cos(theta)); 194 particleGun->SetParticlePosition(G4Three 190 particleGun->SetParticlePosition(G4ThreeVector(x,y,z)); 195 191 196 G4double Xdim = XrayFluoDetector->GetPla 192 G4double Xdim = XrayFluoDetector->GetPlaneSizeXY(); 197 G4double Ydim = XrayFluoDetector->GetPla 193 G4double Ydim = XrayFluoDetector->GetPlaneSizeXY(); 198 194 199 G4double Dx = Xdim*(G4UniformRand()-0.5) 195 G4double Dx = Xdim*(G4UniformRand()-0.5); 200 196 201 G4double Dy = Ydim*(G4UniformRand()-0.5) 197 G4double Dy = Ydim*(G4UniformRand()-0.5); 202 198 203 particleGun->SetParticleMomentumDirectio 199 particleGun->SetParticleMomentumDirection(G4ThreeVector(-x+Dx,-y+Dy,-z)); 204 200 205 } 201 } 206 #ifdef G4ANALYSIS_USE 202 #ifdef G4ANALYSIS_USE 207 203 208 G4double partEnergy = particleGun->GetPartic 204 G4double partEnergy = particleGun->GetParticleEnergy(); 209 XrayFluoAnalysisManager* analysis = XrayFlu 205 XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance(); 210 analysis->analysePrimaryGenerator(partEnergy 206 analysis->analysePrimaryGenerator(partEnergy/keV); 211 207 212 #endif 208 #endif 213 209 214 particleGun->GeneratePrimaryVertex(anEvent); 210 particleGun->GeneratePrimaryVertex(anEvent); 215 } 211 } 216 212 217 //....oooOO0OOooo........oooOO0OOooo........oo 213 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 218 214 219 215 220 216 221 217 222 218 223 219 224 220 225 221 226 222 227 223