Import Geant4 5.0.0 source tree
This commit is contained in:
@@ -21,8 +21,8 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: exampleB02.cc,v 1.9 2002/05/31 11:46:23 dressel Exp $
|
||||
// GEANT4 tag $Name: geant4-04-01 $
|
||||
// $Id: exampleB02.cc,v 1.13 2002/11/13 15:10:27 dressel Exp $
|
||||
// GEANT4 tag $Name: geant4-05-00 $
|
||||
//
|
||||
//
|
||||
// --------------------------------------------------------------
|
||||
@@ -31,140 +31,159 @@
|
||||
// --------------------------------------------------------------
|
||||
// Comments
|
||||
//
|
||||
// This example intends to show how to use both importance sampling and a
|
||||
// customized scoring making use of the scoring framework
|
||||
// in a parallel geometry.
|
||||
//
|
||||
// A simple geometry consisting of a 180 cm high concrete cylinder
|
||||
// is constructed in the mass geometry.
|
||||
// A geometry is constructed in the parallel geometry
|
||||
// in order to assign importance values to slabs
|
||||
// of width 10cm and for scoring. The parallel world volume should
|
||||
// overlap the mass world volume and the radii of the slabs is larger
|
||||
// than the radius of the concrete cylinder in the mass geometry.
|
||||
// Pairs of G4GeometryCell and importance values are stored in
|
||||
// the importance store.
|
||||
// The scoring uses the G4CellSCorer and one customized scorer for
|
||||
// the last slab.
|
||||
//
|
||||
//
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
#include "g4std/set"
|
||||
#include "g4std/iomanip"
|
||||
#include "g4std/iostream"
|
||||
|
||||
#include "G4VPhysicalVolume.hh"
|
||||
#include "G4RunManager.hh"
|
||||
#include "G4UImanager.hh"
|
||||
|
||||
#include "B02DetectorConstruction.hh"
|
||||
#include "B02PhysicsList.hh"
|
||||
#include "B02PrimaryGeneratorAction.hh"
|
||||
|
||||
#include "B02ScoringDetectorConstruction.hh"
|
||||
// construction for the parallel geometry
|
||||
#include "B02ImportanceDetectorConstruction.hh"
|
||||
|
||||
// Files specific for biasing and scoring
|
||||
#include "G4Scorer.hh"
|
||||
#include "G4ParallelGeometrySampler.hh"
|
||||
#include "G4IStore.hh"
|
||||
|
||||
// customized scorer and store
|
||||
#include "B02CellScorer.hh"
|
||||
#include "B02CellScorerStore.hh"
|
||||
|
||||
// a score table
|
||||
#include "G4ScoreTable.hh"
|
||||
|
||||
// AIDA stuff
|
||||
|
||||
#include "AIDA/IAnalysisFactory.h"
|
||||
#include "AIDA/ITree.h"
|
||||
#include "AIDA/ITreeFactory.h"
|
||||
#include "AIDA/IHistogram1D.h"
|
||||
#include "AIDA/IHistogramFactory.h"
|
||||
|
||||
// Files specific for scoring
|
||||
#include "B02Scorer.hh"
|
||||
#include "G4Sigma.hh"
|
||||
#include "G4ParallelScoreSampler.hh"
|
||||
|
||||
// helper function for print out
|
||||
G4std::string FillString(const G4std::string &name, char c, G4int n, G4bool back = true);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
G4std::ostream *myout = &G4cout;
|
||||
G4int numberOfEvent = 1000;
|
||||
G4int numberOfEvent = 100;
|
||||
|
||||
G4String random_status_out_file, random_status_in_file;
|
||||
G4long myseed = 345354;
|
||||
|
||||
HepRandom::setTheSeed(myseed);
|
||||
|
||||
G4RunManager *runManager = new G4RunManager;
|
||||
|
||||
// create the "tracking" detector -----------------
|
||||
runManager->SetUserInitialization(new B02DetectorConstruction);
|
||||
// create the detector ---------------------------
|
||||
B02DetectorConstruction *detector = new B02DetectorConstruction();
|
||||
runManager->SetUserInitialization(detector);
|
||||
// ---------------------------------------------------
|
||||
runManager->SetUserInitialization(new B02PhysicsList);
|
||||
runManager->SetUserAction(new B02PrimaryGeneratorAction);
|
||||
runManager->Initialize();
|
||||
|
||||
// create the detector for scoring
|
||||
B02ScoringDetectorConstruction scoringdetector;
|
||||
|
||||
// create a parallel detector
|
||||
B02ImportanceDetectorConstruction *pdet =
|
||||
new B02ImportanceDetectorConstruction;
|
||||
|
||||
// create an importance
|
||||
G4IStore aIstore(pdet->GetWorldVolume());
|
||||
// create a geometry cell for the world volume replpicanumber is -1!
|
||||
G4GeometryCell gWorldVolumeCell(pdet->GetWorldVolume(), -1);
|
||||
// set world volume importance to 1
|
||||
aIstore.AddImportanceGeometryCell(1, gWorldVolumeCell);
|
||||
|
||||
// create a customized cell scorer store
|
||||
B02CellScorerStore b02store;
|
||||
|
||||
// set importance values and create scorers
|
||||
G4int cell(1);
|
||||
for (cell=1; cell<=18; cell++) {
|
||||
G4GeometryCell gCell = pdet->GetGeometryCell(cell);
|
||||
G4double imp = pow(2,cell-1);
|
||||
aIstore.AddImportanceGeometryCell(imp, gCell);
|
||||
// adding the standard G4CellScorer for 17 concrete cells
|
||||
if (cell<18) {
|
||||
b02store.AddG4CellScorer(gCell);
|
||||
}
|
||||
}
|
||||
|
||||
// create a histogram for a special scorer for the last cell
|
||||
AIDA::IAnalysisFactory *af = AIDA_createAnalysisFactory();
|
||||
AIDA::ITreeFactory *tf = af->createTreeFactory();
|
||||
AIDA::ITree *tree = tf->create("b02.hbook", "hbook",false,true);
|
||||
AIDA::IHistogramFactory *hf = af->createHistogramFactory( *tree );
|
||||
AIDA::IHistogram1D *h =
|
||||
hf->createHistogram1D("10","w*sl vs. e", 30, 0., 20*MeV);
|
||||
// create a special scorer for the last cell
|
||||
B02CellScorer b02scorer(h);
|
||||
|
||||
// create scorer and sampler to score neutrons in the "scoring" detector
|
||||
B02Scorer pScorer;
|
||||
G4ParallelScoreSampler pmgr(*(scoringdetector.Construct()),
|
||||
"neutron", pScorer);
|
||||
pmgr.Initialize();
|
||||
|
||||
|
||||
|
||||
// creating the geometry cell and add both to the store
|
||||
G4GeometryCell gCell = pdet->GetGeometryCell(18);
|
||||
b02store.AddB02CellScorer(&b02scorer, gCell);
|
||||
|
||||
// create importance geometry cell pair for the "rest"cell
|
||||
// with the same importance as the last concrete cell
|
||||
gCell = pdet->GetGeometryCell(19);
|
||||
G4double imp = pow(2,18);
|
||||
aIstore.AddImportanceGeometryCell(imp, gCell);
|
||||
|
||||
|
||||
// create the importance and scoring sampler for biasing and scoring
|
||||
// in the parallel world
|
||||
|
||||
G4CellStoreScorer scorer(b02store);
|
||||
|
||||
G4ParallelGeometrySampler mgs(pdet->GetWorldVolume(),
|
||||
"neutron");
|
||||
mgs.PrepareScoring(&scorer);
|
||||
mgs.PrepareImportanceSampling(&aIstore, 0);
|
||||
mgs.Configure();
|
||||
|
||||
runManager->BeamOn(numberOfEvent);
|
||||
|
||||
// ======= after running ============================
|
||||
// print a table of the scores
|
||||
G4ScoreTable sp(&aIstore);
|
||||
sp.Print(b02store.GetMapGeometryCellCellScorer(), myout);
|
||||
|
||||
// print all the numbers calculated from the scorer
|
||||
*myout << "output pScorer, scoring detector, neutron" << G4endl;
|
||||
*myout << pScorer << G4endl;
|
||||
*myout << "----------------------------------------------" << G4endl;
|
||||
|
||||
// print some exclusive numbers
|
||||
tree->commit();
|
||||
tree->close();
|
||||
|
||||
// head line
|
||||
G4int FieldName = 25;
|
||||
G4int FieldValue = 12;
|
||||
G4std::string vname = FillString("Volume name", ' ', FieldName+1);
|
||||
*myout << vname << '|';
|
||||
vname = FillString(" AV E/Track ", ' ', FieldValue+1, false);
|
||||
*myout << vname << '|';
|
||||
vname = FillString(" sigma", ' ', FieldValue+1);
|
||||
*myout << vname << '|';
|
||||
vname = FillString("Coll_Ent.Tr", ' ', FieldValue+1, false);
|
||||
*myout << vname << '|';
|
||||
*myout << G4endl;
|
||||
delete af;
|
||||
delete tf;
|
||||
delete tree;
|
||||
|
||||
const G4PMapPtkTallys &m = pScorer.GetMapPtkTallys();
|
||||
for (G4PMapPtkTallys::const_iterator mit = m.begin();
|
||||
mit != m.end(); mit++) {
|
||||
G4PTouchableKey ptk = (*mit).first; // get a key identifying a volume
|
||||
G4PMapNameTally mtallies = (*mit).second; // get tallies of the volume
|
||||
G4String name(ptk.fVPhysiclaVolume->GetName()); // print volume name
|
||||
G4int nEnteringTracks = 0;
|
||||
G4double colli_EnteringTrack = 0;
|
||||
G4double meanTrackEnergy = 0, sigmaTrackEnergy = 0;
|
||||
for (G4PMapNameTally::iterator mt = mtallies.begin();
|
||||
mt != mtallies.end(); mt++) {
|
||||
G4String tmp((*mt).first);
|
||||
if (tmp == "HistorysEntering") {
|
||||
nEnteringTracks = G4int((*mt).second.GetXsum());
|
||||
}
|
||||
if (tmp == "EnergyEnteringHistory") {
|
||||
meanTrackEnergy = (*mt).second.GetMean();
|
||||
sigmaTrackEnergy = (*mt).second.GetSigma();
|
||||
}
|
||||
if (tmp == "Collisions") {
|
||||
if (!nEnteringTracks) {
|
||||
G4cout << "exampleB01: Error nEnteringTracks=0" <<G4endl;
|
||||
}
|
||||
else {
|
||||
colli_EnteringTrack = (*mt).second.GetXsum() / nEnteringTracks;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// print values
|
||||
|
||||
G4std::string fname = FillString(name, '.', FieldName);
|
||||
*myout << fname << " |";
|
||||
*myout << G4std::setw(FieldValue) << meanTrackEnergy << " |";
|
||||
*myout << G4std::setw(FieldValue) << sigmaTrackEnergy << " |";
|
||||
*myout << G4std::setw(FieldValue) << colli_EnteringTrack << " |";
|
||||
*myout << G4endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
G4std::string FillString(const G4std::string &name, char c, G4int n, bool back)
|
||||
{
|
||||
G4std::string fname;
|
||||
G4int k = n - name.size();
|
||||
if (k > 0) {
|
||||
if (back) {
|
||||
fname = name;
|
||||
fname += G4std::string(k,c);
|
||||
}
|
||||
else {
|
||||
fname = G4std::string(k,c);
|
||||
fname += name;
|
||||
}
|
||||
}
|
||||
else {
|
||||
fname = name;
|
||||
}
|
||||
return fname;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user