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 
20 #include "Math/GenVector/AxisAngle.h"
21 #include "Math/GenVector/Cartesian3D.h"
22 #include "Math/GenVector/DisplacementVector3D.h"
23 #include "Math/GenVector/Rotation3D.h"
24 #include "Math/GenVector/RotationZ.h"
25 
26 using namespace std;
27 using namespace geant_units::operators;
28 
29 /*
30 File setup.xml:
31  Material(mixt) Air
32  LogicalPart world
33  Solid world
34  Constant length
35  Constant corner
36 File elements.xml:
37  Material(elem) Nitrogen
38  Material(elem) Oxygen
39 */
41  string ns = "setup"; // current namespace faking the filename 'setup.xml'
42 
43  // length of a side of world cube
44  eval.set(ns, "length", "20.*m");
45 
46  // center of a corner in the cube
47  eval.set(ns, "corner", "[length]/4.");
48 
49  // world-solid
50  DDName worldName("world", ns);
51  DDName airName("Air", ns);
52  DDName nitrogenName("Nitrogen", "elements");
53  DDName oxygenName("Oxygen", "elements");
54 
56  worldName, eval.eval(ns, "[length]/2."), eval.eval(ns, "[length]/2."), 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)
82  std::unique_ptr<DDRotationMatrix> r0 = std::make_unique<DDRotationMatrix>();
83  std::unique_ptr<DDRotationMatrix> r30 = std::make_unique<DDRotationMatrix>(ROOT::Math::RotationZ(30._deg));
84  std::unique_ptr<DDRotationMatrix> r60 = std::make_unique<DDRotationMatrix>(ROOT::Math::RotationZ(60._deg));
85  std::unique_ptr<DDRotationMatrix> r90 = std::make_unique<DDRotationMatrix>(ROOT::Math::RotationZ(90._deg));
86 
87  DDrot(DDName("Unit", ns), std::move(r0));
88  DDrot(DDName("R30", ns), std::move(r30));
89  DDrot(DDName("R60", ns), std::move(r60));
90  DDrot(DDName("R90", ns), std::move(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  DDCompactView cpv;
114  cout << "main::initialize DDL parser" << endl;
115  DDLParser myP(cpv);
116 
117  cout << "main::about to set configuration" << endl;
118 
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  DDSolid sensor = DDSolidFactory::box(DDName("sensor", ns),
125  eval.eval(ns, "[setup:corner]/16."),
126  eval.eval(ns, "[setup:corner]/16."),
127  eval.eval(ns, "[setup:corner]/16."));
128 
129  DDLogicalPart supportLP(DDName("support", ns), // name
130  DDName("Oxygen", "elements"), // material
131  DDName("support", ns)); // solid
132 
133  DDLogicalPart sensorLP(DDName("sensor", ns), DDName("Nitrogen", "elements"), DDName("sensor", ns));
134 
135  DDLogicalPart part(DDName("group", ns), DDName("Air", "setup"), DDName("group", "setup"));
136 
137  DDRotation r30(DDName("R30", "setup"));
138  DDRotation r60(DDName("R60", "setup"));
139  DDRotation r90(DDName("R90", "setup"));
140  DDRotation unit(DDName("Unit", "setup"));
143  eval.eval(ns, "[setup:corner]/8."), eval.eval(ns, "[setup:corner]/16."), eval.eval(ns, "[setup:corner]/8."));
145  eval.eval(ns, "[setup:corner]*1.25*cos(0.)"), eval.eval(ns, "[setup:corner]*1.25*sin(0.)"), eval.eval(ns, "0."));
146  DDTranslation t3(eval.eval(ns, "[setup:corner]*1.25*cos(30.*deg)"),
147  eval.eval(ns, "[setup:corner]*1.25*sin(30.*deg)"),
148  eval.eval(ns, "0."));
149  DDTranslation t4(eval.eval(ns, "[setup:corner]*1.25*cos(60.*deg)"),
150  eval.eval(ns, "[setup:corner]*1.25*sin(60.*deg)"),
151  eval.eval(ns, "0."));
152  DDTranslation t5(eval.eval(ns, "[setup:corner]*1.25*cos(90.*deg)"),
153  eval.eval(ns, "[setup:corner]*1.25*sin(90.*deg)"),
154  eval.eval(ns, "0."));
155 
156  cpv.position(sensorLP, supportLP, std::string("1"), t1, unit);
157  cpv.position(supportLP, part, std::string("1"), t2, unit);
158  cpv.position(supportLP, part, std::string("2"), t3, r30);
159  cpv.position(supportLP, part, std::string("3"), t4, r60);
160  cpv.position(supportLP, part, std::string("4"), t5, r90);
161 
162  std::unique_ptr<DDRotationMatrix> rm =
163  std::make_unique<DDRotationMatrix>(ROOT::Math::AxisAngle(DD3Vector(1., 1., 1.), 20._deg));
164  DDRotation rw = DDrot(DDName("group", ns), std::move(rm));
165  DDLogicalPart ws(DDName("world", "setup"));
166  cpv.position(part, ws, std::string("1"), t0, rw);
167 }
168 
169 void output(string filename) {
170  ostream& os(cout);
171 
172  os << "Starting Regressiontest Output" << endl;
174  DDCompactView cpv;
175  cout << "main::initialize DDL parser" << endl;
176  DDLParser myP(cpv);
177 
178  cout << "main::about to set configuration" << endl;
179  FIPConfiguration cf(cpv);
180  cf.readConfig("DetectorDescription/RegressionTest/test/configuration.xml");
181 
182  cout << "main::about to start parsing" << endl;
183 
184  myP.parse(cf);
185 
186  cout << "main::completed Parser" << endl;
187 
188  DDExpandedView exv(cpv);
189  vector<DDTranslation> tvec;
190  bool loop = true;
191  std::cout << "Before the loop..." << std::endl;
192  while (loop) {
193  ROOT::Math::AxisAngle ra(exv.rotation());
194  os << exv.logicalPart() << endl
195  << " " << exv.logicalPart().material() << endl
196  << " " << exv.logicalPart().solid() << endl
197  << " " << exv.translation() << endl;
198  os << " " << ra.Axis() << convertRadToDeg(ra.Angle()) << endl;
199  tvec.emplace_back(exv.translation());
200  loop = exv.next();
201  }
202 
203  vector<DDTranslation>::iterator it = tvec.begin();
204  os << endl << "center points of all solids" << endl;
205  for (; it != tvec.end(); ++it) {
206  os << (*it).x() << " " << (*it).y() << " " << (*it).z() << endl;
207  }
208 }
209 
210 void testParser() {
211  try {
212  cout << "main:: initialize" << endl;
213  DDCompactView cpv;
214  cout << "main::initialize DDL parser" << endl;
215  DDLParser myP(cpv);
216 
217  cout << "main::about to set configuration" << endl;
218 
219  FIPConfiguration cf(cpv);
220  cf.readConfig("DetectorDescription/RegressionTest/test/configuration.xml");
221 
222  cout << "main::about to start parsing" << endl;
223 
224  myP.parse(cf);
225 
226  cout << "main::completed Parser" << endl;
227 
228  cout << endl << endl << "main::Start checking!" << endl << endl;
229 
230  } catch (cms::Exception& e) {
231  cout << "main::PROBLEM:" << endl << " " << e << endl;
232  }
233 }
234 
236  std::cout << "rot asis\n" << rot << std::endl;
237  DD3Vector x, y, z;
238  rot.GetComponents(x, y, z);
239  std::cout << "components\n" << x << "\n" << y << "\n" << z << std::endl;
240  cout << "phiX=" << x.phi() << " or in degrees = " << convertRadToDeg(x.phi()) << endl;
241  cout << "thetaX=" << x.theta() << " or in degrees = " << convertRadToDeg(x.theta()) << endl;
242  cout << "phiY=" << y.phi() << " or in degrees = " << convertRadToDeg(y.phi()) << endl;
243  cout << "thetaY=" << y.theta() << " or in degrees = " << convertRadToDeg(y.theta()) << endl;
244  cout << "phiZ=" << z.phi() << " or in degrees = " << convertRadToDeg(z.phi()) << endl;
245  cout << "thetaZ=" << z.theta() << " or in degrees = " << convertRadToDeg(z.theta()) << endl;
246 
247  cout << "some factor/equations..." << endl;
248  cout << " sin(thetaX()) * cos(phiX()) = " << sin(x.theta()) * cos(x.phi()) << endl;
249 }
250 
251 void testrot() {
252  {
253  ROOT::Math::AxisAngle aa(DD3Vector(1., 1., 1.), 20._deg);
254  DDRotationMatrix rm(aa);
255  cout << "DD3Vector was " << DD3Vector(1., 1., 1.) << " and the rotation was 20*deg around that axis." << endl;
256  printRot(rm);
257  }
258  {
259  DDRotationMatrix rm(1, 0, 0, 0, -1, 0, 0, 0, 1);
260  cout << "(1,0,0, 0,-1,0, 0,0,1)" << endl;
261  printRot(rm);
262  }
263 }
RandomServiceHelper.t2
t2
Definition: RandomServiceHelper.py:257
DDTransform.h
DDrot
DDRotation DDrot(const DDName &name, std::unique_ptr< DDRotationMatrix > rot)
Definition of a uniquely identifiable rotation matrix named by DDName name.
Definition: DDRotation.cc:67
DDExpandedView::rotation
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
Definition: DDExpandedView.cc:47
regressionTest_setup
void regressionTest_setup(ClhepEvaluator &eval)
Definition: build.cc:40
DDLParser::parse
int parse(const DDLDocumentProvider &dp)
Parse all files. Return is meaningless.
Definition: DDLParser.cc:123
DDName
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
angle_units::operators::convertRadToDeg
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
gather_cfg.cout
cout
Definition: gather_cfg.py:144
DDLogicalPart::material
const DDMaterial & material(void) const
Returns a reference object of the material this LogicalPart is made of.
Definition: DDLogicalPart.cc:118
testParser
void testParser()
Definition: build.cc:210
DDExpandedView::next
bool next()
set current node to the next node in the expanded tree
Definition: DDExpandedView.cc:174
ClhepEvaluator
Definition: ClhepEvaluator.h:8
DDLParser.h
geant_units::operators
Definition: GeantUnits.h:18
DDCompactView.h
DDRotationMatrix
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
Definition: DDRotationMatrix.h:8
DD3Vector
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
A DD Translation is currently implemented with Root Vector3D.
Definition: DDTranslation.h:6
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
DDMaterial
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:45
part
part
Definition: HCALResponse.h:20
RandomServiceHelper.t1
t1
Definition: RandomServiceHelper.py:256
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
FrontierCondition_GT_autoExpress_cfi.t0
t0
Definition: FrontierCondition_GT_autoExpress_cfi.py:148
DDTranslation
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
output
void output(string filename)
Definition: build.cc:169
DDCompactView
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
DDSolid.h
submit.rm
rm
Definition: submit.py:77
DDExpandedView
Provides an exploded view of the detector (tree-view)
Definition: DDExpandedView.h:41
RandomServiceHelper.t3
t3
Definition: RandomServiceHelper.py:258
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DDI::Singleton::instance
static value_type & instance()
GeantUnits.h
heppy_loop.loop
loop
Definition: heppy_loop.py:28
DDLParser
DDLParser is the main class of Detector Description Language Parser.
Definition: DDLParser.h:63
DDLogicalPart
A DDLogicalPart aggregates information concerning material, solid and sensitveness ....
Definition: DDLogicalPart.h:93
DDMaterial.h
printRot
void printRot(const DDRotationMatrix &rot)
Definition: build.cc:235
DDTranslation.h
DDLogicalPart.h
DDSolidFactory::shapeless
static DDSolid shapeless(const DDName &name)
Definition: DDSolid.cc:688
unit
Basic3DVector unit() const
Definition: Basic3DVectorLD.h:162
DDExpandedView.h
FIPConfiguration::readConfig
int readConfig(const std::string &filename) override
Read in the configuration file.
Definition: FIPConfiguration.cc:71
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
ClhepEvaluator::set
void set(const std::string &ns, const std::string &name, const std::string &exprValue)
Definition: ClhepEvaluator.cc:42
DDRoot.h
DDName.h
testrot
void testrot()
Definition: build.cc:251
makeMuonMisalignmentScenario.rot
rot
Definition: makeMuonMisalignmentScenario.py:322
DDSolid
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
DDRotation
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
DDExpandedView::logicalPart
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the expanded-view.
Definition: DDExpandedView.cc:41
Exception.h
FIPConfiguration.h
cms::Exception
Definition: Exception.h:70
FIPConfiguration
FIPConfiguration reads in the configuration file for the DDParser.
Definition: FIPConfiguration.h:27
regressionTest_first
void regressionTest_first(ClhepEvaluator &eval)
Definition: build.cc:111
DDExpandedView::translation
const DDTranslation & translation() const
The absolute translation of the current node.
Definition: DDExpandedView.cc:45
ClhepEvaluator::eval
double eval(const std::string &ns, const std::string &expr)
Definition: ClhepEvaluator.cc:85
DDSolidFactory::box
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:533
DDMaterial::addMaterial
int addMaterial(const DDMaterial &m, double fm)
adds a material to the mixture proportional to its fraction-mass fm.
Definition: DDMaterial.cc:63
DDLogicalPart::solid
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
Definition: DDLogicalPart.cc:120
DDCompactView::position
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=nullptr)
Definition: DDCompactView.cc:66
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
DDRotationMatrix.h