Skip to content

Commit

Permalink
Merge pull request #32474 from trtomei/PR-111X-HLTL1TPlugins
Browse files Browse the repository at this point in the history
Plugins for Phase-2 L1T-HLT (11.1.x backport)
  • Loading branch information
cmsbuild committed Dec 16, 2020
2 parents f0be962 + 6904485 commit 04f93c2
Show file tree
Hide file tree
Showing 19 changed files with 1,763 additions and 53 deletions.
197 changes: 197 additions & 0 deletions HLTrigger/HLTfilters/plugins/HLTDoubletDZ.cc
Expand Up @@ -13,6 +13,11 @@
#include "DataFormats/EgammaCandidates/interface/ElectronFwd.h"
#include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
#include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
#include "DataFormats/L1TCorrelator/interface/TkMuon.h"
#include "DataFormats/L1TCorrelator/interface/TkMuonFwd.h"
#include "DataFormats/L1TParticleFlow/interface/PFTau.h"
#include "DataFormats/L1TParticleFlow/interface/HPSPFTau.h"
#include "DataFormats/L1TParticleFlow/interface/HPSPFTauFwd.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "FWCore/Framework/interface/MakerMacros.h"
Expand Down Expand Up @@ -125,6 +130,25 @@ HLTDoubletDZ<reco::RecoChargedCandidate, reco::RecoChargedCandidate>::HLTDoublet
same_(inputTag1_.encode() == inputTag2_.encode()) // same collections to be compared?
{}

template <>
HLTDoubletDZ<l1t::TkMuon, l1t::TkMuon>::HLTDoubletDZ(const edm::ParameterSet& iConfig)
: HLTFilter(iConfig),
originTag1_(iConfig.template getParameter<std::vector<edm::InputTag>>("originTag1")),
originTag2_(iConfig.template getParameter<std::vector<edm::InputTag>>("originTag2")),
inputTag1_(iConfig.template getParameter<edm::InputTag>("inputTag1")),
inputTag2_(iConfig.template getParameter<edm::InputTag>("inputTag2")),
inputToken1_(consumes<trigger::TriggerFilterObjectWithRefs>(inputTag1_)),
inputToken2_(consumes<trigger::TriggerFilterObjectWithRefs>(inputTag2_)),
triggerType1_(iConfig.template getParameter<int>("triggerType1")),
triggerType2_(iConfig.template getParameter<int>("triggerType2")),
minDR_(iConfig.template getParameter<double>("MinDR")),
maxDZ_(iConfig.template getParameter<double>("MaxDZ")),
minPixHitsForDZ_(iConfig.template getParameter<int>("MinPixHitsForDZ")),
min_N_(iConfig.template getParameter<int>("MinN")),
checkSC_(iConfig.template getParameter<bool>("checkSC")),
same_(inputTag1_.encode() == inputTag2_.encode()) // same collections to be compared?
{}

template <typename T1, typename T2>
HLTDoubletDZ<T1, T2>::~HLTDoubletDZ() {}

Expand Down Expand Up @@ -404,6 +428,41 @@ bool HLTDoubletDZ<reco::RecoChargedCandidate, reco::RecoChargedCandidate>::compu
return true;
}

template <>
bool HLTDoubletDZ<l1t::TkMuon, l1t::TkMuon>::computeDZ(edm::Event& iEvent,
l1t::TkMuonRef& r1,
l1t::TkMuonRef& r2) const {
const l1t::TkMuon& candidate1(*r1);
const l1t::TkMuon& candidate2(*r2);
if (reco::deltaR(candidate1, candidate2) < minDR_)
return false;

// We don't care about minPixHitsForDZ_ with the L1TkMuons,
// especially because the pixel does not participate in the L1T
if (std::abs(candidate1.trkzVtx() - candidate2.trkzVtx()) > maxDZ_)
return false;

return true;
}

