Geant4 9.6.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//
27// $Id$
28//
29// ----------------------------------------------------------------------
30// GEANT 4 class source file
31//
32// G4WeightWindowStore
33//
34// ----------------------------------------------------------------------
35
36
38#include "G4VPhysicalVolume.hh"
39#include "G4LogicalVolume.hh"
41
42
44G4WeightWindowStore(const G4VPhysicalVolume &worldvolume) :
45 fWorldVolume(worldvolume),
46 fGeneralUpperEnergyBounds(),
47 fCellToUpEnBoundLoWePairsMap(),
48 fCurrentIterator(fCellToUpEnBoundLoWePairsMap.end())
49{}
50
52{}
53
54
56 G4double partEnergy) const
57{
58 SetInternalIterator(gCell);
59 G4GeometryCellWeight::const_iterator gCellIterator = fCurrentIterator;
60 if (gCellIterator == fCellToUpEnBoundLoWePairsMap.end()) {
61 Error("GetLowerWitgh() - Cell does not exist!");
62 return 0.;
63 }
64 G4UpperEnergyToLowerWeightMap upEnLoWeiPairs =
65 fCurrentIterator->second;
66 G4double lowerWeight = -1;
67 G4bool found = false;
68 for (G4UpperEnergyToLowerWeightMap::iterator it =
69 upEnLoWeiPairs.begin(); it != upEnLoWeiPairs.end(); it++) {
70 if (partEnergy < it->first) {
71 lowerWeight = it->second;
72 found = true;
73 break;
74 }
75 }
76 if (!found) {
77 std::ostringstream err_mess;
78 err_mess << "GetLowerWitgh() - Couldn't find lower weight bound." << G4endl
79 << "Energy: " << partEnergy << ".";
80 Error(err_mess.str());
81 }
82 return lowerWeight;
83
84
85}
86
87void G4WeightWindowStore::
88SetInternalIterator(const G4GeometryCell &gCell) const
89{
90 fCurrentIterator = fCellToUpEnBoundLoWePairsMap.find(gCell);
91}
92
93G4bool G4WeightWindowStore::
94IsInWorld(const G4VPhysicalVolume &aVolume) const
95{
96 G4bool isIn(true);
97 if (!(aVolume == fWorldVolume)) {
98 isIn = fWorldVolume.GetLogicalVolume()->IsAncestor(&aVolume);
99 }
100 return isIn;
101}
102
103
105{
106 G4bool inWorldKnown(IsInWorld(gCell.GetPhysicalVolume()));
107
108 if ( inWorldKnown ) {
109 SetInternalIterator(gCell);
110 inWorldKnown = (fCurrentIterator!=fCellToUpEnBoundLoWePairsMap.end());
111 }
112 return inWorldKnown;
113}
114
115
117{
118 return fWorldVolume;
119}
120
121
123AddLowerWeights(const G4GeometryCell & gCell,
124 const std::vector<G4double> &lowerWeights)
125{
126 if (fGeneralUpperEnergyBounds.empty()) {
127 Error("AddLowerWeights() - No general upper energy limits set!");
128 }
129 if (IsKnown(gCell)) {
130 Error("AddLowerWeights() - Cell already in the store.");
131 }
132 if (lowerWeights.size() != fGeneralUpperEnergyBounds.size()) {
133 std::ostringstream err_mess;
134 err_mess << "AddLowerWeights() - Mismatch between "
135 << "number of lower weights (" << lowerWeights.size()
136 << ") and energy bounds (" << fGeneralUpperEnergyBounds.size()
137 << ")!";
138 Error(err_mess.str());
139 }
141 G4int i = 0;
142 for (std::set<G4double, std::less<G4double> >::iterator it =
143 fGeneralUpperEnergyBounds.begin();
144 it != fGeneralUpperEnergyBounds.end();
145 it++) {
146 map[*it] = lowerWeights[i];
147 i++;
148 }
149 fCellToUpEnBoundLoWePairsMap[gCell] = map;
150}
151
152
155 const G4UpperEnergyToLowerWeightMap& enWeMap)
156{
157 if (IsKnown(gCell)) {
158 Error("AddUpperEboundLowerWeightPairs() - Cell already in the store.");
159 }
160 if (IsKnown(gCell)) {
161 Error("AddUpperEboundLowerWeightPairs() - Cell already in the store.");
162 }
163 fCellToUpEnBoundLoWePairsMap[gCell] = enWeMap;
164
165}
166
167
170 std::less<G4double> > &enBounds)
171{
172 if (!fGeneralUpperEnergyBounds.empty()) {
173 Error("SetGeneralUpperEnergyBounds() - Energy bounds already set.");
174 }
175 fGeneralUpperEnergyBounds = enBounds;
176}
177
178
179void G4WeightWindowStore::Error(const G4String &msg) const
180{
181 G4Exception("G4WeightWindowStore::Error()",
182 "GeomBias0002", FatalException, msg);
183}
@ FatalException
std::map< G4double, G4double, std::less< G4double > > G4UpperEnergyToLowerWeightMap
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
const G4VPhysicalVolume & GetPhysicalVolume() const
G4bool IsAncestor(const G4VPhysicalVolume *p) const
G4LogicalVolume * GetLogicalVolume() const
void AddLowerWeights(const G4GeometryCell &gCell, const std::vector< G4double > &lowerWeights)
void SetGeneralUpperEnergyBounds(const std::set< G4double, std::less< G4double > > &enBounds)
const G4VPhysicalVolume & GetWorldVolume() const
G4bool IsKnown(const G4GeometryCell &gCell) const
G4double GetLowerWeight(const G4GeometryCell &gCell, G4double partEnergy) const
G4WeightWindowStore(const G4VPhysicalVolume &worldvolume)
void AddUpperEboundLowerWeightPairs(const G4GeometryCell &gCell, const G4UpperEnergyToLowerWeightMap &enWeMap)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41