ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4OpticalSurface.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4OpticalSurface.cc
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 //
29 // Optical Surface Class Implementation
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 // mail: gum@triumf.ca
40 
41 #include <iostream>
42 #include <fstream>
43 
44 //#include "G4ios.hh"
45 #include "globals.hh"
46 #include "G4OpticalSurface.hh"
47 
49 // Class Implementation
51 
53  // Operators
55 
57 {
58  if (this != &right)
59  {
60  theName = right.theName;
61  theType = right.theType;
62  theModel = right.theModel;
63  theFinish = right.theFinish;
64  sigma_alpha = right.sigma_alpha;
65  polish = right.polish;
67 
72 
76 
77  if (Reflectivity) delete [] Reflectivity;
79  *(Reflectivity) = *(right.Reflectivity);
80 
81  if (DichroicVector) delete DichroicVector;
83  *DichroicVector = *(right.DichroicVector);
84  }
85  return *this;
86 }
87 
89  // Constructors
91 
95  G4SurfaceType type,
97  : G4SurfaceProperty(name,type),
98  theModel(model),
99  theFinish(finish),
100  theMaterialPropertiesTable(0)
101 {
102  if ( model == glisur ){
103  polish = value;
104  sigma_alpha = 0.0;
105  }
106  else if ( model == unified ) {
107  sigma_alpha = value;
108  polish = 0.0;
109  }
110  else if ( model == LUT ) {
111  sigma_alpha = value;
112  polish = 0.0;
113  }
114  else if ( model == dichroic ) {
115  sigma_alpha = value;
116  polish = 0.0;
117  }
118  else if ( model == DAVIS ) {
119  sigma_alpha = value;
120  polish = 0.0;
121  }
122  else {
123  G4Exception("G4OpticalSurface::G4OpticalSurface()", "mat309",
125  "Constructor called with INVALID model.");
126  }
127 
128  AngularDistribution = NULL;
129 
130  AngularDistributionLUT = NULL;
131  Reflectivity = NULL;
132 
133  DichroicVector = NULL;
134 
135  if (type == dielectric_LUT) {
138  ReadLUTFile();
139  }
140 
141  if (type == dielectric_LUTDAVIS) {
144 
145  Reflectivity = new G4float[RefMax];
147  }
148 
149  if (type == dielectric_dichroic) {
152  }
153 }
154 
156 {
158 
160  if (Reflectivity) delete [] Reflectivity;
161 
162  if (DichroicVector) delete DichroicVector;
163 }
164 
166  : G4SurfaceProperty(right.theName,right.theType)
167 {
168  *this = right;
169  this->theName = right.theName;
170  this->theType = right.theType;
171  this->theModel = right.theModel;
172  this->theFinish = right.theFinish;
173  this->sigma_alpha = right.sigma_alpha;
174  this->polish = right.polish;
176 
177  if (this->AngularDistribution) delete [] AngularDistribution;
178  this->AngularDistribution =
180  *(this->AngularDistribution) = *(right.AngularDistribution);
181 
182  if (this->AngularDistributionLUT) delete [] AngularDistributionLUT;
185  if (this->Reflectivity) delete [] Reflectivity;
186  this->Reflectivity = new G4float[RefMax];
187  *(this->Reflectivity) = *(right.Reflectivity);
188 
189  if (this->DichroicVector) delete DichroicVector;
190  this->DichroicVector = new G4Physics2DVector();
191  *(this->DichroicVector) = *(right.DichroicVector);
192 }
193 
195 {
196  return (this == (G4OpticalSurface *) &right);
197 }
198 
200 {
201  return (this != (G4OpticalSurface *) &right);
202 }
204  // Methods
206 
208 {
209  return indexmax;
210 }
211 
213 {
214  return LUTbins;
215 }
216 
218 {
219  return RefMax;
220 }
221 
223 {
224  return thetaIndexMax;
225 }
226 
228 {
229  return phiIndexMax;
230 }
231 
233 {
234  // Dump info for surface
235 
236  G4cout <<
237  " Surface type = " << G4int(theType) << G4endl <<
238  " Surface finish = " << G4int(theFinish) << G4endl <<
239  " Surface model = " << G4int(theModel) << G4endl;
240 
241  G4cout << G4endl;
242 
243  G4cout << " Surface parameter " << G4endl;
244  G4cout << " ----------------- " << G4endl;
245  if (theModel == glisur ){
246  G4cout << polish << G4endl;
247  }
248  else if (theModel == LUT ){
249  G4cout << sigma_alpha << G4endl;
250  }
251  else {
252  G4cout << sigma_alpha << G4endl;
253  }
254  G4cout << G4endl;
255 }
256 
258 {
259  theType = type;
260 
261  if (type == dielectric_LUTDAVIS) {
263  new G4float[indexmax];
265  }
266 
267  if (type == dielectric_LUT) {
270 
271  ReadLUTFile();
272  }
273  if (type == dielectric_dichroic) {
276  }
277 }
278 
280 {
281  theFinish = finish;
282  if (theType == dielectric_LUT) {
285  ReadLUTFile();
286  }
287 
288  if (theType == dielectric_LUTDAVIS) {
290  new G4float[indexmax];
292 
295  }
296 
297  if (theType == dielectric_dichroic) {
300  }
301 }
302 
304 {
305  G4String readLUTFileName = " ";
306 
308  readLUTFileName = "PolishedLumirrorGlue.dat";
309  }
310  else if (theFinish == polishedlumirrorair) {
311  readLUTFileName = "PolishedLumirror.dat";
312  }
313  else if (theFinish == polishedteflonair) {
314  readLUTFileName = "PolishedTeflon.dat";
315  }
316  else if (theFinish == polishedtioair) {
317  readLUTFileName = "PolishedTiO.dat";
318  }
319  else if (theFinish == polishedtyvekair) {
320  readLUTFileName = "PolishedTyvek.dat";
321  }
322  else if (theFinish == polishedvm2000glue) {
323  readLUTFileName = "PolishedVM2000Glue.dat";
324  }
325  else if (theFinish == polishedvm2000air) {
326  readLUTFileName = "PolishedVM2000.dat";
327  }
328  else if (theFinish == etchedlumirrorglue) {
329  readLUTFileName = "EtchedLumirrorGlue.dat";
330  }
331  else if (theFinish == etchedlumirrorair) {
332  readLUTFileName = "EtchedLumirror.dat";
333  }
334  else if (theFinish == etchedteflonair) {
335  readLUTFileName = "EtchedTeflon.dat";
336  }
337  else if (theFinish == etchedtioair) {
338  readLUTFileName = "EtchedTiO.dat";
339  }
340  else if (theFinish == etchedtyvekair) {
341  readLUTFileName = "EtchedTyvek.dat";
342  }
343  else if (theFinish == etchedvm2000glue) {
344  readLUTFileName = "EtchedVM2000Glue.dat";
345  }
346  else if (theFinish == etchedvm2000air) {
347  readLUTFileName = "EtchedVM2000.dat";
348  }
349  else if (theFinish == groundlumirrorglue) {
350  readLUTFileName = "GroundLumirrorGlue.dat";
351  }
352  else if (theFinish == groundlumirrorair) {
353  readLUTFileName = "GroundLumirror.dat";
354  }
355  else if (theFinish == groundteflonair) {
356  readLUTFileName = "GroundTeflon.dat";
357  }
358  else if (theFinish == groundtioair) {
359  readLUTFileName = "GroundTiO.dat";
360  }
361  else if (theFinish == groundtyvekair) {
362  readLUTFileName = "GroundTyvek.dat";
363  }
364  else if (theFinish == groundvm2000glue) {
365  readLUTFileName = "GroundVM2000Glue.dat";
366  }
367  else if (theFinish == groundvm2000air) {
368  readLUTFileName = "GroundVM2000.dat";
369  }
370 
371  if (readLUTFileName == " ") return;
372 
373  char* path = std::getenv("G4REALSURFACEDATA");
374  if (!path) {
375  G4String excep =
376  "G4OpBoundaryProcess - G4REALSURFACEDATA environment variable not set";
377  G4Exception("G4OpticalSurface::ReadLUTFile()", "mat310",
378  FatalException, excep);
379  return;
380  }
381  G4String pathString(path);
382 
383  readLUTFileName = pathString + "/" + readLUTFileName;
384 
385  std::ifstream readLUTFileHandle(readLUTFileName, std::ios::in);
386 
387  if (readLUTFileHandle) {
389  for (G4int i = 0; i<idxmax; i++) {
390  if (readLUTFileHandle.eof()) break;
391  readLUTFileHandle >> AngularDistribution[i];
392  }
393  if (!readLUTFileHandle.bad()) {
394  G4cout <<"LUT - data file: "<< readLUTFileName <<" read in! "<< G4endl;
395  }
396  else {
397  G4String excep="LUT - data file: "+readLUTFileName+" not read propery";
398  G4Exception("G4OpticalSurface::ReadLUTFile()", "mat312",
399  FatalException, excep);
400  return;
401  }
402  }
403  else {
404  G4String excep ="LUT - data file: "+readLUTFileName+" not found";
405  G4Exception("G4OpticalSurface::ReadLUTFile()", "mat311",
406  FatalException, excep);
407  return;
408  }
409  readLUTFileHandle.close();
410 }
411 
413 {
414  G4String readLUTDAVISFileName = " ";
415 
416  if (theFinish == Rough_LUT) {
417  readLUTDAVISFileName = "Rough_LUT.dat";
418  }else if (theFinish == RoughTeflon_LUT) {
419  readLUTDAVISFileName = "RoughTeflon_LUT.dat";
420  }else if (theFinish == RoughESR_LUT) {
421  readLUTDAVISFileName = "RoughESR_LUT.dat";
422  }else if (theFinish == RoughESRGrease_LUT) {
423  readLUTDAVISFileName = "RoughESRGrease_LUT.dat";
424  }else if (theFinish == Polished_LUT) {
425  readLUTDAVISFileName = "Polished_LUT.dat";
426  }else if (theFinish == PolishedTeflon_LUT) {
427  readLUTDAVISFileName = "PolishedTeflon_LUT.dat";
428  }else if (theFinish == PolishedESR_LUT) {
429  readLUTDAVISFileName = "PolishedESR_LUT.dat";
430  }else if (theFinish == PolishedESRGrease_LUT) {
431  readLUTDAVISFileName = "PolishedESRGrease_LUT.dat";
432  }else if (theFinish == Detector_LUT) {
433  readLUTDAVISFileName = "Detector_LUT.dat";
434  }
435 
436  if (readLUTDAVISFileName == " ") return;
437 
438  char* path = std::getenv("G4REALSURFACEDATA");
439  if (!path) {
440  G4String excep =
441  "G4OpBoundaryProcess - G4REALSURFACEDATA environment variable not set";
442  G4Exception("G4OpticalSurface::ReadLUTDAVISFile()", "mat310",
443  FatalException, excep);
444  return;
445  }
446  G4String pathString(path);
447 
448  readLUTDAVISFileName = pathString + "/" + readLUTDAVISFileName;
449 
450  std::ifstream readLUTDAVISFileHandle(readLUTDAVISFileName, std::ios::in);
451 
452  if (readLUTDAVISFileHandle) {
453 
454  for (G4int i = 0; i<indexmax; i++) {
455  if (readLUTDAVISFileHandle.eof()) break;
456  readLUTDAVISFileHandle >> AngularDistributionLUT[i];
457  }
458  if (!readLUTDAVISFileHandle.bad()) {
459  G4cout <<"LUT DAVIS - data file: " <<
460  readLUTDAVISFileName << " read in! " << G4endl;
461  }
462  else {
463  G4String excep="LUT DAVIS- data file: "+readLUTDAVISFileName+" not read propery";
464  G4Exception("G4OpticalSurface::ReadLUTFile()", "mat312",
465  FatalException, excep);
466  return;
467  }
468  }
469  else {
470  G4String excep ="LUT DAVIS- data file: "+readLUTDAVISFileName+" not found";
471  G4Exception("G4OpticalSurface::ReadLUTFile()", "mat311",
472  FatalException, excep);
473  return;
474  }
475  readLUTDAVISFileHandle.close();
476 }
477 
479 {
480  G4String readReflectivityLUTFileName = " ";
481 
482  if (theFinish == Rough_LUT) {
483  readReflectivityLUTFileName = "Rough_LUTR.dat";
484  }
485  if (theFinish == RoughTeflon_LUT) {
486  readReflectivityLUTFileName = "RoughTeflon_LUTR.dat";
487  }
488  if (theFinish== RoughESR_LUT) {
489  readReflectivityLUTFileName = "RoughESR_LUTR.dat";
490  }
491  if (theFinish == RoughESRGrease_LUT) {
492  readReflectivityLUTFileName = "RoughESRGrease_LUTR.dat";
493  }
494  if (theFinish== Polished_LUT) {
495  readReflectivityLUTFileName = "Polished_LUTR.dat";
496  }
497  if (theFinish == PolishedTeflon_LUT) {
498  readReflectivityLUTFileName = "PolishedTeflon_LUTR.dat";
499  }
500  if (theFinish== PolishedESR_LUT) {
501  readReflectivityLUTFileName = "PolishedESR_LUTR.dat";
502  }
504  readReflectivityLUTFileName = "PolishedESRGrease_LUTR.dat";
505  }
506  if (theFinish== Detector_LUT) {
507  readReflectivityLUTFileName = "Detector_LUTR.dat";
508  }
509 
510  if (readReflectivityLUTFileName == " ") return;
511 
512  char* path = std::getenv("G4REALSURFACEDATA");
513  if (!path) {
514  G4String excep =
515  "G4OpBoundaryProcess - G4REALSURFACEDATA environment variable not set";
516  G4Exception("G4OpticalSurface::ReadReflectivityLUTFile()", "mat310",
517  FatalException, excep);
518  return;
519  }
520  G4String pathString(path);
521 
522  readReflectivityLUTFileName = pathString + "/" + readReflectivityLUTFileName;
523 
524  std::ifstream readReflectivityLUTFileHandle(readReflectivityLUTFileName,
525  std::ios::in);
526 
527  if (readReflectivityLUTFileHandle) {
528  for (G4int i = 0; i<RefMax; i++) {
529  if (readReflectivityLUTFileHandle.eof()) break;
530  readReflectivityLUTFileHandle >> Reflectivity[i];
531  }
532  if (!readReflectivityLUTFileHandle.bad()) {
533  G4cout << "Reflectivity LUT DAVIS - data file: " <<
534  readReflectivityLUTFileName << " read in! " << G4endl;
535  }
536  else {
537  G4String excep="Reflectivity LUT DAVIS- data file: "+readReflectivityLUTFileName+" not read propery";
538  G4Exception("G4OpticalSurface::ReadReflectivityLUTFile()", "mat312",
539  FatalException, excep);
540  return;
541  }
542  }
543  else {
544  G4String excep ="Reflectivity LUT DAVIS - data file: "+readReflectivityLUTFileName+" not found";
545  G4Exception("G4OpticalSurface::ReadReflectivityLUTFile()", "mat311",
546  FatalException, excep);
547  return;
548  }
549  readReflectivityLUTFileHandle.close();
550 }
551 
553 {
554  const char* datadir = std::getenv("G4DICHROICDATA");
555 
556  if(!datadir) {
557  G4Exception("G4OpticalSurface::ReadDichroicFile()","mat313",
558  FatalException,"Environment variable G4DICHROICDATA not defined");
559  return;
560  }
561 
562  std::ostringstream ost;
563  ost << datadir;
564  std::ifstream fin(ost.str().c_str());
565  if( !fin.is_open()) {
567  ed << "Dichroic surface data file <" << ost.str().c_str()
568  << "> is not opened!" << G4endl;
569  G4Exception("G4OpticalSurface::ReadDichroicFile()","mat314",
570  FatalException,ed," ");
571  return;
572  }
573 
574  if( !(DichroicVector->Retrieve(fin)) ) {
576  ed << "Dichroic surface data file <" << ost.str().c_str()
577  << "> is not opened!" << G4endl;
578  G4Exception("G4OpticalSurface::ReadDichroicFile()","mat315",
579  FatalException,ed," ");
580  return;
581  }
582 
583 // DichroicVector->SetBicubicInterpolation(true);
584 
585  G4cout << " *** Dichroic surface data file *** " << G4endl;
586 
587  G4int numberOfXNodes = DichroicVector->GetLengthX();
588  G4int numberOfYNodes = DichroicVector->GetLengthY();
589 
590  G4cout << "numberOfXNodes: " << numberOfXNodes << G4endl;
591  G4cout << "numberOfYNodes: " << numberOfYNodes << G4endl;
592 
593  if (0 > numberOfXNodes || numberOfXNodes >= INT_MAX) numberOfXNodes = 0;
594  if (0 > numberOfYNodes || numberOfYNodes >= INT_MAX) numberOfYNodes = 0;
595 
596  G4PV2DDataVector xVector;
597  G4PV2DDataVector yVector;
598 
599  xVector.resize(numberOfXNodes,0.);
600  yVector.resize(numberOfYNodes,0.);
601 
602  for(G4int i = 0; i<numberOfXNodes; ++i) {
603  G4cout << "i: " << DichroicVector->GetX(i) << G4endl;
604  xVector[i] = DichroicVector->GetX(i);
605  }
606  for(G4int j = 0; j<numberOfYNodes; ++j) {
607  G4cout << "j: " << DichroicVector->GetY(j) << G4endl;
608  yVector[j] = DichroicVector->GetY(j);
609  }
610 
611  for(G4int j = 0; j<numberOfYNodes; ++j) {
612  for(G4int i = 0; i<numberOfXNodes; ++i) {
613  G4cout << " i: " << i << " j: " << j << " "
614  << DichroicVector->GetValue(i,j) << G4endl;
615  }
616  }
617 
618 // G4int idx, idy;
619 
620 // for(G4int j = 0; j<numberOfYNodes-1; ++j) {
621 // G4double y = (yVector[j] + yVector[j+1])/2.;
622 // for(G4int i = 0; i<numberOfXNodes-1; ++i) {
623 // G4double x = (xVector[i] + xVector[i+1])/2.;
624 // G4cout << " x: " << x << " y: " << y << " "
625 // << DichroicVector->Value(x,y,idx,idy) << G4endl;
626 // }
627 // }
628 
629 }