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