Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 delete[] AngularDistribution;
60 AngularDistribution =
61 new G4float[incidentIndexMax * thetaIndexMax * phiIndexMax];
62 *(AngularDistribution) = *(right.AngularDistribution);
63
64 delete[] AngularDistributionLUT;
65 AngularDistributionLUT = new G4float[indexmax];
66 *(AngularDistributionLUT) = *(right.AngularDistributionLUT);
67
68 delete[] Reflectivity;
69 Reflectivity = new G4float[RefMax];
70 *(Reflectivity) = *(right.Reflectivity);
71
72 delete DichroicVector;
73 DichroicVector = new G4Physics2DVector();
74 *DichroicVector = *(right.DichroicVector);
75 }
76 return *this;
77}
78
82 G4SurfaceType type, G4double value)
83 : G4SurfaceProperty(name, type)
84 , theModel(model)
85 , theFinish(finish)
86 , theMaterialPropertiesTable(nullptr)
87{
88 AngularDistribution = nullptr;
89
90 AngularDistributionLUT = nullptr;
91 Reflectivity = nullptr;
92
93 DichroicVector = nullptr;
94
95 switch(theModel)
96 {
97 case glisur:
98 polish = value;
99 sigma_alpha = 0.0;
100 break;
101 case LUT:
102 case dichroic:
103 case DAVIS:
104 ReadDataFile();
105 // fall through
106 case unified:
107 sigma_alpha = value;
108 polish = 0.0;
109 break;
110 default:
111 G4Exception("G4OpticalSurface::G4OpticalSurface()", "mat309",
112 FatalException, "Constructor called with INVALID model.");
113 }
114}
115
117{
118 delete[] AngularDistribution;
119
120 delete[] AngularDistributionLUT;
121
122 delete[] Reflectivity;
123
124 delete DichroicVector;
125}
126
128 : G4SurfaceProperty(right.theName, right.theType)
129{
130 *this = right;
131 this->theName = right.theName;
132 this->theType = right.theType;
133 this->theModel = right.theModel;
134 this->theFinish = right.theFinish;
135 this->sigma_alpha = right.sigma_alpha;
136 this->polish = right.polish;
137 this->theMaterialPropertiesTable = right.theMaterialPropertiesTable;
138
139 delete[] AngularDistribution;
140 this->AngularDistribution =
141 new G4float[incidentIndexMax * thetaIndexMax * phiIndexMax];
142 *(this->AngularDistribution) = *(right.AngularDistribution);
143
144 delete[] AngularDistributionLUT;
145 this->AngularDistributionLUT = new G4float[indexmax];
146 *(this->AngularDistributionLUT) = *(right.AngularDistributionLUT);
147
148 delete[] Reflectivity;
149 this->Reflectivity = new G4float[RefMax];
150 *(this->Reflectivity) = *(right.Reflectivity);
151
152 delete DichroicVector;
153 this->DichroicVector = new G4Physics2DVector();
154 *(this->DichroicVector) = *(right.DichroicVector);
155}
156
158{
159 return (this == (G4OpticalSurface*) &right);
160}
161
163{
164 return (this != (G4OpticalSurface*) &right);
165}
166
167G4int G4OpticalSurface::GetInmax() const { return indexmax; }
168
169G4int G4OpticalSurface::GetLUTbins() const { return LUTbins; }
170
171G4int G4OpticalSurface::GetRefMax() const { return RefMax; }
172
173G4int G4OpticalSurface::GetThetaIndexMax() const { return thetaIndexMax; }
174
175G4int G4OpticalSurface::GetPhiIndexMax() const { return phiIndexMax; }
176
178{
179 // Dump info for surface
180
181 G4cout << " Surface type = " << G4int(theType) << G4endl
182 << " Surface finish = " << G4int(theFinish) << G4endl
183 << " Surface model = " << G4int(theModel) << G4endl << G4endl
184 << " Surface parameter " << G4endl << " ----------------- "
185 << G4endl;
186
187 if(theModel == glisur)
188 {
189 G4cout << " polish: " << polish << G4endl;
190 }
191 else
192 {
193 G4cout << " sigma_alpha: " << sigma_alpha << G4endl;
194 }
195 G4cout << G4endl;
196}
197
199{
200 theType = type;
201 ReadDataFile();
202}
203
205{
206 theFinish = finish;
207 ReadDataFile();
208}
209
211{
212 // type and finish can be set in either order. Thus, we can't check
213 // for consistency. Need to read file on setting either type or finish.
214 switch(theType)
215 {
216 case dielectric_LUT:
217 if(AngularDistribution == nullptr)
218 {
219 AngularDistribution =
220 new G4float[incidentIndexMax * thetaIndexMax * phiIndexMax];
221 }
222 ReadLUTFile();
223 break;
225 if(AngularDistributionLUT == nullptr)
226 {
227 AngularDistributionLUT = new G4float[indexmax];
228 }
230
231 if(Reflectivity == nullptr)
232 {
233 Reflectivity = new G4float[RefMax];
234 }
236 break;
238 if(DichroicVector == nullptr)
239 {
240 DichroicVector = new G4Physics2DVector();
241 }
243 break;
244 default:
245 break;
246 }
247}
248
250{
251 G4String readLUTFileName;
252
253 switch(theFinish)
254 {
256 readLUTFileName = "PolishedLumirrorGlue.z";
257 break;
259 readLUTFileName = "PolishedLumirror.z";
260 break;
262 readLUTFileName = "PolishedTeflon.z";
263 break;
264 case polishedtioair:
265 readLUTFileName = "PolishedTiO.z";
266 break;
267 case polishedtyvekair:
268 readLUTFileName = "PolishedTyvek.z";
269 break;
271 readLUTFileName = "PolishedVM2000Glue.z";
272 break;
274 readLUTFileName = "PolishedVM2000.z";
275 break;
277 readLUTFileName = "EtchedLumirrorGlue.z";
278 break;
280 readLUTFileName = "EtchedLumirror.z";
281 break;
282 case etchedteflonair:
283 readLUTFileName = "EtchedTeflon.z";
284 break;
285 case etchedtioair:
286 readLUTFileName = "EtchedTiO.z";
287 break;
288 case etchedtyvekair:
289 readLUTFileName = "EtchedTyvek.z";
290 break;
291 case etchedvm2000glue:
292 readLUTFileName = "EtchedVM2000Glue.z";
293 break;
294 case etchedvm2000air:
295 readLUTFileName = "EtchedVM2000.z";
296 break;
298 readLUTFileName = "GroundLumirrorGlue.z";
299 break;
301 readLUTFileName = "GroundLumirror.z";
302 break;
303 case groundteflonair:
304 readLUTFileName = "GroundTeflon.z";
305 break;
306 case groundtioair:
307 readLUTFileName = "GroundTiO.z";
308 break;
309 case groundtyvekair:
310 readLUTFileName = "GroundTyvek.z";
311 break;
312 case groundvm2000glue:
313 readLUTFileName = "GroundVM2000Glue.z";
314 break;
315 case groundvm2000air:
316 readLUTFileName = "GroundVM2000.z";
317 break;
318 default:
319 return;
320 }
321
322 std::istringstream iss;
323 ReadCompressedFile(readLUTFileName, iss);
324
325 size_t idxmax = incidentIndexMax * thetaIndexMax * phiIndexMax;
326 for(size_t i = 0; i < idxmax; ++i)
327 {
328 iss >> AngularDistribution[i];
329 }
330 G4cout << "LUT - data file: " << readLUTFileName << " read in! " << G4endl;
331}
332
334{
335 G4String readLUTDAVISFileName;
336
337 switch(theFinish)
338 {
339 case Rough_LUT:
340 readLUTDAVISFileName = "Rough_LUT.z";
341 break;
342 case RoughTeflon_LUT:
343 readLUTDAVISFileName = "RoughTeflon_LUT.z";
344 break;
345 case RoughESR_LUT:
346 readLUTDAVISFileName = "RoughESR_LUT.z";
347 break;
349 readLUTDAVISFileName = "RoughESRGrease_LUT.z";
350 break;
351 case Polished_LUT:
352 readLUTDAVISFileName = "Polished_LUT.z";
353 break;
355 readLUTDAVISFileName = "PolishedTeflon_LUT.z";
356 break;
357 case PolishedESR_LUT:
358 readLUTDAVISFileName = "PolishedESR_LUT.z";
359 break;
361 readLUTDAVISFileName = "PolishedESRGrease_LUT.z";
362 break;
363 case Detector_LUT:
364 readLUTDAVISFileName = "Detector_LUT.z";
365 break;
366 default:
367 return;
368 }
369
370 std::istringstream iss;
371 ReadCompressedFile(readLUTDAVISFileName, iss);
372
373 for(size_t i = 0; i < indexmax; ++i)
374 {
375 iss >> AngularDistributionLUT[i];
376 }
377 G4cout << "LUT DAVIS - data file: " << readLUTDAVISFileName << " read in! "
378 << G4endl;
379}
380
382{
383 G4String readReflectivityLUTFileName;
384
385 switch(theFinish)
386 {
387 case Rough_LUT:
388 readReflectivityLUTFileName = "Rough_LUTR.z";
389 break;
390 case RoughTeflon_LUT:
391 readReflectivityLUTFileName = "RoughTeflon_LUTR.z";
392 break;
393 case RoughESR_LUT:
394 readReflectivityLUTFileName = "RoughESR_LUTR.z";
395 break;
397 readReflectivityLUTFileName = "RoughESRGrease_LUTR.z";
398 break;
399 case Polished_LUT:
400 readReflectivityLUTFileName = "Polished_LUTR.z";
401 break;
403 readReflectivityLUTFileName = "PolishedTeflon_LUTR.z";
404 break;
405 case PolishedESR_LUT:
406 readReflectivityLUTFileName = "PolishedESR_LUTR.z";
407 break;
409 readReflectivityLUTFileName = "PolishedESRGrease_LUTR.z";
410 break;
411 case Detector_LUT:
412 readReflectivityLUTFileName = "Detector_LUTR.z";
413 break;
414 default:
415 return;
416 }
417
418 std::istringstream iss;
419 ReadCompressedFile(readReflectivityLUTFileName, iss);
420
421 for(size_t i = 0; i < RefMax; ++i)
422 {
423 iss >> Reflectivity[i];
424 }
425 G4cout << "LUT DAVIS - reflectivity data file: "
426 << readReflectivityLUTFileName << " read in! " << G4endl;
427}
428
429// uncompress one data file into the input string stream
431 std::istringstream& iss)
432{
433 G4String* dataString = nullptr;
434 G4String path = G4FindDataDir("G4REALSURFACEDATA");
435 G4String compfilename = path + "/" + filename;
436 // create input stream with binary mode operation and position at end of file
437 std::ifstream in(compfilename, std::ios::binary | std::ios::ate);
438 if(in.good())
439 {
440 // get current position in the stream (was set to the end)
441 G4int fileSize = (G4int)in.tellg();
442 // set current position being the beginning of the stream
443 in.seekg(0, std::ios::beg);
444 // create (zlib) byte buffer for the data
445 Bytef* compdata = new Bytef[fileSize];
446 while(in)
447 {
448 in.read((char*) compdata, fileSize);
449 }
450 // create (zlib) byte buffer for the uncompressed data
451 uLongf complen = (uLongf)(fileSize * 4);
452 Bytef* uncompdata = new Bytef[complen];
453 while(Z_OK != uncompress(uncompdata, &complen, compdata, fileSize))
454 {
455 // increase uncompressed byte buffer
456 delete[] uncompdata;
457 complen *= 2;
458 uncompdata = new Bytef[complen];
459 }
460 // delete the compressed data buffer
461 delete[] compdata;
462 // create a string from uncompressed data (will be deallocated by caller)
463 dataString = new G4String((char*) uncompdata, (long) complen);
464 // delete the uncompressed data buffer
465 delete[] uncompdata;
466 }
467 else
468 {
470 ed << "Problem while trying to read " + compfilename + " data file.\n";
471 G4Exception("G4OpticalSurface::ReadCompressedFile", "mat316",
472 FatalException, ed);
473 return;
474 }
475 // create the input string stream from the data string
476 if(dataString != nullptr)
477 {
478 iss.str(*dataString);
479 in.close();
480 delete dataString;
481 G4cout << "G4OpticalSurface: data file " << compfilename
482 << " successfully read in." << G4endl;
483 }
484}
485
487{
488 const char* datadir = G4FindDataDir("G4DICHROICDATA");
489
490 if(datadir == nullptr)
491 {
492 G4Exception("G4OpticalSurface::ReadDichroicFile()", "mat313",
494 "Environment variable G4DICHROICDATA not defined");
495 return;
496 }
497
498 std::ostringstream ost;
499 ost << datadir;
500 std::ifstream fin(ost.str().c_str());
501 if(!fin.is_open())
502 {
504 ed << "Dichroic surface data file <" << ost.str().c_str()
505 << "> is not opened!" << G4endl;
506 G4Exception("G4OpticalSurface::ReadDichroicFile()", "mat314",
507 FatalException, ed, " ");
508 return;
509 }
510
511 if(!(DichroicVector->Retrieve(fin)))
512 {
514 ed << "Dichroic surface data file <" << ost.str().c_str()
515 << "> is not opened!" << G4endl;
516 G4Exception("G4OpticalSurface::ReadDichroicFile()", "mat315",
517 FatalException, ed, " ");
518 return;
519 }
520
521 // DichroicVector->SetBicubicInterpolation(true);
522
523 G4cout << " *** Dichroic surface data file *** " << G4endl;
524
525 G4int numberOfXNodes = (G4int)DichroicVector->GetLengthX();
526 G4int numberOfYNodes = (G4int)DichroicVector->GetLengthY();
527
528 G4cout << "numberOfXNodes: " << numberOfXNodes << G4endl;
529 G4cout << "numberOfYNodes: " << numberOfYNodes << G4endl;
530
531 if(0 > numberOfXNodes || numberOfXNodes >= INT_MAX)
532 {
533 numberOfXNodes = 0;
534 }
535 if(0 > numberOfYNodes || numberOfYNodes >= INT_MAX)
536 {
537 numberOfYNodes = 0;
538 }
539
540 G4PV2DDataVector xVector;
541 G4PV2DDataVector yVector;
542
543 xVector.resize(numberOfXNodes, 0.);
544 yVector.resize(numberOfYNodes, 0.);
545
546 for(G4int i = 0; i < numberOfXNodes; ++i)
547 {
548 G4cout << "i: " << DichroicVector->GetX(i) << G4endl;
549 xVector[i] = DichroicVector->GetX(i);
550 }
551 for(G4int j = 0; j < numberOfYNodes; ++j)
552 {
553 G4cout << "j: " << DichroicVector->GetY(j) << G4endl;
554 yVector[j] = DichroicVector->GetY(j);
555 }
556
557 for(G4int j = 0; j < numberOfYNodes; ++j)
558 {
559 for(G4int i = 0; i < numberOfXNodes; ++i)
560 {
561 G4cout << " i: " << i << " j: " << j << " "
562 << DichroicVector->GetValue(i, j) << G4endl;
563 }
564 }
565}
const char * G4FindDataDir(const char *)
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
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
G4int GetLUTbins() const
void DumpInfo() const
void SetType(const G4SurfaceType &type) override
G4int GetThetaIndexMax() const
G4bool operator==(const G4OpticalSurface &right) const
G4OpticalSurface & operator=(const G4OpticalSurface &right)
void ReadCompressedFile(const G4String &, std::istringstream &)
G4OpticalSurface(const G4OpticalSurface &right)
G4int GetPhiIndexMax() const
G4bool operator!=(const G4OpticalSurface &right) const
~G4OpticalSurface() override
G4int GetRefMax() const
G4int GetInmax() const
void SetFinish(const G4OpticalSurfaceFinish)
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
#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