Skip to content

Commit

Permalink
Merge pull request #39363 from perrotta/simplifyL1TPhase2MuonOffline125X
Browse files Browse the repository at this point in the history
Simplify L1TPhase2MuonOffline and fix L1TRate_Offline and L1TStage2CaloLayer2Offline [CMSSW_12_5_X]
  • Loading branch information
cmsbuild authored Sep 13, 2022
2 parents 43c3f18 + 1a084d9 commit d80b1fb
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 56 deletions.
40 changes: 10 additions & 30 deletions DQMOffline/L1Trigger/interface/L1TPhase2MuonOffline.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,24 @@
// DataFormats
#include "DataFormats/L1Trigger/interface/Muon.h"
#include "DataFormats/L1TMuonPhase2/interface/SAMuon.h"
#include "DataFormats/L1TMuonPhase2/interface/MuonStub.h"
#include "DataFormats/L1TMuonPhase2/interface/TrackerMuon.h"
#include "DataFormats/Candidate/interface/Candidate.h"
#include "DataFormats/HepMCCandidate/interface/GenParticle.h"
#include "DataFormats/L1Trigger/interface/L1MuonParticleFwd.h"
#include "DataFormats/L1Trigger/interface/L1MuonParticle.h"
#include "DataFormats/Math/interface/deltaR.h"
#include "DataFormats/Math/interface/deltaPhi.h"

// FWCore
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/LuminosityBlock.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

// DQMServices
#include "DQMServices/Core/interface/DQMStore.h"
#include "DQMServices/Core/interface/DQMEDAnalyzer.h"

// HLTrigger
#include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"

// Common tools
#include "TrackingTools/TransientTrack/interface/TransientTrack.h"
#include "TrackingTools/TransientTrack/interface/TrackTransientTrack.h"
#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
#include "TrackingTools/PatternTools/interface/Trajectory.h"
#include "TrackingTools/Records/interface/TransientTrackRecord.h"
#include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
#include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
#include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
#include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"

