Geant4 Cross Reference |
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 // G4GeometrySampler 27 // ---------------------------------------------------------------------- 28 29 #include "G4GeometrySampler.hh" 30 31 #include "G4VIStore.hh" 32 #include "G4WeightWindowStore.hh" 33 34 #include "G4VPhysicalVolume.hh" 35 #include "G4ImportanceConfigurator.hh" 36 #include "G4WeightWindowConfigurator.hh" 37 #include "G4WeightCutOffConfigurator.hh" 38 #include "G4TransportationManager.hh" 39 40 G4GeometrySampler:: 41 G4GeometrySampler(G4VPhysicalVolume *world, const G4String& particlename) 42 : fParticleName(particlename), 43 fWorld(world) 44 { 45 } 46 47 G4GeometrySampler:: 48 G4GeometrySampler(const G4String& worldName, const G4String &particlename) 49 : fParticleName(particlename), 50 fWorldName(worldName) 51 { 52 fWorld = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume(); 53 } 54 55 G4GeometrySampler::~G4GeometrySampler() 56 { 57 // ClearSampling(); 58 } 59 60 void G4GeometrySampler::ClearSampling() 61 { 62 delete fImportanceConfigurator; fImportanceConfigurator = nullptr; 63 delete fWeightWindowConfigurator; fWeightWindowConfigurator = nullptr; 64 delete fWeightCutOffConfigurator; fWeightCutOffConfigurator = nullptr; 65 fIStore = nullptr; 66 fConfigurators.clear(); 67 fIsConfigured = false; 68 } 69 70 G4bool G4GeometrySampler::IsConfigured() const 71 { 72 G4bool isconf = false; 73 if (fIsConfigured) 74 { 75 G4cout << "WARNING - G4GeometrySampler::IsConfigured()" 76 << " Some initialization exists, use ClearSampling()" 77 << " before a new initialization !" << G4endl; 78 isconf = true; 79 } 80 return isconf; 81 } 82 83 // void G4GeometrySampler::PrepareScoring(G4VScorer *scorer) 84 // { 85 // G4cout << " preparing scoring configurator " << G4endl; 86 // G4cout << G4endl; 87 // G4cout << G4endl; 88 // G4cout << G4endl; 89 // G4cout << " new fWorld Name: " << fWorld->GetName() << G4endl; 90 // G4cout << G4endl; 91 // G4cout << G4endl; 92 // G4cout << G4endl; 93 // fScoreConfigurator = new G4ScoreConfigurator(fWorld, fParticleName, *scorer, paraflag); 94 // G4cout << " configured scoring " << G4endl; 95 // if (!fScoreConfigurator) 96 // { 97 // G4Exception("G4GeometrySampler::PrepareScoring()", 98 // "FatalError", FatalException, 99 // "Failed allocation of G4ScoreConfigurator !"); 100 // } 101 // } 102 103 void 104 G4GeometrySampler::PrepareImportanceSampling(G4VIStore* istore, 105 const G4VImportanceAlgorithm *ialg) 106 { 107 G4cout << "G4GeometrySampler:: preparing importance sampling WorldName is " << fWorldName << G4endl; 108 fIStore = istore; 109 // G4cout << "G4GeometrySampler:: creating istore, worldVolume: " << fWorld->GetName() << G4endl; 110 111 fImportanceConfigurator = 112 new G4ImportanceConfigurator(&istore->GetWorldVolume(), fParticleName, *fIStore, ialg, paraflag); 113 // new G4ImportanceConfigurator(fWorld, fParticleName, *fIStore, ialg, paraflag); 114 fImportanceConfigurator->SetWorldName(fWorldName); 115 116 if (!fImportanceConfigurator) 117 { 118 G4Exception("G4GeometrySampler::PrepareImportanceSampling()", 119 "FatalError", FatalException, 120 "Failed allocation of G4ImportanceConfigurator !"); 121 } 122 } 123 124 void 125 G4GeometrySampler::PrepareWeightRoulett(G4double wsurvive, 126 G4double wlimit, 127 G4double isource) 128 { 129 // fGCellFinder = new G4GCellFinder(fWorld); 130 G4cout << "G4GeometrySampler:: preparing weight roulette" << G4endl; 131 // fGCellFinder = new G4GCellFinder(); 132 // if (!fGCellFinder) 133 // { 134 // G4Exception("G4GeometrySampler::PrepareWeightRoulett()", 135 // "FatalError", FatalException, 136 // "Failed allocation of G4GCellFinder !"); 137 // } 138 139 fWeightCutOffConfigurator = 140 new G4WeightCutOffConfigurator(fWorld, fParticleName, 141 wsurvive, 142 wlimit, 143 isource, 144 fIStore, 145 paraflag); 146 //*fGCellFinder, paraflag); 147 if (!fWeightCutOffConfigurator) 148 { 149 G4Exception("G4GeometrySampler::PrepareWeightRoulett()", 150 "FatalError", FatalException, 151 "Failed allocation of G4WeightCutOffConfigurator !"); 152 } 153 } 154 155 void 156 G4GeometrySampler::PrepareWeightWindow(G4VWeightWindowStore *wwstore, 157 G4VWeightWindowAlgorithm *wwAlg, 158 G4PlaceOfAction placeOfAction) 159 { 160 161 G4cout << "G4GeometrySampler:: preparing weight window" << G4endl; 162 163 fWWStore = wwstore; 164 165 fWeightWindowConfigurator = 166 new G4WeightWindowConfigurator(&wwstore->GetWorldVolume(), fParticleName, 167 *fWWStore, 168 wwAlg, 169 placeOfAction, paraflag); 170 } 171 172 void G4GeometrySampler::Configure() 173 { 174 if (!IsConfigured()) 175 { 176 fIsConfigured = true; 177 178 if (fImportanceConfigurator) 179 { 180 fConfigurators.push_back(fImportanceConfigurator); 181 } 182 if (fWeightWindowConfigurator) 183 { 184 fConfigurators.push_back(fWeightWindowConfigurator); 185 } 186 } 187 188 #ifdef G4MULTITHREADED 189 G4cout << " make sure AddProcess() is invoked for biasing!!! " << G4endl; 190 #else 191 AddProcess(); 192 #endif 193 194 return; 195 } 196 197 void G4GeometrySampler::AddProcess() 198 { 199 200 G4VSamplerConfigurator *preConf = nullptr; 201 for (auto it = fConfigurators.cbegin(); 202 it != fConfigurators.cend(); ++it) 203 { 204 G4VSamplerConfigurator *currConf =*it; 205 currConf->Configure(preConf); 206 preConf = *it; 207 } 208 if (fWeightCutOffConfigurator != nullptr) 209 { 210 fWeightCutOffConfigurator->Configure(nullptr); 211 } 212 213 return; 214 } 215 216 void G4GeometrySampler::SetParallel(G4bool para) 217 { 218 paraflag = para; 219 } 220 221 void G4GeometrySampler::SetWorld(const G4VPhysicalVolume* World) 222 { 223 fWorld = World; 224 } 225 226 void G4GeometrySampler::SetParticle(const G4String& particlename) 227 { 228 fParticleName = particlename; 229 } 230