CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/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   switch( det->components().front()->type())
00093   {
00094   case GeometricDet::panel:
00095     if( m_totalBlade == 24 )
00096       TrackerStablePhiSort( comp.begin(), comp.end(), ExtractPhi());
00097     else
00098       PhiPosNegSplit_innerOuter( comp.begin(), comp.end());
00099     break;
00100   default:
00101     edm::LogError( "CmsTrackerDiskBuilder" ) << "ERROR - wrong SubDet to sort..... " << det->components().front()->type();
00102   }
00103 
00104   GeometricDet::GeometricDetContainer zminpanels;  // Here z refers abs(z);
00105   GeometricDet::GeometricDetContainer zmaxpanels;  // So, zmin panel is always closer to ip.
00106 
00107   uint32_t totalblade = comp.size()/2;
00108   if( totalblade != m_totalBlade )
00109     edm::LogError( "CmsTrackerDiskBuilder" ) << "ERROR, The Total Number of Blade in one disk is " << totalblade << "; configured " << m_totalBlade;
00110 
00111   zminpanels.reserve( totalblade );
00112   zmaxpanels.reserve( totalblade );
00113   for( uint32_t j = 0; j < totalblade; j++ )
00114   {
00115     if( fabs( comp[2*j]->translation().z()) > fabs( comp[ 2*j +1 ]->translation().z()))
00116     {
00117       zmaxpanels.push_back( comp[2*j] );
00118       zminpanels.push_back( comp[2*j+1] );
00119 
00120     }
00121     else if( fabs( comp[2*j]->translation().z()) < fabs( comp[ 2*j +1 ]->translation().z()))
00122     {
00123       zmaxpanels.push_back( comp[2*j+1] );
00124       zminpanels.push_back( comp[2*j] );
00125     }
00126     else
00127     {
00128       edm::LogWarning( "CmsTrackerDiskBuilder" ) << "WARNING - The Z of  both panels are equal! ";
00129     }
00130   }
00131 
00132   for( uint32_t fn = 0; fn < zminpanels.size(); fn++ )
00133   {
00134     uint32_t blade = fn + 1;
00135     uint32_t panel = 1;
00136     uint32_t temp = ( blade << 2 ) | panel;
00137     zminpanels[fn]->setGeographicalID( temp );
00138   }
00139   
00140   for( uint32_t bn = 0; bn < zmaxpanels.size(); bn++)
00141   {
00142     uint32_t blade = bn + 1;
00143     uint32_t panel = 2;
00144     uint32_t temp = ( blade << 2) | panel;
00145     zmaxpanels[bn]->setGeographicalID( temp );
00146   }
00147   
00148   det->clearComponents();
00149   det->addComponents( zminpanels );
00150   det->addComponents( zmaxpanels );
00151 }