ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pytestem0.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file 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 // ====================================================================
27 // pyTestEm0.cc
28 //
29 // python wrapper for user application
30 // 2007 Q
31 // ====================================================================
32 #include "DetectorConstruction.hh"
33 #include "RunAction.hh"
34 #include "PhysicsList.hh"
36 #include "G4Material.hh"
37 #include "G4MaterialTable.hh"
38 #include "G4ParticleTable.hh"
39 
40 #include <boost/python.hpp>
41 #include <boost/python/list.hpp>
42 
43 #include <vector>
44 #include <string>
45 
46 using namespace boost::python;
47 // ========================================================================================
48 // Wrap Gean4 methods which are not accessible from python because they return a pointer.
49 // ========================================================================================
50 boost::python::list getParticleTable()
51 {
52  // Create a list on heap which will be return to python
53  boost::python::list *particleList = new boost::python::list();
54 
55  // Get particle list fron G4ParticleTable
57 
58  // Fill python list from g4ParticleList
59  for ( int index = 0 ; index <= g4ParticleList->size() ; index++ ) {
60  particleList->append ( (std::string) g4ParticleList->GetParticleName(index) );
61  }
62 
63  return *particleList;
64 }
65 // ====================================================================
66 boost::python::list getMaterialTable()
67  {
68  // Create a list on heap which will be return to python
69  boost::python::list *materialTableList = new boost::python::list();
70 
71  // Get material list fron G4Material
73 
74  std::vector<G4Material*>::iterator itVectorData;
75  for(itVectorData = materialList.begin(); itVectorData != materialList.end(); itVectorData++) {
76  materialTableList->append ( (std::string)(*(itVectorData))->GetName()) ;
77 
78  }
79  return *materialTableList;
80 }
81 
82 
83 // ====================================================================
84 // Expose to Python
85 // ====================================================================
86 
88 
89  def ("getMaterialTable", getMaterialTable);
90 
91  def ("getParticleTable", getParticleTable);
92 
93  class_<DetectorConstruction, DetectorConstruction*,
94  bases<G4VUserDetectorConstruction> >
95  ("DetectorConstruction", "testEm0 detector")
96  .def("SetMaterial",&DetectorConstruction::SetMaterial)
97  ;
98 
99  class_<PrimaryGeneratorAction, PrimaryGeneratorAction*,
100  bases<G4VUserPrimaryGeneratorAction> >
101  ("PrimaryGeneratorAction", init<DetectorConstruction*>())
102  ;
103 
104  class_<RunAction, RunAction*,
105  bases<G4UserRunAction> >
106  ("RunAction", init<DetectorConstruction*, PrimaryGeneratorAction*>())
107  ;
108 
109  class_<PhysicsList, PhysicsList*,
110  bases<G4VUserPhysicsList> >
111  ("PhysicsList", "testEm0 physics list")
112  ;
113 }