CMS 3D CMS Logo

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