| 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,v 1.2 2007/07/06 06:41:59 kmura Exp $
|
|---|
| 27 | // $Name: geant4-09-04-beta-01 $
|
|---|
| 28 | // ====================================================================
|
|---|
| 29 | // pyTestEm0.cc
|
|---|
| 30 | //
|
|---|
| 31 | // python wrapper for user application
|
|---|
| 32 | // 2007 Q
|
|---|
| 33 | // ====================================================================
|
|---|
| 34 | #include "DetectorConstruction.hh"
|
|---|
| 35 | #include "RunAction.hh"
|
|---|
| 36 | #include "PhysicsList.hh"
|
|---|
| 37 | #include "PrimaryGeneratorAction.hh"
|
|---|
| 38 | #include "G4Material.hh"
|
|---|
| 39 | #include "G4MaterialTable.hh"
|
|---|
| 40 | #include "G4ParticleTable.hh"
|
|---|
| 41 |
|
|---|
| 42 | #include <boost/python.hpp>
|
|---|
| 43 | #include <boost/python/list.hpp>
|
|---|
| 44 |
|
|---|
| 45 | #include <vector>
|
|---|
| 46 | #include <string>
|
|---|
| 47 |
|
|---|
| 48 | using namespace boost::python;
|
|---|
| 49 | // ========================================================================================
|
|---|
| 50 | // Wrap Gean4 methods which are not accessible from python because they return a pointer.
|
|---|
| 51 | // ========================================================================================
|
|---|
| 52 | boost::python::list getParticleTable()
|
|---|
| 53 | {
|
|---|
| 54 | // Create a list on heap which will be return to python
|
|---|
| 55 | boost::python::list *particleList = new boost::python::list();
|
|---|
| 56 |
|
|---|
| 57 | // Get particle list fron G4ParticleTable
|
|---|
| 58 | G4ParticleTable *g4ParticleList = G4ParticleTable::GetParticleTable();
|
|---|
| 59 |
|
|---|
| 60 | // Fill python list from g4ParticleList
|
|---|
| 61 | for ( int index = 0 ; index <= g4ParticleList->size() ; index++ ) {
|
|---|
| 62 | particleList->append ( (std::string) g4ParticleList->GetParticleName(index) );
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | return *particleList;
|
|---|
| 66 | }
|
|---|
| 67 | // ====================================================================
|
|---|
| 68 | boost::python::list getMaterialTable()
|
|---|
| 69 | {
|
|---|
| 70 | // Create a list on heap which will be return to python
|
|---|
| 71 | boost::python::list *materialTableList = new boost::python::list();
|
|---|
| 72 |
|
|---|
| 73 | // Get material list fron G4Material
|
|---|
| 74 | G4MaterialTable materialList = *G4Material::GetMaterialTable();
|
|---|
| 75 |
|
|---|
| 76 | std::vector<G4Material*>::iterator itVectorData;
|
|---|
| 77 | for(itVectorData = materialList.begin(); itVectorData != materialList.end(); itVectorData++) {
|
|---|
| 78 | materialTableList->append ( (std::string)(*(itVectorData))->GetName()) ;
|
|---|
| 79 |
|
|---|
| 80 | }
|
|---|
| 81 | return *materialTableList;
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 | // ====================================================================
|
|---|
| 86 | // Expose to Python
|
|---|
| 87 | // ====================================================================
|
|---|
| 88 |
|
|---|
| 89 | BOOST_PYTHON_MODULE(TestEm0) {
|
|---|
| 90 |
|
|---|
| 91 | def ("getMaterialTable", getMaterialTable);
|
|---|
| 92 |
|
|---|
| 93 | def ("getParticleTable", getParticleTable);
|
|---|
| 94 |
|
|---|
| 95 | class_<DetectorConstruction, DetectorConstruction*,
|
|---|
| 96 | bases<G4VUserDetectorConstruction> >
|
|---|
| 97 | ("DetectorConstruction", "testEm0 detector")
|
|---|
| 98 | .def("SetMaterial",&DetectorConstruction::SetMaterial)
|
|---|
| 99 | ;
|
|---|
| 100 |
|
|---|
| 101 | class_<PrimaryGeneratorAction, PrimaryGeneratorAction*,
|
|---|
| 102 | bases<G4VUserPrimaryGeneratorAction> >
|
|---|
| 103 | ("PrimaryGeneratorAction", init<DetectorConstruction*>())
|
|---|
| 104 | ;
|
|---|
| 105 |
|
|---|
| 106 | class_<RunAction, RunAction*,
|
|---|
| 107 | bases<G4UserRunAction> >
|
|---|
| 108 | ("RunAction", init<DetectorConstruction*, PrimaryGeneratorAction*>())
|
|---|
| 109 | ;
|
|---|
| 110 |
|
|---|
| 111 | class_<PhysicsList, PhysicsList*,
|
|---|
| 112 | bases<G4VUserPhysicsList> >
|
|---|
| 113 | ("PhysicsList", "testEm0 physics list")
|
|---|
| 114 | ;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|