Geant4  10.01.p03
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 89039 2015-03-18 09:28:24Z gcosmo $
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 
73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
74 
77  fGasMat(0), fWindowMat(0), fWorldMaterial(0),
78  fPhysWorld(0), fLogicWorld(0), fLogicWind(0), fLogicDet(0),
79  fDetectorMessenger(0), fGasDetectorCuts(0), fRegGasDet(0)
80 {
81  fGasThickness = 23.0*mm;
82  fGasRadius = 10.*cm;
83 
84  fWindowThick = 51.0*micrometer;
85 
87 
89 
90  G4double cut = 23.*mm;
92  fGasDetectorCuts->SetProductionCut(cut,"gamma");
95  fGasDetectorCuts->SetProductionCut(cut,"proton");
96 }
97 
98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
99 
101 {
102  delete fDetectorMessenger;
103  //delete fGasDetectorCuts;
104 }
105 
106 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
107 
109 {
110  //This function illustrates the possible ways to define materials
111  G4String name, symbol ;
112  G4double density;
113  G4int nel;
114  G4int ncomponents;
115  G4double fractionmass;
116 
118  //
119  // define Elements
120  //
121  G4Element* elH = manager->FindOrBuildElement(1);
122  G4Element* elC = manager->FindOrBuildElement(6);
123  G4Element* elO = manager->FindOrBuildElement(8);
124  G4Element* elF = manager->FindOrBuildElement(9);
125  G4Element* elNe = manager->FindOrBuildElement(10);
126  G4Element* elXe = manager->FindOrBuildElement(54);
127  //
128  // simple gases at STP conditions
129  //
130  G4Material* Argon = manager->FindOrBuildMaterial("G4_Ar");
131  G4Material* Kr = manager->FindOrBuildMaterial("G4_Kr");
132  G4Material* Xe = manager->FindOrBuildMaterial("G4_Xe");
133  //
134  // gases at STP conditions
135  //
136  G4Material* CarbonDioxide =
137  manager->FindOrBuildMaterial("G4_CARBON_DIOXIDE");
138  G4Material* Mylar = manager->FindOrBuildMaterial("G4_MYLAR");
139  G4Material* Methane= manager->FindOrBuildMaterial("G4_METHANE");
140  G4Material* Propane= manager->FindOrBuildMaterial("G4_PROPANE");
141  G4Material* empty = manager->FindOrBuildMaterial("G4_Galactic");
142 
143  // 93% Kr + 7% CH4, STP
144  density = 3.491*mg/cm3 ;
145  G4Material* Kr7CH4 = new G4Material(name="Kr7CH4" , density,
146  ncomponents=2);
147  Kr7CH4->AddMaterial( Kr, fractionmass = 0.986 ) ;
148  Kr7CH4->AddMaterial( Methane, fractionmass = 0.014 ) ;
149 
150  G4double TRT_Xe_density = 5.485*mg/cm3;
151  G4Material* TRT_Xe = new G4Material(name="TRT_Xe", TRT_Xe_density, nel=1,
152  kStateGas,293.15*kelvin,1.*atmosphere);
153  TRT_Xe->AddElement(elXe,1);
154 
155  G4double TRT_CO2_density = 1.842*mg/cm3;
156  G4Material* TRT_CO2 = new G4Material(name="TRT_CO2", TRT_CO2_density, nel=2,
157  kStateGas,293.15*kelvin,1.*atmosphere);
158  TRT_CO2->AddElement(elC,1);
159  TRT_CO2->AddElement(elO,2);
160 
162  G4Material* TRT_CF4 = new G4Material(name="TRT_CF4", TRT_CF4_density, nel=2,
163  kStateGas,293.15*kelvin,1.*atmosphere);
164  TRT_CF4->AddElement(elC,1);
165  TRT_CF4->AddElement(elF,4);
166 
167  // ATLAS TRT straw tube gas mixture (20 C, 1 atm)
169  G4Material* XeCO2CF4 =
170  new G4Material(name="XeCO2CF4", XeCO2CF4_density,
171  ncomponents=3,
172  kStateGas,293.15*kelvin,1.*atmosphere);
173  XeCO2CF4->AddMaterial(TRT_Xe,0.807);
174  XeCO2CF4->AddMaterial(TRT_CO2,0.039);
175  XeCO2CF4->AddMaterial(TRT_CF4,0.154);
176 
177  // C3H8,20 C, 2 atm
178  density = 3.758*mg/cm3 ;
179  G4Material* C3H8 = new G4Material(name="C3H8",density,nel=2) ;
180  C3H8->AddElement(elC,3) ;
181  C3H8->AddElement(elH,8) ;
182 
183  // 87.5% Xe + 7.5% CH4 + 5% C3H8, 20 C, 1 atm
184  density = 4.9196*mg/cm3 ;
185  G4Material* XeCH4C3H8 = new G4Material(name="XeCH4C3H8" ,
186  density, ncomponents=3);
187  XeCH4C3H8->AddMaterial( Xe, fractionmass = 0.971 ) ;
188  XeCH4C3H8->AddMaterial( Methane, fractionmass = 0.010 ) ;
189  XeCH4C3H8->AddMaterial( Propane, fractionmass = 0.019 ) ;
190 
191  // 93% Ar + 7% CH4, STP
192  density = 1.709*mg/cm3 ;
193  G4Material* Ar7CH4 = new G4Material(name="Ar7CH4", density, ncomponents=2);
194  Ar7CH4->AddMaterial( Argon, fractionmass = 0.971 ) ;
195  Ar7CH4->AddMaterial( Methane, fractionmass = 0.029 ) ;
196 
197  // 80% Ar + 20% CO2, STP
198  density = 1.8223*mg/cm3 ;
199  G4Material* Ar_80CO2_20 = new G4Material(name="ArCO2" , density,
200  ncomponents=2);
201  Ar_80CO2_20->AddMaterial( Argon, fractionmass = 0.783 ) ;
202  Ar_80CO2_20->AddMaterial( CarbonDioxide, fractionmass = 0.217 ) ;
203 
204  // 80% Xe + 20% CO2, STP
205  density = 5.0818*mg/cm3 ;
206  G4Material* Xe20CO2 = new G4Material(name="Xe20CO2", density,
207  ncomponents=2);
208  Xe20CO2->AddMaterial( Xe, fractionmass = 0.922 ) ;
209  Xe20CO2->AddMaterial( CarbonDioxide, fractionmass = 0.078 ) ;
210 
211  // 80% Kr + 20% CO2, STP
212  density = 3.601*mg/cm3 ;
213  G4Material* Kr20CO2 = new G4Material(name="Kr20CO2" , density,
214  ncomponents=2);
215  Kr20CO2->AddMaterial( Kr, fractionmass = 0.89 ) ;
216  Kr20CO2->AddMaterial( CarbonDioxide, fractionmass = 0.11 ) ;
217 
218  // ALICE mixture TPC_Ne-CO2-2
219  density = 0.939*mg/cm3 ;
220  G4Material* NeCO2 = new G4Material(name="TPC_Ne-CO2-2", density,
221  ncomponents=3);
222  NeCO2->AddElement( elNe, fractionmass = 0.8039 ) ;
223  NeCO2->AddElement( elO, fractionmass = 0.1426 ) ;
224  NeCO2->AddElement( elC, fractionmass = 0.0535 ) ;
225 
226  fGasMat = XeCH4C3H8;
227  fWindowMat = Mylar;
228  fWorldMaterial = empty;
229 
231 }
232 
233 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
234 
236 {
237  G4double contThick = fWindowThick*2 + fGasThickness;
238  G4double contR = fWindowThick*2 + fGasRadius;
239 
240  G4double worldSizeZ = contThick*1.2;
241  G4double worldSizeR = contR*1.2;
242 
243  TestParameters::GetPointer()->SetPositionZ(-0.55*contThick);
244 
245  // Printout parameters
246  G4cout << "\n The WORLD is made of "
247  << worldSizeZ/mm << "mm of " << fWorldMaterial->GetName() ;
248  G4cout << ", the transverse size (R) of the world is " << worldSizeR/mm
249  << " mm. " << G4endl;
250  G4cout << " The CONTAINER is made of "
251  << fWindowThick/mm << "mm of " << fWindowMat->GetName() << G4endl;
252  G4cout << " The TARGET is made of "
253  << fGasThickness/mm << "mm of " << fGasMat->GetName() ;
254  G4cout << ", the transverse size (R) is " << fGasRadius/mm << " mm. "
255  << G4endl;
256  G4cout << G4endl;
257 
258  // World
259  G4Tubs* SolidWorld =
260  new G4Tubs("World",0.,worldSizeR,worldSizeZ/2.,0.,CLHEP::twopi);
261 
262  fLogicWorld = new G4LogicalVolume(SolidWorld, fWorldMaterial, "World");
263 
264  fPhysWorld = new G4PVPlacement(0,
265  G4ThreeVector(0.,0.,0.),
266  "World",
267  fLogicWorld,
268  0,
269  false,
270  0);
271 
272  // Window
273  G4Tubs* wind = new G4Tubs("Absorber",
274  0.,contR,contThick/2.,0.,CLHEP::twopi);
275 
276  fLogicWind = new G4LogicalVolume(wind, fWindowMat, "Window");
277 
278  G4PVPlacement* PhysWind = new G4PVPlacement(0, G4ThreeVector(0.,0.,0.),
279  "Window", fLogicWind,
280  fPhysWorld, false, 0);
281 
282  // Detector volume
283  G4Tubs* det = new G4Tubs("Gas", 0., fGasRadius, fGasThickness/2.,
284  0., CLHEP::twopi);
285 
286  fLogicDet = new G4LogicalVolume(det, fGasMat, "Gas");
287 
288  new G4PVPlacement(0, G4ThreeVector(0.,0.,0.), "Gas", fLogicDet, PhysWind,
289  false, 0);
290 
291  // defined gas detector region
292  fRegGasDet = new G4Region("GasDetector");
295 
296  // visualisation
298  G4VisAttributes* color1 = new G4VisAttributes(G4Colour(0.3, 0.3, 0.3));
299  fLogicWind->SetVisAttributes(color1);
300  G4VisAttributes* color2 = new G4VisAttributes(G4Colour(0.0, 0.3, 0.7));
301  fLogicDet->SetVisAttributes(color2);
302 
304  SetPairEnergy(20*eV);
305  }
306  return fPhysWorld;
307 }
308 
309 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
310 
312 {
313  SetSensitiveDetector(fLogicDet, new TargetSD("GasSD"));
314 }
315 
316 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
317 
319 {
320  // get the pointer to the existing material
321  G4Material* mat = G4Material::GetMaterial(name, false);
322 
323  // create the material by its name
324  if(!mat) { mat = G4NistManager::Instance()->FindOrBuildMaterial(name); }
325 
326  if (mat && mat != fGasMat) {
327  G4cout << "### New target material: " << mat->GetName() << G4endl;
328  fGasMat = mat;
329  if(fLogicDet) {
330  fLogicDet->SetMaterial(mat);
332  }
333  }
334 }
335 
336 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
337 
339 {
340  // get the pointer to the existing material
341  G4Material* mat = G4Material::GetMaterial(name, false);
342 
343  // create the material by its name
344  if(!mat) { mat = G4NistManager::Instance()->FindOrBuildMaterial(name); }
345 
346  if (mat && mat != fWindowMat) {
347  G4cout << "### New material for container: " << mat->GetName() << G4endl;
348  fWindowMat = mat;
349  if(fLogicWind) {
350  fLogicWind->SetMaterial(mat);
352  }
353  }
354 }
355 
356 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
357 
359 {
360  // get the pointer to the existing material
361  G4Material* mat = G4Material::GetMaterial(name, false);
362 
363  // create the material by its name
364  if(!mat) { mat = G4NistManager::Instance()->FindOrBuildMaterial(name); }
365 
366  if (mat && mat != fWorldMaterial) {
367  G4cout << "### New World material: " << mat->GetName() << G4endl;
368  fWorldMaterial = mat;
369  if(fLogicWorld) {
370  fLogicWorld->SetMaterial(mat);
372  }
373  }
374 }
375 
376 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
377 
379 {
380  if(fPhysWorld) {
381  G4Exception ("DetectorConstruction::SetGasThickness()", "test005",
382  JustWarning,
383  "Attempt to change already constructed geometry is ignored");
384  } else {
385  fGasThickness = val;
386  }
387 }
388 
389 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
390 
392 {
393  if(fPhysWorld) {
394  G4Exception ("DetectorConstruction::SetGasRadius()", "test005",
395  JustWarning,
396  "Attempt to change already constructed geometry is ignored");
397  } else {
398  fGasRadius = val;
399  }
400 }
401 
402 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
403 
405 {
406  if(fPhysWorld) {
407  G4Exception ("DetectorConstruction::SetContainerThickness()", "test005",
408  JustWarning,
409  "Attempt to change already constructed geometry is ignored");
410  } else {
411  fWindowThick = val;
412  }
413 }
414 
415 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
416 
418 {
419  if(val > 0.0) {
421  }
422 }
423 
424 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
static const double cm
Definition: G4SIunits.hh:106
G4IonisParamMat * GetIonisation() const
Definition: G4Material.hh:226
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
G4double TRT_Xe_density
Definition: TRTMaterials.hh:86
G4String symbol
Definition: TRTMaterials.hh:40
G4Material * TRT_Xe
Definition: TRTMaterials.hh:87
CLHEP::Hep3Vector G4ThreeVector
void AddRootLogicalVolume(G4LogicalVolume *lv)
Definition: G4Region.cc:254
void AddMaterial(G4Material *material, G4double fraction)
Definition: G4Material.cc:469
static G4Material * GetMaterial(const G4String &name, G4bool warning=true)
Definition: G4Material.cc:603
G4double GetMeanEnergyPerIonPair() const
G4String name
Definition: TRTMaterials.hh:40
const G4String & GetName() const
Definition: G4Material.hh:178
G4VPhysicalVolume * Construct()
Definition: G4Tubs.hh:85
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:588
G4Element * elC
Definition: TRTMaterials.hh:48
void SetWorldMaterial(const G4String &)
G4Element * elF
Definition: TRTMaterials.hh:54
void SetProductionCut(G4double cut, G4int index=-1)
void SetPositionZ(G4double val)
static const double mg
Definition: G4SIunits.hh:163
G4Material * XeCO2CF4
void SetContainerMaterial(const G4String &)
int G4int
Definition: G4Types.hh:78
static G4NistManager * Instance()
G4Element * elH
Definition: TRTMaterials.hh:50
G4ProductionCuts * fGasDetectorCuts
G4double density
Definition: TRTMaterials.hh:39
virtual void ConstructSDandField()
void SetContainerThickness(G4double)
G4LogicalVolume * fLogicDet
G4GLOB_DLL std::ostream G4cout
G4Element * elO
Definition: TRTMaterials.hh:46
G4LogicalVolume * fLogicWorld
void PhysicsHasBeenModified()
G4Material * TRT_CO2
Definition: TRTMaterials.hh:92
G4VPhysicalVolume * fPhysWorld
static const double cm3
Definition: G4SIunits.hh:108
G4double TRT_CF4_density
Definition: TRTMaterials.hh:97
void SetSensitiveDetector(const G4String &logVolName, G4VSensitiveDetector *aSD, G4bool multi=false)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static const double kelvin
Definition: G4SIunits.hh:260
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
static const double micrometer
Definition: G4SIunits.hh:90
static const double eV
Definition: G4SIunits.hh:194
void SetGasMaterial(const G4String &)
G4Material * TRT_CF4
Definition: TRTMaterials.hh:98
G4Element * elXe
Definition: TRTMaterials.hh:52
G4double XeCO2CF4_density
G4LogicalVolume * fLogicWind
static const G4VisAttributes Invisible
static const double atmosphere
Definition: G4SIunits.hh:216
G4double TRT_CO2_density
Definition: TRTMaterials.hh:91
static TestParameters * GetPointer()
#define G4endl
Definition: G4ios.hh:61
void SetProductionCuts(G4ProductionCuts *cut)
void AddElement(G4Element *element, G4int nAtoms)
Definition: G4Material.cc:364
double G4double
Definition: G4Types.hh:76
G4Element * FindOrBuildElement(G4int Z, G4bool isotopes=true)
void SetMaterial(G4Material *pMaterial)
static const double mm
Definition: G4SIunits.hh:102
Messenger class that defines commands for DetectorConstruction.
void SetVisAttributes(const G4VisAttributes *pVA)
G4int nel
Definition: TRTMaterials.hh:41
void SetMeanEnergyPerIonPair(G4double value)
DetectorMessenger * fDetectorMessenger