CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/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   // NP** Phase2 BarrelEndcap
00028   struct PhiSortNP{
00029     bool operator()(const GeometricDet* a,const GeometricDet* b) const {
00030       if ( fabs(a->translation().rho() - b->translation().rho()) < 0.01 &&
00031            (fabs(a->translation().phi() - b->translation().phi()) < 0.01 ||
00032             fabs(a->translation().phi() - b->translation().phi()) > 6.27 ) &&
00033            a->translation().z() * b->translation().z() > 0.0 ) {
00034         return ( fabs(a->translation().z()) < fabs(b->translation().z()) );
00035       }
00036       else
00037         return false;
00038     }
00039   };
00040 
00041 
00042   struct LessZ{
00043     bool operator()(const GeometricDet* a, const GeometricDet* b) const
00044     {
00045       // NP** change for Phase 2 Tracker
00046       if (a->translation().z() == b->translation().z())
00047         {return a->translation().rho() < b->translation().rho();}
00048       else{
00049       // Original version
00050       return a->translation().z() < b->translation().z();}   
00051     }
00052   };
00053   
00054   struct LessModZ{
00055     bool operator()(const GeometricDet* a, const GeometricDet* b) const
00056     {
00057       return fabs(a->translation().z()) < fabs(b->translation().z());   
00058     }
00059   };
00060   
00061   
00062   struct ExtractPhi:public uFcn{
00063     double operator()(const GeometricDet* a)const{
00064       const double pi = 3.141592653592;
00065       double phi = a->phi();
00066       return( phi>= 0 ? phi:phi+2*pi);   
00067     }
00068   };
00069   
00070   struct ExtractPhiModule:public uFcn{
00071     double operator()(const GeometricDet* a)const{
00072       const double pi = 3.141592653592;
00073       std::vector<const GeometricDet*> const & comp = a->components().back()->components();
00074       float phi = 0.;
00075       bool sum = true;
00076       
00077       for(unsigned int i=0;i<comp.size();i++){
00078         if(fabs(comp[i]->phi())>pi/2.) { 
00079           sum = false;
00080           break;
00081         }
00082       }
00083       
00084       if(sum){
00085         for(unsigned int i=0;i<comp.size();i++){
00086           phi+= comp[i]->phi();
00087         }
00088         
00089         double temp = phi/float(comp.size()) < 0. ? 
00090           2*pi + phi/float(comp.size()):
00091           phi/float(comp.size());
00092         return temp;
00093         
00094       }else{
00095         for(unsigned int i=0;i<comp.size();i++){
00096           double phi1 = comp[i]->phi() >= 0 ? comp[i]->phi(): 
00097             comp[i]->phi()+2*pi; 
00098           phi+= phi1;
00099         }
00100         
00101         double com = comp.front()->phi() >= 0 ? comp.front()->phi():
00102           2*pi + comp.front()->phi();
00103         double temp = fabs(phi/float(comp.size()) - com) > 2. ? 
00104           pi - phi/float(comp.size()):
00105           phi/float(comp.size());
00106         temp = temp >= 0? temp:2*pi+temp;
00107         return temp;
00108       }
00109     }
00110   };
00111   
00112   struct ExtractPhiGluedModule:public uFcn{
00113     double operator()(const GeometricDet* a)const{
00114       const double pi = 3.141592653592;
00115       std::vector<const GeometricDet*> comp;
00116       a->deepComponents(comp);
00117       float phi = 0.;
00118       bool sum = true;
00119       
00120       for(unsigned int i=0;i<comp.size();i++){
00121         if(fabs(comp[i]->phi())>pi/2.) {
00122           sum = false;
00123           break;
00124         }
00125       }
00126       
00127       if(sum){
00128         for(unsigned int i=0;i<comp.size();i++){
00129           phi+= comp[i]->phi();
00130         }
00131         
00132         double temp = phi/float(comp.size()) < 0. ? 
00133           2*pi + phi/float(comp.size()):
00134           phi/float(comp.size());
00135         return temp;
00136         
00137       }else{
00138         for(unsigned int i=0;i<comp.size();i++){
00139           double phi1 = comp[i]->phi() >= 0 ? comp[i]->phi(): 
00140             comp[i]->translation().phi()+2*pi; 
00141           phi+= phi1;
00142         }
00143         
00144         double com = comp.front()->phi() >= 0 ? comp.front()->phi():
00145           2*pi + comp.front()->phi();
00146         double temp = fabs(phi/float(comp.size()) - com) > 2. ? 
00147           pi - phi/float(comp.size()):
00148           phi/float(comp.size());
00149         temp = temp >= 0? temp:2*pi+temp;
00150         return temp;
00151       }
00152     }
00153   };
00154   
00155   struct ExtractPhiMirror:public uFcn{
00156     double operator()(const GeometricDet* a)const{
00157       const double pi = 3.141592653592;
00158       double phi = a->phi();
00159       phi = (phi>= 0 ? phi : phi+2*pi); // (-pi,pi] --> [0,2pi)
00160       return ( (pi-phi) >= 0 ? (pi-phi) : (pi-phi)+2*pi ); // (-pi,pi] --> [0,2pi)
00161     }
00162   };
00163   
00164   struct ExtractPhiModuleMirror:public uFcn{
00165     double operator()(const GeometricDet* a)const{
00166       const double pi = 3.141592653592;
00167       double phi = ExtractPhiModule()(a); // [0,2pi)
00168       phi = ( phi <= pi ? phi : phi-2*pi );   // (-pi,pi]   
00169       return (pi-phi);
00170     }
00171   };
00172   
00173   struct ExtractPhiGluedModuleMirror:public uFcn{
00174     double operator()(const GeometricDet* a)const{
00175       const double pi = 3.141592653592;
00176       double phi = ExtractPhiGluedModule()(a); // [0,2pi)
00177       phi = ( phi <= pi ? phi : phi-2*pi );   // (-pi,pi]   
00178       return (pi-phi);
00179     }
00180   };
00181   
00182   struct LessR_module{
00183     bool operator()(const GeometricDet* a, const GeometricDet* b) const
00184     {
00185       return a->deepComponents().front()->rho() < 
00186         b->deepComponents().front()->rho();      
00187     }
00188   };
00189   
00190   struct LessR{
00191     bool operator()(const GeometricDet* a, const GeometricDet* b) const
00192     {
00193       return a->rho() < b->rho(); 
00194     }
00195   };
00196   
00197   
00198  private:
00199   virtual void buildComponent(DDFilteredView& , GeometricDet*, std::string) = 0;
00200 protected:
00201   CmsTrackerStringToEnum theCmsTrackerStringToEnum;
00202 private:
00203   virtual void sortNS(DDFilteredView& , GeometricDet*){}
00204   CmsTrackerStringToEnum _CmsTrackerStringToEnum;
00205 };
00206 
00207 #endif