Geant4_10
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: G4WeightWindowStore.cc 77780 2013-11-28 07:50:59Z gcosmo $
28 //
29 // ----------------------------------------------------------------------
30 // GEANT 4 class source file
31 //
32 // G4WeightWindowStore
33 //
34 // ----------------------------------------------------------------------
35 
36 
37 #include "G4WeightWindowStore.hh"
38 #include "G4VPhysicalVolume.hh"
39 #include "G4LogicalVolume.hh"
42 
43 // ***************************************************************************
44 // Static class variable: ptr to single instance of class
45 // ***************************************************************************
46 //G4ThreadLocal
47 G4WeightWindowStore* G4WeightWindowStore::fInstance = 0;
48 
49 
50 
53 fWorldVolume(G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume()),
54  fGeneralUpperEnergyBounds(),
55  fCellToUpEnBoundLoWePairsMap(),
56  fCurrentIterator(fCellToUpEnBoundLoWePairsMap.end())
57 {}
58 
60 G4WeightWindowStore(G4String ParallelWorldName) :
61 fWorldVolume(G4TransportationManager::GetTransportationManager()->GetParallelWorld(ParallelWorldName)),
62  fGeneralUpperEnergyBounds(),
63  fCellToUpEnBoundLoWePairsMap(),
64  fCurrentIterator(fCellToUpEnBoundLoWePairsMap.end())
65 {}
66 
68 {}
69 
70 
72  G4double partEnergy) const
73 {
74  SetInternalIterator(gCell);
75  G4GeometryCellWeight::const_iterator gCellIterator = fCurrentIterator;
76  if (gCellIterator == fCellToUpEnBoundLoWePairsMap.end()) {
77  Error("GetLowerWitgh() - Cell does not exist!");
78  return 0.;
79  }
80  G4UpperEnergyToLowerWeightMap upEnLoWeiPairs =
81  fCurrentIterator->second;
82  G4double lowerWeight = -1;
83  G4bool found = false;
84  for (G4UpperEnergyToLowerWeightMap::iterator it =
85  upEnLoWeiPairs.begin(); it != upEnLoWeiPairs.end(); it++) {
86  if (partEnergy < it->first) {
87  lowerWeight = it->second;
88  found = true;
89  break;
90  }
91  }
92  if (!found) {
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 
101 }
102 
103 void G4WeightWindowStore::
104 SetInternalIterator(const G4GeometryCell &gCell) const
105 {
106  fCurrentIterator = fCellToUpEnBoundLoWePairsMap.find(gCell);
107 }
108 
109 G4bool G4WeightWindowStore::
110 IsInWorld(const G4VPhysicalVolume &aVolume) const
111 {
112  G4bool isIn(true);
113  if (!(aVolume == *fWorldVolume)) {
114  isIn = fWorldVolume->GetLogicalVolume()->IsAncestor(&aVolume);
115  }
116  return isIn;
117 }
118 
119 
121 {
122  G4bool inWorldKnown(IsInWorld(gCell.GetPhysicalVolume()));
123 
124  if ( inWorldKnown ) {
125  SetInternalIterator(gCell);
126  inWorldKnown = (fCurrentIterator!=fCellToUpEnBoundLoWePairsMap.end());
127  }
128  return inWorldKnown;
129 }
130 
132 {
133  fCellToUpEnBoundLoWePairsMap.clear();
134 }
135 
137 {
138  G4cout << " G4IStore:: SetWorldVolume " << G4endl;
140  G4cout << " World volume is: " << fWorldVolume->GetName() << G4endl;
141  // fGeometryCelli = new G4GeometryCellImportance;
142 }
143 
145 {
147  // fGeometryCelli = new G4GeometryCellImportance;
148 }
149 
150 
152 {
153  return *fWorldVolume;
154 }
155 
157 {
158  return fWorldVolume;
159 }
160 
161 
162 
165  const std::vector<G4double> &lowerWeights)
166 {
167  if (fGeneralUpperEnergyBounds.empty()) {
168  Error("AddLowerWeights() - No general upper energy limits set!");
169  }
170  if (IsKnown(gCell)) {
171  Error("AddLowerWeights() - Cell already in the store.");
172  }
173  if (lowerWeights.size() != fGeneralUpperEnergyBounds.size()) {
174  std::ostringstream err_mess;
175  err_mess << "AddLowerWeights() - Mismatch between "
176  << "number of lower weights (" << lowerWeights.size()
177  << ") and energy bounds (" << fGeneralUpperEnergyBounds.size()
178  << ")!";
179  Error(err_mess.str());
180  }
182  G4int i = 0;
183  for (std::set<G4double, std::less<G4double> >::iterator it =
184  fGeneralUpperEnergyBounds.begin();
185  it != fGeneralUpperEnergyBounds.end();
186  it++) {
187  map[*it] = lowerWeights[i];
188  i++;
189  }
190  fCellToUpEnBoundLoWePairsMap[gCell] = map;
191 }
192 
193 
196  const G4UpperEnergyToLowerWeightMap& enWeMap)
197 {
198  if (IsKnown(gCell)) {
199  Error("AddUpperEboundLowerWeightPairs() - Cell already in the store.");
200  }
201  if (IsKnown(gCell)) {
202  Error("AddUpperEboundLowerWeightPairs() - Cell already in the store.");
203  }
204  fCellToUpEnBoundLoWePairsMap[gCell] = enWeMap;
205 
206 }
207 
208 
211  std::less<G4double> > &enBounds)
212 {
213  if (!fGeneralUpperEnergyBounds.empty()) {
214  Error("SetGeneralUpperEnergyBounds() - Energy bounds already set.");
215  }
216  fGeneralUpperEnergyBounds = enBounds;
217 }
218 
219 
220 void G4WeightWindowStore::Error(const G4String &msg) const
221 {
222  G4Exception("G4WeightWindowStore::Error()",
223  "GeomBias0002", FatalException, msg);
224 }
225 
226 
227 // ***************************************************************************
228 // Returns the instance of the singleton.
229 // Creates it in case it's called for the first time.
230 // ***************************************************************************
231 //
233 {
234  if (!fInstance)
235  {
236  fInstance = new G4WeightWindowStore();
237  }
238  return fInstance;
239 }
240 
241 // ***************************************************************************
242 // Returns the instance of the singleton.
243 // Creates it in case it's called for the first time.
244 // ***************************************************************************
245 //
247 {
248  if (!fInstance)
249  {
250  G4cout << "G4IStore:: Creating new Parallel IStore " << ParallelWorldName << G4endl;
251  fInstance = new G4WeightWindowStore(ParallelWorldName);
252  }
253  return fInstance;
254 }
255 
G4bool IsAncestor(const G4VPhysicalVolume *p) const
void AddLowerWeights(const G4GeometryCell &gCell, const std::vector< G4double > &lowerWeights)
G4Navigator * GetNavigatorForTracking() const
virtual const G4VPhysicalVolume * GetParallelWorldVolumePointer() const
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
virtual G4bool IsKnown(const G4GeometryCell &gCell) const
const G4String & GetName() const
bool G4bool
Definition: G4Types.hh:79
void AddUpperEboundLowerWeightPairs(const G4GeometryCell &gCell, const G4UpperEnergyToLowerWeightMap &enWeMap)
void SetParallelWorldVolume(G4String paraName)
virtual const G4VPhysicalVolume & GetWorldVolume() const
static G4WeightWindowStore * GetInstance()
std::map< G4double, G4double, std::less< G4double > > G4UpperEnergyToLowerWeightMap
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4TransportationManager * GetTransportationManager()
const G4VPhysicalVolume & GetPhysicalVolume() const
G4VPhysicalVolume * GetParallelWorld(const G4String &worldName)
G4LogicalVolume * GetLogicalVolume() const
virtual G4double GetLowerWeight(const G4GeometryCell &gCell, G4double partEnergy) const
G4int first
void SetGeneralUpperEnergyBounds(const std::set< G4double, std::less< G4double > > &enBounds)
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
G4VPhysicalVolume * GetWorldVolume() const