Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
#ifndef L1Trigger_Phase2L1ParticleFlow_egamma_pftkegsorter_barrel_ref_h
#define L1Trigger_Phase2L1ParticleFlow_egamma_pftkegsorter_barrel_ref_h

#include <cstdio>
#include <vector>

#include "pftkegsorter_ref.h"
#include "DataFormats/L1TParticleFlow/interface/layer1_emulator.h"
#include "L1Trigger/Phase2L1ParticleFlow/interface/common/bitonic_hybrid_sort_ref.h"

namespace l1ct {
class PFTkEGSorterBarrelEmulator : public PFTkEGSorterEmulator {
public:
PFTkEGSorterBarrelEmulator(const unsigned int nObjToSort = 10, const unsigned int nObjSorted = 16)
: PFTkEGSorterEmulator(nObjToSort, nObjSorted) {}

#ifdef CMSSW_GIT_HASH
PFTkEGSorterBarrelEmulator(const edm::ParameterSet& iConfig)
: PFTkEGSorterEmulator(iConfig.getParameter<uint32_t>("nObjToSort"),
iConfig.getParameter<uint32_t>("nObjSorted")) {}
#endif

~PFTkEGSorterBarrelEmulator() override {}

void toFirmware_pho(const OutputRegion& outregions, EGIsoObj photons_in[/*nObjSorted_*/]) const {
for (unsigned int i = 0; i < nObjToSort_; i++) {
EGIsoObj pho;
if (i < outregions.egphoton.size()) {
pho = outregions.egphoton[i];
} else
pho.clear();

photons_in[i] = pho;
}
}

void toFirmware_ele(const OutputRegion& outregions, EGIsoEleObj eles_in[/*nObjSorted_*/]) const {
for (unsigned int i = 0; i < nObjToSort_; i++) {
EGIsoEleObj ele;
if (i < outregions.egelectron.size()) {
ele = outregions.egelectron[i];
} else
ele.clear();

eles_in[i] = ele;
}
}

void runPho(const std::vector<l1ct::PFInputRegion>& pfregions,
const std::vector<l1ct::OutputRegion>& outregions,
const std::vector<unsigned int>& region_index,
std::vector<l1ct::EGIsoObjEmu>& eg_sorted_inBoard) override {
run<l1ct::EGIsoObjEmu>(pfregions, outregions, region_index, eg_sorted_inBoard);
}
void runEle(const std::vector<l1ct::PFInputRegion>& pfregions,
const std::vector<l1ct::OutputRegion>& outregions,
const std::vector<unsigned int>& region_index,
std::vector<l1ct::EGIsoEleObjEmu>& eg_sorted_inBoard) override {
run<l1ct::EGIsoEleObjEmu>(pfregions, outregions, region_index, eg_sorted_inBoard);
}

template <typename T>
void run(const std::vector<PFInputRegion>& pfregions,
const std::vector<OutputRegion>& outregions,
const std::vector<unsigned int>& region_index,
std::vector<T>& eg_sorted_inBoard) {
// we copy to be able to resize them
std::vector<std::vector<T>> objs_in;
objs_in.reserve(nObjToSort_);
for (unsigned int i : region_index) {
std::vector<T> objs;
extractEGObjEmu(pfregions[i].region, outregions[i], objs);
if (debug_)
dbgCout() << "objs size " << objs.size() << "\n";
resize_input(objs);
objs_in.push_back(objs);
if (debug_)
dbgCout() << "objs (re)size and total objs size " << objs.size() << " " << objs_in.size() << "\n";
}

merge(objs_in, eg_sorted_inBoard);

if (debug_) {
dbgCout() << "objs.size() size " << eg_sorted_inBoard.size() << "\n";
for (const auto& out : eg_sorted_inBoard)
dbgCout() << "kinematics of sorted objects " << out.hwPt << " " << out.hwEta << " " << out.hwPhi << "\n";
}
}

private:
void extractEGObjEmu(const PFRegionEmu& region,
const l1ct::OutputRegion& outregion,
std::vector<l1ct::EGIsoObjEmu>& eg) {
extractEGObjEmu(region, outregion.egphoton, eg);
}
void extractEGObjEmu(const PFRegionEmu& region,
const l1ct::OutputRegion& outregion,
std::vector<l1ct::EGIsoEleObjEmu>& eg) {
extractEGObjEmu(region, outregion.egelectron, eg);
}
template <typename T>
void extractEGObjEmu(const PFRegionEmu& region,
const std::vector<T>& regional_objects,
std::vector<T>& global_objects) {
for (const auto& reg_obj : regional_objects) {
global_objects.emplace_back(reg_obj);
global_objects.back().hwEta = region.hwGlbEta(reg_obj.hwEta);
global_objects.back().hwPhi = region.hwGlbPhi(reg_obj.hwPhi);
}
}

template <typename T>
void resize_input(std::vector<T>& in) const {
if (in.size() > nObjToSort_) {
in.resize(nObjToSort_);
} else if (in.size() < nObjToSort_) {
for (unsigned int i = 0, diff = (nObjToSort_ - in.size()); i < diff; ++i) {
in.push_back(T());
in.back().clear();
}
}
}

template <typename T>
void merge_regions(const std::vector<T>& in_region1,
const std::vector<T>& in_region2,
std::vector<T>& out,
unsigned int nOut) const {
// we crate a bitonic list
out = in_region1;
if (debug_)
for (const auto& tmp : out)
dbgCout() << "out " << tmp.hwPt << " " << tmp.hwEta << " " << tmp.hwPhi << "\n";
std::reverse(out.begin(), out.end());
if (debug_)
for (const auto& tmp : out)
dbgCout() << "out reverse " << tmp.hwPt << " " << tmp.hwEta << " " << tmp.hwPhi << "\n";
std::copy(in_region2.begin(), in_region2.end(), std::back_inserter(out));
if (debug_)
for (const auto& tmp : out)
dbgCout() << "out inserted " << tmp.hwPt << " " << tmp.hwEta << " " << tmp.hwPhi << "\n";

hybridBitonicMergeRef(&out[0], out.size(), 0, false);

if (out.size() > nOut) {
out.resize(nOut);
if (debug_)
for (const auto& tmp : out)
dbgCout() << "final " << tmp.hwPt << " " << tmp.hwEta << " " << tmp.hwPhi << "\n";
}
}

template <typename T>
void merge(const std::vector<std::vector<T>>& in_objs, std::vector<T>& out) const {
unsigned int nregions = in_objs.size();
std::vector<T> pair_merge(nObjSorted_);
if (nregions == 18) { // merge pairs, and accumulate pairs
for (unsigned int i = 0; i < nregions; i += 2) {
merge_regions(in_objs[i + 0], in_objs[i + 1], pair_merge, nObjSorted_);
if (i == 0)
out = pair_merge;
else
merge_regions(out, pair_merge, out, nObjSorted_);
}
} else if (nregions == 9) { // simple accumulation
for (unsigned int i = 0; i < nregions; ++i) {
for (unsigned int j = 0, nj = in_objs[i].size(); j < nObjSorted_; ++j) {
if (j < nj)
pair_merge[j] = in_objs[i][j];
else
pair_merge[j].clear();
}
if (i == 0)
out = pair_merge;
else
merge_regions(out, pair_merge, out, nObjSorted_);
}
} else
throw std::runtime_error("This sorter requires 18 or 9 regions");
}
};
} // namespace l1ct

