Skip to content

Commit

Permalink
Merge pull request #41100 from perrotta/reduceSqrtInHltProducers
Browse files Browse the repository at this point in the history
Reduce non necessary sqrt computations in RecoTauTag/HLTProducers
  • Loading branch information
cmsbuild authored Mar 21, 2023
2 parents c355de4 + b8b0a9e commit 9a02541
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 106 deletions.
6 changes: 2 additions & 4 deletions RecoTauTag/HLTProducers/interface/CaloTowerCreatorForTauHLT.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CaloTowerCreatorForTauHLT : public edm::global::EDProducer<> {
/// constructor from parameter set
CaloTowerCreatorForTauHLT(const edm::ParameterSet&);
/// destructor
~CaloTowerCreatorForTauHLT() override;
~CaloTowerCreatorForTauHLT() override = default;
///
static void fillDescriptions(edm::ConfigurationDescriptions& desc);

Expand All @@ -47,11 +47,9 @@ class CaloTowerCreatorForTauHLT : public edm::global::EDProducer<> {
/// label of source collection
const edm::EDGetTokenT<CaloTowerCollection> mtowers_token;
/// use only towers in cone mCone around L1 candidate for regional jet reco
const double mCone;
const double mCone, mCone2;
/// label of tau trigger type analysis
const edm::EDGetTokenT<l1extra::L1JetParticleCollection> mTauTrigger_token;
/// imitator of L1 seeds
//edm::InputTag ml1seeds;
/// ET threshold
const double mEtThreshold;
/// E threshold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CaloTowerFromL1TCreatorForTauHLT : public edm::global::EDProducer<> {
/// constructor from parameter set
CaloTowerFromL1TCreatorForTauHLT(const edm::ParameterSet&);
/// destructor
~CaloTowerFromL1TCreatorForTauHLT() override;
~CaloTowerFromL1TCreatorForTauHLT() override = default;
///
static void fillDescriptions(edm::ConfigurationDescriptions& desc);

Expand All @@ -48,11 +48,9 @@ class CaloTowerFromL1TCreatorForTauHLT : public edm::global::EDProducer<> {
/// label of source collection
const edm::EDGetTokenT<CaloTowerCollection> mtowers_token;
/// use only towers in cone mCone around L1 candidate for regional jet reco
const double mCone;
const double mCone, mCone2;
/// label of tau trigger type analysis
const edm::EDGetTokenT<l1t::TauBxCollection> mTauTrigger_token;
/// imitator of L1 seeds
//edm::InputTag ml1seeds;
/// ET threshold
const double mEtThreshold;
/// E threshold
Expand Down
8 changes: 2 additions & 6 deletions RecoTauTag/HLTProducers/interface/L1HLTJetsMatching.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
#include "FWCore/Framework/interface/global/EDProducer.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/L1Trigger/interface/L1JetParticle.h"
#include "DataFormats/L1Trigger/interface/L1JetParticleFwd.h"
#include "DataFormats/JetReco/interface/CaloJetCollection.h"
#include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"

#include <map>
Expand All @@ -20,7 +16,7 @@
class L1HLTJetsMatching : public edm::global::EDProducer<> {
public:
explicit L1HLTJetsMatching(const edm::ParameterSet&);
~L1HLTJetsMatching() override;
~L1HLTJetsMatching() override = default;
void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;

private:
Expand Down
9 changes: 2 additions & 7 deletions RecoTauTag/HLTProducers/interface/L1HLTTauMatching.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/L1Trigger/interface/L1JetParticle.h"
#include "DataFormats/L1Trigger/interface/L1JetParticleFwd.h"
#include "DataFormats/JetReco/interface/CaloJetCollection.h"
#include "DataFormats/TauReco/interface/PFTauFwd.h"
#include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"

Expand All @@ -21,7 +16,7 @@
class L1HLTTauMatching : public edm::global::EDProducer<> {
public:
explicit L1HLTTauMatching(const edm::ParameterSet&);
~L1HLTTauMatching() override;
~L1HLTTauMatching() override = default;
void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

Expand Down
11 changes: 3 additions & 8 deletions RecoTauTag/HLTProducers/interface/L1THLTTauMatching.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@
// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/L1Trigger/interface/Tau.h"
#include "DataFormats/JetReco/interface/CaloJetCollection.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "DataFormats/TauReco/interface/PFTauFwd.h"
#include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"

Expand All @@ -20,7 +15,7 @@
class L1THLTTauMatching : public edm::global::EDProducer<> {
public:
explicit L1THLTTauMatching(const edm::ParameterSet&);
~L1THLTTauMatching() override;
~L1THLTTauMatching() override = default;
void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

Expand Down
38 changes: 18 additions & 20 deletions RecoTauTag/HLTProducers/interface/L1TJetsMatching.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,22 @@ template <typename T>
class L1TJetsMatching : public edm::global::EDProducer<> {
public:
explicit L1TJetsMatching(const edm::ParameterSet&);
~L1TJetsMatching() override;
~L1TJetsMatching() override = default;
void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
std::pair<std::vector<T>, std::vector<T>> categorise(
const std::vector<T>& pfMatchedJets, double pt1, double pt2, double pt3, double Mjj) const;
std::tuple<std::vector<T>, std::vector<T>, std::vector<T>> categoriseVBFPlus2CentralJets(
const std::vector<T>& pfMatchedJets, double pt1, double pt2, double pt3, double Mjj) const;

private:
const edm::EDGetTokenT<std::vector<T>> jetSrc_;
const edm::EDGetTokenT<trigger::TriggerFilterObjectWithRefs> jetTrigger_;
const std::string matchingMode_;
const double pt1Min_;
const double pt2Min_;
const double pt3Min_;
const double mjjMin_;
const double matchingR_;
const double matchingR2_;
};
//
Expand All @@ -80,18 +79,18 @@ std::pair<std::vector<T>, std::vector<T>> L1TJetsMatching<T>::categorise(
std::pair<std::vector<T>, std::vector<T>> output;
unsigned int i1 = 0;
unsigned int i2 = 0;
double mjj = 0;
double m2jj = 0;
if (pfMatchedJets.size() > 1) {
for (unsigned int i = 0; i < pfMatchedJets.size() - 1; i++) {
const T& myJet1 = (pfMatchedJets)[i];

for (unsigned int j = i + 1; j < pfMatchedJets.size(); j++) {
const T& myJet2 = (pfMatchedJets)[j];

const double mjj_test = (myJet1.p4() + myJet2.p4()).M();
const double m2jj_test = (myJet1.p4() + myJet2.p4()).M2();

if (mjj_test > mjj) {
mjj = mjj_test;
if (m2jj_test > m2jj) {
m2jj = m2jj_test;
i1 = i;
i2 = j;
}
Expand All @@ -100,13 +99,14 @@ std::pair<std::vector<T>, std::vector<T>> L1TJetsMatching<T>::categorise(

const T& myJet1 = (pfMatchedJets)[i1];
const T& myJet2 = (pfMatchedJets)[i2];
const double M2jj = (Mjj >= 0. ? Mjj * Mjj : -1.);

if ((mjj > Mjj) && (myJet1.pt() >= pt1) && (myJet2.pt() > pt2)) {
if ((m2jj > M2jj) && (myJet1.pt() >= pt1) && (myJet2.pt() > pt2)) {
output.first.push_back(myJet1);
output.first.push_back(myJet2);
}

if ((mjj > Mjj) && (myJet1.pt() < pt3) && (myJet1.pt() > pt2) && (myJet2.pt() > pt2)) {
if ((m2jj > M2jj) && (myJet1.pt() < pt3) && (myJet1.pt() > pt2) && (myJet2.pt() > pt2)) {
const T& myJetTest = (pfMatchedJets)[0];
if (myJetTest.pt() > pt3) {
output.second.push_back(myJet1);
Expand All @@ -125,18 +125,18 @@ std::tuple<std::vector<T>, std::vector<T>, std::vector<T>> L1TJetsMatching<T>::c
unsigned int i1 = 0;
unsigned int i2 = 0;

double mjj = 0;
double m2jj = 0;
if (pfMatchedJets.size() > 1) {
for (unsigned int i = 0; i < pfMatchedJets.size() - 1; i++) {
const T& myJet1 = (pfMatchedJets)[i];

for (unsigned int j = i + 1; j < pfMatchedJets.size(); j++) {
const T& myJet2 = (pfMatchedJets)[j];

const double mjj_test = (myJet1.p4() + myJet2.p4()).M();
const double m2jj_test = (myJet1.p4() + myJet2.p4()).M2();

if (mjj_test > mjj) {
mjj = mjj_test;
if (m2jj_test > m2jj) {
m2jj = m2jj_test;
i1 = i;
i2 = j;
}
Expand All @@ -145,6 +145,7 @@ std::tuple<std::vector<T>, std::vector<T>, std::vector<T>> L1TJetsMatching<T>::c

const T& myJet1 = (pfMatchedJets)[i1];
const T& myJet2 = (pfMatchedJets)[i2];
const double M2jj = (Mjj >= 0. ? Mjj * Mjj : -1.);

std::vector<T> vec4jets;
vec4jets.reserve(4);
Expand All @@ -153,7 +154,7 @@ std::tuple<std::vector<T>, std::vector<T>, std::vector<T>> L1TJetsMatching<T>::c
std::vector<T> vec6jets;
vec6jets.reserve(6);
if (pfMatchedJets.size() > 3) {
if ((mjj > Mjj) && (myJet1.pt() >= pt3) && (myJet2.pt() > pt2)) {
if ((m2jj > M2jj) && (myJet1.pt() >= pt3) && (myJet2.pt() > pt2)) {
vec4jets.push_back(myJet1);
vec4jets.push_back(myJet2);

Expand All @@ -166,7 +167,7 @@ std::tuple<std::vector<T>, std::vector<T>, std::vector<T>> L1TJetsMatching<T>::c
}
}

if ((mjj > Mjj) && (myJet1.pt() < pt1) && (myJet1.pt() < pt3) && (myJet1.pt() > pt2) &&
if ((m2jj > M2jj) && (myJet1.pt() < pt1) && (myJet1.pt() < pt3) && (myJet1.pt() > pt2) &&
(myJet2.pt() > pt2)) { //60, 30, 50, 500

std::vector<unsigned int> idx_jets;
Expand Down Expand Up @@ -212,8 +213,7 @@ L1TJetsMatching<T>::L1TJetsMatching(const edm::ParameterSet& iConfig)
pt2Min_(iConfig.getParameter<double>("pt2Min")),
pt3Min_(iConfig.getParameter<double>("pt3Min")),
mjjMin_(iConfig.getParameter<double>("mjjMin")),
matchingR_(iConfig.getParameter<double>("matchingR")),
matchingR2_(matchingR_ * matchingR_) {
matchingR2_(iConfig.getParameter<double>("matchingR") * iConfig.getParameter<double>("matchingR")) {
if (matchingMode_ == "VBF") { // Default
produces<std::vector<T>>("TwoJets");
produces<std::vector<T>>("ThreeJets");
Expand All @@ -226,8 +226,6 @@ L1TJetsMatching<T>::L1TJetsMatching(const edm::ParameterSet& iConfig)
<< " (valid values are \"VBF\" and \"VBFPlus2CentralJets\")";
}
}
template <typename T>
L1TJetsMatching<T>::~L1TJetsMatching() {}

template <typename T>
void L1TJetsMatching<T>::produce(edm::StreamID iSId, edm::Event& iEvent, const edm::EventSetup& iES) const {
Expand Down
14 changes: 3 additions & 11 deletions RecoTauTag/HLTProducers/interface/PFJetsMaxInvMassModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,9 @@
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/L1Trigger/interface/Tau.h"
#include "DataFormats/JetReco/interface/CaloJetCollection.h"
#include "DataFormats/TauReco/interface/PFTauFwd.h"
#include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
#include "DataFormats/HLTReco/interface/TriggerObject.h"
#include "DataFormats/HLTReco/interface/TriggerEvent.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "DataFormats/JetReco/interface/PFJetCollection.h"

class PFJetsMaxInvMassModule : public edm::global::EDProducer<> {
private:
Expand All @@ -25,7 +17,7 @@ class PFJetsMaxInvMassModule : public edm::global::EDProducer<> {

public:
explicit PFJetsMaxInvMassModule(const edm::ParameterSet&);
~PFJetsMaxInvMassModule() override;
~PFJetsMaxInvMassModule() override = default;
void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
};
Expand Down
12 changes: 8 additions & 4 deletions RecoTauTag/HLTProducers/src/CaloTowerCreatorForTauHLT.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ CaloTowerCreatorForTauHLT::CaloTowerCreatorForTauHLT(const ParameterSet& p)
: mVerbose(p.getUntrackedParameter<int>("verbose", 0)),
mtowers_token(consumes<CaloTowerCollection>(p.getParameter<InputTag>("towers"))),
mCone(p.getParameter<double>("UseTowersInCone")),
mCone2(mCone * mCone),
mTauTrigger_token(consumes<L1JetParticleCollection>(p.getParameter<InputTag>("TauTrigger"))),
mEtThreshold(p.getParameter<double>("minimumEt")),
mEThreshold(p.getParameter<double>("minimumE")),
mTauId(p.getParameter<int>("TauId")) {
produces<CaloTowerCollection>();
}

CaloTowerCreatorForTauHLT::~CaloTowerCreatorForTauHLT() {}

void CaloTowerCreatorForTauHLT::produce(StreamID sid, Event& evt, const EventSetup& stp) const {
edm::Handle<CaloTowerCollection> caloTowers;
evt.getByToken(mtowers_token, caloTowers);
Expand All @@ -42,6 +41,11 @@ void CaloTowerCreatorForTauHLT::produce(StreamID sid, Event& evt, const EventSet
std::unique_ptr<CaloTowerCollection> cands(new CaloTowerCollection);
cands->reserve(caloTowers->size());

if (mCone < 0.) {
evt.put(std::move(cands));
return;
}

int idTau = 0;
L1JetParticleCollection::const_iterator myL1Jet = jetsgen->begin();
for (; myL1Jet != jetsgen->end(); myL1Jet++) {
Expand All @@ -57,9 +61,9 @@ void CaloTowerCreatorForTauHLT::produce(StreamID sid, Event& evt, const EventSet
}
if (cal->et() >= mEtThreshold && cal->energy() >= mEThreshold) {
math::PtEtaPhiELorentzVector p(cal->et(), cal->eta(), cal->phi(), cal->energy());
double delta = ROOT::Math::VectorUtil::DeltaR((*myL1Jet).p4().Vect(), p);
double delta2 = ROOT::Math::VectorUtil::DeltaR2((*myL1Jet).p4().Vect(), p);

if (delta < mCone) {
if (delta2 < mCone2) {
isAccepted = true;
cands->push_back(*cal);
}
Expand Down
12 changes: 8 additions & 4 deletions RecoTauTag/HLTProducers/src/CaloTowerFromL1TCreatorForTauHLT.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ CaloTowerFromL1TCreatorForTauHLT::CaloTowerFromL1TCreatorForTauHLT(const Paramet
mVerbose(p.getUntrackedParameter<int>("verbose", 0)),
mtowers_token(consumes<CaloTowerCollection>(p.getParameter<InputTag>("towers"))),
mCone(p.getParameter<double>("UseTowersInCone")),
mCone2(mCone * mCone),
mTauTrigger_token(consumes<l1t::TauBxCollection>(p.getParameter<InputTag>("TauTrigger"))),
mEtThreshold(p.getParameter<double>("minimumEt")),
mEThreshold(p.getParameter<double>("minimumE")),
mTauId(p.getParameter<int>("TauId")) {
produces<CaloTowerCollection>();
}

CaloTowerFromL1TCreatorForTauHLT::~CaloTowerFromL1TCreatorForTauHLT() {}

void CaloTowerFromL1TCreatorForTauHLT::produce(StreamID sid, Event& evt, const EventSetup& stp) const {
edm::Handle<CaloTowerCollection> caloTowers;
evt.getByToken(mtowers_token, caloTowers);
Expand All @@ -42,6 +41,11 @@ void CaloTowerFromL1TCreatorForTauHLT::produce(StreamID sid, Event& evt, const E
std::unique_ptr<CaloTowerCollection> cands(new CaloTowerCollection);
cands->reserve(caloTowers->size());

if (mCone < 0.) {
evt.put(std::move(cands));
return;
}

int idTau = 0;
if (jetsgen.isValid()) {
for (auto myL1Jet = jetsgen->begin(mBX); myL1Jet != jetsgen->end(mBX); myL1Jet++) {
Expand All @@ -57,8 +61,8 @@ void CaloTowerFromL1TCreatorForTauHLT::produce(StreamID sid, Event& evt, const E
}
if (cal->et() >= mEtThreshold && cal->energy() >= mEThreshold) {
math::PtEtaPhiELorentzVector p(cal->et(), cal->eta(), cal->phi(), cal->energy());
double delta = ROOT::Math::VectorUtil::DeltaR((*myL1Jet).p4().Vect(), p);
if (delta < mCone) {
double delta2 = ROOT::Math::VectorUtil::DeltaR2((*myL1Jet).p4().Vect(), p);
if (delta2 < mCone2) {
isAccepted = true;
cands->push_back(*cal);
}
Expand Down
6 changes: 4 additions & 2 deletions RecoTauTag/HLTProducers/src/HLTPFDiJetCorrCheckerWithDiTau.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The module stores j1, j2 of any (j1, j2, t1, t2) that satisfies the conditions a
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Utilities/interface/Exception.h"
Expand All @@ -37,7 +38,7 @@ class HLTPFDiJetCorrCheckerWithDiTau : public edm::global::EDProducer<> {
const edm::EDGetTokenT<trigger::TriggerFilterObjectWithRefs> tauSrc_;
const edm::EDGetTokenT<reco::PFJetCollection> pfJetSrc_;
const double extraTauPtCut_;
const double mjjMin_;
const double mjjMin_, m2jjMin_;
const double dRmin_, dRmin2_;
// pt comparator
GreaterByPt<reco::PFJet> pTComparator_;
Expand All @@ -51,6 +52,7 @@ HLTPFDiJetCorrCheckerWithDiTau::HLTPFDiJetCorrCheckerWithDiTau(const edm::Parame
pfJetSrc_(consumes(iConfig.getParameter<edm::InputTag>("pfJetSrc"))),
extraTauPtCut_(iConfig.getParameter<double>("extraTauPtCut")),
mjjMin_(iConfig.getParameter<double>("mjjMin")),
m2jjMin_(mjjMin_ * mjjMin_),
dRmin_(iConfig.getParameter<double>("dRmin")),
dRmin2_(dRmin_ * dRmin_) {
if (dRmin_ <= 0.) {
Expand All @@ -77,7 +79,7 @@ void HLTPFDiJetCorrCheckerWithDiTau::produce(edm::StreamID iSId, edm::Event& iEv
const reco::PFJet& myPFJet1 = pfJets[iJet1];
const reco::PFJet& myPFJet2 = pfJets[iJet2];

if ((myPFJet1.p4() + myPFJet2.p4()).M() < mjjMin_)
if (mjjMin_ >= 0. && (myPFJet1.p4() + myPFJet2.p4()).M2() < m2jjMin_)
continue;

for (unsigned int iTau1 = 0; iTau1 < taus.size(); iTau1++) {
Expand Down
Loading

0 comments on commit 9a02541

Please sign in to comment.