source: trunk/examples/extended/electromagnetic/TestEm8/src/Em8DetectorConstruction.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: 17.1 KB
RevLine 
[807]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//
[1337]27// $Id: Em8DetectorConstruction.cc,v 1.23 2010/06/04 17:08:15 vnivanch Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-01 $
[807]29//
30//
31
32#include "Em8DetectorConstruction.hh"
33#include "Em8DetectorMessenger.hh"
34#include "Em8CalorimeterSD.hh"
35
36
37#include "G4Material.hh"
38#include "G4Tubs.hh"
39#include "G4LogicalVolume.hh"
40#include "G4PVPlacement.hh"
41
42#include "G4FieldManager.hh"
43#include "G4TransportationManager.hh"
44#include "G4SDManager.hh"
45#include "G4GeometryManager.hh"
46#include "G4RunManager.hh"
47
48#include "G4Region.hh"
49#include "G4RegionStore.hh"
50#include "G4PhysicalVolumeStore.hh"
51#include "G4LogicalVolumeStore.hh"
52#include "G4SolidStore.hh"
53#include "G4ProductionCuts.hh"
54
55#include "G4VisAttributes.hh"
56#include "G4Colour.hh"
57
58#include "G4UnitsTable.hh"
59#include "G4ios.hh"
60
61/////////////////////////////////////////////////////////////////////////////
62//
63//
64
65Em8DetectorConstruction::Em8DetectorConstruction()
66:
67fWorldChanged(false),
68fWorldMaterial(NULL),fSolidWorld(NULL),fLogicWorld(NULL),fPhysicsWorld(NULL),
69fAbsorberMaterial(NULL),fSolidAbsorber(NULL),fLogicAbsorber(NULL),
70fPhysicsAbsorber(NULL),fDetectorMessenger(NULL),
71fCalorimeterSD(NULL),fRegGasDet(NULL)
72{
73  fDelta = 0.0001*mm;
74
75  fAbsorberThickness = 23.0*mm;
76
77  fAbsorberRadius    = 10.*cm;
78  fAbsorberZ         = 0.*cm ;
79
80  fWindowThick       = 51.0*micrometer ;
81
82  fGammaCut    = 23*mm; 
83  fElectronCut = 23*mm; 
84  fPositronCut = 23*mm; 
85
86  fDetectorMessenger = new Em8DetectorMessenger(this);
87}
88
89//////////////////////////////////////////////////////////////////////////
90//
91//
92
93Em8DetectorConstruction::~Em8DetectorConstruction()
94{ 
95  delete fDetectorMessenger;
96}
97
98//////////////////////////////////////////////////////////////////////////
99//
100//
101
102G4VPhysicalVolume* Em8DetectorConstruction::Construct()
103{
104  DefineMaterials();
105  return ConstructCalorimeter();
106}
107
108//////////////////////////////////////////////////////////////////////////////
109//
110//
111
112void Em8DetectorConstruction::DefineMaterials()
113{ 
114 //This function illustrates the possible ways to define materials
115 
116  G4String name, symbol ;             //a=mass of a mole;
117  G4double a, z, density ;            //z=mean number of protons; 
118
119  G4int nel ;                       //iz=number of protons  in an isotope;
120                                   // n=number of nucleons in an isotope;
121
122  G4int ncomponents; 
123  G4double fractionmass;
124
125  //
126  // define Elements
127  //
128
129  a = 1.01*g/mole;
130  G4Element* elH  = new G4Element(name="Hydrogen",symbol="H" , z= 1., a);
131
132  a = 12.01*g/mole;
133  G4Element* elC = new G4Element(name="Carbon", symbol="C", z=6., a);
134
135  a = 14.01*g/mole;
136  G4Element* elN  = new G4Element(name="Nitrogen",symbol="N" , z= 7., a);
137
138  a = 16.00*g/mole;
139  G4Element* elO  = new G4Element(name="Oxygen"  ,symbol="O" , z= 8., a);
140
141  a = 39.948*g/mole;
142  G4Element* elAr = new G4Element(name="Argon", symbol="Ar", z=18., a);
143
144  //
145  // define simple materials
146  //
147
148  // Aluminium
149  a = 26.98*g/mole;
150  density = 2.7*g/cm3;
[1337]151  new G4Material(name="Aluminium", z=13., a, density);
[807]152
153  // Mylar
154  density = 1.39*g/cm3;
155  G4Material* Mylar = new G4Material(name="Mylar", density, nel=3);
156  Mylar->AddElement(elO,2);
157  Mylar->AddElement(elC,5);
158  Mylar->AddElement(elH,4);
159
160  // Silicon as detector material
161  density = 2.330*g/cm3;
162  a = 28.09*g/mole;
[1337]163  new G4Material(name="Silicon", z=14., a, density);
[807]164
165  // Krypton as detector gas, STP
166  density = 3.700*mg/cm3 ;
167  a = 83.80*g/mole ;
168  G4Material* Kr  = new G4Material(name="Kr",z=36., a, density );
169
170
171  // Dry air (average composition)
172  density = 1.7836*mg/cm3 ;       // STP
173  G4Material* Argon = new G4Material(name="Argon"  , density, ncomponents=1);
174  Argon->AddElement(elAr, 1);
175
176  density = 1.25053*mg/cm3 ;       // STP
177  G4Material* Nitrogen = new G4Material(name="N2"  , density, ncomponents=1);
178  Nitrogen->AddElement(elN, 2);
179
180  density = 1.4289*mg/cm3 ;       // STP
181  G4Material* Oxygen = new G4Material(name="O2"  , density, ncomponents=1);
182  Oxygen->AddElement(elO, 2);
183
184  density = 1.2928*mg/cm3 ;       // STP
185  G4Material* Air = new G4Material(name="Air"  , density, ncomponents=3);
186  Air->AddMaterial( Nitrogen, fractionmass = 0.7557 ) ;
187  Air->AddMaterial( Oxygen,   fractionmass = 0.2315 ) ;
188  Air->AddMaterial( Argon,    fractionmass = 0.0128 ) ;
189
190  /* **************
191
192  // 93% Kr + 7% CH4, STP
193  density = 3.491*mg/cm3 ;     
194  G4Material* Kr7CH4 = new G4Material(name="Kr7CH4"  , density,
195                                      ncomponents=2);
196  Kr7CH4->AddMaterial( Kr,       fractionmass = 0.986 ) ;
197  Kr7CH4->AddMaterial( metane,   fractionmass = 0.014 ) ;
198
199  G4double TRT_Xe_density = 5.485*mg/cm3;
200  G4Material* TRT_Xe = new G4Material(name="TRT_Xe", TRT_Xe_density, nel=1,
201                                      kStateGas,293.15*kelvin,1.*atmosphere);
202  TRT_Xe->AddElement(elXe,1);
203
204  G4double TRT_CO2_density = 1.842*mg/cm3;
205  G4Material* TRT_CO2 = new G4Material(name="TRT_CO2", TRT_CO2_density, nel=2,
206                                       kStateGas,293.15*kelvin,1.*atmosphere);
207  TRT_CO2->AddElement(elC,1);
208  TRT_CO2->AddElement(elO,2);
209
210  G4double TRT_CF4_density = 3.9*mg/cm3;
211  G4Material* TRT_CF4 = new G4Material(name="TRT_CF4", TRT_CF4_density, nel=2,
212                                       kStateGas,293.15*kelvin,1.*atmosphere);
213  TRT_CF4->AddElement(elC,1);
214  TRT_CF4->AddElement(elF,4);
215
216  // ATLAS TRT straw tube gas mixture (20 C, 1 atm)
217
218  G4double XeCO2CF4_density = 4.76*mg/cm3;
219  G4Material* XeCO2CF4 = new G4Material(name="XeCO2CF4", XeCO2CF4_density,
220                                        ncomponents=3,
221                                        kStateGas,293.15*kelvin,1.*atmosphere);
222  XeCO2CF4->AddMaterial(TRT_Xe,0.807);
223  XeCO2CF4->AddMaterial(TRT_CO2,0.039);
224  XeCO2CF4->AddMaterial(TRT_CF4,0.154);
225
226  *********** */
227
228  // Xenon as detector gas, STP
229  density = 5.858*mg/cm3 ;
230  a = 131.29*g/mole ;
231  G4Material* Xe  = new G4Material(name="Xenon",z=54., a, density );
232
233  // Metane, STP
234  density = 0.7174*mg/cm3 ;
235  G4Material* metane = new G4Material(name="CH4",density,nel=2) ;
236  metane->AddElement(elC,1) ;
237  metane->AddElement(elH,4) ;
238
239  // C3H8,20 C, 2 atm
240  density = 3.758*mg/cm3 ;
241  G4Material* C3H8 = new G4Material(name="C3H8",density,nel=2) ;
242  C3H8->AddElement(elC,3) ;
243  C3H8->AddElement(elH,8) ;
244
245  // Propane, STP
246  density = 2.005*mg/cm3 ;
247  G4Material* propane = new G4Material(name="propane",density,nel=2) ;
248  propane->AddElement(elC,3) ;
249  propane->AddElement(elH,8) ;
250
251  // 87.5% Xe + 7.5% CH4 + 5% C3H8, 20 C, 1 atm
252  density = 4.9196*mg/cm3 ;
253  G4Material* XeCH4C3H8 = new G4Material(name="XeCH4C3H8"  , 
254                                  density,  ncomponents=3);
255  XeCH4C3H8->AddMaterial( Xe,       fractionmass = 0.971 ) ;
256  XeCH4C3H8->AddMaterial( metane,   fractionmass = 0.010 ) ;
257  XeCH4C3H8->AddMaterial( propane,  fractionmass = 0.019 ) ;
258
259  // 93% Ar + 7% CH4, STP
260  density = 1.709*mg/cm3 ;     
261  G4Material* Ar7CH4 = new G4Material(name="Ar7CH4", density, ncomponents=2);
262  Ar7CH4->AddMaterial( Argon,    fractionmass = 0.971 ) ;
263  Ar7CH4->AddMaterial( metane,   fractionmass = 0.029 ) ;
264
265  // Carbon dioxide, STP
266  density = 1.977*mg/cm3;
267  G4Material* CarbonDioxide = new G4Material(name="CO2", density, nel=2);
268  CarbonDioxide->AddElement(elC,1);
269  CarbonDioxide->AddElement(elO,2);
270
271  // 80% Ar + 20% CO2, STP
272  density = 1.8223*mg/cm3 ;     
273  G4Material* Ar_80CO2_20 = new G4Material(name="ArCO2"  , density, 
274                                           ncomponents=2);
275  Ar_80CO2_20->AddMaterial( Argon,           fractionmass = 0.783 ) ;
276  Ar_80CO2_20->AddMaterial( CarbonDioxide,   fractionmass = 0.217 ) ;
277
278  // 80% Xe + 20% CO2, STP
279  density = 5.0818*mg/cm3 ;     
280  G4Material* Xe20CO2 = new G4Material(name="Xe20CO2", density, 
281                                       ncomponents=2);
282  Xe20CO2->AddMaterial( Xe,              fractionmass = 0.922 ) ;
283  Xe20CO2->AddMaterial( CarbonDioxide,   fractionmass = 0.078 ) ;
284
285  // 80% Kr + 20% CO2, STP
286  density = 3.601*mg/cm3 ;     
287  G4Material* Kr20CO2 = new G4Material(name="Kr20CO2"  , density, 
288                                        ncomponents=2);
289  Kr20CO2->AddMaterial( Kr,              fractionmass = 0.89 ) ;
290  Kr20CO2->AddMaterial( CarbonDioxide,   fractionmass = 0.11 ) ;
291
292  // G4cout << *(G4Material::GetMaterialTable()) << G4endl;
293 
294  // fWindowMat = Mylar ;
295 
296  fAbsorberMaterial = XeCH4C3H8;
297  // Al; // Si; // Xe; // Ar7CH4; // C3H8; // XeCH4C3H8;
298
299  fWorldMaterial    = Mylar; // Air ;
300}
301
302/////////////////////////////////////////////////////////////////////////
303//
304//
305 
306G4VPhysicalVolume* Em8DetectorConstruction::ConstructCalorimeter()
307{
308  // Cleanup old geometry
309
310  G4GeometryManager::GetInstance()->OpenGeometry();
311  G4PhysicalVolumeStore::GetInstance()->Clean();
312  G4LogicalVolumeStore::GetInstance()->Clean();
313  G4SolidStore::GetInstance()->Clean();
314
315  //  G4RegionStore::GetInstance()->Clean();
316
317  // complete the Calor parameters definition and print
318
319  ComputeCalorParameters();
320  PrintCalorParameters();
321     
322  // World
323  fSolidWorld = new G4Tubs("World",                             //its name
324                   0.,fWorldSizeR,fWorldSizeZ/2.,0.,twopi)       ;//its size
325                         
326  fLogicWorld = new G4LogicalVolume(fSolidWorld,                //its solid
327                                   fWorldMaterial,      //its material
328                                   "World");            //its name
329                                   
330  fPhysicsWorld = new G4PVPlacement(0,                  //no rotation
331                                 G4ThreeVector(),       //at (0,0,0)
332                                 "World",               //its name
333                                 fLogicWorld,           //its logical volume
334                                 NULL,                  //its mother  volume
335                                 false,                 //no boolean operation
336                                 0);                    //copy number
337
338  // Absorber
339
340  if (fAbsorberThickness > 0.) 
341  { 
342
343    fSolidAbsorber = new G4Tubs("Absorber",             
344                          0.,fAbsorberRadius,fAbsorberThickness/2.,0.,twopi); 
345                         
346    fLogicAbsorber = new G4LogicalVolume(fSolidAbsorber,   
347                                          fAbsorberMaterial, 
348                                          "Absorber");     
349                                         
350    fPhysicsAbsorber = new G4PVPlacement(0,               
351                    G4ThreeVector(0.,0.,fAbsorberZ),       
352                                        "Absorber",       
353                                        fLogicAbsorber,     
354                                        fPhysicsWorld,       
355                                        false,             
356                                        0);               
357                                       
358  }
359  if( fRegGasDet != 0 )  // remove obsolete root logical volume
360  {
361    fRegGasDet->RemoveRootLogicalVolume(fLogicAbsorber);
362  }
363  G4ProductionCuts* cuts = 0;
364
365  if( fRegGasDet == 0 ) // First time - instantiate a region and a cut objects
366  {   
[1337]367    fRegGasDet = new G4Region("GasDetector");
[807]368    cuts = new G4ProductionCuts();
369    fRegGasDet->SetProductionCuts(cuts);
370  }
371  else  // Second time - get a cut object from region
372  {   
373    cuts = fRegGasDet->GetProductionCuts();
374  }
375  fRegGasDet->AddRootLogicalVolume(fLogicAbsorber);                               
376
377  cuts->SetProductionCut(fGammaCut,"gamma");
378  cuts->SetProductionCut(fElectronCut,"e-");
379  cuts->SetProductionCut(fPositronCut,"e+");
380
381  // Sensitive Detectors: Absorber
382 
383  G4SDManager* SDman = G4SDManager::GetSDMpointer();
384
385  if(!fCalorimeterSD)
386  {
387    fCalorimeterSD = new Em8CalorimeterSD("CalorSD",this);
388    SDman->AddNewDetector( fCalorimeterSD );
389  }
390  if (fLogicAbsorber)  fLogicAbsorber->SetSensitiveDetector(fCalorimeterSD);
391
392  // Parameterisation
393
394  //   G4VXrayTRmodel* pTRModel = new G4IrregularXrayTRmodel(logicRadiator,
395  //        fRadThickness,fGasGap);
396
397  //  G4VXrayTRmodel* pTRModel = new G4FoamXrayTRmodel(logicRadiator,
398  //                                    fRadThickness,fGasGap);
399
400  //   G4VXrayTRmodel* pTRModel = new G4RegularXrayTRmodel(logicRadiator,
401  //                                                       fRadThickness,fGasGap);
402
403  //  G4double alphaPlate = 160.0 ;
404  //  G4double alphaGas   = 160.0 ;
405
406  //  G4VXrayTRmodel* pTRModel = new G4GamDistrXrayTRmodel(logicRadiator,
407  //                                           fRadThickness,alphaPlate,
408  //                                              fGasGap,alphaGas);
409
410  //  G4VXrayTRmodel* pTRModel = new G4PlateIrrGasXrayTRmodel(logicRadiator,
411  //       fRadThickness,fGasGap);
412
413  //  pTRModel->GetPlateZmuProduct() ;
414  //  pTRModel->GetGasZmuProduct() ;
415
416  //  pTRModel->GetNumberOfPhotons() ; 
417 
418  // always return physics world
419
420  return fPhysicsWorld;
421}
422
423////////////////////////////////////////////////////////////////////////////
424//
425//
426
427void Em8DetectorConstruction::PrintCalorParameters()
428{
429  G4cout << "\n The  WORLD   is made of " 
430         << fWorldSizeZ/mm << "mm of " << fWorldMaterial->GetName() ;
431  G4cout << ", the transverse size (R) of the world is " << fWorldSizeR/mm
432         << " mm. " << G4endl;
433  G4cout << " The ABSORBER is made of " 
434         << fAbsorberThickness/mm << "mm of " << fAbsorberMaterial->GetName() ;
435  G4cout << ", the transverse size (R) is " << fAbsorberRadius/mm << " mm. " << G4endl;
436  G4cout << " Z position of the (middle of the) absorber " 
437         << fAbsorberZ/mm << "  mm." << G4endl;
438  G4cout << G4endl;
439}
440
441///////////////////////////////////////////////////////////////////////////
442//
443//
444
445void Em8DetectorConstruction::SetAbsorberMaterial(G4String materialChoice)
446{
447  // get the pointer to the material table
448  const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
449
450  // search the material by its name   
451  G4Material* pttoMaterial;
452
453  for (size_t J = 0 ; J < theMaterialTable->size() ; J++)
454  { 
455    pttoMaterial = (*theMaterialTable)[J];
456     
457    if(pttoMaterial->GetName() == materialChoice)
458    {
459      fAbsorberMaterial = pttoMaterial;
460      fLogicAbsorber->SetMaterial(pttoMaterial); 
461
462        // PrintCalorParameters();
463    }             
464  }
465}
466
467////////////////////////////////////////////////////////////////////////////
468//
469//
470
471void Em8DetectorConstruction::SetWorldMaterial(G4String materialChoice)
472{
473  // get the pointer to the material table
474  const G4MaterialTable* theMaterialTable = G4Material::GetMaterialTable();
475
476  // search the material by its name   
477  G4Material* pttoMaterial;
478  for (size_t J=0 ; J<theMaterialTable->size() ; J++)
479  { 
480    pttoMaterial = (*theMaterialTable)[J]; 
481   
482    if(pttoMaterial->GetName() == materialChoice)
483    {
484      fWorldMaterial = pttoMaterial;
485      fLogicWorld->SetMaterial(pttoMaterial);
486 
487       //  PrintCalorParameters();
488    }             
489  }
490}
491
492///////////////////////////////////////////////////////////////////////////
493//
494//
495
496void Em8DetectorConstruction::SetAbsorberThickness(G4double val)
497{
498  // change Absorber thickness and recompute the calorimeter parameters
499  fAbsorberThickness = val;
500  ComputeCalorParameters();
501} 
502
503/////////////////////////////////////////////////////////////////////////////
504//
505//
506
507void Em8DetectorConstruction::SetAbsorberRadius(G4double val)
508{
509  // change the transverse size and recompute the calorimeter parameters
510  fAbsorberRadius = val;
511  ComputeCalorParameters();
512} 
513
514////////////////////////////////////////////////////////////////////////////
515//
516//
517
518void Em8DetectorConstruction::SetWorldSizeZ(G4double val)
519{
520  fWorldChanged=true;
521  fWorldSizeZ = val;
522  ComputeCalorParameters();
523} 
524
525///////////////////////////////////////////////////////////////////////////
526//
527//
528
529void Em8DetectorConstruction::SetWorldSizeR(G4double val)
530{
531  fWorldChanged=true;
532  fWorldSizeR = val;
533  ComputeCalorParameters();
534} 
535
536//////////////////////////////////////////////////////////////////////////////
537//
538//
539
540void Em8DetectorConstruction::SetAbsorberZpos(G4double val)
541{
542  fAbsorberZ  = val;
543  ComputeCalorParameters();
544} 
545
546
547///////////////////////////////////////////////////////////////////////////////
548//
549//
550 
551void Em8DetectorConstruction::UpdateGeometry()
552{
553  G4RunManager::GetRunManager()->DefineWorldVolume(ConstructCalorimeter());
554}
555
556//
557//
558////////////////////////////////////////////////////////////////////////////
559
Note: See TracBrowser for help on using the repository browser.