source: trunk/examples/extended/polarisation/Pol01/src/DetectorConstruction.cc @ 1309

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

update to geant4.9.3

File size: 6.9 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// $Id: DetectorConstruction.cc,v 1.2 2006/10/02 16:25:55 vnivanch Exp $
27// GEANT4 tag $Name: geant4-09-03-cand-01 $
28//
29//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
30//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
31
32#include "DetectorConstruction.hh"
33#include "DetectorMessenger.hh"
34
35#include "G4Material.hh"
36#include "G4Box.hh"
37#include "G4LogicalVolume.hh"
38#include "G4PVPlacement.hh"
39
40#include "G4GeometryManager.hh"
41#include "G4PhysicalVolumeStore.hh"
42#include "G4LogicalVolumeStore.hh"
43#include "G4SolidStore.hh"
44
45#include "G4UnitsTable.hh"
46
47#include "G4PolarizationManager.hh"
48#include "G4NistManager.hh"
49
50//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
51
52DetectorConstruction::DetectorConstruction()
53:pWorld(0), pBox(0), aMaterial(0)
54{
55  boxSizeXY = 50*mm;
56  boxSizeZ = 5*mm;
57  worldSize = 1.*m;
58  aMaterial = 0;
59  wMaterial = 0;
60  SetTargetMaterial("G4_Fe"); 
61  SetWorldMaterial("G4_Galactic"); 
62  detectorMessenger = new DetectorMessenger(this);
63}
64
65//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
66
67DetectorConstruction::~DetectorConstruction()
68{ 
69  delete detectorMessenger;
70}
71
72//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73
74G4VPhysicalVolume* DetectorConstruction::Construct()
75{
76  // Cleanup old geometry
77  G4GeometryManager::GetInstance()->OpenGeometry();
78  G4PhysicalVolumeStore::GetInstance()->Clean();
79  G4LogicalVolumeStore::GetInstance()->Clean();
80  G4SolidStore::GetInstance()->Clean();
81 
82  G4PolarizationManager::GetInstance()->Clean();
83
84  // World
85  //
86  G4Box*
87  sWorld = new G4Box("World",                                   //name
88                   worldSize/2,worldSize/2,worldSize/2);        //dimensions
89
90  G4LogicalVolume*                                                           
91  lWorld = new G4LogicalVolume(sWorld,                  //shape
92                               wMaterial,               //material
93                              "World");                 //name
94
95  pWorld = new G4PVPlacement(0,                         //no rotation
96                           G4ThreeVector(),             //at (0,0,0)
97                           lWorld,                      //logical volume
98                           "World",                     //name
99                           0,                           //mother  volume
100                           false,                       //no boolean operation
101                           0);                          //copy number
102                                                   
103  // Box
104  //                       
105  G4Box*
106  sBox = new G4Box("Container",                         //its name
107                   boxSizeXY/2.,boxSizeXY/2.,boxSizeZ/2.);      //its dimensions
108                   
109  G4LogicalVolume*
110  lBox = new G4LogicalVolume(sBox,                      //its shape
111                             aMaterial,                 //its material
112                             "theBox");                 //its name
113
114  pBox = new G4PVPlacement(0,                           //no rotation
115                           G4ThreeVector(),             //at (0,0,0)
116                           lBox,                        //its logical volume                       
117                           aMaterial->GetName(),        //its name
118                           lWorld,                      //its mother  volume
119                           false,                       //no boolean operation
120                           0);                          //copy number
121
122  // register logical Volume in PolarizationManager with zero polarization
123  G4PolarizationManager * polMgr = G4PolarizationManager::GetInstance();
124  polMgr->SetVolumePolarization(lBox,G4ThreeVector(0.,0.,0.));
125                           
126  PrintParameters();
127 
128  //always return the root volume
129  //
130  return pWorld;
131}
132
133//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
134
135void DetectorConstruction::PrintParameters()
136{
137  G4cout << "\n The Box is " << G4BestUnit(boxSizeXY,"Length")
138         << " x " << G4BestUnit(boxSizeXY,"Length")
139         << " x " << G4BestUnit(boxSizeZ,"Length")
140         << " of " << aMaterial->GetName() << G4endl;
141}
142
143//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
144
145void DetectorConstruction::SetTargetMaterial(G4String materialChoice)
146{
147  // search the material by its name
148  G4Material* mat =
149    G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
150  if (mat != aMaterial) {
151    if(mat) {
152      aMaterial = mat;
153      UpdateGeometry();
154    } else {
155      G4cout << "### Warning!  Target material: <"
156           << materialChoice << "> not found" << G4endl; 
157    }     
158  }
159}
160
161//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
162
163void DetectorConstruction::SetWorldMaterial(G4String materialChoice)
164{
165  // search the material by its name
166  G4Material* mat =
167    G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
168  if (mat != wMaterial) {
169    if(mat) {
170      wMaterial = mat;
171      UpdateGeometry();
172    } else {
173      G4cout << "### Warning! World material: <"
174           << materialChoice << "> not found" << G4endl; 
175    }     
176  }
177}
178
179//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
180
181void DetectorConstruction::SetSizeXY(G4double value)
182{
183  boxSizeXY = value; 
184  if (worldSize<boxSizeXY) worldSize = 1.2*boxSizeXY;
185  UpdateGeometry();
186}
187
188void DetectorConstruction::SetSizeZ(G4double value)
189{
190  boxSizeZ = value; 
191  if (worldSize<boxSizeZ) worldSize = 1.2*boxSizeZ;
192  UpdateGeometry();
193}
194
195//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
196
197#include "G4RunManager.hh"
198
199void DetectorConstruction::UpdateGeometry()
200{
201  if (pWorld) 
202    G4RunManager::GetRunManager()->DefineWorldVolume(Construct());
203}
204
205//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Note: See TracBrowser for help on using the repository browser.