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

  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