Geant4 11.1.1
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 fGeneralUpperEnergyBounds(),
48 fCellToUpEnBoundLoWePairsMap(),
49 fCurrentIterator(fCellToUpEnBoundLoWePairsMap.cend())
50{
51}
52
54G4WeightWindowStore(const G4String& ParallelWorldName)
55 : fWorldVolume(G4TransportationManager::GetTransportationManager()
56 ->GetParallelWorld(ParallelWorldName)),
57 fGeneralUpperEnergyBounds(),
58 fCellToUpEnBoundLoWePairsMap(),
59 fCurrentIterator(fCellToUpEnBoundLoWePairsMap.cend())
60{
61}
62
65{
66}
67
69GetLowerWeight(const G4GeometryCell& gCell,
70 G4double partEnergy) const
71{
72 SetInternalIterator(gCell);
73 auto gCellIterator = fCurrentIterator;
74 if (gCellIterator == fCellToUpEnBoundLoWePairsMap.cend())
75 {
76 Error("GetLowerWitgh() - Cell does not exist!");
77 return 0.;
78 }
79 G4UpperEnergyToLowerWeightMap upEnLoWeiPairs = fCurrentIterator->second;
80 G4double lowerWeight = -1;
81 G4bool found = false;
82 for (auto it = upEnLoWeiPairs.cbegin(); it != upEnLoWeiPairs.cend(); ++it)
83 {
84 if (partEnergy < it->first)
85 {
86 lowerWeight = it->second;
87 found = true;
88 break;
89 }
90 }
91 if (!found)
92 {
93 std::ostringstream err_mess;
94 err_mess << "GetLowerWitgh() - Couldn't find lower weight bound." << G4endl
95 << "Energy: " << partEnergy << ".";
96 Error(err_mess.str());
97 }
98 return lowerWeight;
99}
100
101void G4WeightWindowStore::
102SetInternalIterator(const G4GeometryCell& gCell) const
103{
104 fCurrentIterator = fCellToUpEnBoundLoWePairsMap.find(gCell);
105}
106
107G4bool G4WeightWindowStore::
108IsInWorld(const G4VPhysicalVolume& aVolume) const
109{
110 G4bool isIn(true);
111 if (!(aVolume == *fWorldVolume))
112 {
113 isIn = fWorldVolume->GetLogicalVolume()->IsAncestor(&aVolume);
114 }
115 return isIn;
116}
117
119IsKnown(const G4GeometryCell& gCell) const
120{
121 G4bool inWorldKnown(IsInWorld(gCell.GetPhysicalVolume()));
122
123 if ( inWorldKnown )
124 {
125 SetInternalIterator(gCell);
126 inWorldKnown = (fCurrentIterator!=fCellToUpEnBoundLoWePairsMap.cend());
127 }
128 return inWorldKnown;
129}
130
132{
133 fCellToUpEnBoundLoWePairsMap.clear();
134}
135
137{
138 G4cout << " G4IStore:: SetWorldVolume " << G4endl;
141 G4cout << " World volume is: " << fWorldVolume->GetName() << G4endl;
142 // fGeometryCelli = new G4GeometryCellImportance;
143}
144
146{
148 ->GetParallelWorld(paraName);
149 // fGeometryCelli = new G4GeometryCellImportance;
150}
151
153{
154 return *fWorldVolume;
155}
156
159{
160 return fWorldVolume;
161}
162
165 const std::vector<G4double>& lowerWeights)
166{
167 if (fGeneralUpperEnergyBounds.empty())
168 {
169 Error("AddLowerWeights() - No general upper energy limits set!");
170 }
171 if (IsKnown(gCell))
172 {
173 Error("AddLowerWeights() - Cell already in the store.");
174 }
175 if (lowerWeights.size() != fGeneralUpperEnergyBounds.size())
176 {
177 std::ostringstream err_mess;
178 err_mess << "AddLowerWeights() - Mismatch between "
179 << "number of lower weights (" << lowerWeights.size()
180 << ") and energy bounds (" << fGeneralUpperEnergyBounds.size()
181 << ")!";
182 Error(err_mess.str());
183 }
185 G4int i = 0;
186 for (auto it = fGeneralUpperEnergyBounds.cbegin();
187 it != fGeneralUpperEnergyBounds.cend(); ++it)
188 {
189 map[*it] = lowerWeights[i];
190 ++i;
191 }
192 fCellToUpEnBoundLoWePairsMap[gCell] = map;
193}
194
197 const G4UpperEnergyToLowerWeightMap& enWeMap)
198{
199 if (IsKnown(gCell))
200 {
201 Error("AddUpperEboundLowerWeightPairs() - Cell already in the store.");
202 }
203 if (IsKnown(gCell))
204 {
205 Error("AddUpperEboundLowerWeightPairs() - Cell already in the store.");
206 }
207 fCellToUpEnBoundLoWePairsMap[gCell] = enWeMap;
208
209}
210
213 std::less<G4double> >& enBounds)
214{
215 if (!fGeneralUpperEnergyBounds.empty())
216 {
217 Error("SetGeneralUpperEnergyBounds() - Energy bounds already set.");
218 }
219 fGeneralUpperEnergyBounds = enBounds;
220}
221
222void G4WeightWindowStore::Error(const G4String& msg) const
223{
224 G4Exception("G4WeightWindowStore::Error()",
225 "GeomBias0002", FatalException, msg);
226}
227
228// ***************************************************************************
229// Returns the instance of the singleton.
230// Creates it in case it's called for the first time.
231// ***************************************************************************
232//
234{
235 if (fInstance == nullptr)
236 {
237 fInstance = new G4WeightWindowStore();
238 }
239 return fInstance;
240}
241
242// ***************************************************************************
243// Returns the instance of the singleton.
244// Creates it in case it's called for the first time.
245// ***************************************************************************
246//
248GetInstance(const G4String& ParallelWorldName)
249{
250 if (fInstance == nullptr)
251 {
252#ifdef G4VERBOSE
253 G4cout << "G4IStore:: Creating new Parallel IStore "
254 << ParallelWorldName << G4endl;
255#endif
256 fInstance = new G4WeightWindowStore(ParallelWorldName);
257 }
258 return fInstance;
259}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
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:57
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)
void SetParallelWorldVolume(const G4String &paraName)
virtual const G4VPhysicalVolume * GetParallelWorldVolumePointer() const
void SetGeneralUpperEnergyBounds(const std::set< G4double, std::less< G4double > > &enBounds)
virtual const G4VPhysicalVolume & GetWorldVolume() const
static G4WeightWindowStore * GetInstance()
virtual G4bool IsKnown(const G4GeometryCell &gCell) const
virtual G4double GetLowerWeight(const G4GeometryCell &gCell, G4double partEnergy) const
void AddUpperEboundLowerWeightPairs(const G4GeometryCell &gCell, const G4UpperEnergyToLowerWeightMap &enWeMap)
#define G4ThreadLocal
Definition: tls.hh:77