CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/Geometry/TrackerNumberingBuilder/plugins/CmsTrackerDetIdBuilder.cc

Go to the documentation of this file.
00001 #include "Geometry/TrackerNumberingBuilder/plugins/CmsTrackerDetIdBuilder.h"
00002 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
00003 #include "FWCore/Utilities/interface/Exception.h"
00004 #include "DataFormats/DetId/interface/DetId.h"
00005 
00006 #include <iostream>
00007 #include <fstream>
00008 #include <sstream>
00009 #include <string>
00010 #include <bitset>
00011 
00012 CmsTrackerDetIdBuilder::CmsTrackerDetIdBuilder( unsigned int layerNumberPXB )
00013   : m_layerNumberPXB( layerNumberPXB )
00014 {}
00015 
00016 GeometricDet*
00017 CmsTrackerDetIdBuilder::buildId( GeometricDet* tracker )
00018 {
00019   DetId t( DetId::Tracker, 0 );
00020   tracker->setGeographicalID( t );
00021   iterate( tracker, 0, tracker->geographicalID().rawId() );
00022 
00023   return tracker;
00024 }
00025 
00026 void
00027 CmsTrackerDetIdBuilder::iterate( GeometricDet const *in, int level, unsigned int ID )
00028 {
00029   std::bitset<32> binary_ID(ID);
00030 
00031   // SubDetector (useful to know fron now on, valid only after level 0, where SubDetector is assigned)
00032   uint32_t mask = (7<<25);
00033   uint32_t iSubDet = ID & mask;
00034   iSubDet = iSubDet >> 25;
00035   //
00036   
00037   switch( level )
00038   {
00039     // level 0
00040   case 0:
00041     {  
00042       for( uint32_t i = 0; i<(in)->components().size(); i++ )
00043       {
00044         uint32_t jSubDet = ((in)->components())[i]->geographicalID().rawId();
00045         uint32_t temp = ID;
00046         temp |= (jSubDet<<25);
00047         ((in)->components())[i]->setGeographicalID(temp);       
00048         
00049         switch( jSubDet )
00050         { 
00051           // PXF
00052         case 2:
00053           {
00054             // SubDetector Side start bit is 23 [3 unused and Side length is 2 bit]
00055             if(((in)->components())[i]->translation().z()<0. )
00056             {
00057               temp |= (1<<23); // PXF-
00058             }
00059             else
00060             {
00061               temp |= (2<<23); // PXF+
00062             }
00063             break;
00064           }
00065           // TID
00066         case 4:
00067           {
00068             temp|= (0<<15); // SubDetector Side start bit is 13 [10 unused and Side length is 2 bit]
00069             if((((in)->components())[i])->components()[0]->translation().z()<0. )
00070             {
00071               temp |= (1<<13); // TIDB = TID-
00072             }
00073             else
00074             {
00075               temp |= (2<<13); // TIDF = TID+
00076             }
00077             break;
00078           }
00079           // TEC
00080         case 6:
00081           {
00082             temp |= (0<<20); // SubDetector Side start bit is 18 [5 unused and Side length is 2 bit]
00083             if(((in)->components())[i]->translation().z()<0. )
00084             {
00085               temp |= (1<<18); // TEC-
00086             }
00087             else
00088             {
00089               temp |= (2<<18); // TEC+
00090             }
00091             break;
00092           }
00093           // PXB, TIB, TOB (barrel)
00094         default:
00095           {
00096             // do nothing
00097           }
00098           // SubDetector switch ends
00099         }
00100         
00101         ((in)->components())[i]->setGeographicalID(DetId(temp));        
00102         
00103         // next level
00104         iterate(((in)->components())[i],level+1,((in)->components())[i]->geographicalID().rawId());
00105       }
00106       break;
00107     }
00108   // level 1
00109   case 1:
00110     {
00111       for( uint32_t i = 0; i < (in)->components().size(); i++ )
00112       {
00113         uint32_t temp = ID;
00114       
00115         switch( iSubDet )
00116         {
00117         // PXB
00118         case 1:
00119           {
00120             temp |= (((in)->components())[i]->geographicalID().rawId() << m_layerNumberPXB ); // Layer Number start bit is 16 [5 unused]
00121             break;
00122           }
00123         // PXF
00124         case 2:
00125           {
00126             temp |= (((in)->components())[i]->geographicalID().rawId() << 16 ); // Disk Number start bit is 16
00127             break;
00128           }
00129         // TIB
00130         case 3:
00131           {
00132             temp |= (((in)->components())[i]->geographicalID().rawId() << 14); // Layer Number start bit is 14 [8 unused]
00133             break;
00134           }
00135         
00136         // TID
00137         case 4:
00138           {
00139             temp |= (((in)->components())[i]->geographicalID().rawId() << 11); // Disk (Wheel) Number start bit is 11
00140             break;
00141           }
00142         
00143         // TOB
00144         case 5:
00145           {
00146             temp |= (((in)->components())[i]->geographicalID().rawId() << 14); // Layer Number start bit is 14 [8 unused]
00147             break;
00148           }
00149         
00150         // TEC
00151         case 6:
00152           {
00153             temp |= (((in)->components())[i]->geographicalID().rawId() << 14); // Wheel Number start bit is 14
00154             break;
00155           }
00156       
00157         // the rest
00158         default:
00159           {
00160             // do nothing
00161           }
00162         
00163         // SubDetector switch ends
00164         }
00165       
00166         ((in)->components())[i]->setGeographicalID( temp );
00167       
00168         // next level
00169         iterate(((in)->components())[i],level+1,((in)->components())[i]->geographicalID().rawId());      
00170       }
00171     
00172       break; 
00173     }    
00174     // level 2
00175   case 2: {
00176     
00177     for (uint32_t i=0;i<(in)->components().size();i++) {
00178         
00179       switch (iSubDet) {
00180 
00181         // PXB
00182       case 1:
00183         {
00184           uint32_t temp = ID;
00185           // Ladder Starting bit = 2 (last unused) + 6 (Module Number) = 8
00186           temp |= (((in)->components())[i]->geographicalID().rawId()<<8);
00187           ((in)->components())[i]->setGeographicalID(temp);
00188           break;
00189         }
00190         
00191         // PXF
00192       case 2:
00193         {
00194           uint32_t temp = ID;
00195           // Blade Starting bit = 1 (last unused) + 5 (Module Number) + 2 (Plaquette part) = 8
00196           temp |= (((in)->components())[i]->geographicalID().rawId()<<8);
00197           ((in)->components())[i]->setGeographicalID(temp);
00198           break;
00199         }
00200         
00201         // TIB
00202       case 3:
00203         {
00204           uint32_t temp = ID;
00205           // Side+Part+String Starting bit = 2 (Module Type) + 2 (Module Number) = 4
00206           temp |= (((in)->components())[i]->geographicalID().rawId()<<4);
00207           ((in)->components())[i]->setGeographicalID(temp);
00208           break;
00209         }
00210         
00211         // TID
00212       case 4:
00213         {
00214           uint32_t temp = ID;
00215           // Ring+Part Starting bit = 2 (Module Type) + 5 (Module Number) + 2 (Disk Part)= 9
00216           temp |= (((in)->components())[i]->geographicalID().rawId()<<9);
00217           ((in)->components())[i]->setGeographicalID(DetId(temp));
00218           break;
00219         }
00220         
00221         // TOB
00222       case 5:
00223         {
00224           uint32_t temp = ID;
00225           // Side+Rod Starting bit = 2 (Module Type) + 3 (Module Number) = 5
00226           temp |= (((in)->components())[i]->geographicalID().rawId()<<5);
00227           ((in)->components())[i]->setGeographicalID(temp);
00228           break;
00229         }
00230         
00231         // TEC
00232       case 6:
00233         {
00234           uint32_t temp = ID;
00235           // Petal+Part Starting bit = 2 (Module Type) + 3 (Module Number) + 3 (Ring Number) = 8
00236           temp |= (((in)->components())[i]->geographicalID().rawId()<<8);
00237           ((in)->components())[i]->setGeographicalID(temp);
00238           break;
00239         }
00240         
00241         // the rest
00242       default:
00243         {
00244           // do nothing
00245         }
00246         
00247         // SubDetector switch ends
00248       }
00249 
00250       // next level
00251       iterate(((in)->components())[i],level+1,((in)->components())[i]->geographicalID().rawId());
00252     }
00253     
00254     break;    
00255   }
00256     
00257     // level 3
00258   case 3:
00259     {
00260       for (uint32_t i=0;i<(in)->components().size();i++) {
00261         
00262         switch (iSubDet) {
00263           
00264           // TEC
00265         case 6:
00266           {
00267             // Ring Starting bit = 2 (Module Type) + 3 (Module Number)
00268             uint32_t temp = ID;
00269             temp |= (((in)->components())[i]->geographicalID().rawId()<<5);
00270             ((in)->components())[i]->setGeographicalID(temp);
00271             break;
00272           }
00273           
00274           // the others but TEC
00275         default:
00276           {
00277             uint32_t temp = ID;
00278             temp |= (((in)->components())[i]->geographicalID().rawId()<<2); // Starting bit = 2 (Module Type)
00279             ((in)->components())[i]->setGeographicalID(temp);
00280           }
00281           
00282           // SubDetector switch ends
00283         }
00284         
00285         // next level
00286         iterate(((in)->components())[i],level+1,((in)->components())[i]->geographicalID().rawId());
00287         
00288       }
00289       
00290       break;
00291     }
00292     
00293     // level 4
00294   case 4:
00295     {
00296 
00297       for (uint32_t i=0;i<(in)->components().size();i++) {
00298         
00299         switch (iSubDet) {
00300           
00301           // TEC
00302         case 6:
00303           {
00304             // Module Number bit = 2 (Module Type)
00305             uint32_t temp = ID;
00306             temp |= (((in)->components())[i]->geographicalID().rawId()<<2);
00307             ((in)->components())[i]->setGeographicalID(temp);
00308             // next level
00309             iterate(((in)->components())[i],level+1,((in)->components())[i]->geographicalID().rawId());
00310             break;
00311           }
00312           
00313           // the others stop here!
00314         default:
00315           {
00316             for (uint32_t i=0;i<(in)->components().size();i++) {
00317               uint32_t temp = ID;
00318               temp |= (((in)->components())[i]->geographicalID().rawId());
00319               ((in)->components())[i]->setGeographicalID(temp);
00320             }
00321           }
00322           
00323           // SubDetector switch ends
00324         }
00325 
00326       }
00327       
00328       break;
00329     }
00330     
00331     // level 5
00332   case 5:
00333     {
00334       // TEC Module Type (only TEC arrives here)
00335       for (uint32_t i=0;i<(in)->components().size();i++) {
00336         uint32_t temp = ID;
00337         temp |= (((in)->components())[i]->geographicalID().rawId());
00338         ((in)->components())[i]->setGeographicalID(temp);
00339       }
00340       break;
00341     }
00342     
00343     // throw exception
00344   default:
00345     {
00346       cms::Exception("LogicError") <<" CmsTrackerDetIdBuilder invalid level "<< level;
00347     }
00348     
00349     // level switch ends
00350   }
00351   
00352   return;
00353 
00354 }
00355