Geant4 Cross Reference |
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 // G4GeometrySampler << 26 // >> 27 // $Id: G4GeometrySampler.cc 78011 2013-12-02 11:32:48Z gcosmo $ >> 28 // >> 29 // ---------------------------------------------------------------------- >> 30 // GEANT 4 class source file >> 31 // >> 32 // G4GeometrySampler.cc >> 33 // 27 // ------------------------------------------- 34 // ---------------------------------------------------------------------- 28 35 29 #include "G4GeometrySampler.hh" 36 #include "G4GeometrySampler.hh" 30 37 31 #include "G4VIStore.hh" 38 #include "G4VIStore.hh" 32 #include "G4WeightWindowStore.hh" 39 #include "G4WeightWindowStore.hh" >> 40 //#include "G4VScorer.hh" 33 41 34 #include "G4VPhysicalVolume.hh" 42 #include "G4VPhysicalVolume.hh" >> 43 //#include "G4ScoreConfigurator.hh" 35 #include "G4ImportanceConfigurator.hh" 44 #include "G4ImportanceConfigurator.hh" 36 #include "G4WeightWindowConfigurator.hh" 45 #include "G4WeightWindowConfigurator.hh" 37 #include "G4WeightCutOffConfigurator.hh" 46 #include "G4WeightCutOffConfigurator.hh" >> 47 //#include "G4GCellFinder.hh" 38 #include "G4TransportationManager.hh" 48 #include "G4TransportationManager.hh" 39 49 40 G4GeometrySampler:: 50 G4GeometrySampler:: 41 G4GeometrySampler(G4VPhysicalVolume *world, c << 51 G4GeometrySampler(G4VPhysicalVolume *world, const G4String &particlename) 42 : fParticleName(particlename), 52 : fParticleName(particlename), 43 fWorld(world) << 53 fWorld(world), 44 { << 54 fImportanceConfigurator(0), >> 55 // fScoreConfigurator(0), >> 56 // fGCellFinder(0), >> 57 fWeightCutOffConfigurator(0), >> 58 fIStore(0), >> 59 fWeightWindowConfigurator(0), >> 60 fWWStore(0), >> 61 fIsConfigured(false) >> 62 { >> 63 paraflag = false; >> 64 // fWorldName = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume()->GetName(); >> 65 // if(fWorld == G4TransportationManager::GetTransportationManager()->GetParallelWorld(fWorld->GetName())) paraflag = true; >> 66 // G4cout << "G4GeometrySampler:: Making geometry sampler with world: " << fWorld->GetName() << G4endl; 45 } 67 } 46 68 47 G4GeometrySampler:: 69 G4GeometrySampler:: 48 G4GeometrySampler(const G4String& worldName, << 70 G4GeometrySampler(G4String worldName, const G4String &particlename) 49 : fParticleName(particlename), 71 : fParticleName(particlename), 50 fWorldName(worldName) << 72 fWorldName(worldName), >> 73 fImportanceConfigurator(0), >> 74 // fScoreConfigurator(0), >> 75 // fGCellFinder(0), >> 76 fWeightCutOffConfigurator(0), >> 77 fIStore(0), >> 78 fWeightWindowConfigurator(0), >> 79 fWWStore(0), >> 80 fIsConfigured(false) 51 { 81 { >> 82 paraflag = false; 52 fWorld = G4TransportationManager::GetTranspo 83 fWorld = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume(); >> 84 // fWorld = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume(); >> 85 // G4cout << "G4GeometrySampler:: Making geometry sampler with world: " << fWorld->GetName() << G4endl; >> 86 //G4TransportationManager::GetTransportationManager()->GetParallelWorld(parallelworldName) 53 } 87 } 54 88 55 G4GeometrySampler::~G4GeometrySampler() 89 G4GeometrySampler::~G4GeometrySampler() 56 { 90 { 57 // ClearSampling(); << 91 ClearSampling(); 58 } 92 } 59 93 60 void G4GeometrySampler::ClearSampling() 94 void G4GeometrySampler::ClearSampling() 61 { 95 { 62 delete fImportanceConfigurator; fImportanceC << 96 if (fImportanceConfigurator) 63 delete fWeightWindowConfigurator; fWeightWin << 97 { 64 delete fWeightCutOffConfigurator; fWeightCut << 98 delete fImportanceConfigurator; 65 fIStore = nullptr; << 99 fImportanceConfigurator = 0; >> 100 } >> 101 if (fWeightWindowConfigurator) >> 102 { >> 103 delete fWeightWindowConfigurator; >> 104 fWeightWindowConfigurator = 0; >> 105 } >> 106 // if (fScoreConfigurator) >> 107 // { >> 108 // delete fScoreConfigurator; >> 109 // fScoreConfigurator = 0; >> 110 // } >> 111 if (fWeightCutOffConfigurator) >> 112 { >> 113 delete fWeightCutOffConfigurator; >> 114 fWeightCutOffConfigurator = 0; >> 115 } >> 116 // if (fGCellFinder) >> 117 // { >> 118 // delete fGCellFinder; >> 119 // fGCellFinder = 0; >> 120 // } >> 121 fIStore = 0; 66 fConfigurators.clear(); 122 fConfigurators.clear(); 67 fIsConfigured = false; 123 fIsConfigured = false; 68 } 124 } 69 125 70 G4bool G4GeometrySampler::IsConfigured() const 126 G4bool G4GeometrySampler::IsConfigured() const 71 { 127 { 72 G4bool isconf = false; 128 G4bool isconf = false; 73 if (fIsConfigured) 129 if (fIsConfigured) 74 { 130 { 75 G4cout << "WARNING - G4GeometrySampler::IsC 131 G4cout << "WARNING - G4GeometrySampler::IsConfigured()" 76 << " Some initialization ex << 132 << " Some initalization exists, use ClearSampling()" 77 << " before a new initializ 133 << " before a new initialization !" << G4endl; 78 isconf = true; 134 isconf = true; 79 } 135 } 80 return isconf; 136 return isconf; 81 } 137 } 82 138 83 // void G4GeometrySampler::PrepareScoring(G4VS 139 // void G4GeometrySampler::PrepareScoring(G4VScorer *scorer) 84 // { 140 // { 85 // G4cout << " preparing scoring configurato 141 // G4cout << " preparing scoring configurator " << G4endl; 86 // G4cout << G4endl; 142 // G4cout << G4endl; 87 // G4cout << G4endl; 143 // G4cout << G4endl; 88 // G4cout << G4endl; 144 // G4cout << G4endl; 89 // G4cout << " new fWorld Name: " << fWorld- 145 // G4cout << " new fWorld Name: " << fWorld->GetName() << G4endl; 90 // G4cout << G4endl; 146 // G4cout << G4endl; 91 // G4cout << G4endl; 147 // G4cout << G4endl; 92 // G4cout << G4endl; 148 // G4cout << G4endl; 93 // fScoreConfigurator = new G4ScoreConfigura 149 // fScoreConfigurator = new G4ScoreConfigurator(fWorld, fParticleName, *scorer, paraflag); 94 // G4cout << " configured scoring " << G4end 150 // G4cout << " configured scoring " << G4endl; 95 // if (!fScoreConfigurator) 151 // if (!fScoreConfigurator) 96 // { 152 // { 97 // G4Exception("G4GeometrySampler::Prepare 153 // G4Exception("G4GeometrySampler::PrepareScoring()", 98 // "FatalError", FatalExceptio 154 // "FatalError", FatalException, 99 // "Failed allocation of G4Sco 155 // "Failed allocation of G4ScoreConfigurator !"); 100 // } 156 // } 101 // } 157 // } 102 158 103 void 159 void 104 G4GeometrySampler::PrepareImportanceSampling(G 160 G4GeometrySampler::PrepareImportanceSampling(G4VIStore* istore, 105 con 161 const G4VImportanceAlgorithm *ialg) 106 { 162 { 107 G4cout << "G4GeometrySampler:: preparing imp 163 G4cout << "G4GeometrySampler:: preparing importance sampling WorldName is " << fWorldName << G4endl; 108 fIStore = istore; 164 fIStore = istore; 109 // G4cout << "G4GeometrySampler:: creating 165 // G4cout << "G4GeometrySampler:: creating istore, worldVolume: " << fWorld->GetName() << G4endl; 110 166 111 fImportanceConfigurator = 167 fImportanceConfigurator = 112 new G4ImportanceConfigurator(&istore->GetW 168 new G4ImportanceConfigurator(&istore->GetWorldVolume(), fParticleName, *fIStore, ialg, paraflag); 113 // new G4ImportanceConfigurator(fWorld, f 169 // new G4ImportanceConfigurator(fWorld, fParticleName, *fIStore, ialg, paraflag); 114 fImportanceConfigurator->SetWorldName(fWorld 170 fImportanceConfigurator->SetWorldName(fWorldName); 115 171 116 if (!fImportanceConfigurator) 172 if (!fImportanceConfigurator) 117 { 173 { 118 G4Exception("G4GeometrySampler::PrepareImp 174 G4Exception("G4GeometrySampler::PrepareImportanceSampling()", 119 "FatalError", FatalException, 175 "FatalError", FatalException, 120 "Failed allocation of G4Import 176 "Failed allocation of G4ImportanceConfigurator !"); 121 } 177 } 122 } 178 } 123 179 124 void 180 void 125 G4GeometrySampler::PrepareWeightRoulett(G4doub 181 G4GeometrySampler::PrepareWeightRoulett(G4double wsurvive, 126 G4doub << 182 G4double wlimit, 127 G4doub << 183 G4double isource) 128 { 184 { 129 // fGCellFinder = new G4GCellFinder(fWorld) 185 // fGCellFinder = new G4GCellFinder(fWorld); 130 G4cout << "G4GeometrySampler:: preparing wei 186 G4cout << "G4GeometrySampler:: preparing weight roulette" << G4endl; 131 // fGCellFinder = new G4GCellFinder(); 187 // fGCellFinder = new G4GCellFinder(); 132 // if (!fGCellFinder) 188 // if (!fGCellFinder) 133 // { 189 // { 134 // G4Exception("G4GeometrySampler::Prepare 190 // G4Exception("G4GeometrySampler::PrepareWeightRoulett()", 135 // "FatalError", FatalExceptio 191 // "FatalError", FatalException, 136 // "Failed allocation of G4GCe 192 // "Failed allocation of G4GCellFinder !"); 137 // } 193 // } 138 194 139 fWeightCutOffConfigurator = 195 fWeightCutOffConfigurator = 140 new G4WeightCutOffConfigurator(fWorld, fPa 196 new G4WeightCutOffConfigurator(fWorld, fParticleName, 141 wsurvive, 197 wsurvive, 142 wlimit, 198 wlimit, 143 isource, 199 isource, 144 fIStore, 200 fIStore, 145 paraflag); 201 paraflag); 146 //*fGCellFinder, paraflag); 202 //*fGCellFinder, paraflag); 147 if (!fWeightCutOffConfigurator) 203 if (!fWeightCutOffConfigurator) 148 { 204 { 149 G4Exception("G4GeometrySampler::PrepareWei 205 G4Exception("G4GeometrySampler::PrepareWeightRoulett()", 150 "FatalError", FatalException, 206 "FatalError", FatalException, 151 "Failed allocation of G4Weight 207 "Failed allocation of G4WeightCutOffConfigurator !"); 152 } 208 } 153 } 209 } 154 210 155 void 211 void 156 G4GeometrySampler::PrepareWeightWindow(G4VWeig 212 G4GeometrySampler::PrepareWeightWindow(G4VWeightWindowStore *wwstore, 157 G4VWeig << 213 G4VWeightWindowAlgorithm *wwAlg, 158 G4Place << 214 G4PlaceOfAction placeOfAction) 159 { 215 { 160 216 161 G4cout << "G4GeometrySampler:: preparing wei 217 G4cout << "G4GeometrySampler:: preparing weight window" << G4endl; 162 218 163 fWWStore = wwstore; 219 fWWStore = wwstore; 164 220 165 fWeightWindowConfigurator = 221 fWeightWindowConfigurator = 166 new G4WeightWindowConfigurator(&wwstore->G 222 new G4WeightWindowConfigurator(&wwstore->GetWorldVolume(), fParticleName, 167 *fWWStore, 223 *fWWStore, 168 wwAlg, 224 wwAlg, 169 placeOfAct 225 placeOfAction, paraflag); >> 226 >> 227 // fWeightWindowConfigurator = >> 228 // new G4WeightWindowConfigurator(fWorld, fParticleName, >> 229 // *fWWStore, >> 230 // wwAlg, >> 231 // placeOfAction, paraflag); >> 232 170 } 233 } 171 234 172 void G4GeometrySampler::Configure() 235 void G4GeometrySampler::Configure() 173 { 236 { 174 if (!IsConfigured()) 237 if (!IsConfigured()) 175 { 238 { 176 fIsConfigured = true; 239 fIsConfigured = true; 177 240 >> 241 // if (fScoreConfigurator) >> 242 // { >> 243 // G4cout << " score configurator push_back " << G4endl; >> 244 // fConfigurators.push_back(fScoreConfigurator); >> 245 // G4cout << " pushed " << G4endl; >> 246 // } 178 if (fImportanceConfigurator) 247 if (fImportanceConfigurator) 179 { 248 { 180 fConfigurators.push_back(fImportanceConf 249 fConfigurators.push_back(fImportanceConfigurator); 181 } 250 } 182 if (fWeightWindowConfigurator) 251 if (fWeightWindowConfigurator) 183 { 252 { 184 fConfigurators.push_back(fWeightWindowCo 253 fConfigurators.push_back(fWeightWindowConfigurator); 185 } 254 } >> 255 >> 256 // G4cout << " vsampler configurator loop " << G4endl; >> 257 // G4VSamplerConfigurator *preConf = 0; >> 258 // G4int i = 0; >> 259 // for (G4Configurators::iterator it = fConfigurators.begin(); >> 260 // it != fConfigurators.end(); it++) >> 261 // { >> 262 // i++; >> 263 // G4cout << " looping " << i << G4endl; >> 264 // G4VSamplerConfigurator *currConf =*it; >> 265 // G4cout << " sampler configurator " << G4endl; >> 266 // currConf->Configure(preConf); >> 267 // G4cout << " configure preconf " << G4endl; >> 268 // preConf = *it; >> 269 // } >> 270 // if (fWeightCutOffConfigurator) >> 271 // { >> 272 // G4cout << " NEW weight window configure " << G4endl; >> 273 // fWeightCutOffConfigurator->Configure(0); >> 274 // G4cout << " configured " << G4endl; >> 275 // } 186 } 276 } 187 277 188 #ifdef G4MULTITHREADED 278 #ifdef G4MULTITHREADED 189 G4cout << " make sure AddProcess() is invoke 279 G4cout << " make sure AddProcess() is invoked for biasing!!! " << G4endl; 190 #else 280 #else 191 AddProcess(); 281 AddProcess(); 192 #endif 282 #endif 193 283 194 return; 284 return; 195 } 285 } 196 286 197 void G4GeometrySampler::AddProcess() 287 void G4GeometrySampler::AddProcess() 198 { 288 { 199 289 200 G4VSamplerConfigurator *preConf = nullptr; << 290 G4VSamplerConfigurator *preConf = 0; 201 for (auto it = fConfigurators.cbegin(); << 291 G4int i = 0; 202 it != fConfigurators.cend(); ++it) << 292 for (G4Configurators::iterator it = fConfigurators.begin(); >> 293 it != fConfigurators.end(); it++) 203 { 294 { >> 295 i++; 204 G4VSamplerConfigurator *currConf =*it; 296 G4VSamplerConfigurator *currConf =*it; 205 currConf->Configure(preConf); 297 currConf->Configure(preConf); 206 preConf = *it; 298 preConf = *it; 207 } 299 } 208 if (fWeightCutOffConfigurator != nullptr) << 300 if (fWeightCutOffConfigurator) 209 { 301 { 210 fWeightCutOffConfigurator->Configure(nul << 302 fWeightCutOffConfigurator->Configure(0); 211 } 303 } 212 304 213 return; 305 return; 214 } 306 } 215 307 216 void G4GeometrySampler::SetParallel(G4bool par 308 void G4GeometrySampler::SetParallel(G4bool para) 217 { 309 { 218 paraflag = para; 310 paraflag = para; 219 } 311 } 220 312 221 void G4GeometrySampler::SetWorld(const G4VPhys 313 void G4GeometrySampler::SetWorld(const G4VPhysicalVolume* World) 222 { 314 { 223 fWorld = World; 315 fWorld = World; 224 } 316 } 225 317 226 void G4GeometrySampler::SetParticle(const G4St << 318 void G4GeometrySampler::SetParticle(const G4String &particlename) 227 { 319 { 228 fParticleName = particlename; 320 fParticleName = particlename; 229 } 321 } >> 322 230 323