CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DDHCalLinearXY.cc
Go to the documentation of this file.
1 // File: DDHCalLinearXY.cc
3 // Description: Position nxXny copies at given intervals along x and y axis
5 
6 #include <cmath>
7 #include <algorithm>
8 #include <map>
9 #include <string>
10 #include <vector>
11 
19 
20 //#define EDM_ML_DEBUG
21 
22 class DDHCalLinearXY : public DDAlgorithm {
23 public:
24  //Constructor and Destructor
26  ~DDHCalLinearXY() override;
27 
28  void initialize(const DDNumericArguments& nArgs,
29  const DDVectorArguments& vArgs,
30  const DDMapArguments& mArgs,
31  const DDStringArguments& sArgs,
32  const DDStringVectorArguments& vsArgs) override;
33 
34  void execute(DDCompactView& cpv) override;
35 
36 private:
37  std::string idNameSpace; //Namespace of this and ALL sub-parts
38  std::vector<std::string> childName; //Child name
39  int numberX; //Number of positioning along X-axis
40  double deltaX; //Increment .........
41  int numberY; //Number of positioning along Y-axis
42  double deltaY; //Increment .........
43  std::vector<double> centre; //Centre
44 };
45 
47 #ifdef EDM_ML_DEBUG
48  edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: Creating an instance";
49 #endif
50 }
51 
53 
55  const DDVectorArguments& vArgs,
56  const DDMapArguments&,
57  const DDStringArguments& sArgs,
58  const DDStringVectorArguments& vsArgs) {
59  numberX = int(nArgs["NumberX"]);
60  deltaX = nArgs["DeltaX"];
61  numberY = int(nArgs["NumberY"]);
62  deltaY = nArgs["DeltaY"];
63  centre = vArgs["Center"];
64 
66  childName = vsArgs["Child"];
67 #ifdef EDM_ML_DEBUG
68  edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: Parent " << parent().name() << "\twith " << childName.size()
69  << " children";
70  for (unsigned int i = 0; i < childName.size(); ++i)
71  edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: Child[" << i << "] = " << childName[i];
72  edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: NameSpace " << idNameSpace << "\tNumber along X/Y " << numberX << "/"
73  << numberY << "\tDelta along X/Y " << deltaX << "/" << deltaY << "\tCentre " << centre[0]
74  << ", " << centre[1] << ", " << centre[2];
75 #endif
76 }
77 
79  DDName mother = parent().name();
80  DDName child;
82  double xoff = centre[0] - (numberX - 1) * deltaX / 2.;
83  double yoff = centre[1] - (numberY - 1) * deltaY / 2.;
84  int copy = 0;
85 
86  for (int i = 0; i < numberX; i++) {
87  for (int j = 0; j < numberY; j++) {
88  DDTranslation tran(xoff + i * deltaX, yoff + j * deltaY, centre[2]);
89  bool place = true;
90  unsigned int k = copy;
91  if (childName.size() == 1)
92  k = 0;
93  if (k < childName.size() && (childName[k] != " " && childName[k] != "Null")) {
95  } else {
96  place = false;
97  }
98  copy++;
99  if (place) {
100  cpv.position(child, mother, copy, tran, rot);
101 #ifdef EDM_ML_DEBUG
102  edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: " << child << " number " << copy << " positioned in " << mother
103  << " at " << tran << " with " << rot;
104 #endif
105  } else {
106 #ifdef EDM_ML_DEBUG
107  edm::LogVerbatim("HCalGeom") << "DDHCalLinearXY: No child placed for [" << copy << "]";
108 #endif
109  }
110  }
111  }
112 }
113 
114 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHCalLinearXY, "hcal:DDHCalLinearXY");
Log< level::Info, true > LogVerbatim
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=nullptr)
void execute(DDCompactView &cpv) override
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
static std::string & ns()
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
U second(std::pair< T, U > const &p)
std::vector< std::string > childName
~DDHCalLinearXY() override
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
std::string idNameSpace
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = &#39;:&#39;
Definition: DDSplit.cc:3
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
std::vector< double > centre