Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDHCalFibreBundle.cc
0003 // Description: Create & Position fibre bundles in mother
0004 ///////////////////////////////////////////////////////////////////////////////
0005 
0006 #include <cmath>
0007 #include <algorithm>
0008 #include <map>
0009 #include <string>
0010 #include <vector>
0011 
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 #include "FWCore/PluginManager/interface/PluginFactory.h"
0014 #include "DataFormats/Math/interface/angle_units.h"
0015 #include "DetectorDescription/Core/interface/DDutils.h"
0016 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0017 #include "DetectorDescription/Core/interface/DDSolid.h"
0018 #include "DetectorDescription/Core/interface/DDMaterial.h"
0019 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0020 #include "DetectorDescription/Core/interface/DDSplit.h"
0021 #include "DetectorDescription/Core/interface/DDTypes.h"
0022 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0023 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0024 
0025 //#define EDM_ML_DEBUG
0026 using namespace angle_units::operators;
0027 
0028 class DDHCalFibreBundle : public DDAlgorithm {
0029 public:
0030   //Constructor and Destructor
0031   DDHCalFibreBundle();
0032   ~DDHCalFibreBundle() override;
0033 
0034   void initialize(const DDNumericArguments& nArgs,
0035                   const DDVectorArguments& vArgs,
0036                   const DDMapArguments& mArgs,
0037                   const DDStringArguments& sArgs,
0038                   const DDStringVectorArguments& vsArgs) override;
0039 
0040   void execute(DDCompactView& cpv) override;
0041 
0042 private:
0043   std::string idNameSpace;          //Namespace of this and ALL sub-parts
0044   std::string childPrefix;          //Prefix to child name
0045   std::string material;             //Name of the material for bundles
0046   double deltaZ;                    //Width in  Z  for mother
0047   double deltaPhi;                  //Width in phi for mother
0048   int numberPhi;                    //Number of sections in phi
0049   double tilt;                      //Tilt angle of the readout box
0050   std::vector<double> areaSection;  //Area of a bundle
0051   std::vector<double> rStart;       //Radius at start
0052   std::vector<double> rEnd;         //Radius at End
0053   std::vector<int> bundle;          //Bundle to be positioned
0054 };
0055 
0056 DDHCalFibreBundle::DDHCalFibreBundle() {
0057 #ifdef EDM_ML_DEBUG
0058   edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Creating an instance";
0059 #endif
0060 }
0061 
0062 DDHCalFibreBundle::~DDHCalFibreBundle() {}
0063 
0064 void DDHCalFibreBundle::initialize(const DDNumericArguments& nArgs,
0065                                    const DDVectorArguments& vArgs,
0066                                    const DDMapArguments&,
0067                                    const DDStringArguments& sArgs,
0068                                    const DDStringVectorArguments&) {
0069   deltaPhi = nArgs["DeltaPhi"];
0070   deltaZ = nArgs["DeltaZ"];
0071   numberPhi = int(nArgs["NumberPhi"]);
0072   material = sArgs["Material"];
0073   areaSection = vArgs["AreaSection"];
0074   rStart = vArgs["RadiusStart"];
0075   rEnd = vArgs["RadiusEnd"];
0076   bundle = dbl_to_int(vArgs["Bundles"]);
0077   tilt = nArgs["TiltAngle"];
0078 
0079   idNameSpace = DDCurrentNamespace::ns();
0080   childPrefix = sArgs["Child"];
0081 #ifdef EDM_ML_DEBUG
0082   edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Parent " << parent().name() << " with " << bundle.size()
0083                                << " children with prefix " << childPrefix << ", material " << material << " with "
0084                                << numberPhi << " bundles along phi; width of"
0085                                << " mother " << deltaZ << " along Z, " << convertRadToDeg(deltaPhi)
0086                                << " along phi and with " << rStart.size() << " different bundle types";
0087   for (unsigned int i = 0; i < areaSection.size(); ++i)
0088     edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Child[" << i << "] Area " << areaSection[i] << " R at Start "
0089                                  << rStart[i] << " R at End " << rEnd[i];
0090   edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: NameSpace " << idNameSpace << " Tilt Angle "
0091                                << convertRadToDeg(tilt) << " Bundle type at different positions";
0092   for (unsigned int i = 0; i < bundle.size(); ++i) {
0093     edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Position[" << i << "] "
0094                                  << " with Type " << bundle[i];
0095   }
0096 #endif
0097 }
0098 
0099 void DDHCalFibreBundle::execute(DDCompactView& cpv) {
0100   DDName mother = parent().name();
0101   DDName matname(DDSplit(material).first, DDSplit(material).second);
0102   DDMaterial matter(matname);
0103 
0104   // Create the rotation matrices
0105   double dPhi = deltaPhi / numberPhi;
0106   std::vector<DDRotation> rotation;
0107   for (int i = 0; i < numberPhi; ++i) {
0108     double phi = -0.5 * deltaPhi + (i + 0.5) * dPhi;
0109     double phideg = convertRadToDeg(phi);
0110     std::string rotstr = "R0" + std::to_string(phideg);
0111     DDRotation rot = DDRotation(DDName(rotstr, idNameSpace));
0112     if (!rot) {
0113 #ifdef EDM_ML_DEBUG
0114       edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Creating a new "
0115                                    << "rotation " << rotstr << "\t" << 90 << "," << phideg << "," << 90 << ","
0116                                    << (phideg + 90) << ", 0, 0";
0117 #endif
0118       rot = DDrot(DDName(rotstr, idNameSpace), 90._deg, phi, 90._deg, (90._deg + phi), 0, 0);
0119     }
0120     rotation.emplace_back(rot);
0121   }
0122 
0123   // Create the solids and logical parts
0124   std::vector<DDLogicalPart> logs;
0125   for (unsigned int i = 0; i < areaSection.size(); ++i) {
0126     double r0 = rEnd[i] / std::cos(tilt);
0127     double dStart = areaSection[i] / (2 * dPhi * rStart[i]);
0128     double dEnd = areaSection[i] / (2 * dPhi * r0);
0129     std::string name = childPrefix + std::to_string(i);
0130     DDSolid solid = DDSolidFactory::cons(DDName(name, idNameSpace),
0131                                          0.5 * deltaZ,
0132                                          rStart[i] - dStart,
0133                                          rStart[i] + dStart,
0134                                          r0 - dEnd,
0135                                          r0 + dEnd,
0136                                          -0.5 * dPhi,
0137                                          dPhi);
0138 #ifdef EDM_ML_DEBUG
0139     edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Creating a new solid " << name << " a cons with dZ " << deltaZ
0140                                  << " rStart " << rStart[i] - dStart << ":" << rStart[i] + dStart << " rEnd "
0141                                  << r0 - dEnd << ":" << r0 + dEnd << " Phi " << convertRadToDeg(-0.5 * dPhi) << ":"
0142                                  << convertRadToDeg(0.5 * dPhi);
0143 #endif
0144     DDLogicalPart log(DDName(name, idNameSpace), matter, solid);
0145     logs.emplace_back(log);
0146   }
0147 
0148   // Now posiiton them
0149   int copy = 0;
0150   int nY = (int)(bundle.size()) / numberPhi;
0151   for (unsigned int i = 0; i < bundle.size(); i++) {
0152     DDTranslation tran(0, 0, 0);
0153     int ir = (int)(i) / nY;
0154     if (ir >= numberPhi)
0155       ir = numberPhi - 1;
0156     int ib = bundle[i];
0157     copy++;
0158     if (ib >= 0 && ib < (int)(logs.size())) {
0159       cpv.position(logs[ib], mother, copy, tran, rotation[ir]);
0160 #ifdef EDM_ML_DEBUG
0161       edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: " << logs[ib].name() << " number " << copy
0162                                    << " positioned in " << mother << " at " << tran << " with " << rotation[ir];
0163 #endif
0164     }
0165   }
0166 }
0167 
0168 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHCalFibreBundle, "hcal:DDHCalFibreBundle");