Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-22 04:03:05

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   int bigPixelsx() const { return bigPixelsx_; }
0139   int bigPixelsy() const { return bigPixelsy_; }
0140   float bigPixelsPitchx() const { return bigPixelsPitchx_; }
0141   float bigPixelsPitchy() const { return bigPixelsPitchy_; }
0142   bool isFirstSensor() const { return isFirstSensor_; }
0143   bool isSecondSensor() const { return isSecondSensor_; }
0144   // Only return meaningful results for Outer Trackers.
0145   bool stereo() const { return stereo_; }
0146   bool isLowerSensor() const { return isLowerSensor_; }
0147   bool isUpperSensor() const { return isUpperSensor_; }
0148   double siliconAPVNum() const { return siliconAPVNum_; }
0149 
0150   // DETECTOR DESCRIPTION ORIGIN INFO
0151   bool isFromDD4hep() const { return isFromDD4hep_; }
0152 
0153   // CHILDREN INFO
0154   GeometricDet* component(size_t index) { return const_cast<GeometricDet*>(container_[index]); }
0155   bool isLeaf() const { return container_.empty(); }
0156   // direct children only
0157   // if the current GeometricDet is a leaf, it returns nothing.
0158   ConstGeometricDetContainer& components() { return container_; }
0159   const ConstGeometricDetContainer& components() const { return container_; }
0160   // all descendants
0161   // if the current GeometricDet is a leaf, it returns itself!
0162   ConstGeometricDetContainer deepComponents() const;
0163   void deepComponents(ConstGeometricDetContainer& cont) const;
0164 
0165   // PUBLIC SETTERS (they should obviously be as few as possible!!)
0166   void addComponents(GeometricDetContainer const& cont);
0167   void addComponents(ConstGeometricDetContainer const& cont);
0168   void addComponent(GeometricDet*);
0169   void clearComponents() { container_.clear(); }  // only empties the container, THE CHILDREN ARE NOT DELETED!
0170   void deleteComponents();                        // EXPLICITLY DELETES THE CHILDREN
0171 
0172   // CUSTOM DESTRUCTOR
0173   ~GeometricDet();
0174 
0175   // Utility function
0176   static std::string printNavType(int const* n, size_t sz);
0177 
0178 private:
0179   std::vector<double> computeLegacyShapeParameters(const cms::DDSolidShape& mySolidShape,
0180                                                    const dd4hep::Solid& mySolid) const;
0181 
0182   std::string ddname_;
0183   GeometricEnumType type_;
0184 
0185   nav_type ddd_;
0186   DetId geographicalID_ = 0;
0187 
0188   Translation trans_;  // in mm
0189   double rho_ = 0.;    // in mm
0190   double phi_ = 0.;
0191   RotationMatrix rot_;
0192 
0193   cms::DDSolidShape shape_;
0194   std::vector<double> params_;  // in mm
0195 
0196   double radLength_ = 0.;
0197   double xi_ = 0.;
0198   double pixROCRows_ = 0.;
0199   double pixROCCols_ = 0.;
0200   double pixROCx_ = 0.;
0201   double pixROCy_ = 0.;
0202   int bigPixelsx_ = 0;
0203   int bigPixelsy_ = 0;
0204   float bigPixelsPitchx_ = 0.;
0205   float bigPixelsPitchy_ = 0.;
0206   bool isFirstSensor_ = false;
0207   bool isSecondSensor_ = false;
0208   bool stereo_ = false;
0209   bool isLowerSensor_ = false;
0210   bool isUpperSensor_ = false;
0211   double siliconAPVNum_ = 0.;
0212 
0213   bool isFromDD4hep_ = false;
0214 
0215   ConstGeometricDetContainer container_;
0216 };
0217 
0218 namespace geometric_det_ns {
0219   inline std::ostream& operator<<(std::ostream& os, const GeometricDet::NavRange& n) {
0220     os << GeometricDet::printNavType(n.first, n.second);
0221     return os;
0222   }
0223 }  // namespace geometric_det_ns
0224 
0225 #undef PoolAlloc
0226 #endif