00001 using namespace std;
00002
00003 #include <cmath>
00004 #include <iostream>
00005 #include <fstream>
00006 #include <vector>
00007 #include "DetectorDescription/Parser/interface/DDLParser.h"
00008 #include "DetectorDescription/Parser/interface/FIPConfiguration.h"
00009 #include "DetectorDescription/Algorithm/src/AlgoInit.h"
00010
00011 #include "DetectorDescription/Core/interface/DDCompactView.h"
00012 #include "DetectorDescription/Core/interface/DDExpandedView.h"
00013 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00014
00015 #include "DetectorDescription/Core/interface/DDRoot.h"
00016 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00017 #include "DetectorDescription/Core/interface/DDMaterial.h"
00018 #include "DetectorDescription/Core/interface/DDSolid.h"
00019 #include "DetectorDescription/Core/interface/DDTransform.h"
00020 #include "DetectorDescription/Core/interface/DDCompactView.h"
00021
00022 #include "DetectorDescription/ExprAlgo/interface/ExprEvalSingleton.h"
00023
00024 #include <Math/RotationZ.h>
00025 #include <Math/AxisAngle.h>
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 void regressionTest_setup() {
00039 ExprEvalInterface & eval = ExprEval::instance();
00040
00041 string ns = "setup";
00042
00043
00044 eval.set(ns,"length","20.*m");
00045
00046
00047 eval.set(ns,"corner","[length]/4.");
00048
00049
00050 DDName worldName("world",ns);
00051 DDName airName("Air",ns);
00052 DDName nitrogenName("Nitrogen","elements");
00053 DDName oxygenName("Oxygen","elements");
00054
00055 DDSolidFactory::box(worldName, eval.eval(ns,"[length]/2."),
00056 eval.eval(ns,"[length]/2."),
00057 eval.eval(ns,"[length]/2."));
00058
00059 DDLogicalPart(worldName,
00060 airName,
00061 worldName
00062 );
00063
00064 DDMaterial air(airName,eval.eval(ns,"1.214*mg/cm3"));
00065 air.addMaterial(DDMaterial(nitrogenName),eval.eval(ns,"0.75"));
00066 air.addMaterial(DDMaterial(oxygenName),eval.eval(ns,"0.25"));
00067
00068 cout << air << endl;
00069
00070 DDMaterial(nitrogenName,
00071 eval.eval(ns,"7"),
00072 eval.eval(ns,"14.007*g/mole"),
00073 eval.eval(ns,"0.808*g/cm3") );
00074
00075 DDMaterial(oxygenName,
00076 eval.eval(ns,"8"),
00077 eval.eval(ns,"15.999*g/mole"),
00078 eval.eval(ns,"1.43*g/cm3") );
00079
00080 cout << air << endl;
00081
00082
00083 DDRotationMatrix * r0 = new DDRotationMatrix();
00084 DDRotationMatrix * r30 = new DDRotationMatrix(ROOT::Math::RotationZ(30.*deg));
00085 DDRotationMatrix * r60 = new DDRotationMatrix(ROOT::Math::RotationZ(60.*deg));
00086 DDRotationMatrix * r90 = new DDRotationMatrix(ROOT::Math::RotationZ(90.*deg));
00087
00088 DDrot(DDName("Unit",ns),r0);
00089 DDrot(DDName("R30",ns),r30);
00090 DDrot(DDName("R60",ns),r60);
00091 DDrot(DDName("R90",ns),r90);
00092
00093 DDSolid collectorSolid = DDSolidFactory::shapeless(DDName("group",ns));
00094
00095 DDRootDef::instance().set(worldName);
00096 }
00097
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 void regressionTest_first( ) {
00114 AlgoInit();
00115 DDCompactView cpv;
00116 cout << "main::initialize DDL parser" << endl;
00117 DDLParser myP(cpv);
00118
00119 cout << "main::about to set configuration" << endl;
00120
00121 ExprEvalInterface & eval = ExprEval::instance();
00122 string ns("first");
00123 DDSolid support = DDSolidFactory::box(DDName("support",ns),
00124 eval.eval(ns,"[setup:corner]/4."),
00125 eval.eval(ns,"[setup:corner]/8."),
00126 eval.eval(ns,"[setup:corner]/4.")
00127 );
00128 DDSolid sensor = DDSolidFactory::box(DDName("sensor",ns),
00129 eval.eval(ns,"[setup:corner]/16."),
00130 eval.eval(ns,"[setup:corner]/16."),
00131 eval.eval(ns,"[setup:corner]/16.")
00132 );
00133
00134 DDLogicalPart supportLP(DDName("support",ns),
00135 DDName("Oxygen","elements"),
00136 DDName("support",ns));
00137
00138 DDLogicalPart sensorLP(DDName("sensor",ns),
00139 DDName("Nitrogen","elements"),
00140 DDName("sensor",ns));
00141
00142 DDLogicalPart part(DDName("group",ns),
00143 DDName("Air","setup"),
00144 DDName("group","setup")
00145 );
00146
00147 DDRotation r30(DDName("R30","setup"));
00148 DDRotation r60(DDName("R60","setup"));
00149 DDRotation r90(DDName("R90","setup"));
00150 DDRotation unit(DDName("Unit","setup"));
00151 DDTranslation t0;
00152 DDTranslation t1(eval.eval(ns,"[setup:corner]/8."),
00153 eval.eval(ns,"[setup:corner]/16."),
00154 eval.eval(ns,"[setup:corner]/8.")
00155 );
00156 DDTranslation t2(eval.eval(ns,"[setup:corner]*1.25*cos(0.)"),
00157 eval.eval(ns,"[setup:corner]*1.25*sin(0.)"),
00158 eval.eval(ns,"0."));
00159 DDTranslation t3(eval.eval(ns,"[setup:corner]*1.25*cos(30.*deg)"),
00160 eval.eval(ns,"[setup:corner]*1.25*sin(30.*deg)"),
00161 eval.eval(ns,"0."));
00162 DDTranslation t4(eval.eval(ns,"[setup:corner]*1.25*cos(60.*deg)"),
00163 eval.eval(ns,"[setup:corner]*1.25*sin(60.*deg)"),
00164 eval.eval(ns,"0."));
00165 DDTranslation t5(eval.eval(ns,"[setup:corner]*1.25*cos(90.*deg)"),
00166 eval.eval(ns,"[setup:corner]*1.25*sin(90.*deg)"),
00167 eval.eval(ns,"0."));
00168
00169 cpv.position(sensorLP, supportLP, std::string("1"), t1, unit);
00170 cpv.position(supportLP, part, std::string("1"), t2, unit);
00171 cpv.position(supportLP, part, std::string("2"), t3, r30);
00172 cpv.position(supportLP, part, std::string("3"), t4, r60);
00173 cpv.position(supportLP, part, std::string("4"), t5, r90);
00174
00175 DDRotationMatrix * rm = new DDRotationMatrix(ROOT::Math::AxisAngle(DD3Vector(1.,1.,1.),20.*deg));
00176 DDRotation rw= DDrot(DDName("group", ns), rm);
00177 DDLogicalPart ws(DDName("world","setup"));
00178 cpv.position(part, ws, std::string("1"), t0, rw);
00179 }
00180
00181
00182 void output(string filename)
00183 {
00184 ostream & os(cout);
00185
00186 os << "Starting Regressiontest Output" << endl;
00188 AlgoInit();
00189 DDCompactView cpv;
00190 cout << "main::initialize DDL parser" << endl;
00191 DDLParser myP(cpv);
00192
00193 cout << "main::about to set configuration" << endl;
00194
00195 FIPConfiguration cf(cpv);
00196 cf.readConfig("DetectorDescription/RegressionTest/test/configuration.xml");
00197
00198 cout << "main::about to start parsing" << endl;
00199
00200 myP.parse(cf);
00201
00202 cout << "main::completed Parser" << endl;
00203
00204 DDExpandedView exv(cpv);
00205 vector<DDTranslation> tvec;
00206 bool loop=true;
00207 std::cout << "Before the loop..." << std::endl;
00208 while(loop) {
00209 ROOT::Math::AxisAngle ra(exv.rotation());
00210 os << exv.logicalPart() << endl
00211 << " " << exv.logicalPart().material() << endl
00212 << " " << exv.logicalPart().solid() << endl
00213 << " " << exv.translation() << endl;
00214 os << " " << ra.Axis() << ra.Angle()/deg << endl;
00215 tvec.push_back(exv.translation());
00216 loop = exv.next();
00217 }
00218
00219 vector<DDTranslation>::iterator it = tvec.begin();
00220 os << endl << "center points of all solids" << endl;
00221 for (; it != tvec.end(); ++it) {
00222 os << (*it).x() << " " << (*it).y() << " " << (*it).z() << endl;
00223 }
00224 }
00225
00226 void testParser()
00227 {
00228 try {
00229 cout << "main:: initialize" << endl;
00230 AlgoInit();
00231 DDCompactView cpv;
00232 cout << "main::initialize DDL parser" << endl;
00233 DDLParser myP(cpv);
00234
00235 cout << "main::about to set configuration" << endl;
00236
00237 FIPConfiguration cf(cpv);
00238 cf.readConfig("DetectorDescription/RegressionTest/test/configuration.xml");
00239
00240 cout << "main::about to start parsing" << endl;
00241
00242 myP.parse(cf);
00243
00244 cout << "main::completed Parser" << endl;
00245
00246 cout << endl << endl << "main::Start checking!" << endl << endl;
00247
00248 }
00249 catch (DDException& e)
00250 {
00251 cout << "main::PROBLEM:" << endl
00252 << " " << e << endl;
00253 }
00254 }
00255
00256 void printRot(const DDRotationMatrix & rot) {
00257 std::cout << "rot asis\n" << rot << std::endl;
00258 DD3Vector x,y,z; const_cast<DDRotationMatrix &>(rot).GetComponents(x,y,z);
00259 std::cout << "components\n"
00260 << x << "\n"
00261 << y << "\n"
00262 << z << std::endl;
00263 cout << "phiX=" << x.phi() << " or in degrees = "
00264 << x.phi()/deg << endl;
00265 cout << "thetaX=" << x.theta() << " or in degrees = "
00266 << x.theta()/deg << endl;
00267 cout << "phiY=" << y.phi() << " or in degrees = "
00268 << y.phi()/deg << endl;
00269 cout << "thetaY=" << y.theta() << " or in degrees = "
00270 << y.theta()/deg << endl;
00271 cout << "phiZ=" << z.phi() << " or in degrees = "
00272 << z.phi()/deg << endl;
00273 cout << "thetaZ=" << z.theta() << " or in degrees = "
00274 << z.theta()/deg << endl;
00275
00276 cout << "some factor/equations..." << endl;
00277 cout << " sin(thetaX()) * cos(phiX()) = "
00278 << sin(x.theta()) * cos(x.phi()) << endl;
00279
00280 }
00281
00282 void testrot()
00283 {
00284
00285 {
00286 ROOT::Math::AxisAngle aa(DD3Vector(1.,1.,1.), 20.*deg);
00287 DDRotationMatrix rm(aa);
00288 cout << "DD3Vector was " << DD3Vector(1.,1.,1.) << " and the rotation was 20*deg around that axis." << endl;
00289 printRot(rm);
00290 }
00291 {
00292 DDRotationMatrix rm(1,0,0, 0,-1,0, 0,0,1);
00293 cout << "(1,0,0, 0,-1,0, 0,0,1)" << endl;
00294 printRot(rm);
00295 }
00296 }