forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from p2l1pfp/VourMa-deregionizer-emulator-dev
Sync deregionizer with correlator-common repo
- Loading branch information
Showing
10 changed files
with
556 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 176 additions & 0 deletions
176
L1Trigger/Phase2L1ParticleFlow/plugins/DeregionizerProducer.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
#include <unordered_map> | ||
|
||
#include "FWCore/Framework/interface/stream/EDProducer.h" | ||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/Utilities/interface/InputTag.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
|
||
#include "DataFormats/L1TParticleFlow/interface/PFCandidate.h" | ||
|
||
#include "L1Trigger/Phase2L1ParticleFlow/src/newfirmware/deregionizer/deregionizer_input.h" | ||
#include "L1Trigger/Phase2L1ParticleFlow/src/newfirmware/deregionizer/deregionizer_ref.h" | ||
|
||
class DeregionizerProducer : public edm::stream::EDProducer<> { | ||
public: | ||
explicit DeregionizerProducer(const edm::ParameterSet &); | ||
~DeregionizerProducer() override; | ||
|
||
private: | ||
edm::ParameterSet config_; | ||
edm::EDGetTokenT<l1t::PFCandidateRegionalOutput> token_; | ||
l1ct::DeregionizerEmulator emulator_; | ||
bool debug_; | ||
|
||
std::unordered_map<const l1t::PFCandidate *, l1t::PFClusterRef> clusterRefMap_; | ||
std::unordered_map<const l1t::PFCandidate *, l1t::PFTrackRef> trackRefMap_; | ||
std::unordered_map<const l1t::PFCandidate *, l1t::PFCandidate::MuonRef> muonRefMap_; | ||
|
||
void produce(edm::Event &, const edm::EventSetup &) override; | ||
void hwToEdm_(const std::vector<l1ct::PuppiObjEmu> &hwOut, std::vector<l1t::PFCandidate> &edmOut) const; | ||
void setRefs_(l1t::PFCandidate &pf, const l1ct::PuppiObjEmu &p) const; | ||
}; | ||
|
||
DeregionizerProducer::DeregionizerProducer(const edm::ParameterSet &iConfig) | ||
: config_(iConfig), | ||
token_(consumes<l1t::PFCandidateRegionalOutput>(iConfig.getParameter<edm::InputTag>("RegionalPuppiCands"))), | ||
emulator_(iConfig), | ||
debug_(iConfig.getUntrackedParameter<bool>("debug", 0)) { | ||
produces<l1t::PFCandidateCollection>("Puppi"); | ||
produces<l1t::PFCandidateCollection>("TruncatedPuppi"); | ||
} | ||
|
||
DeregionizerProducer::~DeregionizerProducer() {} | ||
|
||
void DeregionizerProducer::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { | ||
clusterRefMap_.clear(); | ||
trackRefMap_.clear(); | ||
muonRefMap_.clear(); | ||
|
||
auto deregColl = std::make_unique<l1t::PFCandidateCollection>(); | ||
auto truncColl = std::make_unique<l1t::PFCandidateCollection>(); | ||
|
||
edm::Handle<l1t::PFCandidateRegionalOutput> src; | ||
|
||
iEvent.getByToken(token_, src); | ||
|
||
std::vector<float> regionEtas, regionPhis; | ||
std::vector<l1ct::OutputRegion> outputRegions; | ||
std::vector<l1ct::PuppiObjEmu> hwOut; | ||
std::vector<l1t::PFCandidate> edmOut; | ||
std::vector<l1ct::PuppiObjEmu> hwTruncOut; | ||
std::vector<l1t::PFCandidate> edmTruncOut; | ||
|
||
if (debug_) | ||
edm::LogPrint("DeregionizerProducer") << "\nRegional Puppi Candidates"; | ||
for (unsigned int iReg = 0, nReg = src->nRegions(); iReg < nReg; ++iReg) { | ||
l1ct::OutputRegion tempOutputRegion; | ||
|
||
auto region = src->region(iReg); | ||
float eta = src->eta(iReg); | ||
float phi = src->phi(iReg); | ||
if (debug_) | ||
edm::LogPrint("DeregionizerProducer") << "\nRegion " << iReg << "\n" | ||
<< "Eta = " << eta << " and Phi = " << phi << "\n" | ||
<< "###########"; | ||
for (int i = 0, n = region.size(); i < n; ++i) { | ||
l1ct::PuppiObjEmu tempPuppi; | ||
const l1t::PFCandidate &cand = region[i]; | ||
clusterRefMap_[&cand] = cand.pfCluster(); | ||
trackRefMap_[&cand] = cand.pfTrack(); | ||
muonRefMap_[&cand] = cand.muon(); | ||
|
||
tempPuppi.initFromBits(cand.encodedPuppi64()); | ||
tempPuppi.srcCand = &cand; | ||
tempOutputRegion.puppi.push_back(tempPuppi); | ||
if (debug_) | ||
edm::LogPrint("DeregionizerProducer") << "pt[" << i << "] = " << tempOutputRegion.puppi.back().hwPt << ", eta[" | ||
<< i << "] = " << tempOutputRegion.puppi.back().floatEta() << ", phi[" | ||
<< i << "] = " << tempOutputRegion.puppi.back().floatPhi(); | ||
} | ||
if (tempOutputRegion.puppi.size() > 0) { | ||
regionEtas.push_back(eta); | ||
regionPhis.push_back(phi); | ||
outputRegions.push_back(tempOutputRegion); | ||
} | ||
} | ||
|
||
l1ct::DeregionizerInput in = l1ct::DeregionizerInput(regionEtas, regionPhis, outputRegions); | ||
in.setDebug(debug_); | ||
|
||
emulator_.run(in, hwOut, hwTruncOut); | ||
|
||
DeregionizerProducer::hwToEdm_(hwOut, edmOut); | ||
DeregionizerProducer::hwToEdm_(hwTruncOut, edmTruncOut); | ||
|
||
deregColl->swap(edmOut); | ||
truncColl->swap(edmTruncOut); | ||
|
||
iEvent.put(std::move(deregColl), "Puppi"); | ||
iEvent.put(std::move(truncColl), "TruncatedPuppi"); | ||
} | ||
|
||
void DeregionizerProducer::hwToEdm_(const std::vector<l1ct::PuppiObjEmu> &hwOut, | ||
std::vector<l1t::PFCandidate> &edmOut) const { | ||
for (const auto &hwPuppi : hwOut) { | ||
l1t::PFCandidate::ParticleType type; | ||
float mass = 0.13f; | ||
if (hwPuppi.hwId.charged()) { | ||
if (hwPuppi.hwId.isMuon()) { | ||
type = l1t::PFCandidate::Muon; | ||
mass = 0.105; | ||
} else if (hwPuppi.hwId.isElectron()) { | ||
type = l1t::PFCandidate::Electron; | ||
mass = 0.005; | ||
} else | ||
type = l1t::PFCandidate::ChargedHadron; | ||
} else { | ||
type = hwPuppi.hwId.isPhoton() ? l1t::PFCandidate::Photon : l1t::PFCandidate::NeutralHadron; | ||
mass = hwPuppi.hwId.isPhoton() ? 0.0 : 0.5; | ||
} | ||
reco::Particle::PolarLorentzVector p4(hwPuppi.floatPt(), hwPuppi.floatEta(), hwPuppi.floatPhi(), mass); | ||
edmOut.emplace_back( | ||
type, hwPuppi.intCharge(), p4, hwPuppi.floatPuppiW(), hwPuppi.intPt(), hwPuppi.intEta(), hwPuppi.intPhi()); | ||
if (hwPuppi.hwId.charged()) { | ||
edmOut.back().setZ0(hwPuppi.floatZ0()); | ||
edmOut.back().setDxy(hwPuppi.floatDxy()); | ||
edmOut.back().setHwZ0(hwPuppi.hwZ0()); | ||
edmOut.back().setHwDxy(hwPuppi.hwDxy()); | ||
edmOut.back().setHwTkQuality(hwPuppi.hwTkQuality()); | ||
} else { | ||
edmOut.back().setHwPuppiWeight(hwPuppi.hwPuppiW()); | ||
edmOut.back().setHwEmID(hwPuppi.hwEmID()); | ||
} | ||
edmOut.back().setEncodedPuppi64(hwPuppi.pack().to_uint64()); | ||
setRefs_(edmOut.back(), hwPuppi); | ||
} | ||
} | ||
|
||
void DeregionizerProducer::setRefs_(l1t::PFCandidate &pf, const l1ct::PuppiObjEmu &p) const { | ||
if (p.srcCand) { | ||
auto match = clusterRefMap_.find(p.srcCand); | ||
if (match == clusterRefMap_.end()) { | ||
throw cms::Exception("CorruptData") << "Invalid cluster pointer in PF candidate id " << p.intId() << " pt " | ||
<< p.floatPt() << " eta " << p.floatEta() << " phi " << p.floatPhi(); | ||
} | ||
pf.setPFCluster(match->second); | ||
} | ||
if (p.srcCand) { | ||
auto match = trackRefMap_.find(p.srcCand); | ||
if (match == trackRefMap_.end()) { | ||
throw cms::Exception("CorruptData") << "Invalid track pointer in PF candidate id " << p.intId() << " pt " | ||
<< p.floatPt() << " eta " << p.floatEta() << " phi " << p.floatPhi(); | ||
} | ||
pf.setPFTrack(match->second); | ||
} | ||
if (p.srcCand) { | ||
auto match = muonRefMap_.find(p.srcCand); | ||
if (match == muonRefMap_.end()) { | ||
throw cms::Exception("CorruptData") << "Invalid muon pointer in PF candidate id " << p.intId() << " pt " | ||
<< p.floatPt() << " eta " << p.floatEta() << " phi " << p.floatPhi(); | ||
} | ||
pf.setMuon(match->second); | ||
} | ||
} | ||
|
||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
DEFINE_FWK_MODULE(DeregionizerProducer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
L1Trigger/Phase2L1ParticleFlow/python/DeregionizerProducer_cfi.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
|
||
DeregionizerProducer = cms.EDProducer("DeregionizerProducer", | ||
RegionalPuppiCands = cms.InputTag("l1ctLayer1","PuppiRegional"), | ||
nPuppiFinalBuffer = cms.uint32(128), | ||
nPuppiPerClk = cms.uint32(6), | ||
nPuppiFirstBuffers = cms.uint32(12), | ||
nPuppiSecondBuffers = cms.uint32(32), | ||
nPuppiThirdBuffers = cms.uint32(64), | ||
debug = cms.untracked.bool(False) | ||
) |
92 changes: 92 additions & 0 deletions
92
L1Trigger/Phase2L1ParticleFlow/src/newfirmware/deregionizer/deregionizer_input.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include <fstream> | ||
#include <cmath> | ||
#include <vector> | ||
#include "deregionizer_input.h" | ||
|
||
#ifdef CMSSW_GIT_HASH | ||
#include "L1Trigger/Phase2L1ParticleFlow/src/dbgPrintf.h" | ||
#else | ||
#include "../../utils/dbgPrintf.h" | ||
#endif | ||
|
||
l1ct::DeregionizerInput::DeregionizerInput(std::vector<float> ®ionEtaCenter, | ||
std::vector<float> ®ionPhiCenter, | ||
const std::vector<l1ct::OutputRegion> &inputRegions) | ||
: regionEtaCenter_(regionEtaCenter), regionPhiCenter_(regionPhiCenter) { | ||
orderedInRegionsPuppis_ = std::vector<std::vector<std::vector<l1ct::PuppiObjEmu> > >(nEtaRegions); | ||
for (int i = 0, n = nEtaRegions; i < n; i++) | ||
orderedInRegionsPuppis_[i].resize(nPhiRegions); | ||
initRegions(inputRegions); | ||
} | ||
|
||
// +pi read first & account for 2 small eta regions per phi slice | ||
unsigned int l1ct::DeregionizerInput::orderRegionsInPhi(const float eta, const float phi, const float etaComp) const { | ||
unsigned int y; | ||
if (fabs(phi) < 0.35) | ||
y = (eta < etaComp ? 0 : 1); | ||
else if (fabs(phi) < 1.05) | ||
y = (phi > 0 ? (eta < etaComp ? 2 : 3) : (eta < etaComp ? 16 : 17)); | ||
else if (fabs(phi) < 1.75) | ||
y = (phi > 0 ? (eta < etaComp ? 4 : 5) : (eta < etaComp ? 14 : 15)); | ||
else if (fabs(phi) < 2.45) | ||
y = (phi > 0 ? (eta < etaComp ? 6 : 7) : (eta < etaComp ? 12 : 13)); | ||
else | ||
y = (phi > 0 ? (eta < etaComp ? 8 : 9) : (eta < etaComp ? 10 : 11)); | ||
return y; | ||
} | ||
|
||
void l1ct::DeregionizerInput::initRegions(const std::vector<l1ct::OutputRegion> &inputRegions) { | ||
for (int i = 0, n = inputRegions.size(); i < n; i++) { | ||
unsigned int x, y; | ||
float eta = regionEtaCenter_[i]; | ||
float phi = regionPhiCenter_[i]; | ||
|
||
if (fabs(eta) < 0.5) { | ||
x = 0; | ||
y = orderRegionsInPhi(eta, phi, 0.0); | ||
} else if (fabs(eta) < 1.5) { | ||
x = (eta < 0.0 ? 1 : 2); | ||
y = (eta < 0.0 ? orderRegionsInPhi(eta, phi, -1.0) : orderRegionsInPhi(eta, phi, 1.0)); | ||
} else if (fabs(eta) < 2.5) { | ||
x = (eta < 0.0 ? 3 : 4); | ||
y = orderRegionsInPhi(eta, phi, 999.0); // Send all candidates in 3 clks, then wait 3 clks for the barrel | ||
} else /*if ( fabs(eta) < 3.0 )*/ { | ||
x = 5; | ||
y = orderRegionsInPhi(eta, phi, 0.0); // Send eta<0 in 3 clks, eta>0 in the next 3 clks | ||
} | ||
/*else x = 6;*/ // HF | ||
|
||
orderedInRegionsPuppis_[x][y].insert(orderedInRegionsPuppis_[x][y].end(), | ||
inputRegions[i].puppi.begin(), | ||
inputRegions[i].puppi.end()); // For now, merging HF with forward HGCal | ||
|
||
while (!orderedInRegionsPuppis_[x][y].empty() && orderedInRegionsPuppis_[x][y].back().hwPt == 0) | ||
orderedInRegionsPuppis_[x][y].pop_back(); // Zero suppression | ||
} | ||
} | ||
|
||
void l1ct::DeregionizerInput::orderRegions(int order[nEtaRegions]) { | ||
std::vector<std::vector<std::vector<l1ct::PuppiObjEmu> > > tmpOrderedInRegionsPuppis; | ||
for (int i = 0, n = nEtaRegions; i < n; i++) | ||
tmpOrderedInRegionsPuppis.push_back(orderedInRegionsPuppis_[order[i]]); | ||
orderedInRegionsPuppis_ = tmpOrderedInRegionsPuppis; | ||
|
||
if (debug_) { | ||
for (int i = 0, nx = orderedInRegionsPuppis_.size(); i < nx; i++) { | ||
dbgCout() << "\n"; | ||
dbgCout() << "Eta region index : " << i << "\n"; | ||
for (int j = 0, ny = orderedInRegionsPuppis_[i].size(); j < ny; j++) { | ||
dbgCout() << " ---> Phi region index : " << j << "\n"; | ||
for (int iPup = 0, nPup = orderedInRegionsPuppis_[i][j].size(); iPup < nPup; iPup++) { | ||
dbgCout() << " > puppi[" << iPup << "]" | ||
<< " pt = " << orderedInRegionsPuppis_[i][j][iPup].hwPt << "\n"; | ||
} | ||
} | ||
dbgCout() << " ----------------- " | ||
<< "\n"; | ||
} | ||
dbgCout() << "Regions ordered!" | ||
<< "\n"; | ||
dbgCout() << "\n"; | ||
} | ||
} |
Oops, something went wrong.