CMS 3D CMS Logo

DDExpandedView.cc
Go to the documentation of this file.
2 
3 #include <memory>
4 #include <ostream>
5 
12 #include "Math/GenVector/Cartesian3D.h"
13 #include "Math/GenVector/DisplacementVector3D.h"
14 #include "Math/GenVector/Rotation3D.h"
15 
16 class DDPartSelection;
17 
22  : walker_( nullptr ),
23  w2_( cpv.graph(), cpv.root()),
24  trans_( DDTranslation()),
25  rot_( DDRotationMatrix()),
26  depth_( 0 ),
27  worldpos_( cpv.worldPosition())
28 {
29  walker_ = &w2_;
30 
31  const DDPosData * pd((*walker_).current().second);
32  if (!pd)
33  pd = worldpos_;
34  DDExpandedNode expn((*walker_).current().first,
35  pd,
36  trans_,
37  rot_,
38  0);
39 
40  // starting point for position calculations, == root of expanded view
41  history_.emplace_back(expn);
42 }
43 
45 
47 {
48  return history_.back().logp_;
49 }
50 
51 
53 {
54  return history_.back().trans_;
55 }
56 
57 
59 {
60  return history_.back().rot_;
61 }
62 
63 
65 {
66  return history_;
67 }
68 
69 
71 {
72  return depth_;
73 }
74 
75 
77 {
78  return history_.back().copyno();
79 }
80 
87 {
88  bool result(false);
89  if (!scope_.empty() && history_.back() == scope_.back()) {
90  ; // no-next-sibling, if current node is the root of the scope!
91  }
92  else {
93  if ((*walker_).nextSibling()) {
94  DDExpandedNode & expn(history_.back()); // back of history_ is always current node
95  WalkerType::value_type curr = (*walker_).current();
96  DDPosData const * posdOld = expn.posd_;
97  expn.logp_=curr.first;
98  expn.posd_=curr.second;
99 
100  DDGeoHistory::size_type hsize = history_.size();
101 
102 
103  if (hsize>1) {
104  const DDExpandedNode & expnBefore(history_[hsize-2]);
105 
106  // T = T1 + INV[R1] * T2
107  expn.trans_ = expnBefore.trans_ + (expnBefore.rot_ * expn.posd_->trans());
108 
109  // R = R1*INV[R2]
110  // VI in principle we can do this
111  if ( !(expn.posd_->rot()==posdOld->rot()) ) {
112  expn.rot_ = expnBefore.rot_ * expn.posd_->rot();//.inverse();
113  }
114  }
115  else {
116  expn.trans_ = expn.posd_->trans();
117  expn.rot_ = expn.posd_->rot();//.inverse();
118  }
119  ++expn.siblingno_;
120  result = true;
121  }
122  }
123  return result;
124 }
125 
126 
132 {
133  bool result(false);
134  bool depthNotReached(true);
135 
136  // Check for the depth within the scope ...
137  if (depth_) {
138  if ( (history_.size()-scope_.size())==depth_ ) {
139  depthNotReached=false;
140  }
141  }
142  if (depthNotReached) {
143  if ((*walker_).firstChild()) {
144  DDExpandedNode & expnBefore(history_.back());
145  WalkerType::value_type curr = (*walker_).current();
146 
147  DDPosData * newPosd = curr.second;
148 
149  // T = ... (see nextSiblinig())
150  DDTranslation newTrans = expnBefore.trans_ + expnBefore.rot_ * newPosd->trans();
151 
152  // R = ... (see nextSibling())
153  DDRotationMatrix newRot = expnBefore.rot_ * newPosd->rot();//.inverse();
154 
155  // create a new Expanded node and push it to the history ...
156  DDExpandedNode expn(curr.first, curr.second,
157  newTrans, newRot, 0);
158 
159  history_.emplace_back(expn);
160  result = true;
161  } // if firstChild
162  } // if depthNotReached
163  return result;
164 }
165 
166 
172 {
173  bool result(false);
174  bool scopeRoot(false);
175 
176  // check for a scope
177  if (!scope_.empty()) {
178  if (scope_.back() == history_.back()) {
179  // the current node is the root of the scope
180  scopeRoot = true;
181  }
182  }
183 
184  if (!scopeRoot) {
185  if ((*walker_).parent()) {
186  history_.pop_back();
187  result = true;
188  }
189  }
190 
191  return result;
192 }
193 
194 // same implementation as in GraphWalker !
210 {
211  bool res(false);
212  if(firstChild())
213  res=true;
214  else if(nextSibling())
215  res=true;
216  else {
217  while(parent()) {
218  if(nextSibling()) {
219  res=true;
220  break;
221  }
222  }
223  }
224  return res;
225 }
226 
227 
230 {
231  bool res(false);
232  return res;
233 }
234 
235 
236 void dump(const DDGeoHistory & history)
237 {
238  edm::LogInfo("DDExpandedView") << "--GeoHistory-Dump--[" << std::endl;
239  int i=0;
240  for( const auto& it : history ) {
241  edm::LogInfo("DDExpandedView") << " " << i << it.logicalPart() << std::endl;
242  ++i;
243  }
244  edm::LogInfo("DDExpandedView") << "]---------" << std::endl;
245 }
246 
254 std::vector< const DDsvalues_type *> DDExpandedView::specifics() const
255 {
256  // backward compatible
257  std::vector<const DDsvalues_type * > result;
258  specificsV(result);
259  return result;
260 }
261 
262 void
263 DDExpandedView::specificsV(std::vector<const DDsvalues_type * > & result) const
264 {
265  const auto & specs = logicalPart().attachedSpecifics();
266  if( !specs.empty())
267  {
268  result.reserve(specs.size());
269  for( const auto& it : specs ) {
270  // a part selection
271  const DDPartSelection & psel = *(it.first);
272  const DDGeoHistory & hist = geoHistory();
273 
274  if (DDCompareEqual(hist, psel)())
275  result.emplace_back( it.second );
276  }
277  }
278 }
279 
281  DDsvalues_type merged;
282  mergedSpecificsV(merged);
283  return merged;
284 }
285 
287 {
288  merged.clear();
289  const auto& specs = logicalPart().attachedSpecifics();
290  if (specs.empty()) return;
291  const DDGeoHistory & hist = geoHistory();
292  for( const auto& it : specs ) {
293  if (DDCompareEqual(hist, *it.first)())
294  merge(merged,*it.second);
295  }
296 }
297 
305 {
306  return scope_;
307 }
308 
310 {
311  scope_.clear();
312  depth_=0;
313 }
314 
316 {
317  clearScope();
318  while(parent())
319  ;
320 }
321 
322 
334 {
335  bool result(false);
336 
337  DDGeoHistory buf = scope_; // save current scope
338  scope_.clear(); // sets scope to global (full) scope
339 
340  while (parent()) ; // move up to the root of the expanded-view
341 
342  if (descend(sc)) { // try to move down the given scope-history ...
343  scope_ = sc;
344  depth_ = depth;
345  result = true;
346  }
347  else {
348  scope_ = buf;
349  }
350 
351  return result;
352 }
353 
354 
362 {
363  bool result = true;
364  int tempD = depth_;
365  DDGeoHistory tempScope = scope_;
366  reset();
367  DDGeoHistory::size_type s = pos.size();
368  for( DDGeoHistory::size_type j=1; j<s; ++j) {
369  if (! firstChild()) {
370  result = false;
371  break;
372  }
373  int i=0;
374  for (; i<pos[j].siblingno(); ++i) {
375  if (! nextSibling()) {
376  result = false;
377  }
378  }
379  }
380 
381  if (!result) {
382  reset();
383  setScope(tempScope, tempD);
384  }
385  else {
386  scope_ = tempScope;
387  depth_ = tempD;
388  }
389 
390  return result;
391 }
392 
395 {
396  DDGeoHistory::size_type mxx = sc.size();
397  DDGeoHistory::size_type cur = 0;
398  bool result(false);
399 
400  /* algo: compare currerent node in expanded-view with current-node in sc
401  if matching:
402  (A)go to first child in expanded-view, go one level deeper in sc
403  iterate over all children in expanded-view until one of them
404  matches the current node in sc.
405  if no one matches, return false
406  else continue at (A)
407  else return false
408  */
409  const DDExpandedNode & curNode = history_.back();
410 
411  if (!sc.empty()) {
412  if (curNode==sc[cur]) {
413  bool res(false);
414  while(cur+1 < mxx && firstChild()) {
415  ++cur;
416  if (!(history_.back()==sc[cur])) {
417  while(nextSibling()) {
418  if (history_.back()==sc[cur]) {
419  res=true;
420  break;
421  }
422  }
423  }
424  else {
425  res=true;
426  }
427  if (res==false)
428  break;
429  }
430  result = res;
431  }
432  }
433  return result;
434 }
435 
436 
437 bool DDExpandedView::goTo(const nav_type & newpos) {
438  return goTo(&newpos.front(),newpos.size());
439 
440 }
441 
443  return goTo(newpos.first,newpos.second);
444 }
445 
446 bool DDExpandedView::goTo(int const * newpos, size_t sz)
447 {
448  bool result(false);
449 
450  // save the current position
451  DDGeoHistory savedPos = history_;
452 
453  // reset to root node
454  //FIXME: reset to root of scope!!
455  reset();
456 
457  // try to navigate down to the newpos
458  for (size_t i = 1; i < sz; ++i) {
459  result = firstChild();
460  if (result) {
461  int pos = newpos[i];
462  for(int k=0; k<pos; ++k) {
463  result = nextSibling();
464  }
465  }
466  else {
467  break;
468  }
469  }
470 
471  if (!result) {
472  goToHistory(savedPos);
473  }
474  return result;
475 }
476 
478 {
481  nav_type pos(j);
482 
483  for (;i<j;++i)
484  pos[i] = history_[i].siblingno();
485 
486  return pos;
487 }
488 
490 {
492  DDGeoHistory::size_type sz = history_.size();
493  nav_type result(sz);
494 
495  for (; it < sz; ++it) {
496  result[it] = history_[it].copyno();
497  }
498  return result;
499 }
500 
501 std::string printNavType(int const * n, size_t sz){
502  std::ostringstream oss;
503  oss << '(' ;
504  for (int const * it=n; it != n+sz; ++it) {
505  oss << *it << ',';
506  }
507  oss << ')';
508  return oss.str();
509 }
bool next()
set current node to the next node in the expanded tree
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
bool parent()
set the current node to the parent node ...
Relative position of a child-volume inside a parent-volume.
Definition: DDPosData.h:13
DDsvalues_type mergedSpecifics() const
typename math::Graph< DDLogicalPart, DDPosData * >::value_type value_type
Definition: GraphWalker.h:29
bool descend(const DDGeoHistory &sc)
nav_type copyNumbers() const
return the stack of copy numbers
compares a given geometrical-history whether it corresponds to the given part-selector ...
Definition: DDComparator.h:16
#define nullptr
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
virtual ~DDExpandedView()
DDGeoHistory history_
std::vector of DDExpandedNode
std::vector< const DDsvalues_type * > specifics() const
User specific data attached to the current node.
represents one node in the DDExpandedView
unsigned int depth_
depth of the scope, 0==unrestricted depth
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
uint16_t size_type
std::pair< int const *, size_t > NavRange
Definition: Electron.h:6
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
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.
DDRotationMatrix rot_
WalkerType w2_
WalkerType * walker_
the tricky walker
DDTranslation trans_
void dump(const DDGeoHistory &history)
void specificsV(std::vector< const DDsvalues_type * > &vc) const
const DDTranslation trans_
DDExpandedView(const DDCompactView &)
Constructs an expanded-view based on the compact-view.
int depth() const
depth of the scope. 0 means unrestricted depth.
const DDRotationMatrix & rot() const
Definition: DDPosData.h:33
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
const DDTranslation & trans() const
Definition: DDPosData.h:30
DDTranslation trans_
Definition: DDPosData.h:41
bool setScope(const DDGeoHistory &hist, int depth=0)
sets the scope of the expanded view
const DDTranslation & translation() const
The absolute translation of the current node.
void clearScope()
clears the scope; the full tree is available, depth=0
int k[5][pyjets_maxn]
std::vector< DDExpandedNode > DDGeoHistory
Geometrical &#39;path&#39; of the current node up to the root-node.
bool nextB()
broad search order of next()
const DDGeoHistory & scope() const
The scope of the expanded-view.
void reset()
true, if a call to firstChild() would succeed (current node has at least one child) ...
int copyno() const
Copy number associated with the current node.
bool firstChild()
set the current node to the first child ...
bool nextSibling()
set the current node to the next sibling ...
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
Definition: DDsvalues.h:12
const DDRotationMatrix rot_
bool goToHistory(const DDGeoHistory &sc)
bool goTo(const nav_type &)
transversed the DDExpandedView according to the given stack of sibling numbers
const DDPosData * worldpos_
???
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the expanded-view.
std::string printNavType(int const *n, size_t sz)
DDGeoHistory scope_
scope of the expanded view
const std::vector< std::pair< const DDPartSelection *, const DDsvalues_type * > > & attachedSpecifics(void) const
void mergedSpecificsV(DDsvalues_type &res) const
std::vector< int > nav_type
std::vector of sibling numbers
def merge(dictlist, TELL=False)
Definition: MatrixUtil.py:194