diff --git a/L1Trigger/Phase2L1ParticleFlow/plugins/L1TCtL2EgProducer.cc b/L1Trigger/Phase2L1ParticleFlow/plugins/L1TCtL2EgProducer.cc index 25360347e03c6..6bd03b11b2115 100644 --- a/L1Trigger/Phase2L1ParticleFlow/plugins/L1TCtL2EgProducer.cc +++ b/L1Trigger/Phase2L1ParticleFlow/plugins/L1TCtL2EgProducer.cc @@ -36,9 +36,10 @@ class L1TCtL2EgProducer : public edm::global::EDProducer<> { std::vector> encodeLayer1(const std::vector &photons) const; std::vector> encodeLayer1(const std::vector &electrons) const; - std::vector> encodeLayer1EgObjs(unsigned int nObj, - const std::vector &photons, - const std::vector &electrons) const; + void encodeLayer1EgObjs(unsigned int nObj, + std::vector> &data, + const std::vector &photons, + const std::vector &electrons) const; void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override; @@ -56,25 +57,25 @@ class L1TCtL2EgProducer : public edm::global::EDProducer<> { template class PFInstanceInputs { public: - typedef std::vector, std::vector>> InputTokenAndChannels; + typedef std::vector, std::vector>> InputTokenAndRegions; PFInstanceInputs(L1TCtL2EgProducer *prod, const std::vector &confs) { for (const auto &conf : confs) { const auto &producer_tag = conf.getParameter("pfProducer"); - tokensAndChannels_.push_back(std::make_pair( + tokensAndRegions_.push_back(std::make_pair( prod->consumes(edm::InputTag(producer_tag.label(), producer_tag.instance(), producer_tag.process())), - conf.getParameter>("channels"))); + conf.getParameter>("regions"))); } } - const InputTokenAndChannels &tokensAndChannels() const { return tokensAndChannels_; } + const InputTokenAndRegions &tokensAndRegions() const { return tokensAndRegions_; } private: - InputTokenAndChannels tokensAndChannels_; + InputTokenAndRegions tokensAndRegions_; }; class PatternWriter { public: - PatternWriter(const edm::ParameterSet &conf) : dataWriter_(nullptr) { + PatternWriter(const edm::ParameterSet &conf) : region2link_(5), dataWriter_(nullptr) { unsigned int nFramesPerBX = conf.getParameter("nFramesPerBX"); std::map>> channelSpecs; @@ -84,11 +85,42 @@ class L1TCtL2EgProducer : public edm::global::EDProducer<> { unsigned int eventGap = inTMUX * nFramesPerBX - channelConf.getParameter("nWords"); // assuming 96bit (= 3/2 word) // words = TMUX*9-2*3/2*words + std::vector chns = channelConf.getParameter>("channels"); - channelSpecs[l1t::demo::LinkId{channelConf.getParameter("interface"), - channelConf.getParameter("id")}] = - std::make_pair(l1t::demo::ChannelSpec{inTMUX, eventGap}, - std::vector(std::begin(chns), std::end(chns))); + + std::string interface = channelConf.getParameter("interface"); + unsigned int chId = channelConf.getParameter("id"); + l1t::demo::LinkId linkId{interface, size_t(chId)}; + channelSpecs[linkId] = std::make_pair(l1t::demo::ChannelSpec{inTMUX, eventGap}, + std::vector(std::begin(chns), std::end(chns))); + + // NOTE: this could be parametrized from CFG + if (inTMUX == 6) { + if (interface == "eglayer1Barrel" || interface == "eglayer1Endcap") { + // Layer1 TMUX=6 => each one of the regions is mapped to a link + // with the same ID + // # of words = 16 (pho) + 2*16 (ele) = 48 + // no filling words needed + region2link_[chId] = RegionLinkMetadata{linkId, 0}; + } + } else if (inTMUX == 18) { + if (interface == "eglayer1Barrel") { + // Layer1 TMUX=18 => 3 regions are mapped to the same link + // one every 6 BX x 9 words = 54 words + // # of data words = 16 (pho) + 2*16 (ele) = 48 + // # we fill with 54-48 = 6 empty words + region2link_[0] = RegionLinkMetadata{linkId, 6}; + region2link_[1] = RegionLinkMetadata{linkId, 6}; + region2link_[2] = RegionLinkMetadata{linkId, 0}; + } else if (interface == "eglayer1Endcap") { + // Layer1 TMUX=18 => 2 endcap regions are mapped to the same link + // one every 9 BX x 9 words = 81 words + // # of data words = 16 (pho) + 2*16 (ele) = 48 + // # we fill with 81-48 = 33 empty words + region2link_[3] = RegionLinkMetadata{linkId, 33}; + region2link_[4] = RegionLinkMetadata{linkId, 0}; + } + } } dataWriter_ = std::make_unique( @@ -101,11 +133,23 @@ class L1TCtL2EgProducer : public edm::global::EDProducer<> { channelSpecs); } + struct RegionLinkMetadata { + l1t::demo::LinkId linkId; + unsigned int nTrailingWords; + }; + void addEvent(const l1t::demo::EventData &eventData) { dataWriter_->addEvent(eventData); } void flush() { dataWriter_->flush(); } + const RegionLinkMetadata ®ion2Link(unsigned int region) const { + assert(region < region2link_.size()); + return region2link_.at(region); + } + private: + std::vector region2link_; + std::unique_ptr dataWriter_; }; @@ -115,33 +159,33 @@ class L1TCtL2EgProducer : public edm::global::EDProducer<> { ConstituentPtrVector &constituentsPtrs, std::unique_ptr &out) const { edm::Handle handle; - for (const auto &tokenAndChannel : instance.tokensAndChannels()) { - iEvent.getByToken(tokenAndChannel.first, handle); - populate(out, handle, tokenAndChannel.second, constituentsPtrs); + for (const auto &tokenAndRegions : instance.tokensAndRegions()) { + iEvent.getByToken(tokenAndRegions.first, handle); + populate(out, handle, tokenAndRegions.second, constituentsPtrs); } } template void populate(std::unique_ptr &out, const edm::Handle &in, - const std::vector &links, + const std::vector ®ions, ConstituentPtrVector &constituentsPtrs) const { - assert(links.size() == in->nRegions()); + assert(regions.size() == in->nRegions()); for (unsigned int iBoard = 0, nBoard = in->nRegions(); iBoard < nBoard; ++iBoard) { auto region = in->region(iBoard); - int linkID = links[iBoard]; - if (linkID < 0) + int regionID = regions[iBoard]; + if (regionID < 0) continue; - // std::cout << "Board eta: " << in->eta(iBoard) << " phi: " << in->phi(iBoard) << " link: " << linkID << std::endl; + // std::cout << "Board eta: " << in->eta(iBoard) << " phi: " << in->phi(iBoard) << " link: " << regionID << std::endl; for (const auto &obj : region) { - convertToEmu(obj, constituentsPtrs, out->at(linkID)); + convertToEmu(obj, constituentsPtrs, out->at(regionID)); } } } void populate(std::unique_ptr> &out, const edm::Handle> &in, - const std::vector &links, + const std::vector ®ions, ConstituentPtrVector &constituentsPtrs) const { for (int bx = in->getFirstBX(); bx <= in->getLastBX(); bx++) { for (auto egee_itr = in->begin(bx); egee_itr != in->end(bx); egee_itr++) { @@ -247,19 +291,17 @@ std::vector> L1TCtL2EgProducer::encodeLayer1(const std::vector> L1TCtL2EgProducer::encodeLayer1EgObjs(unsigned int nObj, - const std::vector &photons, - const std::vector &electrons) const { - std::vector> ret; +void L1TCtL2EgProducer::encodeLayer1EgObjs(unsigned int nObj, + std::vector> &data, + const std::vector &photons, + const std::vector &electrons) const { auto encoded_photons = encodeLayer1(photons); encoded_photons.resize(nObj, {0}); auto encoded_eles = encodeLayer1(electrons); encoded_eles.resize(2 * nObj, {0}); - std::copy(encoded_photons.begin(), encoded_photons.end(), std::back_inserter(ret)); - std::copy(encoded_eles.begin(), encoded_eles.end(), std::back_inserter(ret)); - - return ret; + std::copy(encoded_photons.begin(), encoded_photons.end(), std::back_inserter(data)); + std::copy(encoded_eles.begin(), encoded_eles.end(), std::back_inserter(data)); } void L1TCtL2EgProducer::produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &) const { @@ -269,24 +311,31 @@ void L1TCtL2EgProducer::produce(edm::StreamID, edm::Event &iEvent, const edm::Ev merge(tkEGInputs_, iEvent, constituents, outEgs); iEvent.put(std::move(outEgs), tkEGInstanceLabel_); - auto boards = std::make_unique>(l2egsorter.nInputBoards()); + auto regions = std::make_unique>(l2egsorter.nInputBoards()); - merge(tkEleInputs_, iEvent, constituents, boards); - merge(tkEmInputs_, iEvent, constituents, boards); + merge(tkEleInputs_, iEvent, constituents, regions); + merge(tkEmInputs_, iEvent, constituents, regions); if (doInPtrn_) { + std::map regio2link; + l1t::demo::EventData inData; - for (unsigned int ibrd = 0; ibrd < boards->size(); ibrd++) { - inData.add( - {"eglayer1", ibrd}, - encodeLayer1EgObjs(l2egsorter.nInputObjPerBoard(), (*boards)[ibrd].egphoton, (*boards)[ibrd].egelectron)); + for (unsigned int ireg = 0; ireg < regions->size(); ireg++) { + const auto &linkData = inPtrnWrt_->region2Link(ireg); + std::vector> data; + + if (inData.has(linkData.linkId)) + data = inData.at(linkData.linkId); + encodeLayer1EgObjs(l2egsorter.nInputObjPerBoard(), data, (*regions)[ireg].egphoton, (*regions)[ireg].egelectron); + data.resize(data.size() + linkData.nTrailingWords, {0}); + inData.add(linkData.linkId, data); } inPtrnWrt_->addEvent(inData); } std::vector out_photons_emu; std::vector out_eles_emu; - l2egsorter.run(*boards, out_photons_emu, out_eles_emu); + l2egsorter.run(*regions, out_photons_emu, out_eles_emu); // PUPPI isolation auto &pfObjs = iEvent.get(pfObjsToken_); diff --git a/L1Trigger/Phase2L1ParticleFlow/python/l1ctLayer2EG_cff.py b/L1Trigger/Phase2L1ParticleFlow/python/l1ctLayer2EG_cff.py index 18e28d46752f0..f5f7308ce8a41 100644 --- a/L1Trigger/Phase2L1ParticleFlow/python/l1ctLayer2EG_cff.py +++ b/L1Trigger/Phase2L1ParticleFlow/python/l1ctLayer2EG_cff.py @@ -7,35 +7,35 @@ tkElectrons=cms.VPSet( cms.PSet( pfProducer=cms.InputTag("l1tLayer1HGCal", 'L1TkElePerBoard'), - channels=cms.vint32(3, 4) + regions=cms.vint32(3, 4) ), cms.PSet( pfProducer=cms.InputTag("l1tLayer1Barrel", 'L1TkElePerBoard'), - channels=cms.vint32(0, 1, 2) + regions=cms.vint32(0, 1, 2) ), ), tkEms=cms.VPSet( cms.PSet( pfProducer=cms.InputTag("l1tLayer1HGCal", 'L1TkEmPerBoard'), - channels=cms.vint32(3, 4) + regions=cms.vint32(3, 4) ), cms.PSet( pfProducer=cms.InputTag("l1tLayer1HGCalNoTK", 'L1TkEmPerBoard'), - channels=cms.vint32(-1) + regions=cms.vint32(-1) ), cms.PSet( pfProducer=cms.InputTag("l1tLayer1Barrel", 'L1TkEmPerBoard'), - channels=cms.vint32(0, 1, 2) + regions=cms.vint32(0, 1, 2) ), ), tkEgs=cms.VPSet( cms.PSet( pfProducer=cms.InputTag("l1tLayer1HGCal", 'L1Eg'), - channels=cms.vint32(-1) + regions=cms.vint32(-1) ), cms.PSet( pfProducer=cms.InputTag("l1tLayer1HGCalNoTK", 'L1Eg'), - channels=cms.vint32(-1) + regions=cms.vint32(-1) ), ), l1PFObjects = cms.InputTag("l1tLayer2Deregionizer", "Puppi"), @@ -81,35 +81,35 @@ cms.PSet( TMUX=cms.uint32(6), nWords=cms.uint32(48), # = 16*2words ele + 16words photons - interface=cms.string("eglayer1"), + interface=cms.string("eglayer1Barrel"), id=cms.uint32(0), channels=cms.vuint32(0) ), cms.PSet( TMUX=cms.uint32(6), nWords=cms.uint32(48), - interface=cms.string("eglayer1"), + interface=cms.string("eglayer1Barrel"), id=cms.uint32(1), channels=cms.vuint32(1) ), cms.PSet( TMUX=cms.uint32(6), nWords=cms.uint32(48), - interface=cms.string("eglayer1"), + interface=cms.string("eglayer1Barrel"), id=cms.uint32(2), channels=cms.vuint32(2) ), cms.PSet( TMUX=cms.uint32(6), nWords=cms.uint32(48), - interface=cms.string("eglayer1"), + interface=cms.string("eglayer1Endcap"), id=cms.uint32(3), channels=cms.vuint32(3) ), cms.PSet( TMUX=cms.uint32(6), nWords=cms.uint32(48), - interface=cms.string("eglayer1"), + interface=cms.string("eglayer1Endcap"), id=cms.uint32(4), channels=cms.vuint32(4) ), @@ -190,6 +190,65 @@ ), ) +# EG Layer2 with Layer1 @ TMUX18 +l1tLayer2EGTM18 = l1tLayer2EG.clone( + tkElectrons=cms.VPSet( + cms.PSet( + pfProducer=cms.InputTag("l1tLayer1HGCalTM18", 'L1TkElePerBoard'), + regions=cms.vint32(3, 4) + ), + cms.PSet( + pfProducer=cms.InputTag("l1tLayer1BarrelSerenityTM18", 'L1TkElePerBoard'), + regions=cms.vint32(0, 1, 2) + ), + ), + tkEms=cms.VPSet( + cms.PSet( + pfProducer=cms.InputTag("l1tLayer1HGCalTM18", 'L1TkEmPerBoard'), + regions=cms.vint32(3, 4) + ), + cms.PSet( + pfProducer=cms.InputTag("l1tLayer1HGCalNoTKTM18", 'L1TkEmPerBoard'), + regions=cms.vint32(-1) + ), + cms.PSet( + pfProducer=cms.InputTag("l1tLayer1BarrelSerenityTM18", 'L1TkEmPerBoard'), + regions=cms.vint32(0, 1, 2) + ), + ), + tkEgs=cms.VPSet( + cms.PSet( + pfProducer=cms.InputTag("l1tLayer1HGCalTM18", 'L1Eg'), + regions=cms.vint32(-1) + ), + cms.PSet( + pfProducer=cms.InputTag("l1tLayer1HGCalNoTKTM18", 'L1Eg'), + regions=cms.vint32(-1) + ), + ), +) + +l1tLayer2EGTM18.inPatternFile.outputFilename = "L1TCTL2EG_TMUX18_InPattern" +l1tLayer2EGTM18.inPatternFile.channels = cms.VPSet( + cms.PSet( + TMUX=cms.uint32(18), + nWords=cms.uint32(156), # = (16*2words ele + 16words photons) * 3 (regions) every 6 BX (54 words) = 48+6(empty)+48+6(empty)+48 = 156 + interface=cms.string("eglayer1Barrel"), + id=cms.uint32(0), + channels=cms.vuint32(0,2,4) + ), + cms.PSet( + TMUX=cms.uint32(18), + nWords=cms.uint32(129), # (16*2words ele + 16words photons) * 2 (regions) every 9 BX (81 words) = 48+33(empty)+48 + interface=cms.string("eglayer1Endcap"), + id=cms.uint32(1), + channels=cms.vuint32(1,3,5) + ), +) +l1tLayer2EGTM18.outPatternFile.outputFilename = 'L1TCTL2EG_TMUX18_OutPattern' +# FIXME: we need to schedule a new deregionizer for TM18 +# l1tLayer2EGTM18.l1PFObjects = cms.InputTag("l1tLayer2Deregionizer", "Puppi"), + L1TLayer2EGTask = cms.Task( l1tLayer2Deregionizer, diff --git a/L1Trigger/Phase2L1ParticleFlow/test/make_l1ct_binaryFiles_cfg.py b/L1Trigger/Phase2L1ParticleFlow/test/make_l1ct_binaryFiles_cfg.py index c6c0e54794bce..f6893e7c069b5 100644 --- a/L1Trigger/Phase2L1ParticleFlow/test/make_l1ct_binaryFiles_cfg.py +++ b/L1Trigger/Phase2L1ParticleFlow/test/make_l1ct_binaryFiles_cfg.py @@ -31,7 +31,7 @@ process.load("SimGeneral.HepPDTESSource.pythiapdt_cfi") process.load("FWCore.MessageLogger.MessageLogger_cfi") process.options = cms.untracked.PSet( wantSummary = cms.untracked.bool(True), allowUnscheduled = cms.untracked.bool(False) ) -process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(1000)) +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(100)) process.MessageLogger.cerr.FwkReport.reportEvery = 1 process.source = cms.Source("PoolSource", @@ -185,10 +185,15 @@ process.runPF.insert(process.runPF.index(process.l1tLayer1HGCal)+1, process.l1tLayer1HGCalTM18) process.runPF.insert(process.runPF.index(process.l1tLayer1HGCalNoTK)+1, process.l1tLayer1HGCalNoTKTM18) process.runPF.insert(process.runPF.index(process.l1tLayer1BarrelSerenity)+1, process.l1tLayer1BarrelSerenityTM18) + # FIXME: we need to schedule a new deregionizer for TM18 + process.runPF.insert(process.runPF.index(process.l1tLayer2EG)+1, process.l1tLayer2EGTM18) if not args.patternFilesOFF: process.l1tLayer1HGCalTM18.patternWriters = cms.untracked.VPSet(*hgcalTM18WriterConfigs) process.l1tLayer1HGCalNoTKTM18.patternWriters = cms.untracked.VPSet(hgcalNoTKOutputTM18WriterConfig) process.l1tLayer1BarrelSerenityTM18.patternWriters = cms.untracked.VPSet() + process.l1tLayer2EGTM18.writeInPattern = True + process.l1tLayer2EGTM18.writeOutPattern = True + if not args.dumpFilesOFF: for det in "HGCalTM18", "HGCalNoTKTM18", "BarrelSerenityTM18": getattr(process, 'l1tLayer1'+det).dumpFileName = cms.untracked.string("TTbar_PU200_"+det+".dump")