CMS 3D CMS Logo

SUSY_HLT_VBF_Mu.cc
Go to the documentation of this file.
9 #include "TLorentzVector.h"
10 #include <cassert>
11 #include <cstdio>
12 #include <cstdlib>
13 #include <fstream>
14 #include <iostream>
15 #include <regex.h>
16 #include <string>
17 #include <sys/types.h>
18 
20  edm::LogInfo("SUSY_HLT_VBF_Mu") << "Constructor SUSY_HLT_VBF_Mu::SUSY_HLT_VBF_Mu " << std::endl;
21  // Get parameters from configuration file
22  theTrigSummary_ = consumes<trigger::TriggerEvent>(ps.getParameter<edm::InputTag>("trigSummary"));
23  theMuonCollection_ = consumes<reco::MuonCollection>(ps.getParameter<edm::InputTag>("MuonCollection"));
24  thePfJetCollection_ = consumes<reco::PFJetCollection>(ps.getParameter<edm::InputTag>("pfJetCollection"));
25  thePfMETCollection_ = consumes<reco::PFMETCollection>(ps.getParameter<edm::InputTag>("pfMETCollection"));
26  theCaloJetCollection_ = consumes<reco::CaloJetCollection>(ps.getParameter<edm::InputTag>("caloJetCollection"));
27  theCaloMETCollection_ = consumes<reco::CaloMETCollection>(ps.getParameter<edm::InputTag>("caloMETCollection"));
28  triggerResults_ = consumes<edm::TriggerResults>(ps.getParameter<edm::InputTag>("TriggerResults"));
29  HLTProcess_ = ps.getParameter<std::string>("HLTProcess");
30  triggerPath_ = ps.getParameter<std::string>("TriggerPath");
31  triggerMuFilter_ = ps.getParameter<edm::InputTag>("TriggerFilterMuon");
32  triggerHTFilter_ = ps.getParameter<edm::InputTag>("TriggerFilterHT");
33  triggerMetFilter_ = ps.getParameter<edm::InputTag>("TriggerFilterMET");
34  triggerDiJetFilter_ = ps.getParameter<edm::InputTag>("TriggerFilterMJJ");
35  triggerCaloMETFilter_ = ps.getParameter<edm::InputTag>("TriggerFilterCaloMET");
36  ptThrJetTrig_ = ps.getUntrackedParameter<double>("PtThrJetTrig");
37  etaThrJetTrig_ = ps.getUntrackedParameter<double>("EtaThrJetTrig");
38  ptThrJet_ = ps.getUntrackedParameter<double>("PtThrJet");
39  etaThrJet_ = ps.getUntrackedParameter<double>("EtaThrJet");
40  deltaetaVBFJets = ps.getUntrackedParameter<double>("DeltaEtaVBFJets");
41  pfmetOnlinethreshold = ps.getUntrackedParameter<double>("PFMetCutOnline");
42  muonOnlinethreshold = ps.getUntrackedParameter<double>("MuonCutOnline");
43  htOnlinethreshold = ps.getUntrackedParameter<double>("HTCutOnline");
44  mjjOnlinethreshold = ps.getUntrackedParameter<double>("MJJCutOnline");
45 }
46 
48  edm::LogInfo("SUSY_HLT_VBF_Mu") << "Destructor SUSY_HLT_VBF_Mu::~SUSY_HLT_VBF_Mu " << std::endl;
49 }
50 
52  bool changed;
53 
54  if (!fHltConfig.init(run, e, HLTProcess_, changed)) {
55  edm::LogError("SUSY_HLT_VBF_Mu") << "Initialization of HLTConfigProvider failed!!";
56  return;
57  }
58 
59  bool pathFound = false;
60  const std::vector<std::string> allTrigNames = fHltConfig.triggerNames();
61  for (size_t j = 0; j < allTrigNames.size(); ++j) {
62  if (allTrigNames[j].find(triggerPath_) != std::string::npos) {
63  pathFound = true;
64  }
65  }
66 
67  if (!pathFound) {
68  LogDebug("SUSY_HLT_VBF_Mu") << "Path not found"
69  << "\n";
70  return;
71  }
72 
73  edm::LogInfo("SUSY_HLT_VBF_Mu") << "SUSY_HLT_VBF_Mu::beginRun" << std::endl;
74 }
75 
77  edm::LogInfo("SUSY_HLT_VBF_Mu") << "SUSY_HLT_VBF_Mu::bookHistograms" << std::endl;
78  // book at beginRun
79  bookHistos(ibooker_);
80 }
81 
83  edm::LogInfo("SUSY_HLT_VBF_Mu") << "SUSY_HLT_VBF_Mu::analyze" << std::endl;
84 
85  //-------------------------------
86  //--- Jets
87  //-------------------------------
88 
89  edm::Handle<reco::PFJetCollection> pfJetCollection;
90  e.getByToken(thePfJetCollection_, pfJetCollection);
91  if (!pfJetCollection.isValid()) {
92  edm::LogError("SUSY_HLT_VBF_Mu") << "invalid collection: PFJets"
93  << "\n";
94  return;
95  }
96 
97  edm::Handle<reco::CaloJetCollection> caloJetCollection;
98  e.getByToken(theCaloJetCollection_, caloJetCollection);
99  if (!caloJetCollection.isValid()) {
100  edm::LogError("SUSY_HLT_VBF_Mu") << "invalid collection: CaloJets"
101  << "\n";
102  return;
103  }
104 
105  //-------------------------------
106  //--- Muon
107  //-------------------------------
109  e.getByToken(theMuonCollection_, MuonCollection);
110  if (!MuonCollection.isValid()) {
111  edm::LogError("SUSY_HLT_VBF_Mu") << "invalid collection: Muons "
112  << "\n";
113  return;
114  }
115 
116  //-------------------------------
117  //--- MET
118  //-------------------------------
119 
120  edm::Handle<reco::CaloMETCollection> caloMETCollection;
121  e.getByToken(theCaloMETCollection_, caloMETCollection);
122  if (!caloMETCollection.isValid()) {
123  edm::LogError("SUSY_HLT_VBF_Mu") << "invalid collection: CaloMET"
124  << "\n";
125  return;
126  }
127 
128  edm::Handle<reco::PFMETCollection> pfMETCollection;
129  e.getByToken(thePfMETCollection_, pfMETCollection);
130  if (!pfMETCollection.isValid()) {
131  edm::LogError("SUSY_HLT_VBF_Mu") << "invalid collection: PFMET"
132  << "\n";
133  return;
134  }
135  //
136 
137  //-------------------------------
138  //--- Trigger
139  //-------------------------------
141  e.getByToken(triggerResults_, hltresults);
142  if (!hltresults.isValid()) {
143  edm::LogError("SUSY_HLT_VBF_Mu") << "invalid collection: TriggerResults"
144  << "\n";
145  return;
146  }
147  edm::Handle<trigger::TriggerEvent> triggerSummary;
148  e.getByToken(theTrigSummary_, triggerSummary);
149  if (!triggerSummary.isValid()) {
150  edm::LogError("SUSY_HLT_VBF_Mu") << "invalid collection: TriggerSummary"
151  << "\n";
152  return;
153  }
154 
155  // get online objects
156 
157  std::vector<float> ptMuon, etaMuon, phiMuon;
158  size_t filterIndexMu = triggerSummary->filterIndex(triggerMuFilter_);
160  if (!(filterIndexMu >= triggerSummary->sizeFilters())) {
161  const trigger::Keys &keys = triggerSummary->filterKeys(filterIndexMu);
162  for (size_t j = 0; j < keys.size(); ++j) {
163  trigger::TriggerObject foundObject = triggerObjects[keys[j]];
164  if (fabs(foundObject.id()) == 13) { // It's a muon
165 
166  bool same = false;
167  for (unsigned int x = 0; x < ptMuon.size(); x++) {
168  if (fabs(ptMuon[x] - foundObject.pt()) < 0.01)
169  same = true;
170  }
171 
172  if (!same) {
173  h_triggerMuPt->Fill(foundObject.pt());
174  h_triggerMuEta->Fill(foundObject.eta());
175  h_triggerMuPhi->Fill(foundObject.phi());
176  ptMuon.push_back(foundObject.pt());
177  etaMuon.push_back(foundObject.eta());
178  phiMuon.push_back(foundObject.phi());
179  }
180  }
181  }
182  }
183 
184  // get online objects
185 
186  size_t filterIndexMet = triggerSummary->filterIndex(triggerMetFilter_);
187  size_t dijetFilterIndex = triggerSummary->filterIndex(triggerDiJetFilter_);
188 
189  if (!(filterIndexMet >= triggerSummary->sizeFilters())) {
190  const trigger::Keys &keys = triggerSummary->filterKeys(filterIndexMet);
191  for (size_t j = 0; j < keys.size(); ++j) {
192  trigger::TriggerObject foundObject = triggerObjects[keys[j]];
193  h_triggerMet->Fill(foundObject.pt());
194  h_triggerMetPhi->Fill(foundObject.phi());
195  }
196  }
197 
198  dijet = -1;
199 
200  std::vector<float> ptJet, etaJet, phiJet;
201  if (!(dijetFilterIndex >= triggerSummary->sizeFilters())) {
202  const trigger::Keys &KEYS(triggerSummary->filterKeys(dijetFilterIndex));
203  const size_t nK(KEYS.size());
204  const trigger::TriggerObjectCollection &TOC(triggerSummary->getObjects());
205 
206  for (size_t i = 0; i < nK; i++) {
207  const trigger::TriggerObject &TO1(TOC[KEYS[i]]);
208  if (TO1.pt() > ptThrJetTrig_ && fabs(TO1.eta()) < etaThrJetTrig_) {
209  // for dijet part
210  for (size_t j = i; j < nK; j++) {
211  if (i < j) {
212  const trigger::TriggerObject &TO2(TOC[KEYS[j]]);
213  if (TO2.pt() > ptThrJetTrig_ && fabs(TO2.eta()) < etaThrJetTrig_) {
214  double tmpdeta = fabs(TO1.eta() - TO2.eta());
215  double tmpopposite = TO1.eta() * TO2.eta();
216  if (tmpdeta > deltaetaVBFJets && tmpopposite < 0) {
217  TLorentzVector j1(TO1.px(), TO1.py(), TO1.pz(), TO1.energy());
218  TLorentzVector j2(TO2.px(), TO2.py(), TO2.pz(), TO2.energy());
219  double tmpmass = (j1 + j2).M();
220  if (dijet < tmpmass) {
221  dijet = tmpmass;
222  }
223  }
224  }
225  }
226  }
227  }
228  }
230  }
231 
232  size_t filterIndexCaloMET = triggerSummary->filterIndex(triggerCaloMETFilter_);
233  if (filterIndexCaloMET < triggerSummary->sizeFilters()) {
234  const trigger::Keys &keys = triggerSummary->filterKeys(filterIndexCaloMET);
235  if (!keys.empty()) {
236  float met_h = triggerObjects[keys[0]].pt();
237  h_triggerCaloMet->Fill(met_h);
238  }
239  }
240 
241  size_t filterIndexHt = triggerSummary->filterIndex(triggerHTFilter_);
242  if (filterIndexHt < triggerSummary->sizeFilters()) {
243  const trigger::Keys &keys = triggerSummary->filterKeys(filterIndexHt);
244  if (!keys.empty()) {
245  float ht = triggerObjects[keys[0]].pt();
246  h_ht->Fill(ht);
247  }
248  }
249 
250  bool hasFired = false;
251 
252  const edm::TriggerNames &trigNames = e.triggerNames(*hltresults);
253  unsigned int numTriggers = trigNames.size();
254 
255  for (unsigned int hltIndex = 0; hltIndex < numTriggers; ++hltIndex) {
256  if (trigNames.triggerName(hltIndex).find(triggerPath_) != std::string::npos && hltresults->wasrun(hltIndex) &&
257  hltresults->accept(hltIndex))
258  hasFired = true;
259  }
260 
261  // Matching the muon
262  int indexOfMatchedMuon = -1;
263  int offlineCounter = 0;
264  for (reco::MuonCollection::const_iterator muon = MuonCollection->begin(); muon != MuonCollection->end(); ++muon) {
265  for (size_t off_i = 0; off_i < ptMuon.size(); ++off_i) {
266  if (reco::deltaR(muon->eta(), muon->phi(), etaMuon[off_i], phiMuon[off_i]) < 0.5) {
267  indexOfMatchedMuon = offlineCounter;
268  break;
269  }
270  }
271  offlineCounter++;
272  }
273 
274  float pfHT = 0.0;
275 
276  for (reco::PFJetCollection::const_iterator i_pfjet = pfJetCollection->begin(); i_pfjet != pfJetCollection->end();
277  ++i_pfjet) {
278  if (i_pfjet->pt() < ptThrJet_)
279  continue;
280  if (fabs(i_pfjet->eta()) > etaThrJet_)
281  continue;
282  pfHT += i_pfjet->pt();
283  }
284 
285  //
286 
287  dijetOff = -1;
288 
289  size_t jetCol = pfJetCollection->size();
290 
291  for (size_t i = 0; i < jetCol; i++) {
292  if (pfJetCollection->at(i).pt() > ptThrJetTrig_ && fabs(pfJetCollection->at(i).eta()) < etaThrJetTrig_) {
293  for (size_t j = i; j < jetCol; j++) {
294  if (i < j) {
295  if (pfJetCollection->at(j).pt() > ptThrJetTrig_ && fabs(pfJetCollection->at(j).eta()) < etaThrJetTrig_) {
296  double tmpdetaOff = fabs(pfJetCollection->at(i).eta() - pfJetCollection->at(j).eta());
297  double tmpoppositeOff = pfJetCollection->at(i).eta() * pfJetCollection->at(j).eta();
298  if (tmpdetaOff > deltaetaVBFJets && tmpoppositeOff < 0) {
299  TLorentzVector j1Off(pfJetCollection->at(i).px(),
300  pfJetCollection->at(i).py(),
301  pfJetCollection->at(i).pz(),
302  pfJetCollection->at(i).energy());
303  TLorentzVector j2Off(pfJetCollection->at(j).px(),
304  pfJetCollection->at(j).py(),
305  pfJetCollection->at(j).pz(),
306  pfJetCollection->at(j).energy());
307  double tmpmassOff = (j1Off + j2Off).M();
308  if (dijetOff < tmpmassOff)
309  dijetOff = tmpmassOff;
310  }
311  }
312  }
313  }
314  }
315  }
316 
317  // For trigger turn on curves
318 
319  // for muon
320  if (indexOfMatchedMuon > -1 && (dijetOff > mjjOnlinethreshold) &&
321  (pfMETCollection->begin()->et() > pfmetOnlinethreshold) && (pfHT > htOnlinethreshold)) {
322  h_den_muonpt->Fill(MuonCollection->at(indexOfMatchedMuon).pt());
323  h_den_muoneta->Fill(MuonCollection->at(indexOfMatchedMuon).eta());
324  if (hasFired) {
325  h_num_muonpt->Fill(MuonCollection->at(indexOfMatchedMuon).pt());
326  h_num_muoneta->Fill(MuonCollection->at(indexOfMatchedMuon).eta());
327  }
328  }
329 
330  // For MJJ
331  if (indexOfMatchedMuon > -1 && (MuonCollection->at(indexOfMatchedMuon).pt() > muonOnlinethreshold) &&
332  (pfMETCollection->begin()->et() > pfmetOnlinethreshold) && (pfHT > htOnlinethreshold)) {
334  if (hasFired) {
336  }
337  }
338 
339  // For HT
340  //
341  if (indexOfMatchedMuon > -1 && (MuonCollection->at(indexOfMatchedMuon).pt() > muonOnlinethreshold) &&
342  (pfMETCollection->begin()->et() > pfmetOnlinethreshold) && (dijetOff > mjjOnlinethreshold)) {
343  h_den_ht->Fill(pfHT);
344  if (hasFired) {
345  h_num_ht->Fill(pfHT);
346  }
347  }
348 
349  if (indexOfMatchedMuon > -1 && (dijetOff > mjjOnlinethreshold) && (pfHT > htOnlinethreshold) &&
350  (MuonCollection->at(indexOfMatchedMuon).pt() > muonOnlinethreshold)) {
351  h_den_met->Fill(pfMETCollection->begin()->et());
352  if (hasFired) {
353  h_num_met->Fill(pfMETCollection->begin()->et());
354  }
355  }
356 }
357 
359  edm::LogInfo("SUSY_HLT_VBF_Mu") << "SUSY_HLT_VBF_Mu::endRun" << std::endl;
360 }
361 
363  ibooker_.cd();
364  ibooker_.setCurrentFolder("HLT/SUSYBSM/SUSY_HLT_VBF_Mu");
365 
366  // offline quantities
367 
368  // online quantities
369  h_triggerMuPt = ibooker_.book1D("triggerMuPt", "Trigger Muon Pt; GeV", 50, 0.0, 500.0);
370  h_triggerMuEta = ibooker_.book1D("triggerMuEta", "Trigger Muon Eta", 20, -3.0, 3.0);
371  h_triggerMuPhi = ibooker_.book1D("triggerMuPhi", "Trigger Muon Phi", 20, -3.5, 3.5);
372 
373  h_triggerCaloMet = ibooker_.book1D("h_triggerCaloMet", "Trigger Calo MET; GeV", 20, 0.0, 500.0);
374 
375  h_ht = ibooker_.book1D("h_ht", "h_ht", 30, 0.0, 1500.0);
376 
377  h_triggerMet = ibooker_.book1D("triggerMet", "Trigger MET; GeV", 20, 0.0, 500.0);
378  h_triggerMetPhi = ibooker_.book1D("triggerMetPhi", "Trigger MET Phi", 20, -3.5, 3.5);
379 
380  h_DiJetMass = ibooker_.book1D("h_DiJetMass", "h_DiJetMass", 500, 0.0, 5000.0);
381 
382  // num and den hists to be divided in harvesting step to make turn on curves
383 
384  h_den_muonpt = ibooker_.book1D("h_den_muonpt", "h_den_muonpt", 50, 0.0, 500.0);
385  h_num_muonpt = ibooker_.book1D("h_num_muonpt", "h_num_muonpt", 50, 0.0, 500.0);
386 
387  h_den_muoneta = ibooker_.book1D("h_den_muoneta", "h_den_muoneta", 20, -3.0, 3.0);
388  h_num_muoneta = ibooker_.book1D("h_num_muoneta", "h_num_muoneta", 20, -3.0, 3.0);
389 
390  h_den_mjj = ibooker_.book1D("h_den_mjj", "h_den_mjj", 500, 0.0, 5000.0);
391  h_num_mjj = ibooker_.book1D("h_num_mjj", "h_num_mjj", 500, 0.0, 5000.0);
392 
393  h_den_met = ibooker_.book1D("h_den_met", "h_den_met", 20, 0.0, 500.0);
394  h_num_met = ibooker_.book1D("h_num_met", "h_num_met", 20, 0.0, 500.0);
395 
396  h_den_ht = ibooker_.book1D("h_den_ht", "h_den_ht", 30, 0.0, 1500.0);
397  h_num_ht = ibooker_.book1D("h_num_ht", "h_num_ht", 30, 0.0, 1500.0);
398 
399  ibooker_.cd();
400 }
401 
402 // define this as a plug-in
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
MonitorElement * h_triggerMuPhi
bool wasrun() const
Was at least one path run?
edm::EDGetTokenT< reco::CaloMETCollection > theCaloMETCollection_
~SUSY_HLT_VBF_Mu() override
MonitorElement * h_num_met
int id() const
getters
Definition: TriggerObject.h:55
trigger::size_type sizeFilters() const
Definition: TriggerEvent.h:135
MonitorElement * h_ht
MonitorElement * h_den_muonpt
MonitorElement * h_triggerCaloMet
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
float phi() const
Definition: TriggerObject.h:58
void analyze(edm::Event const &e, edm::EventSetup const &eSetup) override
edm::InputTag triggerMetFilter_
bool accept() const
Has at least one path accepted the event?
const std::vector< std::string > & triggerNames() const
names of trigger paths
const Keys & filterKeys(trigger::size_type index) const
Definition: TriggerEvent.h:111
edm::EDGetTokenT< reco::MuonCollection > theMuonCollection_
trigger::size_type filterIndex(const edm::InputTag &filterTag) const
find index of filter in data-member vector from filter tag
Definition: TriggerEvent.h:123
double mjjOnlinethreshold
double muonOnlinethreshold
float energy() const
Definition: TriggerObject.h:65
Strings::size_type size() const
Definition: TriggerNames.cc:31
float eta() const
Definition: TriggerObject.h:57
MonitorElement * h_num_muoneta
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
void endRun(edm::Run const &run, edm::EventSetup const &eSetup) override
edm::EDGetTokenT< reco::PFMETCollection > thePfMETCollection_
void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override
edm::EDGetTokenT< reco::PFJetCollection > thePfJetCollection_
HLTConfigProvider fHltConfig
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
void Fill(long long x)
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:22
SUSY_HLT_VBF_Mu(const edm::ParameterSet &ps)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
MonitorElement * h_num_mjj
edm::InputTag triggerDiJetFilter_
const TriggerObjectCollection & getObjects() const
Definition: TriggerEvent.h:98
edm::EDGetTokenT< edm::TriggerResults > triggerResults_
MonitorElement * h_DiJetMass
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
MonitorElement * h_den_met
edm::InputTag triggerHTFilter_
bool isValid() const
Definition: HandleBase.h:74
edm::InputTag triggerMuFilter_
MonitorElement * h_triggerMuPt
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
double htOnlinethreshold
MonitorElement * h_den_mjj
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:81
static const char *const trigNames[]
Definition: EcalDumpRaw.cc:74
std::string const & triggerName(unsigned int index) const
Definition: TriggerNames.cc:22
std::vector< size_type > Keys
std::string HLTProcess_
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
std::string triggerPath_
edm::EDGetTokenT< reco::CaloJetCollection > theCaloJetCollection_
edm::EDGetTokenT< trigger::TriggerEvent > theTrigSummary_
MonitorElement * h_num_muonpt
MonitorElement * h_num_ht
double pfmetOnlinethreshold
MonitorElement * h_triggerMetPhi
MonitorElement * h_triggerMuEta
MonitorElement * h_den_ht
void bookHistos(DQMStore::IBooker &)
MonitorElement * h_triggerMet
edm::InputTag triggerCaloMETFilter_
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:256
Definition: Run.h:45
MonitorElement * h_den_muoneta