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 }
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
bool isMediumMuon(const reco::Muon &, bool run2016_hip_mitigation=false)
const std::string metname
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:45
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: MuonMiniAOD.cc:17
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:214
void analyze(const edm::Event &, const edm::EventSetup &) override
Inizialize parameters for histo binning.
Definition: MuonMiniAOD.cc:76
MuonMiniAOD(const edm::ParameterSet &)
Constructor.
Definition: MuonMiniAOD.cc:6
#define LogTrace(id)
bool isLooseMuon(const reco::Muon &)
int iEvent
Definition: GenABIO.cc:224
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
bool isSoftMuon(const reco::Muon &, const reco::Vertex &, bool run2016_hip_mitigation=false)
~MuonMiniAOD() override
Destructor.
Definition: MuonMiniAOD.cc:16
Log< level::Info, false > LogInfo
bool isHighPtMuon(const reco::Muon &, const reco::Vertex &)
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:212
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:88
static int position[264][3]
Definition: ReadPGInfo.cc:289
bool PassesCut_A(edm::View< pat::Muon >::const_iterator, reco::Vertex, TString)
Definition: MuonMiniAOD.cc:38
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
bool PassesCut_B(edm::View< pat::Muon >::const_iterator, reco::Vertex, TString)
Definition: MuonMiniAOD.cc:57
Definition: Run.h:45