CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/Geometry/TrackerNumberingBuilder/plugins/CmsTrackerDiskBuilder.cc

Go to the documentation of this file.
00001 #include "Geometry/TrackerNumberingBuilder/plugins/CmsTrackerDiskBuilder.h"
00002 #include "DetectorDescription/Core/interface/DDFilteredView.h"
00003 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
00004 #include "Geometry/TrackerNumberingBuilder/plugins/ExtractStringFromDDD.h"
00005 #include "Geometry/TrackerNumberingBuilder/plugins/CmsTrackerPanelBuilder.h"
00006 #include "Geometry/TrackerNumberingBuilder/plugins/TrackerStablePhiSort.h"
00007 #include "DataFormats/DetId/interface/DetId.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 #include <vector>
00010 #include <algorithm>
00011 
00012 using namespace std;
00013 
00014 CmsTrackerDiskBuilder::CmsTrackerDiskBuilder( unsigned int totalBlade )
00015   : m_totalBlade( totalBlade )
00016 {}
00017 
00018 bool
00019 PhiSort( const GeometricDet* Panel1, const GeometricDet* Panel2 )
00020 {
00021   return( Panel1->phi() < Panel2->phi());
00022 }
00023 
00024 void
00025 CmsTrackerDiskBuilder::PhiPosNegSplit_innerOuter( std::vector< GeometricDet const *>::iterator begin,
00026                                                   std::vector< GeometricDet const *>::iterator end )
00027 {
00028   // first sort in phi, lowest first (-pi to +pi)
00029   std::sort( begin, end, PhiSort );
00030 
00031   // now put positive phi (in order) ahead of negative phi as in std geometry
00032   std::vector<const GeometricDet*> theCompsPosNeg;
00033   theCompsPosNeg.empty();
00034   theCompsPosNeg.clear();
00035   // also find the average radius (used to split inner and outer disk panels)
00036   double theRmin = (**begin).rho();
00037   double theRmax = theRmin;
00038   for(vector<const GeometricDet*>::const_iterator it=begin;
00039       it!=end;it++){
00040     if((**it).phi() >= 0) theCompsPosNeg.push_back(*it);
00041     theRmin = std::min( theRmin, (**it).rho());
00042     theRmax = std::max( theRmax, (**it).rho());
00043   }
00044   for(vector<const GeometricDet*>::const_iterator it=begin;
00045       it!=end;it++){
00046     if((**it).phi() < 0) theCompsPosNeg.push_back(*it);
00047   }
00048 
00049   // now put inner disk panels first
00050   double radius_split = 0.5 * (theRmin + theRmax);
00051   std::vector<const GeometricDet*> theCompsInnerOuter;
00052   theCompsInnerOuter.empty();
00053   theCompsInnerOuter.clear();
00054   //unsigned int num_inner = 0;
00055   for(vector<const GeometricDet*>::const_iterator it=theCompsPosNeg.begin();
00056       it!=theCompsPosNeg.end();it++){
00057     if((**it).rho() <= radius_split) {
00058       theCompsInnerOuter.push_back(*it);
00059       //num_inner++;
00060     }
00061   }
00062   for(vector<const GeometricDet*>::const_iterator it=theCompsPosNeg.begin();
00063       it!=theCompsPosNeg.end();it++){
00064     if((**it).rho() > radius_split) theCompsInnerOuter.push_back(*it);
00065   }
00066   //std::cout << "num of inner = " << num_inner << " with radius less than " << radius_split << std::endl;
00067   std::copy(theCompsInnerOuter.begin(), theCompsInnerOuter.end(), begin);
00068 }
00069 
00070 void
00071 CmsTrackerDiskBuilder::buildComponent( DDFilteredView& fv, GeometricDet* g, std::string s )
00072 {
00073   CmsTrackerPanelBuilder theCmsTrackerPanelBuilder;
00074   GeometricDet * subdet = new GeometricDet( &fv, theCmsTrackerStringToEnum.type( ExtractStringFromDDD::getString( s, &fv )));
00075 
00076   switch( theCmsTrackerStringToEnum.type( ExtractStringFromDDD::getString( s, &fv )))
00077   {
00078   case GeometricDet::panel:
00079     theCmsTrackerPanelBuilder.build( fv, subdet, s );
00080     break;
00081   default:
00082     edm::LogError( "CmsTrackerDiskBuilder" ) << " ERROR - I was expecting a Panel, I got a " << ExtractStringFromDDD::getString( s, &fv );   
00083   }  
00084   g->addComponent( subdet );
00085 }
00086 
00087 void
00088 CmsTrackerDiskBuilder::sortNS( DDFilteredView& fv, GeometricDet* det )
00089 {
00090   GeometricDet::GeometricDetContainer & comp = det->components();
00091 
00092 // NP** BIG switch between Phase 1 and Outer Tracker Pixels
00093 if( fabs( comp[0]->translation().z() ) < 1000 ) {
00094 
00095   //std::cerr<<"PHASE1"<<std::endl;
00096 
00098 
00099   switch( det->components().front()->type())
00100   {
00101   case GeometricDet::panel:
00102     if( m_totalBlade == 24 )
00103       TrackerStablePhiSort( comp.begin(), comp.end(), ExtractPhi());
00104     else
00105       PhiPosNegSplit_innerOuter( comp.begin(), comp.end());
00106     break;
00107   default:
00108     edm::LogError( "CmsTrackerDiskBuilder" ) << "ERROR - wrong SubDet to sort..... " << det->components().front()->type();
00109   }
00110 
00111   GeometricDet::GeometricDetContainer zminpanels;  // Here z refers abs(z);
00112   GeometricDet::GeometricDetContainer zmaxpanels;  // So, zmin panel is always closer to ip.
00113 
00114   uint32_t totalblade = comp.size()/2;
00115   if( totalblade != m_totalBlade )
00116     edm::LogError( "CmsTrackerDiskBuilder" ) << "ERROR, The Total Number of Blade in one disk is " << totalblade << "; configured " << m_totalBlade;
00117 
00118   zminpanels.reserve( totalblade );
00119   zmaxpanels.reserve( totalblade );
00120   for( uint32_t j = 0; j < totalblade; j++ )
00121   {
00122     if( fabs( comp[2*j]->translation().z()) > fabs( comp[ 2*j +1 ]->translation().z()))
00123     {
00124       zmaxpanels.push_back( comp[2*j] );
00125       zminpanels.push_back( comp[2*j+1] );
00126 
00127     }
00128     else if( fabs( comp[2*j]->translation().z()) < fabs( comp[ 2*j +1 ]->translation().z()))
00129     {
00130       zmaxpanels.push_back( comp[2*j+1] );
00131       zminpanels.push_back( comp[2*j] );
00132     }
00133     else
00134     {
00135       edm::LogWarning( "CmsTrackerDiskBuilder" ) << "WARNING - The Z of  both panels are equal! ";
00136     }
00137   }
00138 
00139   for( uint32_t fn = 0; fn < zminpanels.size(); fn++ )
00140   {
00141     uint32_t blade = fn + 1;
00142     uint32_t panel = 1;
00143     uint32_t temp = ( blade << 2 ) | panel;
00144     zminpanels[fn]->setGeographicalID( temp );
00145   }
00146   
00147   for( uint32_t bn = 0; bn < zmaxpanels.size(); bn++)
00148   {
00149     uint32_t blade = bn + 1;
00150     uint32_t panel = 2;
00151     uint32_t temp = ( blade << 2) | panel;
00152     zmaxpanels[bn]->setGeographicalID( temp );
00153   }
00154   
00155   det->clearComponents();
00156   det->addComponents( zminpanels );
00157   det->addComponents( zmaxpanels );
00158 }
00159 // NP** BIG switch between Phase 1 and Outer Tracker Pixels
00160 else {
00161 
00162  //std::cerr<< "PHASE2!"<<std::endl;
00163 
00164   switch(det->components().front()->type()){
00165     case GeometricDet::panel:
00166    //   std::cerr<<comp.size()<<" RINGS!!"<<std::endl;
00167    //PhiPosNegSplit_innerOuter(comp.begin(),comp.end());
00168    //TrackerStablePhiSort(comp.begin(),comp.end(), ExtractPhi());
00169       break;
00170     default:
00171       edm::LogError("CmsTrackerDiskBuilder")<<"ERROR - wrong SubDet to sort..... "<<det->components().front()->type();
00172   }
00173 
00174   GeometricDet::GeometricDetContainer rings;
00175   uint32_t  totalrings = comp.size();
00176 
00177   for ( uint32_t rn=0; rn<totalrings; rn++) {
00178     rings.push_back(comp[rn]);
00179     uint32_t blade = rn+1;
00180     uint32_t panel = 1;
00181     uint32_t temp = (blade<<2) | panel;
00182     rings[rn]->setGeographicalID(temp);
00183 
00184   }
00185 
00186   det->clearComponents();
00187   det->addComponents(rings);
00188 }
00189 // NP** End of the BIG switch
00190 
00191 
00192 }
00193