CMS 3D CMS Logo

SMPDQM.cc
Go to the documentation of this file.
2 
3 using namespace std;
4 using namespace reco;
5 
6 struct SortByPt
7 
8 {
9  bool operator()(const TLorentzVector& a, const TLorentzVector& b) const { return a.Pt() > b.Pt(); }
10 };
12  //now do what ever initialization is needed
13  muons_ = consumes<reco::MuonCollection>(iConfig.getParameter<edm::InputTag>("muonCollection"));
14  pvs_ = consumes<edm::View<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("pvs"));
15 
16  elecs_ = consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("elecCollection"));
17  jets_ = consumes<edm::View<reco::PFJet>>(iConfig.getParameter<edm::InputTag>("jets"));
18 
19  for (edm::InputTag const& tag : iConfig.getParameter<std::vector<edm::InputTag>>("mets"))
20  mets_.push_back(consumes<edm::View<reco::MET>>(tag));
21 }
22 
24  // do anything here that needs to be done at desctruction time
25  // (e.g. close files, deallocate resources etc.)
26 }
27 // ------------ method called for each event ------------
29  bei.setCurrentFolder("Physics/SMP");
30 
31  NPV = bei.book1D("NPV", "Number of primary vertices", 40, 0., 80.);
32  MET = bei.book1D("MET", "MET", 100, 0.0, 200);
33  METphi = bei.book1D("METphi", "#phi(MET)", 50, -3.14, 3.14);
34 
35  pt_muons = bei.book1D("pt_muons", "p_{T}(muons)", 40, 0., 200.);
36  eta_muons = bei.book1D("eta_muons", "#eta(muons)", 50, -5., 5.);
37  phi_muons = bei.book1D("phi_muons", "#phi(muons)", 32, -3.2, 3.2);
38  muIso_CombRelIso03 = bei.book1D("muIso_CombRelIso03", "Iso_{rel}^{#mu}", 20, 0., 1.);
39  Nmuons = bei.book1D("Nmuons", "Number of muons", 20, 0., 10.);
40  isGlobalmuon = bei.book1D("isGlobalmuon", "isGlobalmuon", 2, 0, 1);
41  isTrackermuon = bei.book1D("isTrackermuon", "isTrackermuon", 2, 0, 1);
42  isStandalonemuon = bei.book1D("isStandalonemuon", "isStandalonemuon", 2, 0, 1);
43  isPFmuon = bei.book1D("isPFmuon", "isPFmuon", 2, 0, 1);
44  muIso_TrackerBased03 = bei.book1D("muIso_TrackerBased03", "Iso_{trk03}^{#mu}", 20, 0, 10);
45 
46  Nelecs = bei.book1D("Nelecs", "Number of electrons", 20, 0., 10.);
47  HoverE_elecs = bei.book1D("HoverE_elecs", "HoverE", 50, 0., 1.);
48  pt_elecs = bei.book1D("pt_elecs", "p_{T}(elecs)", 40, 0., 200.);
49  eta_elecs = bei.book1D("eta_elecs", "#eta(elecs)", 50, -5., 5.);
50  phi_elecs = bei.book1D("phi_elecs", "#phielecs)", 32, -3.2, 3.2);
51  elIso_cal = bei.book1D("elIso_cal", "Iso_{cal}^{el}", 21, -1., 20.);
52  elIso_trk = bei.book1D("elIso_trk", "Iso_{trk}^{el}", 21, -2., 40.);
53  elIso_CombRelIso = bei.book1D("elIso_CombRelIso", "Iso_{rel}^{el}", 20, 0., 1.);
54 
55  PFJetpt = bei.book1D("PFJetpt", "p_{T}(jets)", 100, 0.0, 100);
56  PFJeteta = bei.book1D("PFJeteta", "#eta(jets)", 50, -2.5, 2.5);
57  PFJetphi = bei.book1D("PFJetphi", "#phi(jets)", 50, -3.14, 3.14);
58  PFJetMulti = bei.book1D("PFJetMulti", "jet multiplicity", 5, -0.5, 4.5);
59  PFJetRapidity = bei.book1D("PFJetRapidity", "y(jets)", 50, -6.0, 6.0);
60  mjj = bei.book1D("mjj", "m_{jj}", 100, 0, 1000);
61  detajj = bei.book1D("detajj", "#Delta#etajj", 20, 0, 5);
62 
63  dphi_lepMET = bei.book1D("dphi_lepMET", "#Delta#phi(lep,MET)", 60, -3.2, 3.2);
64  mass_lepMET = bei.book1D("mass_lepMET", "m(lep,MET)", 200, 0, 200);
65  pt_lepMET = bei.book1D("pt_lepMET", "p_{T}(lep,MET)", 200, 0, 200);
66  detall = bei.book1D("detall", "#Delta#etall", 20, -5, 5);
67  dphill = bei.book1D("dphill", "#Delta#phill", 20, -6.4, 6.4);
68  mll = bei.book1D("mll", "mll", 200, 0, 200);
69  etall = bei.book1D("etall", "#Delta#etall", 60, -6, 6);
70  ptll = bei.book1D("ptll", "p_{T}ll", 200, 0, 200);
71  mjj = bei.book1D("mjj", "mjj", 100, 0, 1000);
72  detajj = bei.book1D("detajj", "#Delta#etajj", 20, 0, 5);
73 
74  dphi_lepjet1 = bei.book1D("dphi_lepjet1", "#Delta#phi(lep,jet1)", 60, -3.2, 3.2);
75 
76  dphi_lep1jet1 = bei.book1D("dphi_lep1jet1", "#Delta#phi(lep1,jet1)", 60, -3.2, 3.2);
77  dphi_lep2jet1 = bei.book1D("dphi_lep2jet1", "#Delta#phi(lep2,jet1)", 60, -3.2, 3.2);
78 }
79 void SMPDQM::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
80  std::vector<TLorentzVector> recoPFJets;
81  recoPFJets.clear();
82  TLorentzVector imet;
83  imet.Clear();
84  std::vector<TLorentzVector> selected_recoPFJets;
85  selected_recoPFJets.clear();
86  std::vector<TLorentzVector> selected_lep;
87  selected_lep.clear();
88 
89  for (std::vector<edm::EDGetTokenT<edm::View<reco::MET>>>::const_iterator met_ = mets_.begin(); met_ != mets_.end();
90  ++met_) {
92  if (!iEvent.getByToken(*met_, met))
93  continue;
94  if (met->begin() != met->end()) {
95  MET->Fill(met->begin()->et());
96  METphi->Fill(met->begin()->phi());
97  imet.SetPtEtaPhiM(met->begin()->et(), 0., met->begin()->phi(), 0.0);
98  }
99  }
100 
101  // Muons
102 
104  if (!iEvent.getByToken(pvs_, pvs)) {
105  return;
106  }
107 
108  unsigned int pvMult = 0;
109 
110  for (edm::View<reco::Vertex>::const_iterator pv = pvs->begin(); pv != pvs->end(); ++pv) {
111  if (pv->position().Rho() < 2 && abs(pv->position().z()) <= 24. && pv->ndof() > 4 && !pv->isFake()) {
112  pvMult++;
113  }
114  }
115  NPV->Fill(pvMult);
116 
118  iEvent.getByToken(muons_, muons);
119  reco::MuonCollection::const_iterator mu;
120  if (!muons.failedToGet()) {
121  Nmuons->Fill(muons->size());
122 
123  for (mu = muons->begin(); mu != muons->end(); ++mu) {
124  if (mu->pt() < 3.0)
125  continue;
126  TLorentzVector Mu;
127  Mu.SetPtEtaPhiM(mu->pt(), mu->eta(), mu->phi(), 0.0);
128  selected_lep.push_back(Mu);
129  pt_muons->Fill(mu->pt());
130  eta_muons->Fill(mu->eta());
131  phi_muons->Fill(mu->phi());
132  isGlobalmuon->Fill(mu->isGlobalMuon());
133  isTrackermuon->Fill(mu->isTrackerMuon());
134  isStandalonemuon->Fill(mu->isStandAloneMuon());
135  isPFmuon->Fill(mu->isPFMuon());
136 
137  reco::MuonIsolation muIso03 = mu->isolationR03();
138  double muonCombRelIso = 1.;
139 
140  muonCombRelIso = (muIso03.emEt + muIso03.hadEt + muIso03.hoEt + muIso03.sumPt) / mu->pt();
141 
142  muIso_TrackerBased03->Fill(muIso03.sumPt / mu->pt());
143  muIso_CombRelIso03->Fill(muonCombRelIso);
144 
145  } //size of muons
146 
147  } // muons
148 
149  // electrons
150 
152  iEvent.getByToken(elecs_, elecs);
153  reco::GsfElectronCollection::const_iterator elec;
154 
155  if (!elecs.failedToGet()) {
156  Nelecs->Fill(elecs->size());
157 
158  for (elec = elecs->begin(); elec != elecs->end(); ++elec) {
159  if (elec->pt() < 5.0)
160  continue;
161  TLorentzVector El;
162  El.SetPtEtaPhiM(elec->pt(), elec->eta(), elec->phi(), 0.0);
163  selected_lep.push_back(El);
164 
165  HoverE_elecs->Fill(elec->hcalOverEcal());
166  pt_elecs->Fill(elec->pt());
167  eta_elecs->Fill(elec->eta());
168  phi_elecs->Fill(elec->phi());
169 
170  reco::GsfTrackRef track = elec->gsfTrack();
171  reco::GsfElectron::IsolationVariables elecIso = elec->dr03IsolationVariables();
172 
173  double elecCombRelIso = 1.;
174 
175  elecCombRelIso = (elecIso.ecalRecHitSumEt + elecIso.hcalRecHitSumEt[0] + elecIso.tkSumPt) / elec->pt();
176  elIso_CombRelIso->Fill(elecCombRelIso);
177  elIso_cal->Fill(elecIso.ecalRecHitSumEt);
178  elIso_trk->Fill(elecIso.tkSumPt);
179  }
180 
181  } // electrons
182  // jets
183 
185  if (!iEvent.getByToken(jets_, jets)) {
186  return;
187  }
188 
189  for (edm::View<reco::PFJet>::const_iterator jet = jets->begin(); jet != jets->end(); ++jet) {
190  if (jet->pt() < 15.0)
191  continue;
192  TLorentzVector ijet;
193  ijet.SetPtEtaPhiM(jet->pt(), jet->eta(), jet->phi(), jet->mass());
194  recoPFJets.push_back(ijet);
195  }
196 
197  std::sort(recoPFJets.begin(), recoPFJets.end(), SortByPt());
198  std::sort(selected_lep.begin(), selected_lep.end(), SortByPt());
199 
200  for (unsigned int i = 0; i < recoPFJets.size(); i++) {
201  bool goodjet = false;
202  for (unsigned int j = 0; j < selected_lep.size(); j++) {
203  if (recoPFJets[i].DeltaR(selected_lep[j]) > 0.4) {
204  goodjet = true;
205  continue;
206  } else {
207  goodjet = false;
208  break;
209  }
210  }
211  if (goodjet) {
212  TLorentzVector temp;
213  temp.Clear();
214  temp.SetPtEtaPhiM(recoPFJets[i].Pt(), recoPFJets[i].Eta(), recoPFJets[i].Phi(), recoPFJets[i].M());
215  selected_recoPFJets.push_back(temp);
216  }
217  }
218 
219  std::sort(selected_recoPFJets.begin(), selected_recoPFJets.end(), SortByPt()); // for safety
220  int njet = 0;
221  for (unsigned int k = 0; k < selected_recoPFJets.size(); k++) {
222  if (k > 4)
223  break;
224  else {
225  njet++;
226  PFJetpt->Fill(selected_recoPFJets.at(k).Pt());
227  PFJeteta->Fill(selected_recoPFJets.at(k).Eta());
228  PFJetphi->Fill(selected_recoPFJets.at(k).Phi());
229  PFJetRapidity->Fill(selected_recoPFJets.at(k).Rapidity());
230  }
231  }
232  PFJetMulti->Fill(njet);
233 
234  // now we have selected jet and lepton collections
235 
236  if (selected_lep.size() > 1) {
237  detall->Fill(selected_lep[0].Eta() - selected_lep[1].Eta());
238  dphill->Fill(selected_lep[0].DeltaPhi(selected_lep[1]));
239  mll->Fill((selected_lep[0] + selected_lep[1]).M());
240  ptll->Fill((selected_lep[0] + selected_lep[1]).Pt());
241  etall->Fill((selected_lep[0] + selected_lep[1]).Eta());
242  if (!selected_recoPFJets.empty()) {
243  dphi_lep1jet1->Fill(selected_recoPFJets[0].DeltaPhi(selected_lep[0]));
244  dphi_lep2jet1->Fill(selected_recoPFJets[0].DeltaPhi(selected_lep[1]));
245  }
246  }
247 
248  else if (selected_lep.size() == 1) {
249  dphi_lepMET->Fill(selected_lep[0].DeltaPhi(imet));
250  mass_lepMET->Fill((selected_lep[0] + imet).M());
251  pt_lepMET->Fill((selected_lep[0] + imet).Pt());
252  if (!selected_recoPFJets.empty()) {
253  dphi_lepjet1->Fill(selected_recoPFJets[0].DeltaPhi(selected_lep[0]));
254  }
255  } // W case
256 
257  else {
258  // std::cout << "zero lepton case" << endl;
259  }
260  if (selected_recoPFJets.size() > 1) {
261  detajj->Fill(abs(selected_recoPFJets[0].Eta() - selected_recoPFJets[1].Eta()));
262  mjj->Fill((selected_recoPFJets[0] + selected_recoPFJets[1]).M());
263  }
264 
265 } // analyze
266 
267 //define this as a plug-in
268 //DEFINE_FWK_MODULE(SMPDQM);
269 
270 //dilepton eta,pt and phi using lorentz vectors
271 //first five jets
272 // dphi(lepton jet)
273 //vbf detajj, mjj
float hadEt
hcal sum-Et
Definition: MuonIsolation.h:8
std::array< float, 7 > hcalRecHitSumEt
Definition: GsfElectron.h:540
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
float sumPt
sum-pt of tracks
Definition: MuonIsolation.h:6
SMPDQM(const edm::ParameterSet &)
Definition: SMPDQM.cc:11
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
void bookHistograms(DQMStore::IBooker &bei, edm::Run const &, edm::EventSetup const &) override
Definition: SMPDQM.cc:28
int njet
Definition: HydjetWrapper.h:91
bool operator()(const TLorentzVector &a, const TLorentzVector &b) const
Definition: SMPDQM.cc:9
int iEvent
Definition: GenABIO.cc:224
Definition: MET.h:41
float emEt
ecal sum-Et
Definition: MuonIsolation.h:7
def pv(vc)
Definition: MetAnalyzer.py:7
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float hoEt
ho sum-Et
Definition: MuonIsolation.h:9
Definition: L1GtObject.h:29
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: SMPDQM.cc:79
~SMPDQM() override
Definition: SMPDQM.cc:23
double b
Definition: hdecay.h:120
fixed size matrix
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
double a
Definition: hdecay.h:121
const_iterator begin() const
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
Definition: Run.h:45