source: trunk/examples/extended/electromagnetic/TestEm6/src/DetectorConstruction.cc @ 1288

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

update to geant4.9.3

File size: 6.8 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.10 2006/06/29 16:57:00 gunter 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#include "G4UniformMagField.hh"
40#include "G4UserLimits.hh"
41
42#include "G4GeometryManager.hh"
43#include "G4PhysicalVolumeStore.hh"
44#include "G4LogicalVolumeStore.hh"
45#include "G4SolidStore.hh"
46
47#include "G4UnitsTable.hh"
48
49//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50
51DetectorConstruction::DetectorConstruction()
52:pBox(0), lBox(0), BoxSize(500*m), aMaterial(0), magField(0)
53{
54  DefineMaterials();
55  SetMaterial("Iron");
56 
57  // create UserLimits
58  userLimits = new G4UserLimits();
59
60  // create commands for interactive definition of the detector 
61  detectorMessenger = new DetectorMessenger(this);
62}
63
64//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
65
66DetectorConstruction::~DetectorConstruction()
67{ delete detectorMessenger;}
68
69//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
70
71G4VPhysicalVolume* DetectorConstruction::Construct()
72{
73  return ConstructVolumes();
74}
75
76//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
77
78void DetectorConstruction::DefineMaterials()
79{ 
80 G4double a, z, density; 
81
82 new G4Material("Beryllium", z= 4., a= 9.012182*g/mole, density= 1.848*g/cm3);
83 new G4Material("Carbon",    z= 6., a= 12.011*g/mole,   density= 2.265*g/cm3);
84 new G4Material("Iron",      z=26., a= 55.85*g/mole,    density= 7.870*g/cm3);
85
86 G4cout << *(G4Material::GetMaterialTable()) << G4endl;
87}
88
89//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
90 
91G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
92{
93  G4GeometryManager::GetInstance()->OpenGeometry();
94  G4PhysicalVolumeStore::GetInstance()->Clean();
95  G4LogicalVolumeStore::GetInstance()->Clean();
96  G4SolidStore::GetInstance()->Clean();
97 
98  G4Box*
99  sBox = new G4Box("Container",                         //its name
100                   BoxSize/2,BoxSize/2,BoxSize/2);      //its dimensions
101                                                             
102  lBox = new G4LogicalVolume(sBox,                      //its shape
103                             aMaterial,                 //its material
104                             aMaterial->GetName());     //its name
105                             
106  lBox->SetUserLimits(userLimits);                           
107                                   
108  pBox = new G4PVPlacement(0,                           //no rotation
109                           G4ThreeVector(),             //at (0,0,0)
110                           lBox,                        //its logical volume
111                           aMaterial->GetName(),        //its name
112                           0,                           //its mother  volume
113                           false,                       //no boolean operation
114                           0);                          //copy number
115                           
116  PrintParameters();
117   
118  //
119  //always return the root volume
120  //
121  return pBox;
122}
123
124//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
125
126void DetectorConstruction::PrintParameters()
127{
128  G4cout << "\n The Box is " << G4BestUnit(BoxSize,"Length")
129         << " of " << aMaterial->GetName() << G4endl;
130}
131
132//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
133
134void DetectorConstruction::SetMaterial(G4String materialChoice)
135{
136  // search the material by its name   
137  G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);     
138  if (pttoMaterial) aMaterial = pttoMaterial;             
139}
140
141//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
142
143void DetectorConstruction::SetSize(G4double value)
144{
145  BoxSize = value;
146} 
147
148//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
149
150#include "G4FieldManager.hh"
151#include "G4TransportationManager.hh"
152
153void DetectorConstruction::SetMagField(G4double fieldValue)
154{
155  //apply a global uniform magnetic field along Z axis
156  G4FieldManager* fieldMgr
157   = G4TransportationManager::GetTransportationManager()->GetFieldManager();
158   
159  if (magField) delete magField;        //delete the existing magn field
160 
161  if (fieldValue!=0.)                   // create a new one if non nul
162    {
163      magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));       
164      fieldMgr->SetDetectorField(magField);
165      fieldMgr->CreateChordFinder(magField);
166    }
167   else
168    {
169      magField = 0;
170      fieldMgr->SetDetectorField(magField);
171    }
172}
173
174//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
175
176void DetectorConstruction::SetMaxStepSize(G4double val)
177{
178  // set the maximum allowed step size
179  //
180  if (val <= DBL_MIN)
181    { G4cout << "\n --->warning from SetMaxStepSize: maxStep " 
182             << val  << " out of range. Command refused" << G4endl;
183      return;
184    }       
185  userLimits->SetMaxAllowedStep(val);
186} 
187
188//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
189
190#include "G4RunManager.hh"
191 
192void DetectorConstruction::UpdateGeometry()
193{
194  G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
195}
196
197//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Note: See TracBrowser for help on using the repository browser.