Skip to content

Commit

Permalink
Merge pull request #39446 from missirol/devel_nonIntTriggerPrescales_…
Browse files Browse the repository at this point in the history
…125X

deprecate integer types for L1T and HLT prescales in `HLTConfigData` and its clients [`12_5_X`]
  • Loading branch information
rappoccio authored Sep 21, 2022
2 parents aa0302e + 6c0922f commit 5877851
Show file tree
Hide file tree
Showing 32 changed files with 561 additions and 428 deletions.
4 changes: 2 additions & 2 deletions Alignment/OfflineValidation/plugins/EopElecTreeWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

struct EopTriggerType {
bool fired;
int prescale;
double prescale;
int index;

EopTriggerType() {
Expand Down Expand Up @@ -411,7 +411,7 @@ void EopElecTreeWriter::analyze(const edm::Event& iEvent, const edm::EventSetup&

const unsigned int prescaleSize = hltConfig_.prescaleSize();
for (unsigned int ps = 0; ps < prescaleSize; ps++) {
const unsigned int prescaleValue = hltConfig_.prescaleValue(ps, triggerName);
auto const prescaleValue = hltConfig_.prescaleValue<double>(ps, triggerName);
if (prescaleValue != 1) {
myTrigger.prescale = prescaleValue;
}
Expand Down
12 changes: 6 additions & 6 deletions Calibration/HcalCalibAlgos/test/GammaJetAnalysis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ class GammaJetAnalysis : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::o
// trigger info
HLTPrescaleProvider hltPrescaleProvider_;
std::vector<int> photonTrigFired_;
std::vector<int> photonTrigPrescale_;
std::vector<double> photonTrigPrescale_;
std::vector<int> jetTrigFired_;
std::vector<int> jetTrigPrescale_;
std::vector<double> jetTrigPrescale_;

// Event info
int runNumber_, lumiBlock_, eventNumber_;
Expand Down Expand Up @@ -782,8 +782,8 @@ void GammaJetAnalysis::analyze(const edm::Event& iEvent, const edm::EventSetup&
photonTrigPrescale_.push_back(-1);
else {
// for triggers with two L1 seeds this fails
std::pair<int, int> prescaleVals =
hltPrescaleProvider_.prescaleValues(iEvent, evSetup, evTrigNames.triggerName(id));
auto const prescaleVals =
hltPrescaleProvider_.prescaleValues<double>(iEvent, evSetup, evTrigNames.triggerName(id));
photonTrigPrescale_.push_back(prescaleVals.first * prescaleVals.second);
}
}
Expand All @@ -799,8 +799,8 @@ void GammaJetAnalysis::analyze(const edm::Event& iEvent, const edm::EventSetup&
if (fired)
jetTrigFlag = true;
jetTrigFired_.push_back(fired);
std::pair<int, int> prescaleVals =
hltPrescaleProvider_.prescaleValues(iEvent, evSetup, evTrigNames.triggerName(id));
auto const prescaleVals =
hltPrescaleProvider_.prescaleValues<double>(iEvent, evSetup, evTrigNames.triggerName(id));
jetTrigPrescale_.push_back(prescaleVals.first * prescaleVals.second);
}
}
Expand Down
44 changes: 22 additions & 22 deletions Calibration/IsolatedParticles/plugins/IsoTrig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

// system include files
#include <memory>
#include <unordered_map>

// Root objects
#include "TROOT.h"
Expand Down Expand Up @@ -198,8 +199,8 @@ class IsoTrig : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::Share
const CaloGeometry *geo_;
math::XYZPoint leadPV_;

std::map<unsigned int, unsigned int> trigList_;
std::map<unsigned int, const std::pair<int, int>> trigPreList_;
std::unordered_map<unsigned int, unsigned int> trigList_;
std::unordered_map<unsigned int, const std::pair<double, double>> trigPreList_;
bool changed_;
double pLimits_[6];
edm::Service<TFileService> fs_;
Expand Down Expand Up @@ -263,7 +264,8 @@ class IsoTrig : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::Share
TH1D *h_eMaxNearP[2], *h_eNeutIso[2];
TH1D *h_etaCalibTracks[5][2][2], *h_etaMipTracks[5][2][2];
TH1D *h_eHcal[5][6][48], *h_eCalo[5][6][48];
TH1I *g_Pre, *g_PreL1, *g_PreHLT, *g_Accepts;
TH1D *g_Pre, *g_PreL1, *g_PreHLT;
TH1I *g_Accepts;
std::vector<math::XYZTLorentzVector> vec_[3];
};

Expand Down Expand Up @@ -660,7 +662,8 @@ void IsoTrig::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
const std::vector<std::string> &triggerNames_ = triggerNames.triggerNames();
if (verbosity_ % 10 > 1)
edm::LogVerbatim("IsoTrack") << "number of HLTs " << triggerNames_.size();
int hlt(-1), preL1(-1), preHLT(-1), prescale(-1);
double preL1(-1), preHLT(-1), prescale(-1);
int hlt(-1);
for (unsigned int i = 0; i < triggerResults->size(); i++) {
unsigned int triggerindx = hltConfig.triggerIndex(triggerNames_[i]);
const std::vector<std::string> &moduleLabels(hltConfig.moduleLabels(triggerindx));
Expand All @@ -680,7 +683,7 @@ void IsoTrig::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
edm::Handle<trigger::TriggerFilterObjectWithRefs> L1cands;
iEvent.getByToken(tok_l1cand_, L1cands);

const std::pair<int, int> prescales(hltPrescaleProvider_.prescaleValues(iEvent, iSetup, triggerNames_[i]));
auto const prescales = hltPrescaleProvider_.prescaleValues<double>(iEvent, iSetup, triggerNames_[i]);
preL1 = prescales.first;
preHLT = prescales.second;
prescale = preL1 * preHLT;
Expand All @@ -692,8 +695,8 @@ void IsoTrig::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
if (trigList_.find(RunNo) != trigList_.end()) {
trigList_[RunNo] += 1;
} else {
trigList_.insert(std::pair<unsigned int, unsigned int>(RunNo, 1));
trigPreList_.insert(std::pair<unsigned int, std::pair<int, int>>(RunNo, prescales));
trigList_.insert({RunNo, 1});
trigPreList_.insert({RunNo, prescales});
}
//loop over all trigger filters in event (i.e. filters passed)
for (unsigned int ifilter = 0; ifilter < triggerEvent.sizeFilters(); ++ifilter) {
Expand Down Expand Up @@ -1174,27 +1177,24 @@ void IsoTrig::beginJob() {

// ------------ method called once each job just after ending the event loop ------------
void IsoTrig::endJob() {
unsigned int preL1, preHLT;
std::map<unsigned int, unsigned int>::iterator itr;
std::map<unsigned int, const std::pair<int, int>>::iterator itrPre;
edm::LogWarning("IsoTrack") << trigNames_.size() << "Triggers were run. RunNo vs HLT accepts for";
for (unsigned int i = 0; i < trigNames_.size(); ++i)
edm::LogWarning("IsoTrack") << "[" << i << "]: " << trigNames_[i];
unsigned int n = maxRunNo_ - minRunNo_ + 1;
g_Pre = fs_->make<TH1I>("h_PrevsRN", "PreScale Vs Run Number", n, minRunNo_, maxRunNo_);
g_PreL1 = fs_->make<TH1I>("h_PreL1vsRN", "L1 PreScale Vs Run Number", n, minRunNo_, maxRunNo_);
g_PreHLT = fs_->make<TH1I>("h_PreHLTvsRN", "HLT PreScale Vs Run Number", n, minRunNo_, maxRunNo_);
g_Pre = fs_->make<TH1D>("h_PrevsRN", "PreScale Vs Run Number", n, minRunNo_, maxRunNo_);
g_PreL1 = fs_->make<TH1D>("h_PreL1vsRN", "L1 PreScale Vs Run Number", n, minRunNo_, maxRunNo_);
g_PreHLT = fs_->make<TH1D>("h_PreHLTvsRN", "HLT PreScale Vs Run Number", n, minRunNo_, maxRunNo_);
g_Accepts = fs_->make<TH1I>("h_HLTAcceptsvsRN", "HLT Accepts Vs Run Number", n, minRunNo_, maxRunNo_);

for (itr = trigList_.begin(), itrPre = trigPreList_.begin(); itr != trigList_.end(); itr++, itrPre++) {
preL1 = (itrPre->second).first;
preHLT = (itrPre->second).second;
edm::LogVerbatim("IsoTrack") << itr->first << " " << itr->second << " " << itrPre->first << " " << preL1 << " "
<< preHLT;
g_Accepts->Fill(itr->first, itr->second);
g_PreL1->Fill(itr->first, preL1);
g_PreHLT->Fill(itr->first, preHLT);
g_Pre->Fill(itr->first, preL1 * preHLT);
for (auto const &[runNum, nAccept] : trigList_) {
auto const &triggerPrescales = trigPreList_[runNum];
auto const preL1 = triggerPrescales.first;
auto const preHLT = triggerPrescales.second;
edm::LogVerbatim("IsoTrack") << runNum << " " << nAccept << " " << preL1 << " " << preHLT;
g_Accepts->Fill(runNum, nAccept);
g_PreL1->Fill(runNum, preL1);
g_PreHLT->Fill(runNum, preHLT);
g_Pre->Fill(runNum, preL1 * preHLT);
}
}

Expand Down
120 changes: 116 additions & 4 deletions CommonTools/TriggerUtils/interface/PrescaleWeightProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,29 @@
// Package: CommonTools/TriggerUtils
// Class: PrescaleWeightProvider
//
/**
/*
\class PrescaleWeightProvider PrescaleWeightProvider.h "CommonTools/TriggerUtils/interface/PrescaleWeightProvider.h"
\brief
This class takes a vector of HLT paths and returns a weight based on their
HLT and L1 prescales. The weight is equal to the lowest combined (L1*HLT) prescale
of the selected paths
\author Aram Avetisyan
*/

#include <memory>
#include <string>
#include <vector>
#include <type_traits>

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

#include "FWCore/Framework/interface/Run.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/InputTag.h"

Expand Down Expand Up @@ -72,8 +73,10 @@ class PrescaleWeightProvider {

// to be called from the ED module's beginRun() method
void initRun(const edm::Run& run, const edm::EventSetup& setup);

// to be called from the ED module's event loop method
int prescaleWeight(const edm::Event& event, const edm::EventSetup& setup);
template <typename T = int>
T prescaleWeight(const edm::Event& event, const edm::EventSetup& setup);

private:
PrescaleWeightProvider(const edm::ParameterSet& config, edm::ConsumesCollector& iC);
Expand All @@ -90,4 +93,113 @@ PrescaleWeightProvider::PrescaleWeightProvider(const edm::ParameterSet& config,
: PrescaleWeightProvider(config, iC) {
hltPrescaleProvider_ = std::make_unique<HLTPrescaleProvider>(config, iC, module);
}
#endif

template <typename T>
T PrescaleWeightProvider::prescaleWeight(const edm::Event& event, const edm::EventSetup& setup) {
static_assert(std::is_same_v<T, double> or std::is_same_v<T, FractionalPrescale>,
"\n\tPlease use prescaleWeight<double> or prescaleWeight<FractionalPrescale>"
"\n\t(other types for HLT prescales are not supported anymore by PrescaleWeightProvider");
if (!init_)
return 1;

// L1
L1GtUtils const& l1GtUtils = hltPrescaleProvider_->l1GtUtils();

// HLT
HLTConfigProvider const& hltConfig = hltPrescaleProvider_->hltConfigProvider();

edm::Handle<edm::TriggerResults> triggerResults;
event.getByToken(triggerResultsToken_, triggerResults);
if (!triggerResults.isValid()) {
if (verbosity_ > 0)
edm::LogError("PrescaleWeightProvider::prescaleWeight")
<< "TriggerResults product not found for InputTag \"" << triggerResultsTag_.encode() << "\"";
return 1;
}

const int SENTINEL(-1);
int weight(SENTINEL);

for (unsigned ui = 0; ui < hltPaths_.size(); ui++) {
const std::string hltPath(hltPaths_.at(ui));
unsigned hltIndex(hltConfig.triggerIndex(hltPath));
if (hltIndex == hltConfig.size()) {
if (verbosity_ > 0)
edm::LogError("PrescaleWeightProvider::prescaleWeight") << "HLT path \"" << hltPath << "\" does not exist";
continue;
}
if (!triggerResults->accept(hltIndex))
continue;

const std::vector<std::pair<bool, std::string> >& level1Seeds = hltConfig.hltL1GTSeeds(hltPath);
if (level1Seeds.size() != 1) {
if (verbosity_ > 0)
edm::LogError("PrescaleWeightProvider::prescaleWeight")
<< "HLT path \"" << hltPath << "\" provides too many L1 seeds";
return 1;
}
parseL1Seeds(level1Seeds.at(0).second);
if (l1SeedPaths_.empty()) {
if (verbosity_ > 0)
edm::LogWarning("PrescaleWeightProvider::prescaleWeight")
<< "Failed to parse L1 seeds for HLT path \"" << hltPath << "\"";
continue;
}

int l1Prescale(SENTINEL);
for (unsigned uj = 0; uj < l1SeedPaths_.size(); uj++) {
int l1TempPrescale(SENTINEL);
int errorCode(0);
if (level1Seeds.at(0).first) { // technical triggers
unsigned techBit(atoi(l1SeedPaths_.at(uj).c_str()));
const std::string techName(*(triggerMenuLite_->gtTechTrigName(techBit, errorCode)));
if (errorCode != 0)
continue;
if (!l1GtUtils.decision(event, techName, errorCode))
continue;
if (errorCode != 0)
continue;
l1TempPrescale = l1GtUtils.prescaleFactor(event, techName, errorCode);
if (errorCode != 0)
continue;
} else { // algorithmic triggers
if (!l1GtUtils.decision(event, l1SeedPaths_.at(uj), errorCode))
continue;
if (errorCode != 0)
continue;
l1TempPrescale = l1GtUtils.prescaleFactor(event, l1SeedPaths_.at(uj), errorCode);
if (errorCode != 0)
continue;
}
if (l1TempPrescale > 0) {
if (l1Prescale == SENTINEL || l1Prescale > l1TempPrescale)
l1Prescale = l1TempPrescale;
}
}
if (l1Prescale == SENTINEL) {
if (verbosity_ > 0)
edm::LogError("PrescaleWeightProvider::prescaleWeight")
<< "Unable to find the L1 prescale for HLT path \"" << hltPath << "\"";
continue;
}

auto const prescale = l1Prescale * hltPrescaleProvider_->prescaleValue<T>(event, setup, hltPath);

if (prescale > 0) {
if (weight == SENTINEL || weight > prescale) {
weight = prescale;
}
}
}

if (weight == SENTINEL) {
if (verbosity_ > 0)
edm::LogWarning("PrescaleWeightProvider::prescaleWeight")
<< "No valid weight for any requested HLT path, returning default weight of 1";
return 1;
}

return weight;
}

#endif // CommonTools_TriggerUtils_PrescaleWeightProvider_h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ void CandidateTriggerObjectProducer::produce(edm::Event& iEvent, const edm::Even
//matching with regexp filter name. More than 1 matching filter is allowed
if (TString(*iHLT).Contains(TRegexp(TString(triggerName_)))) {
triggerInMenu[*iHLT] = true;
const std::pair<int, int> prescales(hltPrescaleProvider_.prescaleValues(iEvent, iSetup, *iHLT));
if (prescales.first * prescales.second == 1)
auto const prescales = hltPrescaleProvider_.prescaleValues<double>(iEvent, iSetup, *iHLT);
if (prescales.first == 1 and prescales.second == 1)
triggerUnprescaled[*iHLT] = true;
}
}
Expand Down
Loading

0 comments on commit 5877851

Please sign in to comment.