LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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 //
31 //
32 // --------------------------------------------------------------
33 // GEANT 4 - exampleB03
34 //
35 // --------------------------------------------------------------
36 // Comments
37 //
38 // This example intends to show how to use both importance sampling and a
39 // customized scoring making use of the scoring framework
40 // in a parallel geometry.
41 //
42 // A simple geometry consisting of a 180 cm high concrete cylinder
43 // is constructed in the mass geometry.
44 // A geometry is constructed in the parallel geometry
45 // in order to assign importance values to slabs
46 // of width 10cm and for scoring. The parallel world volume should
47 // overlap the mass world volume and the radii of the slabs is larger
48 // than the radius of the concrete cylinder in the mass geometry.
49 // Pairs of G4GeometryCell and importance values are stored in
50 // the importance store.
51 // The scoring uses the primitive scorers via the Multi Functional Detector
52 //
53 //
54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
55 
56 #include <iostream>
57 
58 #include "G4Types.hh"
59 
60 #ifdef G4MULTITHREADED
61 #include "G4MTRunManager.hh"
62 #else
63 #include "G4RunManager.hh"
64 #endif
65 
66 #include "G4VPhysicalVolume.hh"
67 #include "G4UImanager.hh"
68 #include "G4SystemOfUnits.hh"
69 
70 #include "B03DetectorConstruction.hh"
71 #include "B03PhysicsList.hh"
72 
73 #include "B03ActionInitialization.hh"
74 // #include "B03PrimaryGeneratorAction.hh"
75 // #include "B03RunAction.hh"
76 
77 // construction for the parallel geometry
78 #include "B03ImportanceDetectorConstruction.hh"
79 
80 // Files specific for biasing and scoring
81 //#include "G4Scorer.hh"
82 // #include "G4GeometrySampler.hh"
83 #include "G4IStore.hh"
84 
85 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
86 
87 int main(int , char **)
88 {
89  G4int numberOfEvents = 100;
90 
91  G4long myseed = 345354;
92 
93 #ifdef G4MULTITHREADED
94  G4MTRunManager * runManager = new G4MTRunManager;
95  G4cout << " Number of cores: " << G4Threading::G4GetNumberOfCores() << G4endl;
96  G4cout << " but using only two! " << G4endl;
97  runManager->SetNumberOfThreads(2);
98  // runManager->SetNumberOfThreads(G4Threading::G4GetNumberOfCores());
99 #else
100  G4RunManager * runManager = new G4RunManager;
101 #endif
102 
103  G4Random::setTheSeed(myseed);
104 
105  // create the detector ---------------------------
106  B03DetectorConstruction *detector = new B03DetectorConstruction();
107  runManager->SetUserInitialization(detector);
108  // ---------------------------------------------------
109 
110  // create a parallel detector
111  G4String parallelName("ParallelBiasingWorld");
112  B03ImportanceDetectorConstruction *pdet =
113  new B03ImportanceDetectorConstruction(parallelName);
114  detector->RegisterParallelWorld(pdet);
115 
116  // G4GeometrySampler pgs(pdet->GetWorldVolume(),"neutron");
117  // B03PhysicsList* physlist = new B03PhysicsList;
118  // name of first parallel world:
119  B03PhysicsList* physlist = new B03PhysicsList(parallelName);
120  // push parallel world to store in case of multiple worlds:
121  physlist->AddParallelWorldName(parallelName);
122  // physlist->AddParallelWorldName(parallelName);
123  //physlist->AddParallelWorldName(sparallelName);
124  // physlist->AddBiasing(&pgs,parallelName);
125 
126  runManager->SetUserInitialization(physlist);
127 
128  // Set user action classes through Worker Initialization
129  //
130  B03ActionInitialization* actions = new B03ActionInitialization;
131  runManager->SetUserInitialization(actions);
132 
133 // runManager->SetUserAction(new B03PrimaryGeneratorAction);
134 // // runManager->SetUserAction(new B03PrimaryGeneratorAction(ifElectron));
135 // runManager->SetUserAction(new B03RunAction);
136 
137  runManager->Initialize();
138 
139  G4VPhysicalVolume& aghostWorld = pdet->GetWorldVolumeAddress();
140  G4cout << " ghost world: " << pdet->GetName() << G4endl;
141 
142  // create an importance
143  G4IStore *aIstore = G4IStore::GetInstance(pdet->GetName());
144 
145  // create a geometry cell for the world volume replpicanumber is 0!
146  G4GeometryCell gWorldVolumeCell(aghostWorld, 0);
147  // set world volume importance to 1
148  aIstore->AddImportanceGeometryCell(1, gWorldVolumeCell);
149 
150  // set importance values and create scorers
151  G4int cell(1);
152  for (cell=1; cell<=18; cell++) {
153  G4GeometryCell gCell = pdet->GetGeometryCell(cell);
154  G4cout << " adding cell: " << cell
155  << " replica: " << gCell.GetReplicaNumber()
156  << " name: " << gCell.GetPhysicalVolume().GetName() << G4endl;
157  G4double imp = std::pow(2.0,cell-1);
158  //x aIstore.AddImportanceGeometryCell(imp, gCell);
159  aIstore->AddImportanceGeometryCell(imp, gCell.GetPhysicalVolume(), cell);
160  }
161 
162  // creating the geometry cell and add both to the store
163  // G4GeometryCell gCell = pdet->GetGeometryCell(18);
164 
165  // create importance geometry cell pair for the "rest"cell
166  // with the same importance as the last concrete cell
167  G4GeometryCell gCell = pdet->GetGeometryCell(19);
168  // G4double imp = std::pow(2.0,18);
169  G4double imp = std::pow(2.0,17);
170  aIstore->AddImportanceGeometryCell(imp, gCell.GetPhysicalVolume(), 19);
171 
172  //temporary fix before runManager->BeamOn works...
173  G4UImanager* UImanager = G4UImanager::GetUIpointer();
174  G4String command1 = "/control/cout/setCoutFile fileName";
175  UImanager->ApplyCommand(command1);
176 
177  G4String command2 = "/run/beamOn "
178  + G4UIcommand::ConvertToString(numberOfEvents);;
179  UImanager->ApplyCommand(command2);
180 
181  // runManager->BeamOn(numberOfEvents);
182 
183  // pgs.ClearSampling();
184 
185  delete runManager;
186 
187  return 0;
188 }
189 
190 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
int main(int, char **)
Definition: exampleB03.cc:87