00001 #include "Kernel/HitPattern.h"
00002
00003 namespace LHCb
00004 {
00005 HitPattern::HitPattern( const std::vector<LHCbID>& ids )
00006 {
00007 for( std::vector<LHCbID>::const_iterator id = ids.begin() ;
00008 id != ids.end(); ++id) {
00009 switch( id->detectorType() ) {
00010 case LHCbID::Velo:
00011 {
00012 LHCb::VeloChannelID veloid = id->veloID() ;
00013 unsigned int station = (veloid.sensor()%64)/2 ;
00014 unsigned int side = (veloid.sensor()%2) ;
00015 unsigned int type = (veloid.sensor()/64) ;
00016
00017
00018
00019
00020 station += 2*(1-type/2) ;
00021 type = type%2 ;
00022 m_velo[side+2*type].set(station) ;
00023 }
00024 break ;
00025 case LHCbID::TT:
00026 {
00027 LHCb::STChannelID stid = id->stID() ;
00028 unsigned int uniquelayer = (stid.station()-1)*2 + stid.layer()-1 ;
00029 m_tt.set(uniquelayer) ;
00030 }
00031 break ;
00032 case LHCbID::IT:
00033 {
00034 LHCb::STChannelID stid = id->stID() ;
00035 unsigned int uniquelayer = (stid.station()-1)*4 + stid.layer()-1 ;
00036 m_it[stid.detRegion()-1].set(uniquelayer) ;
00037 }
00038 break ;
00039 case LHCbID::OT:
00040 {
00041 LHCb::OTChannelID otid = id->otID() ;
00042 unsigned int uniquelayer = (otid.station()-1)*4 + otid.layer() ;
00043 m_ot[otid.quarter()].set(uniquelayer) ;
00044 }
00045 break ;
00046 case LHCbID::Muon:
00047 {
00048 LHCb::MuonTileID muonid = id->muonID() ;
00049 std::cout << "muon station : " << muonid.station() << std::endl ;
00050 m_muon.set( muonid.station()-1 ) ;
00051 }
00052 break ;
00053 default:
00054 ;
00055 }
00056 }
00057 }
00058
00059 std::ostream& HitPattern::fillStream(std::ostream& s) const
00060 {
00061 s << "veloRA: " << m_velo[VeloRA] << std::endl
00062 << "veloRC: " << m_velo[VeloRC] << std::endl
00063 << "veloPhiA: " << m_velo[VeloPhiA] << std::endl
00064 << "veloPhiC: " << m_velo[VeloPhiC] << std::endl
00065 << "TT : " << m_tt << std::endl
00066 << "IT-top: " << m_it[ITTop] << std::endl
00067 << "IT-bot: " << m_it[ITBottom] << std::endl
00068 << "IT-A: " << m_it[ITA] << std::endl
00069 << "IT-C: " << m_it[ITC] << std::endl
00070 << "OT-topA: " << m_ot[OTTopA] << std::endl
00071 << "OT-botA: " << m_ot[OTBottomA] << std::endl
00072 << "OT-topC: " << m_ot[OTTopC] << std::endl
00073 << "OT-botC: " << m_ot[OTBottomC] << std::endl
00074 << "Muon: " << m_muon << std::endl ;
00075 return s ;
00076 }
00077
00078
00079 inline std::bitset<3> hitStations( const std::bitset<HitPattern::NumT>& layers )
00080 {
00081 unsigned long pat = layers.to_ulong() ;
00082 std::bitset<3> rc ;
00083 rc.set(0, pat & 0xF ) ;
00084 rc.set(1, pat & 0xF0 ) ;
00085 rc.set(2, pat & 0xF00 ) ;
00086 return rc ;
00087 }
00088
00089
00090 template<size_t N>
00091 int firstbitset(std::bitset<N> mask) {
00092 int n(0) ;
00093 for( ; n<int(N) && !mask.test(n) ; ++n) {}
00094 return n ;
00095 }
00096
00097
00098 template<size_t N>
00099 int lastbitset(std::bitset<N> mask) {
00100 int n(N-1) ;
00101 for( ; n>=0 && !mask.test(n) ; --n) {}
00102 return n ;
00103 }
00104
00105 size_t HitPattern::numVeloStationsOverlap() const {
00106 return (( m_velo[VeloRA] | m_velo[VeloPhiA] ) &
00107 ( m_velo[VeloRC] | m_velo[VeloPhiC] )).count() ;
00108 }
00109
00110 size_t HitPattern::numITStationsOverlap() const {
00111 return (( hitStations( m_it[ITC] ) & hitStations( m_it[ITBottom] ) )|
00112 ( hitStations( m_it[ITC] ) & hitStations( m_it[ITTop] ) )|
00113 ( hitStations( m_it[ITA] ) & hitStations( m_it[ITBottom] ) )|
00114 ( hitStations( m_it[ITA] ) & hitStations( m_it[ITTop] ) )).count() ;
00115 }
00116
00117 size_t HitPattern::numITOTStationsOverlap() const {
00118 return ( hitStations( it() ) & hitStations( ot() ) ).count() ;
00119 }
00120
00121 size_t HitPattern::numVeloHoles() const {
00122 std::bitset<NumVelo> veloPhi = m_velo[VeloPhiA] | m_velo[VeloPhiC] ;
00123 std::bitset<NumVelo> veloR = m_velo[VeloRA] | m_velo[VeloRC] ;
00124 std::bitset<NumVelo> velo = veloPhi | veloR ;
00125 size_t rc(0) ;
00126 if( velo.any() ) {
00127
00128 int firstbit = firstbitset(velo) ;
00129 int lastbit = lastbitset(velo) ;
00130 for( int n=firstbit+1; n<lastbit; ++n)
00131 rc += (veloPhi.test(n) ? 0 : 1) + (veloR.test(n) ? 0 : 1) ;
00132
00133
00134
00135 }
00136 return rc ;
00137 }
00138
00139 size_t HitPattern::numTHoles() const {
00140 std::bitset<NumT> layers =
00141 m_it[ITC] | m_it[ITBottom] |
00142 m_it[ITA] | m_it[ITTop] |
00143 m_ot[OTTopA] | m_ot[OTTopC] |
00144 m_ot[OTBottomA] | m_ot[OTBottomC] ;
00145 size_t rc(0) ;
00146 if(layers.any()) {
00147 int firstbit = firstbitset(layers) ;
00148 int lastbit = lastbitset(layers) ;
00149 for( int n=firstbit+1; n<lastbit; ++n)
00150 rc += layers.test(n) ? 0 : 1 ;
00151 }
00152 return rc ;
00153 }
00154 }
00155