Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exampleB03.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: exampleB03.cc 70528 2013-05-31 16:50:36Z gcosmo $
31 //
32 //
33 // --------------------------------------------------------------
34 // GEANT 4 - exampleB03
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 primitive scorers via the Multi Functional Detector
53 //
54 //
55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
56 
57 #include <iostream>
58 
59 #ifdef G4MULTITHREADED
60 #include "G4MTRunManager.hh"
61 #else
62 #include "G4RunManager.hh"
63 #endif
64 
65 #include "G4VPhysicalVolume.hh"
66 #include "G4UImanager.hh"
67 #include "G4SystemOfUnits.hh"
68 
70 #include "B03PhysicsList.hh"
71 
73 // #include "B03PrimaryGeneratorAction.hh"
74 // #include "B03RunAction.hh"
75 
76 // construction for the parallel geometry
78 
79 // Files specific for biasing and scoring
80 //#include "G4Scorer.hh"
81 #include "G4GeometrySampler.hh"
82 #include "G4IStore.hh"
83 
84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
85 
86 int main(int , char **)
87 {
88  G4int numberOfEvents = 100;
89 
90  G4long myseed = 345354;
91 
92 #ifdef G4MULTITHREADED
93  G4MTRunManager * runManager = new G4MTRunManager;
94  G4cout << " Number of cores: " << G4Threading::G4GetNumberOfCores() << G4endl;
95  G4cout << " but using only two! " << G4endl;
96  runManager->SetNumberOfThreads(2);
97  // runManager->SetNumberOfThreads(G4Threading::G4GetNumberOfCores());
98 #else
99  G4RunManager * runManager = new G4RunManager;
100 #endif
101 
102  G4Random::setTheSeed(myseed);
103 
104  // create the detector ---------------------------
106  runManager->SetUserInitialization(detector);
107  // ---------------------------------------------------
108 
109  // create a parallel detector
110  G4String parallelName("ParallelBiasingWorld");
112  new B03ImportanceDetectorConstruction(parallelName);
113  detector->RegisterParallelWorld(pdet);
114 
115  G4GeometrySampler pgs(pdet->GetWorldVolume(),"neutron");
116  B03PhysicsList* physlist = new B03PhysicsList;
117  physlist->AddParallelWorldName(parallelName);
118  //physlist->AddParallelWorldName(sparallelName);
119  physlist->AddBiasing(&pgs,parallelName);
120 
121  runManager->SetUserInitialization(physlist);
122 
123  // Set user action classes through Worker Initialization
124  //
126  runManager->SetUserInitialization(actions);
127 
128 // runManager->SetUserAction(new B03PrimaryGeneratorAction);
129 // // runManager->SetUserAction(new B03PrimaryGeneratorAction(ifElectron));
130 // runManager->SetUserAction(new B03RunAction);
131 
132  runManager->Initialize();
133 
134  G4VPhysicalVolume& aghostWorld = pdet->GetWorldVolumeAddress();
135  G4cout << " ghost world: " << pdet->GetName() << G4endl;
136 
137  // create an importance
138  G4IStore *aIstore = G4IStore::GetInstance(pdet->GetName());
139 
140  // create a geometry cell for the world volume replpicanumber is 0!
141  G4GeometryCell gWorldVolumeCell(aghostWorld, 0);
142  // set world volume importance to 1
143  aIstore->AddImportanceGeometryCell(1, gWorldVolumeCell);
144 
145  // set importance values and create scorers
146  G4int cell(1);
147  for (cell=1; cell<=18; cell++) {
148  G4GeometryCell gCell = pdet->GetGeometryCell(cell);
149  G4cout << " adding cell: " << cell
150  << " replica: " << gCell.GetReplicaNumber()
151  << " name: " << gCell.GetPhysicalVolume().GetName() << G4endl;
152  G4double imp = std::pow(2.0,cell-1);
153  //x aIstore.AddImportanceGeometryCell(imp, gCell);
154  aIstore->AddImportanceGeometryCell(imp, gCell.GetPhysicalVolume(), cell);
155  }
156 
157  // creating the geometry cell and add both to the store
158  // G4GeometryCell gCell = pdet->GetGeometryCell(18);
159 
160  // create importance geometry cell pair for the "rest"cell
161  // with the same importance as the last concrete cell
162  G4GeometryCell gCell = pdet->GetGeometryCell(19);
163  // G4double imp = std::pow(2.0,18);
164  G4double imp = std::pow(2.0,17);
165  aIstore->AddImportanceGeometryCell(imp, gCell.GetPhysicalVolume(), 19);
166 
167  //temporary fix before runManager->BeamOn works...
168  G4UImanager* UImanager = G4UImanager::GetUIpointer();
169  G4String command1 = "/control/cout/setCoutFile fileName";
170  UImanager->ApplyCommand(command1);
171 
172  G4String command2 = "/run/beamOn "
173  + G4UIcommand::ConvertToString(numberOfEvents);;
174  UImanager->ApplyCommand(command2);
175 
176  // runManager->BeamOn(numberOfEvents);
177 
178  // pgs.ClearSampling();
179 
180  delete runManager;
181 
182  return 0;
183 }
184 
185 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
void SetNumberOfThreads(G4int n)
Definition of the B03ActionInitialization class.
long G4long
Definition: G4Types.hh:80
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:372
Definition of the B03PhysicsList class.
int main(int argc, char **argv)
Definition: genwindef.cpp:30
Definition of the B03DetectorConstruction class.
int G4int
Definition: G4Types.hh:78
void RegisterParallelWorld(G4VUserParallelWorld *)
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
G4GLOB_DLL std::ostream G4cout
const G4String & GetName() const
G4int G4GetNumberOfCores()
Definition: G4Threading.cc:143
G4int GetReplicaNumber() const
void AddImportanceGeometryCell(G4double importance, const G4GeometryCell &gCell)
Definition: G4IStore.cc:107
const G4VPhysicalVolume & GetPhysicalVolume() const
static G4IStore * GetInstance()
Definition: G4IStore.cc:236
void AddParallelWorldName(G4String &pname)
virtual void Initialize()
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
Definition of the B03ImportanceDetectorConstruction class.
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:447