template <>
bool HLTDoubletDZ<l1t::HPSPFTau, l1t::HPSPFTau>::computeDZ(edm::Event& iEvent,
l1t::HPSPFTauRef& r1,
l1t::HPSPFTauRef& r2) const {
const l1t::HPSPFTau& candidate1(*r1);
const l1t::HPSPFTau& candidate2(*r2);
if (reco::deltaR(candidate1, candidate2) < minDR_)
return false;

// We don't care about minPixHitsForDZ_ with the L1HPSPFTaus,
// especially because the pixel does not participate in the L1T
if (std::abs(candidate1.leadChargedPFCand()->pfTrack()->vertex().z() -
candidate2.leadChargedPFCand()->pfTrack()->vertex().z()) > maxDZ_)
return false;

return true;
}

// ------------ method called to produce the data ------------
template <typename T1, typename T2>
bool HLTDoubletDZ<T1, T2>::hltFilter(edm::Event& iEvent,
Expand Down Expand Up @@ -453,16 +512,154 @@ bool HLTDoubletDZ<T1, T2>::hltFilter(edm::Event& iEvent,
return accept;
}

/// Special instantiation for L1TkMuon
/// L1TkMuon are *not* RecoCandidates, therefore they don't implement superCluster()
/// They are LeafCandidates instead
template <>
bool HLTDoubletDZ<l1t::TkMuon, l1t::TkMuon>::hltFilter(edm::Event& iEvent,
const edm::EventSetup& iSetup,
trigger::TriggerFilterObjectWithRefs& filterproduct) const {
// All HLT filters must create and fill an HLT filter object,
// recording any reconstructed physics objects satisfying (or not)
// this HLT filter, and place it in the Event.
bool accept(false);

std::vector<l1t::TkMuonRef> coll1;
std::vector<l1t::TkMuonRef> coll2;

if (getCollections(iEvent, coll1, coll2, filterproduct)) {
int n(0);
l1t::TkMuonRef r1;
l1t::TkMuonRef r2;

for (unsigned int i1 = 0; i1 != coll1.size(); i1++) {
r1 = coll1[i1];
unsigned int I(0);
if (same_) {
I = i1 + 1;
}
for (unsigned int i2 = I; i2 != coll2.size(); i2++) {
r2 = coll2[i2];

if (!computeDZ(iEvent, r1, r2))
continue;

n++;
filterproduct.addObject(triggerType1_, r1);
filterproduct.addObject(triggerType2_, r2);
}
}

accept = accept || (n >= min_N_);
}

return accept;
}

/// Special instantiation for L1PFTau
/// L1PFTau are *not* RecoCandidates, therefore they don't implement superCluster()
/// They are LeafCandidates instead
template <>
bool HLTDoubletDZ<l1t::PFTau, l1t::PFTau>::hltFilter(edm::Event& iEvent,
const edm::EventSetup& iSetup,
trigger::TriggerFilterObjectWithRefs& filterproduct) const {
// All HLT filters must create and fill an HLT filter object,
// recording any reconstructed physics objects satisfying (or not)
// this HLT filter, and place it in the Event.
bool accept(false);

std::vector<l1t::PFTauRef> coll1;
std::vector<l1t::PFTauRef> coll2;

if (getCollections(iEvent, coll1, coll2, filterproduct)) {
int n(0);
l1t::PFTauRef r1;
l1t::PFTauRef r2;

for (unsigned int i1 = 0; i1 != coll1.size(); i1++) {
r1 = coll1[i1];
unsigned int I(0);
if (same_) {
I = i1 + 1;
}
for (unsigned int i2 = I; i2 != coll2.size(); i2++) {
r2 = coll2[i2];

if (!computeDZ(iEvent, r1, r2))
continue;

n++;
filterproduct.addObject(triggerType1_, r1);
filterproduct.addObject(triggerType2_, r2);
}
}

accept = accept || (n >= min_N_);
}

return accept;
}

/// Special instantiation for L1HPSPFTau
/// L1HPSPFTau are *not* RecoCandidates, therefore they don't implement superCluster()
/// They are LeafCandidates instead
template <>
bool HLTDoubletDZ<l1t::HPSPFTau, l1t::HPSPFTau>::hltFilter(edm::Event& iEvent,
const edm::EventSetup& iSetup,
trigger::TriggerFilterObjectWithRefs& filterproduct) const {
// All HLT filters must create and fill an HLT filter object,
// recording any reconstructed physics objects satisfying (or not)
// this HLT filter, and place it in the Event.
bool accept(false);

std::vector<l1t::HPSPFTauRef> coll1;
std::vector<l1t::HPSPFTauRef> coll2;

if (getCollections(iEvent, coll1, coll2, filterproduct)) {
int n(0);
l1t::HPSPFTauRef r1;
l1t::HPSPFTauRef r2;

for (unsigned int i1 = 0; i1 != coll1.size(); i1++) {
r1 = coll1[i1];
unsigned int I(0);
if (same_) {
I = i1 + 1;
}
for (unsigned int i2 = I; i2 != coll2.size(); i2++) {
r2 = coll2[i2];

if (!computeDZ(iEvent, r1, r2))
continue;

n++;
filterproduct.addObject(triggerType1_, r1);
filterproduct.addObject(triggerType2_, r2);
}
}

accept = accept || (n >= min_N_);
}

return accept;
}

typedef HLTDoubletDZ<reco::Electron, reco::Electron> HLT2ElectronElectronDZ;
typedef HLTDoubletDZ<reco::RecoChargedCandidate, reco::RecoChargedCandidate> HLT2MuonMuonDZ;
typedef HLTDoubletDZ<reco::Electron, reco::RecoChargedCandidate> HLT2ElectronMuonDZ;
typedef HLTDoubletDZ<reco::RecoEcalCandidate, reco::RecoEcalCandidate> HLT2PhotonPhotonDZ;
typedef HLTDoubletDZ<reco::RecoChargedCandidate, reco::RecoEcalCandidate> HLT2MuonPhotonDZ;
typedef HLTDoubletDZ<reco::RecoEcalCandidate, reco::RecoChargedCandidate> HLT2PhotonMuonDZ;
typedef HLTDoubletDZ<l1t::TkMuon, l1t::TkMuon> HLT2L1TkMuonL1TkMuonDZ;
typedef HLTDoubletDZ<l1t::PFTau, l1t::PFTau> HLT2L1PFTauL1PFTauDZ;
typedef HLTDoubletDZ<l1t::HPSPFTau, l1t::HPSPFTau> HLT2L1HPSPFTauL1HPSPFTauDZ;

DEFINE_FWK_MODULE(HLT2ElectronElectronDZ);
DEFINE_FWK_MODULE(HLT2MuonMuonDZ);
DEFINE_FWK_MODULE(HLT2ElectronMuonDZ);
DEFINE_FWK_MODULE(HLT2PhotonPhotonDZ);
DEFINE_FWK_MODULE(HLT2PhotonMuonDZ);
DEFINE_FWK_MODULE(HLT2MuonPhotonDZ);
DEFINE_FWK_MODULE(HLT2L1TkMuonL1TkMuonDZ);
DEFINE_FWK_MODULE(HLT2L1PFTauL1PFTauDZ);
DEFINE_FWK_MODULE(HLT2L1HPSPFTauL1HPSPFTauDZ);
132 changes: 132 additions & 0 deletions HLTrigger/HLTfilters/plugins/L1TEnergySumFilterT.h
@@ -0,0 +1,132 @@
#ifndef HLTrigger_HLTfilters_L1TEnergySumFilterT_h
#define HLTrigger_HLTfilters_L1TEnergySumFilterT_h

#include <vector>
#include <iterator>

#include "DataFormats/Common/interface/Ref.h"
#include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
#include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "HLTrigger/HLTcore/interface/HLTFilter.h"
#include "HLTrigger/HLTcore/interface/defaultModuleLabel.h"

template <typename T>
class L1TEnergySumFilterT : public HLTFilter {
public:
explicit L1TEnergySumFilterT(const edm::ParameterSet&);
~L1TEnergySumFilterT() override;
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
bool hltFilter(edm::Event&,
edm::EventSetup const&,
trigger::TriggerFilterObjectWithRefs& filterproduct) const override;

private:
edm::InputTag const l1tSumTag_;
edm::EDGetTokenT<std::vector<T>> const l1tSumToken_;

trigger::TriggerObjectType const l1tSumType_;
double const minPt_;

edm::ParameterSet scalings_;
std::vector<double> theScalings_;

static trigger::TriggerObjectType typeOfL1TSum(std::string const&);

double offlineEnergySum(double const Et) const;
};

template <typename T>
L1TEnergySumFilterT<T>::L1TEnergySumFilterT(const edm::ParameterSet& iConfig)
: HLTFilter(iConfig),
l1tSumTag_(iConfig.getParameter<edm::InputTag>("inputTag")),
l1tSumToken_(consumes<std::vector<T>>(l1tSumTag_)),
l1tSumType_(typeOfL1TSum(iConfig.getParameter<std::string>("TypeOfSum"))),
minPt_(iConfig.getParameter<double>("MinPt")) {
scalings_ = iConfig.getParameter<edm::ParameterSet>("Scalings");
theScalings_ = scalings_.getParameter<std::vector<double>>("theScalings");
}

template <typename T>
L1TEnergySumFilterT<T>::~L1TEnergySumFilterT() = default;

template <typename T>
trigger::TriggerObjectType L1TEnergySumFilterT<T>::typeOfL1TSum(std::string const& typeOfSum) {
trigger::TriggerObjectType sumEnum;

if (typeOfSum == "MET")
sumEnum = trigger::TriggerObjectType::TriggerL1PFMET;
else if (typeOfSum == "ETT")
sumEnum = trigger::TriggerObjectType::TriggerL1PFETT;
else if (typeOfSum == "HT")
sumEnum = trigger::TriggerObjectType::TriggerL1PFHT;
else if (typeOfSum == "MHT")
sumEnum = trigger::TriggerObjectType::TriggerL1PFMHT;
else {
throw cms::Exception("ConfigurationError")
<< "Wrong type of energy sum: \"" << typeOfSum << "\" (valid choices are: MET, ETT, HT, MHT)";
}

return sumEnum;
}

template <typename T>
void L1TEnergySumFilterT<T>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
makeHLTFilterDescription(desc);
desc.add<edm::InputTag>("inputTag", edm::InputTag("L1PFEnergySums"));

edm::ParameterSetDescription descScalings;
descScalings.add<std::vector<double>>("theScalings", {0.0, 1.0, 0.0});
desc.add<edm::ParameterSetDescription>("Scalings", descScalings);

desc.add<std::string>("TypeOfSum", "HT");
desc.add<double>("MinPt", -1.);
descriptions.add(defaultModuleLabel<L1TEnergySumFilterT<T>>(), desc);
}

