Import Geant4 9.5.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-09 16:46:55 +02:00
parent 89a9605df1
commit b1eb5424d2
10957 changed files with 888481 additions and 160139 deletions
@@ -0,0 +1,195 @@
//
// ********************************************************************
// * 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$
//
/// \file ExG4DetectorConstruction02.cc
/// \brief Implementation of the ExG4DetectorConstruction02 class
#include "ExG4DetectorConstruction02.hh"
#include "ExG4DetectorConstruction02Messenger.hh"
#include "G4Material.hh"
#include "G4NistManager.hh"
#include "G4Box.hh"
#include "G4LogicalVolume.hh"
#include "G4PVPlacement.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExG4DetectorConstruction02::ExG4DetectorConstruction02(
const G4String& boxMaterialName,
G4double boxHx, G4double boxHy, G4double boxHz,
const G4String& worldMaterialName,
G4double worldSizeFactor)
: G4VUserDetectorConstruction(),
fMessenger(this),
fBoxMaterialName(boxMaterialName),
fWorldMaterialName(worldMaterialName),
fBoxDimensions(boxHx*2, boxHy*2, boxHz*2),
fWorldSizeFactor(worldSizeFactor),
fBoxVolume(0),
fWorldVolume(0)
{
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExG4DetectorConstruction02::~ExG4DetectorConstruction02()
{
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4VPhysicalVolume* ExG4DetectorConstruction02::Construct()
{
// Define materials via NIST manager
//
G4NistManager* nistManager = G4NistManager::Instance();
G4bool fromIsotopes = false;
G4Material* worldMaterial
= nistManager->FindOrBuildMaterial(fWorldMaterialName, fromIsotopes);
G4Material* boxMaterial
= nistManager->FindOrBuildMaterial(fBoxMaterialName, fromIsotopes);
// Geometry parameters
//
G4ThreeVector worldDimensions = fBoxDimensions * fWorldSizeFactor;
// World
//
G4Box* sWorld
= new G4Box("World", //name
worldDimensions.x(), //dimensions (half-lentghs)
worldDimensions.y(),
worldDimensions.z());
fWorldVolume
= new G4LogicalVolume(sWorld, //shape
worldMaterial, //material
"World"); //name
G4VPhysicalVolume* pWorld
= new G4PVPlacement(0, //no rotation
G4ThreeVector(), //at (0,0,0)
fWorldVolume, //logical volume
"World", //name
0, //mother volume
false, //no boolean operation
0); //copy number
// Box
//
G4Box* sBox
= new G4Box("Box", //its name
fBoxDimensions.x(), //dimensions (half-lengths)
fBoxDimensions.y(),
fBoxDimensions.z());
fBoxVolume
= new G4LogicalVolume(sBox, //its shape
boxMaterial, //its material
"Box"); //its name
new G4PVPlacement(0, //no rotation
G4ThreeVector(), //at (0,0,0)
fBoxVolume, //its logical volume
"Box", //its name
fWorldVolume, //its mother volume
false, //no boolean operation
0); //copy number
//always return the root volume
//
return pWorld;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExG4DetectorConstruction02::SetBoxMaterial(const G4String& materialName)
{
G4NistManager* nistManager = G4NistManager::Instance();
G4bool fromIsotopes = false;
G4Material* newMaterial
= nistManager->FindOrBuildMaterial(materialName, fromIsotopes);
if ( ! newMaterial ) {
G4cerr << "Material " << materialName << " not found." << G4endl;
G4cerr << "The box material was not changed." << G4endl;
return;
}
if ( fBoxVolume ) fBoxVolume->SetMaterial(newMaterial);
G4cout << "Material of box changed to " << materialName << G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExG4DetectorConstruction02::SetWorldMaterial(const G4String& materialName)
{
G4NistManager* nistManager = G4NistManager::Instance();
G4bool fromIsotopes = false;
G4Material* newMaterial
= nistManager->FindOrBuildMaterial(materialName, fromIsotopes);
if ( ! newMaterial ) {
G4cerr << "Material " << materialName << " not found." << G4endl;
G4cerr << "The box material was not changed." << G4endl;
return;
}
if ( fWorldVolume ) fWorldVolume->SetMaterial(newMaterial);
G4cout << "Material of box changed to " << materialName << G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExG4DetectorConstruction02::SetBoxDimensions(
G4double hx, G4double hy, G4double hz)
{
/// Set box dimension (in half lengths).
/// This setting has effect only if called in PreInit> phase
fBoxDimensions = G4ThreeVector(hx, hy, hz);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExG4DetectorConstruction02::SetWorldSizeFactor(G4double factor)
{
/// Set the multiplication factor from box dimensions to world dimensions.
/// This setting has effect only if called in PreInit> phase
fWorldSizeFactor = factor;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,125 @@
//
// ********************************************************************
// * 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$
//
/// \file ExG4DetectorConstruction02Messenger.cc
/// \brief Implementation of the ExG4DetectorConstruction02Messenger class
#include "ExG4DetectorConstruction02Messenger.hh"
#include "ExG4DetectorConstruction02.hh"
#include "G4UIdirectory.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UIcmdWith3VectorAndUnit.hh"
#include "G4UIcmdWithADouble.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExG4DetectorConstruction02Messenger::ExG4DetectorConstruction02Messenger(
ExG4DetectorConstruction02* detectorConstruction)
: G4UImessenger(),
fDetectorConstruction(detectorConstruction),
fTopDirectory(0),
fDirectory(0),
fSetBoxMaterialCmd(0),
fSetWorldMaterialCmd(0),
fSetBoxDimensionsCmd(0),
fSetWorldSizeFactorCmd(0)
{
fTopDirectory = new G4UIdirectory("/ExG4/");
fTopDirectory->SetGuidance("UI commands of common example classes");
fDirectory = new G4UIdirectory("/ExG4/det/");
fDirectory->SetGuidance("Detector control");
fSetBoxMaterialCmd
= new G4UIcmdWithAString("/ExG4/det/setBoxMaterial",this);
fSetBoxMaterialCmd->SetGuidance("Select material of the box.");
fSetBoxMaterialCmd->SetParameterName("BoxMaterial", false);
fSetBoxMaterialCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
fSetWorldMaterialCmd
= new G4UIcmdWithAString("/ExG4/det/setWorldMaterial",this);
fSetWorldMaterialCmd->SetGuidance("Select material of the world.");
fSetWorldMaterialCmd->SetParameterName("WorldMaterial", false);
fSetWorldMaterialCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
fSetBoxDimensionsCmd
= new G4UIcmdWith3VectorAndUnit("/ExG4/det/setBoxDimensions",this);
fSetBoxDimensionsCmd->SetGuidance("Set box dimensions (in half lentgh).");
fSetBoxDimensionsCmd->SetParameterName(
"BoxDimensionsHx", "BoxDimensionsHy","BoxDimensionsHz",
false);
//fSetBoxDimensionsCmd->SetUnitCategory("Length");
fSetBoxDimensionsCmd->AvailableForStates(G4State_PreInit);
fSetWorldSizeFactorCmd
= new G4UIcmdWithADouble("/ExG4/det/setWorldSizeFactor",this);
fSetWorldSizeFactorCmd->SetGuidance(
"Set the multiplication factor from box dimensions to world dimensions.");
fSetWorldSizeFactorCmd->SetParameterName("WorldSizeFactor", false);
fSetWorldSizeFactorCmd->SetRange("WorldSizeFactor >= 1");
fSetWorldSizeFactorCmd->AvailableForStates(G4State_PreInit);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExG4DetectorConstruction02Messenger::~ExG4DetectorConstruction02Messenger()
{
delete fTopDirectory;
delete fDirectory;
delete fSetBoxMaterialCmd;
delete fSetWorldMaterialCmd;
delete fSetBoxDimensionsCmd;
delete fSetWorldSizeFactorCmd;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExG4DetectorConstruction02Messenger::SetNewValue(G4UIcommand* command,
G4String newValue)
{
if( command == fSetBoxMaterialCmd ) {
fDetectorConstruction->SetBoxMaterial(newValue);
}
else if( command == fSetWorldMaterialCmd ) {
fDetectorConstruction->SetWorldMaterial(newValue);
}
else if( command == fSetBoxDimensionsCmd ) {
G4ThreeVector newDimensions
= fSetBoxDimensionsCmd->GetNew3VectorValue(newValue);
fDetectorConstruction
->SetBoxDimensions(
newDimensions.x(), newDimensions.y(), newDimensions.z());
}
else if ( command == fSetWorldSizeFactorCmd ) {
fDetectorConstruction
->SetWorldSizeFactor(fSetWorldSizeFactorCmd->GetNewDoubleValue(newValue));
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,104 @@
//
// ********************************************************************
// * 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$
//
/// \file ExG4EventAction01.cc
/// \brief Implementation of the ExG4EventAction01 class
#include "ExG4EventAction01.hh"
#include "G4RunManager.hh"
#include "G4Run.hh"
#include "G4Event.hh"
#include "G4Trajectory.hh"
#include "G4TrajectoryContainer.hh"
#include "G4VVisManager.hh"
#include "Randomize.hh"
#include <sstream>
const G4int ExG4EventAction01::fgkDefaultVerboseLevel = 1;
const G4int ExG4EventAction01::fgkDefaultPrintModulo = 10000;
//_____________________________________________________________________________
ExG4EventAction01::ExG4EventAction01()
: G4UserEventAction(),
fMessenger(this),
fVerboseLevel(fgkDefaultVerboseLevel),
fPrintModulo(fgkDefaultPrintModulo),
fSaveRndm(false)
{
/// Standard constructor
}
//_____________________________________________________________________________
ExG4EventAction01::~ExG4EventAction01()
{
/// Destructor
}
//_____________________________________________________________________________
void ExG4EventAction01::BeginOfEventAction(const G4Event* event)
{
// Print event info
//
G4int eventNumber = event->GetEventID();
if ( eventNumber%fPrintModulo == 0 ) {
G4cout << "\n---> Begin of Event: " << eventNumber << G4endl;
}
// Print verbose info
//
if ( fVerboseLevel > 1 ) {
G4cout << "<<< Event " << eventNumber << " started." << G4endl;
}
}
//_____________________________________________________________________________
void ExG4EventAction01::EndOfEventAction(const G4Event* event)
{
// Print verbose info
//
if ( fVerboseLevel > 1 ) {
G4cout << "<<< Event " << event->GetEventID() << " ended." << G4endl;
}
// Save rndm status
//
if ( fSaveRndm ) {
const G4Run* run = G4RunManager::GetRunManager()->GetCurrentRun();
G4int runNumber = run->GetRunID();
G4int eventNumber = event->GetEventID();
std::ostringstream fileName;
fileName << "run" << runNumber << "event" << eventNumber << ".rndm";
CLHEP::HepRandom::saveEngineStatus(fileName.str().c_str());
if ( eventNumber%fPrintModulo == 0 ) {
G4cout << "\n---> End of Event: " << eventNumber << G4endl;
CLHEP::HepRandom::showEngineStatus();
}
}
}
@@ -0,0 +1,94 @@
//
// ********************************************************************
// * 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$
//
/// \file ExG4EventAction01Messenger.cc
/// \brief Implementation of the ExG4EventAction01Messenger class
#include "ExG4EventAction01Messenger.hh"
#include "ExG4EventAction01.hh"
#include "G4UIdirectory.hh"
#include "G4UIcmdWithAnInteger.hh"
#include "G4UIcmdWithABool.hh"
#include "globals.hh"
//_____________________________________________________________________________
ExG4EventAction01Messenger::ExG4EventAction01Messenger(ExG4EventAction01* eventAction)
: G4UImessenger(),
fEventAction(eventAction),
fTopDirectory(0),
fDirectory(0),
fSetVerboseLevelCmd(0),
fSetPrintModuloCmd(0),
fSetSaveRndmCmd(0)
{
fTopDirectory = new G4UIdirectory("/ExG4/");
fTopDirectory->SetGuidance("UI commands of common example classes");
fDirectory = new G4UIdirectory("/ExG4/event/");
fDirectory->SetGuidance("Event control");
fSetVerboseLevelCmd = new G4UIcmdWithAnInteger("/ExG4/event/verboseLevel",this);
fSetVerboseLevelCmd->SetGuidance("Set event verbose level ." );
fSetVerboseLevelCmd->SetParameterName("VerboseLevel",false);
fSetVerboseLevelCmd->AvailableForStates(G4State_PreInit, G4State_Init);
fSetPrintModuloCmd = new G4UIcmdWithAnInteger("/ExG4/event/printModulo",this);
fSetPrintModuloCmd->SetGuidance("Print events modulo n");
fSetPrintModuloCmd->SetParameterName("PrintModulo",false);
fSetPrintModuloCmd->SetRange("PrintModulo>0");
fSetPrintModuloCmd->AvailableForStates(G4State_Idle, G4State_Init);
fSetSaveRndmCmd = new G4UIcmdWithABool("/ExG4/event/saveRndm",this);
fSetSaveRndmCmd->SetGuidance("Activate saving random number at endOfEvent.");
fSetSaveRndmCmd->SetParameterName("SaveRndm",false);
fSetSaveRndmCmd->AvailableForStates(G4State_Idle, G4State_Init);
}
//_____________________________________________________________________________
ExG4EventAction01Messenger::~ExG4EventAction01Messenger()
{
delete fTopDirectory;
delete fDirectory;
delete fSetVerboseLevelCmd;
delete fSetPrintModuloCmd;
delete fSetSaveRndmCmd;
}
//_____________________________________________________________________________
void ExG4EventAction01Messenger::SetNewValue(G4UIcommand* command, G4String newValue)
{
if(command == fSetVerboseLevelCmd) {
fEventAction->SetVerboseLevel(fSetVerboseLevelCmd->GetNewIntValue(newValue));
}
else if ( command == fSetPrintModuloCmd ) {
fEventAction->SetPrintModulo(fSetPrintModuloCmd->GetNewIntValue(newValue));
}
else if ( command == fSetSaveRndmCmd ) {
fEventAction->SetSaveRndm(fSetSaveRndmCmd->GetNewBoolValue(newValue));
}
}
@@ -0,0 +1,76 @@
//
// ********************************************************************
// * 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$
//
/// \file ExG4PrimaryGeneratorAction01.cc
/// \brief Implementation of the ExG4PrimaryGeneratorAction01 class
#include "ExG4PrimaryGeneratorAction01.hh"
#include "G4Event.hh"
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExG4PrimaryGeneratorAction01::ExG4PrimaryGeneratorAction01(
const G4String& particleName,
G4double energy,
G4ThreeVector position,
G4ThreeVector momentumDirection)
: G4VUserPrimaryGeneratorAction(),
fParticleGun(0)
{
G4int nofParticles = 1;
fParticleGun = new G4ParticleGun(nofParticles);
// default particle kinematic
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
G4ParticleDefinition* particle
= particleTable->FindParticle(particleName);
fParticleGun->SetParticleDefinition(particle);
fParticleGun->SetParticleEnergy(energy);
fParticleGun->SetParticlePosition(position);
fParticleGun->SetParticleMomentumDirection(momentumDirection);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExG4PrimaryGeneratorAction01::~ExG4PrimaryGeneratorAction01()
{
delete fParticleGun;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExG4PrimaryGeneratorAction01::GeneratePrimaries(G4Event* anEvent)
{
// this function is called at the begining of event
fParticleGun->GeneratePrimaryVertex(anEvent);
}
@@ -0,0 +1,123 @@
//
// ********************************************************************
// * 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$
//
/// \file ExG4RunAction01.cc
/// \brief Implementation of the ExG4RunAction01 class
#include "ExG4RunAction01.hh"
#include "G4Run.hh"
#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "G4VVisManager.hh"
//#include "G4ios.hh"
//#include <iomanip>
#include "Randomize.hh"
const G4String ExG4RunAction01::fgkDefaultRndmFileName = "run0.rndm";
//_____________________________________________________________________________
ExG4RunAction01::ExG4RunAction01()
: G4UserRunAction(),
fMessenger(this),
fRndmFileName(fgkDefaultRndmFileName),
fVerboseLevel(1),
fSaveRndm(false),
fReadRndm(false),
fAutoSeed(false)
{
/// Standard constructor
}
//_____________________________________________________________________________
ExG4RunAction01::~ExG4RunAction01()
{
/// Destructor
}
//_____________________________________________________________________________
void ExG4RunAction01::BeginOfRunAction(const G4Run* run)
{
if ( fVerboseLevel > 0 ) {
G4cout << "### Run " << run->GetRunID() << " start." << G4endl;
}
// read Rndm status
if ( fReadRndm ) {
G4cout << "\n---> rndm status restored from file: " << fRndmFileName << G4endl;
CLHEP::HepRandom::restoreEngineStatus(fRndmFileName);
CLHEP::HepRandom::showEngineStatus();
}
// automatic (time-based) random seeds for each run
if ( fAutoSeed ) {
G4RunManager::GetRunManager()->SetRandomNumberStore(true);
G4RunManager::GetRunManager()->SetRandomNumberStoreDir("random/");
G4cout << "*******************" << G4endl;
G4cout << "*** AUTOSEED ON ***" << G4endl;
G4cout << "*******************" << G4endl;
long seeds[2];
time_t systime = time(NULL);
seeds[0] = (long) systime;
seeds[1] = (long) (systime*G4UniformRand());
CLHEP::HepRandom::setTheSeeds(seeds);
CLHEP::HepRandom::showEngineStatus();
}
// save Rndm status
if ( fSaveRndm ) {
G4int runNumber = run->GetRunID();
std::ostringstream fileName;
fileName << "run" << runNumber << ".rndm";
CLHEP::HepRandom::saveEngineStatus(fileName.str().c_str());
CLHEP::HepRandom::showEngineStatus();
}
if ( G4VVisManager::GetConcreteInstance() ) {
G4UImanager::GetUIpointer()->ApplyCommand("/vis/scene/notifyHandlers");
}
}
//_____________________________________________________________________________
void ExG4RunAction01::EndOfRunAction(const G4Run* run)
{
// save Rndm status
if ( fSaveRndm ) {
G4int runNumber = run->GetRunID();
std::ostringstream fileName;
fileName << "run" << runNumber << "end.rndm";
CLHEP::HepRandom::saveEngineStatus(fileName.str().c_str());
CLHEP::HepRandom::showEngineStatus();
}
if ( G4VVisManager::GetConcreteInstance() ) {
G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
}
}
@@ -0,0 +1,122 @@
//
// ********************************************************************
// * 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$
//
/// \file ExG4RunAction01Messenger.cc
/// \brief Implementation of the ExG4RunAction01Messenger class
#include "ExG4RunAction01Messenger.hh"
#include "ExG4RunAction01.hh"
#include "G4UIdirectory.hh"
#include "G4UIcmdWithABool.hh"
#include "G4UIcmdWithAnInteger.hh"
#include "G4UIcmdWithAString.hh"
#include "globals.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
ExG4RunAction01Messenger::ExG4RunAction01Messenger(ExG4RunAction01* runAction)
: G4UImessenger(),
fRunAction (runAction),
fTopDirectory(0),
fDirectory(0),
fSetVerboseLevelCmd(0),
fSetSaveRndmCmd(0),
fSetReadRndmCmd(0),
fSetRndmFileNameCmd(0),
fSetAutoSeedCmd(0)
{
fTopDirectory = new G4UIdirectory("/ExG4/");
fTopDirectory->SetGuidance("UI commands of common example classes");
fDirectory = new G4UIdirectory("/ExG4/event/");
fDirectory->SetGuidance("Event control");
fSetVerboseLevelCmd = new G4UIcmdWithAnInteger("/ExG4/run/verboseLevel",this);
fSetVerboseLevelCmd->SetGuidance("Set run verbose level ." );
fSetVerboseLevelCmd->SetParameterName("VerboseLevel",false);
fSetVerboseLevelCmd->AvailableForStates(G4State_PreInit, G4State_Init);
fSetSaveRndmCmd = new G4UIcmdWithABool("/ExG4/run/saveRndm",this);
fSetSaveRndmCmd
->SetGuidance("Activate saving random number at beginOfRun and endOfRun .");
fSetSaveRndmCmd->SetParameterName("SaveRndm",false);
fSetSaveRndmCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
fSetReadRndmCmd = new G4UIcmdWithABool("/ExG4/run/readRndm",this);
fSetReadRndmCmd->SetGuidance("Get rndm status from an external file at beginOfRun.");
fSetReadRndmCmd->SetParameterName("ReadRndm",false);
fSetReadRndmCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
fSetRndmFileNameCmd = new G4UIcmdWithAString("/ExG4/run/rndmFileName",this);
fSetRndmFileNameCmd->SetGuidance("Set rndm file name (to read from).");
fSetRndmFileNameCmd->SetParameterName("RndmFileName",false);
fSetRndmFileNameCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
fSetAutoSeedCmd = new G4UIcmdWithABool("/ExG4/run/autoSeed",this);
fSetAutoSeedCmd->SetGuidance("Switch on/off time-based random seeds");
fSetAutoSeedCmd->SetGuidance(" true: run seeds determined by system time");
fSetAutoSeedCmd->SetGuidance(" false: use command 'random/resetEngineFrom'");
fSetAutoSeedCmd->SetParameterName("AutoSeed",false);
fSetAutoSeedCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
ExG4RunAction01Messenger::~ExG4RunAction01Messenger()
{
delete fTopDirectory;
delete fDirectory;
delete fSetVerboseLevelCmd;
delete fSetSaveRndmCmd;
delete fSetReadRndmCmd;
delete fSetRndmFileNameCmd;
delete fSetAutoSeedCmd;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void ExG4RunAction01Messenger::SetNewValue(G4UIcommand* command,G4String newValues)
{
if ( command == fSetVerboseLevelCmd ) {
fRunAction->SetVerboseLevel(fSetVerboseLevelCmd->GetNewIntValue(newValues));
}
else if ( command == fSetSaveRndmCmd ) {
fRunAction->SetSaveRndm(fSetSaveRndmCmd->GetNewBoolValue(newValues));
}
else if ( command == fSetReadRndmCmd ) {
fRunAction->SetReadRndm(fSetReadRndmCmd->GetNewBoolValue(newValues));
}
else if (command == fSetRndmFileNameCmd) {
fRunAction->SetRndmFileName(newValues);
}
else if ( command == fSetAutoSeedCmd ) {
fRunAction->SetAutoSeed(fSetAutoSeedCmd->GetNewBoolValue(newValues));
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
@@ -0,0 +1,385 @@
//
// ********************************************************************
// * 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$
//
/// \file TrDetectorConstruction.cc
/// \brief Implementation of the TrDetectorConstruction class
#include "TrDetectorConstruction.hh"
#include "G4Material.hh"
#include "G4NistManager.hh"
#include "G4Tubs.hh"
#include "G4Trd.hh"
#include "G4LogicalVolume.hh"
#include "G4PVPlacement.hh"
#include "G4Transform3D.hh"
#include "G4RotationMatrix.hh"
#include "G4ReflectionFactory.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
TrDetectorConstruction::TrDetectorConstruction()
: G4VUserDetectorConstruction(),
fMessenger(this),
fMethod(kWithDirectMatrix)
{
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
TrDetectorConstruction::~TrDetectorConstruction()
{
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4VPhysicalVolume* TrDetectorConstruction::Construct()
{
// Materials
G4NistManager* nist = G4NistManager::Instance();
G4bool fromIsotopes = false;
G4Material* material = nist->FindOrBuildMaterial("G4_AIR", fromIsotopes);
// World
//
G4double rmin = 0.;
G4double rmax = 5*cm;
G4double hz = 5*cm;
G4double phiMin = 0.;
G4double deltaPhi = 360*degree;
G4Tubs* solidWorld
= new G4Tubs("World", //name
rmin, rmax, hz, phiMin, deltaPhi); //size
fWorldVolume
= new G4LogicalVolume(solidWorld, //solid
material, //material
"World"); //name
G4VPhysicalVolume* physiWorld
= new G4PVPlacement(0, //no rotation
G4ThreeVector(), //at (0,0,0)
fWorldVolume, //logical volume
"World", //name
0, //mother volume
false, //no boolean operation
0); //copy number
// Trd volume
//
G4double dX1 = 1*cm;
G4double dX2 = 1*cm;
G4double dY1 = 1*cm;
G4double dY2 = 2*cm;
G4double dZ = 3*cm;
G4Trd* solidTrd
= new G4Trd("trd", //name
dX1/2, dX2/2, dY1/2, dY2/2, dZ/2); //size
fTrdVolume
= new G4LogicalVolume(solidTrd, //solid
material, //material
"trd"); //name
// Place Volume1 and Volume2 according to selected methods
//
switch ( fMethod ) {
case kWithDirectMatrix: PlaceWithDirectMatrix(); break;
case kWithInverseMatrix: PlaceWithInverseMatrix(); break;
case kWithAxialRotations: PlaceWithAxialRotations(); break;
case kWithEulerAngles: PlaceWithEulerAngles(); break;
case kWithReflections: PlaceWithReflections(); break;
default: ;;
}
// Return the root volume
//
return physiWorld;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void TrDetectorConstruction::PlaceWithDirectMatrix()
{
G4double og = 3*cm;
// 1st position
//
G4double phi = 30*deg;
// u, v, w are the daughter axes, projected on the mother frame
G4ThreeVector u = G4ThreeVector(0, 0, -1);
G4ThreeVector v = G4ThreeVector(-std::sin(phi), std::cos(phi),0.);
G4ThreeVector w = G4ThreeVector( std::cos(phi), std::sin(phi),0.);
G4RotationMatrix rotm1 = G4RotationMatrix(u, v, w);
G4cout << "\n --> phi = " << phi/deg << " deg; direct rotation matrix : ";
rotm1.print(G4cout);
G4ThreeVector position1 = og*w;
G4Transform3D transform1 = G4Transform3D(rotm1,position1);
new G4PVPlacement(transform1, //position, rotation
fTrdVolume, //logical volume
"Trd", //name
fWorldVolume, //mother volume
false, //no boolean operation
1); //copy number
// 2nd position
//
phi = phi + 90*deg;
v = G4ThreeVector(-std::sin(phi), std::cos(phi),0.);
w = G4ThreeVector( std::cos(phi), std::sin(phi),0.);
G4RotationMatrix rotm2 = G4RotationMatrix(u, v, w);
G4ThreeVector position2 = og*w;
G4Transform3D transform2 = G4Transform3D(rotm2,position2);
new G4PVPlacement(transform2, //position, rotation
fTrdVolume, //logical volume
"Trd", //name
fWorldVolume, //mother volume
false, //no boolean operation
1); //copy number
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void TrDetectorConstruction::PlaceWithInverseMatrix()
{
G4double og = 3*cm;
// 1st position
//
G4double phi = 30*deg;
// u, v, w are the daughter axes, projected on the mother frame
G4ThreeVector u = G4ThreeVector(0, 0, -1);
G4ThreeVector v = G4ThreeVector(-std::sin(phi), std::cos(phi),0.);
G4ThreeVector w = G4ThreeVector( std::cos(phi), std::sin(phi),0.);
G4RotationMatrix rotm1 = G4RotationMatrix(u, v, w);
G4RotationMatrix* rotm1Inv = new G4RotationMatrix(rotm1.inverse());
G4cout << "\n --> phi = " << phi/deg << " deg; inverse rotation matrix : ";
rotm1Inv->print(G4cout);
G4ThreeVector position1 = og*w;
new G4PVPlacement(rotm1Inv,
position1,
fTrdVolume, //logical volume
"Trd", //name
fWorldVolume, //mother volume
false, //no boolean operation
1); //copy number
// 2nd position
//
phi = phi + 90*deg;
v = G4ThreeVector(-std::sin(phi), std::cos(phi),0.);
w = G4ThreeVector( std::cos(phi), std::sin(phi),0.);
G4RotationMatrix rotm2 = G4RotationMatrix(u, v, w);
G4RotationMatrix* rotm2Inv = new G4RotationMatrix(rotm2.inverse());
G4ThreeVector position2 = og*w;
new G4PVPlacement(rotm2Inv, //rotation
position2, //position
fTrdVolume, //logical volume
"Trd", //name
fWorldVolume, //mother volume
false, //no boolean operation
2); //copy number
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void TrDetectorConstruction::PlaceWithAxialRotations()
{
G4double og = 3*cm;
// 1st position (with first G4PVPlacement constructor)
//
G4double phi = 30*deg, theta = 90*deg;
G4RotationMatrix rotm1 = G4RotationMatrix();
rotm1.rotateY(theta);
rotm1.rotateZ(phi);
G4cout << "\n --> phi = " << phi/deg << " deg; direct rotation matrix : ";
rotm1.print(G4cout);
G4ThreeVector w = G4ThreeVector(std::cos(phi), std::sin(phi),0.);
G4ThreeVector position1 = og*w;
G4Transform3D transform1(rotm1,position1);
new G4PVPlacement(transform1, //rotation,position
fTrdVolume, //logical volume
"Trd", //name
fWorldVolume, //mother volume
false, //no boolean operation
1); //copy number
// 2nd position (with second G4PVPlacement constructor)
//
phi = phi + 90*deg;
//rotm2Inv could be calculated with rotm2.inverse()
//but also by the following :
G4RotationMatrix* rotm2Inv = new G4RotationMatrix();
rotm2Inv->rotateZ(-phi);
rotm2Inv->rotateY(-theta);
w = G4ThreeVector(std::cos(phi), std::sin(phi),0.);
G4ThreeVector position2 = og*w;
new G4PVPlacement(rotm2Inv, //rotation
position2, //position
fTrdVolume, //logical volume
"Trd", //name
fWorldVolume, //mother volume
false, //no boolean operation
2); //copy number
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void TrDetectorConstruction::PlaceWithEulerAngles()
{
//definitions : mother frame = {x,y,z} ; daughter frame = {u,v,w}
// n = node line = intercept of xy and uv planes
// phi_euler = (x,n) : precession
// theta_euler = (z,w) : nutation
// psi_euler = (n,u) : proper rotation
G4double og = 3*cm;
// 1st position (with first G4PVPlacement constructor)
//
G4double phi = 30*deg;
G4double phi_euler = phi + pi/2;
G4double theta_euler = 90*deg;
G4double psi_euler = -90*deg;
//attention : clhep Euler constructor build inverse matrix !
G4RotationMatrix rotm1Inv = G4RotationMatrix(phi_euler,theta_euler,psi_euler);
G4RotationMatrix rotm1 = rotm1Inv.inverse();
//remark : could be built as rotm1 = G4RotationMatrix(-psi, -theta, -phi)
G4cout << "\n --> phi = " << phi/deg << " deg; direct rotation matrix : ";
rotm1.print(G4cout);
G4ThreeVector w = G4ThreeVector(std::cos(phi), std::sin(phi),0.);
G4ThreeVector position1 = og*w;
G4Transform3D transform1 = G4Transform3D(rotm1,position1);
new G4PVPlacement(transform1, //position, rotation
fTrdVolume, //logical volume
"Trd", //name
fWorldVolume, //mother volume
false, //no boolean operation
1); //copy number
// 2nd position (with second G4PVPlacement constructor)
//
phi = phi + 90*deg;
phi_euler = phi + pi/2;
G4RotationMatrix* rotm2Inv
= new G4RotationMatrix(phi_euler,theta_euler,psi_euler);
w = G4ThreeVector(std::cos(phi), std::sin(phi),0.);
G4ThreeVector position2 = og*w;
new G4PVPlacement(rotm2Inv, //rotation
position2, //position
fTrdVolume, //logical volume
"Trd", //name
fWorldVolume, //mother volume
false, //no boolean operation
2); //copy number
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void TrDetectorConstruction::PlaceWithReflections()
{
/// Placement with reflcetions.
/// In order to better show the reflection symmetry we do not apply
/// the rotation along Y axis.
G4double og = 3*cm;
// Place first two positionz in z = - 3cm
//
// 1st position
G4double phi = 30*deg;
G4RotationMatrix rotm1;
//rotm1.rotateY(90*deg);
rotm1.rotateZ(phi);
G4ThreeVector uz = G4ThreeVector(std::cos(phi), std::sin(phi), 0);
G4ThreeVector position = og*uz;
G4Transform3D transform1(rotm1,position);
G4Transform3D translateZ = HepGeom::Translate3D(0, 0, -3.*cm);
new G4PVPlacement(translateZ * transform1, //rotation,position
fTrdVolume, //logical volume
"Trd", //name
fWorldVolume, //mother volume
false, //no boolean operation
1); //copy number
// 2nd position
phi = phi + pi/2 ;
G4RotationMatrix rotm2;
//rotm2.rotateY(90*deg);
rotm2.rotateZ(phi);
uz = G4ThreeVector(std::cos(phi), std::sin(phi), 0.);
position = og*uz;
G4Transform3D transform2 = G4Transform3D(rotm2, position);
new G4PVPlacement(translateZ * transform2, //rotation, position
fTrdVolume, //logical volume
"Trd", //name
fWorldVolume, //mother volume
false, //no boolean operation
2); //copy number
// Place next two positionz in z = + 3cm with reflection
//
// 3rd position
translateZ = HepGeom::Translate3D(0, 0, +3.*cm);
G4Transform3D reflect3D = HepGeom::ReflectZ3D();
G4ReflectionFactory::Instance()
->Place(translateZ * transform1 * reflect3D, //rotation,position
"Trd", //name
fTrdVolume, //logical volume
fWorldVolume, //mother volume
false, //no boolean operation
3); //copy number
// 4rd position
G4ReflectionFactory::Instance()
->Place( translateZ * transform2 * reflect3D,//rotation,position
"Trd", //name
fTrdVolume, //logical volume
fWorldVolume, //mother volume
false, //no boolean operation
4); //copy number
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,88 @@
//
// ********************************************************************
// * 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$
//
/// \file TrDetectorConstructionMessenger.cc
/// \brief Implementation of the TrDetectorConstructionMessenger class
#include "TrDetectorConstructionMessenger.hh"
#include "TrDetectorConstruction.hh"
#include "G4UIdirectory.hh"
#include "G4UIcmdWithAString.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
TrDetectorConstructionMessenger::TrDetectorConstructionMessenger(
TrDetectorConstruction* detectorConstruction)
: G4UImessenger(),
fDetectorConstruction(detectorConstruction),
fDirectory(0),
fSetMethodCmd(0)
{
fDirectory = new G4UIdirectory("/transform/");
fDirectory->SetGuidance("Transform example detector control");
fSetMethodCmd
= new G4UIcmdWithAString("/transform/setMethod",this);
fSetMethodCmd->SetGuidance("Select method for definition of transformations.");
fSetMethodCmd->SetParameterName("Method", false);
fSetMethodCmd->SetCandidates(
"WithDirectMatrix WithInverseMatrix WithAxialRotations WithEulerAngles WithReflections");
fSetMethodCmd->AvailableForStates(G4State_PreInit);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
TrDetectorConstructionMessenger::~TrDetectorConstructionMessenger()
{
delete fDirectory;
delete fSetMethodCmd;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void TrDetectorConstructionMessenger::SetNewValue(G4UIcommand* command,
G4String newValue)
{
if( command == fSetMethodCmd ) {
TrDetectorConstruction::EMethod method;
if ( newValue == "WithDirectMatrix" )
method = TrDetectorConstruction::kWithDirectMatrix;
else if ( newValue == "WithInverseMatrix" )
method = TrDetectorConstruction::kWithInverseMatrix;
else if ( newValue == "WithAxialRotations" )
method = TrDetectorConstruction::kWithAxialRotations;
else if ( newValue == "WithEulerAngles" )
method = TrDetectorConstruction::kWithEulerAngles;
else if ( newValue == "WithReflections" )
method = TrDetectorConstruction::kWithReflections;
else return;
fDetectorConstruction->SetMethod(method);
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......