source: trunk/examples/extended/biasing/B02/exampleB02.cc @ 1230

Last change on this file since 1230 was 1230, checked in by garnier, 14 years ago

update to geant4.9.3

File size: 7.3 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: exampleB02.cc,v 1.22 2007/06/22 13:38:55 ahoward Exp $
28// GEANT4 tag $Name: geant4-09-03-cand-01 $
29//
30//
31// --------------------------------------------------------------
32//      GEANT 4 - exampleB02
33//
34// --------------------------------------------------------------
35// Comments
36//
37// This example intends to show how to use both importance sampling and a
38// customized scoring making use of the scoring framework
39// in a parallel geometry.
40//
41// A simple geometry consisting of a 180 cm high concrete cylinder
42// is constructed in the mass geometry.
43// A geometry is constructed in the parallel geometry
44// in order to assign importance values to slabs
45// of width 10cm and for scoring. The parallel world volume should
46// overlap the mass world volume and  the radii of the slabs is larger
47// than the radius of the concrete cylinder in the mass geometry.
48// Pairs of G4GeometryCell and importance values are stored in
49// the importance store.
50// The scoring uses the G4CellSCorer and one customized scorer for
51// the last slab.
52//
53//
54
55// --------------------------------------------------------------
56
57#include <iostream>
58
59#include "G4VPhysicalVolume.hh"
60#include "G4RunManager.hh"
61#include "G4UImanager.hh"
62
63#include "B02DetectorConstruction.hh"
64#include "B02PhysicsList.hh"
65#include "B02PrimaryGeneratorAction.hh"
66
67#include "B02RunAction.hh"
68#include "B02PSScoringDetectorConstruction.hh"
69
70// construction for the parallel geometry
71#include "B02ImportanceDetectorConstruction.hh"
72
73// Files specific for biasing and scoring
74//#include "G4Scorer.hh"
75#include "G4GeometrySampler.hh"
76#include "G4IStore.hh"
77
78// customized scorer and store
79#include "B02CellScorer.hh"
80#include "B02CellScorerStore.hh"
81
82// a score table
83//#include "G4ScoreTable.hh"
84#include "B02ScoreTable.hh"
85
86// AIDA stuff
87
88#include "AIDA/IAnalysisFactory.h"
89#include "AIDA/ITree.h"
90#include "AIDA/ITreeFactory.h"
91#include "AIDA/IHistogram1D.h"
92#include "AIDA/IHistogramFactory.h"
93
94
95
96int main(int , char **)
97{ 
98  G4int numberOfEvents = 100;
99
100  G4long myseed = 345354;
101
102  CLHEP::HepRandom::setTheSeed(myseed);
103
104  G4RunManager *runManager = new G4RunManager;
105 
106  // create the detector      ---------------------------
107  B02DetectorConstruction *detector = new B02DetectorConstruction();
108  runManager->SetUserInitialization(detector);
109  //  ---------------------------------------------------
110
111  // create a parallel detector
112  // create a parallel detector
113  //  B02ImportanceDetectorConstruction *pdet =
114  //    new B02ImportanceDetectorConstruction;
115  G4String parallelName("ParallelBiasingWorld");
116  B02ImportanceDetectorConstruction *pdet = 
117    new B02ImportanceDetectorConstruction(parallelName);
118  detector->RegisterParallelWorld(pdet);
119
120
121  B02PhysicsList* physlist = new B02PhysicsList;
122  physlist->AddParallelWorldName(parallelName); 
123  //physlist->AddParallelWorldName(sparallelName);
124  runManager->SetUserInitialization(physlist);
125  runManager->SetUserAction(new B02PrimaryGeneratorAction);
126  //  runManager->SetUserAction(new B02PrimaryGeneratorAction(ifElectron));
127  runManager->SetUserAction(new B02RunAction);
128
129  runManager->Initialize();
130
131  G4VPhysicalVolume* ghostWorld = pdet->GetWorldVolume();
132  G4VPhysicalVolume& aghostWorld = pdet->GetWorldVolumeAddress();
133
134  G4cout << " ghost world: " << pdet->GetName() << G4endl;
135
136  // create an importance
137  G4IStore aIstore(aghostWorld);
138  // create a geometry cell for the world volume replpicanumber is 0!
139  G4GeometryCell gWorldVolumeCell(aghostWorld, 0);
140  // set world volume importance to 1
141  aIstore.AddImportanceGeometryCell(1, gWorldVolumeCell);
142
143  // create a customized cell scorer store
144  B02CellScorerStore b02store;
145
146  // set importance values and create scorers
147  G4int cell(1);
148  for (cell=1; cell<=18; cell++) {
149    G4GeometryCell gCell = pdet->GetGeometryCell(cell);
150    G4cout << " adding cell: " << cell << " replica: " << gCell.GetReplicaNumber() << " name: " << gCell.GetPhysicalVolume().GetName() << G4endl;
151    G4double imp = std::pow(2.0,cell-1);
152    //x    aIstore.AddImportanceGeometryCell(imp, gCell);
153    aIstore.AddImportanceGeometryCell(imp, gCell.GetPhysicalVolume(), cell);
154    // adding the standard G4CellScorer for 17 concrete cells
155    if (cell<18) {
156      b02store.AddG4CellScorer(gCell);
157    }
158  }
159
160  // create a histogram for a special scorer for the last cell
161  AIDA::IAnalysisFactory *af = AIDA_createAnalysisFactory();
162  AIDA::ITreeFactory *tf = af->createTreeFactory();
163  AIDA::ITree *tree = tf->create("b02.hbook", "hbook",false,true);
164  AIDA::IHistogramFactory *hf = af->createHistogramFactory( *tree );
165  AIDA::IHistogram1D *h = 
166    hf->createHistogram1D("10","w*sl vs. e", 30, 0., 20*MeV);
167  // create a special scorer for the last cell
168  B02CellScorer b02scorer(h);
169 
170
171
172
173  // creating the geometry cell and add both to the store
174  G4GeometryCell gCell = pdet->GetGeometryCell(18);
175  b02store.AddB02CellScorer(&b02scorer, gCell);
176
177
178  // create importance geometry cell pair for the "rest"cell
179  // with the same importance as the last concrete cell
180  gCell = pdet->GetGeometryCell(19);
181  //  G4double imp = std::pow(2.0,18);
182  G4double imp = std::pow(2.0,17); 
183  aIstore.AddImportanceGeometryCell(imp, gCell.GetPhysicalVolume(), 19);
184 
185
186  // create the importance and scoring sampler for biasing and scoring
187  // in the parallel world
188
189  //  G4CellStoreScorer scorer(b02store);
190
191  G4GeometrySampler pgs(ghostWorld,"neutron");
192
193  pgs.SetParallel(true);
194
195  //
196  //  pgs.PrepareScoring(&scorer);
197
198  pgs.PrepareImportanceSampling(&aIstore, 0);
199
200  pgs.Configure();
201
202  runManager->BeamOn(numberOfEvents);
203
204  // print a table of the scores
205  B02ScoreTable sp(&aIstore);
206
207
208 
209  tree->commit();
210  tree->close();
211
212  delete af;
213  delete tf;
214  delete tree;
215
216  pgs.ClearSampling();
217
218  delete runManager;
219 
220  return 0;
221}
222
223
224
Note: See TracBrowser for help on using the repository browser.