CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/Geometry/TrackerNumberingBuilder/plugins/CmsTrackerLevelBuilder.h

Go to the documentation of this file.
00001 #ifndef Geometry_TrackerNumberingBuilder_CmsTrackerLevelBuilder_H
00002 #define Geometry_TrackerNumberingBuilder_CmsTrackerLevelBuilder_H 
00003 
00004 #include "Geometry/TrackerNumberingBuilder/plugins/CmsTrackerAbstractConstruction.h"
00005 #include "Geometry/TrackerNumberingBuilder/interface/CmsTrackerStringToEnum.h"
00006 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
00007 #include "FWCore/ParameterSet/interface/types.h"
00008 #include <string>
00013 typedef std::unary_function<const GeometricDet*, double> uFcn;
00014 
00015 class CmsTrackerLevelBuilder : public CmsTrackerAbstractConstruction {
00016 public:
00017   virtual void build(DDFilteredView& , GeometricDet*, std::string);
00018   virtual ~CmsTrackerLevelBuilder(){}
00019   
00020   
00021   struct subDetByType{
00022     bool operator()(const GeometricDet* a, const GeometricDet* b) const {
00023       return a->type() < b->type();
00024     }
00025   };
00026   
00027   struct LessZ{
00028     bool operator()(const GeometricDet* a, const GeometricDet* b) const
00029     {
00030       return a->translation().z() < b->translation().z();   
00031     }
00032   };
00033   
00034   struct LessModZ{
00035     bool operator()(const GeometricDet* a, const GeometricDet* b) const
00036     {
00037       return fabs(a->translation().z()) < fabs(b->translation().z());   
00038     }
00039   };
00040   
00041   
00042   struct ExtractPhi:public uFcn{
00043     double operator()(const GeometricDet* a)const{
00044       const double pi = 3.141592653592;
00045       double phi = a->phi();
00046       return( phi>= 0 ? phi:phi+2*pi);   
00047     }
00048   };
00049   
00050   struct ExtractPhiModule:public uFcn{
00051     double operator()(const GeometricDet* a)const{
00052       const double pi = 3.141592653592;
00053       std::vector<const GeometricDet*> const & comp = a->components().back()->components();
00054       float phi = 0.;
00055       bool sum = true;
00056       
00057       for(unsigned int i=0;i<comp.size();i++){
00058         if(fabs(comp[i]->phi())>pi/2.) { 
00059           sum = false;
00060           break;
00061         }
00062       }
00063       
00064       if(sum){
00065         for(unsigned int i=0;i<comp.size();i++){
00066           phi+= comp[i]->phi();
00067         }
00068         
00069         double temp = phi/float(comp.size()) < 0. ? 
00070           2*pi + phi/float(comp.size()):
00071           phi/float(comp.size());
00072         return temp;
00073         
00074       }else{
00075         for(unsigned int i=0;i<comp.size();i++){
00076           double phi1 = comp[i]->phi() >= 0 ? comp[i]->phi(): 
00077             comp[i]->phi()+2*pi; 
00078           phi+= phi1;
00079         }
00080         
00081         double com = comp.front()->phi() >= 0 ? comp.front()->phi():
00082           2*pi + comp.front()->phi();
00083         double temp = fabs(phi/float(comp.size()) - com) > 2. ? 
00084           pi - phi/float(comp.size()):
00085           phi/float(comp.size());
00086         temp = temp >= 0? temp:2*pi+temp;
00087         return temp;
00088       }
00089     }
00090   };
00091   
00092   struct ExtractPhiGluedModule:public uFcn{
00093     double operator()(const GeometricDet* a)const{
00094       const double pi = 3.141592653592;
00095       std::vector<const GeometricDet*> comp;
00096       a->deepComponents(comp);
00097       float phi = 0.;
00098       bool sum = true;
00099       
00100       for(unsigned int i=0;i<comp.size();i++){
00101         if(fabs(comp[i]->phi())>pi/2.) {
00102           sum = false;
00103           break;
00104         }
00105       }
00106       
00107       if(sum){
00108         for(unsigned int i=0;i<comp.size();i++){
00109           phi+= comp[i]->phi();
00110         }
00111         
00112         double temp = phi/float(comp.size()) < 0. ? 
00113           2*pi + phi/float(comp.size()):
00114           phi/float(comp.size());
00115         return temp;
00116         
00117       }else{
00118         for(unsigned int i=0;i<comp.size();i++){
00119           double phi1 = comp[i]->phi() >= 0 ? comp[i]->phi(): 
00120             comp[i]->translation().phi()+2*pi; 
00121           phi+= phi1;
00122         }
00123         
00124         double com = comp.front()->phi() >= 0 ? comp.front()->phi():
00125           2*pi + comp.front()->phi();
00126         double temp = fabs(phi/float(comp.size()) - com) > 2. ? 
00127           pi - phi/float(comp.size()):
00128           phi/float(comp.size());
00129         temp = temp >= 0? temp:2*pi+temp;
00130         return temp;
00131       }
00132     }
00133   };
00134   
00135   struct ExtractPhiMirror:public uFcn{
00136     double operator()(const GeometricDet* a)const{
00137       const double pi = 3.141592653592;
00138       double phi = a->phi();
00139       phi = (phi>= 0 ? phi : phi+2*pi); // (-pi,pi] --> [0,2pi)
00140       return ( (pi-phi) >= 0 ? (pi-phi) : (pi-phi)+2*pi ); // (-pi,pi] --> [0,2pi)
00141     }
00142   };
00143   
00144   struct ExtractPhiModuleMirror:public uFcn{
00145     double operator()(const GeometricDet* a)const{
00146       const double pi = 3.141592653592;
00147       double phi = ExtractPhiModule()(a); // [0,2pi)
00148       phi = ( phi <= pi ? phi : phi-2*pi );   // (-pi,pi]   
00149       return (pi-phi);
00150     }
00151   };
00152   
00153   struct ExtractPhiGluedModuleMirror:public uFcn{
00154     double operator()(const GeometricDet* a)const{
00155       const double pi = 3.141592653592;
00156       double phi = ExtractPhiGluedModule()(a); // [0,2pi)
00157       phi = ( phi <= pi ? phi : phi-2*pi );   // (-pi,pi]   
00158       return (pi-phi);
00159     }
00160   };
00161   
00162   struct LessR_module{
00163     bool operator()(const GeometricDet* a, const GeometricDet* b) const
00164     {
00165       return a->deepComponents().front()->rho() < 
00166         b->deepComponents().front()->rho();      
00167     }
00168   };
00169   
00170   struct LessR{
00171     bool operator()(const GeometricDet* a, const GeometricDet* b) const
00172     {
00173       return a->rho() < b->rho(); 
00174     }
00175   };
00176   
00177   
00178  private:
00179   virtual void buildComponent(DDFilteredView& , GeometricDet*, std::string) = 0;
00180 protected:
00181   CmsTrackerStringToEnum theCmsTrackerStringToEnum;
00182 private:
00183   virtual void sortNS(DDFilteredView& , GeometricDet*){}
00184   CmsTrackerStringToEnum _CmsTrackerStringToEnum;
00185 };
00186 
00187 #endif