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: G4OpRayleigh.cc,v 1.13 2005/07/28 22:28:37 gum Exp $ >> 25 // GEANT4 tag $Name: geant4-08-00-patch-01 $ 27 // 26 // 28 // << 27 // 29 ////////////////////////////////////////////// 28 //////////////////////////////////////////////////////////////////////// 30 // Optical Photon Rayleigh Scattering Class Im 29 // Optical Photon Rayleigh Scattering Class Implementation 31 ////////////////////////////////////////////// 30 //////////////////////////////////////////////////////////////////////// 32 // 31 // 33 // File: G4OpRayleigh.cc << 32 // File: G4OpRayleigh.cc 34 // Description: Discrete Process -- Rayleigh s << 33 // Description: Discrete Process -- Rayleigh scattering of optical 35 // photons << 34 // photons 36 // Version: 1.0 35 // Version: 1.0 37 // Created: 1996-05-31 << 36 // Created: 1996-05-31 38 // Author: Juliet Armstrong 37 // Author: Juliet Armstrong 39 // Updated: 2014-10-10 - This version cal << 38 // Updated: 2005-07-28 - add G4ProcessType to constructor 40 // length for more materials than << 41 // default is kept). To do this t << 42 // ISOTHERMAL_COMPRESSIBILITY as << 43 // optionally an RS_SCALE_LENGTH << 44 // from Philip Graham (Queen Mary << 45 // 2010-06-11 - Fix Bug 207; Than << 46 // (Kellogg Radiation Lab of Calt << 47 // 2005-07-28 - add G4ProcessType << 48 // 2001-10-18 by Peter Gumplinger 39 // 2001-10-18 by Peter Gumplinger 49 // eliminate unused variable warn 40 // eliminate unused variable warning on Linux (gcc-2.95.2) 50 // 2001-09-18 by mma 41 // 2001-09-18 by mma 51 // >numOfMaterials=G4Material::Ge << 42 // >numOfMaterials=G4Material::GetNumberOfMaterials() in BuildPhy 52 // 2001-01-30 by Peter Gumplinger 43 // 2001-01-30 by Peter Gumplinger 53 // > allow for positiv and negati 44 // > allow for positiv and negative CosTheta and force the 54 // > new momentum direction to be 45 // > new momentum direction to be in the same plane as the 55 // > new and old polarization vec 46 // > new and old polarization vectors 56 // 2001-01-29 by Peter Gumplinger 47 // 2001-01-29 by Peter Gumplinger 57 // > fix calculation of SinTheta 48 // > fix calculation of SinTheta (from CosTheta) 58 // 1997-04-09 by Peter Gumplinger 49 // 1997-04-09 by Peter Gumplinger 59 // > new physics/tracking scheme 50 // > new physics/tracking scheme >> 51 // mail: gum@triumf.ca 60 // 52 // 61 ////////////////////////////////////////////// 53 //////////////////////////////////////////////////////////////////////// 62 54 63 #include "G4OpRayleigh.hh" << 64 #include "G4ios.hh" 55 #include "G4ios.hh" 65 #include "G4PhysicalConstants.hh" << 56 #include "G4OpRayleigh.hh" 66 #include "G4SystemOfUnits.hh" << 57 67 #include "G4OpticalParameters.hh" << 58 ///////////////////////// 68 #include "G4OpProcessSubType.hh" << 59 // Class Implementation >> 60 ///////////////////////// >> 61 >> 62 ////////////// >> 63 // Operators >> 64 ////////////// >> 65 >> 66 // G4OpRayleigh::operator=(const G4OpRayleigh &right) >> 67 // { >> 68 // } >> 69 >> 70 ///////////////// >> 71 // Constructors >> 72 ///////////////// 69 73 70 //....oooOO0OOooo........oooOO0OOooo........oo << 71 G4OpRayleigh::G4OpRayleigh(const G4String& pro 74 G4OpRayleigh::G4OpRayleigh(const G4String& processName, G4ProcessType type) 72 : G4VDiscreteProcess(processName, type) << 75 : G4VDiscreteProcess(processName, type) 73 { 76 { 74 Initialise(); << 77 75 SetProcessSubType(fOpRayleigh); << 78 thePhysicsTable = 0; 76 thePhysicsTable = nullptr; << 79 77 << 80 DefaultWater = false; 78 if(verboseLevel > 0) << 81 79 { << 82 if (verboseLevel>0) { 80 G4cout << GetProcessName() << " is created << 83 G4cout << GetProcessName() << " is created " << G4endl; 81 } << 84 } >> 85 >> 86 BuildThePhysicsTable(); 82 } 87 } 83 88 84 //....oooOO0OOooo........oooOO0OOooo........oo << 89 // G4OpRayleigh::G4OpRayleigh(const G4OpRayleigh &right) >> 90 // { >> 91 // } >> 92 >> 93 //////////////// >> 94 // Destructors >> 95 //////////////// >> 96 85 G4OpRayleigh::~G4OpRayleigh() 97 G4OpRayleigh::~G4OpRayleigh() 86 { 98 { 87 // VI: inside this PhysicsTable all properti << 99 if (thePhysicsTable!= 0) { 88 // it is not possible to destroy << 100 thePhysicsTable->clearAndDestroy(); 89 delete thePhysicsTable; << 101 delete thePhysicsTable; >> 102 } 90 } 103 } 91 104 92 //....oooOO0OOooo........oooOO0OOooo........oo << 105 //////////// 93 void G4OpRayleigh::PreparePhysicsTable(const G << 106 // Methods 94 { << 107 //////////// 95 Initialise(); << 96 } << 97 108 98 //....oooOO0OOooo........oooOO0OOooo........oo << 109 // PostStepDoIt 99 void G4OpRayleigh::Initialise() << 110 // ------------- >> 111 // >> 112 G4VParticleChange* >> 113 G4OpRayleigh::PostStepDoIt(const G4Track& aTrack, const G4Step& aStep) 100 { 114 { 101 SetVerboseLevel(G4OpticalParameters::Instanc << 115 aParticleChange.Initialize(aTrack); 102 } << 103 116 104 //....oooOO0OOooo........oooOO0OOooo........oo << 117 const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle(); 105 G4VParticleChange* G4OpRayleigh::PostStepDoIt( << 106 << 107 { << 108 aParticleChange.Initialize(aTrack); << 109 const G4DynamicParticle* aParticle = aTrack. << 110 118 111 if(verboseLevel > 1) << 119 if (verboseLevel>0) { 112 { << 120 G4cout << "Scattering Photon!" << G4endl; 113 G4cout << "OpRayleigh: Scattering Photon!" << 121 G4cout << "Old Momentum Direction: " 114 << "Old Momentum Direction: " << aP << 122 << aParticle->GetMomentumDirection() << G4endl; 115 << G4endl << "Old Polarization: " < << 123 G4cout << "Old Polarization: " 116 << G4endl; << 124 << aParticle->GetPolarization() << G4endl; 117 } << 125 } 118 << 119 G4double cosTheta; << 120 G4ThreeVector oldMomDir, newMomDir; << 121 G4ThreeVector oldPol, newPol; << 122 G4double rand; << 123 G4double cost, sint, sinphi, cosphi; << 124 << 125 do << 126 { << 127 // Try to simulate the scattered photon mo << 128 // w.r.t. the initial photon momentum dire << 129 cost = G4UniformRand(); << 130 sint = std::sqrt(1. - cost * cost); << 131 // consider for the angle 90-180 degrees << 132 if(G4UniformRand() < 0.5) << 133 cost = -cost; << 134 << 135 // simulate the phi angle << 136 rand = twopi * G4UniformRand(); << 137 sinphi = std::sin(rand); << 138 cosphi = std::cos(rand); << 139 << 140 // construct the new momentum direction << 141 newMomDir.set(sint * cosphi, sint * sinphi << 142 oldMomDir = aParticle->GetMomentumDirectio << 143 newMomDir.rotateUz(oldMomDir); << 144 << 145 // calculate the new polarization directio << 146 // The new polarization needs to be in the << 147 // momentum direction and the old polariza << 148 oldPol = aParticle->GetPolarization(); << 149 newPol = (oldPol - newMomDir.dot(oldPol) * << 150 << 151 // There is a corner case, where the new m << 152 // is the same as old polarization directi << 153 // random generate the azimuthal angle w.r << 154 if(newPol.mag() == 0.) << 155 { << 156 rand = G4UniformRand() * twopi; << 157 newPol.set(std::cos(rand), std::sin(rand << 158 newPol.rotateUz(newMomDir); << 159 } << 160 else << 161 { << 162 // There are two directions perpendicula << 163 if(G4UniformRand() < 0.5) << 164 newPol = -newPol; << 165 } << 166 << 167 // simulate according to the distribution << 168 cosTheta = newPol.dot(oldPol); << 169 // Loop checking, 13-Aug-2015, Peter Gumpl << 170 } while(std::pow(cosTheta, 2) < G4UniformRan << 171 << 172 aParticleChange.ProposePolarization(newPol); << 173 aParticleChange.ProposeMomentumDirection(new << 174 << 175 if(verboseLevel > 1) << 176 { << 177 G4cout << "New Polarization: " << newPol < << 178 << "Polarization Change: " << *(aPa << 179 << G4endl << "New Momentum Directio << 180 << "Momentum Change: " << *(aPartic << 181 << G4endl; << 182 } << 183 126 184 return G4VDiscreteProcess::PostStepDoIt(aTra << 127 // find polar angle w.r.t. old polarization vector 185 } << 186 128 187 //....oooOO0OOooo........oooOO0OOooo........oo << 129 G4double rand = G4UniformRand(); 188 void G4OpRayleigh::BuildPhysicsTable(const G4P << 130 189 { << 131 G4double CosTheta = std::pow(rand, 1./3.); 190 if(thePhysicsTable) << 132 G4double SinTheta = std::sqrt(1.-CosTheta*CosTheta); 191 { << 133 192 // thePhysicsTable->clearAndDestroy(); << 134 if(G4UniformRand() < 0.5)CosTheta = -CosTheta; 193 delete thePhysicsTable; << 135 194 thePhysicsTable = nullptr; << 136 // find azimuthal angle w.r.t old polarization vector 195 } << 137 196 << 138 rand = G4UniformRand(); 197 const G4MaterialTable* theMaterialTable = G4 << 139 198 const size_t numOfMaterials = G4 << 140 G4double Phi = twopi*rand; 199 thePhysicsTable = ne << 141 G4double SinPhi = std::sin(Phi); 200 << 142 G4double CosPhi = std::cos(Phi); 201 for(size_t i = 0; i < numOfMaterials; ++i) << 143 202 { << 144 G4double unit_x = SinTheta * CosPhi; 203 G4Material* material = (*the << 145 G4double unit_y = SinTheta * SinPhi; 204 G4MaterialPropertiesTable* matProp = mater << 146 G4double unit_z = CosTheta; 205 G4PhysicsFreeVector* rayleigh = nullptr; << 147 206 if(matProp) << 148 G4ThreeVector NewPolarization (unit_x,unit_y,unit_z); 207 { << 149 208 rayleigh = matProp->GetProperty(kRAYLEIG << 150 // Rotate new polarization direction into global reference system 209 if(rayleigh == nullptr) << 151 210 rayleigh = CalculateRayleighMeanFreePa << 152 G4ThreeVector OldPolarization = aParticle->GetPolarization(); 211 } << 153 OldPolarization = OldPolarization.unit(); 212 thePhysicsTable->insertAt(i, rayleigh); << 154 213 } << 155 NewPolarization.rotateUz(OldPolarization); >> 156 NewPolarization = NewPolarization.unit(); >> 157 >> 158 // -- new momentum direction is normal to the new >> 159 // polarization vector and in the same plane as the >> 160 // old and new polarization vectors -- >> 161 >> 162 G4ThreeVector NewMomentumDirection = >> 163 OldPolarization - NewPolarization * CosTheta; >> 164 >> 165 if(G4UniformRand() < 0.5)NewMomentumDirection = -NewMomentumDirection; >> 166 NewMomentumDirection = NewMomentumDirection.unit(); >> 167 >> 168 aParticleChange.ProposePolarization(NewPolarization); >> 169 >> 170 aParticleChange.ProposeMomentumDirection(NewMomentumDirection); >> 171 >> 172 if (verboseLevel>0) { >> 173 G4cout << "New Polarization: " >> 174 << NewPolarization << G4endl; >> 175 G4cout << "Polarization Change: " >> 176 << *(aParticleChange.GetPolarization()) << G4endl; >> 177 G4cout << "New Momentum Direction: " >> 178 << NewMomentumDirection << G4endl; >> 179 G4cout << "Momentum Change: " >> 180 << *(aParticleChange.GetMomentumDirection()) << G4endl; >> 181 } >> 182 >> 183 return G4VDiscreteProcess::PostStepDoIt(aTrack, aStep); 214 } 184 } 215 185 216 //....oooOO0OOooo........oooOO0OOooo........oo << 186 // BuildThePhysicsTable for the Rayleigh Scattering process 217 G4double G4OpRayleigh::GetMeanFreePath(const G << 187 // -------------------------------------------------------- 218 G4Force << 188 // >> 189 void G4OpRayleigh::BuildThePhysicsTable() 219 { 190 { 220 auto rayleigh = static_cast<G4PhysicsFreeVec << 191 // Builds a table of scattering lengths for each material 221 (*thePhysicsTable)(aTrack.GetMaterial()- << 192 >> 193 if (thePhysicsTable) return; >> 194 >> 195 const G4MaterialTable* theMaterialTable= >> 196 G4Material::GetMaterialTable(); >> 197 G4int numOfMaterials = G4Material::GetNumberOfMaterials(); 222 198 223 G4double rsLength = DBL_MAX; << 199 // create a new physics table 224 if(rayleigh) << 200 225 { << 201 thePhysicsTable = new G4PhysicsTable(numOfMaterials); 226 rsLength = rayleigh->Value(aTrack.GetDynam << 202 227 idx_rslength); << 203 // loop for materials 228 } << 204 229 return rsLength; << 205 for (G4int i=0 ; i < numOfMaterials; i++) >> 206 { >> 207 G4PhysicsOrderedFreeVector* ScatteringLengths = >> 208 new G4PhysicsOrderedFreeVector(); >> 209 >> 210 G4MaterialPropertiesTable *aMaterialPropertiesTable = >> 211 (*theMaterialTable)[i]->GetMaterialPropertiesTable(); >> 212 >> 213 if(aMaterialPropertiesTable){ >> 214 >> 215 G4MaterialPropertyVector* AttenuationLengthVector = >> 216 aMaterialPropertiesTable->GetProperty("RAYLEIGH"); >> 217 >> 218 if(!AttenuationLengthVector){ >> 219 >> 220 if ((*theMaterialTable)[i]->GetName() == "Water") >> 221 { >> 222 // Call utility routine to Generate >> 223 // Rayleigh Scattering Lengths >> 224 >> 225 DefaultWater = true; >> 226 >> 227 ScatteringLengths = >> 228 RayleighAttenuationLengthGenerator(aMaterialPropertiesTable); >> 229 } >> 230 } >> 231 } >> 232 >> 233 thePhysicsTable->insertAt(i,ScatteringLengths); >> 234 } 230 } 235 } 231 236 232 //....oooOO0OOooo........oooOO0OOooo........oo << 237 // GetMeanFreePath() 233 G4PhysicsFreeVector* G4OpRayleigh::CalculateRa << 238 // ----------------- 234 const G4Material* material) const << 239 // >> 240 G4double G4OpRayleigh::GetMeanFreePath(const G4Track& aTrack, >> 241 G4double , >> 242 G4ForceCondition* ) 235 { 243 { 236 G4MaterialPropertiesTable* MPT = material->G << 244 const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle(); >> 245 const G4Material* aMaterial = aTrack.GetMaterial(); >> 246 >> 247 G4double thePhotonMomentum = aParticle->GetTotalMomentum(); 237 248 238 // Retrieve the beta_T or isothermal compres << 249 G4double AttenuationLength = DBL_MAX; 239 // compatibility use a constant if the mater << 240 // doesn't have an ISOTHERMAL_COMPRESSIBILIT << 241 G4double betat; << 242 if(material->GetName() == "Water") << 243 { << 244 betat = 7.658e-23 * m3 / MeV; << 245 } << 246 else if(MPT->ConstPropertyExists(kISOTHERMAL << 247 { << 248 betat = MPT->GetConstProperty(kISOTHERMAL_ << 249 } << 250 else << 251 { << 252 return nullptr; << 253 } << 254 << 255 // If the material doesn't have a RINDEX pro << 256 G4MaterialPropertyVector* rIndex = MPT->GetP << 257 if(rIndex == nullptr) << 258 return nullptr; << 259 << 260 // Retrieve the optional scale factor (scale << 261 G4double scaleFactor = 1.0; << 262 if(MPT->ConstPropertyExists(kRS_SCALE_FACTOR << 263 { << 264 scaleFactor = MPT->GetConstProperty(kRS_SC << 265 } << 266 << 267 // Retrieve the material temperature. For ba << 268 // constant if the material is "Water" << 269 G4double temperature; << 270 if(material->GetName() == "Water") << 271 { << 272 temperature = << 273 283.15 * kelvin; // Temperature of wate << 274 } << 275 else << 276 { << 277 temperature = material->GetTemperature(); << 278 } << 279 << 280 auto rayleighMFPs = new G4PhysicsFreeVector( << 281 // This calculates the meanFreePath via the << 282 const G4double c1 = << 283 scaleFactor * betat * temperature * k_Bolt << 284 << 285 for(size_t uRIndex = 0; uRIndex < rIndex->Ge << 286 { << 287 const G4double energy = rIndex->Ene << 288 const G4double rIndexSquared = (*rIndex)[u << 289 const G4double xlambda = h_Planck * << 290 const G4double c2 = std::pow(tw << 291 const G4double c3 = << 292 std::pow(((rIndexSquared - 1.0) * (rInde << 293 << 294 const G4double meanFreePath = 1.0 / (c1 * << 295 << 296 if(verboseLevel > 0) << 297 { << 298 G4cout << energy << "MeV\t" << meanFreeP << 299 } << 300 250 301 rayleighMFPs->InsertValues(energy, meanFre << 251 if (aMaterial->GetName() == "Water" && DefaultWater){ 302 } << 303 252 304 return rayleighMFPs; << 253 G4bool isOutRange; >> 254 >> 255 AttenuationLength = >> 256 (*thePhysicsTable)(aMaterial->GetIndex())-> >> 257 GetValue(thePhotonMomentum, isOutRange); >> 258 } >> 259 else { >> 260 >> 261 G4MaterialPropertiesTable* aMaterialPropertyTable = >> 262 aMaterial->GetMaterialPropertiesTable(); >> 263 >> 264 if(aMaterialPropertyTable){ >> 265 G4MaterialPropertyVector* AttenuationLengthVector = >> 266 aMaterialPropertyTable->GetProperty("RAYLEIGH"); >> 267 if(AttenuationLengthVector){ >> 268 AttenuationLength = AttenuationLengthVector -> >> 269 GetProperty(thePhotonMomentum); >> 270 } >> 271 else{ >> 272 // G4cout << "No Rayleigh scattering length specified" << G4endl; >> 273 } >> 274 } >> 275 else{ >> 276 // G4cout << "No Rayleigh scattering length specified" << G4endl; >> 277 } >> 278 } >> 279 >> 280 return AttenuationLength; 305 } 281 } 306 282 307 //....oooOO0OOooo........oooOO0OOooo........oo << 283 // RayleighAttenuationLengthGenerator() 308 void G4OpRayleigh::SetVerboseLevel(G4int verbo << 284 // ------------------------------------ >> 285 // Private method to compute Rayleigh Scattering Lengths (for water) >> 286 // >> 287 G4PhysicsOrderedFreeVector* >> 288 G4OpRayleigh::RayleighAttenuationLengthGenerator(G4MaterialPropertiesTable *aMPT) 309 { 289 { 310 verboseLevel = verbose; << 290 // Physical Constants 311 G4OpticalParameters::Instance()->SetRayleigh << 291 >> 292 // isothermal compressibility of water >> 293 G4double betat = 7.658e-23*m3/MeV; >> 294 >> 295 // K Boltzman >> 296 G4double kboltz = 8.61739e-11*MeV/kelvin; >> 297 >> 298 // Temperature of water is 10 degrees celsius >> 299 // conversion to kelvin: >> 300 // TCelsius = TKelvin - 273.15 => 273.15 + 10 = 283.15 >> 301 G4double temp = 283.15*kelvin; >> 302 >> 303 // Retrieve vectors for refraction index >> 304 // and photon momentum from the material properties table >> 305 >> 306 G4MaterialPropertyVector* Rindex = aMPT->GetProperty("RINDEX"); >> 307 >> 308 G4double refsq; >> 309 G4double e; >> 310 G4double xlambda; >> 311 G4double c1, c2, c3, c4; >> 312 G4double Dist; >> 313 G4double refraction_index; >> 314 >> 315 G4PhysicsOrderedFreeVector *RayleighScatteringLengths = >> 316 new G4PhysicsOrderedFreeVector(); >> 317 >> 318 if (Rindex ) { >> 319 >> 320 Rindex->ResetIterator(); >> 321 >> 322 while (++(*Rindex)) { >> 323 >> 324 e = (Rindex->GetPhotonMomentum()); >> 325 >> 326 refraction_index = Rindex->GetProperty(); >> 327 refsq = refraction_index*refraction_index; >> 328 xlambda = h_Planck*c_light/e; >> 329 >> 330 if (verboseLevel>0) { >> 331 G4cout << Rindex->GetPhotonMomentum() << " MeV\t"; >> 332 G4cout << xlambda << " mm\t"; >> 333 } >> 334 >> 335 c1 = 1 / (6.0 * pi); >> 336 c2 = std::pow((2.0 * pi / xlambda), 4); >> 337 c3 = std::pow( ( (refsq - 1.0) * (refsq + 2.0) / 3.0 ), 2); >> 338 c4 = betat * temp * kboltz; >> 339 >> 340 Dist = 1.0 / (c1*c2*c3*c4); >> 341 >> 342 if (verboseLevel>0) { >> 343 G4cout << Dist << " mm" << G4endl; >> 344 } >> 345 RayleighScatteringLengths-> >> 346 InsertValues(Rindex->GetPhotonMomentum(), Dist); >> 347 } >> 348 >> 349 } >> 350 >> 351 return RayleighScatteringLengths; 312 } 352 } 313 353