Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:30:07

0001 /*
0002  * DDAHcalModuleAlgo.cc
0003  *
0004  *  Created on: 27-August-2019
0005  *      Author: Sunanda Banerjee
0006  */
0007 #include "DataFormats/Math/interface/angle_units.h"
0008 #include "DD4hep/DetFactoryHelper.h"
0009 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0010 #include "DetectorDescription/DDCMS/interface/DDutils.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "FWCore/Utilities/interface/Exception.h"
0013 #include "Geometry/HGCalCommonData/interface/AHCalParameters.h"
0014 
0015 //#define EDM_ML_DEBUG
0016 using namespace angle_units::operators;
0017 
0018 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
0019   cms::DDNamespace ns(ctxt, e, true);
0020   cms::DDAlgoArguments args(ctxt, e);
0021   static constexpr double tol = 0.00001 * dd4hep::mm;
0022 
0023   const auto& tile = args.value<std::string>("TileName");                          // Scintillator tile
0024   const auto& materials = args.value<std::vector<std::string> >("MaterialNames");  // Materials
0025   const auto& names = args.value<std::vector<std::string> >("VolumeNames");        // Names
0026   const auto& thick = args.value<std::vector<double> >("Thickness");               // Thickness of the material
0027   std::vector<int> copyNumber;                                                     // Initial copy numbers
0028   copyNumber.resize(materials.size(), 1);
0029 #ifdef EDM_ML_DEBUG
0030   edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: Tile " << tile;
0031   edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << materials.size() << " types of volumes";
0032   for (unsigned int i = 0; i < names.size(); ++i)
0033     edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << names[i] << " of thickness "
0034                                   << cms::convert2mm(thick[i]) << " filled with " << materials[i]
0035                                   << " first copy number " << copyNumber[i];
0036 #endif
0037   const auto& layers = args.value<std::vector<int> >("Layers");             // Number of layers in a section
0038   const auto& layerThick = args.value<std::vector<double> >("LayerThick");  // Thickness of each section
0039   const auto& layerType = args.value<std::vector<int> >("LayerType");       // Type of the layer
0040   const auto& layerSense = args.value<std::vector<int> >("LayerSense");     // Content of a layer (sensitive?)
0041 #ifdef EDM_ML_DEBUG
0042   edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << layers.size() << " blocks";
0043   for (unsigned int i = 0; i < layers.size(); ++i)
0044     edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness " << cms::convert2mm(layerThick[i]) << " with "
0045                                   << layers[i] << " layers";
0046   edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << layerType.size() << " layers";
0047   for (unsigned int i = 0; i < layerType.size(); ++i)
0048     edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerType[i] << " sensitive class "
0049                                   << layerSense[i];
0050 #endif
0051   const auto& widths = args.value<std::vector<double> >("Widths");      // Width (passive, active)
0052   const auto& heights = args.value<std::vector<double> >("Heights");    // Heights (passive, active)
0053   const auto& tileN = args.value<std::vector<int> >("TileN");           // # of tiles (along x, y)
0054   const auto& tileStep = args.value<std::vector<double> >("TileStep");  // Separation between tiles (x, y)
0055 #ifdef EDM_ML_DEBUG
0056   edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << widths.size() << " sizes for width "
0057                                 << "and height:";
0058   for (unsigned int i = 0; i < widths.size(); ++i)
0059     edm::LogVerbatim("HGCalGeom") << " [" << i << "] " << cms::convert2mm(widths[i]) << ":"
0060                                   << cms::convert2mm(heights[i]);
0061   edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << tileN.size() << " tile positioning parameters";
0062   for (unsigned int i = 0; i < tileN.size(); ++i)
0063     edm::LogVerbatim("HGCalGeom") << " [" << i << "] " << tileN[i] << ":" << cms::convert2mm(tileStep[i]);
0064 #endif
0065   const auto& zMinBlock = args.value<double>("zMinBlock");  // Starting z-value of the block
0066 #ifdef EDM_ML_DEBUG
0067   edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: zStart " << cms::convert2mm(zMinBlock) << "  NameSpace "
0068                                 << ns.name();
0069 #endif
0070 
0071   // Mother module
0072   dd4hep::Volume module = ns.volume(args.parentName());
0073 
0074   double zi(zMinBlock);
0075   int laymin(0);
0076   for (unsigned int i = 0; i < layers.size(); i++) {
0077     double zo = zi + layerThick[i];
0078     int laymax = laymin + layers[i];
0079     double zz = zi;
0080     double thickTot(0);
0081     for (int ly = laymin; ly < laymax; ++ly) {
0082       int ii = layerType[ly];
0083       int copy = copyNumber[ii];
0084       zz += (0.5 * thick[ii]);
0085       thickTot += thick[ii];
0086 
0087       std::string name = "HGCal" + names[ii] + std::to_string(copy);
0088 #ifdef EDM_ML_DEBUG
0089       edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo test: Layer " << ly << ":" << ii << " Front "
0090                                     << cms::convert2mm(zi) << " Back " << cms::convert2mm(zo)
0091                                     << " superlayer thickness " << cms::convert2mm(layerThick[i]);
0092 #endif
0093       dd4hep::Material matter = ns.material(materials[ii]);
0094       dd4hep::Volume glog;
0095       if (layerSense[ly] == 0) {
0096         dd4hep::Solid solid = dd4hep::Box(0.5 * widths[0], 0.5 * heights[0], 0.5 * thick[ii]);
0097         ns.addSolidNS(ns.prepend(name), solid);
0098         glog = dd4hep::Volume(solid.name(), solid, matter);
0099 #ifdef EDM_ML_DEBUG
0100         edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << solid.name() << " Box made of " << materials[ii]
0101                                       << " of dimensions " << cms::convert2mm(0.5 * widths[0]) << ", "
0102                                       << cms::convert2mm(0.5 * heights[0]) << ", " << cms::convert2mm(0.5 * thick[ii]);
0103 #endif
0104       } else {
0105         dd4hep::Solid solid = dd4hep::Box(0.5 * widths[1], 0.5 * heights[1], 0.5 * thick[ii]);
0106         ns.addSolidNS(ns.prepend(name), solid);
0107         glog = dd4hep::Volume(solid.name(), solid, matter);
0108 #ifdef EDM_ML_DEBUG
0109         edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << solid.name() << " Box made of " << materials[ii]
0110                                       << " of dimensions " << cms::convert2mm(0.5 * widths[1]) << ", "
0111                                       << cms::convert2mm(0.5 * heights[1]) << ", " << cms::convert2mm(0.5 * thick[ii]);
0112 #endif
0113         int ncol = tileN[0] / 2;
0114         int nrow = tileN[1] / 2;
0115 #ifdef EDM_ML_DEBUG
0116         int kount(0);
0117         edm::LogVerbatim("HGCalGeom") << glog.name() << " Row " << nrow << " Column " << ncol;
0118 #endif
0119         for (int nr = -nrow; nr <= nrow; ++nr) {
0120           int inr = (nr >= 0) ? nr : -nr;
0121           double ypos = (nr >= 0) ? (inr - 0.5) * tileStep[1] : -(inr - 0.5) * tileStep[1];
0122           for (int nc = -ncol; nc <= ncol; ++nc) {
0123             int inc = (nc >= 0) ? nc : -nc;
0124             double xpos = (nc >= 0) ? (inc - 0.5) * tileStep[0] : -(inc - 0.5) * tileStep[0];
0125             if (nr != 0 && nc != 0) {
0126               dd4hep::Position tran(xpos, ypos, 0.0);
0127               dd4hep::Rotation3D rotation;
0128               int copy = inr * AHCalParameters::kColumn_ + inc;
0129               if (nc < 0)
0130                 copy += AHCalParameters::kRowColumn_;
0131               if (nr < 0)
0132                 copy += AHCalParameters::kSignRowColumn_;
0133               dd4hep::Volume glog1 = ns.volume(tile);
0134               glog.placeVolume(glog1, copy, dd4hep::Transform3D(rotation, tran));
0135 #ifdef EDM_ML_DEBUG
0136               kount++;
0137               edm::LogVerbatim("HGCalGeom")
0138                   << "DDAHcalModuleAlgo: " << tile << " number " << copy << " positioned in " << glog.name() << " at ("
0139                   << cms::convert2mm(xpos) << "," << cms::convert2mm(ypos) << ",0) with no rotation";
0140 #endif
0141             }
0142           }
0143         }
0144 #ifdef EDM_ML_DEBUG
0145         edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << kount << " tiles for " << glog.name();
0146 #endif
0147       }
0148       dd4hep::Position r1(0, 0, zz);
0149       module.placeVolume(glog, copy, r1);
0150       ++copyNumber[ii];
0151 #ifdef EDM_ML_DEBUG
0152       edm::LogVerbatim("HGCalGeom") << "DDAHcalModuleAlgo: " << glog.name() << " number " << copy << " positioned in "
0153                                     << module.name() << " at (0,0," << cms::convert2mm(zz) << ") with no rotation";
0154 #endif
0155       zz += (0.5 * thick[ii]);
0156     }  // End of loop over layers in a block
0157     zi = zo;
0158     laymin = laymax;
0159     if (fabs(thickTot - layerThick[i]) > tol) {
0160       if (thickTot > layerThick[i]) {
0161         edm::LogError("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(layerThick[i])
0162                                    << " is smaller than thickness " << cms::convert2mm(thickTot)
0163                                    << " of all its components **** ERROR ****\n";
0164       } else {
0165         edm::LogWarning("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(layerThick[i])
0166                                      << " does not match with " << cms::convert2mm(thickTot) << " of the components\n";
0167       }
0168     }
0169   }  // End of loop over blocks
0170 
0171   return cms::s_executed;
0172 }
0173 
0174 // first argument is the type from the xml file
0175 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDAHcalModuleAlgo, algorithm)