Geant4 VMC Version 6.6
Loading...
Searching...
No Matches
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//_____________________________________________________________________________
32 : fMessenger(this)
33{}
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 worldLV = TG4GeometryServices::Instance()->GetWorld()->GetLogicalVolume();
55 auto worldMaterial = worldLV->GetMaterial();
56
57 // Define region for each logical volume
58 G4int counter = 0;
59 auto lvStore = G4LogicalVolumeStore::GetInstance();
60
61 for (std::size_t i = 0; i < lvStore->size(); ++i) {
62
63 auto lv = (*lvStore)[i];
64 auto materialName = lv->GetMaterial()->GetName();
65 // print debug message
66 if (VerboseLevel() > 1) {
67 G4cout << "-- Volume = " << i << " " << lv->GetName()
68 << " material = " << materialName << G4endl;
69 }
70
71 // skip world
72 if (lv == worldLV) {
73 if (VerboseLevel() > 1) {
74 G4cout << " " << "skipping worldVolume" << G4endl;
75 }
76 continue;
77 }
78
79 // skip volume if it has already a region assigned
80 if (lv->GetRegion() != nullptr &&
81 lv->GetRegion()->GetName() == materialName) {
82 if (VerboseLevel() > 1) {
83 G4cout << " "
84 << "has already region set, skipping" << G4endl;
85 }
86 continue;
87 }
88
89 // Get region fior this material, if it already exists,
90 // and add the logical volume
91 auto regionName = materialName;
92 auto region = g4RegionStore->GetRegion(regionName, false);
93 if (region != nullptr) {
94 if (lv->GetRegion() != region) {
95 // Add volume to the region per material if its region is different
96 // (by default the volume has the DefaultRegionForTheWorld)
97 if (VerboseLevel() > 1) {
98 G4cout << " "
99 << "adding volume in region = " << regionName << G4endl;
100 }
101 region->AddRootLogicalVolume(lv);
102 }
103 continue;
104 }
105
106 // After this line, the region does not exist
107 if (VerboseLevel() > 1) {
108 G4cout << " "
109 << "creating new region = " << regionName << G4endl;
110 }
111 region = new G4Region(regionName);
112 region->AddRootLogicalVolume(lv);
113 ++counter;
114 }
115
116 if (fIsCheck) {
118 }
119
120 if (VerboseLevel() > 0) {
121 G4cout << "Number of added regions: " << counter << G4endl;
122 }
123}
124
125//_____________________________________________________________________________
127{
129
130 if (VerboseLevel() > 1) {
131 G4cout << "Update G4 production cuts table" << G4endl;
132 }
133
134 auto mediumMap = TG4GeometryServices::Instance()->GetMediumMap();
135 auto g4ProductionCutsTable = G4ProductionCutsTable::GetProductionCutsTable();
136
137 // Global energy cuts
138 auto cutEleGlobal = GetGlobalEnergyCut(kCUTELE);
139 auto cutGamGlobal = GetGlobalEnergyCut(kCUTGAM);
140 auto cutHadGlobal = GetGlobalEnergyCut(kCUTHAD);
141
142 // cut vectors for gamma, e-, e+, proton
143 std::vector<G4double> gamCuts;
144 std::vector<G4double> eleCuts;
145 std::vector<G4double> hadCuts;
146
147 // G4cout << "g4RegionStore size: " << G4RegionStore::GetInstance()->size() << G4endl;
148 // G4cout << "g4ProductionCutsTable size: " << g4ProductionCutsTable->GetTableSize() << G4endl;
149
150 // update table (create materials cut couples)
151 g4ProductionCutsTable->CreateCoupleTables();
152 // G4cout << "g4ProductionCutsTable size after update: " << g4ProductionCutsTable->GetTableSize() << G4endl;
153
154 for (std::size_t i = 0; i < g4ProductionCutsTable->GetTableSize(); ++i) {
155 auto couple = g4ProductionCutsTable->GetMaterialCutsCouple(i);
156 auto material = couple->GetMaterial();
157 auto medium = mediumMap->GetMedium(material);
158
159 auto limits = (TG4Limits*)medium->GetLimits();
160 auto cutEle = GetEnergyCut(limits, kCUTELE, cutEleGlobal);
161 auto cutGam = GetEnergyCut(limits, kCUTGAM, cutGamGlobal);
162 auto cutHad = GetEnergyCut(limits, kCUTHAD, cutHadGlobal);
163
164 gamCuts.push_back(cutGam);
165 eleCuts.push_back(cutEle);
166 hadCuts.push_back(cutHad);
167 }
168
169 if (fApplyForGamma) {
170 g4ProductionCutsTable->SetEnergyCutVector(gamCuts, 0);
171 if (VerboseLevel() > 1) {
172 G4cout << "... table updated for Gamma with CUTGAM values" << G4endl;
173 }
174 }
175
176 if (fApplyForElectron) {
177 g4ProductionCutsTable->SetEnergyCutVector(eleCuts, 1);
178 if (VerboseLevel() > 1) {
179 G4cout << "... table updated for Electron with CUTELE values" << G4endl;
180 }
181 }
182
183 if (fApplyForPositron) {
184 g4ProductionCutsTable->SetEnergyCutVector(eleCuts, 2);
185 if (VerboseLevel() > 1) {
186 G4cout << "... table updated for Positron with CUTELE values" << G4endl;
187 }
188 }
189
190 if (fApplyForProton) {
191 g4ProductionCutsTable->SetEnergyCutVector(hadCuts, 3);
192 if (VerboseLevel() > 1) {
193 G4cout << "... table updated for proton with HADR values" << G4endl;
194 }
195 }
196}
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
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