Geant4 examples
extended/common/detectorConstruction/src/ExG4DetectorConstruction02.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 "ExG4DetectorConstruction02.hh"
00032 #include "ExG4DetectorConstruction02Messenger.hh"
00033 
00034 #include "G4Material.hh"
00035 #include "G4NistManager.hh"
00036 #include "G4Box.hh"
00037 #include "G4LogicalVolume.hh"
00038 #include "G4PVPlacement.hh"
00039 
00040 
00041 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00042 
00043 ExG4DetectorConstruction02::ExG4DetectorConstruction02(
00044                               const G4String& boxMaterialName,
00045                               G4double boxHx, G4double boxHy, G4double boxHz,
00046                               const G4String& worldMaterialName,
00047                               G4double worldSizeFactor)
00048  : G4VUserDetectorConstruction(),
00049    fMessenger(this),
00050    fBoxMaterialName(boxMaterialName),
00051    fWorldMaterialName(worldMaterialName),
00052    fBoxDimensions(boxHx*2, boxHy*2, boxHz*2),
00053    fWorldSizeFactor(worldSizeFactor),
00054    fBoxVolume(0),
00055    fWorldVolume(0)
00056 {
00057 }
00058 
00059 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00060 
00061 ExG4DetectorConstruction02::~ExG4DetectorConstruction02()
00062 { 
00063 }
00064 
00065 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00066 
00067 G4VPhysicalVolume* ExG4DetectorConstruction02::Construct()
00068 {
00069   // Define materials via NIST manager
00070   //
00071   G4NistManager* nistManager = G4NistManager::Instance();
00072 
00073   G4bool fromIsotopes = false;
00074 
00075   G4Material* worldMaterial
00076     = nistManager->FindOrBuildMaterial(fWorldMaterialName, fromIsotopes);
00077 
00078   G4Material* boxMaterial
00079     = nistManager->FindOrBuildMaterial(fBoxMaterialName, fromIsotopes);
00080  
00081   // Geometry parameters
00082   //
00083   G4ThreeVector worldDimensions = fBoxDimensions * fWorldSizeFactor;
00084   
00085   
00086   // World
00087   //
00088   G4Box* sWorld 
00089     = new G4Box("World",                                //name
00090                  worldDimensions.x(),                   //dimensions (half-lentghs)
00091                  worldDimensions.y(), 
00092                  worldDimensions.z());
00093 
00094   fWorldVolume 
00095     = new G4LogicalVolume(sWorld,                       //shape
00096                           worldMaterial,                 //material
00097                           "World");                     //name
00098 
00099   G4VPhysicalVolume* pWorld 
00100     = new G4PVPlacement(0,                              //no rotation
00101                         G4ThreeVector(),                //at (0,0,0)
00102                         fWorldVolume,                   //logical volume
00103                         "World",                        //name
00104                         0,                              //mother  volume
00105                         false,                          //no boolean operation
00106                         0);                             //copy number
00107                                                    
00108   // Box
00109   //                       
00110   G4Box* sBox 
00111     = new G4Box("Box",                                  //its name
00112                  fBoxDimensions.x(),                    //dimensions (half-lengths)
00113                  fBoxDimensions.y(), 
00114                  fBoxDimensions.z());
00115                    
00116   fBoxVolume 
00117     = new G4LogicalVolume(sBox,                         //its shape
00118                           boxMaterial,                  //its material
00119                           "Box");                       //its name
00120 
00121   new G4PVPlacement(0,                                  //no rotation
00122                     G4ThreeVector(),                    //at (0,0,0)
00123                     fBoxVolume,                         //its logical volume                       
00124                     "Box",                              //its name
00125                     fWorldVolume,                       //its mother  volume
00126                     false,                              //no boolean operation
00127                     0);                                 //copy number
00128 
00129   //always return the root volume
00130   //
00131   return pWorld;
00132 }
00133 
00134 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00135  
00136 void ExG4DetectorConstruction02::SetBoxMaterial(const G4String& materialName)
00137 {
00138   G4NistManager* nistManager = G4NistManager::Instance();
00139   G4bool fromIsotopes = false;
00140 
00141   G4Material* newMaterial
00142     = nistManager->FindOrBuildMaterial(materialName, fromIsotopes);
00143 
00144   if ( ! newMaterial ) {
00145     G4cerr << "Material " << materialName << " not found." << G4endl;
00146     G4cerr << "The box material was not changed." << G4endl;
00147     return;
00148   }  
00149    
00150   if ( fBoxVolume ) fBoxVolume->SetMaterial(newMaterial);
00151   G4cout << "Material of box changed to " << materialName << G4endl;
00152 }
00153 
00154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00155  
00156 void ExG4DetectorConstruction02::SetWorldMaterial(const G4String& materialName)
00157 {
00158   G4NistManager* nistManager = G4NistManager::Instance();
00159   G4bool fromIsotopes = false;
00160 
00161   G4Material* newMaterial
00162     = nistManager->FindOrBuildMaterial(materialName, fromIsotopes);
00163 
00164   if ( ! newMaterial ) {
00165     G4cerr << "Material " << materialName << " not found." << G4endl;
00166     G4cerr << "The box material was not changed." << G4endl;
00167     return;
00168   }  
00169    
00170   if ( fWorldVolume ) fWorldVolume->SetMaterial(newMaterial);
00171   G4cout << "Material of box changed to " << materialName << G4endl;
00172 }
00173 
00174 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00175  
00176 void ExG4DetectorConstruction02::SetBoxDimensions(
00177                                    G4double hx, G4double hy, G4double hz) 
00178 {
00181 
00182   fBoxDimensions = G4ThreeVector(hx, hy, hz);
00183 }  
00184                                      
00185 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00186 
00187 void ExG4DetectorConstruction02::SetWorldSizeFactor(G4double factor) 
00188 {
00191 
00192   fWorldSizeFactor = factor;
00193 }  
00194                                      
00195 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines