Skip to content

Commit

Permalink
Merge pull request cms-sw#95 from gpetruc/update_to_l1t_phase2_v3_4_36
Browse files Browse the repository at this point in the history
Update to l1t-phase2-v3.4.36
  • Loading branch information
gpetruc authored Jul 11, 2022
2 parents 0a35418 + 1e491a1 commit 9a7c5f5
Show file tree
Hide file tree
Showing 253 changed files with 2,613 additions and 11,391 deletions.
210 changes: 210 additions & 0 deletions DQMOffline/L1Trigger/interface/L1TPhase2MuonOffline.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
#ifndef DQMOFFLINE_L1TRIGGER_L1TPHASE2MUONOFFLINE_H
#define DQMOFFLINE_L1TRIGGER_L1TPHASE2MUONOFFLINE_H

/**
* \file L1TPhase2MuonOffline.h
*
* \author S. Folgueras
*
*/

// 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 "MuonAnalysis/MuonAssociators/interface/PropagateToMuon.h"
#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>
#include <vector>

class GenMuonGMTPair;

//
// DQM class declaration
//

class L1TPhase2MuonOffline : public DQMEDAnalyzer {
public:
L1TPhase2MuonOffline(const edm::ParameterSet& ps);
~L1TPhase2MuonOffline() override;

enum MuType { kSAMuon, kTkMuon, kNMuTypes };
enum VarType { kPt, kEta, kPhi, kIso, kQual, kZ0, kD0, kNVarTypes };
enum EffType { kEffPt, kEffPhi, kEffEta, kEffTypes };
enum ResType { kResPt, kRes1OverPt, kResQOverPt, kResPhi, kResEta, kResCh, kNResTypes };
enum EtaRegion { kEtaRegionAll, kEtaRegionBmtf, kEtaRegionOmtf, kEtaRegionEmtf, kNEtaRegions };
enum QualLevel { kQualOpen, kQualDouble, kQualSingle, kNQualLevels };

protected:
void dqmBeginRun(const edm::Run& run, const edm::EventSetup& iSetup) override;
void analyze(const edm::Event& e, const edm::EventSetup& c) override;

void bookControlHistos(DQMStore::IBooker&, MuType type);
void bookEfficiencyHistos(DQMStore::IBooker& ibooker, MuType type);
void bookResolutionHistos(DQMStore::IBooker& ibooker, MuType type);
void bookHistograms(DQMStore::IBooker& ibooker, const edm::Run& run, const edm::EventSetup& iSetup) override;


//Fill Histos
void fillControlHistos();
void fillEfficiencyHistos();
void fillResolutionHistos();


private:
// Cut and Matching
void getMuonGmtPairs(edm::Handle<l1t::MuonBxCollection>& gmtCands);


// Handles and Tokens
edm::EDGetTokenT<l1t::SAMuonCollection> gmtMuonToken_;
edm::EDGetTokenT<l1t::TrackerMuonCollection> gmtTkMuonToken_;
edm::EDGetTokenT<std::vector<reco::GenParticle>> genParticleToken_;

edm::Handle<l1t::SAMuonCollection> gmtSAMuon_;
edm::Handle<l1t::TrackerMuonCollection> gmtTkMuon_;
edm::Handle<std::vector<reco::GenParticle>> genparticles_;

// PropagateToMuon muonpropagator_;

// vectors of enum values to loop over (and store quantities)
const std::vector<MuType> muonTypes_;
const std::vector<EffType> effTypes_;
const std::vector<ResType> resTypes_;
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<ResType, std::string> resNames_;
std::map<ResType, std::string> resLabels_;
std::map<EtaRegion, std::string> etaNames_;
std::map<QualLevel, std::string> qualNames_;
std::map<MuType, std::string> muonNames_;

// config params
std::string histFolder_;
std::vector<edm::ParameterSet> cutsVPSet_;

std::vector<double> effVsPtBins_;
std::vector<double> effVsPhiBins_;
std::vector<double> effVsEtaBins_;

bool useAtVtxCoord_;
bool isParticleGun_;
float maxGmtMuonDR_;

// Helper methods
void matchMuonsToGen(std::vector<const reco::GenParticle*> genmus);
std::vector<float> getHistBinsEff(EffType eff);
std::tuple<int, double, double> getHistBinsRes(ResType res);

// Keys for histogram maps
/*typedef std::tuple<MuType, ResType, EtaRegion, QualLevel> histoKeyResType_;
typedef std::tuple<MuType, EffType, int, EtaRegion, QualLevel> histoKeyEffType_;
typedef std::tuple<MuType, VarType> histoKeyVarType_;
*/
// Histograms and histogram containers
// std::map<std::tuple<MuType, EffType, int, EtaRegion, QualLevel>, MonitorElement*> efficiencyHistos_;
// std::map<std::tuple<MuType, ResType, EtaRegion, QualLevel>, MonitorElement*> resolutionHistos_;
// TH1F* efficiencyNum_[kNMuTypes][kNEtaRegions][kNQualLevels][kEffTypes];
// TH1F* efficiencyDen_[kNMuTypes][kNEtaRegions][kNQualLevels][kEffTypes];

MonitorElement* efficiencyNum_[kNMuTypes][kNEtaRegions][kNQualLevels][kEffTypes];
MonitorElement* efficiencyDen_[kNMuTypes][kNEtaRegions][kNQualLevels][kEffTypes];
MonitorElement* resolutionHistos_[kNMuTypes][kNEtaRegions][kNQualLevels][kNResTypes];
MonitorElement* controlHistos_[kNMuTypes][kNVarTypes];

// helper variables
std::vector<GenMuonGMTPair> gmtSAMuonPairs_;
std::vector<GenMuonGMTPair> gmtTkMuonPairs_;
std::vector<std::pair<int, QualLevel>> cuts_;

float lsb_pt ;
float lsb_phi;
float lsb_eta;
float lsb_z0 ;
float lsb_d0 ;
};

