Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <algorithm>
0002 #include <cmath>
0003 #include <map>
0004 #include <string>
0005 #include <vector>
0006 
0007 #include "DataFormats/Math/interface/angle_units.h"
0008 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0009 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0010 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0011 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0012 #include "DetectorDescription/Core/interface/DDSplit.h"
0013 #include "DetectorDescription/Core/interface/DDTypes.h"
0014 #include "DetectorDescription/Core/interface/DDutils.h"
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 #include "FWCore/PluginManager/interface/PluginFactory.h"
0017 #include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
0018 
0019 //#define EDM_ML_DEBUG
0020 using namespace angle_units::operators;
0021 
0022 class DDHGCalWafer : public DDAlgorithm {
0023 public:
0024   // Constructor and Destructor
0025   DDHGCalWafer();
0026   ~DDHGCalWafer() override;
0027 
0028   void initialize(const DDNumericArguments& nArgs,
0029                   const DDVectorArguments& vArgs,
0030                   const DDMapArguments& mArgs,
0031                   const DDStringArguments& sArgs,
0032                   const DDStringVectorArguments& vsArgs) override;
0033   void execute(DDCompactView& cpv) override;
0034 
0035 private:
0036   double waferSize_;                     // Wafer Size
0037   int cellType_;                         // Type (1 fine; 2 coarse)
0038   int nColumns_;                         // Maximum number of columns
0039   int nBottomY_;                         // Index of cell position of bottom row
0040   std::vector<std::string> childNames_;  // Names of children
0041   std::vector<int> nCellsRow_;           // Number of cells in a row
0042   std::vector<int> angleEdges_;          // Rotation angles to be used for edges
0043   std::vector<int> detectorType_;        // Detector type of edge cells
0044   std::string idNameSpace_;              // Namespace of this and ALL sub-parts
0045   DDName parentName_;                    // Parent name
0046 };
0047 
0048 DDHGCalWafer::DDHGCalWafer() {
0049 #ifdef EDM_ML_DEBUG
0050   edm::LogVerbatim("HGCalGeom") << "DDHGCalWafer: Creating an instance";
0051 #endif
0052 }
0053 
0054 DDHGCalWafer::~DDHGCalWafer() {}
0055 
0056 void DDHGCalWafer::initialize(const DDNumericArguments& nArgs,
0057                               const DDVectorArguments& vArgs,
0058                               const DDMapArguments&,
0059                               const DDStringArguments& sArgs,
0060                               const DDStringVectorArguments& vsArgs) {
0061   waferSize_ = nArgs["WaferSize"];
0062   cellType_ = (int)(nArgs["CellType"]);
0063   nColumns_ = (int)(nArgs["NColumns"]);
0064   nBottomY_ = (int)(nArgs["NBottomY"]);
0065   childNames_ = vsArgs["ChildNames"];
0066   nCellsRow_ = dbl_to_int(vArgs["NCellsRow"]);
0067   angleEdges_ = dbl_to_int(vArgs["AngleEdges"]);
0068   detectorType_ = dbl_to_int(vArgs["DetectorType"]);
0069   idNameSpace_ = DDCurrentNamespace::ns();
0070   parentName_ = parent().name();
0071 #ifdef EDM_ML_DEBUG
0072   edm::LogVerbatim("HGCalGeom") << childNames_.size() << " children: " << childNames_[0] << "; " << childNames_[1]
0073                                 << " in namespace " << idNameSpace_ << " positioned in " << nCellsRow_.size()
0074                                 << " rows and " << nColumns_ << " columns with lowest column at " << nBottomY_
0075                                 << " in mother " << parentName_ << " of size " << waferSize_;
0076   for (unsigned int k = 0; k < nCellsRow_.size(); ++k)
0077     edm::LogVerbatim("HGCalGeom") << "[" << k << "] Ncells " << nCellsRow_[k] << " Edge rotations "
0078                                   << angleEdges_[2 * k] << ":" << angleEdges_[2 * k + 1] << " Type of edge cells "
0079                                   << detectorType_[2 * k] << ":" << detectorType_[2 * k + 1];
0080 #endif
0081 }
0082 
0083 void DDHGCalWafer::execute(DDCompactView& cpv) {
0084 #ifdef EDM_ML_DEBUG
0085   edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDHGCalWafer...";
0086 #endif
0087   double dx = 0.5 * waferSize_ / nColumns_;
0088   double dy = 0.5 * dx * tan(30._deg);
0089   int ny = nBottomY_;
0090   int kount(0);
0091 
0092   for (unsigned int ir = 0; ir < nCellsRow_.size(); ++ir) {
0093     int nx = 1 - nCellsRow_[ir];
0094     double ypos = dy * ny;
0095     for (int ic = 0; ic < nCellsRow_[ir]; ++ic) {
0096       std::string name(childNames_[0]), rotstr("NULL");
0097       int irot(0);
0098       if (ic == 0) {
0099         name = childNames_[detectorType_[2 * ir]];
0100         irot = angleEdges_[2 * ir];
0101       } else if (ic + 1 == nCellsRow_[ir]) {
0102         name = childNames_[detectorType_[2 * ir + 1]];
0103         irot = angleEdges_[2 * ir + 1];
0104       }
0105       DDRotation rot;
0106       if (irot != 0) {
0107         double phi = convertDegToRad(irot);
0108         rotstr = "R" + formatAsDegrees(phi);
0109         rot = DDRotation(DDName(rotstr, idNameSpace_));
0110         if (!rot) {
0111 #ifdef EDM_ML_DEBUG
0112           edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo: Creating new rotation " << DDName(rotstr, idNameSpace_)
0113                                         << "\t90, " << irot << ", 90, " << (irot + 90) << ", 0, 0";
0114 #endif
0115           rot = DDrot(DDName(rotstr, idNameSpace_), 90._deg, phi, 90._deg, (90._deg + phi), 0, 0);
0116         }
0117       }
0118       double xpos = dx * nx;
0119       nx += 2;
0120       DDTranslation tran(xpos, ypos, 0);
0121       int copy = HGCalTypes::packCellType6(cellType_, kount);
0122       cpv.position(DDName(name, idNameSpace_), parentName_, copy, tran, rot);
0123       ++kount;
0124 #ifdef EDM_ML_DEBUG
0125       edm::LogVerbatim("HGCalGeom") << "DDHGCalWafer: " << DDName(name, idNameSpace_) << " number " << copy
0126                                     << " positioned in " << parentName_ << " at " << tran << " with " << rot;
0127 #endif
0128     }
0129     ny += 6;
0130   }
0131 }
0132 
0133 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalWafer, "hgcal:DDHGCalWafer");