Geant4 VMC Version 6.7
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
TG4RegionsManager2.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Geant4 Virtual Monte Carlo package
3// Copyright (C) 2007 - 2023 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 "TG4RegionsManager2.h"
16#include "TG4GeometryServices.h"
17#include "TG4Globals.h"
18#include "TG4Limits.h"
19#include "TG4Medium.h"
20#include "TG4PhysicsManager.h"
21
22#include <G4LogicalVolumeStore.hh>
23#include <G4Material.hh>
24#include <G4ProductionCuts.hh>
25#include <G4ProductionCutsTable.hh>
26#include <G4Region.hh>
27#include <G4RegionStore.hh>
28#include <G4SystemOfUnits.hh>
29
30//_____________________________________________________________________________
34
35//
36// public methods
37//
38
39//_____________________________________________________________________________
41{
43
44 if (VerboseLevel() > 0) {
45 G4cout << "Define regions for VMC cuts per materials." << G4endl;
46 }
47
48 // Get medium map
49 auto mediumMap = TG4GeometryServices::Instance()->GetMediumMap();
50 // Get G4 region store
51 auto g4RegionStore = G4RegionStore::GetInstance();
52
53 // Get world volume & material
54 auto worldPV = TG4GeometryServices::Instance()->GetWorld();
55 auto worldLV = worldPV->GetLogicalVolume();
56 auto worldMaterial = worldLV->GetMaterial();
57
58 // Get default production cuts
59 auto defaultProductionCuts
60 = G4ProductionCutsTable::GetProductionCutsTable()->GetDefaultProductionCuts();
61
62 // Define region for each logical volume
63 G4int counter = 0;
64 auto lvStore = G4LogicalVolumeStore::GetInstance();
65
66 for (std::size_t i = 0; i < lvStore->size(); ++i) {
67
68 auto lv = (*lvStore)[i];
69 auto materialName = lv->GetMaterial()->GetName();
70 // print debug message
71 if (VerboseLevel() > 1) {
72 G4cout << "-- Volume = " << i << " " << lv->GetName()
73 << " material = " << materialName << G4endl;
74 }
75
76 // skip world
77 if (lv == worldLV) {
78 if (VerboseLevel() > 1) {
79 G4cout << " " << "skipping worldVolume" << G4endl;
80 }
81 continue;
82 }
83
84 // skip volume if it has already a region assigned
85 if (lv->GetRegion() != nullptr &&
86 lv->GetRegion()->GetName() == materialName) {
87 if (VerboseLevel() > 1) {
88 G4cout << " "
89 // << lv->GetRegion() << " "
90 // << lv->GetRegion()->GetName()
91 << "has already region set, skipping" << G4endl;
92 }
93 continue;
94 }
95
96 // Get region fior this material, if it already exists,
97 // and add the logical volume
98 auto regionName = materialName;
99 auto region = g4RegionStore->GetRegion(regionName, false);
100 if (region != nullptr) {
101 if (lv->GetRegion() != region) {
102 // Add volume to the region per material if its region is different
103 // (by default the volume has the DefaultRegionForTheWorld)
104 if (VerboseLevel() > 1) {
105 G4cout << " "
106 << "adding volume in region = " << regionName << G4endl;
107 }
108 region->AddRootLogicalVolume(lv);
109 }
110 continue;
111 }
112
113 // After this line, the region does not exist
114 if (VerboseLevel() > 1) {
115 G4cout << " "
116 << "creating new region = " << regionName << G4endl;
117 }
118 region = new G4Region(regionName);
119 region->AddRootLogicalVolume(lv);
120 region->UsedInMassGeometry(true);
121 region->SetProductionCuts(defaultProductionCuts);
122 ++counter;
123 }
124
125 // Update material lists in regions
126 // (to make the regions ready for UpdateProductionCutsTable by us
127 // as this happens earlier then G4RunManagerKernel::UpdateRegion() call)
128 g4RegionStore->UpdateMaterialList(worldPV);
129
130 if (fIsCheck) {
132 }
133
134 if (VerboseLevel() > 0) {
135 G4cout << "Number of added regions: " << counter << G4endl;
136 }
137}
138
139//_____________________________________________________________________________
141{
143
144 if (VerboseLevel() > 1) {
145 G4cout << "Update G4 production cuts table" << G4endl;
146 }
147
148 auto mediumMap = TG4GeometryServices::Instance()->GetMediumMap();
149 auto g4ProductionCutsTable = G4ProductionCutsTable::GetProductionCutsTable();
150
151 // Global energy cuts
152 auto cutEleGlobal = GetGlobalEnergyCut(kCUTELE);
153 auto cutGamGlobal = GetGlobalEnergyCut(kCUTGAM);
154 auto cutHadGlobal = GetGlobalEnergyCut(kCUTHAD);
155
156 // cut vectors for gamma, e-, e+, proton
157 std::vector<G4double> gamCuts;
158 std::vector<G4double> eleCuts;
159 std::vector<G4double> hadCuts;
160
161 // G4cout << "g4RegionStore size: " << G4RegionStore::GetInstance()->size() << G4endl;
162 // G4cout << "g4ProductionCutsTable size: " << g4ProductionCutsTable->GetTableSize() << G4endl;
163
164 // update table (create materials cut couples)
165 g4ProductionCutsTable->CreateCoupleTables();
166 // G4cout << "g4ProductionCutsTable size after update: " << g4ProductionCutsTable->GetTableSize() << G4endl;
167
168#if G4VERSION_NUMBER <= 1130
169 // reset materials to force cuts recalculation
170 for (std::size_t i = 0; i < g4ProductionCutsTable->GetTableSize(); ++i) {
171 auto couple = const_cast<G4MaterialCutsCouple*>(g4ProductionCutsTable->GetMaterialCutsCouple(i));
172 auto material = couple->GetMaterial();
173 couple->SetMaterial(material);
174 }
175#endif
176
177 for (std::size_t i = 0; i < g4ProductionCutsTable->GetTableSize(); ++i) {
178 auto couple = g4ProductionCutsTable->GetMaterialCutsCouple(i);
179 auto material = couple->GetMaterial();
180 auto medium = mediumMap->GetMedium(material);
181
182 auto limits = (TG4Limits*)medium->GetLimits();
183 auto cutEle = GetEnergyCut(limits, kCUTELE, cutEleGlobal);
184 auto cutGam = GetEnergyCut(limits, kCUTGAM, cutGamGlobal);
185 auto cutHad = GetEnergyCut(limits, kCUTHAD, cutHadGlobal);
186
187 gamCuts.push_back(cutGam);
188 eleCuts.push_back(cutEle);
189 hadCuts.push_back(cutHad);
190 }
191
192 if (fApplyForGamma) {
193 g4ProductionCutsTable->SetEnergyCutVector(gamCuts, 0);
194 if (VerboseLevel() > 1) {
195 G4cout << "... table updated for Gamma with CUTGAM values" << G4endl;
196 }
197 }
198
199 if (fApplyForElectron) {
200 g4ProductionCutsTable->SetEnergyCutVector(eleCuts, 1);
201 if (VerboseLevel() > 1) {
202 G4cout << "... table updated for Electron with CUTELE values" << G4endl;
203 }
204 }
205
206 if (fApplyForPositron) {
207 g4ProductionCutsTable->SetEnergyCutVector(eleCuts, 2);
208 if (VerboseLevel() > 1) {
209 G4cout << "... table updated for Positron with CUTELE values" << G4endl;
210 }
211 }
212
213 if (fApplyForProton) {
214 g4ProductionCutsTable->SetEnergyCutVector(hadCuts, 3);
215 if (VerboseLevel() > 1) {
216 G4cout << "... table updated for proton with HADR values" << G4endl;
217 }
218 }
219}
Definition of the TG4GeometryServices class.
Definition of the TG4Globals class and basic container types.
Definition of the TG4Limits class.
Definition of the TG4Medium class.
Definition of the TG4PhysicsManager class.
Definition of the TG4RegionsManager2 class.
G4VPhysicalVolume * GetWorld() const
static TG4GeometryServices * Instance()
TG4MediumMap * GetMediumMap() const
Extended G4UserLimits class.
Definition TG4Limits.h:38
TG4RegionsMessenger fMessenger
messenger
void UpdateProductionCutsTable() override
void DefineRegions() override
G4bool fIsCheck
option to perform consistency check (by default false)
G4bool fApplyForElectron
option to apply cuts for e- (default is true)
G4bool fApplyForPositron
option to apply cuts for e+ (default is true)
G4double GetEnergyCut(TG4Limits *limits, TG4G3Cut cutType, G4double globalCutValue) const
G4bool fApplyForGamma
option to apply cuts for gamma (default is true)
void CheckRegionsInGeometry() const
G4bool fApplyForProton
option to apply cuts for proton (default is true)
G4double GetGlobalEnergyCut(TG4G3Cut cutType) const
virtual G4int VerboseLevel() const
Definition TG4Verbose.h:78
@ kCUTGAM
Definition TG4G3Cut.h:27
@ kCUTHAD
Definition TG4G3Cut.h:42
@ kCUTELE
Definition TG4G3Cut.h:32