Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:55:09

0001 #include <cmath>
0002 #include <iostream>
0003 #include <string>
0004 #include <vector>
0005 
0006 #include "DetectorDescription/Core/interface/DDRotationMatrix.h"
0007 #include "DetectorDescription/Core/interface/DDTranslation.h"
0008 #include "DetectorDescription/Core/interface/DDCompactView.h"
0009 #include "DetectorDescription/Core/interface/DDExpandedView.h"
0010 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0011 #include "DetectorDescription/Core/interface/DDMaterial.h"
0012 #include "DetectorDescription/Core/interface/DDName.h"
0013 #include "DetectorDescription/Core/interface/DDRoot.h"
0014 #include "DetectorDescription/Core/interface/DDSolid.h"
0015 #include "DetectorDescription/Core/interface/DDTransform.h"
0016 #include "DataFormats/Math/interface/GeantUnits.h"
0017 #include "DetectorDescription/Parser/interface/DDLParser.h"
0018 #include "DetectorDescription/Parser/interface/FIPConfiguration.h"
0019 #include "FWCore/Utilities/interface/Exception.h"
0020 #include "Math/GenVector/AxisAngle.h"
0021 #include "Math/GenVector/Cartesian3D.h"
0022 #include "Math/GenVector/DisplacementVector3D.h"
0023 #include "Math/GenVector/Rotation3D.h"
0024 #include "Math/GenVector/RotationZ.h"
0025 
0026 using namespace std;
0027 using namespace geant_units::operators;
0028 
0029 /*
0030 File setup.xml:
0031   Material(mixt) Air
0032   LogicalPart world
0033   Solid world
0034   Constant length
0035   Constant corner
0036 File elements.xml:
0037   Material(elem) Nitrogen
0038   Material(elem) Oxygen  
0039 */
0040 void regressionTest_setup(ClhepEvaluator& eval) {
0041   string ns = "setup";  // current namespace faking the filename 'setup.xml'
0042 
0043   // length of a side of  world cube
0044   eval.set(ns, "length", "20.*m");
0045 
0046   // center of a corner in the cube
0047   eval.set(ns, "corner", "[length]/4.");
0048 
0049   // world-solid
0050   DDName worldName("world", ns);
0051   DDName airName("Air", ns);
0052   DDName nitrogenName("Nitrogen", "elements");
0053   DDName oxygenName("Oxygen", "elements");
0054 
0055   DDSolidFactory::box(
0056       worldName, eval.eval(ns, "[length]/2."), eval.eval(ns, "[length]/2."), eval.eval(ns, "[length]/2."));
0057 
0058   DDLogicalPart(worldName,  // name
0059                 airName,    // material
0060                 worldName   // solid
0061   );
0062 
0063   DDMaterial air(airName, eval.eval(ns, "1.214*mg/cm3"));  // mixture for Air
0064   air.addMaterial(DDMaterial(nitrogenName), eval.eval(ns, "0.75"));
0065   air.addMaterial(DDMaterial(oxygenName), eval.eval(ns, "0.25"));
0066 
0067   cout << air << endl;
0068 
0069   DDMaterial(nitrogenName,                    // name
0070              eval.eval(ns, "7"),              // Z
0071              eval.eval(ns, "14.007*g/mole"),  // A
0072              eval.eval(ns, "0.808*g/cm3"));   // density
0073 
0074   DDMaterial(oxygenName,                      // name
0075              eval.eval(ns, "8"),              // Z
0076              eval.eval(ns, "15.999*g/mole"),  // A
0077              eval.eval(ns, "1.43*g/cm3"));    // density
0078 
0079   cout << air << endl;
0080 
0081   // Some rotations in the x-y plane (Unit, 30,60,90 degs)
0082   std::unique_ptr<DDRotationMatrix> r0 = std::make_unique<DDRotationMatrix>();
0083   std::unique_ptr<DDRotationMatrix> r30 = std::make_unique<DDRotationMatrix>(ROOT::Math::RotationZ(30._deg));
0084   std::unique_ptr<DDRotationMatrix> r60 = std::make_unique<DDRotationMatrix>(ROOT::Math::RotationZ(60._deg));
0085   std::unique_ptr<DDRotationMatrix> r90 = std::make_unique<DDRotationMatrix>(ROOT::Math::RotationZ(90._deg));
0086 
0087   DDrot(DDName("Unit", ns), std::move(r0));
0088   DDrot(DDName("R30", ns), std::move(r30));
0089   DDrot(DDName("R60", ns), std::move(r60));
0090   DDrot(DDName("R90", ns), std::move(r90));
0091 
0092   DDSolid collectorSolid = DDSolidFactory::shapeless(DDName("group", ns));
0093 
0094   DDRootDef::instance().set(worldName);
0095 }
0096 
0097 ///////////////////////////////////////////////////////////////////////////
0098 /*
0099   naming convention for the 8 corners in the world:
0100   +++ (upper, +x, +y)
0101   -++ (lower, +x, +y)
0102   +-+ (upper, -x, +y)
0103   and so on ...
0104 */
0105 
0106 // Fills corner +++ with a hierarchy of boxes ...
0107 /*
0108   File: first.xml
0109   
0110 */
0111 void regressionTest_first(ClhepEvaluator& eval) {
0112   ///load the new cpv
0113   DDCompactView cpv;
0114   cout << "main::initialize DDL parser" << endl;
0115   DDLParser myP(cpv);
0116 
0117   cout << "main::about to set configuration" << endl;
0118 
0119   string ns("first");
0120   DDSolid support = DDSolidFactory::box(DDName("support", ns),
0121                                         eval.eval(ns, "[setup:corner]/4."),
0122                                         eval.eval(ns, "[setup:corner]/8."),
0123                                         eval.eval(ns, "[setup:corner]/4."));
0124   DDSolid sensor = DDSolidFactory::box(DDName("sensor", ns),
0125                                        eval.eval(ns, "[setup:corner]/16."),
0126                                        eval.eval(ns, "[setup:corner]/16."),
0127                                        eval.eval(ns, "[setup:corner]/16."));
0128 
0129   DDLogicalPart supportLP(DDName("support", ns),         // name
0130                           DDName("Oxygen", "elements"),  // material
0131                           DDName("support", ns));        // solid
0132 
0133   DDLogicalPart sensorLP(DDName("sensor", ns), DDName("Nitrogen", "elements"), DDName("sensor", ns));
0134 
0135   DDLogicalPart part(DDName("group", ns), DDName("Air", "setup"), DDName("group", "setup"));
0136 
0137   DDRotation r30(DDName("R30", "setup"));
0138   DDRotation r60(DDName("R60", "setup"));
0139   DDRotation r90(DDName("R90", "setup"));
0140   DDRotation unit(DDName("Unit", "setup"));
0141   DDTranslation t0;
0142   DDTranslation t1(
0143       eval.eval(ns, "[setup:corner]/8."), eval.eval(ns, "[setup:corner]/16."), eval.eval(ns, "[setup:corner]/8."));
0144   DDTranslation t2(
0145       eval.eval(ns, "[setup:corner]*1.25*cos(0.)"), eval.eval(ns, "[setup:corner]*1.25*sin(0.)"), eval.eval(ns, "0."));
0146   DDTranslation t3(eval.eval(ns, "[setup:corner]*1.25*cos(30.*deg)"),
0147                    eval.eval(ns, "[setup:corner]*1.25*sin(30.*deg)"),
0148                    eval.eval(ns, "0."));
0149   DDTranslation t4(eval.eval(ns, "[setup:corner]*1.25*cos(60.*deg)"),
0150                    eval.eval(ns, "[setup:corner]*1.25*sin(60.*deg)"),
0151                    eval.eval(ns, "0."));
0152   DDTranslation t5(eval.eval(ns, "[setup:corner]*1.25*cos(90.*deg)"),
0153                    eval.eval(ns, "[setup:corner]*1.25*sin(90.*deg)"),
0154                    eval.eval(ns, "0."));
0155 
0156   cpv.position(sensorLP, supportLP, std::string("1"), t1, unit);
0157   cpv.position(supportLP, part, std::string("1"), t2, unit);
0158   cpv.position(supportLP, part, std::string("2"), t3, r30);
0159   cpv.position(supportLP, part, std::string("3"), t4, r60);
0160   cpv.position(supportLP, part, std::string("4"), t5, r90);
0161 
0162   std::unique_ptr<DDRotationMatrix> rm =
0163       std::make_unique<DDRotationMatrix>(ROOT::Math::AxisAngle(DD3Vector(1., 1., 1.), 20._deg));
0164   DDRotation rw = DDrot(DDName("group", ns), std::move(rm));
0165   DDLogicalPart ws(DDName("world", "setup"));
0166   cpv.position(part, ws, std::string("1"), t0, rw);
0167 }
0168 
0169 void output(string filename) {
0170   ostream& os(cout);
0171 
0172   os << "Starting Regressiontest Output" << endl;
0173   ///load the new cpv
0174   DDCompactView cpv;
0175   cout << "main::initialize DDL parser" << endl;
0176   DDLParser myP(cpv);
0177 
0178   cout << "main::about to set configuration" << endl;
0179   FIPConfiguration cf(cpv);
0180   cf.readConfig("DetectorDescription/RegressionTest/test/configuration.xml");
0181 
0182   cout << "main::about to start parsing" << endl;
0183 
0184   myP.parse(cf);
0185 
0186   cout << "main::completed Parser" << endl;
0187 
0188   DDExpandedView exv(cpv);
0189   vector<DDTranslation> tvec;
0190   bool loop = true;
0191   std::cout << "Before the loop..." << std::endl;
0192   while (loop) {
0193     ROOT::Math::AxisAngle ra(exv.rotation());
0194     os << exv.logicalPart() << endl
0195        << "  " << exv.logicalPart().material() << endl
0196        << "  " << exv.logicalPart().solid() << endl
0197        << "  " << exv.translation() << endl;
0198     os << "  " << ra.Axis() << convertRadToDeg(ra.Angle()) << endl;
0199     tvec.emplace_back(exv.translation());
0200     loop = exv.next();
0201   }
0202 
0203   vector<DDTranslation>::iterator it = tvec.begin();
0204   os << endl << "center points of all solids" << endl;
0205   for (; it != tvec.end(); ++it) {
0206     os << (*it).x() << " " << (*it).y() << " " << (*it).z() << endl;
0207   }
0208 }
0209 
0210 void testParser() {
0211   try {
0212     cout << "main:: initialize" << endl;
0213     DDCompactView cpv;
0214     cout << "main::initialize DDL parser" << endl;
0215     DDLParser myP(cpv);
0216 
0217     cout << "main::about to set configuration" << endl;
0218 
0219     FIPConfiguration cf(cpv);
0220     cf.readConfig("DetectorDescription/RegressionTest/test/configuration.xml");
0221 
0222     cout << "main::about to start parsing" << endl;
0223 
0224     myP.parse(cf);
0225 
0226     cout << "main::completed Parser" << endl;
0227 
0228     cout << endl << endl << "main::Start checking!" << endl << endl;
0229 
0230   } catch (cms::Exception& e) {
0231     cout << "main::PROBLEM:" << endl << "         " << e << endl;
0232   }
0233 }
0234 
0235 void printRot(const DDRotationMatrix& rot) {
0236   std::cout << "rot asis\n" << rot << std::endl;
0237   DD3Vector x, y, z;
0238   rot.GetComponents(x, y, z);
0239   std::cout << "components\n" << x << "\n" << y << "\n" << z << std::endl;
0240   cout << "phiX=" << x.phi() << " or in degrees = " << convertRadToDeg(x.phi()) << endl;
0241   cout << "thetaX=" << x.theta() << " or in degrees = " << convertRadToDeg(x.theta()) << endl;
0242   cout << "phiY=" << y.phi() << " or in degrees = " << convertRadToDeg(y.phi()) << endl;
0243   cout << "thetaY=" << y.theta() << " or in degrees = " << convertRadToDeg(y.theta()) << endl;
0244   cout << "phiZ=" << z.phi() << " or in degrees = " << convertRadToDeg(z.phi()) << endl;
0245   cout << "thetaZ=" << z.theta() << " or in degrees = " << convertRadToDeg(z.theta()) << endl;
0246 
0247   cout << "some factor/equations..." << endl;
0248   cout << " sin(thetaX()) * cos(phiX()) = " << sin(x.theta()) * cos(x.phi()) << endl;
0249 }
0250 
0251 void testrot() {
0252   {
0253     ROOT::Math::AxisAngle aa(DD3Vector(1., 1., 1.), 20._deg);
0254     DDRotationMatrix rm(aa);
0255     cout << "DD3Vector was " << DD3Vector(1., 1., 1.) << " and the rotation was 20*deg around that axis." << endl;
0256     printRot(rm);
0257   }
0258   {
0259     DDRotationMatrix rm(1, 0, 0, 0, -1, 0, 0, 0, 1);
0260     cout << "(1,0,0, 0,-1,0, 0,0,1)" << endl;
0261     printRot(rm);
0262   }
0263 }