CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/DetectorDescription/RegressionTest/src/build.cc

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