CMS 3D CMS Logo

MuonMiniAOD.cc
Go to the documentation of this file.
2 
3 using namespace std;
4 using namespace edm;
5 
7  parameters = pSet;
8 
9  // the services:
10 
11  theMuonCollectionLabel_ = consumes<edm::View<pat::Muon> >(parameters.getParameter<edm::InputTag>("MuonCollection"));
12  theVertexLabel_ = consumes<reco::VertexCollection>(parameters.getParameter<edm::InputTag>("VertexLabel"));
13  theBeamSpotLabel_ = mayConsume<reco::BeamSpot>(parameters.getParameter<edm::InputTag>("BeamSpotLabel"));
14 }
15 
18  edm::Run const& /*iRun*/,
19  edm::EventSetup const& /* iSetup */) {
20  ibooker.cd();
21  ibooker.setCurrentFolder("Muons_miniAOD/MuonMiniAOD");
22 
23  workingPoints.push_back(ibooker.book2D("tightMuons", "Tight Muons", 2, 1, 3, 2, 1, 3));
24  workingPoints.push_back(ibooker.book2D("mediumMuons", "Medium Muons", 2, 1, 3, 2, 1, 3));
25  workingPoints.push_back(ibooker.book2D("looseMuons", "Loose Muons", 2, 1, 3, 2, 1, 3));
26  workingPoints.push_back(ibooker.book2D("highPtMuons", "High Pt Muons", 2, 1, 3, 2, 1, 3));
27  workingPoints.push_back(ibooker.book2D("softMuons", "Soft Muons", 2, 1, 3, 2, 1, 3));
28 
29  for (std::vector<MonitorElement*>::iterator monitor = workingPoints.begin(); monitor != workingPoints.end();
30  ++monitor) {
31  (*monitor)->setBinLabel(1, "Pass", 1);
32  (*monitor)->setBinLabel(2, "No Pass", 1);
33  (*monitor)->setBinLabel(1, "Pass", 2);
34  (*monitor)->setBinLabel(2, "No Pass", 2);
35  }
36 }
37 
39  reco::Vertex thePrimaryVertex,
40  TString WorkingPoint) {
41  if (WorkingPoint == "tightMuons")
42  return muon::isTightMuon(*muon1, thePrimaryVertex);
43  else if (WorkingPoint == "mediumMuons")
44  return muon::isMediumMuon(*muon1);
45  else if (WorkingPoint == "looseMuons")
46  return muon::isLooseMuon(*muon1);
47  else if (WorkingPoint == "highPtMuons")
48  return muon::isHighPtMuon(*muon1, thePrimaryVertex);
49  else if (WorkingPoint == "softMuons")
50  return muon::isSoftMuon(*muon1, thePrimaryVertex);
51  else {
52  LogInfo("RecoMuonValidator") << "[MuonMiniAOD]: MuonMiniAOD. Unknown WP, returning false.\n";
53  return false;
54  }
55 }
56 
58  reco::Vertex thePrimaryVertex,
59  TString WorkingPoint) {
60  if (WorkingPoint == "tightMuons")
61  return muon1->isTightMuon(thePrimaryVertex);
62  else if (WorkingPoint == "mediumMuons")
63  return muon1->isMediumMuon();
64  else if (WorkingPoint == "looseMuons")
65  return muon1->isLooseMuon();
66  else if (WorkingPoint == "highPtMuons")
67  return muon1->isHighPtMuon(thePrimaryVertex);
68  else if (WorkingPoint == "softMuons")
69  return muon1->isSoftMuon(thePrimaryVertex);
70  else {
71  LogInfo("RecoMuonValidator") << "[MuonMiniAOD]: MuonMiniAOD. Unknown WP, returning false.\n";
72  return false;
73  }
74 }
75 
77  LogTrace(metname) << "[MuonMiniAOD] Analyze the mu";
78 
79  // Take the muon container
81  iEvent.getByToken(theMuonCollectionLabel_, muons);
82 
83  //Vertex information
85  iEvent.getByToken(theVertexLabel_, vertex);
86 
87  if (!muons.isValid())
88  return;
89 
90  reco::Vertex::Point posVtx;
91  reco::Vertex::Error errVtx;
92  unsigned int theIndexOfThePrimaryVertex = 999.;
93  if (!vertex.isValid()) {
94  LogTrace(metname) << "[EfficiencyAnalyzer] Could not find vertex collection" << std::endl;
95  for (unsigned int ind = 0; ind < vertex->size(); ++ind) {
96  if ((*vertex)[ind].isValid() && !((*vertex)[ind].isFake())) {
97  theIndexOfThePrimaryVertex = ind;
98  break;
99  }
100  }
101  }
102 
103  if (theIndexOfThePrimaryVertex < 100) {
104  posVtx = ((*vertex)[theIndexOfThePrimaryVertex]).position();
105  errVtx = ((*vertex)[theIndexOfThePrimaryVertex]).error();
106  } else {
107  LogInfo("RecoMuonValidator") << "reco::PrimaryVertex not found, use BeamSpot position instead\n";
108 
109  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
110  iEvent.getByToken(theBeamSpotLabel_, recoBeamSpotHandle);
111  reco::BeamSpot bs = *recoBeamSpotHandle;
112 
113  posVtx = bs.position();
114  errVtx(0, 0) = bs.BeamWidthX();
115  errVtx(1, 1) = bs.BeamWidthY();
116  errVtx(2, 2) = bs.sigmaZ();
117  }
118 
119  const reco::Vertex thePrimaryVertex(posVtx, errVtx);
120 
121  for (edm::View<pat::Muon>::const_iterator muon1 = muons->begin(); muon1 != muons->end(); ++muon1) {
122  for (std::vector<MonitorElement*>::iterator monitor = workingPoints.begin(); monitor != workingPoints.end();
123  ++monitor) {
124  int Pass_A = 0;
125  int Pass_B = 0;
126  if (PassesCut_A(muon1, thePrimaryVertex, (*monitor)->getName()))
127  Pass_A = 1;
128  else
129  Pass_A = 2;
130  if (PassesCut_B(muon1, thePrimaryVertex, (*monitor)->getName()))
131  Pass_B = 1;
132  else
133  Pass_B = 2;
134 
135  (*monitor)->Fill(Pass_A, Pass_B);
136  }
137  }
138 }
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
MuonMiniAOD::PassesCut_A
bool PassesCut_A(edm::View< pat::Muon >::const_iterator, reco::Vertex, TString)
Definition: MuonMiniAOD.cc:38
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:29
muon::isSoftMuon
bool isSoftMuon(const reco::Muon &, const reco::Vertex &, bool run2016_hip_mitigation=false)
Definition: MuonSelectors.cc:916
edm::Run
Definition: Run.h:45
MuonMiniAOD::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: MuonMiniAOD.cc:17
edm
HLT enums.
Definition: AlignableModifier.h:19
reco::Vertex::Error
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:44
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
MuonMiniAOD::MuonMiniAOD
MuonMiniAOD(const edm::ParameterSet &)
Constructor.
Definition: MuonMiniAOD.cc:6
edm::Handle
Definition: AssociativeIterator.h:50
relativeConstraints.error
error
Definition: relativeConstraints.py:53
EgammaCutBasedEleId::WorkingPoint
WorkingPoint
Definition: EGammaCutBasedEleId.h:34
cms::cuda::bs
bs
Definition: HistoContainer.h:127
MuonMiniAOD::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Inizialize parameters for histo binning.
Definition: MuonMiniAOD.cc:76
muon::isLooseMuon
bool isLooseMuon(const reco::Muon &)
Definition: MuonSelectors.cc:895
reco::BeamSpot
Definition: BeamSpot.h:21
dqm::implementation::NavigatorBase::cd
virtual void cd()
Definition: DQMStore.cc:29
muon::isHighPtMuon
bool isHighPtMuon(const reco::Muon &, const reco::Vertex &)
Definition: MuonSelectors.cc:933
bphysicsOniaDQM_cfi.vertex
vertex
Definition: bphysicsOniaDQM_cfi.py:7
edm::ParameterSet
Definition: ParameterSet.h:47
PDWG_TauSkim_cff.workingPoints
workingPoints
Definition: PDWG_TauSkim_cff.py:15
muon::isTightMuon
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
Definition: MuonSelectors.cc:880
beam_dqm_sourceclient-live_cfg.monitor
monitor
Definition: beam_dqm_sourceclient-live_cfg.py:242
position
static int position[264][3]
Definition: ReadPGInfo.cc:289
iEvent
int iEvent
Definition: GenABIO.cc:224
MuonMiniAOD::~MuonMiniAOD
~MuonMiniAOD() override
Destructor.
Definition: MuonMiniAOD.cc:16
edm::EventSetup
Definition: EventSetup.h:57
muon::isMediumMuon
bool isMediumMuon(const reco::Muon &, bool run2016_hip_mitigation=false)
Definition: MuonSelectors.cc:899
reco::Vertex::Point
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
std
Definition: JetResolutionObject.h:76
MuonMiniAOD.h
dqm::implementation::IBooker::book2D
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:177
dqm::implementation::IBooker
Definition: DQMStore.h:43
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
MuonMiniAOD::PassesCut_B
bool PassesCut_B(edm::View< pat::Muon >::const_iterator, reco::Vertex, TString)
Definition: MuonMiniAOD.cc:57
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:224
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
reco::Vertex
Definition: Vertex.h:35
metname
const std::string metname
Definition: MuonSeedOrcaPatternRecognition.cc:40