Files
geant4/examples/extended/hadronic/Hadr00/src/DetectorConstruction.cc
T
2016-06-09 15:58:43 +02:00

185 lines
6.0 KiB
C++

//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: DetectorConstruction.cc,v 1.1 2008/07/07 16:37:26 vnivanch Exp $
// GEANT4 tag $Name: geant4-09-02 $
//
/////////////////////////////////////////////////////////////////////////
//
// DetectorConstruction
//
// Created: 20.06.2008 V.Ivanchenko
//
// Modified:
//
////////////////////////////////////////////////////////////////////////
//
#include "DetectorConstruction.hh"
#include "DetectorMessenger.hh"
#include "G4Tubs.hh"
#include "G4LogicalVolume.hh"
#include "G4PVPlacement.hh"
#include "G4RunManager.hh"
#include "G4GeometryManager.hh"
#include "G4PhysicalVolumeStore.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4SolidStore.hh"
#include "G4VisAttributes.hh"
#include "G4Colour.hh"
#include "G4UnitsTable.hh"
#include "G4ios.hh"
#include "G4NistManager.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
DetectorConstruction::DetectorConstruction()
{
logicTarget = 0;
logicWorld = 0;
detectorMessenger = new DetectorMessenger(this);
radius = 5.*cm;
length = 10.*cm;
targetMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Al");
worldMaterial = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic");
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
DetectorConstruction::~DetectorConstruction()
{
delete detectorMessenger;
}
G4VPhysicalVolume* DetectorConstruction::Construct()
{
// Cleanup old geometry
G4GeometryManager::GetInstance()->OpenGeometry();
G4PhysicalVolumeStore::GetInstance()->Clean();
G4LogicalVolumeStore::GetInstance()->Clean();
G4SolidStore::GetInstance()->Clean();
// Sizes
G4double worldR = radius + cm;
G4double worldZ = length + cm;
//
// World
//
G4Tubs* solidW = new G4Tubs("World",0.,worldR,worldZ/2.0,0.,twopi);
logicWorld = new G4LogicalVolume( solidW,worldMaterial,"World");
G4VPhysicalVolume* world = new G4PVPlacement(0,G4ThreeVector(),
logicWorld,"World",0,false,0);
//
// Target volume
//
G4Tubs* solidA = new G4Tubs("Target",0.,radius,length/2.0,0.,twopi);
logicTarget = new G4LogicalVolume( solidA,targetMaterial,"Target");
new G4PVPlacement(0,G4ThreeVector(),logicTarget,"Target",logicWorld,false,0);
G4cout << "### Target consist of "
<< targetMaterial->GetName()
<< " disks with R(mm)= " << radius/mm
<< " Length(mm)= " << length/mm
<< " ###" << G4endl;
// colors
logicWorld->SetVisAttributes(G4VisAttributes::Invisible);
G4VisAttributes* regCcolor = new G4VisAttributes(G4Colour(0., 0.3, 0.7));
logicTarget->SetVisAttributes(regCcolor);
G4cout << *(G4Material::GetMaterialTable()) << G4endl;
return world;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::SetTargetMaterial(const G4String& mat)
{
// search the material by its name
G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat);
if (material && material != targetMaterial) {
targetMaterial = material;
if(logicTarget) logicTarget->SetMaterial(targetMaterial);
G4RunManager::GetRunManager()->PhysicsHasBeenModified();
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::SetWorldMaterial(const G4String& mat)
{
// search the material by its name
G4Material* material = G4NistManager::Instance()->FindOrBuildMaterial(mat);
if (material && material != worldMaterial) {
worldMaterial = material;
if(logicWorld) logicWorld->SetMaterial(worldMaterial);
G4RunManager::GetRunManager()->PhysicsHasBeenModified();
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::UpdateGeometry()
{
G4RunManager::GetRunManager()->DefineWorldVolume(Construct());
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::SetTargetRadius(G4double val)
{
if(val > 0.0 && val != radius) {
radius = val;
G4RunManager::GetRunManager()->GeometryHasBeenModified();
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::SetTargetLength(G4double val)
{
if(val > 0.0 && val != length) {
length = val;
G4RunManager::GetRunManager()->GeometryHasBeenModified();
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......