Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:00:38

0001 #ifndef FastSimulation_CaloGeometryTools_CrystalPad
0002 #define FastSimulation_CaloGeometryTools_CrystalPad
0003 
0004 #include "Geometry/CaloTopology/interface/CaloDirection.h"
0005 
0006 #include "CLHEP/Vector/TwoVector.h"
0007 #include "DataFormats/Math/interface/Vector3D.h"
0008 //#include "Math/GenVector/Transform3D.h"
0009 #include "FastSimulation/CaloGeometryTools/interface/Transform3DPJ.h"
0010 //C++ headers
0011 #include <vector>
0012 
0013 class CrystalPad {
0014 public:
0015   typedef math::XYZVector XYZVector;
0016   typedef math::XYZVector XYZPoint;
0017   typedef ROOT::Math::Transform3DPJ Transform3D;
0018   typedef ROOT::Math::Transform3DPJ::Point Point;
0019 
0020   CrystalPad() { dummy_ = true; };
0021   /// Order matters. 1234 2341 3412 4123 are ok but not 1324 ....
0022   CrystalPad(unsigned number, const std::vector<CLHEP::Hep2Vector>& corners);
0023   /// Constructor from space points, with the description of the local
0024   /// frame (origin,vec1,vec2) where vec1 is normal to the plane and vec2
0025   /// in the plane
0026   CrystalPad(unsigned number,
0027              int onEcal,
0028              const std::vector<XYZPoint>& corners,
0029              const XYZPoint& origin,
0030              const XYZVector& vec1,
0031              const XYZVector& vec2);
0032 
0033   CrystalPad(unsigned number,
0034              const std::vector<XYZPoint>& corners,
0035              const Transform3D&,
0036              double scaf = 1.,
0037              bool bothdirections = false);
0038 
0039   CrystalPad(const CrystalPad& right);
0040 
0041   CrystalPad& operator=(const CrystalPad& rhs);
0042 
0043   ~CrystalPad() { ; };
0044 
0045   /// Check that the point (in the local frame) is inside the crystal.
0046   bool inside(const CLHEP::Hep2Vector& point, bool debug = false) const;
0047   /// Check that the point (in the global frame) is inside the crystal.
0048   //  bool globalinside(XYZPoint) const;
0049 
0050   /// coordinates of the point in the local frame
0051   //  CLHEP::Hep2Vector localPoint(XYZPoint point) const;
0052 
0053   /// get the corners
0054   inline const std::vector<CLHEP::Hep2Vector>& getCorners() const { return corners_; }
0055 
0056   /// Rescale the Quad to allow for some inaccuracy ...
0057   void resetCorners();
0058 
0059   /// print
0060   void print() const;
0061 
0062   /// access methods to the survivalProbability
0063   inline double survivalProbability() const { return survivalProbability_; };
0064   inline void setSurvivalProbability(double val) { survivalProbability_ = val; };
0065 
0066   /// access to the corners in direction iside; n=0,1
0067   CLHEP::Hep2Vector& edge(unsigned iside, int n);
0068 
0069   /// access to one corner (NE,NW,SE,SW)
0070   CLHEP::Hep2Vector& edge(CaloDirection);
0071 
0072   /// access to the number
0073   inline unsigned getNumber() const { return number_; };
0074 
0075   /// get the coordinates in the original frame
0076   /*
0077   inline XYZPoint originalCoordinates(CLHEP::Hep2Vector point) const
0078     {
0079       XYZPoint p(point.x(),point.y(),0.);
0080       return trans_.Inverse() * p;
0081     }
0082   */
0083 
0084   inline bool operator==(const CrystalPad& quad) const {
0085     //      std::cout << " First " << quad.getCellID() << " Second " << this->getCellID() << std::endl;
0086     return quad.getNumber() == this->getNumber();
0087   }
0088 
0089   inline bool operator<(const CrystalPad& quad) const { return (center_.mag() < quad.center().mag()); }
0090 
0091   /// xmin xmax, ymin ymax of the quad
0092   void extrems(double& xmin, double& xmax, double& ymin, double& ymax) const;
0093 
0094   ///get the center
0095   inline const CLHEP::Hep2Vector& center() const { return center_; }
0096 
0097   /// for graphic debugging
0098   void getDrawingCoordinates(std::vector<float>& x, std::vector<float>& y) const;
0099 
0100 private:
0101   static std::vector<CLHEP::Hep2Vector> aVector;
0102 
0103   std::vector<CLHEP::Hep2Vector> corners_;
0104   std::vector<CLHEP::Hep2Vector> dir_;
0105   unsigned number_;
0106   Transform3D trans_;
0107   ROOT::Math::Rotation3D rotation_;
0108   XYZVector translation_;
0109   double survivalProbability_;
0110   CLHEP::Hep2Vector center_;
0111   double epsilon_;
0112   bool dummy_;
0113   double yscalefactor_;
0114 
0115 public:
0116   /// equality operator
0117   class padEqual {
0118   public:
0119     padEqual(unsigned cell)
0120         : ref_(cell){
0121               //        std::cout << " quadEqual " << ref_ << std::endl;
0122           };
0123     ~padEqual() { ; };
0124     inline bool operator()(const CrystalPad& quad) const { return (ref_ == quad.getNumber()); }
0125 
0126   private:
0127     unsigned ref_;
0128   };
0129 };
0130 
0131 #include <iosfwd>
0132 std::ostream& operator<<(std::ostream& o, CrystalPad& quad);
0133 
0134 #endif