LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
pyG4Material.cc
Go to the documentation of this file.
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: pyG4Material.cc 76884 2013-11-18 12:54:03Z gcosmo $
27 // ====================================================================
28 // pyG4Material.cc
29 //
30 // 2005 Q
31 // ====================================================================
32 #include <boost/python.hpp>
33 #include "G4Version.hh"
34 #include "G4Material.hh"
35 
36 using namespace boost::python;
37 
38 // ====================================================================
39 // thin wrappers
40 // ====================================================================
41 namespace pyG4Material {
42 
43 // AddElement
44 void (G4Material::*f1_AddElement)(G4Element*, G4int)
45  = &G4Material::AddElement;
46 void (G4Material::*f2_AddElement)(G4Element*, G4double)
47  = &G4Material::AddElement;
48 
49 BOOST_PYTHON_FUNCTION_OVERLOADS(f_GetMaterial, G4Material::GetMaterial, 1, 2)
50 
51 // raw pointer -> Python list conversion
52 list f_GetFractionVector(const G4Material* material)
53 {
54  list fracList;
55  const G4double* fracVec= material-> GetFractionVector();
56  G4int nele= material-> GetNumberOfElements();
57  for(G4int i=0; i<nele; i++) {
58  fracList.append(fracVec[i]);
59  }
60  return fracList;
61 }
62 
63 list f_GetAtomsVector(const G4Material* material)
64 {
65  list atomsList;
66  const G4int* atomsVec= material-> GetAtomsVector();
67  G4int nele= material-> GetNumberOfElements();
68  for(G4int i=0; i<nele; i++) {
69  atomsList.append(atomsVec[i]);
70  }
71  return atomsList;
72 }
73 
74 list f_GetVecNbOfAtomsPerVolume(const G4Material* material)
75 {
76  list nbOfAtomsPerVolumeList;
77  const G4double* nbOfAtomsPerVolumeVec= material-> GetVecNbOfAtomsPerVolume();
78  G4int nele= material-> GetNumberOfElements();
79  for(G4int i=0; i<nele; i++) {
80  nbOfAtomsPerVolumeList.append(nbOfAtomsPerVolumeVec[i]);
81  }
82  return nbOfAtomsPerVolumeList;
83 }
84 
85 list f_GetAtomicNumDensityVector(const G4Material* material)
86 {
87  list atomicNumDensityList;
88  const G4double* atomicNumDensityVec= material-> GetAtomicNumDensityVector();
89  G4int nele= material-> GetNumberOfElements();
90  for(G4int i=0; i<nele; i++) {
91  atomicNumDensityList.append(atomicNumDensityVec[i]);
92  }
93  return atomicNumDensityList;
94 }
95 
96 // copy constructor is private, so ...
97 void Print(G4Material& mat)
98 {
99  G4cout << mat;
100 }
101 
102 }
103 
104 using namespace pyG4Material;
105 
106 // ====================================================================
107 // module definition
108 // ====================================================================
110 {
111  class_<G4Material, G4Material*, boost::noncopyable>
112  ("G4Material", "material class", no_init)
113  .def(init<const G4String&, G4double, G4double, G4double>())
114  .def(init<const G4String&, G4double, G4int>())
115  // ---
116  .def("AddElement", f1_AddElement)
117  .def("AddElement", f2_AddElement)
118  .def("AddMaterial", &G4Material::AddMaterial)
119  .def("GetName", &G4Material::GetName,
120  return_value_policy<reference_existing_object>())
121  .def("GetChemicalFormula", &G4Material::GetChemicalFormula,
122  return_value_policy<reference_existing_object>())
123  .def("SetName", &G4Material::SetName)
124  .def("SetChemicalFormula", &G4Material::SetChemicalFormula)
125  .def("GetDensity", &G4Material::GetDensity)
126  .def("GetState", &G4Material::GetState)
127  .def("GetTemperature", &G4Material::GetTemperature)
128  .def("GetPressure", &G4Material::GetPressure)
129  // ---
130  .def("GetElementVector", &G4Material::GetElementVector,
131  return_internal_reference<>())
132  .def("GetElement", &G4Material::GetElement,
133  return_value_policy<reference_existing_object>())
134  .def("GetTotNbOfAtomsPerVolume", &G4Material::GetTotNbOfAtomsPerVolume)
135  .def("GetTotNbOfElectPerVolume", &G4Material::GetTotNbOfElectPerVolume)
136  .def("GetFractionVector", f_GetFractionVector)
137  .def("GetAtomsVector", f_GetAtomsVector)
138  .def("GetVecNbOfAtomsPerVolume", f_GetVecNbOfAtomsPerVolume)
139  .def("GetAtomicNumDensityVector", f_GetAtomicNumDensityVector)
140  // ----
141  .def("GetElectronDensity", &G4Material::GetElectronDensity)
142  .def("GetRadlen", &G4Material::GetRadlen)
143  .def("GetNuclearInterLength", &G4Material::GetNuclearInterLength)
144  .def("GetIonisation", &G4Material::GetIonisation,
145  return_internal_reference<>())
146  .def("GetSandiaTable", &G4Material::GetSandiaTable,
147  return_internal_reference<>())
148  // ---
149  .def("GetZ", &G4Material::GetZ)
150  .def("GetA", &G4Material::GetA)
151  .def("SetMaterialPropertiesTable", &G4Material::SetMaterialPropertiesTable)
152  .def("GetMaterialPropertiesTable", &G4Material::GetMaterialPropertiesTable,
153  return_internal_reference<>())
154  .def("GetMaterialTable", &G4Material::GetMaterialTable,
155  return_value_policy<reference_existing_object>())
156  .staticmethod("GetMaterialTable")
157  .def("GetNumberOfMaterials", &G4Material::GetNumberOfMaterials)
158  .staticmethod("GetNumberOfMaterials")
159  .def("GetIndex", &G4Material::GetIndex)
160  .def("GetMaterial", &G4Material::GetMaterial,
161  f_GetMaterial()
162  [return_value_policy<reference_existing_object>()])
163  .staticmethod("GetMaterial")
164  // ---
165  //.def(self_ns::str(self))
166  .def("Print", Print)
167  ;
168 
169  // ---
170  enum_<G4State>("G4State")
171  .value("kStateUndefined", kStateUndefined)
172  .value("kStateSolid", kStateSolid)
173  .value("kStateLiquid", kStateLiquid)
174  .value("kStateGas", kStateGas)
175  ;
176 }
177 
BOOST_PYTHON_FUNCTION_OVERLOADS(f_func2, func2, 1, 2)
void(G4Material::* f2_AddElement)(G4Element *, G4double)
Definition: pyG4Material.cc:46
Float_t mat
Definition: plot.C:40
list f_GetVecNbOfAtomsPerVolume(const G4Material *material)
Definition: pyG4Material.cc:74
void Print(G4Material &mat)
Definition: pyG4Material.cc:97
std::string value(boost::any const &)
void(G4Material::* f1_AddElement)(G4Element *, G4int)
Definition: pyG4Material.cc:44
void export_G4Material()
list f_GetAtomsVector(const G4Material *material)
Definition: pyG4Material.cc:63
list f_GetAtomicNumDensityVector(const G4Material *material)
Definition: pyG4Material.cc:85
list f_GetFractionVector(const G4Material *material)
Definition: pyG4Material.cc:52