Import Geant4 11.0.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2021-06-25 16:12:29 +02:00
parent c968e26a39
commit 6399a014b6
4200 changed files with 207479 additions and 237366 deletions
@@ -0,0 +1,48 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
/// \file VG01ActionInitialization.cc
/// \brief Implementation of the VG01ActionInitialization class
#include "VG01ActionInitialization.hh"
#include "VG01PrimaryGeneratorAction.hh"
VG01ActionInitialization::VG01ActionInitialization()
: G4VUserActionInitialization()
{}
VG01ActionInitialization::~VG01ActionInitialization()
{}
void VG01ActionInitialization::BuildForMaster() const
{
}
void VG01ActionInitialization::Build() const
{
SetUserAction(new VG01PrimaryGeneratorAction);
}
@@ -0,0 +1,136 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// Authors: J. Apostolakis & S. Wenzel (CERN) 2018-2021
//
// Derived from FullCMS code by Mihaly Novak (2017-18)
#include "VG01DetectorConstruction.hh"
#include "globals.hh"
#include "G4SystemOfUnits.hh"
#include "G4VisAttributes.hh"
#include "G4UniformMagField.hh"
#include "G4FieldManager.hh"
#include "G4TransportationManager.hh"
#include "G4VPhysicalVolume.hh"
#include "G4RunManager.hh"
#include "VG01DetectorMessenger.hh"
#include "G4RunManager.hh"
#include "G4TransportationManager.hh"
#include "G4PropagatorInField.hh"
#include "G4VecGeomConverter.h"
#include <VecGeom/management/GeoManager.h>
G4double VG01DetectorConstruction::fglobFieldValue = 0.0;
VG01DetectorConstruction::VG01DetectorConstruction()
: G4VUserDetectorConstruction(), fWorld(nullptr), fFieldMgr(nullptr),
fUniformMagField(nullptr), fDetectorMessenger(nullptr)
{
fGDMLFileName = "TestNTST.gdml";
fDetectorMessenger = new VG01DetectorMessenger(this);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
VG01DetectorConstruction::~VG01DetectorConstruction() {
delete fDetectorMessenger;
if (fUniformMagField) {
delete fUniformMagField;
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4VPhysicalVolume* VG01DetectorConstruction::Construct() {
// parser.SetOverlapCheck(true);
G4TransportationManager *trMgr =
G4TransportationManager::GetTransportationManager();
assert(trMgr);
fParser.Read(fGDMLFileName, false);
fWorld = (G4VPhysicalVolume *)fParser.GetWorldVolume();
// enabling 'check' mode in G4 Navigator
G4Navigator *nav = trMgr->GetNavigatorForTracking();
assert(nav);
nav->CheckMode(true);
// nav->SetVerboseLevel(1);
std::cout << "Enabled Check mode in G4Navigator";
// write back
// fParser.Write("out.gdml", fWorld);
fFieldMgr = trMgr->GetFieldManager();
fWorld->GetLogicalVolume()->SetVisAttributes(G4VisAttributes::GetInvisible());
if (fWorld==nullptr) {
G4ExceptionDescription ed;
ed << "World volume not set properly check your setup selection criteria"
<< "or GDML input!" << G4endl;
G4Exception( "VG01DetectorConstruction::Construct()",
"G4VecGeomNavExtExample_0001", FatalException, ed );
}
CreateMagFieldAndIntegrator();
if (fUseVecGeom) {
// This is converting the geometry to VecGeom and implicitely also setting
// the navigator; We should pull this out really
G4VecGeomConverter::Instance().SetVerbose(1);
G4VecGeomConverter::Instance().ConvertG4Geometry(fWorld);
G4cout << vecgeom::GeoManager::Instance().getMaxDepth() << "\n";
}
return fWorld;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void VG01DetectorConstruction::CreateMagFieldAndIntegrator()
{
delete fUniformMagField;
if (std::abs(fglobFieldValue)>0.0) {
// Apply a global uniform magnetic field along the Z axis.
// Note: only when the magnetic field (pointer) is NOT zero,
// does the Geant4 transportion in field get activated.
fUniformMagField =
new G4UniformMagField(G4ThreeVector(0.0,0.0,fglobFieldValue));
fFieldMgr->SetDetectorField(fUniformMagField);
fFieldMgr->CreateChordFinder(fUniformMagField);
G4cout << G4endl
<< " *** SETTING MAGNETIC FIELD in Z direction : fieldValue = "
<< fglobFieldValue / tesla << " tesla *** " << G4endl << G4endl;
}
else
{
fFieldMgr->SetDetectorField(nullptr);
G4cout << G4endl
<< " *** NO MAGNETIC FIELD SET *** " << G4endl
<< G4endl;
}
}
@@ -0,0 +1,84 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// Authors: J. Apostolakis & S. Wenzel (CERN) 2018-2021
//
// Started from FullCMS code by Mihaly Novak (CERN) 2017
#include "VG01DetectorMessenger.hh"
#include "VG01DetectorConstruction.hh"
#include "G4UIdirectory.hh"
#include "G4UIcmdWithADoubleAndUnit.hh"
#include "G4UIcmdWithAString.hh"
#include "globals.hh"
VG01DetectorMessenger::
VG01DetectorMessenger( VG01DetectorConstruction* myDet )
: G4UImessenger(), fDetector( myDet )
{
fDetectorDir = new G4UIdirectory( "/mydet/" );
fDetectorDir->SetGuidance( "Detector control." );
fFieldCommand = new G4UIcmdWithADoubleAndUnit( "/mydet/setField", this );
fFieldCommand->SetGuidance( "Define uniform magnetic field along Z." );
fFieldCommand->SetGuidance( " -> in unit of [Tesla]" );
fFieldCommand->SetParameterName( "By", false );
fFieldCommand->SetDefaultValue( 0.0 );
fFieldCommand->SetUnitCategory( "Magnetic flux density" );
fFieldCommand->AvailableForStates( G4State_PreInit, G4State_Idle );
fGDMLCommand = new G4UIcmdWithAString( "/mydet/setGdmlFile", this );
fGDMLCommand->SetGuidance( "Set the GDML file." );
fGDMLCommand->SetDefaultValue( "TestNTST.gdml" );
fGDMLCommand->AvailableForStates( G4State_PreInit, G4State_Idle );
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
VG01DetectorMessenger::~VG01DetectorMessenger() {
delete fFieldCommand;
delete fDetectorDir;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void VG01DetectorMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
{
if ( command == fFieldCommand ) {
fDetector->SetMagFieldValue(fFieldCommand->GetNewDoubleValue(newValue));
}
else
{
if ( command == fGDMLCommand ) {
fDetector->SetGDMLFileName( newValue );
} else {
G4cerr << "VG01DetectorMessenger: ERROR> Unknown command " << G4endl;
}
}
}
@@ -0,0 +1,113 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
/// \file geometry/VecGeomNavigation/src/VG01PrimaryGeneratorAction.cc
/// \brief Implementation of the VG01PrimaryGeneratorAction class
//
// Authors: J. Apostolakis & S. Wenzel (CERN) 2018-2021
//
// Started from FullCMS code by Mihaly Novak (CERN) 2017
#include "VG01PrimaryGeneratorAction.hh"
#include "G4Event.hh"
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"
#include "G4SystemOfUnits.hh"
#include "G4RandomDirection.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
VG01PrimaryGeneratorAction::VG01PrimaryGeneratorAction( EGeneratorMode mode )
: G4VUserPrimaryGeneratorAction(),
fParticleGun(0),
fMode(mode)
{
G4int n_particle = 1;
fParticleGun = new G4ParticleGun(n_particle);
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
G4String particleName;
fParticleGun->SetParticleDefinition(
particleTable->FindParticle(particleName="geantino"));
fParticleGun->SetParticleEnergy(1.0*GeV);
fParticleGun->SetParticlePosition(G4ThreeVector(0,0,0) ); // -1.2*m, 0.1, 0.1));
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
VG01PrimaryGeneratorAction::~VG01PrimaryGeneratorAction()
{
delete fParticleGun;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void VG01PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
G4ThreeVector dir(1.0,0.0,0.0);
// G4ThreeVector FixedMode[3] =
// { G4ThreeVector(1,0,0), G4ThreeVector(1,0.1,0), G4ThreeVector( 1, 0, 0.1)};
G4ThreeVector AxisModeVectors[3] =
{ G4ThreeVector(1,0,0), G4ThreeVector(0,1,0), G4ThreeVector( 0, 0, 1.0)};
if( fMode == kFreeMode ){
// Do not fix the direction
// -- UI commands to particle mode can change it!
fParticleGun->GeneratePrimaryVertex(anEvent);
return;
//----
}
else if( fMode == kFixedMode )
{
G4int i = anEvent->GetEventID() % 3;
dir= G4ThreeVector(1.0,0.0,0.0);
switch(i)
{
case 0:
break;
case 1:
dir.setY(0.1);
break;
case 2:
dir.setZ(0.1);
break;
}
}
else if( fMode == kUniformMode )
{
dir = G4RandomDirection();
}
else if ( fMode == kAxisMode )
{
G4int i = anEvent->GetEventID() % 3;
dir = AxisModeVectors[i];
}
fParticleGun->SetParticleMomentumDirection(dir);
fParticleGun->GeneratePrimaryVertex(anEvent);
}
@@ -0,0 +1,227 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
// Author : J. Apostolakis, (EP/SFT CERN) 2019-21
//
// Refines the existing G4SteppingVerbose, adding:
// - direction of particle
// - safety (at step's start point)
#include "VG01SteppingVerboseWithDir.hh"
#include "G4SteppingManager.hh"
#include "G4UnitsTable.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
VG01SteppingVerboseWithDir::VG01SteppingVerboseWithDir()
: G4SteppingVerbose()
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
VG01SteppingVerboseWithDir::~VG01SteppingVerboseWithDir()
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void VG01SteppingVerboseWithDir::Banner()
{
G4cout << G4endl;
G4cout << std::setw( 5) << "Step#" << " "
<< std::setw( 9) << "X (mm)" << " "
<< std::setw( 9) << "Y (mm)" << " "
<< std::setw( 9) << "Z (mm)" << " "
<< std::setw(11) << "Ek (MeV)" << " "
<< std::setw( 8) << "dE (MeV)" << " "
<< std::setw( 7) << "Step(mm)" << " "
<< std::setw(12) << "Track(mm)" << " "
<< std::setw( 7) << "Safety(mm)" << " | "
<< std::setw(11) << " Dir.x " << " "
<< std::setw(11) << " Dir.y " << " "
<< std::setw(11) << " Dir.z " << " | "
<< std::setw(15) << "Material"
<< std::setw(14) << "Process"
<< std::setw(15) << "NextVolu"
<< G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void VG01SteppingVerboseWithDir::StepInfo()
{
CopyState();
G4int prec = G4cout.precision(6);
if( verboseLevel >= 1 ){
if( verboseLevel >= 4 ) VerboseTrack();
if( verboseLevel >= 3 ){ Banner(); }
G4cout << std::setw( 5)<<fTrack->GetCurrentStepNumber() << " "
<< std::setw( 9)<<fTrack->GetPosition().x() / CLHEP::mm << " "
<< std::setw( 9)<<fTrack->GetPosition().y() / CLHEP::mm << " "
<< std::setw( 9)<<fTrack->GetPosition().z() / CLHEP::mm << " " // << " Ek = "
<< std::setw(11)<<fTrack->GetKineticEnergy() / CLHEP::MeV << " ";
G4cout.precision(3);
G4cout << std::setw( 8)<<fStep->GetTotalEnergyDeposit() / CLHEP::MeV << " "
<< std::setw( 7)<<fStep->GetStepLength() / CLHEP::mm << " ";
G4cout.precision(6);
G4cout << std::setw(12)<<fTrack->GetTrackLength() / CLHEP::mm << " ";
G4cout.precision(5);
G4StepPoint* preStepPt= fTrack->GetStep()->GetPreStepPoint();
if( preStepPt != nullptr ) {
G4double safety = preStepPt->GetSafety();
G4cout << std::setw( 8) << ( (safety > 1.0e-9) ? safety : 0.0 ) << " ";
} else {
G4cout << std::setw( 8) << "-0.0_(N/A)" << " ";
}
G4cout << "| ";
G4cout << std::setw(11)<<fTrack->GetMomentumDirection().x() << " "
<< std::setw(11)<<fTrack->GetMomentumDirection().y() << " "
<< std::setw(11)<<fTrack->GetMomentumDirection().z() << " | ";
G4cout << std::setw(15) << fTrack->GetMaterial()->GetName() << " ";
G4VProcess const* pds= fStep->GetPostStepPoint()->GetProcessDefinedStep();
G4cout << std::setw(14) << ( ( pds != nullptr) ? pds->GetProcessName() :
G4String( "User Limit") ) << " ";
// if( fStepStatus != fWorldBoundary){
if( fTrack->GetNextVolume() != nullptr ) {
G4cout << std::setw(10) << fTrack->GetNextVolume()->GetName();
G4cout << std::setw( 4) << fTrack->GetNextVolume()->GetCopyNo();
} else {
G4cout << std::setw(10) << "OutOfWorld";
}
G4cout << " ";
G4cout << G4endl;
if( verboseLevel == 2 ){
G4int tN2ndariesTot = fN2ndariesAtRestDoIt +
fN2ndariesAlongStepDoIt +
fN2ndariesPostStepDoIt;
if(tN2ndariesTot>0){
G4cout << " :----- List of 2ndaries - "
<< "#SpawnInStep=" << std::setw(3) << tN2ndariesTot
<< "(Rest=" << std::setw(2) << fN2ndariesAtRestDoIt
<< ",Along=" << std::setw(2) << fN2ndariesAlongStepDoIt
<< ",Post=" << std::setw(2) << fN2ndariesPostStepDoIt
<< "), "
<< "#SpawnTotal=" << std::setw(3) << (*fSecondary).size()
<< " ---------------"
<< G4endl;
for(size_t lp1=(*fSecondary).size()-tN2ndariesTot;
lp1<(*fSecondary).size(); lp1++){
G4cout << " : "
<< std::setw(8)
<< (*fSecondary)[lp1]->GetPosition().x() / CLHEP::mm << " "
<< std::setw(8)
<< (*fSecondary)[lp1]->GetPosition().y() / CLHEP::mm << " "
<< std::setw(8)
<< (*fSecondary)[lp1]->GetPosition().z() / CLHEP::mm << " "
<< std::setw(8)
<< (*fSecondary)[lp1]->GetKineticEnergy() / CLHEP::MeV << " "
<< std::setw(10)
<< (*fSecondary)[lp1]->GetDefinition()->GetParticleName() << " ";
G4cout << G4endl;
}
G4cout << " :-----------------------------"
<< "----------------------------------"
<< "-- EndOf2ndaries Info ---------------"
<< G4endl;
}
}
}
G4cout.precision(prec);
// G4cout<< "exit VG01SteppingVerboseWithDir::StepInfo " <<G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void VG01SteppingVerboseWithDir::TrackingStarted()
{
CopyState();
G4int prec = G4cout.precision(6);
if( verboseLevel > 0 ){
Banner();
G4cout << std::setw( 5)<<fTrack->GetCurrentStepNumber() << " "
<< std::setw( 9)<<fTrack->GetPosition().x() / CLHEP::mm << " "
<< std::setw( 9)<<fTrack->GetPosition().y() / CLHEP::mm << " "
<< std::setw( 9)<<fTrack->GetPosition().z() / CLHEP::mm << " " // << " E_0 = "
<< std::setw(11)<<fTrack->GetKineticEnergy() / CLHEP::MeV << " ";
// << " ( = " << std::setw(8) << G4BestUnit(fTrack->GetKineticEnergy(),"Energy") << " ) "
G4cout.precision(3);
G4cout << std::setw( 8) << fStep->GetTotalEnergyDeposit() / CLHEP::MeV << " "
<< std::setw( 7) << fStep->GetStepLength() / CLHEP::mm << " ";
G4cout.precision(6);
G4cout << std::setw(12) << fTrack->GetTrackLength() / CLHEP::mm << " ";
G4Step const* step= fTrack->GetStep();
G4StepPoint const * preStepPt= nullptr;
if( step != nullptr )
preStepPt =fTrack->GetStep()->GetPreStepPoint();
if( preStepPt != nullptr ) {
G4double safety = preStepPt->GetSafety();
G4cout << std::setw( 8) << ( (safety > 1.0e-9) ? safety : 0.0 ) << " ";
} else {
G4cout << std::setw( 8) << "N/A" << " ";
}
G4cout << "| ";
G4cout << std::setw(11) << fTrack->GetMomentumDirection().x() << " "
<< std::setw(11) << fTrack->GetMomentumDirection().y() << " "
<< std::setw(11) << fTrack->GetMomentumDirection().z() << " | ";
// Material and volume name
if(fTrack->GetVolume()){
G4Material* material = fTrack->GetVolume()->GetLogicalVolume()->GetMaterial();
if( material != nullptr ){
G4cout << std::setw(15) << material->GetName() << " ";
}
else {
G4cout << std::setw(15) << "No-Material" << " ";
}
G4cout << std::setw(14) << "initStep" << " ";
G4cout << std::setw(10) << fTrack->GetVolume()->GetName();
G4cout << std::setw( 4) << fTrack->GetVolume()->GetCopyNo() << " (initial Volume)";
} else {
G4cout << std::setw(10) << "No-Material" << " ";
G4cout << std::setw(14) << "initStep" << " ";
G4cout << std::setw(10) << "OutOfWorld" << " ";
}
// fTrack->GetMaterial() fails at track start !!!!
G4cout << G4endl;
}
G4cout.precision(prec);
}