CMS 3D CMS Logo

GeometricTimingDet.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 
78 }
79 #ifdef GEOMETRICDETDEBUG
80 // for use outside CMSSW framework only since it asks for a default DDCompactView...
82  ddd_(navtype.begin(),navtype.end()), type_(type){
83  //
84  // I need to find the params by myself :(
85  //
86  //std::cout << "GeometricTimingDet1" << std::endl;
87  fromDD_ = true;
88  DDCompactView cpv; // bad, bad, bad!
89  DDExpandedView ev(cpv);
90  ev.goTo(navtype);
91  params_ = ((ev.logicalPart()).solid()).parameters();
92  trans_ = ev.translation();
93  phi_ = trans_.Phi();
94  rho_ = trans_.Rho();
95  rot_ = ev.rotation();
96  shape_ = ((ev.logicalPart()).solid()).shape();
97  ddname_ = ((ev.logicalPart()).ddname()).name();
98  parents_ = GeoHistory(ev.geoHistory().begin(),ev.geoHistory().end()) ;
99  volume_ = ((ev.logicalPart()).solid()).volume();
100  density_ = ((ev.logicalPart()).material()).density();
101  // _weight = (ev.logicalPart()).weight();
102  weight_ = density_ * ( volume_ / 1000.); // volume mm3->cm3
103  copy_ = ev.copyno();
104  material_ = ((ev.logicalPart()).material()).name().fullname();
105  radLength_ = getDouble("TrackerRadLength",ev);
106  xi_ = getDouble("TrackerXi",ev);
107  pixROCRows_ = getDouble("PixelROCRows",ev);
108  pixROCCols_ = getDouble("PixelROCCols",ev);
109  pixROCx_ = getDouble("PixelROC_X",ev);
110  pixROCy_ = getDouble("PixelROC_Y",ev);
111  stereo_ = getString("TrackerStereoDetectors",ev)==strue;
112  siliconAPVNum_ = getDouble("SiliconAPVNumber",ev);
113 
114 }
115 
117  //
118  // Set by hand the ddd_
119  //
120  //std::cout << "GeometricTimingDet2" << std::endl;
121  fromDD_ = true;
122  ddd_ = nav_type(fv->navPos().begin(),fv->navPos().end() );
123  params_ = ((fv->logicalPart()).solid()).parameters();
124  trans_ = fv->translation();
125  phi_ = trans_.Phi();
126  rho_ = trans_.Rho();
127  rot_ = fv->rotation();
128  shape_ = ((fv->logicalPart()).solid()).shape();
129  ddname_ = ((fv->logicalPart()).ddname()).name();
130  parents_ = GeoHistory(fv->geoHistory().begin(),fv->geoHistory().end()) ;
131  volume_ = ((fv->logicalPart()).solid()).volume();
132  density_ = ((fv->logicalPart()).material()).density();
133  // weight_ = (fv->logicalPart()).weight();
134  weight_ = density_ * ( volume_ / 1000.); // volume mm3->cm3
135  copy_ = fv->copyno();
136  material_ = ((fv->logicalPart()).material()).name().fullname();
137  radLength_ = getDouble("TrackerRadLength",*fv);
138  xi_ = getDouble("TrackerXi",*fv);
139  pixROCRows_ = getDouble("PixelROCRows",*fv);
140  pixROCCols_ = getDouble("PixelROCCols",*fv);
141  pixROCx_ = getDouble("PixelROC_X",*fv);
142  pixROCy_ = getDouble("PixelROC_Y",*fv);
143  stereo_ = getString("TrackerStereoDetectors",*fv)=="true";
144  siliconAPVNum_ = getDouble("SiliconAPVNumber",*fv);
145 
146 }
147 #endif
148 
150  //
151  // Set by hand the ddd_
152  //
153  trans_(fv->translation()),
154  phi_(trans_.Phi()),
155  rho_(trans_.Rho()),
156  rot_(fv->rotation()),
157  shape_(((fv->logicalPart()).solid()).shape()),
158  ddname_(((fv->logicalPart()).ddname()).name()),
159  type_(type),
160  params_(((fv->logicalPart()).solid()).parameters()),
161  // want this :) ddd_(fv->navPos().begin(),fv->navPos().end()),
162 #ifdef GEOMTRICDETDEBUG
163  parents_(fv->geoHistory().begin(),fv->geoHistory().end()),
164  volume_(((fv->logicalPart()).solid()).volume()),
165  density_(((fv->logicalPart()).material()).density()),
166  // _weight = (fv->logicalPart()).weight();
167  weight_(density_ * ( volume_ / 1000.)), // volume mm3->cm3
168  copy_(fv->copyno()),
169  material_(((fv->logicalPart()).material()).name().fullname()),
170 #endif
171  radLength_(getDouble("TrackerRadLength",*fv)),
172  xi_(getDouble("TrackerXi",*fv)),
173  pixROCRows_(getDouble("PixelROCRows",*fv)),
174  pixROCCols_(getDouble("PixelROCCols",*fv)),
175  pixROCx_(getDouble("PixelROC_X",*fv)),
176  pixROCy_(getDouble("PixelROC_Y",*fv)),
177  stereo_(getString("TrackerStereoDetectors",*fv)==strue),
178  siliconAPVNum_(getDouble("SiliconAPVNumber",*fv))
179 #ifdef GEOMTRICDETDEBUG
180  ,
181  fromDD_(true)
182 #endif
183 {
184  const DDFilteredView::nav_type& nt = fv->navPos();
185  ddd_ = nav_type(nt.begin(), nt.end());
186 }
187 
188 // PGeometricTimingDet is persistent version... make it... then come back here and make the
189 // constructor.
191  trans_(onePGD.x_, onePGD.y_, onePGD.z_),
192  phi_(onePGD.phi_), //_trans.Phi()),
193  rho_(onePGD.rho_), //_trans.Rho()),
194  rot_(onePGD.a11_, onePGD.a12_, onePGD.a13_,
195  onePGD.a21_, onePGD.a22_, onePGD.a23_,
196  onePGD.a31_, onePGD.a32_, onePGD.a33_),
197  shape_(static_cast<DDSolidShape>(onePGD.shape_)),
198  ddd_(),
199  ddname_(onePGD.name_, onePGD.ns_),//, "fromdb");
200  type_(type),
201  params_(),
203 #ifdef GEOMTRICDETDEBUG
204  parents_(), // will remain empty... hate wasting the space but want all methods to work.
205  volume_(onePGD.volume_),
206  density_(onePGD.density_),
207  weight_(onePGD.weight_),
208  copy_(onePGD.copy_),
209  material_(onePGD.material_),
210 #endif
211  radLength_(onePGD.radLength_),
212  xi_(onePGD.xi_),
213  pixROCRows_(onePGD.pixROCRows_),
214  pixROCCols_(onePGD.pixROCCols_),
215  pixROCx_(onePGD.pixROCx_),
216  pixROCy_(onePGD.pixROCy_),
217  stereo_(onePGD.stereo_),
219 #ifdef GEOMTRICDETDEBUG
220  , // mind the tricky comma is needed.
221  fromDD_(false)
222 #endif
223 {
224  //std::cout << "GeometricTimingDet4" << std::endl;
225 
226  if(onePGD.shape_==1||onePGD.shape_==3){ //The parms vector is neede only in the case of box or trap shape
227  params_.reserve(11);
228  params_.emplace_back(onePGD.params_0);
229  params_.emplace_back(onePGD.params_1);
230  params_.emplace_back(onePGD.params_2);
231  params_.emplace_back(onePGD.params_3);
232  params_.emplace_back(onePGD.params_4);
233  params_.emplace_back(onePGD.params_5);
234  params_.emplace_back(onePGD.params_6);
235  params_.emplace_back(onePGD.params_7);
236  params_.emplace_back(onePGD.params_8);
237  params_.emplace_back(onePGD.params_9);
238  params_.emplace_back(onePGD.params_10);
239  }
240 
241  ddd_.reserve(onePGD.numnt_);
242  ddd_.emplace_back(onePGD.nt0_);
243  ddd_.emplace_back(onePGD.nt1_);
244  ddd_.emplace_back(onePGD.nt2_);
245  ddd_.emplace_back(onePGD.nt3_);
246  if ( onePGD.numnt_ > 4 ) {
247  ddd_.emplace_back(onePGD.nt4_);
248  if ( onePGD.numnt_ > 5 ) {
249  ddd_.emplace_back(onePGD.nt5_);
250  if ( onePGD.numnt_ > 6 ) {
251  ddd_.emplace_back(onePGD.nt6_);
252  if ( onePGD.numnt_ > 7 ) {
253  ddd_.emplace_back(onePGD.nt7_);
254  if ( onePGD.numnt_ > 8 ) {
255  ddd_.emplace_back(onePGD.nt8_);
256  if ( onePGD.numnt_ > 9 ) {
257  ddd_.emplace_back(onePGD.nt9_);
258  if ( onePGD.numnt_ > 10 ) {
259  ddd_.emplace_back(onePGD.nt10_);
260  }}}}}}
261  }
262 
263 }
264 
266  //
267  // iterate on all the components ;)
268  //
270  deepComponents(temp);
271  return temp;
272 }
273 
275  if (isLeaf()) {
276  cont.emplace_back(this);
277  }
278  else
279  std::for_each(container_.begin(),container_.end(),
280  [&](const GeometricTimingDet* iDet) {
281  iDet->deepComponents(cont);
282  }
283  );
284 }
285 
287  container_.reserve(container_.size()+cont.size());
288  std::copy(cont.begin(), cont.end(), back_inserter(container_));
289 }
290 
292  container_.reserve(container_.size()+cont.size());
293  std::copy(cont.begin(), cont.end(), back_inserter(container_));
294 }
295 
297  container_.emplace_back(det);
298 }
299 
300 namespace {
301  struct Deleter {
302  void operator()(GeometricTimingDet const* det) const { delete const_cast<GeometricTimingDet*>(det);}
303  };
304 }
305 
307  std::for_each(container_.begin(),container_.end(),Deleter());
308  container_.clear();
309 }
310 
311 
313  Position pos(float(trans_.x()/cm),
314  float(trans_.y()/cm),
315  float(trans_.z()/cm));
316  return pos;
317 }
318 
320  DD3Vector x, y, z;
321  rot_.GetComponents(x, y, z);
322  Rotation rotation(float(x.X()),float(x.Y()),float(x.Z()),
323  float(y.X()),float(y.Y()),float(y.Z()),
324  float(z.X()),float(z.Y()),float(z.Z()));
325  return rotation;
326 }
327 
328 std::unique_ptr<Bounds> GeometricTimingDet::bounds() const{
329  const std::vector<double>& par = params_;
330  TrackerShapeToBounds shapeToBounds;
331  return std::unique_ptr<Bounds>(shapeToBounds.buildBounds(shape_,par));
332 }
333 
std::vector< GeometricTimingDet * > GeometricTimingDetContainer
type
Definition: HCALResponse.h:21
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
GeometricTimingEnumType type_
def copy(args, dbName)
std::vector< DDExpandedNode > GeoHistory
DDSolidShape
Definition: DDSolidShapes.h:6
bool ev
nav_type navPos() const
return the stack of sibling numbers
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:81
void addComponents(GeometricTimingDetContainer const &cont)
Position positionBounds() const
nav_type navPos() const
return the stack of sibling numbers which indicates the current position in the DDExpandedView ...
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
std::vector< double > params_
Bounds * buildBounds(const DDSolidShape &, const std::vector< double > &) const
std::unique_ptr< Bounds > bounds() const
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
A DD Translation is currently implemented with Root Vector3D.
Definition: DDTranslation.h:6
DDTranslation const & translation() const
ConstGeometricTimingDetContainer deepComponents() const
void addComponent(GeometricTimingDet *)
const std::string fullname() const
Definition: DDName.h:43
GeometricTimingDet(DDFilteredView *fv, GeometricTimingEnumType dd)
DDExpandedView::nav_type nav_type
#define end
Definition: vmac.h:39
const DDTranslation & translation() const
The absolute translation of the current node.
DDExpandedView::nav_type DDnav_type
int nt
Definition: AMPTWrapper.h:32
enum GeometricTimingDet::GTDEnumType GeometricTimingEnumType
int copyno() const
Copy number associated with the current node.
DDName const & name() const
DDExpandedView::nav_type nav_type
#define begin
Definition: vmac.h:32
DDRotationMatrix const & rotation() const
bool goTo(const nav_type &)
transversed the DDExpandedView according to the given stack of sibling numbers
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the expanded-view.
DDSolidShape const & shape() const
Provides an exploded view of the detector (tree-view)
DDRotationMatrix rot_
ConstGeometricTimingDetContainer container_
Rotation rotationBounds() const
std::vector< GeometricTimingDet const * > ConstGeometricTimingDetContainer