Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4GeometrySampler.cc
Go to the documentation of this file.
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 //
27 // $Id: G4GeometrySampler.cc 105155 2017-07-14 09:08:41Z gcosmo $
28 //
29 // ----------------------------------------------------------------------
30 // GEANT 4 class source file
31 //
32 // G4GeometrySampler.cc
33 //
34 // ----------------------------------------------------------------------
35 
36 #include "G4GeometrySampler.hh"
37 
38 #include "G4VIStore.hh"
39 #include "G4WeightWindowStore.hh"
40 //#include "G4VScorer.hh"
41 
42 #include "G4VPhysicalVolume.hh"
43 //#include "G4ScoreConfigurator.hh"
47 //#include "G4GCellFinder.hh"
49 
51  G4GeometrySampler(G4VPhysicalVolume *world, const G4String &particlename)
52  : fParticleName(particlename),
53  fWorld(world),
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;
67 }
68 
70  G4GeometrySampler(G4String worldName, const G4String &particlename)
71  : fParticleName(particlename),
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)
81 {
82  paraflag = false;
84  // fWorld = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();
85  // G4cout << "G4GeometrySampler:: Making geometry sampler with world: " << fWorld->GetName() << G4endl;
86  //G4TransportationManager::GetTransportationManager()->GetParallelWorld(parallelworldName)
87 }
88 
90 {
91  // ClearSampling();
92 }
93 
95 {
96  if (fImportanceConfigurator)
97  {
98  delete fImportanceConfigurator;
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;
122  fConfigurators.clear();
123  fIsConfigured = false;
124 }
125 
127 {
128  G4bool isconf = false;
129  if (fIsConfigured)
130  {
131  G4cout << "WARNING - G4GeometrySampler::IsConfigured()"
132  << " Some initalization exists, use ClearSampling()"
133  << " before a new initialization !" << G4endl;
134  isconf = true;
135  }
136  return isconf;
137 }
138 
139 // void G4GeometrySampler::PrepareScoring(G4VScorer *scorer)
140 // {
141 // G4cout << " preparing scoring configurator " << G4endl;
142 // G4cout << G4endl;
143 // G4cout << G4endl;
144 // G4cout << G4endl;
145 // G4cout << " new fWorld Name: " << fWorld->GetName() << G4endl;
146 // G4cout << G4endl;
147 // G4cout << G4endl;
148 // G4cout << G4endl;
149 // fScoreConfigurator = new G4ScoreConfigurator(fWorld, fParticleName, *scorer, paraflag);
150 // G4cout << " configured scoring " << G4endl;
151 // if (!fScoreConfigurator)
152 // {
153 // G4Exception("G4GeometrySampler::PrepareScoring()",
154 // "FatalError", FatalException,
155 // "Failed allocation of G4ScoreConfigurator !");
156 // }
157 // }
158 
159 void
161  const G4VImportanceAlgorithm *ialg)
162 {
163  G4cout << "G4GeometrySampler:: preparing importance sampling WorldName is " << fWorldName << G4endl;
164  fIStore = istore;
165  // G4cout << "G4GeometrySampler:: creating istore, worldVolume: " << fWorld->GetName() << G4endl;
166 
167  fImportanceConfigurator =
168  new G4ImportanceConfigurator(&istore->GetWorldVolume(), fParticleName, *fIStore, ialg, paraflag);
169  // new G4ImportanceConfigurator(fWorld, fParticleName, *fIStore, ialg, paraflag);
170  fImportanceConfigurator->SetWorldName(fWorldName);
171 
172  if (!fImportanceConfigurator)
173  {
174  G4Exception("G4GeometrySampler::PrepareImportanceSampling()",
175  "FatalError", FatalException,
176  "Failed allocation of G4ImportanceConfigurator !");
177  }
178 }
179 
180 void
182  G4double wlimit,
183  G4double isource)
184 {
185  // fGCellFinder = new G4GCellFinder(fWorld);
186  G4cout << "G4GeometrySampler:: preparing weight roulette" << G4endl;
187  // fGCellFinder = new G4GCellFinder();
188 // if (!fGCellFinder)
189 // {
190 // G4Exception("G4GeometrySampler::PrepareWeightRoulett()",
191 // "FatalError", FatalException,
192 // "Failed allocation of G4GCellFinder !");
193 // }
194 
195  fWeightCutOffConfigurator =
196  new G4WeightCutOffConfigurator(fWorld, fParticleName,
197  wsurvive,
198  wlimit,
199  isource,
200  fIStore,
201  paraflag);
202  //*fGCellFinder, paraflag);
203  if (!fWeightCutOffConfigurator)
204  {
205  G4Exception("G4GeometrySampler::PrepareWeightRoulett()",
206  "FatalError", FatalException,
207  "Failed allocation of G4WeightCutOffConfigurator !");
208  }
209 }
210 
211 void
214  G4PlaceOfAction placeOfAction)
215 {
216 
217  G4cout << "G4GeometrySampler:: preparing weight window" << G4endl;
218 
219  fWWStore = wwstore;
220 
221  fWeightWindowConfigurator =
222  new G4WeightWindowConfigurator(&wwstore->GetWorldVolume(), fParticleName,
223  *fWWStore,
224  wwAlg,
225  placeOfAction, paraflag);
226 
227  // fWeightWindowConfigurator =
228  // new G4WeightWindowConfigurator(fWorld, fParticleName,
229  // *fWWStore,
230  // wwAlg,
231  // placeOfAction, paraflag);
232 
233 }
234 
236 {
237  if (!IsConfigured())
238  {
239  fIsConfigured = true;
240 
241 // if (fScoreConfigurator)
242 // {
243 // G4cout << " score configurator push_back " << G4endl;
244 // fConfigurators.push_back(fScoreConfigurator);
245 // G4cout << " pushed " << G4endl;
246 // }
247  if (fImportanceConfigurator)
248  {
249  fConfigurators.push_back(fImportanceConfigurator);
250  }
251  if (fWeightWindowConfigurator)
252  {
253  fConfigurators.push_back(fWeightWindowConfigurator);
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  // }
276  }
277 
278 #ifdef G4MULTITHREADED
279  G4cout << " make sure AddProcess() is invoked for biasing!!! " << G4endl;
280 #else
281  AddProcess();
282 #endif
283 
284  return;
285 }
286 
288 {
289 
290  G4VSamplerConfigurator *preConf = 0;
291  G4int i = 0;
292  for (G4Configurators::iterator it = fConfigurators.begin();
293  it != fConfigurators.end(); it++)
294  {
295  i++;
296  G4VSamplerConfigurator *currConf =*it;
297  currConf->Configure(preConf);
298  preConf = *it;
299  }
300  if (fWeightCutOffConfigurator)
301  {
302  fWeightCutOffConfigurator->Configure(0);
303  }
304 
305  return;
306 }
307 
309 {
310  paraflag = para;
311 }
312 
314 {
315  fWorld = World;
316 }
317 
318 void G4GeometrySampler::SetParticle(const G4String &particlename)
319 {
320  fParticleName = particlename;
321 }
322 
virtual G4bool IsConfigured() const
void SetWorld(const G4VPhysicalVolume *world)
virtual void Configure(G4VSamplerConfigurator *preConf)=0
virtual void PrepareWeightWindow(G4VWeightWindowStore *wwstore, G4VWeightWindowAlgorithm *wwAlg, G4PlaceOfAction placeOfAction)
G4Navigator * GetNavigatorForTracking() const
G4GeometrySampler(G4VPhysicalVolume *worldvolume, const G4String &particlename)
void SetParallel(G4bool paraflag)
virtual const G4VPhysicalVolume & GetWorldVolume() const =0
int G4int
Definition: G4Types.hh:78
virtual void ClearSampling()
G4GLOB_DLL std::ostream G4cout
G4PlaceOfAction
bool G4bool
Definition: G4Types.hh:79
virtual void AddProcess()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4TransportationManager * GetTransportationManager()
virtual void Configure(G4VSamplerConfigurator *preConf)
virtual void PrepareWeightRoulett(G4double wsurvive, G4double wlimit, G4double isource)
void SetParticle(const G4String &particlename)
#define G4endl
Definition: G4ios.hh:61
virtual const G4VPhysicalVolume & GetWorldVolume() const =0
double G4double
Definition: G4Types.hh:76
virtual void Configure()
G4VPhysicalVolume * GetWorldVolume() const
virtual void PrepareImportanceSampling(G4VIStore *istore, const G4VImportanceAlgorithm *ialg)
virtual ~G4GeometrySampler()