Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/processes/optical/src/G4OpRayleigh.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /processes/optical/src/G4OpRayleigh.cc (Version 11.3.0) and /processes/optical/src/G4OpRayleigh.cc (Version 9.6.p1)


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