Skip to content
Snippets Groups Projects

Reinforce misordered clusters checks

Merged Louis Henry requested to merge lohenry-refineMisordered into master
All threads resolved!
1 file
+ 41
37
Compare changes
  • Side-by-side
  • Inline
@@ -138,7 +138,7 @@ namespace {
constexpr unsigned getLinkInBank( short int c ) { return ( ( c >> FTRawBank::linkShift ) ); }
constexpr int cell( short int c ) { return ( c >> FTRawBank::cellShift ) & FTRawBank::cellMaximum; }
constexpr short int cell( short int c ) { return ( c >> FTRawBank::cellShift ) & FTRawBank::cellMaximum; }
constexpr int fraction( short int c ) { return ( c >> FTRawBank::fractionShift ) & FTRawBank::fractionMaximum; }
@@ -214,19 +214,21 @@ FTLiteClusters FTRawBankDecoder::decode<6>( const EventContext& evtCtx, LHCb::Ra
auto quarter = offset.globalQuarterIdx();
// Define Lambda functions to be used in loop
auto make_cluster = [&clus, &quarter]( unsigned int chan, int fraction, int size ) {
clus.addHit( std::forward_as_tuple( LHCb::Detector::FTChannelID{chan}, fraction, size ), quarter );
auto make_cluster = [&clus, &quarter]( int chan, int fraction, int size ) {
clus.addHit(
std::forward_as_tuple( LHCb::Detector::FTChannelID{static_cast<unsigned int>( chan )}, fraction, size ),
quarter );
};
// Make clusters between two channels
auto make_clusters = [&]( unsigned firstChannel, short int c, short int c2 ) {
unsigned int widthClus = ( cell( c2 ) - cell( c ) + 2 ); // lastCh-firstCh+4/2
auto make_clusters = [&]( int firstChannel, short int c, short int c2 ) {
short int widthClus = ( cell( c2 ) - cell( c ) + 2 ); // lastCh-firstCh+4/2
// fragmented clusters, size > 2*max size
// only edges were saved, add middles now
if ( widthClus > 8 ) {
// add the first edge cluster, and then the middle clusters
unsigned int i = 0;
short int i = 0;
for ( ; i < widthClus - 4; i += 4 ) {
// all middle clusters will have same size as the first cluster,
// for max size 4, fractions is always 1
@@ -234,7 +236,7 @@ FTLiteClusters FTRawBankDecoder::decode<6>( const EventContext& evtCtx, LHCb::Ra
}
// add the last edge
unsigned int lastChannel = firstChannel + i + std::floor( ( widthClus - i - 1 ) / 2 ) - 1;
int lastChannel = firstChannel + i + std::floor( ( widthClus - i - 1 ) / 2 ) - 1;
make_cluster( lastChannel, ( widthClus - 1 ) % 2, 0 );
} else { // big cluster size upto size 8
make_cluster( firstChannel + ( widthClus - 1 ) / 2 - 1, ( widthClus - 1 ) % 2, widthClus );
@@ -301,19 +303,21 @@ FTLiteClusters FTRawBankDecoder::decode<5>( const EventContext& evtCtx, LHCb::Ra
auto quarter = offset.globalQuarterIdx();
// Define Lambda functions to be used in loop
auto make_cluster = [&clus, &quarter]( unsigned chan, int fraction, int size ) {
clus.addHit( std::forward_as_tuple( LHCb::Detector::FTChannelID{chan}, fraction, size ), quarter );
auto make_cluster = [&clus, &quarter]( int chan, int fraction, int size ) {
clus.addHit(
std::forward_as_tuple( LHCb::Detector::FTChannelID{static_cast<unsigned int>( chan )}, fraction, size ),
quarter );
};
// Make clusters between two channels
auto make_clusters = [&]( unsigned firstChannel, short int c, short int c2 ) {
unsigned int delta = ( cell( c2 ) - cell( c ) );
auto make_clusters = [&]( int firstChannel, short int c, short int c2 ) {
short int delta = ( cell( c2 ) - cell( c ) );
// fragmented clusters, size > 2*max size
// only edges were saved, add middles now
if ( delta > LHCb::Detector::FT::RawBank::maxClusterWidth ) {
// add the first edge cluster, and then the middle clusters
for ( unsigned int i = LHCb::Detector::FT::RawBank::maxClusterWidth; i < delta;
for ( short int i = LHCb::Detector::FT::RawBank::maxClusterWidth; i < delta;
i += LHCb::Detector::FT::RawBank::maxClusterWidth ) {
// all middle clusters will have same size as the first cluster,
// so re-use the fraction
@@ -322,9 +326,9 @@ FTLiteClusters FTRawBankDecoder::decode<5>( const EventContext& evtCtx, LHCb::Ra
// add the last edge
make_cluster( firstChannel + delta, fraction( c2 ), 0 );
} else { // big cluster size upto size 8
unsigned int widthClus = 2 * delta - 1 + fraction( c2 );
int widthClus = 2 * delta - 1 + fraction( c2 );
make_cluster( firstChannel + ( widthClus - 1 ) / 2 -
int( ( LHCb::Detector::FT::RawBank::maxClusterWidth - 1 ) / 2 ),
static_cast<int>( ( LHCb::Detector::FT::RawBank::maxClusterWidth - 1 ) / 2 ),
( widthClus - 1 ) % 2, widthClus );
} // end if adjacent clusters
}; // End lambda make_clusters
@@ -334,13 +338,13 @@ FTLiteClusters FTRawBankDecoder::decode<5>( const EventContext& evtCtx, LHCb::Ra
auto last = bank->end<short int>();
if ( *( last - 1 ) == 0 ) --last; // Remove padding at the end
for ( ; it < last; ++it ) { // loop over the clusters
unsigned short int c = *it;
auto channel = LHCb::Detector::FTChannelID{offset + channelInBank( c )};
auto c = *it;
auto channel = LHCb::Detector::FTChannelID{offset + channelInBank( c )};
if ( !cSize( c ) || it + 1 == last ) // No size flag or last cluster
make_cluster( channel, fraction( c ), LHCb::Detector::FT::RawBank::maxClusterWidth );
else { // Flagged or not the last one.
unsigned c2 = *( it + 1 );
auto c2 = *( it + 1 );
if ( cSize( c2 ) && getLinkInBank( c ) == getLinkInBank( c2 ) ) {
make_clusters( channel, c, c2 );
++it;
@@ -579,32 +583,30 @@ FTLiteClusters FTRawBankDecoder::decode( const EventContext& evtCtx, LHCb::RawBa
LHCb::Detector::FTChannelID globalSiPMID;
// Define Lambda functions to be used in loop
short int lastCluster( 0 );
unsigned lastLink( 0 );
auto make_cluster = [&globalSiPMID, &clustersInBankPerLinkID, &localLinkIndex]( unsigned chan, int fraction,
auto make_cluster = [&globalSiPMID, &clustersInBankPerLinkID, &localLinkIndex]( unsigned chan, int fraction,
int size ) {
clustersInBankPerLinkID[localLinkIndex].emplace_back( LHCb::Detector::FTChannelID( globalSiPMID + chan ),
fraction, size );
};
// Make clusters between two channels
std::function<void( unsigned, short int, short int )> make_clusters;
std::function<void( short int, short int, short int )> make_clusters;
if ( m_ignoreLarge ) {
make_clusters = [&]( unsigned, short int c, short int c2 ) {
make_clusters = [&]( short int, short int c, short int c2 ) {
unsigned int widthClus = ( cell( c2 ) - cell( c ) + 2 ); // lastCh-firstCh+4/2
unsigned int size = ( widthClus > 2 * LHCb::Detector::FT::RawBank::maxClusterWidth ) ? 0 : widthClus;
make_cluster( cell( c ), 1, size );
make_cluster( cell( c2 ), 1, size );
}; // End lambda make_clusters
} else {
make_clusters = [&]( unsigned firstChannel, short int c, short int c2 ) {
unsigned int widthClus = ( cell( c2 ) - cell( c ) + 2 ); // lastCh-firstCh+4/2
make_clusters = [&]( short int firstChannel, short int c, short int c2 ) {
short int widthClus = ( cell( c2 ) - cell( c ) + 2 ); // lastCh-firstCh+4/2
// fragmented clusters, size > 2*max size
// only edges were saved, add middles now
if ( widthClus > 2 * LHCb::Detector::FT::RawBank::maxClusterWidth ) {
// add the first edge cluster, and then the middle clusters
unsigned int i = 0;
short int i = 0;
for ( ; i < widthClus - LHCb::Detector::FT::RawBank::maxClusterWidth;
i += LHCb::Detector::FT::RawBank::maxClusterWidth ) {
// all middle clusters will have same size as the first cluster,
@@ -613,7 +615,7 @@ FTLiteClusters FTRawBankDecoder::decode( const EventContext& evtCtx, LHCb::RawBa
}
// add the last edge
unsigned int lastChannel = firstChannel + i + std::floor( ( widthClus - i - 1 ) / 2 ) - 1;
short int lastChannel = firstChannel + i + std::floor( ( widthClus - i - 1 ) / 2 ) - 1;
make_cluster( lastChannel, ( widthClus - 1 ) % 2, 0 );
} else { // big cluster size upto size 8
@@ -626,9 +628,11 @@ FTLiteClusters FTRawBankDecoder::decode( const EventContext& evtCtx, LHCb::RawBa
clusters = clusters.subspan( 2 ); // skip first 32b of header
if ( !clusters.empty() && clusters.back() == 0 )
clusters = clusters.first( clusters.size() - 1 ); // Remove padding at the end
while ( !clusters.empty() ) { // loop over the clusters
unsigned channelInSiPM = cell( clusters[0] );
localLinkIndex = getLinkInBank( clusters[0] );
short int lastChannel( -1 );
unsigned lastLink( 0 );
while ( !clusters.empty() ) { // loop over the clusters
short int channelInSiPM = cell( clusters[0] );
localLinkIndex = getLinkInBank( clusters[0] );
if ( localLinkIndex >= FTRawBank::BankProperties::NbLinksPerBank ) {
++m_wrongLocalLink;
++m_wrongLocalLink_hist[iRow];
@@ -642,14 +646,14 @@ FTLiteClusters FTRawBankDecoder::decode( const EventContext& evtCtx, LHCb::RawBa
clusters = clusters.subspan( 1 );
continue;
}
if ( localLinkIndex == lastLink && clusters[0] < lastCluster ) {
if ( localLinkIndex == lastLink && channelInSiPM <= lastChannel ) {
++m_misordered;
++m_misordered_hist[iRow * FTRawBank::BankProperties::NbLinksPerBank + localLinkIndex];
// Skip the cluster
clusters = clusters.subspan( 1 );
continue;
}
lastCluster = clusters[0];
lastChannel = channelInSiPM;
lastLink = localLinkIndex;
if ( !cSize( clusters[0] ) ) { // Not flagged as large
make_cluster( channelInSiPM, fraction( clusters[0] ), LHCb::Detector::FT::RawBank::maxClusterWidth );
@@ -669,7 +673,7 @@ FTLiteClusters FTRawBankDecoder::decode( const EventContext& evtCtx, LHCb::RawBa
// Contrary to v8, size 4 means that the first fragment of a large cluster always has fraction 0
++m_corrupt2;
++m_corruptCluster2_hist[iRow * FTRawBank::BankProperties::NbLinksPerBank + localLinkIndex];
} else if ( cell( clusters[1] ) < cell( clusters[0] ) ) {
} else if ( cell( clusters[1] ) <= channelInSiPM ) {
// FIXME
// Clusters should come in order. This is behaviour puts into question the whole concept of large
// clusters
@@ -681,7 +685,8 @@ FTLiteClusters FTRawBankDecoder::decode( const EventContext& evtCtx, LHCb::RawBa
clusters = clusters.subspan( 1 );
} else {
make_clusters( channelInSiPM, clusters[0], clusters[1] );
clusters = clusters.subspan( 1 );
lastChannel = cell( clusters[1] );
clusters = clusters.subspan( 1 );
}
}
}
@@ -690,7 +695,6 @@ FTLiteClusters FTRawBankDecoder::decode( const EventContext& evtCtx, LHCb::RawBa
// last cluster in bank or in sipm
if ( clusters.size() == 1 || getLinkInBank( clusters[0] ) != getLinkInBank( clusters[1] ) ) {
make_cluster( channelInSiPM, fraction( clusters[0] ), 0 );
lastLink = localLinkIndex;
}
// flagged as first cluster of a large one
else if ( fraction( clusters[0] ) ) {
@@ -700,7 +704,7 @@ FTLiteClusters FTRawBankDecoder::decode( const EventContext& evtCtx, LHCb::RawBa
++m_corrupt1;
++m_corruptCluster1_hist[iRow * FTRawBank::BankProperties::NbLinksPerBank + localLinkIndex];
clusters = clusters.subspan( 1 );
} else if ( cell( clusters[1] ) < cell( clusters[0] ) ) {
} else if ( cell( clusters[1] ) <= channelInSiPM ) {
// FIXME
// Clusters should come in order. This is behaviour puts into question the whole concept of large
// clusters
@@ -712,8 +716,8 @@ FTLiteClusters FTRawBankDecoder::decode( const EventContext& evtCtx, LHCb::RawBa
clusters = clusters.subspan( 1 );
} else { // this should always be true
make_clusters( channelInSiPM, clusters[0], clusters[1] );
clusters = clusters.subspan( 1 );
lastLink = localLinkIndex;
lastChannel = cell( clusters[1] );
clusters = clusters.subspan( 1 );
}
}
}
Loading