source: trunk/examples/extended/electromagnetic/TestEm11/src/DetectorConstruction.cc

Last change on this file was 1337, checked in by garnier, 14 years ago

tag geant4.9.4 beta 1 + modifs locales

File size: 8.5 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.9 2009/11/16 15:09:10 maire Exp $
27// GEANT4 tag $Name: geant4-09-04-beta-01 $
28
29//
30//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
31//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32
33#include "DetectorConstruction.hh"
34#include "DetectorMessenger.hh"
35
36#include "G4NistManager.hh"
37#include "G4Box.hh"
38#include "G4LogicalVolume.hh"
39#include "G4VPhysicalVolume.hh"
40#include "G4PVPlacement.hh"
41#include "G4PVReplica.hh"
42#include "G4UniformMagField.hh"
43
44#include "G4GeometryManager.hh"
45#include "G4PhysicalVolumeStore.hh"
46#include "G4LogicalVolumeStore.hh"
47#include "G4SolidStore.hh"
48
49#include "G4UnitsTable.hh"
50
51//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
52
53DetectorConstruction::DetectorConstruction()
54{
55  // default parameter values
56  absorSizeX = absorSizeYZ = 1*mm;
57  nbOfLayers = 1;
58 
59  absorMaterial = 0;
60  magField = 0;
61  pAbsor   = 0;
62 
63  DefineMaterials();
64  SetMaterial("G4_Si");
65
66  // create commands for interactive definition of the detector 
67  detectorMessenger = new DetectorMessenger(this);
68}
69
70//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
71
72DetectorConstruction::~DetectorConstruction()
73{ delete detectorMessenger;}
74
75//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
76
77G4VPhysicalVolume* DetectorConstruction::Construct()
78{
79  return ConstructVolumes();
80}
81
82//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
83
84void DetectorConstruction::DefineMaterials()
85{ 
86  G4NistManager* man = G4NistManager::Instance();
87 
88  G4bool isotopes = false;
89 
90  man->FindOrBuildMaterial("G4_Al", isotopes);
91  man->FindOrBuildMaterial("G4_Si", isotopes);
92  man->FindOrBuildMaterial("G4_Fe", isotopes);
93  man->FindOrBuildMaterial("G4_Cu", isotopes); 
94  man->FindOrBuildMaterial("G4_Ge", isotopes);
95  man->FindOrBuildMaterial("G4_Mo", isotopes);
96  man->FindOrBuildMaterial("G4_Ta", isotopes);
97  man->FindOrBuildMaterial("G4_W" , isotopes);
98  man->FindOrBuildMaterial("G4_Au", isotopes);
99  man->FindOrBuildMaterial("G4_Pb", isotopes); 
100  man->FindOrBuildMaterial("G4_PbWO4", isotopes);
101  man->FindOrBuildMaterial("G4_SODIUM_IODIDE", isotopes);
102 
103  man->FindOrBuildMaterial("G4_AIR"  , isotopes);
104  ///man->FindOrBuildMaterial("G4_WATER", isotopes);
105 
106  G4Element* H = man->FindOrBuildElement("H", isotopes); 
107  G4Element* O = man->FindOrBuildElement("O", isotopes);
108 
109  G4Material* H2O = 
110  new G4Material("Water", 1.000*g/cm3, 2);
111  H2O->AddElement(H, 2);
112  H2O->AddElement(O, 1);
113  H2O->GetIonisation()->SetMeanExcitationEnergy(75.0*eV);
114       
115 G4cout << *(G4Material::GetMaterialTable()) << G4endl;
116}
117
118//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
119 
120G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
121{
122  G4GeometryManager::GetInstance()->OpenGeometry();
123  G4PhysicalVolumeStore::GetInstance()->Clean();
124  G4LogicalVolumeStore::GetInstance()->Clean();
125  G4SolidStore::GetInstance()->Clean();
126                   
127  // Absorber
128  //
129  G4Box* 
130  sAbsor = new G4Box("Absorber",                                //name
131                 absorSizeX/2,absorSizeYZ/2,absorSizeYZ/2);     //size
132
133  G4LogicalVolume*
134  lAbsor = new G4LogicalVolume(sAbsor,                  //solid
135                               absorMaterial,           //material
136                              "Absorber");              //name
137                                   
138  pAbsor = new G4PVPlacement(0,                         //no rotation
139                             G4ThreeVector(),           //at (0,0,0)
140                             lAbsor,                    //logical volume
141                            "Absorber",                 //name
142                             0,                         //mother  volume
143                             false,                     //no boolean operation
144                             0);                        //copy number
145
146  // Layers
147  //
148  layerThickness = absorSizeX/nbOfLayers;
149 
150  if (nbOfLayers > 1)  {                           
151                           
152    G4Box*
153    sLayer = new G4Box("Layer",                                 //name
154                 layerThickness/2,absorSizeYZ/2,absorSizeYZ/2); //dimensions
155                 
156    G4LogicalVolume*                                                         
157    lLayer = new G4LogicalVolume(sLayer,                //shape
158                                 absorMaterial,         //material
159                                 "Layer");              //name
160                                                   
161             new G4PVReplica("Layer",                   //name
162                           lLayer,                      //logical volume
163                           lAbsor,                      //mother  volume
164                           kXAxis,                      //axis   of replica
165                           nbOfLayers,                  //number of replica
166                           layerThickness);             //width  of replica
167  }                       
168
169  PrintParameters();
170   
171  //
172  //always return the root volume
173  // 
174  return pAbsor;
175}
176
177//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
178
179void DetectorConstruction::PrintParameters()
180{
181  G4cout << "\n---------------------------------------------------------\n";
182  G4cout << "---> The Absorber is " << G4BestUnit(absorSizeX,"Length")
183         << " of " << absorMaterial->GetName() << " divided in " << nbOfLayers
184         << " slices of " << G4BestUnit(layerThickness,"Length") << G4endl;
185  G4cout << "\n---------------------------------------------------------\n";
186}
187
188//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
189
190void DetectorConstruction::SetSizeX(G4double value)
191{
192  absorSizeX = value;
193}
194 
195//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
196
197void DetectorConstruction::SetSizeYZ(G4double value)
198{
199  absorSizeYZ = value; 
200} 
201
202//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
203
204void DetectorConstruction::SetMaterial(G4String materialChoice)
205{
206  // search the material by its name   
207  G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);     
208  if (pttoMaterial) absorMaterial = pttoMaterial;
209}
210
211//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
212
213void DetectorConstruction::SetNbOfLayers(G4int value)
214{
215  nbOfLayers = value; 
216}
217 
218//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
219
220#include "G4FieldManager.hh"
221#include "G4TransportationManager.hh"
222
223void DetectorConstruction::SetMagField(G4double fieldValue)
224{
225  //apply a global uniform magnetic field along Z axis
226  G4FieldManager* fieldMgr
227   = G4TransportationManager::GetTransportationManager()->GetFieldManager();
228   
229  if (magField) delete magField;        //delete the existing magn field
230 
231  if (fieldValue!=0.)                   // create a new one if non nul
232    {
233      magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));       
234      fieldMgr->SetDetectorField(magField);
235      fieldMgr->CreateChordFinder(magField);
236    }
237   else
238    {
239      magField = 0;
240      fieldMgr->SetDetectorField(magField);
241    }
242}
243
244//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
245
246#include "G4RunManager.hh"
247 
248void DetectorConstruction::UpdateGeometry()
249{
250G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
251}
252
253//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Note: See TracBrowser for help on using the repository browser.