Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDHCalForwardAlgo.cc
0003 // Description: Cable mockup between barrel and endcap gap
0004 ///////////////////////////////////////////////////////////////////////////////
0005 
0006 #include <cmath>
0007 #include <algorithm>
0008 #include <map>
0009 #include <string>
0010 #include <vector>
0011 
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 #include "FWCore/PluginManager/interface/PluginFactory.h"
0014 #include "DetectorDescription/Core/interface/DDutils.h"
0015 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0016 #include "DetectorDescription/Core/interface/DDSolid.h"
0017 #include "DetectorDescription/Core/interface/DDMaterial.h"
0018 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0019 #include "DetectorDescription/Core/interface/DDSplit.h"
0020 #include "DetectorDescription/Core/interface/DDTypes.h"
0021 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0022 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0023 
0024 //#define EDM_ML_DEBUG
0025 
0026 class DDHCalForwardAlgo : public DDAlgorithm {
0027 public:
0028   //Constructor and Destructor
0029   DDHCalForwardAlgo();  //const std::string & name);
0030   ~DDHCalForwardAlgo() override;
0031 
0032   void initialize(const DDNumericArguments& nArgs,
0033                   const DDVectorArguments& vArgs,
0034                   const DDMapArguments& mArgs,
0035                   const DDStringArguments& sArgs,
0036                   const DDStringVectorArguments& vsArgs) override;
0037 
0038   void execute(DDCompactView& cpv) override;
0039 
0040 private:
0041   std::string cellMat;                 //Cell material
0042   double cellDx, cellDy, cellDz;       //Cell size
0043   double startY;                       //Starting Y for Cell
0044   std::vector<std::string> childName;  //Children name
0045   std::vector<int> number;             //Number of cells
0046   std::vector<int> size;               //Number of children
0047   std::vector<int> type;               //First child
0048 
0049   std::string idNameSpace;  //Namespace for aLL sub-parts
0050 };
0051 
0052 DDHCalForwardAlgo::DDHCalForwardAlgo() : number(0), size(0), type(0) {
0053 #ifdef EDM_ML_DEBUG
0054   edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo: Creating an instance";
0055 #endif
0056 }
0057 
0058 DDHCalForwardAlgo::~DDHCalForwardAlgo() {}
0059 
0060 void DDHCalForwardAlgo::initialize(const DDNumericArguments& nArgs,
0061                                    const DDVectorArguments& vArgs,
0062                                    const DDMapArguments&,
0063                                    const DDStringArguments& sArgs,
0064                                    const DDStringVectorArguments& vsArgs) {
0065   cellMat = sArgs["CellMaterial"];
0066   cellDx = nArgs["CellDx"];
0067   cellDy = nArgs["CellDy"];
0068   cellDz = nArgs["CellDz"];
0069   startY = nArgs["StartY"];
0070 
0071   childName = vsArgs["Child"];
0072   number = dbl_to_int(vArgs["Number"]);
0073   size = dbl_to_int(vArgs["Size"]);
0074   type = dbl_to_int(vArgs["Type"]);
0075 
0076 #ifdef EDM_ML_DEBUG
0077   edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo: Cell material " << cellMat << "\tCell Size " << cellDx << ", "
0078                                << cellDy << ", " << cellDz << "\tStarting Y " << startY << "\tChildren " << childName[0]
0079                                << ", " << childName[1] << "\n               "
0080                                << "          Cell positioning done for " << number.size() << " times";
0081   for (unsigned int i = 0; i < number.size(); i++)
0082     edm::LogVerbatim("HCalGeom") << "\t" << i << " Number of children " << size[i] << " occurence " << number[i]
0083                                  << " first child index " << type[i];
0084 #endif
0085   idNameSpace = DDCurrentNamespace::ns();
0086 #ifdef EDM_ML_DEBUG
0087   edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo debug: Parent " << parent().name() << " NameSpace " << idNameSpace;
0088 #endif
0089 }
0090 
0091 void DDHCalForwardAlgo::execute(DDCompactView& cpv) {
0092 #ifdef EDM_ML_DEBUG
0093   edm::LogVerbatim("HCalGeom") << "==>> Constructing DDHCalForwardAlgo...";
0094 #endif
0095   DDName parentName = parent().name();
0096   double ypos = startY;
0097   int box = 0;
0098 
0099   for (unsigned int i = 0; i < number.size(); i++) {
0100     double dx = cellDx * size[i];
0101     int indx = type[i];
0102     for (int j = 0; j < number[i]; j++) {
0103       box++;
0104       std::string name = parentName.name() + std::to_string(box);
0105       DDSolid solid = DDSolidFactory::box(DDName(name, idNameSpace), dx, cellDy, cellDz);
0106 #ifdef EDM_ML_DEBUG
0107       edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo: " << DDName(name, idNameSpace) << " Box made of " << cellMat
0108                                    << " of Size " << dx << ", " << cellDy << ", " << cellDz;
0109 #endif
0110       DDName matname(DDSplit(cellMat).first, DDSplit(cellMat).second);
0111       DDMaterial matter(matname);
0112       DDLogicalPart genlogic(solid.ddname(), matter, solid);
0113 
0114       DDTranslation r0(0.0, ypos, 0.0);
0115       DDRotation rot;
0116       cpv.position(solid.ddname(), parentName, box, r0, rot);
0117 #ifdef EDM_ML_DEBUG
0118       edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo: " << solid.ddname() << " number " << box << " positioned in "
0119                                    << parentName << " at " << r0 << " with " << rot;
0120 #endif
0121       DDName child(DDSplit(childName[indx]).first, DDSplit(childName[indx]).second);
0122       double xpos = -dx + cellDx;
0123       ypos += 2 * cellDy;
0124       indx = 1 - indx;
0125 
0126       for (int k = 0; k < size[i]; k++) {
0127         DDTranslation r1(xpos, 0.0, 0.0);
0128         cpv.position(child, solid.ddname(), k + 1, r1, rot);
0129 #ifdef EDM_ML_DEBUG
0130         edm::LogVerbatim("HCalGeom") << "DDHCalForwardAlgo: " << child << " number " << k + 1 << " positioned in "
0131                                      << solid.ddname() << " at " << r1 << " with " << rot;
0132 #endif
0133         xpos += 2 * cellDx;
0134       }
0135     }
0136   }
0137 #ifdef EDM_ML_DEBUG
0138   edm::LogVerbatim("HCalGeom") << "<<== End of DDHCalForwardAlgo construction";
0139 #endif
0140 }
0141 
0142 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHCalForwardAlgo, "hcal:DDHCalForwardAlgo");