Geant4 VMC Version 6.6
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// Moved after Root includes to avoid shadowed variables
43// generated from short units names
44#include <G4SystemOfUnits.hh>
45
46#include <iomanip>
47#include <math.h>
48#include <vector>
49
52const G4double TG4GeometryServices::fgkAZTolerance = 0.001;
53const G4double TG4GeometryServices::fgkDensityTolerance = 0.005;
54
55//_____________________________________________________________________________
57 : TG4Verbose("geometryServices"),
58 fIsG3toG4(false),
59 fMediumMap(0),
60 fOpSurfaceMap(0),
61 fWorld(0)
62{
64
65 if (fgInstance) {
66 TG4Globals::Exception("TG4GeometryServices", "TG4GeometryServices",
67 "Cannot create two instances of singleton.");
68 }
69
72
73 fgInstance = this;
74}
75
76//_____________________________________________________________________________
85
86//
87// private methods
88//
89
90#ifdef USE_G3TOG4
91//_____________________________________________________________________________
92G4bool TG4GeometryServices::IsG3Volume(const G4String& lvName) const
93{
97
98 if (G4StrUtil::contains(lvName, gSeparator))
99 return false;
100 else
101 return true;
102}
103
104//_____________________________________________________________________________
106 G4double /*a*/, G4double z, const G4Element* element) const
107{
110
111 G4double ae = element->GetA() * TG4G3Units::InverseAtomicWeight();
112 G4double ze = element->GetZ();
113
114 // g3tog4 can redefine A
115 G4double ax;
116 if (z < 1) {
117 // vacuum
118 ax = 1.01 * g / mole;
119 }
120 else
121 ax = G3Ele.GetEle(z)->GetA() * TG4G3Units::InverseAtomicWeight();
122
123 if (std::abs(ax - ae) < fgkAZTolerance && std::abs(z - ze) < fgkAZTolerance)
124 return true;
125 else
126 return false;
127}
128#else
129//_____________________________________________________________________________
130G4bool TG4GeometryServices::IsG3Volume(const G4String& /*lvName*/) const
131{
135
136 return false;
137}
138
139//_____________________________________________________________________________
141 G4double /*a*/, G4double /*z*/, const G4Element* /*element*/) const
142{
145
146 return false;
147}
148#endif
149
150//_____________________________________________________________________________
152 G4int nofElements, G4double density, const G4Material* material) const
153{
156
157 G4double dm = material->GetDensity() * TG4G3Units::InverseMassDensity();
158 G4int ne = material->GetNumberOfElements();
159
160 // density percentual difference
161 G4double diff = std::abs(density - dm) / (density + dm) * 2.;
162
163 if (nofElements == ne && diff < fgkDensityTolerance)
164 return true;
165 else
166 return false;
167}
168
169//_____________________________________________________________________________
171 G4int nmat, G4double* a, G4double* wmat) const
172{
176
177 G4double* weight = new G4double[abs(nmat)];
178
179 if (nmat < 0) {
180 G4double aMol = 0.;
181 G4int i;
182 for (i = 0; i < abs(nmat); i++) {
183 // total molecular weight
184 aMol += wmat[i] * a[i];
185 }
186 if (aMol == 0.) {
187 TG4Globals::Warning("TG4GeometryServices", "ConvertAtomWeight",
188 "Total molecular weight = 0.");
189 }
190 for (i = 0; i < abs(nmat); i++) {
191 // weight fractions
192 weight[i] = wmat[i] * a[i] / aMol;
193 }
194 }
195 else
196 for (G4int j = 0; j < nmat; j++) weight[j] = wmat[j];
197
198 return weight;
199}
200
201//
202// public methods
203//
204
205//_____________________________________________________________________________
207 Float_t* array, G4int size, G4bool copyValues) const
208{
211
212 G4double* doubleArray;
213 if (size > 0) {
214 doubleArray = new G4double[size];
215 if (copyValues) {
216 for (G4int i = 0; i < size; i++) doubleArray[i] = array[i];
217 }
218 }
219 else {
220 doubleArray = 0;
221 }
222 return doubleArray;
223}
224
225//_____________________________________________________________________________
227 Double_t* array, G4int size, G4bool copyValues) const
228{
231
232 G4double* doubleArray;
233 if (size > 0) {
234 doubleArray = new G4double[size];
235 if (copyValues) {
236 for (G4int i = 0; i < size; i++) doubleArray[i] = array[i];
237 }
238 }
239 else {
240 doubleArray = 0;
241 }
242 return doubleArray;
243}
244
245//_____________________________________________________________________________
246G4String TG4GeometryServices::CutName(const char* name) const
247{
249
250 G4String cutName = name;
251 G4int i = cutName.length();
252 while (cutName[--i] == ' ') cutName = cutName.substr(0, i);
253
254 return cutName;
255}
256
257//_____________________________________________________________________________
258G4String TG4GeometryServices::CutMaterialName(const char* name) const
259{
261
262 G4String cutName = name;
263 cutName = cutName.substr(0, cutName.find('$'));
264
265 return CutName(cutName);
266}
267
268//_____________________________________________________________________________
270 const G4String& volumePath, G4String& volName, G4int& copyNo) const
271{
273
274 G4String path(volumePath);
275
276 G4int npos1 = path.find('/');
277 G4int npos2 = path.find('_');
278 G4int npos3 = path.find('/', 2);
279 if (npos3 < 0) npos3 = path.length();
280
281 volName = path.substr(npos1 + 1, npos2 - npos1 - 1);
282 G4String copyNoStr = path.substr(npos2 + 1, npos3 - npos2);
283 std::istringstream in(copyNoStr);
284 in >> copyNo;
285
286 return path.substr(npos3, path.length() - npos3);
287}
288
289//_____________________________________________________________________________
290const G4String& TG4GeometryServices::UserVolumeName(const G4String& name) const
291{
294
295#ifdef USE_G3TOG4
296 if (fIsG3toG4 && G4StrUtil::contains(name, gSeparator)) {
297 fgBuffer = name.substr(0, name.find(gSeparator));
298 return fgBuffer;
299 }
300 else {
301 return name;
302 }
303#else
304 return name;
305#endif
306}
307
308//_____________________________________________________________________________
310 EMCOpSurfaceModel model) const
311{
313
314 // clang-format off
315 switch (model) {
316 case kGlisur: return glisur;
317 case kUnified: return unified;
318 case kLUT: return LUT;
319 case kDAVIS: return DAVIS;
320 case kdichroic: return dichroic;
321 // clang-format on
322 default:
323 TG4Globals::Warning("TG4GeometryServices", "SurfaceModel",
324 "Unknown optical surface model, return Glisur.");
325 return glisur;
326 }
327}
328
329//_____________________________________________________________________________
330G4SurfaceType TG4GeometryServices::SurfaceType(EMCOpSurfaceType surfType) const
331{
333
334 // clang-format off
335 switch (surfType) {
336 case kDielectric_metal: return dielectric_metal;
337 case kDielectric_dielectric: return dielectric_dielectric;
338 case kDielectric_LUT: return dielectric_LUT;
339 case kDielectric_LUTDAVIS: return dielectric_LUTDAVIS;
340 case kDielectric_dichroic: return dielectric_dichroic;
341 case kFirsov: return firsov;
342 case kXray: return x_ray;
343 // clang-format on
344 default:
345 TG4Globals::Warning("TG4GeometryServices", "SurfaceType",
346 "Unknown optical surface type, return dielectric_metal.");
347 return dielectric_metal;
348 }
349}
350
351//_____________________________________________________________________________
353 EMCOpSurfaceFinish finish) const
354{
356
357 // clang-format off
358 switch (finish) {
359 case kPolished: return polished;
360 case kPolishedfrontpainted: return polishedfrontpainted;
361 case kPolishedbackpainted: return polishedbackpainted;
362 //
363 case kGround: return ground;
364 case kGroundfrontpainted: return groundfrontpainted;
365 case kGroundbackpainted: return groundbackpainted;
366 //
367 case kPolishedlumirrorair: return polishedlumirrorair;
368 case kPolishedlumirrorglue: return polishedlumirrorglue;
369 //
370 case kPolishedair: return polishedair;
371 case kPolishedteflonair: return polishedteflonair;
372 case kPolishedtioair: return polishedtioair;
373 case kPolishedtyvekair: return polishedtyvekair;
374 case kPolishedvm2000air: return polishedvm2000air;
375 case kPolishedvm2000glue: return polishedvm2000glue;
376 //
377 case kEtchedlumirrorair: return etchedlumirrorair;
378 case kEtchedlumirrorglue: return etchedlumirrorglue;
379 case kEtchedair: return etchedair;
380 case kEtchedteflonair: return etchedteflonair;
381 case kEtchedtioair: return etchedtioair;
382 case kEtchedtyvekair: return etchedtyvekair;
383 case kEtchedvm2000air: return etchedvm2000air;
384 case kEtchedvm2000glue: return etchedvm2000glue;
385 case kGroundlumirrorair: return groundlumirrorair;
386 case kGroundlumirrorglue: return groundlumirrorglue;
387 case kGroundair: return groundair;
388 case kGroundteflonair: return groundteflonair;
389 case kGroundtioair: return groundtioair;
390 case kGroundtyvekair: return groundtyvekair;
391 case kGroundvm2000air: return groundvm2000air;
392 case kGroundvm2000glue: return groundvm2000glue;
393 //
394 case kRough_LUT: return Rough_LUT;
395 case kRoughTeflon_LUT: return RoughTeflon_LUT;
396 case kRoughESR_LUT: return RoughESR_LUT;
397 case kRoughESRGrease_LUT: return RoughESRGrease_LUT;
398 //
399 case kPolished_LUT: return Polished_LUT;
400 case kPolishedTeflon_LUT: return PolishedTeflon_LUT;
401 case kPolishedESR_LUT: return PolishedESR_LUT;
402 case kPolishedESRGrease_LUT: return PolishedESRGrease_LUT;
403 //
404 case kDetector_LUT: return Detector_LUT;
405 // clang-format on
406 default:
407 TG4Globals::Warning("TG4GeometryServices", "SurfaceFinish",
408 "Unknown optical surface finish, return polished.");
409 return polished;
410 }
411}
412
413//_____________________________________________________________________________
415 const G4Transform3D& transform, TGeoHMatrix& matrix) const
416{
418
419 Double_t* translation = new Double_t[3];
420 Double_t* rotation = new Double_t[9];
421 for (G4int i = 0; i < 3; i++)
422 for (G4int j = 0; j < 3; j++) {
423 rotation[i * 3 + j] = transform(i, j);
424 translation[i] = transform(i, 3) / cm;
425 }
426 matrix.SetTranslation(translation);
427 matrix.SetRotation(rotation);
428 delete[] translation;
429 delete[] rotation;
430}
431
432//_____________________________________________________________________________
433G4Material* TG4GeometryServices::MixMaterials(G4String name, G4double density,
434 const TG4StringVector& matNames, const TG4doubleVector& matWeights)
435{
437
438 // number of materials to be mixed
439 G4int nofMaterials = matNames.size();
440 if (nofMaterials != G4int(matWeights.size())) {
441 TG4Globals::Exception("TG4GeometryServices", "MixMaterials",
442 "Different number of material names and weigths.");
443 }
444
445 if (VerboseLevel() > 1) {
446 G4cout << "Nof of materials to be mixed: " << nofMaterials << G4endl;
447 }
448
449 // fill vector of materials
450 std::vector<G4Material*> matVector;
451 G4int im;
452 for (im = 0; im < nofMaterials; im++) {
453 // material
454 G4Material* material = G4Material::GetMaterial(matNames[im]);
455 matVector.push_back(material);
456 }
457
458 // create the mixed material
459 G4Material* mixture = new G4Material(name, density, nofMaterials);
460 for (im = 0; im < nofMaterials; im++) {
461 G4Material* material = matVector[im];
462 G4double fraction = matWeights[im];
463 mixture->AddMaterial(material, fraction);
464 }
465
466 return mixture;
467}
468
469//_____________________________________________________________________________
470void TG4GeometryServices::PrintLimits(const G4String& name) const
471{
473
474 TG4Limits* limits = FindLimits(name, true);
475
476 if (limits) limits->Print();
477}
478
479//_____________________________________________________________________________
480void TG4GeometryServices::PrintVolumeLimits(const G4String& volumeName) const
481{
484
485 G4LogicalVolume* lv = FindLogicalVolume(volumeName, false);
486
487 if (lv) {
488 TG4Limits* limits = GetLimits(lv->GetUserLimits());
489 G4cout << volumeName << " ";
490 if (limits)
491 limits->Print();
492 else
493 G4cout << "has not the limits set." << G4endl;
494 }
495}
496
497//_____________________________________________________________________________
498void TG4GeometryServices::PrintStatistics(G4bool open, G4bool close) const
499{
501
502 if (open) TG4Globals::PrintStars(true);
503
504 G4cout << " GEANT4 Geometry statistics: " << G4endl << " "
505 << std::setw(5) << NofG4LogicalVolumes() << " logical volumes"
506 << G4endl << " " << std::setw(5) << NofG4PhysicalVolumes()
507 << " physical volumes" << G4endl << " " << std::setw(5)
508 << G4Material::GetNumberOfMaterials() << " materials" << G4endl
509 << " " << std::setw(5) << TG4Limits::GetNofLimits()
510 << " user limits" << G4endl;
511
512 if (close) TG4Globals::PrintStars(false);
513}
514
515//_____________________________________________________________________________
517{
519
520 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
521
522 G4cout << "Logical volume store: " << G4endl;
523
524 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
525
526 G4LogicalVolume* lv = (*lvStore)[i];
527
528 void* address = lv->GetMaterial();
529 G4cout << "Logical volume: " << G4endl;
530 G4cout << " " << std::setw(5) << i << " " << lv << " " << lv->GetName()
531 << " " << std::setw(5) << lv->GetNoDaughters() << " daughters"
532 << " limits: " << lv->GetUserLimits()
533 << " material: " << lv->GetMaterial()->GetName() << " " << address
534 << G4endl;
535
536 for (size_t j = 0; j < lv->GetNoDaughters(); j++) {
537 void* addressd = lv->GetDaughter(j)->GetLogicalVolume()->GetMaterial();
538 G4cout << " Daughter: " << std::setw(5) << j << " "
539 << lv->GetDaughter(j) << " " << lv->GetDaughter(j)->GetName()
540 << " of LV: " << lv->GetDaughter(j)->GetLogicalVolume() << " "
541 << lv->GetDaughter(j)->GetLogicalVolume()->GetName()
542 << " copy no: " << lv->GetDaughter(j)->GetCopyNo()
543 << " material: "
544 << lv->GetDaughter(j)->GetLogicalVolume()->GetMaterial()->GetName()
545 << " " << addressd << G4endl;
546 }
547 }
548}
549
550//_____________________________________________________________________________
552{
554
555 G4PhysicalVolumeStore* pvStore = G4PhysicalVolumeStore::GetInstance();
556
557 for (G4int i = 0; i < G4int(pvStore->size()); i++) {
558 G4VPhysicalVolume* pv = (*pvStore)[i];
559 G4cout << i << "th volume name=" << pv->GetName()
560 << " g3name=" << UserVolumeName(pv->GetName())
561 << " copyNo=" << pv->GetCopyNo() << G4endl;
562 }
563}
564
565//_____________________________________________________________________________
567{
569
570 const G4ElementTable* elementTable = G4Element::GetElementTable();
571
572 G4cout << "Element table: " << G4endl;
573
574 for (G4int i = 0; i < G4int(elementTable->size()); i++) {
575
576 G4Element* element = (*elementTable)[i];
577 G4cout << " " << std::setw(5) << i << "th element:"
578 << " " << element << G4endl;
579 }
580}
581
582//_____________________________________________________________________________
584{
586
587 // Dump materials
588 const G4MaterialTable* matTable = G4Material::GetMaterialTable();
589 G4cout << *matTable;
590}
591
592//_____________________________________________________________________________
594{
596
597 // Dump material properties tables
598 // associated with materials
599 const G4MaterialTable* matTable = G4Material::GetMaterialTable();
600 for (G4int i = 0; i < G4int(matTable->size()); i++) {
601 if ((*matTable)[i] && (*matTable)[i]->GetMaterialPropertiesTable()) {
602
603 G4cout << (*matTable)[i]->GetName()
604 << " material properties table: " << G4endl;
605 (*matTable)[i]->GetMaterialPropertiesTable()->DumpTable();
606 }
607 }
608
609 // Dump material properties tables
610 // associated with optical surfaces
611 TG4OpSurfaceMap::const_iterator it;
612 for (it = fOpSurfaceMap->begin(); it != fOpSurfaceMap->end(); it++) {
613 if (it->second && it->second->GetMaterialPropertiesTable()) {
614
615 G4cout << it->first
616 << " optical surface material properties table: " << G4endl;
617 it->second->GetMaterialPropertiesTable()->DumpTable();
618 }
619 }
620}
621
622//_____________________________________________________________________________
624{
626
627 fMediumMap->Print();
628}
629
630//_____________________________________________________________________________
631void TG4GeometryServices::PrintCuts(const G4String& cutName) const
632{
635
636 TG4G3Cut cut = TG4G3CutVector::GetCut(cutName);
637 if (cut == kNoG3Cuts) {
638 TG4Globals::Exception("TG4GeometryServices", "PrintCuts",
639 TString(cutName.c_str()) + " not defined.");
640 return;
641 }
642
643 G4cout << "Cut " << cutName << G4endl;
644 G4cout << "Medium ID"
645 << " "
646 << "cutValue(MeV)" << G4endl;
647 for (G4int i = 0; i < fMediumMap->GetNofMedia(); i++) {
648 TG4Medium* medium = fMediumMap->GetMedium(i + 1);
649 if (dynamic_cast<TG4Limits*>(medium->GetLimits())) {
650 G4double cutValue =
651 (*GetLimits(medium->GetLimits())->GetCutVector())[cut];
652 G4cout << i + 1 << " " << cutValue << G4endl;
653 }
654 else {
655 // G4cout << "Medium " << medium->GetName()
656 // << " has not TG4Limits " << G4endl;
657 }
658 }
659}
660
661//_____________________________________________________________________________
662void TG4GeometryServices::PrintControls(const G4String& controlName) const
663{
666
667 TG4G3Control control = TG4G3ControlVector::GetControl(controlName);
668 if (control == kNoG3Controls) {
669 TG4Globals::Exception("TG4GeometryServices", "PrintControls",
670 TString(controlName.c_str()) + " not defined.");
671 return;
672 }
673
674 G4cout << "Control " << controlName << G4endl;
675 G4cout << "Medium ID"
676 << " "
677 << "controlValue" << G4endl;
678 for (G4int i = 0; i < fMediumMap->GetNofMedia(); i++) {
679
680 TG4Medium* medium = fMediumMap->GetMedium(i + 1);
681 G4int controlValue =
682 (*GetLimits(medium->GetLimits())->GetControlVector())[control];
683
684 G4cout << i + 1 << " " << controlValue << G4endl;
685 }
686}
687
688#ifdef USE_G3TOG4
689//_____________________________________________________________________________
691{
694
695 gSeparator = separator;
696}
697#else
698//_____________________________________________________________________________
700{
703}
704#endif
705
706//_____________________________________________________________________________
708{
713
714 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
715
716 G4int counter = 0;
717 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
718 G4LogicalVolume* lv = (*lvStore)[i];
719 if (IsG3Volume(lv->GetName())) counter++;
720 }
721
722 return counter;
723}
724
725//_____________________________________________________________________________
727{
729
730 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
731 return lvStore->size();
732}
733
734//_____________________________________________________________________________
736{
738
739 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
740
741 G4int counter = 0;
742 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
743 counter += ((*lvStore)[i])->GetNoDaughters();
744 }
745
746 return counter;
747}
748
749//_____________________________________________________________________________
751{
753
754 if (!limits) return 0;
755
756 TG4Limits* tg4Limits = dynamic_cast<TG4Limits*>(limits);
757 if (!tg4Limits) {
759 "TG4GeometryServices", "GetLimits(.)", "Wrong limits type");
760 return 0;
761 }
762
763 return tg4Limits;
764}
765
766//_____________________________________________________________________________
768 const TG4G3CutVector& cuts, const TG4G3ControlVector& controls) const
769{
772
773 if (!limits) return 0;
774
775 TG4Limits* tg4Limits = dynamic_cast<TG4Limits*>(limits);
776
777 if (tg4Limits) return tg4Limits;
778
779 G4UserLimits* g4Limits = dynamic_cast<G4UserLimits*>(limits);
780
781 if (g4Limits) {
782 tg4Limits = new TG4Limits(*limits, cuts, controls);
783 delete limits;
784 return tg4Limits;
785 }
786
788 "TG4GeometryServices", "GetLimits(..)", "Wrong limits type.");
789 return 0;
790}
791
792//_____________________________________________________________________________
794 const G4String& name, G4bool silent) const
795{
797
798 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
799
800 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
801 G4LogicalVolume* lv = (*lvStore)[i];
802 if (lv->GetName() == name) return lv;
803 }
804
805 if (!silent) {
806 TG4Globals::Warning("TG4GeometryServices", "FindLogicalVolume",
807 "Logical volume " + TString(name) + " not found.");
808 }
809 return 0;
810}
811
812//_____________________________________________________________________________
814 const G4String& name, G4int copyNo, G4bool silent) const
815{
818
819 G4PhysicalVolumeStore* pvStore = G4PhysicalVolumeStore::GetInstance();
820
821 for (G4int i = 0; i < G4int(pvStore->size()); i++) {
822 G4VPhysicalVolume* pv = (*pvStore)[i];
823 // G4cout << i << "th volume "
824 // << pv->GetName() << " "
825 // << UserVolumeName(pv->GetName()) << " "
826 // << pv->GetCopyNo()
827 // << G4endl;
828 if (UserVolumeName(pv->GetName()) == name && pv->GetCopyNo() == copyNo)
829 return pv;
830 }
831
832 if (!silent) {
833 TG4Globals::Warning("TG4GeometryServices", "FindPhysicalVolume",
834 "Physical volume " + TString(name) + " not found.");
835 }
836 return 0;
837}
838
839//_____________________________________________________________________________
841 const G4String& name, G4int copyNo, G4LogicalVolume* mlv, G4bool silent) const
842{
845
846 for (size_t i = 0; i < mlv->GetNoDaughters(); i++) {
847 G4VPhysicalVolume* dpv = mlv->GetDaughter(i);
848 if (UserVolumeName(dpv->GetName()) == name && dpv->GetCopyNo() == copyNo)
849 return dpv;
850 }
851
852 if (!silent) {
853 TG4Globals::Warning("TG4GeometryServices", "FindDaughter",
854 "Physical volume " + TString(name) + " not found.");
855 }
856 return 0;
857}
858
859//_____________________________________________________________________________
861 const G4String& name, G4bool silent) const
862{
864
865 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
866
867 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
868 G4LogicalVolume* lv = (*lvStore)[i];
869 TG4Limits* limits = GetLimits(lv->GetUserLimits());
870 if (limits && limits->GetName() == name) return limits;
871 }
872
873 if (!silent) {
874 TG4Globals::Warning("TG4GeometryServices", "FindLimits",
875 "Limits " + TString(name) + " not found.");
876 }
877 return 0;
878}
879
880//_____________________________________________________________________________
882 const G4String& name, G4bool silent) const
883{
886
887 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
888
889 for (G4int i = 0; i < G4int(lvStore->size()); i++) {
890 G4LogicalVolume* lv = (*lvStore)[i];
891 if (!dynamic_cast<TG4Limits*>(lv->GetUserLimits())) {
892 continue;
893 }
894 TG4Limits* limits = GetLimits(lv->GetUserLimits());
895 if (limits && limits->GetName() == name) return limits;
896 }
897
898 if (!silent) {
899 TG4Globals::Warning("TG4GeometryServices", "FindLimits",
900 "Limits " + TString(name) + " not found.");
901 }
902 return 0;
903}
904
905//_____________________________________________________________________________
907 const G4Material* material, G4bool silent) const
908{
910
911 // Get medium
912 TG4Medium* medium = fMediumMap->GetMedium(material, !silent);
913 if (!medium) return 0;
914
915 return FindLimits(medium->GetName(), silent);
916}
917
918//_____________________________________________________________________________
919G4int TG4GeometryServices::GetMediumId(G4LogicalVolume* lv) const
920{
923
924 TG4Medium* medium = fMediumMap->GetMedium(lv, false);
925
926 if (!medium) return 0;
927
928 return medium->GetID();
929}
930
931//_____________________________________________________________________________
932G4double TG4GeometryServices::GetEffA(G4Material* material) const
933{
936
937 G4double a = 0.;
938 G4int nofElements = material->GetNumberOfElements();
939 if (nofElements > 1) {
940 // TG4Globals::Warning(
941 // "TG4GeometryServices", "GetEffA",
942 // "Effective A for material mixture (" + TString(material->GetName()) +
943 // ") is used.");
944
945 for (G4int i = 0; i < nofElements; i++) {
946 G4double aOfElement = material->GetElement(i)->GetA();
947 G4double massFraction = material->GetFractionVector()[i];
948 a += aOfElement * massFraction / (TG4G3Units::AtomicWeight());
949 }
950 }
951 else {
952 a = material->GetA();
954 }
955 return a;
956}
957
958//_____________________________________________________________________________
959G4double TG4GeometryServices::GetEffZ(G4Material* material) const
960{
963
964 G4double z = 0.;
965 G4int nofElements = material->GetNumberOfElements();
966 if (nofElements > 1) {
967 // TG4Globals::Warning(
968 // "TG4GeometryServices", "GetEffZ",
969 // "Effective Z for material mixture (" + TString(material->GetName()) +
970 // ") is used.");
971
972 for (G4int i = 0; i < nofElements; i++) {
973 G4double zOfElement = material->GetElement(i)->GetZ();
974 G4double massFraction = material->GetFractionVector()[i];
975 z += zOfElement * massFraction;
976 }
977 }
978 else {
979 z = material->GetZ();
980 }
981 return z;
982}
983
984//_____________________________________________________________________________
986 G4double a, G4double z, G4double density) const
987{
990
991 const G4MaterialTable* kpMatTable = G4Material::GetMaterialTable();
992
993 for (G4int i = 0; i < G4int(G4Material::GetNumberOfMaterials()); i++) {
994
995 G4Material* material = (*kpMatTable)[i];
996
997 if (CompareElement(a, z, material->GetElement(0)) &&
998 CompareMaterial(1, density, material))
999
1000 return material;
1001 }
1002
1003 return 0;
1004}
1005
1006//_____________________________________________________________________________
1008 G4double* a, G4double* z, G4double density, G4int nmat, G4double* wmat) const
1009{
1012
1013 G4double* weight = ConvertAtomWeight(nmat, a, wmat);
1014
1015 // loop over materials
1016 G4Material* found = 0;
1017 for (G4int i = 0; i < G4int(G4Material::GetNumberOfMaterials()); i++) {
1018
1019 G4Material* material = (*G4Material::GetMaterialTable())[i];
1020 G4int nofElements = material->GetNumberOfElements();
1021
1022 if (CompareMaterial(nofElements, density, material)) {
1023
1024 // loop over elements
1025 G4bool equal = true;
1026 for (G4int ie = 0; ie < nofElements; ie++) {
1027
1028 G4double we = (material->GetFractionVector())[ie];
1029
1030 if (!CompareElement(a[ie], z[ie], material->GetElement(ie)) ||
1031 std::abs(weight[ie] - we) > fgkAZTolerance) {
1032
1033 equal = false;
1034 break;
1035 }
1036 }
1037 if (equal) {
1038 found = material;
1039 break;
1040 }
1041 }
1042 }
1043
1044 delete[] weight;
1045 return found;
1046}
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
void PrintLimits(const G4String &name) const
void PrintMaterialsProperties() const
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)
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
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.
G4int GetNofMedia() const
TG4Medium * GetMedium(G4int mediumID, G4bool warn=true) const
void Print() const
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
Base class for defining the verbose level and a common messenger.
Definition TG4Verbose.h:36
virtual G4int VerboseLevel() const
Definition TG4Verbose.h:78
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.