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" >> 42 #include "G4PhysicalConstants.hh" >> 43 #include "G4SystemOfUnits.hh" 40 #include "G4Event.hh" 44 #include "G4Event.hh" 41 #include "G4Gamma.hh" << 42 #include "G4ParticleGun.hh" 45 #include "G4ParticleGun.hh" 43 #include "G4ParticleTable.hh" 46 #include "G4ParticleTable.hh" 44 #include "G4ParticleDefinition.hh" 47 #include "G4ParticleDefinition.hh" 45 #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 #ifdef G4ANALYSIS_USE 50 #include "G4SystemOfUnits.hh" << 52 #include "AIDA/AIDA.h" 51 << 53 #endif 52 //....oooOO0OOooo........oooOO0OOooo........oo 54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 53 55 54 XrayFluoPrimaryGeneratorAction::XrayFluoPrimar << 56 XrayFluoPrimaryGeneratorAction::XrayFluoPrimaryGeneratorAction(XrayFluoDetectorConstruction* XrayFluoDC) 55 XrayFluoDetectorConstruct << 56 :rndmFlag("off"),beam("off"),spectrum("off") 57 :rndmFlag("off"),beam("off"),spectrum("off"),isoVert("off"),phaseSpaceGunFlag(false), 57 rayleighFlag(true), detectorPosition(0) << 58 rayleighFlag(true), particleEnergies(0), particleTypes(0), detectorPosition(0) 58 { 59 { 59 runAction = 0; << 60 60 XrayFluoDetector = XrayFluoDC; 61 XrayFluoDetector = XrayFluoDC; 61 62 62 G4int n_particle = 1; 63 G4int n_particle = 1; 63 particleGun = new G4ParticleGun(n_particle) 64 particleGun = new G4ParticleGun(n_particle); 64 65 65 //create a messenger for this class 66 //create a messenger for this class 66 gunMessenger = new XrayFluoPrimaryGeneratorM << 67 gunMessenger = new XrayFluoPrimaryGeneratorMessenger(this); 67 << 68 runManager = new XrayFluoRunAction(); >> 69 68 // default particle kinematic 70 // default particle kinematic >> 71 >> 72 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); >> 73 G4String particleName; 69 G4ParticleDefinition* particle 74 G4ParticleDefinition* particle 70 = G4Gamma::Definition(); << 75 = particleTable->FindParticle(particleName="gamma"); 71 particleGun->SetParticleDefinition(particle) 76 particleGun->SetParticleDefinition(particle); 72 particleGun->SetParticleMomentumDirection(G4 77 particleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.)); 73 particleGun->SetParticleEnergy(10. * keV); 78 particleGun->SetParticleEnergy(10. * keV); 74 79 75 G4double position = -0.5*(XrayFluoDetector-> 80 G4double position = -0.5*(XrayFluoDetector->GetWorldSizeZ()); 76 particleGun->SetParticlePosition(G4ThreeVect 81 particleGun->SetParticlePosition(G4ThreeVector(0.*cm,0.*cm,position)); 77 82 >> 83 >> 84 78 G4cout << "XrayFluoPrimaryGeneratorAction cr 85 G4cout << "XrayFluoPrimaryGeneratorAction created" << G4endl; 79 86 80 } 87 } 81 88 82 //....oooOO0OOooo........oooOO0OOooo........oo << 83 89 >> 90 #ifdef G4ANALYSIS_USE 84 void XrayFluoPrimaryGeneratorAction::ActivateP 91 void XrayFluoPrimaryGeneratorAction::ActivatePhaseSpace(G4String fileName) { 85 92 86 // load phase-space 93 // load phase-space 87 phaseSpaceGunFlag = true; 94 phaseSpaceGunFlag = true; 88 95 89 // reads the data stored on disk form previo 96 // reads the data stored on disk form previous runs 90 // and get these data to data members 97 // and get these data to data members 91 98 92 XrayFluoAnalysisManager* analysis = XrayFlu 99 XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance(); 93 analysis->LoadGunData(fileName, rayleighFlag 100 analysis->LoadGunData(fileName, rayleighFlag); >> 101 particleEnergies = analysis->GetEmittedParticleEnergies(); >> 102 particleTypes = analysis->GetEmittedParticleTypes(); 94 detectorPosition = XrayFluoDetector->GetDete 103 detectorPosition = XrayFluoDetector->GetDetectorPosition(); 95 detectorPosition.setR(detectorPosition.r()-( 104 detectorPosition.setR(detectorPosition.r()-(5.*cm)); // 5 cm before the detector, so in front of it. >> 105 #else >> 106 void XrayFluoPrimaryGeneratorAction::ActivatePhaseSpace(G4String ) { >> 107 #endif 96 108 97 } 109 } 98 110 99 //....oooOO0OOooo........oooOO0OOooo........oo << 100 111 101 void XrayFluoPrimaryGeneratorAction::SetRaylei 112 void XrayFluoPrimaryGeneratorAction::SetRayleighFlag (G4bool value) 102 { 113 { 103 rayleighFlag = value; << 114 >> 115 G4cout << "value: " << value << G4endl; >> 116 rayleighFlag = value; >> 117 104 } 118 } 105 119 106 120 107 //....oooOO0OOooo........oooOO0OOooo........oo 121 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 108 122 109 XrayFluoPrimaryGeneratorAction::~XrayFluoPrima 123 XrayFluoPrimaryGeneratorAction::~XrayFluoPrimaryGeneratorAction() 110 { 124 { 111 delete particleGun; 125 delete particleGun; 112 delete gunMessenger; 126 delete gunMessenger; >> 127 delete runManager; >> 128 >> 129 G4cout << "XrayFluoPrimaryGeneratorAction deleted" << G4endl; >> 130 113 } 131 } 114 132 115 //....oooOO0OOooo........oooOO0OOooo........oo 133 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 116 134 117 void XrayFluoPrimaryGeneratorAction::GenerateP 135 void XrayFluoPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) 118 { 136 { 119 //retrieve runAction, if not done << 120 if (!runAction) << 121 { << 122 //Sequential runaction << 123 if (G4RunManager::GetRunManager()->GetRu << 124 G4RunManager::sequentialRM) << 125 runAction = static_cast<const XrayFluoRunAct << 126 (G4RunManager::GetRunManager()->GetUserRun << 127 else //MT master runaction << 128 runAction = static_cast<const XrayFluoRunAct << 129 (G4MTRunManager::GetMasterRunManager()->Ge << 130 if (!runAction) << 131 G4cout << "Something wrong here!" << G4endl; << 132 } << 133 << 134 //this function is called at the begining of 137 //this function is called at the begining of event 135 // 138 // 136 G4double z0 = -0.5*(XrayFluoDetector->GetWor 139 G4double z0 = -0.5*(XrayFluoDetector->GetWorldSizeZ()); 137 G4double y0 = 0.*cm, x0 = 0.*cm; 140 G4double y0 = 0.*cm, x0 = 0.*cm; 138 if (rndmFlag == "on") 141 if (rndmFlag == "on") 139 { 142 { 140 y0 = (XrayFluoDetector->GetDia3SizeXY()) 143 y0 = (XrayFluoDetector->GetDia3SizeXY())/std::sqrt(2.)*(G4UniformRand()-0.5); // it was GetSampleSizeXY(), 141 x0 = (XrayFluoDetector->GetDia3SizeXY()) 144 x0 = (XrayFluoDetector->GetDia3SizeXY())/std::sqrt(2.)*(G4UniformRand()-0.5); // not divided by std::sqrt(2.) 142 } 145 } 143 particleGun->SetParticlePosition(G4ThreeVect 146 particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0)); 144 147 145 //randomize starting point 148 //randomize starting point 146 if (beam == "on") 149 if (beam == "on") 147 { 150 { 148 G4double radius = 0.5 * mm; 151 G4double radius = 0.5 * mm; 149 G4double rho = radius*std::sqrt(G4Unifor 152 G4double rho = radius*std::sqrt(G4UniformRand()); 150 G4double theta = 2*pi*G4UniformRand()*ra 153 G4double theta = 2*pi*G4UniformRand()*rad; 151 G4double position = -0.5*(XrayFluoDetect 154 G4double position = -0.5*(XrayFluoDetector->GetWorldSizeZ()); 152 155 153 G4double y = rho * std::sin(theta); 156 G4double y = rho * std::sin(theta); 154 G4double x = rho * std::cos(theta); 157 G4double x = rho * std::cos(theta); 155 158 156 particleGun->SetParticlePosition(G4Three 159 particleGun->SetParticlePosition(G4ThreeVector(x,y,position)); 157 } 160 } 158 //shoot particles according to a certain spe 161 //shoot particles according to a certain spectrum 159 if (spectrum =="on") 162 if (spectrum =="on") 160 { 163 { 161 G4String particle = particleGun->GetPar 164 G4String particle = particleGun->GetParticleDefinition() 162 ->GetParticleName(); 165 ->GetParticleName(); 163 if(particle == "proton"|| particle == "a 166 if(particle == "proton"|| particle == "alpha") 164 { 167 { 165 G4DataVector* energies = runAction->GetEn << 168 G4DataVector* energies = runManager->GetEnergies(); 166 G4DataVector* data = runAction->GetData() << 169 G4DataVector* data = runManager->GetData(); 167 170 168 G4double sum = runAction->GetDataSum(); << 171 G4double sum = runManager->GetDataSum(); 169 G4double partSum = 0; 172 G4double partSum = 0; 170 G4int j = 0; 173 G4int j = 0; 171 G4double random= sum*G4UniformRand(); 174 G4double random= sum*G4UniformRand(); 172 while (partSum<random) 175 while (partSum<random) 173 { 176 { 174 partSum += (*data)[j]; 177 partSum += (*data)[j]; 175 j++; 178 j++; 176 } 179 } 177 180 178 particleGun->SetParticleEnergy((*energies) 181 particleGun->SetParticleEnergy((*energies)[j]); 179 182 180 } 183 } 181 else if (particle == "gamma") 184 else if (particle == "gamma") 182 { 185 { 183 const XrayFluoDataSet* dataSet = runAction << 186 const XrayFluoDataSet* dataSet = runManager->GetGammaSet(); 184 187 185 G4int i = 0; 188 G4int i = 0; 186 G4int id = 0; 189 G4int id = 0; 187 G4double minEnergy = 0. * keV; 190 G4double minEnergy = 0. * keV; 188 G4double particleEnergy= 0.; 191 G4double particleEnergy= 0.; 189 G4double maxEnergy = 10. * keV; 192 G4double maxEnergy = 10. * keV; 190 G4double energyRange = maxEnergy - minEner 193 G4double energyRange = maxEnergy - minEnergy; 191 194 192 while ( i == 0) 195 while ( i == 0) 193 { 196 { 194 G4double random = G4UniformRand(); 197 G4double random = G4UniformRand(); 195 198 196 G4double randomNum = G4UniformRand(); 199 G4double randomNum = G4UniformRand(); //*5.0E6; 197 200 198 particleEnergy = (random*energyRange) 201 particleEnergy = (random*energyRange) + minEnergy; 199 202 200 if ((dataSet->FindValue(particleEnergy 203 if ((dataSet->FindValue(particleEnergy,id)) > randomNum) 201 { 204 { 202 i = 1; 205 i = 1; 203 206 204 } 207 } 205 } 208 } 206 particleGun->SetParticleEnergy(particleEn 209 particleGun->SetParticleEnergy(particleEnergy); 207 } 210 } 208 } 211 } 209 212 210 // Randomize starting point and direction 213 // Randomize starting point and direction 211 214 212 if (isoVert == "on") 215 if (isoVert == "on") 213 { 216 { 214 G4double rho = 1. *m; 217 G4double rho = 1. *m; 215 //theta in [0;pi/2] 218 //theta in [0;pi/2] 216 G4double theta = (pi/2)*G4UniformRand(); 219 G4double theta = (pi/2)*G4UniformRand(); 217 //phi in [-pi;pi] 220 //phi in [-pi;pi] 218 G4double phi = (G4UniformRand()*2*pi)- p 221 G4double phi = (G4UniformRand()*2*pi)- pi; 219 G4double x = rho*std::sin(theta)*std::si 222 G4double x = rho*std::sin(theta)*std::sin(phi); 220 G4double y = rho*std::sin(theta)*std::co 223 G4double y = rho*std::sin(theta)*std::cos(phi); 221 G4double z = -(rho*std::cos(theta)); 224 G4double z = -(rho*std::cos(theta)); 222 particleGun->SetParticlePosition(G4Three 225 particleGun->SetParticlePosition(G4ThreeVector(x,y,z)); 223 226 224 G4double Xdim = XrayFluoDetector->GetSam 227 G4double Xdim = XrayFluoDetector->GetSampleSizeXY(); 225 G4double Ydim = XrayFluoDetector->GetSam 228 G4double Ydim = XrayFluoDetector->GetSampleSizeXY(); 226 229 227 G4double Dx = Xdim*(G4UniformRand()-0.5) 230 G4double Dx = Xdim*(G4UniformRand()-0.5); 228 231 229 G4double Dy = Ydim*(G4UniformRand()-0.5) 232 G4double Dy = Ydim*(G4UniformRand()-0.5); 230 233 231 particleGun->SetParticleMomentumDirectio 234 particleGun->SetParticleMomentumDirection(G4ThreeVector(-x+Dx,-y+Dy,-z)); 232 235 233 } 236 } 234 237 235 // using prevoiously genereated emissions fr 238 // using prevoiously genereated emissions from sample..... 236 239 237 if (phaseSpaceGunFlag){ 240 if (phaseSpaceGunFlag){ 238 241 >> 242 size_t i = anEvent->GetEventID(); >> 243 239 particleGun->SetParticlePosition(detectorP 244 particleGun->SetParticlePosition(detectorPosition); 240 particleGun->SetParticleMomentumDirection( 245 particleGun->SetParticleMomentumDirection(detectorPosition); 241 << 246 G4double energy; 242 G4ParticleTable* particleTable = G4Particl 247 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable(); 243 << 248 G4ParticleDefinition* particle; 244 const std::pair<G4double,G4String> kine = << 249 if (i < particleEnergies->size()) { 245 XrayFluoAnalysisManager::getInstance()-> << 250 energy = (*particleEnergies)[i]; >> 251 particle = particleTable->FindParticle((*particleTypes)[i]); >> 252 } 246 253 247 G4double energy = kine.first; << 254 else { 248 G4ParticleDefinition* particle = particleT << 255 energy = 0.; >> 256 particle = particleTable->FindParticle("gamma"); >> 257 } 249 258 250 particleGun->SetParticleEnergy(energy); 259 particleGun->SetParticleEnergy(energy); 251 particleGun->SetParticleDefinition(particl 260 particleGun->SetParticleDefinition(particle); 252 261 253 262 254 } 263 } 255 264 >> 265 #ifdef G4ANALYSIS_USE >> 266 256 G4double partEnergy = particleGun->GetPartic 267 G4double partEnergy = particleGun->GetParticleEnergy(); 257 XrayFluoAnalysisManager* analysis = XrayFlu 268 XrayFluoAnalysisManager* analysis = XrayFluoAnalysisManager::getInstance(); 258 analysis->analysePrimaryGenerator(partEnergy 269 analysis->analysePrimaryGenerator(partEnergy/keV); 259 270 >> 271 #endif 260 272 261 particleGun->GeneratePrimaryVertex(anEvent); 273 particleGun->GeneratePrimaryVertex(anEvent); 262 } 274 } 263 275 264 //....oooOO0OOooo........oooOO0OOooo........oo 276 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 265 277 266 278 267 279 268 280 269 281 270 282 271 283 272 284 273 285 274 286