Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4WeightWindowStore.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4WeightWindowStore implementation
27//
28// Author: Michael Dressel (CERN), 2003
29// Modified: Alex Howard (CERN), 2013 - Changed class to a 'singleton'
30// ----------------------------------------------------------------------
31
33#include "G4VPhysicalVolume.hh"
34#include "G4LogicalVolume.hh"
37
38// ***************************************************************************
39// Static class variable: ptr to single instance of class
40// ***************************************************************************
41G4ThreadLocal G4WeightWindowStore* G4WeightWindowStore::fInstance = nullptr;
42
45 : fWorldVolume(G4TransportationManager::GetTransportationManager()
46 ->GetNavigatorForTracking()->GetWorldVolume()),
47 fCurrentIterator(fCellToUpEnBoundLoWePairsMap.cend())
48{
49}
50
52G4WeightWindowStore(const G4String& ParallelWorldName)
53 : fWorldVolume(G4TransportationManager::GetTransportationManager()
54 ->GetParallelWorld(ParallelWorldName)),
55 fCurrentIterator(fCellToUpEnBoundLoWePairsMap.cend())
56{
57}
58
60
62GetLowerWeight(const G4GeometryCell& gCell,
63 G4double partEnergy) const
64{
65 SetInternalIterator(gCell);
66 auto gCellIterator = fCurrentIterator;
67 if (gCellIterator == fCellToUpEnBoundLoWePairsMap.cend())
68 {
69 Error("GetLowerWitgh() - Cell does not exist!");
70 return 0.;
71 }
72 G4UpperEnergyToLowerWeightMap upEnLoWeiPairs = fCurrentIterator->second;
73 G4double lowerWeight = -1;
74 G4bool found = false;
75 for (const auto & upEnLoWeiPair : upEnLoWeiPairs)
76 {
77 if (partEnergy < upEnLoWeiPair.first)
78 {
79 lowerWeight = upEnLoWeiPair.second;
80 found = true;
81 break;
82 }
83 }
84 if (!found)
85 {
86 std::ostringstream err_mess;
87 err_mess << "GetLowerWitgh() - Couldn't find lower weight bound." << G4endl
88 << "Energy: " << partEnergy << ".";
89 Error(err_mess.str());
90 }
91 return lowerWeight;
92}
93
94void G4WeightWindowStore::
95SetInternalIterator(const G4GeometryCell& gCell) const
96{
97 fCurrentIterator = fCellToUpEnBoundLoWePairsMap.find(gCell);
98}
99
100G4bool G4WeightWindowStore::
101IsInWorld(const G4VPhysicalVolume& aVolume) const
102{
103 G4bool isIn(true);
104 if (!(aVolume == *fWorldVolume))
105 {
106 isIn = fWorldVolume->GetLogicalVolume()->IsAncestor(&aVolume);
107 }
108 return isIn;
109}
110
112IsKnown(const G4GeometryCell& gCell) const
113{
114 G4bool inWorldKnown(IsInWorld(gCell.GetPhysicalVolume()));
115
116 if ( inWorldKnown )
117 {
118 SetInternalIterator(gCell);
119 inWorldKnown = (fCurrentIterator!=fCellToUpEnBoundLoWePairsMap.cend());
120 }
121 return inWorldKnown;
122}
123
125{
126 fCellToUpEnBoundLoWePairsMap.clear();
127}
128
130{
131 G4cout << " G4IStore:: SetWorldVolume " << G4endl;
134 G4cout << " World volume is: " << fWorldVolume->GetName() << G4endl;
135 // fGeometryCelli = new G4GeometryCellImportance;
136}
137
139{
141 ->GetParallelWorld(paraName);
142 // fGeometryCelli = new G4GeometryCellImportance;
143}
144
146{
147 return *fWorldVolume;
148}
149
152{
153 return fWorldVolume;
154}
155
158 const std::vector<G4double>& lowerWeights)
159{
160 if (fGeneralUpperEnergyBounds.empty())
161 {
162 Error("AddLowerWeights() - No general upper energy limits set!");
163 }
164 if (IsKnown(gCell))
165 {
166 Error("AddLowerWeights() - Cell already in the store.");
167 }
168 if (lowerWeights.size() != fGeneralUpperEnergyBounds.size())
169 {
170 std::ostringstream err_mess;
171 err_mess << "AddLowerWeights() - Mismatch between "
172 << "number of lower weights (" << lowerWeights.size()
173 << ") and energy bounds (" << fGeneralUpperEnergyBounds.size()
174 << ")!";
175 Error(err_mess.str());
176 }
178 G4int i = 0;
179 for (G4double fGeneralUpperEnergyBound : fGeneralUpperEnergyBounds)
180 {
181 map[fGeneralUpperEnergyBound] = lowerWeights[i];
182 ++i;
183 }
184 fCellToUpEnBoundLoWePairsMap[gCell] = map;
185}
186
189 const G4UpperEnergyToLowerWeightMap& enWeMap)
190{
191 if (IsKnown(gCell))
192 {
193 Error("AddUpperEboundLowerWeightPairs() - Cell already in the store.");
194 }
195 if (IsKnown(gCell))
196 {
197 Error("AddUpperEboundLowerWeightPairs() - Cell already in the store.");
198 }
199 fCellToUpEnBoundLoWePairsMap[gCell] = enWeMap;
200
201}
202
205 std::less<G4double> >& enBounds)
206{
207 if (!fGeneralUpperEnergyBounds.empty())
208 {
209 Error("SetGeneralUpperEnergyBounds() - Energy bounds already set.");
210 }
211 fGeneralUpperEnergyBounds = enBounds;
212}
213
214void G4WeightWindowStore::Error(const G4String& msg) const
215{
216 G4Exception("G4WeightWindowStore::Error()",
217 "GeomBias0002", FatalException, msg);
218}
219
220// ***************************************************************************
221// Returns the instance of the singleton.
222// Creates it in case it's called for the first time.
223// ***************************************************************************
224//
226{
227 if (fInstance == nullptr)
228 {
229 fInstance = new G4WeightWindowStore();
230 }
231 return fInstance;
232}
233
234// ***************************************************************************
235// Returns the instance of the singleton.
236// Creates it in case it's called for the first time.
237// ***************************************************************************
238//
240GetInstance(const G4String& ParallelWorldName)
241{
242 if (fInstance == nullptr)
243 {
244#ifdef G4VERBOSE
245 G4cout << "G4IStore:: Creating new Parallel IStore "
246 << ParallelWorldName << G4endl;
247#endif
248 fInstance = new G4WeightWindowStore(ParallelWorldName);
249 }
250 return fInstance;
251}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::map< G4double, G4double, std::less< G4double > > G4UpperEnergyToLowerWeightMap
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
const G4VPhysicalVolume & GetPhysicalVolume() const
G4bool IsAncestor(const G4VPhysicalVolume *p) const
G4VPhysicalVolume * GetWorldVolume() const
G4VPhysicalVolume * GetParallelWorld(const G4String &worldName)
static G4TransportationManager * GetTransportationManager()
G4Navigator * GetNavigatorForTracking() const
G4LogicalVolume * GetLogicalVolume() const
const G4String & GetName() const
void AddLowerWeights(const G4GeometryCell &gCell, const std::vector< G4double > &lowerWeights)
~G4WeightWindowStore() override
void SetParallelWorldVolume(const G4String &paraName)
virtual const G4VPhysicalVolume * GetParallelWorldVolumePointer() const
void SetGeneralUpperEnergyBounds(const std::set< G4double, std::less< G4double > > &enBounds)
static G4WeightWindowStore * GetInstance()
G4bool IsKnown(const G4GeometryCell &gCell) const override
const G4VPhysicalVolume & GetWorldVolume() const override
G4double GetLowerWeight(const G4GeometryCell &gCell, G4double partEnergy) const override
void AddUpperEboundLowerWeightPairs(const G4GeometryCell &gCell, const G4UpperEnergyToLowerWeightMap &enWeMap)
#define G4ThreadLocal
Definition tls.hh:77