Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 //
27 // $Id: G4WeightWindowStore.cc 88801 2015-03-10 14:38:27Z 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 G4WeightWindowStore* G4WeightWindowStore::fInstance = 0;
47 
50 fWorldVolume(G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume()),
51  fGeneralUpperEnergyBounds(),
52  fCellToUpEnBoundLoWePairsMap(),
53  fCurrentIterator(fCellToUpEnBoundLoWePairsMap.end())
54 {}
55 
57 G4WeightWindowStore(const G4String& ParallelWorldName) :
58 fWorldVolume(G4TransportationManager::GetTransportationManager()->GetParallelWorld(ParallelWorldName)),
59  fGeneralUpperEnergyBounds(),
60  fCellToUpEnBoundLoWePairsMap(),
61  fCurrentIterator(fCellToUpEnBoundLoWePairsMap.end())
62 {}
63 
65 {}
66 
67 
69  G4double partEnergy) const
70 {
71  SetInternalIterator(gCell);
72  G4GeometryCellWeight::const_iterator gCellIterator = fCurrentIterator;
73  if (gCellIterator == fCellToUpEnBoundLoWePairsMap.end()) {
74  Error("GetLowerWitgh() - Cell does not exist!");
75  return 0.;
76  }
77  G4UpperEnergyToLowerWeightMap upEnLoWeiPairs =
78  fCurrentIterator->second;
79  G4double lowerWeight = -1;
80  G4bool found = false;
81  for (G4UpperEnergyToLowerWeightMap::iterator it =
82  upEnLoWeiPairs.begin(); it != upEnLoWeiPairs.end(); it++) {
83  if (partEnergy < it->first) {
84  lowerWeight = it->second;
85  found = true;
86  break;
87  }
88  }
89  if (!found) {
90  std::ostringstream err_mess;
91  err_mess << "GetLowerWitgh() - Couldn't find lower weight bound." << G4endl
92  << "Energy: " << partEnergy << ".";
93  Error(err_mess.str());
94  }
95  return lowerWeight;
96 
97 
98 }
99 
100 void G4WeightWindowStore::
101 SetInternalIterator(const G4GeometryCell &gCell) const
102 {
103  fCurrentIterator = fCellToUpEnBoundLoWePairsMap.find(gCell);
104 }
105 
106 G4bool G4WeightWindowStore::
107 IsInWorld(const G4VPhysicalVolume &aVolume) const
108 {
109  G4bool isIn(true);
110  if (!(aVolume == *fWorldVolume)) {
111  isIn = fWorldVolume->GetLogicalVolume()->IsAncestor(&aVolume);
112  }
113  return isIn;
114 }
115 
116 
118 {
119  G4bool inWorldKnown(IsInWorld(gCell.GetPhysicalVolume()));
120 
121  if ( inWorldKnown ) {
122  SetInternalIterator(gCell);
123  inWorldKnown = (fCurrentIterator!=fCellToUpEnBoundLoWePairsMap.end());
124  }
125  return inWorldKnown;
126 }
127 
129 {
130  fCellToUpEnBoundLoWePairsMap.clear();
131 }
132 
134 {
135  G4cout << " G4IStore:: SetWorldVolume " << G4endl;
137  G4cout << " World volume is: " << fWorldVolume->GetName() << G4endl;
138  // fGeometryCelli = new G4GeometryCellImportance;
139 }
140 
142 {
144  // fGeometryCelli = new G4GeometryCellImportance;
145 }
146 
147 
149 {
150  return *fWorldVolume;
151 }
152 
154 {
155  return fWorldVolume;
156 }
157 
158 
159 
162  const std::vector<G4double> &lowerWeights)
163 {
164  if (fGeneralUpperEnergyBounds.empty()) {
165  Error("AddLowerWeights() - No general upper energy limits set!");
166  }
167  if (IsKnown(gCell)) {
168  Error("AddLowerWeights() - Cell already in the store.");
169  }
170  if (lowerWeights.size() != fGeneralUpperEnergyBounds.size()) {
171  std::ostringstream err_mess;
172  err_mess << "AddLowerWeights() - Mismatch between "
173  << "number of lower weights (" << lowerWeights.size()
174  << ") and energy bounds (" << fGeneralUpperEnergyBounds.size()
175  << ")!";
176  Error(err_mess.str());
177  }
179  G4int i = 0;
180  for (std::set<G4double, std::less<G4double> >::iterator it =
181  fGeneralUpperEnergyBounds.begin();
182  it != fGeneralUpperEnergyBounds.end();
183  it++) {
184  map[*it] = lowerWeights[i];
185  i++;
186  }
187  fCellToUpEnBoundLoWePairsMap[gCell] = map;
188 }
189 
190 
193  const G4UpperEnergyToLowerWeightMap& enWeMap)
194 {
195  if (IsKnown(gCell)) {
196  Error("AddUpperEboundLowerWeightPairs() - Cell already in the store.");
197  }
198  if (IsKnown(gCell)) {
199  Error("AddUpperEboundLowerWeightPairs() - Cell already in the store.");
200  }
201  fCellToUpEnBoundLoWePairsMap[gCell] = enWeMap;
202 
203 }
204 
205 
208  std::less<G4double> > &enBounds)
209 {
210  if (!fGeneralUpperEnergyBounds.empty()) {
211  Error("SetGeneralUpperEnergyBounds() - Energy bounds already set.");
212  }
213  fGeneralUpperEnergyBounds = enBounds;
214 }
215 
216 
217 void G4WeightWindowStore::Error(const G4String &msg) const
218 {
219  G4Exception("G4WeightWindowStore::Error()",
220  "GeomBias0002", FatalException, msg);
221 }
222 
223 
224 // ***************************************************************************
225 // Returns the instance of the singleton.
226 // Creates it in case it's called for the first time.
227 // ***************************************************************************
228 //
230 {
231  if (!fInstance)
232  {
233  fInstance = new G4WeightWindowStore();
234  }
235  return fInstance;
236 }
237 
238 // ***************************************************************************
239 // Returns the instance of the singleton.
240 // Creates it in case it's called for the first time.
241 // ***************************************************************************
242 //
244 {
245  if (!fInstance)
246  {
247  G4cout << "G4IStore:: Creating new Parallel IStore " << ParallelWorldName << G4endl;
248  fInstance = new G4WeightWindowStore(ParallelWorldName);
249  }
250  return fInstance;
251 }
252 
G4bool IsAncestor(const G4VPhysicalVolume *p) const
void AddLowerWeights(const G4GeometryCell &gCell, const std::vector< G4double > &lowerWeights)
G4Navigator * GetNavigatorForTracking() const
virtual const G4VPhysicalVolume * GetParallelWorldVolumePointer() const
#define G4ThreadLocal
Definition: tls.hh:89
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
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