CMS 3D CMS Logo

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