#include <memory>
#include "TRegexp.h"
#include <utility>
Expand All @@ -63,7 +43,7 @@ class GenMuonGMTPair;
class L1TPhase2MuonOffline : public DQMEDAnalyzer {
public:
L1TPhase2MuonOffline(const edm::ParameterSet& ps);
~L1TPhase2MuonOffline() override;
~L1TPhase2MuonOffline() override = default;

enum MuType { kSAMuon, kTkMuon, kNMuTypes };
enum VarType { kPt, kEta, kPhi, kIso, kQual, kZ0, kD0, kNVarTypes };
Expand Down Expand Up @@ -105,13 +85,13 @@ class L1TPhase2MuonOffline : public DQMEDAnalyzer {
const std::vector<MuType> muonTypes_;
const std::vector<EffType> effTypes_;
const std::vector<ResType> resTypes_;
const std::vector<VarType> varTypes_;
// const std::vector<VarType> varTypes_;
const std::vector<EtaRegion> etaRegions_;
const std::vector<QualLevel> qualLevels_;

// maps with histogram name bits
std::map<EffType, std::string> effNames_;
std::map<EffType, std::string> effLabels_;
// std::map<EffType, std::string> effNames_;
// std::map<EffType, std::string> effLabels_;
std::map<ResType, std::string> resNames_;
std::map<ResType, std::string> resLabels_;
std::map<EtaRegion, std::string> etaNames_;
Expand Down Expand Up @@ -143,11 +123,11 @@ class L1TPhase2MuonOffline : public DQMEDAnalyzer {
std::vector<GenMuonGMTPair> gmtTkMuonPairs_;
std::vector<std::pair<int, QualLevel>> cuts_;

float lsb_pt = Phase2L1GMT::LSBpt;
float lsb_phi = Phase2L1GMT::LSBphi;
float lsb_eta = Phase2L1GMT::LSBeta;
float lsb_z0 = Phase2L1GMT::LSBSAz0;
float lsb_d0 = Phase2L1GMT::LSBSAd0;
const float lsb_pt = Phase2L1GMT::LSBpt;
const float lsb_phi = Phase2L1GMT::LSBphi;
const float lsb_eta = Phase2L1GMT::LSBeta;
const float lsb_z0 = Phase2L1GMT::LSBSAz0;
const float lsb_d0 = Phase2L1GMT::LSBSAd0;
};

//
Expand All @@ -159,7 +139,7 @@ class GenMuonGMTPair {
GenMuonGMTPair(const GenMuonGMTPair& muongmtPair);
~GenMuonGMTPair(){};

float dR();
float dR2();
float pt() const { return mu_->pt(); };
float eta() const { return mu_->eta(); };
float phi() const { return mu_->phi(); };
Expand Down
44 changes: 25 additions & 19 deletions DQMOffline/L1Trigger/src/L1TPhase2MuonOffline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "DataFormats/L1TMuonPhase2/interface/Constants.h"

using namespace reco;
using namespace trigger;
using namespace edm;
using namespace std;
using namespace l1t;
Expand Down Expand Up @@ -46,10 +45,12 @@ GenMuonGMTPair::GenMuonGMTPair(const GenMuonGMTPair& muonGmtPair) {
muPhi_ = muonGmtPair.muPhi_;
}

float GenMuonGMTPair::dR() {
float dEta = gmtmu_ ? (gmtEta_ - muEta_) : 999.;
float dPhi = gmtmu_ ? reco::deltaPhi(gmtPhi_, muPhi_) : 999.;
return sqrt(dEta * dEta + dPhi * dPhi);
float GenMuonGMTPair::dR2() {
if (!gmtmu_)
return 999.;
float dEta = gmtEta_ - muEta_;
float dPhi = reco::deltaPhi(gmtPhi_, muPhi_);
return dEta * dEta + dPhi * dPhi;
}

L1TPhase2MuonOffline::EtaRegion GenMuonGMTPair::etaRegion() const {
Expand Down Expand Up @@ -140,8 +141,6 @@ L1TPhase2MuonOffline::L1TPhase2MuonOffline(const ParameterSet& ps)
}
}

//_____________________________________________________________________
L1TPhase2MuonOffline::~L1TPhase2MuonOffline() {}
//----------------------------------------------------------------------
void L1TPhase2MuonOffline::dqmBeginRun(const edm::Run& run, const edm::EventSetup& iSetup) {
edm::LogInfo("L1TPhase2MuonOFfline") << "L1TPhase2MuonOffline::dqmBeginRun" << endl;
Expand Down Expand Up @@ -185,6 +184,8 @@ void L1TPhase2MuonOffline::analyze(const Event& iEvent, const EventSetup& eventS
fillControlHistos();

// Match each muon to a gen muon, if possible.
if (genmus.empty())
return;
edm::LogInfo("L1TPhase2MuonOffline") << "L1TPhase2MuonOffline::analyze() calling matchMuonsToGen() " << endl;
matchMuonsToGen(genmus);

Expand All @@ -208,6 +209,7 @@ void L1TPhase2MuonOffline::bookControlHistos(DQMStore::IBooker& ibooker, MuType
controlHistos_[mutype][kZ0] = ibooker.book1D(muonNames_[mutype] + "Z0", "MuonZ0; Z_{0}", 50, 0, 50.0);
controlHistos_[mutype][kD0] = ibooker.book1D(muonNames_[mutype] + "D0", "MuonD0; D_{0}", 50, 0, 200.);
}

void L1TPhase2MuonOffline::bookEfficiencyHistos(DQMStore::IBooker& ibooker, MuType mutype) {
edm::LogInfo("L1TPhase2MuonOffline") << "L1TPhase2MuonOffline::bookEfficiencyHistos()" << endl;

Expand Down Expand Up @@ -238,6 +240,7 @@ void L1TPhase2MuonOffline::bookEfficiencyHistos(DQMStore::IBooker& ibooker, MuTy
}
}
}

void L1TPhase2MuonOffline::bookResolutionHistos(DQMStore::IBooker& ibooker, MuType mutype) {
edm::LogInfo("L1TPhase2MuonOffline") << "L1TPhase2MuonOffline::bookResolutionHistos()" << endl;

Expand Down Expand Up @@ -279,24 +282,22 @@ void L1TPhase2MuonOffline::fillControlHistos() {
controlHistos_[kTkMuon][kD0]->Fill(lsb_d0 * muIt.hwD0());
}
}

void L1TPhase2MuonOffline::fillEfficiencyHistos() {
for (const auto& muIt : gmtSAMuonPairs_) {
auto eta = muIt.etaRegion();
for (const auto var : effTypes_) {
auto varToFill = muIt.getVar(var);
for (const auto& cut : cuts_) {
const auto gmtPtCut = cut.first;
const auto q = cut.second;

efficiencyDen_[kSAMuon][eta][q][var]->Fill(varToFill);
if (muIt.gmtPt() < 0)
continue; // gmt muon does not exits

continue; // there is not an assciated gmt muon
if (muIt.gmtQual() < q * 4)
continue; //quality requirements
const auto gmtPtCut = cut.first;
if (var != kEffPt && muIt.gmtPt() < gmtPtCut)
continue; // pt requirement

efficiencyNum_[kSAMuon][eta][q][var]->Fill(varToFill);
}
}
Expand All @@ -308,23 +309,21 @@ void L1TPhase2MuonOffline::fillEfficiencyHistos() {
for (const auto var : effTypes_) {
auto varToFill = muIt.getVar(var);
for (const auto& cut : cuts_) {
const auto gmtPtCut = cut.first;
const auto q = cut.second;

efficiencyDen_[kTkMuon][eta][q][var]->Fill(varToFill);
if (muIt.gmtPt() < 0)
continue; // gmt muon does not exits

continue; // there is not an assciated gmt muon
if (muIt.gmtQual() < q * 4)
continue; //quality requirements
const auto gmtPtCut = cut.first;
if (var != kEffPt && muIt.gmtPt() < gmtPtCut)
continue; // pt requirement

efficiencyNum_[kTkMuon][eta][q][var]->Fill(varToFill);
}
}
}
}

void L1TPhase2MuonOffline::fillResolutionHistos() {
for (const auto& muIt : gmtSAMuonPairs_) {
if (muIt.gmtPt() < 0)
Expand Down Expand Up @@ -358,6 +357,7 @@ void L1TPhase2MuonOffline::fillResolutionHistos() {
}
}
}

//_____________________________________________________________________
void L1TPhase2MuonOffline::matchMuonsToGen(std::vector<const reco::GenParticle*> genmus) {
gmtSAMuonPairs_.clear();
Expand All @@ -368,18 +368,24 @@ void L1TPhase2MuonOffline::matchMuonsToGen(std::vector<const reco::GenParticle*>
for (const reco::GenParticle* gen : genmus) {
edm::LogInfo("L1TPhase2MuonOffline") << "Looping on genmus: " << gen << endl;
GenMuonGMTPair pairBestCand(&(*gen), nullptr);
float dr2Best = maxGmtMuonDR_ * maxGmtMuonDR_;
for (auto& muIt : *gmtSAMuon_) {
GenMuonGMTPair pairTmpCand(&(*gen), &(muIt));
if ((pairTmpCand.dR() < maxGmtMuonDR_) && (pairTmpCand.dR() < pairBestCand.dR())) {
float dr2Tmp = pairTmpCand.dR2();
if (dr2Tmp < dr2Best) {
dr2Best = dr2Tmp;
pairBestCand = pairTmpCand;
}
}
gmtSAMuonPairs_.emplace_back(pairBestCand);

GenMuonGMTPair pairBestCand2(&(*gen), nullptr);
dr2Best = maxGmtMuonDR_ * maxGmtMuonDR_;
for (auto& tkmuIt : *gmtTkMuon_) {
GenMuonGMTPair pairTmpCand(&(*gen), &(tkmuIt));
if ((pairTmpCand.dR() < maxGmtMuonDR_) && (pairTmpCand.dR() < pairBestCand2.dR())) {
float dr2Tmp = pairTmpCand.dR2();
if (dr2Tmp < dr2Best) {
dr2Best = dr2Tmp;
pairBestCand2 = pairTmpCand;
}
}
Expand Down
12 changes: 6 additions & 6 deletions DQMOffline/L1Trigger/src/L1TRate_Offline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -505,14 +505,14 @@ bool L1TRate_Offline::getXSexFitsPython(const edm::ParameterSet& ps) {
foundFit = true;
break;
}
}

if (!foundFit) {
noError = false;
if (!foundFit) {
noError = false;

int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_PY_MISSING_FIT);
eCount++;
m_ErrorMonitor->getTH1()->SetBinContent(WARNING_PY_MISSING_FIT, eCount);
}
int eCount = m_ErrorMonitor->getTH1()->GetBinContent(WARNING_PY_MISSING_FIT);
eCount++;
m_ErrorMonitor->getTH1()->SetBinContent(WARNING_PY_MISSING_FIT, eCount);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion DQMOffline/L1Trigger/src/L1TStage2CaloLayer2Offline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ void L1TStage2CaloLayer2Offline::fillJets(edm::Event const& e, const unsigned in
minDeltaR = currentDeltaR;
closestL1Jet = *jet;
foundMatch = true;
break;
}
}
// }
Expand Down

0 comments on commit d80b1fb

Please sign in to comment.