#endif
25 changes: 17 additions & 8 deletions L1Trigger/Phase2L1ParticleFlow/interface/egamma/pftkegsorter_ref.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef FIRMWARE_PFTKEGSORTER_REF_H
#define FIRMWARE_PFTKEGSORTER_REF_H
#ifndef L1Trigger_Phase2L1ParticleFlow_egamma_pftkegsorter_ref_h
#define L1Trigger_Phase2L1ParticleFlow_egamma_pftkegsorter_ref_h

#include <cstdio>
#include <vector>
Expand All @@ -11,10 +11,6 @@
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#endif

namespace edm {
class ParameterSet;
}

namespace l1ct {
class PFTkEGSorterEmulator {
public:
Expand All @@ -28,10 +24,23 @@ namespace l1ct {

#endif

~PFTkEGSorterEmulator(){};
virtual ~PFTkEGSorterEmulator() {}

void setDebug(bool debug = true) { debug_ = debug; };

virtual void runPho(const std::vector<l1ct::PFInputRegion>& pfregions,
const std::vector<l1ct::OutputRegion>& outregions,
const std::vector<unsigned int>& region_index,
std::vector<l1ct::EGIsoObjEmu>& eg_sorted_inBoard) {
run<l1ct::EGIsoObjEmu>(pfregions, outregions, region_index, eg_sorted_inBoard);
}
virtual void runEle(const std::vector<l1ct::PFInputRegion>& pfregions,
const std::vector<l1ct::OutputRegion>& outregions,
const std::vector<unsigned int>& region_index,
std::vector<l1ct::EGIsoEleObjEmu>& eg_sorted_inBoard) {
run<l1ct::EGIsoEleObjEmu>(pfregions, outregions, region_index, eg_sorted_inBoard);
}

template <typename T>
void run(const std::vector<l1ct::PFInputRegion>& pfregions,
const std::vector<l1ct::OutputRegion>& outregions,
Expand Down Expand Up @@ -64,7 +73,7 @@ namespace l1ct {
}
}

private:
protected:
unsigned int nObjToSort_, nObjSorted_;
bool debug_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
#include <cassert>
#include <algorithm>

#ifdef CMSSW_GIT_HASH
#include "L1Trigger/Phase2L1ParticleFlow/interface/dbgPrintf.h"
#else
#include "../../utils/dbgPrintf.h"
#endif

namespace l1ct {
namespace tdr_regionizer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "L1Trigger/Phase2L1ParticleFlow/interface/egamma/pftkegalgo_ref.h"
#include "L1Trigger/Phase2L1ParticleFlow/interface/pf/pfalgo_common_ref.h"
#include "L1Trigger/Phase2L1ParticleFlow/interface/egamma/pftkegsorter_ref.h"
#include "L1Trigger/Phase2L1ParticleFlow/interface/egamma/pftkegsorter_barrel_ref.h"
#include "L1Trigger/Phase2L1ParticleFlow/interface/L1TCorrelatorLayer1PatternFileWriter.h"

#include "DataFormats/L1TCorrelator/interface/TkElectron.h"
Expand Down Expand Up @@ -278,8 +279,15 @@ L1TCorrelatorLayer1Producer::L1TCorrelatorLayer1Producer(const edm::ParameterSet
l1tkegalgo_ = std::make_unique<l1ct::PFTkEGAlgoEmulator>(
l1ct::PFTkEGAlgoEmuConfig(iConfig.getParameter<edm::ParameterSet>("tkEgAlgoParameters")));

l1tkegsorter_ =
std::make_unique<l1ct::PFTkEGSorterEmulator>(iConfig.getParameter<edm::ParameterSet>("tkEgSorterParameters"));
const std::string &egsortalgo = iConfig.getParameter<std::string>("tkEgSorterAlgo");
if (egsortalgo == "Barrel") {
l1tkegsorter_ = std::make_unique<l1ct::PFTkEGSorterBarrelEmulator>(
iConfig.getParameter<edm::ParameterSet>("tkEgSorterParameters"));
} else if (egsortalgo == "Endcap") {
l1tkegsorter_ =
std::make_unique<l1ct::PFTkEGSorterEmulator>(iConfig.getParameter<edm::ParameterSet>("tkEgSorterParameters"));
} else
throw cms::Exception("Configuration", "Unsupported tkEgSorterAlgo");

if (l1tkegalgo_->writeEgSta())
produces<BXVector<l1t::EGamma>>("L1Eg");
Expand Down Expand Up @@ -482,8 +490,8 @@ void L1TCorrelatorLayer1Producer::produce(edm::Event &iEvent, const edm::EventSe

// l1tkegsorter_->setDebug(true);
for (auto &board : event_.board_out) {
l1tkegsorter_->run(event_.pfinputs, event_.out, board.region_index, board.egphoton);
l1tkegsorter_->run(event_.pfinputs, event_.out, board.region_index, board.egelectron);
l1tkegsorter_->runPho(event_.pfinputs, event_.out, board.region_index, board.egphoton);
l1tkegsorter_->runEle(event_.pfinputs, event_.out, board.region_index, board.egelectron);
}

// save PF into the event
Expand Down
4 changes: 4 additions & 0 deletions L1Trigger/Phase2L1ParticleFlow/python/l1ctLayer1_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
nEMCALO_EGIN = 10,
nEM_EGOUT = 10,
),
tkEgSorterAlgo = cms.string("Barrel"),
tkEgSorterParameters=tkEgSorterParameters.clone(
nObjToSort = 10
),
Expand Down Expand Up @@ -271,6 +272,7 @@
writeEGSta=True,
doCompositeTkEle=True,
trkQualityPtMin=0.), # This should be 10 GeV when doCompositeTkEle=False
tkEgSorterAlgo = cms.string("Endcap"),
tkEgSorterParameters=tkEgSorterParameters.clone(
nObjToSort = 5
),
Expand Down Expand Up @@ -368,6 +370,7 @@
doEndcapHwQual=True,
writeBeforeBremRecovery=False,
writeEGSta=True),
tkEgSorterAlgo = cms.string("Endcap"),
tkEgSorterParameters=tkEgSorterParameters.clone(
nObjToSort=5
),
Expand Down Expand Up @@ -452,6 +455,7 @@
nEM_EGOUT = 5, # to be defined
doBremRecovery=True,
writeEGSta=True),
tkEgSorterAlgo = cms.string("Endcap"),
tkEgSorterParameters=tkEgSorterParameters.clone(),
caloSectors = cms.VPSet(
cms.PSet(
Expand Down
10 changes: 10 additions & 0 deletions L1Trigger/Phase2L1ParticleFlow/src/egamma/pftkegalgo_ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ void PFTkEGAlgoEmulator::link_emCalo2tk_elliptic(const PFRegionEmu &r,
float dEtaMax = cfg.dEtaValues[eta_index];
float dPhiMax = cfg.dPhiValues[eta_index];

if (debug_ > 2 && calo.hwPt > 0) {
dbgCout() << "[REF] tried to link calo " << ic << " (pt " << calo.intPt() << ", eta " << calo.intEta()
<< ", phi " << calo.intPhi() << ") "
<< " to tk " << itk << " (pt " << tk.intPt() << ", eta " << tk.intEta() << ", phi " << tk.intPhi()
<< "): "
<< " eta_index " << eta_index << ", "
<< " dEta " << d_eta << " (max " << dEtaMax << "), dPhi " << d_phi << " (max " << dPhiMax << ") "
<< " ellipse = "
<< (((d_phi / dPhiMax) * (d_phi / dPhiMax)) + ((d_eta / dEtaMax) * (d_eta / dEtaMax))) << "\n";
}
if ((((d_phi / dPhiMax) * (d_phi / dPhiMax)) + ((d_eta / dEtaMax) * (d_eta / dEtaMax))) < 1.) {
// NOTE: for now we implement only best pt match. This is NOT what is done in the L1TkElectronTrackProducer
if (fabs(tk.floatPt() - calo.floatPt()) < dPtMin) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@
from L1Trigger.Phase2L1GMT.gmt_cfi import l1tStandaloneMuons
process.l1tSAMuonsGmt = l1tStandaloneMuons.clone()

process.l1tLayer1BarrelSerenity = process.l1tLayer1Barrel.clone()
process.l1tLayer1BarrelSerenity.regionizerAlgo = "MultififoBarrel"
process.l1tLayer1BarrelSerenity.regionizerAlgoParameters = cms.PSet(
barrelSetup = cms.string("Full54"),
useAlsoVtxCoords = cms.bool(True),
nClocks = cms.uint32(54),
nHCalLinks = cms.uint32(2),
nECalLinks = cms.uint32(1),
nTrack = cms.uint32(22),
nCalo = cms.uint32(15),
nEmCalo = cms.uint32(12),
nMu = cms.uint32(2))
process.l1tLayer1BarrelSerenity.pfAlgoParameters.nTrack = 22
process.l1tLayer1BarrelSerenity.pfAlgoParameters.nSelCalo = 15
process.l1tLayer1BarrelSerenity.pfAlgoParameters.nCalo = 15
process.l1tLayer1BarrelSerenity.pfAlgoParameters.nAllNeutral = 27
process.l1tLayer1BarrelSerenity.puAlgoParameters.nTrack = 22
process.l1tLayer1BarrelSerenity.puAlgoParameters.nIn = 27
process.l1tLayer1BarrelSerenity.puAlgoParameters.nOut = 27
process.l1tLayer1BarrelSerenity.puAlgoParameters.finalSortAlgo = "FoldedHybrid"


process.l1tLayer1Barrel9 = process.l1tLayer1Barrel.clone()
process.l1tLayer1Barrel9.puAlgo.nFinalSort = 32
process.l1tLayer1Barrel9.regions[0].etaBoundaries = [ -1.5, -0.5, 0.5, 1.5 ]
Expand All @@ -55,6 +77,7 @@
process.l1tGTTInputProducer +
process.l1tVertexFinderEmulator +
process.l1tLayer1Barrel +
process.l1tLayer1BarrelSerenity +
process.l1tLayer1Barrel9 +
process.l1tLayer1HGCal +
process.l1tLayer1HGCalNoTK +
Expand All @@ -63,7 +86,7 @@
process.runPF.associate(process.L1TLayer1TaskInputsTask)


for det in "Barrel", "Barrel9", "HGCal", "HGCalNoTK", "HF":
for det in "Barrel", "BarrelSerenity", "Barrel9", "HGCal", "HGCalNoTK", "HF":
l1pf = getattr(process, 'l1tLayer1'+det)
l1pf.dumpFileName = cms.untracked.string("TTbar_PU200_"+det+".dump")

Expand Down
Loading