Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-14 22:36:08

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     OTPhase2EndCap = 204,
0072     OTPhase2Barrel = 205,
0073     OTPhase2Layer = 208,
0074     OTPhase2Stack = 215,
0075     PixelPhase2Barrel = 201,
0076     PixelPhase2EndCap = 202,
0077     OTPhase2Wheel = 209,
0078     PixelPhase2FullDisk = 217,
0079     PixelPhase2ReducedDisk = 227,
0080     PixelPhase2TDRDisk = 237,
0081     PixelPhase2DoubleDisk = 347,
0082     PixelPhase2SubDisk = 357
0083   } GeometricEnumType;
0084 
0085   // Constructors from Filtered View (called while looping over DD).
0086   GeometricDet(DDFilteredView* fv, GeometricEnumType dd);
0087   GeometricDet(cms::DDFilteredView* fv, GeometricEnumType dd);
0088   // Constructors from persistent data (from DB)
0089   GeometricDet(const PGeometricDet::Item& onePGD, GeometricEnumType dd);
0090 
0091   // ACCESS GENERAL INFO
0092   const std::string& name() const { return ddname_; }
0093   const GeometricEnumType& type() const { return type_; }
0094 
0095   // NAVIGATION related info
0096   const nav_type& navType() const { return ddd_; }
0097   NavRange navpos() const { return NavRange(&ddd_.front(), ddd_.size()); }
0098   const DetId& geographicalId() const { return geographicalID_; }
0099   void setGeographicalID(DetId id) { geographicalID_ = id; }
0100 
0101   // VOLUME POSITION in CMS frame of reference
0102   const Translation& translation() const { return trans_; }  // in mm
0103   double rho() const { return rho_; }                        // in mm
0104   double phi() const { return phi_; }
0105   const RotationMatrix& rotation() const { return rot_; }
0106 
0107   // BOUNDS
0108   std::unique_ptr<Bounds> bounds() const;
0109   Position positionBounds() const;  // in cm
0110   Rotation rotationBounds() const;
0111 
0112   // SOLID SHAPE
0113   // old DD
0114   LegacySolidShape shape() const { return cms::dd::value(cms::LegacySolidShapeMap, shape_); }
0115   // DD4hep
0116   const cms::DDSolidShape& shape_dd4hep() const { return shape_; }
0117   // solid shape parameters
0118   const std::vector<double>& params() const {
0119     if (shape_ != cms::DDSolidShape::ddbox && shape_ != cms::DDSolidShape::ddtrap &&
0120         shape_ != cms::DDSolidShape::ddtubs) {
0121       edm::LogError("GeometricDet::params()")
0122           << "Called on a shape which is neither a box, a trap, nor a tub. This is not supported!";
0123     }
0124     return params_;
0125   }  // in mm
0126 
0127   // RADIATION LENGTH AND ENERGY LOSS
0128   double radLength() const { return radLength_; }
0129   double xi() const { return xi_; }
0130 
0131   // SENSOR INFO
0132   // Only return meaningful results for pixels.
0133   bool isBricked() const { return isBricked_; }
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   double siliconAPVNum() const { return siliconAPVNum_; }
0143 
0144   // DETECTOR DESCRIPTION ORIGIN INFO
0145   bool isFromDD4hep() const { return isFromDD4hep_; }
0146 
0147   // CHILDREN INFO
0148   GeometricDet* component(size_t index) { return const_cast<GeometricDet*>(container_[index]); }
0149   bool isLeaf() const { return container_.empty(); }
0150   // direct children only
0151   // if the current GeometricDet is a leaf, it returns nothing.
0152   ConstGeometricDetContainer& components() { return container_; }
0153   const ConstGeometricDetContainer& components() const { return container_; }
0154   // all descendants
0155   // if the current GeometricDet is a leaf, it returns itself!
0156   ConstGeometricDetContainer deepComponents() const;
0157   void deepComponents(ConstGeometricDetContainer& cont) const;
0158 
0159   // PUBLIC SETTERS (they should obviously be as few as possible!!)
0160   void addComponents(GeometricDetContainer const& cont);
0161   void addComponents(ConstGeometricDetContainer const& cont);
0162   void addComponent(GeometricDet*);
0163   void clearComponents() { container_.clear(); }  // only empties the container, THE CHILDREN ARE NOT DELETED!
0164   void deleteComponents();                        // EXPLICITLY DELETES THE CHILDREN
0165 
0166   // CUSTOM DESTRUCTOR
0167   ~GeometricDet();
0168 
0169   // Utility function
0170   static std::string printNavType(int const* n, size_t sz);
0171 
0172 private:
0173   std::vector<double> computeLegacyShapeParameters(const cms::DDSolidShape& mySolidShape,
0174                                                    const dd4hep::Solid& mySolid) const;
0175 
0176   std::string ddname_;
0177   GeometricEnumType type_;
0178 
0179   nav_type ddd_;
0180   DetId geographicalID_ = 0;
0181 
0182   Translation trans_;  // in mm
0183   double rho_ = 0.;    // in mm
0184   double phi_ = 0.;
0185   RotationMatrix rot_;
0186 
0187   cms::DDSolidShape shape_;
0188   std::vector<double> params_;  // in mm
0189 
0190   double radLength_ = 0.;
0191   double xi_ = 0.;
0192   bool isBricked_ = false;
0193   double pixROCRows_ = 0.;
0194   double pixROCCols_ = 0.;
0195   double pixROCx_ = 0.;
0196   double pixROCy_ = 0.;
0197   bool stereo_ = false;
0198   bool isLowerSensor_ = false;
0199   bool isUpperSensor_ = false;
0200   double siliconAPVNum_ = 0.;
0201 
0202   bool isFromDD4hep_ = false;
0203 
0204   ConstGeometricDetContainer container_;
0205 };
0206 
0207 namespace geometric_det_ns {
0208   inline std::ostream& operator<<(std::ostream& os, const GeometricDet::NavRange& n) {
0209     os << GeometricDet::printNavType(n.first, n.second);
0210     return os;
0211   }
0212 }  // namespace geometric_det_ns
0213 
0214 #undef PoolAlloc
0215 #endif