Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:08:11

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDHCalLinearXY.cc
0003 // Description: Position nxXny copies at given intervals along x and y axis
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/DDCurrentNamespace.h"
0015 #include "DetectorDescription/Core/interface/DDSplit.h"
0016 #include "DetectorDescription/Core/interface/DDTypes.h"
0017 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0018 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0019 
0020 //#define EDM_ML_DEBUG
0021 
0022 class DDHCalLinearXY : public DDAlgorithm {
0023 public:
0024   //Constructor and Destructor
0025   DDHCalLinearXY();
0026   ~DDHCalLinearXY() override;
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 
0034   void execute(DDCompactView& cpv) override;
0035 
0036 private:
0037   std::string idNameSpace;             //Namespace of this and ALL sub-parts
0038   std::vector<std::string> childName;  //Child name
0039   int numberX;                         //Number of positioning along X-axis
0040   double deltaX;                       //Increment               .........
0041   int numberY;                         //Number of positioning along Y-axis
0042   double deltaY;                       //Increment               .........
0043   std::vector<double> centre;          //Centre
0044 };
0045 
0046 DDHCalLinearXY::DDHCalLinearXY() {
0047 #ifdef EDM_ML_DEBUG
0048   edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: Creating an instance";
0049 #endif
0050 }
0051 
0052 DDHCalLinearXY::~DDHCalLinearXY() {}
0053 
0054 void DDHCalLinearXY::initialize(const DDNumericArguments& nArgs,
0055                                 const DDVectorArguments& vArgs,
0056                                 const DDMapArguments&,
0057                                 const DDStringArguments& sArgs,
0058                                 const DDStringVectorArguments& vsArgs) {
0059   numberX = int(nArgs["NumberX"]);
0060   deltaX = nArgs["DeltaX"];
0061   numberY = int(nArgs["NumberY"]);
0062   deltaY = nArgs["DeltaY"];
0063   centre = vArgs["Center"];
0064 
0065   idNameSpace = DDCurrentNamespace::ns();
0066   childName = vsArgs["Child"];
0067 #ifdef EDM_ML_DEBUG
0068   edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: Parent " << parent().name() << "\twith " << childName.size()
0069                                << " children";
0070   for (unsigned int i = 0; i < childName.size(); ++i)
0071     edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: Child[" << i << "] = " << childName[i];
0072   edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: NameSpace " << idNameSpace << "\tNumber along X/Y " << numberX << "/"
0073                                << numberY << "\tDelta along X/Y " << deltaX << "/" << deltaY << "\tCentre " << centre[0]
0074                                << ", " << centre[1] << ", " << centre[2];
0075 #endif
0076 }
0077 
0078 void DDHCalLinearXY::execute(DDCompactView& cpv) {
0079   DDName mother = parent().name();
0080   DDName child;
0081   DDRotation rot;
0082   double xoff = centre[0] - (numberX - 1) * deltaX / 2.;
0083   double yoff = centre[1] - (numberY - 1) * deltaY / 2.;
0084   int copy = 0;
0085 
0086   for (int i = 0; i < numberX; i++) {
0087     for (int j = 0; j < numberY; j++) {
0088       DDTranslation tran(xoff + i * deltaX, yoff + j * deltaY, centre[2]);
0089       bool place = true;
0090       unsigned int k = copy;
0091       if (childName.size() == 1)
0092         k = 0;
0093       if (k < childName.size() && (childName[k] != " " && childName[k] != "Null")) {
0094         child = DDName(DDSplit(childName[k]).first, DDSplit(childName[k]).second);
0095       } else {
0096         place = false;
0097       }
0098       copy++;
0099       if (place) {
0100         cpv.position(child, mother, copy, tran, rot);
0101 #ifdef EDM_ML_DEBUG
0102         edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: " << child << " number " << copy << " positioned in " << mother
0103                                      << " at " << tran << " with " << rot;
0104 #endif
0105       } else {
0106 #ifdef EDM_ML_DEBUG
0107         edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: No child placed for [" << copy << "]";
0108 #endif
0109       }
0110     }
0111   }
0112 }
0113 
0114 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHCalLinearXY, "hcal:DDHCalLinearXY");