CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EfficiencyAnalyzer.cc
Go to the documentation of this file.
1 /* This Class Header */
3 
4 /* Collaborating Class Header */
15 
16 using namespace edm;
17 
18 #include "TLorentzVector.h"
19 #include "TFile.h"
20 #include <vector>
21 #include "math.h"
22 
23 
26 
27 
30 
31 /* C++ Headers */
32 #include <iostream>
33 #include <fstream>
34 #include <cmath>
35 using namespace std;
36 using namespace edm;
37 
39  parameters = pSet;
40 }
41 
43 
45 #ifdef DEBUG
46  cout << "[EfficiencyAnalyzer] Parameters initialization" <<endl;
47 #endif
48  metname = "EfficiencyAnalyzer";
49  LogTrace(metname)<<"[EfficiencyAnalyzer] Parameters initialization";
50  dbe->setCurrentFolder("Muons/EfficiencyAnalyzer");
51 
54 
55 
56  ptBin_ = parameters.getParameter<int>("ptBin");
57  ptMin_ = parameters.getParameter<double>("ptMin");
58  ptMax_ = parameters.getParameter<double>("ptMax");
59 
60  etaBin_ = parameters.getParameter<int>("etaBin");
61  etaMin_ = parameters.getParameter<double>("etaMin");
62  etaMax_ = parameters.getParameter<double>("etaMax");
63 
64  phiBin_ = parameters.getParameter<int>("phiBin");
65  phiMin_ = parameters.getParameter<double>("phiMin");
66  phiMax_ = parameters.getParameter<double>("phiMax");
67 
68 
69 
70  test_TightMu_Minv = dbe->book1D("test_TightMu_Minv" ,"Minv",50,70,110);
71 
72  h_allProbes_pt = dbe->book1D("allProbes_pt","All Probes Pt", ptBin_, ptMin_, ptMax_);
73  h_allProbes_barrel_pt = dbe->book1D("allProbes_barrel_pt","Barrel: all Probes Pt", ptBin_, ptMin_, ptMax_);
74  h_allProbes_endcap_pt = dbe->book1D("allProbes_endcap_pt","Endcap: all Probes Pt", ptBin_, ptMin_, ptMax_);
75  h_allProbes_eta = dbe->book1D("allProbes_eta","All Probes Eta", etaBin_, etaMin_, etaMax_);
76  h_allProbes_hp_eta = dbe->book1D("allProbes_hp_eta","High Pt all Probes Eta", etaBin_, etaMin_, etaMax_);
77  h_allProbes_phi = dbe->book1D("allProbes_phi","All Probes Phi", phiBin_, phiMin_, phiMax_);
78 
79  h_passProbes_TightMu_pt = dbe->book1D("passProbes_TightMu_pt","TightMu Passing Probes Pt", ptBin_ , ptMin_ , ptMax_ );
80  h_passProbes_TightMu_barrel_pt = dbe->book1D("passProbes_TightMu_barrel_pt","Barrel: TightMu Passing Probes Pt", ptBin_ , ptMin_ , ptMax_ );
81  h_passProbes_TightMu_endcap_pt = dbe->book1D("passProbes_TightMu_endcap_pt","Endcap: TightMu Passing Probes Pt", ptBin_ , ptMin_ , ptMax_ );
82  h_passProbes_TightMu_eta = dbe->book1D("passProbes_TightMu_eta","TightMu Passing Probes #eta", etaBin_, etaMin_, etaMax_);
83  h_passProbes_TightMu_hp_eta = dbe->book1D("passProbes_TightMu_hp_eta","High Pt TightMu Passing Probes #eta", etaBin_, etaMin_, etaMax_);
84  h_passProbes_TightMu_phi = dbe->book1D("passProbes_TightMu_phi","TightMu Passing Probes #phi", phiBin_, phiMin_, phiMax_);
85 
86 
87 
88  /*h_failProbes_TightMu_pt = dbe->book1D("failProbes_TightMu_pt","TightMu Failling Probes Pt", ptBin_ , ptMin_ , ptMax_ );
89  h_failProbes_TightMu_eta = dbe->book1D("failProbes_TightMu_eta","TightMu Failling Probes #eta", etaBin_, etaMin_, etaMax_);
90  h_failProbes_TightMu_phi = dbe->book1D("failProbes_TightMu_phi","TightMu Failling Probes #phi", phiBin_, phiMin_, phiMax_);
91  */
92 
93 #ifdef DEBUG
94  cout << "[EfficiencyAnalyzer] Parameters initialization DONE" <<endl;
95 #endif
96 }
97 
99 
100  LogTrace(metname)<<"[EfficiencyAnalyzer] Analyze the mu in different eta regions";
101 
103  iEvent.getByLabel(theMuonCollectionLabel, muons);
104 
105 
107  iEvent.getByLabel(theTrackCollectionLabel,tracks);
108 
109 
111  Handle<reco::BeamSpot> beamSpotHandle;
112  iEvent.getByLabel("offlineBeamSpot", beamSpotHandle);
113  beamSpot = *beamSpotHandle;
114 
115  if(!muons.isValid()) return;
116 
117 
118  // Loop on muon collection
119  TLorentzVector Mu1, Mu2;
120 
121  bool isMB = false;
122  bool isME = false;
123 
124  for (reco::MuonCollection::const_iterator recoMu1 = muons->begin(); recoMu1!=muons->end(); ++recoMu1) {
125 
126  LogTrace(metname)<<"[EfficiencyAnalyzer] loop over first muons" << endl;
127 
128  //--- Define combined isolation
129  reco::MuonIsolation Iso_muon = recoMu1->isolationR03();
130  float combIso = (Iso_muon.emEt + Iso_muon.hadEt + Iso_muon.sumPt);
131 
132  //--- Is Global Muon
133  if (!recoMu1->isGlobalMuon()) continue;
134 
135  // get the track combinig the information from both the Tracker and the Spectrometer
136  reco::TrackRef recoCombinedGlbTrack1 = recoMu1->combinedMuon();
137  float muPt1 = recoCombinedGlbTrack1->pt();
138  Mu1.SetPxPyPzE(recoCombinedGlbTrack1->px(), recoCombinedGlbTrack1->py(),recoCombinedGlbTrack1->pz(), recoCombinedGlbTrack1->p());
139 
140 
141  //--- Define if it is a tight muon
142  if (recoMu1->isGlobalMuon() && recoMu1->isTrackerMuon() && recoMu1->combinedMuon()->normalizedChi2()<10.
143  && recoMu1->combinedMuon()->hitPattern().numberOfValidMuonHits()>0 && fabs(recoMu1->combinedMuon()->dxy(beamSpot.position()))<0.2 && recoMu1->combinedMuon()->hitPattern().numberOfValidPixelHits()>0 && recoMu1->numberOfMatches() > 1) {
144 
145  //-- is isolated muon
146  if (muPt1 > 15 && (combIso/muPt1) < 0.1 ) {
147 
148 
149  for (reco::MuonCollection::const_iterator recoMu2 = muons->begin(); recoMu2!=muons->end(); ++recoMu2){
150 
151  LogTrace(metname)<<"[EfficiencyAnalyzer] loop over second muon" <<endl;
152 
153  if (recoMu2 == recoMu1) continue;
154 
155 
156  if (recoMu2->eta() < 1.479 ) isMB = true;
157  if (recoMu2->eta() >= 1.479 ) isME = true;
158 
159 
160  //--> should we apply track quality cuts???
161  Mu2.SetPxPyPzE(recoMu2->px(), recoMu2->py(), recoMu2->pz(), recoMu2->p());
162 
163  if (!recoMu2->isTrackerMuon()) continue;
164 
165  if ( recoMu2->pt() < 5 ) continue;
166 
167  if ( (recoMu1->charge())*(recoMu2->charge()) > 0 ) continue;
168 
169  float Minv = (Mu1+Mu2).M();
170 
171  if ( Minv < 70 || Minv > 110 ) continue;
172 
173  h_allProbes_pt->Fill(recoMu2->pt());
174  h_allProbes_eta->Fill(recoMu2->eta());
175  h_allProbes_phi->Fill(recoMu2->phi());
176 
177 
178  if (isMB) h_allProbes_barrel_pt->Fill(recoMu2->pt());
179  if (isME) h_allProbes_endcap_pt->Fill(recoMu2->pt());
180  if(recoMu2->pt() > 20 ) h_allProbes_hp_eta->Fill(recoMu2->eta());
181 
182 
183  test_TightMu_Minv->Fill(Minv);
184 
185 
186  // Probes passing the tight muon criteria
187 
188  if (recoMu2->isGlobalMuon() && recoMu2->isTrackerMuon() && recoMu2->combinedMuon()->normalizedChi2()<10. && recoMu2->combinedMuon()->hitPattern().numberOfValidMuonHits()>0 && fabs(recoMu2->combinedMuon()->dxy(beamSpot.position()))<0.2 && recoMu2->combinedMuon()->hitPattern().numberOfValidPixelHits()>0 && recoMu2->numberOfMatches() > 1) {
189 
190  h_passProbes_TightMu_pt->Fill(recoMu2->pt());
191  h_passProbes_TightMu_eta->Fill(recoMu2->eta());
192  h_passProbes_TightMu_phi->Fill(recoMu2->phi());
193 
194  if (isMB) h_passProbes_TightMu_barrel_pt->Fill(recoMu2->pt());
195  if (isME) h_passProbes_TightMu_endcap_pt->Fill(recoMu2->pt());
196  if( recoMu2->pt() > 20 ) h_passProbes_TightMu_hp_eta->Fill(recoMu2->eta());
197 
198  }
199  }
200 
201  }
202  }
203  }
204 }
205 
206 
207 
208 
209 
float hadEt
hcal sum-Et
Definition: MuonIsolation.h:9
T getParameter(std::string const &) const
float sumPt
sum-pt of tracks
Definition: MuonIsolation.h:7
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
MonitorElement * h_allProbes_eta
edm::ParameterSet parameters
void Fill(long long x)
MonitorElement * h_allProbes_pt
int iEvent
Definition: GenABIO.cc:243
MonitorElement * h_passProbes_TightMu_hp_eta
MonitorElement * h_passProbes_TightMu_eta
float emEt
ecal sum-Et
Definition: MuonIsolation.h:8
MonitorElement * h_passProbes_TightMu_phi
MonitorElement * h_passProbes_TightMu_pt
MonitorElement * h_passProbes_TightMu_barrel_pt
bool isValid() const
Definition: HandleBase.h:76
edm::InputTag theMuonCollectionLabel
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
#define LogTrace(id)
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup)
MonitorElement * h_passProbes_TightMu_endcap_pt
void beginJob(DQMStore *dbe)
Inizialize parameters for histo binning.
tuple tracks
Definition: testEve_cfg.py:39
MonitorElement * test_TightMu_Minv
edm::InputTag theTrackCollectionLabel
tuple muons
Definition: patZpeak.py:38
tuple cout
Definition: gather_cfg.py:121
const Point & position() const
position
Definition: BeamSpot.h:63
MonitorElement * h_allProbes_hp_eta
MonitorElement * h_allProbes_phi
MonitorElement * h_allProbes_endcap_pt
EfficiencyAnalyzer(const edm::ParameterSet &pset, MuonServiceProxy *theService)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
MonitorElement * h_allProbes_barrel_pt