CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GeometricDet.cc
Go to the documentation of this file.
8 
9 #include "CLHEP/Units/GlobalSystemOfUnits.h"
10 
11 #include <boost/bind.hpp>
12 
13 #include <cfloat>
14 #include <vector>
15 #include <string>
16 
17 namespace {
18 
19  const std::string strue("true");
20 
21  template<typename DDView>
22  double getDouble(const char * s, DDView const & ev) {
23  DDValue val(s);
24  std::vector<const DDsvalues_type *> result;
25  ev.specificsV(result);
26  std::vector<const DDsvalues_type *>::iterator it = result.begin();
27  bool foundIt = false;
28  for (; it != result.end(); ++it)
29  {
30  foundIt = DDfetch(*it,val);
31  if (foundIt) break;
32  }
33  if (foundIt)
34  {
35  const std::vector<std::string> & temp = val.strings();
36  if (temp.size() != 1)
37  {
38  throw cms::Exception("Configuration") << "I need 1 "<< s << " tags";
39  }
40  return double(::atof(temp[0].c_str()));
41  }
42  return 0;
43  }
44 
45  template<typename DDView>
46  std::string getString(const char * s, DDView const & ev) {
47  DDValue val(s);
48  std::vector<const DDsvalues_type *> result;
49  ev.specificsV(result);
50  std::vector<const DDsvalues_type *>::iterator it = result.begin();
51  bool foundIt = false;
52  for (; it != result.end(); ++it)
53  {
54  foundIt = DDfetch(*it,val);
55  if (foundIt) break;
56 
57  }
58  if (foundIt)
59  {
60  const std::vector<std::string> & temp = val.strings();
61  if (temp.size() != 1)
62  {
63  throw cms::Exception("Configuration") << "I need 1 "<< s << " tags";
64  }
65  return temp[0];
66  }
67  return "NotFound";
68  }
69 }
70 
71 
77  //std::cout << "~GeometricDet5" << std::endl;
79 }
80 #ifdef GEOMETRICDETDEBUG
81 // for use outside CMSSW framework only since it asks for a default DDCompactView...
82 GeometricDet::GeometricDet(DDnav_type const & navtype, GeometricEnumType type) :
83  _ddd(navtype.begin(),navtype.end()), _type(type){
84  //
85  // I need to find the params by myself :(
86  //
87  //std::cout << "GeometricDet1" << std::endl;
88  _fromDD = true;
89  DDCompactView cpv; // bad, bad, bad!
90  DDExpandedView ev(cpv);
91  ev.goTo(navtype);
92  _params = ((ev.logicalPart()).solid()).parameters();
93  _trans = ev.translation();
94  _phi = _trans.Phi();
95  _rho = _trans.Rho();
96  _rot = ev.rotation();
97  _shape = ((ev.logicalPart()).solid()).shape();
98  _ddname = ((ev.logicalPart()).ddname()).name();
99  _parents = GeoHistory(ev.geoHistory().begin(),ev.geoHistory().end()) ;
100  _volume = ((ev.logicalPart()).solid()).volume();
101  _density = ((ev.logicalPart()).material()).density();
102  // _weight = (ev.logicalPart()).weight();
103  _weight = _density * ( _volume / 1000.); // volume mm3->cm3
104  _copy = ev.copyno();
105  _material = ((ev.logicalPart()).material()).name().fullname();
106  _radLength = getDouble("TrackerRadLength",ev);
107  _xi = getDouble("TrackerXi",ev);
108  _pixROCRows = getDouble("PixelROCRows",ev);
109  _pixROCCols = getDouble("PixelROCCols",ev);
110  _pixROCx = getDouble("PixelROC_X",ev);
111  _pixROCy = getDouble("PixelROC_Y",ev);
112  _stereo = getString("TrackerStereoDetectors",ev)==strue;
113  _siliconAPVNum = getDouble("SiliconAPVNumber",ev);
114 
115 }
116 
117 GeometricDet::GeometricDet(DDExpandedView* fv, GeometricEnumType type) : _type(type) {
118  //
119  // Set by hand the _ddd
120  //
121  //std::cout << "GeometricDet2" << std::endl;
122  _fromDD = true;
123  _ddd = nav_type(fv->navPos().begin(),fv->navPos().end() );
124  _params = ((fv->logicalPart()).solid()).parameters();
125  _trans = fv->translation();
126  _phi = _trans.Phi();
127  _rho = _trans.Rho();
128  _rot = fv->rotation();
129  _shape = ((fv->logicalPart()).solid()).shape();
130  _ddname = ((fv->logicalPart()).ddname()).name();
131  _parents = GeoHistory(fv->geoHistory().begin(),fv->geoHistory().end()) ;
132  _volume = ((fv->logicalPart()).solid()).volume();
133  _density = ((fv->logicalPart()).material()).density();
134  // _weight = (fv->logicalPart()).weight();
135  _weight = _density * ( _volume / 1000.); // volume mm3->cm3
136  _copy = fv->copyno();
137  _material = ((fv->logicalPart()).material()).name().fullname();
138  _radLength = getDouble("TrackerRadLength",*fv);
139  _xi = getDouble("TrackerXi",*fv);
140  _pixROCRows = getDouble("PixelROCRows",*fv);
141  _pixROCCols = getDouble("PixelROCCols",*fv);
142  _pixROCx = getDouble("PixelROC_X",*fv);
143  _pixROCy = getDouble("PixelROC_Y",*fv);
144  _stereo = getString("TrackerStereoDetectors",*fv)=="true";
145  _siliconAPVNum = getDouble("SiliconAPVNumber",*fv);
146 
147 }
148 #endif
149 
151  //
152  // Set by hand the _ddd
153  //
154  _trans(fv->translation()),
155  _phi(_trans.Phi()),
156  _rho(_trans.Rho()),
157  _rot(fv->rotation()),
158  _shape(((fv->logicalPart()).solid()).shape()),
159  _ddname(((fv->logicalPart()).ddname()).name()),
160  _type(type),
161  _params(((fv->logicalPart()).solid()).parameters()),
162  // want this :) _ddd(fv->navPos().begin(),fv->navPos().end()),
163 #ifdef GEOMTRICDETDEBUG
164  _parents(fv->geoHistory().begin(),fv->geoHistory().end()),
165  _volume(((fv->logicalPart()).solid()).volume()),
166  _density(((fv->logicalPart()).material()).density()),
167  // _weight = (fv->logicalPart()).weight();
168  _weight(_density * ( _volume / 1000.)), // volume mm3->cm3
169  _copy(fv->copyno()),
170  _material(((fv->logicalPart()).material()).name().fullname()),
171 #endif
172  _radLength(getDouble("TrackerRadLength",*fv)),
173  _xi(getDouble("TrackerXi",*fv)),
174  _pixROCRows(getDouble("PixelROCRows",*fv)),
175  _pixROCCols(getDouble("PixelROCCols",*fv)),
176  _pixROCx(getDouble("PixelROC_X",*fv)),
177  _pixROCy(getDouble("PixelROC_Y",*fv)),
178  _stereo(getString("TrackerStereoDetectors",*fv)==strue),
179  _siliconAPVNum(getDouble("SiliconAPVNumber",*fv))
180 #ifdef GEOMTRICDETDEBUG
181  ,
182  _fromDD(true)
183 #endif
184 {
185  //std::cout << "GeometricDet3" << std::endl;
186  // workaround instead of this at initialization _ddd(fv->navPos().begin(),fv->navPos().end()),
187  const DDFilteredView::nav_type& nt = fv->navPos();
188  _ddd = nav_type(nt.begin(), nt.end());
189 }
190 
191 // PGeometricDet is persistent version... make it... then come back here and make the
192 // constructor.
194  _trans(onePGD._x, onePGD._y, onePGD._z),
195  _phi(onePGD._phi), //_trans.Phi()),
196  _rho(onePGD._rho), //_trans.Rho()),
197  _rot(onePGD._a11, onePGD._a12, onePGD._a13,
198  onePGD._a21, onePGD._a22, onePGD._a23,
199  onePGD._a31, onePGD._a32, onePGD._a33),
200  _shape(DDSolidShapesName::index(onePGD._shape)),
201  _ddd(),
202  _ddname(onePGD._name, onePGD._ns),//, "fromdb");
203  _type(type),
204  _params(),
205  _geographicalID(onePGD._geographicalID),
206 #ifdef GEOMTRICDETDEBUG
207  _parents(), // will remain empty... hate wasting the space but want all methods to work.
208  _volume(onePGD._volume),
209  _density(onePGD._density),
210  _weight(onePGD._weight),
211  _copy(onePGD._copy),
212  _material(onePGD._material),
213 #endif
214  _radLength(onePGD._radLength),
215  _xi(onePGD._xi),
216  _pixROCRows(onePGD._pixROCRows),
217  _pixROCCols(onePGD._pixROCCols),
218  _pixROCx(onePGD._pixROCx),
219  _pixROCy(onePGD._pixROCy),
220  _stereo(onePGD._stereo),
221  _siliconAPVNum(onePGD._siliconAPVNum)
222 #ifdef GEOMTRICDETDEBUG
223  , // mind the tricky comma is needed.
224  _fromDD(false)
225 #endif
226 {
227  //std::cout << "GeometricDet4" << std::endl;
228 
229  if(onePGD._shape==1||onePGD._shape==3){ //The parms vector is neede only in the case of box or trap shape
230  _params.reserve(11);
231  _params.push_back(onePGD._params0);
232  _params.push_back(onePGD._params1);
233  _params.push_back(onePGD._params2);
234  _params.push_back(onePGD._params3);
235  _params.push_back(onePGD._params4);
236  _params.push_back(onePGD._params5);
237  _params.push_back(onePGD._params6);
238  _params.push_back(onePGD._params7);
239  _params.push_back(onePGD._params8);
240  _params.push_back(onePGD._params9);
241  _params.push_back(onePGD._params10);
242  }
243 
244  _ddd.reserve(onePGD._numnt);
245  _ddd.push_back(onePGD._nt0);
246  _ddd.push_back(onePGD._nt1);
247  _ddd.push_back(onePGD._nt2);
248  _ddd.push_back(onePGD._nt3);
249  if ( onePGD._numnt > 4 ) {
250  _ddd.push_back(onePGD._nt4);
251  if ( onePGD._numnt > 5 ) {
252  _ddd.push_back(onePGD._nt5);
253  if ( onePGD._numnt > 6 ) {
254  _ddd.push_back(onePGD._nt6);
255  if ( onePGD._numnt > 7 ) {
256  _ddd.push_back(onePGD._nt7);
257  if ( onePGD._numnt > 8 ) {
258  _ddd.push_back(onePGD._nt8);
259  if ( onePGD._numnt > 9 ) {
260  _ddd.push_back(onePGD._nt9);
261  if ( onePGD._numnt > 10 ) {
262  _ddd.push_back(onePGD._nt10);
263  }}}}}}
264  }
265 
266 }
267 
269  //
270  // iterate on all the components ;)
271  //
272  //std::cout << "deepComponents1" << std::endl;
274  deepComponents(_temp);
275  return _temp;
276 }
277 
279  //std::cout << "const deepComponents2" << std::endl;
280  if (isLeaf())
281  cont.push_back(this);
282  else
283  std::for_each(_container.begin(),_container.end(),
284  [&](const GeometricDet* iDet) {
285  iDet->deepComponents(cont);
286  }
287  );
288 }
289 
291  //std::cout << "addComponents" << std::endl;
292  _container.reserve(_container.size()+cont.size());
293  std::copy(cont.begin(), cont.end(), back_inserter(_container));
294 }
295 
297  //std::cout << "addComponents" << std::endl;
298  _container.reserve(_container.size()+cont.size());
299  std::copy(cont.begin(), cont.end(), back_inserter(_container));
300 }
301 
303  //std::cout << "deepComponent" << std::endl;
304  _container.push_back(det);
305 }
306 
307 namespace {
308  struct Deleter {
309  void operator()(GeometricDet const* det) const { delete const_cast<GeometricDet*>(det);}
310  };
311 }
312 
314  //std::cout << "deleteComponents" << std::endl;
315  std::for_each(_container.begin(),_container.end(),Deleter());
316  _container.clear();
317 }
318 
319 
321  //std::cout << "positionBounds" << std::endl;
322  Position _pos(float(_trans.x()/cm),
323  float(_trans.y()/cm),
324  float(_trans.z()/cm));
325  return _pos;
326 }
327 
329  //std::cout << "rotationBounds" << std::endl;
330  DD3Vector x, y, z;
331  _rot.GetComponents(x, y, z);
332  Rotation _rotation(float(x.X()),float(x.Y()),float(x.Z()),
333  float(y.X()),float(y.Y()),float(y.Z()),
334  float(z.X()),float(z.Y()),float(z.Z()));
335  return _rotation;
336 }
337 
338 std::unique_ptr<Bounds> GeometricDet::bounds() const{
339  //std::cout << "bounds" << std::endl;
340  const std::vector<double>& par = _params;
341  TrackerShapeToBounds shapeToBounds;
342  return std::unique_ptr<Bounds>(shapeToBounds.buildBounds(_shape,par));
343 }
344 
ConstGeometricDetContainer _container
Definition: GeometricDet.h:303
type
Definition: HCALResponse.h:21
double _pixROCCols
Definition: GeometricDet.h:326
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
DDName _ddname
Definition: GeometricDet.h:310
tuple cont
load Luminosity info ##
Definition: generateEDF.py:622
double _pixROCRows
Definition: GeometricDet.h:325
void addComponent(GeometricDet *)
double _pixROCy
Definition: GeometricDet.h:328
DDSolidShape const & shape() const
Definition: GeometricDet.h:136
double _siliconAPVNum
Definition: GeometricDet.h:330
bool isLeaf() const
Definition: GeometricDet.h:107
bool ev
DDTranslation _trans
Definition: GeometricDet.h:304
nav_type navPos() const
return the stack of sibling numbers
type of data representation of DDCompactView
Definition: DDCompactView.h:77
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:80
std::vector< GeometricDet * > GeometricDetContainer
Definition: GeometricDet.h:37
double _pixROCx
Definition: GeometricDet.h:327
enum GeometricDet::GDEnumType GeometricEnumType
nav_type _ddd
Definition: GeometricDet.h:309
nav_type navPos() const
return the stack of sibling numbers which indicates the current position in the DDExpandedView ...
tuple result
Definition: mps_fire.py:84
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
DDName const & name() const
Definition: GeometricDet.h:144
Bounds * buildBounds(const DDSolidShape &, const std::vector< double > &) const
Position positionBounds() const
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
A DD Translation is currently implemented with Root Vector3D.
Definition: DDTranslation.h:6
const std::string fullname() const
Definition: DDName.h:51
std::vector< double > _params
Definition: GeometricDet.h:312
GeometricDet(DDFilteredView *fv, GeometricEnumType dd)
std::unique_ptr< Bounds > bounds() const
#define end
Definition: vmac.h:37
void deleteComponents()
const DDTranslation & translation() const
The absolute translation of the current node.
int nt
Definition: AMPTWrapper.h:32
std::vector< GeometricDet const * > ConstGeometricDetContainer
Definition: GeometricDet.h:36
DDSolidShape _shape
Definition: GeometricDet.h:308
int copyno() const
Copy number associated with the current node.
double _radLength
Definition: GeometricDet.h:323
ConstGeometricDetContainer deepComponents() const
DDExpandedView::nav_type nav_type
void addComponents(GeometricDetContainer const &cont)
#define begin
Definition: vmac.h:30
Rotation rotationBounds() const
DDRotationMatrix _rot
Definition: GeometricDet.h:307
DDExpandedView::nav_type nav_type
Definition: GeometricDet.h:44
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the expanded-view.
volatile std::atomic< bool > shutdown_flag false
Provides an exploded view of the detector (tree-view)
std::vector< DDExpandedNode > GeoHistory
Definition: GeometricDet.h:43