Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:31

0001 /****************************************************************************
0002 *
0003 * Authors:
0004 *   Jan Kašpar (jan.kaspar@gmail.com)
0005 *   CMSSW developpers (based on class GeometricDet)
0006 *
0007 *  Rewritten + Moved out common functionalities to DetGeomDesc(Builder) by Gabrielle Hugo.
0008 *  Migrated to DD4hep by Gabrielle Hugo and Wagner Carvalho.
0009 *
0010 ****************************************************************************/
0011 
0012 #ifndef Geometry_VeryForwardGeometryBuilder_DetGeomDesc
0013 #define Geometry_VeryForwardGeometryBuilder_DetGeomDesc
0014 
0015 #include <utility>
0016 #include <vector>
0017 
0018 #include "DetectorDescription/Core/interface/DDFilteredView.h"
0019 #include "DetectorDescription/DDCMS/interface/DDFilteredView.h"
0020 #include "CondFormats/GeometryObjects/interface/PDetGeomDesc.h"
0021 
0022 #include "DataFormats/DetId/interface/DetId.h"
0023 #include <Math/Rotation3D.h>
0024 
0025 class CTPPSRPAlignmentCorrectionData;
0026 
0027 /**
0028  * \brief Geometrical description of a sensor.
0029  *
0030  * Class resembling GeometricDet class. Slight changes were made to suit needs of the TOTEM RP description.
0031  * Each instance is a tree node, with geometrical information from DDD (shift, rotation, material, ...), ID and list of children nodes.
0032  *
0033  * The <b>translation</b> and <b>rotation</b> parameters are defined by <b>local-to-global</b>
0034  * coordinate transform. That is, if r_l is a point in local coordinate system and x_g in global,
0035  * then the transform reads:
0036  \verbatim
0037     x_g = rotation * x_l + translation
0038  \endverbatim
0039  *
0040  * July 2020: Migrated to DD4hep
0041  * To avoid any regression with values from XMLs / Geant4, all lengths are converted from DD4hep unit to mm.
0042  *
0043  **/
0044 
0045 struct DiamondDimensions {
0046   double xHalfWidth;
0047   double yHalfWidth;
0048   double zHalfWidth;
0049 };
0050 
0051 class DetGeomDesc {
0052 public:
0053   using Container = std::vector<DetGeomDesc*>;
0054   using RotationMatrix = ROOT::Math::Rotation3D;
0055   using Translation = ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<double>>;
0056 
0057   // Constructor from old DD DDFilteredView
0058   /// \param[in] isRun2 Switch between legacy run 2-like geometry and 2021+ scenarii
0059   DetGeomDesc(const DDFilteredView& fv, const bool isRun2);
0060   // Constructor from DD4hep DDFilteredView
0061   /// \param[in] isRun2 Switch between legacy run 2-like geometry and 2021+ scenarii
0062   DetGeomDesc(const cms::DDFilteredView& fv, const bool isRun2);
0063   // Constructor from DB object PDetGeomDesc
0064   DetGeomDesc(const PDetGeomDesc& gd);
0065   // Constructor from DB object PDetGeomDesc::Item
0066   DetGeomDesc(const PDetGeomDesc::Item& item);
0067   virtual ~DetGeomDesc();
0068 
0069   enum CopyMode { cmWithChildren, cmWithoutChildren };
0070   DetGeomDesc(const DetGeomDesc& ref, CopyMode cm = cmWithChildren);
0071 
0072   // general info
0073   const std::string& name() const { return m_name; }
0074   int copyno() const { return m_copy; }
0075 
0076   // is DD4hep
0077   bool isDD4hep() const { return m_isDD4hep; }
0078 
0079   // placement info
0080   const Translation& translation() const { return m_trans; }  // in mm
0081   const RotationMatrix& rotation() const { return m_rot; }
0082 
0083   // shape info
0084   // params() is left for general access to solid shape parameters (any shape, not only box!).
0085   // Though, it should be used only with great care, for two reasons:
0086   // 1. Order of shape parameters may possibly change from a version of DD4hep to another.
0087   // 2. Among all parameters, those representing a length are expressed in mm (for old DD) or the DD4hep-configured unit (for DD4hep), while PPS uses mm.
0088   const std::vector<double>& params() const { return m_params; }  // default unit: mm for oldDD, DD4hep unit for DD4hep
0089   bool isABox() const { return m_isABox; }
0090   const DiamondDimensions& getDiamondDimensions() const {
0091     if (!isABox()) {
0092       edm::LogError("DetGeomDesc::getDiamondDimensions is not called on a box, for solid ")
0093           << name() << ", Id = " << geographicalID();
0094     }
0095     return m_diamondBoxParams;
0096   }  // in mm
0097 
0098   // sensor type
0099   const std::string& sensorType() const { return m_sensorType; }
0100 
0101   // ID info
0102   DetId geographicalID() const { return m_geographicalID; }
0103 
0104   // components (children) management
0105   const Container& components() const { return m_container; }
0106   float parentZPosition() const { return m_z; }  // in mm
0107   void addComponent(DetGeomDesc*);
0108   bool isLeaf() const { return m_container.empty(); }
0109 
0110   // alignment
0111   void applyAlignment(const CTPPSRPAlignmentCorrectionData&);
0112 
0113   void print() const;
0114 
0115   void invertZSign() { m_trans.SetZ(-m_trans.z()); }
0116 
0117 private:
0118   void deleteComponents();      // deletes just the first daughters
0119   void deepDeleteComponents();  // traverses the tree and deletes all nodes.
0120   void clearComponents() { m_container.resize(0); }
0121 
0122   std::string computeNameWithNoNamespace(std::string_view nameFromView) const;
0123   std::vector<double> computeParameters(const cms::DDFilteredView& fv) const;
0124   DiamondDimensions computeDiamondDimensions(const bool isABox,
0125                                              const bool isDD4hep,
0126                                              const std::vector<double>& params) const;
0127   DetId computeDetID(const std::string& name,
0128                      const std::vector<int>& copyNos,
0129                      const unsigned int copyNum,
0130                      const bool isRun2) const;
0131   DetId computeDetIDFromDD4hep(const std::string& name,
0132                                const std::vector<int>& copyNos,
0133                                const unsigned int copyNum,
0134                                const bool isRun2) const;
0135   std::string computeSensorType(std::string_view name);
0136 
0137   std::string m_name;  // with no namespace
0138   int m_copy;
0139   bool m_isDD4hep;
0140   Translation m_trans;  // in mm
0141   RotationMatrix m_rot;
0142   std::vector<double> m_params;  // default unit: mm from oldDD, DD4hep unit for DD4hep
0143   bool m_isABox;
0144   DiamondDimensions m_diamondBoxParams;  // in mm
0145   std::string m_sensorType;
0146   DetId m_geographicalID;
0147 
0148   Container m_container;
0149   float m_z;  // in mm
0150 };
0151 
0152 struct DetGeomDescCompare {
0153   bool operator()(const DetGeomDesc& a, const DetGeomDesc& b) const {
0154     return (a.geographicalID() != b.geographicalID()
0155                 ? a.geographicalID() < b.geographicalID()  // Sort by DetId
0156                 // If DetIds are identical (== 0 for non-sensors), sort by name and copy number.
0157                 : (a.name() != b.name() ? a.name() < b.name() : a.copyno() < b.copyno()));
0158   }
0159 };
0160 
0161 #endif