//
// helper class to manage GMT-GenMuon pairing
//
class GenMuonGMTPair {
public:
GenMuonGMTPair(const reco::GenParticle* mu, const l1t::L1Candidate* gmtmu);
GenMuonGMTPair(const GenMuonGMTPair& muongmtPair);
~GenMuonGMTPair(){};

float dR();
float pt() const { return mu_->pt(); };
float eta() const { return mu_->eta(); };
float phi() const { return mu_->phi(); };
int charge() const { return mu_->charge(); };

// Now properties of the L1 candidate:
float gmtPt() const { return gmtmu_ ? gmtmu_->pt() : -1.; };
float gmtEta() const { return gmtmu_ ? gmtEta_ : -5.; };
float gmtPhi() const { return gmtmu_ ? gmtPhi_ : -5.; };
int gmtCharge() const { return gmtmu_ ? gmtmu_->charge() : -5; };
int gmtQual() const { return gmtmu_ ? gmtmu_->hwQual() : -1; };

L1TPhase2MuonOffline::EtaRegion etaRegion() const;
double getDeltaVar(const L1TPhase2MuonOffline::ResType) const;
double getVar(const L1TPhase2MuonOffline::EffType) const;

private:
const reco::GenParticle* mu_;
const l1t::L1Candidate* gmtmu_;

// L1T muon eta and phi coordinates to be used
// Can be the coordinates from the 2nd muon station or from the vertex
float gmtEta_;
float gmtPhi_;

float muEta_;
float muPhi_;
};


#endif
4 changes: 2 additions & 2 deletions DQMOffline/L1Trigger/interface/L1TPhase2OuterTrackerTkMET.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "DataFormats/Common/interface/DetSetVectorNew.h"
#include "DataFormats/L1TrackTrigger/interface/TTTypes.h"
// #include "DataFormats/L1TVertex/interface/Vertex.h"
#include "DataFormats/L1TCorrelator/interface/TkPrimaryVertex.h"
#include "DataFormats/L1Trigger/interface/VertexWord.h"

