source: trunk/examples/extended/electromagnetic/TestEm2/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: 7.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//
27// $Id: DetectorConstruction.cc,v 1.14 2009/09/16 18:07:30 maire Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-01 $
29
30//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
31//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32
33#include "DetectorConstruction.hh"
34#include "DetectorMessenger.hh"
35
36#include "G4Tubs.hh"
37#include "G4LogicalVolume.hh"
38#include "G4PVPlacement.hh"
39#include "G4UniformMagField.hh"
40
41#include "G4GeometryManager.hh"
42#include "G4PhysicalVolumeStore.hh"
43#include "G4LogicalVolumeStore.hh"
44#include "G4SolidStore.hh"
45
46#include "G4FieldManager.hh"
47#include "G4TransportationManager.hh"
48
49#include "G4NistManager.hh"
50#include "G4RunManager.hh"
51
52#include "G4UnitsTable.hh"
53
54//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
55
56DetectorConstruction::DetectorConstruction()
57:nLtot(40),nRtot(50),dLradl(0.5),dRradl(0.1),
58 dLlength(0.),dRlength(0.),
59 myMaterial(0),magField(0),
60 EcalLength(0.),EcalRadius(0.),
61 solidEcal(0),logicEcal(0),physiEcal(0)
62{
63  DefineMaterials();
64  SetMaterial("G4_PbWO4");
65  detectorMessenger = new DetectorMessenger(this);
66}
67
68//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
69
70DetectorConstruction::~DetectorConstruction()
71{ delete detectorMessenger;}
72
73//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
74
75G4VPhysicalVolume* DetectorConstruction::Construct()
76{
77  return ConstructVolumes();
78}
79
80//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
81
82void DetectorConstruction::DefineMaterials()
83{
84  //
85  // define few Elements by hand
86  //
87  G4double a, z;
88   
89  G4Element* H  = new G4Element("Hydrogen",  "H", z= 1., a=   1.01*g/mole);
90  G4Element* O  = new G4Element("Oxygen"  ,  "O", z= 8., a=  16.00*g/mole);
91  G4Element* Ge = new G4Element("Germanium", "Ge",z=32., a=  72.59*g/mole);
92  G4Element* Bi = new G4Element("Bismuth",   "Bi",z=83., a= 208.98*g/mole);
93
94  //
95  // define materials
96  //
97  G4double density;
98  G4int ncomponents, natoms;
99
100  // water with ionisation potential 75 eV
101  G4Material* H2O = 
102  new G4Material("Water", density= 1.00*g/cm3, ncomponents=2);
103  H2O->AddElement(H, natoms=2);
104  H2O->AddElement(O, natoms=1);
105  H2O->GetIonisation()->SetMeanExcitationEnergy(75.0*eV);
106
107  // pure materails
108  new G4Material("liquidArgon", z=18., a= 39.95*g/mole, density= 1.390*g/cm3);
109  new G4Material("Aluminium",   z=13., a= 26.98*g/mole, density= 2.7*g/cm3);
110  new G4Material("Iron",        z=26., a= 55.85*g/mole, density= 7.87*g/cm3); 
111  new G4Material("Copper",      z=29., a= 63.55*g/mole, density= 8.960*g/cm3); 
112  new G4Material("Tungsten",    z=74., a=183.84*g/mole, density=19.35*g/cm3);   
113  new G4Material("Lead",        z=82., a=207.19*g/mole, density=11.35*g/cm3); 
114  new G4Material("Uranium"    , z=92., a=238.03*g/mole, density= 18.95*g/cm3);
115
116  // compound material
117  G4Material* BGO = 
118  new G4Material("BGO", density= 7.10*g/cm3, ncomponents=3);
119  BGO->AddElement(O , natoms=12);
120  BGO->AddElement(Ge, natoms= 3);
121  BGO->AddElement(Bi, natoms= 4);
122
123  G4cout << *(G4Material::GetMaterialTable()) << G4endl;
124}
125
126//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
127
128G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
129{
130  G4double Radl = myMaterial->GetRadlen();
131
132  dLlength = dLradl*Radl; dRlength = dRradl*Radl;
133  EcalLength = nLtot*dLlength;  EcalRadius = nRtot*dRlength;
134
135  // Cleanup old geometry
136  G4GeometryManager::GetInstance()->OpenGeometry();
137  G4PhysicalVolumeStore::GetInstance()->Clean();
138  G4LogicalVolumeStore::GetInstance()->Clean();
139  G4SolidStore::GetInstance()->Clean();
140
141  //
142  // Ecal
143  //
144  solidEcal = new G4Tubs("Ecal",0.,EcalRadius,0.5*EcalLength,0.,360*deg);
145  logicEcal = new G4LogicalVolume( solidEcal,myMaterial,"Ecal",0,0,0);
146  physiEcal = new G4PVPlacement(0,G4ThreeVector(),
147                                logicEcal,"Ecal",0,false,0);
148
149  G4cout << "Absorber is " << G4BestUnit(EcalLength,"Length")
150         << " of " << myMaterial->GetName() << G4endl;
151  G4cout << myMaterial << G4endl;     
152
153  //
154  //always return the physical World
155  //
156  return physiEcal;
157}
158
159//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
160
161void DetectorConstruction::SetMaterial(const G4String& materialChoice)
162{
163  // search the material by its name
164  G4Material* pttoMaterial =
165    G4NistManager::Instance()->FindOrBuildMaterial(materialChoice);
166
167  if (pttoMaterial) {
168    myMaterial = pttoMaterial;
169    if(logicEcal) logicEcal->SetMaterial(myMaterial);
170    G4RunManager::GetRunManager()->PhysicsHasBeenModified();
171  }
172}
173
174//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
175
176void DetectorConstruction::SetLBining(G4ThreeVector Value)
177{
178  nLtot = (G4int)Value(0);
179  if (nLtot > MaxBin) {
180    G4cout << "\n ---> warning from SetLBining: "
181           << nLtot << " truncated to " << MaxBin << G4endl;
182    nLtot = MaxBin;
183  } 
184  dLradl = Value(1);
185}
186
187//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
188
189void DetectorConstruction::SetRBining(G4ThreeVector Value)
190{
191  nRtot = (G4int)Value(0);
192  if (nRtot > MaxBin) {
193    G4cout << "\n ---> warning from SetRBining: "
194           << nRtot << " truncated to " << MaxBin << G4endl;
195    nRtot = MaxBin;
196  }   
197  dRradl = Value(1);
198}
199
200//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
201
202void DetectorConstruction::SetMagField(G4double fieldValue)
203{
204  //apply a global uniform magnetic field along Z axis
205  G4FieldManager* fieldMgr
206   = G4TransportationManager::GetTransportationManager()->GetFieldManager();
207
208  if(magField) delete magField;         //delete the existing magn field
209
210  if(fieldValue!=0.)                    // create a new one if non nul
211  { magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));
212    fieldMgr->SetDetectorField(magField);
213    fieldMgr->CreateChordFinder(magField);
214  } else {
215    magField = 0;
216    fieldMgr->SetDetectorField(magField);
217  }
218}
219
220//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
221
222void DetectorConstruction::UpdateGeometry()
223{
224  G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
225}
226
227//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Note: See TracBrowser for help on using the repository browser.