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  bool ret(true);
19 
20  std::cout << "*********FIRST BY firstChild, firstChild, nextSibling, nextSibling*********" << std::endl;
21  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno() << " !=? " << rhs.logicalPart().name().name()
22  << ":" << rhs.copyno() << std::endl;
23  lhs.firstChild();
24  rhs.firstChild();
25  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno() << " !=? " << rhs.logicalPart().name().name()
26  << ":" << rhs.copyno() << std::endl;
27  lhs.firstChild();
28  rhs.firstChild();
29  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno() << " !=? " << rhs.logicalPart().name().name()
30  << ":" << rhs.copyno() << std::endl;
31  lhs.nextSibling();
32  rhs.nextSibling();
33  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno() << " !=? " << rhs.logicalPart().name().name()
34  << ":" << rhs.copyno() << std::endl;
35  lhs.nextSibling();
36  rhs.nextSibling();
37  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno() << " !=? " << rhs.logicalPart().name().name()
38  << ":" << rhs.copyno() << std::endl;
39  lhs.parent();
40  rhs.parent();
41  std::cout << "*********THEN BY next, next, next, next*********" << std::endl;
42  lhs.parent();
43  rhs.parent();
44  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno() << " !=? " << rhs.logicalPart().name().name()
45  << ":" << rhs.copyno() << std::endl;
46  lhs.next();
47  rhs.next();
48  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno() << " !=? " << rhs.logicalPart().name().name()
49  << ":" << rhs.copyno() << std::endl;
50  lhs.next();
51  rhs.next();
52  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno() << " !=? " << rhs.logicalPart().name().name()
53  << ":" << rhs.copyno() << std::endl;
54  std::cout << lhs.depth() << " depth " << rhs.depth() << std::endl;
55  lhs.next();
56  rhs.next();
57  std::cout << lhs.depth() << " depth " << rhs.depth() << std::endl;
58  std::cout << lhs.logicalPart().name().name() << ":" << lhs.copyno() << " !=? " << rhs.logicalPart().name().name()
59  << ":" << rhs.copyno() << std::endl;
60  return ret;
61 }
62 
63 bool DDCompareCPV(const DDCompactView& lhs, const DDCompactView& rhs, const DDCompOptions& ddco) {
64  bool ret(true);
65 
66  const auto& g1 = lhs.graph();
67  const auto& g2 = rhs.graph();
68 
71 
72  adjl_iterator git1 = g1.begin();
73  adjl_iterator gend1 = g1.end();
74  adjl_iterator git2 = g2.begin();
75  adjl_iterator gend2 = g2.end();
76 
77  Graph::index_type i = 0;
78 
79  while (git1 != gend1 && git2 != gend2 && ret) {
80  const DDLogicalPart& ddLP1 = g1.nodeData(git1);
81  const DDLogicalPart& ddLP2 = g2.nodeData(git2);
82  std::cout << ++i << " P " << ddLP1.name() << " " << ddLP2.name() << std::endl;
83  if (!DDCompareLP(ddLP1, ddLP2, ddco)) {
84  ret = false;
85  break;
86  } else if (!git1->empty() && !git2->empty()) {
87  auto cit1 = git1->begin();
88  auto cend1 = git1->end();
89  auto cit2 = git2->begin();
90  auto cend2 = git2->end();
91 
92  while (cit1 != cend1 && cit2 != cend2) {
93  const DDLogicalPart& ddcurLP1 = g1.nodeData(cit1->first);
94  const DDLogicalPart& ddcurLP2 = g2.nodeData(cit2->first);
95  std::cout << ++i << " c1--> " << g1.edgeData(cit1->second)->copyno() << " " << ddcurLP1.name().fullname()
96  << std::endl;
97  std::cout << ++i << " c2--> " << g2.edgeData(cit2->second)->copyno() << " " << ddcurLP2.name().fullname()
98  << std::endl;
99  const DDPosData* p1(g1.edgeData(cit1->second));
100  const DDPosData* p2(g2.edgeData(cit2->second));
101 
102  if (p1->copyno() != p2->copyno() || !DDCompareLP(ddcurLP1, ddcurLP2, ddco)) {
103  std::cout << "Failed to match node (fullname:copy_no): 1: " << ddcurLP1.name().fullname() << ":"
104  << p1->copyno() << " 2: " << ddcurLP2.name().fullname() << ":" << p2->copyno() << std::endl;
105  ret = false;
106  break;
107  } else if (!DDCompareDDTrans(p1->trans(), p2->trans())) {
108  std::cout << "Failed to match translation " << std::endl;
109  ret = false;
110  break;
111  } else if (!DDCompareDDRot(p1->ddrot(), p2->ddrot(), ddco)) {
112  std::cout << "Failed to match rotation " << std::endl;
113  ret = false;
114  break;
115  }
116  ++cit1;
117  ++cit2;
118  }
119  } else if (git1->size() != git2->size()) {
120  ret = false;
121  std::cout << "DDCompactViews are different because number of children do not match" << std::endl;
122  std::cout << "graph1 size of edge_list: " << git1->size() << " and graph2 size of edge_list: " << git2->size()
123  << std::endl;
124  break;
125  }
126  ++git1;
127  ++git2;
128  }
129  return ret;
130 }
131 
132 bool DDCompareLP(const DDLogicalPart& lhs, const DDLogicalPart& rhs, const DDCompOptions& ddco) {
133  bool ret(true);
134  // for a logical part to be equal, the solid must be equal and the name must be equal.
135  if (lhs.name().fullname() != rhs.name().fullname()) {
136  ret = false;
137  std::cout << "LogicalPart names do not match " << lhs.name().fullname() << " and " << rhs.name().fullname()
138  << std::endl;
139  } else if (!DDCompareSolid(lhs.solid(), rhs.solid(), ddco)) {
140  ret = false;
141  std::cout << "LogicalPart Solids do not match " << lhs.name().fullname() << " and " << rhs.name().fullname()
142  << std::endl;
143  }
144  return ret;
145 }
146 
147 bool DDCompareSolid(const DDSolid& lhs, const DDSolid& rhs, const DDCompOptions& ddco) {
148  bool ret(true);
149  switch (lhs.shape()) {
151  case DDSolidShape::ddbox:
167  if (lhs.name().fullname() != rhs.name().fullname()) {
168  ret = false;
169  std::cout << "Solid names do not match for solid " << lhs.name().fullname() << " and " << rhs.name().fullname()
170  << std::endl;
171  } else if (lhs.shape() != rhs.shape()) {
172  ret = false;
173  std::cout << "Shape types do not match for solids " << lhs.name().fullname() << " and " << rhs.name().fullname()
174  << " even though their names match " << std::endl;
175  } else if (!DDCompareDBLVEC(lhs.parameters(), rhs.parameters())) {
176  ret = false;
177  std::cout << "Parameters do not match for solids " << lhs.name().fullname() << " and " << rhs.name().fullname()
178  << " even though their names and shape type match." << std::endl;
179  std::cout << "size: " << lhs.parameters().size() << " " << rhs.parameters().size() << std::endl;
180  }
181  break;
182  }
186  if (!DDCompareBoolSol(lhs, rhs, ddco)) {
187  ret = false;
188  }
189  break;
190  }
191  default:
192  break;
193  }
194  return ret;
195 }
196 
197 // Default tolerance was 0.0004
198 bool DDCompareDBLVEC(const std::vector<double>& lhs, const std::vector<double>& rhs, double tol) {
199  bool ret(true);
200  std::ios_base::fmtflags originalFlags = std::cout.flags();
201  int originalPrecision = std::cout.precision();
202  if (lhs.size() != rhs.size()) {
203  ret = false;
204  std::cout << "Size of vectors do not match." << std::endl;
205  } else {
206  for (size_t i = 0; i < lhs.size(); ++i) {
207  if (std::fabs(lhs[i] - rhs[i]) > tol) {
208  ret = false;
209  std::cout << "Vector content at index " << i << " does not match ";
210  std::cout << std::setw(12) << std::fixed << std::setprecision(4) << lhs[i] << " != " << rhs[i] << std::endl;
211  break;
212  }
213  }
214  }
215  // Now set everything back to defaults
216  std::cout.flags(originalFlags);
217  std::cout.precision(originalPrecision);
218  return ret;
219 }
220 
221 bool DDCompareBoolSol(const DDBooleanSolid& lhs, const DDBooleanSolid& rhs, const DDCompOptions& ddco) {
222  bool ret(true);
223  if (lhs.name().fullname() != rhs.name().fullname()) {
224  ret = false;
225  std::cout << "BooleanSolid names do not match ";
226  } else if (lhs.shape() != rhs.shape()) {
227  ret = false;
228  std::cout << "BooleanSolid shape types do not match ";
229  } else if (!DDCompareDBLVEC(lhs.parameters(), rhs.parameters(), ddco.distTol_)) {
230  ret = false;
231  std::cout << "BooleanSolid parameters do not match ";
232  } else if (!DDCompareSolid(lhs.solidA(), rhs.solidA(), ddco)) {
233  ret = false;
234  std::cout << "BooleanSolid SolidA solids do not match ";
235  } else if (!DDCompareSolid(lhs.solidB(), rhs.solidB(), ddco)) {
236  ret = false;
237  std::cout << "BooleanSolid SolidB solids do not match ";
238  } else if (!DDCompareDDTrans(lhs.translation(), rhs.translation(), ddco.distTol_)) {
239  ret = false;
240  std::cout << "BooleanSolid Translations do not match ";
241  } else if (!DDCompareDDRot(lhs.rotation(), rhs.rotation(), ddco)) {
242  ret = false;
243  std::cout << "BooleanSolid Rotations do not match ";
244  }
245  if (!ret) {
246  std::cout << "for boolean solids " << lhs.name().fullname() << " and " << rhs.name().fullname() << std::endl;
247  }
248  return ret;
249 }
250 
251 // Default tolerance was 0.0004
252 bool DDCompareDDTrans(const DDTranslation& lhs, const DDTranslation& rhs, double tol) {
253  bool ret(true);
254  if (std::fabs(lhs.x() - rhs.x()) > tol || std::fabs(lhs.y() - rhs.y()) > tol || std::fabs(lhs.z() - rhs.z()) > tol) {
255  ret = false;
256  }
257  return ret;
258 }
259 
260 bool DDCompareDDRot(const DDRotation& lhs, const DDRotation& rhs, const DDCompOptions& ddco) {
261  bool ret(true);
262  if (ddco.compRotName_ && lhs.name().fullname() != rhs.name().fullname()) {
263  ret = false;
264  std::cout << "DDRotation names do not match " << lhs.name().fullname() << " and " << rhs.name().fullname()
265  << std::endl;
266  } else if (!DDCompareDDRotMat(lhs.rotation(), rhs.rotation())) {
267  ret = false;
268  std::cout << "DDRotationMatrix values do not match " << lhs.name().fullname() << " and " << rhs.name().fullname()
269  << std::endl;
270  }
271  return ret;
272 }
273 
274 // Default tolerance was 0.0004
275 bool DDCompareDDRotMat(const DDRotationMatrix& lhs, const DDRotationMatrix& rhs, double tol) {
276  bool ret(true);
277  // manual way to do it... postponed. Tested with Distance method from root::math
278  //DD3Vector x1, y1, z1;
279  //lhs.GetComponents(x1,y1,z1);
280  //DD3Vector x2, y2, z2;
281  //rhs.GetComponents(x2,y2,z2);
282  double dist = Distance(lhs, rhs);
283  if (std::fabs(dist) > tol) {
284  std::cout << "Rotation matrices do not match." << std::endl;
285  ret = false;
286  DD3Vector x, y, z;
287  std::cout << "FIRST" << std::endl;
288  lhs.GetComponents(x, y, z);
289  std::cout << std::setw(12) << std::fixed << std::setprecision(4) << x.X();
290  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.X();
291  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.X();
292  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Y();
293  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Y();
294  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Y();
295  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Z();
296  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Z();
297  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Z() << std::endl;
298  std::cout << "SECOND" << std::endl;
299  rhs.GetComponents(x, y, z);
300  std::cout << std::setw(12) << std::fixed << std::setprecision(4) << x.X();
301  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.X();
302  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.X();
303  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Y();
304  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Y();
305  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Y();
306  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << x.Z();
307  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << y.Z();
308  std::cout << "," << std::setw(12) << std::fixed << std::setprecision(4) << z.Z() << std::endl;
309  }
310 
311  return ret;
312 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:367
DDSolidShapes.h
DDCompOptions::distTol_
double distTol_
Definition: DDCompareTools.h:34
DDBooleanSolid::solidB
DDSolid solidB(void) const
Definition: DDSolid.cc:468
alignBH_cfg.fixed
fixed
Definition: alignBH_cfg.py:54
mps_fire.i
i
Definition: mps_fire.py:428
DDExpandedView::firstChild
bool firstChild()
set the current node to the first child ...
Definition: DDExpandedView.cc:101
DDSolidShape::ddtrap
DDCompareEPV
bool DDCompareEPV(DDExpandedView &lhs, DDExpandedView &rhs, const DDCompOptions &ddco)
Definition: DDCompareTools.cc:17
DDSolidShape::ddtorus
detailsBasic3DVector::z
float float float z
Definition: extBasic3DVector.h:14
DDSolidShape::ddpseudotrap
DDSolidShape::ddpolyhedra_rrz
gather_cfg.cout
cout
Definition: gather_cfg.py:144
diffTwoXMLs.g1
g1
Definition: diffTwoXMLs.py:52
DDExpandedView.h
DDExpandedView::next
bool next()
set current node to the next node in the expanded tree
Definition: DDExpandedView.cc:175
DDBooleanSolid::rotation
DDRotation rotation(void) const
Definition: DDSolid.cc:462
DDCompactView.h
DDBooleanSolid
Definition: DDSolid.h:173
DDExpandedView::copyno
int copyno() const
Copy number associated with the current node.
Definition: DDExpandedView.cc:54
DDSolid::shape
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:119
DDBooleanSolid::translation
DDTranslation translation(void) const
Definition: DDSolid.cc:464
DDExpandedView::nextSibling
bool nextSibling()
set the current node to the next sibling ...
Definition: DDExpandedView.cc:61
DDTranslation
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
DDSolidShape::ddtubs
DDCompactView::graph
const Graph & graph() const
Provides read-only access to the data structure of the compact-view.
Definition: DDCompactView.cc:59
DDCompareBoolSol
bool DDCompareBoolSol(const DDBooleanSolid &lhs, const DDBooleanSolid &rhs, const DDCompOptions &ddco)
Needs to know because of Rotation Matrix of Boolean Relationship.
Definition: DDCompareTools.cc:221
DDCompOptions::compRotName_
bool compRotName_
Definition: DDCompareTools.h:31
adjl_iterator
Graph::const_adj_iterator adjl_iterator
Definition: GeometryInfoDump.cc:19
DDCompareCPV
bool DDCompareCPV(const DDCompactView &lhs, const DDCompactView &rhs, const DDCompOptions &ddco)
Definition: DDCompareTools.cc:63
DDCompactView
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
DDSolidShape::ddtrunctubs
DDSolidShape::ddpolyhedra_rz
DDBase::name
const N & name() const
Definition: DDBase.h:59
DDCompareDBLVEC
bool DDCompareDBLVEC(const std::vector< double > &lhs, const std::vector< double > &rhs, double tol)
Definition: DDCompareTools.cc:198
p2
double p2[4]
Definition: TauolaWrapper.h:90
DDCompareDDRot
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.
Definition: DDCompareTools.cc:260
DDCompareTools.h
DDExpandedView
Provides an exploded view of the detector (tree-view)
Definition: DDExpandedView.h:41
DDPosData.h
DDPosData
Relative position of a child-volume inside a parent-volume.
Definition: DDPosData.h:13
DDCompareLP
bool DDCompareLP(const DDLogicalPart &lhs, const DDLogicalPart &rhs, const DDCompOptions &ddco)
LogicalParts have solids which could be BooleanSolids.
Definition: DDCompareTools.cc:132
DDCompactView::Graph
math::Graph< DDLogicalPart, DDPosData * > Graph
Definition: DDCompactView.h:83
DD3Vector
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
Definition: PGeometricDetBuilder.cc:19
DDSolidShape::ddellipticaltube
DDSolidShape::ddsphere
DDSolidShape::ddcons
DDLogicalPart
A DDLogicalPart aggregates information concerning material, solid and sensitveness ....
Definition: DDLogicalPart.h:93
DDRotation::rotation
const DDRotationMatrix & rotation() const
Returns the read-only rotation-matrix.
Definition: DDTransform.h:81
DDName::name
const std::string & name() const
Returns the name.
Definition: DDName.cc:41
p1
double p1[4]
Definition: TauolaWrapper.h:89
DDSolidShape::dd_not_init
diffTwoXMLs.g2
g2
Definition: diffTwoXMLs.py:71
DDCompOptions
DDComparators need to know if names of DDRotation matter.
Definition: DDCompareTools.h:22
DDRotationMatrix
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
Definition: DDRotationMatrix.h:8
DDSolidShape::ddbox
math::Graph< DDLogicalPart, DDPosData * >::index_type
std::vector< double >::size_type index_type
Definition: Graph.h:15
DDName.h
DDCompareSolid
bool DDCompareSolid(const DDSolid &lhs, const DDSolid &rhs, const DDCompOptions &ddco)
Needs to know about rotmat because of BooleanSolid.
Definition: DDCompareTools.cc:147
genVertex_cff.x
x
Definition: genVertex_cff.py:12
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
DDSolid::parameters
const std::vector< double > & parameters(void) const
Give the parameters of the solid.
Definition: DDSolid.cc:121
DDSolidShape::ddextrudedpolygon
DDSolidShape::ddshapeless
DDSolid
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
DDRotation
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
DDExpandedView::logicalPart
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the expanded-view.
Definition: DDExpandedView.cc:42
DDBooleanSolid::solidA
DDSolid solidA(void) const
Definition: DDSolid.cc:466
DDSolidShape::ddcuttubs
DDSolidShape::ddpolycone_rrz
math::Graph< DDLogicalPart, DDPosData * >
DDName::fullname
const std::string fullname() const
Definition: DDName.h:40
DDCompareDDTrans
bool DDCompareDDTrans(const DDTranslation &lhs, const DDTranslation &rhs, double tol)
Definition: DDCompareTools.cc:252
DDExpandedView::depth
int depth() const
depth of the scope. 0 means unrestricted depth.
Definition: DDExpandedView.cc:52
DDCompareDDRotMat
bool DDCompareDDRotMat(const DDRotationMatrix &lhs, const DDRotationMatrix &rhs, double tol)
Definition: DDCompareTools.cc:275
DDSolidShape::ddsubtraction
DDSolidShape::ddintersection
DDExpandedView::parent
bool parent()
set the current node to the parent node ...
Definition: DDExpandedView.cc:138
DDLogicalPart::solid
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
Definition: DDLogicalPart.cc:120
DDSolidShape::ddunion
DDSolidShape::ddpolycone_rz
math::Graph< DDLogicalPart, DDPosData * >::const_adj_iterator
adj_list::const_iterator const_adj_iterator
Definition: Graph.h:105