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 // >> 23 // >> 24 // $Id: G4Cerenkov.cc,v 1.14 2003/02/12 08:52:55 gcosmo Exp $ >> 25 // GEANT4 tag $Name: geant4-05-02-patch-01 $ >> 26 // 26 ////////////////////////////////////////////// 27 //////////////////////////////////////////////////////////////////////// 27 // Cerenkov Radiation Class Implementation 28 // Cerenkov Radiation Class Implementation 28 ////////////////////////////////////////////// 29 //////////////////////////////////////////////////////////////////////// 29 // 30 // 30 // File: G4Cerenkov.cc << 31 // File: G4Cerenkov.cc 31 // Description: Discrete Process -- Generation << 32 // Description: Continuous Process -- Generation of Cerenkov Photons 32 // Version: 2.1 33 // Version: 2.1 33 // Created: 1996-02-21 << 34 // Created: 1996-02-21 34 // Author: Juliet Armstrong 35 // Author: Juliet Armstrong 35 // Updated: 2007-09-30 by Peter Gumplinger << 36 // Updated: 2001-09-17, migration of Materials to pure STL (mma) 36 // > change inheritance to G4VDis << 37 // GetContinuousStepLimit -> GetM << 38 // AlongStepDoIt -> PostStepDoIt << 39 // 2005-08-17 by Peter Gumplinger << 40 // > change variable name MeanNum << 41 // 2005-07-28 by Peter Gumplinger << 42 // > add G4ProcessType to constru << 43 // 2001-09-17, migration of Mater << 44 // 2000-11-12 by Peter Gumplinger 37 // 2000-11-12 by Peter Gumplinger 45 // > add check on CerenkovAngleIn 38 // > add check on CerenkovAngleIntegrals->IsFilledVectorExist() 46 // in method GetAverageNumberOfPh << 39 // in method GetAverageNumberOfPhotons 47 // > and a test for MeanNumberOfP << 40 // > and a test for MeanNumPhotons <= 0.0 in DoIt 48 // 2000-09-18 by Peter Gumplinger 41 // 2000-09-18 by Peter Gumplinger 49 // > change: aSecondaryPosition=x 42 // > change: aSecondaryPosition=x0+rand*aStep.GetDeltaPosition(); 50 // aSecondaryTrack->Set 43 // aSecondaryTrack->SetTouchable(0); 51 // 1999-10-29 by Peter Gumplinger 44 // 1999-10-29 by Peter Gumplinger 52 // > change: == into <= in GetCon 45 // > change: == into <= in GetContinuousStepLimit 53 // 1997-08-08 by Peter Gumplinger 46 // 1997-08-08 by Peter Gumplinger 54 // > add protection against /0 47 // > add protection against /0 55 // > G4MaterialPropertiesTable; n 48 // > G4MaterialPropertiesTable; new physics/tracking scheme 56 // 49 // >> 50 // mail: gum@triumf.ca >> 51 // 57 ////////////////////////////////////////////// 52 //////////////////////////////////////////////////////////////////////// 58 53 59 #include "G4Cerenkov.hh" << 60 << 61 #include "G4ios.hh" 54 #include "G4ios.hh" 62 #include "G4LossTableManager.hh" << 63 #include "G4Material.hh" << 64 #include "G4MaterialCutsCouple.hh" << 65 #include "G4MaterialPropertiesTable.hh" << 66 #include "G4OpticalParameters.hh" << 67 #include "G4OpticalPhoton.hh" << 68 #include "G4ParticleDefinition.hh" << 69 #include "G4ParticleMomentum.hh" << 70 #include "G4PhysicalConstants.hh" << 71 #include "G4PhysicsFreeVector.hh" << 72 #include "G4Poisson.hh" 55 #include "G4Poisson.hh" 73 #include "G4SystemOfUnits.hh" << 56 #include "G4Cerenkov.hh" 74 #include "G4ThreeVector.hh" << 75 #include "Randomize.hh" << 76 #include "G4PhysicsModelCatalog.hh" << 77 << 78 //....oooOO0OOooo........oooOO0OOooo........oo << 79 G4Cerenkov::G4Cerenkov(const G4String& process << 80 : G4VProcess(processName, type) << 81 , fNumPhotons(0) << 82 { << 83 secID = G4PhysicsModelCatalog::GetModelID("m << 84 SetProcessSubType(fCerenkov); << 85 57 86 thePhysicsTable = nullptr; << 58 ///////////////////////// >> 59 // Class Implementation >> 60 ///////////////////////// 87 61 88 if(verboseLevel > 0) << 62 ////////////// 89 { << 63 // Operators 90 G4cout << GetProcessName() << " is created << 64 ////////////// 91 } << 92 Initialise(); << 93 } << 94 65 95 //....oooOO0OOooo........oooOO0OOooo........oo << 66 // G4Cerenkov::operator=(const G4Cerenkov &right) 96 G4Cerenkov::~G4Cerenkov() << 67 // { 97 { << 68 // } 98 if(thePhysicsTable != nullptr) << 99 { << 100 thePhysicsTable->clearAndDestroy(); << 101 delete thePhysicsTable; << 102 } << 103 } << 104 69 105 void G4Cerenkov::ProcessDescription(std::ostre << 70 ///////////////// 106 { << 71 // Constructors 107 out << "The Cerenkov effect simulates optica << 72 ///////////////// 108 out << "passage of charged particles through << 109 out << "to have the property RINDEX (refract << 110 G4VProcess::DumpInfo(); << 111 << 112 G4OpticalParameters* params = G4OpticalParam << 113 out << "Maximum beta change per step: " << p << 114 out << "Maximum photons per step: " << param << 115 out << "Track secondaries first: " << 116 << params->GetCerenkovTrackSecondariesFi << 117 out << "Stack photons: " << params->GetCeren << 118 out << "Verbose level: " << params->GetCeren << 119 } << 120 73 121 //....oooOO0OOooo........oooOO0OOooo........oo << 74 G4Cerenkov::G4Cerenkov(const G4String& processName) 122 G4bool G4Cerenkov::IsApplicable(const G4Partic << 75 : G4VContinuousProcess(processName) 123 { 76 { 124 return (aParticleType.GetPDGCharge() != 0.0 << 77 fTrackSecondariesFirst = false; 125 aParticleType.GetPDGMass() != 0.0 && << 78 fMaxPhotons = 0; 126 aParticleType.GetParticleName() != " << 127 !aParticleType.IsShortLived()) << 128 ? true << 129 : false; << 130 } << 131 79 132 //....oooOO0OOooo........oooOO0OOooo........oo << 80 thePhysicsTable = NULL; 133 void G4Cerenkov::Initialise() << 134 { << 135 G4OpticalParameters* params = G4OpticalParam << 136 SetMaxBetaChangePerStep(params->GetCerenkovM << 137 SetMaxNumPhotonsPerStep(params->GetCerenkovM << 138 SetTrackSecondariesFirst(params->GetCerenkov << 139 SetStackPhotons(params->GetCerenkovStackPhot << 140 SetVerboseLevel(params->GetCerenkovVerboseLe << 141 } << 142 81 143 //....oooOO0OOooo........oooOO0OOooo........oo << 82 if (verboseLevel>0) { 144 void G4Cerenkov::BuildPhysicsTable(const G4Par << 83 G4cout << GetProcessName() << " is created " << G4endl; 145 { << 84 } 146 if(thePhysicsTable) << 147 return; << 148 85 149 const G4MaterialTable* theMaterialTable = G4 << 86 BuildThePhysicsTable(); 150 std::size_t numOfMaterials = G4 << 87 } 151 88 152 thePhysicsTable = new G4PhysicsTable(numOfMa << 89 // G4Cerenkov::G4Cerenkov(const G4Cerenkov &right) >> 90 // { >> 91 // } 153 92 154 // loop over materials << 93 //////////////// 155 for(std::size_t i = 0; i < numOfMaterials; + << 94 // Destructors 156 { << 95 //////////////// 157 G4PhysicsFreeVector* cerenkovIntegral = nu << 158 << 159 // Retrieve vector of refraction indices f << 160 // from the material's optical properties << 161 G4Material* aMaterial = (*theMate << 162 G4MaterialPropertiesTable* MPT = aMaterial << 163 << 164 if(MPT) << 165 { << 166 cerenkovIntegral << 167 G4MaterialPropertyVector* refractiveInde << 168 << 169 if(refractiveIndex) << 170 { << 171 // Retrieve the first refraction index << 172 // of (photon energy, refraction index << 173 G4double currentRI = (*refractiveIndex << 174 if(currentRI > 1.0) << 175 { << 176 // Create first (photon energy, Cere << 177 G4double currentPM = refractiveInde << 178 G4double currentCAI = 0.0; << 179 << 180 cerenkovIntegral->InsertValues(curre << 181 << 182 // Set previous values to current on << 183 G4double prevPM = currentPM; << 184 G4double prevCAI = currentCAI; << 185 G4double prevRI = currentRI; << 186 << 187 // loop over all (photon energy, ref << 188 // pairs stored for this material << 189 for(std::size_t ii = 1; ii < refract << 190 { << 191 currentRI = (*refractiveIndex)[ii << 192 currentPM = refractiveIndex->Ener << 193 currentCAI = prevCAI + (currentPM << 194 (1.0 / (p << 195 1.0 / (c << 196 << 197 cerenkovIntegral->InsertValues(cur << 198 << 199 prevPM = currentPM; << 200 prevCAI = currentCAI; << 201 prevRI = currentRI; << 202 } << 203 } << 204 } << 205 } << 206 96 207 // The Cerenkov integral for a given mater << 97 G4Cerenkov::~G4Cerenkov() 208 // thePhysicsTable according to the positi << 98 { 209 // the material table. << 99 if (thePhysicsTable != NULL) { 210 thePhysicsTable->insertAt(i, cerenkovInteg << 100 thePhysicsTable->clearAndDestroy(); 211 } << 101 delete thePhysicsTable; >> 102 } 212 } 103 } 213 104 214 //....oooOO0OOooo........oooOO0OOooo........oo << 105 //////////// 215 G4VParticleChange* G4Cerenkov::PostStepDoIt(co << 106 // Methods 216 co << 107 //////////// >> 108 >> 109 // AlongStepDoIt >> 110 // ------------- >> 111 // >> 112 G4VParticleChange* >> 113 G4Cerenkov::AlongStepDoIt(const G4Track& aTrack, const G4Step& aStep) >> 114 217 // This routine is called for each tracking St 115 // This routine is called for each tracking Step of a charged particle 218 // in a radiator. A Poisson-distributed number 116 // in a radiator. A Poisson-distributed number of photons is generated 219 // according to the Cerenkov formula, distribu 117 // according to the Cerenkov formula, distributed evenly along the track 220 // segment and uniformly azimuth w.r.t. the pa << 118 // segment and uniformly azimuth w.r.t. the particle direction. The 221 // parameters are then transformed into the Ma << 119 // parameters are then transformed into the Master Reference System, and 222 // they are added to the particle change. << 120 // they are added to the particle change. 223 121 224 { 122 { 225 aParticleChange.Initialize(aTrack); << 123 ////////////////////////////////////////////////////// >> 124 // Should we ensure that the material is dispersive? >> 125 ////////////////////////////////////////////////////// 226 126 227 const G4DynamicParticle* aParticle = aTrack. << 127 aParticleChange.Initialize(aTrack); 228 const G4Material* aMaterial = aTrack. << 229 128 230 G4StepPoint* pPreStepPoint = aStep.GetPreSt << 129 const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle(); 231 G4StepPoint* pPostStepPoint = aStep.GetPostS << 130 const G4Material* aMaterial = aTrack.GetMaterial(); 232 131 233 G4ThreeVector x0 = pPreStepPoint->GetPositio << 132 G4StepPoint* pPreStepPoint = aStep.GetPreStepPoint(); 234 G4ThreeVector p0 = aStep.GetDeltaPosition(). << 133 G4StepPoint* pPostStepPoint = aStep.GetPostStepPoint(); 235 G4double t0 = pPreStepPoint->GetGlobalT << 236 << 237 G4MaterialPropertiesTable* MPT = aMaterial-> << 238 if(!MPT) << 239 return pParticleChange; << 240 << 241 G4MaterialPropertyVector* Rindex = MPT->GetP << 242 if(!Rindex) << 243 return pParticleChange; << 244 << 245 G4double charge = aParticle->GetDefinition() << 246 << 247 G4double beta1 = pPreStepPoint->GetBeta(); << 248 G4double beta2 = pPostStepPoint->GetBeta(); << 249 G4double beta = (beta1 + beta2) * 0.5; << 250 << 251 G4double MeanNumberOfPhotons = << 252 GetAverageNumberOfPhotons(charge, beta, aM << 253 G4double MeanNumberOfPhotons1 = << 254 GetAverageNumberOfPhotons(charge, beta1, a << 255 G4double MeanNumberOfPhotons2 = << 256 GetAverageNumberOfPhotons(charge, beta2, a << 257 << 258 if(MeanNumberOfPhotons <= 0.0) << 259 { << 260 // return unchanged particle and no second << 261 aParticleChange.SetNumberOfSecondaries(0); << 262 return pParticleChange; << 263 } << 264 << 265 MeanNumberOfPhotons *= aStep.GetStepLength() << 266 fNumPhotons = (G4int) G4Poisson(Mean << 267 << 268 // third condition added to prevent infinite << 269 // see bugzilla 2555 << 270 if(fNumPhotons <= 0 || !fStackingFlag || << 271 std::max(MeanNumberOfPhotons1, MeanNumber << 272 { << 273 // return unchanged particle and no second << 274 aParticleChange.SetNumberOfSecondaries(0); << 275 return pParticleChange; << 276 } << 277 << 278 //////////////////////////////////////////// << 279 aParticleChange.SetNumberOfSecondaries(fNumP << 280 << 281 if(fTrackSecondariesFirst) << 282 { << 283 if(aTrack.GetTrackStatus() == fAlive) << 284 aParticleChange.ProposeTrackStatus(fSusp << 285 } << 286 << 287 //////////////////////////////////////////// << 288 G4double Pmin = Rindex->Energy(0); << 289 G4double Pmax = Rindex->GetMaxEnergy(); << 290 G4double dp = Pmax - Pmin; << 291 << 292 G4double nMax = Rindex->GetMaxValue() << 293 G4double BetaInverse = 1. / beta; << 294 << 295 G4double maxCos = BetaInverse / nMax; << 296 G4double maxSin2 = (1.0 - maxCos) * (1.0 + m << 297 << 298 for(G4int i = 0; i < fNumPhotons; ++i) << 299 { << 300 // Determine photon energy << 301 G4double rand; << 302 G4double sampledEnergy, sampledRI; << 303 G4double cosTheta, sin2Theta; << 304 << 305 // sample an energy << 306 do << 307 { << 308 rand = G4UniformRand(); << 309 sampledEnergy = Pmin + rand * dp; << 310 sampledRI = Rindex->Value(sampledEne << 311 cosTheta = BetaInverse / sampledRI; << 312 << 313 sin2Theta = (1.0 - cosTheta) * (1.0 + co << 314 rand = G4UniformRand(); << 315 << 316 // Loop checking, 07-Aug-2015, Vladimir << 317 } while(rand * maxSin2 > sin2Theta); << 318 << 319 // Create photon momentum direction vector << 320 // with respect to the coordinate system w << 321 // direction is aligned with the z axis << 322 rand = G4UniformRand(); << 323 G4double phi = twopi * rand; << 324 G4double sinPhi = std::sin(phi); << 325 G4double cosPhi = std::cos(phi); << 326 G4double sinTheta = std::sqrt(sin2Theta); << 327 G4ParticleMomentum photonMomentum(sinTheta << 328 cosTheta << 329 << 330 // Rotate momentum direction back to globa << 331 photonMomentum.rotateUz(p0); << 332 << 333 // Determine polarization of new photon << 334 G4ThreeVector photonPolarization(cosTheta << 335 -sinTheta << 336 << 337 // Rotate back to original coord system << 338 photonPolarization.rotateUz(p0); << 339 << 340 // Generate a new photon: << 341 auto aCerenkovPhoton = << 342 new G4DynamicParticle(G4OpticalPhoton::O << 343 << 344 aCerenkovPhoton->SetPolarization(photonPol << 345 aCerenkovPhoton->SetKineticEnergy(sampledE << 346 << 347 G4double NumberOfPhotons, N; << 348 << 349 do << 350 { << 351 rand = G4UniformRand(); << 352 NumberOfPhotons = MeanNumberOfPhotons1 - << 353 rand * (MeanNumberOfPh << 354 N = << 355 G4UniformRand() * std::max(MeanNumberO << 356 // Loop checking, 07-Aug-2015, Vladimir << 357 } while(N > NumberOfPhotons); << 358 << 359 G4double delta = rand * aStep.GetStepLengt << 360 G4double deltaTime = << 361 delta / << 362 (pPreStepPoint->GetVelocity() + << 363 rand * (pPostStepPoint->GetVelocity() - << 364 0.5); << 365 << 366 G4double aSecondaryTime = t0 + de << 367 G4ThreeVector aSecondaryPosition = x0 + ra << 368 << 369 // Generate new G4Track object: << 370 G4Track* aSecondaryTrack = << 371 new G4Track(aCerenkovPhoton, aSecondaryT << 372 << 373 aSecondaryTrack->SetTouchableHandle( << 374 aStep.GetPreStepPoint()->GetTouchableHan << 375 aSecondaryTrack->SetParentID(aTrack.GetTra << 376 aSecondaryTrack->SetCreatorModelID(secID); << 377 aParticleChange.AddSecondary(aSecondaryTra << 378 } << 379 << 380 if(verboseLevel > 1) << 381 { << 382 G4cout << "\n Exiting from G4Cerenkov::DoI << 383 << aParticleChange.GetNumberOfSecon << 384 } << 385 134 386 return pParticleChange; << 135 G4ThreeVector x0 = pPreStepPoint->GetPosition(); 387 } << 136 G4ThreeVector p0 = aStep.GetDeltaPosition().unit(); >> 137 G4double t0 = pPreStepPoint->GetGlobalTime(); 388 138 389 //....oooOO0OOooo........oooOO0OOooo........oo << 139 G4MaterialPropertiesTable* aMaterialPropertiesTable = 390 void G4Cerenkov::PreparePhysicsTable(const G4P << 140 aMaterial->GetMaterialPropertiesTable(); 391 { << 141 if (!aMaterialPropertiesTable) 392 Initialise(); << 142 return G4VContinuousProcess::AlongStepDoIt(aTrack, aStep); >> 143 >> 144 const G4MaterialPropertyVector* Rindex = >> 145 aMaterialPropertiesTable->GetProperty("RINDEX"); >> 146 if (!Rindex) >> 147 return G4VContinuousProcess::AlongStepDoIt(aTrack, aStep); >> 148 >> 149 G4double MeanNumPhotons = >> 150 GetAverageNumberOfPhotons(aParticle,aMaterial,Rindex); >> 151 >> 152 if (MeanNumPhotons <= 0.0) { >> 153 >> 154 // return unchanged particle and no secondaries >> 155 >> 156 aParticleChange.SetNumberOfSecondaries(0); >> 157 >> 158 return G4VContinuousProcess::AlongStepDoIt(aTrack, aStep); >> 159 >> 160 } >> 161 >> 162 G4double step_length; >> 163 step_length = aStep.GetStepLength(); >> 164 >> 165 MeanNumPhotons = MeanNumPhotons * step_length; >> 166 >> 167 G4int NumPhotons = (G4int) G4Poisson(MeanNumPhotons); >> 168 >> 169 if (NumPhotons <= 0) { >> 170 >> 171 // return unchanged particle and no secondaries >> 172 >> 173 aParticleChange.SetNumberOfSecondaries(0); >> 174 >> 175 return G4VContinuousProcess::AlongStepDoIt(aTrack, aStep); >> 176 } >> 177 >> 178 //////////////////////////////////////////////////////////////// >> 179 >> 180 aParticleChange.SetNumberOfSecondaries(NumPhotons); >> 181 >> 182 if (fTrackSecondariesFirst) { >> 183 if (aTrack.GetTrackStatus() == fAlive ) >> 184 aParticleChange.SetStatusChange(fSuspend); >> 185 } >> 186 >> 187 //////////////////////////////////////////////////////////////// >> 188 >> 189 G4double Pmin = Rindex->GetMinPhotonMomentum(); >> 190 G4double Pmax = Rindex->GetMaxPhotonMomentum(); >> 191 G4double dp = Pmax - Pmin; >> 192 >> 193 G4double nMax = Rindex->GetMaxProperty(); >> 194 >> 195 G4double BetaInverse = aParticle->GetTotalEnergy() / >> 196 aParticle->GetTotalMomentum(); >> 197 >> 198 G4double maxCos = BetaInverse / nMax; >> 199 G4double maxSin2 = (1.0 - maxCos) * (1.0 + maxCos); >> 200 >> 201 for (G4int i = 0; i < NumPhotons; i++) { >> 202 >> 203 // Determine photon momentum >> 204 >> 205 G4double rand; >> 206 G4double sampledMomentum, sampledRI; >> 207 G4double cosTheta, sin2Theta; >> 208 >> 209 // sample a momentum >> 210 >> 211 do { >> 212 rand = G4UniformRand(); >> 213 sampledMomentum = Pmin + rand * dp; >> 214 sampledRI = Rindex->GetProperty(sampledMomentum); >> 215 cosTheta = BetaInverse / sampledRI; >> 216 >> 217 sin2Theta = (1.0 - cosTheta)*(1.0 + cosTheta); >> 218 rand = G4UniformRand(); >> 219 >> 220 } while (rand*maxSin2 > sin2Theta); >> 221 >> 222 // Generate random position of photon on cone surface >> 223 // defined by Theta >> 224 >> 225 rand = G4UniformRand(); >> 226 >> 227 G4double phi = 2*M_PI*rand; >> 228 G4double sinPhi = sin(phi); >> 229 G4double cosPhi = cos(phi); >> 230 >> 231 // calculate x,y, and z components of photon momentum >> 232 // (in coord system with primary particle direction >> 233 // aligned with the z axis) >> 234 >> 235 G4double sinTheta = sqrt(sin2Theta); >> 236 G4double px = sinTheta*cosPhi; >> 237 G4double py = sinTheta*sinPhi; >> 238 G4double pz = cosTheta; >> 239 >> 240 // Create photon momentum direction vector >> 241 // The momentum direction is still with respect >> 242 // to the coordinate system where the primary >> 243 // particle direction is aligned with the z axis >> 244 >> 245 G4ParticleMomentum photonMomentum(px, py, pz); >> 246 >> 247 // Rotate momentum direction back to global reference >> 248 // system >> 249 >> 250 photonMomentum.rotateUz(p0); >> 251 >> 252 // Determine polarization of new photon >> 253 >> 254 G4double sx = cosTheta*cosPhi; >> 255 G4double sy = cosTheta*sinPhi; >> 256 G4double sz = -sinTheta; >> 257 >> 258 G4ThreeVector photonPolarization(sx, sy, sz); >> 259 >> 260 // Rotate back to original coord system >> 261 >> 262 photonPolarization.rotateUz(p0); >> 263 >> 264 // Generate a new photon: >> 265 >> 266 G4DynamicParticle* aCerenkovPhoton = >> 267 new G4DynamicParticle(G4OpticalPhoton::OpticalPhoton(), >> 268 photonMomentum); >> 269 aCerenkovPhoton->SetPolarization >> 270 (photonPolarization.x(), >> 271 photonPolarization.y(), >> 272 photonPolarization.z()); >> 273 >> 274 aCerenkovPhoton->SetKineticEnergy(sampledMomentum); >> 275 >> 276 // Generate new G4Track object: >> 277 >> 278 rand = G4UniformRand(); >> 279 >> 280 G4double delta = rand * aStep.GetStepLength(); >> 281 G4double deltaTime = delta / >> 282 ((pPreStepPoint->GetVelocity()+ >> 283 pPostStepPoint->GetVelocity())/2.); >> 284 >> 285 G4double aSecondaryTime = t0 + deltaTime; >> 286 >> 287 G4ThreeVector aSecondaryPosition = >> 288 x0 + rand * aStep.GetDeltaPosition(); >> 289 >> 290 G4Track* aSecondaryTrack = >> 291 new G4Track(aCerenkovPhoton,aSecondaryTime,aSecondaryPosition); >> 292 >> 293 aSecondaryTrack->SetTouchableHandle((G4VTouchable*)0); >> 294 >> 295 aSecondaryTrack->SetParentID(aTrack.GetTrackID()); >> 296 >> 297 aParticleChange.AddSecondary(aSecondaryTrack); >> 298 } >> 299 >> 300 if (verboseLevel>0) { >> 301 G4cout << "\n Exiting from G4Cerenkov::DoIt -- NumberOfSecondaries = " >> 302 << aParticleChange.GetNumberOfSecondaries() << G4endl; >> 303 } >> 304 >> 305 return G4VContinuousProcess::AlongStepDoIt(aTrack, aStep); 393 } 306 } 394 307 395 //....oooOO0OOooo........oooOO0OOooo........oo << 308 // BuildThePhysicsTable for the Cerenkov process 396 G4double G4Cerenkov::GetMeanFreePath(const G4T << 309 // --------------------------------------------- 397 G4ForceCo << 310 // >> 311 >> 312 void G4Cerenkov::BuildThePhysicsTable() 398 { 313 { 399 return 1.; << 314 if (thePhysicsTable) return; >> 315 >> 316 const G4MaterialTable* theMaterialTable= >> 317 G4Material::GetMaterialTable(); >> 318 G4int numOfMaterials = G4Material::GetNumberOfMaterials(); >> 319 >> 320 // create new physics table >> 321 >> 322 thePhysicsTable = new G4PhysicsTable(numOfMaterials); >> 323 >> 324 // loop for materials >> 325 >> 326 for (G4int i=0 ; i < numOfMaterials; i++) >> 327 { >> 328 G4PhysicsOrderedFreeVector* aPhysicsOrderedFreeVector = >> 329 new G4PhysicsOrderedFreeVector(); >> 330 >> 331 // Retrieve vector of refraction indices for the material >> 332 // from the material's optical properties table >> 333 >> 334 G4Material* aMaterial = (*theMaterialTable)[i]; >> 335 >> 336 G4MaterialPropertiesTable* aMaterialPropertiesTable = >> 337 aMaterial->GetMaterialPropertiesTable(); >> 338 >> 339 if (aMaterialPropertiesTable) { >> 340 >> 341 G4MaterialPropertyVector* theRefractionIndexVector = >> 342 aMaterialPropertiesTable->GetProperty("RINDEX"); >> 343 >> 344 if (theRefractionIndexVector) { >> 345 >> 346 // Retrieve the first refraction index in vector >> 347 // of (photon momentum, refraction index) pairs >> 348 >> 349 theRefractionIndexVector->ResetIterator(); >> 350 ++(*theRefractionIndexVector); // advance to 1st entry >> 351 >> 352 G4double currentRI = theRefractionIndexVector-> >> 353 GetProperty(); >> 354 >> 355 if (currentRI > 1.0) { >> 356 >> 357 // Create first (photon momentum, Cerenkov Integral) >> 358 // pair >> 359 >> 360 G4double currentPM = theRefractionIndexVector-> >> 361 GetPhotonMomentum(); >> 362 G4double currentCAI = 0.0; >> 363 >> 364 aPhysicsOrderedFreeVector-> >> 365 InsertValues(currentPM , currentCAI); >> 366 >> 367 // Set previous values to current ones prior to loop >> 368 >> 369 G4double prevPM = currentPM; >> 370 G4double prevCAI = currentCAI; >> 371 G4double prevRI = currentRI; >> 372 >> 373 // loop over all (photon momentum, refraction index) >> 374 // pairs stored for this material >> 375 >> 376 while(++(*theRefractionIndexVector)) >> 377 { >> 378 currentRI=theRefractionIndexVector-> >> 379 GetProperty(); >> 380 >> 381 currentPM = theRefractionIndexVector-> >> 382 GetPhotonMomentum(); >> 383 >> 384 currentCAI = 0.5*(1.0/(prevRI*prevRI) + >> 385 1.0/(currentRI*currentRI)); >> 386 >> 387 currentCAI = prevCAI + >> 388 (currentPM - prevPM) * currentCAI; >> 389 >> 390 aPhysicsOrderedFreeVector-> >> 391 InsertValues(currentPM, currentCAI); >> 392 >> 393 prevPM = currentPM; >> 394 prevCAI = currentCAI; >> 395 prevRI = currentRI; >> 396 } >> 397 >> 398 } >> 399 } >> 400 } >> 401 >> 402 // The Cerenkov integral for a given material >> 403 // will be inserted in thePhysicsTable >> 404 // according to the position of the material in >> 405 // the material table. >> 406 >> 407 thePhysicsTable->insertAt(i,aPhysicsOrderedFreeVector); >> 408 >> 409 } 400 } 410 } 401 411 402 //....oooOO0OOooo........oooOO0OOooo........oo << 412 // GetContinuousStepLimit 403 G4double G4Cerenkov::PostStepGetPhysicalIntera << 413 // ---------------------- 404 const G4Track& aTrack, G4double, G4ForceCond << 414 // >> 415 >> 416 G4double >> 417 G4Cerenkov::GetContinuousStepLimit(const G4Track& aTrack, >> 418 G4double , >> 419 G4double , >> 420 G4double& ) 405 { 421 { 406 *condition = NotForced; << 422 // If user has defined an average maximum number of photons to 407 G4double StepLimit = DBL_MAX; << 423 // be generated in a Step, then return the Step length for that 408 fNumPhotons = 0; << 424 // number of photons. 409 << 425 410 const G4Material* aMaterial = aTrack.GetMate << 426 if (fMaxPhotons <= 0) return DBL_MAX; 411 std::size_t materialIndex = aMaterial->Get << 427 412 << 428 const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle(); 413 // If Physics Vector is not defined no Ceren << 429 const G4Material* aMaterial = aTrack.GetMaterial(); 414 if(!(*thePhysicsTable)[materialIndex]) << 430 415 { << 431 G4MaterialPropertiesTable* aMaterialPropertiesTable = 416 return StepLimit; << 432 aMaterial->GetMaterialPropertiesTable(); 417 } << 433 if (!aMaterialPropertiesTable) return DBL_MAX; 418 << 434 419 const G4DynamicParticle* aParticle = aTrack. << 435 const G4MaterialPropertyVector* Rindex = 420 const G4MaterialCutsCouple* couple = aTrack. << 436 aMaterialPropertiesTable->GetProperty("RINDEX"); 421 << 437 if (!Rindex) return DBL_MAX; 422 G4double kineticEnergy = a << 438 423 const G4ParticleDefinition* particleType = a << 439 G4double MeanNumPhotons = 424 G4double mass = p << 440 GetAverageNumberOfPhotons(aParticle,aMaterial,Rindex); 425 << 441 426 G4double beta = aParticle->GetTotalMomentum << 442 if(MeanNumPhotons <= 0.0) return DBL_MAX; 427 G4double gamma = aParticle->GetTotalEnergy() << 443 428 << 444 G4double StepLimit = fMaxPhotons / MeanNumPhotons; 429 G4MaterialPropertiesTable* aMaterialProperti << 430 aMaterial->GetMaterialPropertiesTable(); << 431 << 432 G4MaterialPropertyVector* Rindex = nullptr; << 433 << 434 if(aMaterialPropertiesTable) << 435 Rindex = aMaterialPropertiesTable->GetProp << 436 << 437 G4double nMax; << 438 if(Rindex) << 439 { << 440 nMax = Rindex->GetMaxValue(); << 441 } << 442 else << 443 { << 444 return StepLimit; << 445 } << 446 << 447 G4double BetaMin = 1. / nMax; << 448 if(BetaMin >= 1.) << 449 return StepLimit; << 450 << 451 G4double GammaMin = 1. / std::sqrt(1. - Beta << 452 if(gamma < GammaMin) << 453 return StepLimit; << 454 << 455 G4double kinEmin = mass * (GammaMin - 1.); << 456 G4double RangeMin = << 457 G4LossTableManager::Instance()->GetRange(p << 458 G4double Range = G4LossTableManager::Instanc << 459 particleType, kineticEnergy, couple); << 460 G4double Step = Range - RangeMin; << 461 << 462 // If the step is smaller than G4ThreeVector << 463 // that the particle does not move. See bug << 464 static const G4double minAllowedStep = G4Thr << 465 if(Step < minAllowedStep) << 466 return StepLimit; << 467 << 468 if(Step < StepLimit) << 469 StepLimit = Step; << 470 << 471 // If user has defined an average maximum nu << 472 // a Step, then calculate the Step length fo << 473 if(fMaxPhotons > 0) << 474 { << 475 const G4double charge = aParticle->GetDefi << 476 G4double MeanNumberOfPhotons = << 477 GetAverageNumberOfPhotons(charge, beta, << 478 Step = 0.; << 479 if(MeanNumberOfPhotons > 0.0) << 480 Step = fMaxPhotons / MeanNumberOfPhotons << 481 if(Step > 0. && Step < StepLimit) << 482 StepLimit = Step; << 483 } << 484 << 485 // If user has defined an maximum allowed ch << 486 if(fMaxBetaChange > 0.) << 487 { << 488 G4double dedx = G4LossTableManager::Instan << 489 particleType, kineticEnergy, couple); << 490 G4double deltaGamma = << 491 gamma - 1. / std::sqrt(1. - beta * beta << 492 (1. - fMax << 493 << 494 Step = mass * deltaGamma / dedx; << 495 if(Step > 0. && Step < StepLimit) << 496 StepLimit = Step; << 497 } << 498 445 499 *condition = StronglyForced; << 446 return StepLimit; 500 return StepLimit; << 501 } 447 } 502 448 503 //....oooOO0OOooo........oooOO0OOooo........oo << 449 // GetAverageNumberOfPhotons 504 G4double G4Cerenkov::GetAverageNumberOfPhotons << 450 // ------------------------- 505 const G4double charge, const G4double beta, << 506 G4MaterialPropertyVector* Rindex) const << 507 // This routine computes the number of Cerenko 451 // This routine computes the number of Cerenkov photons produced per 508 // Geant4-unit (millimeter) in the current med << 452 // GEANT-unit (millimeter) in the current medium. >> 453 // ^^^^^^^^^^ >> 454 >> 455 G4double >> 456 G4Cerenkov::GetAverageNumberOfPhotons(const G4DynamicParticle* aParticle, >> 457 const G4Material* aMaterial, >> 458 const G4MaterialPropertyVector* Rindex) const 509 { 459 { 510 constexpr G4double Rfact = 369.81 / (eV * cm << 460 const G4double Rfact = 369.81/(eV * cm); 511 if(beta <= 0.0) << 512 return 0.0; << 513 G4double BetaInverse = 1. / beta; << 514 << 515 // Vectors used in computation of Cerenkov A << 516 // - Refraction Indices for the current mat << 517 // - new G4PhysicsFreeVector allocated to h << 518 std::size_t materialIndex = aMaterial->GetIn << 519 << 520 // Retrieve the Cerenkov Angle Integrals for << 521 G4PhysicsVector* CerenkovAngleIntegrals = (( << 522 << 523 std::size_t length = CerenkovAngleIntegrals- << 524 if(0 == length) << 525 return 0.0; << 526 << 527 // Min and Max photon energies << 528 G4double Pmin = Rindex->Energy(0); << 529 G4double Pmax = Rindex->GetMaxEnergy(); << 530 << 531 // Min and Max Refraction Indices << 532 G4double nMin = Rindex->GetMinValue(); << 533 G4double nMax = Rindex->GetMaxValue(); << 534 << 535 // Max Cerenkov Angle Integral << 536 G4double CAImax = (*CerenkovAngleIntegrals)[ << 537 << 538 G4double dp, ge; << 539 // If n(Pmax) < 1/Beta -- no photons generat << 540 if(nMax < BetaInverse) << 541 { << 542 dp = 0.0; << 543 ge = 0.0; << 544 } << 545 // otherwise if n(Pmin) >= 1/Beta -- photons << 546 else if(nMin > BetaInverse) << 547 { << 548 dp = Pmax - Pmin; << 549 ge = CAImax; << 550 } << 551 // If n(Pmin) < 1/Beta, and n(Pmax) >= 1/Bet << 552 // that the value of n(P) == 1/Beta. Interpo << 553 // GetEnergy() and Value() methods of the G4 << 554 // the Value() method of G4PhysicsVector. << 555 else << 556 { << 557 Pmin = Rindex->GetEnergy(BetaInverse); << 558 dp = Pmax - Pmin; << 559 << 560 G4double CAImin = CerenkovAngleIntegrals-> << 561 ge = CAImax - CAImin; << 562 << 563 if(verboseLevel > 1) << 564 { << 565 G4cout << "CAImin = " << CAImin << G4end << 566 } << 567 } << 568 << 569 // Calculate number of photons << 570 G4double NumPhotons = Rfact * charge / eplus << 571 (dp - ge * BetaInverse << 572 461 573 return NumPhotons; << 462 if(aParticle->GetTotalMomentum() <= 0.0)return 0.0; 574 } << 575 463 576 //....oooOO0OOooo........oooOO0OOooo........oo << 464 G4double BetaInverse = aParticle->GetTotalEnergy() / 577 void G4Cerenkov::SetTrackSecondariesFirst(cons << 465 aParticle->GetTotalMomentum(); 578 { << 579 fTrackSecondariesFirst = state; << 580 G4OpticalParameters::Instance()->SetCerenkov << 581 fTrackSecondariesFirst); << 582 } << 583 466 584 //....oooOO0OOooo........oooOO0OOooo........oo << 467 // Vectors used in computation of Cerenkov Angle Integral: 585 void G4Cerenkov::SetMaxBetaChangePerStep(const << 468 // - Refraction Indices for the current material 586 { << 469 // - new G4PhysicsOrderedFreeVector allocated to hold CAI's 587 fMaxBetaChange = value * CLHEP::perCent; << 470 588 G4OpticalParameters::Instance()->SetCerenkov << 471 G4int materialIndex = aMaterial->GetIndex(); 589 } << 590 472 591 //....oooOO0OOooo........oooOO0OOooo........oo << 473 // Retrieve the Cerenkov Angle Integrals for this material 592 void G4Cerenkov::SetMaxNumPhotonsPerStep(const << 593 { << 594 fMaxPhotons = NumPhotons; << 595 G4OpticalParameters::Instance()->SetCerenkov << 596 } << 597 474 598 void G4Cerenkov::SetStackPhotons(const G4bool << 475 G4PhysicsOrderedFreeVector* CerenkovAngleIntegrals = 599 { << 476 (G4PhysicsOrderedFreeVector*)((*thePhysicsTable)(materialIndex)); 600 fStackingFlag = stackingFlag; << 601 G4OpticalParameters::Instance()->SetCerenkov << 602 } << 603 477 604 //....oooOO0OOooo........oooOO0OOooo........oo << 478 if(!(CerenkovAngleIntegrals->IsFilledVectorExist()))return 0.0; 605 void G4Cerenkov::DumpPhysicsTable() const << 606 { << 607 G4cout << "Dump Physics Table!" << G4endl; << 608 for(std::size_t i = 0; i < thePhysicsTable-> << 609 { << 610 (*thePhysicsTable)[i]->DumpValues(); << 611 } << 612 } << 613 479 614 //....oooOO0OOooo........oooOO0OOooo........oo << 480 // Min and Max photon momenta 615 void G4Cerenkov::SetVerboseLevel(G4int verbose << 481 G4double Pmin = Rindex->GetMinPhotonMomentum(); 616 { << 482 G4double Pmax = Rindex->GetMaxPhotonMomentum(); 617 verboseLevel = verbose; << 483 618 G4OpticalParameters::Instance()->SetCerenkov << 484 // Min and Max Refraction Indices >> 485 G4double nMin = Rindex->GetMinProperty(); >> 486 G4double nMax = Rindex->GetMaxProperty(); >> 487 >> 488 // Max Cerenkov Angle Integral >> 489 G4double CAImax = CerenkovAngleIntegrals->GetMaxValue(); >> 490 >> 491 G4double dp, ge; >> 492 >> 493 // If n(Pmax) < 1/Beta -- no photons generated >> 494 >> 495 if (nMax < BetaInverse) { >> 496 dp = 0; >> 497 ge = 0; >> 498 } >> 499 >> 500 // otherwise if n(Pmin) >= 1/Beta -- photons generated >> 501 >> 502 else if (nMin > BetaInverse) { >> 503 dp = Pmax - Pmin; >> 504 ge = CAImax; >> 505 } >> 506 >> 507 // If n(Pmin) < 1/Beta, and n(Pmax) >= 1/Beta, then >> 508 // we need to find a P such that the value of n(P) == 1/Beta. >> 509 // Interpolation is performed by the GetPhotonMomentum() and >> 510 // GetProperty() methods of the G4MaterialPropertiesTable and >> 511 // the GetValue() method of G4PhysicsVector. >> 512 >> 513 else { >> 514 Pmin = Rindex->GetPhotonMomentum(BetaInverse); >> 515 dp = Pmax - Pmin; >> 516 >> 517 // need boolean for current implementation of G4PhysicsVector >> 518 // ==> being phased out >> 519 G4bool isOutRange; >> 520 G4double CAImin = CerenkovAngleIntegrals-> >> 521 GetValue(Pmin, isOutRange); >> 522 ge = CAImax - CAImin; >> 523 >> 524 if (verboseLevel>0) { >> 525 G4cout << "CAImin = " << CAImin << G4endl; >> 526 G4cout << "ge = " << ge << G4endl; >> 527 } >> 528 } >> 529 >> 530 // particle charge >> 531 G4double charge = aParticle->GetDefinition()->GetPDGCharge(); >> 532 >> 533 // Calculate number of photons >> 534 G4double NumPhotons = Rfact * charge/eplus * charge/eplus * >> 535 (dp - ge * BetaInverse*BetaInverse); >> 536 >> 537 return NumPhotons; 619 } 538 } 620 539