RunAction::RunAction():af(0), tree(0)
{
histo[0] = 0;
#ifdef G4ANALYSIS_USE
// Creating the analysis factory
af = AIDA_createAnalysisFactory();
if (af) {
// Creating the tree factory
AIDA::ITreeFactory* tf = af->createTreeFactory();
// Creating a tree mapped to an hbook file.
G4bool readOnly = false;
G4bool createNew = true;
G4String options = "--noErrors uncompress";
tree = tf->create("TestEm4.hbook","hbook",readOnly,createNew, options);
//tree = tf->create("TestEm4.root","root",readOnly,createNew, options);
//tree = tf->create("TestEm4.XML" ,"XML" ,readOnly,createNew, options);
delete tf;
if (tree) {
// Creating a histogram factory
AIDA::IHistogramFactory* hf = af->createHistogramFactory(*tree);
// Creating the histogram
histo[0]=hf->createHistogram1D // 头文件中定义了histo[1]
("1","total energy deposit in HpGe Detector(keV)",3000,1.,3000);
// energy ragin 1-5000keV
delete hf;
}
}
#endif
}
RunAction::~RunAction()
{
#ifdef G4ANALYSIS_USE
tree->commit(); // Writing the histograms to the file
tree->close(); // and closing the tree (and the file)
void Histo::book()
{
#ifdef G4ANALYSIS_USE
// Creating the analysis factory
if(!af) af = AIDA_createAnalysisFactory();
// Creating the tree factory
AIDA::ITreeFactory* tf = af->createTreeFactory();
// Creating a tree mapped to a new hbook file.
G4String name = histDir + histName + histExt + "." + histType;
tree = tf->create(name, histType, false, true, option);
delete tf;
// Creating a histogram factory, whose histograms will be handled by the tree
AIDA::IHistogramFactory* hf = af->createHistogramFactory( *tree );
// Creating an 1-dimensional histograms in the root directory of the tree
for(G4int i=0; i<nHisto; i++) {
if(active) {
G4String idd;
if(histType == "root") idd = "h" + ids;
else idd = ids;
histo = hf->createHistogram1D(idd, tittles, bins, xmin, xmax);
} else {
histo = 0;
}
}
delete hf;
// Creating a tuple factory, whose tuples will be handled by the tree
if(tupleList != "") {
AIDA::ITupleFactory* tpf = af->createTupleFactory( *tree );
ntup = tpf->create(tupleId, tupleName, tupleList);
delete tpf;
}
#endif
}
fHisto->fill(p->GetKineticEnergy(), slw);
}作者: 鸿飞冥冥 时间: 2015-4-8 10:17
Geant4 学习心得—AIDA的使用 IV
AIDA(Abstract Interfaces for Data Analysis)主要是提供Hbook,ROOT,或者XML格式输出。在学习的过程中有几种不同的调用方式。
#include "G4RotationMatrix.hh"
class A01DetectorConstruction : public G4VUserDetectorConstruction
{
private:
G4RotationMatrix* armRotation;
}
(2)在DetectorConstruction.cc中定义转动角度,在G4VPlacement中的第一项设置转动。
armRotation = new G4RotationMatrix();
armRotation->rotateY(armAngle);
// second arm
secondArmPhys
= new G4PVPlacement(armRotation,G4ThreeVector(x,0.,z),secondArmLogical,
"secondArmPhys",worldLogical,0,0);
(3)A01中DetectorConstruction.cc的设置磁场转动
// placement of Tube
G4RotationMatrix* fieldRot = new G4RotationMatrix();
fieldRot->rotateX(90.*deg);
new G4PVPlacement(fieldRot,G4ThreeVector(),magneticLogical,
"magneticPhysical",worldLogical,0,0);