DetectorConstruction.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 /// \file hadronic/Hadr00/src/DetectorConstruction.cc
00027 /// \brief Implementation of the DetectorConstruction class
00028 //
00029 // $Id$
00030 //
00031 /////////////////////////////////////////////////////////////////////////
00032 //
00033 // DetectorConstruction
00034 //
00035 // Created: 20.06.2008 V.Ivanchenko
00036 //
00037 // Modified:
00038 //
00039 ////////////////////////////////////////////////////////////////////////
00040 // 
00041 
00042 #include "DetectorConstruction.hh"
00043 #include "DetectorMessenger.hh"
00044 
00045 #include "G4Tubs.hh"
00046 #include "G4LogicalVolume.hh"
00047 #include "G4PVPlacement.hh"
00048 
00049 #include "G4RunManager.hh"
00050 
00051 #include "G4GeometryManager.hh"
00052 #include "G4PhysicalVolumeStore.hh"
00053 #include "G4LogicalVolumeStore.hh"
00054 #include "G4SolidStore.hh"
00055 
00056 #include "G4VisAttributes.hh"
00057 #include "G4Colour.hh"
00058 
00059 #include "G4UnitsTable.hh"
00060 #include "G4ios.hh"
00061 
00062 #include "G4NistManager.hh"
00063 
00064 #include "G4PhysicalConstants.hh"
00065 #include "G4SystemOfUnits.hh"
00066 
00067 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00068 
00069 DetectorConstruction::DetectorConstruction()
00070 {
00071   fLogicTarget = 0;
00072   fLogicWorld  = 0;
00073   fDetectorMessenger = new DetectorMessenger(this);
00074 
00075   fRadius = 5.*cm;
00076   fLength = 10.*cm;
00077 
00078   fTargetMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Al");
00079   fWorldMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
00080 }
00081 
00082 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00083 
00084 DetectorConstruction::~DetectorConstruction()
00085 { 
00086   delete fDetectorMessenger;
00087 }
00088 
00089 G4VPhysicalVolume* DetectorConstruction::Construct()
00090 {
00091   // Cleanup old geometry
00092 
00093   G4GeometryManager::GetInstance()->OpenGeometry();
00094   G4PhysicalVolumeStore::GetInstance()->Clean();
00095   G4LogicalVolumeStore::GetInstance()->Clean();
00096   G4SolidStore::GetInstance()->Clean();
00097 
00098   // Sizes
00099   G4double worldR  = fRadius + cm;
00100   G4double worldZ  = fLength + cm;
00101 
00102   //
00103   // World
00104   //
00105   G4Tubs* solidW = new G4Tubs("World", 0., worldR, 0.5*worldZ, 0., twopi);
00106   fLogicWorld = new G4LogicalVolume(solidW, fWorldMaterial,"World");
00107   G4VPhysicalVolume* world = new G4PVPlacement(0, G4ThreeVector(),
00108                                                fLogicWorld, "World", 
00109                                                0, false, 0);
00110 
00111   //
00112   // Target volume
00113   //
00114   G4Tubs* solidA = new G4Tubs("Target", 0., fRadius, 0.5*fLength, 0.,twopi);
00115   fLogicTarget = new G4LogicalVolume( solidA, fTargetMaterial, "Target");
00116   new G4PVPlacement(0, G4ThreeVector(), fLogicTarget, "Target",
00117                     fLogicWorld, false, 0);
00118 
00119   G4cout << "### Target consist of " 
00120          << fTargetMaterial->GetName() 
00121          << " disks with R(mm)= " << fRadius/mm
00122          << "  fLength(mm)= " << fLength/mm
00123          <<  "  ###" << G4endl;
00124 
00125   // colors
00126   fLogicWorld->SetVisAttributes(G4VisAttributes::Invisible);
00127 
00128   G4VisAttributes* regCcolor = new G4VisAttributes(G4Colour(0., 0.3, 0.7));
00129   fLogicTarget->SetVisAttributes(regCcolor);
00130 
00131   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
00132 
00133   return world;
00134 }
00135 
00136 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00137 
00138 void DetectorConstruction::SetTargetMaterial(const G4String& mat)
00139 {
00140   // search the material by its name
00141   G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat);
00142 
00143   if (material && material != fTargetMaterial) {
00144     fTargetMaterial = material;
00145     if(fLogicTarget) fLogicTarget->SetMaterial(fTargetMaterial);
00146     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
00147   }
00148 }
00149 
00150 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00151 
00152 void DetectorConstruction::SetWorldMaterial(const G4String& mat)
00153 {
00154   // search the material by its name
00155   G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat);
00156 
00157   if (material && material != fWorldMaterial) {
00158     fWorldMaterial = material;
00159     if(fLogicWorld) fLogicWorld->SetMaterial(fWorldMaterial);
00160     G4RunManager::GetRunManager()->PhysicsHasBeenModified();
00161   }
00162 }
00163 
00164 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00165 
00166 void DetectorConstruction::UpdateGeometry()
00167 {
00168   G4RunManager::GetRunManager()->DefineWorldVolume(Construct());
00169 }
00170 
00171 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00172 
00173 void DetectorConstruction::SetTargetRadius(G4double val)  
00174 {
00175   if(val > 0.0 && val != fRadius) {
00176     fRadius = val;
00177     G4RunManager::GetRunManager()->GeometryHasBeenModified();
00178   } 
00179 }
00180 
00181 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00182 
00183 void DetectorConstruction::SetTargetLength(G4double val)  
00184 {
00185   if(val > 0.0 && val != fLength) {
00186     fLength = val;
00187     G4RunManager::GetRunManager()->GeometryHasBeenModified();
00188   } 
00189 }
00190 
00191 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

Generated on 19 Feb 2017 for QwGeant4 by  doxygen 1.6.1