Skip to content

Commit

Permalink
Merge pull request #23632 from rekovic/pr102_OMTF_Unpacker-GhostBuste…
Browse files Browse the repository at this point in the history
…r_CaloLayer2_HoEext_QualNtuple

L1 PR 10_2 Omtf unpacker and ghost-buster & CaloLayer2 HoEext and Qual bit in ntuple
  • Loading branch information
cmsbuild committed Jun 22, 2018
2 parents dd04f07 + 94f508d commit 7d7c199
Show file tree
Hide file tree
Showing 16 changed files with 200 additions and 30 deletions.
4 changes: 2 additions & 2 deletions DataFormats/L1Trigger/interface/BXVector.impl
Expand Up @@ -104,7 +104,7 @@ template < class T >
typename BXVector<T>::const_iterator
BXVector<T>::begin( int bx ) const
{
assert(itrs_.size() > 0);
assert(!itrs_.empty());
return data_.begin()+itrs_[indexFromBX(bx)];
}

Expand Down Expand Up @@ -171,7 +171,7 @@ void BXVector<T>::clear()
template < class T >
void BXVector<T>::insert(int bx, unsigned i,T object)
{
if(i >= size(bx)){
if(i > size(bx)){
//cout<<"ERROR: bx "<<bx<<" is only "<<size(bx)<<" long"<<endl;
}
else{
Expand Down
2 changes: 1 addition & 1 deletion EventFilter/L1TRawToDigi/plugins/OmtfUnpacker.cc
Expand Up @@ -142,7 +142,7 @@ void OmtfUnpacker::produce(edm::Event& event, const edm::EventSetup& setup)
auto producedRPCDigis = std::make_unique<RPCDigiCollection>();
auto producedCscLctDigis = std::make_unique<CSCCorrelatedLCTDigiCollection>();
auto producedMuonDigis = std::make_unique<l1t::RegionalMuonCandBxCollection>();
producedMuonDigis->setBXRange(-3,3);
producedMuonDigis->setBXRange(-3,4);
auto producedDTPhDigis = std::make_unique<L1MuDTChambPhContainer>();
auto producedDTThDigis = std::make_unique<L1MuDTChambThContainer>();
std::vector<L1MuDTChambPhDigi> phi_Container;
Expand Down
14 changes: 12 additions & 2 deletions EventFilter/L1TRawToDigi/src/OmtfMuonUnpacker.cc
Expand Up @@ -27,8 +27,18 @@ void MuonUnpacker::unpack(unsigned int fed, unsigned int amc, const MuonDataWord
digi.setTrackAddress(trackAddr);
digi.setTFIdentifiers(iProcessor, overlap);
int bx = data.bxNum()-3;
LogTrace("") <<"OMTF Muon, BX="<<bx<<", hwPt="<<digi.hwPt()<< std::endl;
if(std::abs(bx) <= 3) producedMuonDigis->push_back(bx,digi);
LogTrace("") <<"OMTF Muon, BX="<<bx<<", hwPt="<<digi.hwPt()<<", link: "<<digi.link() << std::endl;

// add digi to collection, keep fixed ascending link orderi (insert in proper place)
l1t::RegionalMuonCandBxCollection::const_iterator itb=producedMuonDigis->begin(bx);
l1t::RegionalMuonCandBxCollection::const_iterator ite=producedMuonDigis->end(bx);
unsigned int indeks = 0;
while (indeks < ite-itb) {
if (digi.link()<(itb+indeks)->link()) break;
indeks++;
}
producedMuonDigis->insert(bx,indeks,digi);

}

}
1 change: 1 addition & 0 deletions L1Trigger/L1TCalorimeter/src/CaloTools.cc
Expand Up @@ -394,6 +394,7 @@ l1t::EGamma l1t::CaloTools::egP4MP(l1t::EGamma& eg) {
tmpEG.setFootprintEt(eg.footprintEt());
tmpEG.setNTT(eg.nTT());
tmpEG.setShape(eg.shape());
tmpEG.setTowerHoE(eg.towerHoE());

return tmpEG;

Expand Down
Expand Up @@ -127,14 +127,16 @@ void l1t::Stage2Layer2EGammaAlgorithmFirmwareImp1::processEvent(const std::vecto
// Identification of the egamma
// Based on the seed tower FG bit, the H/E ratio of the seed tower, and the shape of the cluster
bool hOverEBit = cluster.hOverE()>0;
bool hOverEExtBit = true;
if(!params_->egBypassExtHOverE())
hOverEBit &= HoE_ext;
hOverEExtBit = HoE_ext;
bool shapeBit = idShape(cluster, egamma.hwPt());
bool fgBit = !(cluster.fgECAL());
int qual = 0;
if(fgBit) qual |= (0x1); // first bit = FG
if(hOverEBit) qual |= (0x1<<1); // second bit = H/E
if(shapeBit) qual |= (0x1<<2); // third bit = shape
if(hOverEExtBit) qual |= (0x1<<3); // fourth bit = shape
egamma.setHwQual( qual );

// Isolation
Expand Down Expand Up @@ -231,8 +233,9 @@ void l1t::Stage2Layer2EGammaAlgorithmFirmwareImp1::processEvent(const std::vecto
int fgBit = egammas_raw.at(iEG).hwQual() & (0x1);
int hOverEBit = egammas_raw.at(iEG).hwQual()>>1 & (0x1);
int shapeBit = egammas_raw.at(iEG).hwQual()>>2 & (0x1);
int hOverEExtBit = egammas_raw.at(iEG).hwQual()>>3 & (0x1);

bool IDcuts = (fgBit && hOverEBit && shapeBit) || (egammas_raw.at(iEG).pt()>=params_->egMaxPtHOverE()) || (params_->egBypassEGVetos());
bool IDcuts = (fgBit && hOverEBit && shapeBit && hOverEExtBit) || (egammas_raw.at(iEG).pt()>=params_->egMaxPtHOverE()) || (params_->egBypassEGVetos());

if(!IDcuts) continue;

Expand Down
16 changes: 5 additions & 11 deletions L1Trigger/L1TMuonOverlap/interface/GhostBuster.h
Expand Up @@ -9,19 +9,13 @@

#include <memory>

#include "L1Trigger/L1TMuonOverlap/interface/IGhostBuster.h"
#include "L1Trigger/L1TMuonOverlap/interface/AlgoMuon.h"

class OMTFGhostBuster {

public:

void select(std::vector<AlgoMuon> & refHitCands, int charge=0);

void setNphiBins(unsigned int phiBins) {nPhiBins = phiBins;};

private:

unsigned int nPhiBins;
class GhostBuster: public IGhostBuster {
public:
~GhostBuster() override {};
std::vector<AlgoMuon> select(std::vector<AlgoMuon> refHitCands, int charge=0) override;

};
#endif
27 changes: 27 additions & 0 deletions L1Trigger/L1TMuonOverlap/interface/GhostBusterPreferRefDt.h
@@ -0,0 +1,27 @@
#ifndef OMTF_GhostBusterPreferRefDt_H
#define OMTF_GhostBusterPreferRefDt_H

#include <vector>
#include <ostream>

#include <map>
#include <set>

#include <memory>

#include "L1Trigger/L1TMuonOverlap/interface/IGhostBuster.h"
#include "L1Trigger/L1TMuonOverlap/interface/AlgoMuon.h"
#include "L1Trigger/L1TMuonOverlap/interface/OMTFConfiguration.h"

class GhostBusterPreferRefDt: public IGhostBuster {
private:
const OMTFConfiguration* omtfConfig;
public:
GhostBusterPreferRefDt(OMTFConfiguration* omtfConfig):omtfConfig(omtfConfig) {};

~GhostBusterPreferRefDt() override {};

std::vector<AlgoMuon> select(std::vector<AlgoMuon> refHitCands, int charge=0) override;

};
#endif
21 changes: 21 additions & 0 deletions L1Trigger/L1TMuonOverlap/interface/IGhostBuster.h
@@ -0,0 +1,21 @@
/*
* IGhostBuster.h
*
* Created on: Jun 28, 2017
* Author: kbunkow
*/

#ifndef OMTF_IGHOSTBUSTER_H_
#define OMTF_IGHOSTBUSTER_H_

#include "L1Trigger/L1TMuonOverlap/interface/AlgoMuon.h"

class IGhostBuster {
public:
virtual ~IGhostBuster() {}

virtual std::vector<AlgoMuon> select(std::vector<AlgoMuon> refHitCands, int charge=0) = 0;

};

#endif /* OMTF_IGHOSTBUSTER_H_ */
2 changes: 1 addition & 1 deletion L1Trigger/L1TMuonOverlap/interface/OMTFReconstruction.h
Expand Up @@ -74,7 +74,7 @@ class OMTFReconstruction {
OMTFConfiguration *m_OMTFConfig;
OMTFinputMaker m_InputMaker;
OMTFSorter m_Sorter;
OMTFGhostBuster m_GhostBuster;
std::unique_ptr<IGhostBuster> m_GhostBuster;
OMTFProcessor *m_OMTF;
///
xercesc::DOMElement *aTopElement;
Expand Down
3 changes: 2 additions & 1 deletion L1Trigger/L1TMuonOverlap/python/simOmtfDigis_cfi.py
Expand Up @@ -14,7 +14,8 @@
eventsXMLFiles = cms.vstring("TestEvents.xml"),
dropRPCPrimitives = cms.bool(False),
dropDTPrimitives = cms.bool(False),
dropCSCPrimitives = cms.bool(False)
dropCSCPrimitives = cms.bool(False),
#ghostBusterType = cms.string("GhostBusterPreferRefDt")
)


10 changes: 7 additions & 3 deletions L1Trigger/L1TMuonOverlap/src/GhostBuster.cc
Expand Up @@ -9,7 +9,7 @@ namespace {
int phiGMT(int phiAlgo) { return phiAlgo*437/pow(2,12); }
}

void OMTFGhostBuster::select(std::vector<AlgoMuon> & refHitCands, int charge){
std::vector<AlgoMuon> GhostBuster::select(std::vector<AlgoMuon> refHitCands, int charge){

std::vector<AlgoMuon> refHitCleanCands;
// Sort candidates with decreased goodness,
Expand All @@ -28,12 +28,16 @@ void OMTFGhostBuster::select(std::vector<AlgoMuon> & refHitCands, int charge){
// if(std::abs(it1->getPhi() - it2->getPhi())<5/360.0*nPhiBins){
isGhost=true;
break;
//which one candidate is killed depends only on the order in the refHitCands (the one with smaller index is taken), and this order is assured by the sort above
//TODO here the candidate that is killed does not kill other candidates - check if the firmware does the same (KB)
}
}
if(it1->getQ()>0 && !isGhost) refHitCleanCands.push_back(*it1);
}

refHitCleanCands.resize( 3, AlgoMuon(0,999,9999,0,0,0,0,0) );
refHitCleanCands.resize( 3, AlgoMuon(0,999,9999,0,0,0,0,0) ); //FIXME
//refHitCleanCands.resize( 3, AlgoMuon() );


std::stringstream myStr;
bool hasCandidates = false;
Expand All @@ -54,5 +58,5 @@ void OMTFGhostBuster::select(std::vector<AlgoMuon> & refHitCands, int charge){
if(hasCandidates) edm::LogInfo("OMTF Sorter")<<myStr.str();

// update refHitCands with refHitCleanCands
refHitCands = refHitCleanCands;
return refHitCleanCands;
}
97 changes: 97 additions & 0 deletions L1Trigger/L1TMuonOverlap/src/GhostBusterPreferRefDt.cc
@@ -0,0 +1,97 @@
#include "L1Trigger/L1TMuonOverlap/interface/GhostBusterPreferRefDt.h"

#include <sstream>

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "L1Trigger/L1TMuonOverlap/interface/OMTFConfiguration.h"

namespace {
int phiGMT(int phiAlgo) { return phiAlgo*437/pow(2,12); }
}

std::vector<AlgoMuon> GhostBusterPreferRefDt::select(std::vector<AlgoMuon> refHitCands, int charge) {
auto customLess = [&](const AlgoMuon& a, const AlgoMuon& b)->bool {
int aRefLayerLogicNum = omtfConfig->getRefToLogicNumber()[a.getRefLayer()];
int bRefLayerLogicNum = omtfConfig->getRefToLogicNumber()[b.getRefLayer()];
if(a.getQ() > b.getQ())
return false;
else if(a.getQ()==b.getQ() && aRefLayerLogicNum < bRefLayerLogicNum) {
return false;
}
else if (a.getQ()==b.getQ() && aRefLayerLogicNum == bRefLayerLogicNum && a.getDisc() > b.getDisc() )
return false;
else if (a.getQ()==b.getQ() && aRefLayerLogicNum == bRefLayerLogicNum && a.getDisc() == b.getDisc() && a.getPatternNumber() > b.getPatternNumber() )
return false;
else if (a.getQ()==b.getQ() && aRefLayerLogicNum == bRefLayerLogicNum && a.getDisc() == b.getDisc() && a.getPatternNumber() == b.getPatternNumber() && a.getRefHitNumber() < b.getRefHitNumber())
return false;
else
return true;
//TODO check if the firmware really includes the pattern number and refHit number here
};

/* auto customLess = [&](const AlgoMuon& a, const AlgoMuon& b)->bool {
int aRefLayerLogicNum = omtfConfig->getRefToLogicNumber()[a.getRefLayer()];
int bRefLayerLogicNum = omtfConfig->getRefToLogicNumber()[b.getRefLayer()];
if(a.getQ() > b.getQ())
return false;
else if(a.getQ()==b.getQ() && aRefLayerLogicNum < bRefLayerLogicNum) {
return false;
}
else if (a.getQ()==b.getQ() && aRefLayerLogicNum == bRefLayerLogicNum && a.getPatternNumber() > b.getPatternNumber() )
return false;
else if (a.getQ()==b.getQ() && aRefLayerLogicNum == bRefLayerLogicNum && a.getPatternNumber() == b.getPatternNumber() && a.getRefHitNumber() < b.getRefHitNumber())
return false;
else
return true;
//TODO check if the firmware really includes the pattern number and refHit number here
};*/

std::vector<AlgoMuon> refHitCleanCands;
// Sort candidates with decreased goodness,
// where goodness definied in < operator of AlgoMuon
std::sort( refHitCands.rbegin(), refHitCands.rend(), customLess );

for(std::vector<AlgoMuon>::iterator it1 = refHitCands.begin();
it1 != refHitCands.end(); ++it1){
bool isGhost=false;
for(std::vector<AlgoMuon>::iterator it2 = refHitCleanCands.begin();
it2 != refHitCleanCands.end(); ++it2){
//do not accept candidates with similar phi (any charge combination)
//veto window 5deg(=half of logic cone)=5/360*5760=80"logic strips"
//veto window 5 degree in GMT scale is 5/360*576=8 units
if (std::abs( phiGMT(it1->getPhi()) - phiGMT(it2->getPhi()) ) < 8 ) {
// if(std::abs(it1->getPhi() - it2->getPhi())<5/360.0*nPhiBins){
isGhost=true;
break;
//which one candidate is killed depends only on the order in the refHitCands (the one with smaller index is taken), and this order is assured by the sort above
//TODO here the candidate that is killed does not kill other candidates - check if the firmware does the same (KB)
}
}
if(it1->getQ()>0 && !isGhost) refHitCleanCands.push_back(*it1);
}

refHitCleanCands.resize( 3, AlgoMuon(0,999,9999,0,0,0,0,0) ); //FIXME
//refHitCleanCands.resize( 3, AlgoMuon() );


std::stringstream myStr;
bool hasCandidates = false;
for(unsigned int iRefHit=0;iRefHit<refHitCands.size();++iRefHit){
if(refHitCands[iRefHit].getQ()){
hasCandidates=true;
break;
}
}
for(unsigned int iRefHit=0;iRefHit<refHitCands.size();++iRefHit){
if(refHitCands[iRefHit].getQ()) myStr<<"Ref hit: "<<iRefHit<<" "<<refHitCands[iRefHit]<<std::endl;
}
myStr<<"Selected Candidates with charge: "<<charge<<std::endl;
for(unsigned int iCand=0; iCand<refHitCleanCands.size(); ++iCand){
myStr<<"Cand: "<<iCand<<" "<<refHitCleanCands[iCand]<<std::endl;
}

if(hasCandidates) edm::LogInfo("OMTF Sorter")<<myStr.str();

// update refHitCands with refHitCleanCands
return refHitCleanCands;
}
17 changes: 13 additions & 4 deletions L1Trigger/L1TMuonOverlap/src/OMTFReconstruction.cc
Expand Up @@ -13,6 +13,7 @@
#include "L1Trigger/L1TMuonOverlap/interface/OMTFConfiguration.h"
#include "L1Trigger/L1TMuonOverlap/interface/XMLConfigWriter.h"
#include "L1Trigger/L1TMuonOverlap/interface/OmtfName.h"
#include "L1Trigger/L1TMuonOverlap/interface/GhostBusterPreferRefDt.h"

#include "L1Trigger/RPCTrigger/interface/RPCConst.h"

Expand Down Expand Up @@ -71,7 +72,15 @@ void OMTFReconstruction::beginRun(edm::Run const& run, edm::EventSetup const& iS

m_OMTFConfig->configure(omtfParams);
m_OMTF->configure(m_OMTFConfig, omtfParams);
m_GhostBuster.setNphiBins(m_OMTFConfig->nPhiBins());
//m_GhostBuster.setNphiBins(m_OMTFConfig->nPhiBins());

if(m_Config.exists("ghostBusterType") ) {
if(m_Config.getParameter<std::string>("ghostBusterType") == "GhostBusterPreferRefDt")
m_GhostBuster.reset(new GhostBusterPreferRefDt(m_OMTFConfig) );
}
else
m_GhostBuster.reset(new GhostBuster() );

m_Sorter.setNphiBins(m_OMTFConfig->nPhiBins());

m_InputMaker.initialize(iSetup, m_OMTFConfig);
Expand Down Expand Up @@ -139,10 +148,10 @@ void OMTFReconstruction::getProcessorCandidates(unsigned int iProcessor, l1t::tf
m_Sorter.sortRefHitResults(results, algoCandidates);

// perform GB
m_GhostBuster.select(algoCandidates);

std::vector<AlgoMuon> gbCandidates = m_GhostBuster->select(algoCandidates);
// fill RegionalMuonCand colleciton
std::vector<l1t::RegionalMuonCand> candMuons = m_Sorter.candidates(iProcessor, mtfType, algoCandidates);
std::vector<l1t::RegionalMuonCand> candMuons = m_Sorter.candidates(iProcessor, mtfType, gbCandidates);

//fill outgoing collection
for (auto & candMuon : candMuons) {
Expand Down
6 changes: 3 additions & 3 deletions L1Trigger/L1TMuonOverlap/test/runMuonOverlap.py
Expand Up @@ -11,10 +11,10 @@
process.options = cms.untracked.PSet(wantSummary = cms.untracked.bool(False))

process.source = cms.Source('PoolSource',
fileNames = cms.untracked.vstring('file:/afs/cern.ch/work/g/gflouris/public/SingleMuPt6180_noanti_10k_eta1.root')
)
#fileNames = cms.untracked.vstring('file:/afs/cern.ch/work/g/gflouris/public/SingleMuPt6180_noanti_10k_eta1.root')
fileNames = cms.untracked.vstring('file:///afs/cern.ch/work/k/kbunkow/private/omtf_data/SingleMu_15_p_1_1_qtl.root') )

process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(10))
process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(1000))

# PostLS1 geometry used
process.load('Configuration.Geometry.GeometryExtended2015Reco_cff')
Expand Down
Expand Up @@ -65,6 +65,7 @@ namespace L1Analysis
egNTT.clear();
egShape.clear();
egTowerHoE.clear();
egHwQual.clear();

nTaus = 0;
tauEt.clear();
Expand Down Expand Up @@ -148,6 +149,7 @@ namespace L1Analysis
std::vector<short int> egNTT;
std::vector<short int> egShape;
std::vector<short int> egTowerHoE;
std::vector<short int> egHwQual;

unsigned short int nTaus;
std::vector<float> tauEt;
Expand Down
1 change: 1 addition & 0 deletions L1Trigger/L1TNtuples/src/L1AnalysisL1Upgrade.cc
Expand Up @@ -30,6 +30,7 @@ void L1Analysis::L1AnalysisL1Upgrade::SetEm(const edm::Handle<l1t::EGammaBxColle
l1upgrade_.egNTT.push_back(it->nTT());
l1upgrade_.egShape.push_back(it->shape());
l1upgrade_.egTowerHoE.push_back(it->towerHoE());
l1upgrade_.egHwQual.push_back(it->hwQual());
l1upgrade_.nEGs++;
}
}
Expand Down

0 comments on commit 7d7c199

Please sign in to comment.