Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:04

0001 #include "DataFormats/HLTReco/interface/TriggerObject.h"
0002 #include "DataFormats/Math/interface/LorentzVector.h"
0003 #include "DataFormats/Math/interface/deltaR.h"
0004 #include "FWCore/Common/interface/TriggerNames.h"
0005 #include "FWCore/Framework/interface/Frameworkfwd.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "HLTriggerOffline/SUSYBSM/interface/SUSY_HLT_VBF_Mu.h"
0009 #include "TLorentzVector.h"
0010 #include <cassert>
0011 #include <cstdio>
0012 #include <cstdlib>
0013 #include <fstream>
0014 #include <iostream>
0015 #include <regex.h>
0016 #include <string>
0017 #include <sys/types.h>
0018 
0019 SUSY_HLT_VBF_Mu::SUSY_HLT_VBF_Mu(const edm::ParameterSet &ps) {
0020   edm::LogInfo("SUSY_HLT_VBF_Mu") << "Constructor SUSY_HLT_VBF_Mu::SUSY_HLT_VBF_Mu " << std::endl;
0021   // Get parameters from configuration file

0022   theTrigSummary_ = consumes<trigger::TriggerEvent>(ps.getParameter<edm::InputTag>("trigSummary"));
0023   theMuonCollection_ = consumes<reco::MuonCollection>(ps.getParameter<edm::InputTag>("MuonCollection"));
0024   thePfJetCollection_ = consumes<reco::PFJetCollection>(ps.getParameter<edm::InputTag>("pfJetCollection"));
0025   thePfMETCollection_ = consumes<reco::PFMETCollection>(ps.getParameter<edm::InputTag>("pfMETCollection"));
0026   theCaloJetCollection_ = consumes<reco::CaloJetCollection>(ps.getParameter<edm::InputTag>("caloJetCollection"));
0027   theCaloMETCollection_ = consumes<reco::CaloMETCollection>(ps.getParameter<edm::InputTag>("caloMETCollection"));
0028   triggerResults_ = consumes<edm::TriggerResults>(ps.getParameter<edm::InputTag>("TriggerResults"));
0029   HLTProcess_ = ps.getParameter<std::string>("HLTProcess");
0030   triggerPath_ = ps.getParameter<std::string>("TriggerPath");
0031   triggerMuFilter_ = ps.getParameter<edm::InputTag>("TriggerFilterMuon");
0032   triggerHTFilter_ = ps.getParameter<edm::InputTag>("TriggerFilterHT");
0033   triggerMetFilter_ = ps.getParameter<edm::InputTag>("TriggerFilterMET");
0034   triggerDiJetFilter_ = ps.getParameter<edm::InputTag>("TriggerFilterMJJ");
0035   triggerCaloMETFilter_ = ps.getParameter<edm::InputTag>("TriggerFilterCaloMET");
0036   ptThrJetTrig_ = ps.getUntrackedParameter<double>("PtThrJetTrig");
0037   etaThrJetTrig_ = ps.getUntrackedParameter<double>("EtaThrJetTrig");
0038   ptThrJet_ = ps.getUntrackedParameter<double>("PtThrJet");
0039   etaThrJet_ = ps.getUntrackedParameter<double>("EtaThrJet");
0040   deltaetaVBFJets = ps.getUntrackedParameter<double>("DeltaEtaVBFJets");
0041   pfmetOnlinethreshold = ps.getUntrackedParameter<double>("PFMetCutOnline");
0042   muonOnlinethreshold = ps.getUntrackedParameter<double>("MuonCutOnline");
0043   htOnlinethreshold = ps.getUntrackedParameter<double>("HTCutOnline");
0044   mjjOnlinethreshold = ps.getUntrackedParameter<double>("MJJCutOnline");
0045 }
0046 
0047 SUSY_HLT_VBF_Mu::~SUSY_HLT_VBF_Mu() {
0048   edm::LogInfo("SUSY_HLT_VBF_Mu") << "Destructor SUSY_HLT_VBF_Mu::~SUSY_HLT_VBF_Mu " << std::endl;
0049 }
0050 
0051 void SUSY_HLT_VBF_Mu::dqmBeginRun(edm::Run const &run, edm::EventSetup const &e) {
0052   bool changed;
0053 
0054   if (!fHltConfig.init(run, e, HLTProcess_, changed)) {
0055     edm::LogError("SUSY_HLT_VBF_Mu") << "Initialization of HLTConfigProvider failed!!";
0056     return;
0057   }
0058 
0059   bool pathFound = false;
0060   const std::vector<std::string> allTrigNames = fHltConfig.triggerNames();
0061   for (size_t j = 0; j < allTrigNames.size(); ++j) {
0062     if (allTrigNames[j].find(triggerPath_) != std::string::npos) {
0063       pathFound = true;
0064     }
0065   }
0066 
0067   if (!pathFound) {
0068     LogDebug("SUSY_HLT_VBF_Mu") << "Path not found"
0069                                 << "\n";
0070     return;
0071   }
0072 
0073   edm::LogInfo("SUSY_HLT_VBF_Mu") << "SUSY_HLT_VBF_Mu::beginRun" << std::endl;
0074 }
0075 
0076 void SUSY_HLT_VBF_Mu::bookHistograms(DQMStore::IBooker &ibooker_, edm::Run const &, edm::EventSetup const &) {
0077   edm::LogInfo("SUSY_HLT_VBF_Mu") << "SUSY_HLT_VBF_Mu::bookHistograms" << std::endl;
0078   // book at beginRun

0079   bookHistos(ibooker_);
0080 }
0081 
0082 void SUSY_HLT_VBF_Mu::analyze(edm::Event const &e, edm::EventSetup const &eSetup) {
0083   edm::LogInfo("SUSY_HLT_VBF_Mu") << "SUSY_HLT_VBF_Mu::analyze" << std::endl;
0084 
0085   //-------------------------------

0086   //--- Jets

0087   //-------------------------------

0088 
0089   edm::Handle<reco::PFJetCollection> pfJetCollection;
0090   e.getByToken(thePfJetCollection_, pfJetCollection);
0091   if (!pfJetCollection.isValid()) {
0092     edm::LogError("SUSY_HLT_VBF_Mu") << "invalid collection: PFJets"
0093                                      << "\n";
0094     return;
0095   }
0096 
0097   edm::Handle<reco::CaloJetCollection> caloJetCollection;
0098   e.getByToken(theCaloJetCollection_, caloJetCollection);
0099   if (!caloJetCollection.isValid()) {
0100     edm::LogError("SUSY_HLT_VBF_Mu") << "invalid collection: CaloJets"
0101                                      << "\n";
0102     return;
0103   }
0104 
0105   //-------------------------------

0106   //--- Muon

0107   //-------------------------------

0108   edm::Handle<reco::MuonCollection> MuonCollection;
0109   e.getByToken(theMuonCollection_, MuonCollection);
0110   if (!MuonCollection.isValid()) {
0111     edm::LogError("SUSY_HLT_VBF_Mu") << "invalid collection: Muons "
0112                                      << "\n";
0113     return;
0114   }
0115 
0116   //-------------------------------

0117   //--- MET

0118   //-------------------------------

0119 
0120   edm::Handle<reco::CaloMETCollection> caloMETCollection;
0121   e.getByToken(theCaloMETCollection_, caloMETCollection);
0122   if (!caloMETCollection.isValid()) {
0123     edm::LogError("SUSY_HLT_VBF_Mu") << "invalid collection: CaloMET"
0124                                      << "\n";
0125     return;
0126   }
0127 
0128   edm::Handle<reco::PFMETCollection> pfMETCollection;
0129   e.getByToken(thePfMETCollection_, pfMETCollection);
0130   if (!pfMETCollection.isValid()) {
0131     edm::LogError("SUSY_HLT_VBF_Mu") << "invalid collection: PFMET"
0132                                      << "\n";
0133     return;
0134   }
0135   //

0136 
0137   //-------------------------------

0138   //--- Trigger

0139   //-------------------------------

0140   edm::Handle<edm::TriggerResults> hltresults;
0141   e.getByToken(triggerResults_, hltresults);
0142   if (!hltresults.isValid()) {
0143     edm::LogError("SUSY_HLT_VBF_Mu") << "invalid collection: TriggerResults"
0144                                      << "\n";
0145     return;
0146   }
0147   edm::Handle<trigger::TriggerEvent> triggerSummary;
0148   e.getByToken(theTrigSummary_, triggerSummary);
0149   if (!triggerSummary.isValid()) {
0150     edm::LogError("SUSY_HLT_VBF_Mu") << "invalid collection: TriggerSummary"
0151                                      << "\n";
0152     return;
0153   }
0154 
0155   // get online objects

0156 
0157   std::vector<float> ptMuon, etaMuon, phiMuon;
0158   size_t filterIndexMu = triggerSummary->filterIndex(triggerMuFilter_);
0159   trigger::TriggerObjectCollection triggerObjects = triggerSummary->getObjects();
0160   if (!(filterIndexMu >= triggerSummary->sizeFilters())) {
0161     const trigger::Keys &keys = triggerSummary->filterKeys(filterIndexMu);
0162     for (size_t j = 0; j < keys.size(); ++j) {
0163       trigger::TriggerObject foundObject = triggerObjects[keys[j]];
0164       if (fabs(foundObject.id()) == 13) {  // It's a muon

0165 
0166         bool same = false;
0167         for (unsigned int x = 0; x < ptMuon.size(); x++) {
0168           if (fabs(ptMuon[x] - foundObject.pt()) < 0.01)
0169             same = true;
0170         }
0171 
0172         if (!same) {
0173           h_triggerMuPt->Fill(foundObject.pt());
0174           h_triggerMuEta->Fill(foundObject.eta());
0175           h_triggerMuPhi->Fill(foundObject.phi());
0176           ptMuon.push_back(foundObject.pt());
0177           etaMuon.push_back(foundObject.eta());
0178           phiMuon.push_back(foundObject.phi());
0179         }
0180       }
0181     }
0182   }
0183 
0184   // get online objects

0185 
0186   size_t filterIndexMet = triggerSummary->filterIndex(triggerMetFilter_);
0187   size_t dijetFilterIndex = triggerSummary->filterIndex(triggerDiJetFilter_);
0188 
0189   if (!(filterIndexMet >= triggerSummary->sizeFilters())) {
0190     const trigger::Keys &keys = triggerSummary->filterKeys(filterIndexMet);
0191     for (size_t j = 0; j < keys.size(); ++j) {
0192       trigger::TriggerObject foundObject = triggerObjects[keys[j]];
0193       h_triggerMet->Fill(foundObject.pt());
0194       h_triggerMetPhi->Fill(foundObject.phi());
0195     }
0196   }
0197 
0198   dijet = -1;
0199 
0200   std::vector<float> ptJet, etaJet, phiJet;
0201   if (!(dijetFilterIndex >= triggerSummary->sizeFilters())) {
0202     const trigger::Keys &KEYS(triggerSummary->filterKeys(dijetFilterIndex));
0203     const size_t nK(KEYS.size());
0204     const trigger::TriggerObjectCollection &TOC(triggerSummary->getObjects());
0205 
0206     for (size_t i = 0; i < nK; i++) {
0207       const trigger::TriggerObject &TO1(TOC[KEYS[i]]);
0208       if (TO1.pt() > ptThrJetTrig_ && fabs(TO1.eta()) < etaThrJetTrig_) {
0209         // for dijet part

0210         for (size_t j = i; j < nK; j++) {
0211           if (i < j) {
0212             const trigger::TriggerObject &TO2(TOC[KEYS[j]]);
0213             if (TO2.pt() > ptThrJetTrig_ && fabs(TO2.eta()) < etaThrJetTrig_) {
0214               double tmpdeta = fabs(TO1.eta() - TO2.eta());
0215               double tmpopposite = TO1.eta() * TO2.eta();
0216               if (tmpdeta > deltaetaVBFJets && tmpopposite < 0) {
0217                 TLorentzVector j1(TO1.px(), TO1.py(), TO1.pz(), TO1.energy());
0218                 TLorentzVector j2(TO2.px(), TO2.py(), TO2.pz(), TO2.energy());
0219                 double tmpmass = (j1 + j2).M();
0220                 if (dijet < tmpmass) {
0221                   dijet = tmpmass;
0222                 }
0223               }
0224             }
0225           }
0226         }
0227       }
0228     }
0229     h_DiJetMass->Fill(dijet);
0230   }
0231 
0232   size_t filterIndexCaloMET = triggerSummary->filterIndex(triggerCaloMETFilter_);
0233   if (filterIndexCaloMET < triggerSummary->sizeFilters()) {
0234     const trigger::Keys &keys = triggerSummary->filterKeys(filterIndexCaloMET);
0235     if (!keys.empty()) {
0236       float met_h = triggerObjects[keys[0]].pt();
0237       h_triggerCaloMet->Fill(met_h);
0238     }
0239   }
0240 
0241   size_t filterIndexHt = triggerSummary->filterIndex(triggerHTFilter_);
0242   if (filterIndexHt < triggerSummary->sizeFilters()) {
0243     const trigger::Keys &keys = triggerSummary->filterKeys(filterIndexHt);
0244     if (!keys.empty()) {
0245       float ht = triggerObjects[keys[0]].pt();
0246       h_ht->Fill(ht);
0247     }
0248   }
0249 
0250   bool hasFired = false;
0251 
0252   const edm::TriggerNames &trigNames = e.triggerNames(*hltresults);
0253   unsigned int numTriggers = trigNames.size();
0254 
0255   for (unsigned int hltIndex = 0; hltIndex < numTriggers; ++hltIndex) {
0256     if (trigNames.triggerName(hltIndex).find(triggerPath_) != std::string::npos && hltresults->wasrun(hltIndex) &&
0257         hltresults->accept(hltIndex))
0258       hasFired = true;
0259   }
0260 
0261   // Matching the muon

0262   int indexOfMatchedMuon = -1;
0263   int offlineCounter = 0;
0264   for (reco::MuonCollection::const_iterator muon = MuonCollection->begin(); muon != MuonCollection->end(); ++muon) {
0265     for (size_t off_i = 0; off_i < ptMuon.size(); ++off_i) {
0266       if (reco::deltaR(muon->eta(), muon->phi(), etaMuon[off_i], phiMuon[off_i]) < 0.5) {
0267         indexOfMatchedMuon = offlineCounter;
0268         break;
0269       }
0270     }
0271     offlineCounter++;
0272   }
0273 
0274   float pfHT = 0.0;
0275 
0276   for (reco::PFJetCollection::const_iterator i_pfjet = pfJetCollection->begin(); i_pfjet != pfJetCollection->end();
0277        ++i_pfjet) {
0278     if (i_pfjet->pt() < ptThrJet_)
0279       continue;
0280     if (fabs(i_pfjet->eta()) > etaThrJet_)
0281       continue;
0282     pfHT += i_pfjet->pt();
0283   }
0284 
0285   //

0286 
0287   dijetOff = -1;
0288 
0289   size_t jetCol = pfJetCollection->size();
0290 
0291   for (size_t i = 0; i < jetCol; i++) {
0292     if (pfJetCollection->at(i).pt() > ptThrJetTrig_ && fabs(pfJetCollection->at(i).eta()) < etaThrJetTrig_) {
0293       for (size_t j = i; j < jetCol; j++) {
0294         if (i < j) {
0295           if (pfJetCollection->at(j).pt() > ptThrJetTrig_ && fabs(pfJetCollection->at(j).eta()) < etaThrJetTrig_) {
0296             double tmpdetaOff = fabs(pfJetCollection->at(i).eta() - pfJetCollection->at(j).eta());
0297             double tmpoppositeOff = pfJetCollection->at(i).eta() * pfJetCollection->at(j).eta();
0298             if (tmpdetaOff > deltaetaVBFJets && tmpoppositeOff < 0) {
0299               TLorentzVector j1Off(pfJetCollection->at(i).px(),
0300                                    pfJetCollection->at(i).py(),
0301                                    pfJetCollection->at(i).pz(),
0302                                    pfJetCollection->at(i).energy());
0303               TLorentzVector j2Off(pfJetCollection->at(j).px(),
0304                                    pfJetCollection->at(j).py(),
0305                                    pfJetCollection->at(j).pz(),
0306                                    pfJetCollection->at(j).energy());
0307               double tmpmassOff = (j1Off + j2Off).M();
0308               if (dijetOff < tmpmassOff)
0309                 dijetOff = tmpmassOff;
0310             }
0311           }
0312         }
0313       }
0314     }
0315   }
0316 
0317   //  For trigger turn on curves

0318 
0319   // for muon

0320   if (indexOfMatchedMuon > -1 && (dijetOff > mjjOnlinethreshold) &&
0321       (pfMETCollection->begin()->et() > pfmetOnlinethreshold) && (pfHT > htOnlinethreshold)) {
0322     h_den_muonpt->Fill(MuonCollection->at(indexOfMatchedMuon).pt());
0323     h_den_muoneta->Fill(MuonCollection->at(indexOfMatchedMuon).eta());
0324     if (hasFired) {
0325       h_num_muonpt->Fill(MuonCollection->at(indexOfMatchedMuon).pt());
0326       h_num_muoneta->Fill(MuonCollection->at(indexOfMatchedMuon).eta());
0327     }
0328   }
0329 
0330   // For MJJ

0331   if (indexOfMatchedMuon > -1 && (MuonCollection->at(indexOfMatchedMuon).pt() > muonOnlinethreshold) &&
0332       (pfMETCollection->begin()->et() > pfmetOnlinethreshold) && (pfHT > htOnlinethreshold)) {
0333     h_den_mjj->Fill(dijetOff);
0334     if (hasFired) {
0335       h_num_mjj->Fill(dijetOff);
0336     }
0337   }
0338 
0339   // For HT

0340   //

0341   if (indexOfMatchedMuon > -1 && (MuonCollection->at(indexOfMatchedMuon).pt() > muonOnlinethreshold) &&
0342       (pfMETCollection->begin()->et() > pfmetOnlinethreshold) && (dijetOff > mjjOnlinethreshold)) {
0343     h_den_ht->Fill(pfHT);
0344     if (hasFired) {
0345       h_num_ht->Fill(pfHT);
0346     }
0347   }
0348 
0349   if (indexOfMatchedMuon > -1 && (dijetOff > mjjOnlinethreshold) && (pfHT > htOnlinethreshold) &&
0350       (MuonCollection->at(indexOfMatchedMuon).pt() > muonOnlinethreshold)) {
0351     h_den_met->Fill(pfMETCollection->begin()->et());
0352     if (hasFired) {
0353       h_num_met->Fill(pfMETCollection->begin()->et());
0354     }
0355   }
0356 }
0357 
0358 void SUSY_HLT_VBF_Mu::bookHistos(DQMStore::IBooker &ibooker_) {
0359   ibooker_.cd();
0360   ibooker_.setCurrentFolder("HLT/SUSYBSM/SUSY_HLT_VBF_Mu");
0361 
0362   // offline quantities

0363 
0364   // online quantities

0365   h_triggerMuPt = ibooker_.book1D("triggerMuPt", "Trigger Muon Pt; GeV", 50, 0.0, 500.0);
0366   h_triggerMuEta = ibooker_.book1D("triggerMuEta", "Trigger Muon Eta", 20, -3.0, 3.0);
0367   h_triggerMuPhi = ibooker_.book1D("triggerMuPhi", "Trigger Muon Phi", 20, -3.5, 3.5);
0368 
0369   h_triggerCaloMet = ibooker_.book1D("h_triggerCaloMet", "Trigger Calo MET; GeV", 20, 0.0, 500.0);
0370 
0371   h_ht = ibooker_.book1D("h_ht", "h_ht", 30, 0.0, 1500.0);
0372 
0373   h_triggerMet = ibooker_.book1D("triggerMet", "Trigger MET; GeV", 20, 0.0, 500.0);
0374   h_triggerMetPhi = ibooker_.book1D("triggerMetPhi", "Trigger MET Phi", 20, -3.5, 3.5);
0375 
0376   h_DiJetMass = ibooker_.book1D("h_DiJetMass", "h_DiJetMass", 500, 0.0, 5000.0);
0377 
0378   // num and den hists to be divided in harvesting step to make turn on curves

0379 
0380   h_den_muonpt = ibooker_.book1D("h_den_muonpt", "h_den_muonpt", 50, 0.0, 500.0);
0381   h_num_muonpt = ibooker_.book1D("h_num_muonpt", "h_num_muonpt", 50, 0.0, 500.0);
0382 
0383   h_den_muoneta = ibooker_.book1D("h_den_muoneta", "h_den_muoneta", 20, -3.0, 3.0);
0384   h_num_muoneta = ibooker_.book1D("h_num_muoneta", "h_num_muoneta", 20, -3.0, 3.0);
0385 
0386   h_den_mjj = ibooker_.book1D("h_den_mjj", "h_den_mjj", 500, 0.0, 5000.0);
0387   h_num_mjj = ibooker_.book1D("h_num_mjj", "h_num_mjj", 500, 0.0, 5000.0);
0388 
0389   h_den_met = ibooker_.book1D("h_den_met", "h_den_met", 20, 0.0, 500.0);
0390   h_num_met = ibooker_.book1D("h_num_met", "h_num_met", 20, 0.0, 500.0);
0391 
0392   h_den_ht = ibooker_.book1D("h_den_ht", "h_den_ht", 30, 0.0, 1500.0);
0393   h_num_ht = ibooker_.book1D("h_num_ht", "h_num_ht", 30, 0.0, 1500.0);
0394 
0395   ibooker_.cd();
0396 }
0397 
0398 // define this as a plug-in

0399 DEFINE_FWK_MODULE(SUSY_HLT_VBF_Mu);