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