File indexing completed on 2023-03-17 10:58:13
0001 #include "DQMOffline/Muon/interface/MuonMiniAOD.h"
0002
0003 using namespace std;
0004 using namespace edm;
0005
0006 MuonMiniAOD::MuonMiniAOD(const edm::ParameterSet& pSet) {
0007 parameters = pSet;
0008
0009
0010
0011 theMuonCollectionLabel_ = consumes<edm::View<pat::Muon> >(parameters.getParameter<edm::InputTag>("MuonCollection"));
0012 theVertexLabel_ = consumes<reco::VertexCollection>(parameters.getParameter<edm::InputTag>("VertexLabel"));
0013 theBeamSpotLabel_ = mayConsume<reco::BeamSpot>(parameters.getParameter<edm::InputTag>("BeamSpotLabel"));
0014 }
0015
0016 MuonMiniAOD::~MuonMiniAOD() {}
0017 void MuonMiniAOD::bookHistograms(DQMStore::IBooker& ibooker,
0018 edm::Run const& ,
0019 edm::EventSetup const& ) {
0020 ibooker.cd();
0021 ibooker.setCurrentFolder("Muons_miniAOD/MuonMiniAOD");
0022
0023 workingPoints.push_back(ibooker.book2D("tightMuons", "Tight Muons", 2, 1, 3, 2, 1, 3));
0024 workingPoints.push_back(ibooker.book2D("mediumMuons", "Medium Muons", 2, 1, 3, 2, 1, 3));
0025 workingPoints.push_back(ibooker.book2D("looseMuons", "Loose Muons", 2, 1, 3, 2, 1, 3));
0026 workingPoints.push_back(ibooker.book2D("highPtMuons", "High Pt Muons", 2, 1, 3, 2, 1, 3));
0027 workingPoints.push_back(ibooker.book2D("softMuons", "Soft Muons", 2, 1, 3, 2, 1, 3));
0028
0029 for (std::vector<MonitorElement*>::iterator monitor = workingPoints.begin(); monitor != workingPoints.end();
0030 ++monitor) {
0031 (*monitor)->setBinLabel(1, "Pass", 1);
0032 (*monitor)->setBinLabel(2, "No Pass", 1);
0033 (*monitor)->setBinLabel(1, "Pass", 2);
0034 (*monitor)->setBinLabel(2, "No Pass", 2);
0035 }
0036 }
0037
0038 bool MuonMiniAOD::PassesCut_A(edm::View<pat::Muon>::const_iterator muon1,
0039 reco::Vertex thePrimaryVertex,
0040 TString WorkingPoint) {
0041 if (WorkingPoint == "tightMuons")
0042 return muon::isTightMuon(*muon1, thePrimaryVertex);
0043 else if (WorkingPoint == "mediumMuons")
0044 return muon::isMediumMuon(*muon1);
0045 else if (WorkingPoint == "looseMuons")
0046 return muon::isLooseMuon(*muon1);
0047 else if (WorkingPoint == "highPtMuons")
0048 return muon::isHighPtMuon(*muon1, thePrimaryVertex);
0049 else if (WorkingPoint == "softMuons")
0050 return muon::isSoftMuon(*muon1, thePrimaryVertex);
0051 else {
0052 LogInfo("RecoMuonValidator") << "[MuonMiniAOD]: MuonMiniAOD. Unknown WP, returning false.\n";
0053 return false;
0054 }
0055 }
0056
0057 bool MuonMiniAOD::PassesCut_B(edm::View<pat::Muon>::const_iterator muon1,
0058 reco::Vertex thePrimaryVertex,
0059 TString WorkingPoint) {
0060 if (WorkingPoint == "tightMuons")
0061 return muon1->isTightMuon(thePrimaryVertex);
0062 else if (WorkingPoint == "mediumMuons")
0063 return muon1->isMediumMuon();
0064 else if (WorkingPoint == "looseMuons")
0065 return muon1->isLooseMuon();
0066 else if (WorkingPoint == "highPtMuons")
0067 return muon1->isHighPtMuon(thePrimaryVertex);
0068 else if (WorkingPoint == "softMuons")
0069 return muon1->isSoftMuon(thePrimaryVertex);
0070 else {
0071 LogInfo("RecoMuonValidator") << "[MuonMiniAOD]: MuonMiniAOD. Unknown WP, returning false.\n";
0072 return false;
0073 }
0074 }
0075
0076 void MuonMiniAOD::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0077 LogTrace(metname) << "[MuonMiniAOD] Analyze the mu";
0078
0079
0080 edm::Handle<edm::View<pat::Muon> > muons;
0081 iEvent.getByToken(theMuonCollectionLabel_, muons);
0082
0083
0084 edm::Handle<reco::VertexCollection> vertex;
0085 iEvent.getByToken(theVertexLabel_, vertex);
0086
0087 if (!muons.isValid())
0088 return;
0089
0090 reco::Vertex::Point posVtx;
0091 reco::Vertex::Error errVtx;
0092 unsigned int theIndexOfThePrimaryVertex = 999.;
0093 if (!vertex.isValid()) {
0094 LogTrace(metname) << "[EfficiencyAnalyzer] Could not find vertex collection" << std::endl;
0095 for (unsigned int ind = 0; ind < vertex->size(); ++ind) {
0096 if ((*vertex)[ind].isValid() && !((*vertex)[ind].isFake())) {
0097 theIndexOfThePrimaryVertex = ind;
0098 break;
0099 }
0100 }
0101 }
0102
0103 if (theIndexOfThePrimaryVertex < 100) {
0104 posVtx = ((*vertex)[theIndexOfThePrimaryVertex]).position();
0105 errVtx = ((*vertex)[theIndexOfThePrimaryVertex]).error();
0106 } else {
0107 LogInfo("RecoMuonValidator") << "reco::PrimaryVertex not found, use BeamSpot position instead\n";
0108
0109 edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
0110 iEvent.getByToken(theBeamSpotLabel_, recoBeamSpotHandle);
0111 reco::BeamSpot bs = *recoBeamSpotHandle;
0112
0113 posVtx = bs.position();
0114 errVtx(0, 0) = bs.BeamWidthX();
0115 errVtx(1, 1) = bs.BeamWidthY();
0116 errVtx(2, 2) = bs.sigmaZ();
0117 }
0118
0119 const reco::Vertex thePrimaryVertex(posVtx, errVtx);
0120
0121 for (edm::View<pat::Muon>::const_iterator muon1 = muons->begin(); muon1 != muons->end(); ++muon1) {
0122 for (std::vector<MonitorElement*>::iterator monitor = workingPoints.begin(); monitor != workingPoints.end();
0123 ++monitor) {
0124 int Pass_A = 0;
0125 int Pass_B = 0;
0126 if (PassesCut_A(muon1, thePrimaryVertex, (*monitor)->getName()))
0127 Pass_A = 1;
0128 else
0129 Pass_A = 2;
0130 if (PassesCut_B(muon1, thePrimaryVertex, (*monitor)->getName()))
0131 Pass_B = 1;
0132 else
0133 Pass_B = 2;
0134
0135 (*monitor)->Fill(Pass_A, Pass_B);
0136 }
0137 }
0138 }