Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDAHcalModuleAlgo.cc
0003 // Description: Geometry factory class for HGCal (EE and HESil)
0004 ///////////////////////////////////////////////////////////////////////////////
0005 
0006 #include <algorithm>
0007 #include <cmath>
0008 #include <string>
0009 #include <vector>
0010 
0011 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0012 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0013 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0014 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0015 #include "DetectorDescription/Core/interface/DDMaterial.h"
0016 #include "DetectorDescription/Core/interface/DDSolid.h"
0017 #include "DetectorDescription/Core/interface/DDSplit.h"
0018 #include "DetectorDescription/Core/interface/DDTypes.h"
0019 #include "DetectorDescription/Core/interface/DDutils.h"
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 #include "FWCore/PluginManager/interface/PluginFactory.h"
0022 #include "Geometry/HGCalCommonData/interface/AHCalParameters.h"
0023 
0024 //#define EDM_ML_DEBUG
0025 
0026 class DDAHcalModuleAlgo : public DDAlgorithm {
0027 public:
0028   // Constructor and Destructor
0029   DDAHcalModuleAlgo();  // const std::string & name);
0030 
0031   void initialize(const DDNumericArguments& nArgs,
0032                   const DDVectorArguments& vArgs,
0033                   const DDMapArguments& mArgs,
0034                   const DDStringArguments& sArgs,
0035                   const DDStringVectorArguments& vsArgs) override;
0036   void execute(DDCompactView& cpv) override;
0037 
0038 protected:
0039   void constructLayers(const DDLogicalPart&, DDCompactView& cpv);
0040   void positionSensitive(DDLogicalPart& glog, DDCompactView& cpv);
0041 
0042 private:
0043   static constexpr double tol_ = 0.00001;
0044 
0045   std::string tile_;                    // Scintillator tile
0046   std::vector<std::string> materials_;  // Materials
0047   std::vector<std::string> names_;      // Names
0048   std::vector<double> thick_;           // Thickness of the material
0049   std::vector<int> copyNumber_;         // Initial copy numbers
0050   std::vector<int> layers_;             // Number of layers in a section
0051   std::vector<double> layerThick_;      // Thickness of each section
0052   std::vector<int> layerType_;          // Type of the layer
0053   std::vector<int> layerSense_;         // Content of a layer (sensitive?)
0054   std::vector<double> widths_;          // Width (passive, active)
0055   std::vector<double> heights_;         // Heights (passive, active)
0056   std::vector<int> tileN_;              // # of tiles (along x, y)
0057   std::vector<double> tileStep_;        // Separation between tiles (x, y)
0058   double zMinBlock_;                    // Starting z-value of the block
0059   std::string idNameSpace_;             // Namespace of this and ALL sub-parts
0060 };
0061 
0062 DDAHcalModuleAlgo::DDAHcalModuleAlgo() {
0063 #ifdef EDM_ML_DEBUG
0064   edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: Creating an instance";
0065 #endif
0066 }
0067 
0068 void DDAHcalModuleAlgo::initialize(const DDNumericArguments& nArgs,
0069                                    const DDVectorArguments& vArgs,
0070                                    const DDMapArguments&,
0071                                    const DDStringArguments& sArgs,
0072                                    const DDStringVectorArguments& vsArgs) {
0073   tile_ = sArgs["TileName"];
0074 #ifdef EDM_ML_DEBUG
0075   edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: Tile " << tile_;
0076 #endif
0077   materials_ = vsArgs["MaterialNames"];
0078   names_ = vsArgs["VolumeNames"];
0079   thick_ = vArgs["Thickness"];
0080   copyNumber_.resize(materials_.size(), 1);
0081 #ifdef EDM_ML_DEBUG
0082   edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << materials_.size() << " types of volumes";
0083   for (unsigned int i = 0; i < names_.size(); ++i)
0084     edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << names_[i] << " of thickness " << thick_[i]
0085                                   << " filled with " << materials_[i] << " first copy number " << copyNumber_[i];
0086 #endif
0087   layers_ = dbl_to_int(vArgs["Layers"]);
0088   layerThick_ = vArgs["LayerThick"];
0089 #ifdef EDM_ML_DEBUG
0090   edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << layers_.size() << " blocks";
0091   for (unsigned int i = 0; i < layers_.size(); ++i)
0092     edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness " << layerThick_[i] << " with " << layers_[i]
0093                                   << " layers";
0094 #endif
0095   layerType_ = dbl_to_int(vArgs["LayerType"]);
0096   layerSense_ = dbl_to_int(vArgs["LayerSense"]);
0097 #ifdef EDM_ML_DEBUG
0098   edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << layerType_.size() << " layers";
0099   for (unsigned int i = 0; i < layerType_.size(); ++i)
0100     edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerType_[i] << " sensitive class "
0101                                   << layerSense_[i];
0102 #endif
0103   widths_ = vArgs["Widths"];
0104   heights_ = vArgs["Heights"];
0105 #ifdef EDM_ML_DEBUG
0106   edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << widths_.size() << " sizes for width "
0107                                 << "and height:";
0108   for (unsigned int i = 0; i < widths_.size(); ++i)
0109     edm::LogVerbatim("HGCalGeom") << " [" << i << "] " << widths_[i] << ":" << heights_[i];
0110 #endif
0111   tileN_ = dbl_to_int(vArgs["TileN"]);
0112   tileStep_ = vArgs["TileStep"];
0113 #ifdef EDM_ML_DEBUG
0114   edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << tileN_.size() << " tile positioning parameters";
0115   for (unsigned int i = 0; i < tileN_.size(); ++i)
0116     edm::LogVerbatim("HGCalGeom") << " [" << i << "] " << tileN_[i] << ":" << tileStep_[i];
0117 #endif
0118   zMinBlock_ = nArgs["zMinBlock"];
0119   idNameSpace_ = DDCurrentNamespace::ns();
0120 #ifdef EDM_ML_DEBUG
0121   edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: zStart " << zMinBlock_ << "  NameSpace " << idNameSpace_;
0122 #endif
0123 }
0124 
0125 ////////////////////////////////////////////////////////////////////
0126 // DDAHcalModuleAlgo methods...
0127 ////////////////////////////////////////////////////////////////////
0128 
0129 void DDAHcalModuleAlgo::execute(DDCompactView& cpv) {
0130 #ifdef EDM_ML_DEBUG
0131   edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDAHcalModuleAlgo...";
0132 #endif
0133   constructLayers(parent(), cpv);
0134 #ifdef EDM_ML_DEBUG
0135   edm::LogVerbatim("HGCalGeom") << "<<== End of DDAHcalModuleAlgo construction";
0136 #endif
0137 }
0138 
0139 void DDAHcalModuleAlgo::constructLayers(const DDLogicalPart& module, DDCompactView& cpv) {
0140 #ifdef EDM_ML_DEBUG
0141   edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo test: \t\tInside Layers";
0142 #endif
0143   double zi(zMinBlock_);
0144   int laymin(0);
0145   for (unsigned int i = 0; i < layers_.size(); i++) {
0146     double zo = zi + layerThick_[i];
0147     int laymax = laymin + layers_[i];
0148     double zz = zi;
0149     double thickTot(0);
0150     for (int ly = laymin; ly < laymax; ++ly) {
0151       int ii = layerType_[ly];
0152       int copy = copyNumber_[ii];
0153       zz += (0.5 * thick_[ii]);
0154       thickTot += thick_[ii];
0155 
0156       std::string name = "HGCal" + names_[ii] + std::to_string(copy);
0157 #ifdef EDM_ML_DEBUG
0158       edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo test: Layer " << ly << ":" << ii << " Front " << zi
0159                                     << " Back " << zo << " superlayer thickness " << layerThick_[i];
0160 #endif
0161       DDName matName(DDSplit(materials_[ii]).first, DDSplit(materials_[ii]).second);
0162       DDMaterial matter(matName);
0163       DDLogicalPart glog;
0164       if (layerSense_[ly] == 0) {
0165         DDSolid solid =
0166             DDSolidFactory::box(DDName(name, idNameSpace_), 0.5 * widths_[0], 0.5 * heights_[0], 0.5 * thick_[ii]);
0167         glog = DDLogicalPart(solid.ddname(), matter, solid);
0168 #ifdef EDM_ML_DEBUG
0169         edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << solid.name() << " Box made of " << matName
0170                                       << " of dimensions " << 0.5 * widths_[0] << ", " << 0.5 * heights_[0] << ", "
0171                                       << 0.5 * thick_[ii];
0172 #endif
0173       } else {
0174         DDSolid solid =
0175             DDSolidFactory::box(DDName(name, idNameSpace_), 0.5 * widths_[1], 0.5 * heights_[1], 0.5 * thick_[ii]);
0176         glog = DDLogicalPart(solid.ddname(), matter, solid);
0177 #ifdef EDM_ML_DEBUG
0178         edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << solid.name() << " Box made of " << matName
0179                                       << " of dimensions " << 0.5 * widths_[1] << ", " << 0.5 * heights_[1] << ", "
0180                                       << 0.5 * thick_[ii];
0181 #endif
0182         positionSensitive(glog, cpv);
0183       }
0184       DDTranslation r1(0, 0, zz);
0185       DDRotation rot;
0186       cpv.position(glog, module, copy, r1, rot);
0187       ++copyNumber_[ii];
0188 #ifdef EDM_ML_DEBUG
0189       edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << glog.name() << " number " << copy << " positioned in "
0190                                     << module.name() << " at " << r1 << " with " << rot;
0191 #endif
0192       zz += (0.5 * thick_[ii]);
0193     }  // End of loop over layers in a block
0194     zi = zo;
0195     laymin = laymax;
0196     if (fabs(thickTot - layerThick_[i]) > tol_) {
0197       if (thickTot > layerThick_[i]) {
0198         edm::LogError("HGCalGeom") << "Thickness of the partition " << layerThick_[i] << " is smaller than thickness "
0199                                    << thickTot << " of all its components **** ERROR ****\n";
0200       } else {
0201         edm::LogWarning("HGCalGeom") << "Thickness of the partition " << layerThick_[i] << " does not match with "
0202                                      << thickTot << " of the components\n";
0203       }
0204     }
0205   }  // End of loop over blocks
0206 }
0207 
0208 void DDAHcalModuleAlgo::positionSensitive(DDLogicalPart& glog, DDCompactView& cpv) {
0209   int ncol = tileN_[0] / 2;
0210   int nrow = tileN_[1] / 2;
0211 #ifdef EDM_ML_DEBUG
0212   int kount(0);
0213   edm::LogVerbatim("HGCalGeom") << glog.ddname() << " Row " << nrow << " Column " << ncol;
0214 #endif
0215   for (int nr = -nrow; nr <= nrow; ++nr) {
0216     int inr = (nr >= 0) ? nr : -nr;
0217     double ypos = (nr >= 0) ? (inr - 0.5) * tileStep_[1] : -(inr - 0.5) * tileStep_[1];
0218     for (int nc = -ncol; nc <= ncol; ++nc) {
0219       int inc = (nc >= 0) ? nc : -nc;
0220       double xpos = (nc >= 0) ? (inc - 0.5) * tileStep_[0] : -(inc - 0.5) * tileStep_[0];
0221       if (nr != 0 && nc != 0) {
0222         DDTranslation tran(xpos, ypos, 0.0);
0223         DDRotation rotation;
0224         int copy = inr * AHCalParameters::kColumn_ + inc;
0225         if (nc < 0)
0226           copy += AHCalParameters::kRowColumn_;
0227         if (nr < 0)
0228           copy += AHCalParameters::kSignRowColumn_;
0229         DDName name = DDName(DDSplit(tile_).first, DDSplit(tile_).second);
0230         cpv.position(name, glog.ddname(), copy, tran, rotation);
0231 #ifdef EDM_ML_DEBUG
0232         kount++;
0233         edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << name << " number " << copy << " positioned in "
0234                                       << glog.ddname() << " at " << tran << " with " << rotation;
0235 #endif
0236       }
0237     }
0238   }
0239 #ifdef EDM_ML_DEBUG
0240   edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << kount << " tiles for " << glog.ddname();
0241 #endif
0242 }
0243 
0244 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDAHcalModuleAlgo, "hgcal:DDAHcalModuleAlgo");