CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/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   unsigned short volumeno;
00064   unsigned short copyno;
00065 
00067   static void printUniqueNames(handles::const_iterator begin,
00068                                handles::const_iterator end);
00069 
00070 
00071   // Phi ranges: Used by: LessDPhiMax; bSector; bSlab::[min|max]Phi();
00072   // MagBSector, MagBRod
00073 
00075   // FIXME: actually returns phi of the point on median plane of the -phi 
00076   // surface, except for trapezoids where the absoulte min has been implemented
00077   Geom::Phi<float> minPhi() const {return thePhiMin;}
00079   // FIXME: actually returns phi of the point on median plane of the +phi 
00080   // surface
00081   Geom::Phi<float> maxPhi() const {return surface(SurfaceOrientation::phiplus).position().phi();}
00082 
00084   // ASSUMPTION: Computed on median Z plane, but this is not a problem since
00085   // all Z planes are orthogonal to the beam line in the current geometry.
00086   double minZ() const {return surface(SurfaceOrientation::zminus).position().z();}
00087   double maxZ() const {return surface(SurfaceOrientation::zplus).position().z();}
00088 
00090   double minR() const {return theRMin;}
00091 
00093   //  double maxR() const {return theRMax;}  
00094 
00096   const GloballyPositioned<float> * placement() const {return refPlane;}
00097 
00099   DDSolidShape shape() const {return solid.shape();}
00100 
00102   std::vector<VolumeSide> sides() const;
00103 
00105   MagVolume6Faces* magVolume;
00106 
00107   bool toExpand() const {return expand;}
00108 
00110   bool isIron() const{return isIronFlag;}
00111 
00113   int masterSector;
00114 
00115 private:
00116   // Disallow Default/copy ctor & assignment op.
00117   // (we want to handle only pointers!!!)
00118   volumeHandle(const volumeHandle& v);
00119   volumeHandle operator=(const volumeHandle &v);
00120 
00121   // The volume's six surfaces.
00122   RCPS surfaces[6];
00123   // If the corresponding surface has been assigned to a shared surface.
00124   bool isAssigned[6];
00125 
00126   // initialise the refPlane
00127   void referencePlane(const DDExpandedView &fv);
00128   // Build the surfaces for a box
00129   void buildBox(const DDExpandedView & fv);
00130   // Build the surfaces for a trapezoid
00131   void buildTrap(const DDExpandedView & fv);
00132   // Build the surfaces for a ddtubs shape
00133   void buildTubs(const DDExpandedView & fv);  
00134   // Build the surfaces for a ddcons shape
00135   void buildCons(const DDExpandedView & fv);  
00136   // Build the surfaces for a ddpseudotrap shape
00137   void buildPseudoTrap(const DDExpandedView & fv);
00138   // Build the surfaces for a ddtrunctubs shape
00139   void buildTruncTubs(const DDExpandedView & fv);
00140 
00141   // Build phi, z surfaces (common for ddtubs and ddcons)
00142   void buildPhiZSurf(double startPhi, double deltaPhi, double zhalf,
00143                      double rCentr);
00144 
00145   // Distance from the origin along the normal to the volume's zphi plane.
00146   double theRN;
00147   
00148   // Max and min radius for _any_ point within the volume
00149   // FIXME!
00150   double theRMin;
00151   double theRMax;
00152   Geom::Phi<float> thePhiMin;
00153 
00154   // The refPlane is the "main plane" for the solid. It corresponds to the 
00155   // x,y plane in the DDD local frame, and defines a frame where the local
00156   // coordinates are the same as in DDD.
00157   GloballyPositioned<float> * refPlane;
00158 
00159   // the DDSolid.
00160   DDSolid solid;  
00161 
00162   // the center of the volume
00163   GlobalPoint center_;
00164 
00165   // Flag this as a master volume out of wich a 2pi volume should be built 
00166   // (e.g. central cylinder); this is taken into account by sides().
00167   bool expand;
00168 
00169   // Temporary hack to keep information on material. Will eventually be replaced!  
00170   bool isIronFlag;
00171 
00172 };
00173 
00174 
00175 // Extractors for precomputed_value_sort() (safe sorting)
00176 
00177 // To sort volumes in Z
00178 struct MagGeoBuilderFromDDD::ExtractZ : public uFcn {
00179   double operator()(const volumeHandle* v) const {
00180     return v->center().z();
00181   }
00182 };
00183 
00184 // To sort volumes in abs(Z)
00185 struct MagGeoBuilderFromDDD::ExtractAbsZ : public uFcn {
00186   double operator()(const volumeHandle* v) const {
00187     return fabs(v->center().z());
00188   }
00189 };
00190 
00191 
00192 // To sort volumes in phi (from -pi to pi).
00193 struct MagGeoBuilderFromDDD::ExtractPhi : public uFcn {
00194   double operator()(const volumeHandle* v) const {
00195     // note that Geom::Phi is implicitly converted to double.
00196     // Periodicity is guaranteed.
00197     return v->center().phi();
00198   }
00199 };
00200 
00201 // To sort volumes based on max phi(from -pi to pi).
00202 struct MagGeoBuilderFromDDD::ExtractPhiMax : public uFcn {
00203   double operator()(const volumeHandle* v) const {
00204     // note that Geom::Phi is implicitly converted to double.
00205     // Periodicity is guaranteed.
00206     return v->maxPhi();
00207   }  
00208 };
00209 
00210 // To sort volumes in R
00211 struct MagGeoBuilderFromDDD::ExtractR : public uFcn {
00212   double operator()(const volumeHandle* v) const {
00213     return v->center().perp();
00214   }
00215 };
00216 
00217 // To sort volumes in RN (distance of (x,y) plane from origin)
00218   struct MagGeoBuilderFromDDD::ExtractRN : public uFcn {
00219   double operator()(const volumeHandle* v) const {
00220     return v->RN();
00221   }
00222 };
00223 
00224 
00225 // To sort angles within any range SMALLER THAN PI "counter-clockwise",
00226 // even if the angles cross the pi boundary.
00227 // CAVEAT: // The result is undefined if the input values cover a 
00228 // range larger than pi!!!
00229 struct MagGeoBuilderFromDDD::LessDPhi{
00230   bool operator()(double phi1, double phi2) const {
00231     // handle periodicity
00232     return ((Geom::Phi<float>(phi2)-Geom::Phi<float>(phi1))>0.);
00233   }  
00234 };
00235 
00236 // Compare the Z of volumes.
00237 // Should be used ONLY for std::max_element and std::min_element 
00238 // and NEVER for sorting (use precomputed_value_sort with ExtractZ instead)
00239 struct MagGeoBuilderFromDDD::LessZ{
00240   bool operator()(const volumeHandle * v1, const volumeHandle * v2) const
00241   {
00242     if (v1->center().z() < v2->center().z()) return true;
00243     return false;
00244   }
00245 };
00246 
00247 #endif
00248