Import Geant4 10.4.0 source tree

This commit is contained in:
Gabriele Cosmo
2017-12-08 12:52:30 +01:00
parent 98e455a940
commit fc6af9e721
2166 changed files with 276760 additions and 100873 deletions
@@ -0,0 +1,62 @@
//
// ********************************************************************
// * 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: ActionInitialization 68058 2013-03-13 14:47:43Z gcosmo $
//
/// \file ActionInitialization
/// \brief Implementation of the ActionInitialization class
#include "ActionInitialization.hh"
#include "PrimaryGeneratorAction.hh"
#include "RunAction.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ActionInitialization::ActionInitialization(const G4String& fileName)
: G4VUserActionInitialization(),
fFileName(fileName)
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ActionInitialization::~ActionInitialization()
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ActionInitialization::BuildForMaster() const
{
SetUserAction(new RunAction(fFileName));
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ActionInitialization::Build() const
{
SetUserAction(new PrimaryGeneratorAction);
SetUserAction(new RunAction(fFileName));
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,181 @@
//
// ********************************************************************
// * 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 101905 2016-12-07 11:34:39Z gunter $
//
/// \file DetectorConstruction
/// \brief Implementation of the DetectorConstruction class
#include "DetectorConstruction.hh"
#include "ScreenSD.hh"
#include "G4Material.hh"
#include "G4NistManager.hh"
#include "G4Box.hh"
#include "G4LogicalVolume.hh"
#include "G4PVPlacement.hh"
#include "G4GlobalMagFieldMessenger.hh"
#include "G4SDManager.hh"
#include "G4VisAttributes.hh"
#include "G4Colour.hh"
#include "G4SystemOfUnits.hh"
#include "G4AutoDelete.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4ThreadLocal
G4GlobalMagFieldMessenger* DetectorConstruction::fMagFieldMessenger = 0;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
DetectorConstruction::DetectorConstruction()
: G4VUserDetectorConstruction()
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
DetectorConstruction::~DetectorConstruction()
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4VPhysicalVolume* DetectorConstruction::Construct()
{
// Get nist material manager
G4NistManager* nistManager = G4NistManager::Instance();
// Build materials
G4Material* air = nistManager->FindOrBuildMaterial("G4_AIR");
G4Material* csi = nistManager->FindOrBuildMaterial("G4_CESIUM_IODIDE");
// There is no need to test if materials were built/found
// as G4NistManager would issue an error otherwise
// Try the code with "XYZ".
// Print all materials
G4cout << *(G4Material::GetMaterialTable()) << G4endl;
// Option to switch on/off checking of volumes overlaps
G4bool checkOverlaps = true;
//
// World
//
// The world dimensions
G4double worldHxyz = 2.*m;
// world volume
G4Box* worldS = new G4Box("World", worldHxyz, worldHxyz, worldHxyz);
G4LogicalVolume* worldLV = new G4LogicalVolume(worldS, air, "World");
G4VPhysicalVolume* worldPV
= new G4PVPlacement(
0, G4ThreeVector(), worldLV, "World", 0, false, 0, checkOverlaps);
//
// Box
//
// The box dimensions
G4double boxHxy = 1.*m;
G4double boxHz = 10.*cm;
// box volume
G4Box* boxS = new G4Box("World", boxHxy, boxHxy, boxHz);
G4LogicalVolume* boxLV = new G4LogicalVolume(boxS, csi, "Box");
// The box position
G4double posz = 0.*m;
new G4PVPlacement(
0, G4ThreeVector(0, 0, posz),
boxLV, "Box", worldLV, false, 0, checkOverlaps);
//
// Scoring screen
//
// The screen dimensions
G4double screenHxy = 1.999*m;
G4double screenHz = 1.*mm;
// Screen volume
G4Box* screenS = new G4Box("World", screenHxy, screenHxy, screenHz);
G4LogicalVolume* screenLV = new G4LogicalVolume(screenS, air, "Screen");
// The screen position
posz += boxHz + screenHz;
new G4PVPlacement(
0, G4ThreeVector(0, 0, posz),
screenLV, "Screen", worldLV, false, 0, checkOverlaps);
//
// Visualization attributes
//
worldLV->SetVisAttributes(G4VisAttributes::GetInvisible());
auto simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0, 1.0, 1.0));
simpleBoxVisAtt->SetVisibility(true);
boxLV->SetVisAttributes(simpleBoxVisAtt);
screenLV->SetVisAttributes(simpleBoxVisAtt);
//
// Always return the physical World
//
return worldPV;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::ConstructSDandField()
{
// G4SDManager::GetSDMpointer()->SetVerboseLevel(1);
//
// Sensitive detectors
//
auto screenSD = new ScreenSD("ScreenSD");
G4SDManager::GetSDMpointer()->AddNewDetector(screenSD);
SetSensitiveDetector("Screen", screenSD);
//
// Magnetic field
//
// Create global magnetic field messenger.
// Uniform magnetic field is then created automatically if
// the field value is not zero.
G4ThreeVector fieldValue;
fMagFieldMessenger = new G4GlobalMagFieldMessenger(fieldValue);
fMagFieldMessenger->SetVerboseLevel(1);
// Register the field messenger for deleting
G4AutoDelete::Register(fMagFieldMessenger);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,105 @@
//
// ********************************************************************
// * 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: PrimaryGeneratorAction 100946 2016-11-03 11:28:08Z gcosmo $
//
/// \file PrimaryGeneratorAction
/// \brief Implementation of the PrimaryGeneratorAction class
#include "PrimaryGeneratorAction.hh"
#include "G4RunManager.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4LogicalVolume.hh"
#include "G4Box.hh"
#include "G4Event.hh"
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4Proton.hh"
#include "G4SystemOfUnits.hh"
#include "Randomize.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
PrimaryGeneratorAction::PrimaryGeneratorAction()
: G4VUserPrimaryGeneratorAction(),
fParticleGun(nullptr)
{
G4int nofParticles = 1;
fParticleGun = new G4ParticleGun(nofParticles);
// default particle kinematic
fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
fParticleGun->SetParticleEnergy(1.*GeV);
fParticleGun->SetParticleDefinition(G4Proton::Proton());
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
PrimaryGeneratorAction::~PrimaryGeneratorAction()
{
delete fParticleGun;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
// This function is called at the begining of event
// In order to avoid dependence of PrimaryGeneratorAction
// on DetectorConstruction class we get world volume
// from G4LogicalVolumeStore
//
G4double worldZHalfLength = 0.;
auto worldLV = G4LogicalVolumeStore::GetInstance()->GetVolume("World");
// Check that the world volume has box shape
G4Box* worldBox = nullptr;
if ( worldLV ) {
worldBox = dynamic_cast<G4Box*>(worldLV->GetSolid());
}
if ( worldBox ) {
worldZHalfLength = worldBox->GetZHalfLength();
}
else {
G4ExceptionDescription msg;
msg << "World volume of box shape not found." << G4endl;
msg << "Perhaps you have changed geometry." << G4endl;
msg << "The gun will be place in the center.";
G4Exception("PrimaryGeneratorAction::GeneratePrimaries()",
"MyCode0002", JustWarning, msg);
}
// Set gun position
fParticleGun
->SetParticlePosition(G4ThreeVector(0., 0., -worldZHalfLength));
fParticleGun->GeneratePrimaryVertex(anEvent);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,97 @@
//
// ********************************************************************
// * 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: RunAction 100946 2016-11-03 11:28:08Z gcosmo $
//
/// \file RunAction
/// \brief Implementation of the RunAction class
#include "RunAction.hh"
#include "Analysis.hh"
#include "G4Run.hh"
#include "G4RunManager.hh"
#include "G4UnitsTable.hh"
#include "G4SystemOfUnits.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
RunAction::RunAction(const G4String& fileName)
: G4UserRunAction(),
fFileName(fileName)
{
// Create analysis manager
// The choice of analysis technology is done via selectin of a namespace
// in Analysis.hh
auto analysisManager = G4AnalysisManager::Instance();
G4cout << "Using " << analysisManager->GetType() << G4endl;
analysisManager->SetVerboseLevel(1);
analysisManager->SetNtupleMerging(true);
// Note: merging ntuples is available only with Root output
// Set default fileName
analysisManager->SetFileName(fFileName);
// Create ntuple
//
analysisManager->CreateNtuple("Screen", "Screen hits");
analysisManager->CreateNtupleIColumn("ID"); // column id = 0
analysisManager->CreateNtupleIColumn("PDG"); // column id = 1
analysisManager->CreateNtupleDColumn("Ekin"); // column id = 2
analysisManager->CreateNtupleDColumn("Xpos"); // column id = 3
analysisManager->CreateNtupleDColumn("Ypos"); // column id = 4
analysisManager->CreateNtupleDColumn("time"); // column id = 5
analysisManager->FinishNtuple();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
RunAction::~RunAction()
{
delete G4AnalysisManager::Instance();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::BeginOfRunAction(const G4Run* /*run*/)
{
// Get analysis manager
auto analysisManager = G4AnalysisManager::Instance();
// Open an output file
analysisManager->OpenFile();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::EndOfRunAction(const G4Run* /*run*/)
{
// Save ntuple and close file
auto analysisManager = G4AnalysisManager::Instance();
analysisManager->Write();
analysisManager->CloseFile();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,108 @@
//
// ********************************************************************
// * 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 ScreenSD.cc
/// \brief Implementation of the ScreenSD class
//
#include "ScreenSD.hh"
#include "Analysis.hh"
#include "G4VTouchable.hh"
#include "G4Step.hh"
#include "G4ios.hh"
#include "G4SystemOfUnits.hh"
#include "G4VProcess.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ScreenSD::ScreenSD(const G4String& name)
: G4VSensitiveDetector(name)
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ScreenSD::~ScreenSD()
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ScreenSD::Initialize(G4HCofThisEvent* /*hce*/)
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4bool ScreenSD::ProcessHits(G4Step* step, G4TouchableHistory* /*history*/)
{
// Current track:
const G4Track* track = step->GetTrack();
// Track ID:
G4int ID = track->GetTrackID();
// code PDG:
G4int pdgCode = track->GetDefinition()->GetPDGEncoding();
// Remember preStepPoint:
G4StepPoint* preStepPoint = step->GetPreStepPoint();
// Ekin:
G4double Ekin = preStepPoint->GetKineticEnergy();
// Obtain local coordinates:
const G4VTouchable* touchable = preStepPoint->GetTouchable();
G4ThreeVector globalPosition = preStepPoint->GetPosition();
G4ThreeVector localPosition
= touchable->GetHistory()->GetTopTransform().TransformPoint(globalPosition);
// // Example for obtaining the local direction:
// G4ThreeVector globalDirection = preStepPoint->GetMomentumDirection();
// G4ThreeVector localDirection
// = touchable->GetHistory()->GetTopTransform().TransformAxis(localDirection);
// Time
G4double time = preStepPoint->GetGlobalTime();
// Store hit in the ntuple
G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
analysisManager->FillNtupleIColumn(0, ID);
analysisManager->FillNtupleIColumn(1, pdgCode);
analysisManager->FillNtupleDColumn(2, Ekin/MeV);
analysisManager->FillNtupleDColumn(3, localPosition.x()/cm);
analysisManager->FillNtupleDColumn(4, localPosition.y()/cm);
analysisManager->FillNtupleDColumn(5, time/ns);
analysisManager->AddNtupleRow();
return true;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ScreenSD::EndOfEvent(G4HCofThisEvent* /*hce*/)
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......