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 {
19  bool ret(true);
20 
21  std::cout <<"*********FIRST BY firstChild, firstChild, nextSibling, nextSibling*********" << std::endl;
22  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
23  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
24  << std::endl;
25  lhs.firstChild();
26  rhs.firstChild();
27  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
28  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
29  << std::endl;
30  lhs.firstChild();
31  rhs.firstChild();
32  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
33  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
34  << std::endl;
35  lhs.nextSibling();
36  rhs.nextSibling();
37  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
38  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
39  << std::endl;
40  lhs.nextSibling();
41  rhs.nextSibling();
42  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
43  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
44  << std::endl;
45  lhs.parent();
46  rhs.parent();
47  std::cout <<"*********THEN BY next, next, next, next*********" << std::endl;
48  lhs.parent();
49  rhs.parent();
50  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
51  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
52  << std::endl;
53  lhs.next();
54  rhs.next();
55  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
56  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
57  << std::endl;
58  lhs.next();
59  rhs.next();
60  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
61  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
62  << std::endl;
63  std::cout << lhs.depth() << " depth " << rhs.depth() << std::endl;
64  lhs.next();
65  rhs.next();
66  std::cout << lhs.depth() << " depth " << rhs.depth() << std::endl;
67  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno()
68  << " !=? " << rhs.logicalPart().name().name() << ":" << rhs.copyno()
69  << std::endl;
70  return ret;
71 }
72 
73 bool DDCompareCPV(const DDCompactView& lhs, const DDCompactView& rhs, const DDCompOptions& ddco)
74 {
75  bool ret(true);
76 
77  const auto & g1 = lhs.graph();
78  const auto & g2 = rhs.graph();
79 
82 
83  adjl_iterator git1 = g1.begin();
84  adjl_iterator gend1 = g1.end();
85  adjl_iterator git2 = g2.begin();
86  adjl_iterator gend2 = g2.end();
87 
89 
90  while ( git1 != gend1 && git2 != gend2 && ret ) {
91  const DDLogicalPart & ddLP1 = g1.nodeData(git1);
92  const DDLogicalPart & ddLP2 = g2.nodeData(git2);
93  std::cout << ++i << " P " << ddLP1.name() << " " << ddLP2.name() << std::endl;
94  if ( ! DDCompareLP(ddLP1, ddLP2, ddco) ) {
95  ret = false;
96  break;
97  } else if (!git1->empty() && !git2->empty() ) {
98  auto cit1 = git1->begin();
99  auto cend1 = git1->end();
100  auto cit2 = git2->begin();
101  auto cend2 = git2->end();
102 
103  while ( cit1 != cend1 && cit2 != cend2 ) {
104  const DDLogicalPart & ddcurLP1 = g1.nodeData(cit1->first);
105  const DDLogicalPart & ddcurLP2 = g2.nodeData(cit2->first);
106  std::cout << ++i << " c1--> " << g1.edgeData(cit1->second)->copyno() << " " << ddcurLP1.name().fullname() << std::endl;
107  std::cout << ++i << " c2--> " << g2.edgeData(cit2->second)->copyno() << " " << ddcurLP2.name().fullname() << std::endl;
108  const DDPosData* p1(g1.edgeData(cit1->second));
109  const DDPosData* p2(g2.edgeData(cit2->second));
110 
111  if ( p1->copyno() != p2->copyno() ||
112  ! DDCompareLP(ddcurLP1,ddcurLP2,ddco) ) {
113  std::cout << "Failed to match node (fullname:copy_no): 1: "
114  << ddcurLP1.name().fullname() << ":" << p1->copyno() << " 2: "
115  << ddcurLP2.name().fullname() << ":" << p2->copyno() << std::endl;
116  ret = false;
117  break;
118  } else if ( ! DDCompareDDTrans(p1->trans(), p2->trans()) ) {
119  std::cout << "Failed to match translation " << std::endl;
120  ret = false;
121  break;
122  } else if ( ! DDCompareDDRot(p1->ddrot(), p2->ddrot(), ddco) ) {
123  std::cout << "Failed to match rotation " << std::endl;
124  ret = false;
125  break;
126  }
127  ++cit1;
128  ++cit2;
129  }
130  } else if ( git1->size() != git2->size() ) {
131  ret = false;
132  std::cout << "DDCompactViews are different because number of children do not match" << std::endl;
133  std::cout << "graph1 size of edge_list: " << git1->size() << " and graph2 size of edge_list: " << git2->size() << std::endl;
134  break;
135  }
136  ++git1;
137  ++git2;
138  }
139  return ret;
140 }
141 
142 bool DDCompareLP(const DDLogicalPart& lhs, const DDLogicalPart& rhs, const DDCompOptions& ddco)
143 {
144  bool ret(true);
145  // for a logical part to be equal, the solid must be equal and the name must be equal.
146  if ( lhs.name().fullname() != rhs.name().fullname() ) {
147  ret = false;
148  std::cout << "LogicalPart names do not match " << lhs.name().fullname()
149  << " and " << rhs.name().fullname() << std::endl;
150  } else if ( ! DDCompareSolid(lhs.solid(), rhs.solid(), ddco) ){
151  ret = false;
152  std::cout << "LogicalPart Solids do not match " << lhs.name().fullname()
153  << " and " << rhs.name().fullname() << std::endl;
154  }
155  return ret;
156 }
157 
158 bool DDCompareSolid(const DDSolid& lhs, const DDSolid& rhs, const DDCompOptions& ddco)
159 {
160  bool ret(true);
161  switch ( lhs.shape() ) {
163  case DDSolidShape::ddbox:
166  case DDSolidShape::ddtrap:
179  {
180  if ( lhs.name().fullname() != rhs.name().fullname() ) {
181  ret = false;
182  std::cout << "Solid names do not match for solid " << lhs.name().fullname() << " and " << rhs.name().fullname() << std::endl;
183  } else if ( lhs.shape() != rhs.shape() ) {
184  ret = false;
185  std::cout << "Shape types do not match for solids " << lhs.name().fullname()
186  << " and " << rhs.name().fullname()
187  << " even though their names match " << std::endl;
188  } else if ( ! DDCompareDBLVEC(lhs.parameters(), rhs.parameters()) ) {
189  ret = false;
190  std::cout << "Parameters do not match for solids " << lhs.name().fullname()
191  << " and " << rhs.name().fullname()
192  << " even though their names and shape type match." << std::endl;
193  std::cout << "size: " << lhs.parameters().size() << " " << rhs.parameters().size() << std::endl;
194  }
195  break;
196  }
200  {
201  if ( ! DDCompareBoolSol(lhs, rhs, ddco) ) {
202  ret = false;
203  }
204  break;
205  }
206  default:
207  break;
208  }
209  return ret;
210 }
211 
212 // Default tolerance was 0.0004
213 bool DDCompareDBLVEC( const std::vector<double>& lhs, const std::vector<double>& rhs, double tol)
214 {
215  bool ret(true);
216  std::ios_base::fmtflags originalFlags = std::cout.flags();
217  int originalPrecision = std::cout.precision();
218  if( lhs.size() != rhs.size())
219  {
220  ret = false;
221  std::cout << "Size of vectors do not match." << std::endl;
222  }
223  else
224  {
225  for( size_t i = 0; i < lhs.size() ; ++i )
226  {
227  if( std::fabs( lhs[i] - rhs[i] ) > tol )
228  {
229  ret = false;
230  std::cout << "Vector content at index " << i << " does not match " ;
231  std::cout << std::setw(12) << std::fixed << std::setprecision(4) << lhs[i] << " != " << rhs[i] << std::endl;
232  break;
233  }
234  }
235  }
236  // Now set everything back to defaults
237  std::cout.flags( originalFlags );
238  std::cout.precision( originalPrecision );
239  return ret;
240 }
241 
242 bool DDCompareBoolSol( const DDBooleanSolid& lhs, const DDBooleanSolid& rhs, const DDCompOptions& ddco)
243 {
244  bool ret(true);
245  if ( lhs.name().fullname() != rhs.name().fullname() ) {
246  ret = false;
247  std::cout << "BooleanSolid names do not match ";
248  } else if ( lhs.shape() != rhs.shape() ) {
249  ret = false;
250  std::cout << "BooleanSolid shape types do not match ";
251  } else if ( ! DDCompareDBLVEC(lhs.parameters(), rhs.parameters(), ddco.distTol_) ) {
252  ret = false;
253  std::cout << "BooleanSolid parameters do not match ";
254  } else if ( ! DDCompareSolid(lhs.solidA(), rhs.solidA(), ddco) ) {
255  ret = false;
256  std::cout << "BooleanSolid SolidA solids do not match ";
257  } else if ( ! DDCompareSolid(lhs.solidB(), rhs.solidB(), ddco) ) {
258  ret= false;
259  std::cout << "BooleanSolid SolidB solids do not match ";
260  } else if ( ! DDCompareDDTrans(lhs.translation(), rhs.translation(), ddco.distTol_) ) {
261  ret = false;
262  std::cout << "BooleanSolid Translations do not match ";
263  } else if ( ! DDCompareDDRot(lhs.rotation(), rhs.rotation(), ddco) ) {
264  ret = false;
265  std::cout << "BooleanSolid Rotations do not match ";
266  }
267  if ( ! ret ) {
268  std::cout << "for boolean solids "
269  << lhs.name().fullname() << " and "
270  << rhs.name().fullname() << std::endl;
271  }
272  return ret;
273 }
274 
275 // Default tolerance was 0.0004
276 bool DDCompareDDTrans( const DDTranslation& lhs, const DDTranslation& rhs, double tol)
277 {
278  bool ret(true);
279  if ( std::fabs(lhs.x() - rhs.x()) > tol
280  || std::fabs(lhs.y() - rhs.y()) > tol
281  || std::fabs(lhs.z() - rhs.z()) > tol ) {
282  ret=false;
283  }
284  return ret;
285 }
286 
287 bool DDCompareDDRot( const DDRotation& lhs, const DDRotation& rhs, const DDCompOptions& ddco)
288 {
289  bool ret(true);
290  if ( ddco.compRotName_ && lhs.name().fullname() != rhs.name().fullname() ) {
291  ret = false;
292  std::cout << "DDRotation names do not match "
293  << lhs.name().fullname() << " and "
294  << rhs.name().fullname() << std::endl;
295  } else if ( ! DDCompareDDRotMat( lhs.rotation(), rhs.rotation()) ) {
296  ret = false;
297  std::cout << "DDRotationMatrix values do not match "
298  << lhs.name().fullname() << " and "
299  << rhs.name().fullname() << std::endl;
300  }
301  return ret;
302 }
303 
304 // Default tolerance was 0.0004
305 bool DDCompareDDRotMat( const DDRotationMatrix& lhs, const DDRotationMatrix& rhs, double tol )
306 {
307  bool ret(true);
308  // manual way to do it... postponed. Tested with Distance method from root::math
309  //DD3Vector x1, y1, z1;
310  //lhs.GetComponents(x1,y1,z1);
311  //DD3Vector x2, y2, z2;
312  //rhs.GetComponents(x2,y2,z2);
313  double dist = Distance(lhs,rhs);
314  if ( std::fabs(dist) > tol ) {
315  std::cout << "Rotation matrices do not match." << std::endl;
316  ret = false;
317  DD3Vector x, y, z;
318  std::cout << "FIRST" << std::endl;
319  lhs.GetComponents(x,y,z);
320  std::cout << std::setw(12) << std::fixed << std::setprecision(4) << x.X();
321  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.X();
322  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.X();
323  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Y();
324  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Y();
325  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Y();
326  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Z();
327  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Z();
328  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Z() << std::endl;
329  std::cout << "SECOND" << std::endl;
330  rhs.GetComponents(x,y,z);
331  std::cout << std::setw(12) << std::fixed << std::setprecision(4) << x.X();
332  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.X();
333  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.X();
334  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Y();
335  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Y();
336  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Y();
337  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Z();
338  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Z();
339  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Z() << std::endl;
340  }
341 
342  return ret;
343 }
bool next()
set current node to the next node in the expanded tree
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:74
bool DDCompareDBLVEC(const std::vector< double > &lhs, const std::vector< double > &rhs, double tol)
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
bool DDCompareLP(const DDLogicalPart &lhs, const DDLogicalPart &rhs, const DDCompOptions &ddco)
LogicalParts have solids which could be BooleanSolids.
DDTranslation translation(void) const
Definition: DDSolid.cc:604
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
float float float z
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
bool DDCompareDDRotMat(const DDRotationMatrix &lhs, const DDRotationMatrix &rhs, double tol)
DDSolid solidB(void) const
Definition: DDSolid.cc:616
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:68
bool DDCompareSolid(const DDSolid &lhs, const DDSolid &rhs, const DDCompOptions &ddco)
Needs to know about rotmat because of BooleanSolid.
DDRotation rotation(void) const
Definition: DDSolid.cc:598
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
A DD Translation is currently implemented with Root Vector3D.
Definition: DDTranslation.h:6
bool DDCompareCPV(const DDCompactView &lhs, const DDCompactView &rhs, const DDCompOptions &ddco)
int depth() const
depth of the scope. 0 means unrestricted depth.
const std::string fullname() const
Definition: DDName.h:43
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:138
bool DDCompareEPV(DDExpandedView &lhs, DDExpandedView &rhs, const DDCompOptions &ddco)
Graph::const_adj_iterator adjl_iterator
double p2[4]
Definition: TauolaWrapper.h:90
bool DDCompareDDTrans(const DDTranslation &lhs, const DDTranslation &rhs, double tol)
DDSolid solidA(void) const
Definition: DDSolid.cc:610
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.
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 ...
double p1[4]
Definition: TauolaWrapper.h:89
bool DDCompareDDRot(const DDRotation &lhs, const DDRotation &rhs, const DDCompOptions &ddco)
Allows to compare name or not. If not, compares only values of the rotation matrix.
const DDRotationMatrix & rotation() const
Returns the read-only rotation-matrix.
Definition: DDTransform.h:93
math::Graph< DDLogicalPart, DDPosData * > Graph
Definition: DDCompactView.h:83
bool DDCompareBoolSol(const DDBooleanSolid &lhs, const DDBooleanSolid &rhs, const DDCompOptions &ddco)
Needs to know because of Rotation Matrix of Boolean Relationship.
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)
const std::string & name() const
Returns the name.
Definition: DDName.cc:53