CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/DQM/EcalCommon/src/Numbers.cc

Go to the documentation of this file.
00001 // $Id: Numbers.cc,v 1.82 2012/02/28 16:38:13 yiiyama Exp $
00002 
00011 #include <sstream>
00012 #include <iomanip>
00013 #include <set>
00014 
00015 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00016 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00017 
00018 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
00019 #include "DataFormats/EcalDetId/interface/EcalScDetId.h"
00020 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
00021 #include "DataFormats/EcalDetId/interface/EcalPnDiodeDetId.h"
00022 #include "DataFormats/EcalRawData/interface/EcalDCCHeaderBlock.h"
00023 
00024 #include "FWCore/Framework/interface/ESHandle.h"
00025 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
00026 #include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
00027 #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h"
00028 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00029 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00030 
00031 #include "DQM/EcalCommon/interface/Numbers.h"
00032 
00033 //-------------------------------------------------------------------------
00034 
00035 const EcalElectronicsMapping* Numbers::map = 0;
00036 const EcalTrigTowerConstituentsMap* Numbers::mapTT = 0;
00037 const CaloGeometry *Numbers::geometry = 0;
00038 
00039 const unsigned Numbers::crystalsTCCArraySize_;
00040 const unsigned Numbers::crystalsDCCArraySize_;
00041 
00042 std::vector<DetId> Numbers::crystalsTCC_[crystalsTCCArraySize_];
00043 std::vector<DetId> Numbers::crystalsDCC_[crystalsDCCArraySize_];
00044 
00045 bool Numbers::init = false;
00046 
00047 //-------------------------------------------------------------------------
00048 
00049 void
00050 Numbers::initGeometry( const edm::EventSetup& setup, bool verbose )
00051 {
00052 
00053   if( Numbers::init ) return;
00054 
00055   if ( verbose ) std::cout << "Initializing EcalElectronicsMapping ..." << std::endl;
00056 
00057   Numbers::init = true;
00058 
00059   edm::ESHandle<EcalElectronicsMapping> handle;
00060   setup.get<EcalMappingRcd>().get(handle);
00061   Numbers::map = handle.product();
00062 
00063   edm::ESHandle<EcalTrigTowerConstituentsMap> handleTT;
00064   setup.get<IdealGeometryRecord>().get(handleTT);
00065   Numbers::mapTT = handleTT.product();
00066 
00067   edm::ESHandle<CaloGeometry> handleGeom;
00068   setup.get<CaloGeometryRecord>().get(handleGeom);
00069   Numbers::geometry = handleGeom.product();
00070 
00071   if ( verbose ) std::cout << "done." << std::endl;
00072 
00073 }
00074 
00075 //-------------------------------------------------------------------------
00076 
00077 int
00078 Numbers::iEB( const unsigned ism )
00079 {
00080 
00081   // EB-
00082   if( ism >=  1 && ism <= 18 ) return( -ism );
00083 
00084   // EB+
00085   if( ism >= 19 && ism <= 36 ) return( +ism - 18 );
00086 
00087   throw cms::Exception("InvalidParameter") << "Wrong SM id determination: iSM = " << ism;
00088 
00089 }
00090 
00091 //-------------------------------------------------------------------------
00092 
00093 std::string
00094 Numbers::sEB( const unsigned ism  )
00095 {
00096 
00097   int ieb = Numbers::iEB( ism );
00098 
00099   std::ostringstream s;
00100   s << "EB" << std::setw(3) << std::setfill('0')
00101     << std::setiosflags( std::ios::showpos )
00102     << std::setiosflags( std::ios::internal )
00103     << ieb
00104     << std::resetiosflags( std::ios::showpos )
00105     << std::resetiosflags( std::ios::internal );
00106   return( s.str() );
00107 
00108 }
00109 
00110 //-------------------------------------------------------------------------
00111 
00112 int
00113 Numbers::iEE( const unsigned ism )
00114 {
00115 
00116   // EE-
00117   if( ism ==  1 ) return( -7 );
00118   if( ism ==  2 ) return( -8 );
00119   if( ism ==  3 ) return( -9 );
00120   if( ism ==  4 ) return( -1 );
00121   if( ism ==  5 ) return( -2 );
00122   if( ism ==  6 ) return( -3 );
00123   if( ism ==  7 ) return( -4 );
00124   if( ism ==  8 ) return( -5 );
00125   if( ism ==  9 ) return( -6 );
00126 
00127   // EE+
00128   if( ism == 10 ) return( +7 );
00129   if( ism == 11 ) return( +8 );
00130   if( ism == 12 ) return( +9 );
00131   if( ism == 13 ) return( +1 );
00132   if( ism == 14 ) return( +2 );
00133   if( ism == 15 ) return( +3 );
00134   if( ism == 16 ) return( +4 );
00135   if( ism == 17 ) return( +5 );
00136   if( ism == 18 ) return( +6 );
00137 
00138   throw cms::Exception("InvalidParameter") << "Wrong SM id determination: iSM = " << ism;
00139 
00140 }
00141 
00142 //-------------------------------------------------------------------------
00143 
00144 EcalSubdetector
00145 Numbers::subDet( const EBDetId& id )
00146 {
00147 
00148   return( id.subdet() );
00149 
00150 }
00151 
00152 //-------------------------------------------------------------------------
00153 
00154 EcalSubdetector
00155 Numbers::subDet( const EEDetId& id ) 
00156 {
00157 
00158   return( id.subdet() );
00159 
00160 }
00161 
00162 //-------------------------------------------------------------------------
00163 
00164 EcalSubdetector
00165 Numbers::subDet( const EcalTrigTowerDetId& id )
00166 {
00167 
00168   return( id.subDet() );
00169 
00170 }
00171 
00172 //-------------------------------------------------------------------------                                                                                                                                                                
00173 
00174 EcalSubdetector
00175 Numbers::subDet( const EcalScDetId& id )
00176 {
00177 
00178   return( id.subdet() );
00179 
00180 }
00181 
00182 //-------------------------------------------------------------------------
00183 
00184 EcalSubdetector
00185 Numbers::subDet( const EcalElectronicsId& id ) 
00186 {
00187 
00188   return( id.subdet() );
00189 
00190 }
00191 
00192 //-------------------------------------------------------------------------
00193 
00194 EcalSubdetector
00195 Numbers::subDet( const EcalPnDiodeDetId& id ) 
00196 {
00197 
00198   return( (EcalSubdetector) id.iEcalSubDetectorId() );
00199 
00200 }
00201 
00202 //-------------------------------------------------------------------------
00203 
00204 EcalSubdetector 
00205 Numbers::subDet( const EcalDCCHeaderBlock& id )
00206 {
00207 
00208   int idcc = id.id();
00209 
00210   // EE-
00211   if ( idcc >=  1 && idcc <=  9 ) return( EcalEndcap );
00212 
00213   // EB-/EB+
00214   if ( idcc >= 10 && idcc <= 45 ) return( EcalBarrel);
00215 
00216   // EE+
00217   if ( idcc >= 46 && idcc <= 54 ) return( EcalEndcap );
00218 
00219   throw cms::Exception("InvalidParameter") << "Wrong DCC id: dcc = " << idcc;
00220 
00221 }
00222 
00223 //-------------------------------------------------------------------------
00224 
00225 std::string
00226 Numbers::sEE( const unsigned ism  )
00227 {
00228 
00229   int iee = Numbers::iEE( ism );
00230 
00231   std::ostringstream s;
00232   s << "EE" << std::setw(3) << std::setfill('0')
00233     << std::setiosflags( std::ios::showpos )
00234     << std::setiosflags( std::ios::internal )
00235     << iee
00236     << std::resetiosflags( std::ios::showpos )
00237     << std::resetiosflags( std::ios::internal );
00238   return( s.str() );
00239 
00240 }
00241 
00242 //-------------------------------------------------------------------------
00243 
00244 // for EB, converts between two schemes. Old scheme [1:9] for EB-, new scheme (used in EBDetId) [1:9] for EB+
00245 unsigned
00246 Numbers::iSM( const unsigned ism, const EcalSubdetector subdet )
00247 {
00248 
00249   if( subdet == EcalBarrel ) {
00250 
00251     if( ism >=  1 && ism <= 18 ) return( ism+18 );
00252 
00253     if( ism >= 19 && ism <= 36 ) return( ism-18 );
00254 
00255     throw cms::Exception("InvalidParameter") << "Wrong SM id: iSM = " << ism;
00256 
00257   } else if( subdet == EcalEndcap ) {
00258 
00259     if( ism >=  1 && ism <=  9 ) return( ism+9 );
00260 
00261     if (ism >= 10 && ism <= 18 ) return( ism-9 );
00262 
00263     throw cms::Exception("InvalidParameter") << "Wrong SM id: iSM = " << ism;
00264 
00265   }
00266 
00267   throw cms::Exception("InvalidParameter") << "Invalid subdetector: subdet = " << subdet;
00268 
00269 }
00270 
00271 //-------------------------------------------------------------------------
00272 
00273 unsigned
00274 Numbers::iSM( const EBDetId& id )
00275 {
00276 
00277   if( !Numbers::map ) throw cms::Exception("ObjectUnavailable") << "ECAL Geometry not available";
00278 
00279   const EcalElectronicsId eid = Numbers::map->getElectronicsId(id);
00280   int idcc = eid.dccId();
00281 
00282   // EB-/EB+
00283   if( idcc >= 10 && idcc <= 45 ) return( idcc - 9 );
00284 
00285   throw cms::Exception("InvalidParameter") << "Wrong DCC id: dcc = " << idcc;
00286 
00287 }
00288 
00289 
00290 //-------------------------------------------------------------------------
00291 
00292 unsigned
00293 Numbers::iSM( const EEDetId& id )
00294 {
00295 
00296   if( !Numbers::map ) throw cms::Exception("ObjectUnavailable") << "ECAL Geometry not available";
00297 
00298   const EcalElectronicsId eid = Numbers::map->getElectronicsId(id);
00299   int idcc = eid.dccId();
00300 
00301   // EE-
00302   if( idcc >=  1 && idcc <=  9 ) return( idcc );
00303 
00304   // EE+
00305   if( idcc >= 46 && idcc <= 54 ) return( idcc - 45 + 9 );
00306 
00307   throw cms::Exception("InvalidParameter") << "Wrong DCC id: dcc = " << idcc;
00308 
00309 }
00310 
00311 //-------------------------------------------------------------------------
00312 
00313 unsigned
00314 Numbers::iSM( const EcalTrigTowerDetId& id )
00315 {
00316 
00317   if( !Numbers::map ) throw cms::Exception("ObjectUnavailable") << "ECAL Geometry not available";
00318 
00319   EcalSubdetector subdet = Numbers::subDet( id );
00320 
00321   if( subdet == EcalBarrel ) {
00322 
00323     int idcc = Numbers::map->DCCid(id);
00324 
00325     // EB-/EB+
00326     if( idcc >= 10 && idcc <= 45 ) return( idcc - 9 );
00327 
00328     throw cms::Exception("InvalidParameter") << "Wrong DCC id: dcc = " << idcc;
00329 
00330   } else if( subdet ==  EcalEndcap) {
00331 
00332     int idcc = Numbers::map->DCCid(id);
00333 
00334     // EE-
00335     if( idcc >=  1 && idcc <=  9 ) return( idcc );
00336 
00337     // EE+
00338     if( idcc >= 46 && idcc <= 54 ) return( idcc - 45 + 9 );
00339 
00340     throw cms::Exception("InvalidParameter") << "Wrong DCC id: dcc = " << idcc;
00341 
00342   }
00343 
00344   throw cms::Exception("InvalidParameter") << "Invalid subdetector: subdet = " << subdet;
00345 
00346 }
00347 
00348 //-------------------------------------------------------------------------
00349 
00350 unsigned
00351 Numbers::iSM( const EcalElectronicsId& id )
00352 {
00353 
00354   int idcc = id.dccId();
00355 
00356   // EE-
00357   if( idcc >=  1 && idcc <=  9 ) return( idcc );
00358 
00359   // EB-/EB+
00360   if( idcc >= 10 && idcc <= 45 ) return( idcc - 9 );
00361 
00362   // EE+
00363   if( idcc >= 46 && idcc <= 54 ) return( idcc - 45 + 9 );
00364 
00365   throw cms::Exception("InvalidParameter") << "Wrong DCC id: dcc = " << idcc;
00366 
00367 }
00368 
00369 //-------------------------------------------------------------------------
00370 
00371 unsigned
00372 Numbers::iSM( const EcalPnDiodeDetId& id )
00373 {
00374 
00375   int idcc = id.iDCCId();
00376 
00377   // EE-
00378   if( idcc >=  1 && idcc <=  9 ) return( idcc );
00379 
00380   // EB-/EB+
00381   if( idcc >= 10 && idcc <= 45 ) return( idcc - 9 );
00382 
00383   // EE+
00384   if( idcc >= 46 && idcc <= 54 ) return( idcc - 45 + 9 );
00385 
00386   throw cms::Exception("InvalidParameter") << "Wrong DCC id: dcc = " << idcc;
00387 
00388 }
00389 
00390 //-------------------------------------------------------------------------
00391 
00392 unsigned
00393 Numbers::iSM( const EcalScDetId& id )
00394 {
00395 
00396   std::pair<int, int> dccsc = Numbers::map->getDCCandSC( id );
00397 
00398   int idcc = dccsc.first;
00399 
00400   // EE-
00401   if( idcc >=  1 && idcc <=  9 ) return( idcc );
00402 
00403   // EB-/EB+
00404   if( idcc >= 10 && idcc <= 45 ) return( idcc - 9 );
00405 
00406   // EE+
00407   if( idcc >= 46 && idcc <= 54 ) return( idcc - 45 + 9 );
00408 
00409   throw cms::Exception("InvalidParameter") << "Wrong DCC id: dcc = " << idcc;
00410 
00411 }
00412 
00413 //-------------------------------------------------------------------------
00414 
00415 unsigned
00416 Numbers::iSM( const EcalDCCHeaderBlock& id, const EcalSubdetector subdet )
00417 {
00418 
00419   int idcc = id.id();
00420 
00421   // EE-
00422   if( idcc >=  1 && idcc <=  9 ) return( idcc );
00423 
00424   // EB-/EB+
00425   if( idcc >= 10 && idcc <= 45 ) return( idcc - 9 );
00426 
00427   // EE+
00428   if( idcc >= 46 && idcc <= 54 ) return( idcc - 45 + 9 );
00429 
00430   throw cms::Exception("InvalidParameter") << "Wrong DCC id: dcc = " << idcc;
00431 
00432 }
00433 
00434 //-------------------------------------------------------------------------
00435 
00436 unsigned
00437 Numbers::iSC( const EcalScDetId& id )
00438 {
00439 
00440     std::pair<int, int> dccsc = Numbers::map->getDCCandSC( id );
00441 
00442     return static_cast<unsigned>(dccsc.second);
00443 
00444 }
00445 
00446 //-------------------------------------------------------------------------
00447 
00448 unsigned
00449 Numbers::iSC( const unsigned ism, const EcalSubdetector subdet, const unsigned i1, const unsigned i2 )
00450 {
00451 
00452   if( subdet == EcalBarrel ) {
00453 
00454     int iet = 1 + ((i1-1)/5);
00455     int ipt = 1 + ((i2-1)/5);
00456 
00457     return( (ipt-1) + 4*(iet-1) + 1 );
00458 
00459   } else if( subdet == EcalEndcap ) {
00460 
00461     if( !Numbers::map ) throw( std::runtime_error( "ECAL Geometry not available" ) );
00462 
00463     // use ism only for determination of +/-
00464 
00465     int iz = 0;
00466 
00467     if( ism >=  1 && ism <=  9 ) iz = -1;
00468     if( ism >= 10 && ism <= 18 ) iz = +1;
00469 
00470     EEDetId id(i1, i2, iz, EEDetId::XYMODE); // throws an exception if invalid
00471 
00472     const EcalElectronicsId eid = Numbers::map->getElectronicsId(id);
00473 
00474     return( static_cast<unsigned>( eid.towerId() ));
00475 
00476   }
00477 
00478   throw cms::Exception("InvalidParameter") << "Invalid subdetector: subdet = " << subdet;
00479 
00480 }
00481 
00482 //-------------------------------------------------------------------------
00483 
00484 unsigned
00485 Numbers::iTT( const unsigned ism, const EcalSubdetector subdet, const unsigned i1, const unsigned i2 )
00486 {
00487 
00488   if( subdet == EcalBarrel ) {
00489 
00490     return( Numbers::iSC(ism, subdet, i1, i2) );
00491 
00492   } else if( subdet == EcalEndcap ) {
00493 
00494     if( !Numbers::mapTT ) throw cms::Exception("ObjectUnavailable") << "ECAL Geometry not available";
00495 
00496     // use ism only for determination of +/-
00497 
00498     int iz = 0;
00499 
00500     if( ism >=  1 && ism <=  9 ) iz = -1;
00501     if( ism >= 10 && ism <= 18 ) iz = +1;
00502 
00503     EEDetId id(i1, i2, iz, EEDetId::XYMODE); // throws an exception if invalid
00504 
00505     const EcalTrigTowerDetId towid = Numbers::mapTT->towerOf(id);
00506 
00507     return( static_cast<unsigned>( iTT(towid) ) );
00508 
00509   }
00510 
00511   throw cms::Exception("InvalidParameter") << "Invalid subdetector: subdet = " << subdet;
00512 
00513 }
00514 
00515 //-------------------------------------------------------------------------
00516 
00517 unsigned
00518 Numbers::iTT( const EcalTrigTowerDetId& id )
00519 {
00520 
00521   if( !Numbers::map ) throw cms::Exception("ObjectUnavailable") << "ECAL Geometry not available";
00522 
00523   EcalSubdetector subdet = Numbers::subDet( id );
00524 
00525   if( subdet == EcalBarrel || subdet ==  EcalEndcap ) return( static_cast<unsigned>( Numbers::map->iTT(id) ) );
00526 
00527   throw cms::Exception("InvalidParameter") << "Invalid subdetector: subdet = " << subdet;
00528 
00529 }
00530 
00531 //-------------------------------------------------------------------------
00532 
00533 unsigned
00534 Numbers::iTCC( const unsigned ism, const EcalSubdetector subdet, const unsigned i1, const unsigned i2 )
00535 {
00536 
00537   if( !Numbers::mapTT ) throw cms::Exception("ObjectUnavailable") << "ECAL Geometry not available";
00538 
00539   if( subdet == EcalBarrel ) {
00540 
00541     EBDetId id(i1, i2, EBDetId::ETAPHIMODE);
00542 
00543     const EcalTrigTowerDetId towid = Numbers::mapTT->towerOf(id);
00544 
00545     return( static_cast<unsigned>( Numbers::map->TCCid(towid) ) );
00546 
00547   } else if( subdet ==  EcalEndcap) {
00548 
00549     int iz = 0;
00550 
00551     if( ism >=  1 && ism <=  9 ) iz = -1;
00552     if( ism >= 10 && ism <= 18 ) iz = +1;
00553 
00554     EEDetId id(i1, i2, iz, EEDetId::XYMODE);
00555 
00556     const EcalTrigTowerDetId towid = Numbers::mapTT->towerOf(id);
00557 
00558     return( static_cast<unsigned>( Numbers::map->TCCid(towid) ) );
00559 
00560   }
00561 
00562   throw cms::Exception("InvalidSubdetector") << "subdet = " << subdet;
00563 
00564 }
00565 
00566 //-------------------------------------------------------------------------
00567 
00568 unsigned
00569 Numbers::iTCC( const EcalTrigTowerDetId& id )
00570 {
00571 
00572   if( !Numbers::map ) throw cms::Exception("ObjectUnavailable") << "ECAL Geometry not available";
00573 
00574   EcalSubdetector subdet = Numbers::subDet( id );
00575 
00576   if( subdet == EcalBarrel || subdet == EcalEndcap ) return( static_cast<unsigned>( Numbers::map->TCCid(id) ) );
00577 
00578   throw cms::Exception("InvalidParameter") << "Invalid subdetector: subdet = " << subdet;
00579 
00580 }
00581 
00582 //-------------------------------------------------------------------------
00583 
00584 std::vector<DetId> *
00585 Numbers::crystals( const EcalTrigTowerDetId& id )
00586 {
00587 
00588   if( !Numbers::map ) throw cms::Exception("ObjectUnavailable") << "ECAL Geometry not available";
00589 
00590   int itcc = Numbers::map->TCCid(id);
00591   int itt = Numbers::map->iTT(id);
00592 
00593   unsigned index = 100*(itcc-1) + (itt-1);
00594 
00595   if( index >= crystalsTCCArraySize_ ) throw cms::Exception("InvalidParameter") << "TCC index " << index;
00596 
00597   if ( Numbers::crystalsTCC_[index].size() == 0 ) {
00598     Numbers::crystalsTCC_[index] = Numbers::map->ttConstituents( itcc, itt );
00599   }
00600 
00601   return &(Numbers::crystalsTCC_[index]);
00602 
00603 }
00604 
00605 //-------------------------------------------------------------------------
00606 
00607 unsigned
00608 Numbers::RtHalf(const EBDetId& id)
00609 {
00610 
00611   int ic = id.ic();
00612   int ie = (ic-1)/20 + 1;
00613   int ip = (ic-1)%20 + 1;
00614 
00615   if( ie > 5 && ip < 11 ) return 1;
00616 
00617   return 0;
00618 
00619 }
00620 
00621 //-------------------------------------------------------------------------
00622 
00623 unsigned
00624 Numbers::RtHalf(const EEDetId& id)
00625 {
00626 
00627   int ix = id.ix();
00628 
00629   int ism = Numbers::iSM( id );
00630 
00631   // EE-05
00632   if ( ism ==  8 && ix > 50 ) return 1;
00633 
00634   // EE+05
00635   if ( ism == 17 && ix > 50 ) return 1;
00636 
00637   return 0;
00638 
00639 }
00640 
00641 //-------------------------------------------------------------------------
00642 
00643 std::vector<DetId> *
00644 Numbers::crystals( const EcalElectronicsId& id )
00645 {
00646 
00647   if( !Numbers::map ) throw cms::Exception("ObjectUnavailable") << "ECAL Geometry not available";
00648 
00649   int idcc = id.dccId();
00650   int isc = id.towerId();
00651 
00652   return Numbers::crystals( idcc, isc );
00653 
00654 }
00655 
00656 //-------------------------------------------------------------------------
00657 
00658 std::vector<DetId> *
00659 Numbers::crystals( unsigned idcc, unsigned isc )
00660 {
00661 
00662   if( !Numbers::map ) throw cms::Exception("ObjectUnavailable") << "ECAL Geometry not available";
00663 
00664   unsigned index = 100*(idcc-1) + (isc-1);
00665 
00666   if( index > crystalsDCCArraySize_ ) throw cms::Exception("InvalidParameter") << "DCC index " << index;
00667 
00668   if ( Numbers::crystalsDCC_[index].size() == 0 ) {
00669     Numbers::crystalsDCC_[index] = Numbers::map->dccTowerConstituents(idcc, isc);
00670   }
00671 
00672   return &(Numbers::crystalsDCC_[index]);
00673 
00674 }
00675 
00676 //-------------------------------------------------------------------------
00677 
00678 const EcalScDetId
00679 Numbers::getEcalScDetId( const EEDetId& id )
00680 {
00681 
00682   if( !Numbers::map ) throw cms::Exception("ObjectUnavailable") << "ECAL Geometry not available";
00683 
00684   const EcalElectronicsId& eid = Numbers::map->getElectronicsId(id);
00685 
00686   int idcc = eid.dccId();
00687   int isc = eid.towerId();
00688 
00689   const std::vector<EcalScDetId> ids = Numbers::map->getEcalScDetId( idcc, isc, true );
00690 
00691   return ids.size() > 0 ? ids[0] : EcalScDetId();
00692 
00693 }
00694 
00695 //-------------------------------------------------------------------------
00696 
00697 unsigned
00698 Numbers::indexEB( const unsigned ism, const unsigned ie, const unsigned ip )
00699 {
00700 
00701   unsigned ic = (ip-1) + 20*(ie-1) + 1;
00702 
00703   if( ic == 0 || ic > static_cast<unsigned>( EBDetId::kCrystalsPerSM ) ) throw cms::Exception("InvalidParameter") << "ism=" << ism << " ie=" << ie << " ip=" << ip;
00704 
00705   return ic;
00706 
00707 }
00708 
00709 //-------------------------------------------------------------------------
00710 
00711 unsigned
00712 Numbers::indexEE( const unsigned ism, const unsigned ix, const unsigned iy )
00713 {
00714 
00715   int iz = 0;
00716 
00717   if( ism >=  1 && ism <=  9 ) iz = -1;
00718   if( ism >= 10 && ism <= 18 ) iz = +1;
00719 
00720   if( !EEDetId::validDetId(ix, iy, iz) ) throw cms::Exception("InvalidParameter") << "ism=" << ism << " ix=" << ix << " iy=" << iy;
00721 
00722   return( 1000*ix + iy );
00723 
00724 }
00725 
00726 //-------------------------------------------------------------------------
00727 
00728 unsigned
00729 Numbers::icEB( const unsigned ism, const unsigned ie, const unsigned ip )
00730 {
00731 
00732   return Numbers::indexEB( ism, ie, ip );
00733 
00734 }
00735 
00736 //-------------------------------------------------------------------------
00737 
00738 unsigned
00739 Numbers::icEE( const unsigned ism, const unsigned ix, const unsigned iy )
00740 {
00741 
00742   if( !Numbers::map ) throw cms::Exception("ObjectUnavailable") << "ECAL Geometry not available";
00743 
00744   int iz = 0;
00745 
00746   if( ism >=  1 && ism <=  9 ) iz = -1;
00747   if( ism >= 10 && ism <= 18 ) iz = +1;
00748 
00749   EEDetId id(ix, iy, iz, EEDetId::XYMODE);
00750 
00751   const EcalElectronicsId eid = Numbers::map->getElectronicsId(id);
00752 
00753   int vfe = eid.towerId();
00754   int strip = eid.stripId();
00755   int channel = eid.xtalId();
00756 
00757   // EE-05 & EE+05
00758   if( ism == 8 || ism == 17 ) {
00759     if( vfe > 17 ) vfe = vfe - 7;
00760   }
00761 
00762   unsigned ic = (vfe-1)*25 + (strip-1)*5 + channel;
00763 
00764   if( ic == 0 || ic > static_cast<unsigned>( EEDetId::kSizeForDenseIndexing ) ) throw cms::Exception("InvalidParameter") << "ic=" << ic;
00765 
00766   return ic;
00767 
00768 }
00769 
00770 //-------------------------------------------------------------------------
00771 
00772 int
00773 Numbers::ix0EE( const unsigned ism )
00774 {
00775 
00776   if( ism == 1 || ism == 15 ) return( -  5 );
00777   if( ism == 2 || ism == 14 ) return( +  0 );
00778   if( ism == 3 || ism == 13 ) return( + 10 );
00779   if( ism == 4 || ism == 12 ) return( + 40 );
00780   if( ism == 5 || ism == 11 ) return( + 50 );
00781   if( ism == 6 || ism == 10 ) return( + 55 );
00782   if( ism == 7 || ism == 18 ) return( + 50 );
00783   if( ism == 8 || ism == 17 ) return( + 25 );
00784   if( ism == 9 || ism == 16 ) return( +  0 );
00785 
00786   return( + 0 );
00787 
00788 }
00789 
00790 //-------------------------------------------------------------------------
00791 
00792 int
00793 Numbers::ix0EEm( const unsigned ism )
00794 {
00795 
00796   switch( ism ){
00797   case 1: return -105;
00798   case 2: return -100;
00799   case 3: return -90;
00800   case 4: return -60;
00801   case 5: return -50;
00802   case 6: return -45;
00803   case 7: return -50;
00804   case 8: return -75;
00805   case 9: return -100;
00806   }
00807 
00808   return ix0EE( ism );
00809 }
00810 
00811 int
00812 Numbers::iy0EE( const unsigned ism )
00813 {
00814 
00815   if( ism == 1 || ism == 10 ) return( + 20 );
00816   if( ism == 2 || ism == 11 ) return( + 45 );
00817   if( ism == 3 || ism == 12 ) return( + 55 );
00818   if( ism == 4 || ism == 13 ) return( + 55 );
00819   if( ism == 5 || ism == 14 ) return( + 45 );
00820   if( ism == 6 || ism == 15 ) return( + 20 );
00821   if( ism == 7 || ism == 16 ) return( +  0 );
00822   if( ism == 8 || ism == 17 ) return( -  5 );
00823   if( ism == 9 || ism == 18 ) return( +  0 );
00824 
00825   return( + 0 );
00826 
00827 }
00828 
00829 //-------------------------------------------------------------------------
00830 
00831 bool
00832 Numbers::validEE( const unsigned ism, const unsigned ix, const unsigned iy )
00833 {
00834 
00835   int iz = 0;
00836 
00837   if( ism >=  1 && ism <=  9 ) iz = -1;
00838   if( ism >= 10 && ism <= 18 ) iz = +1;
00839 
00840   if( EEDetId::validDetId(ix, iy, iz) ) {
00841 
00842     EEDetId id(ix, iy, iz, EEDetId::XYMODE);
00843 
00844     if( Numbers::iSM( id ) == ism ) return true;
00845 
00846   }
00847 
00848   return false;
00849 
00850 }
00851 
00852 //-------------------------------------------------------------------------
00853 
00854 bool
00855 Numbers::validEESc( const unsigned ism, const unsigned ix, const unsigned iy )
00856 {
00857 
00858   int iz = 0;
00859 
00860   if( ism >=  1 && ism <=  9 ) iz = -1;
00861   if( ism >= 10 && ism <= 18 ) iz = +1;
00862 
00863   if( EcalScDetId::validDetId(ix, iy, iz) ) {
00864 
00865     EcalScDetId id(ix, iy, iz);
00866 
00867     if( Numbers::iSM( id ) == ism ) return true;
00868 
00869   }
00870 
00871   return false;
00872 }
00873 
00874 unsigned
00875 Numbers::nCCUs(const unsigned ism)
00876 {
00877   switch(ism){
00878   case 8:
00879   case 17:
00880     return 41;
00881   case 1:
00882   case 6:
00883   case 10:
00884   case 15:
00885     return 34;
00886   case 3:
00887   case 12:
00888   case 4:
00889   case 13:
00890   case 7:
00891   case 16:
00892   case 9:
00893   case 18:
00894     return 33;
00895   case 2:
00896   case 11:
00897   case 5:
00898   case 14:
00899     return 32;
00900   default:
00901     return 0;
00902   }
00903 }
00904 
00905 unsigned
00906 Numbers::nTTs(const unsigned itcc)
00907 {
00908   using namespace std;
00909   vector<DetId> crystals(map->tccConstituents(itcc));
00910 
00911   set<int> itts;
00912   for(vector<DetId>::iterator cItr(crystals.begin()); cItr != crystals.end(); ++cItr)
00913     itts.insert(map->iTT(mapTT->towerOf(*cItr)));
00914 
00915   return itts.size();
00916 }
00917 
00918 const EcalElectronicsMapping *
00919 Numbers::getElectronicsMapping()
00920 {
00921 
00922   if( !Numbers::map ) throw cms::Exception("ObjectUnavailable") << "ECAL Geometry not available";
00923 
00924   return Numbers::map;
00925 
00926 }
00927 
00928 float
00929 Numbers::eta( const DetId &id )
00930 {
00931   const GlobalPoint& pos = geometry->getPosition(id);
00932   return pos.eta();
00933 }
00934 
00935 float
00936 Numbers::phi( const DetId &id )
00937 {
00938   const GlobalPoint& pos = geometry->getPosition(id);
00939   return pos.phi();
00940 }
00941