Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DataFormats/HLTReco/interface/TriggerObject.h"
0002 #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
0003 #include "DataFormats/Math/interface/LorentzVector.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_MuEle_Hadronic.h"
0009 
0010 SUSY_HLT_MuEle_Hadronic::SUSY_HLT_MuEle_Hadronic(const edm::ParameterSet &ps) {
0011   edm::LogInfo("SUSY_HLT_MuEle_Hadronic")
0012       << "Constructor SUSY_HLT_MuEle_Hadronic::SUSY_HLT_MuEle_Hadronic " << std::endl;
0013   // Get parameters from configuration file

0014   theTrigSummary_ = consumes<trigger::TriggerEvent>(ps.getParameter<edm::InputTag>("trigSummary"));
0015   theMuonCollection_ = consumes<reco::MuonCollection>(ps.getParameter<edm::InputTag>("MuonCollection"));
0016   theElectronCollection_ = consumes<reco::GsfElectronCollection>(ps.getParameter<edm::InputTag>("ElectronCollection"));
0017   thePfJetCollection_ = consumes<reco::PFJetCollection>(ps.getParameter<edm::InputTag>("pfJetCollection"));
0018   theCaloJetCollection_ = consumes<reco::CaloJetCollection>(ps.getParameter<edm::InputTag>("caloJetCollection"));
0019   triggerResults_ = consumes<edm::TriggerResults>(ps.getParameter<edm::InputTag>("TriggerResults"));
0020   HLTProcess_ = ps.getParameter<std::string>("HLTProcess");
0021   triggerPath_ = ps.getParameter<std::string>("TriggerPath");
0022   triggerPathAuxiliaryForMuEle_ = ps.getParameter<std::string>("TriggerPathAuxiliaryForMuEle");
0023   triggerPathAuxiliaryForHadronic_ = ps.getParameter<std::string>("TriggerPathAuxiliaryForHadronic");
0024   triggerFilter_ = ps.getParameter<edm::InputTag>("TriggerFilter");
0025   ptThrJet_ = ps.getUntrackedParameter<double>("PtThrJet");
0026   etaThrJet_ = ps.getUntrackedParameter<double>("EtaThrJet");
0027 }
0028 
0029 SUSY_HLT_MuEle_Hadronic::~SUSY_HLT_MuEle_Hadronic() {
0030   edm::LogInfo("SUSY_HLT_MuEle_Hadronic")
0031       << "Destructor SUSY_HLT_MuEle_Hadronic::~SUSY_HLT_MuEle_Hadronic " << std::endl;
0032 }
0033 
0034 void SUSY_HLT_MuEle_Hadronic::dqmBeginRun(edm::Run const &run, edm::EventSetup const &e) {
0035   bool changed;
0036 
0037   if (!fHltConfig.init(run, e, HLTProcess_, changed)) {
0038     edm::LogError("SUSY_HLT_MuEle_Hadronic") << "Initialization of HLTConfigProvider failed!!";
0039     return;
0040   }
0041 
0042   bool pathFound = false;
0043   const std::vector<std::string> allTrigNames = fHltConfig.triggerNames();
0044   for (size_t j = 0; j < allTrigNames.size(); ++j) {
0045     if (allTrigNames[j].find(triggerPath_) != std::string::npos) {
0046       pathFound = true;
0047     }
0048   }
0049 
0050   if (!pathFound) {
0051     LogDebug("SUSY_HLT_MuEle_Hadronic") << "Path not found"
0052                                         << "\n";
0053     return;
0054   }
0055   // std::vector<std::string> filtertags = fHltConfig.moduleLabels( triggerPath_

0056   // ); triggerFilter_ =

0057   // edm::InputTag(filtertags[filtertags.size()-1],"",fHltConfig.processName());

0058   // triggerFilter_ = edm::InputTag("hltPFMET120Mu5L3PreFiltered", "",

0059   // fHltConfig.processName());

0060 
0061   edm::LogInfo("SUSY_HLT_MuEle_Hadronic") << "SUSY_HLT_MuEle_Hadronic::beginRun" << std::endl;
0062 }
0063 
0064 void SUSY_HLT_MuEle_Hadronic::bookHistograms(DQMStore::IBooker &ibooker_, edm::Run const &, edm::EventSetup const &) {
0065   edm::LogInfo("SUSY_HLT_MuEle_Hadronic") << "SUSY_HLT_MuEle_Hadronic::bookHistograms" << std::endl;
0066   // book at beginRun

0067   bookHistos(ibooker_);
0068 }
0069 
0070 void SUSY_HLT_MuEle_Hadronic::analyze(edm::Event const &e, edm::EventSetup const &eSetup) {
0071   edm::LogInfo("SUSY_HLT_MuEle_Hadronic") << "SUSY_HLT_MuEle_Hadronic::analyze" << std::endl;
0072 
0073   //-------------------------------

0074   //--- Jets

0075   //-------------------------------

0076   edm::Handle<reco::PFJetCollection> pfJetCollection;
0077   e.getByToken(thePfJetCollection_, pfJetCollection);
0078   if (!pfJetCollection.isValid()) {
0079     edm::LogError("SUSY_HLT_MuEle_Hadronic") << "invalid collection: PFJets"
0080                                              << "\n";
0081     return;
0082   }
0083   edm::Handle<reco::CaloJetCollection> caloJetCollection;
0084   e.getByToken(theCaloJetCollection_, caloJetCollection);
0085   if (!caloJetCollection.isValid()) {
0086     edm::LogError("SUSY_HLT_MuEle_Hadronic") << "invalid collection: CaloJets"
0087                                              << "\n";
0088     return;
0089   }
0090 
0091   //-------------------------------

0092   //--- Muon

0093   //-------------------------------

0094   edm::Handle<reco::MuonCollection> MuonCollection;
0095   e.getByToken(theMuonCollection_, MuonCollection);
0096   if (!MuonCollection.isValid()) {
0097     edm::LogError("SUSY_HLT_MuEle_Hadronic") << "invalid collection: Muons "
0098                                              << "\n";
0099     return;
0100   }
0101 
0102   //-------------------------------

0103   //--- Electron

0104   //-------------------------------

0105   edm::Handle<reco::GsfElectronCollection> ElectronCollection;
0106   e.getByToken(theElectronCollection_, ElectronCollection);
0107   if (!ElectronCollection.isValid()) {
0108     edm::LogError("SUSY_HLT_MuEle_Hadronic") << "invalid collection: Electrons "
0109                                              << "\n";
0110     return;
0111   }
0112 
0113   //-------------------------------

0114   //--- Trigger

0115   //-------------------------------

0116   edm::Handle<edm::TriggerResults> hltresults;
0117   e.getByToken(triggerResults_, hltresults);
0118   if (!hltresults.isValid()) {
0119     edm::LogError("SUSY_HLT_MuEle_Hadronic") << "invalid collection: TriggerResults"
0120                                              << "\n";
0121     return;
0122   }
0123   edm::Handle<trigger::TriggerEvent> triggerSummary;
0124   e.getByToken(theTrigSummary_, triggerSummary);
0125   if (!triggerSummary.isValid()) {
0126     edm::LogError("SUSY_HLT_MuEle_Hadronic") << "invalid collection: TriggerSummary"
0127                                              << "\n";
0128     return;
0129   }
0130 
0131   // get online objects

0132   std::vector<float> ptMuon, etaMuon, phiMuon, ptElectron, etaElectron, phiElectron;
0133   size_t filterIndexEle = triggerSummary->filterIndex(triggerFilter_);
0134   trigger::TriggerObjectCollection triggerObjects = triggerSummary->getObjects();
0135   if (!(filterIndexEle >= triggerSummary->sizeFilters())) {
0136     const trigger::Keys &keys = triggerSummary->filterKeys(filterIndexEle);
0137     for (size_t j = 0; j < keys.size(); ++j) {
0138       trigger::TriggerObject foundObject = triggerObjects[keys[j]];
0139       if (foundObject.id() == trigger::TriggerElectron) {  // It's an electron

0140 
0141         bool same = false;
0142         for (unsigned int x = 0; x < ptElectron.size(); x++) {
0143           if (fabs(ptElectron[x] - foundObject.pt()) < 0.01 || fabs(etaElectron[x] - foundObject.eta()) < 0.001 ||
0144               fabs(phiElectron[x] - foundObject.phi()) < 0.001)
0145             same = true;
0146         }
0147 
0148         if (!same) {
0149           h_triggerElePt->Fill(foundObject.pt());
0150           h_triggerEleEta->Fill(foundObject.eta());
0151           h_triggerElePhi->Fill(foundObject.phi());
0152           ptElectron.push_back(foundObject.pt());
0153           etaElectron.push_back(foundObject.eta());
0154           phiElectron.push_back(foundObject.phi());
0155         }
0156       }
0157       if (foundObject.id() == trigger::TriggerMuon) {  // It's a muon

0158 
0159         bool same = false;
0160         for (unsigned int x = 0; x < ptMuon.size(); x++) {
0161           if (fabs(ptMuon[x] - foundObject.pt()) < 0.01)
0162             same = true;
0163         }
0164 
0165         if (!same) {
0166           h_triggerMuPt->Fill(foundObject.pt());
0167           h_triggerMuEta->Fill(foundObject.eta());
0168           h_triggerMuPhi->Fill(foundObject.phi());
0169           ptMuon.push_back(foundObject.pt());
0170           etaMuon.push_back(foundObject.eta());
0171           phiMuon.push_back(foundObject.phi());
0172         }
0173       }
0174     }
0175   }
0176 
0177   if (!ptMuon.empty() && !ptElectron.empty()) {
0178     math::PtEtaPhiMLorentzVectorD *mu1 = new math::PtEtaPhiMLorentzVectorD(ptMuon[0], etaMuon[0], phiMuon[0], 0.106);
0179     math::PtEtaPhiMLorentzVectorD *ele2 =
0180         new math::PtEtaPhiMLorentzVectorD(ptElectron[0], etaElectron[0], phiElectron[0], 0.0005);
0181     (*mu1) += (*ele2);
0182     h_triggerMuEleMass->Fill(mu1->M());
0183     delete mu1;
0184     delete ele2;
0185   } else {
0186     h_triggerMuEleMass->Fill(-1.);
0187   }
0188 
0189   bool hasFired = false;
0190   bool hasFiredAuxiliaryForMuEleLeg = false;
0191   bool hasFiredAuxiliaryForHadronicLeg = false;
0192   const edm::TriggerNames &trigNames = e.triggerNames(*hltresults);
0193   unsigned int numTriggers = trigNames.size();
0194   for (unsigned int hltIndex = 0; hltIndex < numTriggers; ++hltIndex) {
0195     if (trigNames.triggerName(hltIndex).find(triggerPath_) != std::string::npos && hltresults->wasrun(hltIndex) &&
0196         hltresults->accept(hltIndex))
0197       hasFired = true;
0198     if (trigNames.triggerName(hltIndex).find(triggerPathAuxiliaryForMuEle_) != std::string::npos &&
0199         hltresults->wasrun(hltIndex) && hltresults->accept(hltIndex))
0200       hasFiredAuxiliaryForMuEleLeg = true;
0201     if (trigNames.triggerName(hltIndex).find(triggerPathAuxiliaryForHadronic_) != std::string::npos &&
0202         hltresults->wasrun(hltIndex) && hltresults->accept(hltIndex))
0203       hasFiredAuxiliaryForHadronicLeg = true;
0204   }
0205 
0206   if (hasFiredAuxiliaryForMuEleLeg || hasFiredAuxiliaryForHadronicLeg) {
0207     // Matching the muon

0208     int indexOfMatchedMuEle[2] = {-1};
0209     int matchedCounter = 0;
0210     int offlineCounter = 0;
0211     for (reco::MuonCollection::const_iterator muon = MuonCollection->begin();
0212          (muon != MuonCollection->end() && matchedCounter < 1);
0213          ++muon) {
0214       for (size_t off_i = 0; off_i < ptMuon.size(); ++off_i) {
0215         if (sqrt((muon->phi() - phiMuon[off_i]) * (muon->phi() - phiMuon[off_i]) +
0216                  (muon->eta() - etaMuon[off_i]) * (muon->eta() - etaMuon[off_i])) < 0.5) {
0217           indexOfMatchedMuEle[matchedCounter] = offlineCounter;
0218           matchedCounter++;
0219           break;
0220         }
0221       }
0222       offlineCounter++;
0223     }
0224 
0225     for (reco::GsfElectronCollection::const_iterator electron = ElectronCollection->begin();
0226          (electron != ElectronCollection->end() && matchedCounter < 2);
0227          ++electron) {
0228       for (size_t off_i = 0; off_i < ptElectron.size(); ++off_i) {
0229         if (sqrt((electron->phi() - phiElectron[off_i]) * (electron->phi() - phiElectron[off_i]) +
0230                  (electron->eta() - etaElectron[off_i]) * (electron->eta() - etaElectron[off_i])) < 0.5) {
0231           indexOfMatchedMuEle[matchedCounter] = offlineCounter;
0232           matchedCounter++;
0233           break;
0234         }
0235       }
0236       offlineCounter++;
0237     }
0238 
0239     float caloHT = 0.0;
0240     float pfHT = 0.0;
0241     for (reco::PFJetCollection::const_iterator i_pfjet = pfJetCollection->begin(); i_pfjet != pfJetCollection->end();
0242          ++i_pfjet) {
0243       if (i_pfjet->pt() < ptThrJet_)
0244         continue;
0245       if (fabs(i_pfjet->eta()) > etaThrJet_)
0246         continue;
0247       pfHT += i_pfjet->pt();
0248     }
0249     for (reco::CaloJetCollection::const_iterator i_calojet = caloJetCollection->begin();
0250          i_calojet != caloJetCollection->end();
0251          ++i_calojet) {
0252       if (i_calojet->pt() < ptThrJet_)
0253         continue;
0254       if (fabs(i_calojet->eta()) > etaThrJet_)
0255         continue;
0256       caloHT += i_calojet->pt();
0257     }
0258 
0259     if (hasFiredAuxiliaryForMuEleLeg && !MuonCollection->empty() && !ElectronCollection->empty()) {
0260       if (hasFired && indexOfMatchedMuEle[1] >= 0 && indexOfMatchedMuEle[0] >= 0) {  // check that ele is there too

0261         h_EleTurnOn_num->Fill(ElectronCollection->at(indexOfMatchedMuEle[1]).pt());
0262         h_MuTurnOn_num->Fill(MuonCollection->at(indexOfMatchedMuEle[0]).pt());
0263       }
0264       h_MuTurnOn_den->Fill(MuonCollection->at(0).pt());
0265       h_EleTurnOn_den->Fill(ElectronCollection->at(0).pt());
0266     }
0267 
0268     if (hasFiredAuxiliaryForHadronicLeg) {
0269       if (hasFired) {
0270         h_pfHTTurnOn_num->Fill(pfHT);
0271       }
0272       h_pfHTTurnOn_den->Fill(pfHT);
0273     }
0274   }
0275 }
0276 
0277 void SUSY_HLT_MuEle_Hadronic::bookHistos(DQMStore::IBooker &ibooker_) {
0278   ibooker_.cd();
0279   ibooker_.setCurrentFolder("HLT/SUSYBSM/" + triggerPath_);
0280 
0281   // offline quantities

0282 
0283   // online quantities

0284   h_triggerMuPt = ibooker_.book1D("triggerMuPt", "Trigger Muon Pt; GeV", 50, 0.0, 500.0);
0285   h_triggerMuEta = ibooker_.book1D("triggerMuEta", "Trigger Muon Eta", 20, -3.0, 3.0);
0286   h_triggerMuPhi = ibooker_.book1D("triggerMuPhi", "Trigger Muon Phi", 20, -3.5, 3.5);
0287 
0288   h_triggerElePt = ibooker_.book1D("triggerElePt", "Trigger Electron Pt; GeV", 50, 0.0, 500.0);
0289   h_triggerEleEta = ibooker_.book1D("triggerEleEta", "Trigger Electron Eta", 20, -3.0, 3.0);
0290   h_triggerElePhi = ibooker_.book1D("triggerElePhi", "Trigger Electron Phi", 20, -3.5, 3.5);
0291 
0292   h_triggerMuEleMass = ibooker_.book1D("triggerMuEleMass", "Trigger MuEle Mass", 202, -2, 200);
0293 
0294   // num and den hists to be divided in harvesting step to make turn on curves

0295   h_pfHTTurnOn_num = ibooker_.book1D("pfHTTurnOn_num", "PF HT Turn On Numerator", 30, 0.0, 1500.0);
0296   h_pfHTTurnOn_den = ibooker_.book1D("pfHTTurnOn_den", "PF HT Turn On Denominator", 30, 0.0, 1500.0);
0297   h_MuTurnOn_num = ibooker_.book1D("MuTurnOn_num", "Muon Turn On Numerator", 30, 0.0, 150);
0298   h_MuTurnOn_den = ibooker_.book1D("MuTurnOn_den", "Muon Turn On Denominator", 30, 0.0, 150.0);
0299   h_EleTurnOn_num = ibooker_.book1D("EleTurnOn_num", "Electron Turn On Numerator", 30, 0.0, 150);
0300   h_EleTurnOn_den = ibooker_.book1D("EleTurnOn_den", "Electron Turn On Denominator", 30, 0.0, 150.0);
0301 
0302   ibooker_.cd();
0303 }
0304 
0305 // define this as a plug-in

0306 DEFINE_FWK_MODULE(SUSY_HLT_MuEle_Hadronic);