Import Geant4 9.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-09 15:16:48 +02:00
parent 75c7fd177d
commit a8e9364cea
6592 changed files with 84274 additions and 69292 deletions
@@ -0,0 +1,473 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: ExN03DetectorConstruction.cc,v 1.1 2007/05/26 00:18:28 tkoi Exp $
// GEANT4 tag $Name: geant4-09-00 $
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "ExN03DetectorConstruction.hh"
#include "ExN03DetectorMessenger.hh"
#include "G4Material.hh"
#include "G4Box.hh"
#include "G4LogicalVolume.hh"
#include "G4PVPlacement.hh"
#include "G4PVReplica.hh"
#include "G4UniformMagField.hh"
#include "G4GeometryManager.hh"
#include "G4PhysicalVolumeStore.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4SolidStore.hh"
#include "G4VisAttributes.hh"
#include "G4Colour.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03DetectorConstruction::ExN03DetectorConstruction()
:AbsorberMaterial(0),GapMaterial(0),defaultMaterial(0),
solidWorld(0),logicWorld(0),physiWorld(0),
solidCalor(0),logicCalor(0),physiCalor(0),
solidLayer(0),logicLayer(0),physiLayer(0),
solidAbsorber(0),logicAbsorber(0),physiAbsorber(0),
solidGap (0),logicGap (0),physiGap (0),
magField(0)
{
// default parameter values of the calorimeter
AbsorberThickness = 10.*mm;
GapThickness = 5.*mm;
NbOfLayers = 10;
CalorSizeYZ = 10.*cm;
ComputeCalorParameters();
// materials
DefineMaterials();
SetAbsorberMaterial("Lead");
SetGapMaterial("liquidArgon");
// create commands for interactive definition of the calorimeter
detectorMessenger = new ExN03DetectorMessenger(this);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03DetectorConstruction::~ExN03DetectorConstruction()
{ delete detectorMessenger;}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4VPhysicalVolume* ExN03DetectorConstruction::Construct()
{
return ConstructCalorimeter();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03DetectorConstruction::DefineMaterials()
{
//This function illustrates the possible ways to define materials
G4String symbol; //a=mass of a mole;
G4double a, z, density; //z=mean number of protons;
G4int iz, n; //iz=number of protons in an isotope;
// n=number of nucleons in an isotope;
G4int ncomponents, natoms;
G4double abundance, fractionmass;
//
// define Elements
//
G4Element* H = new G4Element("Hydrogen",symbol="H" , z= 1., a= 1.01*g/mole);
G4Element* C = new G4Element("Carbon" ,symbol="C" , z= 6., a= 12.01*g/mole);
G4Element* N = new G4Element("Nitrogen",symbol="N" , z= 7., a= 14.01*g/mole);
G4Element* O = new G4Element("Oxygen" ,symbol="O" , z= 8., a= 16.00*g/mole);
G4Element* Si = new G4Element("Silicon",symbol="Si" , z= 14., a= 28.09*g/mole);
//
// define an Element from isotopes, by relative abundance
//
G4Isotope* U5 = new G4Isotope("U235", iz=92, n=235, a=235.01*g/mole);
G4Isotope* U8 = new G4Isotope("U238", iz=92, n=238, a=238.03*g/mole);
G4Element* U = new G4Element("enriched Uranium",symbol="U",ncomponents=2);
U->AddIsotope(U5, abundance= 90.*perCent);
U->AddIsotope(U8, abundance= 10.*perCent);
//
// define simple materials
//
new G4Material("Aluminium", z=13., a=26.98*g/mole, density=2.700*g/cm3);
new G4Material("liquidArgon", z=18., a= 39.95*g/mole, density= 1.390*g/cm3);
new G4Material("Lead" , z=82., a= 207.19*g/mole, density= 11.35*g/cm3);
//
// define a material from elements. case 1: chemical molecule
//
G4Material* H2O =
new G4Material("Water", density= 1.000*g/cm3, ncomponents=2);
H2O->AddElement(H, natoms=2);
H2O->AddElement(O, natoms=1);
// overwrite computed meanExcitationEnergy with ICRU recommended value
H2O->GetIonisation()->SetMeanExcitationEnergy(75.0*eV);
G4Material* Sci =
new G4Material("Scintillator", density= 1.032*g/cm3, ncomponents=2);
Sci->AddElement(C, natoms=9);
Sci->AddElement(H, natoms=10);
G4Material* Myl =
new G4Material("Mylar", density= 1.397*g/cm3, ncomponents=3);
Myl->AddElement(C, natoms=10);
Myl->AddElement(H, natoms= 8);
Myl->AddElement(O, natoms= 4);
G4Material* SiO2 =
new G4Material("quartz",density= 2.200*g/cm3, ncomponents=2);
SiO2->AddElement(Si, natoms=1);
SiO2->AddElement(O , natoms=2);
//
// define a material from elements. case 2: mixture by fractional mass
//
G4Material* Air =
new G4Material("Air" , density= 1.290*mg/cm3, ncomponents=2);
Air->AddElement(N, fractionmass=0.7);
Air->AddElement(O, fractionmass=0.3);
//
// define a material from elements and/or others materials (mixture of mixtures)
//
G4Material* Aerog =
new G4Material("Aerogel", density= 0.200*g/cm3, ncomponents=3);
Aerog->AddMaterial(SiO2, fractionmass=62.5*perCent);
Aerog->AddMaterial(H2O , fractionmass=37.4*perCent);
Aerog->AddElement (C , fractionmass= 0.1*perCent);
//
// examples of gas in non STP conditions
//
G4Material* CO2 =
new G4Material("CarbonicGas", density= 27.*mg/cm3, ncomponents=2,
kStateGas, 325.*kelvin, 50.*atmosphere);
CO2->AddElement(C, natoms=1);
CO2->AddElement(O, natoms=2);
G4Material* steam =
new G4Material("WaterSteam", density= 0.3*mg/cm3, ncomponents=1,
kStateGas, 500.*kelvin, 2.*atmosphere);
steam->AddMaterial(H2O, fractionmass=1.);
//
// examples of vacuum
//
G4Material* Vacuum =
new G4Material("Galactic", z=1., a=1.01*g/mole,density= universe_mean_density,
kStateGas, 2.73*kelvin, 3.e-18*pascal);
G4Material* beam =
new G4Material("Beam", density= 1.e-5*g/cm3, ncomponents=1,
kStateGas, STP_Temperature, 2.e-2*bar);
beam->AddMaterial(Air, fractionmass=1.);
G4cout << *(G4Material::GetMaterialTable()) << G4endl;
//default materials of the World
defaultMaterial = Vacuum;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
G4VPhysicalVolume* ExN03DetectorConstruction::ConstructCalorimeter()
{
// Clean old geometry, if any
//
G4GeometryManager::GetInstance()->OpenGeometry();
G4PhysicalVolumeStore::GetInstance()->Clean();
G4LogicalVolumeStore::GetInstance()->Clean();
G4SolidStore::GetInstance()->Clean();
// complete the Calor parameters definition
ComputeCalorParameters();
//
// World
//
solidWorld = new G4Box("World", //its name
WorldSizeX/2,WorldSizeYZ/2,WorldSizeYZ/2); //its size
logicWorld = new G4LogicalVolume(solidWorld, //its solid
defaultMaterial, //its material
"World"); //its name
physiWorld = new G4PVPlacement(0, //no rotation
G4ThreeVector(), //at (0,0,0)
logicWorld, //its logical volume
"World", //its name
0, //its mother volume
false, //no boolean operation
0); //copy number
//
// Calorimeter
//
solidCalor=0; logicCalor=0; physiCalor=0;
solidLayer=0; logicLayer=0; physiLayer=0;
if (CalorThickness > 0.)
{ solidCalor = new G4Box("Calorimeter", //its name
CalorThickness/2,CalorSizeYZ/2,CalorSizeYZ/2);//size
logicCalor = new G4LogicalVolume(solidCalor, //its solid
defaultMaterial, //its material
"Calorimeter"); //its name
physiCalor = new G4PVPlacement(0, //no rotation
G4ThreeVector(), //at (0,0,0)
logicCalor, //its logical volume
"Calorimeter", //its name
logicWorld, //its mother volume
false, //no boolean operation
0); //copy number
//
// Layer
//
solidLayer = new G4Box("Layer", //its name
LayerThickness/2,CalorSizeYZ/2,CalorSizeYZ/2); //size
logicLayer = new G4LogicalVolume(solidLayer, //its solid
defaultMaterial, //its material
"Layer"); //its name
if (NbOfLayers > 1)
physiLayer = new G4PVReplica("Layer", //its name
logicLayer, //its logical volume
logicCalor, //its mother
kXAxis, //axis of replication
NbOfLayers, //number of replica
LayerThickness); //witdth of replica
else
physiLayer = new G4PVPlacement(0, //no rotation
G4ThreeVector(), //at (0,0,0)
logicLayer, //its logical volume
"Layer", //its name
logicCalor, //its mother volume
false, //no boolean operation
0); //copy number
}
//
// Absorber
//
solidAbsorber=0; logicAbsorber=0; physiAbsorber=0;
if (AbsorberThickness > 0.)
{ solidAbsorber = new G4Box("Absorber", //its name
AbsorberThickness/2,CalorSizeYZ/2,CalorSizeYZ/2);
logicAbsorber = new G4LogicalVolume(solidAbsorber, //its solid
AbsorberMaterial, //its material
AbsorberMaterial->GetName()); //name
physiAbsorber = new G4PVPlacement(0, //no rotation
G4ThreeVector(-GapThickness/2,0.,0.), //its position
logicAbsorber, //its logical volume
AbsorberMaterial->GetName(), //its name
logicLayer, //its mother
false, //no boulean operat
0); //copy number
}
//
// Gap
//
solidGap=0; logicGap=0; physiGap=0;
if (GapThickness > 0.)
{ solidGap = new G4Box("Gap",
GapThickness/2,CalorSizeYZ/2,CalorSizeYZ/2);
logicGap = new G4LogicalVolume(solidGap,
GapMaterial,
GapMaterial->GetName());
physiGap = new G4PVPlacement(0, //no rotation
G4ThreeVector(AbsorberThickness/2,0.,0.), //its position
logicGap, //its logical volume
GapMaterial->GetName(), //its name
logicLayer, //its mother
false, //no boulean operat
0); //copy number
}
PrintCalorParameters();
//
// Visualization attributes
//
logicWorld->SetVisAttributes (G4VisAttributes::Invisible);
G4VisAttributes* simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
simpleBoxVisAtt->SetVisibility(true);
logicCalor->SetVisAttributes(simpleBoxVisAtt);
/*
// Below are vis attributes that permits someone to test / play
// with the interactive expansion / contraction geometry system of the
// vis/OpenInventor driver :
{G4VisAttributes* simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,0.0));
simpleBoxVisAtt->SetVisibility(true);
delete logicCalor->GetVisAttributes();
logicCalor->SetVisAttributes(simpleBoxVisAtt);}
{G4VisAttributes* atb= new G4VisAttributes(G4Colour(1.0,0.0,0.0));
logicLayer->SetVisAttributes(atb);}
{G4VisAttributes* atb= new G4VisAttributes(G4Colour(0.0,1.0,0.0));
atb->SetForceSolid(true);
logicAbsorber->SetVisAttributes(atb);}
{//Set opacity = 0.2 then transparency = 1 - 0.2 = 0.8
G4VisAttributes* atb= new G4VisAttributes(G4Colour(0.0,0.0,1.0,0.2));
atb->SetForceSolid(true);
logicGap->SetVisAttributes(atb);}
*/
//
//always return the physical World
//
return physiWorld;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03DetectorConstruction::PrintCalorParameters()
{
G4cout << "\n------------------------------------------------------------"
<< "\n---> The calorimeter is " << NbOfLayers << " layers of: [ "
<< AbsorberThickness/mm << "mm of " << AbsorberMaterial->GetName()
<< " + "
<< GapThickness/mm << "mm of " << GapMaterial->GetName() << " ] "
<< "\n------------------------------------------------------------\n";
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03DetectorConstruction::SetAbsorberMaterial(G4String materialChoice)
{
// search the material by its name
G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
if (pttoMaterial) AbsorberMaterial = pttoMaterial;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03DetectorConstruction::SetGapMaterial(G4String materialChoice)
{
// search the material by its name
G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
if (pttoMaterial) GapMaterial = pttoMaterial;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03DetectorConstruction::SetAbsorberThickness(G4double val)
{
// change Absorber thickness and recompute the calorimeter parameters
AbsorberThickness = val;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03DetectorConstruction::SetGapThickness(G4double val)
{
// change Gap thickness and recompute the calorimeter parameters
GapThickness = val;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03DetectorConstruction::SetCalorSizeYZ(G4double val)
{
// change the transverse size and recompute the calorimeter parameters
CalorSizeYZ = val;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03DetectorConstruction::SetNbOfLayers(G4int val)
{
NbOfLayers = val;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "G4FieldManager.hh"
#include "G4TransportationManager.hh"
void ExN03DetectorConstruction::SetMagField(G4double fieldValue)
{
//apply a global uniform magnetic field along Z axis
G4FieldManager* fieldMgr
= G4TransportationManager::GetTransportationManager()->GetFieldManager();
if(magField) delete magField; //delete the existing magn field
if(fieldValue!=0.) // create a new one if non nul
{ magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));
fieldMgr->SetDetectorField(magField);
fieldMgr->CreateChordFinder(magField);
} else {
magField = 0;
fieldMgr->SetDetectorField(magField);
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "G4RunManager.hh"
void ExN03DetectorConstruction::UpdateGeometry()
{
G4RunManager::GetRunManager()->DefineWorldVolume(ConstructCalorimeter());
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,150 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: ExN03DetectorMessenger.cc,v 1.1 2007/05/26 00:18:28 tkoi Exp $
// GEANT4 tag $Name: geant4-09-00 $
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "ExN03DetectorMessenger.hh"
#include "ExN03DetectorConstruction.hh"
#include "G4UIdirectory.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UIcmdWithAnInteger.hh"
#include "G4UIcmdWithADoubleAndUnit.hh"
#include "G4UIcmdWithoutParameter.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03DetectorMessenger::ExN03DetectorMessenger(
ExN03DetectorConstruction* ExN03Det)
:ExN03Detector(ExN03Det)
{
N03Dir = new G4UIdirectory("/N03/");
N03Dir->SetGuidance("UI commands of this example");
detDir = new G4UIdirectory("/N03/det/");
detDir->SetGuidance("detector control");
AbsMaterCmd = new G4UIcmdWithAString("/N03/det/setAbsMat",this);
AbsMaterCmd->SetGuidance("Select Material of the Absorber.");
AbsMaterCmd->SetParameterName("choice",false);
AbsMaterCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
GapMaterCmd = new G4UIcmdWithAString("/N03/det/setGapMat",this);
GapMaterCmd->SetGuidance("Select Material of the Gap.");
GapMaterCmd->SetParameterName("choice",false);
GapMaterCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
AbsThickCmd = new G4UIcmdWithADoubleAndUnit("/N03/det/setAbsThick",this);
AbsThickCmd->SetGuidance("Set Thickness of the Absorber");
AbsThickCmd->SetParameterName("Size",false);
AbsThickCmd->SetRange("Size>=0.");
AbsThickCmd->SetUnitCategory("Length");
AbsThickCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
GapThickCmd = new G4UIcmdWithADoubleAndUnit("/N03/det/setGapThick",this);
GapThickCmd->SetGuidance("Set Thickness of the Gap");
GapThickCmd->SetParameterName("Size",false);
GapThickCmd->SetRange("Size>=0.");
GapThickCmd->SetUnitCategory("Length");
GapThickCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
SizeYZCmd = new G4UIcmdWithADoubleAndUnit("/N03/det/setSizeYZ",this);
SizeYZCmd->SetGuidance("Set tranverse size of the calorimeter");
SizeYZCmd->SetParameterName("Size",false);
SizeYZCmd->SetRange("Size>0.");
SizeYZCmd->SetUnitCategory("Length");
SizeYZCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
NbLayersCmd = new G4UIcmdWithAnInteger("/N03/det/setNbOfLayers",this);
NbLayersCmd->SetGuidance("Set number of layers.");
NbLayersCmd->SetParameterName("NbLayers",false);
NbLayersCmd->SetRange("NbLayers>0 && NbLayers<500");
NbLayersCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
UpdateCmd = new G4UIcmdWithoutParameter("/N03/det/update",this);
UpdateCmd->SetGuidance("Update calorimeter geometry.");
UpdateCmd->SetGuidance("This command MUST be applied before \"beamOn\" ");
UpdateCmd->SetGuidance("if you changed geometrical value(s).");
UpdateCmd->AvailableForStates(G4State_Idle);
MagFieldCmd = new G4UIcmdWithADoubleAndUnit("/N03/det/setField",this);
MagFieldCmd->SetGuidance("Define magnetic field.");
MagFieldCmd->SetGuidance("Magnetic field will be in Z direction.");
MagFieldCmd->SetParameterName("Bz",false);
MagFieldCmd->SetUnitCategory("Magnetic flux density");
MagFieldCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03DetectorMessenger::~ExN03DetectorMessenger()
{
delete NbLayersCmd;
delete AbsMaterCmd; delete GapMaterCmd;
delete AbsThickCmd; delete GapThickCmd;
delete SizeYZCmd; delete UpdateCmd;
delete MagFieldCmd;
delete detDir;
delete N03Dir;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03DetectorMessenger::SetNewValue(G4UIcommand* command,G4String newValue)
{
if( command == AbsMaterCmd )
{ ExN03Detector->SetAbsorberMaterial(newValue);}
if( command == GapMaterCmd )
{ ExN03Detector->SetGapMaterial(newValue);}
if( command == AbsThickCmd )
{ ExN03Detector->SetAbsorberThickness(AbsThickCmd
->GetNewDoubleValue(newValue));}
if( command == GapThickCmd )
{ ExN03Detector->SetGapThickness(GapThickCmd->GetNewDoubleValue(newValue));}
if( command == SizeYZCmd )
{ ExN03Detector->SetCalorSizeYZ(SizeYZCmd->GetNewDoubleValue(newValue));}
if( command == NbLayersCmd )
{ ExN03Detector->SetNbOfLayers(NbLayersCmd->GetNewIntValue(newValue));}
if( command == UpdateCmd )
{ ExN03Detector->UpdateGeometry(); }
if( command == MagFieldCmd )
{ ExN03Detector->SetMagField(MagFieldCmd->GetNewDoubleValue(newValue));}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,108 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: ExN03EventAction.cc,v 1.1 2007/05/26 00:18:28 tkoi Exp $
// GEANT4 tag $Name: geant4-09-00 $
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "ExN03EventAction.hh"
#include "ExN03RunAction.hh"
#include "ExN03EventActionMessenger.hh"
#include "G4Event.hh"
#include "G4TrajectoryContainer.hh"
#include "G4VTrajectory.hh"
#include "G4VVisManager.hh"
#include "G4UnitsTable.hh"
#include "Randomize.hh"
#include <iomanip>
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03EventAction::ExN03EventAction(ExN03RunAction* run)
:runAct(run),printModulo(1),eventMessenger(0)
{
eventMessenger = new ExN03EventActionMessenger(this);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03EventAction::~ExN03EventAction()
{
delete eventMessenger;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03EventAction::BeginOfEventAction(const G4Event* evt)
{
G4int evtNb = evt->GetEventID();
if (evtNb%printModulo == 0) {
G4cout << "\n---> Begin of event: " << evtNb << G4endl;
CLHEP::HepRandom::showEngineStatus();
}
// initialisation per event
EnergyAbs = EnergyGap = 0.;
TrackLAbs = TrackLGap = 0.;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03EventAction::EndOfEventAction(const G4Event* evt)
{
//accumulates statistic
//
runAct->fillPerEvent(EnergyAbs, EnergyGap, TrackLAbs, TrackLGap);
//print per event (modulo n)
//
G4int evtNb = evt->GetEventID();
if (evtNb%printModulo == 0) {
G4cout << "---> End of event: " << evtNb << G4endl;
G4cout
<< " Absorber: total energy: " << std::setw(7)
<< G4BestUnit(EnergyAbs,"Energy")
<< " total track length: " << std::setw(7)
<< G4BestUnit(TrackLAbs,"Length")
<< G4endl
<< " Gap: total energy: " << std::setw(7)
<< G4BestUnit(EnergyGap,"Energy")
<< " total track length: " << std::setw(7)
<< G4BestUnit(TrackLGap,"Length")
<< G4endl;
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,73 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: ExN03EventActionMessenger.cc,v 1.1 2007/05/26 00:18:28 tkoi Exp $
// GEANT4 tag $Name: geant4-09-00 $
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "ExN03EventActionMessenger.hh"
#include "ExN03EventAction.hh"
#include "G4UIdirectory.hh"
#include "G4UIcmdWithAnInteger.hh"
#include "globals.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03EventActionMessenger::ExN03EventActionMessenger(ExN03EventAction* EvAct)
:eventAction(EvAct)
{
eventDir = new G4UIdirectory("/N03/event/");
eventDir->SetGuidance("event control");
PrintCmd = new G4UIcmdWithAnInteger("/N03/event/printModulo",this);
PrintCmd->SetGuidance("Print events modulo n");
PrintCmd->SetParameterName("EventNb",false);
PrintCmd->SetRange("EventNb>0");
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03EventActionMessenger::~ExN03EventActionMessenger()
{
delete PrintCmd;
delete eventDir;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03EventActionMessenger::SetNewValue(
G4UIcommand* command,G4String newValue)
{
if(command == PrintCmd)
{eventAction->SetPrintModulo(PrintCmd->GetNewIntValue(newValue));}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,244 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: ExN03PhysicsList.cc,v 1.1 2007/05/26 00:18:28 tkoi Exp $
// GEANT4 tag $Name: geant4-09-00 $
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "ExN03PhysicsList.hh"
#include "G4ProcessManager.hh"
#include "G4ParticleTypes.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03PhysicsList::ExN03PhysicsList(): G4VUserPhysicsList()
{
defaultCutValue = 1.0*mm;
SetVerboseLevel(1);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03PhysicsList::~ExN03PhysicsList()
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03PhysicsList::ConstructParticle()
{
// In this method, static member functions should be called
// for all particles which you want to use.
// This ensures that objects of these particle types will be
// created in the program.
ConstructBosons();
ConstructLeptons();
ConstructMesons();
ConstructBaryons();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03PhysicsList::ConstructBosons()
{
// pseudo-particles
G4Geantino::GeantinoDefinition();
G4ChargedGeantino::ChargedGeantinoDefinition();
// gamma
G4Gamma::GammaDefinition();
// optical photon
G4OpticalPhoton::OpticalPhotonDefinition();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03PhysicsList::ConstructLeptons()
{
// leptons
G4Electron::ElectronDefinition();
G4Positron::PositronDefinition();
G4MuonPlus::MuonPlusDefinition();
G4MuonMinus::MuonMinusDefinition();
G4NeutrinoE::NeutrinoEDefinition();
G4AntiNeutrinoE::AntiNeutrinoEDefinition();
G4NeutrinoMu::NeutrinoMuDefinition();
G4AntiNeutrinoMu::AntiNeutrinoMuDefinition();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03PhysicsList::ConstructMesons()
{
// mesons
G4PionPlus::PionPlusDefinition();
G4PionMinus::PionMinusDefinition();
G4PionZero::PionZeroDefinition();
G4Eta::EtaDefinition();
G4EtaPrime::EtaPrimeDefinition();
G4KaonPlus::KaonPlusDefinition();
G4KaonMinus::KaonMinusDefinition();
G4KaonZero::KaonZeroDefinition();
G4AntiKaonZero::AntiKaonZeroDefinition();
G4KaonZeroLong::KaonZeroLongDefinition();
G4KaonZeroShort::KaonZeroShortDefinition();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03PhysicsList::ConstructBaryons()
{
// barions
G4Proton::ProtonDefinition();
G4AntiProton::AntiProtonDefinition();
G4Neutron::NeutronDefinition();
G4AntiNeutron::AntiNeutronDefinition();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03PhysicsList::ConstructProcess()
{
AddTransportation();
ConstructEM();
ConstructGeneral();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "G4ComptonScattering.hh"
#include "G4GammaConversion.hh"
#include "G4PhotoElectricEffect.hh"
#include "G4MultipleScattering.hh"
#include "G4eIonisation.hh"
#include "G4eBremsstrahlung.hh"
#include "G4eplusAnnihilation.hh"
#include "G4MuIonisation.hh"
#include "G4MuBremsstrahlung.hh"
#include "G4MuPairProduction.hh"
#include "G4hIonisation.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03PhysicsList::ConstructEM()
{
theParticleIterator->reset();
while( (*theParticleIterator)() ){
G4ParticleDefinition* particle = theParticleIterator->value();
G4ProcessManager* pmanager = particle->GetProcessManager();
G4String particleName = particle->GetParticleName();
if (particleName == "gamma") {
// gamma
pmanager->AddDiscreteProcess(new G4PhotoElectricEffect);
pmanager->AddDiscreteProcess(new G4ComptonScattering);
pmanager->AddDiscreteProcess(new G4GammaConversion);
} else if (particleName == "e-") {
//electron
pmanager->AddProcess(new G4MultipleScattering,-1, 1,1);
pmanager->AddProcess(new G4eIonisation, -1, 2,2);
pmanager->AddProcess(new G4eBremsstrahlung, -1, 3,3);
} else if (particleName == "e+") {
//positron
pmanager->AddProcess(new G4MultipleScattering,-1, 1,1);
pmanager->AddProcess(new G4eIonisation, -1, 2,2);
pmanager->AddProcess(new G4eBremsstrahlung, -1, 3,3);
pmanager->AddProcess(new G4eplusAnnihilation, 0,-1,4);
} else if( particleName == "mu+" ||
particleName == "mu-" ) {
//muon
pmanager->AddProcess(new G4MultipleScattering,-1, 1,1);
pmanager->AddProcess(new G4MuIonisation, -1, 2,2);
pmanager->AddProcess(new G4MuBremsstrahlung, -1, 3,3);
pmanager->AddProcess(new G4MuPairProduction, -1, 4,4);
} else if ((!particle->IsShortLived()) &&
(particle->GetPDGCharge() != 0.0) &&
(particle->GetParticleName() != "chargedgeantino")) {
//all others charged particles except geantino
pmanager->AddProcess(new G4MultipleScattering,-1, 1,1);
pmanager->AddProcess(new G4hIonisation, -1, 2,2);
}
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "G4Decay.hh"
void ExN03PhysicsList::ConstructGeneral()
{
// Add Decay Process
G4Decay* theDecayProcess = new G4Decay();
theParticleIterator->reset();
while( (*theParticleIterator)() ){
G4ParticleDefinition* particle = theParticleIterator->value();
G4ProcessManager* pmanager = particle->GetProcessManager();
if (theDecayProcess->IsApplicable(*particle)) {
pmanager ->AddProcess(theDecayProcess);
// set ordering for PostStepDoIt and AtRestDoIt
pmanager ->SetProcessOrdering(theDecayProcess, idxPostStep);
pmanager ->SetProcessOrdering(theDecayProcess, idxAtRest);
}
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03PhysicsList::SetCuts()
{
if (verboseLevel >0){
G4cout << "ExN03PhysicsList::SetCuts:";
G4cout << "CutLength : " << G4BestUnit(defaultCutValue,"Length") << G4endl;
}
// set cut values for gamma at first and for e- second and next for e+,
// because some processes for e+/e- need cut values for gamma
//
SetCutValue(defaultCutValue, "gamma");
SetCutValue(defaultCutValue, "e-");
SetCutValue(defaultCutValue, "e+");
if (verboseLevel>0) DumpCutValuesTable();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,98 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: ExN03PrimaryGeneratorAction.cc,v 1.1 2007/05/26 00:18:28 tkoi Exp $
// GEANT4 tag $Name: geant4-09-00 $
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "ExN03PrimaryGeneratorAction.hh"
#include "ExN03DetectorConstruction.hh"
#include "ExN03PrimaryGeneratorMessenger.hh"
#include "G4Event.hh"
#include "G4ParticleGun.hh"
#include "G4ParticleTable.hh"
#include "G4ParticleDefinition.hh"
#include "Randomize.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03PrimaryGeneratorAction::ExN03PrimaryGeneratorAction(
ExN03DetectorConstruction* ExN03DC)
:ExN03Detector(ExN03DC),rndmFlag("off")
{
G4int n_particle = 1;
particleGun = new G4ParticleGun(n_particle);
//create a messenger for this class
gunMessenger = new ExN03PrimaryGeneratorMessenger(this);
// default particle kinematic
G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
G4String particleName;
G4ParticleDefinition* particle
= particleTable->FindParticle(particleName="e-");
particleGun->SetParticleDefinition(particle);
particleGun->SetParticleMomentumDirection(G4ThreeVector(1.,0.,0.));
particleGun->SetParticleEnergy(50.*MeV);
G4double position = -0.5*(ExN03Detector->GetWorldSizeX());
particleGun->SetParticlePosition(G4ThreeVector(position,0.*cm,0.*cm));
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03PrimaryGeneratorAction::~ExN03PrimaryGeneratorAction()
{
delete particleGun;
delete gunMessenger;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
{
//this function is called at the begining of event
//
G4double x0 = -0.5*(ExN03Detector->GetWorldSizeX());
G4double y0 = 0.*cm, z0 = 0.*cm;
if (rndmFlag == "on")
{y0 = (ExN03Detector->GetCalorSizeYZ())*(G4UniformRand()-0.5);
z0 = (ExN03Detector->GetCalorSizeYZ())*(G4UniformRand()-0.5);
}
particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
particleGun->GeneratePrimaryVertex(anEvent);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,77 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: ExN03PrimaryGeneratorMessenger.cc,v 1.1 2007/05/26 00:18:28 tkoi Exp $
// GEANT4 tag $Name: geant4-09-00 $
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "ExN03PrimaryGeneratorMessenger.hh"
#include "ExN03PrimaryGeneratorAction.hh"
#include "G4UIdirectory.hh"
#include "G4UIcmdWithAString.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03PrimaryGeneratorMessenger::ExN03PrimaryGeneratorMessenger(
ExN03PrimaryGeneratorAction* ExN03Gun)
:ExN03Action(ExN03Gun)
{
gunDir = new G4UIdirectory("/N03/gun/");
gunDir->SetGuidance("PrimaryGenerator control");
RndmCmd = new G4UIcmdWithAString("/N03/gun/rndm",this);
RndmCmd->SetGuidance("Shoot randomly the incident particle.");
RndmCmd->SetGuidance(" Choice : on(default), off");
RndmCmd->SetParameterName("choice",true);
RndmCmd->SetDefaultValue("on");
RndmCmd->SetCandidates("on off");
RndmCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03PrimaryGeneratorMessenger::~ExN03PrimaryGeneratorMessenger()
{
delete RndmCmd;
delete gunDir;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03PrimaryGeneratorMessenger::SetNewValue(
G4UIcommand* command, G4String newValue)
{
if( command == RndmCmd )
{ ExN03Action->SetRndmFlag(newValue);}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,143 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: ExN03RunAction.cc,v 1.1 2007/05/26 00:18:28 tkoi Exp $
// GEANT4 tag $Name: geant4-09-00 $
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "ExN03RunAction.hh"
#include "G4Run.hh"
#include "G4RunManager.hh"
#include "G4UnitsTable.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03RunAction::ExN03RunAction()
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03RunAction::~ExN03RunAction()
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03RunAction::BeginOfRunAction(const G4Run* aRun)
{
G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
//inform the runManager to save random number seed
//G4RunManager::GetRunManager()->SetRandomNumberStore(true);
//initialize cumulative quantities
//
sumEAbs = sum2EAbs =sumEGap = sum2EGap = 0.;
sumLAbs = sum2LAbs =sumLGap = sum2LGap = 0.;
Eabs_tally = new G4ConvergenceTester();
Egap_tally = new G4ConvergenceTester();
Labs_tally = new G4ConvergenceTester();
Lgap_tally = new G4ConvergenceTester();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03RunAction::fillPerEvent(G4double EAbs, G4double EGap,
G4double LAbs, G4double LGap)
{
//accumulate statistic
//
sumEAbs += EAbs; sum2EAbs += EAbs*EAbs;
sumEGap += EGap; sum2EGap += EGap*EGap;
sumLAbs += LAbs; sum2LAbs += LAbs*LAbs;
sumLGap += LGap; sum2LGap += LGap*LGap;
Eabs_tally->AddScore( EAbs );
Egap_tally->AddScore( EGap );
Labs_tally->AddScore( LAbs );
Lgap_tally->AddScore( LGap );
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03RunAction::EndOfRunAction(const G4Run* aRun)
{
G4int NbOfEvents = aRun->GetNumberOfEvent();
if (NbOfEvents == 0) return;
//compute statistics: mean and rms
//
sumEAbs /= NbOfEvents; sum2EAbs /= NbOfEvents;
G4double rmsEAbs = sum2EAbs - sumEAbs*sumEAbs;
if (rmsEAbs >0.) rmsEAbs = std::sqrt(rmsEAbs); else rmsEAbs = 0.;
sumEGap /= NbOfEvents; sum2EGap /= NbOfEvents;
G4double rmsEGap = sum2EGap - sumEGap*sumEGap;
if (rmsEGap >0.) rmsEGap = std::sqrt(rmsEGap); else rmsEGap = 0.;
sumLAbs /= NbOfEvents; sum2LAbs /= NbOfEvents;
G4double rmsLAbs = sum2LAbs - sumLAbs*sumLAbs;
if (rmsLAbs >0.) rmsLAbs = std::sqrt(rmsLAbs); else rmsLAbs = 0.;
sumLGap /= NbOfEvents; sum2LGap /= NbOfEvents;
G4double rmsLGap = sum2LGap - sumLGap*sumLGap;
if (rmsLGap >0.) rmsLGap = std::sqrt(rmsLGap); else rmsLGap = 0.;
//print
//
G4cout
<< "\n--------------------End of Run------------------------------\n"
<< "\n mean Energy in Absorber : " << G4BestUnit(sumEAbs,"Energy")
<< " +- " << G4BestUnit(rmsEAbs,"Energy")
<< "\n mean Energy in Gap : " << G4BestUnit(sumEGap,"Energy")
<< " +- " << G4BestUnit(rmsEGap,"Energy")
<< G4endl;
G4cout
<< "\n mean trackLength in Absorber : " << G4BestUnit(sumLAbs,"Length")
<< " +- " << G4BestUnit(rmsLAbs,"Length")
<< "\n mean trackLength in Gap : " << G4BestUnit(sumLGap,"Length")
<< " +- " << G4BestUnit(rmsLGap,"Length")
<< "\n------------------------------------------------------------\n"
<< G4endl;
Eabs_tally->ShowResult();
Eabs_tally->ShowHistory();
Egap_tally->ShowResult();
Egap_tally->ShowHistory();
Labs_tally->ShowResult();
Labs_tally->ShowHistory();
Lgap_tally->ShowResult();
Lgap_tally->ShowHistory();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,78 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: ExN03SteppingAction.cc,v 1.1 2007/05/26 00:18:28 tkoi Exp $
// GEANT4 tag $Name: geant4-09-00 $
//
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "ExN03SteppingAction.hh"
#include "ExN03DetectorConstruction.hh"
#include "ExN03EventAction.hh"
#include "G4Step.hh"
////#include "G4RunManager.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03SteppingAction::ExN03SteppingAction(ExN03DetectorConstruction* det,
ExN03EventAction* evt)
:detector(det), eventaction(evt)
{ }
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03SteppingAction::~ExN03SteppingAction()
{ }
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03SteppingAction::UserSteppingAction(const G4Step* aStep)
{
// get volume of the current step
G4VPhysicalVolume* volume
= aStep->GetPreStepPoint()->GetTouchableHandle()->GetVolume();
// collect energy and track length step by step
G4double edep = aStep->GetTotalEnergyDeposit();
G4double stepl = 0.;
if (aStep->GetTrack()->GetDefinition()->GetPDGCharge() != 0.)
stepl = aStep->GetStepLength();
if (volume == detector->GetAbsorber()) eventaction->AddAbs(edep,stepl);
if (volume == detector->GetGap()) eventaction->AddGap(edep,stepl);
//example of saving random number seed of this event, under condition
//// if (condition) G4RunManager::GetRunManager()->rndmSaveThisEvent();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,182 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: ExN03SteppingVerbose.cc,v 1.1 2007/05/26 00:18:28 tkoi Exp $
// GEANT4 tag $Name: geant4-09-00 $
//
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#include "ExN03SteppingVerbose.hh"
#include "G4SteppingManager.hh"
#include "G4UnitsTable.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03SteppingVerbose::ExN03SteppingVerbose()
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
ExN03SteppingVerbose::~ExN03SteppingVerbose()
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03SteppingVerbose::StepInfo()
{
CopyState();
G4int prec = G4cout.precision(3);
if( verboseLevel >= 1 ){
if( verboseLevel >= 4 ) VerboseTrack();
if( verboseLevel >= 3 ){
G4cout << G4endl;
G4cout << std::setw( 5) << "#Step#" << " "
<< std::setw( 6) << "X" << " "
<< std::setw( 6) << "Y" << " "
<< std::setw( 6) << "Z" << " "
<< std::setw( 9) << "KineE" << " "
<< std::setw( 9) << "dEStep" << " "
<< std::setw(10) << "StepLeng"
<< std::setw(10) << "TrakLeng"
<< std::setw(10) << "Volume" << " "
<< std::setw(10) << "Process" << G4endl;
}
G4cout << std::setw(5) << fTrack->GetCurrentStepNumber() << " "
<< std::setw(6) << G4BestUnit(fTrack->GetPosition().x(),"Length")
<< std::setw(6) << G4BestUnit(fTrack->GetPosition().y(),"Length")
<< std::setw(6) << G4BestUnit(fTrack->GetPosition().z(),"Length")
<< std::setw(6) << G4BestUnit(fTrack->GetKineticEnergy(),"Energy")
<< std::setw(6) << G4BestUnit(fStep->GetTotalEnergyDeposit(),"Energy")
<< std::setw(6) << G4BestUnit(fStep->GetStepLength(),"Length")
<< std::setw(6) << G4BestUnit(fTrack->GetTrackLength(),"Length")
<< " ";
// if( fStepStatus != fWorldBoundary){
if( fTrack->GetNextVolume() != 0 ) {
G4cout << std::setw(10) << fTrack->GetVolume()->GetName();
} else {
G4cout << std::setw(10) << "OutOfWorld";
}
if(fStep->GetPostStepPoint()->GetProcessDefinedStep() != 0){
G4cout << " "
<< std::setw(10)
<< fStep->GetPostStepPoint()->GetProcessDefinedStep()
->GetProcessName();
} else {
G4cout << " UserLimit";
}
G4cout << G4endl;
if( verboseLevel == 2 ){
G4int tN2ndariesTot = fN2ndariesAtRestDoIt +
fN2ndariesAlongStepDoIt +
fN2ndariesPostStepDoIt;
if(tN2ndariesTot>0){
G4cout << " :----- List of 2ndaries - "
<< "#SpawnInStep=" << std::setw(3) << tN2ndariesTot
<< "(Rest=" << std::setw(2) << fN2ndariesAtRestDoIt
<< ",Along=" << std::setw(2) << fN2ndariesAlongStepDoIt
<< ",Post=" << std::setw(2) << fN2ndariesPostStepDoIt
<< "), "
<< "#SpawnTotal=" << std::setw(3) << (*fSecondary).size()
<< " ---------------"
<< G4endl;
for(size_t lp1=(*fSecondary).size()-tN2ndariesTot;
lp1<(*fSecondary).size(); lp1++){
G4cout << " : "
<< std::setw(6)
<< G4BestUnit((*fSecondary)[lp1]->GetPosition().x(),"Length")
<< std::setw(6)
<< G4BestUnit((*fSecondary)[lp1]->GetPosition().y(),"Length")
<< std::setw(6)
<< G4BestUnit((*fSecondary)[lp1]->GetPosition().z(),"Length")
<< std::setw(6)
<< G4BestUnit((*fSecondary)[lp1]->GetKineticEnergy(),"Energy")
<< std::setw(10)
<< (*fSecondary)[lp1]->GetDefinition()->GetParticleName();
G4cout << G4endl;
}
G4cout << " :-----------------------------"
<< "----------------------------------"
<< "-- EndOf2ndaries Info ---------------"
<< G4endl;
}
}
}
G4cout.precision(prec);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void ExN03SteppingVerbose::TrackingStarted()
{
CopyState();
G4int prec = G4cout.precision(3);
if( verboseLevel > 0 ){
G4cout << std::setw( 5) << "Step#" << " "
<< std::setw( 6) << "X" << " "
<< std::setw( 6) << "Y" << " "
<< std::setw( 6) << "Z" << " "
<< std::setw( 9) << "KineE" << " "
<< std::setw( 9) << "dEStep" << " "
<< std::setw(10) << "StepLeng"
<< std::setw(10) << "TrakLeng"
<< std::setw(10) << "Volume" << " "
<< std::setw(10) << "Process" << G4endl;
G4cout << std::setw( 5) << fTrack->GetCurrentStepNumber() << " "
<< std::setw( 6) << G4BestUnit(fTrack->GetPosition().x(),"Length")
<< std::setw( 6) << G4BestUnit(fTrack->GetPosition().y(),"Length")
<< std::setw( 6) << G4BestUnit(fTrack->GetPosition().z(),"Length")
<< std::setw( 6) << G4BestUnit(fTrack->GetKineticEnergy(),"Energy")
<< std::setw( 6) << G4BestUnit(fStep->GetTotalEnergyDeposit(),"Energy")
<< std::setw( 6) << G4BestUnit(fStep->GetStepLength(),"Length")
<< std::setw( 6) << G4BestUnit(fTrack->GetTrackLength(),"Length")
<< " ";
if(fTrack->GetNextVolume()){
G4cout << std::setw(10) << fTrack->GetVolume()->GetName();
} else {
G4cout << "OutOfWorld";
}
G4cout << " initStep" << G4endl;
}
G4cout.precision(prec);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -0,0 +1,696 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
// Convergence Tests for Monte Carlo resut.
//
// Reference
// MCNP(TM) -A General Monte Carlo N-Particle Transport Code
// Version 4B
// Judith F. Briesmeister, Editor
// LA-12625-M, Issued: March 1997, UC 705 and UC 700
// CHAPTER 2. GEOMETRY, DATA, PHYSICS, AND MATHEMATICS
// VI. ESTIMATION OF THE MONTE CARLO PRECISION
//
// Positives numbers are assumed for inputs
//
// Koi, Tatsumi (SLAC/SCCS)
//
#include "G4ConvergenceTester.hh"
G4ConvergenceTester::G4ConvergenceTester()
{
nonzero_histories.clear();
largest_scores.clear();
largest_scores.push_back( 0.0 );
n=0;
sum=0;
noBinOfHistory = 16;
history_grid.resize( noBinOfHistory , 0 );
mean_history.resize( noBinOfHistory , 0.0 );
var_history.resize( noBinOfHistory , 0.0 );
sd_history.resize( noBinOfHistory , 0.0 );
r_history.resize( noBinOfHistory , 0.0 );
vov_history.resize( noBinOfHistory , 0.0 );
fom_history.resize( noBinOfHistory , 0.0 );
shift_history.resize( noBinOfHistory , 0.0 );
e_history.resize( noBinOfHistory , 0.0 );
r2eff_history.resize( noBinOfHistory , 0.0 );
r2int_history.resize( noBinOfHistory , 0.0 );
timer = new G4Timer();
timer->Start();
cpu_time.clear();
cpu_time.push_back( 0.0 );
noBinOfPDF = 10; // this will be used calculating SLOPE
noPass = 0;
noTotal = 8;
}
G4ConvergenceTester::~G4ConvergenceTester()
{
delete timer;
}
void G4ConvergenceTester::AddScore( G4double x )
{
//G4cout << x << G4endl;
timer->Stop();
cpu_time.push_back( timer->GetSystemElapsed() + timer->GetUserElapsed() );
if ( x == 0.0 )
{
}
else
{
nonzero_histories.insert( std::pair< G4int , G4double > ( n , x ) );
if ( x > largest_scores.back() )
{
// Following serch should become faster if begin from bottom.
std::vector< G4double >::iterator it;
for ( it = largest_scores.begin() ; it != largest_scores.end() ; it++ )
{
if ( x > *it )
{
largest_scores.insert( it , x );
break;
}
}
if ( largest_scores.size() > 201 )
{
largest_scores.pop_back();
}
//G4cout << largest_scores.size() << " " << largest_scores.front() << " " << largest_scores.back() << G4endl;
}
sum += x;
}
n++;
return;
}
void G4ConvergenceTester::calStat()
{
efficiency = double( nonzero_histories.size() ) / n;
mean = sum / n;
G4double sum_x2 = 0.0;
var = 0.0;
shift = 0.0;
vov = 0.0;
G4double xi;
std::map< G4int , G4double >::iterator it;
for ( it = nonzero_histories.begin() ; it != nonzero_histories.end() ; it++ )
{
xi = it->second;
sum_x2 += xi * xi;
var += ( xi - mean ) * ( xi - mean );
shift += ( xi - mean ) * ( xi - mean ) * ( xi - mean );
vov += ( xi - mean ) * ( xi - mean ) * ( xi - mean ) * ( xi - mean );
}
var += ( n - nonzero_histories.size() ) * mean * mean;
shift += ( n - nonzero_histories.size() ) * mean * mean * mean * ( -1 );
vov += ( n - nonzero_histories.size() ) * mean * mean * mean * mean;
vov = vov / ( var * var ) - 1.0 / n;
var = var/(n-1);
sd = std::sqrt ( var );
r = sd / mean / std::sqrt ( n );
r2eff = ( 1 - efficiency ) / ( efficiency * n );
r2int = sum_x2 / ( sum * sum ) - 1 / ( efficiency * n );
shift = shift / ( 2 * var * n );
fom = 1 / (r*r) / cpu_time.back();
// Find Largest History
//G4double largest = 0.0;
largest = 0.0;
largest_score_happened = 0;
G4double spend_time_of_largest = 0.0;
for ( it = nonzero_histories.begin() ; it != nonzero_histories.end() ; it++ )
{
if ( std::abs ( it->second ) > largest )
{
largest = it->second;
largest_score_happened = it->first;
spend_time_of_largest = cpu_time [ it->first ] - cpu_time [ it->first - 1 ];
}
}
mean_1 = 0.0;
var_1 = 0.0;
shift_1 = 0.0;
vov_1 = 0.0;
sd_1 = 0.0;
r_1 = 0.0;
vov_1 = 0.0;
// G4cout << "The largest history = " << largest << G4endl;
mean_1 = ( sum + largest ) / ( n + 1 );
sum_x2 = 0.0;
for ( it = nonzero_histories.begin() ; it != nonzero_histories.end() ; it++ )
{
xi = it->second;
sum_x2 += xi * xi;
var_1 += ( xi - mean_1 ) * ( xi - mean_1 );
shift_1 += ( xi - mean_1 ) * ( xi - mean_1 ) * ( xi - mean_1 );
vov_1 += ( xi - mean_1 ) * ( xi - mean_1 ) * ( xi - mean_1 ) * ( xi - mean_1 );
}
xi = largest;
sum_x2 += xi * xi;
var_1 += ( xi - mean_1 ) * ( xi - mean_1 );
shift_1 += ( xi - mean_1 ) * ( xi - mean_1 ) * ( xi - mean_1 );
vov_1 += ( xi - mean_1 ) * ( xi - mean_1 ) * ( xi - mean_1 ) * ( xi - mean_1 );
var_1 += ( n - nonzero_histories.size() ) * mean_1 * mean_1;
shift_1 += ( n - nonzero_histories.size() ) * mean_1 * mean_1 * mean_1 * ( -1 );
vov_1 += ( n - nonzero_histories.size() ) * mean_1 * mean_1 * mean_1 * mean_1;
vov_1 = vov_1 / ( var_1 * var_1 ) - 1.0 / ( n + 1 );
var_1 = var_1 / n ;
sd_1 = std::sqrt ( var_1 );
r_1 = sd_1 / mean_1 / std::sqrt ( n + 1 );
shift_1 = shift_1 / ( 2 * var_1 * ( n + 1 ) );
fom_1 = 1 / ( r * r ) / ( cpu_time.back() + spend_time_of_largest );
if ( nonzero_histories.size() < 500 )
{
G4cout << "Number of non zero history too small to calcuarte SLOPE" << G4endl;
}
else
{
G4int i = int ( nonzero_histories.size() );
// 5% criterion
G4int j = int ( i * 0.05 );
while ( int( largest_scores.size() ) > j )
{
largest_scores.pop_back();
}
calc_slope_fit( largest_scores );
}
calc_grid_point_of_history();
calc_stat_history();
}
void G4ConvergenceTester::calc_grid_point_of_history()
{
// histroy_grid [ 0,,,15 ]
// history_grid [0] 1/16 ,,, history_grid [15] 16/16
// if number of event is x then history_grid [15] become x-1.
// 16 -> noBinOfHisotry
G4int i;
for ( i = 1 ; i <= noBinOfHistory ; i++ )
{
history_grid [ i-1 ] = int ( n / ( double( noBinOfHistory ) ) * i - 0.1 );
//G4cout << "history_grid " << i-1 << " " << history_grid [ i-1 ] << G4endl;
}
}
void G4ConvergenceTester::calc_stat_history()
{
// G4cout << "i/16 till_ith mean var sd r vov fom shift e r2eff r2int" << G4endl;
G4int i;
for ( i = 1 ; i <= noBinOfHistory ; i++ )
{
G4int ith = history_grid [ i-1 ];
G4int nonzero_till_ith = 0;
G4double xi;
G4double mean_till_ith = 0.0;
std::map< G4int , G4double >::iterator it;
for ( it = nonzero_histories.begin() ; it !=nonzero_histories.end() ; it++ )
{
if ( it->first <= ith )
{
xi = it->second;
mean_till_ith += xi;
nonzero_till_ith++;
}
}
mean_till_ith = mean_till_ith / ( ith+1 );
mean_history [ i-1 ] = mean_till_ith;
G4double sum_x2_till_ith = 0.0;
G4double var_till_ith = 0.0;
G4double vov_till_ith = 0.0;
G4double shift_till_ith = 0.0;
for ( it = nonzero_histories.begin() ; it !=nonzero_histories.end() ; it++ )
{
if ( it->first <= ith )
{
xi = it->second;
sum_x2_till_ith += xi * xi;
var_till_ith += ( xi - mean_till_ith ) * ( xi - mean_till_ith );
shift_till_ith += ( xi - mean_till_ith ) * ( xi - mean_till_ith ) * ( xi - mean_till_ith );
vov_till_ith += ( xi - mean_till_ith ) * ( xi - mean_till_ith ) * ( xi - mean_till_ith ) * ( xi - mean_till_ith );
}
}
var_till_ith += ( (ith+1) - nonzero_till_ith ) * mean_till_ith * mean_till_ith;
vov_till_ith += ( (ith+1) - nonzero_till_ith ) * mean_till_ith * mean_till_ith * mean_till_ith * mean_till_ith ;
vov_till_ith = vov_till_ith / ( var_till_ith * var_till_ith ) - 1.0 / (ith+1);
vov_history [ i-1 ] = vov_till_ith;
var_till_ith = var_till_ith / ( ith+1 - 1 );
var_history [ i-1 ] = var_till_ith;
sd_history [ i-1 ] = std::sqrt( var_till_ith );
r_history [ i-1 ] = std::sqrt( var_till_ith ) / mean_till_ith / std::sqrt ( 1.0*(ith+1) );
fom_history [ i-1 ] = 1 / ( r_history [ i-1 ] * r_history [ i-1 ] ) / cpu_time [ ith ];
shift_till_ith += ( (ith+1) - nonzero_till_ith ) * mean_till_ith * mean_till_ith * mean_till_ith * ( -1 );
shift_till_ith = shift_till_ith / ( 2 * var_till_ith * (ith+1) );
shift_history [ i-1 ] = shift_till_ith;
e_history [ i-1 ] = 1.0*nonzero_till_ith / (ith+1);
r2eff_history [ i-1 ] = ( 1 - e_history [ i-1 ] ) / ( e_history [ i-1 ] * (ith+1) );
G4double sum_till_ith = mean_till_ith * (ith+1);
r2int_history [ i-1 ] = ( sum_x2_till_ith ) / ( sum_till_ith * sum_till_ith ) - 1 / ( e_history [ i-1 ] * (ith+1) );
}
}
void G4ConvergenceTester::ShowResult()
{
calStat();
G4cout << "EFFICIENCY = " << efficiency << G4endl;
G4cout << "MEAN = " << mean << G4endl;
G4cout << "VAR = " << var << G4endl;
G4cout << "SD = " << sd << G4endl;
G4cout << "R = "<< r << G4endl;
G4cout << "SHIFT = "<< shift << G4endl;
G4cout << "VOV = "<< vov << G4endl;
G4cout << "FOM = "<< fom << G4endl;
G4cout << "THE LARGEST SCORE = " << largest << " and it happend at " << largest_score_happened << "th event" << G4endl;
G4cout << "Affected Mean = " << mean_1 << " and its ratio to orignal is " << mean_1/mean << G4endl;
G4cout << "Affected VAR = " << var_1 << " and its ratio to orignal is " << var_1/var << G4endl;
G4cout << "Affected R = " << r_1 << " and its ratio to orignal is " << r_1/r << G4endl;
G4cout << "Affected SHIFT = " << shift_1 << " and its ratio to orignal is " << shift_1/shift << G4endl;
G4cout << "Affected FOM = " << fom_1 << " and its ratio to orignal is " << fom_1/fom << G4endl;
check_stat_history();
// check SLOPE and output result
if ( slope >= 3 )
{
noPass++;
G4cout << "SLOPE is large enough" << G4endl;
}
else
{
G4cout << "SLOPE is not large enough" << G4endl;
}
G4cout << "This result passes " << noPass << " / "<< noTotal << " Convergence Test." << G4endl;
G4cout << G4endl;
}
void G4ConvergenceTester::ShowHistory()
{
G4cout << "i/" << noBinOfHistory << " till_ith mean var sd r vov fom shift e r2eff r2int" << G4endl;
for ( G4int i = 1 ; i <= noBinOfHistory ; i++ )
{
G4cout << i << " "
<< history_grid [ i-1 ] << " "
<< mean_history [ i-1 ] << " "
<< var_history [ i-1 ] << " "
<< sd_history [ i-1 ] << " "
<< r_history [ i-1 ] << " "
<< vov_history [ i-1 ] << " "
<< fom_history [ i-1 ] << " "
<< shift_history [ i-1 ] << " "
<< e_history [ i-1 ] << " "
<< r2eff_history [ i-1 ] << " "
<< r2int_history [ i-1 ] << " "
<< G4endl;
}
}
void G4ConvergenceTester::check_stat_history()
{
// 1 sigma rejection for null hypothesis
std::vector<G4double> first_ally;
std::vector<G4double> second_ally;
// use 2nd half of hisories
G4int N = mean_history.size() / 2;
G4int i;
G4double pearson_r;
G4double t;
first_ally.resize( N );
second_ally.resize( N );
// Mean
for ( i = 0 ; i < N ; i++ )
{
first_ally [ i ] = history_grid [ N + i ];
second_ally [ i ] = mean_history [ N + i ];
}
pearson_r = calc_Pearson_r ( N , first_ally , second_ally );
t = pearson_r * std::sqrt ( ( N - 2 ) / ( 1 - pearson_r * pearson_r ) );
if ( t < 0.429318 ) // Student t of (Degree of freedom = N-2 )
{
G4cout << "MEAN distribution is RANDOM" << G4endl;
noPass++;
}
else
{
G4cout << "MEAN distribution is not RANDOM" << G4endl;
}
// R
for ( i = 0 ; i < N ; i++ )
{
first_ally [ i ] = 1.0 / std::sqrt ( history_grid [ N + i ] );
second_ally [ i ] = r_history [ N + i ];
}
pearson_r = calc_Pearson_r ( N , first_ally , second_ally );
t = pearson_r * std::sqrt ( ( N - 2 ) / ( 1 - pearson_r * pearson_r ) );
if ( t > 1.090546 )
{
G4cout << "r follows 1/std::sqrt(N)" << G4endl;
noPass++;
}
else
{
G4cout << "r does not follow 1/std::sqrt(N)" << G4endl;
}
G4cout << "r is monotonically decrease " << is_monotonically_decrease( second_ally ) << G4endl;
if ( r_history.back() < 0.1 )
{
G4cout << "r is less than 0.1. r = " << r_history.back() << G4endl;
noPass++;
}
else
{
G4cout << "r is NOT less than 0.1. r = " << r_history.back() << G4endl;
}
// VOV
for ( i = 0 ; i < N ; i++ )
{
first_ally [ i ] = 1.0 / history_grid [ N + i ];
second_ally [ i ] = vov_history [ N + i ];
}
pearson_r = calc_Pearson_r ( N , first_ally , second_ally );
t = pearson_r * std::sqrt ( ( N - 2 ) / ( 1 - pearson_r * pearson_r ) );
if ( t > 1.090546 )
{
G4cout << "VOV follows 1/std::sqrt(N)" << G4endl;
noPass++;
}
else
{
G4cout << "VOV does not follow 1/std::sqrt(N)" << G4endl;
}
G4cout << "VOV is monotonically decrease " << is_monotonically_decrease( second_ally ) << G4endl;
// FOM
for ( i = 0 ; i < N ; i++ )
{
first_ally [ i ] = history_grid [ N + i ];
second_ally [ i ] = fom_history [ N + i ];
}
pearson_r = calc_Pearson_r ( N , first_ally , second_ally );
t = pearson_r * std::sqrt ( ( N - 2 ) / ( 1 - pearson_r * pearson_r ) );
if ( t < 0.429318 )
{
G4cout << "FOM distribution is RANDOM" << G4endl;
noPass++;
}
else
{
G4cout << "FOM distribution is not RANDOM" << G4endl;
}
}
G4double G4ConvergenceTester::calc_Pearson_r ( G4int N , std::vector<G4double> first_ally , std::vector<G4double> second_ally )
{
G4double first_mean = 0.0;
G4double second_mean = 0.0;
G4int i;
for ( i = 0 ; i < N ; i++ )
{
first_mean += first_ally [ i ];
second_mean += second_ally [ i ];
}
first_mean = first_mean / N;
second_mean = second_mean / N;
G4double a = 0.0;
for ( i = 0 ; i < N ; i++ )
{
a += ( first_ally [ i ] - first_mean ) * ( second_ally [ i ] - second_mean );
}
G4double b1 = 0.0;
G4double b2 = 0.0;
for ( i = 0 ; i < N ; i++ )
{
b1 += ( first_ally [ i ] - first_mean ) * ( first_ally [ i ] - first_mean );
b2 += ( second_ally [ i ] - second_mean ) * ( second_ally [ i ] - second_mean );
}
G4double r = a / std::sqrt ( b1 * b2 );
return r;
}
G4bool G4ConvergenceTester::is_monotonically_decrease ( std::vector<G4double> ally )
{
std::vector<G4double>::iterator it;
for ( it = ally.begin() ; it != ally.end() - 1 ; it++ )
{
if ( *it < *(it+1) ) return FALSE;
}
noPass++;
return TRUE;
}
//void G4ConvergenceTester::calc_slope_fit ( std::vector<G4double> largest_socres )
void G4ConvergenceTester::calc_slope_fit ( std::vector<G4double> )
{
// create PDF bins
G4double max = largest_scores.front();
G4int last = int ( largest_scores.size() );
G4double min = 0.0;
if ( largest_scores.back() != 0 )
{
min = largest_scores.back();
}
else
{
min = largest_scores[ last-1 ];
last = last - 1;
}
//G4cout << "largest " << max << G4endl;
//G4cout << "last " << min << G4endl;
if ( max*0.99 < min )
{
// upper limit is assumed to have been reached
slope = 10.0;
return;
}
std::vector < G4double > pdf_grid;
pdf_grid.resize( noBinOfPDF+1 ); // no grid = no bins + 1
pdf_grid[ 0 ] = max;
pdf_grid[ noBinOfPDF ] = min;
G4double log10_max = std::log10( max );
G4double log10_min = std::log10( min );
G4double log10_delta = log10_max - log10_min;
for ( G4int i = 1 ; i < noBinOfPDF ; i++ )
{
pdf_grid[i] = std::pow ( 10.0 , log10_max - log10_delta/10.0*(i) );
//G4cout << "pdf i " << i << " " << pdf_grid[i] << G4endl;
}
std::vector < G4double > pdf;
pdf.resize( noBinOfPDF );
for ( G4int j=0 ; j < last ; j ++ )
{
for ( G4int i = 0 ; i < 11 ; i++ )
{
if ( largest_scores[j] >= pdf_grid[i+1] )
{
pdf[i] += 1.0 / ( pdf_grid[i] - pdf_grid[i+1] ) / n;
//G4cout << "pdf " << j << " " << i << " " << largest_scores[j] << " " << G4endl;
break;
}
}
}
f_xi.resize( noBinOfPDF );
f_yi.resize( noBinOfPDF );
for ( G4int i = 0 ; i < noBinOfPDF ; i++ )
{
//G4cout << "pdf i " << i << " " << (pdf_grid[i]+pdf_grid[i+1])/2 << " " << pdf[i] << G4endl;
f_xi[i] = (pdf_grid[i]+pdf_grid[i+1])/2;
f_yi[i] = pdf[i];
}
// number of variables ( a and k )
minimizer = new G4SimplexDownhill<G4ConvergenceTester> ( this , 2 );
//G4double minimum = minimizer->GetMinimum();
std::vector<G4double> mp = minimizer->GetMinimumPoint();
G4double k = mp[1];
//G4cout << "SLOPE " << 1/mp[1]+1 << G4endl;
//G4cout << "SLOPE a " << mp[0] << G4endl;
//G4cout << "SLOPE k " << mp[1] << G4endl;
//G4cout << "SLOPE minimum " << minimizer->GetMinimum() << G4endl;
slope = 1/mp[1]+1;
if ( k < 1.0/9 ) // Please look Pareto distribution with "sigma=a" and "k"
{
slope = 10;
}
if ( slope > 10 )
{
slope = 10;
}
}
G4double G4ConvergenceTester::slope_fitting_function ( std::vector< G4double > x )
{
G4double a = x[0];
G4double k = x[1];
if ( a <= 0 )
{
return 3.402823466e+38; // FLOAT_MAX
}
if ( k == 0 )
{
return 3.402823466e+38; // FLOAT_MAX
}
// f_xi and f_yi is filled at "calc_slope_fit"
G4double y = 0.0;
G4int i;
for ( i = 0 ; i < int ( f_yi.size() ) ; i++ )
{
//if ( 1/a * ( 1 + k * f_xi [ i ] / a ) < 0 )
if ( ( 1 + k * f_xi [ i ] / a ) < 0 )
{
//return 3.402823466e+38; // FLOAT_MAX
y +=3.402823466e+38; // FLOAT_MAX
}
y += ( f_yi [ i ] - 1/a*std::pow ( ( 1 + k * f_xi [ i ] / a ) , - 1/k - 1 ) ) * ( f_yi [ i ] - 1/a*std::pow ( ( 1 + k * f_xi [ i ] / a ) , - 1/k - 1 ) );
}
// G4cout << "y = " << y << G4endl;
return y;
}