CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/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             temp |= (((in)->components())[i]->geographicalID().rawId()<<20); // Layer Number start bit is 16 [5 unused]
00122             break;
00123           }
00124         // PXF
00125         case 2:
00126           {
00127 //          temp |= (((in)->components())[i]->geographicalID().rawId() << 16 ); // Disk Number start bit is 16
00128             temp |= (((in)->components())[i]->geographicalID().rawId()<<18); // Disk Number start bit is 16
00129             break;
00130           }
00131         // TIB
00132         case 3:
00133           {
00134             temp |= (((in)->components())[i]->geographicalID().rawId() << 14); // Layer Number start bit is 14 [8 unused]
00135             break;
00136           }
00137         
00138         // TID
00139         case 4:
00140           {
00141             temp |= (((in)->components())[i]->geographicalID().rawId() << 11); // Disk (Wheel) Number start bit is 11
00142             break;
00143           }
00144         
00145         // TOB
00146         case 5:
00147           {
00148             temp |= (((in)->components())[i]->geographicalID().rawId() << 14); // Layer Number start bit is 14 [8 unused]
00149             break;
00150           }
00151         
00152         // TEC
00153         case 6:
00154           {
00155             temp |= (((in)->components())[i]->geographicalID().rawId() << 14); // Wheel Number start bit is 14
00156             break;
00157           }
00158       
00159         // the rest
00160         default:
00161           {
00162             // do nothing
00163           }
00164         
00165         // SubDetector switch ends
00166         }
00167       
00168         ((in)->components())[i]->setGeographicalID( temp );
00169       
00170         // next level
00171         iterate(((in)->components())[i],level+1,((in)->components())[i]->geographicalID().rawId());      
00172       }
00173     
00174       break; 
00175     }    
00176     // level 2
00177   case 2: {
00178     
00179     for (uint32_t i=0;i<(in)->components().size();i++) {
00180         
00181       switch (iSubDet) {
00182 
00183         // PXB
00184       case 1:
00185         {
00186           uint32_t temp = ID;
00187           // Ladder Starting bit = 2 (last unused) + 6 (Module Number) = 8
00188           temp |= (((in)->components())[i]->geographicalID().rawId()<<12);//<<10);//8)
00189           ((in)->components())[i]->setGeographicalID(temp);
00190           break;
00191         }
00192         
00193         // PXF
00194       case 2:
00195         {
00196           uint32_t temp = ID;
00197           // Blade Starting bit = 1 (last unused) + 5 (Module Number) + 2 (Plaquette part) = 8
00198 //        temp |= (((in)->components())[i]->geographicalID().rawId()<<8);
00199           temp |= (((in)->components())[i]->geographicalID().rawId()<<10);
00200           ((in)->components())[i]->setGeographicalID(temp);
00201           break;
00202         }
00203         
00204         // TIB
00205       case 3:
00206         {
00207           uint32_t temp = ID;
00208           // Side+Part+String Starting bit = 2 (Module Type) + 2 (Module Number) = 4
00209           temp |= (((in)->components())[i]->geographicalID().rawId()<<4);
00210           ((in)->components())[i]->setGeographicalID(temp);
00211           break;
00212         }
00213         
00214         // TID
00215       case 4:
00216         {
00217           uint32_t temp = ID;
00218           // Ring+Part Starting bit = 2 (Module Type) + 5 (Module Number) + 2 (Disk Part)= 9
00219           temp |= (((in)->components())[i]->geographicalID().rawId()<<9);
00220           ((in)->components())[i]->setGeographicalID(DetId(temp));
00221           break;
00222         }
00223         
00224         // TOB
00225       case 5:
00226         {
00227           uint32_t temp = ID;
00228           // Side+Rod Starting bit = 2 (Module Type) + 3 (Module Number) = 5
00229           temp |= (((in)->components())[i]->geographicalID().rawId()<<5);
00230           ((in)->components())[i]->setGeographicalID(temp);
00231           break;
00232         }
00233         
00234         // TEC
00235       case 6:
00236         {
00237           uint32_t temp = ID;
00238           // Petal+Part Starting bit = 2 (Module Type) + 3 (Module Number) + 3 (Ring Number) = 8
00239           temp |= (((in)->components())[i]->geographicalID().rawId()<<8);
00240           ((in)->components())[i]->setGeographicalID(temp);
00241           break;
00242         }
00243         
00244         // the rest
00245       default:
00246         {
00247           // do nothing
00248         }
00249         
00250         // SubDetector switch ends
00251       }
00252 
00253       // next level
00254       iterate(((in)->components())[i],level+1,((in)->components())[i]->geographicalID().rawId());
00255     }
00256     
00257     break;    
00258   }
00259     
00260     // level 3
00261   case 3:
00262     {
00263       for (uint32_t i=0;i<(in)->components().size();i++) {
00264         
00265         switch (iSubDet) {
00266           
00267           // TEC
00268         case 6:
00269           {
00270             // Ring Starting bit = 2 (Module Type) + 3 (Module Number)
00271             uint32_t temp = ID;
00272             temp |= (((in)->components())[i]->geographicalID().rawId()<<5);
00273             ((in)->components())[i]->setGeographicalID(temp);
00274             break;
00275           }
00276           
00277           // the others but TEC
00278         default:
00279           {
00280             uint32_t temp = ID;
00281             temp |= (((in)->components())[i]->geographicalID().rawId()<<2); // Starting bit = 2 (Module Type)
00282             ((in)->components())[i]->setGeographicalID(temp);
00283           }
00284           
00285           // SubDetector switch ends
00286         }
00287         
00288         // next level
00289         iterate(((in)->components())[i],level+1,((in)->components())[i]->geographicalID().rawId());
00290         
00291       }
00292       
00293       break;
00294     }
00295     
00296     // level 4
00297   case 4:
00298     {
00299 
00300       for (uint32_t i=0;i<(in)->components().size();i++) {
00301         
00302         switch (iSubDet) {
00303           
00304           // TEC
00305         case 6:
00306           {
00307             // Module Number bit = 2 (Module Type)
00308             uint32_t temp = ID;
00309             temp |= (((in)->components())[i]->geographicalID().rawId()<<2);
00310             ((in)->components())[i]->setGeographicalID(temp);
00311             // next level
00312             iterate(((in)->components())[i],level+1,((in)->components())[i]->geographicalID().rawId());
00313             break;
00314           }
00315           
00316           // the others stop here!
00317         default:
00318           {
00319             for (uint32_t i=0;i<(in)->components().size();i++) {
00320               uint32_t temp = ID;
00321               temp |= (((in)->components())[i]->geographicalID().rawId());
00322               ((in)->components())[i]->setGeographicalID(temp);
00323             }
00324           }
00325           
00326           // SubDetector switch ends
00327         }
00328 
00329       }
00330       
00331       break;
00332     }
00333     
00334     // level 5
00335   case 5:
00336     {
00337       // TEC Module Type (only TEC arrives here)
00338       for (uint32_t i=0;i<(in)->components().size();i++) {
00339         uint32_t temp = ID;
00340         temp |= (((in)->components())[i]->geographicalID().rawId());
00341         ((in)->components())[i]->setGeographicalID(temp);
00342       }
00343       break;
00344     }
00345     
00346     // throw exception
00347   default:
00348     {
00349       cms::Exception("LogicError") <<" CmsTrackerDetIdBuilder invalid level "<< level;
00350     }
00351     
00352     // level switch ends
00353   }
00354   
00355   return;
00356 
00357 }
00358