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 
24  std::cout <<"*********FIRST BY firstChild, firstChild, nextSibling, nextSibling*********" << std::endl;
25  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
26  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
27  << std::endl;
28  lhs.firstChild();
29  rhs.firstChild();
30  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
31  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
32  << std::endl;
33  lhs.firstChild();
34  rhs.firstChild();
35  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
36  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
37  << std::endl;
38  lhs.nextSibling();
39  rhs.nextSibling();
40  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
41  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
42  << std::endl;
43  lhs.nextSibling();
44  rhs.nextSibling();
45  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
46  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
47  << std::endl;
48  lhs.parent();
49  rhs.parent();
50  std::cout <<"*********THEN BY next, next, next, next*********" << std::endl;
51  lhs.parent();
52  rhs.parent();
53  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
54  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
55  << std::endl;
56  lhs.next();
57  rhs.next();
58  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
59  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
60  << std::endl;
61  lhs.next();
62  rhs.next();
63  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
64  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
65  << std::endl;
66  std::cout << lhs.depth() << " depth " << rhs.depth() << std::endl;
67  lhs.next();
68  rhs.next();
69  std::cout << lhs.depth() << " depth " << rhs.depth() << std::endl;
70  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
71  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
72  << std::endl;
73  return ret;
74 }
75 
77 
79 
80 bool DDCompareCPV::operator()(const DDCompactView& lhs, const DDCompactView& rhs) const {
81  bool ret(true);
82 
83  const auto & g1 = lhs.graph();
84  const auto & g2 = rhs.graph();
85 
88 
89  adjl_iterator git1 = g1.begin();
90  adjl_iterator gend1 = g1.end();
91  adjl_iterator git2 = g2.begin();
92  adjl_iterator gend2 = g2.end();
93 
95 
96  while ( git1 != gend1 && git2 != gend2 && ret ) {
97  const DDLogicalPart & ddLP1 = g1.nodeData(git1);
98  const DDLogicalPart & ddLP2 = g2.nodeData(git2);
99  std::cout << ++i << " P " << ddLP1.name() << " " << ddLP2.name() << std::endl;
100  if ( ! DDCompareLP(ddco_)(ddLP1, ddLP2) ) {
101  ret = false;
102  break;
103  } else if (!git1->empty() && !git2->empty() ) {
104  auto cit1 = git1->begin();
105  auto cend1 = git1->end();
106  auto cit2 = git2->begin();
107  auto cend2 = git2->end();
108 
109  while ( cit1 != cend1 && cit2 != cend2 ) {
110  const DDLogicalPart & ddcurLP1 = g1.nodeData(cit1->first);
111  const DDLogicalPart & ddcurLP2 = g2.nodeData(cit2->first);
112  std::cout << ++i << " c1--> " << g1.edgeData(cit1->second)->copyno() << " " << ddcurLP1.name().fullname() << std::endl;
113  std::cout << ++i << " c2--> " << g2.edgeData(cit2->second)->copyno() << " " << ddcurLP2.name().fullname() << std::endl;
114  const DDPosData* p1(g1.edgeData(cit1->second));
115  const DDPosData* p2(g2.edgeData(cit2->second));
116 
117  if ( p1->copyno() != p2->copyno() ||
118  ! DDCompareLP(ddco_)(ddcurLP1,ddcurLP2) ) {
119  std::cout << "Failed to match node (fullname:copy_no): 1: "
120  << ddcurLP1.name().fullname() << ":" << p1->copyno() << " 2: "
121  << ddcurLP2.name().fullname() << ":" << p2->copyno() << std::endl;
122  ret = false;
123  break;
124  } else if ( ! DDCompareDDTrans()(p1->trans(), p2->trans()) ) {
125  std::cout << "Failed to match translation " << std::endl;
126  ret = false;
127  break;
128  } else if ( ! DDCompareDDRot(ddco_)(p1->ddrot(), p2->ddrot()) ) {
129  std::cout << "Failed to match rotation " << std::endl;
130  ret = false;
131  break;
132  }
133  ++cit1;
134  ++cit2;
135  }
136  } else if ( git1->size() != git2->size() ) {
137  ret = false;
138  std::cout << "DDCompactViews are different because number of children do not match" << std::endl;
139  std::cout << "graph1 size of edge_list: " << git1->size() << " and graph2 size of edge_list: " << git2->size() << std::endl;
140  break;
141  }
142  ++git1;
143  ++git2;
144  }
145  return ret;
146 }
147 
149 
151 
152 bool DDCompareLP::operator()(const DDLogicalPart& lhs, const DDLogicalPart& rhs) const {
153  bool ret(true);
154  // for a logical part to be equal, the solid must be equal and the name must be equal.
155  if ( lhs.name().fullname() != rhs.name().fullname() ) {
156  ret = false;
157  std::cout << "LogicalPart names do not match " << lhs.name().fullname()
158  << " and " << rhs.name().fullname() << std::endl;
159  } else if ( ! DDCompareSolid(ddco_)(lhs.solid(), rhs.solid()) ){
160  ret = false;
161  std::cout << "LogicalPart Solids do not match " << lhs.name().fullname()
162  << " and " << rhs.name().fullname() << std::endl;
163  }
164  return ret;
165 }
166 
168 
170 
171 bool DDCompareSolid::operator()(const DDSolid& lhs, const DDSolid& rhs) const {
172  bool ret(true);
173  switch ( lhs.shape() ) {
175  case DDSolidShape::ddbox:
178  case DDSolidShape::ddtrap:
191  {
192  if ( lhs.name().fullname() != rhs.name().fullname() ) {
193  ret = false;
194  std::cout << "Solid names do not match for solid " << lhs.name().fullname() << " and " << rhs.name().fullname() << std::endl;
195  } else if ( lhs.shape() != rhs.shape() ) {
196  ret = false;
197  std::cout << "Shape types do not match for solids " << lhs.name().fullname()
198  << " and " << rhs.name().fullname()
199  << " even though their names match " << std::endl;
200  } else if ( ! DDCompareDBLVEC()(lhs.parameters(), rhs.parameters()) ) {
201  ret = false;
202  std::cout << "Parameters do not match for solids " << lhs.name().fullname()
203  << " and " << rhs.name().fullname()
204  << " even though their names and shape type match." << std::endl;
205  std::cout << "size: " << lhs.parameters().size() << " " << rhs.parameters().size() << std::endl;
206  }
207  break;
208  }
212  {
213  if ( ! DDCompareBoolSol(ddco_)(lhs, rhs) ) {
214  ret = false;
215  }
216  break;
217  }
218  default:
219  break;
220  }
221  return ret;
222 }
223 
225 
227 
228 bool
229 DDCompareDBLVEC::operator() ( const std::vector<double>& lhs, const std::vector<double>& rhs ) const
230 {
231  bool ret(true);
232  std::ios_base::fmtflags originalFlags = std::cout.flags();
233  int originalPrecision = std::cout.precision();
234  if( lhs.size() != rhs.size())
235  {
236  ret = false;
237  std::cout << "Size of vectors do not match." << std::endl;
238  }
239  else
240  {
241  for( size_t i = 0; i < lhs.size() ; ++i )
242  {
243  if( std::fabs( lhs[i] - rhs[i] ) > tol_ )
244  {
245  ret = false;
246  std::cout << "Vector content at index " << i << " does not match " ;
247  std::cout << std::setw(12) << std::fixed << std::setprecision(4) << lhs[i] << " != " << rhs[i] << std::endl;
248  break;
249  }
250  }
251  }
252  // Now set everything back to defaults
253  std::cout.flags( originalFlags );
254  std::cout.precision( originalPrecision );
255  return ret;
256 }
257 
259 
261 bool DDCompareBoolSol::operator() ( const DDBooleanSolid& lhs, const DDBooleanSolid& rhs ) const {
262  bool ret(true);
263  if ( lhs.name().fullname() != rhs.name().fullname() ) {
264  ret = false;
265  std::cout << "BooleanSolid names do not match ";
266  } else if ( lhs.shape() != rhs.shape() ) {
267  ret = false;
268  std::cout << "BooleanSolid shape types do not match ";
269  } else if ( ! DDCompareDBLVEC(ddco_.distTol_)(lhs.parameters(), rhs.parameters()) ) {
270  ret = false;
271  std::cout << "BooleanSolid parameters do not match ";
272  } else if ( ! DDCompareSolid(ddco_)(lhs.solidA(), rhs.solidA()) ) {
273  ret = false;
274  std::cout << "BooleanSolid SolidA solids do not match ";
275  } else if ( ! DDCompareSolid(ddco_)(lhs.solidB(), rhs.solidB()) ) {
276  ret= false;
277  std::cout << "BooleanSolid SolidB solids do not match ";
278  } else if ( ! DDCompareDDTrans(ddco_.distTol_)(lhs.translation(), rhs.translation()) ) {
279  ret = false;
280  std::cout << "BooleanSolid Translations do not match ";
281  } else if ( ! DDCompareDDRot(ddco_)(lhs.rotation(), rhs.rotation()) ) {
282  ret = false;
283  std::cout << "BooleanSolid Rotations do not match ";
284  }
285  if ( ! ret ) {
286  std::cout << "for boolean solids "
287  << lhs.name().fullname() << " and "
288  << rhs.name().fullname() << std::endl;
289  }
290  return ret;
291 }
292 
294 
296 
297 bool DDCompareDDTrans::operator() ( const DDTranslation& lhs, const DDTranslation& rhs ) const {
298  bool ret(true);
299  if ( std::fabs(lhs.x() - rhs.x()) > tol_
300  || std::fabs(lhs.y() - rhs.y()) > tol_
301  || std::fabs(lhs.z() - rhs.z()) > tol_ ) {
302  ret=false;
303  }
304  return ret;
305 }
306 
308 
310 
311 bool DDCompareDDRot::operator() ( const DDRotation& lhs, const DDRotation& rhs ) const {
312  bool ret(true);
313  if ( ddco_.compRotName_ && lhs.name().fullname() != rhs.name().fullname() ) {
314  ret = false;
315  std::cout << "DDRotation names do not match "
316  << lhs.name().fullname() << " and "
317  << rhs.name().fullname() << std::endl;
318  } else if ( ! DDCompareDDRotMat()(*lhs.rotation(), *rhs.rotation()) ) {
319  ret = false;
320  std::cout << "DDRotationMatrix values do not match "
321  << lhs.name().fullname() << " and "
322  << rhs.name().fullname() << std::endl;
323  }
324  return ret;
325 }
326 
328 
330 
332  bool ret(true);
333  // manual way to do it... postponed. Tested with Distance method from root::math
334  //DD3Vector x1, y1, z1;
335  //lhs.GetComponents(x1,y1,z1);
336  //DD3Vector x2, y2, z2;
337  //rhs.GetComponents(x2,y2,z2);
338  double dist = Distance(lhs,rhs);
339  if ( std::fabs(dist) > tol_ ) {
340  std::cout << "Rotation matrices do not match." << std::endl;
341  ret = false;
342  DD3Vector x, y, z;
343  std::cout << "FIRST" << std::endl;
344  lhs.GetComponents(x,y,z);
345  std::cout << std::setw(12) << std::fixed << std::setprecision(4) << x.X();
346  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.X();
347  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.X();
348  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Y();
349  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Y();
350  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Y();
351  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Z();
352  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Z();
353  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Z() << std::endl;
354  std::cout << "SECOND" << std::endl;
355  rhs.GetComponents(x,y,z);
356  std::cout << std::setw(12) << std::fixed << std::setprecision(4) << x.X();
357  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.X();
358  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.X();
359  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Y();
360  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Y();
361  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Y();
362  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Z();
363  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Z();
364  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Z() << std::endl;
365  }
366 
367  return ret;
368 }
369 
370 
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:144
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
Needs to know about rotmat because of BooleanSolid.
DDTranslation translation(void) const
Definition: DDSolid.cc:605
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
DDCompOptions ddco_
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:83
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:617
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
DDRotation rotation(void) const
Definition: DDSolid.cc:599
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: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:138
bool operator()(const std::vector< double > &lhs, const std::vector< double > &rhs) const
Graph::const_adj_iterator adjl_iterator
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:611
const Graph & graph() const
Provides read-only access to the data structure of the compact-view.
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_
LogicalParts have solids which could be BooleanSolids.
double p1[4]
Definition: TauolaWrapper.h:89
math::Graph< DDLogicalPart, DDPosData * > Graph
Definition: DDCompactView.h:86
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:88