Import Geant4 10.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-10 11:51:14 +02:00
parent e2d2f9810a
commit 286caacf06
12421 changed files with 730077 additions and 502383 deletions
@@ -23,10 +23,10 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id$
//
/// \file B4dPrimaryGeneratorAction.cc
/// \brief Implementation of the B4dPrimaryGeneratorAction class
// $Id: B4PrimaryGeneratorAction.cc 75215 2013-10-29 16:07:06Z gcosmo $
//
/// \file B4PrimaryGeneratorAction.cc
/// \brief Implementation of the B4PrimaryGeneratorAction class
#include "B4PrimaryGeneratorAction.hh"
@@ -85,9 +85,12 @@ void B4PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
worldZHalfLength = worldBox->GetZHalfLength();
}
else {
G4cerr << "World volume of box not found." << G4endl;
G4cerr << "Perhaps you have changed geometry." << G4endl;
G4cerr << "The gun will be place in the center." << G4endl;
G4ExceptionDescription msg;
msg << "World volume of box not found." << G4endl;
msg << "Perhaps you have changed geometry." << G4endl;
msg << "The gun will be place in the center.";
G4Exception("B4PrimaryGeneratorAction::GeneratePrimaries()",
"MyCode0002", JustWarning, msg);
}
// Set gun position
+70 -64
View File
@@ -23,7 +23,7 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id$
// $Id: B4RunAction.cc 75215 2013-10-29 16:07:06Z gcosmo $
//
/// \file B4RunAction.cc
/// \brief Implementation of the B4RunAction class
@@ -41,50 +41,30 @@
B4RunAction::B4RunAction()
: G4UserRunAction()
{
}
// set printing event number per each event
G4RunManager::GetRunManager()->SetPrintProgress(1);
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B4RunAction::~B4RunAction()
{
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B4RunAction::BeginOfRunAction(const G4Run* run)
{
G4cout << "### Run " << run->GetRunID() << " start." << G4endl;
//inform the runManager to save random number seed
//G4RunManager::GetRunManager()->SetRandomNumberStore(true);
// Book histograms, ntuple
//
// Create analysis manager
// The choice of analysis technology is done via selectin of a namespace
// in B4Analysis.hh
G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
G4cout << "Using " << analysisManager->GetType()
<< " analysis manager" << G4endl;
G4cout << "Using " << analysisManager->GetType() << G4endl;
// Create directories
//analysisManager->SetHistoDirectoryName("histograms");
//analysisManager->SetNtupleDirectoryName("ntuple");
// Open an output file
//
G4String fileName = "B4";
analysisManager->OpenFile(fileName);
analysisManager->SetVerboseLevel(1);
analysisManager->SetFirstHistoId(1);
// Creating histograms
// Book histograms, ntuple
//
// Creating histograms
analysisManager->CreateH1("1","Edep in absorber", 100, 0., 800*MeV);
analysisManager->CreateH1("2","Edep in gap", 100, 0., 100*MeV);
analysisManager->CreateH1("3","trackL in absorber", 100, 0., 1*m);
analysisManager->CreateH1("4","trackL in gap", 100, 0., 50*cm);
// Creating ntuple
//
analysisManager->CreateNtuple("B4", "Edep and TrackL");
@@ -97,43 +77,69 @@ void B4RunAction::BeginOfRunAction(const G4Run* run)
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B4RunAction::EndOfRunAction(const G4Run* aRun)
B4RunAction::~B4RunAction()
{
G4int nofEvents = aRun->GetNumberOfEvent();
if ( nofEvents == 0 ) return;
// print histogram statistics
//
G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
if ( analysisManager->GetH1(1) ) {
G4cout << "\n ----> print histograms statistic \n" << G4endl;
G4cout
<< " EAbs : mean = " << G4BestUnit(analysisManager->GetH1(1)->mean(), "Energy")
<< " rms = " << G4BestUnit(analysisManager->GetH1(1)->rms(), "Energy")
<< G4endl;
G4cout
<< " EGap : mean = " << G4BestUnit(analysisManager->GetH1(2)->mean(), "Energy")
<< " rms = " << G4BestUnit(analysisManager->GetH1(2)->rms(), "Energy")
<< G4endl;
G4cout
<< " LAbs : mean = " << G4BestUnit(analysisManager->GetH1(3)->mean(), "Length")
<< " rms = " << G4BestUnit(analysisManager->GetH1(3)->rms(), "Length")
<< G4endl;
G4cout
<< " LGap : mean = " << G4BestUnit(analysisManager->GetH1(4)->mean(), "Length")
<< " rms = " << G4BestUnit(analysisManager->GetH1(4)->rms(), "Length")
<< G4endl;
}
// save histograms
//
analysisManager->Write();
analysisManager->CloseFile();
// complete cleanup
//
delete G4AnalysisManager::Instance();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B4RunAction::BeginOfRunAction(const G4Run* /*run*/)
{
//inform the runManager to save random number seed
//G4RunManager::GetRunManager()->SetRandomNumberStore(true);
// Get analysis manager
G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
// Open an output file
//
G4String fileName = "B4";
analysisManager->OpenFile(fileName);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B4RunAction::EndOfRunAction(const G4Run* /*run*/)
{
// print histogram statistics
//
G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
if ( analysisManager->GetH1(1) ) {
G4cout << "\n ----> print histograms statistic ";
if(isMaster) {
G4cout << "for the entire run \n" << G4endl;
}
else {
G4cout << "for the local thread \n" << G4endl;
}
G4cout << " EAbs : mean = "
<< G4BestUnit(analysisManager->GetH1(1)->mean(), "Energy")
<< " rms = "
<< G4BestUnit(analysisManager->GetH1(1)->rms(), "Energy") << G4endl;
G4cout << " EGap : mean = "
<< G4BestUnit(analysisManager->GetH1(2)->mean(), "Energy")
<< " rms = "
<< G4BestUnit(analysisManager->GetH1(2)->rms(), "Energy") << G4endl;
G4cout << " LAbs : mean = "
<< G4BestUnit(analysisManager->GetH1(3)->mean(), "Length")
<< " rms = "
<< G4BestUnit(analysisManager->GetH1(3)->rms(), "Length") << G4endl;
G4cout << " LGap : mean = "
<< G4BestUnit(analysisManager->GetH1(4)->mean(), "Length")
<< " rms = "
<< G4BestUnit(analysisManager->GetH1(4)->rms(), "Length") << G4endl;
}
// save histograms & ntuple
//
analysisManager->Write();
analysisManager->CloseFile();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,63 @@
//
// ********************************************************************
// * 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: B4dActionInitialization.cc 68058 2013-03-13 14:47:43Z gcosmo $
//
/// \file B4dActionInitialization.cc
/// \brief Implementation of the B4dActionInitialization class
#include "B4dActionInitialization.hh"
#include "B4PrimaryGeneratorAction.hh"
#include "B4RunAction.hh"
#include "B4dEventAction.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B4dActionInitialization::B4dActionInitialization()
: G4VUserActionInitialization()
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B4dActionInitialization::~B4dActionInitialization()
{;}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B4dActionInitialization::BuildForMaster() const
{
SetUserAction(new B4RunAction);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B4dActionInitialization::Build() const
{
SetUserAction(new B4PrimaryGeneratorAction);
SetUserAction(new B4RunAction);
SetUserAction(new B4dEventAction);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -23,7 +23,7 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id$
// $Id: B4dDetectorConstruction.cc 77601 2013-11-26 17:08:44Z gcosmo $
//
/// \file B4dDetectorConstruction.cc
/// \brief Implementation of the B4dDetectorConstruction class
@@ -37,7 +37,8 @@
#include "G4LogicalVolume.hh"
#include "G4PVPlacement.hh"
#include "G4PVReplica.hh"
#include "G4UniformMagField.hh"
#include "G4GlobalMagFieldMessenger.hh"
#include "G4AutoDelete.hh"
#include "G4SDManager.hh"
#include "G4SDChargedFilter.hh"
@@ -49,41 +50,26 @@
#include "G4VisAttributes.hh"
#include "G4Colour.hh"
#include "G4FieldManager.hh"
#include "G4TransportationManager.hh"
#include "G4GenericMessenger.hh"
#include "G4PhysicalConstants.hh"
#include "G4SystemOfUnits.hh"
#include <stdio.h>
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4ThreadLocal
G4GlobalMagFieldMessenger* B4dDetectorConstruction::fMagFieldMessenger = 0;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B4dDetectorConstruction::B4dDetectorConstruction()
: G4VUserDetectorConstruction(),
fMessenger(0),
fMagField(0),
fCheckOverlaps(true)
{
// Define /B4/det commands using generic messenger class
fMessenger
= new G4GenericMessenger(this, "/B4/det/", "Detector construction control");
// Define /B4/det/setMagField command
G4GenericMessenger::Command& setMagFieldCmd
= fMessenger->DeclareMethod("setMagField",
&B4dDetectorConstruction::SetMagField,
"Define magnetic field value (in X direction");
setMagFieldCmd.SetUnitCategory("Magnetic flux density");
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B4dDetectorConstruction::~B4dDetectorConstruction()
{
delete fMagField;
delete fMessenger;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -95,7 +81,6 @@ G4VPhysicalVolume* B4dDetectorConstruction::Construct()
// Define volumes
return DefineVolumes();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -104,8 +89,7 @@ void B4dDetectorConstruction::DefineMaterials()
{
// Lead material defined using NIST Manager
G4NistManager* nistManager = G4NistManager::Instance();
G4bool fromIsotopes = false;
nistManager->FindOrBuildMaterial("G4_Pb", fromIsotopes);
nistManager->FindOrBuildMaterial("G4_Pb");
// Liquid argon material
G4double a; // mass of a mole;
@@ -143,9 +127,10 @@ G4VPhysicalVolume* B4dDetectorConstruction::DefineVolumes()
G4Material* gapMaterial = G4Material::GetMaterial("liquidArgon");
if ( ! defaultMaterial || ! absorberMaterial || ! gapMaterial ) {
G4cerr << "Cannot retrieve materials already defined. " << G4endl;
G4cerr << "Exiting application " << G4endl;
exit(1);
G4ExceptionDescription msg;
msg << "Cannot retrieve materials already defined.";
G4Exception("B4DetectorConstruction::DefineVolumes()",
"MyCode0001", FatalException, msg);
}
//
@@ -227,7 +212,7 @@ G4VPhysicalVolume* B4dDetectorConstruction::DefineVolumes()
= new G4LogicalVolume(
absorberS, // its solid
absorberMaterial, // its material
"Abso"); // its name
"AbsoLV"); // its name
new G4PVPlacement(
0, // no rotation
@@ -250,7 +235,7 @@ G4VPhysicalVolume* B4dDetectorConstruction::DefineVolumes()
= new G4LogicalVolume(
gapS, // its solid
gapMaterial, // its material
"Gap"); // its name
"GapLV"); // its name
new G4PVPlacement(
0, // no rotation
@@ -272,43 +257,6 @@ G4VPhysicalVolume* B4dDetectorConstruction::DefineVolumes()
<< gapThickness/mm << "mm of " << gapMaterial->GetName() << " ] "
<< "\n------------------------------------------------------------\n";
//
// Scorers
//
// declare Absorber as a MultiFunctionalDetector scorer
//
G4MultiFunctionalDetector* absDetector
= new G4MultiFunctionalDetector("Absorber");
G4VPrimitiveScorer* primitive;
G4SDChargedFilter* charged = new G4SDChargedFilter("chargedFilter");
primitive = new G4PSEnergyDeposit("Edep");
absDetector->RegisterPrimitive(primitive);
primitive = new G4PSTrackLength("TrackLength");
primitive ->SetFilter(charged);
absDetector->RegisterPrimitive(primitive);
G4SDManager::GetSDMpointer()->AddNewDetector(absDetector);
absorberLV->SetSensitiveDetector(absDetector);
// declare Gap as a MultiFunctionalDetector scorer
//
G4MultiFunctionalDetector* gapDetector
= new G4MultiFunctionalDetector("Gap");
primitive = new G4PSEnergyDeposit("Edep");
gapDetector->RegisterPrimitive(primitive);
primitive = new G4PSTrackLength("TrackLength");
primitive ->SetFilter(charged);
gapDetector->RegisterPrimitive(primitive);
G4SDManager::GetSDMpointer()->AddNewDetector(gapDetector);
gapLV->SetSensitiveDetector(gapDetector);
//
// Visualization attributes
//
@@ -326,25 +274,55 @@ G4VPhysicalVolume* B4dDetectorConstruction::DefineVolumes()
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B4dDetectorConstruction::SetMagField(G4double fieldValue)
void B4dDetectorConstruction::ConstructSDandField()
{
// Apply a global uniform magnetic field along X axis
G4FieldManager* fieldManager
= G4TransportationManager::GetTransportationManager()->GetFieldManager();
G4SDManager::GetSDMpointer()->SetVerboseLevel(1);
//
// Scorers
//
// Delete the existing magnetic field
if ( fMagField ) delete fMagField;
// declare Absorber as a MultiFunctionalDetector scorer
//
G4MultiFunctionalDetector* absDetector
= new G4MultiFunctionalDetector("Absorber");
if ( fieldValue != 0. ) {
// create a new one if not null
fMagField
= new G4UniformMagField(G4ThreeVector(fieldValue, 0., 0.));
fieldManager->SetDetectorField(fMagField);
fieldManager->CreateChordFinder(fMagField);
}
else {
fMagField = 0;
fieldManager->SetDetectorField(fMagField);
}
G4VPrimitiveScorer* primitive;
primitive = new G4PSEnergyDeposit("Edep");
absDetector->RegisterPrimitive(primitive);
primitive = new G4PSTrackLength("TrackLength");
G4SDChargedFilter* charged = new G4SDChargedFilter("chargedFilter");
primitive ->SetFilter(charged);
absDetector->RegisterPrimitive(primitive);
SetSensitiveDetector("AbsoLV",absDetector);
// declare Gap as a MultiFunctionalDetector scorer
//
G4MultiFunctionalDetector* gapDetector
= new G4MultiFunctionalDetector("Gap");
primitive = new G4PSEnergyDeposit("Edep");
gapDetector->RegisterPrimitive(primitive);
primitive = new G4PSTrackLength("TrackLength");
primitive ->SetFilter(charged);
gapDetector->RegisterPrimitive(primitive);
SetSensitiveDetector("GapLV",gapDetector);
//
// Magnetic field
//
// Create global magnetic field messenger.
// Uniform magnetic field is then created automatically if
// the field value is not zero.
G4ThreeVector fieldValue = G4ThreeVector();
fMagFieldMessenger = new G4GlobalMagFieldMessenger(fieldValue);
fMagFieldMessenger->SetVerboseLevel(1);
// Register the field messenger for deleting
G4AutoDelete::Register(fMagFieldMessenger);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+35 -43
View File
@@ -23,7 +23,7 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id$
// $Id: B4dEventAction.cc 75604 2013-11-04 13:17:26Z gcosmo $
//
/// \file B4dEventAction.cc
/// \brief Implementation of the B4dEventAction class
@@ -35,7 +35,6 @@
#include "G4Event.hh"
#include "G4SDManager.hh"
#include "G4HCofThisEvent.hh"
#include "G4GenericMessenger.hh"
#include "G4UnitsTable.hh"
#include "Randomize.hh"
@@ -45,47 +44,39 @@
B4dEventAction::B4dEventAction()
: G4UserEventAction(),
fMessenger(0),
fPrintModulo(1)
{
// Define /B4/event commands using generic messenger class
fMessenger = new G4GenericMessenger(this, "/B4/event/", "Event control");
// Define /B4/event/setPrintModulo command
G4GenericMessenger::Command& setPrintModulo
= fMessenger->DeclareProperty("setPrintModulo",
fPrintModulo,
"Print events modulo n");
setPrintModulo.SetRange("value>0");
}
fAbsoEdepHCID(-1),
fGapEdepHCID(-1),
fAbsoTrackLengthHCID(-1),
fGapTrackLengthHCID(-1)
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
B4dEventAction::~B4dEventAction()
{
delete fMessenger;
}
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4THitsMap<G4double>*
B4dEventAction::GetHitsCollection(const G4String& hcName,
B4dEventAction::GetHitsCollection(G4int hcID,
const G4Event* event) const
{
G4int hcID
= G4SDManager::GetSDMpointer()->GetCollectionID(hcName);
G4THitsMap<G4double>* hitsCollection
= static_cast<G4THitsMap<G4double>*>(
event->GetHCofThisEvent()->GetHC(hcID));
if ( ! hitsCollection ) {
G4cerr << "Cannot access hitsCollection " << hcName << G4endl;
exit(1);
G4ExceptionDescription msg;
msg << "Cannot access hitsCollection ID " << hcID;
G4Exception("B4dEventAction::GetHitsCollection()",
"MyCode0003", FatalException, msg);
}
return hitsCollection;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4double B4dEventAction::GetSum(G4THitsMap<G4double>* hitsMap) const
{
G4double sumValue = 0;
@@ -119,33 +110,34 @@ void B4dEventAction::PrintEventStatistics(
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B4dEventAction::BeginOfEventAction(const G4Event* event)
{
G4int eventID = event->GetEventID();
if ( eventID % fPrintModulo == 0 ) {
G4cout << "\n---> Begin of event: " << eventID << G4endl;
//CLHEP::HepRandom::showEngineStatus();
}
}
void B4dEventAction::BeginOfEventAction(const G4Event* /*event*/)
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void B4dEventAction::EndOfEventAction(const G4Event* event)
{
// Get sum value from hits collections
// Get hist collections IDs
if ( fAbsoEdepHCID == -1 ) {
fAbsoEdepHCID
= G4SDManager::GetSDMpointer()->GetCollectionID("Absorber/Edep");
fGapEdepHCID
= G4SDManager::GetSDMpointer()->GetCollectionID("Gap/Edep");
fAbsoTrackLengthHCID
= G4SDManager::GetSDMpointer()->GetCollectionID("Absorber/TrackLength");
fGapTrackLengthHCID
= G4SDManager::GetSDMpointer()->GetCollectionID("Gap/TrackLength");
}
// Get sum values from hits collections
//
G4double absoEdep
= GetSum(GetHitsCollection("Absorber/Edep", event));
G4double gapEdep
= GetSum(GetHitsCollection("Gap/Edep", event));
G4double absoEdep = GetSum(GetHitsCollection(fAbsoEdepHCID, event));
G4double gapEdep = GetSum(GetHitsCollection(fGapEdepHCID, event));
G4double absoTrackLength
= GetSum(GetHitsCollection("Absorber/TrackLength", event));
= GetSum(GetHitsCollection(fAbsoTrackLengthHCID, event));
G4double gapTrackLength
= GetSum(GetHitsCollection("Gap/TrackLength", event));
= GetSum(GetHitsCollection(fGapTrackLengthHCID, event));
// get analysis manager
G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
@@ -168,9 +160,9 @@ void B4dEventAction::EndOfEventAction(const G4Event* event)
//print per event (modulo n)
//
G4int eventID = event->GetEventID();
if ( eventID % fPrintModulo == 0) {
G4int printModulo = G4RunManager::GetRunManager()->GetPrintProgress();
if ( ( printModulo > 0 ) && ( eventID % printModulo == 0 ) ) {
G4cout << "---> End of event: " << eventID << G4endl;
PrintEventStatistics(absoEdep, absoTrackLength, gapEdep, gapTrackLength);
}
}