6 #include "G4RunManager.hh"
7 #include "G4UnitsTable.hh"
8 #include "G4IntersectionSolid.hh"
11 #include "G4SDManager.hh"
12 #include "G4Material.hh"
13 #include "G4MaterialTable.hh"
14 #include "G4Polyhedra.hh"
15 #include "G4BREPSolidPolyhedra.hh"
16 #include "G4LogicalVolume.hh"
17 #include "G4PVPlacement.hh"
18 #include "G4PVParameterised.hh"
19 #include "G4OpticalSurface.hh"
20 #include "G4LogicalBorderSurface.hh"
21 #include "G4ThreeVector.hh"
22 #include "G4VisAttributes.hh"
24 #include "Randomize.hh"
26 using namespace TelescopeSimulatorLX;
27 using namespace CLHEP;
31 fTelescopeName(telescopeName)
32 fMirrorDataFile(mirrorDataFile)
34 const G4String eyeName = fTelescopeName.substr(0, 2);
38 else if (eyeName ==
"LM")
40 else if (eyeName ==
"LA")
42 else if (eyeName ==
"CO")
45 G4Exception(
"Error in FDsimG4Mirror !!! Unknown telescope.");
47 fMotherPhysicalVolume = mother;
51 const eTelescope eTelescopeName = GeteTelescope(fTelescopeName);
52 ReadMirrorSegmentPositions(eTelescopeName, fMirrorDataFile.c_str());
62 delete[] m_MirrorParams;
69 G4cerr <<
" ================================================================\n"
70 " = Mirror parameters\n"
72 " = Mirror parameters for telescope " << fTelescopeName <<
" read from:\n"
73 " = " << fMirrorDataFile <<
"\n"
75 " ================================================================" << G4endl;
82 const G4RunManager*
const runManager = G4RunManager::GetRunManager();
93 G4SDManager*
const sdManager = G4SDManager::GetSDMpointer();
95 sdManager->AddNewDetector(mirrorSD);
99 G4double fReflectivity[NUM] = { 0 };
100 G4double fPhotonEnergy[NUM] = { 0, 10*
eV };
105 const G4double& sigma_alpha = mirrorRoughness.
Sigma_alpha;
106 const vector<G4double>& wavelength = mirrorRoughness.
Wavelength;
107 const vector<G4double>& specularSpike = mirrorRoughness.
SpecularSpike;
108 const vector<G4double>& specularLobe = mirrorRoughness.
SpecularLobe;
109 const vector<G4double>& backscatter = mirrorRoughness.
Backscatter;
116 const eTelescope eTelescopeName = GeteTelescope(fTelescopeName);
118 const G4int seed = eTelescopeName;
119 const G4int luxury = 3;
120 RanluxEngine myRanluxEngine(seed, luxury);
121 RandGauss GaussDist(myRanluxEngine);
123 for (G4int i = 0; i < fNumOfMirrors; ++i) {
124 char szaux[100] =
"";
125 sprintf(szaux,
"MirrorOpticalSurface_%02i", i);
126 G4OpticalSurface*
const opticalAirMirror =
new G4OpticalSurface(szaux);
128 opticalAirMirror->SetModel(unified);
129 opticalAirMirror->SetType(dielectric_metal);
130 opticalAirMirror->SetFinish(polished);
132 for (G4int j = 0; j < NUM; ++j)
133 fReflectivity[j] = m_MirrorParams[i].fReflec375 / 100;
135 G4MaterialPropertiesTable*
const mirrorMPT =
new G4MaterialPropertiesTable();
136 mirrorMPT->AddProperty(
"REFLECTIVITY", fPhotonEnergy, fReflectivity, NUM);
138 if (MirrorReflectionType ==
"Diffusive") {
139 opticalAirMirror->SetFinish(ground);
140 opticalAirMirror->SetSigmaAlpha(sigma_alpha);
142 mirrorMPT->AddProperty(
"SPECULARSPIKECONSTANT",
new G4MaterialPropertyVector());
143 mirrorMPT->AddProperty(
"SPECULARLOBECONSTANT",
new G4MaterialPropertyVector());
144 mirrorMPT->AddProperty(
"BACKSCATTERCONSTANT",
new G4MaterialPropertyVector());
146 for (
unsigned iwl = 0, n = wavelength.size(); iwl < n; ++iwl) {
147 const G4double energy = h_Planck * c_light / wavelength[iwl];
148 mirrorMPT->AddEntry(
"SPECULARSPIKECONSTANT", energy, specularSpike[iwl]);
149 mirrorMPT->AddEntry(
"SPECULARLOBECONSTANT", energy, specularLobe[iwl]);
150 mirrorMPT->AddEntry(
"BACKSCATTERCONSTANT", energy, backscatter[iwl]);
155 opticalAirMirror->SetMaterialPropertiesTable(MirrorMPT);
159 G4LogicalVolume*
const mirrorSegment_log = mirrorSegment->
GetLogicalVolume();
160 mirrorSegment_log->SetOptimisation(
false);
164 const G4double elevation = m_MirrorParams[i].fVertAnglePos*
deg;
165 const G4double azimuth = m_MirrorParams[i].fHorzAnglePos*
deg;
167 const G4double xRotAngle = (elevation < 0) ? -90.0*
deg : 90.0*
deg;
169 const G4double deltaElevation = GaussDist.fire(0, mirrorSegmentTiltSigma);
170 const G4double deltaAzimuth = GaussDist.fire(0, mirrorSegmentTiltSigma);
172 G4RotationMatrix mirrorRot;
173 mirrorRot.rotateX(xRotAngle);
174 mirrorRot.rotateZ(-elevation + deltaElevation);
175 mirrorRot.rotateY(azimuth + deltaAzimuth);
177 if (VerbosityLevel > 0 && mirrorSegmentTiltSigma > 0) {
178 G4cerr <<
"Mirror " << i <<
" tilted by (elevation, azimuth) "
179 << deltaElevation/
deg <<
" (deg) "
180 << deltaAzimuth/
deg <<
" (deg) "
186 G4RotationMatrix vectorRot;
187 vectorRot.rotateZ(-elevation);
188 vectorRot.rotateY(azimuth);
189 const G4double thickness = mirrorSegment->
GetThickness();
190 G4ThreeVector mirrorPos(m_MirrorParams[i].fRadius + thickness/2, 0, 0);
191 mirrorPos = vectorRot * mirrorPos;
193 sprintf(szaux,
"MirrorSegment_%02i", i+1);
194 const G4Transform3D transform(mirrorRot, mirrorPos);
196 sprintf(szaux,
"MirrorLogicalBorderSurface_%02i", i);
198 #if (G4VERSION_NUMBER >= 900)
200 G4PVPlacement*
const mirrorSegment_phys =
201 new G4PVPlacement(transform, szaux, MirrorSegment_log, fMotherPhysicalVolume,
false, ++numOfCopy);
202 if (VerbosityLevel > 2)
203 mirrorSegment_phys->CheckOverlaps(10000);
206 if (useSD && mirrorSD)
207 mirrorSegment_log->SetSensitiveDetector(mirrorSD);
211 if (verbosityLevel > 0) {
212 G4cerr <<
"==== Mirror Surface properties ====\n"
213 "==== Mirror Reflection type : " << MirrorReflectionType <<
"====" << G4endl;
214 if (mirrorReflectionType ==
"Diffusive") {
215 G4cerr <<
"==== sigma_alpha = " << sigma_alpha/
deg <<
" deg. ====\n"
216 "==== Parameters vs wavelength (Wl (nm) \t SpecularSpike \t SpecularLobe \t Backscatter) ====" << G4endl;
217 for (
unsigned int i = 0, n = wavelength.size(); i < n; ++i) {
218 G4cerr << wavelength[i]/nm <<
'\t'
219 << specularSpike[i] <<
'\t'
220 << specularLobe[i] <<
'\t'
232 const int nMirrorCnt = fNumOfMirrors;
235 stringstream errorstr;
236 if ((nMirrorCnt = reader.
ReadMirrorParams(eTelescopeName)) != fNumOfMirrors) {
237 errorstr <<
" Reading of mirror params from file " << fMirrorDataFile <<
" failed !!!\n"
238 <<
"(info read for " << nMirrorCnt <<
" mirror segments, " << fNumOfMirrors <<
" required for this telescope.)";
239 G4Exception(errorstr.str());
241 G4cerr <<
"read mirror params success - " << nMirrorCnt <<
" items readed" << G4endl;
243 if (!reader.
GetMirrorParams(m_MirrorParams, nMirrorCnt) || nMirrorCnt != fNumOfMirrors) {
244 G4cerr <<
"Get mirror params failed" << G4endl;
246 G4cerr <<
"Get mirror params success, " << nMirrorCnt <<
" items added" << G4endl;
255 if (telescopeName ==
"LL1")
257 else if (telescopeName ==
"LL2")
259 else if (telescopeName ==
"LL3")
261 else if (telescopeName ==
"LL4")
263 else if (telescopeName ==
"LL5")
265 else if (telescopeName ==
"LL6")
267 else if (telescopeName ==
"LM1")
269 else if (telescopeName ==
"LM2")
271 else if (telescopeName ==
"LM3")
273 else if (telescopeName ==
"LM4")
275 else if (telescopeName ==
"LM5")
277 else if (telescopeName ==
"LM6")
279 else if (telescopeName ==
"LA1")
281 else if (telescopeName ==
"LA2")
283 else if (telescopeName ==
"LA3")
285 else if (telescopeName ==
"LA4")
287 else if (telescopeName ==
"LA5")
289 else if (telescopeName ==
"LA6")
291 else if (telescopeName ==
"CO1")
293 else if (telescopeName ==
"CO2")
295 else if (telescopeName ==
"CO3")
297 else if (telescopeName ==
"CO4")
299 else if (telescopeName ==
"CO5")
301 else if (telescopeName ==
"CO6")
304 return eTelescopeName;
std::vector< G4double > Backscatter
std::vector< G4double > SpecularSpike
G4double fMirrorSegmentTiltSigma
MIRRORPARAMS * PMIRRORPARAMS
G4LogicalVolume * GetLogicalVolume() const
std::vector< G4double > SpecularLobe
SurfaceRoughness fMirrorRoughness
std::vector< G4double > Wavelength
virtual G4int ReadMirrorParams(eTelescope eTelescopeName)
void ReadMirrorSegmentPositions(const eTelescope eTelescopeName, const char *const szFilename)
G4bool GetMirrorParams(PMIRRORPARAMS pparams, G4int &nParamsCnt)
G4double GetThickness() const
G4bool fUseSensitiveDetectors
G4String fMirrorReflectionType
eTelescope GeteTelescope(const G4String &telescopeName)