Geant4 VMC
Version 6.8
Toggle main menu visibility
Loading...
Searching...
No Matches
source
geometry
src
TG4MediumMap.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 "
TG4MediumMap.h
"
16
#include "
TG4GeometryServices.h
"
17
#include "
TG4Globals.h
"
18
#include "
TG4Medium.h
"
19
20
#include <G4LogicalVolume.hh>
21
#include <G4Material.hh>
22
23
#include <iomanip>
24
25
//_____________________________________________________________________________
26
TG4MediumMap::TG4MediumMap
() :
fIdMap
(),
fLVMap
(),
fMaterialMap
()
27
{
29
}
30
31
//_____________________________________________________________________________
32
TG4MediumMap::~TG4MediumMap
()
33
{
35
36
// Delete medium objects
37
std::map<G4int, TG4Medium*>::const_iterator it;
38
for
(it =
fIdMap
.begin(); it !=
fIdMap
.end(); ++it)
delete
it->second;
39
}
40
41
//
42
// public methods
43
//
44
45
//_____________________________________________________________________________
46
TG4Medium
*
TG4MediumMap::AddMedium
(G4int mediumID, G4bool warn)
47
{
50
51
TG4Medium
* medium =
GetMedium
(mediumID,
false
);
52
53
if
(medium) {
54
if
(warn) {
55
TString text =
"Medium with given ID="
;
56
text += mediumID;
57
text +=
" already exists."
;
58
TG4Globals::Warning
(
"TG4MediumMap"
,
"AddMedium"
, text);
59
}
60
return
medium;
61
}
62
63
medium =
new
TG4Medium
(mediumID);
64
fIdMap
[mediumID] = medium;
65
return
medium;
66
}
67
68
//_____________________________________________________________________________
69
void
TG4MediumMap::MapMedium
(G4LogicalVolume* lv, G4int mediumID)
70
{
73
74
TG4Medium
* medium =
GetMedium
(mediumID);
75
76
if
(!medium) {
77
TString text =
"Medium with given ID="
;
78
text += mediumID;
79
text +=
" not defined."
;
80
TG4Globals::Warning
(
"TG4MediumMap"
,
"MapMedium"
, text);
81
return
;
82
}
83
84
fLVMap
[lv] = medium;
85
86
if
(
fMaterialMap
.find(lv->GetMaterial()) ==
fMaterialMap
.end()) {
87
fMaterialMap
[lv->GetMaterial()] = medium;
88
}
89
}
90
91
//_____________________________________________________________________________
92
void
TG4MediumMap::MapMedium
(
const
G4String& lvName, G4int mediumID)
93
{
96
97
auto
volumes =
TG4GeometryServices::Instance
()->
FindLogicalVolumes
(lvName);
98
99
if
(volumes.empty()) {
100
TG4Globals::Warning
(
"TG4MediumMap"
,
"MapMedium"
,
101
"Logical volume "
+ TString(lvName) +
" not defined."
);
102
return
;
103
}
104
105
for
(
auto
lv : volumes)
MapMedium
(lv, mediumID);
106
}
107
108
//_____________________________________________________________________________
109
void
TG4MediumMap::Print
()
const
110
{
112
113
if
(
fIdMap
.size()) {
114
G4cout <<
"Dump of TG4MediumMap - "
<<
fIdMap
.size()
115
<<
" entries:"
<< G4endl;
116
G4int counter = 0;
117
std::map<G4int, TG4Medium*>::const_iterator it;
118
for
(it =
fIdMap
.begin(); it !=
fIdMap
.end(); ++it) {
119
G4cout <<
"Map element "
<< std::setw(3) << counter++ <<
" "
;
120
it->second->Print();
121
G4cout << G4endl;
122
}
123
}
124
}
125
126
//_____________________________________________________________________________
127
G4int
TG4MediumMap::GetNofMedia
()
const
128
{
130
131
return
fIdMap
.size();
132
}
133
134
//_____________________________________________________________________________
135
TG4Medium
*
TG4MediumMap::GetMedium
(G4int mediumID, G4bool warn)
const
136
{
138
139
std::map<G4int, TG4Medium*>::const_iterator it =
fIdMap
.find(mediumID);
140
141
if
(it ==
fIdMap
.end()) {
142
if
(warn) {
143
TString text =
"Medium with given ID="
;
144
text += mediumID;
145
text +=
" not defined."
;
146
TG4Globals::Warning
(
"TG4MediumMap"
,
"GetMedium"
, text);
147
}
148
return
0;
149
}
150
151
return
it->second;
152
}
153
154
//_____________________________________________________________________________
155
TG4Medium
*
TG4MediumMap::GetMedium
(
const
G4String& name, G4bool warn)
const
156
{
158
159
std::map<G4int, TG4Medium*>::const_iterator it;
160
for
(it =
fIdMap
.begin(); it !=
fIdMap
.end(); ++it)
161
if
(it->second->GetName() == name)
return
it->second;
162
163
// Give warning if not found
164
if
(warn) {
165
TG4Globals::Warning
(
"TG4MediumMap"
,
"GetMedium"
,
166
"Medium "
+ TString(name) +
" is not found."
);
167
}
168
return
0;
169
}
170
171
//_____________________________________________________________________________
172
TG4Medium
*
TG4MediumMap::GetMedium
(G4LogicalVolume* lv, G4bool warn)
const
173
{
175
176
std::map<G4LogicalVolume*, TG4Medium*>::const_iterator it =
fLVMap
.find(lv);
177
178
if
(it ==
fLVMap
.end()) {
179
if
(warn) {
180
TG4Globals::Warning
(
"TG4MediumMap"
,
"GetMedium"
,
181
"Medium for LV "
+ TString(lv->GetName()) +
" is not found."
);
182
}
183
return
0;
184
}
185
186
return
it->second;
187
}
188
189
//_____________________________________________________________________________
190
TG4Medium
*
TG4MediumMap::GetMedium
(
191
const
G4Material* material, G4bool warn)
const
192
{
194
195
std::map<const G4Material*, TG4Medium*>::const_iterator it =
196
fMaterialMap
.find(material);
197
198
if
(it ==
fMaterialMap
.end()) {
199
if
(warn) {
200
TG4Globals::Warning
(
"TG4MediumMap"
,
"GetMedium"
,
201
"Medium for material "
+ TString(material->GetName()) +
202
" is not found."
);
203
}
204
return
0;
205
}
206
207
return
it->second;
208
}
209
210
//_____________________________________________________________________________
211
void
TG4MediumMap::GetMedia
(
const
G4String& namePattern,
212
std::vector<TG4Medium*>& media, G4bool warn)
const
213
{
216
217
// Strip pattern
218
std::string pattern = namePattern;
219
if
(pattern.find(
"*"
) != std::string::npos) {
220
pattern.erase(pattern.find(
"*"
));
221
}
222
223
G4bool found =
false
;
224
std::map<G4int, TG4Medium*>::const_iterator it;
225
for
(it =
fIdMap
.begin(); it !=
fIdMap
.end(); ++it) {
226
if
(it->second->GetName().find(pattern) != std::string::npos) {
227
media.push_back(it->second);
228
found =
true
;
229
}
230
}
231
232
// Give warning if not found
233
if
(warn && (!found)) {
234
TG4Globals::Warning
(
"TG4MediumMap"
,
"GetMedia"
,
235
"No medium with name pattern "
+ TString(namePattern) +
" was found."
);
236
}
237
}
TG4GeometryServices.h
Definition of the TG4GeometryServices class.
TG4Globals.h
Definition of the TG4Globals class and basic container types.
TG4MediumMap.h
Definition of the TG4MediumMap class.
TG4Medium.h
Definition of the TG4Medium class.
TG4GeometryServices::Instance
static TG4GeometryServices * Instance()
Definition
TG4GeometryServices.h:209
TG4GeometryServices::FindLogicalVolumes
std::vector< G4LogicalVolume * > FindLogicalVolumes(const G4String &name, G4bool silent=false) const
Definition
TG4GeometryServices.cxx:908
TG4Globals::Warning
static void Warning(const TString &className, const TString &methodName, const TString &text)
Definition
TG4Globals.cxx:48
TG4MediumMap::MapMedium
void MapMedium(G4LogicalVolume *lv, G4int mediumID)
Definition
TG4MediumMap.cxx:69
TG4MediumMap::TG4MediumMap
TG4MediumMap()
Definition
TG4MediumMap.cxx:26
TG4MediumMap::AddMedium
TG4Medium * AddMedium(G4int mediumID, G4bool warn=true)
Definition
TG4MediumMap.cxx:46
TG4MediumMap::fIdMap
std::map< G4int, TG4Medium * > fIdMap
map of medias to their IDs
Definition
TG4MediumMap.h:64
TG4MediumMap::GetNofMedia
G4int GetNofMedia() const
Definition
TG4MediumMap.cxx:127
TG4MediumMap::GetMedium
TG4Medium * GetMedium(G4int mediumID, G4bool warn=true) const
Definition
TG4MediumMap.cxx:135
TG4MediumMap::Print
void Print() const
Definition
TG4MediumMap.cxx:109
TG4MediumMap::fMaterialMap
std::map< const G4Material *, TG4Medium * > fMaterialMap
map of materials to medias
Definition
TG4MediumMap.h:70
TG4MediumMap::~TG4MediumMap
~TG4MediumMap()
Definition
TG4MediumMap.cxx:32
TG4MediumMap::fLVMap
std::map< G4LogicalVolume *, TG4Medium * > fLVMap
map of medias to the logical volumes
Definition
TG4MediumMap.h:67
TG4MediumMap::GetMedia
void GetMedia(const G4String &namePattern, std::vector< TG4Medium * > &media, G4bool warn=true) const
Definition
TG4MediumMap.cxx:211
TG4Medium
Helper class to keep medium data.
Definition
TG4Medium.h:29
Generated on
for Geant4 VMC by
1.17.0