CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonMiniAOD.cc
Go to the documentation of this file.
2 
3 
4 
5 
6 using namespace std;
7 using namespace edm;
8 
9 
10 
12  parameters = pSet;
13 
14  // the services:
15 
16  theMuonCollectionLabel_ = consumes<edm::View<pat::Muon> > (parameters.getParameter<edm::InputTag>("MuonCollection"));
17  theVertexLabel_ = consumes<reco::VertexCollection>(parameters.getParameter<edm::InputTag>("VertexLabel"));
18  theBeamSpotLabel_ = mayConsume<reco::BeamSpot> (parameters.getParameter<edm::InputTag>("BeamSpotLabel"));
19 
20 }
21 
22 
25  edm::Run const & /*iRun*/,
26  edm::EventSetup const & /* iSetup */){
27 
28  ibooker.cd();
29  ibooker.setCurrentFolder("Muons_miniAOD/MuonMiniAOD");
30 
31 
32  workingPoints.push_back(ibooker.book2D("tightMuons" ,"Tight Muons" ,2,1,3,2,1,3));
33  workingPoints.push_back(ibooker.book2D("mediumMuons","Medium Muons" ,2,1,3,2,1,3));
34  workingPoints.push_back(ibooker.book2D("looseMuons" ,"Loose Muons" ,2,1,3,2,1,3));
35  workingPoints.push_back(ibooker.book2D("highPtMuons","High Pt Muons",2,1,3,2,1,3));
36  workingPoints.push_back(ibooker.book2D("softMuons" ,"Soft Muons" ,2,1,3,2,1,3));
37 
38  for (std::vector<MonitorElement*>::iterator monitor = workingPoints.begin();
39  monitor != workingPoints.end(); ++monitor){
40  (*monitor)-> setBinLabel(1,"Pass",1);
41  (*monitor) -> setBinLabel(2,"No Pass",1);
42  (*monitor) -> setBinLabel(1,"Pass",2);
43  (*monitor) -> setBinLabel(2,"No Pass",2);
44  }
45 
46 }
47 
49 
50  if (WorkingPoint == "tightMuons")
51  return muon::isTightMuon(*muon1,thePrimaryVertex);
52  else if (WorkingPoint == "mediumMuons")
53  return muon::isMediumMuon(*muon1);
54  else if (WorkingPoint == "looseMuons")
55  return muon::isLooseMuon(*muon1);
56  else if (WorkingPoint == "highPtMuons")
57  return muon::isHighPtMuon(*muon1,thePrimaryVertex);
58  else if (WorkingPoint == "softMuons")
59  return muon::isSoftMuon(*muon1,thePrimaryVertex);
60  else{
61  LogInfo("RecoMuonValidator") << "[MuonMiniAOD]: MuonMiniAOD. Unknown WP, returning false.\n";
62  return false;
63  }
64 
65 }
66 
68 
69  if (WorkingPoint == "tightMuons")
70  return muon1 -> isTightMuon(thePrimaryVertex);
71  else if (WorkingPoint == "mediumMuons")
72  return muon1 -> isMediumMuon();
73  else if (WorkingPoint == "looseMuons")
74  return muon1 -> isLooseMuon();
75  else if (WorkingPoint == "highPtMuons")
76  return muon1 -> isHighPtMuon(thePrimaryVertex);
77  else if (WorkingPoint == "softMuons")
78  return muon1 -> isSoftMuon(thePrimaryVertex);
79  else{
80  LogInfo("RecoMuonValidator") << "[MuonMiniAOD]: MuonMiniAOD. Unknown WP, returning false.\n";
81  return false;
82  }
83 
84 }
85 
86 
88  LogTrace(metname)<<"[MuonMiniAOD] Analyze the mu";
89 
90 
91  // Take the muon container
93  iEvent.getByToken(theMuonCollectionLabel_,muons);
94 
95  //Vertex information
97  iEvent.getByToken(theVertexLabel_, vertex);
98 
99 
100  if(!muons.isValid()) return;
101 
102  reco::Vertex::Point posVtx;
103  reco::Vertex::Error errVtx;
104  unsigned int theIndexOfThePrimaryVertex = 999.;
105  if (!vertex.isValid()) {
106  LogTrace(metname) << "[EfficiencyAnalyzer] Could not find vertex collection" << std::endl;
107  for (unsigned int ind=0; ind<vertex->size(); ++ind) {
108  if ( (*vertex)[ind].isValid() && !((*vertex)[ind].isFake()) ) {
109  theIndexOfThePrimaryVertex = ind;
110  break;
111  }
112  }
113  }
114 
115  if (theIndexOfThePrimaryVertex<100) {
116  posVtx = ((*vertex)[theIndexOfThePrimaryVertex]).position();
117  errVtx = ((*vertex)[theIndexOfThePrimaryVertex]).error();
118  }
119  else {
120  LogInfo("RecoMuonValidator") << "reco::PrimaryVertex not found, use BeamSpot position instead\n";
121 
122  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
123  iEvent.getByToken(theBeamSpotLabel_,recoBeamSpotHandle);
124  reco::BeamSpot bs = *recoBeamSpotHandle;
125 
126  posVtx = bs.position();
127  errVtx(0,0) = bs.BeamWidthX();
128  errVtx(1,1) = bs.BeamWidthY();
129  errVtx(2,2) = bs.sigmaZ();
130  }
131 
132 
133 
134  const reco::Vertex thePrimaryVertex(posVtx,errVtx);
135 
136  for (edm::View<pat::Muon>::const_iterator muon1 = muons->begin(); muon1 != muons->end(); ++muon1){
137 
138  for (std::vector<MonitorElement*>::iterator monitor = workingPoints.begin();
139  monitor != workingPoints.end(); ++monitor){
140  int Pass_A = 0;
141  int Pass_B = 0;
142  if (PassesCut_A(muon1, thePrimaryVertex,(*monitor)->getName()))
143  Pass_A = 1;
144  else
145  Pass_A = 2;
146  if (PassesCut_B(muon1, thePrimaryVertex,(*monitor)->getName()))
147  Pass_B = 1;
148  else
149  Pass_B = 2;
150 
151  (*monitor)->Fill(Pass_A,Pass_B);
152  }
153 
154  }
155 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
const std::string metname
virtual ~MuonMiniAOD()
Destructor.
Definition: MuonMiniAOD.cc:23
void cd(void)
Definition: DQMStore.cc:269
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:43
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: MuonMiniAOD.cc:24
void analyze(const edm::Event &, const edm::EventSetup &) override
Inizialize parameters for histo binning.
Definition: MuonMiniAOD.cc:87
bool isMediumMuon(const reco::Muon &)
MuonMiniAOD(const edm::ParameterSet &)
Constructor.
Definition: MuonMiniAOD.cc:11
bool isLooseMuon(const reco::Muon &)
bool isSoftMuon(const reco::Muon &, const reco::Vertex &)
int iEvent
Definition: GenABIO.cc:230
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:86
bool isValid() const
Definition: HandleBase.h:75
#define LogTrace(id)
bool isHighPtMuon(const reco::Muon &, const reco::Vertex &)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
double sigmaZ() const
sigma z
Definition: BeamSpot.h:80
double BeamWidthY() const
beam width Y
Definition: BeamSpot.h:88
tuple muons
Definition: patZpeak.py:38
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
static int position[264][3]
Definition: ReadPGInfo.cc:509
const Point & position() const
position
Definition: BeamSpot.h:62
bool PassesCut_A(edm::View< pat::Muon >::const_iterator, reco::Vertex, TString)
Definition: MuonMiniAOD.cc:48
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
bool PassesCut_B(edm::View< pat::Muon >::const_iterator, reco::Vertex, TString)
Definition: MuonMiniAOD.cc:67
Definition: Run.h:42