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  walker_ = &w2_;
29 
30  const DDPosData* pd((*walker_).current().second);
31  if (!pd)
32  pd = worldpos_;
33  DDExpandedNode expn((*walker_).current().first, pd, trans_, rot_, 0);
34 
35  // starting point for position calculations, == root of expanded view
36  history_.emplace_back(expn);
37 }
38 
40 
41 const DDLogicalPart& DDExpandedView::logicalPart() const { return history_.back().logp_; }
42 
43 const std::string& DDExpandedView::name() const { return history_.back().logp_.ddname().name(); }
44 
45 const DDTranslation& DDExpandedView::translation() const { return history_.back().trans_; }
46 
47 const DDRotationMatrix& DDExpandedView::rotation() const { return history_.back().rot_; }
48 
50 
51 int DDExpandedView::depth() const { return depth_; }
52 
53 int DDExpandedView::copyno() const { return history_.back().copyno(); }
54 
61  bool result(false);
62  if (!scope_.empty() && history_.back() == scope_.back()) {
63  ; // no-next-sibling, if current node is the root of the scope!
64  } else {
65  if ((*walker_).nextSibling()) {
66  DDExpandedNode& expn(history_.back()); // back of history_ is always current node
67  WalkerType::value_type curr = (*walker_).current();
68  DDPosData const* posdOld = expn.posd_;
69  expn.logp_ = curr.first;
70  expn.posd_ = curr.second;
71 
72  DDGeoHistory::size_type hsize = history_.size();
73 
74  if (hsize > 1) {
75  const DDExpandedNode& expnBefore(history_[hsize - 2]);
76 
77  // T = T1 + INV[R1] * T2
78  expn.trans_ = expnBefore.trans_ + (expnBefore.rot_ * expn.posd_->trans());
79 
80  // R = R1*INV[R2]
81  // VI in principle we can do this
82  if (!(expn.posd_->rot() == posdOld->rot())) {
83  expn.rot_ = expnBefore.rot_ * expn.posd_->rot(); //.inverse();
84  }
85  } else {
86  expn.trans_ = expn.posd_->trans();
87  expn.rot_ = expn.posd_->rot(); //.inverse();
88  }
89  ++expn.siblingno_;
90  result = true;
91  }
92  }
93  return result;
94 }
95 
101  bool result(false);
102  bool depthNotReached(true);
103 
104  // Check for the depth within the scope ...
105  if (depth_) {
106  if ((history_.size() - scope_.size()) == depth_) {
107  depthNotReached = false;
108  }
109  }
110  if (depthNotReached) {
111  if ((*walker_).firstChild()) {
112  DDExpandedNode& expnBefore(history_.back());
113  WalkerType::value_type curr = (*walker_).current();
114 
115  DDPosData* newPosd = curr.second;
116 
117  // T = ... (see nextSiblinig())
118  DDTranslation newTrans = expnBefore.trans_ + expnBefore.rot_ * newPosd->trans();
119 
120  // R = ... (see nextSibling())
121  DDRotationMatrix newRot = expnBefore.rot_ * newPosd->rot(); //.inverse();
122 
123  // create a new Expanded node and push it to the history ...
124  DDExpandedNode expn(curr.first, curr.second, newTrans, newRot, 0);
125 
126  history_.emplace_back(expn);
127  result = true;
128  } // if firstChild
129  } // if depthNotReached
130  return result;
131 }
132 
138  bool result(false);
139  bool scopeRoot(false);
140 
141  // check for a scope
142  if (!scope_.empty()) {
143  if (scope_.back() == history_.back()) {
144  // the current node is the root of the scope
145  scopeRoot = true;
146  }
147  }
148 
149  if (!scopeRoot) {
150  if ((*walker_).parent()) {
151  history_.pop_back();
152  result = true;
153  }
154  }
155 
156  return result;
157 }
158 
159 // same implementation as in GraphWalker !
175  bool res(false);
176  if (firstChild())
177  res = true;
178  else if (nextSibling())
179  res = true;
180  else {
181  while (parent()) {
182  if (nextSibling()) {
183  res = true;
184  break;
185  }
186  }
187  }
188  return res;
189 }
190 
193  bool res(false);
194  return res;
195 }
196 
197 void dump(const DDGeoHistory& history) {
198  edm::LogInfo("DDExpandedView") << "--GeoHistory-Dump--[" << std::endl;
199  int i = 0;
200  for (const auto& it : history) {
201  edm::LogInfo("DDExpandedView") << " " << i << it.logicalPart() << std::endl;
202  ++i;
203  }
204  edm::LogInfo("DDExpandedView") << "]---------" << std::endl;
205 }
206 
214 std::vector<const DDsvalues_type*> DDExpandedView::specifics() const {
215  // backward compatible
216  std::vector<const DDsvalues_type*> result;
217  specificsV(result);
218  return result;
219 }
220 
221 void DDExpandedView::specificsV(std::vector<const DDsvalues_type*>& result) const {
222  const auto& specs = logicalPart().attachedSpecifics();
223  if (!specs.empty()) {
224  result.reserve(specs.size());
225  for (const auto& it : specs) {
226  // a part selection
227  const DDPartSelection& psel = *(it.first);
228  const DDGeoHistory& hist = geoHistory();
229 
230  if (DDCompareEqual(hist, psel)())
231  result.emplace_back(it.second);
232  }
233  }
234 }
235 
237  DDsvalues_type merged;
238  mergedSpecificsV(merged);
239  return merged;
240 }
241 
243  merged.clear();
244  const auto& specs = logicalPart().attachedSpecifics();
245  if (specs.empty())
246  return;
247  const DDGeoHistory& hist = geoHistory();
248  for (const auto& it : specs) {
249  if (DDCompareEqual(hist, *it.first)())
250  merge(merged, *it.second);
251  }
252 }
253 
260 const DDGeoHistory& DDExpandedView::scope() const { return scope_; }
261 
263  scope_.clear();
264  depth_ = 0;
265 }
266 
268  clearScope();
269  while (parent())
270  ;
271 }
272 
284  bool result(false);
285 
286  DDGeoHistory buf = scope_; // save current scope
287  scope_.clear(); // sets scope to global (full) scope
288 
289  while (parent())
290  ; // move up to the root of the expanded-view
291 
292  if (descend(sc)) { // try to move down the given scope-history ...
293  scope_ = sc;
294  depth_ = depth;
295  result = true;
296  } else {
297  scope_ = buf;
298  }
299 
300  return result;
301 }
302 
310  bool result = true;
311  int tempD = depth_;
312  DDGeoHistory tempScope = scope_;
313  reset();
314  DDGeoHistory::size_type s = pos.size();
315  for (DDGeoHistory::size_type j = 1; j < s; ++j) {
316  if (!firstChild()) {
317  result = false;
318  break;
319  }
320  int i = 0;
321  for (; i < pos[j].siblingno(); ++i) {
322  if (!nextSibling()) {
323  result = false;
324  }
325  }
326  }
327 
328  if (!result) {
329  reset();
330  setScope(tempScope, tempD);
331  } else {
332  scope_ = tempScope;
333  depth_ = tempD;
334  }
335 
336  return result;
337 }
338 
341  DDGeoHistory::size_type mxx = sc.size();
342  DDGeoHistory::size_type cur = 0;
343  bool result(false);
344 
345  /* algo: compare currerent node in expanded-view with current-node in sc
346  if matching:
347  (A)go to first child in expanded-view, go one level deeper in sc
348  iterate over all children in expanded-view until one of them
349  matches the current node in sc.
350  if no one matches, return false
351  else continue at (A)
352  else return false
353  */
354  const DDExpandedNode& curNode = history_.back();
355 
356  if (!sc.empty()) {
357  if (curNode == sc[cur]) {
358  bool res(false);
359  while (cur + 1 < mxx && firstChild()) {
360  ++cur;
361  if (!(history_.back() == sc[cur])) {
362  while (nextSibling()) {
363  if (history_.back() == sc[cur]) {
364  res = true;
365  break;
366  }
367  }
368  } else {
369  res = true;
370  }
371  if (res == false)
372  break;
373  }
374  result = res;
375  }
376  }
377  return result;
378 }
379 
380 bool DDExpandedView::goTo(const nav_type& newpos) { return goTo(&newpos.front(), newpos.size()); }
381 
382 bool DDExpandedView::goTo(NavRange newpos) { return goTo(newpos.first, newpos.second); }
383 
384 bool DDExpandedView::goTo(int const* newpos, size_t sz) {
385  bool result(false);
386 
387  // save the current position
388  DDGeoHistory savedPos = history_;
389 
390  // reset to root node
391  //FIXME: reset to root of scope!!
392  reset();
393 
394  // try to navigate down to the newpos
395  for (size_t i = 1; i < sz; ++i) {
396  result = firstChild();
397  if (result) {
398  int pos = newpos[i];
399  for (int k = 0; k < pos; ++k) {
400  result = nextSibling();
401  }
402  } else {
403  break;
404  }
405  }
406 
407  if (!result) {
408  goToHistory(savedPos);
409  }
410  return result;
411 }
412 
416  nav_type pos(j);
417 
418  for (; i < j; ++i)
419  pos[i] = history_[i].siblingno();
420 
421  return pos;
422 }
423 
426  DDGeoHistory::size_type sz = history_.size();
427  nav_type result(sz);
428 
429  for (; it < sz; ++it) {
430  result[it] = history_[it].copyno();
431  }
432  return result;
433 }
434 
435 std::string printNavType(int const* n, size_t sz) {
436  std::ostringstream oss;
437  oss << '(';
438  for (int const* it = n; it != n + sz; ++it) {
439  oss << *it << ',';
440  }
441  oss << ')';
442  return oss.str();
443 }
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
bool descend(const DDGeoHistory &sc)
nav_type copyNumbers() const
return the stack of copy numbers
const std::string & name() const
The name of the logical-part of the current node in the expanded-view.
compares a given geometrical-history whether it corresponds to the given part-selector ...
Definition: DDComparator.h:15
#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_
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
Definition: DDsvalues.h:12
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:31
typename math::Graph< DDLogicalPart, DDPosData * >::value_type value_type
Definition: GraphWalker.h:28
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
const DDTranslation & trans() const
Definition: DDPosData.h:28
DDTranslation trans_
Definition: DDPosData.h:39
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
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 ...
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