CMS 3D CMS Logo

DDHCalTestBeamAlgo.cc
Go to the documentation of this file.
1 // File: DDHCalTestBeamAlgo.cc
3 // Description: Position inside the mother according to (eta,phi)
5 
6 #include <cmath>
7 #include <algorithm>
8 #include <map>
9 #include <string>
10 #include <vector>
11 
20 
21 //#define EDM_ML_DEBUG
22 using namespace geant_units::operators;
23 
24 class DDHCalTestBeamAlgo : public DDAlgorithm {
25 public:
26  //Constructor and Destructor
28  ~DDHCalTestBeamAlgo() override;
29 
30  void initialize(const DDNumericArguments& nArgs,
31  const DDVectorArguments& vArgs,
32  const DDMapArguments& mArgs,
33  const DDStringArguments& sArgs,
34  const DDStringVectorArguments& vsArgs) override;
35 
36  void execute(DDCompactView& cpv) override;
37 
38 private:
39  double eta; //Eta at which beam is focussed
40  double phi; //Phi ................
41  double theta; //Corresponding theta value
42  double distance; //Distance of the centre of rotation
43  double distanceZ; //Distance along x-axis of the centre of rotation
44  double dist; //Overall distance
45  double dz; //Half length along z of the volume to be placed
46  int copyNumber; //Copy Number
47 
48  std::string idNameSpace; //Namespace of this and ALL sub-parts
49  std::string childName; //Children name
50 };
51 
53 #ifdef EDM_ML_DEBUG
54  edm::LogVerbatim("HCalGeom") << "DDHCalTestBeamAlgo: Creating an instance";
55 #endif
56 }
57 
59 
61  const DDVectorArguments&,
62  const DDMapArguments&,
63  const DDStringArguments& sArgs,
64  const DDStringVectorArguments&) {
65  eta = nArgs["Eta"];
66  theta = 2.0 * atan(exp(-eta));
67  phi = nArgs["Phi"];
68  distance = nArgs["Dist"];
69  distanceZ = nArgs["DistZ"];
70  dz = nArgs["Dz"];
71  copyNumber = int(nArgs["Number"]);
72  dist = (distance + distanceZ / sin(theta));
73 #ifdef EDM_ML_DEBUG
74  edm::LogVerbatim("HCalGeom") << "DDHCalTestBeamAlgo: Parameters for position"
75  << "ing--"
76  << " Eta " << eta << "\tPhi " << convertRadToDeg(phi) << "\tTheta "
77  << convertRadToDeg(theta) << "\tDistance " << distance << "/" << distanceZ << "/" << dist
78  << "\tDz " << dz << "\tcopyNumber " << copyNumber;
79 #endif
80  idNameSpace = DDCurrentNamespace::ns();
81  childName = sArgs["ChildName"];
82 #ifdef EDM_ML_DEBUG
83  edm::LogVerbatim("HCalGeom") << "DDHCalTestBeamAlgo:Parent " << parent().name() << "\tChild " << childName
84  << " NameSpace " << idNameSpace;
85 #endif
86 }
87 
89  double thetax = 90._deg + theta;
90  double sthx = sin(thetax);
91  if (std::abs(sthx) > 1.e-12)
92  sthx = 1. / sthx;
93  else
94  sthx = 1.;
95  double phix = atan2(sthx * cos(theta) * sin(phi), sthx * cos(theta) * cos(phi));
96  double thetay = 90._deg;
97  double phiy = 90._deg + phi;
98  double thetaz = theta;
99  double phiz = phi;
100 
102  std::string rotstr = childName;
103 #ifdef EDM_ML_DEBUG
104  edm::LogVerbatim("HCalGeom") << "DDHCalTestBeamAlgo: Creating a rotation " << rotstr << "\t"
105  << convertRadToDeg(thetax) << "," << convertRadToDeg(phix) << ","
106  << convertRadToDeg(thetay) << "," << convertRadToDeg(phiy) << ","
107  << convertRadToDeg(thetaz) << "," << convertRadToDeg(phiz);
108 #endif
109  rotation = DDrot(DDName(rotstr, idNameSpace), thetax, phix, thetay, phiy, thetaz, phiz);
110 
111  double r = dist * sin(theta);
112  double xpos = r * cos(phi);
113  double ypos = r * sin(phi);
114  double zpos = dist * cos(theta);
115  DDTranslation tran(xpos, ypos, zpos);
116 
117  DDName parentName = parent().name();
118  cpv.position(DDName(childName, idNameSpace), parentName, copyNumber, tran, rotation);
119 #ifdef EDM_ML_DEBUG
120  edm::LogVerbatim("HCalGeom") << "DDHCalTestBeamAlgo: " << DDName(childName, idNameSpace) << " number " << copyNumber
121  << " positioned in " << parentName << " at " << tran << " with " << rotation;
122 
123  xpos = (dist - dz) * sin(theta) * cos(phi);
124  ypos = (dist - dz) * sin(theta) * sin(phi);
125  zpos = (dist - dz) * cos(theta);
126 
127  edm::LogInfo("HCalGeom") << "DDHCalTestBeamAlgo: Suggested Beam position "
128  << "(" << xpos << ", " << ypos << ", " << zpos << ") and (dist, eta, phi) = (" << (dist - dz)
129  << ", " << eta << ", " << phi << ")";
130 #endif
131 }
132 
133 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHCalTestBeamAlgo, "hcal:DDHCalTestBeamAlgo");
static AlgebraicMatrix initialize()
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
static std::string & ns()
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
~DDHCalTestBeamAlgo() override
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
DDRotation DDrot(const DDName &name, std::unique_ptr< DDRotationMatrix > rot)
Definition of a uniquely identifiable rotation matrix named by DDName name.
Definition: DDRotation.cc:67
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=0)
#define DEFINE_EDM_PLUGIN(factory, type, name)
void execute(DDCompactView &cpv) override