class DQMStore;
class L1TPhase2OuterTrackerTkMET : public DQMEDAnalyzer {
Expand All @@ -41,7 +41,7 @@ class L1TPhase2OuterTrackerTkMET : public DQMEDAnalyzer {
private:
edm::ParameterSet conf_;
const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> m_topoToken;
edm::EDGetTokenT<l1t::TkPrimaryVertexCollection> pvToken;
edm::EDGetTokenT<l1t::VertexWordCollection> pvToken;
edm::EDGetTokenT<std::vector<TTTrack<Ref_Phase2TrackerDigi_> > > ttTrackToken_;

float maxZ0; // in cm
Expand Down
37 changes: 37 additions & 0 deletions DQMOffline/L1Trigger/python/L1TPhase2MuonDQMEfficiency_cfi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import FWCore.ParameterSet.Config as cms

# generate the efficiency strings for the DQMGenericClient from the pt and quality cuts
def generateEfficiencyStrings(ptQualCuts):
numDenDir = "nums_and_dens/"
varStrings = ['Pt', 'Eta', 'Phi']
etaStrings = ['etaMin0_etaMax0p83', 'etaMin0p83_etaMax1p24', 'etaMin1p24_etaMax2p4', 'etaMin0_etaMax2p4']
qualStrings = {'qualOpen', 'qualDouble', 'qualSingle'}
muonStrings = ['SAMuon','TkMuon']

efficiencyStrings = []

for muonString in muonStrings:
for qualString in qualStrings:
for etaString in etaStrings:
effNumDenPrefix = numDenDir+"Eff_"+muonString+"_"+etaString+"_"+qualString+"_"
effNamePrefix = "efficiencies/eff_"+muonString+"_"+etaString+"_"+qualString+"_"

for varString in varStrings:
effDenName = effNumDenPrefix+varString+"_Den"
effNumName = effNumDenPrefix+varString+"_Num"
effName = effNamePrefix+varString

efficiencyStrings.append(effName+" '"+effName+";;L1 muon efficiency' "+effNumName+" "+effDenName)
return efficiencyStrings

from DQMServices.Core.DQMEDHarvester import DQMEDHarvester
from DQMOffline.L1Trigger.L1TPhase2MuonOffline_cfi import ptQualCuts

l1tPhase2MuonEfficiency = DQMEDHarvester("DQMGenericClient",
subDirs = cms.untracked.vstring(["L1T/L1TPhase2/Muons/SAMuon","L1T/L1TPhase2/Muons/TkMuon"]),
efficiency = cms.vstring(),
efficiencyProfile = cms.untracked.vstring(generateEfficiencyStrings(ptQualCuts)),
resolution = cms.vstring(),
outputFileName = cms.untracked.string(""),
verbose = cms.untracked.uint32(4)
)
52 changes: 52 additions & 0 deletions DQMOffline/L1Trigger/python/L1TPhase2MuonOffline_cfi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from builtins import range
import FWCore.ParameterSet.Config as cms

# define binning for efficiency plots
# pt
import itertools
effVsPtBins=list(itertools.chain(range(0, 30, 1), range(30, 50, 2),
range(50, 70, 5), range(70, 100, 10),
range(100, 200, 25), range(200, 300, 50),
range(300, 500, 100), range(500, 700, 200),
range(700, 1000, 300)))
effVsPtBins.append(1000)

# phi
nPhiBins = 34
phiMin = -3.4
phiMax = 3.4
effVsPhiBins = [i*(phiMax-phiMin)/nPhiBins + phiMin for i in range(nPhiBins+1)]

# eta
nEtaBins = 50
etaMin = -2.5
etaMax = 2.5
effVsEtaBins = [i*(etaMax-etaMin)/nEtaBins + etaMin for i in range(nEtaBins+1)]

# vtx
effVsVtxBins = range(0, 101)

# A list of pt cut + quality cut pairs for which efficiency plots should be made
ptQualCuts = [[22, 12], [15, 8], [3, 4]]
cutsPSets = []
for ptQualCut in ptQualCuts:
cutsPSets.append(cms.untracked.PSet(ptCut = cms.untracked.int32(ptQualCut[0]),
qualCut = cms.untracked.int32(ptQualCut[1])))

from DQMServices.Core.DQMEDAnalyzer import DQMEDAnalyzer
l1tPhase2MuonOffline = DQMEDAnalyzer('L1TPhase2MuonOffline',
histFolder = cms.untracked.string('L1T/L1TPhase2/Muons/'),
cuts = cms.untracked.VPSet(cutsPSets),
useL1AtVtxCoord = cms.untracked.bool(False),

genParticlesInputTag = cms.untracked.InputTag("genParticles"),
gmtMuonToken = cms.InputTag("L1SAMuonsGmt", "promptSAMuons"),
gmtTkMuonToken = cms.InputTag("L1TkMuonsGmt",""),

efficiencyVsPtBins = cms.untracked.vdouble(effVsPtBins),
efficiencyVsPhiBins = cms.untracked.vdouble(effVsPhiBins),
efficiencyVsEtaBins = cms.untracked.vdouble(effVsEtaBins),
efficiencyVsVtxBins = cms.untracked.vdouble(effVsVtxBins),
)


8 changes: 5 additions & 3 deletions DQMOffline/L1Trigger/python/L1TPhase2Offline_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
OuterTrackerTkMET = DQMEDAnalyzer('L1TPhase2OuterTrackerTkMET',
TopFolderName = cms.string('L1T/L1TPhase2/'),
TTTracksTag = cms.InputTag("TTTracksFromTrackletEmulation", "Level1TTTracks"),
L1VertexInputTag = cms.InputTag("L1TkPrimaryVertex"),
L1VertexInputTag = cms.InputTag("L1VertexFinderEmulator", "l1verticesEmulation"),
maxZ0 = cms.double ( 15. ) , # in cm
maxEta = cms.double ( 2.4 ) ,
chi2dofMax = cms.double( 10. ),
Expand Down Expand Up @@ -131,10 +131,12 @@
xmax=cms.untracked.double(5.),
),
),

)

from DQMOffline.L1Trigger.L1TPhase2MuonOffline_cfi import *

l1tPhase2OfflineDQM = cms.Sequence(
l1tPhase2CorrelatorOfflineDQM +
OuterTrackerTkMET
OuterTrackerTkMET +
l1tPhase2MuonOffline
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from DQMOffline.L1Trigger.L1TTauDiff_cfi import *

from DQMOffline.L1Trigger.L1TMuonDQMEfficiency_cff import *
from DQMOffline.L1Trigger.L1TPhase2MuonDQMEfficiency_cfi import *

# harvesting sequence for all datasets
DQMHarvestL1TMon = cms.Sequence(
Expand Down Expand Up @@ -52,6 +53,6 @@

# harvesting sequence for phase 2
DQMHarvestL1TPhase2 = cms.Sequence(

l1tPhase2MuonEfficiency
)

Loading

0 comments on commit 9a7c5f5

Please sign in to comment.