Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:50:12

0001 #ifndef Geometry_TrackerNumberingBuilder_GeometricDet_H
0002 #define Geometry_TrackerNumberingBuilder_GeometricDet_H
0003 
0004 #include "CondFormats/GeometryObjects/interface/PGeometricDet.h"
0005 #include "DetectorDescription/DDCMS/interface/DDSolidShapes.h"
0006 #include "DataFormats/GeometrySurface/interface/Surface.h"
0007 #include "DataFormats/GeometrySurface/interface/Bounds.h"
0008 #include "DataFormats/DetId/interface/DetId.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 #include "FWCore/ParameterSet/interface/types.h"
0011 
0012 #include <DD4hep/Shapes.h>
0013 #include <Math/Rotation3D.h>
0014 #include <Math/Vector3D.h>
0015 
0016 #include <vector>
0017 #include <memory>
0018 #include <ext/pool_allocator.h>
0019 
0020 class DDFilteredView;
0021 
0022 namespace cms {
0023   class DDFilteredView;
0024 }
0025 
0026 /**
0027  * Composite class GeometricDet. A composite can contain other composites, and so on;
0028  * You can understand what you are looking at via enum.
0029  */
0030 
0031 class GeometricDet {
0032 public:
0033   using NavRange = std::pair<int const*, size_t>;
0034   using ConstGeometricDetContainer = std::vector<GeometricDet const*>;
0035   using GeometricDetContainer = std::vector<GeometricDet*>;
0036   using RotationMatrix = ROOT::Math::Rotation3D;
0037   using Translation = ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<double> >;
0038 
0039 #ifdef PoolAlloc
0040   using nav_type = std::vector<int, PoolAlloc<int> >;
0041 #else
0042   using nav_type = std::vector<int>;
0043 #endif
0044 
0045   using Position = Surface::PositionType;
0046   using Rotation = Surface::RotationType;
0047 
0048   typedef enum GDEnumType {
0049     unknown = 100,
0050     Tracker = 0,
0051     PixelBarrel = 1,
0052     PixelEndCap = 2,
0053     TIB = 3,
0054     TID = 4,
0055     TOB = 5,
0056     TEC = 6,
0057     layer = 8,
0058     wheel = 9,
0059     strng = 10,
0060     rod = 11,
0061     petal = 12,
0062     ring = 13,
0063     ladder = 14,
0064     mergedDet = 15,
0065     DetUnit = 16,
0066     disk = 17,
0067     panel = 18,
0068     PixelPhase1Barrel = 101,
0069     PixelPhase1EndCap = 102,
0070     PixelPhase1Disk = 117,
0071     ITPhase2Combined = 180,
0072     OTPhase2EndCap = 204,
0073     OTPhase2Barrel = 205,
0074     OTPhase2Layer = 208,
0075     OTPhase2Stack = 215,
0076     PixelPhase2Barrel = 201,
0077     PixelPhase2EndCap = 202,
0078     OTPhase2Wheel = 209,
0079     PixelPhase2FullDisk = 217,
0080     PixelPhase2ReducedDisk = 227,
0081     PixelPhase2TDRDisk = 237,
0082     PixelPhase2DoubleDisk = 347,
0083     PixelPhase2SubDisk = 357
0084   } GeometricEnumType;
0085 
0086   // Constructors from Filtered View (called while looping over DD).
0087   GeometricDet(DDFilteredView* fv, GeometricEnumType dd);
0088   GeometricDet(cms::DDFilteredView* fv, GeometricEnumType dd);
0089   // Constructors from persistent data (from DB)
0090   GeometricDet(const PGeometricDet::Item& onePGD, GeometricEnumType dd);
0091 
0092   // ACCESS GENERAL INFO
0093   const std::string& name() const { return ddname_; }
0094   const GeometricEnumType& type() const { return type_; }
0095 
0096   // NAVIGATION related info
0097   const nav_type& navType() const { return ddd_; }
0098   NavRange navpos() const { return NavRange(&ddd_.front(), ddd_.size()); }
0099   const DetId& geographicalId() const { return geographicalID_; }
0100   void setGeographicalID(DetId id) { geographicalID_ = id; }
0101 
0102   // VOLUME POSITION in CMS frame of reference
0103   const Translation& translation() const { return trans_; }  // in mm
0104   double rho() const { return rho_; }                        // in mm
0105   double phi() const { return phi_; }
0106   const RotationMatrix& rotation() const { return rot_; }
0107 
0108   // BOUNDS
0109   std::unique_ptr<Bounds> bounds() const;
0110   Position positionBounds() const;  // in cm
0111   Rotation rotationBounds() const;
0112 
0113   // SOLID SHAPE
0114   // old DD
0115   LegacySolidShape shape() const { return cms::dd::value(cms::LegacySolidShapeMap, shape_); }
0116   // DD4hep
0117   const cms::DDSolidShape& shape_dd4hep() const { return shape_; }
0118   // solid shape parameters
0119   const std::vector<double>& params() const {
0120     if (shape_ != cms::DDSolidShape::ddbox && shape_ != cms::DDSolidShape::ddtrap &&
0121         shape_ != cms::DDSolidShape::ddtubs) {
0122       edm::LogError("GeometricDet::params()")
0123           << "Called on a shape which is neither a box, a trap, nor a tub. This is not supported!";
0124     }
0125     return params_;
0126   }  // in mm
0127 
0128   // RADIATION LENGTH AND ENERGY LOSS
0129   double radLength() const { return radLength_; }
0130   double xi() const { return xi_; }
0131 
0132   // SENSOR INFO
0133   // Only return meaningful results for pixels.
0134   double pixROCRows() const { return pixROCRows_; }
0135   double pixROCCols() const { return pixROCCols_; }
0136   double pixROCx() const { return pixROCx_; }
0137   double pixROCy() const { return pixROCy_; }
0138   // Only return meaningful results for Outer Trackers.
0139   bool stereo() const { return stereo_; }
0140   bool isLowerSensor() const { return isLowerSensor_; }
0141   bool isUpperSensor() const { return isUpperSensor_; }
0142   bool isFirstSensor() const { return isFirstSensor_; }
0143   bool isSecondSensor() const { return isSecondSensor_; }
0144   double siliconAPVNum() const { return siliconAPVNum_; }
0145 
0146   // DETECTOR DESCRIPTION ORIGIN INFO
0147   bool isFromDD4hep() const { return isFromDD4hep_; }
0148 
0149   // CHILDREN INFO
0150   GeometricDet* component(size_t index) { return const_cast<GeometricDet*>(container_[index]); }
0151   bool isLeaf() const { return container_.empty(); }
0152   // direct children only
0153   // if the current GeometricDet is a leaf, it returns nothing.
0154   ConstGeometricDetContainer& components() { return container_; }
0155   const ConstGeometricDetContainer& components() const { return container_; }
0156   // all descendants
0157   // if the current GeometricDet is a leaf, it returns itself!
0158   ConstGeometricDetContainer deepComponents() const;
0159   void deepComponents(ConstGeometricDetContainer& cont) const;
0160 
0161   // PUBLIC SETTERS (they should obviously be as few as possible!!)
0162   void addComponents(GeometricDetContainer const& cont);
0163   void addComponents(ConstGeometricDetContainer const& cont);
0164   void addComponent(GeometricDet*);
0165   void clearComponents() { container_.clear(); }  // only empties the container, THE CHILDREN ARE NOT DELETED!
0166   void deleteComponents();                        // EXPLICITLY DELETES THE CHILDREN
0167 
0168   // CUSTOM DESTRUCTOR
0169   ~GeometricDet();
0170 
0171   // Utility function
0172   static std::string printNavType(int const* n, size_t sz);
0173 
0174 private:
0175   std::vector<double> computeLegacyShapeParameters(const cms::DDSolidShape& mySolidShape,
0176                                                    const dd4hep::Solid& mySolid) const;
0177 
0178   std::string ddname_;
0179   GeometricEnumType type_;
0180 
0181   nav_type ddd_;
0182   DetId geographicalID_ = 0;
0183 
0184   Translation trans_;  // in mm
0185   double rho_ = 0.;    // in mm
0186   double phi_ = 0.;
0187   RotationMatrix rot_;
0188 
0189   cms::DDSolidShape shape_;
0190   std::vector<double> params_;  // in mm
0191 
0192   double radLength_ = 0.;
0193   double xi_ = 0.;
0194   double pixROCRows_ = 0.;
0195   double pixROCCols_ = 0.;
0196   double pixROCx_ = 0.;
0197   double pixROCy_ = 0.;
0198   bool stereo_ = false;
0199   bool isLowerSensor_ = false;
0200   bool isUpperSensor_ = false;
0201   bool isFirstSensor_ = false;
0202   bool isSecondSensor_ = false;
0203   double siliconAPVNum_ = 0.;
0204 
0205   bool isFromDD4hep_ = false;
0206 
0207   ConstGeometricDetContainer container_;
0208 };
0209 
0210 namespace geometric_det_ns {
0211   inline std::ostream& operator<<(std::ostream& os, const GeometricDet::NavRange& n) {
0212     os << GeometricDet::printNavType(n.first, n.second);
0213     return os;
0214   }
0215 }  // namespace geometric_det_ns
0216 
0217 #undef PoolAlloc
0218 #endif