Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:21

0001 #include "DD4hep/DetFactoryHelper.h"
0002 #include "DataFormats/Math/interface/CMSUnits.h"
0003 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 
0006 using namespace std;
0007 using namespace dd4hep;
0008 using namespace cms;
0009 using namespace cms_units::operators;
0010 
0011 static long algorithm(Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
0012   cms::DDNamespace ns(ctxt, e, true);
0013   DDAlgoArguments args(ctxt, e);
0014   int startCopyNo = args.value<int>("StartCopyNo");
0015   double rpos = args.value<double>("Rpos");
0016   double zpos = args.value<double>("Zpos");
0017   double optoHeight = args.value<double>("OptoHeight");
0018   double optoWidth = args.value<double>("OptoWidth");
0019   vector<double> angles = args.value<vector<double> >("Angles");
0020   Volume child = ns.volume(args.value<string>("ChildName"));
0021   Volume mother = ns.volume(args.parentName());
0022 
0023   edm::LogVerbatim("TECGeom") << "Parent " << mother.name() << " Child " << child.name() << " NameSpace " << ns.name();
0024   edm::LogVerbatim("TECGeom") << "Height of the Hybrid " << optoHeight << " and Width " << optoWidth << "Rpos " << rpos
0025                               << " Zpos " << zpos << " StartCopyNo " << startCopyNo << " Number " << angles.size();
0026 
0027   // given r positions are for the lower left corner
0028   rpos += optoHeight / 2;
0029   int copyNo = startCopyNo;
0030   for (double angle : angles) {
0031     double phix = -angle;
0032     // given phi positions are for the lower left corner
0033     phix += asin(optoWidth / 2 / rpos);
0034     double xpos = rpos * cos(phix);
0035     double ypos = rpos * sin(phix);
0036     Position tran(xpos, ypos, zpos);
0037 
0038     Rotation3D rotation;
0039     double phiy = phix + 90._deg;
0040     double phideg = convertRadToDeg(phix);
0041     if (phideg != 0) {
0042       string rotstr = ns.nsName(child.name()) + std::to_string(phideg * 1000.);
0043       auto irot = ctxt.rotations.find(ns.prepend(rotstr));
0044       if (irot != ctxt.rotations.end()) {
0045         rotation = ns.rotation(ns.prepend(rotstr));
0046       } else {
0047         double theta = 90._deg;
0048         edm::LogVerbatim("TECGeom") << "test: Creating a new "
0049                                     << "rotation: " << rotstr << "\t90., " << convertRadToDeg(phix) << ", 90.,"
0050                                     << convertRadToDeg(phiy) << ", 0, 0";
0051         rotation = makeRotation3D(theta, phix, theta, phiy, 0., 0.);
0052       }
0053     }
0054     mother.placeVolume(child, copyNo, Transform3D(rotation, tran));
0055     edm::LogVerbatim("TECGeom") << "test " << child.name() << " number " << copyNo << " positioned in " << mother.name()
0056                                 << " at " << tran << " with " << rotation;
0057     copyNo++;
0058   }
0059   edm::LogVerbatim("TECGeom") << "<<== End of DDTECOptoHybAlgo construction ...";
0060   return 1;
0061 }
0062 
0063 // first argument is the type from the xml file
0064 DECLARE_DDCMS_DETELEMENT(DDCMS_track_DDTECOptoHybAlgo, algorithm)