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
G4LogicalVolume* lv =
98
TG4GeometryServices::Instance
()->
FindLogicalVolume
(lvName);
99
100
if
(!lv) {
101
TG4Globals::Warning
(
"TG4MediumMap"
,
"MapMedium"
,
102
"Logical volume "
+ TString(lvName) +
" not defined."
);
103
return
;
104
}
105
106
MapMedium
(lv, mediumID);
107
}
108
109
//_____________________________________________________________________________
110
void
TG4MediumMap::Print
()
const
111
{
113
114
if
(
fIdMap
.size()) {
115
G4cout <<
"Dump of TG4MediumMap - "
<<
fIdMap
.size()
116
<<
" entries:"
<< G4endl;
117
G4int counter = 0;
118
std::map<G4int, TG4Medium*>::const_iterator it;
119
for
(it =
fIdMap
.begin(); it !=
fIdMap
.end(); ++it) {
120
G4cout <<
"Map element "
<< std::setw(3) << counter++ <<
" "
;
121
it->second->Print();
122
G4cout << G4endl;
123
}
124
}
125
}
126
127
//_____________________________________________________________________________
128
G4int
TG4MediumMap::GetNofMedia
()
const
129
{
131
132
return
fIdMap
.size();
133
}
134
135
//_____________________________________________________________________________
136
TG4Medium
*
TG4MediumMap::GetMedium
(G4int mediumID, G4bool warn)
const
137
{
139
140
std::map<G4int, TG4Medium*>::const_iterator it =
fIdMap
.find(mediumID);
141
142
if
(it ==
fIdMap
.end()) {
143
if
(warn) {
144
TString text =
"Medium with given ID="
;
145
text += mediumID;
146
text +=
" not defined."
;
147
TG4Globals::Warning
(
"TG4MediumMap"
,
"GetMedium"
, text);
148
}
149
return
0;
150
}
151
152
return
it->second;
153
}
154
155
//_____________________________________________________________________________
156
TG4Medium
*
TG4MediumMap::GetMedium
(
const
G4String& name, G4bool warn)
const
157
{
159
160
std::map<G4int, TG4Medium*>::const_iterator it;
161
for
(it =
fIdMap
.begin(); it !=
fIdMap
.end(); ++it)
162
if
(it->second->GetName() == name)
return
it->second;
163
164
// Give warning if not found
165
if
(warn) {
166
TG4Globals::Warning
(
"TG4MediumMap"
,
"GetMedium"
,
167
"Medium "
+ TString(name) +
" is not found."
);
168
}
169
return
0;
170
}
171
172
//_____________________________________________________________________________
173
TG4Medium
*
TG4MediumMap::GetMedium
(G4LogicalVolume* lv, G4bool warn)
const
174
{
176
177
std::map<G4LogicalVolume*, TG4Medium*>::const_iterator it =
fLVMap
.find(lv);
178
179
if
(it ==
fLVMap
.end()) {
180
if
(warn) {
181
TG4Globals::Warning
(
"TG4MediumMap"
,
"GetMedium"
,
182
"Medium for LV "
+ TString(lv->GetName()) +
" is not found."
);
183
}
184
return
0;
185
}
186
187
return
it->second;
188
}
189
190
//_____________________________________________________________________________
191
TG4Medium
*
TG4MediumMap::GetMedium
(
192
const
G4Material* material, G4bool warn)
const
193
{
195
196
std::map<const G4Material*, TG4Medium*>::const_iterator it =
197
fMaterialMap
.find(material);
198
199
if
(it ==
fMaterialMap
.end()) {
200
if
(warn) {
201
TG4Globals::Warning
(
"TG4MediumMap"
,
"GetMedium"
,
202
"Medium for material "
+ TString(material->GetName()) +
203
" is not found."
);
204
}
205
return
0;
206
}
207
208
return
it->second;
209
}
210
211
//_____________________________________________________________________________
212
void
TG4MediumMap::GetMedia
(
const
G4String& namePattern,
213
std::vector<TG4Medium*>& media, G4bool warn)
const
214
{
217
218
// Strip pattern
219
std::string pattern = namePattern;
220
if
(pattern.find(
"*"
) != std::string::npos) {
221
pattern.erase(pattern.find(
"*"
));
222
}
223
224
G4bool found =
false
;
225
std::map<G4int, TG4Medium*>::const_iterator it;
226
for
(it =
fIdMap
.begin(); it !=
fIdMap
.end(); ++it) {
227
if
(it->second->GetName().find(pattern) != std::string::npos) {
228
media.push_back(it->second);
229
found =
true
;
230
}
231
}
232
233
// Give warning if not found
234
if
(warn && (!found)) {
235
TG4Globals::Warning
(
"TG4MediumMap"
,
"GetMedia"
,
236
"No medium with name pattern "
+ TString(namePattern) +
" was found."
);
237
}
238
}
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::FindLogicalVolume
G4LogicalVolume * FindLogicalVolume(const G4String &name, G4bool silent=false) const
Definition
TG4GeometryServices.cxx:793
TG4GeometryServices::Instance
static TG4GeometryServices * Instance()
Definition
TG4GeometryServices.h:169
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:128
TG4MediumMap::GetMedium
TG4Medium * GetMedium(G4int mediumID, G4bool warn=true) const
Definition
TG4MediumMap.cxx:136
TG4MediumMap::Print
void Print() const
Definition
TG4MediumMap.cxx:110
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:212
TG4Medium
Helper class to keep medium data.
Definition
TG4Medium.h:29
Generated on
for Geant4 VMC by
1.17.0