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 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

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