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>
10 
13 #include "CLHEP/Units/GlobalSystemOfUnits.h"
14 
20 
22 
23 #include <Math/RotationZ.h>
24 #include <Math/AxisAngle.h>
25 
26 /*
27 File setup.xml:
28  Material(mixt) Air
29  LogicalPart world
30  Solid world
31  Constant length
32  Constant corner
33 File elements.xml:
34  Material(elem) Nitrogen
35  Material(elem) Oxygen
36 */
39 
40  string ns = "setup"; // current namespace faking the filename 'setup.xml'
41 
42  // length of a side of world cube
43  eval.set(ns,"length","20.*m");
44 
45  // center of a corner in the cube
46  eval.set(ns,"corner","[length]/4.");
47 
48  // world-solid
49  DDName worldName("world",ns);
50  DDName airName("Air",ns);
51  DDName nitrogenName("Nitrogen","elements");
52  DDName oxygenName("Oxygen","elements");
53 
54  DDSolidFactory::box(worldName, eval.eval(ns,"[length]/2."),
55  eval.eval(ns,"[length]/2."),
56  eval.eval(ns,"[length]/2."));
57 
58  DDLogicalPart(worldName, // name
59  airName, // material
60  worldName // solid
61  );
62 
63  DDMaterial air(airName,eval.eval(ns,"1.214*mg/cm3")); // mixture for Air
64  air.addMaterial(DDMaterial(nitrogenName),eval.eval(ns,"0.75"));
65  air.addMaterial(DDMaterial(oxygenName),eval.eval(ns,"0.25"));
66 
67  cout << air << endl;
68 
69  DDMaterial(nitrogenName, // name
70  eval.eval(ns,"7"), // Z
71  eval.eval(ns,"14.007*g/mole"), // A
72  eval.eval(ns,"0.808*g/cm3") ); // density
73 
74  DDMaterial(oxygenName, // name
75  eval.eval(ns,"8"), // Z
76  eval.eval(ns,"15.999*g/mole"), // A
77  eval.eval(ns,"1.43*g/cm3") ); // density
78 
79  cout << air << endl;
80 
81  // Some rotations in the x-y plane (Unit, 30,60,90 degs)
83  DDRotationMatrix * r30 = new DDRotationMatrix(ROOT::Math::RotationZ(30.*deg));
84  DDRotationMatrix * r60 = new DDRotationMatrix(ROOT::Math::RotationZ(60.*deg));
85  DDRotationMatrix * r90 = new DDRotationMatrix(ROOT::Math::RotationZ(90.*deg));
86 
87  DDrot(DDName("Unit",ns),r0);
88  DDrot(DDName("R30",ns),r30);
89  DDrot(DDName("R60",ns),r60);
90  DDrot(DDName("R90",ns),r90);
91 
92  DDSolid collectorSolid = DDSolidFactory::shapeless(DDName("group",ns));
93 
94  DDRootDef::instance().set(worldName);
95 }
96 
98 /*
99  naming convention for the 8 corners in the world:
100  +++ (upper, +x, +y)
101  -++ (lower, +x, +y)
102  +-+ (upper, -x, +y)
103  and so on ...
104 */
105 
106 // Fills corner +++ with a hierarchy of boxes ...
107 /*
108  File: first.xml
109 
110 */
113  AlgoInit();
114  DDCompactView cpv;
115  cout << "main::initialize DDL parser" << endl;
116  DDLParser myP(cpv);// = DDLParser::instance();
117 
118  cout << "main::about to set configuration" << endl;
119 
121  string ns("first");
122  DDSolid support = DDSolidFactory::box(DDName("support",ns),
123  eval.eval(ns,"[setup:corner]/4."),
124  eval.eval(ns,"[setup:corner]/8."),
125  eval.eval(ns,"[setup:corner]/4.")
126  );
127  DDSolid sensor = DDSolidFactory::box(DDName("sensor",ns),
128  eval.eval(ns,"[setup:corner]/16."),
129  eval.eval(ns,"[setup:corner]/16."),
130  eval.eval(ns,"[setup:corner]/16.")
131  );
132 
133  DDLogicalPart supportLP(DDName("support",ns), // name
134  DDName("Oxygen","elements"), // material
135  DDName("support",ns)); // solid
136 
137  DDLogicalPart sensorLP(DDName("sensor",ns),
138  DDName("Nitrogen","elements"),
139  DDName("sensor",ns));
140 
141  DDLogicalPart part(DDName("group",ns),
142  DDName("Air","setup"),
143  DDName("group","setup")
144  );
145 
146  DDRotation r30(DDName("R30","setup"));
147  DDRotation r60(DDName("R60","setup"));
148  DDRotation r90(DDName("R90","setup"));
149  DDRotation unit(DDName("Unit","setup"));
150  DDTranslation t0;
151  DDTranslation t1(eval.eval(ns,"[setup:corner]/8."),
152  eval.eval(ns,"[setup:corner]/16."),
153  eval.eval(ns,"[setup:corner]/8.")
154  );
155  DDTranslation t2(eval.eval(ns,"[setup:corner]*1.25*cos(0.)"),
156  eval.eval(ns,"[setup:corner]*1.25*sin(0.)"),
157  eval.eval(ns,"0."));
158  DDTranslation t3(eval.eval(ns,"[setup:corner]*1.25*cos(30.*deg)"),
159  eval.eval(ns,"[setup:corner]*1.25*sin(30.*deg)"),
160  eval.eval(ns,"0."));
161  DDTranslation t4(eval.eval(ns,"[setup:corner]*1.25*cos(60.*deg)"),
162  eval.eval(ns,"[setup:corner]*1.25*sin(60.*deg)"),
163  eval.eval(ns,"0."));
164  DDTranslation t5(eval.eval(ns,"[setup:corner]*1.25*cos(90.*deg)"),
165  eval.eval(ns,"[setup:corner]*1.25*sin(90.*deg)"),
166  eval.eval(ns,"0."));
167 
168  cpv.position(sensorLP, supportLP, std::string("1"), t1, unit);
169  cpv.position(supportLP, part, std::string("1"), t2, unit);
170  cpv.position(supportLP, part, std::string("2"), t3, r30);
171  cpv.position(supportLP, part, std::string("3"), t4, r60);
172  cpv.position(supportLP, part, std::string("4"), t5, r90);
173 
174  DDRotationMatrix * rm = new DDRotationMatrix(ROOT::Math::AxisAngle(DD3Vector(1.,1.,1.),20.*deg));
175  DDRotation rw= DDrot(DDName("group", ns), rm);
176  DDLogicalPart ws(DDName("world","setup"));
177  cpv.position(part, ws, std::string("1"), t0, rw);
178 }
179 
180 
181 void output(string filename)
182 {
183  ostream & os(cout);
184 
185  os << "Starting Regressiontest Output" << endl;
187  AlgoInit();
188  DDCompactView cpv;
189  cout << "main::initialize DDL parser" << endl;
190  DDLParser myP(cpv);// = DDLParser::instance();
191 
192  cout << "main::about to set configuration" << endl;
193  // myP->SetConfig("configuration.xml");
194  FIPConfiguration cf(cpv);
195  cf.readConfig("DetectorDescription/RegressionTest/test/configuration.xml");
196 
197  cout << "main::about to start parsing" << endl;
198 
199  myP.parse(cf);
200 
201  cout << "main::completed Parser" << endl;
202 
203  DDExpandedView exv(cpv);
204  vector<DDTranslation> tvec;
205  bool loop=true;
206  std::cout << "Before the loop..." << std::endl;
207  while(loop) {
208  ROOT::Math::AxisAngle ra(exv.rotation());
209  os << exv.logicalPart() << endl
210  << " " << exv.logicalPart().material() << endl
211  << " " << exv.logicalPart().solid() << endl
212  << " " << exv.translation() << endl;
213  os << " " << ra.Axis() << ra.Angle()/deg << endl;
214  tvec.push_back(exv.translation());
215  loop = exv.next();
216  }
217 
218  vector<DDTranslation>::iterator it = tvec.begin();
219  os << endl << "center points of all solids" << endl;
220  for (; it != tvec.end(); ++it) {
221  os << (*it).x() << " " << (*it).y() << " " << (*it).z() << endl;
222  }
223 }
224 
226 {
227  try {
228  cout << "main:: initialize" << endl;
229  AlgoInit();
230  DDCompactView cpv;
231  cout << "main::initialize DDL parser" << endl;
232  DDLParser myP(cpv);// = DDLParser::instance();
233 
234  cout << "main::about to set configuration" << endl;
235  // myP->SetConfig("configuration.xml");
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; const_cast<DDRotationMatrix &>(rot).GetComponents(x,y,z);
258  std::cout << "components\n"
259  << x << "\n"
260  << y << "\n"
261  << z << std::endl;
262  cout << "phiX=" << x.phi() << " or in degrees = "
263  << x.phi()/deg << endl;
264  cout << "thetaX=" << x.theta() << " or in degrees = "
265  << x.theta()/deg << endl;
266  cout << "phiY=" << y.phi() << " or in degrees = "
267  << y.phi()/deg << endl;
268  cout << "thetaY=" << y.theta() << " or in degrees = "
269  << y.theta()/deg << endl;
270  cout << "phiZ=" << z.phi() << " or in degrees = "
271  << z.phi()/deg << endl;
272  cout << "thetaZ=" << z.theta() << " or in degrees = "
273  << z.theta()/deg << endl;
274 
275  cout << "some factor/equations..." << endl;
276  cout << " sin(thetaX()) * cos(phiX()) = "
277  << sin(x.theta()) * cos(x.phi()) << endl;
278 
279 }
280 
281 void testrot()
282 {
283  // ExprEvalInterface & eval = ExprEval::instance();
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:225
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:222
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:41
void testrot()
Definition: build.cc:281
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
virtual void set(const std::string &ns, const std::string &name, const std::string &valueExpr)=0
put a new variable named &#39;namespace:name&#39; into the dictionary of the evaluator
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
double double double z
void regressionTest_first()
Definition: build.cc:111
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:255
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:37
void AlgoInit()
Definition: AlgoInit.cc:13
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
A DD Translation is currently implemented with Root Vector3D.
Definition: DDTranslation.h:6
string unit
Definition: csvLumiCalc.py:46
string rm
Definition: submit.py:76
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Interface of an Expression Evaluator.
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:93
DDLParser is the main class of Detector Description Language Parser.
Definition: DDLParser.h:64
virtual double eval(const std::string &ns, const std::string &expr)=0
evaluate an expression expr inside the local namespace
FIPConfiguration reads in the configuration file for the DDParser.
part
Definition: HCALResponse.h:21
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
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.