Skip to content

Commit

Permalink
Update jet writer for optional collections.
Browse files Browse the repository at this point in the history
  • Loading branch information
thesps committed Oct 20, 2023
1 parent 498ed94 commit 8570d4f
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 67 deletions.
80 changes: 51 additions & 29 deletions L1Trigger/Phase2L1ParticleFlow/plugins/L1CTJetFileWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class L1CTJetFileWriter : public edm::one::EDAnalyzer<edm::one::SharedResources>
public:
explicit L1CTJetFileWriter(const edm::ParameterSet&);

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

private:
// ----------constants, enums and typedefs ---------
Expand All @@ -45,8 +45,10 @@ class L1CTJetFileWriter : public edm::one::EDAnalyzer<edm::one::SharedResources>
std::vector<ap_uint<64>> encodeSums(const std::vector<l1t::EtSum> jets);

l1t::demo::BoardDataWriter fileWriterOutputToGT_;
std::vector<edm::EDGetTokenT<edm::View<l1t::PFJet>>> jetsTokens_;
std::vector<edm::EDGetTokenT<edm::View<l1t::EtSum>>> mhtTokens_;
std::vector<std::pair<edm::EDGetTokenT<edm::View<l1t::PFJet>>, edm::EDGetTokenT<edm::View<l1t::EtSum>>>> tokens_;
std::vector<std::pair<bool,bool>> tokensToWrite_;
//std::vector<edm::EDGetTokenT<edm::View<l1t::PFJet>>> jetsTokens_;
//std::vector<edm::EDGetTokenT<edm::View<l1t::EtSum>>> mhtTokens_;
};

L1CTJetFileWriter::L1CTJetFileWriter(const edm::ParameterSet& iConfig)
Expand All @@ -67,8 +69,19 @@ L1CTJetFileWriter::L1CTJetFileWriter(const edm::ParameterSet& iConfig)
maxLinesPerFile_,
channelSpecsOutputToGT_) {
for(const auto &pset : collections_){
jetsTokens_.push_back(consumes<edm::View<l1t::PFJet>>(pset.getParameter<edm::InputTag>("jets")));
mhtTokens_.push_back(consumes<edm::View<l1t::EtSum>>(pset.getParameter<edm::InputTag>("mht")));
edm::EDGetTokenT<edm::View<l1t::PFJet>> jetToken;
edm::EDGetTokenT<edm::View<l1t::EtSum>> mhtToken;
bool writeJetToken(false), writeMhtToken(false);
if(pset.exists("jets")){
jetToken = consumes<edm::View<l1t::PFJet>>(pset.getParameter<edm::InputTag>("jets"));
writeJetToken = true;
}
if(pset.exists("mht")){
mhtToken = consumes<edm::View<l1t::EtSum>>(pset.getParameter<edm::InputTag>("mht"));
writeMhtToken = true;
}
tokens_.push_back(std::make_pair(jetToken, mhtToken));
tokensToWrite_.push_back(std::make_pair(writeJetToken, writeMhtToken));
}
}

