Geant4 VMC Version 6.6
Loading...
Searching...
No Matches
TG4OpGeometryManager.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Geant4 Virtual Monte Carlo package
3// Copyright (C) 2007 - 2014 Ivana Hrivnacova
4// All rights reserved.
5//
6// For the licensing terms see geant4_vmc/LICENSE.
7// Contact: root-vmc@cern.ch
8//-------------------------------------------------
9
14
16#include "TG4G3ControlVector.h"
17#include "TG4G3CutVector.h"
18#include "TG4G3Units.h"
19#include "TG4GeometryServices.h"
20#include "TG4Globals.h"
21#include "TG4Limits.h"
22#include "TG4Medium.h"
23#include "TG4MediumMap.h"
24
25#include <G4Box.hh>
26#include <G4Cons.hh>
27#include <G4EllipticalTube.hh>
28#include <G4Hype.hh>
29#include <G4LogicalBorderSurface.hh>
30#include <G4LogicalSkinSurface.hh>
31#include <G4LogicalVolume.hh>
32#include <G4Material.hh>
33#include <G4MaterialPropertiesTable.hh>
34#include <G4MaterialTable.hh>
35#include <G4OpticalSurface.hh>
36#include <G4Para.hh>
37#include <G4Polycone.hh>
38#include <G4Polyhedra.hh>
39#include <G4ReflectedSolid.hh>
40#include <G4Sphere.hh>
41#include <G4SystemOfUnits.hh>
42#include <G4Torus.hh>
43#include <G4Transform3D.hh>
44#include <G4Trap.hh>
45#include <G4Trd.hh>
46#include <G4Tubs.hh>
47#include <G4TwistedTrap.hh>
48
49#include <Riostream.h>
50#include <TArrayD.h>
51#include <TString.h>
52
53//_____________________________________________________________________________
55 : TG4Verbose("opGeometryManager"), fGeometryServices(0), fOpSurfaceMap(0)
56{
58
60 if (!fGeometryServices) {
61 TG4Globals::Exception("TG4OpGeometryManager", "TG4OpGeometryManager",
62 "TG4GeometryServices have to be defined first");
63 }
65}
66
67//_____________________________________________________________________________
72
73//
74// private methods
75//
76
77//_____________________________________________________________________________
79 const G4String& propertyName, Double_t value) const
80{
85
86 // clang-format off
87 if (propertyName == "ABSLENGTH" ||
88 propertyName == "RAYLEIGH" ||
89 propertyName == "WLSABSLENGTH" ||
90 propertyName == "WLSABSLENGTH2" ||
91 propertyName == "MIEHG") {
92 return value * TG4G3Units::Length();
93 }
94
95 if (propertyName == "BIRKS_CONSTANT") {
96
98 }
99
100 if (propertyName == "ALPHASCINTILLATIONYIELD" ||
101 propertyName == "DEUTERONSCINTILLATIONYIELD" ||
102 propertyName == "ELECTRONSCINTILLATIONYIELD" ||
103 propertyName == "IONSCINTILLATIONYIELD" ||
104 propertyName == "PROTONSCINTILLATIONYIELD" ||
105 propertyName == "SCINTILLATIONYIELD" ||
106 propertyName == "TRITONSCINTILLATIONYIELD") {
107
108 return value * TG4G3Units::InverseEnergy();
109 }
110
111 if (propertyName == "SCINTILLATIONRISETIME1" ||
112 propertyName == "SCINTILLATIONRISETIME2" ||
113 propertyName == "SCINTILLATIONRISETIME3" ||
114 propertyName == "SCINTILLATIONTIMECONSTANT1" ||
115 propertyName == "SCINTILLATIONTIMECONSTANT2" ||
116 propertyName == "SCINTILLATIONTIMECONSTANT3" ||
117 propertyName == "WLSTIMECONSTANT" ||
118 propertyName == "WLSTIMECONSTANT2") {
119
120 return value * TG4G3Units::Time();
121 }
122
123 if (propertyName == "ISOTHERMAL_COMPRESSIBILITY" ) {
124 return value * std::pow(TG4G3Units::Length(), 3) * TG4G3Units::InverseEnergy();
125 }
126
127 if (propertyName == "ALPHASCINTILLATIONYIELD1" ||
128 propertyName == "ALPHASCINTILLATIONYIELD2" ||
129 propertyName == "ALPHASCINTILLATIONYIELD3" ||
130 propertyName == "DEUTERONCINTILLATIONYIELD1" ||
131 propertyName == "DEUTERONCINTILLATIONYIELD2" ||
132 propertyName == "DEUTERONCINTILLATIONYIELD3" ||
133 propertyName == "ELECTRONINTILLATIONYIELD1" ||
134 propertyName == "ELECTRONINTILLATIONYIELD2" ||
135 propertyName == "ELECTRONINTILLATIONYIELD3" ||
136 propertyName == "IONSCINTILLATIONYIELD1" ||
137 propertyName == "IONSCINTILLATIONYIELD2" ||
138 propertyName == "IONSCINTILLATIONYIELD3" ||
139 propertyName == "PROTONSCINTILLATIONYIELD1" ||
140 propertyName == "PROTONSCINTILLATIONYIELD2" ||
141 propertyName == "PROTONSCINTILLATIONYIELD3" ||
142 propertyName == "RESOLUTIONSCALE" ||
143 propertyName == "SCINTILLATIONCOMPONENT1" ||
144 propertyName == "SCINTILLATIONCOMPONENT2" ||
145 propertyName == "SCINTILLATIONCOMPONENT3" ||
146 propertyName == "SCINTILLATIONYIELD1" ||
147 propertyName == "SCINTILLATIONYIELD2" ||
148 propertyName == "SCINTILLATIONYIELD3" ||
149 propertyName == "TRITONSCINTILLATIONYIELD1" ||
150 propertyName == "TRITONSCINTILLATIONYIELD2" ||
151 propertyName == "TRITONSCINTILLATIONYIELD3" ||
152 propertyName == "RS_SCALE_FACTOR" ||
153 propertyName == "WLSCOMPONENT" ||
154 propertyName == "WLSCOMPONENT2" ||
155 propertyName == "WLSMEANNUMBERPHOTONS" ||
156 propertyName == "WLSMEANNUMBERPHOTONS2" ||
157 propertyName == "MIEHG_BACKWARD" ||
158 propertyName == "MIEHG_FORWARD" ||
159 propertyName == "MIEHG_FORWARD_RATIO" ||
160 propertyName == "BACKSCATTERCONSTANT" ||
161 propertyName == "EFFICIENCY" ||
162 propertyName == "GROUPVEL" || // Check
163 propertyName == "IMAGINARYRINDEX" ||
164 propertyName == "REFLECTIVITY" ||
165 propertyName == "REALRINDEX" ||
166 propertyName == "RINDEX" ||
167 propertyName == "SPECULARLOBECONSTANT" ||
168 propertyName == "SPECULARSPIKECONSTANT" ||
169 propertyName == "SURFACEROUGHNESS" ||
170 propertyName == "TRANSMITTANCE") {
171
172 return value;
173 }
174 // clang-format on
175
176 TString text = "Unknown material property ";
177 text += propertyName.data();
178 text += "x\n";
179 text += "No units conversion performed.";
180 TG4Globals::Warning("TG4OpGeometryManager", "AddUnit", text);
181 return value;
182}
183
184//
185// public methods - TVirtualMC implementation
186//
187
188//_____________________________________________________________________________
189void TG4OpGeometryManager::SetCerenkov(Int_t itmed, Int_t npckov,
190 Float_t* ppckov, Float_t* absco, Float_t* effic, Float_t* rindex,
191 Bool_t aspline, Bool_t rspline)
192{
210
211 G4double* ppckovDbl = fGeometryServices->CreateG4doubleArray(ppckov, npckov);
212 G4double* abscoDbl = fGeometryServices->CreateG4doubleArray(absco, npckov);
213 G4double* efficDbl = fGeometryServices->CreateG4doubleArray(effic, npckov);
214 G4double* rindexDbl = fGeometryServices->CreateG4doubleArray(rindex, npckov);
215
217 itmed, npckov, ppckovDbl, abscoDbl, efficDbl, rindexDbl, aspline, rspline);
218
219 delete[] ppckovDbl;
220 delete[] abscoDbl;
221 delete[] efficDbl;
222 delete[] rindexDbl;
223}
224
225//_____________________________________________________________________________
226void TG4OpGeometryManager::SetCerenkov(Int_t itmed, Int_t npckov,
227 Double_t* ppckov, Double_t* absco, Double_t* /*effic*/, Double_t* rindex,
228 Bool_t aspline, Bool_t rspline)
229{
247
248 // add units and detect if Rindex == 0
249 G4bool isRindex = false;
250 G4double* ppckov2 = fGeometryServices->CreateG4doubleArray(ppckov, npckov);
251 G4double* absco2 = fGeometryServices->CreateG4doubleArray(absco, npckov);
252 for (G4int i = 0; i < npckov; i++) {
253 ppckov2[i] *= TG4G3Units::Energy();
254 absco2[i] *= TG4G3Units::Length();
255 if (rindex[i] != 0.0) isRindex = true;
256 }
257
258 // get material of medium from table
260 if (!medium) {
261 TString text = "Medium ";
262 text += itmed;
263 text += " not found.";
264 TG4Globals::Warning("TG4OpGeometryManager", "SetCerenkov", text);
265 delete[] ppckov2;
266 delete[] absco2;
267 return;
268 }
269 G4Material* material = medium->GetMaterial();
270
271 // get materials properties table or create it if it does not yet
272 // exist
273 G4MaterialPropertiesTable* table = material->GetMaterialPropertiesTable();
274 if (!table) {
275 table = new G4MaterialPropertiesTable();
276 material->SetMaterialPropertiesTable(table);
277 }
278
279 // add material properties into the table
280 table->AddProperty("ABSLENGTH", ppckov2, absco2, npckov, false, aspline);
281 // used in G4OpAbsorption process
282
283 // table->AddProperty("EFFICIENCY", ppckov2, effic, npckov);
284 // EFFICIENCY must be set to optical surfaces
285
286 // Set RINDEX only if defined with non zero values.
287 // The zero value is a Geant3 convention to define material as metal which was
288 // not adopted in Geant4, where 0 values cause unpredicatable behavior in
289 // G4OpBoundary process
290 if (isRindex) {
291 table->AddProperty("RINDEX", ppckov2, rindex, npckov, false, rspline);
292 // used in G4Cerenkov, G4OpRayleigh, G4OpBoundary
293 }
294
295 delete[] ppckov2;
296 delete[] absco2;
297
298 // verbose
299 if (VerboseLevel() > 0) {
300 G4cout << "The tables for UV photon tracking set for "
301 << material->GetName() << G4endl;
302 }
303}
304
305//_____________________________________________________________________________
307 EMCOpSurfaceModel model, EMCOpSurfaceType surfaceType,
308 EMCOpSurfaceFinish surfaceFinish, Double_t sigmaAlpha)
309{
311
312 auto g4Model = fGeometryServices->SurfaceModel(model);
313 auto g4Type = fGeometryServices->SurfaceType(surfaceType);
314 auto g4Finish = fGeometryServices->SurfaceFinish(surfaceFinish);
315 auto surface =
316 new G4OpticalSurface(name, g4Model, g4Finish, g4Type, sigmaAlpha);
317
318 // Store the surface in the map
319 (*fOpSurfaceMap)[name] = surface;
320}
321
322//_____________________________________________________________________________
324 const char* vol1Name, int vol1CopyNo, const char* vol2Name, int vol2CopyNo,
325 const char* opSurfaceName)
326{
328
329 // Get physical volumes
330 G4VPhysicalVolume* pv1 =
331 fGeometryServices->FindPhysicalVolume(vol1Name, vol1CopyNo, true);
332 G4VPhysicalVolume* pv2 =
333 fGeometryServices->FindPhysicalVolume(vol2Name, vol2CopyNo, true);
334
335 if (!pv1 || !pv2) {
336 TString text;
337 if (!pv1) {
338 text = TString("Cannot find physical volume: ") + vol1Name;
339 text += TG4Globals::Endl();
340 }
341 if (!pv2) text += TString("Cannot find physical volume: ") + vol2Name;
342 TG4Globals::Warning("TG4OpGeometryManager", "SetBorderSurface", text);
343 return;
344 }
345
346 // Get the optical surface
347 TG4OpSurfaceMap::iterator it = fOpSurfaceMap->find(opSurfaceName);
348 if (it == fOpSurfaceMap->end()) {
349 TG4Globals::Warning("TG4OpGeometryManager", "SetBorderSurface",
350 TString("Cannot find optical surface: ") + opSurfaceName);
351 return;
352 }
353 G4OpticalSurface* surface = (*it).second;
354
355 // Create the border surface
356 new G4LogicalBorderSurface(name, pv1, pv2, surface);
357}
358
359//_____________________________________________________________________________
361 const char* name, const char* volName, const char* opSurfaceName)
362{
364
365 // Get logical volume
366 G4LogicalVolume* lv = fGeometryServices->FindLogicalVolume(volName, true);
367
368 if (!lv) {
369 TG4Globals::Warning("TG4OpGeometryManager",
370 "SetSkinSurface:", "Cannot find logical volume: " + TString(volName));
371 return;
372 }
373
374 // Get the optical surface
375 TG4OpSurfaceMap::iterator it = fOpSurfaceMap->find(opSurfaceName);
376 if (it == fOpSurfaceMap->end()) {
377 TG4Globals::Warning("TG4OpGeometryManager", "SetBorderSurface",
378 "Cannot find optical surface: " + TString(opSurfaceName));
379 return;
380 }
381 G4OpticalSurface* surface = (*it).second;
382
383 // Create the skin surface
384 new G4LogicalSkinSurface(name, lv, surface);
385}
386
387//_____________________________________________________________________________
389 const char* propertyName, Int_t np, Double_t* pp, Double_t* values,
390 Bool_t createNewKey, Bool_t spline)
391{
393
394 // create material properties table
395 // get material of medium from table
397 if (!medium) {
398 TString text = "Medium ";
399 text += itmed;
400 text += "not found.";
401 TG4Globals::Warning("TG4OpGeometryManager", "SetMaterialProperty", text);
402 return;
403 }
404 G4Material* material = medium->GetMaterial();
405
406 // get materials properties table or create it if it does not yet
407 // exist
408 G4MaterialPropertiesTable* table = material->GetMaterialPropertiesTable();
409 if (!table) {
410 table = new G4MaterialPropertiesTable();
411 material->SetMaterialPropertiesTable(table);
412 }
413
414 // add units
415 G4double* pp2 = fGeometryServices->CreateG4doubleArray(pp, np);
416 G4double* val2 = fGeometryServices->CreateG4doubleArray(values, np);
417 for (G4int i = 0; i < np; i++) {
418 pp2[i] = pp2[i] * TG4G3Units::Energy();
419 val2[i] = AddUnit(propertyName, values[i]);
420 }
421 table->AddProperty(propertyName, pp2, val2, np, createNewKey, spline);
422
423 delete[] pp2;
424 delete[] val2;
425
426 // verbose
427 if (VerboseLevel() > 0) {
428 G4cout << "The material properties " << propertyName << " set for "
429 << material->GetName() << G4endl;
430 }
431}
432
433//_____________________________________________________________________________
435 Int_t itmed, const char* propertyName, Double_t value)
436{
438
439 // create material properties table
440 // get material of medium from table
442 if (!medium) {
443 TString text = "Medium ";
444 text += itmed;
445 text += "not found.";
446 TG4Globals::Warning("TG4OpGeometryManager", "SetMaterialProperty", text);
447 return;
448 }
449 G4Material* material = medium->GetMaterial();
450
451 // get materials properties table or create it if it does not yet
452 // exist
453 G4MaterialPropertiesTable* table = material->GetMaterialPropertiesTable();
454 if (!table) {
455 table = new G4MaterialPropertiesTable();
456 material->SetMaterialPropertiesTable(table);
457 }
458
459 // Add units
460 value = AddUnit(propertyName, value);
461
462 // Birks constant is set in a different way
463 if (G4String(propertyName) == "BIRKS_CONSTANT") {
464 material->GetIonisation()->SetBirksConstant(value);
465 }
466 else {
467 table->AddConstProperty(propertyName, value);
468 }
469
470 // verbose
471 if (VerboseLevel() > 0) {
472 G4cout << "The material property " << propertyName << " set for "
473 << material->GetName() << G4endl;
474 }
475}
476
477//_____________________________________________________________________________
478void TG4OpGeometryManager::SetMaterialProperty(const char* surfaceName,
479 const char* propertyName, Int_t np, Double_t* pp, Double_t* values,
480 Bool_t createNewKey, Bool_t spline)
481{
483
484 // create material properties table
485 // get optical surface from the map
486 // Get the optical surface
487 TG4OpSurfaceMap::iterator it = fOpSurfaceMap->find(surfaceName);
488 if (it == fOpSurfaceMap->end()) {
489 TG4Globals::Warning("TG4OpGeometryManager", "SetMaterialProperty",
490 "Cannot find optical surface: " + TString(surfaceName));
491 return;
492 }
493 G4OpticalSurface* surface = (*it).second;
494
495 // get materials properties table or create it if it does not yet
496 // exist
497 G4MaterialPropertiesTable* table = surface->GetMaterialPropertiesTable();
498 if (!table) {
499 table = new G4MaterialPropertiesTable();
500 surface->SetMaterialPropertiesTable(table);
501 }
502
503 // add units
504 G4double* pp2 = fGeometryServices->CreateG4doubleArray(pp, np);
505 G4double* val2 = fGeometryServices->CreateG4doubleArray(values, np);
506 for (G4int i = 0; i < np; i++) {
507 pp2[i] = pp2[i] * TG4G3Units::Energy();
508 val2[i] = AddUnit(propertyName, values[i]);
509 }
510 table->AddProperty(propertyName, pp2, val2, np, createNewKey, spline);
511 delete[] pp2;
512 delete[] val2;
513
514 // verbose
515 if (VerboseLevel() > 0) {
516 G4cout << "The material properties " << propertyName
517 << " set for optical surface " << surface->GetName() << G4endl;
518 }
519}
520
521//_____________________________________________________________________________
522void TG4OpGeometryManager::Gfmate(Int_t imat, char* name, Float_t& a,
523 Float_t& z, Float_t& dens, Float_t& radl, Float_t& absl, Float_t* ubuf,
524 Int_t& nbuf)
525{
527
528 G4double da, dz, ddens, dradl, dabsl;
529 Double_t dubuf[100];
530 Gfmate(imat, name, da, dz, ddens, dradl, dabsl, dubuf, nbuf);
531
532 a = da;
533 z = dz;
534 dens = ddens;
535 radl = dradl;
536 absl = dabsl;
537 for (Int_t i = 0; i < nbuf; i++) ubuf[i] = dubuf[i];
538}
539
540//_____________________________________________________________________________
541void TG4OpGeometryManager::Gfmate(Int_t imat, char* name, Double_t& a,
542 Double_t& z, Double_t& dens, Double_t& radl, Double_t& absl,
543 Double_t* /*ubuf*/, Int_t& nbuf)
544{
546
547 TG4Globals::Warning("TG4OpGeometryManager", "Gfmate",
548 "Deprecated function - now replaced with GetMaterial(Int_t imat, ...)");
549
550 G4Material* material = G4Material::GetMaterialTable()->at(imat - 1);
551
552 if (material) {
553 const char* chName = material->GetName();
554 strcpy(name, chName);
555 a = fGeometryServices->GetEffA(material);
556 z = fGeometryServices->GetEffZ(material);
557
558 dens = material->GetDensity();
559 dens /= TG4G3Units::MassDensity();
560
561 radl = material->GetRadlen();
562 radl /= TG4G3Units::Length();
563
564 // the following parameters are not defined in Geant4
565 absl = 0.;
566 nbuf = 0;
567 }
568 else {
569 TString text = "Material ";
570 text += imat;
571 text += " has not been found.";
572 TG4Globals::Exception("TG4OpGeometryManager", "Gfmate", text);
573 }
574}
575
576//_____________________________________________________________________________
577Bool_t TG4OpGeometryManager::GetMaterial(Int_t imat, TString& name, Double_t& a,
578 Double_t& z, Double_t& density, Double_t& radl, Double_t& inter, TArrayD& par)
579{
582
583 G4Material* material = G4Material::GetMaterialTable()->at(imat - 1);
584
585 if (!material) {
586 TString text = "Material ";
587 text += imat;
588 text += " has not been found.";
589 TG4Globals::Warning("TG4OpGeometryManager", "GetMaterial", text);
590 return false;
591 }
592
593 name = material->GetName();
594 a = fGeometryServices->GetEffA(material);
595 z = fGeometryServices->GetEffZ(material);
596
597 density = material->GetDensity();
598 density /= TG4G3Units::MassDensity();
599
600 radl = material->GetRadlen();
601 radl /= TG4G3Units::Length();
602
603 inter = 0.; // TO DO: check how to get this
604 par.Set(0);
605 return true;
606}
Definition of the TG4G3ControlVector class.
Definition of the TG4G3CutVector class.
Definition of the TG4G3Units class.
Definition of the TG4GeometryServices class.
Definition of the TG4Globals class and basic container types.
Definition of the TG4Limits class.
Definition of the TG4MediumMap class.
Definition of the TG4Medium class.
Definition of the TG4OpGeometryManager class.
static G4double Energy()
Definition TG4G3Units.h:105
static G4double Length()
Definition TG4G3Units.h:81
static G4double InverseEnergy()
Definition TG4G3Units.h:157
static G4double Time()
Definition TG4G3Units.h:93
static G4double MassDensity()
Definition TG4G3Units.h:117
G4OpticalSurfaceFinish SurfaceFinish(EMCOpSurfaceFinish finish) const
G4double * CreateG4doubleArray(Float_t *array, G4int size, G4bool copyValues=true) const
G4LogicalVolume * FindLogicalVolume(const G4String &name, G4bool silent=false) const
static TG4GeometryServices * Instance()
G4SurfaceType SurfaceType(EMCOpSurfaceType surfType) const
G4VPhysicalVolume * FindPhysicalVolume(const G4String &name, G4int copyNo, G4bool silent=false) const
G4double GetEffA(G4Material *material) const
G4OpticalSurfaceModel SurfaceModel(EMCOpSurfaceModel model) const
TG4MediumMap * GetMediumMap() const
TG4OpSurfaceMap * GetOpSurfaceMap() const
G4double GetEffZ(G4Material *material) const
static void Warning(const TString &className, const TString &methodName, const TString &text)
static void Exception(const TString &className, const TString &methodName, const TString &text)
static TString Endl()
Definition TG4Globals.h:100
TG4Medium * GetMedium(G4int mediumID, G4bool warn=true) const
Helper class to keep medium data.
Definition TG4Medium.h:29
G4Material * GetMaterial() const
Definition TG4Medium.h:94
virtual void SetCerenkov(Int_t itmed, Int_t npckov, Float_t *ppckov, Float_t *absco, Float_t *effic, Float_t *rindex, Bool_t aspline, Bool_t rspline)
virtual Bool_t GetMaterial(Int_t imat, TString &name, Double_t &a, Double_t &z, Double_t &density, Double_t &radl, Double_t &inter, TArrayD &par)
TG4OpSurfaceMap * fOpSurfaceMap
map of optical surfaces names to their objects
virtual void SetMaterialProperty(Int_t itmed, const char *propertyName, Int_t np, Double_t *pp, Double_t *values, Bool_t createNewKey, Bool_t spline)
virtual void Gfmate(Int_t imat, char *name, Float_t &a, Float_t &z, Float_t &dens, Float_t &radl, Float_t &absl, Float_t *ubuf, Int_t &nbuf)
virtual void SetSkinSurface(const char *name, const char *volName, const char *opSurfaceName)
TG4GeometryServices * fGeometryServices
geometry services
Double_t AddUnit(const G4String &propertyName, Double_t value) const
virtual void SetBorderSurface(const char *name, const char *vol1Name, int vol1CopyNo, const char *vol2Name, int vol2CopyNo, const char *opSurfaceName)
virtual void DefineOpSurface(const char *name, EMCOpSurfaceModel model, EMCOpSurfaceType surfaceType, EMCOpSurfaceFinish surfaceFinish, Double_t sigmaAlpha)
Base class for defining the verbose level and a common messenger.
Definition TG4Verbose.h:36
virtual G4int VerboseLevel() const
Definition TG4Verbose.h:78