Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
examples/extended/electromagnetic/TestEm8/src/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 //
26 /// \file electromagnetic/TestEm8/src/DetectorConstruction.cc
27 /// \brief Implementation of the DetectorConstruction class
28 //
29 // $Id: DetectorConstruction.cc 68198 2013-03-18 16:39:51Z maire $
30 //
31 /////////////////////////////////////////////////////////////////////////
32 //
33 // TestEm8: Gaseous detector
34 //
35 // Created: 31.08.2010 V.Ivanchenko ob base of V.Grichine code
36 //
37 // Modified:
38 //
39 ////////////////////////////////////////////////////////////////////////
40 //
41 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
42 
43 #include "DetectorConstruction.hh"
44 #include "DetectorMessenger.hh"
45 #include "TargetSD.hh"
46 #include "PrimaryGeneratorAction.hh"
47 
48 #include "G4Material.hh"
49 #include "G4Tubs.hh"
50 #include "G4LogicalVolume.hh"
51 #include "G4PVPlacement.hh"
52 
53 #include "G4SDManager.hh"
54 #include "G4GeometryManager.hh"
55 #include "G4RunManager.hh"
56 #include "G4NistManager.hh"
57 
58 #include "G4Region.hh"
59 #include "G4RegionStore.hh"
60 #include "G4PhysicalVolumeStore.hh"
61 #include "G4LogicalVolumeStore.hh"
62 #include "G4SolidStore.hh"
63 #include "G4ProductionCuts.hh"
64 
65 #include "G4VisAttributes.hh"
66 #include "G4Colour.hh"
67 
68 #include "G4UnitsTable.hh"
69 #include "G4PhysicalConstants.hh"
70 #include "G4SystemOfUnits.hh"
71 #include "G4ios.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), fTargetSD(0), fGasDetectorCuts(0),
80  fRegGasDet(0), fPrimaryGenerator(p)
81 {
82  fGasThickness = 23.0*mm;
83  fGasRadius = 10.*cm;
84 
85  fWindowThick = 51.0*micrometer;
86 
87  DefineMaterials();
88 
89  fDetectorMessenger = new DetectorMessenger(this);
90 
91  G4double cut = 23.*mm;
92  fGasDetectorCuts = new G4ProductionCuts();
93  fGasDetectorCuts->SetProductionCut(cut,"gamma");
94  fGasDetectorCuts->SetProductionCut(cut,"e-");
95  fGasDetectorCuts->SetProductionCut(cut,"e+");
96  fGasDetectorCuts->SetProductionCut(cut,"proton");
97 }
98 
99 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
100 
102 {
103  delete fDetectorMessenger;
104  delete fGasDetectorCuts;
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 = 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 = new G4Material(name="XeCO2CF4", XeCO2CF4_density,
170  ncomponents=3,
171  kStateGas,293.15*kelvin,1.*atmosphere);
172  XeCO2CF4->AddMaterial(TRT_Xe,0.807);
173  XeCO2CF4->AddMaterial(TRT_CO2,0.039);
174  XeCO2CF4->AddMaterial(TRT_CF4,0.154);
175 
176  // C3H8,20 C, 2 atm
177  density = 3.758*mg/cm3 ;
178  G4Material* C3H8 = new G4Material(name="C3H8",density,nel=2) ;
179  C3H8->AddElement(elC,3) ;
180  C3H8->AddElement(elH,8) ;
181 
182  // 87.5% Xe + 7.5% CH4 + 5% C3H8, 20 C, 1 atm
183  density = 4.9196*mg/cm3 ;
184  G4Material* XeCH4C3H8 = new G4Material(name="XeCH4C3H8" ,
185  density, ncomponents=3);
186  XeCH4C3H8->AddMaterial( Xe, fractionmass = 0.971 ) ;
187  XeCH4C3H8->AddMaterial( Methane, fractionmass = 0.010 ) ;
188  XeCH4C3H8->AddMaterial( Propane, fractionmass = 0.019 ) ;
189 
190  // 93% Ar + 7% CH4, STP
191  density = 1.709*mg/cm3 ;
192  G4Material* Ar7CH4 = new G4Material(name="Ar7CH4", density, ncomponents=2);
193  Ar7CH4->AddMaterial( Argon, fractionmass = 0.971 ) ;
194  Ar7CH4->AddMaterial( Methane, fractionmass = 0.029 ) ;
195 
196  // 80% Ar + 20% CO2, STP
197  density = 1.8223*mg/cm3 ;
198  G4Material* Ar_80CO2_20 = new G4Material(name="ArCO2" , density,
199  ncomponents=2);
200  Ar_80CO2_20->AddMaterial( Argon, fractionmass = 0.783 ) ;
201  Ar_80CO2_20->AddMaterial( CarbonDioxide, fractionmass = 0.217 ) ;
202 
203  // 80% Xe + 20% CO2, STP
204  density = 5.0818*mg/cm3 ;
205  G4Material* Xe20CO2 = new G4Material(name="Xe20CO2", density,
206  ncomponents=2);
207  Xe20CO2->AddMaterial( Xe, fractionmass = 0.922 ) ;
208  Xe20CO2->AddMaterial( CarbonDioxide, fractionmass = 0.078 ) ;
209 
210  // 80% Kr + 20% CO2, STP
211  density = 3.601*mg/cm3 ;
212  G4Material* Kr20CO2 = new G4Material(name="Kr20CO2" , density,
213  ncomponents=2);
214  Kr20CO2->AddMaterial( Kr, fractionmass = 0.89 ) ;
215  Kr20CO2->AddMaterial( CarbonDioxide, fractionmass = 0.11 ) ;
216 
217  // ALICE mixture TPC_Ne-CO2-2
218  density = 0.939*mg/cm3 ;
219  G4Material* NeCO2 = new G4Material(name="TPC_Ne-CO2-2", density,
220  ncomponents=3);
221  NeCO2->AddElement( elNe, fractionmass = 0.8039 ) ;
222  NeCO2->AddElement( elO, fractionmass = 0.1426 ) ;
223  NeCO2->AddElement( elC, fractionmass = 0.0535 ) ;
224 
225  fGasMat = XeCH4C3H8;
226  fWindowMat = Mylar;
227  fWorldMaterial = empty;
228 
230 }
231 
232 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
233 
235 {
236  // Cleanup old geometry
238 
239  if(fRegGasDet) { delete fRegGasDet; }
240  fRegGasDet = new G4Region("GasDetector");
241  fRegGasDet->SetProductionCuts(fGasDetectorCuts);
242 
247 
248  G4double contThick = fWindowThick*2 + fGasThickness;
249  G4double contR = fWindowThick*2 + fGasRadius;
250 
251  G4double worldSizeZ = contThick*1.2;
252  G4double worldSizeR = contR*1.2;
253 
254  fPrimaryGenerator->SetPositionZ(-0.55*contThick);
255 
256  // Printout parameters
257  G4cout << "\n The WORLD is made of "
258  << worldSizeZ/mm << "mm of " << fWorldMaterial->GetName() ;
259  G4cout << ", the transverse size (R) of the world is " << worldSizeR/mm
260  << " mm. " << G4endl;
261  G4cout << " The CONTAINER is made of "
262  << fWindowThick/mm << "mm of " << fWindowMat->GetName() << G4endl;
263  G4cout << " The TARGET is made of "
264  << fGasThickness/mm << "mm of " << fGasMat->GetName() ;
265  G4cout << ", the transverse size (R) is " << fGasRadius/mm << " mm. "
266  << G4endl;
267  G4cout << G4endl;
268 
269  // World
270  G4Tubs* SolidWorld = new G4Tubs("World",
271  0.,worldSizeR,worldSizeZ/2.,0.,CLHEP::twopi);
272 
273  fLogicWorld = new G4LogicalVolume(SolidWorld, fWorldMaterial, "World");
274 
275  fPhysWorld = new G4PVPlacement(0, //no rotation
276  G4ThreeVector(0.,0.,0.),
277  "World",
278  fLogicWorld,
279  0, //its mother volume
280  false, //no boolean operation
281  0); //copy number
282 
283  // Window
284  G4Tubs* wind = new G4Tubs("Absorber",
285  0.,contR,contThick/2.,0.,CLHEP::twopi);
286 
287  fLogicWind = new G4LogicalVolume(wind, fWindowMat, "Window");
288 
289  G4PVPlacement* PhysWind = new G4PVPlacement(0, G4ThreeVector(0.,0.,0.),
290  "Window", fLogicWind,
291  fPhysWorld, false, 0);
292 
293  // Detector volume
294  G4Tubs* det = new G4Tubs("Gas", 0., fGasRadius, fGasThickness/2.,
295  0., CLHEP::twopi);
296 
297  fLogicDet = new G4LogicalVolume(det, fGasMat, "Gas");
298 
299  new G4PVPlacement(0, G4ThreeVector(0.,0.,0.), "Gas", fLogicDet, PhysWind,
300  false, 0);
301 
302  fRegGasDet->AddRootLogicalVolume(fLogicDet);
303 
304  // Sensitive Detectors:
306  if(!fTargetSD)
307  {
308  fTargetSD = new TargetSD("GasSD");
309  SDman->AddNewDetector( fTargetSD );
310  }
311  fLogicDet->SetSensitiveDetector(fTargetSD);
312 
313  // visualisation
315  G4VisAttributes* color1 = new G4VisAttributes(G4Colour(0.3, 0.3, 0.3));
316  fLogicWind->SetVisAttributes(color1);
317  G4VisAttributes* color2 = new G4VisAttributes(G4Colour(0.0, 0.3, 0.7));
318  fLogicDet->SetVisAttributes(color2);
319 
320  if(0.0 == fGasMat->GetIonisation()->GetMeanEnergyPerIonPair()) {
321  SetPairEnergy(20*eV);
322  }
323  return fPhysWorld;
324 }
325 
326 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
327 
329 {
330  // get the pointer to the existing material
331  G4Material* mat = G4Material::GetMaterial(name, false);
332 
333  // create the material by its name
334  if(!mat) { mat = G4NistManager::Instance()->FindOrBuildMaterial(name); }
335 
336  if (mat && mat != fGasMat) {
337  G4cout << "### New target material: " << mat->GetName() << G4endl;
338  fGasMat = mat;
339  if(fLogicDet) {
340  fLogicDet->SetMaterial(mat);
342  }
343  }
344 }
345 
346 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
347 
349 {
350  // get the pointer to the existing material
351  G4Material* mat = G4Material::GetMaterial(name, false);
352 
353  // create the material by its name
354  if(!mat) { mat = G4NistManager::Instance()->FindOrBuildMaterial(name); }
355 
356  if (mat && mat != fWindowMat) {
357  G4cout << "### New material for container: " << mat->GetName() << G4endl;
358  fWindowMat = mat;
359  if(fLogicWind) {
360  fLogicWind->SetMaterial(mat);
362  }
363  }
364 }
365 
366 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
367 
369 {
370  // get the pointer to the existing material
371  G4Material* mat = G4Material::GetMaterial(name, false);
372 
373  // create the material by its name
374  if(!mat) { mat = G4NistManager::Instance()->FindOrBuildMaterial(name); }
375 
376  if (mat && mat != fWorldMaterial) {
377  G4cout << "### New World material: " << mat->GetName() << G4endl;
378  fWorldMaterial = mat;
379  if(fLogicWorld) {
380  fLogicWorld->SetMaterial(mat);
382  }
383  }
384 }
385 
386 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
387 
389 {
390  if(fGasThickness != val) {
392  fGasThickness = val;
393  }
394 }
395 
396 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
397 
399 {
400  if(fGasRadius != val) {
402  fGasRadius = val;
403  }
404 }
405 
406 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
407 
409 {
410  if(fWindowThick != val) {
412  fWindowThick = val;
413  }
414 }
415 
416 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
417 
419 {
420  if(val > 0.0) {
421  fGasMat->GetIonisation()->SetMeanEnergyPerIonPair(val);
422  }
423 }
424 
425 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void GeometryHasBeenModified(G4bool prop=true)
G4IonisParamMat * GetIonisation() const
Definition: G4Material.hh:224
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:450
static G4Material * GetMaterial(const G4String &name, G4bool warning=true)
Definition: G4Material.cc:578
G4double GetMeanEnergyPerIonPair() const
const char * p
Definition: xmltok.h:285
const G4String & GetName() const
Definition: G4Material.hh:176
Definition: G4Tubs.hh:84
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:564
G4Element * elC
Definition: TRTMaterials.hh:48
int atmosphere
Definition: hepunit.py:151
static void Clean()
Definition: G4SolidStore.cc:79
G4Element * elF
Definition: TRTMaterials.hh:54
const XML_Char * name
void SetProductionCut(G4double cut, G4int index=-1)
G4Material * XeCO2CF4
int G4int
Definition: G4Types.hh:78
static G4NistManager * Instance()
G4Element * elH
Definition: TRTMaterials.hh:50
static G4PhysicalVolumeStore * GetInstance()
G4double density
Definition: TRTMaterials.hh:39
G4GLOB_DLL std::ostream G4cout
G4Element * elO
Definition: TRTMaterials.hh:46
void PhysicsHasBeenModified()
G4Material * TRT_CO2
Definition: TRTMaterials.hh:92
static G4LogicalVolumeStore * GetInstance()
static G4SolidStore * GetInstance()
G4double TRT_CF4_density
Definition: TRTMaterials.hh:97
static G4GeometryManager * GetInstance()
void AddNewDetector(G4VSensitiveDetector *aSD)
Definition: G4SDManager.cc:67
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
G4Material * TRT_CF4
Definition: TRTMaterials.hh:98
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
G4Element * elXe
Definition: TRTMaterials.hh:52
G4double XeCO2CF4_density
static const G4VisAttributes Invisible
G4double TRT_CO2_density
Definition: TRTMaterials.hh:91
#define G4endl
Definition: G4ios.hh:61
void SetProductionCuts(G4ProductionCuts *cut)
void OpenGeometry(G4VPhysicalVolume *vol=0)
void AddElement(G4Element *element, G4int nAtoms)
Definition: G4Material.cc:345
double G4double
Definition: G4Types.hh:76
G4Element * FindOrBuildElement(G4int Z, G4bool isotopes=true)
void SetMaterial(G4Material *pMaterial)
int micrometer
Definition: hepunit.py:34
void SetVisAttributes(const G4VisAttributes *pVA)
void SetSensitiveDetector(G4VSensitiveDetector *pSDetector)
G4int nel
Definition: TRTMaterials.hh:41
void SetMeanEnergyPerIonPair(G4double value)