CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/CondFormats/L1TObjects/src/L1CaloGeometry.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     L1Geometry
00004 // Class  :     L1CaloGeometry
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Werner Sun
00010 //         Created:  Mon Oct 23 21:52:36 EDT 2006
00011 // $Id: L1CaloGeometry.cc,v 1.5 2009/10/30 03:33:28 wsun Exp $
00012 //
00013 
00014 // system include files
00015 #include <cmath>
00016 
00017 // user include files
00018 #include "CondFormats/L1TObjects/interface/L1CaloGeometry.h"
00019 
00020 
00021 //
00022 // constants, enums and typedefs
00023 //
00024 
00025 //
00026 // static data member definitions
00027 //
00028 
00029 // double L1CaloGeometry::m_gctEmJetPhiOffset =
00030 //    -M_PI / L1CaloGeometry::kNumberGctEmJetPhiBins ;
00031 // double L1CaloGeometry::m_gctEtSumPhiOffset = 0. ;
00032 
00033 // double L1CaloGeometry::m_gctEmJetPhiBinWidth =
00034 //    2. * M_PI / L1CaloGeometry::kNumberGctEmJetPhiBins ;
00035 // double L1CaloGeometry::m_gctEtSumPhiBinWidth =
00036 //    2. * M_PI / L1CaloGeometry::kNumberGctEtSumPhiBins ;
00037 
00038 // double L1CaloGeometry::m_gctEtaBinBoundaries[
00039 //    kNumberGctCentralEtaBinsPerHalf + kNumberGctForwardEtaBinsPerHalf + 1 ] = {
00040 //       0.0000,
00041 //       0.3480,
00042 //       0.6950,
00043 //       1.0440,
00044 //       1.3920,
00045 //       1.7400,
00046 //       2.1720,
00047 //       3.0000,
00048 //       3.5000,
00049 //       4.0000,
00050 //       4.5000,
00051 //       5.0000 } ;
00052 
00053 //
00054 // constructors and destructor
00055 //
00056 L1CaloGeometry::L1CaloGeometry()
00057   : m_version( kOrig ), // if version is not in CondDB, set it to kOrig
00058     m_numberGctEmJetPhiBins( 0 ),
00059     m_numberGctEtSumPhiBins( 0 ),
00060     m_numberGctHtSumPhiBins( 0 ),
00061     m_numberGctCentralEtaBinsPerHalf( 0 ),
00062     m_numberGctForwardEtaBinsPerHalf( 0 ),
00063     m_etaSignBitOffset( 0 ),
00064     m_gctEtaBinBoundaries(),
00065     m_etaBinsPerHalf( 0 ),
00066     m_gctEmJetPhiBinWidth( 0. ),
00067     m_gctEtSumPhiBinWidth( 0. ),
00068     m_gctHtSumPhiBinWidth( 0. ),
00069     m_gctEmJetPhiOffset( 0. ),
00070     m_gctEtSumPhiOffset( 0. ),
00071     m_gctHtSumPhiOffset( 0. )
00072 {
00073 }
00074 
00075 L1CaloGeometry::L1CaloGeometry( unsigned int numberGctEmJetPhiBins,
00076                                 double gctEmJetPhiBinOffset,
00077                                 unsigned int numberGctEtSumPhiBins,
00078                                 double gctEtSumPhiBinOffset,
00079                                 unsigned int numberGctHtSumPhiBins,
00080                                 double gctHtSumPhiBinOffset,
00081                                 unsigned int numberGctCentralEtaBinsPerHalf,
00082                                 unsigned int numberGctForwardEtaBinsPerHalf,
00083                                 unsigned int etaSignBitOffset,
00084                                 const std::vector<double>& gctEtaBinBoundaries)
00085   : m_version( kAddedMHTPhi ),
00086     m_numberGctEmJetPhiBins( numberGctEmJetPhiBins ),
00087     m_numberGctEtSumPhiBins( numberGctEtSumPhiBins ),
00088     m_numberGctHtSumPhiBins( numberGctHtSumPhiBins ),
00089     m_numberGctCentralEtaBinsPerHalf( numberGctCentralEtaBinsPerHalf ),
00090     m_numberGctForwardEtaBinsPerHalf( numberGctForwardEtaBinsPerHalf ),
00091     m_etaSignBitOffset( etaSignBitOffset ),
00092     m_gctEtaBinBoundaries( gctEtaBinBoundaries )
00093 {
00094   m_etaBinsPerHalf =
00095     m_numberGctCentralEtaBinsPerHalf + m_numberGctForwardEtaBinsPerHalf ;
00096 
00097   m_gctEmJetPhiBinWidth = 2. * M_PI / m_numberGctEmJetPhiBins ;
00098   m_gctEtSumPhiBinWidth = 2. * M_PI / m_numberGctEtSumPhiBins ;
00099   m_gctHtSumPhiBinWidth = 2. * M_PI / m_numberGctHtSumPhiBins ;
00100 
00101   m_gctEmJetPhiOffset = gctEmJetPhiBinOffset * m_gctEmJetPhiBinWidth ;
00102   m_gctEtSumPhiOffset = gctEtSumPhiBinOffset * m_gctEtSumPhiBinWidth ;
00103   m_gctHtSumPhiOffset = gctHtSumPhiBinOffset * m_gctHtSumPhiBinWidth ;
00104 }
00105 
00106 // L1CaloGeometry::L1CaloGeometry(const L1CaloGeometry& rhs)
00107 // {
00108 //    // do actual copying here;
00109 // }
00110 
00111 L1CaloGeometry::~L1CaloGeometry()
00112 {
00113 }
00114 
00115 //
00116 // assignment operators
00117 //
00118 // const L1CaloGeometry& L1CaloGeometry::operator=(const L1CaloGeometry& rhs)
00119 // {
00120 //   //An exception safe implementation is
00121 //   L1CaloGeometry temp(rhs);
00122 //   swap(rhs);
00123 //
00124 //   return *this;
00125 // }
00126 
00127 //
00128 // member functions
00129 //
00130 
00131 //
00132 // const member functions
00133 //
00134 
00135 double
00136 L1CaloGeometry::globalEtaBinCenter( unsigned int globalEtaIndex ) const
00137 {
00138    int etaIndex ;
00139    double etaSign = 1. ;
00140    if( globalEtaIndex < m_etaBinsPerHalf )
00141    {
00142       etaIndex = m_etaBinsPerHalf - globalEtaIndex - 1 ;
00143       etaSign = -1. ;
00144    }
00145    else
00146    {
00147       etaIndex = globalEtaIndex - m_etaBinsPerHalf ;
00148    }
00149 
00150    return 0.5 * etaSign *
00151       ( m_gctEtaBinBoundaries[ etaIndex ] +
00152         m_gctEtaBinBoundaries[ etaIndex + 1 ] ) ;
00153 }
00154 
00155 double
00156 L1CaloGeometry::globalEtaBinLowEdge( unsigned int globalEtaIndex ) const
00157 {
00158    int etaIndex ;
00159    double etaSign = 1. ;
00160    if( globalEtaIndex < m_etaBinsPerHalf )
00161    {
00162       etaIndex = m_etaBinsPerHalf - globalEtaIndex - 1 ;
00163       etaSign = -1. ;
00164    }
00165    else
00166    {
00167       etaIndex = globalEtaIndex - m_etaBinsPerHalf ;
00168    }
00169 
00170    return ( etaSign > 0. ? 
00171             m_gctEtaBinBoundaries[ etaIndex ] :
00172             -m_gctEtaBinBoundaries[ etaIndex + 1 ] ) ;
00173 }
00174 
00175 double
00176 L1CaloGeometry::globalEtaBinHighEdge( unsigned int globalEtaIndex ) const
00177 {
00178    int etaIndex ;
00179    double etaSign = 1. ;
00180    if( globalEtaIndex < m_etaBinsPerHalf )
00181    {
00182       etaIndex = m_etaBinsPerHalf - globalEtaIndex - 1 ;
00183       etaSign = -1. ;
00184    }
00185    else
00186    {
00187       etaIndex = globalEtaIndex - m_etaBinsPerHalf ;
00188    }
00189 
00190    return ( etaSign > 0. ? 
00191             m_gctEtaBinBoundaries[ etaIndex + 1 ] :
00192             -m_gctEtaBinBoundaries[ etaIndex ] ) ;
00193 }
00194 
00195 double
00196 L1CaloGeometry::etaBinCenter( unsigned int etaIndex,
00197                               bool central ) const
00198 {
00199    // Central/tau jets and EM have etaIndex = 0-6 for eta = 0-3.
00200    // Forward jets have etaIndex = 0-3 for eta = 3-5.
00201    double etaSign = 1. ;
00202 
00203    // Check sign BEFORE shifting forward jet bin index.
00204    if( etaIndex >= m_etaSignBitOffset )
00205    {
00206       etaSign = -1. ;
00207       etaIndex -= m_etaSignBitOffset ;
00208    }
00209 
00210    // Shift forward jet bin index AFTER checking sign bit.
00211    if( !central )
00212    {
00213       etaIndex += m_numberGctCentralEtaBinsPerHalf ;
00214    }
00215 
00216    return 0.5 * etaSign *
00217       ( m_gctEtaBinBoundaries[ etaIndex ] +
00218         m_gctEtaBinBoundaries[ etaIndex + 1 ] ) ;
00219 }
00220 
00221 double
00222 L1CaloGeometry::etaBinLowEdge( unsigned int etaIndex,
00223                                bool central ) const
00224 {
00225    // Central/tau jets and EM have etaIndex = 0-6 for eta = 0-3.
00226    // Forward jets have etaIndex = 0-3 for eta = 3-5.
00227    double etaSign = 1. ;
00228 
00229    // Check sign BEFORE shifting forward jet bin index.
00230    if( etaIndex >= m_etaSignBitOffset )
00231    {
00232       etaSign = -1. ;
00233       etaIndex -= m_etaSignBitOffset ;
00234    }
00235 
00236    // Shift forward jet bin index AFTER checking sign bit.
00237    if( !central )
00238    {
00239       etaIndex += m_numberGctCentralEtaBinsPerHalf ;
00240    }
00241 
00242    return ( etaSign > 0. ? 
00243             m_gctEtaBinBoundaries[ etaIndex ] :
00244             -m_gctEtaBinBoundaries[ etaIndex + 1 ] ) ;
00245 }
00246 
00247 double
00248 L1CaloGeometry::etaBinHighEdge( unsigned int etaIndex,
00249                                 bool central ) const
00250 {
00251    // Central/tau jets and EM have etaIndex = 0-6 for eta = 0-3.
00252    // Forward jets have etaIndex = 0-3 for eta = 3-5.
00253    double etaSign = 1. ;
00254 
00255    // Check sign BEFORE shifting forward jet bin index.
00256    if( etaIndex >= m_etaSignBitOffset )
00257    {
00258       etaSign = -1. ;
00259       etaIndex -= m_etaSignBitOffset ;
00260    }
00261 
00262    // Shift forward jet bin index AFTER checking sign bit.
00263    if( !central )
00264    {
00265       etaIndex += m_numberGctCentralEtaBinsPerHalf ;
00266    }
00267 
00268    return ( etaSign > 0. ? 
00269             m_gctEtaBinBoundaries[ etaIndex + 1 ] :
00270             -m_gctEtaBinBoundaries[ etaIndex ] ) ;
00271 }
00272 
00273 double
00274 L1CaloGeometry::emJetPhiBinCenter( unsigned int phiIndex ) const
00275 {
00276    return ( ( double ) phiIndex + 0.5 ) * m_gctEmJetPhiBinWidth +
00277       m_gctEmJetPhiOffset ;
00278 }
00279 
00280 double
00281 L1CaloGeometry::emJetPhiBinLowEdge( unsigned int phiIndex ) const
00282 {
00283    return ( ( double ) phiIndex ) * m_gctEmJetPhiBinWidth +
00284       m_gctEmJetPhiOffset ;
00285 }
00286 
00287 double
00288 L1CaloGeometry::emJetPhiBinHighEdge( unsigned int phiIndex ) const
00289 {
00290    return ( ( double ) phiIndex + 1. ) * m_gctEmJetPhiBinWidth +
00291       m_gctEmJetPhiOffset ;
00292 }
00293 
00294 double
00295 L1CaloGeometry::etSumPhiBinCenter( unsigned int phiIndex ) const
00296 {
00297    return ( ( double ) phiIndex + 0.5 ) * m_gctEtSumPhiBinWidth +
00298       m_gctEtSumPhiOffset ;
00299 }
00300 
00301 double
00302 L1CaloGeometry::etSumPhiBinLowEdge( unsigned int phiIndex ) const
00303 {
00304    return ( ( double ) phiIndex ) * m_gctEtSumPhiBinWidth +
00305       m_gctEtSumPhiOffset ;
00306 }
00307 
00308 double
00309 L1CaloGeometry::etSumPhiBinHighEdge( unsigned int phiIndex ) const
00310 {
00311    return ( ( double ) phiIndex + 1. ) * m_gctEtSumPhiBinWidth +
00312       m_gctEtSumPhiOffset ;
00313 }
00314 
00315 double
00316 L1CaloGeometry::htSumPhiBinCenter( unsigned int phiIndex ) const
00317 {
00318   if( m_version == kOrig )
00319     {
00320       return ( ( double ) phiIndex + 0.5 ) * m_gctEtSumPhiBinWidth * 4. +
00321         m_gctEtSumPhiOffset ;
00322     }
00323   else
00324     {
00325       return ( ( double ) phiIndex + 0.5 ) * m_gctHtSumPhiBinWidth +
00326         m_gctHtSumPhiOffset ;
00327     }
00328 }
00329 
00330 double
00331 L1CaloGeometry::htSumPhiBinLowEdge( unsigned int phiIndex ) const
00332 {
00333   if( m_version == kOrig )
00334     {
00335       return ( ( double ) phiIndex ) * m_gctEtSumPhiBinWidth * 4. +
00336         m_gctEtSumPhiOffset ;
00337     }
00338   else
00339     {
00340       return ( ( double ) phiIndex ) * m_gctHtSumPhiBinWidth +
00341         m_gctHtSumPhiOffset ;
00342     }
00343 }
00344 
00345 double
00346 L1CaloGeometry::htSumPhiBinHighEdge( unsigned int phiIndex ) const
00347 {
00348   if( m_version == kOrig )
00349     {
00350       return ( ( double ) phiIndex + 1. ) * m_gctEtSumPhiBinWidth * 4. +
00351         m_gctEtSumPhiOffset ;
00352     }
00353   else
00354     {
00355       return ( ( double ) phiIndex + 1. ) * m_gctHtSumPhiBinWidth +
00356         m_gctHtSumPhiOffset ;
00357     }
00358 }
00359 
00360 unsigned int
00361 L1CaloGeometry::etaIndex( const double& etaValue ) const
00362 {
00363    unsigned int etaIndex = 0 ;
00364 
00365    for( unsigned int i = 0 ; i < m_numberGctCentralEtaBinsPerHalf ; ++i )
00366    {
00367       if( fabs( etaValue ) >= m_gctEtaBinBoundaries[ i ] )
00368       {
00369          etaIndex = i ;
00370       }
00371    }
00372 
00373    for( unsigned int i = 0 ; i < m_numberGctForwardEtaBinsPerHalf ; ++i )
00374    {
00375       if( fabs( etaValue ) >=
00376           m_gctEtaBinBoundaries[ i + m_numberGctCentralEtaBinsPerHalf ] )
00377       {
00378          etaIndex = i ;
00379       }
00380    }
00381 
00382    if( etaValue < 0. )
00383    {
00384       etaIndex += m_etaSignBitOffset ;
00385    }
00386 
00387    return etaIndex ;
00388 }
00389 
00390 unsigned int
00391 L1CaloGeometry::globalEtaIndex( const double& etaValue ) const
00392 {
00393    unsigned int etaIndex = 0 ;
00394 
00395    if( etaValue < 0. )
00396    {
00397       for( unsigned int i = m_etaBinsPerHalf ; i > 0 ; --i )
00398       {
00399          if( fabs( etaValue ) < m_gctEtaBinBoundaries[ i ] )
00400          {
00401             etaIndex = m_etaBinsPerHalf - i ;
00402          }
00403       }
00404    }
00405    else
00406    {
00407       for( unsigned int i = 0 ; i < m_etaBinsPerHalf ; ++i )
00408       {
00409          if( etaValue >= m_gctEtaBinBoundaries[ i ] )
00410          {
00411             etaIndex = i + m_etaBinsPerHalf ;
00412          }
00413       }
00414    }
00415 
00416    return etaIndex ;
00417 }
00418 
00419 unsigned int
00420 L1CaloGeometry::emJetPhiIndex( const double& phiValue ) const
00421 {
00422    double phiAdjusted = phiValue - m_gctEmJetPhiOffset ;
00423 
00424    // Check phiValue is between m_gctEmJetPhiOffset and m_gctEmJetPhiOffset+2pi
00425    if( phiAdjusted < 0. )
00426    {
00427       do
00428       {
00429          phiAdjusted += 2. * M_PI ;
00430       }
00431       while( phiAdjusted < 0. ) ;
00432    }
00433    else if( phiAdjusted > 2. * M_PI )
00434    {
00435       do
00436       {
00437          phiAdjusted -= 2. * M_PI ;
00438       }
00439       while( phiAdjusted > 2. * M_PI ) ;
00440    }
00441 
00442    return ( ( int ) ( phiAdjusted / m_gctEmJetPhiBinWidth ) ) ;
00443 }
00444 
00445 unsigned int
00446 L1CaloGeometry::etSumPhiIndex( const double& phiValue ) const
00447 {
00448    double phiAdjusted = phiValue - m_gctEtSumPhiOffset ;
00449 
00450    // Check phiValue is between m_gctEtSumPhiOffset and m_gctEtSumPhiOffset+2pi
00451    if( phiAdjusted < 0. )
00452    {
00453       do
00454       {
00455          phiAdjusted += 2. * M_PI ;
00456       }
00457       while( phiAdjusted < 0. ) ;
00458    }
00459    else if( phiAdjusted > 2. * M_PI )
00460    {
00461       do
00462       {
00463          phiAdjusted -= 2. * M_PI ;
00464       }
00465       while( phiAdjusted > 2. * M_PI ) ;
00466    }
00467 
00468    return ( ( int ) ( phiAdjusted / m_gctEtSumPhiBinWidth ) ) ;
00469 }
00470 
00471 unsigned int
00472 L1CaloGeometry::htSumPhiIndex( const double& phiValue ) const
00473 {
00474    double phiAdjusted = phiValue - m_gctEtSumPhiOffset ;
00475 
00476    // Check phiValue is between m_gctEtSumPhiOffset and m_gctEtSumPhiOffset+2pi
00477    if( phiAdjusted < 0. )
00478    {
00479       do
00480       {
00481          phiAdjusted += 2. * M_PI ;
00482       }
00483       while( phiAdjusted < 0. ) ;
00484    }
00485    else if( phiAdjusted > 2. * M_PI )
00486    {
00487       do
00488       {
00489          phiAdjusted -= 2. * M_PI ;
00490       }
00491       while( phiAdjusted > 2. * M_PI ) ;
00492    }
00493 
00494    if( m_version == kOrig )
00495      {
00496        return ( ( int ) ( phiAdjusted / ( m_gctEtSumPhiBinWidth * 4. ) ) ) ;
00497      }
00498    else
00499      {
00500        return ( ( int ) ( phiAdjusted / m_gctHtSumPhiBinWidth ) ) ;
00501      }
00502 }
00503 
00504 unsigned int
00505 L1CaloGeometry::numberGctHtSumPhiBins() const
00506 {
00507   if( m_version == kOrig )
00508     {
00509       return m_numberGctEtSumPhiBins / 4 ;
00510     }
00511   else
00512     {
00513       return m_numberGctHtSumPhiBins ;
00514     }
00515 }
00516 
00517 std::ostream& operator << ( std::ostream& os, const L1CaloGeometry& obj )
00518 {
00519    os << "L1CaloGeometry:" << std::endl ;
00520 
00521    os << "Central/tau eta bins: low / center / high" << std::endl ;
00522    for( unsigned int i = 0 ; i < obj.numberGctCentralEtaBinsPerHalf() ; ++i )
00523      {
00524        os << "  bin " << i << ": "
00525           << obj.etaBinLowEdge( i ) << " / "
00526           << obj.etaBinCenter( i ) << " / "
00527           << obj.etaBinHighEdge( i )
00528           << std::endl ;
00529      }
00530 
00531    os << "Forward eta bins: low / center / high" << std::endl ;
00532    for( unsigned int i = 0 ; i < obj.numberGctForwardEtaBinsPerHalf() ; ++i )
00533      {
00534        os << "  bin " << i << ": "
00535           << obj.etaBinLowEdge( i, false ) << " / "
00536           << obj.etaBinCenter( i, false ) << " / "
00537           << obj.etaBinHighEdge( i, false )
00538           << std::endl ;
00539      }
00540 
00541    os << "Global eta bins: low / center / high" << std::endl ;
00542    for( unsigned int i = 0 ; i < obj.numberGctCentralEtaBinsPerHalf() +
00543           obj.numberGctForwardEtaBinsPerHalf() ; ++i )
00544      {
00545        os << "  bin " << i << ": "
00546           << obj.globalEtaBinLowEdge( i ) << " / "
00547           << obj.globalEtaBinCenter( i ) << " / "
00548           << obj.globalEtaBinHighEdge( i )
00549           << std::endl ;
00550      }
00551 
00552    os << "EM/jet phi bins: low / center / high" << std::endl ;
00553    for( unsigned int i = 0 ; i < obj.numberGctEmJetPhiBins() ; ++i )
00554      {
00555        os << "  bin " << i << ": "
00556           << obj.emJetPhiBinLowEdge( i ) << " / "
00557           << obj.emJetPhiBinCenter( i ) << " / "
00558           << obj.emJetPhiBinHighEdge( i )
00559           << std::endl ;
00560      }
00561 
00562    os << "Et sum phi bins: low / center / high" << std::endl ;
00563    for( unsigned int i = 0 ; i < obj.numberGctEtSumPhiBins() ; ++i )
00564      {
00565        os << "  bin " << i << ": "
00566           << obj.etSumPhiBinLowEdge( i ) << " / "
00567           << obj.etSumPhiBinCenter( i ) << " / "
00568           << obj.etSumPhiBinHighEdge( i )
00569           << std::endl ;
00570      }
00571 
00572    os << "Ht sum phi bins: low / center / high" << std::endl ;
00573    for( unsigned int i = 0 ; i < obj.numberGctHtSumPhiBins() ; ++i )
00574      {
00575        os << "  bin " << i << ": "
00576           << obj.htSumPhiBinLowEdge( i ) << " / "
00577           << obj.htSumPhiBinCenter( i ) << " / "
00578           << obj.htSumPhiBinHighEdge( i )
00579           << std::endl ;
00580      }
00581 
00582    return os ;
00583 }
00584 
00585 //
00586 // static member functions
00587 //