Geant4 examples
basic/B4/B4a/src/B4DetectorConstruction.cc
Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id$
00027 // 
00030 
00031 #include "B4DetectorConstruction.hh"
00032 
00033 #include "G4Material.hh"
00034 #include "G4NistManager.hh"
00035 
00036 #include "G4Box.hh"
00037 #include "G4LogicalVolume.hh"
00038 #include "G4PVPlacement.hh"
00039 #include "G4PVReplica.hh"
00040 #include "G4UniformMagField.hh"
00041 
00042 #include "G4GeometryManager.hh"
00043 #include "G4PhysicalVolumeStore.hh"
00044 #include "G4LogicalVolumeStore.hh"
00045 #include "G4SolidStore.hh"
00046 
00047 #include "G4VisAttributes.hh"
00048 #include "G4Colour.hh"
00049 
00050 #include "G4FieldManager.hh"
00051 #include "G4TransportationManager.hh"
00052 
00053 #include <stdio.h>
00054 
00055 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00056 
00057 B4DetectorConstruction::B4DetectorConstruction()
00058  : G4VUserDetectorConstruction(),
00059    fMessenger(this),
00060    fMagField(0),
00061    fAbsorberPV(0),
00062    fGapPV(0),
00063    fCheckOverlaps(true)
00064 {
00065 }
00066 
00067 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00068 
00069 B4DetectorConstruction::~B4DetectorConstruction()
00070 { 
00071   delete fMagField;
00072 }
00073 
00074 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00075 
00076 G4VPhysicalVolume* B4DetectorConstruction::Construct()
00077 {
00078   // Define materials 
00079   DefineMaterials();
00080   
00081   // Define volumes
00082   return DefineVolumes();
00083 }
00084 
00085 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00086 
00087 void B4DetectorConstruction::DefineMaterials()
00088 { 
00089   // Lead material defined using NIST Manager
00090   G4NistManager* nistManager = G4NistManager::Instance();
00091   G4bool fromIsotopes = false;
00092   nistManager->FindOrBuildMaterial("G4_Pb", fromIsotopes);
00093   
00094   // Liquid argon material
00095   G4double a;  // mass of a mole;
00096   G4double z;  // z=mean number of protons;  
00097   G4double density; 
00098   new G4Material("liquidArgon", z=18., a= 39.95*g/mole, density= 1.390*g/cm3);
00099          // The argon by NIST Manager is a gas with a different density
00100 
00101   // Vacuum
00102   new G4Material("Galactic", z=1., a=1.01*g/mole,density= universe_mean_density,
00103                   kStateGas, 2.73*kelvin, 3.e-18*pascal);
00104 
00105   // Print materials
00106   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
00107 }
00108 
00109 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00110 
00111 G4VPhysicalVolume* B4DetectorConstruction::DefineVolumes()
00112 {
00113   // Geometry parameters
00114   G4int nofLayers = 10;
00115   G4double absoThickness = 10.*mm;
00116   G4double gapThickness =  5.*mm;
00117   G4double calorSizeXY  = 10.*cm;
00118 
00119   G4double layerThickness = absoThickness + gapThickness;
00120   G4double calorThickness = nofLayers * layerThickness;
00121   G4double worldSizeXY = 1.2 * calorSizeXY;
00122   G4double worldSizeZ  = 1.2 * calorThickness; 
00123   
00124   // Get materials
00125   G4Material* defaultMaterial = G4Material::GetMaterial("Galactic");
00126   G4Material* absorberMaterial = G4Material::GetMaterial("G4_Pb");
00127   G4Material* gapMaterial = G4Material::GetMaterial("liquidArgon");
00128   
00129   if ( ! defaultMaterial || ! absorberMaterial || ! gapMaterial ) {
00130     G4cerr << "Cannot retrieve materials already defined. " << G4endl;
00131     G4cerr << "Exiting application " << G4endl;
00132     exit(1);
00133   }  
00134    
00135   //     
00136   // World
00137   //
00138   G4VSolid* worldS 
00139     = new G4Box("World",           // its name
00140                  worldSizeXY/2, worldSizeXY/2, worldSizeZ/2); // its size
00141                          
00142   G4LogicalVolume* worldLV
00143     = new G4LogicalVolume(
00144                  worldS,           // its solid
00145                  defaultMaterial,  // its material
00146                  "World");         // its name
00147                                    
00148   G4VPhysicalVolume* worldPV
00149     = new G4PVPlacement(
00150                  0,                // no rotation
00151                  G4ThreeVector(),  // at (0,0,0)
00152                  worldLV,          // its logical volume                         
00153                  "World",          // its name
00154                  0,                // its mother  volume
00155                  false,            // no boolean operation
00156                  0,                // copy number
00157                  fCheckOverlaps);  // checking overlaps 
00158   
00159   //                               
00160   // Calorimeter
00161   //  
00162   G4VSolid* calorimeterS
00163     = new G4Box("Calorimeter",     // its name
00164                  calorSizeXY/2, calorSizeXY/2, calorThickness/2); // its size
00165                          
00166   G4LogicalVolume* calorLV
00167     = new G4LogicalVolume(
00168                  calorimeterS,     // its solid
00169                  defaultMaterial,  // its material
00170                  "Calorimeter");   // its name
00171                                    
00172   new G4PVPlacement(
00173                  0,                // no rotation
00174                  G4ThreeVector(),  // at (0,0,0)
00175                  calorLV,          // its logical volume                         
00176                  "Calorimeter",    // its name
00177                  worldLV,          // its mother  volume
00178                  false,            // no boolean operation
00179                  0,                // copy number
00180                  fCheckOverlaps);  // checking overlaps 
00181   
00182   //                                 
00183   // Layer
00184   //
00185   G4VSolid* layerS 
00186     = new G4Box("Layer",           // its name
00187                  calorSizeXY/2, calorSizeXY/2, layerThickness/2); // its size
00188                          
00189   G4LogicalVolume* layerLV
00190     = new G4LogicalVolume(
00191                  layerS,           // its solid
00192                  defaultMaterial,  // its material
00193                  "Layer");         // its name
00194 
00195   new G4PVReplica(
00196                  "Layer",          // its name
00197                  layerLV,          // its logical volume
00198                  calorLV,          // its mother
00199                  kZAxis,           // axis of replication
00200                  nofLayers,        // number of replica
00201                  layerThickness);  // witdth of replica
00202   
00203   //                               
00204   // Absorber
00205   //
00206   G4VSolid* absorberS 
00207     = new G4Box("Abso",            // its name
00208                  calorSizeXY/2, calorSizeXY/2, absoThickness/2); // its size
00209                          
00210   G4LogicalVolume* absorberLV
00211     = new G4LogicalVolume(
00212                  absorberS,        // its solid
00213                  absorberMaterial, // its material
00214                  "Abso");          // its name
00215                                    
00216   fAbsorberPV
00217     = new G4PVPlacement(
00218                  0,                // no rotation
00219                  G4ThreeVector(0., 0., -gapThickness/2), // its position
00220                  absorberLV,       // its logical volume                         
00221                  "Abso",           // its name
00222                  layerLV,          // its mother  volume
00223                  false,            // no boolean operation
00224                  0,                // copy number
00225                  fCheckOverlaps);  // checking overlaps 
00226 
00227   //                               
00228   // Gap
00229   //
00230   G4VSolid* gapS 
00231     = new G4Box("Gap",             // its name
00232                  calorSizeXY/2, calorSizeXY/2, gapThickness/2); // its size
00233                          
00234   G4LogicalVolume* gapLV
00235     = new G4LogicalVolume(
00236                  gapS,             // its solid
00237                  gapMaterial,      // its material
00238                  "Gap");           // its name
00239                                    
00240   fGapPV
00241     = new G4PVPlacement(
00242                  0,                // no rotation
00243                  G4ThreeVector(0., 0., absoThickness/2), // its position
00244                  gapLV,            // its logical volume                         
00245                  "Gap",            // its name
00246                  layerLV,          // its mother  volume
00247                  false,            // no boolean operation
00248                  0,                // copy number
00249                  fCheckOverlaps);  // checking overlaps 
00250   
00251   //
00252   // print parameters
00253   //
00254   G4cout << "\n------------------------------------------------------------"
00255          << "\n---> The calorimeter is " << nofLayers << " layers of: [ "
00256          << absoThickness/mm << "mm of " << absorberMaterial->GetName() 
00257          << " + "
00258          << gapThickness/mm << "mm of " << gapMaterial->GetName() << " ] " 
00259          << "\n------------------------------------------------------------\n";
00260   
00261   //                                        
00262   // Visualization attributes
00263   //
00264   worldLV->SetVisAttributes (G4VisAttributes::Invisible);
00265 
00266   G4VisAttributes* simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
00267   simpleBoxVisAtt->SetVisibility(true);
00268   calorLV->SetVisAttributes(simpleBoxVisAtt);
00269 
00270   //
00271   // Always return the physical World
00272   //
00273   return worldPV;
00274 }
00275 
00276 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00277 
00278 void B4DetectorConstruction::SetMagField(G4double fieldValue)
00279 {
00280   // Apply a global uniform magnetic field along X axis
00281   G4FieldManager* fieldManager
00282     = G4TransportationManager::GetTransportationManager()->GetFieldManager();
00283 
00284   // Delete the existing magnetic field
00285   if ( fMagField )  delete fMagField; 
00286 
00287   if ( fieldValue != 0. ) {
00288     // create a new one if not null
00289     fMagField 
00290       = new G4UniformMagField(G4ThreeVector(fieldValue, 0., 0.));
00291       
00292     fieldManager->SetDetectorField(fMagField);
00293     fieldManager->CreateChordFinder(fMagField);
00294   } 
00295   else {
00296     fMagField = 0;
00297     fieldManager->SetDetectorField(fMagField);
00298   }
00299 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines