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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 ]

Diff markup

Differences between /geometry/biasing/src/G4WeightWindowStore.cc (Version 11.3.0) and /geometry/biasing/src/G4WeightWindowStore.cc (Version 10.5.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4WeightWindowStore implementation          << 
 27 //                                                 26 //
 28 // Author: Michael Dressel (CERN), 2003        <<  27 //
 29 // Modified: Alex Howard (CERN), 2013 - Change << 
 30 // -------------------------------------------     28 // ----------------------------------------------------------------------
                                                   >>  29 // GEANT 4 class source file
                                                   >>  30 //
                                                   >>  31 // G4WeightWindowStore
                                                   >>  32 //
                                                   >>  33 // ----------------------------------------------------------------------
                                                   >>  34 
 31                                                    35 
 32 #include "G4WeightWindowStore.hh"                  36 #include "G4WeightWindowStore.hh"
 33 #include "G4VPhysicalVolume.hh"                    37 #include "G4VPhysicalVolume.hh"
 34 #include "G4LogicalVolume.hh"                      38 #include "G4LogicalVolume.hh"
 35 #include "G4GeometryCellStepStream.hh"             39 #include "G4GeometryCellStepStream.hh"
 36 #include "G4TransportationManager.hh"              40 #include "G4TransportationManager.hh"
 37                                                    41 
 38 // *******************************************     42 // ***************************************************************************
 39 // Static class variable: ptr to single instan     43 // Static class variable: ptr to single instance of class
 40 // *******************************************     44 // ***************************************************************************
 41 G4ThreadLocal G4WeightWindowStore* G4WeightWin <<  45 G4ThreadLocal G4WeightWindowStore* G4WeightWindowStore::fInstance = 0;
 42                                                    46 
 43 G4WeightWindowStore::                              47 G4WeightWindowStore::
 44 G4WeightWindowStore()                          <<  48 G4WeightWindowStore() :
 45  : fWorldVolume(G4TransportationManager::GetTr <<  49 fWorldVolume(G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume()),
 46                 ->GetNavigatorForTracking()->G <<  50   fGeneralUpperEnergyBounds(),
 47    fCurrentIterator(fCellToUpEnBoundLoWePairsM <<  51   fCellToUpEnBoundLoWePairsMap(),
 48 {                                              <<  52   fCurrentIterator(fCellToUpEnBoundLoWePairsMap.end())
 49 }                                              <<  53 {}
 50                                                    54 
 51 G4WeightWindowStore::                              55 G4WeightWindowStore::
 52 G4WeightWindowStore(const G4String& ParallelWo <<  56 G4WeightWindowStore(const G4String& ParallelWorldName) :
 53  : fWorldVolume(G4TransportationManager::GetTr <<  57 fWorldVolume(G4TransportationManager::GetTransportationManager()->GetParallelWorld(ParallelWorldName)),
 54                 ->GetParallelWorld(ParallelWor <<  58   fGeneralUpperEnergyBounds(),
 55    fCurrentIterator(fCellToUpEnBoundLoWePairsM <<  59   fCellToUpEnBoundLoWePairsMap(),
 56 {                                              <<  60   fCurrentIterator(fCellToUpEnBoundLoWePairsMap.end())
 57 }                                              <<  61 {}
 58                                                    62 
 59 G4WeightWindowStore::~G4WeightWindowStore() =  <<  63 G4WeightWindowStore::~G4WeightWindowStore()
                                                   >>  64 {}
 60                                                    65 
 61 G4double G4WeightWindowStore::                 <<  66 
 62 GetLowerWeight(const G4GeometryCell& gCell,    <<  67 G4double G4WeightWindowStore::GetLowerWeight(const G4GeometryCell &gCell, 
 63                      G4double partEnergy) cons <<  68                G4double partEnergy) const
 64 {                                                  69 {
 65   SetInternalIterator(gCell);                      70   SetInternalIterator(gCell);
 66   auto gCellIterator = fCurrentIterator;       <<  71   G4GeometryCellWeight::const_iterator gCellIterator = fCurrentIterator;
 67   if (gCellIterator == fCellToUpEnBoundLoWePai <<  72   if (gCellIterator ==  fCellToUpEnBoundLoWePairsMap.end()) {
 68   {                                            << 
 69     Error("GetLowerWitgh() - Cell does not exi     73     Error("GetLowerWitgh() - Cell does not exist!");
 70     return 0.;                                     74     return 0.;
 71   }                                                75   }
 72   G4UpperEnergyToLowerWeightMap upEnLoWeiPairs <<  76   G4UpperEnergyToLowerWeightMap upEnLoWeiPairs =
                                                   >>  77     fCurrentIterator->second;
 73   G4double lowerWeight = -1;                       78   G4double lowerWeight = -1;
 74   G4bool found = false;                            79   G4bool found = false;
 75   for (const auto & upEnLoWeiPair : upEnLoWeiP <<  80   for (G4UpperEnergyToLowerWeightMap::iterator it = 
 76   {                                            <<  81    upEnLoWeiPairs.begin(); it != upEnLoWeiPairs.end(); it++) {
 77     if (partEnergy < upEnLoWeiPair.first)      <<  82     if (partEnergy < it->first) {
 78     {                                          <<  83       lowerWeight = it->second;
 79       lowerWeight = upEnLoWeiPair.second;      << 
 80       found = true;                                84       found = true;
 81       break;                                       85       break;
 82     }                                              86     }
 83   }                                                87   }
 84   if (!found)                                  <<  88   if (!found) {
 85   {                                            << 
 86     std::ostringstream err_mess;                   89     std::ostringstream err_mess;
 87     err_mess << "GetLowerWitgh() - Couldn't fi     90     err_mess << "GetLowerWitgh() - Couldn't find lower weight bound." << G4endl
 88              << "Energy: " << partEnergy << ".     91              << "Energy: " << partEnergy << ".";
 89     Error(err_mess.str());                         92     Error(err_mess.str());
 90   }                                                93   }
 91   return lowerWeight;                              94   return lowerWeight;
                                                   >>  95 
                                                   >>  96 
 92 }                                                  97 }
 93                                                    98 
 94 void G4WeightWindowStore::                         99 void G4WeightWindowStore::
 95 SetInternalIterator(const G4GeometryCell& gCel << 100 SetInternalIterator(const G4GeometryCell &gCell) const
 96 {                                                 101 {
 97   fCurrentIterator = fCellToUpEnBoundLoWePairs    102   fCurrentIterator = fCellToUpEnBoundLoWePairsMap.find(gCell);
 98 }                                                 103 }
 99                                                   104 
100 G4bool G4WeightWindowStore::                      105 G4bool G4WeightWindowStore::
101 IsInWorld(const G4VPhysicalVolume& aVolume) co << 106 IsInWorld(const G4VPhysicalVolume &aVolume) const
102 {                                                 107 {
103   G4bool isIn(true);                              108   G4bool isIn(true);
104   if (!(aVolume == *fWorldVolume))             << 109   if (!(aVolume == *fWorldVolume)) {
105   {                                            << 
106     isIn = fWorldVolume->GetLogicalVolume()->I    110     isIn = fWorldVolume->GetLogicalVolume()->IsAncestor(&aVolume);
107   }                                               111   }
108   return isIn;                                    112   return isIn;
109 }                                                 113 }
110                                                   114 
111 G4bool G4WeightWindowStore::                   << 115 
112 IsKnown(const G4GeometryCell& gCell) const     << 116 G4bool G4WeightWindowStore::IsKnown(const G4GeometryCell &gCell) const
113 {                                                 117 {
114   G4bool inWorldKnown(IsInWorld(gCell.GetPhysi    118   G4bool inWorldKnown(IsInWorld(gCell.GetPhysicalVolume()));
115                                                << 119           
116   if ( inWorldKnown )                          << 120   if ( inWorldKnown ) {
117   {                                            << 
118     SetInternalIterator(gCell);                   121     SetInternalIterator(gCell);
119     inWorldKnown = (fCurrentIterator!=fCellToU << 122     inWorldKnown = (fCurrentIterator!=fCellToUpEnBoundLoWePairsMap.end());
120   }                                               123   }
121   return inWorldKnown;                            124   return inWorldKnown;
122 }                                                 125 }
123                                                   126 
124 void G4WeightWindowStore::Clear()                 127 void G4WeightWindowStore::Clear()
125 {                                                 128 {
126   fCellToUpEnBoundLoWePairsMap.clear();           129   fCellToUpEnBoundLoWePairsMap.clear();
127 }                                                 130 }
128                                                   131 
129 void G4WeightWindowStore::SetWorldVolume()        132 void G4WeightWindowStore::SetWorldVolume()
130 {                                                 133 {
131   G4cout << " G4IStore:: SetWorldVolume " << G    134   G4cout << " G4IStore:: SetWorldVolume " << G4endl;
132   fWorldVolume = G4TransportationManager::GetT << 135   fWorldVolume = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
133                  ->GetNavigatorForTracking()-> << 
134   G4cout << " World volume is: " << fWorldVolu    136   G4cout << " World volume is: " << fWorldVolume->GetName() << G4endl;
135   // fGeometryCelli = new G4GeometryCellImport << 137   //  fGeometryCelli = new G4GeometryCellImportance;
136 }                                                 138 }
137                                                   139 
138 void G4WeightWindowStore::SetParallelWorldVolu << 140 void G4WeightWindowStore::SetParallelWorldVolume(G4String paraName)
139 {                                                 141 {
140   fWorldVolume = G4TransportationManager::GetT << 142   fWorldVolume = G4TransportationManager::GetTransportationManager()->GetParallelWorld(paraName);
141                  ->GetParallelWorld(paraName); << 143     //  fGeometryCelli = new G4GeometryCellImportance;
142   // fGeometryCelli = new G4GeometryCellImport << 
143 }                                                 144 }
144                                                   145 
                                                   >> 146 
145 const G4VPhysicalVolume &G4WeightWindowStore::    147 const G4VPhysicalVolume &G4WeightWindowStore::GetWorldVolume() const
146 {                                                 148 {
147   return *fWorldVolume;                           149   return *fWorldVolume;
148 }                                                 150 }
149                                                   151 
150 const G4VPhysicalVolume* G4WeightWindowStore:: << 152 const G4VPhysicalVolume* G4WeightWindowStore::GetParallelWorldVolumePointer() const
151 GetParallelWorldVolumePointer() const          << 
152 {                                                 153 {
153   return fWorldVolume;                            154   return fWorldVolume;
154 }                                                 155 }
155                                                   156 
                                                   >> 157 
                                                   >> 158 
156 void G4WeightWindowStore::                        159 void G4WeightWindowStore::
157 AddLowerWeights(const G4GeometryCell& gCell,   << 160 AddLowerWeights(const G4GeometryCell & gCell,
158                 const std::vector<G4double>& l << 161                 const std::vector<G4double> &lowerWeights)
159 {                                                 162 {
160   if (fGeneralUpperEnergyBounds.empty())       << 163   if (fGeneralUpperEnergyBounds.empty()) {
161   {                                            << 
162     Error("AddLowerWeights() - No general uppe    164     Error("AddLowerWeights() - No general upper energy limits set!");
163   }                                               165   }
164   if (IsKnown(gCell))                          << 166   if (IsKnown(gCell)) {
165   {                                            << 
166     Error("AddLowerWeights() - Cell already in    167     Error("AddLowerWeights() - Cell already in the store.");
167   }                                               168   }
168   if (lowerWeights.size() != fGeneralUpperEner << 169   if (lowerWeights.size() != fGeneralUpperEnergyBounds.size()) {
169   {                                            << 
170     std::ostringstream err_mess;                  170     std::ostringstream err_mess;
171     err_mess << "AddLowerWeights() - Mismatch     171     err_mess << "AddLowerWeights() - Mismatch between "
172              << "number of lower weights (" <<    172              << "number of lower weights (" << lowerWeights.size()
173              << ") and energy bounds (" << fGe    173              << ") and energy bounds (" << fGeneralUpperEnergyBounds.size()
174              << ")!";                             174              << ")!";
175     Error(err_mess.str());                        175     Error(err_mess.str());
176   }                                               176   }
177   G4UpperEnergyToLowerWeightMap map;              177   G4UpperEnergyToLowerWeightMap map;
178   G4int i = 0;                                    178   G4int i = 0;
179   for (G4double fGeneralUpperEnergyBound : fGe << 179   for (std::set<G4double, std::less<G4double> >::iterator it = 
180   {                                            << 180    fGeneralUpperEnergyBounds.begin(); 
181     map[fGeneralUpperEnergyBound] = lowerWeigh << 181        it != fGeneralUpperEnergyBounds.end();
182     ++i;                                       << 182        it++) {
                                                   >> 183     map[*it] = lowerWeights[i];
                                                   >> 184     i++;
183   }                                               185   }
184   fCellToUpEnBoundLoWePairsMap[gCell] = std::m << 186   fCellToUpEnBoundLoWePairsMap[gCell] = map;
185 }                                                 187 }
186                                                   188 
                                                   >> 189  
187 void G4WeightWindowStore::                        190 void G4WeightWindowStore::
188 AddUpperEboundLowerWeightPairs(const G4Geometr << 191 AddUpperEboundLowerWeightPairs(const G4GeometryCell &gCell,
189                                const G4UpperEn    192                                const G4UpperEnergyToLowerWeightMap& enWeMap)
190 {                                                 193 {
191   if (IsKnown(gCell))                          << 194   if (IsKnown(gCell)) {
192   {                                            << 
193     Error("AddUpperEboundLowerWeightPairs() -     195     Error("AddUpperEboundLowerWeightPairs() - Cell already in the store.");
194   }                                               196   }
195   if (IsKnown(gCell))                          << 197   if (IsKnown(gCell)) {
196   {                                            << 
197     Error("AddUpperEboundLowerWeightPairs() -     198     Error("AddUpperEboundLowerWeightPairs() - Cell already in the store.");
198   }                                               199   }
199   fCellToUpEnBoundLoWePairsMap[gCell] = enWeMa    200   fCellToUpEnBoundLoWePairsMap[gCell] = enWeMap;
200                                                   201 
201 }                                                 202 }
202                                                   203 
                                                   >> 204 
203 void G4WeightWindowStore::                        205 void G4WeightWindowStore::
204 SetGeneralUpperEnergyBounds(const std::set<G4d    206 SetGeneralUpperEnergyBounds(const std::set<G4double,
205                             std::less<G4double << 207                             std::less<G4double> > &enBounds)
206 {                                                 208 {
207   if (!fGeneralUpperEnergyBounds.empty())      << 209   if (!fGeneralUpperEnergyBounds.empty()) {
208   {                                            << 
209     Error("SetGeneralUpperEnergyBounds() - Ene    210     Error("SetGeneralUpperEnergyBounds() - Energy bounds already set.");
210   }                                               211   }
211   fGeneralUpperEnergyBounds = enBounds;           212   fGeneralUpperEnergyBounds = enBounds;
212 }                                                 213 }
213                                                << 214 
214 void G4WeightWindowStore::Error(const G4String << 215   
                                                   >> 216 void G4WeightWindowStore::Error(const G4String &msg) const
215 {                                                 217 {
216   G4Exception("G4WeightWindowStore::Error()",     218   G4Exception("G4WeightWindowStore::Error()",
217               "GeomBias0002", FatalException,     219               "GeomBias0002", FatalException, msg);
218 }                                                 220 }
219                                                   221 
                                                   >> 222 
220 // *******************************************    223 // ***************************************************************************
221 // Returns the instance of the singleton.         224 // Returns the instance of the singleton.
222 // Creates it in case it's called for the firs    225 // Creates it in case it's called for the first time.
223 // *******************************************    226 // ***************************************************************************
224 //                                                227 //
225 G4WeightWindowStore* G4WeightWindowStore::GetI    228 G4WeightWindowStore* G4WeightWindowStore::GetInstance()
226 {                                                 229 {
227   if (fInstance == nullptr)                    << 230   if (!fInstance)
228   {                                               231   {
229     fInstance = new G4WeightWindowStore();        232     fInstance = new G4WeightWindowStore();
230   }                                               233   }
231   return fInstance;                               234   return fInstance;    
232 }                                                 235 }
233                                                   236 
234 // *******************************************    237 // ***************************************************************************
235 // Returns the instance of the singleton.         238 // Returns the instance of the singleton.
236 // Creates it in case it's called for the firs    239 // Creates it in case it's called for the first time.
237 // *******************************************    240 // ***************************************************************************
238 //                                                241 //
239 G4WeightWindowStore* G4WeightWindowStore::     << 242 G4WeightWindowStore* G4WeightWindowStore::GetInstance(const G4String& ParallelWorldName)
240 GetInstance(const G4String& ParallelWorldName) << 
241 {                                                 243 {
242   if (fInstance == nullptr)                    << 244   if (!fInstance)
243   {                                               245   {
244 #ifdef G4VERBOSE                               << 246     G4cout << "G4IStore:: Creating new Parallel IStore " << ParallelWorldName << G4endl;
245     G4cout << "G4IStore:: Creating new Paralle << 
246            << ParallelWorldName << G4endl;     << 
247 #endif                                         << 
248     fInstance = new G4WeightWindowStore(Parall    247     fInstance = new G4WeightWindowStore(ParallelWorldName);
249   }                                               248   }
250   return fInstance;                               249   return fInstance;    
251 }                                                 250 }
                                                   >> 251 
252                                                   252