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