template <typename T>
bool L1TEnergySumFilterT<T>::hltFilter(edm::Event& iEvent,
edm::EventSetup const& iSetup,
trigger::TriggerFilterObjectWithRefs& filterproduct) const {
// All HLT filters must create and fill an HLT filter object,
// recording any reconstructed physics objects satisfying (or not)
// this HLT filter, and place it in the Event.

// The filter object
if (saveTags()) {
filterproduct.addCollectionTag(l1tSumTag_);
}

auto const& l1tSums = iEvent.getHandle(l1tSumToken_);

int nSum(0);
for (auto iSum = l1tSums->begin(); iSum != l1tSums->end(); ++iSum) {
double offlinePt = 0.0;
// pt or sumEt?
if (l1tSumType_ == trigger::TriggerObjectType::TriggerL1PFMET or
l1tSumType_ == trigger::TriggerObjectType::TriggerL1PFMHT) {
offlinePt = offlineEnergySum(iSum->pt());
} else if (l1tSumType_ == trigger::TriggerObjectType::TriggerL1PFETT or
l1tSumType_ == trigger::TriggerObjectType::TriggerL1PFHT) {
offlinePt = offlineEnergySum(iSum->sumEt());
}

if (offlinePt >= minPt_) {
++nSum;
edm::Ref<std::vector<T>> ref(l1tSums, std::distance(l1tSums->begin(), iSum));
filterproduct.addObject(l1tSumType_, ref);
}
}

// return final filter decision
return nSum > 0;
}

template <typename T>
double L1TEnergySumFilterT<T>::offlineEnergySum(double const Et) const {
return (theScalings_.at(0) + Et * theScalings_.at(1) + Et * Et * theScalings_.at(2));
}

#endif // HLTrigger_HLTfilters_L1TEnergySumFilterT_h

0 comments on commit 04f93c2

Please sign in to comment.