Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 << 25 // >> 26 // >> 27 // 26 ////////////////////////////////////////////// 28 //////////////////////////////////////////////////////////////////////// 27 // Optical Surface Class Implementation 29 // Optical Surface Class Implementation 28 ////////////////////////////////////////////// 30 //////////////////////////////////////////////////////////////////////// 29 // 31 // 30 // File: G4OpticalSurface.cc 32 // File: G4OpticalSurface.cc 31 // Description: An optical surface class for u 33 // Description: An optical surface class for use in G4OpBoundaryProcess 32 // Version: 2.0 34 // Version: 2.0 33 // Created: 1997-06-26 35 // Created: 1997-06-26 34 // Author: Peter Gumplinger 36 // Author: Peter Gumplinger 35 // updated: 2017-02-24 Mariele Stockhoff a 37 // updated: 2017-02-24 Mariele Stockhoff add DAVIS model 36 ////////////////////////////////////////////// 38 //////////////////////////////////////////////////////////////////////// 37 39 38 #include "G4OpticalSurface.hh" << 40 #include <iostream> 39 << 41 #include <fstream> 40 #include "globals.hh" << 41 << 42 #include <zlib.h> 42 #include <zlib.h> 43 43 44 #include <fstream> << 44 #include "globals.hh" 45 #include <iostream> << 45 #include "G4OpticalSurface.hh" 46 46 47 G4OpticalSurface& G4OpticalSurface::operator=( 47 G4OpticalSurface& G4OpticalSurface::operator=(const G4OpticalSurface& right) 48 { 48 { 49 if (this != &right) { << 49 if(this != &right) 50 theName = right.theName; << 50 { 51 theType = right.theType; << 51 theName = right.theName; 52 theModel = right.theModel; << 52 theType = right.theType; 53 theFinish = right.theFinish; << 53 theModel = right.theModel; 54 sigma_alpha = right.sigma_alpha; << 54 theFinish = right.theFinish; 55 polish = right.polish; << 55 sigma_alpha = right.sigma_alpha; >> 56 polish = right.polish; 56 theMaterialPropertiesTable = right.theMate 57 theMaterialPropertiesTable = right.theMaterialPropertiesTable; 57 58 58 delete[] AngularDistribution; << 59 if(AngularDistribution) 59 AngularDistribution = new G4float[incident << 60 delete[] AngularDistribution; >> 61 AngularDistribution = >> 62 new G4float[incidentIndexMax * thetaIndexMax * phiIndexMax]; 60 *(AngularDistribution) = *(right.AngularDi 63 *(AngularDistribution) = *(right.AngularDistribution); 61 64 62 delete[] AngularDistributionLUT; << 65 if(AngularDistributionLUT) 63 AngularDistributionLUT = new G4float[index << 66 delete[] AngularDistributionLUT; >> 67 AngularDistributionLUT = new G4float[indexmax]; 64 *(AngularDistributionLUT) = *(right.Angula 68 *(AngularDistributionLUT) = *(right.AngularDistributionLUT); 65 69 66 delete[] Reflectivity; << 70 if(Reflectivity) 67 Reflectivity = new G4float[RefMax]; << 71 delete[] Reflectivity; >> 72 Reflectivity = new G4float[RefMax]; 68 *(Reflectivity) = *(right.Reflectivity); 73 *(Reflectivity) = *(right.Reflectivity); 69 74 70 delete DichroicVector; << 75 if(DichroicVector) 71 DichroicVector = new G4Physics2DVector(); << 76 delete DichroicVector; >> 77 DichroicVector = new G4Physics2DVector(); 72 *DichroicVector = *(right.DichroicVector); 78 *DichroicVector = *(right.DichroicVector); 73 } 79 } 74 return *this; 80 return *this; 75 } 81 } 76 82 77 G4OpticalSurface::G4OpticalSurface(const G4Str << 83 G4OpticalSurface::G4OpticalSurface(const G4String& name, 78 G4OpticalSurfaceFinish finish, G4SurfaceType << 84 G4OpticalSurfaceModel model, 79 : G4SurfaceProperty(name, type), theModel(mo << 85 G4OpticalSurfaceFinish finish, >> 86 G4SurfaceType type, G4double value) >> 87 : G4SurfaceProperty(name, type) >> 88 , theModel(model) >> 89 , theFinish(finish) >> 90 , theMaterialPropertiesTable(nullptr) 80 { 91 { 81 AngularDistribution = nullptr; 92 AngularDistribution = nullptr; 82 93 83 AngularDistributionLUT = nullptr; 94 AngularDistributionLUT = nullptr; 84 Reflectivity = nullptr; << 95 Reflectivity = nullptr; 85 96 86 DichroicVector = nullptr; 97 DichroicVector = nullptr; 87 98 88 switch (theModel) { << 99 switch(theModel) >> 100 { 89 case glisur: 101 case glisur: 90 polish = value; << 102 polish = value; 91 sigma_alpha = 0.0; 103 sigma_alpha = 0.0; 92 break; 104 break; 93 case LUT: 105 case LUT: 94 case dichroic: 106 case dichroic: 95 case DAVIS: 107 case DAVIS: 96 ReadDataFile(); 108 ReadDataFile(); 97 // fall through 109 // fall through 98 case unified: 110 case unified: 99 sigma_alpha = value; 111 sigma_alpha = value; 100 polish = 0.0; << 112 polish = 0.0; 101 break; 113 break; 102 default: 114 default: 103 G4Exception("G4OpticalSurface::G4Optical << 115 G4Exception("G4OpticalSurface::G4OpticalSurface()", "mat309", 104 "Constructor called with INVALID model << 116 FatalException, "Constructor called with INVALID model."); 105 } 117 } 106 } 118 } 107 119 108 G4OpticalSurface::~G4OpticalSurface() 120 G4OpticalSurface::~G4OpticalSurface() 109 { 121 { 110 delete[] AngularDistribution; << 122 if(AngularDistribution) 111 << 123 delete[] AngularDistribution; 112 delete[] AngularDistributionLUT; << 113 124 114 delete[] Reflectivity; << 125 if(AngularDistributionLUT) >> 126 delete[] AngularDistributionLUT; >> 127 if(Reflectivity) >> 128 delete[] Reflectivity; 115 129 116 delete DichroicVector; << 130 if(DichroicVector) >> 131 delete DichroicVector; 117 } 132 } 118 133 119 G4OpticalSurface::G4OpticalSurface(const G4Opt 134 G4OpticalSurface::G4OpticalSurface(const G4OpticalSurface& right) 120 : G4SurfaceProperty(right.theName, right.the 135 : G4SurfaceProperty(right.theName, right.theType) 121 { 136 { 122 *this = right; << 137 *this = right; 123 this->theName = right.theName; << 138 this->theName = right.theName; 124 this->theType = right.theType; << 139 this->theType = right.theType; 125 this->theModel = right.theModel; << 140 this->theModel = right.theModel; 126 this->theFinish = right.theFinish; << 141 this->theFinish = right.theFinish; 127 this->sigma_alpha = right.sigma_alpha; << 142 this->sigma_alpha = right.sigma_alpha; 128 this->polish = right.polish; << 143 this->polish = right.polish; 129 this->theMaterialPropertiesTable = right.the 144 this->theMaterialPropertiesTable = right.theMaterialPropertiesTable; 130 145 131 delete[] AngularDistribution; << 146 if(this->AngularDistribution) 132 this->AngularDistribution = new G4float[inci << 147 delete[] AngularDistribution; >> 148 this->AngularDistribution = >> 149 new G4float[incidentIndexMax * thetaIndexMax * phiIndexMax]; 133 *(this->AngularDistribution) = *(right.Angul 150 *(this->AngularDistribution) = *(right.AngularDistribution); 134 151 135 delete[] AngularDistributionLUT; << 152 if(this->AngularDistributionLUT) 136 this->AngularDistributionLUT = new G4float[i << 153 delete[] AngularDistributionLUT; >> 154 this->AngularDistributionLUT = new G4float[indexmax]; 137 *(this->AngularDistributionLUT) = *(right.An 155 *(this->AngularDistributionLUT) = *(right.AngularDistributionLUT); 138 << 156 if(this->Reflectivity) 139 delete[] Reflectivity; << 157 delete[] Reflectivity; 140 this->Reflectivity = new G4float[RefMax]; << 158 this->Reflectivity = new G4float[RefMax]; 141 *(this->Reflectivity) = *(right.Reflectivity 159 *(this->Reflectivity) = *(right.Reflectivity); 142 160 143 delete DichroicVector; << 161 if(this->DichroicVector) 144 this->DichroicVector = new G4Physics2DVector << 162 delete DichroicVector; >> 163 this->DichroicVector = new G4Physics2DVector(); 145 *(this->DichroicVector) = *(right.DichroicVe 164 *(this->DichroicVector) = *(right.DichroicVector); 146 } 165 } 147 166 148 G4bool G4OpticalSurface::operator==(const G4Op 167 G4bool G4OpticalSurface::operator==(const G4OpticalSurface& right) const 149 { 168 { 150 return (this == (G4OpticalSurface*)&right); << 169 return (this == (G4OpticalSurface*) &right); 151 } 170 } 152 171 153 G4bool G4OpticalSurface::operator!=(const G4Op 172 G4bool G4OpticalSurface::operator!=(const G4OpticalSurface& right) const 154 { 173 { 155 return (this != (G4OpticalSurface*)&right); << 174 return (this != (G4OpticalSurface*) &right); 156 } 175 } 157 176 158 G4int G4OpticalSurface::GetInmax() const { ret << 177 G4int G4OpticalSurface::GetInmax(void) const { return indexmax; } 159 178 160 G4int G4OpticalSurface::GetLUTbins() const { r << 179 G4int G4OpticalSurface::GetLUTbins(void) const { return LUTbins; } 161 180 162 G4int G4OpticalSurface::GetRefMax() const { re << 181 G4int G4OpticalSurface::GetRefMax(void) const { return RefMax; } 163 182 164 G4int G4OpticalSurface::GetThetaIndexMax() con << 183 G4int G4OpticalSurface::GetThetaIndexMax(void) const { return thetaIndexMax; } 165 184 166 G4int G4OpticalSurface::GetPhiIndexMax() const << 185 G4int G4OpticalSurface::GetPhiIndexMax(void) const { return phiIndexMax; } 167 186 168 void G4OpticalSurface::DumpInfo() const 187 void G4OpticalSurface::DumpInfo() const 169 { 188 { 170 // Dump info for surface 189 // Dump info for surface 171 190 172 G4cout << " Surface type = " << G4int(the 191 G4cout << " Surface type = " << G4int(theType) << G4endl 173 << " Surface finish = " << G4int(the 192 << " Surface finish = " << G4int(theFinish) << G4endl 174 << " Surface model = " << G4int(the << 193 << " Surface model = " << G4int(theModel) << G4endl << G4endl 175 << G4endl << " ----------------- " < << 194 << " Surface parameter " << G4endl << " ----------------- " >> 195 << G4endl; 176 196 177 if (theModel == glisur) { << 197 if(theModel == glisur) >> 198 { 178 G4cout << " polish: " << polish << G4endl; 199 G4cout << " polish: " << polish << G4endl; 179 } 200 } 180 else { << 201 else >> 202 { 181 G4cout << " sigma_alpha: " << sigma_alpha 203 G4cout << " sigma_alpha: " << sigma_alpha << G4endl; 182 } 204 } 183 G4cout << G4endl; 205 G4cout << G4endl; 184 } 206 } 185 207 186 void G4OpticalSurface::SetType(const G4Surface 208 void G4OpticalSurface::SetType(const G4SurfaceType& type) 187 { 209 { 188 theType = type; 210 theType = type; 189 ReadDataFile(); 211 ReadDataFile(); 190 } 212 } 191 213 192 void G4OpticalSurface::SetFinish(const G4Optic 214 void G4OpticalSurface::SetFinish(const G4OpticalSurfaceFinish finish) 193 { 215 { 194 theFinish = finish; 216 theFinish = finish; 195 ReadDataFile(); 217 ReadDataFile(); 196 } 218 } 197 219 198 void G4OpticalSurface::ReadDataFile() 220 void G4OpticalSurface::ReadDataFile() 199 { 221 { 200 // type and finish can be set in either orde 222 // type and finish can be set in either order. Thus, we can't check 201 // for consistency. Need to read file on set 223 // for consistency. Need to read file on setting either type or finish. 202 switch (theType) { << 224 switch(theType) >> 225 { 203 case dielectric_LUT: 226 case dielectric_LUT: 204 if (AngularDistribution == nullptr) { << 227 if(!AngularDistribution) 205 AngularDistribution = new G4float[inci << 228 AngularDistribution = 206 } << 229 new G4float[incidentIndexMax * thetaIndexMax * phiIndexMax]; 207 ReadLUTFile(); 230 ReadLUTFile(); 208 break; 231 break; 209 case dielectric_LUTDAVIS: 232 case dielectric_LUTDAVIS: 210 if (AngularDistributionLUT == nullptr) { << 233 if(!AngularDistributionLUT) 211 AngularDistributionLUT = new G4float[i 234 AngularDistributionLUT = new G4float[indexmax]; 212 } << 213 ReadLUTDAVISFile(); 235 ReadLUTDAVISFile(); 214 236 215 if (Reflectivity == nullptr) { << 237 if(!Reflectivity) 216 Reflectivity = new G4float[RefMax]; 238 Reflectivity = new G4float[RefMax]; 217 } << 218 ReadReflectivityLUTFile(); 239 ReadReflectivityLUTFile(); 219 break; 240 break; 220 case dielectric_dichroic: 241 case dielectric_dichroic: 221 if (DichroicVector == nullptr) { << 242 if(!DichroicVector) 222 DichroicVector = new G4Physics2DVector 243 DichroicVector = new G4Physics2DVector(); 223 } << 224 ReadDichroicFile(); 244 ReadDichroicFile(); 225 break; 245 break; 226 default: 246 default: 227 break; 247 break; 228 } 248 } 229 } 249 } 230 250 231 void G4OpticalSurface::ReadLUTFile() 251 void G4OpticalSurface::ReadLUTFile() 232 { 252 { 233 G4String readLUTFileName; 253 G4String readLUTFileName; 234 254 235 switch (theFinish) { << 255 switch(theFinish) >> 256 { 236 case polishedlumirrorglue: 257 case polishedlumirrorglue: 237 readLUTFileName = "PolishedLumirrorGlue. 258 readLUTFileName = "PolishedLumirrorGlue.z"; 238 break; 259 break; 239 case polishedlumirrorair: 260 case polishedlumirrorair: 240 readLUTFileName = "PolishedLumirror.z"; 261 readLUTFileName = "PolishedLumirror.z"; 241 break; 262 break; 242 case polishedteflonair: 263 case polishedteflonair: 243 readLUTFileName = "PolishedTeflon.z"; 264 readLUTFileName = "PolishedTeflon.z"; 244 break; 265 break; 245 case polishedtioair: 266 case polishedtioair: 246 readLUTFileName = "PolishedTiO.z"; 267 readLUTFileName = "PolishedTiO.z"; 247 break; 268 break; 248 case polishedtyvekair: 269 case polishedtyvekair: 249 readLUTFileName = "PolishedTyvek.z"; 270 readLUTFileName = "PolishedTyvek.z"; 250 break; 271 break; 251 case polishedvm2000glue: 272 case polishedvm2000glue: 252 readLUTFileName = "PolishedVM2000Glue.z" 273 readLUTFileName = "PolishedVM2000Glue.z"; 253 break; 274 break; 254 case polishedvm2000air: 275 case polishedvm2000air: 255 readLUTFileName = "PolishedVM2000.z"; 276 readLUTFileName = "PolishedVM2000.z"; 256 break; 277 break; 257 case etchedlumirrorglue: 278 case etchedlumirrorglue: 258 readLUTFileName = "EtchedLumirrorGlue.z" 279 readLUTFileName = "EtchedLumirrorGlue.z"; 259 break; 280 break; 260 case etchedlumirrorair: 281 case etchedlumirrorair: 261 readLUTFileName = "EtchedLumirror.z"; 282 readLUTFileName = "EtchedLumirror.z"; 262 break; 283 break; 263 case etchedteflonair: 284 case etchedteflonair: 264 readLUTFileName = "EtchedTeflon.z"; 285 readLUTFileName = "EtchedTeflon.z"; 265 break; 286 break; 266 case etchedtioair: 287 case etchedtioair: 267 readLUTFileName = "EtchedTiO.z"; 288 readLUTFileName = "EtchedTiO.z"; 268 break; 289 break; 269 case etchedtyvekair: 290 case etchedtyvekair: 270 readLUTFileName = "EtchedTyvek.z"; 291 readLUTFileName = "EtchedTyvek.z"; 271 break; 292 break; 272 case etchedvm2000glue: 293 case etchedvm2000glue: 273 readLUTFileName = "EtchedVM2000Glue.z"; 294 readLUTFileName = "EtchedVM2000Glue.z"; 274 break; 295 break; 275 case etchedvm2000air: 296 case etchedvm2000air: 276 readLUTFileName = "EtchedVM2000.z"; 297 readLUTFileName = "EtchedVM2000.z"; 277 break; 298 break; 278 case groundlumirrorglue: 299 case groundlumirrorglue: 279 readLUTFileName = "GroundLumirrorGlue.z" 300 readLUTFileName = "GroundLumirrorGlue.z"; 280 break; 301 break; 281 case groundlumirrorair: 302 case groundlumirrorair: 282 readLUTFileName = "GroundLumirror.z"; 303 readLUTFileName = "GroundLumirror.z"; 283 break; 304 break; 284 case groundteflonair: 305 case groundteflonair: 285 readLUTFileName = "GroundTeflon.z"; 306 readLUTFileName = "GroundTeflon.z"; 286 break; 307 break; 287 case groundtioair: 308 case groundtioair: 288 readLUTFileName = "GroundTiO.z"; 309 readLUTFileName = "GroundTiO.z"; 289 break; 310 break; 290 case groundtyvekair: 311 case groundtyvekair: 291 readLUTFileName = "GroundTyvek.z"; 312 readLUTFileName = "GroundTyvek.z"; 292 break; 313 break; 293 case groundvm2000glue: 314 case groundvm2000glue: 294 readLUTFileName = "GroundVM2000Glue.z"; 315 readLUTFileName = "GroundVM2000Glue.z"; 295 break; 316 break; 296 case groundvm2000air: 317 case groundvm2000air: 297 readLUTFileName = "GroundVM2000.z"; 318 readLUTFileName = "GroundVM2000.z"; 298 break; 319 break; 299 default: 320 default: 300 return; 321 return; 301 } 322 } 302 323 303 std::istringstream iss; 324 std::istringstream iss; 304 ReadCompressedFile(readLUTFileName, iss); 325 ReadCompressedFile(readLUTFileName, iss); 305 326 306 size_t idxmax = incidentIndexMax * thetaInde 327 size_t idxmax = incidentIndexMax * thetaIndexMax * phiIndexMax; 307 for (size_t i = 0; i < idxmax; ++i) { << 328 for(size_t i = 0; i < idxmax; ++i) >> 329 { 308 iss >> AngularDistribution[i]; 330 iss >> AngularDistribution[i]; 309 } 331 } 310 G4cout << "LUT - data file: " << readLUTFile 332 G4cout << "LUT - data file: " << readLUTFileName << " read in! " << G4endl; 311 } 333 } 312 334 313 void G4OpticalSurface::ReadLUTDAVISFile() 335 void G4OpticalSurface::ReadLUTDAVISFile() 314 { 336 { 315 G4String readLUTDAVISFileName; 337 G4String readLUTDAVISFileName; 316 338 317 switch (theFinish) { << 339 switch(theFinish) >> 340 { 318 case Rough_LUT: 341 case Rough_LUT: 319 readLUTDAVISFileName = "Rough_LUT.z"; 342 readLUTDAVISFileName = "Rough_LUT.z"; 320 break; 343 break; 321 case RoughTeflon_LUT: 344 case RoughTeflon_LUT: 322 readLUTDAVISFileName = "RoughTeflon_LUT. 345 readLUTDAVISFileName = "RoughTeflon_LUT.z"; 323 break; 346 break; 324 case RoughESR_LUT: 347 case RoughESR_LUT: 325 readLUTDAVISFileName = "RoughESR_LUT.z"; 348 readLUTDAVISFileName = "RoughESR_LUT.z"; 326 break; 349 break; 327 case RoughESRGrease_LUT: 350 case RoughESRGrease_LUT: 328 readLUTDAVISFileName = "RoughESRGrease_L 351 readLUTDAVISFileName = "RoughESRGrease_LUT.z"; 329 break; 352 break; 330 case Polished_LUT: 353 case Polished_LUT: 331 readLUTDAVISFileName = "Polished_LUT.z"; 354 readLUTDAVISFileName = "Polished_LUT.z"; 332 break; 355 break; 333 case PolishedTeflon_LUT: 356 case PolishedTeflon_LUT: 334 readLUTDAVISFileName = "PolishedTeflon_L 357 readLUTDAVISFileName = "PolishedTeflon_LUT.z"; 335 break; 358 break; 336 case PolishedESR_LUT: 359 case PolishedESR_LUT: 337 readLUTDAVISFileName = "PolishedESR_LUT. 360 readLUTDAVISFileName = "PolishedESR_LUT.z"; 338 break; 361 break; 339 case PolishedESRGrease_LUT: 362 case PolishedESRGrease_LUT: 340 readLUTDAVISFileName = "PolishedESRGreas 363 readLUTDAVISFileName = "PolishedESRGrease_LUT.z"; 341 break; 364 break; 342 case Detector_LUT: 365 case Detector_LUT: 343 readLUTDAVISFileName = "Detector_LUT.z"; 366 readLUTDAVISFileName = "Detector_LUT.z"; 344 break; 367 break; 345 default: 368 default: 346 return; 369 return; 347 } 370 } 348 371 349 std::istringstream iss; 372 std::istringstream iss; 350 ReadCompressedFile(readLUTDAVISFileName, iss 373 ReadCompressedFile(readLUTDAVISFileName, iss); 351 374 352 for (size_t i = 0; i < indexmax; ++i) { << 375 for(size_t i = 0; i < indexmax; ++i) >> 376 { 353 iss >> AngularDistributionLUT[i]; 377 iss >> AngularDistributionLUT[i]; 354 } 378 } 355 G4cout << "LUT DAVIS - data file: " << readL << 379 G4cout << "LUT DAVIS - data file: " << readLUTDAVISFileName << " read in! " >> 380 << G4endl; 356 } 381 } 357 382 358 void G4OpticalSurface::ReadReflectivityLUTFile 383 void G4OpticalSurface::ReadReflectivityLUTFile() 359 { 384 { 360 G4String readReflectivityLUTFileName; 385 G4String readReflectivityLUTFileName; 361 386 362 switch (theFinish) { << 387 switch(theFinish) >> 388 { 363 case Rough_LUT: 389 case Rough_LUT: 364 readReflectivityLUTFileName = "Rough_LUT 390 readReflectivityLUTFileName = "Rough_LUTR.z"; 365 break; 391 break; 366 case RoughTeflon_LUT: 392 case RoughTeflon_LUT: 367 readReflectivityLUTFileName = "RoughTefl 393 readReflectivityLUTFileName = "RoughTeflon_LUTR.z"; 368 break; 394 break; 369 case RoughESR_LUT: 395 case RoughESR_LUT: 370 readReflectivityLUTFileName = "RoughESR_ 396 readReflectivityLUTFileName = "RoughESR_LUTR.z"; 371 break; 397 break; 372 case RoughESRGrease_LUT: 398 case RoughESRGrease_LUT: 373 readReflectivityLUTFileName = "RoughESRG 399 readReflectivityLUTFileName = "RoughESRGrease_LUTR.z"; 374 break; 400 break; 375 case Polished_LUT: 401 case Polished_LUT: 376 readReflectivityLUTFileName = "Polished_ 402 readReflectivityLUTFileName = "Polished_LUTR.z"; 377 break; 403 break; 378 case PolishedTeflon_LUT: 404 case PolishedTeflon_LUT: 379 readReflectivityLUTFileName = "PolishedT 405 readReflectivityLUTFileName = "PolishedTeflon_LUTR.z"; 380 break; 406 break; 381 case PolishedESR_LUT: 407 case PolishedESR_LUT: 382 readReflectivityLUTFileName = "PolishedE 408 readReflectivityLUTFileName = "PolishedESR_LUTR.z"; 383 break; 409 break; 384 case PolishedESRGrease_LUT: 410 case PolishedESRGrease_LUT: 385 readReflectivityLUTFileName = "PolishedE 411 readReflectivityLUTFileName = "PolishedESRGrease_LUTR.z"; 386 break; 412 break; 387 case Detector_LUT: 413 case Detector_LUT: 388 readReflectivityLUTFileName = "Detector_ 414 readReflectivityLUTFileName = "Detector_LUTR.z"; 389 break; 415 break; 390 default: 416 default: 391 return; 417 return; 392 } 418 } 393 419 394 std::istringstream iss; 420 std::istringstream iss; 395 ReadCompressedFile(readReflectivityLUTFileNa 421 ReadCompressedFile(readReflectivityLUTFileName, iss); 396 422 397 for (size_t i = 0; i < RefMax; ++i) { << 423 for(size_t i = 0; i < RefMax; ++i) >> 424 { 398 iss >> Reflectivity[i]; 425 iss >> Reflectivity[i]; 399 } 426 } 400 G4cout << "LUT DAVIS - reflectivity data fil << 427 G4cout << "LUT DAVIS - reflectivity data file: " 401 << G4endl; << 428 << readReflectivityLUTFileName << " read in! " << G4endl; 402 } 429 } 403 430 404 // uncompress one data file into the input str 431 // uncompress one data file into the input string stream 405 void G4OpticalSurface::ReadCompressedFile(cons << 432 void G4OpticalSurface::ReadCompressedFile(G4String filename, >> 433 std::istringstream& iss) 406 { 434 { 407 G4String* dataString = nullptr; << 435 G4String* dataString = nullptr; 408 G4String path = G4FindDataDir("G4REALSURFACE << 436 G4String path = std::getenv("G4REALSURFACEDATA"); 409 G4String compfilename = path + "/" + filenam 437 G4String compfilename = path + "/" + filename; 410 // create input stream with binary mode oper 438 // create input stream with binary mode operation and position at end of file 411 std::ifstream in(compfilename, std::ios::bin 439 std::ifstream in(compfilename, std::ios::binary | std::ios::ate); 412 if (in.good()) { << 440 if(in.good()) >> 441 { 413 // get current position in the stream (was 442 // get current position in the stream (was set to the end) 414 G4int fileSize = (G4int)in.tellg(); << 443 int fileSize = in.tellg(); 415 // set current position being the beginnin 444 // set current position being the beginning of the stream 416 in.seekg(0, std::ios::beg); 445 in.seekg(0, std::ios::beg); 417 // create (zlib) byte buffer for the data 446 // create (zlib) byte buffer for the data 418 auto compdata = new Bytef[fileSize]; << 447 Bytef* compdata = new Bytef[fileSize]; 419 while (in) { << 448 while(in) 420 in.read((char*)compdata, fileSize); << 449 { >> 450 in.read((char*) compdata, fileSize); 421 } 451 } 422 // create (zlib) byte buffer for the uncom 452 // create (zlib) byte buffer for the uncompressed data 423 auto complen = (uLongf)(fileSize * 4); << 453 uLongf complen = (uLongf)(fileSize * 4); 424 auto uncompdata = new Bytef[complen]; << 454 Bytef* uncompdata = new Bytef[complen]; 425 while (Z_OK != uncompress(uncompdata, &com << 455 while(Z_OK != uncompress(uncompdata, &complen, compdata, fileSize)) >> 456 { 426 // increase uncompressed byte buffer 457 // increase uncompressed byte buffer 427 delete[] uncompdata; 458 delete[] uncompdata; 428 complen *= 2; 459 complen *= 2; 429 uncompdata = new Bytef[complen]; 460 uncompdata = new Bytef[complen]; 430 } 461 } 431 // delete the compressed data buffer 462 // delete the compressed data buffer 432 delete[] compdata; 463 delete[] compdata; 433 // create a string from uncompressed data 464 // create a string from uncompressed data (will be deallocated by caller) 434 dataString = new G4String((char*)uncompdat << 465 dataString = new G4String((char*) uncompdata, (long) complen); 435 // delete the uncompressed data buffer 466 // delete the uncompressed data buffer 436 delete[] uncompdata; 467 delete[] uncompdata; 437 } 468 } 438 else { << 469 else >> 470 { 439 G4ExceptionDescription ed; 471 G4ExceptionDescription ed; 440 ed << "Problem while trying to read " + co 472 ed << "Problem while trying to read " + compfilename + " data file.\n"; 441 G4Exception("G4OpticalSurface::ReadCompres << 473 G4Exception("G4OpticalSurface::ReadCompressedFile", "mat316", >> 474 FatalException, ed); 442 return; 475 return; 443 } 476 } 444 // create the input string stream from the d 477 // create the input string stream from the data string 445 if (dataString != nullptr) { << 478 if(dataString) >> 479 { 446 iss.str(*dataString); 480 iss.str(*dataString); 447 in.close(); 481 in.close(); 448 delete dataString; 482 delete dataString; 449 G4cout << "G4OpticalSurface: data file " < << 483 G4cout << "G4OpticalSurface: data file " << compfilename >> 484 << " successfully read in." << G4endl; 450 } 485 } 451 } 486 } 452 487 453 void G4OpticalSurface::ReadDichroicFile() 488 void G4OpticalSurface::ReadDichroicFile() 454 { 489 { 455 const char* datadir = G4FindDataDir("G4DICHR << 490 const char* datadir = std::getenv("G4DICHROICDATA"); 456 491 457 if (datadir == nullptr) { << 492 if(!datadir) 458 G4Exception("G4OpticalSurface::ReadDichroi << 493 { 459 "Environment variable G4DICHROICDATA not << 494 G4Exception("G4OpticalSurface::ReadDichroicFile()", "mat313", >> 495 FatalException, >> 496 "Environment variable G4DICHROICDATA not defined"); 460 return; 497 return; 461 } 498 } 462 499 463 std::ostringstream ost; 500 std::ostringstream ost; 464 ost << datadir; 501 ost << datadir; 465 std::ifstream fin(ost.str().c_str()); 502 std::ifstream fin(ost.str().c_str()); 466 if (! fin.is_open()) { << 503 if(!fin.is_open()) >> 504 { 467 G4ExceptionDescription ed; 505 G4ExceptionDescription ed; 468 ed << "Dichroic surface data file <" << os << 506 ed << "Dichroic surface data file <" << ost.str().c_str() 469 G4Exception("G4OpticalSurface::ReadDichroi << 507 << "> is not opened!" << G4endl; >> 508 G4Exception("G4OpticalSurface::ReadDichroicFile()", "mat314", >> 509 FatalException, ed, " "); 470 return; 510 return; 471 } 511 } 472 512 473 if (! (DichroicVector->Retrieve(fin))) { << 513 if(!(DichroicVector->Retrieve(fin))) >> 514 { 474 G4ExceptionDescription ed; 515 G4ExceptionDescription ed; 475 ed << "Dichroic surface data file <" << os << 516 ed << "Dichroic surface data file <" << ost.str().c_str() 476 G4Exception("G4OpticalSurface::ReadDichroi << 517 << "> is not opened!" << G4endl; >> 518 G4Exception("G4OpticalSurface::ReadDichroicFile()", "mat315", >> 519 FatalException, ed, " "); 477 return; 520 return; 478 } 521 } 479 522 480 // DichroicVector->SetBicubicInterpolation( 523 // DichroicVector->SetBicubicInterpolation(true); 481 524 482 G4cout << " *** Dichroic surface data file * 525 G4cout << " *** Dichroic surface data file *** " << G4endl; 483 526 484 auto numberOfXNodes = (G4int)DichroicVector- << 527 G4int numberOfXNodes = DichroicVector->GetLengthX(); 485 auto numberOfYNodes = (G4int)DichroicVector- << 528 G4int numberOfYNodes = DichroicVector->GetLengthY(); 486 529 487 G4cout << "numberOfXNodes: " << numberOfXNod 530 G4cout << "numberOfXNodes: " << numberOfXNodes << G4endl; 488 G4cout << "numberOfYNodes: " << numberOfYNod 531 G4cout << "numberOfYNodes: " << numberOfYNodes << G4endl; 489 532 490 if (0 > numberOfXNodes || numberOfXNodes >= << 533 if(0 > numberOfXNodes || numberOfXNodes >= INT_MAX) 491 numberOfXNodes = 0; 534 numberOfXNodes = 0; 492 } << 535 if(0 > numberOfYNodes || numberOfYNodes >= INT_MAX) 493 if (0 > numberOfYNodes || numberOfYNodes >= << 494 numberOfYNodes = 0; 536 numberOfYNodes = 0; 495 } << 496 537 497 G4PV2DDataVector xVector; 538 G4PV2DDataVector xVector; 498 G4PV2DDataVector yVector; 539 G4PV2DDataVector yVector; 499 540 500 xVector.resize(numberOfXNodes, 0.); 541 xVector.resize(numberOfXNodes, 0.); 501 yVector.resize(numberOfYNodes, 0.); 542 yVector.resize(numberOfYNodes, 0.); 502 543 503 for (G4int i = 0; i < numberOfXNodes; ++i) { << 544 for(G4int i = 0; i < numberOfXNodes; ++i) >> 545 { 504 G4cout << "i: " << DichroicVector->GetX(i) 546 G4cout << "i: " << DichroicVector->GetX(i) << G4endl; 505 xVector[i] = DichroicVector->GetX(i); 547 xVector[i] = DichroicVector->GetX(i); 506 } 548 } 507 for (G4int j = 0; j < numberOfYNodes; ++j) { << 549 for(G4int j = 0; j < numberOfYNodes; ++j) >> 550 { 508 G4cout << "j: " << DichroicVector->GetY(j) 551 G4cout << "j: " << DichroicVector->GetY(j) << G4endl; 509 yVector[j] = DichroicVector->GetY(j); 552 yVector[j] = DichroicVector->GetY(j); 510 } 553 } 511 554 512 for (G4int j = 0; j < numberOfYNodes; ++j) { << 555 for(G4int j = 0; j < numberOfYNodes; ++j) 513 for (G4int i = 0; i < numberOfXNodes; ++i) << 556 { 514 G4cout << " i: " << i << " j: " << j << << 557 for(G4int i = 0; i < numberOfXNodes; ++i) >> 558 { >> 559 G4cout << " i: " << i << " j: " << j << " " >> 560 << DichroicVector->GetValue(i, j) << G4endl; 515 } 561 } 516 } 562 } 517 } 563 } 518 564