CMS 3D CMS Logo

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