ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pyG4Material.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file pyG4Material.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 // pyG4Material.cc
28 //
29 // 2005 Q
30 // ====================================================================
31 #include <boost/python.hpp>
32 #include "G4Material.hh"
33 
34 using namespace boost::python;
35 
36 // ====================================================================
37 // thin wrappers
38 // ====================================================================
39 namespace pyG4Material {
40 
41 // AddElement
46 
47 // GetMaterial
48 G4Material* (*f1_GetMaterial)(const G4String&, G4bool)
50 G4Material* (*f2_GetMaterial)(G4double, G4double, G4double)
52 G4Material* (*f3_GetMaterial)(size_t, G4double)
54 
56 
57 // raw pointer -> Python list conversion
59 {
60  list fracList;
61  const G4double* fracVec= material-> GetFractionVector();
62  G4int nele= material-> GetNumberOfElements();
63  for(G4int i=0; i<nele; i++) {
64  fracList.append(fracVec[i]);
65  }
66  return fracList;
67 }
68 
70 {
71  list atomsList;
72  const G4int* atomsVec= material-> GetAtomsVector();
73  G4int nele= material-> GetNumberOfElements();
74  for(G4int i=0; i<nele; i++) {
75  atomsList.append(atomsVec[i]);
76  }
77  return atomsList;
78 }
79 
81 {
82  list nbOfAtomsPerVolumeList;
83  const G4double* nbOfAtomsPerVolumeVec= material-> GetVecNbOfAtomsPerVolume();
84  G4int nele= material-> GetNumberOfElements();
85  for(G4int i=0; i<nele; i++) {
86  nbOfAtomsPerVolumeList.append(nbOfAtomsPerVolumeVec[i]);
87  }
88  return nbOfAtomsPerVolumeList;
89 }
90 
92 {
93  list atomicNumDensityList;
94  const G4double* atomicNumDensityVec= material-> GetAtomicNumDensityVector();
95  G4int nele= material-> GetNumberOfElements();
96  for(G4int i=0; i<nele; i++) {
97  atomicNumDensityList.append(atomicNumDensityVec[i]);
98  }
99  return atomicNumDensityList;
100 }
101 
102 // copy constructor is private, so ...
104 {
105  G4cout << mat;
106 }
107 
108 }
109 
110 using namespace pyG4Material;
111 
112 // ====================================================================
113 // module definition
114 // ====================================================================
116 {
117  class_<G4Material, G4Material*, boost::noncopyable>
118  ("G4Material", "material class", no_init)
119  .def(init<const G4String&, G4double, G4double, G4double>())
120  .def(init<const G4String&, G4double, G4int>())
121  // ---
122  .def("AddElement", f1_AddElement)
123  .def("AddElement", f2_AddElement)
124  .def("AddMaterial", &G4Material::AddMaterial)
125  .def("GetName", &G4Material::GetName,
126  return_value_policy<reference_existing_object>())
127  .def("GetChemicalFormula", &G4Material::GetChemicalFormula,
128  return_value_policy<reference_existing_object>())
129  .def("SetName", &G4Material::SetName)
130  .def("SetChemicalFormula", &G4Material::SetChemicalFormula)
131  .def("GetDensity", &G4Material::GetDensity)
132  .def("GetState", &G4Material::GetState)
133  .def("GetTemperature", &G4Material::GetTemperature)
134  .def("GetPressure", &G4Material::GetPressure)
135  // ---
136  .def("GetElementVector", &G4Material::GetElementVector,
137  return_internal_reference<>())
138  .def("GetElement", &G4Material::GetElement,
139  return_value_policy<reference_existing_object>())
140  .def("GetTotNbOfAtomsPerVolume", &G4Material::GetTotNbOfAtomsPerVolume)
141  .def("GetTotNbOfElectPerVolume", &G4Material::GetTotNbOfElectPerVolume)
142  .def("GetFractionVector", f_GetFractionVector)
143  .def("GetAtomsVector", f_GetAtomsVector)
144  .def("GetVecNbOfAtomsPerVolume", f_GetVecNbOfAtomsPerVolume)
145  .def("GetAtomicNumDensityVector", f_GetAtomicNumDensityVector)
146  // ----
147  .def("GetElectronDensity", &G4Material::GetElectronDensity)
148  .def("GetRadlen", &G4Material::GetRadlen)
149  .def("GetNuclearInterLength", &G4Material::GetNuclearInterLength)
150  .def("GetIonisation", &G4Material::GetIonisation,
151  return_internal_reference<>())
152  .def("GetSandiaTable", &G4Material::GetSandiaTable,
153  return_internal_reference<>())
154  // ---
155  .def("GetZ", &G4Material::GetZ)
156  .def("GetA", &G4Material::GetA)
157  .def("SetMaterialPropertiesTable", &G4Material::SetMaterialPropertiesTable)
158  .def("GetMaterialPropertiesTable", &G4Material::GetMaterialPropertiesTable,
159  return_internal_reference<>())
160  .def("GetMaterialTable", &G4Material::GetMaterialTable,
161  return_value_policy<reference_existing_object>())
162  .staticmethod("GetMaterialTable")
163  .def("GetNumberOfMaterials", &G4Material::GetNumberOfMaterials)
164  .staticmethod("GetNumberOfMaterials")
165  .def("GetIndex", &G4Material::GetIndex)
166  .def("GetMaterial", f1_GetMaterial, f_GetMaterial()
167  [return_value_policy<reference_existing_object>()])
168  .def("GetMaterial", f2_GetMaterial,
169  return_value_policy<reference_existing_object>())
170  .def("GetMaterial", f3_GetMaterial,
171  return_value_policy<reference_existing_object>())
172  .staticmethod("GetMaterial")
173  // ---
174  //.def(self_ns::str(self))
175  .def("Print", Print)
176  ;
177 
178  // ---
179  enum_<G4State>("G4State")
180  .value("kStateUndefined", kStateUndefined)
181  .value("kStateSolid", kStateSolid)
182  .value("kStateLiquid", kStateLiquid)
183  .value("kStateGas", kStateGas)
184  ;
185 }