Expand All @@ -78,27 +91,31 @@ void L1CTJetFileWriter::analyze(const edm::Event& iEvent, const edm::EventSetup&
// 1) Pack collections in the order they're specified. jets then sums within collection
std::vector<ap_uint<64>> link_words;
for(unsigned iCollection = 0; iCollection < collections_.size(); iCollection++){
const auto &jetToken = jetsTokens_.at(iCollection);
// 2) Encode jet information onto vectors containing link data
// TODO remove the sort here and sort the input collection where it's created
const edm::View<l1t::PFJet>& jets = iEvent.get(jetToken);
std::vector<l1t::PFJet> sortedJets;
sortedJets.reserve(jets.size());
std::copy(jets.begin(), jets.end(), std::back_inserter(sortedJets));

std::stable_sort(
sortedJets.begin(), sortedJets.end(), [](l1t::PFJet i, l1t::PFJet j) { return (i.hwPt() > j.hwPt()); });
const auto outputJets(encodeJets(sortedJets));
link_words.insert(link_words.end(), outputJets.begin(), outputJets.end());

// 3) Encode sums onto vectors containing link data
const auto &mhtToken = mhtTokens_.at(iCollection);
const edm::View<l1t::EtSum>& mht = iEvent.get(mhtToken);
std::vector<l1t::EtSum> orderedSums;
std::copy(mht.begin(), mht.end(), std::back_inserter(orderedSums));
// TODO: reorder the sums checking the EtSumType
const auto outputSums(encodeSums(orderedSums));
link_words.insert(link_words.end(), outputSums.begin(), outputSums.end());
if(tokensToWrite_.at(iCollection).first){
const auto &jetToken = tokens_.at(iCollection).first;
// 2) Encode jet information onto vectors containing link data
// TODO remove the sort here and sort the input collection where it's created
const edm::View<l1t::PFJet>& jets = iEvent.get(jetToken);
std::vector<l1t::PFJet> sortedJets;
sortedJets.reserve(jets.size());
std::copy(jets.begin(), jets.end(), std::back_inserter(sortedJets));

std::stable_sort(
sortedJets.begin(), sortedJets.end(), [](l1t::PFJet i, l1t::PFJet j) { return (i.hwPt() > j.hwPt()); });
const auto outputJets(encodeJets(sortedJets));
link_words.insert(link_words.end(), outputJets.begin(), outputJets.end());
}

if(tokensToWrite_.at(iCollection).second){
// 3) Encode sums onto vectors containing link data
const auto &mhtToken = tokens_.at(iCollection).second;
const edm::View<l1t::EtSum>& mht = iEvent.get(mhtToken);
std::vector<l1t::EtSum> orderedSums;
std::copy(mht.begin(), mht.end(), std::back_inserter(orderedSums));
// TODO: reorder the sums checking the EtSumType
const auto outputSums(encodeSums(orderedSums));
link_words.insert(link_words.end(), outputSums.begin(), outputSums.end());
}
}
// 4) Pack jet information into 'event data' object, and pass that to file writer
l1t::demo::EventData eventDataJets;
Expand Down Expand Up @@ -134,14 +151,19 @@ std::vector<ap_uint<64>> L1CTJetFileWriter::encodeSums(const std::vector<l1t::Et
std::vector<ap_uint<64>> sum_words;
int valid = sums.at(0).pt() > 0;
// TODO this is not going to be bit exact
l1gt::Sum ht{valid, sums.at(1).pt(), sums.at(1).phi() / l1gt::Scales::ETAPHI_LSB, sums.at(0).pt()};
l1gt::Sum ht;
ht.valid = valid;
ht.vector_pt.V = sums.at(1).hwPt();
ht.vector_phi.V = sums.at(1).hwPhi();
ht.scalar_pt.V = sums.at(0).hwPt();
//l1gt::Sum ht{valid, sums.at(1).pt(), sums.at(1).phi() / l1gt::Scales::ETAPHI_LSB, sums.at(0).pt()};
sum_words.push_back(ht.pack());
sum_words.push_back(0);
return sum_words;
}

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
void L1CTJetFileWriter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
/*void L1CTJetFileWriter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
//The following says we do not know what parameters are allowed so do no validation
// Please change this to state exactly what you do use, even if it is no parameters
edm::ParameterSetDescription desc;
Expand All @@ -168,7 +190,7 @@ void L1CTJetFileWriter::fillDescriptions(edm::ConfigurationDescriptions& descrip
desc.add<uint32_t>("maxLinesPerFile", 1024);
desc.add<std::string>("format", "EMPv2");
descriptions.addDefault(desc);
}
}*/

//define this as a plug-in
DEFINE_FWK_MODULE(L1CTJetFileWriter);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import FWCore.ParameterSet.Config as cms

l1ctSeededConeJetFileWriter = cms.EDAnalyzer('L1CTJetFileWriter',
l1tSeededConeJetFileWriter = cms.EDAnalyzer('L1CTJetFileWriter',
collections = cms.untracked.VPSet([cms.PSet(jets = cms.InputTag("sc4PFL1PuppiCorrectedEmulator"),
mht = cms.InputTag("sc4PFL1PuppiCorrectedEmulatorMHT"))]),
nJets = cms.uint32(12),
Expand Down
58 changes: 31 additions & 27 deletions L1Trigger/Phase2L1ParticleFlow/python/l1pfJetMet_cff.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import FWCore.ParameterSet.Config as cms
from L1Trigger.Phase2L1ParticleFlow.L1SeedConePFJetProducer_cfi import L1SeedConePFJetProducer, L1SeedConePFJetEmulatorProducer
from L1Trigger.Phase2L1ParticleFlow.DeregionizerProducer_cfi import DeregionizerProducer as l1ctLayer2Deregionizer, DeregionizerProducerExtended as l1ctLayer2DeregionizerExtended
sc4PFL1PF = L1SeedConePFJetProducer.clone(L1PFObjects = 'l1ctLayer1:PF')
sc4PFL1Puppi = L1SeedConePFJetProducer.clone()
sc4PFL1PuppiEmulator = L1SeedConePFJetEmulatorProducer.clone(L1PFObject = cms.InputTag('l1ctLayer2Deregionizer', 'Puppi'))
sc4PFL1PuppiCorrectedEmulator = L1SeedConePFJetEmulatorProducer.clone(L1PFObject = cms.InputTag('l1ctLayer2Deregionizer', 'Puppi'),
doCorrections = cms.bool(True),
correctorFile = cms.string("L1Trigger/Phase2L1ParticleFlow/data/jecs/jecs_20220308.root"),
correctorDir = cms.string('L1PuppiSC4EmuJets'))
sc8PFL1PuppiCorrectedEmulator = L1SeedConePFJetEmulatorProducer.clone(L1PFObject = cms.InputTag('l1ctLayer2Deregionizer', 'Puppi'),
coneSize = cms.double(0.8),
doCorrections = cms.bool(True),
correctorFile = cms.string("L1Trigger/Phase2L1ParticleFlow/data/jecs/jecs_20220308.root"),
correctorDir = cms.string('L1PuppiSC4EmuJets'))
from L1Trigger.Phase2L1ParticleFlow.l1tSeedConePFJetProducer_cfi import l1tSeedConePFJetProducer, l1tSeedConePFJetEmulatorProducer
from L1Trigger.Phase2L1ParticleFlow.l1tDeregionizerProducer_cfi import l1tDeregionizerProducer as l1tLayer2Deregionizer, l1tDeregionizerProducerExtended as l1tLayer2DeregionizerExtended
l1tSC4PFL1PF = l1tSeedConePFJetProducer.clone(L1PFObjects = 'l1tLayer1:PF')
l1tSC4PFL1Puppi = l1tSeedConePFJetProducer.clone()
l1tSC4PFL1PuppiEmulator = l1tSeedConePFJetEmulatorProducer.clone(L1PFObjects = 'l1tLayer2Deregionizer:Puppi')
l1tSC8PFL1PuppiEmulator = l1tSeedConePFJetEmulatorProducer.clone(L1PFObjects = 'l1tLayer2Deregionizer:Puppi',
coneSize = cms.double(0.8))
l1tSC4PFL1PuppiCorrectedEmulator = l1tSeedConePFJetEmulatorProducer.clone(L1PFObjects = 'l1tLayer2Deregionizer:Puppi',
doCorrections = cms.bool(True),
correctorFile = cms.string("L1Trigger/Phase2L1ParticleFlow/data/jecs/jecs_20220308.root"),
correctorDir = cms.string('L1PuppiSC4EmuJets'))
l1tSC8PFL1PuppiCorrectedEmulator = l1tSeedConePFJetEmulatorProducer.clone(L1PFObjects = 'l1tLayer2Deregionizer:Puppi',
coneSize = cms.double(0.8),
doCorrections = cms.bool(True),
correctorFile = cms.string("L1Trigger/Phase2L1ParticleFlow/data/jecs/jecs_20220308.root"),
correctorDir = cms.string('L1PuppiSC4EmuJets'))

_correctedJets = cms.EDProducer("L1TCorrectedPFJetProducer",
jets = cms.InputTag("_tag_"),
Expand All @@ -28,24 +30,26 @@
from Configuration.Eras.Modifier_phase2_hgcalV11_cff import phase2_hgcalV11
phase2_hgcalV11.toModify(_correctedJets, correctorFile = "L1Trigger/Phase2L1ParticleFlow/data/jecs/jecs_20220308.root")

from L1Trigger.Phase2L1ParticleFlow.L1MHTPFProducer_cfi import L1MHTPFProducer
sc4PFL1PuppiCorrectedEmulatorMHT = L1MHTPFProducer.clone(jets = cms.InputTag("sc4PFL1PuppiCorrectedEmulator"))
sc8PFL1PuppiCorrectedEmulatorMHT = L1MHTPFProducer.clone(jets = cms.InputTag("sc8PFL1PuppiCorrectedEmulator"))
from L1Trigger.Phase2L1ParticleFlow.l1tMHTPFProducer_cfi import l1tMHTPFProducer
l1tSC4PFL1PuppiCorrectedEmulatorMHT = l1tMHTPFProducer.clone(jets = 'l1tSC4PFL1PuppiCorrectedEmulator')

sc4PFL1PuppiExtended = sc4PFL1Puppi.clone(L1PFObjects = 'l1ctLayer1Extended:Puppi')
sc4PFL1PuppiExtendedEmulator = sc4PFL1PuppiEmulator.clone(L1PFObjects = cms.InputTag('l1ctLayer2DeregionizerExtended', 'Puppi'))
sc4PFL1PuppiExtendedCorrectedEmulator = _correctedJets.clone(jets = 'sc4PFL1PuppiExtendedEmulator', correctorDir = 'L1PuppiSC4EmuDeregJets')
l1tSC4PFL1PuppiExtended = l1tSeedConePFJetProducer.clone(L1PFObjects = 'l1tLayer1Extended:Puppi')
l1tSC4PFL1PuppiExtendedEmulator = l1tSeedConePFJetEmulatorProducer.clone(L1PFObjects = 'l1tLayer2DeregionizerExtended:Puppi')
l1tSC4PFL1PuppiExtendedCorrectedEmulator = l1tSeedConePFJetEmulatorProducer.clone(L1PFObjects = 'l1tLayer2DeregionizerExtended:Puppi',
doCorrections = cms.bool(True),
correctorFile = cms.string("L1Trigger/Phase2L1ParticleFlow/data/jecs/jecs_20220308.root"),
correctorDir = cms.string('L1PuppiSC4EmuJets'))

l1PFJetsTask = cms.Task(
l1ctLayer2Deregionizer, sc4PFL1PF, sc4PFL1Puppi, sc4PFL1PuppiEmulator, sc4PFL1PuppiCorrectedEmulator, sc4PFL1PuppiCorrectedEmulatorMHT,
sc8PFL1PuppiCorrectedEmulator, sc8PFL1PuppiCorrectedEmulatorMHT
L1TPFJetsTask = cms.Task(
l1tLayer2Deregionizer, l1tSC4PFL1PF, l1tSC4PFL1Puppi, l1tSC4PFL1PuppiEmulator, l1tSC4PFL1PuppiCorrectedEmulator, l1tSC4PFL1PuppiCorrectedEmulatorMHT,
l1tSC8PFL1PuppiEmulator, l1tSC8PFL1PuppiCorrectedEmulator
)

l1PFJetsExtendedTask = cms.Task(
l1ctLayer2DeregionizerExtended, sc4PFL1PuppiExtended, sc4PFL1PuppiExtendedEmulator, sc4PFL1PuppiExtendedCorrectedEmulator
L1TPFJetsExtendedTask = cms.Task(
l1tLayer2DeregionizerExtended, l1tSC4PFL1PuppiExtended, l1tSC4PFL1PuppiExtendedEmulator, l1tSC4PFL1PuppiExtendedCorrectedEmulator
)

L1TPFJetsEmulationTask = cms.Task(
l1tLayer2Deregionizer, l1tSCPFL1PuppiEmulator, l1tSCPFL1PuppiCorrectedEmulator, l1tSCPFL1PuppiCorrectedEmulatorMHT
l1tLayer2Deregionizer, l1tSC4PFL1PuppiEmulator, l1tSC4PFL1PuppiCorrectedEmulator, l1tSC4PFL1PuppiCorrectedEmulatorMHT,
l1tSC8PFL1PuppiEmulator, l1tSC8PFL1PuppiCorrectedEmulator
)

20 changes: 10 additions & 10 deletions L1Trigger/Phase2L1ParticleFlow/test/make_l1ct_binaryFiles_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,20 @@

process.load('L1Trigger.Phase2L1ParticleFlow.l1ctLayer1_cff')
process.load('L1Trigger.Phase2L1ParticleFlow.l1ctLayer2EG_cff')
process.load('L1Trigger.Phase2L1ParticleFlow.l1pfJetMet_cff')
process.load('L1Trigger.L1TTrackMatch.l1tGTTInputProducer_cfi')
process.load('L1Trigger.L1TTrackMatch.l1tTrackSelectionProducer_cfi')
process.l1tTrackSelectionProducer.processSimulatedTracks = False # these would need stubs, and are not used anyway
process.load('L1Trigger.VertexFinder.l1tVertexProducer_cfi')
from L1Trigger.Phase2L1GMT.gmt_cfi import l1tStandaloneMuons
process.l1tSAMuonsGmt = l1tStandaloneMuons.clone()

from L1Trigger.Phase2L1ParticleFlow.l1SeedConePFJetEmulatorProducer_cfi import l1SeedConePFJetEmulatorProducer
from L1Trigger.Phase2L1ParticleFlow.l1tDeregionizerProducer_cfi import l1tDeregionizerProducer
from L1Trigger.Phase2L1ParticleFlow.l1tJetFileWriter_cfi import l1tSeededConeJetFileWriter
process.l1tLayer2Deregionizer = l1tDeregionizerProducer.clone()
process.l1tLayer2SeedConeJetsCorrected = l1SeedConePFJetEmulatorProducer.clone(L1PFObjects = cms.InputTag('l1tLayer2Deregionizer', 'Puppi'),
doCorrections = cms.bool(True),
correctorFile = cms.string("L1Trigger/Phase2L1ParticleFlow/data/jecs/jecs_20220308.root"),
correctorDir = cms.string('L1PuppiSC4EmuJets'))
process.l1tLayer2SeedConeJetWriter = l1tSeededConeJetFileWriter.clone(jets = "l1tLayer2SeedConeJetsCorrected")
l1ctLayer2SCJetsProducts = cms.untracked.VPSet([cms.PSet(jets = cms.InputTag("l1tSC4PFL1PuppiCorrectedEmulator"),
mht = cms.InputTag("l1tSC4PFL1PuppiCorrectedEmulatorMHT")),
cms.PSet(jets = cms.InputTag("l1tSC8PFL1PuppiCorrectedEmulator"),)
])
process.l1tLayer2SeedConeJetWriter = l1tSeededConeJetFileWriter.clone(collections = l1ctLayer2SCJetsProducts)

process.l1tLayer1BarrelTDR = process.l1tLayer1Barrel.clone()
process.l1tLayer1BarrelTDR.regionizerAlgo = cms.string("TDR")
Expand Down Expand Up @@ -133,7 +131,9 @@
process.l1tLayer1HF +
process.l1tLayer1 +
process.l1tLayer2Deregionizer +
process.l1tLayer2SeedConeJetsCorrected +
process.l1tSC4PFL1PuppiCorrectedEmulator +
process.l1tSC4PFL1PuppiCorrectedEmulatorMHT +
process.l1tSC8PFL1PuppiCorrectedEmulator +
# process.l1tLayer2SeedConeJetWriter +
process.l1tLayer2EG
)
Expand All @@ -152,7 +152,7 @@
#####################################################################################################################
## Layer 2 seeded-cone jets
if not args.patternFilesOFF:
process.runPF.insert(process.runPF.index(process.l1tLayer2SeedConeJetsCorrected)+1, process.l1tLayer2SeedConeJetWriter)
process.runPF.insert(process.runPF.index(process.l1tSC8PFL1PuppiCorrectedEmulator)+1, process.l1tLayer2SeedConeJetWriter)
process.l1tLayer2SeedConeJetWriter.maxLinesPerFile = _eventsPerFile*54

if not args.dumpFilesOFF:
Expand Down

0 comments on commit 8570d4f

Please sign in to comment.