Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deregionizer pattern files #128

Open
wants to merge 4 commits into
base: L1PF_14_2_X
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions L1Trigger/Phase2L1ParticleFlow/plugins/L1CTDeregionizerFileWriter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#include <memory>
#include <numeric>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"

#include "DataFormats/Common/interface/View.h"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?


#include "L1Trigger/DemonstratorTools/interface/BoardDataWriter.h"
#include "L1Trigger/DemonstratorTools/interface/utilities.h"
#include "DataFormats/L1TParticleFlow/interface/PFCandidate.h"

//
// class declaration
//

class L1CTDeregionizerFileWriter : public edm::one::EDAnalyzer<edm::one::SharedResources> {
public:
explicit L1CTDeregionizerFileWriter(const edm::ParameterSet&);

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
// ----------constants, enums and typedefs ---------
edm::EDGetTokenT<std::vector<l1t::PFCandidate>> l1PFToken_;
size_t nFramesPerBX_;
size_t ctl2BoardTMUX_;
size_t gapLengthOutput_;
size_t maxLinesPerFile_;
std::map<l1t::demo::LinkId, std::pair<l1t::demo::ChannelSpec, std::vector<size_t>>> channelSpecsOutput_;

// ----------member functions ----------------------
void analyze(const edm::Event&, const edm::EventSetup&) override;
void endJob() override;

std::vector<std::vector<ap_uint<64>>> encodePuppi(const std::vector<l1t::PFCandidate> particles, const int nrows);

l1t::demo::BoardDataWriter fileWriterOutput_;
};

L1CTDeregionizerFileWriter::L1CTDeregionizerFileWriter(const edm::ParameterSet& iConfig)
: l1PFToken_(consumes<std::vector<l1t::PFCandidate>>(iConfig.getParameter<edm::InputTag>("L1PFObjects"))),
nFramesPerBX_(iConfig.getParameter<unsigned>("nFramesPerBX")),
ctl2BoardTMUX_(iConfig.getParameter<unsigned>("TMUX")),
gapLengthOutput_(iConfig.getParameter<unsigned>("gapLengthOutput")),
maxLinesPerFile_(iConfig.getParameter<unsigned>("maxLinesPerFile")),
channelSpecsOutput_{
{{"deregionizer", 0}, {{ctl2BoardTMUX_, gapLengthOutput_}, {0}}},
{{"deregionizer", 1}, {{ctl2BoardTMUX_, gapLengthOutput_}, {1}}},
{{"deregionizer", 2}, {{ctl2BoardTMUX_, gapLengthOutput_}, {2}}},
{{"deregionizer", 3}, {{ctl2BoardTMUX_, gapLengthOutput_}, {3}}},
},
fileWriterOutput_(l1t::demo::parseFileFormat(iConfig.getParameter<std::string>("format")),
iConfig.getParameter<std::string>("outputFilename"),
iConfig.getParameter<std::string>("outputFileExtension"),
nFramesPerBX_,
ctl2BoardTMUX_,
maxLinesPerFile_,
channelSpecsOutput_) {}

void L1CTDeregionizerFileWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
using namespace edm;

const std::vector<l1t::PFCandidate> particles = iEvent.get(l1PFToken_);
std::vector<std::vector<ap_uint<64>>> link_words = encodePuppi(particles, 4);

l1t::demo::EventData eventData;
for (size_t i = 0; i < 4; i++) {
eventData.add({"deregionizer", i}, link_words.at(i));
}
fileWriterOutput_.addEvent(eventData);
}

// ------------ method called once each job just after ending the event loop ------------
void L1CTDeregionizerFileWriter::endJob() {
// Writing pending events to file before exiting
fileWriterOutput_.flush();
}

std::vector<std::vector<ap_uint<64>>> L1CTDeregionizerFileWriter::encodePuppi(
const std::vector<l1t::PFCandidate> particles, const int nrows) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a ref?

// 'reshape' the 1D View of particles to a 2D vector with nrows in the first dimension
// pack the particles to their 64 bit HW representation
std::vector<std::vector<ap_uint<64>>> particles_packed_reshaped(nrows);
for (uint i = 0; i < particles.size(); i++) {
ap_uint<64> p = particles.at(i).encodedPuppi64();
particles_packed_reshaped[i % nrows].push_back(p);
}
return particles_packed_reshaped;
}

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
void L1CTDeregionizerFileWriter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("L1PFObjects", edm::InputTag("l1tLayer2Deregionizer", "Puppi"));
desc.add<std::string>("outputFilename", "L1CTDeregionizerPatterns");
desc.add<std::string>("outputFileExtension", "txt.gz");
desc.add<uint32_t>("nFramesPerBX", 9);
desc.add<uint32_t>("gapLengthOutput", 4);
desc.add<uint32_t>("TMUX", 6);
desc.add<uint32_t>("maxLinesPerFile", 1024);
desc.add<std::string>("format", "EMPv2");
descriptions.addDefault(desc);
}

//define this as a plug-in
DEFINE_FWK_MODULE(L1CTDeregionizerFileWriter);
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
nJets = cms.uint32(12))
])
process.l1tLayer2SeedConeJetWriter = l1tSeededConeJetFileWriter.clone(collections = l1ctLayer2SCJetsProducts)

process.l1tLayer2DeregionizerWriter = cms.EDAnalyzer('L1CTDeregionizerFileWriter')
process.l1tLayer1BarrelTDR = process.l1tLayer1Barrel.clone()
process.l1tLayer1BarrelTDR.regionizerAlgo = cms.string("TDR")
process.l1tLayer1BarrelTDR.regionizerAlgoParameters = cms.PSet(
Expand Down Expand Up @@ -166,10 +166,12 @@
process.l1tLayer2EG.outPatternFile.maxLinesPerFile = _eventsPerFile*54

#####################################################################################################################
## Layer 2 seeded-cone jets
## Layer 2 seeded-cone jets and deregionizer
if not args.patternFilesOFF:
process.runPF.insert(process.runPF.index(process.l1tSC8PFL1PuppiCorrectedEmulator)+1, process.l1tLayer2SeedConeJetWriter)
process.l1tLayer2SeedConeJetWriter.maxLinesPerFile = _eventsPerFile*54
process.runPF.insert(process.runPF.index(process.l1tLayer2SeedConeJetWriter)+1, process.l1tLayer2DeregionizerWriter)
process.l1tLayer2DeregionizerWriter.maxLinesPerFile = cms.uint32(_eventsPerFile*54)

if not args.dumpFilesOFF:
for det in "Barrel", "BarrelTDR", "BarrelSerenity", "HGCal", "HGCalElliptic", "HGCalNoTK", "HF":
Expand Down