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