CMS 3D CMS Logo

build.cc
Go to the documentation of this file.
1 #include <cmath>
2 #include <iostream>
3 #include <string>
4 #include <vector>
5 
6 #include "CLHEP/Units/GlobalSystemOfUnits.h"
7 #include "CLHEP/Units/SystemOfUnits.h"
22 #include "Math/GenVector/AxisAngle.h"
23 #include "Math/GenVector/Cartesian3D.h"
24 #include "Math/GenVector/DisplacementVector3D.h"
25 #include "Math/GenVector/Rotation3D.h"
26 #include "Math/GenVector/RotationZ.h"
27 
28 using namespace std;
29 
30 /*
31 File setup.xml:
32  Material(mixt) Air
33  LogicalPart world
34  Solid world
35  Constant length
36  Constant corner
37 File elements.xml:
38  Material(elem) Nitrogen
39  Material(elem) Oxygen
40 */
43 
44  string ns = "setup"; // current namespace faking the filename 'setup.xml'
45 
46  // length of a side of world cube
47  eval.set(ns,"length","20.*m");
48 
49  // center of a corner in the cube
50  eval.set(ns,"corner","[length]/4.");
51 
52  // world-solid
53  DDName worldName("world",ns);
54  DDName airName("Air",ns);
55  DDName nitrogenName("Nitrogen","elements");
56  DDName oxygenName("Oxygen","elements");
57 
58  DDSolidFactory::box(worldName, eval.eval(ns,"[length]/2."),
59  eval.eval(ns,"[length]/2."),
60  eval.eval(ns,"[length]/2."));
61 
62  DDLogicalPart(worldName, // name
63  airName, // material
64  worldName // solid
65  );
66 
67  DDMaterial air(airName,eval.eval(ns,"1.214*mg/cm3")); // mixture for Air
68  air.addMaterial(DDMaterial(nitrogenName),eval.eval(ns,"0.75"));
69  air.addMaterial(DDMaterial(oxygenName),eval.eval(ns,"0.25"));
70 
71  cout << air << endl;
72 
73  DDMaterial(nitrogenName, // name
74  eval.eval(ns,"7"), // Z
75  eval.eval(ns,"14.007*g/mole"), // A
76  eval.eval(ns,"0.808*g/cm3") ); // density
77 
78  DDMaterial(oxygenName, // name
79  eval.eval(ns,"8"), // Z
80  eval.eval(ns,"15.999*g/mole"), // A
81  eval.eval(ns,"1.43*g/cm3") ); // density
82 
83  cout << air << endl;
84 
85  // Some rotations in the x-y plane (Unit, 30,60,90 degs)
87  DDRotationMatrix * r30 = new DDRotationMatrix(ROOT::Math::RotationZ(30.*deg));
88  DDRotationMatrix * r60 = new DDRotationMatrix(ROOT::Math::RotationZ(60.*deg));
89  DDRotationMatrix * r90 = new DDRotationMatrix(ROOT::Math::RotationZ(90.*deg));
90 
91  DDrot(DDName("Unit",ns),r0);
92  DDrot(DDName("R30",ns),r30);
93  DDrot(DDName("R60",ns),r60);
94  DDrot(DDName("R90",ns),r90);
95 
96  DDSolid collectorSolid = DDSolidFactory::shapeless(DDName("group",ns));
97 
98  DDRootDef::instance().set(worldName);
99 }
100 
102 /*
103  naming convention for the 8 corners in the world:
104  +++ (upper, +x, +y)
105  -++ (lower, +x, +y)
106  +-+ (upper, -x, +y)
107  and so on ...
108 */
109 
110 // Fills corner +++ with a hierarchy of boxes ...
111 /*
112  File: first.xml
113 
114 */
117  DDCompactView cpv;
118  cout << "main::initialize DDL parser" << endl;
119  DDLParser myP(cpv);
120 
121  cout << "main::about to set configuration" << endl;
122 
124  string ns("first");
125  DDSolid support = DDSolidFactory::box(DDName("support",ns),
126  eval.eval(ns,"[setup:corner]/4."),
127  eval.eval(ns,"[setup:corner]/8."),
128  eval.eval(ns,"[setup:corner]/4.")
129  );
130  DDSolid sensor = DDSolidFactory::box(DDName("sensor",ns),
131  eval.eval(ns,"[setup:corner]/16."),
132  eval.eval(ns,"[setup:corner]/16."),
133  eval.eval(ns,"[setup:corner]/16.")
134  );
135 
136  DDLogicalPart supportLP(DDName("support",ns), // name
137  DDName("Oxygen","elements"), // material
138  DDName("support",ns)); // solid
139 
140  DDLogicalPart sensorLP(DDName("sensor",ns),
141  DDName("Nitrogen","elements"),
142  DDName("sensor",ns));
143 
144  DDLogicalPart part(DDName("group",ns),
145  DDName("Air","setup"),
146  DDName("group","setup")
147  );
148 
149  DDRotation r30(DDName("R30","setup"));
150  DDRotation r60(DDName("R60","setup"));
151  DDRotation r90(DDName("R90","setup"));
152  DDRotation unit(DDName("Unit","setup"));
154  DDTranslation t1(eval.eval(ns,"[setup:corner]/8."),
155  eval.eval(ns,"[setup:corner]/16."),
156  eval.eval(ns,"[setup:corner]/8.")
157  );
158  DDTranslation t2(eval.eval(ns,"[setup:corner]*1.25*cos(0.)"),
159  eval.eval(ns,"[setup:corner]*1.25*sin(0.)"),
160  eval.eval(ns,"0."));
161  DDTranslation t3(eval.eval(ns,"[setup:corner]*1.25*cos(30.*deg)"),
162  eval.eval(ns,"[setup:corner]*1.25*sin(30.*deg)"),
163  eval.eval(ns,"0."));
164  DDTranslation t4(eval.eval(ns,"[setup:corner]*1.25*cos(60.*deg)"),
165  eval.eval(ns,"[setup:corner]*1.25*sin(60.*deg)"),
166  eval.eval(ns,"0."));
167  DDTranslation t5(eval.eval(ns,"[setup:corner]*1.25*cos(90.*deg)"),
168  eval.eval(ns,"[setup:corner]*1.25*sin(90.*deg)"),
169  eval.eval(ns,"0."));
170 
171  cpv.position(sensorLP, supportLP, std::string("1"), t1, unit);
172  cpv.position(supportLP, part, std::string("1"), t2, unit);
173  cpv.position(supportLP, part, std::string("2"), t3, r30);
174  cpv.position(supportLP, part, std::string("3"), t4, r60);
175  cpv.position(supportLP, part, std::string("4"), t5, r90);
176 
177  DDRotationMatrix * rm = new DDRotationMatrix(ROOT::Math::AxisAngle(DD3Vector(1.,1.,1.),20.*deg));
178  DDRotation rw= DDrot(DDName("group", ns), rm);
179  DDLogicalPart ws(DDName("world","setup"));
180  cpv.position(part, ws, std::string("1"), t0, rw);
181 }
182 
183 
184 void output(string filename)
185 {
186  ostream & os(cout);
187 
188  os << "Starting Regressiontest Output" << endl;
190  DDCompactView cpv;
191  cout << "main::initialize DDL parser" << endl;
192  DDLParser myP(cpv);
193 
194  cout << "main::about to set configuration" << endl;
195  FIPConfiguration cf(cpv);
196  cf.readConfig("DetectorDescription/RegressionTest/test/configuration.xml");
197 
198  cout << "main::about to start parsing" << endl;
199 
200  myP.parse(cf);
201 
202  cout << "main::completed Parser" << endl;
203 
204  DDExpandedView exv(cpv);
205  vector<DDTranslation> tvec;
206  bool loop=true;
207  std::cout << "Before the loop..." << std::endl;
208  while(loop) {
209  ROOT::Math::AxisAngle ra(exv.rotation());
210  os << exv.logicalPart() << endl
211  << " " << exv.logicalPart().material() << endl
212  << " " << exv.logicalPart().solid() << endl
213  << " " << exv.translation() << endl;
214  os << " " << ra.Axis() << ra.Angle()/deg << endl;
215  tvec.emplace_back(exv.translation());
216  loop = exv.next();
217  }
218 
219  vector<DDTranslation>::iterator it = tvec.begin();
220  os << endl << "center points of all solids" << endl;
221  for (; it != tvec.end(); ++it) {
222  os << (*it).x() << " " << (*it).y() << " " << (*it).z() << endl;
223  }
224 }
225 
227 {
228  try {
229  cout << "main:: initialize" << endl;
230  DDCompactView cpv;
231  cout << "main::initialize DDL parser" << endl;
232  DDLParser myP(cpv);
233 
234  cout << "main::about to set configuration" << endl;
235 
236  FIPConfiguration cf(cpv);
237  cf.readConfig("DetectorDescription/RegressionTest/test/configuration.xml");
238 
239  cout << "main::about to start parsing" << endl;
240 
241  myP.parse(cf);
242 
243  cout << "main::completed Parser" << endl;
244 
245  cout << endl << endl << "main::Start checking!" << endl << endl;
246 
247  }
248  catch (cms::Exception& e)
249  {
250  cout << "main::PROBLEM:" << endl
251  << " " << e << endl;
252  }
253 }
254 
256  std::cout << "rot asis\n" << rot << std::endl;
257  DD3Vector x,y,z;
258  rot.GetComponents(x,y,z);
259  std::cout << "components\n"
260  << x << "\n"
261  << y << "\n"
262  << z << std::endl;
263  cout << "phiX=" << x.phi() << " or in degrees = "
264  << x.phi()/deg << endl;
265  cout << "thetaX=" << x.theta() << " or in degrees = "
266  << x.theta()/deg << endl;
267  cout << "phiY=" << y.phi() << " or in degrees = "
268  << y.phi()/deg << endl;
269  cout << "thetaY=" << y.theta() << " or in degrees = "
270  << y.theta()/deg << endl;
271  cout << "phiZ=" << z.phi() << " or in degrees = "
272  << z.phi()/deg << endl;
273  cout << "thetaZ=" << z.theta() << " or in degrees = "
274  << z.theta()/deg << endl;
275 
276  cout << "some factor/equations..." << endl;
277  cout << " sin(thetaX()) * cos(phiX()) = "
278  << sin(x.theta()) * cos(x.phi()) << endl;
279 
280 }
281 
282 void testrot()
283 {
284  {
285  ROOT::Math::AxisAngle aa(DD3Vector(1.,1.,1.), 20.*deg);
286  DDRotationMatrix rm(aa);
287  cout << "DD3Vector was " << DD3Vector(1.,1.,1.) << " and the rotation was 20*deg around that axis." << endl;
288  printRot(rm);
289  }
290  {
291  DDRotationMatrix rm(1,0,0, 0,-1,0, 0,0,1);
292  cout << "(1,0,0, 0,-1,0, 0,0,1)" << endl;
293  printRot(rm);
294  }
295 }
void testParser()
Definition: build.cc:226
bool next()
set current node to the next node in the expanded tree
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
int parse(const DDLDocumentProvider &dp)
Parse all files. Return is meaningless.
Definition: DDLParser.cc:145
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:41
void testrot()
Definition: build.cc:282
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
int readConfig(const std::string &filename) override
Read in the configuration file.
type of data representation of DDCompactView
Definition: DDCompactView.h:90
void regressionTest_first()
Definition: build.cc:115
A DDSolid represents the shape of a part.
Definition: DDSolid.h:38
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:67
void printRot(const DDRotationMatrix &rot)
Definition: build.cc:255
int addMaterial(const DDMaterial &m, double fm)
adds a material to the mixture proportional to its fraction-mass fm.
Definition: DDMaterial.cc:74
T x() const
Cartesian x coordinate.
static value_type & instance()
void regressionTest_setup()
Definition: build.cc:41
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
A DD Translation is currently implemented with Root Vector3D.
Definition: DDTranslation.h:6
auto const T2 &decltype(t1.eta()) t2
Definition: deltaR.h:16
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:92
static DDSolid box(const DDName &name, double xHalf, double yHalf, double zHalf)
Creates a box with side length 2*xHalf, 2*yHalf, 2*zHalf.
Definition: DDSolid.cc:819
const DDTranslation & translation() const
The absolute translation of the current node.
DDRotation DDrot(const DDName &name, DDRotationMatrix *rot)
Definition of a uniquely identifiable rotation matrix named by DDName name.
Definition: DDRotation.cc:90
DDLParser is the main class of Detector Description Language Parser.
Definition: DDLParser.h:62
FIPConfiguration reads in the configuration file for the DDParser.
part
Definition: HCALResponse.h:20
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=0)
void output(string filename)
Definition: build.cc:184
static DDSolid shapeless(const DDName &name)
Definition: DDSolid.cc:1059
void set(const std::string &ns, const std::string &name, const std::string &exprValue)
double eval(const std::string &ns, const std::string &expr)
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the expanded-view.
rm
Definition: submit.py:76
Provides an exploded view of the detector (tree-view)
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
const DDMaterial & material(void) const
Returns a reference object of the material this LogicalPart is made of.