Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-24 22:52:01

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 #include "Geometry/HGCalCommonData/interface/HGCalWaferMask.h"
0014 #include "Geometry/HGCalCommonData/interface/HGCalCell.h"
0015 
0016 #include <string>
0017 #include <vector>
0018 #include <sstream>
0019 
0020 //#define EDM_ML_DEBUG
0021 
0022 class DDHGCalWaferPartialRotated : public DDAlgorithm {
0023 public:
0024   // Constructor and Destructor
0025   DDHGCalWaferPartialRotated() = default;
0026   ~DDHGCalWaferPartialRotated() override = default;
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   std::string material_;           // Material name for module with gap
0037   std::string waferTag_;           // Tag for type of wafer
0038   double thick_;                   // Module thickness
0039   double waferSize_;               // Wafer size
0040   double waferSepar_;              // Sensor separation
0041   double waferThick_;              // Wafer thickness
0042   std::vector<std::string> tags_;  // Tags to be added to each name
0043   std::vector<int> partialTypes_;  // Type of partial wafer
0044   std::vector<int> placementIndex_;
0045   std::vector<std::string> placementIndexTags_;  // Plaement index of the wafers
0046   std::vector<std::string> layerNames_;          // Names of the layers
0047   std::vector<std::string> materials_;           // Materials of the layers
0048   std::vector<double> layerThick_;               // Thickness of layers
0049   std::vector<int> layerType_;                   // Layer types
0050   std::vector<int> layers_;                      // Number of layers in a section
0051   std::string senseName_;                        // Name of the sensitive layer
0052   double senseT_;                                // Thickness of sensitive layer
0053   int senseType_;                                // Cell Type (0,1,2: Fine, Course 2/3)
0054   std::string nameSpace_;                        // Namespace to be used
0055 };
0056 
0057 void DDHGCalWaferPartialRotated::initialize(const DDNumericArguments& nArgs,
0058                                             const DDVectorArguments& vArgs,
0059                                             const DDMapArguments&,
0060                                             const DDStringArguments& sArgs,
0061                                             const DDStringVectorArguments& vsArgs) {
0062   material_ = sArgs["ModuleMaterial"];
0063   thick_ = nArgs["ModuleThickness"];
0064   waferSize_ = nArgs["WaferSize"];
0065   waferThick_ = nArgs["WaferThickness"];
0066   waferTag_ = sArgs["WaferTag"];
0067 #ifdef EDM_ML_DEBUG
0068   waferSepar_ = nArgs["SensorSeparation"];
0069   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: Module " << parent().name() << " made of " << material_
0070                                 << " T " << thick_ << " Wafer 2r " << waferSize_ << " Half Separation " << waferSepar_
0071                                 << " T " << waferThick_;
0072 #endif
0073   tags_ = vsArgs["Tags"];
0074   partialTypes_ = dbl_to_int(vArgs["PartialTypes"]);
0075   placementIndex_ = dbl_to_int(vArgs["PlacementIndex"]);
0076   placementIndexTags_ = vsArgs["PlacementIndexTags"];
0077 #ifdef EDM_ML_DEBUG
0078   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << tags_.size() << " variations of wafer types";
0079   for (unsigned int k = 0; k < tags_.size(); ++k) {
0080     for (unsigned int m = 0; m < placementIndex_.size(); ++m) {
0081       edm::LogVerbatim("HGCalGeom") << "Type[" << k << "] " << tags_[k] << " Partial " << partialTypes_[k]
0082                                     << " Placement Index " << placementIndex_[m] << " Tag " << placementIndexTags_[m];
0083     }
0084   }
0085 #endif
0086   layerNames_ = vsArgs["LayerNames"];
0087   materials_ = vsArgs["LayerMaterials"];
0088   layerThick_ = vArgs["LayerThickness"];
0089   layerType_ = dbl_to_int(vArgs["LayerTypes"]);
0090 #ifdef EDM_ML_DEBUG
0091   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << layerNames_.size() << " types of volumes";
0092   for (unsigned int i = 0; i < layerNames_.size(); ++i)
0093     edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames_[i] << " of thickness " << layerThick_[i]
0094                                   << " filled with " << materials_[i] << " type " << layerType_[i];
0095 #endif
0096   layers_ = dbl_to_int(vArgs["Layers"]);
0097 #ifdef EDM_ML_DEBUG
0098   std::ostringstream st1;
0099   for (unsigned int i = 0; i < layers_.size(); ++i)
0100     st1 << " [" << i << "] " << layers_[i];
0101   edm::LogVerbatim("HGCalGeom") << "There are " << layers_.size() << " blocks" << st1.str();
0102 #endif
0103   senseName_ = sArgs["SenseName"];
0104   senseT_ = nArgs["SenseThick"];
0105   senseType_ = static_cast<int>(nArgs["SenseType"]);
0106   nameSpace_ = DDCurrentNamespace::ns();
0107 #ifdef EDM_ML_DEBUG
0108   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: NameSpace " << nameSpace_ << ": Sensitive Layer Name "
0109                                 << senseName_ << " Thickness " << senseT_ << " Type " << senseType_;
0110 #endif
0111 }
0112 
0113 void DDHGCalWaferPartialRotated::execute(DDCompactView& cpv) {
0114 #ifdef EDM_ML_DEBUG
0115   edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalWaferPartialRotated...";
0116 #endif
0117 
0118   static constexpr double tol = 0.00001;
0119   static const double sqrt3 = std::sqrt(3.0);
0120   double r = 0.5 * waferSize_;
0121   double R = 2.0 * r / sqrt3;
0122   std::string parentName = parent().name().name();
0123 
0124   // Loop over all types
0125   for (unsigned int k = 0; k < tags_.size(); ++k) {
0126     for (unsigned int m = 0; m < placementIndex_.size(); ++m) {
0127       // First the mother
0128       std::string mother = parentName + placementIndexTags_[m] + waferTag_ + tags_[k];
0129       std::vector<std::pair<double, double> > wxy =
0130           HGCalWaferMask::waferXY(partialTypes_[k], placementIndex_[m], r, R, 0.0, 0.0);
0131       std::vector<double> xM, yM;
0132       for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
0133         xM.emplace_back(wxy[i].first);
0134         yM.emplace_back(wxy[i].second);
0135       }
0136       std::vector<double> zw = {-0.5 * thick_, 0.5 * thick_};
0137       std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
0138       DDSolid solid = DDSolidFactory::extrudedpolygon(mother, xM, yM, zw, zx, zy, scale);
0139       DDName matName(DDSplit(material_).first, DDSplit(material_).second);
0140       DDMaterial matter(matName);
0141       DDLogicalPart glogM = DDLogicalPart(solid.ddname(), matter, solid);
0142 #ifdef EDM_ML_DEBUG
0143       edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << solid.name() << " extruded polygon made of "
0144                                     << matName << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
0145                                     << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
0146                                     << scale[1] << " partial " << partialTypes_[k] << " placement index "
0147                                     << placementIndex_[m] << " and " << xM.size() << " edges";
0148       for (unsigned int j = 0; j < xM.size(); ++j)
0149         edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << xM[j] << ":" << yM[j];
0150 #endif
0151 
0152       // Then the layers
0153       wxy = HGCalWaferMask::waferXY(partialTypes_[k], placementIndex_[m], r, R, 0.0, 0.0);
0154       std::vector<double> xL, yL;
0155       for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
0156         xL.emplace_back(wxy[i].first);
0157         yL.emplace_back(wxy[i].second);
0158       }
0159       std::vector<DDLogicalPart> glogs(materials_.size());
0160       std::vector<int> copyNumber(materials_.size(), 1);
0161       double zi(-0.5 * thick_), thickTot(0.0);
0162       for (unsigned int l = 0; l < layers_.size(); l++) {
0163         unsigned int i = layers_[l];
0164 #ifdef EDM_ML_DEBUG
0165         edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated:Layer " << l << ":" << i << " T " << layerThick_[i]
0166                                       << " Copy " << copyNumber[i];
0167 #endif
0168         DDRotation rot;
0169         if (copyNumber[i] == 1) {
0170           if (layerType_[i] > 0) {
0171             zw[0] = -0.5 * waferThick_;
0172             zw[1] = 0.5 * waferThick_;
0173           } else {
0174             zw[0] = -0.5 * layerThick_[i];
0175             zw[1] = 0.5 * layerThick_[i];
0176           }
0177           std::string lname = layerNames_[i] + placementIndexTags_[m] + waferTag_ + tags_[k];
0178           solid = DDSolidFactory::extrudedpolygon(lname, xL, yL, zw, zx, zy, scale);
0179           DDName matN(DDSplit(materials_[i]).first, DDSplit(materials_[i]).second);
0180           DDMaterial matter(matN);
0181           glogs[i] = DDLogicalPart(solid.ddname(), matter, solid);
0182 #ifdef EDM_ML_DEBUG
0183           edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << solid.name()
0184                                         << " extruded polygon made of " << matN << " z|x|y|s (0) " << zw[0] << ":"
0185                                         << zx[0] << ":" << zy[0] << ":" << scale[0] << " z|x|y|s (1) " << zw[1] << ":"
0186                                         << zx[1] << ":" << zy[1] << ":" << scale[1] << " partial " << partialTypes_[k]
0187                                         << " placement index " << placementIndex_[m] << " and " << xL.size()
0188                                         << " edges";
0189           for (unsigned int j = 0; j < xL.size(); ++j)
0190             edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << xL[j] << ":" << yL[j];
0191 #endif
0192           if ((layerType_[i] > 0) && (senseType_ >= 0)) {
0193             std::string sname = senseName_ + placementIndexTags_[m] + waferTag_ + tags_[k];
0194             zw[0] = -0.5 * senseT_;
0195             zw[1] = 0.5 * senseT_;
0196             solid = DDSolidFactory::extrudedpolygon(sname, xL, yL, zw, zx, zy, scale);
0197             DDLogicalPart glog = DDLogicalPart(solid.ddname(), matter, solid);
0198 #ifdef EDM_ML_DEBUG
0199             edm::LogVerbatim("HGCalGeom")
0200                 << "DDHGCalWaferPartialRotated: " << solid.name() << " extruded polygon made of " << matN
0201                 << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0] << " z|x|y|s (1) "
0202                 << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1] << " partial " << partialTypes_[k]
0203                 << " placement index " << placementIndex_[m] << " and " << xL.size() << " edges";
0204             for (unsigned int j = 0; j < xL.size(); ++j)
0205               edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << xL[j] << ":" << yL[j];
0206 #endif
0207             auto posSense = HGCalCell::cellOrient(placementIndex_[m]);
0208             double zpos = (posSense.second > 0) ? -0.5 * (waferThick_ - senseT_) : 0.5 * (waferThick_ - senseT_);
0209             DDTranslation tran(0, 0, zpos);
0210             int copy = 10 + senseType_;
0211             cpv.position(glog, glogs[i], copy, tran, rot);
0212 #ifdef EDM_ML_DEBUG
0213             edm::LogVerbatim("HGCalGeom")
0214                 << "DDHGCalWaferPartialRotated: " << glog.name() << " number " << copy << " positioned in "
0215                 << glogs[i].name() << " at " << tran << " with no rotation";
0216 #endif
0217           }
0218         }
0219         DDTranslation tran0(0, 0, (zi + 0.5 * layerThick_[i]));
0220         cpv.position(glogs[i], glogM, copyNumber[i], tran0, rot);
0221 #ifdef EDM_ML_DEBUG
0222         edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << glogs[i].name() << " number "
0223                                       << copyNumber[i] << " positioned in " << glogM.name() << " at " << tran0
0224                                       << " with no rotation";
0225 #endif
0226         ++copyNumber[i];
0227         zi += layerThick_[i];
0228         thickTot += layerThick_[i];
0229       }
0230       if (std::abs(thickTot - thick_) >= tol) {
0231         if (thickTot > thick_) {
0232           edm::LogError("HGCalGeom") << "Thickness of the partition " << thick_ << " is smaller than " << thickTot
0233                                      << ": thickness of all its components **** ERROR ****";
0234         } else {
0235           edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick_ << " does not match with " << thickTot
0236                                        << " of the components";
0237         }
0238       }
0239     }
0240   }
0241 }
0242 
0243 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalWaferPartialRotated, "hgcal:DDHGCalWaferPartialRotated");