CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/MagneticField/GeomBuilder/src/volumeHandle.h

Go to the documentation of this file.
00001 #ifndef volumeHandle_H
00002 #define volumeHandle_H
00003 
00015 #include "MagneticField/GeomBuilder/src/MagGeoBuilderFromDDD.h"
00016 
00017 /* #include "DDD/DDCore/interface/DDSolid.h" */
00018 #include "DetectorDescription/Core/interface/DDSolid.h"
00019 #include "DataFormats/GeometrySurface/interface/Surface.h"
00020 //#include "ClassReuse/SurfaceGeometry/interface/BoundPlane.h"
00021 #include "MagneticField/VolumeGeometry/interface/VolumeSide.h"
00022 
00023 class DDExpandedView;
00024 class MagVolume6Faces;
00025 
00026 
00027 class MagGeoBuilderFromDDD::volumeHandle {
00028 public:
00029   typedef Surface::GlobalPoint     GlobalPoint;
00030   typedef Surface::LocalPoint      LocalPoint;
00031   typedef Surface::LocalVector     LocalVector;
00032   typedef SurfaceOrientation::GlobalFace Sides;
00033   volumeHandle(const DDExpandedView & fv, bool expand2Pi=false);
00034   ~volumeHandle();
00035 
00037   const GlobalPoint & center() const;
00039   const double RN() const {return theRN;}
00041   const Surface & surface(int which_side) const;
00042   const Surface & surface(Sides which_side) const;
00044   bool sameSurface(const Surface & s1, Sides which_side, float tolerance = 0.01);
00046   bool setSurface(const Surface & s1, Sides which_side);
00048   bool isPlaneMatched(int which_side) const {
00049     return isAssigned[which_side];
00050   }
00051 
00052   int references(int which_side) const { // FIXME!
00053 /*     return surfaces[which_side]->references(); */
00054     return 0;
00055   }
00056 
00058   std::string name;
00060   std::string magFile;
00062   int copyno;
00063 
00065   static void printUniqueNames(handles::const_iterator begin,
00066                                handles::const_iterator end);
00067 
00068 
00069   // Phi ranges: Used by: LessDPhiMax; bSector; bSlab::[min|max]Phi();
00070   // MagBSector, MagBRod
00071 
00073   // FIXME: actually returns phi of the point on median plane of the -phi 
00074   // surface, except for trapezoids where the absoulte min has been implemented
00075   Geom::Phi<float> minPhi() const {return thePhiMin;}
00077   // FIXME: actually returns phi of the point on median plane of the +phi 
00078   // surface
00079   Geom::Phi<float> maxPhi() const {return surface(SurfaceOrientation::phiplus).position().phi();}
00080 
00082   // ASSUMPTION: Computed on median Z plane, but this is not a problem since
00083   // all Z planes are orthogonal to the beam line in the current geometry.
00084   double minZ() const {return surface(SurfaceOrientation::zminus).position().z();}
00085   double maxZ() const {return surface(SurfaceOrientation::zplus).position().z();}
00086 
00088   double minR() const {return theRMin;}
00089 
00091   //  double maxR() const {return theRMax;}  
00092 
00094   const GloballyPositioned<float> * placement() const {return refPlane;}
00095 
00097   DDSolidShape shape() const {return solid.shape();}
00098 
00100   std::vector<VolumeSide> sides() const;
00101 
00103   MagVolume6Faces* magVolume;
00104 
00105   bool toExpand() const {return expand;}
00106 
00108   bool isIron() const{return isIronFlag;}
00109 
00111   int masterSector;
00112 
00113 private:
00114   // Disallow Default/copy ctor & assignment op.
00115   // (we want to handle only pointers!!!)
00116   volumeHandle(const volumeHandle& v);
00117   volumeHandle operator=(const volumeHandle &v);
00118 
00119   // The volume's six surfaces.
00120   RCPS surfaces[6];
00121   // If the corresponding surface has been assigned to a shared surface.
00122   bool isAssigned[6];
00123 
00124   // initialise the refPlane
00125   void referencePlane(const DDExpandedView &fv);
00126   // Build the surfaces for a box
00127   void buildBox(const DDExpandedView & fv);
00128   // Build the surfaces for a trapezoid
00129   void buildTrap(const DDExpandedView & fv);
00130   // Build the surfaces for a ddtubs shape
00131   void buildTubs(const DDExpandedView & fv);  
00132   // Build the surfaces for a ddcons shape
00133   void buildCons(const DDExpandedView & fv);  
00134   // Build the surfaces for a ddpseudotrap shape
00135   void buildPseudoTrap(const DDExpandedView & fv);
00136   // Build the surfaces for a ddtrunctubs shape
00137   void buildTruncTubs(const DDExpandedView & fv);
00138 
00139   // Build phi, z surfaces (common for ddtubs and ddcons)
00140   void buildPhiZSurf(double startPhi, double deltaPhi, double zhalf,
00141                      double rCentr);
00142 
00143   // Distance from the origin along the normal to the volume's zphi plane.
00144   double theRN;
00145   
00146   // Max and min radius for _any_ point within the volume
00147   // FIXME!
00148   double theRMin;
00149   double theRMax;
00150   Geom::Phi<float> thePhiMin;
00151 
00152   // The refPlane is the "main plane" for the solid. It corresponds to the 
00153   // x,y plane in the DDD local frame, and defines a frame where the local
00154   // coordinates are the same as in DDD.
00155   GloballyPositioned<float> * refPlane;
00156 
00157   // the DDSolid.
00158   DDSolid solid;  
00159 
00160   // the center of the volume
00161   GlobalPoint center_;
00162 
00163   // Flag this as a master volume out of wich a 2pi volume should be built 
00164   // (e.g. central cylinder); this is taken into account by sides().
00165   bool expand;
00166 
00167   // Temporary hack to keep information on material. Will eventually be replaced!  
00168   bool isIronFlag;
00169 
00170 };
00171 
00172 
00173 // Extractors for precomputed_value_sort() (safe sorting)
00174 
00175 // To sort volumes in Z
00176 struct MagGeoBuilderFromDDD::ExtractZ : public uFcn {
00177   double operator()(const volumeHandle* v) const {
00178     return v->center().z();
00179   }
00180 };
00181 
00182 // To sort volumes in abs(Z)
00183 struct MagGeoBuilderFromDDD::ExtractAbsZ : public uFcn {
00184   double operator()(const volumeHandle* v) const {
00185     return fabs(v->center().z());
00186   }
00187 };
00188 
00189 
00190 // To sort volumes in phi (from -pi to pi).
00191 struct MagGeoBuilderFromDDD::ExtractPhi : public uFcn {
00192   double operator()(const volumeHandle* v) const {
00193     // note that Geom::Phi is implicitly converted to double.
00194     // Periodicity is guaranteed.
00195     return v->center().phi();
00196   }
00197 };
00198 
00199 // To sort volumes based on max phi(from -pi to pi).
00200 struct MagGeoBuilderFromDDD::ExtractPhiMax : public uFcn {
00201   double operator()(const volumeHandle* v) const {
00202     // note that Geom::Phi is implicitly converted to double.
00203     // Periodicity is guaranteed.
00204     return v->maxPhi();
00205   }  
00206 };
00207 
00208 // To sort volumes in R
00209 struct MagGeoBuilderFromDDD::ExtractR : public uFcn {
00210   double operator()(const volumeHandle* v) const {
00211     return v->center().perp();
00212   }
00213 };
00214 
00215 // To sort volumes in RN (distance of (x,y) plane from origin)
00216   struct MagGeoBuilderFromDDD::ExtractRN : public uFcn {
00217   double operator()(const volumeHandle* v) const {
00218     return v->RN();
00219   }
00220 };
00221 
00222 
00223 // To sort angles within any range SMALLER THAN PI "counter-clockwise",
00224 // even if the angles cross the pi boundary.
00225 // CAVEAT: // The result is undefined if the input values cover a 
00226 // range larger than pi!!!
00227 struct MagGeoBuilderFromDDD::LessDPhi{
00228   bool operator()(double phi1, double phi2) const {
00229     // handle periodicity
00230     return ((Geom::Phi<float>(phi2)-Geom::Phi<float>(phi1))>0.);
00231   }  
00232 };
00233 
00234 // Compare the Z of volumes.
00235 // Should be used ONLY for std::max_element and std::min_element 
00236 // and NEVER for sorting (use precomputed_value_sort with ExtractZ instead)
00237 struct MagGeoBuilderFromDDD::LessZ{
00238   bool operator()(const volumeHandle * v1, const volumeHandle * v2) const
00239   {
00240     if (v1->center().z() < v2->center().z()) return true;
00241     return false;
00242   }
00243 };
00244 
00245 #endif
00246