Skip to content

Commit

Permalink
Merge pull request #21151 from Dr15Jones/fixL1ArrayOverruns
Browse files Browse the repository at this point in the history
Properly handle arrays where index can be negative
  • Loading branch information
cmsbuild committed Nov 9, 2017
2 parents 2075664 + 41a2c7d commit 4fa2511
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 17 deletions.
34 changes: 29 additions & 5 deletions L1Trigger/L1TTwinMux/src/RPCHitCleaner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,30 @@ RPCHitCleaner::RPCHitCleaner(RPCDigiCollection inrpcDigis){
m_inrpcDigis = inrpcDigis;
}

namespace {
constexpr int max_rpc_bx = 3;
constexpr int min_rpc_bx = -3;

//Need to shift the index so that index 0
// corresponds to min_rpc_bx
class BxToStrips {
public:
BxToStrips(): m_strips{} {} //zero initializes

static bool outOfRange(int iBX) {
return (iBX > max_rpc_bx or iBX < min_rpc_bx) ;
}

int& operator[](int iBX) {
return m_strips[iBX-min_rpc_bx];
}

size_t size() const { return m_strips.size(); }
private:
std::array<int,max_rpc_bx-min_rpc_bx+1> m_strips;
};
}

void RPCHitCleaner::run(const edm::EventSetup& c) {

std::map<detId_Ext, int> hits;
Expand Down Expand Up @@ -69,12 +93,12 @@ void RPCHitCleaner::run(const edm::EventSetup& c) {
for( auto chamber = m_inrpcDigis.begin(); chamber != m_inrpcDigis.end(); ++chamber ){
RPCDetId detid = (*chamber).first;
if(detid.region()!=0 ) continue; //Region = 0 Barrel
int strips[5] = {0};
BxToStrips strips;
int cluster_n1 = -10;
bx_hits[detid] = 10;
//Keep cluster with min bx in a roll
for( auto digi = (*chamber).second.first ; digi != (*chamber).second.second; ++digi ) {
if(fabs(digi->bx())>3 ) continue;
if(BxToStrips::outOfRange(digi->bx()) ) continue;
//int cluster_id = hits[(detid.ring()+2)][(detid.station()-1)][(detid.sector()-1)][(detid.layer()-1)][(digi->bx()+2)][detid.roll()-1][digi->strip()];
detId_Ext tmp{detid,digi->bx(),digi->strip()};
int cluster_id = hits[tmp];
Expand All @@ -93,11 +117,11 @@ void RPCHitCleaner::run(const edm::EventSetup& c) {
///keep only one bx per st/sec/wheel/layer
if(digi->bx()!=bx_hits[detid] ) continue;
///Count strips in a cluster
if(cluster_n1 != cluster_id) {strips[digi->bx()+3] = {0}; }
strips[digi->bx()+3] ++ ;
if(cluster_n1 != cluster_id) {strips[digi->bx()] = {0}; }
strips[digi->bx()] ++ ;
cluster_n1 = cluster_id;

if( vcluster_size[cluster_id] ==3 && strips[digi->bx()+3]!=2) continue;
if( vcluster_size[cluster_id] ==3 && strips[digi->bx()]!=2) continue;
///Keep clusters with size=2. Calculate and store the mean phi in RPCtoDTTranslator
RPCDigi digi_out(digi->strip(), digi->bx());
m_outrpcDigis.insertDigi(detid, digi_out);
Expand Down
45 changes: 33 additions & 12 deletions L1Trigger/L1TTwinMux/src/RPCtoDTTranslator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,44 @@ RPCtoDTTranslator::RPCtoDTTranslator(RPCDigiCollection inrpcDigis){

}

namespace {
constexpr int max_rpc_bx = 2;
constexpr int min_rpc_bx = -2;

//Need to shift the index so that index 0
// corresponds to min_rpc_bx
class BxToHit {
public:
BxToHit(): m_hits{} {} //zero initializes

static bool outOfRange(int iBX) {
return (iBX > max_rpc_bx or iBX < min_rpc_bx);
}

int& operator[](int iBX) {
return m_hits[iBX-min_rpc_bx];
}

size_t size() const { return m_hits.size(); }
private:
std::array<int,max_rpc_bx-min_rpc_bx+1> m_hits;
};
}


void RPCtoDTTranslator::run(const edm::EventSetup& c) {

std::vector<L1MuDTChambPhDigi> l1ttma_out;
std::vector<L1MuDTChambPhDigi> l1ttma_hits_out;

std::vector<rpc_hit> vrpc_hit_layer1, vrpc_hit_layer2, vrpc_hit_st3, vrpc_hit_st4;

int max_rpc_bx = 2; int min_rpc_bx = -2;

///Init structues
for( auto chamber = m_rpcDigis.begin(); chamber != m_rpcDigis.end(); ++chamber ) {
RPCDetId detid = (*chamber).first;
for( auto digi = (*chamber).second.first ; digi != (*chamber).second.second; ++digi ) {
if(detid.region()!=0 ) continue; //Region = 0 Barrel
if(digi->bx()>max_rpc_bx || digi->bx()<min_rpc_bx) continue;
if(BxToHit::outOfRange(digi->bx())) continue;
if(detid.layer()==1) vrpc_hit_layer1.push_back({digi->bx(), detid.station(), detid.sector(), detid.ring(), detid, digi->strip(), detid.roll(), detid.layer()});
if(detid.station()==3) vrpc_hit_st3.push_back({digi->bx(), detid.station(), detid.sector(), detid.ring(), detid, digi->strip(), detid.roll(), detid.layer()});
if(detid.layer()==2) vrpc_hit_layer2.push_back({digi->bx(), detid.station(), detid.sector(), detid.ring(), detid, digi->strip(), detid.roll(), detid.layer()});
Expand Down Expand Up @@ -167,9 +190,7 @@ void RPCtoDTTranslator::run(const edm::EventSetup& c) {

}
///Use ts2tag variable to store N rpchits for the same st/wheel/sec
int const bx_range = (max_rpc_bx - min_rpc_bx) + 1 ;
int hit[bx_range];
for (int n=0; n<bx_range; n++) hit[n] = 0;
BxToHit hit;
itr1=0;
for(unsigned int l1=0; l1<vrpc_hit_layer1.size(); l1++){
if(vrpc_hit_layer1[l1].station!=st || st>2 || vrpc_hit_layer1[l1].sector!=sec || vrpc_hit_layer1[l1].wheel!=wh) continue;
Expand All @@ -188,8 +209,8 @@ void RPCtoDTTranslator::run(const edm::EventSetup& c) {
phi2 /= 2;
}

l1ttma_hits_out.emplace_back(vrpc_hit_layer1[l1].bx, wh, sec-1, st, phi2, 0, 3, hit[vrpc_hit_layer1[l1].bx+2], 0, 2);
hit[vrpc_hit_layer1[l1].bx+2]++;
l1ttma_hits_out.emplace_back(vrpc_hit_layer1[l1].bx, wh, sec-1, st, phi2, 0, 3, hit[vrpc_hit_layer1[l1].bx], 0, 2);
hit[vrpc_hit_layer1[l1].bx]++;
}
itr1 = 0;
for(unsigned int l2=0; l2<vrpc_hit_layer2.size(); l2++){
Expand All @@ -208,8 +229,8 @@ void RPCtoDTTranslator::run(const edm::EventSetup& c) {
phi2 = phi2 + (radialAngle(vrpc_hit_layer2[l2-1].detid, c, vrpc_hit_layer2[l2-1].strip)<<2);
phi2 /= 2;
}
l1ttma_hits_out.emplace_back( vrpc_hit_layer2[l2].bx, wh, sec-1, st, phi2, 0, 3, hit[vrpc_hit_layer2[l2].bx+2] , 0, 2);
hit[vrpc_hit_layer2[l2].bx+2]++;
l1ttma_hits_out.emplace_back( vrpc_hit_layer2[l2].bx, wh, sec-1, st, phi2, 0, 3, hit[vrpc_hit_layer2[l2].bx] , 0, 2);
hit[vrpc_hit_layer2[l2].bx]++;

}
itr1 = 0;
Expand All @@ -230,8 +251,8 @@ void RPCtoDTTranslator::run(const edm::EventSetup& c) {
phi2 = phi2 + (radialAngle(vrpc_hit_st3[l1-1].detid, c, vrpc_hit_st3[l1-1].strip)<<2);
phi2 /= 2;
}
l1ttma_hits_out.emplace_back( vrpc_hit_st3[l1].bx, wh, sec-1, st, phi2, 0, 3, hit[vrpc_hit_st3[l1].bx+2], 0, 2);
hit[vrpc_hit_st3[l1].bx+2]++;
l1ttma_hits_out.emplace_back( vrpc_hit_st3[l1].bx, wh, sec-1, st, phi2, 0, 3, hit[vrpc_hit_st3[l1].bx], 0, 2);
hit[vrpc_hit_st3[l1].bx]++;

}
itr1 = 0;
Expand Down

0 comments on commit 4fa2511

Please sign in to comment.