CMS 3D CMS Logo

DDCompareTools.cc
Go to the documentation of this file.
2 
3 #include <cstddef>
4 #include <cmath>
5 #include <iomanip>
6 #include <iostream>
7 #include <string>
8 #include <utility>
9 
15 #include "Math/GenVector/Rotation3D.h"
16 
18 
20 
22  bool ret(true);
23  /* struct DDCompareCPVGraph : public std::binary_function<DDCompactView::graph_type, DDCompactView::graph_type, bool> { */
24  /* bool operator()(const DDCompactView::graph_type& lhs, const DDCompactView::graph_type& rhs) const { */
25  /* bool ret; */
26  // const graph<DDLogicalPart, DDPosData*>& g1= lhs;
27  // graph<DDLogicalPart, DDPosData*>::const_iterator beg1 = g1.begin();
28  //DDCompactView::graph_type::const_iterator beg1 = lhs.begin();
29  /* std::cout << "size of lhs = " << lhs.edge_size() << std::endl; */
30  /* std::cout << "size of rhs = " << rhs.edge_size() << std::endl; */
31  /* std::cout << "iterating over lhs edges?" << std::endl; */
32  /* graph<DDLogicalPart, DDPosData*>::const_iterator beg1(lhs), end1(lhs); */
33  /* beg1 = lhs.begin_iter(); */
34  /* end1 = lhs.end_iter(); */
35  /* size_t countem(0); */
36  /* for ( ; beg1 != end1 ; ++beg1 ) { */
37  /* ++countem; */
38  /* } */
39  /* std::cout << "between lhs.begin_iter() and lhs.end_iter() there are " << countem << std::endl; */
40  /* graph<DDLogicalPart,DDPosData*>::const_edge_range cer = lhs.graph().edges(lhs.root()); */
41  /* graph<DDLogicalPart,DDPosData*>::adj_iterator i = const_edge_range.first */
42  // DDExpandedView v1(lhs), v2(rhs);
43  // if (v1.next()) std::cout << "v1 is true" << std::endl;
44  // if (v2.next()) std::cout << "v2 is true" << std::endl;
45  // DDNodeComparator ddnc;
46  //if ( ddnc (v1, v2) ) {
47  // ret = true;
48  //}
49  /* while (v1.next()) { */
50  /* if (v2.next()) { */
51  /* std::cout << v1.logicalPart().name().name() << ":" << v1.copyno() */
52  /* << " !=? " << v2.logicalPart().name().name() << ":" << v2.copyno() */
53  /* << std::endl; */
54 
55  /* if ( v1.logicalPart().name().name() != v2.logicalPart().name().name() ) { */
56  /* std::cout << v1.logicalPart().name().name() << ":" << v1.copyno() */
57  /* << " !=? " << v2.logicalPart().name().name() << ":" << v2.copyno() */
58  /* << std::endl; */
59  /* // std::cout << v1.logicalPart().name().name() << " !=? " << v2.logicalPart().name().name() << std::endl; */
60  /* ret=false; */
61  /* break; */
62  /* } */
63  /* } */
64  /* } */
65  std::cout <<"*********FIRST BY firstChild, firstChild, nextSibling, nextSibling*********" << std::endl;
66  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
67  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
68  << std::endl;
69  lhs.firstChild();
70  rhs.firstChild();
71  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
72  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
73  << std::endl;
74  lhs.firstChild();
75  rhs.firstChild();
76  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
77  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
78  << std::endl;
79  lhs.nextSibling();
80  rhs.nextSibling();
81  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
82  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
83  << std::endl;
84  lhs.nextSibling();
85  rhs.nextSibling();
86  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
87  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
88  << std::endl;
89  lhs.parent();
90  rhs.parent();
91  std::cout <<"*********THEN BY next, next, next, next*********" << std::endl;
92  lhs.parent();
93  rhs.parent();
94  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
95  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
96  << std::endl;
97  lhs.next();
98  rhs.next();
99  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
100  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
101  << std::endl;
102  lhs.next();
103  rhs.next();
104  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
105  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
106  << std::endl;
107  std::cout << lhs.depth() << " depth " << rhs.depth() << std::endl;
108  lhs.next();
109  rhs.next();
110  std::cout << lhs.depth() << " depth " << rhs.depth() << std::endl;
111  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
112  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
113  << std::endl;
114  return ret;
115 }
116 
118 
120 
121 bool DDCompareCPV::operator()(const DDCompactView& lhs, const DDCompactView& rhs) const {
122  bool ret(true);
123 
124  const DDCompactView::graph_type & g1 = lhs.graph();
125  const DDCompactView::graph_type & g2 = rhs.graph();
126 
127  typedef DDCompactView::graph_type::const_adj_iterator adjl_iterator;
128  adjl_iterator git1 = g1.begin();
129  adjl_iterator gend1 = g1.end();
130  adjl_iterator git2 = g2.begin();
131  adjl_iterator gend2 = g2.end();
132  /* std::cout << "uniqueness test: " << &(*git1) << " != " << &(*git2) */
133  /* << " and " << &(*gend1) << " != " << &(*gend2) << std::endl; */
134  // DDCompactView::graph_type::const_iterator bit = g1.begin_iter();
136  // for (; git1 != gend1; ++git1) {
137  while ( git1 != gend1 && git2 != gend2 && ret ) {
138  const DDLogicalPart & ddLP1 = g1.nodeData(git1);
139  const DDLogicalPart & ddLP2 = g2.nodeData(git2);
140  std::cout << ++i << " P " << ddLP1.name() << " " << ddLP2.name() << std::endl;
141  if ( ! DDCompareLP(ddco_)(ddLP1, ddLP2) ) {
142  ret = false;
143  break;
144  } else if (!git1->empty() && !git2->empty() ) {
145  DDCompactView::graph_type::edge_list::const_iterator cit1 = git1->begin();
146  DDCompactView::graph_type::edge_list::const_iterator cend1 = git1->end();
147  DDCompactView::graph_type::edge_list::const_iterator cit2 = git2->begin();
148  DDCompactView::graph_type::edge_list::const_iterator cend2 = git2->end();
149  //for (; cit != cend; ++cit) {
150  while ( cit1 != cend1 && cit2 != cend2 ) {
151  const DDLogicalPart & ddcurLP1 = g1.nodeData(cit1->first);
152  const DDLogicalPart & ddcurLP2 = g2.nodeData(cit2->first);
153  std::cout << ++i << " c1--> " << g1.edgeData(cit1->second)->copyno() << " " << ddcurLP1.name().fullname() << std::endl;
154  std::cout << ++i << " c2--> " << g2.edgeData(cit2->second)->copyno() << " " << ddcurLP2.name().fullname() << std::endl;
155  const DDPosData* p1(g1.edgeData(cit1->second));
156  const DDPosData* p2(g2.edgeData(cit2->second));
157  // if ( g1.edgeData(cit1->second)->copyno_ != g2.edgeData(cit2->second)->copyno_
158 // if ( p1->copyno_ != p2->copyno_
159 // || ddcurLP1.name().fullname() != ddcurLP2.name().fullname() ) {
160 // std::cout << "Failed to match node (fullname:copy_no): 1: "
161 // << ddcurLP1.name().fullname() << ":" << p1->copyno_ << " 2: "
162 // << ddcurLP2.name().fullname() << ":" << p2->copyno_ << std::endl;
163 // ret = false;
164 // break;
165  if ( p1->copyno() != p2->copyno() ||
166  ! DDCompareLP(ddco_)(ddcurLP1,ddcurLP2) ) {
167  std::cout << "Failed to match node (fullname:copy_no): 1: "
168  << ddcurLP1.name().fullname() << ":" << p1->copyno() << " 2: "
169  << ddcurLP2.name().fullname() << ":" << p2->copyno() << std::endl;
170  ret = false;
171  break;
172  } else if ( ! DDCompareDDTrans()(p1->trans(), p2->trans()) ) {
173  std::cout << "Failed to match translation " << std::endl;
174 // std::cout << "1: " << std::setw(12) << std::fixed << std::setprecision(4) << p1->trans_.x();
175 // std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << p1->trans_.y();
176 // std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << p1->trans_.z() << std::endl;
177 // std::cout << "2: " << std::setw(12) << std::fixed << std::setprecision(4) << p2->trans_.x();
178 // std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << p2->trans_.y();
179 // std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << p2->trans_.z() << std::endl;
180  ret = false;
181  break;
182  } else if ( ! DDCompareDDRot(ddco_)(p1->ddrot(), p2->ddrot()) ) {
183  std::cout << "Failed to match rotation " << std::endl;
184  ret = false;
185  break;
186  }
187  ++cit1;
188  ++cit2;
189  }
190  } else if ( git1->size() != git2->size() ) {
191  ret = false;
192  std::cout << "DDCompactViews are different because number of children do not match" << std::endl;
193  std::cout << "graph1 size of edge_list: " << git1->size() << " and graph2 size of edge_list: " << git2->size() << std::endl;
194  break;
195  }
196  ++git1;
197  ++git2;
198  }
199  return ret;
200 }
201 
203 
205 
206 bool DDCompareLP::operator()(const DDLogicalPart& lhs, const DDLogicalPart& rhs) const {
207  bool ret(true);
208  // for a logical part to be equal, the solid must be equal and the name must be equal.
209  if ( lhs.name().fullname() != rhs.name().fullname() ) {
210  ret = false;
211  std::cout << "LogicalPart names do not match " << lhs.name().fullname()
212  << " and " << rhs.name().fullname() << std::endl;
213  } else if ( ! DDCompareSolid(ddco_)(lhs.solid(), rhs.solid()) ){
214  ret = false;
215  std::cout << "LogicalPart Solids do not match " << lhs.name().fullname()
216  << " and " << rhs.name().fullname() << std::endl;
217  }
218  return ret;
219 }
220 
222 
224 
225 bool DDCompareSolid::operator()(const DDSolid& lhs, const DDSolid& rhs) const {
226  bool ret(true);
227  switch ( lhs.shape() ) {
228  case dd_not_init:
229  case ddbox:
230  case ddtubs:
231  case ddcuttubs:
232  case ddtrap:
233  case ddcons:
234  case ddpolycone_rz:
235  case ddpolyhedra_rz:
236  case ddpolycone_rrz:
237  case ddpolyhedra_rrz:
238  case ddextrudedpolygon:
239  case ddtorus:
240  case ddpseudotrap:
241  case ddtrunctubs:
242  case ddsphere:
243  case ddorb:
244  case ddellipticaltube:
245  case ddellipsoid:
246  case ddparallelepiped:
247  case ddshapeless:
248  {
249  if ( lhs.name().fullname() != rhs.name().fullname() ) {
250  ret = false;
251  std::cout << "Solid names do not match for solid " << lhs.name().fullname() << " and " << rhs.name().fullname() << std::endl;
252  } else if ( lhs.shape() != rhs.shape() ) {
253  ret = false;
254  std::cout << "Shape types do not match for solids " << lhs.name().fullname()
255  << " and " << rhs.name().fullname()
256  << " even though their names match " << std::endl;
257  } else if ( ! DDCompareDBLVEC()(lhs.parameters(), rhs.parameters()) ) {
258  ret = false;
259  std::cout << "Parameters do not match for solids " << lhs.name().fullname()
260  << " and " << rhs.name().fullname()
261  << " even though their names and shape type match." << std::endl;
262  std::cout << "size: " << lhs.parameters().size() << " " << rhs.parameters().size() << std::endl;
263  }
264  break;
265  }
266  case ddunion:
267  case ddsubtraction:
268  case ddintersection:
269  {
270  if ( ! DDCompareBoolSol(ddco_)(lhs, rhs) ) {
271  ret = false;
272  }
273  break;
274  }
275  case ddreflected:
276  {
277  DDReflectionSolid rs1(lhs);
278  DDReflectionSolid rs2(rhs);
279  if ( ! DDCompareSolid(ddco_)( rs1.unreflected(), rs2.unreflected()) ) {
280  ret = false;
281  std::cout << "Unreflected volumes of DDReflections do not match. Reflections are "
282  << lhs.name().fullname() << " and " << rhs.name().fullname() << std::endl;
283  }
284  break;
285  }
286  default:
287  break;
288  }
289  return ret;
290 }
291 
293 
295 
296 bool
297 DDCompareDBLVEC::operator() ( const std::vector<double>& lhs, const std::vector<double>& rhs ) const
298 {
299  bool ret(true);
300  std::ios_base::fmtflags originalFlags = std::cout.flags();
301  int originalPrecision = std::cout.precision();
302  if( lhs.size() != rhs.size())
303  {
304  ret = false;
305  std::cout << "Size of vectors do not match." << std::endl;
306  }
307  else
308  {
309  for( size_t i = 0; i < lhs.size() ; ++i )
310  {
311  if( std::fabs( lhs[i] - rhs[i] ) > tol_ )
312  {
313  ret = false;
314  std::cout << "Vector content at index " << i << " does not match " ;
315  std::cout << std::setw(12) << std::fixed << std::setprecision(4) << lhs[i] << " != " << rhs[i] << std::endl;
316  break;
317  }
318  }
319  }
320  // Now set everything back to defaults
321  std::cout.flags( originalFlags );
322  std::cout.precision( originalPrecision );
323  return ret;
324 }
325 
327 
329 bool DDCompareBoolSol::operator() ( const DDBooleanSolid& lhs, const DDBooleanSolid& rhs ) const {
330  bool ret(true);
331  if ( lhs.name().fullname() != rhs.name().fullname() ) {
332  ret = false;
333  std::cout << "BooleanSolid names do not match ";
334  } else if ( lhs.shape() != rhs.shape() ) {
335  ret = false;
336  std::cout << "BooleanSolid shape types do not match ";
337  } else if ( ! DDCompareDBLVEC(ddco_.distTol_)(lhs.parameters(), rhs.parameters()) ) {
338  ret = false;
339  std::cout << "BooleanSolid parameters do not match ";
340  } else if ( ! DDCompareSolid(ddco_)(lhs.solidA(), rhs.solidA()) ) {
341  ret = false;
342  std::cout << "BooleanSolid SolidA solids do not match ";
343  } else if ( ! DDCompareSolid(ddco_)(lhs.solidB(), rhs.solidB()) ) {
344  ret= false;
345  std::cout << "BooleanSolid SolidB solids do not match ";
346  } else if ( ! DDCompareDDTrans(ddco_.distTol_)(lhs.translation(), rhs.translation()) ) {
347  ret = false;
348  std::cout << "BooleanSolid Translations do not match ";
349  } else if ( ! DDCompareDDRot(ddco_)(lhs.rotation(), rhs.rotation()) ) {
350  ret = false;
351  std::cout << "BooleanSolid Rotations do not match ";
352  }
353  if ( ! ret ) {
354  std::cout << "for boolean solids "
355  << lhs.name().fullname() << " and "
356  << rhs.name().fullname() << std::endl;
357  }
358  return ret;
359 }
360 
362 
364 
365 bool DDCompareDDTrans::operator() ( const DDTranslation& lhs, const DDTranslation& rhs ) const {
366  bool ret(true);
367  if ( std::fabs(lhs.x() - rhs.x()) > tol_
368  || std::fabs(lhs.y() - rhs.y()) > tol_
369  || std::fabs(lhs.z() - rhs.z()) > tol_ ) {
370  ret=false;
371  }
372  return ret;
373 }
374 
376 
378 
379 bool DDCompareDDRot::operator() ( const DDRotation& lhs, const DDRotation& rhs ) const {
380  bool ret(true);
381  if ( ddco_.compRotName_ && lhs.name().fullname() != rhs.name().fullname() ) {
382  ret = false;
383  std::cout << "DDRotation names do not match "
384  << lhs.name().fullname() << " and "
385  << rhs.name().fullname() << std::endl;
386  } else if ( ! DDCompareDDRotMat()(*lhs.rotation(), *rhs.rotation()) ) {
387  ret = false;
388  std::cout << "DDRotationMatrix values do not match "
389  << lhs.name().fullname() << " and "
390  << rhs.name().fullname() << std::endl;
391  }
392  return ret;
393 }
394 
396 
398 
400  bool ret(true);
401  // manual way to do it... postponed. Tested with Distance method from root::math
402  //DD3Vector x1, y1, z1;
403  //lhs.GetComponents(x1,y1,z1);
404  //DD3Vector x2, y2, z2;
405  //rhs.GetComponents(x2,y2,z2);
406  double dist = Distance(lhs,rhs);
407  if ( std::fabs(dist) > tol_ ) {
408  std::cout << "Rotation matrices do not match." << std::endl;
409  ret = false;
410  DD3Vector x, y, z;
411  std::cout << "FIRST" << std::endl;
412  lhs.GetComponents(x,y,z);
413  std::cout << std::setw(12) << std::fixed << std::setprecision(4) << x.X();
414  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.X();
415  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.X();
416  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Y();
417  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Y();
418  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Y();
419  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Z();
420  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Z();
421  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Z() << std::endl;
422  std::cout << "SECOND" << std::endl;
423  rhs.GetComponents(x,y,z);
424  std::cout << std::setw(12) << std::fixed << std::setprecision(4) << x.X();
425  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.X();
426  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.X();
427  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Y();
428  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Y();
429  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Y();
430  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Z();
431  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Z();
432  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Z() << std::endl;
433  }
434 
435  return ret;
436 }
437 
438 
bool next()
set current node to the next node in the expanded tree
const DDRotationMatrix * rotation() const
Returns the read-only rotation-matrix.
Definition: DDTransform.h:91
const std::vector< double > & parameters(void) const
Give the parameters of the solid.
Definition: DDSolid.cc:150
bool parent()
set the current node to the parent node ...
Relative position of a child-volume inside a parent-volume.
Definition: DDPosData.h:13
std::vector< double >::size_type index_type
Definition: Graph.h:16
const N & name() const
Definition: DDBase.h:78
DDCompOptions ddco_
bool operator()(const DDCompactView &lhs, const DDCompactView &rhs) const
const graph_type & graph() const
Provides read-only access to the data structure of the compact-view.
Needs to know about rotmat because of BooleanSolid.
DDTranslation translation(void) const
Definition: DDSolid.cc:656
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
DDCompOptions ddco_
type of data representation of DDCompactView
Definition: DDCompactView.h:90
DDCompOptions ddco_
Needs to know because of Rotation Matrix of Boolean Relationship.
A DDSolid represents the shape of a part.
Definition: DDSolid.h:38
DDSolid solidB(void) const
Definition: DDSolid.cc:668
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
bool operator()(const DDTranslation &lhs, const DDTranslation &rhs) const
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:67
DDSolid unreflected(void) const
Definition: DDSolid.cc:291
DDRotation rotation(void) const
Definition: DDSolid.cc:650
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
A DD Translation is currently implemented with Root Vector3D.
Definition: DDTranslation.h:6
const N & nodeData(const edge_type &) const
Definition: Graph.h:312
const E & edgeData(index_type i) const
Definition: Graph.h:178
bool operator()(const DDLogicalPart &lhs, const DDLogicalPart &rhs) const
int depth() const
depth of the scope. 0 means unrestricted depth.
const std::string fullname() const
Definition: DDName.h:52
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:92
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:144
bool operator()(const std::vector< double > &lhs, const std::vector< double > &rhs) const
bool operator()(DDExpandedView &lhs, DDExpandedView &rhs) const
double p2[4]
Definition: TauolaWrapper.h:90
DDCompOptions ddco_
bool operator()(const DDSolid &lhs, const DDSolid &rhs) const
bool operator()(const DDBooleanSolid &lhs, const DDBooleanSolid &rhs) const
DDCompOptions ddco_
DDSolid solidA(void) const
Definition: DDSolid.cc:662
DDComparators need to know if names of DDRotation matter.
adj_iterator end()
Definition: Graph.h:194
bool operator()(const DDRotationMatrix &lhs, const DDRotationMatrix &rhs) const
int copyno() const
Definition: DDPosData.h:35
int copyno() const
Copy number associated with the current node.
bool firstChild()
set the current node to the first child ...
Allows to compare name or not. If not, compares only values of the rotation matrix.
bool nextSibling()
set the current node to the next sibling ...
adj_iterator begin()
Definition: Graph.h:192
DDCompOptions ddco_
LogicalParts have solids which could be BooleanSolids.
double p1[4]
Definition: TauolaWrapper.h:89
adj_list::const_iterator const_adj_iterator
Definition: Graph.h:125
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the expanded-view.
Provides an exploded view of the detector (tree-view)
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
bool operator()(const DDRotation &lhs, const DDRotation &rhs) const
const std::string & name() const
Returns the name.
Definition: DDName.cc:90