Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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
43G4WeightWindowStore::
44G4WeightWindowStore()
45 : fWorldVolume(G4TransportationManager::GetTransportationManager()
46 ->GetNavigatorForTracking()->GetWorldVolume()),
47 fCurrentIterator(fCellToUpEnBoundLoWePairsMap.cend())
48{
49}
50
51G4WeightWindowStore::
52G4WeightWindowStore(const G4String& ParallelWorldName)
53 : fWorldVolume(G4TransportationManager::GetTransportationManager()
54 ->GetParallelWorld(ParallelWorldName)),
55 fCurrentIterator(fCellToUpEnBoundLoWePairsMap.cend())
56{
57}
58
60GetLowerWeight(const G4GeometryCell& gCell,
61 G4double partEnergy) const
62{
63 SetInternalIterator(gCell);
64 auto gCellIterator = fCurrentIterator;
65 if (gCellIterator == fCellToUpEnBoundLoWePairsMap.cend())
66 {
67 Error("GetLowerWitgh() - Cell does not exist!");
68 return 0.;
69 }
70 G4UpperEnergyToLowerWeightMap upEnLoWeiPairs = fCurrentIterator->second;
71 G4double lowerWeight = -1;
72 G4bool found = false;
73 for (const auto & upEnLoWeiPair : upEnLoWeiPairs)
74 {
75 if (partEnergy < upEnLoWeiPair.first)
76 {
77 lowerWeight = upEnLoWeiPair.second;
78 found = true;
79 break;
80 }
81 }
82 if (!found)
83 {
84 std::ostringstream err_mess;
85 err_mess << "GetLowerWitgh() - Couldn't find lower weight bound." << G4endl
86 << "Energy: " << partEnergy << ".";
87 Error(err_mess.str());
88 }
89 return lowerWeight;
90}
91
92void G4WeightWindowStore::
93SetInternalIterator(const G4GeometryCell& gCell) const
94{
95 fCurrentIterator = fCellToUpEnBoundLoWePairsMap.find(gCell);
96}
97
98G4bool G4WeightWindowStore::
99IsInWorld(const G4VPhysicalVolume& aVolume) const
100{
101 G4bool isIn(true);
102 if (!(aVolume == *fWorldVolume))
103 {
104 isIn = fWorldVolume->GetLogicalVolume()->IsAncestor(&aVolume);
105 }
106 return isIn;
107}
108
110IsKnown(const G4GeometryCell& gCell) const
111{
112 G4bool inWorldKnown(IsInWorld(gCell.GetPhysicalVolume()));
113
114 if ( inWorldKnown )
115 {
116 SetInternalIterator(gCell);
117 inWorldKnown = (fCurrentIterator!=fCellToUpEnBoundLoWePairsMap.cend());
118 }
119 return inWorldKnown;
120}
121
123{
124 fCellToUpEnBoundLoWePairsMap.clear();
125}
126
128{
129 G4cout << " G4IStore:: SetWorldVolume " << G4endl;
132 G4cout << " World volume is: " << fWorldVolume->GetName() << G4endl;
133 // fGeometryCelli = new G4GeometryCellImportance;
134}
135
137{
139 ->GetParallelWorld(paraName);
140 // fGeometryCelli = new G4GeometryCellImportance;
141}
142
144{
145 return *fWorldVolume;
146}
147
150{
151 return fWorldVolume;
152}
153
156 const std::vector<G4double>& lowerWeights)
157{
158 if (fGeneralUpperEnergyBounds.empty())
159 {
160 Error("AddLowerWeights() - No general upper energy limits set!");
161 }
162 if (IsKnown(gCell))
163 {
164 Error("AddLowerWeights() - Cell already in the store.");
165 }
166 if (lowerWeights.size() != fGeneralUpperEnergyBounds.size())
167 {
168 std::ostringstream err_mess;
169 err_mess << "AddLowerWeights() - Mismatch between "
170 << "number of lower weights (" << lowerWeights.size()
171 << ") and energy bounds (" << fGeneralUpperEnergyBounds.size()
172 << ")!";
173 Error(err_mess.str());
174 }
176 G4int i = 0;
177 for (G4double fGeneralUpperEnergyBound : fGeneralUpperEnergyBounds)
178 {
179 map[fGeneralUpperEnergyBound] = lowerWeights[i];
180 ++i;
181 }
182 fCellToUpEnBoundLoWePairsMap[gCell] = std::move(map);
183}
184
187 const G4UpperEnergyToLowerWeightMap& enWeMap)
188{
189 if (IsKnown(gCell))
190 {
191 Error("AddUpperEboundLowerWeightPairs() - Cell already in the store.");
192 }
193 if (IsKnown(gCell))
194 {
195 Error("AddUpperEboundLowerWeightPairs() - Cell already in the store.");
196 }
197 fCellToUpEnBoundLoWePairsMap[gCell] = enWeMap;
198
199}
200
203 std::less<G4double> >& enBounds)
204{
205 if (!fGeneralUpperEnergyBounds.empty())
206 {
207 Error("SetGeneralUpperEnergyBounds() - Energy bounds already set.");
208 }
209 fGeneralUpperEnergyBounds = enBounds;
210}
211
212void G4WeightWindowStore::Error(const G4String& msg) const
213{
214 G4Exception("G4WeightWindowStore::Error()",
215 "GeomBias0002", FatalException, msg);
216}
217
218// ***************************************************************************
219// Returns the instance of the singleton.
220// Creates it in case it's called for the first time.
221// ***************************************************************************
222//
224{
225 if (fInstance == nullptr)
226 {
227 fInstance = new G4WeightWindowStore();
228 }
229 return fInstance;
230}
231
232// ***************************************************************************
233// Returns the instance of the singleton.
234// Creates it in case it's called for the first time.
235// ***************************************************************************
236//
237G4WeightWindowStore* G4WeightWindowStore::
238GetInstance(const G4String& ParallelWorldName)
239{
240 if (fInstance == nullptr)
241 {
242#ifdef G4VERBOSE
243 G4cout << "G4IStore:: Creating new Parallel IStore "
244 << ParallelWorldName << G4endl;
245#endif
246 fInstance = new G4WeightWindowStore(ParallelWorldName);
247 }
248 return fInstance;
249}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::map< G4double, G4double, std::less< G4double > > G4UpperEnergyToLowerWeightMap
G4UpperEnergyToLowerWeightMap and G4GeometryCellWeight are maps used internally by the weight window ...
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
G4GeometryCell is used for scoring and importance sampling. It defines a "cell", which,...
const G4VPhysicalVolume & GetPhysicalVolume() const
G4VPhysicalVolume * GetWorldVolume() const
G4TransportationManager is a singleton class which stores the navigator used by the transportation pr...
G4VPhysicalVolume * GetParallelWorld(const G4String &worldName)
static G4TransportationManager * GetTransportationManager()
G4Navigator * GetNavigatorForTracking() const
G4VPhysicalVolume is an abstract base class for the representation of a positioned volume....
G4WeightWindowStore is an concrete implementation of a weight window store according to the G4VWeight...
void AddLowerWeights(const G4GeometryCell &gCell, const std::vector< G4double > &lowerWeights)
void SetParallelWorldVolume(const G4String &paraName)
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