Skip to content

Commit

Permalink
Merge pull request #23515 from kreczko/kreczko-issue-CMSLITDPG-585-part1
Browse files Browse the repository at this point in the history
[L1T][DQMOffline] Upgrading L1TEGammaOffline (CMSLITDPG-585)
  • Loading branch information
cmsbuild committed Jun 22, 2018
2 parents 0c79770 + 3028027 commit 7441668
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 80 deletions.
8 changes: 7 additions & 1 deletion DQMOffline/L1Trigger/interface/L1TEGammaOffline.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class L1TEGammaOffline: public DQMEDAnalyzer {
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
void analyze(edm::Event const& e, edm::EventSetup const& eSetup) override;
void endRun(edm::Run const& run, edm::EventSetup const& eSetup) override;
void endJob() override;

private:
bool passesLooseEleId(reco::GsfElectron const& electron) const;
Expand All @@ -74,6 +75,8 @@ class L1TEGammaOffline: public DQMEDAnalyzer {
bool findTagAndProbePair(edm::Handle<reco::GsfElectronCollection> const& electrons);
bool matchesAnHLTObject(double eta, double phi) const;

void normalise2DHistogramsToBinArea();

math::XYZPoint PVPoint_;

//variables from config file
Expand All @@ -98,6 +101,9 @@ class L1TEGammaOffline: public DQMEDAnalyzer {
std::vector<double> photonEfficiencyThresholds_;
std::vector<double> photonEfficiencyBins_;

double maxDeltaRForL1Matching_;
double maxDeltaRForHLTMatching_;

reco::GsfElectron tagElectron_;
reco::GsfElectron probeElectron_;
double tagAndProbleInvariantMass_;
Expand Down Expand Up @@ -178,7 +184,7 @@ class L1TEGammaOffline: public DQMEDAnalyzer {

MonitorElement* h_resolutionPhotonEta_;

// electron turn-ons
// photon turn-ons
std::map<double, MonitorElement*> h_efficiencyPhotonET_EB_pass_;
std::map<double, MonitorElement*> h_efficiencyPhotonET_EE_pass_;
std::map<double, MonitorElement*> h_efficiencyPhotonET_EB_EE_pass_;
Expand Down
5 changes: 5 additions & 0 deletions DQMOffline/L1Trigger/python/L1TEGammaDiff_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,16 @@
'L1EGammaEtavsPhotonEta',
]

# remove photon variables (code to produce them is currently commented out)
resolution_plots = [plot for plot in resolution_plots if 'Photon' not in plot]
plots2D = [plot for plot in plots2D if 'Photon' not in plot]

allPlots = []
allPlots.extend(allEfficiencyPlots)
allPlots.extend(resolution_plots)
allPlots.extend(plots2D)


from DQMOffline.L1Trigger.L1TDiffHarvesting_cfi import l1tDiffHarvesting
l1tEGammaEmuDiff = l1tDiffHarvesting.clone(
plotCfgs=cms.untracked.VPSet(
Expand Down
88 changes: 26 additions & 62 deletions DQMOffline/L1Trigger/python/L1TEGammaEfficiency_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,47 +30,6 @@
'photon': [],
}

allEfficiencyPlots = []
add_plot = allEfficiencyPlots.append
for variable, thresholds in variables.iteritems():
for plot in plots[variable]:
for threshold in thresholds:
plotName = '{0}_threshold_{1}'.format(plot, threshold)
add_plot(plotName)

for variable, thresholds in deepInspectionThresholds.iteritems():
for plot in deepInspectionPlots[variable]:
for threshold in thresholds:
plotName = '{0}_threshold_{1}'.format(plot, threshold)
add_plot(plotName)

from DQMOffline.L1Trigger.L1TEfficiencyHarvesting_cfi import l1tEfficiencyHarvesting
l1tEGammaEfficiency = l1tEfficiencyHarvesting.clone(
plotCfgs=cms.untracked.VPSet(
cms.untracked.PSet(
numeratorDir=cms.untracked.string("L1T/L1TObjects/L1TEGamma/L1TriggerVsReco/efficiency_raw"),
outputDir=cms.untracked.string("L1T/L1TObjects/L1TEGamma/L1TriggerVsReco"),
numeratorSuffix=cms.untracked.string("_Num"),
denominatorSuffix=cms.untracked.string("_Den"),
plots=cms.untracked.vstring(allEfficiencyPlots)
),
)
)

l1tEGammaEmuEfficiency = l1tEfficiencyHarvesting.clone(
plotCfgs=cms.untracked.VPSet(
cms.untracked.PSet(
numeratorDir=cms.untracked.string(
"L1TEMU/L1TObjects/L1TEGamma/L1TriggerVsReco/efficiency_raw"),
outputDir=cms.untracked.string("L1TEMU/L1TObjects/L1TEGamma/L1TriggerVsReco"),
numeratorSuffix=cms.untracked.string("_Num"),
denominatorSuffix=cms.untracked.string("_Den"),
plots=cms.untracked.vstring(allEfficiencyPlots)
),
)
)

# modifications for the pp reference run
variables_HI = {
'electron': L1TEGammaOffline_cfi.electronEfficiencyThresholds_HI,
'photon': L1TEGammaOffline_cfi.photonEfficiencyThresholds_HI,
Expand All @@ -81,28 +40,33 @@
'photon': [],
}

allEfficiencyPlots_HI = []
add_plot = allEfficiencyPlots_HI.append
for variable, thresholds in variables_HI.iteritems():
for plot in plots[variable]:
for threshold in thresholds:
plotName = '{0}_threshold_{1}'.format(plot, threshold)
add_plot(plotName)
# remove photon variables (code to produce them is currently commented out)
variables['photon'] = []
variables_HI['photon'] = []

for variable, thresholds in deepInspectionThresholds_HI.iteritems():
for plot in deepInspectionPlots[variable]:
for threshold in thresholds:
plotName = '{0}_threshold_{1}'.format(plot, threshold)
add_plot(plotName)
from DQMOffline.L1Trigger.L1TCommon import generateEfficiencyStrings as ges
efficiencyStrings = list(ges(variables, plots))
efficiencyStrings += list(ges(deepInspectionThresholds, deepInspectionPlots))

from Configuration.Eras.Modifier_ppRef_2017_cff import ppRef_2017
ppRef_2017.toModify(l1tEGammaEfficiency,
plotCfgs = {
0:dict(plots = allEfficiencyPlots_HI),
}
efficiencyStrings_HI = list(ges(variables_HI, plots))
efficiencyStrings_HI += list(ges(deepInspectionThresholds_HI,
deepInspectionPlots))

from DQMServices.Core.DQMEDHarvester import DQMEDHarvester
l1tEGammaEfficiency = DQMEDHarvester(
"DQMGenericClient",
commands=cms.vstring(),
resolution=cms.vstring(),
subDirs=cms.untracked.vstring('L1T/L1TObjects/L1TEGamma/L1TriggerVsReco'),
efficiency=cms.vstring(),
efficiencyProfile=cms.untracked.vstring(efficiencyStrings),
)
ppRef_2017.toModify(l1tEGammaEmuEfficiency,
plotCfgs = {
0:dict(plots = allEfficiencyPlots_HI),
}

l1tEGammaEmuEfficiency = l1tEGammaEfficiency.clone(
subDirs=cms.untracked.vstring(
'L1TEMU/L1TObjects/L1TEGamma/L1TriggerVsReco'),
)

from Configuration.Eras.Modifier_ppRef_2017_cff import ppRef_2017
ppRef_2017.toModify(l1tEGammaEfficiency, efficiencyProfile=efficiencyStrings_HI)
ppRef_2017.toModify(l1tEGammaEmuEfficiency, efficiencyProfile=efficiencyStrings_HI)
2 changes: 2 additions & 0 deletions DQMOffline/L1Trigger/python/L1TEGammaOffline_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@

photonEfficiencyThresholds=cms.vdouble(photonEfficiencyThresholds),
photonEfficiencyBins=cms.vdouble(photonEfficiencyBins),
maxDeltaRForL1Matching=cms.double(0.3),
maxDeltaRForHLTMatching=cms.double(0.3),

histDefinitions=cms.PSet(
nVertex=histDefinitions.nVertex.clone(),
Expand Down
107 changes: 90 additions & 17 deletions DQMOffline/L1Trigger/src/L1TEGammaOffline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "FWCore/Framework/interface/MakerMacros.h"
// Geometry
#include "DataFormats/Math/interface/deltaR.h"
#include "DataFormats/Math/interface/deltaPhi.h"
#include "DataFormats/Math/interface/LorentzVector.h"
#include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
#include "TLorentzVector.h"
Expand Down Expand Up @@ -49,14 +50,60 @@ L1TEGammaOffline::L1TEGammaOffline(const edm::ParameterSet& ps) :
deepInspectionElectronThresholds_(ps.getParameter < std::vector<double> > ("deepInspectionElectronThresholds")),
photonEfficiencyThresholds_(ps.getParameter < std::vector<double> > ("photonEfficiencyThresholds")),
photonEfficiencyBins_(ps.getParameter < std::vector<double> > ("photonEfficiencyBins")),
maxDeltaRForL1Matching_(ps.getParameter <double> ("maxDeltaRForL1Matching")),
maxDeltaRForHLTMatching_(ps.getParameter <double> ("maxDeltaRForHLTMatching")),
tagElectron_(),
probeElectron_(),
tagAndProbleInvariantMass_(-1.),
hltConfig_(),
triggerIndices_(),
triggerResults_(),
triggerEvent_(),
histDefinitions_(dqmoffline::l1t::readHistDefinitions(ps.getParameterSet("histDefinitions"), PlotConfigNames))
histDefinitions_(dqmoffline::l1t::readHistDefinitions(ps.getParameterSet("histDefinitions"), PlotConfigNames)),
h_nVertex_(),
h_tagAndProbeMass_(),
h_L1EGammaETvsElectronET_EB_(),
h_L1EGammaETvsElectronET_EE_(),
h_L1EGammaETvsElectronET_EB_EE_(),
h_L1EGammaPhivsElectronPhi_EB_(),
h_L1EGammaPhivsElectronPhi_EE_(),
h_L1EGammaPhivsElectronPhi_EB_EE_(),
h_L1EGammaEtavsElectronEta_(),
h_resolutionElectronET_EB_(),
h_resolutionElectronET_EE_(),
h_resolutionElectronET_EB_EE_(),
h_resolutionElectronPhi_EB_(),
h_resolutionElectronPhi_EE_(),
h_resolutionElectronPhi_EB_EE_(),
h_resolutionElectronEta_(),
h_efficiencyElectronET_EB_pass_(),
h_efficiencyElectronET_EE_pass_(),
h_efficiencyElectronET_EB_EE_pass_(),
h_efficiencyElectronPhi_vs_Eta_pass_(),
h_efficiencyElectronEta_pass_(),
h_efficiencyElectronPhi_pass_(),
h_efficiencyElectronNVertex_pass_(),
h_efficiencyElectronET_EB_total_(),
h_efficiencyElectronET_EE_total_(),
h_efficiencyElectronET_EB_EE_total_(),
h_efficiencyElectronPhi_vs_Eta_total_(),
h_efficiencyElectronEta_total_(),
h_efficiencyElectronPhi_total_(),
h_efficiencyElectronNVertex_total_(),
h_L1EGammaETvsPhotonET_EB_(),
h_L1EGammaETvsPhotonET_EE_(),
h_L1EGammaETvsPhotonET_EB_EE_(),
h_L1EGammaPhivsPhotonPhi_EB_(),
h_L1EGammaPhivsPhotonPhi_EE_(),
h_L1EGammaPhivsPhotonPhi_EB_EE_(),
h_L1EGammaEtavsPhotonEta_(),
h_resolutionPhotonEta_(),
h_efficiencyPhotonET_EB_pass_(),
h_efficiencyPhotonET_EE_pass_(),
h_efficiencyPhotonET_EB_EE_pass_(),
h_efficiencyPhotonET_EB_total_(),
h_efficiencyPhotonET_EE_total_(),
h_efficiencyPhotonET_EB_EE_total_()
{
edm::LogInfo("L1TEGammaOffline") << "Constructor " << "L1TEGammaOffline::L1TEGammaOffline " << std::endl;
}
Expand Down Expand Up @@ -95,7 +142,7 @@ void L1TEGammaOffline::bookHistograms(DQMStore::IBooker & ibooker, edm::Run cons

//book at beginRun
bookElectronHistos(ibooker);
bookPhotonHistos(ibooker);
// bookPhotonHistos(ibooker);
}

//
Expand Down Expand Up @@ -136,7 +183,7 @@ void L1TEGammaOffline::analyze(edm::Event const& e, edm::EventSetup const& eSetu
}
// L1T
fillElectrons(e, nVertex);
fillPhotons(e, nVertex);
// fillPhotons(e, nVertex);
}

void L1TEGammaOffline::fillElectrons(edm::Event const& e, const unsigned int nVertex)
Expand Down Expand Up @@ -167,7 +214,7 @@ void L1TEGammaOffline::fillElectrons(edm::Event const& e, const unsigned int nVe
auto probeElectron = probeElectron_;

// find corresponding L1 EG
double minDeltaR = 0.3;
double minDeltaR = maxDeltaRForL1Matching_;
l1t::EGamma closestL1EGamma;
bool foundMatch = false;

Expand All @@ -180,6 +227,7 @@ void L1TEGammaOffline::fillElectrons(edm::Event const& e, const unsigned int nVe
minDeltaR = currentDeltaR;
closestL1EGamma = *egamma;
foundMatch = true;
break;
}

}
Expand All @@ -200,8 +248,8 @@ void L1TEGammaOffline::fillElectrons(edm::Event const& e, const unsigned int nVe
// if no reco value, relative resolution does not make sense -> sort to overflow
double outOfBounds = 9999;
double resolutionEt = recoEt > 0 ? (l1Et - recoEt) / recoEt : outOfBounds;
double resolutionEta = std::abs(recoEta) > 0 ? (l1Eta - recoEta) / recoEta : outOfBounds;
double resolutionPhi = std::abs(recoPhi) > 0 ? (l1Phi - recoPhi) / recoPhi : outOfBounds;
double resolutionEta = l1Eta - recoEta;
double resolutionPhi = reco::deltaPhi(l1Phi, recoPhi);

using namespace dqmoffline::l1t;
// eta
Expand Down Expand Up @@ -415,7 +463,7 @@ bool L1TEGammaOffline::matchesAnHLTObject(double eta, double phi) const{
std::vector<unsigned int> firedTriggers = getFiredTriggerIndices(triggerIndices_, results);
std::vector<edm::InputTag> hltFilters = getHLTFilters(firedTriggers, hltConfig_, triggerProcess_);
const trigger::TriggerObjectCollection hltObjects = getTriggerObjects(hltFilters, triggerEvent_);
const trigger::TriggerObjectCollection matchedObjects = getMatchedTriggerObjects(eta, phi, 0.3, hltObjects);
const trigger::TriggerObjectCollection matchedObjects = getMatchedTriggerObjects(eta, phi, maxDeltaRForHLTMatching_, hltObjects);

return !matchedObjects.empty();
}
Expand Down Expand Up @@ -478,8 +526,8 @@ void L1TEGammaOffline::fillPhotons(edm::Event const& e, const unsigned int nVert
// if no reco value, relative resolution does not make sense -> sort to overflow
double outOfBounds = 9999;
double resolutionEt = recoEt > 0 ? (l1Et - recoEt) / recoEt : outOfBounds;
double resolutionEta = std::abs(recoEta) > 0 ? (l1Eta - recoEta) / recoEta : outOfBounds;
double resolutionPhi = std::abs(recoPhi) > 0 ? (l1Phi - recoPhi) / recoPhi : outOfBounds;
double resolutionEta = l1Eta - recoEta;
double resolutionPhi = reco::deltaPhi(l1Phi, recoPhi);

using namespace dqmoffline::l1t;
// eta
Expand Down Expand Up @@ -595,19 +643,19 @@ void L1TEGammaOffline::bookElectronHistos(DQMStore::IBooker & ibooker)

h_resolutionElectronPhi_EB_ =
ibooker.book1D("resolutionElectronPhi_EB",
"#phi_{electron} resolution (EB); (#phi_{electron}^{L1} - #phi_{electron}^{offline})/#phi_{electron}^{offline}; events",
"#phi_{electron} resolution (EB); #phi_{electron}^{L1} - #phi_{electron}^{offline}; events",
120, -0.3, 0.3);
h_resolutionElectronPhi_EE_ =
ibooker.book1D("resolutionElectronPhi_EE",
"electron #phi resolution (EE); (#phi_{electron}^{L1} - #phi_{electron}^{offline})/#phi_{electron}^{offline}; events",
"electron #phi resolution (EE); #phi_{electron}^{L1} - #phi_{electron}^{offline}; events",
120, -0.3, 0.3);
h_resolutionElectronPhi_EB_EE_ =
ibooker.book1D("resolutionElectronPhi_EB_EE",
"electron #phi resolution (EB+EE); (#phi_{electron}^{L1} - #phi_{electron}^{offline})/#phi_{electron}^{offline}; events",
"electron #phi resolution (EB+EE); #phi_{electron}^{L1} - #phi_{electron}^{offline}; events",
120, -0.3, 0.3);

h_resolutionElectronEta_ = ibooker.book1D("resolutionElectronEta",
"electron #eta resolution (EB); (L1 EGamma #eta - GSF Electron #eta)/GSF Electron #eta; events", 120, -0.3, 0.3);
"electron #eta resolution (EB); L1 EGamma #eta - GSF Electron #eta; events", 120, -0.3, 0.3);

// electron turn-ons
ibooker.setCurrentFolder(efficiencyFolder_);
Expand Down Expand Up @@ -715,17 +763,17 @@ void L1TEGammaOffline::bookPhotonHistos(DQMStore::IBooker & ibooker)
"photon ET resolution (EB+EE); (L1 EGamma E_{T} - Photon E_{T})/ Photon E_{T}; events", 50, -1, 1.5);

h_resolutionPhotonPhi_EB_ = ibooker.book1D("resolutionPhotonPhi_EB",
"#phi_{photon} resolution (EB); (#phi_{photon}^{L1} - #phi_{photon}^{offline})/#phi_{photon}^{offline}; events",
"#phi_{photon} resolution (EB); #phi_{photon}^{L1} - #phi_{photon}^{offline}; events",
120, -0.3, 0.3);
h_resolutionPhotonPhi_EE_ = ibooker.book1D("resolutionPhotonPhi_EE",
"photon #phi resolution (EE); (#phi_{photon}^{L1} - #phi_{photon}^{offline})/#phi_{photon}^{offline}; events",
"photon #phi resolution (EE); #phi_{photon}^{L1} - #phi_{photon}^{offline}; events",
120, -0.3, 0.3);
h_resolutionPhotonPhi_EB_EE_ = ibooker.book1D("resolutionPhotonPhi_EB_EE",
"photon #phi resolution (EB+EE); (#phi_{photon}^{L1} - #phi_{photon}^{offline})/#phi_{photon}^{offline}; events",
"photon #phi resolution (EB+EE); #phi_{photon}^{L1} - #phi_{photon}^{offline}; events",
120, -0.3, 0.3);

h_resolutionPhotonEta_ = ibooker.book1D("resolutionPhotonEta",
"photon #eta resolution (EB); (L1 EGamma #eta - Photon #eta)/ Photon #eta; events", 120, -0.3, 0.3);
"photon #eta resolution (EB); L1 EGamma #eta - Photon #eta; events", 120, -0.3, 0.3);

// photon turn-ons
ibooker.setCurrentFolder(efficiencyFolder_);
Expand Down Expand Up @@ -759,5 +807,30 @@ void L1TEGammaOffline::bookPhotonHistos(DQMStore::IBooker & ibooker)
ibooker.cd();
}

void L1TEGammaOffline::endJob(){
normalise2DHistogramsToBinArea();
}

void L1TEGammaOffline::normalise2DHistogramsToBinArea() {
std::vector<MonitorElement *> monElementstoNormalize = {
h_L1EGammaETvsElectronET_EB_, h_L1EGammaETvsElectronET_EE_,
h_L1EGammaETvsElectronET_EB_EE_, h_L1EGammaPhivsElectronPhi_EB_,
h_L1EGammaPhivsElectronPhi_EE_, h_L1EGammaPhivsElectronPhi_EB_EE_,
h_L1EGammaEtavsElectronEta_, h_L1EGammaETvsPhotonET_EB_,
h_L1EGammaETvsPhotonET_EE_, h_L1EGammaETvsPhotonET_EB_EE_,
h_L1EGammaPhivsPhotonPhi_EB_, h_L1EGammaPhivsPhotonPhi_EE_,
h_L1EGammaPhivsPhotonPhi_EB_EE_, h_L1EGammaEtavsPhotonEta_
};

for (auto mon : monElementstoNormalize) {
if (mon != nullptr) {
auto h = mon->getTH2F();
if (h != nullptr) {
h->Scale(1, "width");
}
}
}
}

//define this as a plug-in
DEFINE_FWK_MODULE (L1TEGammaOffline);

0 comments on commit 7441668

Please sign in to comment.