Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // >> 27 // $Id: XrayFluoPrimaryGeneratorAction.cc >> 28 // GEANT4 tag $Name: xray_fluo-V03-02-00 27 // 29 // 28 // Author: Elena Guardincerri (Elena.Guardince 30 // Author: Elena Guardincerri (Elena.Guardincerri@ge.infn.it) 29 // 31 // 30 // History: 32 // History: 31 // ----------- 33 // ----------- 32 // 28 Nov 2001 Elena Guardincerri Created 34 // 28 Nov 2001 Elena Guardincerri Created 33 // 35 // 34 // ------------------------------------------- 36 // ------------------------------------------------------------------- 35 37 36 #include "XrayFluoPrimaryGeneratorAction.hh" 38 #include "XrayFluoPrimaryGeneratorAction.hh" 37 #include "XrayFluoDetectorConstruction.hh" 39 #include "XrayFluoDetectorConstruction.hh" 38 #include "XrayFluoPrimaryGeneratorMessenger.hh 40 #include "XrayFluoPrimaryGeneratorMessenger.hh" 39 #include "XrayFluoRunAction.hh" 41 #include "XrayFluoRunAction.hh" 40 #include "G4Event.hh" 42 #include "G4Event.hh" 41 #include "G4Gamma.hh" 43 #include "G4Gamma.hh" 42 #include "G4ParticleGun.hh" 44 #include "G4ParticleGun.hh" 43 #include "G4ParticleTable.hh" 45 #include "G4ParticleTable.hh" 44 #include "G4ParticleDefinition.hh" 46 #include "G4ParticleDefinition.hh" 45 #include "G4MTRunManager.hh" 47 #include "G4MTRunManager.hh" 46 #include "Randomize.hh" 48 #include "Randomize.hh" 47 #include "XrayFluoAnalysisManager.hh" 49 #include "XrayFluoAnalysisManager.hh" 48 #include "XrayFluoDataSet.hh" 50 #include "XrayFluoDataSet.hh" 49 #include "G4PhysicalConstants.hh" 51 #include "G4PhysicalConstants.hh" 50 #include "G4SystemOfUnits.hh" 52 #include "G4SystemOfUnits.hh" 51 53 52 //....oooOO0OOooo........oooOO0OOooo........oo 54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 53 55 54 XrayFluoPrimaryGeneratorAction::XrayFluoPrimar 56 XrayFluoPrimaryGeneratorAction::XrayFluoPrimaryGeneratorAction(const 55 XrayFluoDetectorConstruct 57 XrayFluoDetectorConstruction* XrayFluoDC) 56 :rndmFlag("off"),beam("off"),spectrum("off") 58 :rndmFlag("off"),beam("off"),spectrum("off"),isoVert("off"),phaseSpaceGunFlag(false), 57 rayleighFlag(true), detectorPosition(0) 59 rayleighFlag(true), detectorPosition(0) 58 { 60 { 59 runAction = 0; 61 runAction = 0; 60 XrayFluoDetector = XrayFluoDC; 62 XrayFluoDetector = XrayFluoDC; 61 63 62 G4int n_particle = 1; 64 G4int n_particle = 1; 63 particleGun = new G4ParticleGun(n_particle) 65 particleGun = new G4ParticleGun(n_particle); 64 66 65 //create a messenger for this class 67 //create a messenger for this class 66 gunMessenger = new XrayFluoPrimaryGeneratorM 68 gunMessenger = new XrayFluoPrimaryGeneratorMessenger(this); 67 69 68 // default particle kinematic 70 // default particle kinematic 69 G4ParticleDefinition* particle 71 G4ParticleDefinition* particle 70 = G4Gamma::Definition(); 72 = G4Gamma::Definition(); 71 particleGun->SetParticleDefinition(particle) 73 particleGun->SetParticleDefinition(particle); 72 particleGun->SetParticleMomentumDirection(G4 74 particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.)); 73 particleGun->SetParticleEnergy(10. * keV); 75 particleGun->SetParticleEnergy(10. * keV); 74 76 75 G4double position = -0.5*(XrayFluoDetector-> 77 G4double position = -0.5*(XrayFluoDetector->GetWorldSizeZ()); 76 particleGun->SetParticlePosition(G4ThreeVect 78 particleGun->SetParticlePosition(G4ThreeVector(0.*cm,0.*cm,position)); 77 79 78 G4cout << "XrayFluoPrimaryGeneratorAction cr 80 G4cout << "XrayFluoPrimaryGeneratorAction created" << G4endl; 79 81 80 } 82 } 81 83 82 //....oooOO0OOooo........oooOO0OOooo........oo 84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 83 85 84 void XrayFluoPrimaryGeneratorAction::ActivateP 86 void XrayFluoPrimaryGeneratorAction::ActivatePhaseSpace(G4String fileName) { 85 87 86 // load phase-space 88 // load phase-space 87 phaseSpaceGunFlag = true; 89 phaseSpaceGunFlag = true; 88 90 89 // reads the data stored on disk form previo 91 // reads the data stored on disk form previous runs 90 // and get these data to data members 92 // and get these data to data members 91 93 92 XrayFluoAnalysisManager* analysis = XrayFlu 94 XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance(); 93 analysis->LoadGunData(fileName, rayleighFlag 95 analysis->LoadGunData(fileName, rayleighFlag); 94 detectorPosition = XrayFluoDetector->GetDete 96 detectorPosition = XrayFluoDetector->GetDetectorPosition(); 95 detectorPosition.setR(detectorPosition.r()-( 97 detectorPosition.setR(detectorPosition.r()-(5.*cm)); // 5 cm before the detector, so in front of it. 96 98 97 } 99 } 98 100 99 //....oooOO0OOooo........oooOO0OOooo........oo 101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 100 102 101 void XrayFluoPrimaryGeneratorAction::SetRaylei 103 void XrayFluoPrimaryGeneratorAction::SetRayleighFlag (G4bool value) 102 { 104 { 103 rayleighFlag = value; 105 rayleighFlag = value; 104 } 106 } 105 107 106 108 107 //....oooOO0OOooo........oooOO0OOooo........oo 109 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 108 110 109 XrayFluoPrimaryGeneratorAction::~XrayFluoPrima 111 XrayFluoPrimaryGeneratorAction::~XrayFluoPrimaryGeneratorAction() 110 { 112 { 111 delete particleGun; 113 delete particleGun; 112 delete gunMessenger; 114 delete gunMessenger; 113 } 115 } 114 116 115 //....oooOO0OOooo........oooOO0OOooo........oo 117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 116 118 117 void XrayFluoPrimaryGeneratorAction::GenerateP 119 void XrayFluoPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) 118 { 120 { 119 //retrieve runAction, if not done 121 //retrieve runAction, if not done 120 if (!runAction) 122 if (!runAction) 121 { 123 { 122 //Sequential runaction 124 //Sequential runaction 123 if (G4RunManager::GetRunManager()->GetRu 125 if (G4RunManager::GetRunManager()->GetRunManagerType() == 124 G4RunManager::sequentialRM) 126 G4RunManager::sequentialRM) 125 runAction = static_cast<const XrayFluoRunAct 127 runAction = static_cast<const XrayFluoRunAction*> 126 (G4RunManager::GetRunManager()->GetUserRun 128 (G4RunManager::GetRunManager()->GetUserRunAction()); 127 else //MT master runaction 129 else //MT master runaction 128 runAction = static_cast<const XrayFluoRunAct 130 runAction = static_cast<const XrayFluoRunAction*> 129 (G4MTRunManager::GetMasterRunManager()->Ge 131 (G4MTRunManager::GetMasterRunManager()->GetUserRunAction()); 130 if (!runAction) 132 if (!runAction) 131 G4cout << "Something wrong here!" << G4endl; 133 G4cout << "Something wrong here!" << G4endl; 132 } 134 } 133 135 134 //this function is called at the begining of 136 //this function is called at the begining of event 135 // 137 // 136 G4double z0 = -0.5*(XrayFluoDetector->GetWor 138 G4double z0 = -0.5*(XrayFluoDetector->GetWorldSizeZ()); 137 G4double y0 = 0.*cm, x0 = 0.*cm; 139 G4double y0 = 0.*cm, x0 = 0.*cm; 138 if (rndmFlag == "on") 140 if (rndmFlag == "on") 139 { 141 { 140 y0 = (XrayFluoDetector->GetDia3SizeXY()) 142 y0 = (XrayFluoDetector->GetDia3SizeXY())/std::sqrt(2.)*(G4UniformRand()-0.5); // it was GetSampleSizeXY(), 141 x0 = (XrayFluoDetector->GetDia3SizeXY()) 143 x0 = (XrayFluoDetector->GetDia3SizeXY())/std::sqrt(2.)*(G4UniformRand()-0.5); // not divided by std::sqrt(2.) 142 } 144 } 143 particleGun->SetParticlePosition(G4ThreeVect 145 particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0)); 144 146 145 //randomize starting point 147 //randomize starting point 146 if (beam == "on") 148 if (beam == "on") 147 { 149 { 148 G4double radius = 0.5 * mm; 150 G4double radius = 0.5 * mm; 149 G4double rho = radius*std::sqrt(G4Unifor 151 G4double rho = radius*std::sqrt(G4UniformRand()); 150 G4double theta = 2*pi*G4UniformRand()*ra 152 G4double theta = 2*pi*G4UniformRand()*rad; 151 G4double position = -0.5*(XrayFluoDetect 153 G4double position = -0.5*(XrayFluoDetector->GetWorldSizeZ()); 152 154 153 G4double y = rho * std::sin(theta); 155 G4double y = rho * std::sin(theta); 154 G4double x = rho * std::cos(theta); 156 G4double x = rho * std::cos(theta); 155 157 156 particleGun->SetParticlePosition(G4Three 158 particleGun->SetParticlePosition(G4ThreeVector(x,y,position)); 157 } 159 } 158 //shoot particles according to a certain spe 160 //shoot particles according to a certain spectrum 159 if (spectrum =="on") 161 if (spectrum =="on") 160 { 162 { 161 G4String particle = particleGun->GetPar 163 G4String particle = particleGun->GetParticleDefinition() 162 ->GetParticleName(); 164 ->GetParticleName(); 163 if(particle == "proton"|| particle == "a 165 if(particle == "proton"|| particle == "alpha") 164 { 166 { 165 G4DataVector* energies = runAction->GetEn 167 G4DataVector* energies = runAction->GetEnergies(); 166 G4DataVector* data = runAction->GetData() 168 G4DataVector* data = runAction->GetData(); 167 169 168 G4double sum = runAction->GetDataSum(); 170 G4double sum = runAction->GetDataSum(); 169 G4double partSum = 0; 171 G4double partSum = 0; 170 G4int j = 0; 172 G4int j = 0; 171 G4double random= sum*G4UniformRand(); 173 G4double random= sum*G4UniformRand(); 172 while (partSum<random) 174 while (partSum<random) 173 { 175 { 174 partSum += (*data)[j]; 176 partSum += (*data)[j]; 175 j++; 177 j++; 176 } 178 } 177 179 178 particleGun->SetParticleEnergy((*energies) 180 particleGun->SetParticleEnergy((*energies)[j]); 179 181 180 } 182 } 181 else if (particle == "gamma") 183 else if (particle == "gamma") 182 { 184 { 183 const XrayFluoDataSet* dataSet = runAction 185 const XrayFluoDataSet* dataSet = runAction->GetGammaSet(); 184 186 185 G4int i = 0; 187 G4int i = 0; 186 G4int id = 0; 188 G4int id = 0; 187 G4double minEnergy = 0. * keV; 189 G4double minEnergy = 0. * keV; 188 G4double particleEnergy= 0.; 190 G4double particleEnergy= 0.; 189 G4double maxEnergy = 10. * keV; 191 G4double maxEnergy = 10. * keV; 190 G4double energyRange = maxEnergy - minEner 192 G4double energyRange = maxEnergy - minEnergy; 191 193 192 while ( i == 0) 194 while ( i == 0) 193 { 195 { 194 G4double random = G4UniformRand(); 196 G4double random = G4UniformRand(); 195 197 196 G4double randomNum = G4UniformRand(); 198 G4double randomNum = G4UniformRand(); //*5.0E6; 197 199 198 particleEnergy = (random*energyRange) 200 particleEnergy = (random*energyRange) + minEnergy; 199 201 200 if ((dataSet->FindValue(particleEnergy 202 if ((dataSet->FindValue(particleEnergy,id)) > randomNum) 201 { 203 { 202 i = 1; 204 i = 1; 203 205 204 } 206 } 205 } 207 } 206 particleGun->SetParticleEnergy(particleEn 208 particleGun->SetParticleEnergy(particleEnergy); 207 } 209 } 208 } 210 } 209 211 210 // Randomize starting point and direction 212 // Randomize starting point and direction 211 213 212 if (isoVert == "on") 214 if (isoVert == "on") 213 { 215 { 214 G4double rho = 1. *m; 216 G4double rho = 1. *m; 215 //theta in [0;pi/2] 217 //theta in [0;pi/2] 216 G4double theta = (pi/2)*G4UniformRand(); 218 G4double theta = (pi/2)*G4UniformRand(); 217 //phi in [-pi;pi] 219 //phi in [-pi;pi] 218 G4double phi = (G4UniformRand()*2*pi)- p 220 G4double phi = (G4UniformRand()*2*pi)- pi; 219 G4double x = rho*std::sin(theta)*std::si 221 G4double x = rho*std::sin(theta)*std::sin(phi); 220 G4double y = rho*std::sin(theta)*std::co 222 G4double y = rho*std::sin(theta)*std::cos(phi); 221 G4double z = -(rho*std::cos(theta)); 223 G4double z = -(rho*std::cos(theta)); 222 particleGun->SetParticlePosition(G4Three 224 particleGun->SetParticlePosition(G4ThreeVector(x,y,z)); 223 225 224 G4double Xdim = XrayFluoDetector->GetSam 226 G4double Xdim = XrayFluoDetector->GetSampleSizeXY(); 225 G4double Ydim = XrayFluoDetector->GetSam 227 G4double Ydim = XrayFluoDetector->GetSampleSizeXY(); 226 228 227 G4double Dx = Xdim*(G4UniformRand()-0.5) 229 G4double Dx = Xdim*(G4UniformRand()-0.5); 228 230 229 G4double Dy = Ydim*(G4UniformRand()-0.5) 231 G4double Dy = Ydim*(G4UniformRand()-0.5); 230 232 231 particleGun->SetParticleMomentumDirectio 233 particleGun->SetParticleMomentumDirection(G4ThreeVector(-x+Dx,-y+Dy,-z)); 232 234 233 } 235 } 234 236 235 // using prevoiously genereated emissions fr 237 // using prevoiously genereated emissions from sample..... 236 238 237 if (phaseSpaceGunFlag){ 239 if (phaseSpaceGunFlag){ 238 240 239 particleGun->SetParticlePosition(detectorP 241 particleGun->SetParticlePosition(detectorPosition); 240 particleGun->SetParticleMomentumDirection( 242 particleGun->SetParticleMomentumDirection(detectorPosition); 241 243 242 G4ParticleTable* particleTable = G4Particl 244 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); 243 245 244 const std::pair<G4double,G4String> kine = 246 const std::pair<G4double,G4String> kine = 245 XrayFluoAnalysisManager::getInstance()-> 247 XrayFluoAnalysisManager::getInstance()->GetEmittedParticleEnergyAndType(); 246 248 247 G4double energy = kine.first; 249 G4double energy = kine.first; 248 G4ParticleDefinition* particle = particleT 250 G4ParticleDefinition* particle = particleTable->FindParticle(kine.second); 249 251 250 particleGun->SetParticleEnergy(energy); 252 particleGun->SetParticleEnergy(energy); 251 particleGun->SetParticleDefinition(particl 253 particleGun->SetParticleDefinition(particle); 252 254 253 255 254 } 256 } 255 257 256 G4double partEnergy = particleGun->GetPartic 258 G4double partEnergy = particleGun->GetParticleEnergy(); 257 XrayFluoAnalysisManager* analysis = XrayFlu 259 XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance(); 258 analysis->analysePrimaryGenerator(partEnergy 260 analysis->analysePrimaryGenerator(partEnergy/keV); 259 261 260 262 261 particleGun->GeneratePrimaryVertex(anEvent); 263 particleGun->GeneratePrimaryVertex(anEvent); 262 } 264 } 263 265 264 //....oooOO0OOooo........oooOO0OOooo........oo 266 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 265 267 266 268 267 269 268 270 269 271 270 272 271 273 272 274 273 275 274 276