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