Geant4 VMC Version 6.8
Loading...
Searching...
No Matches
TG4GeometryServices.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
15#include "TG4GeometryServices.h"
16#include "TG4G3ControlVector.h"
17#include "TG4G3Units.h"
18#include "TG4Globals.h"
19#include "TG4IntMap.h"
20#include "TG4Limits.h"
21#include "TG4Medium.h"
22#include "TG4MediumMap.h"
23#include "TG4NameMap.h"
24
25#include <G4Element.hh>
26#include <G4LogicalVolume.hh>
27#include <G4LogicalVolumeStore.hh>
28#include <G4Material.hh>
29#include <G4MaterialPropertiesTable.hh>
30#include <G4MaterialPropertyVector.hh>
31#include <G4PhysicalVolumeStore.hh>
32#include <G4UserLimits.hh>
33#include <G4VPhysicalVolume.hh>
34#ifdef USE_G3TOG4
35#include <G3EleTable.hh>
36#include <G3toG4.hh>
37#endif
38
39#include "Riostream.h"
40#include <TGeoMatrix.h>
41
42#ifdef USE_VGM
43#include "RootGM/volumes/Placement.h"
44#endif
45
46// Moved after Root includes to avoid shadowed variables
47// generated from short units names
48#include <G4SystemOfUnits.hh>
49
50#include <algorithm>
51#include <cstdlib>
52#include <iomanip>
53#include <math.h>
54#include <vector>
55
58const G4double TG4GeometryServices::fgkAZTolerance = 0.001;
59const G4double TG4GeometryServices::fgkDensityTolerance = 0.005;
60
61//_____________________________________________________________________________
63 : TG4Verbose("geometryServices"),
64 fIsG3toG4(false),
65 fMediumMap(0),
67 fWorld(0),
71{
73
74 if (fgInstance) {
75 TG4Globals::Exception("TG4GeometryServices", "TG4GeometryServices",
76 "Cannot create two instances of singleton.");
77 }
78
81
82 fgInstance = this;
83}
84
85//_____________________________________________________________________________
94
95//
96// private methods
97//
98
99#ifdef USE_G3TOG4
100//_____________________________________________________________________________
101G4bool TG4GeometryServices::IsG3Volume(const G4String& lvName) const
102{
106
107 if (G4StrUtil::contains(lvName, gSeparator))
108 return false;
109 else
110 return true;
111}
112
113//_____________________________________________________________________________
115 G4double /*a*/, G4double z, const G4Element* element) const
116{
119
120 G4double ae = element->GetA() * TG4G3Units::InverseAtomicWeight();
121 G4double ze = element->GetZ();
122
123 // g3tog4 can redefine A
124 G4double ax;
125 if (z < 1) {
126 // vacuum
127 ax = 1.01 * g / mole;
128 }
129 else
130 ax = G3Ele.GetEle(z)->GetA() * TG4G3Units::InverseAtomicWeight();
131
132 if (std::abs(ax - ae) < fgkAZTolerance && std::abs(z - ze) < fgkAZTolerance)
133 return true;
134 else
135 return false;
136}
137#else
138//_____________________________________________________________________________
139G4bool TG4GeometryServices::IsG3Volume(const G4String& /*lvName*/) const
140{
144
145 return false;
146}
147
148//_____________________________________________________________________________
150 G4double /*a*/, G4double /*z*/, const G4Element* /*element*/) const
151{
154
155 return false;
156}
157#endif
158
159//_____________________________________________________________________________
161 G4int nofElements, G4double density, const G4Material* material) const
162{
165
166 G4double dm = material->GetDensity() * TG4G3Units::InverseMassDensity();
167 G4int ne = material->GetNumberOfElements();
168
169 // density percentual difference
170 G4double diff = std::abs(density - dm) / (density + dm) * 2.;
171
172 if (nofElements == ne && diff < fgkDensityTolerance)
173 return true;
174 else
175 return false;
176}
177
178//_____________________________________________________________________________
180 G4int nmat, G4double* a, G4double* wmat) const
181{
185
186 G4double* weight = new G4double[abs(nmat)];
187
188 if (nmat < 0) {
189 G4double aMol = 0.;
190 G4int i;
191 for (i = 0; i < abs(nmat); i++) {
192 // total molecular weight
193 aMol += wmat[i] * a[i];
194 }
195 if (aMol == 0.) {
196 TG4Globals::Warning("TG4GeometryServices", "ConvertAtomWeight",
197 "Total molecular weight = 0.");
198 }
199 for (i = 0; i < abs(nmat); i++) {
200 // weight fractions
201 weight[i] = wmat[i] * a[i] / aMol;
202 }
203 }
204 else
205 for (G4int j = 0; j < nmat; j++) weight[j] = wmat[j];
206
207 return weight;
208}
209
210//
211// public methods
212//
213
214//_____________________________________________________________________________
216{
219
220 fAssemblyLevels.clear();
222
223 // Do nothing if accounting assembly levels is switched off
224 if (!fAccountAssemblyLevels) return;
225
226#ifdef USE_VGM
227 if (!RootGM::Placement::GetIncludeAssembliesInNames()) return;
228 const char prefix = RootGM::Placement::GetNamePrefix();
229 const char separator = RootGM::Placement::GetNameSeparator();
230
231 const G4PhysicalVolumeStore* store = G4PhysicalVolumeStore::GetInstance();
232 G4int maxId = -1;
233 for (G4VPhysicalVolume* pv : *store)
234 maxId = std::max(maxId, pv->GetInstanceID());
235 if (maxId < 0) return;
236 fAssemblyLevels.resize(maxId + 1);
237
238 for (G4VPhysicalVolume* pv : *store) {
239 const G4String& name = pv->GetName();
240 if (name.size() < 2 || name[0] != prefix) continue;
241
242 TG4AssemblyLevels levels;
243 for (std::size_t start = 1; start <= name.size();) {
244 const std::size_t sep = name.find(separator, start);
245 levels.fNames.push_back(name.substr(
246 start, sep == G4String::npos ? G4String::npos : sep - start));
247 levels.fCopyNos.push_back(-1);
248 if (sep == G4String::npos) break;
249 start = sep + 1;
250 }
251 if (levels.fNames.size() < 2) continue;
252
253 // every component but the last is a collapsed node named "<volume>_<copyNo>"
254 for (std::size_t i = 0; i + 1 < levels.fNames.size(); ++i) {
255 G4String& part = levels.fNames[i];
256 const std::size_t us = part.rfind('_');
257 if (us == G4String::npos || us + 1 >= part.size()) continue;
258 if (part.find_first_not_of("0123456789", us + 1) != G4String::npos) continue;
259 levels.fCopyNos[i] = std::atoi(part.c_str() + us + 1);
260 part.resize(us);
261 }
262 fAssemblyLevels[pv->GetInstanceID()] = levels;
263 }
264
265 if (VerboseLevel() > 1) {
266 G4cout << "### AssemblyLevels constructed." << G4endl;
267 }
268#endif
269}
270
271//_____________________________________________________________________________
273 const G4VPhysicalVolume* pv) const
274{
275 static const TG4AssemblyLevels kNone;
276
278 return kNone;
279 }
280
281 const G4int id = pv->GetInstanceID();
282 if (id < 0 || id >= G4int(fAssemblyLevels.size())) return kNone;
283
284 return fAssemblyLevels[id];
285}
286
287//_____________________________________________________________________________
289 Float_t* array, G4int size, G4bool copyValues) const
290{
293
294 G4double* doubleArray;
295 if (size > 0) {
296 doubleArray = new G4double[size];
297 if (copyValues) {
298 for (G4int i = 0; i < size; i++) doubleArray[i] = array[i];
299 }
300 }
301 else {
302 doubleArray = 0;
303 }
304 return doubleArray;
305}
306
307//_____________________________________________________________________________
309 Double_t* array, G4int size, G4bool copyValues) const
310{
313
314 G4double* doubleArray;
315 if (size > 0) {
316 doubleArray = new G4double[size];
317 if (copyValues) {
318 for (G4int i = 0; i < size; i++) doubleArray[i] = array[i];
319 }
320 }
321 else {
322 doubleArray = 0;
323 }
324 return doubleArray;
325}
326
327//_____________________________________________________________________________
328G4String TG4GeometryServices::CutName(const char* name) const
329{
331
332 G4String cutName = name;
333 G4int i = cutName.length();
334 while (cutName[--i] == ' ') cutName = cutName.substr(0, i);
335
336 return cutName;
337}
338
339//_____________________________________________________________________________
340G4String TG4GeometryServices::CutMaterialName(const char* name) const
341{
343
344 G4String cutName = name;
345 cutName = cutName.substr(0, cutName.find('$'));
346
347 return CutName(cutName);
348}
349
350//_____________________________________________________________________________
352 const G4String& volumePath, G4String& volName, G4int& copyNo) const
353{
355
356 G4String path(volumePath);
357
358 G4int npos1 = path.find('/');
359 G4int npos2 = path.find('_');
360 G4int npos3 = path.find('/', 2);
361 if (npos3 < 0) npos3 = path.length();
362
363 volName = path.substr(npos1 + 1, npos2 - npos1 - 1);
364 G4String copyNoStr = path.substr(npos2 + 1, npos3 - npos2);
365 std::istringstream in(copyNoStr);
366 in >> copyNo;
367
368 return path.substr(npos3, path.length() - npos3);
369}
370
371//_____________________________________________________________________________
372const G4String& TG4GeometryServices::UserVolumeName(const G4String& name) const
373{
376
377#ifdef USE_G3TOG4
378 if (fIsG3toG4 && G4StrUtil::contains(name, gSeparator)) {
379 fgBuffer = name.substr(0, name.find(gSeparator));
380 return fgBuffer;
381 }
382 else {
383 return name;
384 }
385#else
386 return name;
387#endif
388}
389
390//_____________________________________________________________________________
392 EMCOpSurfaceModel model) const
393{
395
396 // clang-format off
397 switch (model) {
398 case kGlisur: return glisur;
399 case kUnified: return unified;
400 case kLUT: return LUT;
401 case kDAVIS: return DAVIS;
402 case kdichroic: return dichroic;
403 // clang-format on
404 default:
405 TG4Globals::Warning("TG4GeometryServices", "SurfaceModel",
406 "Unknown optical surface model, return Glisur.");
407 return glisur;
408 }
409}
410
411//_____________________________________________________________________________
412G4SurfaceType TG4GeometryServices::SurfaceType(EMCOpSurfaceType surfType) const
413{
415
416 // clang-format off
417 switch (surfType) {
418 case kDielectric_metal: return dielectric_metal;
419 case kDielectric_dielectric: return dielectric_dielectric;
420 case kDielectric_LUT: return dielectric_LUT;
421 case kDielectric_LUTDAVIS: return dielectric_LUTDAVIS;
422 case kDielectric_dichroic: return dielectric_dichroic;
423 case kFirsov: return firsov;
424 case kXray: return x_ray;
425 // clang-format on
426 default:
427 TG4Globals::Warning("TG4GeometryServices", "SurfaceType",
428 "Unknown optical surface type, return dielectric_metal.");
429 return dielectric_metal;
430 }
431}
432
433//_____________________________________________________________________________
435 EMCOpSurfaceFinish finish) const
436{
438
439 // clang-format off
440 switch (finish) {
441 case kPolished: return polished;
442 case kPolishedfrontpainted: return polishedfrontpainted;
443 case kPolishedbackpainted: return polishedbackpainted;
444 //
445 case kGround: return ground;
446 case kGroundfrontpainted: return groundfrontpainted;
447 case kGroundbackpainted: return groundbackpainted;
448 //
449 case kPolishedlumirrorair: return polishedlumirrorair;
450 case kPolishedlumirrorglue: return polishedlumirrorglue;
451 //
452 case kPolishedair: return polishedair;
453 case kPolishedteflonair: return polishedteflonair;
454 case kPolishedtioair: return polishedtioair;
455 case kPolishedtyvekair: return polishedtyvekair;
456 case kPolishedvm2000air: return polishedvm2000air;
457 case kPolishedvm2000glue: return polishedvm2000glue;
458 //
459 case kEtchedlumirrorair: return etchedlumirrorair;
460 case kEtchedlumirrorglue: return etchedlumirrorglue;
461 case kEtchedair: return etchedair;
462 case kEtchedteflonair: return etchedteflonair;
463 case kEtchedtioair: return etchedtioair;
464 case kEtchedtyvekair: return etchedtyvekair;
465 case kEtchedvm2000air: return etchedvm2000air;
466 case kEtchedvm2000glue: return etchedvm2000glue;
467 case kGroundlumirrorair: return groundlumirrorair;
468 case kGroundlumirrorglue: return groundlumirrorglue;
469 case kGroundair: return groundair;
470 case kGroundteflonair: return groundteflonair;
471 case kGroundtioair: return groundtioair;
472 case kGroundtyvekair: return groundtyvekair;
473 case kGroundvm2000air: return groundvm2000air;
474 case kGroundvm2000glue: return groundvm2000glue;
475 //
476 case kRough_LUT: return Rough_LUT;
477 case kRoughTeflon_LUT: return RoughTeflon_LUT;
478 case kRoughESR_LUT: return RoughESR_LUT;
479 case kRoughESRGrease_LUT: return RoughESRGrease_LUT;
480 //
481 case kPolished_LUT: return Polished_LUT;
482 case kPolishedTeflon_LUT: return PolishedTeflon_LUT;
483 case kPolishedESR_LUT: return PolishedESR_LUT;
484 case kPolishedESRGrease_LUT: return PolishedESRGrease_LUT;
485 //
486 case kDetector_LUT: return Detector_LUT;
487 // clang-format on
488 default:
489 TG4Globals::Warning("TG4GeometryServices", "SurfaceFinish",
490 "Unknown optical surface finish, return polished.");
491 return polished;
492 }
493}
494
495//_____________________________________________________________________________
497 const G4Transform3D& transform, TGeoHMatrix& matrix) const
498{
500
501 Double_t* translation = new Double_t[3];
502 Double_t* rotation = new Double_t[9];
503 for (G4int i = 0; i < 3; i++)
504 for (G4int j = 0; j < 3; j++) {
505 rotation[i * 3 + j] = transform(i, j);
506 translation[i] = transform(i, 3) / cm;
507 }
508 matrix.SetTranslation(translation);
509 matrix.SetRotation(rotation);
510 delete[] translation;
511 delete[] rotation;
512}
513
514//_____________________________________________________________________________
515G4Material* TG4GeometryServices::MixMaterials(G4String name, G4double density,
516 const TG4StringVector& matNames, const TG4doubleVector& matWeights)
517{
519
520 // number of materials to be mixed
521 G4int nofMaterials = matNames.size();
522 if (nofMaterials != G4int(matWeights.size())) {
523 TG4Globals::Exception("TG4GeometryServices", "MixMaterials",
524 "Different number of material names and weigths.");
525 }
526
527 if (VerboseLevel() > 1) {
528 G4cout << "Nof of materials to be mixed: " << nofMaterials << G4endl;
529 }
530
531 // fill vector of materials
532 std::vector<G4Material*> matVector;
533 G4int im;
534 for (im = 0; im < nofMaterials; im++) {
535 // material
536 G4Material* material = G4Material::GetMaterial(matNames[im]);
537 matVector.push_back(material);
538 }
539
540 // create the mixed material
541 G4Material* mixture = new G4Material(name, density, nofMaterials);
542 for (im = 0; im < nofMaterials; im++) {
543 G4Material* material = matVector[im];
544 G4double fraction = matWeights[im];
545 mixture->AddMaterial(material, fraction);
546 }
547
548 return mixture;
549}
550
551//_____________________________________________________________________________
552void TG4GeometryServices::PrintLimits(const G4String& name) const
553{
555
556 TG4Limits* limits = FindLimits(name, true);
557
558 if (limits) limits->Print();
559}
560
561//_____________________________________________________________________________
562void TG4GeometryServices::PrintVolumeLimits(const G4String& volumeName) const
563{
566
567 G4LogicalVolume* lv = FindLogicalVolume(volumeName, false);
568
569 if (lv) {
570 TG4Limits* limits = GetLimits(lv->GetUserLimits());
571 G4cout << volumeName << " ";
572 if (limits)
573 limits->Print();
574 else
575 G4cout << "has not the limits set." << G4endl;
576 }
577}
578
579//_____________________________________________________________________________
580void TG4GeometryServices::PrintStatistics(G4bool open, G4bool close) const
581{
583
584 if (open) TG4Globals::PrintStars(true);
585
586 G4cout << " GEANT4 Geometry statistics: " << G4endl << " "
587 << std::setw(5) << NofG4LogicalVolumes() << " logical volumes"
588 << G4endl << " " << std::setw(5) << NofG4PhysicalVolumes()
589 << " physical volumes" << G4endl << " " << std::setw(5)
590 << G4Material::GetNumberOfMaterials() << " materials" << G4endl
591 << " " << std::setw(5) << TG4Limits::GetNofLimits()
592 << " user limits" << G4endl;
593
594 if (close) TG4Globals::PrintStars(false);
595}
596
597//_____________________________________________________________________________
599{
601
602 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
603
604 G4cout << "Logical volume store: " << G4endl;
605
606 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
607
608 G4LogicalVolume* lv = (*lvStore)[i];
609
610 void* address = lv->GetMaterial();
611 G4cout << "Logical volume: " << G4endl;
612 G4cout << " " << std::setw(5) << i << " " << lv << " " << lv->GetName()
613 << " " << std::setw(5) << lv->GetNoDaughters() << " daughters"
614 << " limits: " << lv->GetUserLimits()
615 << " material: " << lv->GetMaterial()->GetName() << " " << address
616 << G4endl;
617
618 for (size_t j = 0; j < lv->GetNoDaughters(); j++) {
619 void* addressd = lv->GetDaughter(j)->GetLogicalVolume()->GetMaterial();
620 G4cout << " Daughter: " << std::setw(5) << j << " "
621 << lv->GetDaughter(j) << " " << lv->GetDaughter(j)->GetName()
622 << " of LV: " << lv->GetDaughter(j)->GetLogicalVolume() << " "
623 << lv->GetDaughter(j)->GetLogicalVolume()->GetName()
624 << " copy no: " << lv->GetDaughter(j)->GetCopyNo()
625 << " material: "
626 << lv->GetDaughter(j)->GetLogicalVolume()->GetMaterial()->GetName()
627 << " " << addressd << G4endl;
628 }
629 }
630}
631
632//_____________________________________________________________________________
634{
636
637 G4PhysicalVolumeStore* pvStore = G4PhysicalVolumeStore::GetInstance();
638
639 for (G4int i = 0; i < G4int(pvStore->size()); i++) {
640 G4VPhysicalVolume* pv = (*pvStore)[i];
641 G4cout << i << "th volume name=" << pv->GetName()
642 << " g3name=" << UserVolumeName(pv->GetName())
643 << " copyNo=" << pv->GetCopyNo() << G4endl;
644 }
645}
646
647//_____________________________________________________________________________
649{
651
652 const G4ElementTable* elementTable = G4Element::GetElementTable();
653
654 G4cout << "Element table: " << G4endl;
655
656 for (G4int i = 0; i < G4int(elementTable->size()); i++) {
657
658 G4Element* element = (*elementTable)[i];
659 G4cout << " " << std::setw(5) << i << "th element:"
660 << " " << element << G4endl;
661 }
662}
663
664//_____________________________________________________________________________
666{
668
669 // Dump materials
670 const G4MaterialTable* matTable = G4Material::GetMaterialTable();
671 G4cout << *matTable;
672}
673
674//_____________________________________________________________________________
676{
678
679 // Dump material properties tables
680 // associated with materials
681 const G4MaterialTable* matTable = G4Material::GetMaterialTable();
682 for (G4int i = 0; i < G4int(matTable->size()); i++) {
683 if ((*matTable)[i] && (*matTable)[i]->GetMaterialPropertiesTable()) {
684
685 G4cout << (*matTable)[i]->GetName()
686 << " material properties table: " << G4endl;
687 (*matTable)[i]->GetMaterialPropertiesTable()->DumpTable();
688 }
689 }
690
691 // Dump material properties tables
692 // associated with optical surfaces
693 TG4OpSurfaceMap::const_iterator it;
694 for (it = fOpSurfaceMap->begin(); it != fOpSurfaceMap->end(); it++) {
695 if (it->second && it->second->GetMaterialPropertiesTable()) {
696
697 G4cout << it->first
698 << " optical surface material properties table: " << G4endl;
699 it->second->GetMaterialPropertiesTable()->DumpTable();
700 }
701 }
702}
703
704//_____________________________________________________________________________
706{
708
709 fMediumMap->Print();
710}
711
712//_____________________________________________________________________________
713void TG4GeometryServices::PrintCuts(const G4String& cutName) const
714{
717
718 TG4G3Cut cut = TG4G3CutVector::GetCut(cutName);
719 if (cut == kNoG3Cuts) {
720 TG4Globals::Exception("TG4GeometryServices", "PrintCuts",
721 TString(cutName.c_str()) + " not defined.");
722 return;
723 }
724
725 G4cout << "Cut " << cutName << G4endl;
726 G4cout << "Medium ID"
727 << " "
728 << "cutValue(MeV)" << G4endl;
729 for (G4int i = 0; i < fMediumMap->GetNofMedia(); i++) {
730 TG4Medium* medium = fMediumMap->GetMedium(i + 1);
731 if (dynamic_cast<TG4Limits*>(medium->GetLimits())) {
732 G4double cutValue =
733 (*GetLimits(medium->GetLimits())->GetCutVector())[cut];
734 G4cout << i + 1 << " " << cutValue << G4endl;
735 }
736 else {
737 // G4cout << "Medium " << medium->GetName()
738 // << " has not TG4Limits " << G4endl;
739 }
740 }
741}
742
743//_____________________________________________________________________________
744void TG4GeometryServices::PrintControls(const G4String& controlName) const
745{
748
749 TG4G3Control control = TG4G3ControlVector::GetControl(controlName);
750 if (control == kNoG3Controls) {
751 TG4Globals::Exception("TG4GeometryServices", "PrintControls",
752 TString(controlName.c_str()) + " not defined.");
753 return;
754 }
755
756 G4cout << "Control " << controlName << G4endl;
757 G4cout << "Medium ID"
758 << " "
759 << "controlValue" << G4endl;
760 for (G4int i = 0; i < fMediumMap->GetNofMedia(); i++) {
761
762 TG4Medium* medium = fMediumMap->GetMedium(i + 1);
763 G4int controlValue =
764 (*GetLimits(medium->GetLimits())->GetControlVector())[control];
765
766 G4cout << i + 1 << " " << controlValue << G4endl;
767 }
768}
769
770#ifdef USE_G3TOG4
771//_____________________________________________________________________________
773{
776
777 gSeparator = separator;
778}
779#else
780//_____________________________________________________________________________
782{
785}
786#endif
787
788//_____________________________________________________________________________
790{
795
796 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
797
798 G4int counter = 0;
799 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
800 G4LogicalVolume* lv = (*lvStore)[i];
801 if (IsG3Volume(lv->GetName())) counter++;
802 }
803
804 return counter;
805}
806
807//_____________________________________________________________________________
809{
811
812 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
813 return lvStore->size();
814}
815
816//_____________________________________________________________________________
818{
820
821 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
822
823 G4int counter = 0;
824 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
825 counter += ((*lvStore)[i])->GetNoDaughters();
826 }
827
828 return counter;
829}
830
831//_____________________________________________________________________________
833{
835
836 if (!limits) return 0;
837
838 TG4Limits* tg4Limits = dynamic_cast<TG4Limits*>(limits);
839 if (!tg4Limits) {
841 "TG4GeometryServices", "GetLimits(.)", "Wrong limits type");
842 return 0;
843 }
844
845 return tg4Limits;
846}
847
848//_____________________________________________________________________________
850 const TG4G3CutVector& cuts, const TG4G3ControlVector& controls) const
851{
854
855 if (!limits) return 0;
856
857 TG4Limits* tg4Limits = dynamic_cast<TG4Limits*>(limits);
858
859 if (tg4Limits) return tg4Limits;
860
861 G4UserLimits* g4Limits = dynamic_cast<G4UserLimits*>(limits);
862
863 if (g4Limits) {
864 tg4Limits = new TG4Limits(*limits, cuts, controls);
865 delete limits;
866 return tg4Limits;
867 }
868
870 "TG4GeometryServices", "GetLimits(..)", "Wrong limits type.");
871 return 0;
872}
873
874//_____________________________________________________________________________
876 const G4String& name, G4bool silent) const
877{
879
880 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
881
882 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
883 G4LogicalVolume* lv = (*lvStore)[i];
884 if (lv->GetName() == name) return lv;
885 }
886
887 if (!silent) {
888 TG4Globals::Warning("TG4GeometryServices", "FindLogicalVolume",
889 "Logical volume " + TString(name) + " not found.");
890 }
891 return 0;
892}
893
894//_____________________________________________________________________________
896 const G4String& name, G4int copyNo, G4bool silent) const
897{
900
901 G4PhysicalVolumeStore* pvStore = G4PhysicalVolumeStore::GetInstance();
902
903 for (G4int i = 0; i < G4int(pvStore->size()); i++) {
904 G4VPhysicalVolume* pv = (*pvStore)[i];
905 // G4cout << i << "th volume "
906 // << pv->GetName() << " "
907 // << UserVolumeName(pv->GetName()) << " "
908 // << pv->GetCopyNo()
909 // << G4endl;
910 if (UserVolumeName(pv->GetName()) == name && pv->GetCopyNo() == copyNo)
911 return pv;
912 }
913
914 if (!silent) {
915 TG4Globals::Warning("TG4GeometryServices", "FindPhysicalVolume",
916 "Physical volume " + TString(name) + " not found.");
917 }
918 return 0;
919}
920
921//_____________________________________________________________________________
923 const G4String& name, G4int copyNo, G4LogicalVolume* mlv, G4bool silent) const
924{
927
928 for (size_t i = 0; i < mlv->GetNoDaughters(); i++) {
929 G4VPhysicalVolume* dpv = mlv->GetDaughter(i);
930 if (UserVolumeName(dpv->GetName()) == name && dpv->GetCopyNo() == copyNo)
931 return dpv;
932 }
933
934 if (!silent) {
935 TG4Globals::Warning("TG4GeometryServices", "FindDaughter",
936 "Physical volume " + TString(name) + " not found.");
937 }
938 return 0;
939}
940
941//_____________________________________________________________________________
943 const G4String& name, G4bool silent) const
944{
946
947 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
948
949 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
950 G4LogicalVolume* lv = (*lvStore)[i];
951 TG4Limits* limits = GetLimits(lv->GetUserLimits());
952 if (limits && limits->GetName() == name) return limits;
953 }
954
955 if (!silent) {
956 TG4Globals::Warning("TG4GeometryServices", "FindLimits",
957 "Limits " + TString(name) + " not found.");
958 }
959 return 0;
960}
961
962//_____________________________________________________________________________
964 const G4String& name, G4bool silent) const
965{
968
969 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
970
971 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
972 G4LogicalVolume* lv = (*lvStore)[i];
973 if (!dynamic_cast<TG4Limits*>(lv->GetUserLimits())) {
974 continue;
975 }
976 TG4Limits* limits = GetLimits(lv->GetUserLimits());
977 if (limits && limits->GetName() == name) return limits;
978 }
979
980 if (!silent) {
981 TG4Globals::Warning("TG4GeometryServices", "FindLimits",
982 "Limits " + TString(name) + " not found.");
983 }
984 return 0;
985}
986
987//_____________________________________________________________________________
989 const G4Material* material, G4bool silent) const
990{
992
993 // Get medium
994 TG4Medium* medium = fMediumMap->GetMedium(material, !silent);
995 if (!medium) return 0;
996
997 return FindLimits(medium->GetName(), silent);
998}
999
1000//_____________________________________________________________________________
1001G4int TG4GeometryServices::GetMediumId(G4LogicalVolume* lv) const
1002{
1005
1006 TG4Medium* medium = fMediumMap->GetMedium(lv, false);
1007
1008 if (!medium) return 0;
1009
1010 return medium->GetID();
1011}
1012
1013//_____________________________________________________________________________
1014G4double TG4GeometryServices::GetEffA(G4Material* material) const
1015{
1018
1019 G4double a = 0.;
1020 G4int nofElements = material->GetNumberOfElements();
1021 if (nofElements > 1) {
1022 // TG4Globals::Warning(
1023 // "TG4GeometryServices", "GetEffA",
1024 // "Effective A for material mixture (" + TString(material->GetName()) +
1025 // ") is used.");
1026
1027 for (G4int i = 0; i < nofElements; i++) {
1028 G4double aOfElement = material->GetElement(i)->GetA();
1029 G4double massFraction = material->GetFractionVector()[i];
1030 a += aOfElement * massFraction / (TG4G3Units::AtomicWeight());
1031 }
1032 }
1033 else {
1034 a = material->GetA();
1036 }
1037 return a;
1038}
1039
1040//_____________________________________________________________________________
1041G4double TG4GeometryServices::GetEffZ(G4Material* material) const
1042{
1045
1046 G4double z = 0.;
1047 G4int nofElements = material->GetNumberOfElements();
1048 if (nofElements > 1) {
1049 // TG4Globals::Warning(
1050 // "TG4GeometryServices", "GetEffZ",
1051 // "Effective Z for material mixture (" + TString(material->GetName()) +
1052 // ") is used.");
1053
1054 for (G4int i = 0; i < nofElements; i++) {
1055 G4double zOfElement = material->GetElement(i)->GetZ();
1056 G4double massFraction = material->GetFractionVector()[i];
1057 z += zOfElement * massFraction;
1058 }
1059 }
1060 else {
1061 z = material->GetZ();
1062 }
1063 return z;
1064}
1065
1066//_____________________________________________________________________________
1068 G4double a, G4double z, G4double density) const
1069{
1072
1073 const G4MaterialTable* kpMatTable = G4Material::GetMaterialTable();
1074
1075 for (G4int i = 0; i < G4int(G4Material::GetNumberOfMaterials()); i++) {
1076
1077 G4Material* material = (*kpMatTable)[i];
1078
1079 if (CompareElement(a, z, material->GetElement(0)) &&
1080 CompareMaterial(1, density, material))
1081
1082 return material;
1083 }
1084
1085 return 0;
1086}
1087
1088//_____________________________________________________________________________
1090 G4double* a, G4double* z, G4double density, G4int nmat, G4double* wmat) const
1091{
1094
1095 G4double* weight = ConvertAtomWeight(nmat, a, wmat);
1096
1097 // loop over materials
1098 G4Material* found = 0;
1099 for (G4int i = 0; i < G4int(G4Material::GetNumberOfMaterials()); i++) {
1100
1101 G4Material* material = (*G4Material::GetMaterialTable())[i];
1102 G4int nofElements = material->GetNumberOfElements();
1103
1104 if (CompareMaterial(nofElements, density, material)) {
1105
1106 // loop over elements
1107 G4bool equal = true;
1108 for (G4int ie = 0; ie < nofElements; ie++) {
1109
1110 G4double we = (material->GetFractionVector())[ie];
1111
1112 if (!CompareElement(a[ie], z[ie], material->GetElement(ie)) ||
1113 std::abs(weight[ie] - we) > fgkAZTolerance) {
1114
1115 equal = false;
1116 break;
1117 }
1118 }
1119 if (equal) {
1120 found = material;
1121 break;
1122 }
1123 }
1124 }
1125
1126 delete[] weight;
1127 return found;
1128}
Definition of the TG4G3ControlVector class.
Definition of the TG4G3Units class.
Definition of the TG4GeometryServices class.
Definition of the TG4Globals class and basic container types.
Definition of the TG4IntMap class.
Definition of the TG4Limits class.
Definition of the TG4MediumMap class.
Definition of the TG4Medium class.
Definition of the TG4NameMap class.
Vector of control process values with convenient set/get methods.
static TG4G3Control GetControl(const G4String &controlName)
Vector of kinetic energy cut values with convenient set/get methods.
static TG4G3Cut GetCut(const G4String &cutName)
static G4double AtomicWeight()
Definition TG4G3Units.h:123
static G4double InverseMassDensity()
Definition TG4G3Units.h:169
static G4double InverseAtomicWeight()
Definition TG4G3Units.h:175
Services for accessing to Geant4 geometry.
void PrintControls(const G4String &controlName) const
G4String CutVolumePath(const G4String &volumePath, G4String &volName, G4int &copyNo) const
static const G4double fgkDensityTolerance
density tolerance (percentual)
static TG4GeometryServices * fgInstance
this instance
TG4OpSurfaceMap * fOpSurfaceMap
map of optical surfaces names to their objects
void PrintPhysicalVolumeStore() const
TG4MediumMap * fMediumMap
map of madia
TG4Limits * FindLimits(const G4String &name, G4bool silent=false) const
G4Material * FindMaterial(G4double a, G4double z, G4double density) const
G4OpticalSurfaceFinish SurfaceFinish(EMCOpSurfaceFinish finish) const
G4double * ConvertAtomWeight(G4int nmat, G4double *a, G4double *wmat) const
G4int GetMediumId(G4LogicalVolume *lv) const
G4Material * MixMaterials(G4String name, G4double density, const TG4StringVector &matNames, const TG4doubleVector &matWeights)
G4bool IsG3Volume(const G4String &lvName) const
G4double * CreateG4doubleArray(Float_t *array, G4int size, G4bool copyValues=true) const
void PrintStatistics(G4bool open, G4bool close) const
G4LogicalVolume * FindLogicalVolume(const G4String &name, G4bool silent=false) const
const G4String & UserVolumeName(const G4String &name) const
G4String CutName(const char *name) const
G4SurfaceType SurfaceType(EMCOpSurfaceType surfType) const
TG4Limits * FindLimits2(const G4String &name, G4bool silent=false) const
G4bool CompareElement(G4double a, G4double z, const G4Element *elem) const
std::vector< TG4AssemblyLevels > fAssemblyLevels
assembly levels per placement, indexed by its Geant4 instance id
void PrintLimits(const G4String &name) const
void PrintMaterialsProperties() const
G4bool fAccountAssemblyLevels
option to account assembly levels in the volume level hierarchy
G4VPhysicalVolume * FindPhysicalVolume(const G4String &name, G4int copyNo, G4bool silent=false) const
TG4Limits * GetLimits(G4UserLimits *limits) const
G4bool fIsG3toG4
info if user geometry is defined via G3toG4
G4VPhysicalVolume * FindDaughter(const G4String &name, G4int copyNo, G4LogicalVolume *mlv, G4bool silent=false) const
void SetG3toG4Separator(char separator)
G4VPhysicalVolume * fWorld
top physical volume (world)
G4bool fAssemblyLevelsBuilt
whether fAssemblyLevels has been filled
static const G4double fgkAZTolerance
A,Z tolerance.
G4double GetEffA(G4Material *material) const
G4bool CompareMaterial(G4int nofElements, G4double density, const G4Material *material) const
G4String CutMaterialName(const char *name) const
void PrintVolumeLimits(const G4String &volumeName) const
G4OpticalSurfaceModel SurfaceModel(EMCOpSurfaceModel model) const
void PrintCuts(const G4String &cutName) const
const TG4AssemblyLevels & GetAssemblyLevels(const G4VPhysicalVolume *pv) const
void Convert(const G4Transform3D &transform, TGeoHMatrix &matrix) const
G4double GetEffZ(G4Material *material) const
static G4String fgBuffer
string buffer
static void PrintStars(G4bool emptyLineFirst)
static void Warning(const TString &className, const TString &methodName, const TString &text)
static void Exception(const TString &className, const TString &methodName, const TString &text)
Extended G4UserLimits class.
Definition TG4Limits.h:38
G4String GetName() const
Definition TG4Limits.h:129
const TG4G3CutVector * GetCutVector() const
Definition TG4Limits.h:141
static G4int GetNofLimits()
Definition TG4Limits.h:105
void Print() const
const TG4G3ControlVector * GetControlVector() const
Definition TG4Limits.h:147
The map of media to logical volumes.
Helper class to keep medium data.
Definition TG4Medium.h:29
G4UserLimits * GetLimits() const
Definition TG4Medium.h:99
G4int GetID() const
Definition TG4Medium.h:84
G4String GetName() const
Definition TG4Medium.h:89
virtual G4int VerboseLevel() const
Definition TG4Verbose.h:78
TG4Verbose(const G4String &cmdName)
std::map< G4String, G4OpticalSurface * > TG4OpSurfaceMap
The map between optical surfaces names and their objects.
std::vector< G4String > TG4StringVector
Definition TG4Globals.h:49
std::vector< G4double > TG4doubleVector
Definition TG4Globals.h:45
TG4G3Cut
Enumeration for G3 types of kinetic energy cuts.
Definition TG4G3Cut.h:22
TG4G3Control
Enumeration for G3 types of physics processes controls.
@ kNoG3Cuts
Invalid value.
Definition TG4G3Cut.h:80
@ kNoG3Controls
No process control.
std::vector< G4int > fCopyNos
-1 where the Geant4 copy number applies
std::vector< G4String > fNames
outermost first; last is the placed volume