Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
pytestem0.cc
이 파일의 문서화 페이지로 가기
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // $Id: pyTestEm0.cc 66241 2012-12-13 18:34:42Z gunter $
27 // ====================================================================
28 // pyTestEm0.cc
29 //
30 // python wrapper for user application
31 // 2007 Q
32 // ====================================================================
33 #include "DetectorConstruction.hh"
34 #include "RunAction.hh"
35 #include "PhysicsList.hh"
37 #include "G4Material.hh"
38 #include "G4MaterialTable.hh"
39 #include "G4ParticleTable.hh"
40 
41 #include <boost/python.hpp>
42 #include <boost/python/list.hpp>
43 
44 #include <vector>
45 #include <string>
46 
47 using namespace boost::python;
48 // ========================================================================================
49 // Wrap Gean4 methods which are not accessible from python because they return a pointer.
50 // ========================================================================================
51 boost::python::list getParticleTable()
52 {
53  // Create a list on heap which will be return to python
54  boost::python::list *particleList = new boost::python::list();
55 
56  // Get particle list fron G4ParticleTable
58 
59  // Fill python list from g4ParticleList
60  for ( int index = 0 ; index <= g4ParticleList->size() ; index++ ) {
61  particleList->append ( (std::string) g4ParticleList->GetParticleName(index) );
62  }
63 
64  return *particleList;
65 }
66 // ====================================================================
67 boost::python::list getMaterialTable()
68  {
69  // Create a list on heap which will be return to python
70  boost::python::list *materialTableList = new boost::python::list();
71 
72  // Get material list fron G4Material
74 
75  std::vector<G4Material*>::iterator itVectorData;
76  for(itVectorData = materialList.begin(); itVectorData != materialList.end(); itVectorData++) {
77  materialTableList->append ( (std::string)(*(itVectorData))->GetName()) ;
78 
79  }
80  return *materialTableList;
81 }
82 
83 
84 // ====================================================================
85 // Expose to Python
86 // ====================================================================
87 
89 
90  def ("getMaterialTable", getMaterialTable);
91 
92  def ("getParticleTable", getParticleTable);
93 
94  class_<DetectorConstruction, DetectorConstruction*,
95  bases<G4VUserDetectorConstruction> >
96  ("DetectorConstruction", "testEm0 detector")
97  .def("SetMaterial",&DetectorConstruction::SetMaterial)
98  ;
99 
100  class_<PrimaryGeneratorAction, PrimaryGeneratorAction*,
101  bases<G4VUserPrimaryGeneratorAction> >
102  ("PrimaryGeneratorAction", init<DetectorConstruction*>())
103  ;
104 
105  class_<RunAction, RunAction*,
106  bases<G4UserRunAction> >
107  ("RunAction", init<DetectorConstruction*, PrimaryGeneratorAction*>())
108  ;
109 
110  class_<PhysicsList, PhysicsList*,
111  bases<G4VUserPhysicsList> >
112  ("PhysicsList", "testEm0 physics list")
113  ;
114 }
boost::python::list getParticleTable()
Definition: pytestem0.cc:51
G4int size() const
static G4ParticleTable * GetParticleTable()
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:593
boost::python::list getMaterialTable()
Definition: pytestem0.cc:67
The primary generator action class with particle gun.
std::vector< G4Material * > G4MaterialTable
BOOST_PYTHON_MODULE(testem0)
Definition: pytestem0.cc:88
static MCGIDI_particle * particleList
const G4String & GetParticleName(G4int index) const
Simple detector construction with a box volume placed in a world.