Import Geant4 10.7.0.beta source tree
This commit is contained in:
@@ -37,9 +37,6 @@
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
|
||||
|
||||
#include "TSActionInitialization.hh"
|
||||
#include "TSDetectorConstruction.hh"
|
||||
#include "TSPrimaryGeneratorAction.hh"
|
||||
@@ -53,36 +50,30 @@ TSActionInitialization* TSActionInitialization::fgInstance = 0;
|
||||
|
||||
TSActionInitialization* TSActionInitialization::Instance()
|
||||
{
|
||||
return fgInstance;
|
||||
return fgInstance;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
TSActionInitialization::TSActionInitialization()
|
||||
{
|
||||
fgInstance = this;
|
||||
}
|
||||
TSActionInitialization::TSActionInitialization() { fgInstance = this; }
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
TSActionInitialization::~TSActionInitialization()
|
||||
{
|
||||
fgInstance = 0;
|
||||
}
|
||||
TSActionInitialization::~TSActionInitialization() { fgInstance = 0; }
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void TSActionInitialization::BuildForMaster() const
|
||||
{
|
||||
SetUserAction(new TSRunAction);
|
||||
SetUserAction(new TSRunAction);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void TSActionInitialization::Build() const
|
||||
{
|
||||
SetUserAction(new TSPrimaryGeneratorAction);
|
||||
SetUserAction(new TSRunAction);
|
||||
SetUserAction(new TSPrimaryGeneratorAction);
|
||||
SetUserAction(new TSRunAction);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
@@ -51,9 +51,6 @@
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
|
||||
|
||||
#include "TSDetectorConstruction.hh"
|
||||
|
||||
#include "G4RunManager.hh"
|
||||
@@ -89,30 +86,27 @@ TSDetectorConstruction* TSDetectorConstruction::Instance()
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
TSDetectorConstruction::TSDetectorConstruction()
|
||||
: fWorldPhys(0),
|
||||
fWorldMaterialName("G4_Galactic"),
|
||||
fTargetMaterialName("G4_B"),
|
||||
fCasingMaterialName("G4_WATER"),
|
||||
fWorldDim(G4ThreeVector(0.5*m, 0.5*m, 0.5*m)),
|
||||
fTargetDim(G4ThreeVector(0.5*m, 0.5*m, 0.5*m)),
|
||||
fTargetSections(G4ThreeVector(5, 5, 5)),
|
||||
fMfdName("Target_MFD")
|
||||
: fWorldPhys(0)
|
||||
, fWorldMaterialName("G4_Galactic")
|
||||
, fTargetMaterialName("G4_B")
|
||||
, fCasingMaterialName("G4_WATER")
|
||||
, fWorldDim(G4ThreeVector(0.5 * m, 0.5 * m, 0.5 * m))
|
||||
, fTargetDim(G4ThreeVector(0.5 * m, 0.5 * m, 0.5 * m))
|
||||
, fTargetSections(G4ThreeVector(5, 5, 5))
|
||||
, fMfdName("Target_MFD")
|
||||
{
|
||||
fgInstance = this;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
TSDetectorConstruction::~TSDetectorConstruction()
|
||||
{
|
||||
fgInstance = 0;
|
||||
}
|
||||
TSDetectorConstruction::~TSDetectorConstruction() { fgInstance = 0; }
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
G4VPhysicalVolume* TSDetectorConstruction::Construct()
|
||||
{
|
||||
return ConstructWorld(ConstructMaterials());
|
||||
return ConstructWorld(ConstructMaterials());
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
@@ -120,179 +114,158 @@ G4VPhysicalVolume* TSDetectorConstruction::Construct()
|
||||
TSDetectorConstruction::MaterialCollection_t
|
||||
TSDetectorConstruction::ConstructMaterials()
|
||||
{
|
||||
MaterialCollection_t materials;
|
||||
G4NistManager* nist = G4NistManager::Instance();
|
||||
MaterialCollection_t materials;
|
||||
G4NistManager* nist = G4NistManager::Instance();
|
||||
|
||||
materials["World"] = nist->FindOrBuildMaterial(fWorldMaterialName);
|
||||
materials["Target"] = nist->FindOrBuildMaterial(fTargetMaterialName);
|
||||
materials["Casing"] = nist->FindOrBuildMaterial(fCasingMaterialName);
|
||||
materials["World"] = nist->FindOrBuildMaterial(fWorldMaterialName);
|
||||
materials["Target"] = nist->FindOrBuildMaterial(fTargetMaterialName);
|
||||
materials["Casing"] = nist->FindOrBuildMaterial(fCasingMaterialName);
|
||||
|
||||
return materials;
|
||||
return materials;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
G4VPhysicalVolume*
|
||||
TSDetectorConstruction::ConstructWorld(const MaterialCollection_t& materials)
|
||||
G4VPhysicalVolume* TSDetectorConstruction::ConstructWorld(
|
||||
const MaterialCollection_t& materials)
|
||||
{
|
||||
G4UserLimits* steplimit = new G4UserLimits(0.1*(fTargetDim.z()
|
||||
/fTargetSections.z()));
|
||||
G4bool check_overlap = false;
|
||||
G4UserLimits* steplimit =
|
||||
new G4UserLimits(0.1 * (fTargetDim.z() / fTargetSections.z()));
|
||||
G4bool check_overlap = false;
|
||||
|
||||
G4Box* world_solid = new G4Box("World",
|
||||
0.5*fWorldDim.x(),
|
||||
0.5*fWorldDim.y(),
|
||||
0.5*fWorldDim.z());
|
||||
G4LogicalVolume* world_log = new G4LogicalVolume(world_solid,
|
||||
materials.find("World")
|
||||
->second,
|
||||
"World");
|
||||
fWorldPhys = new G4PVPlacement(0,
|
||||
G4ThreeVector(0.),
|
||||
"World",
|
||||
world_log,
|
||||
0, false, 0, check_overlap);
|
||||
G4Box* world_solid = new G4Box("World", 0.5 * fWorldDim.x(),
|
||||
0.5 * fWorldDim.y(), 0.5 * fWorldDim.z());
|
||||
G4LogicalVolume* world_log =
|
||||
new G4LogicalVolume(world_solid, materials.find("World")->second, "World");
|
||||
fWorldPhys = new G4PVPlacement(0, G4ThreeVector(0.), "World", world_log, 0,
|
||||
false, 0, check_overlap);
|
||||
|
||||
G4int nz = fTargetSections.z();
|
||||
G4int ny = fTargetSections.y();
|
||||
G4int nx = fTargetSections.x();
|
||||
G4int nz = fTargetSections.z();
|
||||
G4int ny = fTargetSections.y();
|
||||
G4int nx = fTargetSections.x();
|
||||
|
||||
// spacing between sections
|
||||
G4double sx = fTargetDim.x()/fTargetSections.x();
|
||||
G4double sy = fTargetDim.y()/fTargetSections.y();
|
||||
G4double sz = fTargetDim.z()/fTargetSections.z();
|
||||
// spacing between sections
|
||||
G4double sx = fTargetDim.x() / fTargetSections.x();
|
||||
G4double sy = fTargetDim.y() / fTargetSections.y();
|
||||
G4double sz = fTargetDim.z() / fTargetSections.z();
|
||||
|
||||
//G4cout << "World has dimensions : "
|
||||
//<< G4BestUnit(fWorldDim, "Length") << G4endl;
|
||||
// G4cout << "World has dimensions : "
|
||||
//<< G4BestUnit(fWorldDim, "Length") << G4endl;
|
||||
|
||||
//------------------------------------------------------------------------//
|
||||
// Set Visual Attributes
|
||||
//------------------------------------------------------------------------//
|
||||
G4VisAttributes* red = new G4VisAttributes(G4Color(1., 0., 0., 1.0));
|
||||
G4VisAttributes* green = new G4VisAttributes(G4Color(0., 1., 0., 0.25));
|
||||
G4VisAttributes* blue = new G4VisAttributes(G4Color(0., 0., 1., 0.1));
|
||||
G4VisAttributes* white = new G4VisAttributes(G4Color(1., 1., 1., 1.));
|
||||
//------------------------------------------------------------------------//
|
||||
// Set Visual Attributes
|
||||
//------------------------------------------------------------------------//
|
||||
G4VisAttributes* red = new G4VisAttributes(G4Color(1., 0., 0., 1.0));
|
||||
G4VisAttributes* green = new G4VisAttributes(G4Color(0., 1., 0., 0.25));
|
||||
G4VisAttributes* blue = new G4VisAttributes(G4Color(0., 0., 1., 0.1));
|
||||
G4VisAttributes* white = new G4VisAttributes(G4Color(1., 1., 1., 1.));
|
||||
|
||||
white->SetVisibility(true);
|
||||
red->SetVisibility(true);
|
||||
green->SetVisibility(true);
|
||||
blue->SetVisibility(true);
|
||||
white->SetVisibility(true);
|
||||
red->SetVisibility(true);
|
||||
green->SetVisibility(true);
|
||||
blue->SetVisibility(true);
|
||||
|
||||
white->SetForceWireframe(true);
|
||||
red->SetForceSolid(true);
|
||||
green->SetForceSolid(true);
|
||||
blue->SetForceSolid(true);
|
||||
white->SetForceWireframe(true);
|
||||
red->SetForceSolid(true);
|
||||
green->SetForceSolid(true);
|
||||
blue->SetForceSolid(true);
|
||||
|
||||
world_log->SetVisAttributes(white);
|
||||
world_log->SetVisAttributes(white);
|
||||
|
||||
for(G4int k = 0; k < nz; ++k)
|
||||
for(G4int j = 0; j < ny; ++j)
|
||||
for(G4int i = 0; i < nx; ++i)
|
||||
{
|
||||
// displacement of section
|
||||
G4double dx
|
||||
= 0.5*sx + static_cast<G4double>(i)*sx - 0.5*fWorldDim.x();
|
||||
G4double dy
|
||||
= 0.5*sy + static_cast<G4double>(j)*sy - 0.5*fWorldDim.y();
|
||||
G4double dz
|
||||
= 0.5*sz + static_cast<G4double>(k)*sz - 0.5*fWorldDim.z();
|
||||
G4ThreeVector td = G4ThreeVector(dx, dy, -dz);
|
||||
// make unique name
|
||||
std::stringstream ss_name;
|
||||
ss_name << "Target_" << i << "_" << j << "_" << k;
|
||||
for(G4int k = 0; k < nz; ++k)
|
||||
for(G4int j = 0; j < ny; ++j)
|
||||
for(G4int i = 0; i < nx; ++i)
|
||||
{
|
||||
// displacement of section
|
||||
G4double dx =
|
||||
0.5 * sx + static_cast<G4double>(i) * sx - 0.5 * fWorldDim.x();
|
||||
G4double dy =
|
||||
0.5 * sy + static_cast<G4double>(j) * sy - 0.5 * fWorldDim.y();
|
||||
G4double dz =
|
||||
0.5 * sz + static_cast<G4double>(k) * sz - 0.5 * fWorldDim.z();
|
||||
G4ThreeVector td = G4ThreeVector(dx, dy, -dz);
|
||||
// make unique name
|
||||
std::stringstream ss_name;
|
||||
ss_name << "Target_" << i << "_" << j << "_" << k;
|
||||
|
||||
G4Box* target_solid = new G4Box(ss_name.str(),
|
||||
0.5*sx,
|
||||
0.5*sy,
|
||||
0.5*sz);
|
||||
G4Box* target_solid =
|
||||
new G4Box(ss_name.str(), 0.5 * sx, 0.5 * sy, 0.5 * sz);
|
||||
|
||||
G4Material* target_material = 0;
|
||||
G4bool is_casing = true;
|
||||
|
||||
G4Material* target_material = 0;
|
||||
G4bool is_casing = true;
|
||||
if(j == 0 || j + 1 == ny || i == 0 || i + 1 == nx ||
|
||||
(nz > 1 && (k == 0 || k + 1 == nz)))
|
||||
target_material = materials.find("Casing")->second;
|
||||
else
|
||||
{
|
||||
target_material = materials.find("Target")->second;
|
||||
is_casing = false;
|
||||
}
|
||||
|
||||
if(j == 0 || j+1 == ny || i == 0 || i+1 == nx ||
|
||||
(nz > 1 && (k == 0 || k+1 == nz)))
|
||||
target_material = materials.find("Casing")->second;
|
||||
else {
|
||||
target_material = materials.find("Target")->second;
|
||||
is_casing = false;
|
||||
}
|
||||
G4LogicalVolume* target_log =
|
||||
new G4LogicalVolume(target_solid, target_material, ss_name.str());
|
||||
|
||||
G4LogicalVolume* target_log =
|
||||
new G4LogicalVolume(target_solid,
|
||||
target_material,
|
||||
ss_name.str());
|
||||
target_log->SetUserLimits(steplimit);
|
||||
|
||||
target_log->SetUserLimits(steplimit);
|
||||
new G4PVPlacement(0, td, ss_name.str(), target_log, fWorldPhys, true,
|
||||
k * nx * ny + j * nx + i, check_overlap);
|
||||
|
||||
new G4PVPlacement(0,
|
||||
td,
|
||||
ss_name.str(),
|
||||
target_log,
|
||||
fWorldPhys,
|
||||
true,
|
||||
k*nx*ny + j*nx + i,
|
||||
check_overlap);
|
||||
fScoringVolumes.insert(target_log);
|
||||
|
||||
fScoringVolumes.insert(target_log);
|
||||
if(is_casing)
|
||||
target_log->SetVisAttributes(blue);
|
||||
else
|
||||
{
|
||||
// making a checkerboard for kicks...
|
||||
G4bool even_z = (k % 2 == 0) ? true : false;
|
||||
G4bool even_y = (j % 2 == 0) ? true : false;
|
||||
G4bool even_x = (i % 2 == 0) ? true : false;
|
||||
|
||||
if(is_casing)
|
||||
target_log->SetVisAttributes(blue);
|
||||
else
|
||||
{
|
||||
// making a checkerboard for kicks...
|
||||
G4bool even_z = (k%2 == 0) ? true : false;
|
||||
G4bool even_y = (j%2 == 0) ? true : false;
|
||||
G4bool even_x = (i%2 == 0) ? true : false;
|
||||
G4VisAttributes* theColor = nullptr;
|
||||
|
||||
G4VisAttributes* theColor = nullptr;
|
||||
if((even_z))
|
||||
{
|
||||
if((even_y && even_x) || (!even_y && !even_x))
|
||||
theColor = red;
|
||||
else
|
||||
theColor = green;
|
||||
}
|
||||
else // ! even_z
|
||||
{
|
||||
if((!even_y && even_x) || (even_y && !even_x))
|
||||
theColor = red;
|
||||
else
|
||||
theColor = green;
|
||||
}
|
||||
|
||||
if((even_z))
|
||||
{
|
||||
if((even_y && even_x) || (!even_y && !even_x))
|
||||
theColor = red;
|
||||
else
|
||||
theColor = green;
|
||||
} else // ! even_z
|
||||
{
|
||||
if((!even_y && even_x) || (even_y && !even_x))
|
||||
theColor = red;
|
||||
else
|
||||
theColor = green;
|
||||
}
|
||||
target_log->SetVisAttributes(theColor);
|
||||
}
|
||||
}
|
||||
|
||||
target_log->SetVisAttributes(theColor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return fWorldPhys;
|
||||
return fWorldPhys;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void TSDetectorConstruction::ConstructSDandField()
|
||||
{
|
||||
//------------------------------------------------//
|
||||
// MultiFunctionalDetector //
|
||||
//------------------------------------------------//
|
||||
// Define MultiFunctionalDetector with name.
|
||||
G4MultiFunctionalDetector* MFDet = new G4MultiFunctionalDetector(fMfdName);
|
||||
G4SDManager::GetSDMpointer()->AddNewDetector(MFDet);
|
||||
G4VPrimitiveScorer* edep = new G4PSEnergyDeposit("EnergyDeposit");
|
||||
MFDet->RegisterPrimitive(edep);
|
||||
G4VPrimitiveScorer* nstep = new G4PSNofStep("NumberOfSteps");
|
||||
MFDet->RegisterPrimitive(nstep);
|
||||
//------------------------------------------------//
|
||||
// MultiFunctionalDetector //
|
||||
//------------------------------------------------//
|
||||
// Define MultiFunctionalDetector with name.
|
||||
G4MultiFunctionalDetector* MFDet = new G4MultiFunctionalDetector(fMfdName);
|
||||
G4SDManager::GetSDMpointer()->AddNewDetector(MFDet);
|
||||
G4VPrimitiveScorer* edep = new G4PSEnergyDeposit("EnergyDeposit");
|
||||
MFDet->RegisterPrimitive(edep);
|
||||
G4VPrimitiveScorer* nstep = new G4PSNofStep("NumberOfSteps");
|
||||
MFDet->RegisterPrimitive(nstep);
|
||||
|
||||
// add scoring volumes
|
||||
for(auto ite : fScoringVolumes)
|
||||
{
|
||||
SetSensitiveDetector(ite, MFDet);
|
||||
}
|
||||
// add scoring volumes
|
||||
for(auto ite : fScoringVolumes)
|
||||
{
|
||||
SetSensitiveDetector(ite, MFDet);
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
#include "TSPhysicsList.hh"
|
||||
|
||||
#include "G4RunManager.hh"
|
||||
@@ -90,15 +89,12 @@ TSPhysicsList* TSPhysicsList::fgInstance = 0;
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
TSPhysicsList* TSPhysicsList::Instance()
|
||||
{
|
||||
return fgInstance;
|
||||
}
|
||||
TSPhysicsList* TSPhysicsList::Instance() { return fgInstance; }
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
TSPhysicsList::TSPhysicsList()
|
||||
: fDefaultCutValue(1.*CLHEP::mm)
|
||||
: fDefaultCutValue(1. * CLHEP::mm)
|
||||
{
|
||||
fgInstance = this;
|
||||
|
||||
@@ -125,67 +121,66 @@ TSPhysicsList::~TSPhysicsList()
|
||||
|
||||
void TSPhysicsList::ConstructParticle()
|
||||
{
|
||||
for(auto c : fConstructors)
|
||||
{
|
||||
c->ConstructParticle();
|
||||
}
|
||||
for(auto c : fConstructors)
|
||||
{
|
||||
c->ConstructParticle();
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void TSPhysicsList::ConstructProcess()
|
||||
{
|
||||
// Transportation
|
||||
//
|
||||
AddTransportation();
|
||||
// Transportation
|
||||
//
|
||||
AddTransportation();
|
||||
|
||||
for(auto c : fConstructors)
|
||||
for(auto c : fConstructors)
|
||||
{
|
||||
c->ConstructProcess();
|
||||
}
|
||||
|
||||
std::set<G4String> step_limit_particles;
|
||||
// standard particles
|
||||
step_limit_particles.insert("e-");
|
||||
step_limit_particles.insert("e+");
|
||||
step_limit_particles.insert("alpha");
|
||||
step_limit_particles.insert("He3");
|
||||
step_limit_particles.insert("GenericIon");
|
||||
step_limit_particles.insert("proton");
|
||||
step_limit_particles.insert("neutron");
|
||||
// more ~exotic particles
|
||||
step_limit_particles.insert("pi+");
|
||||
step_limit_particles.insert("pi-");
|
||||
step_limit_particles.insert("mu+");
|
||||
step_limit_particles.insert("mu-");
|
||||
|
||||
auto particleIterator = GetParticleIterator();
|
||||
particleIterator->reset();
|
||||
|
||||
G4PhysicsListHelper* ph = G4PhysicsListHelper::GetPhysicsListHelper();
|
||||
|
||||
while((*particleIterator)())
|
||||
{
|
||||
G4ParticleDefinition* particle = particleIterator->value();
|
||||
G4String pname = particle->GetParticleName();
|
||||
|
||||
if(step_limit_particles.find(pname) != step_limit_particles.end() ||
|
||||
particle->GetPDGCharge())
|
||||
{
|
||||
c->ConstructProcess();
|
||||
}
|
||||
|
||||
std::set<G4String> step_limit_particles;
|
||||
// standard particles
|
||||
step_limit_particles.insert("e-");
|
||||
step_limit_particles.insert("e+");
|
||||
step_limit_particles.insert("alpha");
|
||||
step_limit_particles.insert("He3");
|
||||
step_limit_particles.insert("GenericIon");
|
||||
step_limit_particles.insert("proton");
|
||||
step_limit_particles.insert("neutron");
|
||||
// more ~exotic particles
|
||||
step_limit_particles.insert("pi+");
|
||||
step_limit_particles.insert("pi-");
|
||||
step_limit_particles.insert("mu+");
|
||||
step_limit_particles.insert("mu-");
|
||||
|
||||
auto particleIterator=GetParticleIterator();
|
||||
particleIterator->reset();
|
||||
|
||||
G4PhysicsListHelper* ph = G4PhysicsListHelper::GetPhysicsListHelper();
|
||||
|
||||
while( (*particleIterator)() )
|
||||
{
|
||||
G4ParticleDefinition* particle = particleIterator->value();
|
||||
G4String pname = particle->GetParticleName();
|
||||
|
||||
if(step_limit_particles.find(pname) != step_limit_particles.end() ||
|
||||
particle->GetPDGCharge())
|
||||
{
|
||||
ph->RegisterProcess(new G4StepLimiter, particle);
|
||||
}
|
||||
ph->RegisterProcess(new G4StepLimiter, particle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void TSPhysicsList::SetCuts()
|
||||
{
|
||||
SetCutValue(fDefaultCutValue, "e-");
|
||||
SetCutValue(fDefaultCutValue, "e+");
|
||||
SetCutValue(fDefaultCutValue, "gamma");
|
||||
SetCutValue(fDefaultCutValue, "proton");
|
||||
SetCutValue(fDefaultCutValue, "e-");
|
||||
SetCutValue(fDefaultCutValue, "e+");
|
||||
SetCutValue(fDefaultCutValue, "gamma");
|
||||
SetCutValue(fDefaultCutValue, "proton");
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
#include "TSPrimaryGeneratorAction.hh"
|
||||
#include "TSDetectorConstruction.hh"
|
||||
|
||||
@@ -53,43 +52,38 @@ using namespace CLHEP;
|
||||
|
||||
TSPrimaryGeneratorAction::TSPrimaryGeneratorAction()
|
||||
{
|
||||
fGun = new G4ParticleGun(1);
|
||||
fGun = new G4ParticleGun(1);
|
||||
|
||||
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
|
||||
G4String particleName;
|
||||
G4ParticleDefinition* particle
|
||||
= particleTable->FindParticle(particleName="neutron");
|
||||
|
||||
fGun->SetParticleDefinition(particle);
|
||||
fGun->SetParticleEnergy(1.*MeV);
|
||||
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
|
||||
G4String particleName;
|
||||
G4ParticleDefinition* particle =
|
||||
particleTable->FindParticle(particleName = "neutron");
|
||||
|
||||
fGun->SetParticleDefinition(particle);
|
||||
fGun->SetParticleEnergy(1. * MeV);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
TSPrimaryGeneratorAction::~TSPrimaryGeneratorAction()
|
||||
{
|
||||
delete fGun;
|
||||
}
|
||||
TSPrimaryGeneratorAction::~TSPrimaryGeneratorAction() { delete fGun; }
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void TSPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
|
||||
{
|
||||
TIMEMORY_AUTO_TIMER("");
|
||||
static TSDetectorConstruction* detector
|
||||
= TSDetectorConstruction::Instance();
|
||||
TIMEMORY_AUTO_TIMER("");
|
||||
static TSDetectorConstruction* detector = TSDetectorConstruction::Instance();
|
||||
|
||||
G4ThreeVector dir(0.,0., 1.);
|
||||
G4ThreeVector pos(detector->GetWorldDimensions().x()*(G4UniformRand()-0.5),
|
||||
detector->GetWorldDimensions().y()*(G4UniformRand()-0.5),
|
||||
-0.5*detector->GetWorldDimensions().z());
|
||||
G4ThreeVector dir(0., 0., 1.);
|
||||
G4ThreeVector pos(
|
||||
detector->GetWorldDimensions().x() * (G4UniformRand() - 0.5),
|
||||
detector->GetWorldDimensions().y() * (G4UniformRand() - 0.5),
|
||||
-0.5 * detector->GetWorldDimensions().z());
|
||||
|
||||
dir /= dir.mag();
|
||||
fGun->SetParticleMomentumDirection(dir);
|
||||
fGun->SetParticlePosition(pos);
|
||||
fGun->GeneratePrimaryVertex(anEvent);
|
||||
dir /= dir.mag();
|
||||
fGun->SetParticleMomentumDirection(dir);
|
||||
fGun->SetParticlePosition(pos);
|
||||
fGun->GeneratePrimaryVertex(anEvent);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
@@ -68,7 +68,6 @@
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
#include "TSRun.hh"
|
||||
|
||||
#include "G4SDManager.hh"
|
||||
@@ -88,31 +87,31 @@ std::vector<G4StatContainer<G4ConvergenceTester>*> TSRun::fConvMaps;
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
TSRun::TSRun(const G4String& mfd_name)
|
||||
: G4Run()
|
||||
: G4Run()
|
||||
{
|
||||
ConstructMFD(mfd_name);
|
||||
ConstructMFD(mfd_name);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
TSRun::~TSRun()
|
||||
{
|
||||
//--- Clear HitsMap for RUN
|
||||
for(unsigned i = 0; i < fRunMaps.size(); ++i)
|
||||
delete fRunMaps[i];
|
||||
//--- Clear HitsMap for RUN
|
||||
for(unsigned i = 0; i < fRunMaps.size(); ++i)
|
||||
delete fRunMaps[i];
|
||||
|
||||
if(!G4Threading::IsWorkerThread())
|
||||
{
|
||||
for(unsigned i = 0; i < fAtomicRunMaps.size(); ++i)
|
||||
delete fAtomicRunMaps[i];
|
||||
if(!G4Threading::IsWorkerThread())
|
||||
{
|
||||
for(unsigned i = 0; i < fAtomicRunMaps.size(); ++i)
|
||||
delete fAtomicRunMaps[i];
|
||||
|
||||
for(auto& itr: fConvMaps)
|
||||
delete itr;
|
||||
for(auto& itr : fConvMaps)
|
||||
delete itr;
|
||||
|
||||
fAtomicRunMaps.clear();
|
||||
fMutexRunMaps.clear();
|
||||
fConvMaps.clear();
|
||||
}
|
||||
fAtomicRunMaps.clear();
|
||||
fMutexRunMaps.clear();
|
||||
fConvMaps.clear();
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
@@ -120,60 +119,59 @@ TSRun::~TSRun()
|
||||
// clear all data members.
|
||||
void TSRun::ConstructMFD(const G4String& mfdName)
|
||||
{
|
||||
|
||||
G4SDManager* SDman = G4SDManager::GetSDMpointer();
|
||||
//=================================================
|
||||
// Initalize RunMaps for accumulation.
|
||||
// Get CollectionIDs for HitCollections.
|
||||
//=================================================
|
||||
G4MultiFunctionalDetector* mfd =
|
||||
(G4MultiFunctionalDetector*)(SDman->FindSensitiveDetector(mfdName));
|
||||
//
|
||||
if ( mfd )
|
||||
G4SDManager* SDman = G4SDManager::GetSDMpointer();
|
||||
//=================================================
|
||||
// Initalize RunMaps for accumulation.
|
||||
// Get CollectionIDs for HitCollections.
|
||||
//=================================================
|
||||
G4MultiFunctionalDetector* mfd =
|
||||
(G4MultiFunctionalDetector*) (SDman->FindSensitiveDetector(mfdName));
|
||||
//
|
||||
if(mfd)
|
||||
{
|
||||
//--- Loop over the registered primitive scorers.
|
||||
for(G4int icol = 0; icol < mfd->GetNumberOfPrimitives(); icol++)
|
||||
{
|
||||
//--- Loop over the registered primitive scorers.
|
||||
for (G4int icol = 0; icol < mfd->GetNumberOfPrimitives(); icol++){
|
||||
// Get Primitive Scorer object.
|
||||
G4VPrimitiveScorer* scorer = mfd->GetPrimitive(icol);
|
||||
// collection name and collectionID for HitsCollection,
|
||||
// where type of HitsCollection is G4THitsMap in case
|
||||
// of primitive scorer.
|
||||
// The collection name is given by <MFD name>/<Primitive
|
||||
// Scorer name>.
|
||||
G4String collectionName = scorer->GetName();
|
||||
G4String fullCollectionName = mfdName+"/"+collectionName;
|
||||
G4int collectionID = SDman->GetCollectionID(fullCollectionName);
|
||||
//
|
||||
if ( collectionID >= 0 ){
|
||||
G4cout << "++ " << fullCollectionName<< " id " << collectionID
|
||||
<< G4endl;
|
||||
// Store obtained HitsCollection information into data members.
|
||||
// And, creates new G4THitsMap for accumulating quantities during RUN.
|
||||
fCollNames.push_back(fullCollectionName);
|
||||
fCollIDs.push_back(collectionID);
|
||||
fRunMaps.push_back(new G4THitsMap<G4double>(mfdName,
|
||||
collectionName));
|
||||
fStatMaps.push_back(new G4StatContainer<G4StatAnalysis>(
|
||||
mfdName,
|
||||
collectionName,
|
||||
TSDetectorConstruction::Instance()->GetTotalTargets()));
|
||||
if(!G4Threading::IsWorkerThread())
|
||||
{
|
||||
fAtomicRunMaps.push_back(new G4TAtomicHitsMap<G4double>
|
||||
(mfdName, collectionName));
|
||||
fMutexRunMaps[fCollNames[collectionID]].clear();
|
||||
fConvMaps.push_back(new G4StatContainer<G4ConvergenceTester>(
|
||||
mfdName,
|
||||
collectionName,
|
||||
TSDetectorConstruction::Instance()->GetTotalTargets()));
|
||||
}
|
||||
} else {
|
||||
G4cout << "** collection " << fullCollectionName << " not found. "
|
||||
<<G4endl;
|
||||
// Get Primitive Scorer object.
|
||||
G4VPrimitiveScorer* scorer = mfd->GetPrimitive(icol);
|
||||
// collection name and collectionID for HitsCollection,
|
||||
// where type of HitsCollection is G4THitsMap in case
|
||||
// of primitive scorer.
|
||||
// The collection name is given by <MFD name>/<Primitive
|
||||
// Scorer name>.
|
||||
G4String collectionName = scorer->GetName();
|
||||
G4String fullCollectionName = mfdName + "/" + collectionName;
|
||||
G4int collectionID = SDman->GetCollectionID(fullCollectionName);
|
||||
//
|
||||
if(collectionID >= 0)
|
||||
{
|
||||
G4cout << "++ " << fullCollectionName << " id " << collectionID
|
||||
<< G4endl;
|
||||
// Store obtained HitsCollection information into data members.
|
||||
// And, creates new G4THitsMap for accumulating quantities during RUN.
|
||||
fCollNames.push_back(fullCollectionName);
|
||||
fCollIDs.push_back(collectionID);
|
||||
fRunMaps.push_back(new G4THitsMap<G4double>(mfdName, collectionName));
|
||||
fStatMaps.push_back(new G4StatContainer<G4StatAnalysis>(
|
||||
mfdName, collectionName,
|
||||
TSDetectorConstruction::Instance()->GetTotalTargets()));
|
||||
if(!G4Threading::IsWorkerThread())
|
||||
{
|
||||
fAtomicRunMaps.push_back(
|
||||
new G4TAtomicHitsMap<G4double>(mfdName, collectionName));
|
||||
fMutexRunMaps[fCollNames[collectionID]].clear();
|
||||
fConvMaps.push_back(new G4StatContainer<G4ConvergenceTester>(
|
||||
mfdName, collectionName,
|
||||
TSDetectorConstruction::Instance()->GetTotalTargets()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
G4cout << "** collection " << fullCollectionName << " not found. "
|
||||
<< G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
@@ -183,67 +181,66 @@ void TSRun::ConstructMFD(const G4String& mfdName)
|
||||
// is accumulated during a TSRun.
|
||||
void TSRun::RecordEvent(const G4Event* aEvent)
|
||||
{
|
||||
G4Run::RecordEvent(aEvent);
|
||||
G4Run::RecordEvent(aEvent);
|
||||
|
||||
//=============================
|
||||
// HitsCollection of This Event
|
||||
//============================
|
||||
G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent();
|
||||
if (!HCE)
|
||||
return;
|
||||
//=============================
|
||||
// HitsCollection of This Event
|
||||
//============================
|
||||
G4HCofThisEvent* HCE = aEvent->GetHCofThisEvent();
|
||||
if(!HCE)
|
||||
return;
|
||||
|
||||
for(unsigned i = 0; i < fCollIDs.size(); ++i)
|
||||
for(unsigned i = 0; i < fCollIDs.size(); ++i)
|
||||
{
|
||||
G4int fCollID = fCollIDs.at(i);
|
||||
//=======================================================
|
||||
// Sum up HitsMap of this Event into HitsMap of this RUN
|
||||
//=======================================================
|
||||
G4THitsMap<G4double>* EvtMap = 0;
|
||||
if(fCollID >= 0) // Collection is attached to HCE
|
||||
EvtMap = static_cast<G4THitsMap<G4double>*>(HCE->GetHC(fCollID));
|
||||
else
|
||||
G4cout << " Error EvtMap Not Found " << G4endl;
|
||||
|
||||
TIMEMORY_AUTO_TIMER("[" + fCollNames.at(i) + "]");
|
||||
|
||||
if(EvtMap)
|
||||
{
|
||||
G4int fCollID = fCollIDs.at(i);
|
||||
//=======================================================
|
||||
// Sum up HitsMap of this Event into HitsMap of this RUN
|
||||
//=======================================================
|
||||
G4THitsMap<G4double>* EvtMap = 0;
|
||||
if ( fCollID >= 0 ) // Collection is attached to HCE
|
||||
EvtMap = static_cast<G4THitsMap<G4double>*>(HCE->GetHC(fCollID));
|
||||
else
|
||||
G4cout <<" Error EvtMap Not Found " << G4endl;
|
||||
|
||||
TIMEMORY_AUTO_TIMER("[" + fCollNames.at(i) + "]");
|
||||
|
||||
if ( EvtMap )
|
||||
{
|
||||
//=== Sum up HitsMap of this event to HitsMap of RUN.===
|
||||
{
|
||||
TIMEMORY_BASIC_AUTO_TIMER("[standard_run_map]");
|
||||
*fRunMaps[fCollID] += *EvtMap;
|
||||
}
|
||||
//=== Sum up HitsMap of this event to atomic HitsMap of RUN.===
|
||||
{
|
||||
TIMEMORY_BASIC_AUTO_TIMER("[atomic_run_map]");
|
||||
*fAtomicRunMaps[fCollID] += *EvtMap;
|
||||
}
|
||||
//=== Sum up HitsMap of this event to StatMap of RUN.===
|
||||
{
|
||||
TIMEMORY_BASIC_AUTO_TIMER("[stat_analysis_map]");
|
||||
// G4StatAnalysis map
|
||||
*fStatMaps[fCollID] += *EvtMap;
|
||||
}
|
||||
//=== Sum up HitsMap of this event to MutexMap of RUN.===
|
||||
{
|
||||
TIMEMORY_BASIC_AUTO_TIMER("[convergence_test_map]");
|
||||
// G4ConvergenceTester run map
|
||||
static G4Mutex mtx = G4MUTEX_INITIALIZER;
|
||||
G4AutoLock lock(&mtx);
|
||||
*fConvMaps[fCollID] += *EvtMap;
|
||||
}
|
||||
//=== Sum up HitsMap of this event to MutexMap of RUN.===
|
||||
{
|
||||
TIMEMORY_BASIC_AUTO_TIMER("[mutex_run_map]");
|
||||
// mutex run map
|
||||
static G4Mutex mtx = G4MUTEX_INITIALIZER;
|
||||
G4AutoLock lock(&mtx);
|
||||
for(const auto& itr : *EvtMap)
|
||||
fMutexRunMaps[fCollNames[fCollID]][itr.first]
|
||||
+= *itr.second;
|
||||
}
|
||||
}
|
||||
//=== Sum up HitsMap of this event to HitsMap of RUN.===
|
||||
{
|
||||
TIMEMORY_BASIC_AUTO_TIMER("[standard_run_map]");
|
||||
*fRunMaps[fCollID] += *EvtMap;
|
||||
}
|
||||
//=== Sum up HitsMap of this event to atomic HitsMap of RUN.===
|
||||
{
|
||||
TIMEMORY_BASIC_AUTO_TIMER("[atomic_run_map]");
|
||||
*fAtomicRunMaps[fCollID] += *EvtMap;
|
||||
}
|
||||
//=== Sum up HitsMap of this event to StatMap of RUN.===
|
||||
{
|
||||
TIMEMORY_BASIC_AUTO_TIMER("[stat_analysis_map]");
|
||||
// G4StatAnalysis map
|
||||
*fStatMaps[fCollID] += *EvtMap;
|
||||
}
|
||||
//=== Sum up HitsMap of this event to MutexMap of RUN.===
|
||||
{
|
||||
TIMEMORY_BASIC_AUTO_TIMER("[convergence_test_map]");
|
||||
// G4ConvergenceTester run map
|
||||
static G4Mutex mtx = G4MUTEX_INITIALIZER;
|
||||
G4AutoLock lock(&mtx);
|
||||
*fConvMaps[fCollID] += *EvtMap;
|
||||
}
|
||||
//=== Sum up HitsMap of this event to MutexMap of RUN.===
|
||||
{
|
||||
TIMEMORY_BASIC_AUTO_TIMER("[mutex_run_map]");
|
||||
// mutex run map
|
||||
static G4Mutex mtx = G4MUTEX_INITIALIZER;
|
||||
G4AutoLock lock(&mtx);
|
||||
for(const auto& itr : *EvtMap)
|
||||
fMutexRunMaps[fCollNames[fCollID]][itr.first] += *itr.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
@@ -251,15 +248,15 @@ void TSRun::RecordEvent(const G4Event* aEvent)
|
||||
// Merge hits map from threads
|
||||
void TSRun::Merge(const G4Run* aTSRun)
|
||||
{
|
||||
const TSRun* localTSRun = static_cast<const TSRun*>(aTSRun);
|
||||
const TSRun* localTSRun = static_cast<const TSRun*>(aTSRun);
|
||||
|
||||
for(unsigned i = 0; i < fRunMaps.size(); ++i)
|
||||
{
|
||||
*fRunMaps[i] += *localTSRun->fRunMaps[i];
|
||||
*fStatMaps[i] += *localTSRun->fStatMaps[i];
|
||||
}
|
||||
for(unsigned i = 0; i < fRunMaps.size(); ++i)
|
||||
{
|
||||
*fRunMaps[i] += *localTSRun->fRunMaps[i];
|
||||
*fStatMaps[i] += *localTSRun->fStatMaps[i];
|
||||
}
|
||||
|
||||
G4Run::Merge(aTSRun);
|
||||
G4Run::Merge(aTSRun);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
@@ -272,7 +269,7 @@ G4THitsMap<G4double>* TSRun::GetHitsMap(const G4String& collName) const
|
||||
for(unsigned i = 0; i < fCollNames.size(); ++i)
|
||||
{
|
||||
if(collName == fCollNames[i])
|
||||
return fRunMaps[i];
|
||||
return fRunMaps[i];
|
||||
}
|
||||
|
||||
G4Exception("TSRun", collName.c_str(), JustWarning,
|
||||
@@ -285,13 +282,13 @@ G4THitsMap<G4double>* TSRun::GetHitsMap(const G4String& collName) const
|
||||
// Access AtomicsHitsMap.
|
||||
// by full description of collection name, that is
|
||||
// <MultiFunctional Detector Name>/<Primitive Scorer Name>
|
||||
G4TAtomicHitsMap<G4double>*
|
||||
TSRun::GetAtomicHitsMap(const G4String& collName) const
|
||||
G4TAtomicHitsMap<G4double>* TSRun::GetAtomicHitsMap(
|
||||
const G4String& collName) const
|
||||
{
|
||||
for(unsigned i = 0; i < fCollNames.size(); ++i)
|
||||
{
|
||||
if(collName == fCollNames[i])
|
||||
return fAtomicRunMaps[i];
|
||||
return fAtomicRunMaps[i];
|
||||
}
|
||||
|
||||
G4Exception("TSRun", collName.c_str(), JustWarning,
|
||||
@@ -304,11 +301,10 @@ TSRun::GetAtomicHitsMap(const G4String& collName) const
|
||||
// Access AtomicsHitsMap.
|
||||
// by full description of collection name, that is
|
||||
// <MultiFunctional Detector Name>/<Primitive Scorer Name>
|
||||
TSRun::MutexHitsMap_t*
|
||||
TSRun::GetMutexHitsMap(const G4String& collName) const
|
||||
TSRun::MutexHitsMap_t* TSRun::GetMutexHitsMap(const G4String& collName) const
|
||||
{
|
||||
if(fMutexRunMaps.find(collName) != fMutexRunMaps.end())
|
||||
return &fMutexRunMaps[collName];
|
||||
return &fMutexRunMaps[collName];
|
||||
|
||||
G4Exception("TSRun", collName.c_str(), JustWarning,
|
||||
"GetHitsMap failed to locate the requested MutexHitsMap");
|
||||
@@ -320,29 +316,29 @@ TSRun::GetMutexHitsMap(const G4String& collName) const
|
||||
// Access StatMap.
|
||||
// by full description of collection name, that is
|
||||
// <MultiFunctional Detector Name>/<Primitive Scorer Name>
|
||||
G4StatContainer<G4StatAnalysis>*
|
||||
TSRun::GetStatMap(const G4String& collName) const
|
||||
{
|
||||
for(unsigned i = 0; i < fCollNames.size(); ++i)
|
||||
{
|
||||
if(collName == fCollNames[i])
|
||||
return fStatMaps[i];
|
||||
}
|
||||
|
||||
G4Exception("TSRun", collName.c_str(), JustWarning,
|
||||
"GetStatMap failed to locate the requested StatMap");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
G4StatContainer<G4ConvergenceTester>*
|
||||
TSRun::GetConvMap(const G4String& collName) const
|
||||
G4StatContainer<G4StatAnalysis>* TSRun::GetStatMap(
|
||||
const G4String& collName) const
|
||||
{
|
||||
for(unsigned i = 0; i < fCollNames.size(); ++i)
|
||||
{
|
||||
if(collName == fCollNames[i])
|
||||
return fConvMaps[i];
|
||||
return fStatMaps[i];
|
||||
}
|
||||
|
||||
G4Exception("TSRun", collName.c_str(), JustWarning,
|
||||
"GetStatMap failed to locate the requested StatMap");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
G4StatContainer<G4ConvergenceTester>* TSRun::GetConvMap(
|
||||
const G4String& collName) const
|
||||
{
|
||||
for(unsigned i = 0; i < fCollNames.size(); ++i)
|
||||
{
|
||||
if(collName == fCollNames[i])
|
||||
return fConvMaps[i];
|
||||
}
|
||||
|
||||
G4Exception("TSRun", collName.c_str(), JustWarning,
|
||||
|
||||
@@ -34,13 +34,13 @@
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
#include "TSRunAction.hh"
|
||||
#include "TSActionInitialization.hh"
|
||||
|
||||
#include "G4RunManager.hh"
|
||||
#include "G4Run.hh"
|
||||
#include "G4Timer.hh"
|
||||
#include "G4TaskRunManager.hh"
|
||||
|
||||
#include "TSRun.hh"
|
||||
#include "TSDetectorConstruction.hh"
|
||||
@@ -49,326 +49,369 @@
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
TSRunAction::TSRunAction()
|
||||
: fDetector(TSDetectorConstruction::Instance()),
|
||||
fName(fDetector->GetMFDName())
|
||||
{ }
|
||||
: fDetector(TSDetectorConstruction::Instance())
|
||||
, fName(fDetector->GetMFDName())
|
||||
{}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
TSRunAction::~TSRunAction()
|
||||
{ }
|
||||
TSRunAction::~TSRunAction() {}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
G4Run* TSRunAction::GenerateRun()
|
||||
{
|
||||
return new TSRun(fName);
|
||||
}
|
||||
G4Run* TSRunAction::GenerateRun() { return new TSRun(fName); }
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void TSRunAction::BeginOfRunAction(const G4Run* aRun)
|
||||
{
|
||||
G4int evts_to_process = aRun->GetNumberOfEventToBeProcessed();
|
||||
G4RunManager::GetRunManager()->SetPrintProgress((evts_to_process > 100)
|
||||
? evts_to_process/100
|
||||
: 1);
|
||||
if(IsMaster())
|
||||
G4PrintEnv();
|
||||
G4int evts_to_process = aRun->GetNumberOfEventToBeProcessed();
|
||||
G4RunManager::GetRunManager()->SetPrintProgress(
|
||||
(evts_to_process > 100) ? evts_to_process / 100 : 1);
|
||||
if(IsMaster())
|
||||
G4PrintEnv();
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void TSRunAction::EndOfRunAction(const G4Run* aRun)
|
||||
{
|
||||
if(IsMaster())
|
||||
{
|
||||
G4cout << " ###### EndOfTSRunAction ###### " << G4endl;
|
||||
|
||||
if(IsMaster())
|
||||
aRun->GetNumberOfEvent();
|
||||
std::ofstream fileout;
|
||||
G4String fname = "";
|
||||
std::stringstream separator;
|
||||
|
||||
separator << "============================================================";
|
||||
|
||||
typedef std::set<G4int> IDSet_t;
|
||||
IDSet_t IDs;
|
||||
|
||||
//- TSRun object.
|
||||
const TSRun* tsRun = static_cast<const TSRun*>(aRun);
|
||||
//--- Dump all scored quantities involved in TSRun.
|
||||
|
||||
//---------------------------------------------
|
||||
// Dump accumulated quantities for this RUN.
|
||||
//---------------------------------------------
|
||||
std::vector<G4String> primScorerNames{ "EnergyDeposit", "NumberOfSteps" };
|
||||
std::vector<G4String> fnames{ "mfd_tl", "mfd_tg" };
|
||||
std::vector<G4double> units{ CLHEP::eV, CLHEP::keV, 1, 1 };
|
||||
std::vector<G4String> unitstr{ "keV", "steps" };
|
||||
|
||||
//----------------------------------------------------------------------//
|
||||
// lambda to print double value
|
||||
auto print = [](std::ostream& fout, G4int first, G4double second,
|
||||
G4double unit1, G4double unit2, G4String unit2str) {
|
||||
if(fout)
|
||||
fout << first << " " << second / unit1 << G4endl;
|
||||
|
||||
G4cout << " " << std::setw(10) << first << " " << std::setw(15)
|
||||
<< std::setprecision(6) << std::fixed << second / unit2 << " "
|
||||
<< unit2str << G4endl;
|
||||
G4cout.unsetf(std::ios::fixed);
|
||||
};
|
||||
//----------------------------------------------------------------------//
|
||||
// lambda to print statistics
|
||||
auto stat_print = [](std::ostream& fout, G4int first, G4StatAnalysis* stat,
|
||||
G4ConvergenceTester* conv, G4double unit1,
|
||||
G4double unit2, G4String unit2str) {
|
||||
if(!stat || !conv)
|
||||
return;
|
||||
auto fsecond = (*stat);
|
||||
auto psecond = (*stat);
|
||||
fsecond /= unit1;
|
||||
psecond /= unit2;
|
||||
if(fout)
|
||||
{
|
||||
fout << first << " " << fsecond << G4endl;
|
||||
conv->ShowResult(fout);
|
||||
}
|
||||
std::stringstream ss;
|
||||
ss << " " << std::setw(10) << first << " " << std::setw(15)
|
||||
<< std::setprecision(6) << std::fixed << psecond << " " << unit2str;
|
||||
// skip print of ConvergenceTester to stdout
|
||||
G4cout << ss.str() << G4endl;
|
||||
};
|
||||
//----------------------------------------------------------------------//
|
||||
|
||||
for(unsigned i = 0; i < primScorerNames.size(); ++i)
|
||||
{
|
||||
G4cout << " ###### EndOfTSRunAction ###### " << G4endl;
|
||||
|
||||
aRun->GetNumberOfEvent();
|
||||
std::ofstream fileout;
|
||||
G4String fname = "";
|
||||
std::stringstream separator;
|
||||
|
||||
separator
|
||||
<< "============================================================";
|
||||
|
||||
typedef std::set<G4int> IDSet_t;
|
||||
IDSet_t IDs;
|
||||
|
||||
//- TSRun object.
|
||||
const TSRun* tsRun = static_cast<const TSRun*>(aRun);
|
||||
//--- Dump all scored quantities involved in TSRun.
|
||||
|
||||
//---------------------------------------------
|
||||
// Dump accumulated quantities for this RUN.
|
||||
//---------------------------------------------
|
||||
std::vector<G4String> primScorerNames { "EnergyDeposit",
|
||||
"NumberOfSteps" };
|
||||
std::vector<G4String> fnames { "mfd_tl", "mfd_tg" };
|
||||
std::vector<G4double> units { CLHEP::eV, CLHEP::keV, 1, 1 };
|
||||
std::vector<G4String> unitstr { "keV", "steps" };
|
||||
|
||||
//----------------------------------------------------------------------//
|
||||
// lambda to print double value
|
||||
auto print = [] (std::ostream& fout,
|
||||
G4int first, G4double second,
|
||||
G4double unit1, G4double unit2, G4String unit2str)
|
||||
for(unsigned j = 0; j < fnames.size(); ++j)
|
||||
{
|
||||
if(fout)
|
||||
fout << first
|
||||
<< " " << second/unit1
|
||||
<< G4endl;
|
||||
fname = fnames.at(j) + "_" + primScorerNames.at(i) + ".out";
|
||||
fileout.open(fname);
|
||||
G4cout << separator.str() << G4endl;
|
||||
G4cout << " opened file " << fname << " for output" << G4endl;
|
||||
G4cout << separator.str() << G4endl;
|
||||
|
||||
G4cout
|
||||
<< " " << std::setw(10) << first
|
||||
<< " " << std::setw(15) << std::setprecision(6)
|
||||
<< std::fixed << second/unit2 << " " << unit2str
|
||||
<< G4endl;
|
||||
G4cout.unsetf(std::ios::fixed);
|
||||
};
|
||||
//----------------------------------------------------------------------//
|
||||
// lambda to print statistics
|
||||
auto stat_print = [] (std::ostream& fout,
|
||||
G4int first, G4StatAnalysis* stat, G4ConvergenceTester* conv,
|
||||
G4double unit1, G4double unit2, G4String unit2str)
|
||||
{
|
||||
if(!stat || !conv)
|
||||
return;
|
||||
auto fsecond = (*stat);
|
||||
auto psecond = (*stat);
|
||||
fsecond /= unit1;
|
||||
psecond /= unit2;
|
||||
if(fout)
|
||||
G4bool valid = true;
|
||||
if(j == 0)
|
||||
{
|
||||
G4THitsMap<G4double>* hitmap =
|
||||
tsRun->GetHitsMap(fName + "/" + primScorerNames.at(i));
|
||||
G4StatContainer<G4StatAnalysis>* statmap =
|
||||
tsRun->GetStatMap(fName + "/" + primScorerNames.at(i));
|
||||
G4StatContainer<G4ConvergenceTester>* convmap =
|
||||
tsRun->GetConvMap(fName + "/" + primScorerNames.at(i));
|
||||
|
||||
if(hitmap && hitmap->size() != 0)
|
||||
{
|
||||
fout << first << " " << fsecond << G4endl;
|
||||
conv->ShowResult(fout);
|
||||
for(auto itr = hitmap->begin(); itr != hitmap->end(); itr++)
|
||||
{
|
||||
if(!hitmap->GetObject(itr))
|
||||
continue;
|
||||
IDs.insert(itr->first);
|
||||
std::get<0>(fTypeCompare[primScorerNames.at(i)][itr->first]) =
|
||||
*itr->second / units.at(i);
|
||||
print(fileout, itr->first, *itr->second, units.at(i),
|
||||
units.at(i + 1), unitstr.at(i));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
valid = false;
|
||||
}
|
||||
std::stringstream ss;
|
||||
ss << " " << std::setw(10) << first
|
||||
<< " " << std::setw(15) << std::setprecision(6)
|
||||
<< std::fixed << psecond << " " << unit2str;
|
||||
// skip print of ConvergenceTester to stdout
|
||||
G4cout << ss.str() << G4endl;
|
||||
};
|
||||
//----------------------------------------------------------------------//
|
||||
|
||||
for(unsigned i = 0; i < primScorerNames.size(); ++i)
|
||||
{
|
||||
for(unsigned j = 0; j < fnames.size(); ++j)
|
||||
{
|
||||
fname = fnames.at(j) + "_" + primScorerNames.at(i) + ".out";
|
||||
fileout.open(fname);
|
||||
G4cout << separator.str() << G4endl;
|
||||
G4cout << " opened file " << fname << " for output" << G4endl;
|
||||
G4cout << separator.str() << G4endl;
|
||||
|
||||
G4bool valid = true;
|
||||
if(j == 0)
|
||||
if(statmap && statmap->size() != 0 && convmap && convmap->size() != 0)
|
||||
{
|
||||
auto stat_fname = "stat_" + fname;
|
||||
std::ofstream statout;
|
||||
statout.open(stat_fname);
|
||||
for(auto itr = statmap->begin(); itr != statmap->end(); itr++)
|
||||
{
|
||||
G4THitsMap<G4double>* hitmap
|
||||
= tsRun->GetHitsMap(fName + "/" + primScorerNames.at(i));
|
||||
G4StatContainer<G4StatAnalysis>* statmap
|
||||
= tsRun->GetStatMap(fName + "/" + primScorerNames.at(i));
|
||||
G4StatContainer<G4ConvergenceTester>* convmap
|
||||
= tsRun->GetConvMap(fName + "/" + primScorerNames.at(i));
|
||||
|
||||
if(hitmap && hitmap->size() != 0)
|
||||
{
|
||||
for(auto itr = hitmap->begin(); itr != hitmap->end(); itr++)
|
||||
{
|
||||
if(!hitmap->GetObject(itr))
|
||||
continue;
|
||||
IDs.insert(itr->first);
|
||||
std::get<0>(fTypeCompare[primScorerNames.at(i)][itr->first])
|
||||
= *itr->second/units.at(i);
|
||||
print(fileout, itr->first, *itr->second,
|
||||
units.at(i), units.at(i+1), unitstr.at(i));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if(statmap && statmap->size() != 0 &&
|
||||
convmap && convmap->size() != 0)
|
||||
{
|
||||
auto stat_fname = "stat_" + fname;
|
||||
std::ofstream statout;
|
||||
statout.open(stat_fname);
|
||||
for(auto itr = statmap->begin(); itr != statmap->end(); itr++)
|
||||
{
|
||||
G4int _f = statmap->GetIndex(itr);
|
||||
G4StatAnalysis* _s = statmap->GetObject(itr);
|
||||
G4ConvergenceTester* _c = convmap->GetObject(_f);
|
||||
stat_print(statout, _f, _s, _c,
|
||||
units.at(i), units.at(i+1), unitstr.at(i));
|
||||
}
|
||||
statout.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << " StatMap/ConvMap is either not "
|
||||
<< "created or the StatMap/ConvMap was empty";
|
||||
if(statmap)
|
||||
ss << " (StatMap size == " << statmap->size() << ")";
|
||||
if(convmap)
|
||||
ss << " (ConvMap size == " << convmap->size() << ")";
|
||||
|
||||
G4Exception("TSRunAction", "002", JustWarning,
|
||||
G4String(primScorerNames.at(i) +
|
||||
ss.str()).c_str());
|
||||
}
|
||||
|
||||
if(!valid)
|
||||
{
|
||||
G4Exception("TSRunAction", "000", JustWarning,
|
||||
G4String(primScorerNames.at(i) +
|
||||
" HitsMap is either not "
|
||||
"created or the HitsMap was empty").c_str());
|
||||
}
|
||||
G4int _f = statmap->GetIndex(itr);
|
||||
G4StatAnalysis* _s = statmap->GetObject(itr);
|
||||
G4ConvergenceTester* _c = convmap->GetObject(_f);
|
||||
stat_print(statout, _f, _s, _c, units.at(i), units.at(i + 1),
|
||||
unitstr.at(i));
|
||||
}
|
||||
else
|
||||
{
|
||||
G4TAtomicHitsMap<G4double>* hitmap
|
||||
= tsRun->GetAtomicHitsMap(fName + "/" +
|
||||
primScorerNames.at(i));
|
||||
if(hitmap && hitmap->size() != 0)
|
||||
{
|
||||
for(auto itr = hitmap->begin(); itr != hitmap->end(); itr++)
|
||||
{
|
||||
IDs.insert(itr->first);
|
||||
std::get<1>(fTypeCompare[primScorerNames.at(i)][itr->first])
|
||||
= *itr->second/units.at(i);
|
||||
print(fileout, itr->first, *itr->second,
|
||||
units.at(i), units.at(i+1), unitstr.at(i));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
valid = false;
|
||||
}
|
||||
statout.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << " StatMap/ConvMap is either not "
|
||||
<< "created or the StatMap/ConvMap was empty";
|
||||
if(statmap)
|
||||
ss << " (StatMap size == " << statmap->size() << ")";
|
||||
if(convmap)
|
||||
ss << " (ConvMap size == " << convmap->size() << ")";
|
||||
|
||||
if(!valid)
|
||||
{
|
||||
G4Exception("TSRunAction", "001", JustWarning,
|
||||
G4String(primScorerNames.at(i) +
|
||||
" HitsMap is either not "
|
||||
"created or the HitsMap was empty").c_str());
|
||||
}
|
||||
}
|
||||
G4Exception("TSRunAction", "002", JustWarning,
|
||||
G4String(primScorerNames.at(i) + ss.str()).c_str());
|
||||
}
|
||||
|
||||
fileout.close();
|
||||
G4cout << separator.str() << G4endl;
|
||||
G4cout << " closed file " << fname << " for output" << G4endl;
|
||||
if(!valid)
|
||||
{
|
||||
G4Exception("TSRunAction", "000", JustWarning,
|
||||
G4String(primScorerNames.at(i) +
|
||||
" HitsMap is either not "
|
||||
"created or the HitsMap was empty")
|
||||
.c_str());
|
||||
}
|
||||
}
|
||||
// add the mutex data
|
||||
TSRun::MutexHitsMap_t* hitmap
|
||||
= tsRun->GetMutexHitsMap(fName + "/" +
|
||||
primScorerNames.at(i));
|
||||
if(hitmap && hitmap->size() != 0)
|
||||
else
|
||||
{
|
||||
for(auto itr = hitmap->begin();
|
||||
itr != hitmap->end(); itr++)
|
||||
G4TAtomicHitsMap<G4double>* hitmap =
|
||||
tsRun->GetAtomicHitsMap(fName + "/" + primScorerNames.at(i));
|
||||
if(hitmap && hitmap->size() != 0)
|
||||
{
|
||||
for(auto itr = hitmap->begin(); itr != hitmap->end(); itr++)
|
||||
{
|
||||
IDs.insert(itr->first);
|
||||
std::get<2>(fTypeCompare[primScorerNames.at(i)][itr->first])
|
||||
= itr->second/units.at(i);
|
||||
IDs.insert(itr->first);
|
||||
std::get<1>(fTypeCompare[primScorerNames.at(i)][itr->first]) =
|
||||
*itr->second / units.at(i);
|
||||
print(fileout, itr->first, *itr->second, units.at(i),
|
||||
units.at(i + 1), unitstr.at(i));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if(!valid)
|
||||
{
|
||||
G4Exception("TSRunAction", "001", JustWarning,
|
||||
G4String(primScorerNames.at(i) +
|
||||
" HitsMap is either not "
|
||||
"created or the HitsMap was empty")
|
||||
.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
fileout.close();
|
||||
G4cout << separator.str() << G4endl;
|
||||
G4cout << " closed file " << fname << " for output" << G4endl;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------//
|
||||
// Check that the values are equivalent and there are no
|
||||
// IDs in one container that aren't in another
|
||||
//--------------------------------------------------------------------//
|
||||
|
||||
fname = "mfd_diff.out";
|
||||
fileout.open(fname);
|
||||
|
||||
G4cout << separator.str() << G4endl;
|
||||
G4cout << " opened file " << fname << " for difference output" << G4endl;
|
||||
G4cout << separator.str() << G4endl;
|
||||
|
||||
fileout << " " << std::setw(10) << "ID"
|
||||
<< " "
|
||||
<< std::setw(30) << std::setprecision(12) << std::fixed
|
||||
<< "MFD value"
|
||||
<< " "
|
||||
<< std::setw(30) << std::setprecision(12) << std::fixed
|
||||
<< "Atomic Hits Map value"
|
||||
<< " "
|
||||
<< std::setw(30) << std::setprecision(8) << std::scientific
|
||||
<< "Difference"
|
||||
<< " "
|
||||
<< std::setw(30) << std::setprecision(8) << std::scientific
|
||||
<< "Diff (MFD - MUTEXED)"
|
||||
<< " "
|
||||
<< std::setw(30) << std::setprecision(8) << std::scientific
|
||||
<< "Diff (ATOM_HIT_MAP - MUTEXED)"
|
||||
<< G4endl << G4endl;
|
||||
|
||||
for(auto itr1 = fTypeCompare.begin();
|
||||
itr1 != fTypeCompare.end(); ++itr1)
|
||||
// add the mutex data
|
||||
TSRun::MutexHitsMap_t* hitmap =
|
||||
tsRun->GetMutexHitsMap(fName + "/" + primScorerNames.at(i));
|
||||
if(hitmap && hitmap->size() != 0)
|
||||
{
|
||||
fileout << "\n\nType = " << itr1->first << "\n" << G4endl;
|
||||
for(auto itr2 = itr1->second.begin();
|
||||
itr2 != itr1->second.end(); ++itr2)
|
||||
{
|
||||
G4double d01
|
||||
= std::fabs(std::get<0>(itr2->second) -
|
||||
std::get<1>(itr2->second));
|
||||
G4double d02
|
||||
= std::fabs(std::get<0>(itr2->second) -
|
||||
std::get<2>(itr2->second));
|
||||
G4double d03
|
||||
= std::fabs(std::get<1>(itr2->second) -
|
||||
std::get<2>(itr2->second));
|
||||
|
||||
|
||||
auto _print_diff = [&] (const G4double& _dval)
|
||||
{
|
||||
if(_dval > 0.0)
|
||||
fileout << std::setprecision(8) << std::scientific
|
||||
<< std::setw(30) << _dval << " ";
|
||||
else
|
||||
fileout << std::setprecision(1) << std::fixed
|
||||
<< std::setw(30) << _dval << " ";
|
||||
};
|
||||
|
||||
fileout
|
||||
<< " " << std::setw(10) << itr2->first
|
||||
<< " "
|
||||
<< std::setw(30) << std::setprecision(12) << std::fixed
|
||||
<< std::get<0>(itr2->second)
|
||||
<< " "
|
||||
<< std::setw(30) << std::setprecision(12) << std::fixed
|
||||
<< std::get<1>(itr2->second)
|
||||
<< " ";
|
||||
|
||||
_print_diff(d01);
|
||||
_print_diff(d02);
|
||||
_print_diff(d03);
|
||||
|
||||
fileout << G4endl;
|
||||
|
||||
}
|
||||
for(auto itr = hitmap->begin(); itr != hitmap->end(); itr++)
|
||||
{
|
||||
IDs.insert(itr->first);
|
||||
std::get<2>(fTypeCompare[primScorerNames.at(i)][itr->first]) =
|
||||
itr->second / units.at(i);
|
||||
}
|
||||
}
|
||||
|
||||
fileout.close();
|
||||
G4cout << " closed file " << fname << " for difference output" << G4endl;
|
||||
G4cout << separator.str() << G4endl;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------//
|
||||
// Check that the values are equivalent and there are no
|
||||
// IDs in one container that aren't in another
|
||||
//--------------------------------------------------------------------//
|
||||
|
||||
fname = "mfd_diff.out";
|
||||
fileout.open(fname);
|
||||
|
||||
G4cout << separator.str() << G4endl;
|
||||
G4cout << " opened file " << fname << " for difference output" << G4endl;
|
||||
G4cout << separator.str() << G4endl;
|
||||
|
||||
fileout << " " << std::setw(10) << "ID"
|
||||
<< " " << std::setw(30) << std::setprecision(12) << std::fixed
|
||||
<< "MFD value"
|
||||
<< " " << std::setw(30) << std::setprecision(12) << std::fixed
|
||||
<< "Atomic Hits Map value"
|
||||
<< " " << std::setw(30) << std::setprecision(8)
|
||||
<< std::scientific << "Difference"
|
||||
<< " " << std::setw(30) << std::setprecision(8)
|
||||
<< std::scientific << "Diff (MFD - MUTEXED)"
|
||||
<< " " << std::setw(30) << std::setprecision(8)
|
||||
<< std::scientific << "Diff (ATOM_HIT_MAP - MUTEXED)" << G4endl
|
||||
<< G4endl;
|
||||
|
||||
//----------------------------------------------------------------------//
|
||||
//
|
||||
// Example of using tasking in the user-application. Although this
|
||||
// is sort of trivial case and might not result in any speed-up
|
||||
// it is a good validation test because the order that strings
|
||||
// are joined matters. Although the tasks are executed asynchronously
|
||||
// and may complete at different times, the return values from
|
||||
// the tasks are stored in futures and are "joined" in the order
|
||||
// that they were submitted to the task-group
|
||||
//
|
||||
//----------------------------------------------------------------------//
|
||||
// do not directly call G4TaskManager::GetInstance() as this will generate
|
||||
// an instance
|
||||
auto tm = dynamic_cast<G4TaskRunManager*>(G4RunManager::GetRunManager());
|
||||
// Get the thread-pool if available
|
||||
auto tp = (tm) ? tm->GetThreadPool() : nullptr;
|
||||
// write a join algorithm which combines the strings from the tasks
|
||||
auto join_output = [](std::string& lhs, std::string&& rhs) {
|
||||
return (lhs += rhs);
|
||||
};
|
||||
|
||||
// this is the outer-loop of tasks
|
||||
auto report_type_comparison = [=](const G4String& id,
|
||||
const IDcompare_t& comp) {
|
||||
// the 'report_type_comparison' generates more tasks
|
||||
auto report_subtype_comparison = [](const G4int& idx,
|
||||
const Compare_t& value) {
|
||||
std::stringstream streamout;
|
||||
G4double d01 = std::fabs(std::get<0>(value) - std::get<1>(value));
|
||||
G4double d02 = std::fabs(std::get<0>(value) - std::get<2>(value));
|
||||
G4double d03 = std::fabs(std::get<1>(value) - std::get<2>(value));
|
||||
|
||||
auto _print_diff = [&](const G4double& _dval) {
|
||||
if(_dval > 0.0)
|
||||
streamout << std::setprecision(8) << std::scientific
|
||||
<< std::setw(30) << _dval << " ";
|
||||
else
|
||||
streamout << std::setprecision(1) << std::fixed << std::setw(30)
|
||||
<< _dval << " ";
|
||||
};
|
||||
|
||||
streamout << " " << std::setw(10) << idx << " " << std::setw(30)
|
||||
<< std::setprecision(12) << std::fixed << std::get<0>(value)
|
||||
<< " " << std::setw(30) << std::setprecision(12)
|
||||
<< std::fixed << std::get<1>(value) << " ";
|
||||
|
||||
_print_diff(d01);
|
||||
_print_diff(d02);
|
||||
_print_diff(d03);
|
||||
|
||||
streamout << G4endl;
|
||||
return streamout.str();
|
||||
};
|
||||
|
||||
std::stringstream streamout;
|
||||
streamout << "\n\nType = " << id << "\n" << G4endl;
|
||||
if(tp)
|
||||
{
|
||||
// create a task group (nested inside the 'report_type_comparison' task)
|
||||
G4TaskGroup<std::string> tg(join_output, tp);
|
||||
// create the tasks in the task-group
|
||||
for(auto titr = comp.begin(); titr != comp.end(); ++titr)
|
||||
tg.exec(report_subtype_comparison, titr->first, titr->second);
|
||||
// wait on the tasks to finish and execute the join function
|
||||
// this will block the outer task from completing until all the inner
|
||||
// tasks have been completed
|
||||
streamout << tg.join();
|
||||
}
|
||||
else
|
||||
{
|
||||
// if there isn't a tasking thread-pool then we make traditional
|
||||
// function call on this thread
|
||||
for(auto titr = comp.begin(); titr != comp.end(); ++titr)
|
||||
streamout << report_subtype_comparison(titr->first, titr->second);
|
||||
}
|
||||
// this is the completion of the outer tasks
|
||||
return streamout.str();
|
||||
};
|
||||
|
||||
G4String tasking_result = "";
|
||||
if(tp)
|
||||
{
|
||||
G4cout << "\n\nGenerating diff output via tasking... ";
|
||||
// create a task group to
|
||||
G4TaskGroup<std::string> tg(join_output, tp);
|
||||
for(auto itr = fTypeCompare.begin(); itr != fTypeCompare.end(); ++itr)
|
||||
tg.exec(report_type_comparison, itr->first, itr->second);
|
||||
// wait on the tasks to finish and execute the join function
|
||||
tasking_result = tg.join();
|
||||
}
|
||||
|
||||
// if thread-pool was available, lets validate that tasking did what was
|
||||
// expected
|
||||
if(tp)
|
||||
{
|
||||
// generate the output serially
|
||||
G4String serial_result = "";
|
||||
for(auto itr = fTypeCompare.begin(); itr != fTypeCompare.end(); ++itr)
|
||||
serial_result += report_type_comparison(itr->first, itr->second);
|
||||
|
||||
// write the tasking result even if it was bad so that it can viewed
|
||||
fileout << tasking_result;
|
||||
|
||||
// compare the strings -- should be the same
|
||||
if(serial_result != tasking_result)
|
||||
{
|
||||
G4Exception("TSRunAction", "003", JustWarning,
|
||||
"Output written via tasking did not match output written "
|
||||
"serially. Appending serial result to output file");
|
||||
fileout
|
||||
<< "\n\n#================CORRECT_SERIAL_OUTPUT================#\n\n";
|
||||
fileout << serial_result;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// if thread-pool was not available, then just write serially
|
||||
for(auto itr = fTypeCompare.begin(); itr != fTypeCompare.end(); ++itr)
|
||||
fileout << report_type_comparison(itr->first, itr->second);
|
||||
}
|
||||
|
||||
fileout.close();
|
||||
G4cout << " closed file " << fname << " for difference output" << G4endl;
|
||||
G4cout << separator.str() << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user