CMS 3D CMS Logo

build.cc

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

Generated on Tue Jun 9 17:32:28 2009 for CMSSW by  doxygen 1.5.4