CMS 3D CMS Logo

DDCompareTools.cc
Go to the documentation of this file.
2 
3 #include <stddef.h>
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->size() && git2->size() ) {
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->rot_, p2->rot_) ) {
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 ddtorus:
239  case ddpseudotrap:
240  case ddtrunctubs:
241  case ddsphere:
242  case ddorb:
243  case ddellipticaltube:
244  case ddellipsoid:
245  case ddparallelepiped:
246  case ddshapeless:
247  {
248  if ( lhs.name().fullname() != rhs.name().fullname() ) {
249  ret = false;
250  std::cout << "Solid names do not match for solid " << lhs.name().fullname() << " and " << rhs.name().fullname() << std::endl;
251  } else if ( lhs.shape() != rhs.shape() ) {
252  ret = false;
253  std::cout << "Shape types do not match for solids " << lhs.name().fullname()
254  << " and " << rhs.name().fullname()
255  << " even though their names match " << std::endl;
256  } else if ( ! DDCompareDBLVEC()(lhs.parameters(), rhs.parameters()) ) {
257  ret = false;
258  std::cout << "Parameters do not match for solids " << lhs.name().fullname()
259  << " and " << rhs.name().fullname()
260  << " even though their names and shape type match." << std::endl;
261  std::cout << "size: " << lhs.parameters().size() << " " << rhs.parameters().size() << std::endl;
262  }
263  break;
264  }
265  case ddunion:
266  case ddsubtraction:
267  case ddintersection:
268  {
269  if ( ! DDCompareBoolSol(ddco_)(lhs, rhs) ) {
270  ret = false;
271  }
272  break;
273  }
274  case ddreflected:
275  {
276  DDReflectionSolid rs1(lhs);
277  DDReflectionSolid rs2(rhs);
278  if ( ! DDCompareSolid(ddco_)( rs1.unreflected(), rs2.unreflected()) ) {
279  ret = false;
280  std::cout << "Unreflected volumes of DDReflections do not match. Reflections are "
281  << lhs.name().fullname() << " and " << rhs.name().fullname() << std::endl;
282  }
283  break;
284  }
285  default:
286  break;
287  }
288  return ret;
289 }
290 
292 
294 
295 bool
296 DDCompareDBLVEC::operator() ( const std::vector<double>& lhs, const std::vector<double>& rhs ) const
297 {
298  bool ret(true);
299  std::ios_base::fmtflags originalFlags = std::cout.flags();
300  int originalPrecision = std::cout.precision();
301  if( lhs.size() != rhs.size())
302  {
303  ret = false;
304  std::cout << "Size of vectors do not match." << std::endl;
305  }
306  else
307  {
308  for( size_t i = 0; i < lhs.size() ; ++i )
309  {
310  if( std::fabs( lhs[i] - rhs[i] ) > tol_ )
311  {
312  ret = false;
313  std::cout << "Vector content at index " << i << " does not match " ;
314  std::cout << std::setw(12) << std::fixed << std::setprecision(4) << lhs[i] << " != " << rhs[i] << std::endl;
315  break;
316  }
317  }
318  }
319  // Now set everything back to defaults
320  std::cout.flags( originalFlags );
321  std::cout.precision( originalPrecision );
322  return ret;
323 }
324 
326 
328 bool DDCompareBoolSol::operator() ( const DDBooleanSolid& lhs, const DDBooleanSolid& rhs ) const {
329  bool ret(true);
330  if ( lhs.name().fullname() != rhs.name().fullname() ) {
331  ret = false;
332  std::cout << "BooleanSolid names do not match ";
333  } else if ( lhs.shape() != rhs.shape() ) {
334  ret = false;
335  std::cout << "BooleanSolid shape types do not match ";
336  } else if ( ! DDCompareDBLVEC(ddco_.distTol_)(lhs.parameters(), rhs.parameters()) ) {
337  ret = false;
338  std::cout << "BooleanSolid parameters do not match ";
339  } else if ( ! DDCompareSolid(ddco_)(lhs.solidA(), rhs.solidA()) ) {
340  ret = false;
341  std::cout << "BooleanSolid SolidA solids do not match ";
342  } else if ( ! DDCompareSolid(ddco_)(lhs.solidB(), rhs.solidB()) ) {
343  ret= false;
344  std::cout << "BooleanSolid SolidB solids do not match ";
345  } else if ( ! DDCompareDDTrans(ddco_.distTol_)(lhs.translation(), rhs.translation()) ) {
346  ret = false;
347  std::cout << "BooleanSolid Translations do not match ";
348  } else if ( ! DDCompareDDRot(ddco_)(lhs.rotation(), rhs.rotation()) ) {
349  ret = false;
350  std::cout << "BooleanSolid Rotations do not match ";
351  }
352  if ( ! ret ) {
353  std::cout << "for boolean solids "
354  << lhs.name().fullname() << " and "
355  << rhs.name().fullname() << std::endl;
356  }
357  return ret;
358 }
359 
361 
363 
364 bool DDCompareDDTrans::operator() ( const DDTranslation& lhs, const DDTranslation& rhs ) const {
365  bool ret(true);
366  if ( std::fabs(lhs.x() - rhs.x()) > tol_
367  || std::fabs(lhs.y() - rhs.y()) > tol_
368  || std::fabs(lhs.z() - rhs.z()) > tol_ ) {
369  ret=false;
370  }
371  return ret;
372 }
373 
375 
377 
378 bool DDCompareDDRot::operator() ( const DDRotation& lhs, const DDRotation& rhs ) const {
379  bool ret(true);
380  if ( ddco_.compRotName_ && lhs.name().fullname() != rhs.name().fullname() ) {
381  ret = false;
382  std::cout << "DDRotation names do not match "
383  << lhs.name().fullname() << " and "
384  << rhs.name().fullname() << std::endl;
385  } else if ( ! DDCompareDDRotMat()(*lhs.rotation(), *rhs.rotation()) ) {
386  ret = false;
387  std::cout << "DDRotationMatrix values do not match "
388  << lhs.name().fullname() << " and "
389  << rhs.name().fullname() << std::endl;
390  }
391  return ret;
392 }
393 
395 
397 
399  bool ret(true);
400  // manual way to do it... postponed. Tested with Distance method from root::math
401  //DD3Vector x1, y1, z1;
402  //lhs.GetComponents(x1,y1,z1);
403  //DD3Vector x2, y2, z2;
404  //rhs.GetComponents(x2,y2,z2);
405  double dist = Distance(lhs,rhs);
406  if ( std::fabs(dist) > tol_ ) {
407  std::cout << "Rotation matrices do not match." << std::endl;
408  ret = false;
409  DD3Vector x, y, z;
410  std::cout << "FIRST" << std::endl;
411  lhs.GetComponents(x,y,z);
412  std::cout << std::setw(12) << std::fixed << std::setprecision(4) << x.X();
413  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.X();
414  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.X();
415  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Y();
416  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Y();
417  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Y();
418  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Z();
419  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Z();
420  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Z() << std::endl;
421  std::cout << "SECOND" << std::endl;
422  rhs.GetComponents(x,y,z);
423  std::cout << std::setw(12) << std::fixed << std::setprecision(4) << x.X();
424  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.X();
425  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.X();
426  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Y();
427  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Y();
428  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Y();
429  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Z();
430  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Z();
431  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Z() << std::endl;
432  }
433 
434  return ret;
435 }
436 
437 
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:88
const std::vector< double > & parameters(void) const
Give the parameters of the solid.
Definition: DDSolid.cc:146
bool parent()
set the current node to the parent node ...
Relative position of a child-volume inside a parent-volume.
Definition: DDPosData.h:13
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.
const N & nodeData(const edge_type &) const
Definition: adjgraph.h:317
const E & edgeData(index_type i) const
Definition: adjgraph.h:183
DDTranslation translation(void) const
Definition: DDSolid.cc:542
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
std::vector< double >::size_type index_type
Definition: adjgraph.h:15
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:37
DDSolid solidB(void) const
Definition: DDSolid.cc:554
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:64
DDSolid unreflected(void) const
Definition: DDSolid.cc:287
DDRotation rotation(void) const
Definition: DDSolid.cc:536
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
A DD Translation is currently implemented with Root Vector3D.
Definition: DDTranslation.h:6
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:53
int copyno_
Definition: DDPosData.h:38
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:140
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:548
DDComparators need to know if names of DDRotation matter.
bool operator()(const DDRotationMatrix &lhs, const DDRotationMatrix &rhs) const
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 ...
DDCompOptions ddco_
adj_list::const_iterator const_adj_iterator
Definition: adjgraph.h:125
LogicalParts have solids which could be BooleanSolids.
double p1[4]
Definition: TauolaWrapper.h:89
adj_iterator begin()
Definition: adjgraph.h:197
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
adj_iterator end()
Definition: adjgraph.h:199