10 #include "HGCal/TBStandaloneSimulator/interface/TBGeometry.h"
21 PyObject* q = PyDict_GetItemString(o, name.c_str());
23 c.
smap[name] = string(PyString_AsString(q));
29 PyObject* q = PyDict_GetItemString(o, name.c_str());
31 c.
dmap[name] = PyFloat_AsDouble(q);
37 PyObject* q = PyDict_GetItemString(o, name.c_str());
39 c.
imap[name] =
static_cast<int>(PyInt_AsLong(q));
43 void debug(map<string, T>& o)
45 for(
typename map<string, T>::iterator it = o.begin(); it != o.end(); it++)
46 cout <<
" " << it->first <<
":\t" << it->second << endl;
52 : _modulename(modulename),
56 _sensitive(std::map<int, int>())
65 "from HGCal.TBStandaloneSimulator.TBGeometryUtil import "
71 sprintf(cmd,
"createGeometry('%s')", _modulename.c_str());
72 cout << endl << cmd << endl;
73 PyObject* geom = (PyObject*)TPython::Eval(cmd);
79 PyObject* world = PyDict_GetItemString(geom,
"world");
81 setString(_world, world,
"shape");
82 setString(_world, world,
"units");
83 setDouble(_world, world,
"xside");
84 setDouble(_world, world,
"yside");
85 setDouble(_world, world,
"zside");
94 PyObject* header = PyDict_GetItemString(geom,
"header");
96 setInteger(_header, header,
"model");
97 setInteger(_header, header,
"version");
99 _header.imap[
"model"] = 1;
100 _header.imap[
"version"] = 1;
105 PyObject* geometry = PyDict_GetItemString(geom,
"geometry");
109 int nelements = PyList_Size(geometry);
110 for(
int c = 0; c < nelements; c++) {
111 PyObject* item = PyList_GetItem(geometry, c);
112 PyObject* keys = PyDict_Keys(item);
113 int nkeys = PyList_Size(keys);
116 setInteger(element, item,
"sensitive");
117 setString(element, item,
"shape");
118 setString(element, item,
"material");
119 setString(element, item,
"units");
120 for(
int ii = 0; ii < nkeys; ii++) {
121 PyObject* key = PyList_GetItem(keys, ii);
122 string name = string(PyString_AsString(key));
123 if ( name ==
"sensitive" )
continue;
124 if ( name ==
"shape" )
continue;
125 if ( name ==
"material" )
continue;
126 if ( name ==
"units" )
continue;
127 if ( element.
dmap.find(name) != element.
dmap.end() )
continue;
128 if ( name ==
"first" || name ==
"last" )
129 setInteger(element, item, name);
131 setDouble(element, item, name);
133 _geometry.push_back(element);
144 for(
size_t c = 0; c < _geometry.size(); c++) {
146 if ( element.
imap[
"sensitive"] ) {
148 _sensitive[layer] = c;
161 if ( item ==
"world" ) {
163 }
else if ( item ==
"sensitive" ) {
164 if ( _sensitive.find(index) != _sensitive.end() )
165 return _geometry[_sensitive[index]];
168 }
else if ( item ==
"geometry" ) {
171 if ( index >= (
int)_geometry.size() )
174 return _geometry[index];
182 os <<
"World" << endl << endl;
184 for(map<string, string>::iterator it = world.
smap.begin();
185 it != world.
smap.end();
187 sprintf(record,
" %-16s:\t%s",
188 (it->first).c_str(), (it->second).c_str());
189 os << record << endl;
191 for(map<string, double>::iterator it = world.
dmap.begin();
192 it != world.
dmap.end();
194 sprintf(record,
" %-16s:\t%f",
195 (it->first).c_str(), it->second);
196 os << record << endl;
200 os <<
"Geometry - number of elements: " << o.
size() << endl;
202 for(
size_t c = 0; c < o.
size(); c++) {
205 if ( element.
imap[
"first"] )
206 os <<
"BEGIN(SamplingSection)"
209 os <<
" element " << c;
210 if ( element.
imap[
"sensitive"] )
211 os <<
"\t== sensitive ==";
214 for(map<string, string>::iterator it = element.
smap.begin();
215 it != element.
smap.end();
217 sprintf(record,
" %-16s:\t%s",
218 (it->first).c_str(), (it->second).c_str());
219 os << record << endl;
222 for(map<string, double>::iterator it = element.
dmap.begin();
223 it != element.
dmap.end();
225 sprintf(record,
" %-16s:\t%f",
226 (it->first).c_str(), it->second);
227 os << record << endl;
230 if ( element.
imap[
"last"] )
231 os <<
"END(SamplingSection)" << endl;
std::map< std::string, double > dmap
std::map< std::string, int > imap
std::ostream & operator<<(std::ostream &, const HGCalTBDetId &id)
std::map< std::string, std::string > smap
TBGeometry::Element operator()(std::string, int index=0)