Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-04-11 22:43:56

0001 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0002 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0003 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0004 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0005 #include "DetectorDescription/Core/interface/DDMaterial.h"
0006 #include "DetectorDescription/Core/interface/DDSolid.h"
0007 #include "DetectorDescription/Core/interface/DDSplit.h"
0008 #include "DetectorDescription/Core/interface/DDTypes.h"
0009 #include "DetectorDescription/Core/interface/DDutils.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/PluginManager/interface/PluginFactory.h"
0012 #include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
0013 
0014 #include <string>
0015 #include <vector>
0016 
0017 //#define EDM_ML_DEBUG
0018 
0019 class DDHGCalWafer8 : public DDAlgorithm {
0020 public:
0021   // Constructor and Destructor
0022   DDHGCalWafer8() {}
0023 
0024   void initialize(const DDNumericArguments& nArgs,
0025                   const DDVectorArguments& vArgs,
0026                   const DDMapArguments& mArgs,
0027                   const DDStringArguments& sArgs,
0028                   const DDStringVectorArguments& vsArgs) override;
0029   void execute(DDCompactView& cpv) override;
0030 
0031 private:
0032   double waferSize_;                    // Wafer size
0033   double waferT_;                       // Wafer thickness
0034   double waferSepar_;                   // Sensor separation
0035   int nCells_;                          // Half number of cells along u-v axis
0036   int cellType_;                        // Cell Type (0,1,2: Fine, Course 2/3)
0037   std::string material_;                // Material name for module with gap
0038   std::vector<std::string> cellNames_;  // Name of the cells
0039   std::string nameSpace_;               // Namespace to be used
0040 };
0041 
0042 void DDHGCalWafer8::initialize(const DDNumericArguments& nArgs,
0043                                const DDVectorArguments&,
0044                                const DDMapArguments&,
0045                                const DDStringArguments& sArgs,
0046                                const DDStringVectorArguments& vsArgs) {
0047   waferSize_ = nArgs["WaferSize"];
0048   waferT_ = nArgs["WaferThick"];
0049   waferSepar_ = nArgs["SensorSeparation"];
0050   nCells_ = (int)(nArgs["NCells"]);
0051   cellType_ = (int)(nArgs["CellType"]);
0052   material_ = sArgs["Material"];
0053   cellNames_ = vsArgs["CellNames"];
0054   nameSpace_ = DDCurrentNamespace::ns();
0055 #ifdef EDM_ML_DEBUG
0056   edm::LogVerbatim("HGCalGeom") << "DDHGCalWafer8: Wafer 2r " << waferSize_ << " T " << waferT_ << " Half Separation "
0057                                 << waferSepar_ << " Cells/Wafer " << nCells_ << " Cell Type " << cellType_
0058                                 << " Material " << material_ << " Names " << parent().name() << " NameSpace "
0059                                 << nameSpace_ << ": # of cells " << cellNames_.size();
0060   for (unsigned int k = 0; k < cellNames_.size(); ++k)
0061     edm::LogVerbatim("HGCalGeom") << "DDHGCalWafer8: Cell[" << k << "] " << cellNames_[k];
0062 #endif
0063 }
0064 
0065 void DDHGCalWafer8::execute(DDCompactView& cpv) {
0066   static const double sqrt3 = std::sqrt(3.0);
0067   double rM = 0.5 * (waferSize_ + waferSepar_);
0068   double RM2 = rM / sqrt3;
0069   double R = waferSize_ / (3.0 * nCells_);
0070   double r = 0.5 * R * sqrt3;
0071 
0072   // First the full cell
0073   std::vector<double> xM = {rM, 0, -rM, -rM, 0, rM};
0074   std::vector<double> yM = {RM2, 2 * RM2, RM2, -RM2, -2 * RM2, -RM2};
0075   std::vector<double> zw = {-0.5 * waferT_, 0.5 * waferT_};
0076   std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
0077   DDName parentName = parent().name();
0078   DDSolid solid = DDSolidFactory::extrudedpolygon(parentName, xM, yM, zw, zx, zy, scale);
0079   DDName matName(DDSplit(material_).first, DDSplit(material_).second);
0080   DDMaterial matter(matName);
0081   DDLogicalPart glog = DDLogicalPart(solid.ddname(), matter, solid);
0082 #ifdef EDM_ML_DEBUG
0083   edm::LogVerbatim("HGCalGeom") << "DDHGCalWafer8: " << solid.name() << " extruded polygon made of " << matName
0084                                 << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
0085                                 << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
0086                                 << " and " << xM.size() << " edges";
0087   for (unsigned int k = 0; k < xM.size(); ++k)
0088     edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xM[k] << ":" << yM[k];
0089   int counter(0);
0090 #endif
0091 
0092   DDRotation rot;
0093   for (int u = 0; u < 2 * nCells_; ++u) {
0094     for (int v = 0; v < 2 * nCells_; ++v) {
0095       if (((v - u) < nCells_) && (u - v) <= nCells_) {
0096 #ifdef EDM_ML_DEBUG
0097         counter++;
0098 #endif
0099         int n2 = nCells_ / 2;
0100         double yp = (u - 0.5 * v - n2) * 2 * r;
0101         double xp = (1.5 * (v - nCells_) + 1.0) * R;
0102         int cell(0);
0103         if ((u == 0) && (v == 0))
0104           cell = 7;
0105         else if ((u == 0) && (v == nCells_ - 1))
0106           cell = 8;
0107         else if ((u == nCells_) && (v == 2 * nCells_ - 1))
0108           cell = 9;
0109         else if ((u == 2 * nCells_ - 1) && (v == 2 * nCells_ - 1))
0110           cell = 10;
0111         else if ((u == 2 * nCells_ - 1) && (v == nCells_ - 1))
0112           cell = 11;
0113         else if ((u == nCells_) && (v == 0))
0114           cell = 12;
0115         else if (u == 0)
0116           cell = 1;
0117         else if ((v - u) == (nCells_ - 1))
0118           cell = 4;
0119         else if (v == (2 * nCells_ - 1))
0120           cell = 2;
0121         else if (u == (2 * nCells_ - 1))
0122           cell = 5;
0123         else if ((u - v) == nCells_)
0124           cell = 3;
0125         else if (v == 0)
0126           cell = 6;
0127         DDTranslation tran(xp, yp, 0);
0128         int copy = HGCalTypes::packCellTypeUV(cellType_, u, v);
0129         cpv.position(DDName(cellNames_[cell]), glog, copy, tran, rot);
0130 #ifdef EDM_ML_DEBUG
0131         edm::LogVerbatim("HGCalGeom") << "DDHGCalWafer8: " << cellNames_[cell] << " number " << copy << " position in "
0132                                       << glog.name() << " at " << tran << " with no rotation";
0133 #endif
0134       }
0135     }
0136   }
0137 #ifdef EDM_ML_DEBUG
0138   edm::LogVerbatim("HGCalGeom") << "\nDDHGCalWafer8::Counter : " << counter << "\n===============================\n";
0139 #endif
0140 }
0141 
0142 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalWafer8, "hgcal:DDHGCalWafer8");