Import Geant4 11.2.0 source tree

This commit is contained in:
Gabriele Cosmo
2023-12-08 10:43:34 +01:00
parent dd1f179cda
commit 860a2b92bf
3962 changed files with 139318 additions and 164259 deletions
@@ -1,5 +1,5 @@
#---Adding all polarisation examples subdirectories explicitly
cmake_minimum_required(VERSION 3.16...3.21)
cmake_minimum_required(VERSION 3.16...3.27)
add_subdirectory(Pol01)
+5
View File
@@ -5,6 +5,11 @@ which **must** added in reverse chronological order (newest at the top). It must
be used as a substitute for writing good git commit messages!
## 2023-11-15 I. Hrivnacova (exPolarisation-V11-01-00)
- Updated vis.mac macros:
- Changed "/vis/open XYZ [600x600-0+0]" to "/vis/open" to allow run-time choices
and simplified comments.
## 2021-12-10 Ben Morgan (exPolarisation-V11-00-00)
- Change to new Markdown History format
@@ -1,6 +1,6 @@
#----------------------------------------------------------------------------
# Setup the project
cmake_minimum_required(VERSION 3.16...3.21)
cmake_minimum_required(VERSION 3.16...3.27)
project(Pol01)
#----------------------------------------------------------------------------
@@ -40,7 +40,7 @@ target_link_libraries(Pol01 ${Geant4_LIBRARIES} )
# relies on these scripts being in the current working directory.
#
set(Pol01_SCRIPTS
heprep2.mac histo.mac histos.mac pol01.in pol01.out vis.mac
histos.mac pol01.in pol01.out vis.mac plotResults.C
)
foreach(_script ${Pol01_SCRIPTS})
@@ -5,6 +5,21 @@ which **must** added in reverse chronological order (newest at the top). It must
be used as a substitute for writing good git commit messages!
## 2023-07-16 Vladimir Ivanchenko (expol01-V11-01-01)
- removed annoining printout for the default macro
## 2023-07-05 Igor Semeniouk (expol01-V11-01-00)
- Pol01 update to allow run in mt mode
- added ActionInitialization class
- Pol01.cc - default run manager and initialization via ActionInitialization
- RunAction - Updated save histograms logic, scaling in master only
- The file histo.mac - removed ( not working )
- Convert classes ProcessesCount, RunAction::ParticleStatistics
to user defined accumulables.
- Add the root macro plotResults.C
- DetectorConstruction use GeometryHasBeenModified(), not recreate
the geometry in material definition.
## 2021-12-10 Ben Morgan (expol01-V11-00-00)
- Change to new Markdown History format
+10 -12
View File
@@ -40,9 +40,7 @@
#include "PhysicsList.hh"
#include "PrimaryGeneratorAction.hh"
#include "RunAction.hh"
#include "EventAction.hh"
#include "SteppingAction.hh"
#include "ActionInitialization.hh"
#include "G4VisExecutive.hh"
#include "G4UIExecutive.hh"
@@ -57,21 +55,21 @@ int main(int argc,char** argv) {
ui = new G4UIExecutive(argc, argv);
}
// Construct a serial run manager
auto* runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::SerialOnly);
//Creating run manager
auto runManager = G4RunManagerFactory::CreateRunManager();
if (argc==3) {
G4int nThreads = G4UIcommand::ConvertToInt(argv[2]);
runManager->SetNumberOfThreads(nThreads);
}
// set mandatory initialization classes
DetectorConstruction* det = new DetectorConstruction();
runManager->SetUserInitialization(det);
runManager->SetUserInitialization(new PhysicsList());
PrimaryGeneratorAction* prim = new PrimaryGeneratorAction(det);
runManager->SetUserAction(prim);
// set user action classes
RunAction* run;
runManager->SetUserAction(run = new RunAction(det,prim));
runManager->SetUserAction(new EventAction(run));
runManager->SetUserAction(new SteppingAction(det,prim,run));
// User action initialization
runManager->SetUserInitialization(new ActionInitialization(det));
// get the pointer to the User Interface manager
G4UImanager* UImanager = G4UImanager::GetUIpointer();
@@ -1,40 +0,0 @@
#
# Macro file for A01app
#
/control/verbose 2
/run/verbose 2
#
/run/initialize
#
# Create empty scene ("world" is default)
#
/vis/scene/create pol01.heprep.gz
#
# Create a scene handler for a specific graphics system
# Edit the next line(s) to choose another graphic system
#
/vis/open HepRepXML
/vis/viewer/set/culling global false
/vis/viewer/zoom 1.4
/vis/viewer/set/viewpointThetaPhi 60 25 deg
/vis/viewer/flush
#/vis/viewer/zoom 0.0001
#/vis/viewer/set/viewpointThetaPhi 90 90.0001 deg
#/vis/scene/endOfEventAction accumulate
#
# Add volume to scene
#
/vis/scene/add/volume
#
# Add trajectories to scene
#
/vis/scene/add/trajectories
#
# Add hits to scene
#
/vis/scene/add/hits
#
# Do runs
#
/tracking/storeTrajectory 1
/run/beamOn 20
@@ -1,48 +0,0 @@
#
# Macro file for "Pol01.cc"
# (can be run in batch, without graphic)
#
/control/verbose 2
/run/verbose 2
#
#/testem/det/setMat Tungsten
/testem/det/setMat Iron
/testem/det/setSizeZ 1.75 mm
/testem/phys/addPhysics polarized
#/testem/phys/addPhysics standard
/run/printProgress 5000
#
/run/initialize
#
/polarization/manager/verbose 1
/polarization/volume/set theBox 0. 0. 0.08
/polarization/volume/list
#
#/process/inactivate pol-eIoni
#/process/inactivate pol-eBrem
#/process/inactivate pol-compt
#
/gun/polarization 0. 0. -1.
/gun/particle gamma
#
/gun/energy 10 MeV
#
##/tracking/verbose 1
##/run/beamOn 1
#
/analysis/setFileName polar
/analysis/h1/set 1 110 0 11 MeV #gamma energy
/analysis/h1/set 2 100 -1. 1. #gamma cos(theta)
/analysis/h1/set 3 100 -180. 180. deg #gamma phi
/analysis/h1/set 4 100 -1.5 1.5 #gamma polarization
/analysis/h1/set 5 110 0 11 MeV #electron energy
/analysis/h1/set 6 100 -1. 1. #electron cos(theta)
/analysis/h1/set 7 100 -180. 180. deg #electron phi
/analysis/h1/set 8 100 -1.5 1.5 #electron polarization
/analysis/h1/set 9 110 0 11 MeV #positron energy
/analysis/h1/set 10 100 -1. 1. none #positron cos(theta)
/analysis/h1/set 11 100 -180. 180. deg #positron phi
/analysis/h1/set 12 100 -1.5 1.5 #positron polarization
#
/run/beamOn 10000
#
@@ -0,0 +1,54 @@
//
// ********************************************************************
// * 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 POl01/include/ActionInitialization.hh
/// \brief Definition of the ActionInitialization class
#ifndef ActionInitialization_h
#define ActionInitialization_h 1
#include "G4VUserActionInitialization.hh"
class DetectorConstruction;
/// Action initialization class.
class ActionInitialization : public G4VUserActionInitialization
{
public:
ActionInitialization(DetectorConstruction*);
~ActionInitialization() override = default;
void BuildForMaster() const override;
void Build() const override;
private:
DetectorConstruction* fDetector;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#endif
@@ -51,7 +51,8 @@ public:
public:
G4VPhysicalVolume* Construct();
G4VPhysicalVolume* Construct() override;
void ConstructSDandField() override;
void SetSizeXY (G4double);
void SetSizeZ (G4double);
@@ -70,6 +71,10 @@ public:
G4double GetBoxSizeZ() {return fBoxSizeZ;};
G4Material* GetMaterial() {return fTargetMaterial;};
private:
void ConstructMaterials();
void PrintParameters();
private:
@@ -33,29 +33,32 @@
#ifndef ProcessesCount_HH
#define ProcessesCount_HH
#include "G4VAccumulable.hh"
#include "globals.hh"
#include <vector>
#include <map>
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
class ProcessCount
class ProcessesCount : public G4VAccumulable
{
public:
ProcessCount(G4String name) {fName=name; fCounter=0;};
~ProcessCount() {};
public:
G4String GetName() {return fName;};
G4int GetCounter() {return fCounter;};
void Count() {fCounter++;};
private:
G4String fName; // process name
G4int fCounter; // process counter
public:
ProcessesCount() = delete;
ProcessesCount(const G4String& name);
~ProcessesCount() = default;
G4int GetCounter(const G4String& procName) { return fProcCounter[procName]; };
void Count(const G4String& procName);
void Print();
void Merge(const G4VAccumulable&) override;
void Reset() override { fProcCounter.clear(); }
private:
std::map<G4String, G4int> fProcCounter;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
typedef std::vector<ProcessCount*> ProcessesCount;
#endif
@@ -35,7 +35,7 @@
#include "G4UserRunAction.hh"
#include "G4AnalysisManager.hh"
#include "ProcessesCount.hh"
#include "G4VAccumulable.hh"
#include "globals.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -49,15 +49,17 @@ class G4ParticleDefinition;
class RunAction : public G4UserRunAction
{
class ParticleStatistics {
class ParticleStatistics : public G4VAccumulable {
public:
ParticleStatistics();
ParticleStatistics(const G4String& name);
~ParticleStatistics();
void EventFinished();
void FillData(G4double kinEnergy, G4double costheta,
G4double longitudinalPolarization);
void PrintResults(G4int totalNumberOfEvents);
void Clear();
void Reset() override;
void Merge(const G4VAccumulable& other) override;
private:
G4int fCurrentNumber;
G4int fTotalNumber, fTotalNumber2;
@@ -68,13 +70,13 @@ class RunAction : public G4UserRunAction
public:
RunAction(DetectorConstruction*, PrimaryGeneratorAction*);
RunAction(DetectorConstruction*, PrimaryGeneratorAction* = nullptr);
virtual ~RunAction();
virtual void BeginOfRunAction(const G4Run*);
virtual void EndOfRunAction(const G4Run*);
void CountProcesses(G4String);
void CountProcesses(G4String&);
void FillData(const G4ParticleDefinition* particle,
G4double kinEnergy, G4double costheta, G4double phi,
@@ -93,15 +95,10 @@ private:
DetectorConstruction* fDetector;
PrimaryGeneratorAction* fPrimary;
ProcessesCount* fProcCounter;
G4AnalysisManager* fAnalysisManager;
G4int fTotalEventCount;
ParticleStatistics fPhotonStats;
ParticleStatistics fElectronStats;
ParticleStatistics fPositronStats;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,21 @@
void plotResults(const char* fname = "polar.root") {
// Open a ROOT file and read histograms
TFile myfile(fname,"READ");
TH1D* histo[12];
for (Int_t j=0; j<12;j++)
histo[j] = (TH1D *) myfile.Get(Form("h%d",j+1));
// Produce a plot
TCanvas *c1 = new TCanvas("c1","The Pol01 example",1200,900);
gStyle->SetOptStat(0);
c1->Divide(4,3);
for (Int_t j=0; j<12;j++) {
c1->cd(j+1);
histo[j]->ls();
histo[j]->DrawCopy();
}
c1->Update();
}
@@ -3,13 +3,14 @@
# (can be run in batch, without graphic, without analysis)
#
/control/verbose 2
/run/verbose 2
/control/cout/ignoreThreadsExcept 0
/run/verbose 1
#
/testem/det/setMat G4_Fe
/testem/det/setSizeZ 1.75 mm
/testem/phys/addPhysics polarized
#/testem/phys/addPhysics standard
/run/printProgress 5000
/run/printProgress 500
#
/run/initialize
/run/setCut 0.1 mm
+33 -68
View File
@@ -1,3 +1,4 @@
Environment variable "G4FORCE_RUN_MANAGER_TYPE" enabled with value == Serial. Forcing G4RunManager type...
############################################
!!! WARNING - FPE detection is activated !!!
@@ -10,7 +11,7 @@
**************************************************************
Geant4 version Name: geant4-11-01-ref-06 (30-June-2023)
Geant4 version Name: geant4-11-02-ref-00 (8-December-2023)
Copyright : Geant4 Collaboration
References : NIM A 506 (2003), 250-303
: IEEE-TNS 53 (2006), 270-278
@@ -18,27 +19,20 @@
WWW : http://geant4.org/
**************************************************************
... set ntuple merging row mode : row-wise - done
... create file : pol01.root - done
... open analysis file : pol01.root - done
... open analysis file : pol01.root - done
/run/verbose 2
/control/cout/ignoreThreadsExcept 0
/run/verbose 1
#
/testem/det/setMat G4_Fe
/testem/det/setSizeZ 1.75 mm
/run/geometryModified
/testem/phys/addPhysics polarized
PhysicsList::AddPhysicsList: <polarized>
#/testem/phys/addPhysics standard
/run/printProgress 5000
/run/printProgress 500
#
/run/initialize
userDetector->Construct() start.
The Box is 5 cm x 5 cm x 1.75 mm of G4_Fe
World is registered to the default region.
physicsList->Construct() start.
physicsList->CheckParticleList() start.
physicsList->setCut() start.
/run/setCut 0.1 mm
#
/polarization/manager/verbose 1
@@ -173,19 +167,6 @@ pol-eIoni: for e+ XStype:3 SubType=2
===== EM models for the G4Region DefaultRegionForTheWorld ======
PolarizedMollerBhabha : Emin= 0 eV Emax= 100 TeV
Region <DefaultRegionForTheWorld> -- -- appears in <World> world volume
This region is in the mass world.
Root logical volume(s) : World
Pointers : G4VUserRegionInformation[0], G4UserLimits[0], G4FastSimulationManager[0], G4UserSteppingAction[0]
Materials : G4_Galactic G4_Fe
Production cuts : gamma 100 um e- 100 um e+ 100 um proton 100 um
Region <DefaultRegionForParallelWorld> -- -- is not associated to any world.
Root logical volume(s) :
Pointers : G4VUserRegionInformation[0], G4UserLimits[0], G4FastSimulationManager[0], G4UserSteppingAction[0]
Materials :
Production cuts : gamma 100 um e- 100 um e+ 100 um proton 100 um
========= Table of registered couples ============================
Index : 0 used in the geometry : Yes
@@ -204,31 +185,43 @@ Index : 1 used in the geometry : Yes
==================================================================
Start closing geometry.
G4GeometryManager::ReportVoxelStats -- Voxel Statistics
Total memory consumed for geometry optimisation: 0 kByte
Total CPU time elapsed for geometry optimisation: 0 seconds
### Run 0 starts.
### Run 0 start.
... set ntuple merging row mode : row-wise - done
... create file : pol01.root - done
... open analysis file : pol01.root - done
... open analysis file : pol01.root - done
--> Event 0 starts.
--> Event 500 starts.
--> Event 1000 starts.
--> Event 1500 starts.
--> Event 2000 starts.
--> Event 2500 starts.
--> Event 3000 starts.
--> Event 3500 starts.
--> Event 4000 starts.
--> Event 4500 starts.
--> Event 5000 starts.
--> Event 5500 starts.
--> Event 6000 starts.
--> Event 6500 starts.
--> Event 7000 starts.
--> Event 7500 starts.
--> Event 8000 starts.
--> Event 8500 starts.
--> Event 9000 starts.
--> Event 9500 starts.
Run terminated.
Run Summary
Number of events processed : 10000
User=0.060000s Real=0.055713s Sys=0.000000s
User=0.110000s Real=0.140173s Sys=0.000000s
The run consists of 10000 gamma of 10 MeV through 1.75 mm of G4_Fe (density: 7.874 g/cm3 )
Process calls frequency --->
Transportation = 31124
pol-conv = 219
msc = 1691
pol-eIoni = 684
pol-eBrem = 325
pol-annihil = 66
pol-compt = 280
pol-phot = 176
Transportation= 31124 msc= 1691 pol-annihil= 66
pol-compt= 280 pol-conv= 219 pol-eBrem= 325
pol-eIoni= 684 pol-phot= 176
Gamma:
Mean Number per Event :1.0054
Mean Energy :9.6029 MeV +- 1.8442 MeV
@@ -241,6 +234,7 @@ Mean Polarization :-0.73452 +- 0.28136
Mean Number per Event :0.0156
Mean Energy :4.0642 MeV +- 1.9962 MeV
Mean Polarization :-0.57169 +- 0.33581
... write file : pol01.root - done
... close file : pol01.root - done
... delete empty file : pol01.root - done
@@ -251,36 +245,7 @@ mixmax state, file version 1.0
N=17 V[N]={847175755666492636, 1425179808836154274, 1647568236133457718, 1084436876417971381, 166440695823598628, 1332950029560277730, 1392569583841259893, 1534215877070228699, 1030844911574454052, 17057310262608394, 1951505961711811416, 566340641376567458, 1168380125282625022, 345267671194425884, 25187549425416789, 310131633279191295, 1262900853831910112} counter= 11sumtot= 2273095466006287675
---------------------------------------
#
G4 kernel has come to Quit state.
UserDetectorConstruction deleted.
UserPhysicsList deleted.
UserActionInitialization deleted.
UserWorkerInitialization deleted.
UserWorkerThreadInitialization deleted.
UserRunAction deleted.
UserPrimaryGenerator deleted.
RunManager is deleting RunManagerKernel.
G4SDManager deleted.
EventManager deleted.
Units table cleared.
TransportationManager deleted.
Total navigation history collections cleaned: 7
G4RNGHelper object is deleted.
================== Deleting memory pools ===================
Pool ID '20G4NavigationLevelRep', size : 0.00769 MB
Pool ID '24G4ReferenceCountedHandleIvE', size : 0.000961 MB
Pool ID '7G4Event', size : 0.000961 MB
Pool ID '15G4PrimaryVertex', size : 0.000961 MB
Pool ID '17G4PrimaryParticle', size : 0.000961 MB
Pool ID '17G4DynamicParticle', size : 0.00192 MB
Pool ID '7G4Track', size : 0.00288 MB
Pool ID '18G4TouchableHistory', size : 0.000961 MB
Pool ID '15G4CountedObjectIvE', size : 0.000961 MB
Number of memory pools allocated: 9 of which, static: 0
Dynamic pools deleted: 9 / Total memory freed: 0.018 MB
============================================================
G4Allocator objects are deleted.
UImanager deleted.
StateManager deleted.
RunManagerKernel is deleted. Good bye :)
RunManager is deleted.
@@ -0,0 +1,68 @@
//
// ********************************************************************
// * 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 Pol01/src/ActionInitialization.cc
/// \brief Implementation of the ActionInitialization class
#include "ActionInitialization.hh"
#include "DetectorConstruction.hh"
#include "EventAction.hh"
#include "PrimaryGeneratorAction.hh"
#include "RunAction.hh"
#include "SteppingAction.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ActionInitialization::ActionInitialization(DetectorConstruction* det)
: G4VUserActionInitialization(), fDetector(det)
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ActionInitialization::BuildForMaster() const
{
auto runAction = new RunAction(fDetector);
SetUserAction(runAction);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ActionInitialization::Build() const
{
PrimaryGeneratorAction* prim = new PrimaryGeneratorAction(fDetector);
SetUserAction(prim);
// set user action classes
RunAction* run = new RunAction(fDetector, prim);
SetUserAction(run);
SetUserAction(new EventAction(run));
SetUserAction(new SteppingAction(fDetector, prim, run));
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -38,6 +38,7 @@
#include "G4LogicalVolume.hh"
#include "G4PVPlacement.hh"
#include "G4RunManager.hh"
#include "G4GeometryManager.hh"
#include "G4PhysicalVolumeStore.hh"
#include "G4LogicalVolumeStore.hh"
@@ -58,29 +59,42 @@ DetectorConstruction::DetectorConstruction()
fBoxSizeXY = 50*mm;
fBoxSizeZ = 5*mm;
fWorldSize = 1.*m;
SetTargetMaterial("G4_Fe");
SetWorldMaterial("G4_Galactic");
ConstructMaterials();
fMessenger = new DetectorMessenger(this);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
DetectorConstruction::~DetectorConstruction()
{
{
delete fMessenger;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::ConstructMaterials()
{
auto nistManager = G4NistManager::Instance();
fTargetMaterial = nistManager->FindOrBuildMaterial("G4_Fe");
if(fTargetMaterial == nullptr) {
G4cerr << "### ERROR - Material: <"
<< "G4_Fe" << "> not found" << G4endl;
}
fWorldMaterial = nistManager->FindOrBuildMaterial("G4_Galactic");
if(fWorldMaterial == nullptr) {
G4cerr << "### ERROR - Material: <"
<< "G4_Galactic" << "> not found" << G4endl;
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4LogicalVolume* lBox;
G4VPhysicalVolume* DetectorConstruction::Construct()
{
// Cleanup old geometry
G4GeometryManager::GetInstance()->OpenGeometry();
G4PhysicalVolumeStore::GetInstance()->Clean();
G4LogicalVolumeStore::GetInstance()->Clean();
G4SolidStore::GetInstance()->Clean();
G4PolarizationManager::GetInstance()->Clean();
// G4PolarizationManager::GetInstance()->Clean();
// World
//
@@ -88,7 +102,7 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
sWorld = new G4Box("World", //name
fWorldSize/2,fWorldSize/2,fWorldSize/2); //dimensions
G4LogicalVolume*
G4LogicalVolume*
lWorld = new G4LogicalVolume(sWorld, //shape
fWorldMaterial, //material
"World"); //name
@@ -100,14 +114,14 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
0, //mother volume
false, //no boolean operation
0); //copy number
// Box
//
//
G4Box*
sBox = new G4Box("Container", //its name
fBoxSizeXY/2.,fBoxSizeXY/2.,fBoxSizeZ/2.);//its dimensions
G4LogicalVolume*
//G4LogicalVolume*
lBox = new G4LogicalVolume(sBox, //its shape
fTargetMaterial, //its material
"theBox"); //its name
@@ -120,12 +134,8 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
false, //no boolean operation
0); //copy number
// register logical Volume in PolarizationManager with zero polarization
G4PolarizationManager * polMgr = G4PolarizationManager::GetInstance();
polMgr->SetVolumePolarization(lBox,G4ThreeVector(0.,0.,0.));
PrintParameters();
//always return the root volume
//
return fWorld;
@@ -133,6 +143,15 @@ G4VPhysicalVolume* DetectorConstruction::Construct()
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::ConstructSDandField()
{
// register logical Volume in PolarizationManager with zero polarization
G4PolarizationManager * polMgr = G4PolarizationManager::GetInstance();
polMgr->SetVolumePolarization(lBox,G4ThreeVector(0.,0.,0.));
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void DetectorConstruction::PrintParameters()
{
G4cout << "\n The Box is " << G4BestUnit(fBoxSizeXY,"Length")
@@ -151,11 +170,12 @@ void DetectorConstruction::SetTargetMaterial(G4String materialChoice)
if (mat != fTargetMaterial) {
if(mat) {
fTargetMaterial = mat;
G4RunManager::GetRunManager()->PhysicsHasBeenModified();
UpdateGeometry();
} else {
G4cout << "### Warning! Target material: <"
<< materialChoice << "> not found" << G4endl;
}
<< materialChoice << "> not found" << G4endl;
}
}
}
@@ -169,11 +189,12 @@ void DetectorConstruction::SetWorldMaterial(G4String materialChoice)
if (mat != fWorldMaterial) {
if(mat) {
fWorldMaterial = mat;
G4RunManager::GetRunManager()->PhysicsHasBeenModified();
UpdateGeometry();
} else {
G4cout << "### Warning! World material: <"
<< materialChoice << "> not found" << G4endl;
}
<< materialChoice << "> not found" << G4endl;
}
}
}
@@ -181,14 +202,14 @@ void DetectorConstruction::SetWorldMaterial(G4String materialChoice)
void DetectorConstruction::SetSizeXY(G4double value)
{
fBoxSizeXY = value;
fBoxSizeXY = value;
if (fWorldSize<fBoxSizeXY) fWorldSize = 1.2*fBoxSizeXY;
UpdateGeometry();
}
void DetectorConstruction::SetSizeZ(G4double value)
{
fBoxSizeZ = value;
fBoxSizeZ = value;
if (fWorldSize<fBoxSizeZ) fWorldSize = 1.2*fBoxSizeZ;
UpdateGeometry();
}
@@ -199,8 +220,9 @@ void DetectorConstruction::SetSizeZ(G4double value)
void DetectorConstruction::UpdateGeometry()
{
if (fWorld)
G4RunManager::GetRunManager()->DefineWorldVolume(Construct());
// if (fWorld)
// G4RunManager::GetRunManager()->DefineWorldVolume(Construct());
G4RunManager::GetRunManager()->GeometryHasBeenModified();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,79 @@
//
// ********************************************************************
// * 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 polarisation/Pol01/src/ProcessesCount.cc
/// \brief Implementation of the ProcessesCount class
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "ProcessesCount.hh"
#include <iomanip>
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ProcessesCount::ProcessesCount(const G4String& name) : G4VAccumulable(name) {}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ProcessesCount::Count(const G4String& procName)
{
if (const auto& [it, inserted] = fProcCounter.try_emplace(procName, 1); !inserted) {
it->second++; // Exists already
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ProcessesCount::Print()
{
G4int index = 0;
std::map<G4String, G4int>::iterator it;
for (it = fProcCounter.begin(); it != fProcCounter.end(); it++) {
G4String procName = it->first;
G4int count = it->second;
G4cout << " " << std::setw(20) << procName << "=" << std::setw(7) << count
<< (++index % 3 == 0 ? "\n" : " ");
}
G4cout << G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ProcessesCount::Merge(const G4VAccumulable& other)
{
auto worker = dynamic_cast<const ProcessesCount&>(other);
for (const auto& proc : worker.fProcCounter) {
const auto& [it, inserted] = fProcCounter.emplace(proc);
if (!inserted) {
it->second += proc.second; // proc exists already in master
}
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -26,7 +26,7 @@
/// \file polarisation/Pol01/src/RunAction.cc
/// \brief Implementation of the RunAction class
//
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -49,19 +49,32 @@
#include "G4PhysicalConstants.hh"
#include <iomanip>
#include "ProcessesCount.hh"
#include "G4AccumulableManager.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
RunAction::RunAction(DetectorConstruction* det, PrimaryGeneratorAction* prim)
: G4UserRunAction(),
fGamma(0), fElectron(0), fPositron(0),
fDetector(det), fPrimary(prim), fProcCounter(0), fAnalysisManager(0),
fTotalEventCount(0),
fPhotonStats(), fElectronStats(), fPositronStats()
: fDetector(det), fPrimary(prim), fAnalysisManager(0),
fTotalEventCount(0)
{
fGamma = G4Gamma::Gamma();
fElectron = G4Electron::Electron();
fPositron = G4Positron::Positron();
auto accumulableManager = G4AccumulableManager::Instance();
auto fPhotonStats = new ParticleStatistics("PhotonStats");
auto fElectronStats = new ParticleStatistics("ElectronStats");
auto fPositronStats = new ParticleStatistics("PositronStats");
auto fProcCounter = new ProcessesCount("ProcCounter");
accumulableManager->RegisterAccumulable(fPhotonStats);
accumulableManager->RegisterAccumulable(fElectronStats);
accumulableManager->RegisterAccumulable(fPositronStats);
accumulableManager->RegisterAccumulable(fProcCounter);
BookHisto();
}
@@ -73,38 +86,40 @@ RunAction::~RunAction()
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::BeginOfRunAction(const G4Run* aRun)
{
{
G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
auto accumulableManager = G4AccumulableManager::Instance();
accumulableManager->Reset();
// save Rndm status
// G4RunManager::GetRunManager()->SetRandomNumberStore(false);
// CLHEP::HepRandom::showEngineStatus();
if (fProcCounter) delete fProcCounter;
fProcCounter = new ProcessesCount;
fTotalEventCount = 0;
fPhotonStats.Clear();
fElectronStats.Clear();
fPositronStats.Clear();
// Open file histogram file
fAnalysisManager->OpenFile();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::FillData(const G4ParticleDefinition* particle,
G4double kinEnergy, G4double costheta,
G4double kinEnergy, G4double costheta,
G4double phi,
G4double longitudinalPolarization)
{
auto accManager = G4AccumulableManager::Instance();
G4int id = -1;
if (particle == fGamma) {
fPhotonStats.FillData(kinEnergy, costheta, longitudinalPolarization);
if(fAnalysisManager) { id = 1; }
} else if (particle == fElectron) {
fElectronStats.FillData(kinEnergy, costheta, longitudinalPolarization);
if(fAnalysisManager) { id = 5; }
if (particle == fGamma) {
dynamic_cast<ParticleStatistics*>(accManager->GetAccumulable("PhotonStats"))->FillData(kinEnergy, costheta, longitudinalPolarization);
if(fAnalysisManager) { id = 1; }
} else if (particle == fElectron) {
dynamic_cast<ParticleStatistics*>(accManager->GetAccumulable("ElectronStats"))->FillData(kinEnergy, costheta, longitudinalPolarization);
if(fAnalysisManager) { id = 5; }
} else if (particle == fPositron) {
fPositronStats.FillData(kinEnergy, costheta, longitudinalPolarization);
if(fAnalysisManager) { id = 9; }
dynamic_cast<ParticleStatistics*>(accManager->GetAccumulable("PositronStats"))->FillData(kinEnergy, costheta, longitudinalPolarization);
if(fAnalysisManager) { id = 9; }
}
if(id > 0) {
fAnalysisManager->FillH1(id,kinEnergy,1.0);
@@ -125,13 +140,14 @@ void RunAction::BookHisto()
fAnalysisManager->SetVerboseLevel(1);
// Open file histogram file
fAnalysisManager->OpenFile("pol01");
fAnalysisManager->SetFileName("pol01");
fAnalysisManager->SetFirstHistoId(1);
// Creating an 1-dimensional histograms in the root directory of the tree
const G4String id[] = { "h1", "h2", "h3", "h4", "h5",
const G4String id[] = { "h1", "h2", "h3", "h4", "h5",
"h6", "h7", "h8", "h9", "h10", "h11", "h12"};
const G4String title[] =
const G4String title[] =
{ "Gamma Energy distribution", //1
"Gamma Cos(Theta) distribution", //2
"Gamma Phi angular distribution", //3
@@ -163,96 +179,101 @@ void RunAction::BookHisto()
void RunAction::SaveHisto(G4int nevents)
{
if(fAnalysisManager) {
G4double norm = 1.0/G4double(nevents);
for(int i=0; i<12; ++i) {
fAnalysisManager->ScaleH1(i, norm);
if (IsMaster()) {
G4double norm = 1.0/G4double(nevents);
for(int i=0; i<12; ++i) {
fAnalysisManager->ScaleH1(i, norm);
}
}
fAnalysisManager->Write();
fAnalysisManager->CloseFile();
}
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::CountProcesses(G4String procName)
void RunAction::CountProcesses(G4String& procName)
{
// is the process already counted ?
// *AS* change to std::map?!
size_t nbProc = fProcCounter->size();
size_t i = 0;
while ((i<nbProc)&&((*fProcCounter)[i]->GetName()!=procName)) i++;
if (i == nbProc) fProcCounter->push_back( new ProcessCount(procName));
(*fProcCounter)[i]->Count();
auto accManager = G4AccumulableManager::Instance();
dynamic_cast<ProcessesCount*>(accManager->GetAccumulable("ProcCounter"))->Count(procName);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::EndOfRunAction(const G4Run* aRun)
{
G4int NbOfEvents = aRun->GetNumberOfEvent();
// Total number of events in run (all threads)
G4int NbOfEvents = aRun->GetNumberOfEventToBeProcessed();
// G4int NbOfEvents = aRun->GetNumberOfEvent();
if (NbOfEvents == 0) return;
G4int prec = G4cout.precision(5);
G4Material* material = fDetector->GetMaterial();
G4double density = material->GetDensity();
G4ParticleDefinition* particle =
fPrimary->GetParticleGun()->GetParticleDefinition();
G4String Particle = particle->GetParticleName();
G4double energy = fPrimary->GetParticleGun()->GetParticleEnergy();
G4cout << "\n The run consists of " << NbOfEvents << " "<< Particle << " of "
<< G4BestUnit(energy,"Energy") << " through "
<< G4BestUnit(fDetector->GetBoxSizeZ(),"Length") << " of "
<< material->GetName() << " (density: "
<< G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
//frequency of processes
G4cout << "\n Process calls frequency --->\n";
for (size_t i=0; i< fProcCounter->size();i++) {
G4String procName = (*fProcCounter)[i]->GetName();
G4int count = (*fProcCounter)[i]->GetCounter();
G4cout << "\t" << procName << " = " << count<<"\n";
}
if (fTotalEventCount == 0) return;
G4cout<<" Gamma: \n";
fPhotonStats.PrintResults(fTotalEventCount);
G4cout<<" Electron: \n";
fElectronStats.PrintResults(fTotalEventCount);
G4cout<<" Positron: \n";
fPositronStats.PrintResults(fTotalEventCount);
if (fPrimary != nullptr) {
G4ParticleDefinition* particle =
fPrimary->GetParticleGun()->GetParticleDefinition();
G4String Particle = particle->GetParticleName();
G4double energy = fPrimary->GetParticleGun()->GetParticleEnergy();
G4cout << "\n The run consists of " << fTotalEventCount << " "<< Particle << " of "
<< G4BestUnit(energy,"Energy") << " through "
<< G4BestUnit(fDetector->GetBoxSizeZ(),"Length") << " of "
<< material->GetName() << " (density: "
<< G4BestUnit(density,"Volumic Mass") << ")" << G4endl;
}
//cross check from G4EmCalculator
// G4cout << "\n Verification from G4EmCalculator. \n";
// G4cout << "\n Verification from G4EmCalculator. \n";
// G4EmCalculator emCal;
//restore default format
G4cout.precision(prec);
auto accManager = G4AccumulableManager::Instance();
accManager->Merge();
// write out histograms
if (IsMaster()) {
//frequency of processes
G4cout << "\n Process calls frequency --->\n";
dynamic_cast<ProcessesCount*>(accManager->GetAccumulable("ProcCounter"))->Print();
G4cout<<" Gamma: \n";
dynamic_cast<ParticleStatistics*>(accManager->GetAccumulable("PhotonStats"))->PrintResults(NbOfEvents);
G4cout<<" Electron: \n";
dynamic_cast<ParticleStatistics*>(accManager->GetAccumulable("ElectronStats"))->PrintResults(NbOfEvents);
G4cout<<" Positron: \n";
dynamic_cast<ParticleStatistics*>(accManager->GetAccumulable("PositronStats"))->PrintResults(NbOfEvents);
G4cout<<G4endl;
}
//restore default format
G4cout.precision(prec);
// write out histograms
SaveHisto(NbOfEvents);
if (IsMaster()) {
// show Rndm status
CLHEP::HepRandom::showEngineStatus();
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::EventFinished()
{
auto accManager = G4AccumulableManager::Instance();
++fTotalEventCount;
fPhotonStats.EventFinished();
fElectronStats.EventFinished();
fPositronStats.EventFinished();
dynamic_cast<ParticleStatistics*>(accManager->GetAccumulable("PhotonStats"))->EventFinished();
dynamic_cast<ParticleStatistics*>(accManager->GetAccumulable("ElectronStats"))->EventFinished();
dynamic_cast<ParticleStatistics*>(accManager->GetAccumulable("PositronStats"))->EventFinished();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
RunAction::ParticleStatistics::ParticleStatistics()
: fCurrentNumber(0),
RunAction::ParticleStatistics::ParticleStatistics(const G4String& name)
: G4VAccumulable(name),fCurrentNumber(0),
fTotalNumber(0), fTotalNumber2(0),
fSumEnergy(0), fSumEnergy2(0),
fSumPolarization(0), fSumPolarization2(0),
@@ -274,7 +295,7 @@ void RunAction::ParticleStatistics::EventFinished()
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::ParticleStatistics:: FillData(G4double kinEnergy,
void RunAction::ParticleStatistics:: FillData(G4double kinEnergy,
G4double costheta,
G4double longitudinalPolarization)
{
@@ -307,7 +328,7 @@ void RunAction::ParticleStatistics::PrintResults(G4int totalNumberOfEvents)
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::ParticleStatistics::Clear()
void RunAction::ParticleStatistics::Reset()
{
fCurrentNumber=0;
fTotalNumber=fTotalNumber2=0;
@@ -317,3 +338,20 @@ void RunAction::ParticleStatistics::Clear()
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void RunAction::ParticleStatistics::Merge(const G4VAccumulable& other)
{
auto rstat = dynamic_cast<const RunAction::ParticleStatistics&>(other);
fCurrentNumber += rstat.fCurrentNumber;
fTotalNumber += rstat.fTotalNumber;
fTotalNumber2 += rstat.fTotalNumber2;
fSumEnergy += rstat.fSumEnergy;
fSumEnergy2 += rstat.fSumEnergy2;
fSumPolarization += rstat.fSumPolarization;
fSumPolarization2 += rstat.fSumPolarization2;
fSumCosTheta += rstat.fSumCosTheta;
fSumCosTheta2 += rstat.fSumCosTheta2;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+5 -15
View File
@@ -10,20 +10,10 @@
#
/run/initialize
#
# Use this open statement to create an OpenGL view:
/vis/open OGL 600x600-0+0
#
# Use this open statement to create a .prim file suitable for
# viewing in DAWN:
#/vis/open DAWNFILE
#
# Use this open statement to create a .heprep file suitable for
# viewing in HepRApp:
#/vis/open HepRepFile
#
# Use this open statement to create a .wrl file suitable for
# viewing in a VRML viewer:
#/vis/open VRML2FILE
# Open a viewer
/vis/open
# This opens the default viewer - see examples/basic/B1/vis.mac for a
# more comprehensive overview of options. Also the documentation.
#
# Disable auto refresh and quieten vis messages whilst scene and
# trajectories are established:
@@ -79,5 +69,5 @@
# For file-based drivers, use this to create an empty detector view:
#/vis/viewer/flush
#
/run/beamOn 10
#/run/beamOn 10