source: trunk/source/processes/biasing/src/G4GeometrySampler.cc @ 846

Last change on this file since 846 was 819, checked in by garnier, 16 years ago

import all except CVS

File size: 8.2 KB
Line 
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,v 1.8 2007/06/01 09:52:23 ahoward Exp $
28// GEANT4 tag $Name: geant4-09-01-patch-02 $
29//
30// ----------------------------------------------------------------------
31// GEANT 4 class source file
32//
33// G4GeometrySampler.cc
34//
35// ----------------------------------------------------------------------
36
37#include "G4GeometrySampler.hh"
38
39#include "G4VIStore.hh"
40#include "G4WeightWindowStore.hh"
41//#include "G4VScorer.hh"
42
43#include "G4VPhysicalVolume.hh"
44//#include "G4ScoreConfigurator.hh"
45#include "G4ImportanceConfigurator.hh"
46#include "G4WeightWindowConfigurator.hh"
47#include "G4WeightCutOffConfigurator.hh"
48#include "G4GCellFinder.hh"
49
50 G4GeometrySampler::
51 G4GeometrySampler(G4VPhysicalVolume *parallelworld, const G4String &particlename)
52  : fParticleName(particlename),
53    fWorld(parallelworld),
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}
65
66G4GeometrySampler::~G4GeometrySampler()
67{
68  ClearSampling();
69}
70
71void G4GeometrySampler::ClearSampling()
72{
73  if (fImportanceConfigurator)
74  {
75    delete fImportanceConfigurator;
76    fImportanceConfigurator = 0;
77  }
78  if (fWeightWindowConfigurator)
79  {
80    delete fWeightWindowConfigurator;
81    fWeightWindowConfigurator = 0;
82  }
83//   if (fScoreConfigurator)
84//   {
85//     delete fScoreConfigurator;
86//     fScoreConfigurator = 0;
87//   }
88  if (fWeightCutOffConfigurator)
89  {
90    delete fWeightCutOffConfigurator;
91    fWeightCutOffConfigurator = 0;
92  }
93  if (fGCellFinder)
94  {
95    delete fGCellFinder;
96    fGCellFinder = 0;
97  }
98  fIStore = 0;
99  fConfigurators.clear();
100  fIsConfigured = false;
101}
102
103G4bool G4GeometrySampler::IsConfigured() const
104{
105  G4bool isconf = false;
106  if (fIsConfigured)
107  {
108   G4cout << "WARNING - G4GeometrySampler::IsConfigured()"
109          << "          Some initalization exists, use ClearSampling()"
110          << "          before a new initialization !" << G4endl;
111   isconf = true;
112  }
113  return isconf;
114}
115
116// void G4GeometrySampler::PrepareScoring(G4VScorer *scorer)
117// {
118//   G4cout << " preparing scoring configurator " << G4endl;
119//   G4cout << G4endl;
120//   G4cout << G4endl;
121//   G4cout << G4endl;
122//   G4cout << " new fWorld Name: " << fWorld->GetName() << G4endl;
123//   G4cout << G4endl;
124//   G4cout << G4endl;
125//   G4cout << G4endl;
126//   fScoreConfigurator = new G4ScoreConfigurator(fWorld, fParticleName, *scorer, paraflag);
127//   G4cout << " configured scoring " << G4endl;
128//   if (!fScoreConfigurator)
129//   {
130//     G4Exception("G4GeometrySampler::PrepareScoring()",
131//                 "FatalError", FatalException,
132//                 "Failed allocation of G4ScoreConfigurator !");
133//   }
134// }
135
136void
137G4GeometrySampler::PrepareImportanceSampling(G4VIStore *istore,
138                                           const G4VImportanceAlgorithm  *ialg)
139{
140  G4cout << " preparing importance sampling " << G4endl;
141  fIStore = istore;
142  G4cout << " creating istore " << G4endl;
143
144  fImportanceConfigurator =
145    new G4ImportanceConfigurator(fWorld, fParticleName, *fIStore, ialg, paraflag);
146
147  G4cout << " creating importance configurator " << G4endl;
148
149  if (!fImportanceConfigurator)
150  {
151    G4Exception("G4GeometrySampler::PrepareImportanceSampling()",
152                "FatalError", FatalException,
153                "Failed allocation of G4ImportanceConfigurator !");
154  }
155}
156
157void
158G4GeometrySampler::PrepareWeightRoulett(G4double wsurvive, 
159                                            G4double wlimit,
160                                            G4double isource)
161{
162  //  fGCellFinder = new G4GCellFinder(fWorld);
163  G4cout << " preparing weight roulette" << G4endl;
164  fGCellFinder = new G4GCellFinder();
165  if (!fGCellFinder)
166  {
167    G4Exception("G4GeometrySampler::PrepareWeightRoulett()",
168                "FatalError", FatalException,
169                "Failed allocation of G4GCellFinder !");
170  }
171 
172  fWeightCutOffConfigurator = 
173    new G4WeightCutOffConfigurator(fWorld, fParticleName,
174                                   wsurvive,
175                                   wlimit,
176                                   isource,
177                                   fIStore,
178                                   *fGCellFinder, paraflag);
179  if (!fWeightCutOffConfigurator)
180  {
181    G4Exception("G4GeometrySampler::PrepareWeightRoulett()",
182                "FatalError", FatalException,
183                "Failed allocation of G4WeightCutOffConfigurator !");
184  }
185}
186
187void
188G4GeometrySampler::PrepareWeightWindow(G4VWeightWindowStore *wwstore,
189                                           G4VWeightWindowAlgorithm *wwAlg,
190                                           G4PlaceOfAction placeOfAction)
191{
192
193  G4cout << " preparing weight window" << G4endl;
194
195  fWWStore = wwstore;
196 
197  fWeightWindowConfigurator =
198    new G4WeightWindowConfigurator(fWorld, fParticleName,
199                                    *fWWStore,
200                                    wwAlg,
201                                    placeOfAction, paraflag);
202}
203
204void G4GeometrySampler::Configure()
205{
206  G4cout << " entering configure " << G4endl;
207  if (!IsConfigured())
208  {
209    fIsConfigured = true;
210
211//     if (fScoreConfigurator)
212//     {
213//       G4cout << " score configurator push_back " << G4endl;
214//       fConfigurators.push_back(fScoreConfigurator);
215//       G4cout << " pushed " << G4endl;
216//     }
217    if (fImportanceConfigurator)
218    {
219      G4cout << " importance configurator push_back " << G4endl;
220      fConfigurators.push_back(fImportanceConfigurator);
221      G4cout << " pushed " << G4endl;
222    }
223    if (fWeightWindowConfigurator)
224    {
225      G4cout << " weight window configurator push_back " << G4endl;
226      fConfigurators.push_back(fWeightWindowConfigurator);
227      G4cout << " pushed " << G4endl;
228    }
229   
230    G4cout << " vsampler configurator loop " << G4endl;
231    G4VSamplerConfigurator *preConf = 0;
232    G4int i = 0;
233    for (G4Configurators::iterator it = fConfigurators.begin();
234         it != fConfigurators.end(); it++)
235    {
236      i++;
237      G4cout << " looping " << i << G4endl;
238      G4VSamplerConfigurator *currConf =*it;
239      G4cout << " sampler configurator " << G4endl;
240      currConf->Configure(preConf);
241      G4cout << " configure preconf " << G4endl;
242      preConf = *it;
243    }
244    if (fWeightCutOffConfigurator)
245    {
246      G4cout << " NEW weight window configure " << G4endl;
247      fWeightCutOffConfigurator->Configure(0);
248      G4cout << " configured " << G4endl;
249    }
250  }
251  return;
252}
253
254void G4GeometrySampler::SetParallel(G4bool para)
255{
256  paraflag = para;
257}
258
259void G4GeometrySampler::SetParticle(const G4String &particlename)
260{
261  fParticleName = particlename;
262}
263
Note: See TracBrowser for help on using the repository browser.