Import Geant4 10.3.1 source tree
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
# - build library
|
||||
|
||||
# library
|
||||
set(_TARGET ExN03pl)
|
||||
add_library(
|
||||
${_TARGET} SHARED
|
||||
PhysicsList.cc
|
||||
pyExN03pl.cc
|
||||
)
|
||||
|
||||
set_target_properties(${_TARGET} PROPERTIES PREFIX "")
|
||||
set_target_properties(${_TARGET} PROPERTIES SUFFIX ".so")
|
||||
set_target_properties(${_TARGET}
|
||||
PROPERTIES INSTALL_RPATH
|
||||
${GEANT4_LIBRARY_DIR}
|
||||
BUILD_WITH_INSTALL_RPATH TRUE)
|
||||
|
||||
target_link_libraries (${_TARGET}
|
||||
${GEANT4_LIBRARIES_WITH_VIS} boost_python
|
||||
${PYTHON_LIBRARIES})
|
||||
|
||||
# install
|
||||
install(TARGETS ${_TARGET} LIBRARY DESTINATION ${G4SITEMODULES_INSTALL_DIR})
|
||||
@@ -1,226 +0,0 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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: PhysicsList.cc 66892 2013-01-17 10:57:59Z gunter $
|
||||
//
|
||||
//
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#include "PhysicsList.hh"
|
||||
#include "G4SystemOfUnits.hh"
|
||||
|
||||
#include "G4ProcessManager.hh"
|
||||
|
||||
#include "G4BosonConstructor.hh"
|
||||
#include "G4LeptonConstructor.hh"
|
||||
#include "G4MesonConstructor.hh"
|
||||
#include "G4BosonConstructor.hh"
|
||||
#include "G4BaryonConstructor.hh"
|
||||
#include "G4IonConstructor.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
PhysicsList::PhysicsList(): G4VUserPhysicsList()
|
||||
{
|
||||
defaultCutValue = 1.0*mm;
|
||||
SetVerboseLevel(1);
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
PhysicsList::~PhysicsList()
|
||||
{}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void PhysicsList::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.
|
||||
|
||||
G4BosonConstructor pBosonConstructor;
|
||||
pBosonConstructor.ConstructParticle();
|
||||
|
||||
G4LeptonConstructor pLeptonConstructor;
|
||||
pLeptonConstructor.ConstructParticle();
|
||||
|
||||
G4MesonConstructor pMesonConstructor;
|
||||
pMesonConstructor.ConstructParticle();
|
||||
|
||||
G4BaryonConstructor pBaryonConstructor;
|
||||
pBaryonConstructor.ConstructParticle();
|
||||
|
||||
G4IonConstructor pIonConstructor;
|
||||
pIonConstructor.ConstructParticle();
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void PhysicsList::ConstructProcess()
|
||||
{
|
||||
AddTransportation();
|
||||
ConstructEM();
|
||||
ConstructDecay();
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#include "G4PhysicsListHelper.hh"
|
||||
|
||||
#include "G4ComptonScattering.hh"
|
||||
#include "G4GammaConversion.hh"
|
||||
#include "G4PhotoElectricEffect.hh"
|
||||
|
||||
#include "G4eMultipleScattering.hh"
|
||||
#include "G4eIonisation.hh"
|
||||
#include "G4eBremsstrahlung.hh"
|
||||
#include "G4eplusAnnihilation.hh"
|
||||
|
||||
#include "G4MuMultipleScattering.hh"
|
||||
#include "G4MuIonisation.hh"
|
||||
#include "G4MuBremsstrahlung.hh"
|
||||
#include "G4MuPairProduction.hh"
|
||||
|
||||
#include "G4hMultipleScattering.hh"
|
||||
#include "G4hIonisation.hh"
|
||||
#include "G4hBremsstrahlung.hh"
|
||||
#include "G4hPairProduction.hh"
|
||||
|
||||
#include "G4ionIonisation.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void PhysicsList::ConstructEM()
|
||||
{
|
||||
G4PhysicsListHelper* ph = G4PhysicsListHelper::GetPhysicsListHelper();
|
||||
|
||||
theParticleIterator->reset();
|
||||
while( (*theParticleIterator)() ){
|
||||
G4ParticleDefinition* particle = theParticleIterator->value();
|
||||
G4String particleName = particle->GetParticleName();
|
||||
|
||||
if (particleName == "gamma") {
|
||||
// gamma
|
||||
ph->RegisterProcess(new G4PhotoElectricEffect, particle);
|
||||
ph->RegisterProcess(new G4ComptonScattering, particle);
|
||||
ph->RegisterProcess(new G4GammaConversion, particle);
|
||||
|
||||
} else if (particleName == "e-") {
|
||||
//electron
|
||||
ph->RegisterProcess(new G4eMultipleScattering, particle);
|
||||
ph->RegisterProcess(new G4eIonisation, particle);
|
||||
//ph->RegisterProcess(new G4eBremsstrahlung, particle);
|
||||
|
||||
} else if (particleName == "e+") {
|
||||
//positron
|
||||
ph->RegisterProcess(new G4eMultipleScattering, particle);
|
||||
ph->RegisterProcess(new G4eIonisation, particle);
|
||||
//ph->RegisterProcess(new G4eBremsstrahlung, particle);
|
||||
ph->RegisterProcess(new G4eplusAnnihilation, particle);
|
||||
|
||||
} else if( particleName == "mu+" ||
|
||||
particleName == "mu-" ) {
|
||||
//muon
|
||||
ph->RegisterProcess(new G4MuMultipleScattering, particle);
|
||||
ph->RegisterProcess(new G4MuIonisation, particle);
|
||||
ph->RegisterProcess(new G4MuBremsstrahlung, particle);
|
||||
ph->RegisterProcess(new G4MuPairProduction, particle);
|
||||
|
||||
} else if( particleName == "proton" ||
|
||||
particleName == "pi-" ||
|
||||
particleName == "pi+" ) {
|
||||
//proton
|
||||
ph->RegisterProcess(new G4hMultipleScattering, particle);
|
||||
ph->RegisterProcess(new G4hIonisation, particle);
|
||||
ph->RegisterProcess(new G4hBremsstrahlung, particle);
|
||||
ph->RegisterProcess(new G4hPairProduction, particle);
|
||||
|
||||
} else if( particleName == "alpha" ||
|
||||
particleName == "He3" ) {
|
||||
//alpha
|
||||
ph->RegisterProcess(new G4hMultipleScattering, particle);
|
||||
ph->RegisterProcess(new G4ionIonisation, particle);
|
||||
|
||||
} else if( particleName == "GenericIon" ) {
|
||||
//Ions
|
||||
ph->RegisterProcess(new G4hMultipleScattering, particle);
|
||||
ph->RegisterProcess(new G4ionIonisation, particle);
|
||||
|
||||
} else if ((!particle->IsShortLived()) &&
|
||||
(particle->GetPDGCharge() != 0.0) &&
|
||||
(particle->GetParticleName() != "chargedgeantino")) {
|
||||
//all others charged particles except geantino
|
||||
ph->RegisterProcess(new G4hMultipleScattering, particle);
|
||||
ph->RegisterProcess(new G4hIonisation, particle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#include "G4Decay.hh"
|
||||
|
||||
void PhysicsList::ConstructDecay()
|
||||
{
|
||||
G4PhysicsListHelper* ph = G4PhysicsListHelper::GetPhysicsListHelper();
|
||||
|
||||
// Add Decay Process
|
||||
G4Decay* theDecayProcess = new G4Decay();
|
||||
theParticleIterator->reset();
|
||||
while( (*theParticleIterator)() ){
|
||||
G4ParticleDefinition* particle = theParticleIterator->value();
|
||||
if (theDecayProcess->IsApplicable(*particle)) {
|
||||
ph->RegisterProcess(theDecayProcess, particle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
void PhysicsList::SetCuts()
|
||||
{
|
||||
if (verboseLevel >0){
|
||||
G4cout << "PhysicsList::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+");
|
||||
SetCutValue(defaultCutValue, "proton");
|
||||
|
||||
if (verboseLevel>0) DumpCutValuesTable();
|
||||
}
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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: PhysicsList.hh 66892 2013-01-17 10:57:59Z gunter $
|
||||
//
|
||||
//
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#ifndef PhysicsList_h
|
||||
#define PhysicsList_h 1
|
||||
|
||||
#include "G4VUserPhysicsList.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
class PhysicsList: public G4VUserPhysicsList
|
||||
{
|
||||
public:
|
||||
PhysicsList();
|
||||
virtual ~PhysicsList();
|
||||
|
||||
// Construct particle and physics
|
||||
void ConstructParticle();
|
||||
void ConstructProcess();
|
||||
|
||||
void SetCuts();
|
||||
|
||||
private:
|
||||
|
||||
// these methods Construct physics processes and register them
|
||||
void ConstructDecay();
|
||||
void ConstructEM();
|
||||
};
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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: pyExN03pl.cc 76884 2013-11-18 12:54:03Z gcosmo $
|
||||
// ====================================================================
|
||||
// pyExN03pl.cc
|
||||
//
|
||||
// [ExN03pl]
|
||||
// a site-module of Geant4Py
|
||||
//
|
||||
// a physics list presnted in ExN03 of Geant4 example
|
||||
//
|
||||
// 2005 Q
|
||||
// ====================================================================
|
||||
#include <boost/python.hpp>
|
||||
#include "G4RunManager.hh"
|
||||
#include "PhysicsList.hh"
|
||||
|
||||
using namespace boost::python;
|
||||
|
||||
// ====================================================================
|
||||
// thin wrappers
|
||||
// ====================================================================
|
||||
namespace pyExN03pl {
|
||||
|
||||
PhysicsList* Construct()
|
||||
{
|
||||
PhysicsList* pl= new PhysicsList;
|
||||
|
||||
G4RunManager* runMgr= G4RunManager::GetRunManager();
|
||||
runMgr-> SetUserInitialization(pl);
|
||||
|
||||
return pl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using namespace pyExN03pl;
|
||||
|
||||
// ====================================================================
|
||||
// Expose to Python
|
||||
// ====================================================================
|
||||
|
||||
BOOST_PYTHON_MODULE(ExN03pl) {
|
||||
|
||||
class_<PhysicsList, PhysicsList*, bases<G4VUserPhysicsList> >
|
||||
("PhysicsList", "ExN03 physics list")
|
||||
;
|
||||
|
||||
// ---
|
||||
def("Construct", Construct,
|
||||
return_value_policy<reference_existing_object>());
|
||||
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
"""
|
||||
Python module
|
||||
|
||||
This module provides classes and functions for scoring reactions
|
||||
|
||||
[C] MCVertex:
|
||||
[C] MCParticle:
|
||||
[f] read_next_vertex(stream):
|
||||
|
||||
Q, 2006
|
||||
"""
|
||||
import string
|
||||
from Geant4.hepunit import *
|
||||
|
||||
# ==================================================================
|
||||
# public symbols
|
||||
# ==================================================================
|
||||
__all__ = [ 'MCParticle', 'MCVertex', 'read_next_vertex' ]
|
||||
|
||||
|
||||
# ==================================================================
|
||||
# class definition
|
||||
# ==================================================================
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# MCParticle
|
||||
# ------------------------------------------------------------------
|
||||
class MCParticle:
|
||||
"MC particle"
|
||||
def __init__(self, aname, aZ, aA, akE, apx, apy, apz):
|
||||
self.name = aname
|
||||
self.Z = aZ
|
||||
self.A = aA
|
||||
self.kineticE = akE
|
||||
self.px = apx
|
||||
self.py = apy
|
||||
self.pz = apz
|
||||
|
||||
def printout(self):
|
||||
print "--- particle: %s, Z=%2d, A=%2d, kE=%g" % \
|
||||
(self.name, self.Z, self.A, self.kineticE/MeV)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# MCVertex
|
||||
# ------------------------------------------------------------------
|
||||
class MCVertex :
|
||||
"MC vertex"
|
||||
def __init__(self, ax, ay, az):
|
||||
self.x = ax
|
||||
self.y = ay
|
||||
self.z = az
|
||||
self.nparticle = 0
|
||||
self.particle_list = []
|
||||
|
||||
def append_particle(self, aparticle):
|
||||
self.particle_list.append(aparticle)
|
||||
self.nparticle= self.nparticle+1
|
||||
|
||||
def printout(self):
|
||||
print "@@@ vertex: x=(%g,%g,%g) Nsec=%3d" % \
|
||||
(self.x/cm, self.y/cm, self.z/cm, self.nparticle)
|
||||
for p in self.particle_list:
|
||||
p.printout()
|
||||
|
||||
def dump_vertex(self, stream):
|
||||
aline = "%g %g %g %d\n" % \
|
||||
(self.x/m, self.y/m, self.z/m, self.nparticle)
|
||||
stream.write(aline)
|
||||
for p in self.particle_list:
|
||||
aline = " %s %d %d %g %g %g %g\n" % \
|
||||
(p.name, p.Z, p.A, p.kineticE/MeV, p.px/MeV, p.py/MeV, p.pz/MeV)
|
||||
stream.write(aline)
|
||||
|
||||
def __del__(self):
|
||||
np = len(self.particle_list)
|
||||
del self.particle_list[0:np]
|
||||
|
||||
|
||||
# ==================================================================
|
||||
# I/O interface
|
||||
# ==================================================================
|
||||
def read_next_vertex(stream):
|
||||
"read next vertex from a file stream"
|
||||
line= stream.readline()
|
||||
if line == "": # EOF
|
||||
return 0
|
||||
|
||||
# reading vertex
|
||||
data = line.split()
|
||||
x = string.atof(data[0]) * m
|
||||
y = string.atof(data[1]) * m
|
||||
z = string.atof(data[2]) * m
|
||||
nsec = string.atoi(data[3])
|
||||
|
||||
vertex = MCVertex(x,y,z)
|
||||
|
||||
# reading particles
|
||||
for p in range(0, nsec):
|
||||
data = stream.readline().split()
|
||||
pname = data[0]
|
||||
Z = string.atoi(data[1])
|
||||
A = string.atoi(data[2])
|
||||
kE = string.atof(data[3]) * MeV
|
||||
px = string.atof(data[4]) * MeV
|
||||
py = string.atof(data[5]) * MeV
|
||||
pz = string.atof(data[6]) * MeV
|
||||
|
||||
particle = MCParticle(pname, Z, A, kE, px, py, pz)
|
||||
vertex.append_particle(particle)
|
||||
|
||||
return vertex
|
||||
|
||||
|
||||
# ==================================================================
|
||||
# test
|
||||
# ==================================================================
|
||||
def test():
|
||||
f = open("reaction.dat")
|
||||
f.seek(0)
|
||||
|
||||
while(1):
|
||||
vertex = read_next_vertex(f)
|
||||
if vertex == 0:
|
||||
break
|
||||
vertex.printout()
|
||||
del vertex
|
||||
f.close()
|
||||
print ">>> EOF"
|
||||
|
||||
|
||||
# ==================================================================
|
||||
# main
|
||||
# ==================================================================
|
||||
if __name__ == "__main__":
|
||||
test()
|
||||
|
||||
@@ -1,189 +0,0 @@
|
||||
"""
|
||||
Python module
|
||||
|
||||
This module provides ROOT IO interface for MCScore data
|
||||
|
||||
[C] MCScoreROOTIO
|
||||
[f] loop_tree(tfile, analyze_vertex):
|
||||
|
||||
Q, 2006
|
||||
"""
|
||||
from array import array
|
||||
import string
|
||||
from Geant4.hepunit import *
|
||||
import mcscore
|
||||
import ROOT
|
||||
|
||||
# ==================================================================
|
||||
# public symbols
|
||||
# ==================================================================
|
||||
__all__ = [ 'MCScoreROOTIO', 'loop_tree' ]
|
||||
|
||||
|
||||
# ==================================================================
|
||||
# class definition
|
||||
# ==================================================================
|
||||
# ------------------------------------------------------------------
|
||||
# MCScoreROOTIO
|
||||
# ------------------------------------------------------------------
|
||||
class MCScoreROOTIO:
|
||||
"ROOT IO interface for MCScore"
|
||||
def __init__(self, bsize=250):
|
||||
self.maxparticle = bsize # buffer size for #particles/vertex
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
def define_tree(self):
|
||||
"define ROOT tree"
|
||||
# defining tree header...
|
||||
self.vtree = ROOT.TTree('vertex', 'mc vertex')
|
||||
self.ptree = ROOT.TTree('particle', 'mc particle')
|
||||
|
||||
# vertex...
|
||||
self.a_x = array('d', [0.]); self.vtree.Branch('x', self.a_x, 'x/d')
|
||||
self.a_y = array('d', [0.]); self.vtree.Branch('y', self.a_y, 'y/d')
|
||||
self.a_z = array('d', [0.]); self.vtree.Branch('z', self.a_z, 'z/d')
|
||||
|
||||
#global a_np, a_namelist, a_Z, a_A, a_ke, a_px, a_py, a_pz
|
||||
self.a_np = array('i', [0]); self.ptree.Branch('np', self.a_np, 'np/i')
|
||||
|
||||
self.a_namelist = array('c', self.maxparticle*10*['\0'])
|
||||
# 10 characters/particle
|
||||
self.ptree.Branch('namelist', self.a_namelist, 'namelist/C')
|
||||
|
||||
self.a_Z = array('i', self.maxparticle*[0])
|
||||
self.ptree.Branch('Z', self.a_Z, 'Z[np]/I')
|
||||
|
||||
self.a_A = array('i', self.maxparticle*[0])
|
||||
self.ptree.Branch('A', self.a_A, 'A[np]/i')
|
||||
|
||||
self.a_ke = array('d', self.maxparticle*[0.])
|
||||
self.ptree.Branch('kE', self.a_ke, 'kE[np]/d')
|
||||
|
||||
self.a_px = array('d', self.maxparticle*[0.])
|
||||
self.ptree.Branch('px', self.a_px, 'px[np]/d')
|
||||
|
||||
self.a_py = array('d', self.maxparticle*[0.])
|
||||
self.ptree.Branch('py', self.a_py, 'py[np]/d')
|
||||
|
||||
self.a_pz = array('d', self.maxparticle*[0.])
|
||||
self.ptree.Branch('pz', self.a_pz, 'pz[np]/d')
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
def fill_tree(self, vertex):
|
||||
"fill vertex information to ROOT tree"
|
||||
# ------------------------------------------------------------------
|
||||
def push_pname(i0, pname): # local function
|
||||
n = len(pname)
|
||||
for i in xrange(n):
|
||||
self.a_namelist[i0+i] = pname[i]
|
||||
self.a_namelist[i0+n] = ' '
|
||||
|
||||
self.a_x[0] = vertex.x
|
||||
self.a_y[0] = vertex.y
|
||||
self.a_z[0] = vertex.z
|
||||
self.vtree.Fill()
|
||||
|
||||
if vertex.nparticle > self.maxparticle:
|
||||
raise """
|
||||
*** buffer overflow in #particles/vertex.
|
||||
*** please increment buffersize in MCScoreROOTIO(bsize).
|
||||
""", self.maxparticle
|
||||
|
||||
idx_namelist = 0
|
||||
self.a_np[0] = vertex.nparticle
|
||||
for ip in range(vertex.nparticle):
|
||||
particle = vertex.particle_list[ip]
|
||||
push_pname(idx_namelist, particle.name)
|
||||
idx_namelist += (len(particle.name)+1)
|
||||
self.a_Z[ip] = particle.Z
|
||||
self.a_A[ip] = particle.A
|
||||
self.a_ke[ip] = particle.kineticE
|
||||
self.a_px[ip] = particle.px
|
||||
self.a_py[ip] = particle.py
|
||||
self.a_pz[ip] = particle.pz
|
||||
|
||||
self.a_namelist[idx_namelist] = '\0'
|
||||
self.ptree.Fill()
|
||||
|
||||
|
||||
# ==================================================================
|
||||
# functions
|
||||
# ==================================================================
|
||||
def loop_tree(tfile, analyze_vertex):
|
||||
"""
|
||||
loop ROOT tree in a ROOT file.
|
||||
* analyze_vertex: user function : analyze_vertex(MCVertex)
|
||||
"""
|
||||
avtree = tfile.Get("vertex")
|
||||
aptree = tfile.Get("particle")
|
||||
|
||||
# reading vertex...
|
||||
n_vertex = avtree.GetEntries()
|
||||
for ivtx in xrange(n_vertex):
|
||||
avtree.GetEntry(ivtx)
|
||||
aptree.GetEntry(ivtx)
|
||||
|
||||
# vertex
|
||||
vertex = MCScore.MCVertex(avtree.x, avtree.y, avtree.z)
|
||||
|
||||
# reading secondary particles...
|
||||
nsec = aptree.np
|
||||
namelist = aptree.namelist
|
||||
pname = namelist.split()
|
||||
for ip in xrange(nsec):
|
||||
particle = MCScore.MCParticle(pname[ip], aptree.Z[ip], aptree.A[ip],
|
||||
aptree.kE[ip], aptree.px[ip],
|
||||
aptree.py[ip], aptree.pz[ip])
|
||||
vertex.append_particle(particle)
|
||||
|
||||
analyze_vertex(vertex)
|
||||
|
||||
return n_vertex
|
||||
|
||||
|
||||
# ==================================================================
|
||||
# test
|
||||
# ==================================================================
|
||||
def test_t2root():
|
||||
g = ROOT.TFile("reaction.root", 'recreate')
|
||||
|
||||
rootio = MCScoreROOTIO()
|
||||
rootio.define_tree()
|
||||
|
||||
f = open("reaction.dat")
|
||||
f.seek(0)
|
||||
|
||||
while(1):
|
||||
vertex = MCScore.read_next_vertex(f)
|
||||
if vertex == 0:
|
||||
break
|
||||
|
||||
# filling ...
|
||||
rootio.fill_tree(vertex)
|
||||
|
||||
del vertex
|
||||
|
||||
print ">>> EOF"
|
||||
f.close()
|
||||
|
||||
# closing ROOT file
|
||||
g.Write()
|
||||
g.Close()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
def test_loop():
|
||||
def my_analysis(vertex):
|
||||
vertex.printout()
|
||||
|
||||
f = ROOT.TFile("reaction.root", 'read')
|
||||
nv = loop_tree(f, my_analysis)
|
||||
print "*** # of vertex= ", nv
|
||||
|
||||
|
||||
# ==================================================================
|
||||
# main
|
||||
# ==================================================================
|
||||
if __name__ == "__main__":
|
||||
test_t2root()
|
||||
test_loop()
|
||||
|
||||
Reference in New Issue
Block a user