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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.2)


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