Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:43

0001 #include "DD4hep/DetFactoryHelper.h"
0002 #include "DataFormats/Math/interface/angle_units.h"
0003 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0004 #include "DetectorDescription/DDCMS/interface/DDutils.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 
0007 //#define EDM_ML_DEBUG
0008 using namespace angle_units::operators;
0009 
0010 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
0011   cms::DDNamespace ns(ctxt, e, true);
0012   cms::DDAlgoArguments args(ctxt, e);
0013   // Header section
0014   double eta = args.value<double>("Eta");                        //Eta at which beam is focussed
0015   double phi = args.value<double>("Phi");                        //Phi    ................
0016   double theta = 2.0 * atan(exp(-eta));                          //Corresponding theta value
0017   double distance = args.value<double>("Dist");                  //Distance of the centre of rotation
0018   double distanceZ = args.value<double>("DistZ");                //Distance along x-axis of the centre of rotation
0019   double dist = (distance + distanceZ / sin(theta));             //Overall distance
0020   int copyNumber = args.value<int>("Number");                    //Copy Number
0021   std::string childName = args.value<std::string>("ChildName");  //Children name
0022   double dz = args.value<double>("Dz");                          //Half length along z of the volume to be placed
0023 #ifdef EDM_ML_DEBUG
0024   edm::LogVerbatim("HCalGeom") << "DDHCalTestBeamAlgo: Parameters for positioning-- Eta " << eta << "\tPhi "
0025                                << convertRadToDeg(phi) << "\tTheta " << convertRadToDeg(theta) << "\tDistance "
0026                                << cms::convert2mm(distance) << "/" << cms::convert2mm(distanceZ) << "/"
0027                                << cms::convert2mm(dist) << "\tDz " << cms::convert2mm(dz) << "\tcopyNumber "
0028                                << copyNumber;
0029   edm::LogVerbatim("HCalGeom") << "DDHCalTestBeamAlgo:Parent " << args.parentName() << "\tChild " << childName
0030                                << " NameSpace " << ns.name();
0031 #endif
0032 
0033   dd4hep::Volume parent = ns.volume(args.parentName());
0034 
0035   double thetax = 90._deg + theta;
0036   double sthx = sin(thetax);
0037   if (std::abs(sthx) > 1.e-12)
0038     sthx = 1. / sthx;
0039   else
0040     sthx = 1.;
0041   double phix = atan2(sthx * cos(theta) * sin(phi), sthx * cos(theta) * cos(phi));
0042   double thetay = 90._deg;
0043   double phiy = 90._deg + phi;
0044   double thetaz = theta;
0045   double phiz = phi;
0046 
0047   dd4hep::Rotation3D rotation = cms::makeRotation3D(thetax, phix, thetay, phiy, thetaz, phiz);
0048 #ifdef EDM_ML_DEBUG
0049   edm::LogVerbatim("HCalGeom") << "DDHCalTestBeamAlgo: Creating a rotation \t" << convertRadToDeg(thetax) << ","
0050                                << convertRadToDeg(phix) << "," << convertRadToDeg(thetay) << ","
0051                                << convertRadToDeg(phiy) << "," << convertRadToDeg(thetaz) << ","
0052                                << convertRadToDeg(phiz);
0053 #endif
0054 
0055   double r = dist * sin(theta);
0056   double xpos = r * cos(phi);
0057   double ypos = r * sin(phi);
0058   double zpos = dist * cos(theta);
0059   dd4hep::Position tran(xpos, ypos, zpos);
0060 
0061   childName = ns.prepend(childName);
0062   dd4hep::Volume child = ns.volume(childName);
0063   parent.placeVolume(child, copyNumber, dd4hep::Transform3D(rotation, tran));
0064 #ifdef EDM_ML_DEBUG
0065   edm::LogVerbatim("HCalGeom") << "DDHCalTestBeamAlgo: " << child.name() << " number " << copyNumber
0066                                << " positioned in " << parent.name() << " at (" << cms::convert2mm(xpos) << ", "
0067                                << cms::convert2mm(ypos) << ", " << cms::convert2mm(zpos)
0068                                << ") with rotation: " << rotation;
0069 #endif
0070   xpos = (dist - dz) * sin(theta) * cos(phi);
0071   ypos = (dist - dz) * sin(theta) * sin(phi);
0072   zpos = (dist - dz) * cos(theta);
0073 
0074   edm::LogInfo("HCalGeom") << "DDHCalTestBeamAlgo: Suggested Beam position (" << cms::convert2mm(xpos) << ", "
0075                            << cms::convert2mm(ypos) << ", " << cms::convert2mm(zpos) << ") and (dist, eta, phi) = ("
0076                            << cms::convert2mm(dist - dz) << ", " << eta << ", " << phi << ")";
0077 
0078   return cms::s_executed;
0079 }
0080 
0081 // first argument is the type from the xml file
0082 DECLARE_DDCMS_DETELEMENT(DDCMS_hcal_DDHCalTestBeamAlgo, algorithm);