Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DetectorConstruction.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 // $Id: DetectorConstruction.cc 101905 2016-12-07 11:34:39Z gunter $
30 //
32 //
33 // TestEm8: Gaseous detector
34 //
35 // Created: 31.08.2010 V.Ivanchenko ob base of V.Grichine code
36 //
37 // Modified:
38 //
40 //
41 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
42 
43 #include "DetectorConstruction.hh"
44 #include "DetectorMessenger.hh"
45 #include "TargetSD.hh"
46 
47 #include "G4Material.hh"
48 #include "G4Tubs.hh"
49 #include "G4LogicalVolume.hh"
50 #include "G4PVPlacement.hh"
51 
52 #include "G4SDManager.hh"
53 #include "G4GeometryManager.hh"
54 #include "G4RunManager.hh"
55 #include "G4NistManager.hh"
56 
57 #include "G4Region.hh"
58 #include "G4RegionStore.hh"
59 #include "G4PhysicalVolumeStore.hh"
60 #include "G4LogicalVolumeStore.hh"
61 #include "G4SolidStore.hh"
62 #include "G4ProductionCuts.hh"
63 
64 #include "G4VisAttributes.hh"
65 #include "G4Colour.hh"
66 
67 #include "G4UnitsTable.hh"
68 #include "G4PhysicalConstants.hh"
69 #include "G4SystemOfUnits.hh"
70 #include "G4ios.hh"
71 #include "TestParameters.hh"
72 #include "G4PionPlus.hh"
73 
74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
75 
78  fGasMat(0), fWindowMat(0), fWorldMaterial(0),
79  fSolidWorld(0), fSolidContainer(0), fSolidDetector(0),
80  fPhysWorld(0), fLogicWorld(0), fLogicContainer(0), fLogicDetector(0),
81  fDetectorMessenger(0), fGasDetectorCuts(0), fRegGasDet(0)
82 {
83  fGasThickness = 23.0*mm;
84  fGasRadius = 10.*cm;
85 
86  fWindowThick = 51.0*micrometer;
87 
88  DefineMaterials();
89 
90  fDetectorMessenger = new DetectorMessenger(this);
91 
92  G4double cut = 23.*mm;
93  fGasDetectorCuts = new G4ProductionCuts();
94  fGasDetectorCuts->SetProductionCut(cut,"gamma");
95  fGasDetectorCuts->SetProductionCut(cut,"e-");
96  fGasDetectorCuts->SetProductionCut(cut,"e+");
97  fGasDetectorCuts->SetProductionCut(cut,"proton");
98 }
99 
100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
101 
103 {
104  delete fDetectorMessenger;
105 }
106 
107 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
108 
109 void DetectorConstruction::DefineMaterials()
110 {
111  //This function illustrates the possible ways to define materials
112  G4String name, symbol ;
113  G4double density;
114  G4int nel;
115  G4int ncomponents;
116  G4double fractionmass;
117 
119  //
120  // define Elements
121  //
122  G4Element* elH = manager->FindOrBuildElement(1);
123  G4Element* elC = manager->FindOrBuildElement(6);
124  G4Element* elO = manager->FindOrBuildElement(8);
125  G4Element* elF = manager->FindOrBuildElement(9);
126  G4Element* elNe = manager->FindOrBuildElement(10);
127  G4Element* elXe = manager->FindOrBuildElement(54);
128  //
129  // simple gases at STP conditions
130  //
131  G4Material* Argon = manager->FindOrBuildMaterial("G4_Ar");
132  G4Material* Kr = manager->FindOrBuildMaterial("G4_Kr");
133  G4Material* Xe = manager->FindOrBuildMaterial("G4_Xe");
134  //
135  // gases at STP conditions
136  //
137  G4Material* CarbonDioxide =
138  manager->FindOrBuildMaterial("G4_CARBON_DIOXIDE");
139  G4Material* Mylar = manager->FindOrBuildMaterial("G4_MYLAR");
140  G4Material* Methane= manager->FindOrBuildMaterial("G4_METHANE");
141  G4Material* Propane= manager->FindOrBuildMaterial("G4_PROPANE");
142  G4Material* empty = manager->FindOrBuildMaterial("G4_Galactic");
143 
144  // 93% Kr + 7% CH4, STP
145  density = 3.491*mg/cm3 ;
146  G4Material* Kr7CH4 =
147  new G4Material(name="Kr7CH4" , density,
148  ncomponents=2);
149  Kr7CH4->AddMaterial( Kr, fractionmass = 0.986 ) ;
150  Kr7CH4->AddMaterial( Methane, fractionmass = 0.014 ) ;
151 
152  G4double TRT_Xe_density = 5.485*mg/cm3;
153  G4Material* TRT_Xe =
154  new G4Material(name="TRT_Xe", TRT_Xe_density, nel=1,
155  kStateGas,293.15*kelvin,1.*atmosphere);
156  TRT_Xe->AddElement(elXe,1);
157 
158  G4double TRT_CO2_density = 1.842*mg/cm3;
159  G4Material* TRT_CO2 =
160  new G4Material(name="TRT_CO2", TRT_CO2_density, nel=2,
161  kStateGas,293.15*kelvin,1.*atmosphere);
162  TRT_CO2->AddElement(elC,1);
163  TRT_CO2->AddElement(elO,2);
164 
165  G4double TRT_CF4_density = 3.9*mg/cm3;
166  G4Material* TRT_CF4 =
167  new G4Material(name="TRT_CF4", TRT_CF4_density, nel=2,
168  kStateGas,293.15*kelvin,1.*atmosphere);
169  TRT_CF4->AddElement(elC,1);
170  TRT_CF4->AddElement(elF,4);
171 
172  // ATLAS TRT straw tube gas mixture (20 C, 1 atm)
173  G4double XeCO2CF4_density = 4.76*mg/cm3;
174  G4Material* XeCO2CF4 =
175  new G4Material(name="XeCO2CF4", XeCO2CF4_density,
176  ncomponents=3,
177  kStateGas,293.15*kelvin,1.*atmosphere);
178  XeCO2CF4->AddMaterial(TRT_Xe,0.807);
179  XeCO2CF4->AddMaterial(TRT_CO2,0.039);
180  XeCO2CF4->AddMaterial(TRT_CF4,0.154);
181 
182  // C3H8,20 C, 2 atm
183  density = 3.758*mg/cm3 ;
184  G4Material* C3H8 =
185  new G4Material(name="C3H8",density,nel=2,
186  kStateGas,293.15*kelvin,2.*atmosphere);
187  C3H8->AddElement(elC,3) ;
188  C3H8->AddElement(elH,8) ;
189 
190  // 87.5% Xe + 7.5% CH4 + 5% C3H8, 20 C, 1 atm
191  density = 4.9196*mg/cm3 ;
192  G4Material* XeCH4C3H8 =
193  new G4Material(name="XeCH4C3H8" ,
194  density, ncomponents=3,
196  XeCH4C3H8->AddMaterial( Xe, fractionmass = 0.971 ) ;
197  XeCH4C3H8->AddMaterial( Methane, fractionmass = 0.010 ) ;
198  XeCH4C3H8->AddMaterial( Propane, fractionmass = 0.019 ) ;
199 
200  // 93% Ar + 7% CH4, STP
201  density = 1.709*mg/cm3 ;
202  G4Material* Ar7CH4 =
203  new G4Material(name="Ar7CH4", density, ncomponents=2,
205  Ar7CH4->AddMaterial( Argon, fractionmass = 0.971 ) ;
206  Ar7CH4->AddMaterial( Methane, fractionmass = 0.029 ) ;
207 
208  // 80% Ar + 20% CO2, STP
209  density = 1.8223*mg/cm3 ;
210  G4Material* Ar_80CO2_20 =
211  new G4Material(name="ArCO2" , density, ncomponents=2,
213  Ar_80CO2_20->AddMaterial( Argon, fractionmass = 0.783 ) ;
214  Ar_80CO2_20->AddMaterial( CarbonDioxide, fractionmass = 0.217 ) ;
215 
216  // 80% Xe + 20% CO2, STP
217  density = 5.0818*mg/cm3 ;
218  G4Material* Xe20CO2 =
219  new G4Material(name="Xe20CO2", density, ncomponents=2,
221  Xe20CO2->AddMaterial( Xe, fractionmass = 0.922 ) ;
222  Xe20CO2->AddMaterial( CarbonDioxide, fractionmass = 0.078 ) ;
223 
224  // 80% Kr + 20% CO2, STP
225  density = 3.601*mg/cm3 ;
226  G4Material* Kr20CO2 =
227  new G4Material(name="Kr20CO2", density, ncomponents=2,
229  Kr20CO2->AddMaterial( Kr, fractionmass = 0.89 ) ;
230  Kr20CO2->AddMaterial( CarbonDioxide, fractionmass = 0.11 ) ;
231 
232  // ALICE mixture TPC_Ne-CO2-2
233  density = 0.939*mg/cm3 ;
234  G4Material* NeCO2 =
235  new G4Material(name="TPC_Ne-CO2-2", density, ncomponents=3,
237  NeCO2->AddElement( elNe, fractionmass = 0.8039 ) ;
238  NeCO2->AddElement( elO, fractionmass = 0.1426 ) ;
239  NeCO2->AddElement( elC, fractionmass = 0.0535 ) ;
240 
241  // ALICE TRD mixure 85% Xe + 15% CO2 NTP
242  density = 4.9389*mg/cm3 ;
243  G4Material* Xe15CO2 =
244  new G4Material(name="Xe15CO2", density, ncomponents=2,
246  Xe15CO2->AddMaterial( Xe, fractionmass = 0.944 );
247  Xe15CO2->AddMaterial( CarbonDioxide, fractionmass = 0.056 );
248 
249  fGasMat = XeCH4C3H8;
250  fWindowMat = Mylar;
251  fWorldMaterial = empty;
252 
254 
255 }
256 
257 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
258 
260 {
261  G4double contThick = fWindowThick*2 + fGasThickness;
262  G4double contR = fWindowThick*2 + fGasRadius;
263 
264  G4double worldSizeZ = contThick*1.2;
265  G4double worldSizeR = contR*1.2;
266 
267  TestParameters::GetPointer()->SetPositionZ(-0.55*contThick);
268 
269  // Printout parameters
270  G4cout << "\n The WORLD is made of "
271  << worldSizeZ/mm << "mm of " << fWorldMaterial->GetName() ;
272  G4cout << ", the transverse size (R) of the world is " << worldSizeR/mm
273  << " mm. " << G4endl;
274  G4cout << " The CONTAINER is made of "
275  << fWindowThick/mm << "mm of " << fWindowMat->GetName() << G4endl;
276  G4cout << " The TARGET is made of "
277  << fGasThickness/mm << "mm of " << fGasMat->GetName() ;
278  G4cout << ", the transverse size (R) is " << fGasRadius/mm << " mm. "
279  << G4endl;
280  G4cout << G4endl;
281 
282  // World
283  fSolidWorld =
284  new G4Tubs("World",0.,worldSizeR,worldSizeZ/2.,0.,CLHEP::twopi);
285 
286  fLogicWorld = new G4LogicalVolume(fSolidWorld, fWorldMaterial, "World");
287 
288  fPhysWorld = new G4PVPlacement(0,
289  G4ThreeVector(0.,0.,0.),
290  "World",
291  fLogicWorld,
292  0,
293  false,
294  0);
295 
296  // Window
297  fSolidContainer = new G4Tubs("Absorber",
298  0.,contR,contThick/2.,0.,CLHEP::twopi);
299 
300  fLogicContainer = new G4LogicalVolume(fSolidContainer, fWindowMat, "Window");
301 
302  G4PVPlacement* PhysWind = new G4PVPlacement(0, G4ThreeVector(0.,0.,0.),
303  "Window", fLogicContainer,
304  fPhysWorld, false, 0);
305 
306  // Detector volume
307  fSolidDetector = new G4Tubs("Gas", 0., fGasRadius, fGasThickness/2.,
308  0., CLHEP::twopi);
309 
310  fLogicDetector = new G4LogicalVolume(fSolidDetector, fGasMat, "Gas");
311 
312  new G4PVPlacement(0, G4ThreeVector(0.,0.,0.), "Gas", fLogicDetector,
313  PhysWind, false, 0);
314 
315  // defined gas detector region
316  fRegGasDet = new G4Region("GasDetector");
317  fRegGasDet->SetProductionCuts(fGasDetectorCuts);
318  fRegGasDet->AddRootLogicalVolume(fLogicDetector);
319 
320  // visualisation
322  G4VisAttributes* color1 = new G4VisAttributes(G4Colour(0.3, 0.3, 0.3));
323  fLogicContainer->SetVisAttributes(color1);
324  G4VisAttributes* color2 = new G4VisAttributes(G4Colour(0.0, 0.3, 0.7));
325  fLogicDetector->SetVisAttributes(color2);
326 
327  if(0.0 == fGasMat->GetIonisation()->GetMeanEnergyPerIonPair()) {
328  SetPairEnergy(20*eV);
329  }
330  return fPhysWorld;
331 }
332 
333 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
334 
336 {
337  auto sd = new TargetSD("GasSD");
339  SetSensitiveDetector(fLogicDetector, sd);
340 }
341 
342 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
343 
345 {
346  // get the pointer to the existing material
347  G4Material* mat = G4Material::GetMaterial(name, false);
348 
349  // create the material by its name
350  if(!mat) { mat = G4NistManager::Instance()->FindOrBuildMaterial(name); }
351 
352  if (mat && mat != fGasMat) {
353  G4cout << "### New target material: " << mat->GetName() << G4endl;
354  fGasMat = mat;
355  if(fLogicDetector) {
356  fLogicDetector->SetMaterial(mat);
358  }
359  }
360 }
361 
362 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
363 
365 {
366  // get the pointer to the existing material
367  G4Material* mat = G4Material::GetMaterial(name, false);
368 
369  // create the material by its name
370  if(!mat) { mat = G4NistManager::Instance()->FindOrBuildMaterial(name); }
371 
372  if (mat && mat != fWindowMat) {
373  G4cout << "### New material for container: " << mat->GetName() << G4endl;
374  fWindowMat = mat;
375  if(fLogicContainer) {
376  fLogicContainer->SetMaterial(mat);
378  }
379  }
380 }
381 
382 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
383 
385 {
386  // get the pointer to the existing material
387  G4Material* mat = G4Material::GetMaterial(name, false);
388 
389  // create the material by its name
390  if(!mat) { mat = G4NistManager::Instance()->FindOrBuildMaterial(name); }
391 
392  if (mat && mat != fWorldMaterial) {
393  G4cout << "### New World material: " << mat->GetName() << G4endl;
394  fWorldMaterial = mat;
395  if(fLogicWorld) {
396  fLogicWorld->SetMaterial(mat);
398  }
399  }
400 }
401 
402 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
403 
405 {
406  fGasThickness = val;
407  if(fPhysWorld) { ChangeGeometry(); }
408 }
409 
410 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
411 
413 {
414  fGasRadius = val;
415  if(fPhysWorld) { ChangeGeometry(); }
416 }
417 
418 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
419 
421 {
422  fWindowThick = val;
423  if(fPhysWorld) { ChangeGeometry(); }
424 }
425 
426 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
427 
429 {
430  if(val > 0.0) {
431  fGasMat->GetIonisation()->SetMeanEnergyPerIonPair(val);
432  }
433 }
434 
435 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
436 
437 void DetectorConstruction::ChangeGeometry()
438 {
439  G4double contThick = fWindowThick*2 + fGasThickness;
440  G4double contR = fWindowThick*2 + fGasRadius;
441 
442  G4double worldSizeZ = contThick*1.2;
443  G4double worldSizeR = contR*1.2;
444 
445  TestParameters::GetPointer()->SetPositionZ(-0.55*contThick);
446 
447  fSolidWorld->SetOuterRadius(worldSizeR);
448  fSolidWorld->SetZHalfLength(worldSizeZ*0.5);
449 
450  fSolidContainer->SetOuterRadius(contR);
451  fSolidContainer->SetZHalfLength(contThick*0.5);
452 
453  fSolidDetector->SetOuterRadius(fGasRadius);
454  fSolidDetector->SetZHalfLength(fGasThickness*0.5);
455 
456 }
457 
458 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
const XML_Char * name
Definition: expat.h:151
G4IonisParamMat * GetIonisation() const
Definition: G4Material.hh:226
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
Definition of the TestParameters class.
void SetZHalfLength(G4double dz)
Definition: G4Box.cc:174
static constexpr double mm
Definition: G4SIunits.hh:115
static constexpr double mg
Definition: G4SIunits.hh:184
CLHEP::Hep3Vector G4ThreeVector
void AddRootLogicalVolume(G4LogicalVolume *lv)
Definition: G4Region.cc:290
void AddMaterial(G4Material *material, G4double fraction)
Definition: G4Material.cc:467
static G4Material * GetMaterial(const G4String &name, G4bool warning=true)
Definition: G4Material.cc:602
G4double GetMeanEnergyPerIonPair() const
const G4String & GetName() const
Definition: G4Material.hh:178
G4VPhysicalVolume * Construct()
Definition: G4Tubs.hh:85
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:587
void SetWorldMaterial(const G4String &)
void SetProductionCut(G4double cut, G4int index=-1)
void SetPositionZ(G4double val)
float STP_Temperature
Definition: hepunit.py:302
void SetContainerMaterial(const G4String &)
int G4int
Definition: G4Types.hh:78
static G4NistManager * Instance()
virtual void ConstructSDandField()
void SetContainerThickness(G4double)
G4GLOB_DLL std::ostream G4cout
void PhysicsHasBeenModified()
static constexpr double cm
Definition: G4SIunits.hh:119
static constexpr double eV
Definition: G4SIunits.hh:215
static constexpr double kelvin
Definition: G4SIunits.hh:281
static constexpr double cm3
Definition: G4SIunits.hh:121
void SetSensitiveDetector(const G4String &logVolName, G4VSensitiveDetector *aSD, G4bool multi=false)
void AddNewDetector(G4VSensitiveDetector *aSD)
Definition: G4SDManager.cc:71
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
void SetOuterRadius(G4double newRMax)
void SetGasMaterial(const G4String &)
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
static TestParameters * GetPointer()
static const G4double NTP_Temperature
Definition: G4Material.hh:116
#define G4endl
Definition: G4ios.hh:61
void SetProductionCuts(G4ProductionCuts *cut)
void AddElement(G4Element *element, G4int nAtoms)
Definition: G4Material.cc:362
double G4double
Definition: G4Types.hh:76
G4Element * FindOrBuildElement(G4int Z, G4bool isotopes=true)
void SetMaterial(G4Material *pMaterial)
static constexpr double atmosphere
Definition: G4SIunits.hh:237
static constexpr double micrometer
Definition: G4SIunits.hh:100
static const G4VisAttributes & GetInvisible()
void SetVisAttributes(const G4VisAttributes *pVA)
static constexpr double twopi
Definition: SystemOfUnits.h:55
void SetZHalfLength(G4double newDz)
void SetMeanEnergyPerIonPair(G4double value)
int STP_Pressure
Definition: hepunit.py:303