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/Math/interface/LorentzVector.h"
0003 #include "FWCore/Common/interface/TriggerNames.h"
0004 #include "FWCore/Framework/interface/Frameworkfwd.h"
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "HLTriggerOffline/SUSYBSM/interface/SUSY_HLT_DoubleMuon_Hadronic.h"
0008 
0009 SUSY_HLT_DoubleMuon_Hadronic::SUSY_HLT_DoubleMuon_Hadronic(const edm::ParameterSet &ps) {
0010   edm::LogInfo("SUSY_HLT_DoubleMuon_Hadronic") << "Constructor "
0011                                                   "SUSY_HLT_DoubleMuon_Hadronic::SUSY_HLT_DoubleMuon_Hadronic "
0012                                                << 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   thePfJetCollection_ = consumes<reco::PFJetCollection>(ps.getParameter<edm::InputTag>("pfJetCollection"));
0017   theCaloJetCollection_ = consumes<reco::CaloJetCollection>(ps.getParameter<edm::InputTag>("caloJetCollection"));
0018   triggerResults_ = consumes<edm::TriggerResults>(ps.getParameter<edm::InputTag>("TriggerResults"));
0019   HLTProcess_ = ps.getParameter<std::string>("HLTProcess");
0020   triggerPath_ = ps.getParameter<std::string>("TriggerPath");
0021   triggerPathAuxiliaryForMuon_ = ps.getParameter<std::string>("TriggerPathAuxiliaryForMuon");
0022   triggerPathAuxiliaryForHadronic_ = ps.getParameter<std::string>("TriggerPathAuxiliaryForHadronic");
0023   triggerFilter_ = ps.getParameter<edm::InputTag>("TriggerFilter");
0024   ptThrJet_ = ps.getUntrackedParameter<double>("PtThrJet");
0025   etaThrJet_ = ps.getUntrackedParameter<double>("EtaThrJet");
0026 }
0027 
0028 SUSY_HLT_DoubleMuon_Hadronic::~SUSY_HLT_DoubleMuon_Hadronic() {
0029   edm::LogInfo("SUSY_HLT_DoubleMuon_Hadronic") << "Destructor "
0030                                                   "SUSY_HLT_DoubleMuon_Hadronic::~SUSY_HLT_DoubleMuon_Hadronic "
0031                                                << std::endl;
0032 }
0033 
0034 void SUSY_HLT_DoubleMuon_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_DoubleMuon_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_DoubleMuon_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_DoubleMuon_Hadronic") << "SUSY_HLT_DoubleMuon_Hadronic::beginRun" << std::endl;
0062 }
0063 
0064 void SUSY_HLT_DoubleMuon_Hadronic::bookHistograms(DQMStore::IBooker &ibooker_,
0065                                                   edm::Run const &,
0066                                                   edm::EventSetup const &) {
0067   edm::LogInfo("SUSY_HLT_DoubleMuon_Hadronic") << "SUSY_HLT_DoubleMuon_Hadronic::bookHistograms" << std::endl;
0068   // book at beginRun

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

0076   //--- Jets

0077   //-------------------------------

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

0094   //--- Muon

0095   //-------------------------------

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

0105   //--- Trigger

0106   //-------------------------------

0107   edm::Handle<edm::TriggerResults> hltresults;
0108   e.getByToken(triggerResults_, hltresults);
0109   if (!hltresults.isValid()) {
0110     edm::LogError("SUSY_HLT_DoubleMuon_Hadronic") << "invalid collection: TriggerResults"
0111                                                   << "\n";
0112     return;
0113   }
0114   edm::Handle<trigger::TriggerEvent> triggerSummary;
0115   e.getByToken(theTrigSummary_, triggerSummary);
0116   if (!triggerSummary.isValid()) {
0117     edm::LogError("SUSY_HLT_DoubleMuon_Hadronic") << "invalid collection: TriggerSummary"
0118                                                   << "\n";
0119     return;
0120   }
0121 
0122   // get online objects

0123   std::vector<float> ptMuon, etaMuon, phiMuon;
0124   size_t filterIndex = triggerSummary->filterIndex(triggerFilter_);
0125   trigger::TriggerObjectCollection triggerObjects = triggerSummary->getObjects();
0126   if (!(filterIndex >= triggerSummary->sizeFilters())) {
0127     const trigger::Keys &keys = triggerSummary->filterKeys(filterIndex);
0128     for (size_t j = 0; j < keys.size(); ++j) {
0129       trigger::TriggerObject foundObject = triggerObjects[keys[j]];
0130       if (fabs(foundObject.id()) == 13) {  // It's a muon

0131         h_triggerMuPt->Fill(foundObject.pt());
0132         h_triggerMuEta->Fill(foundObject.eta());
0133         h_triggerMuPhi->Fill(foundObject.phi());
0134         ptMuon.push_back(foundObject.pt());
0135         etaMuon.push_back(foundObject.eta());
0136         phiMuon.push_back(foundObject.phi());
0137       }
0138     }
0139     if (ptMuon.size() >= 2) {
0140       math::PtEtaPhiMLorentzVectorD *mu1 = new math::PtEtaPhiMLorentzVectorD(ptMuon[0], etaMuon[0], phiMuon[0], 0.106);
0141       math::PtEtaPhiMLorentzVectorD *mu2 = new math::PtEtaPhiMLorentzVectorD(ptMuon[1], etaMuon[1], phiMuon[1], 0.106);
0142       (*mu1) += (*mu2);
0143       h_triggerDoubleMuMass->Fill(mu1->M());
0144       delete mu1;
0145       delete mu2;
0146     } else {
0147       h_triggerDoubleMuMass->Fill(-1.);
0148     }
0149   }
0150 
0151   bool hasFired = false;
0152   bool hasFiredAuxiliaryForMuonLeg = false;
0153   bool hasFiredAuxiliaryForHadronicLeg = false;
0154   const edm::TriggerNames &trigNames = e.triggerNames(*hltresults);
0155   unsigned int numTriggers = trigNames.size();
0156   for (unsigned int hltIndex = 0; hltIndex < numTriggers; ++hltIndex) {
0157     if (trigNames.triggerName(hltIndex).find(triggerPath_) != std::string::npos && hltresults->wasrun(hltIndex) &&
0158         hltresults->accept(hltIndex))
0159       hasFired = true;
0160     if (trigNames.triggerName(hltIndex).find(triggerPathAuxiliaryForMuon_) != std::string::npos &&
0161         hltresults->wasrun(hltIndex) && hltresults->accept(hltIndex))
0162       hasFiredAuxiliaryForMuonLeg = true;
0163     if (trigNames.triggerName(hltIndex).find(triggerPathAuxiliaryForHadronic_) != std::string::npos &&
0164         hltresults->wasrun(hltIndex) && hltresults->accept(hltIndex))
0165       hasFiredAuxiliaryForHadronicLeg = true;
0166   }
0167 
0168   if (hasFiredAuxiliaryForMuonLeg || hasFiredAuxiliaryForHadronicLeg) {
0169     // Matching the muon

0170     int indexOfMatchedMuon[2] = {-1};
0171     int matchedCounter = 0;
0172     int offlineCounter = 0;
0173     for (reco::MuonCollection::const_iterator muon = MuonCollection->begin();
0174          (muon != MuonCollection->end() && matchedCounter < 2);
0175          ++muon) {
0176       for (size_t off_i = 0; off_i < ptMuon.size(); ++off_i) {
0177         if (sqrt((muon->phi() - phiMuon[off_i]) * (muon->phi() - phiMuon[off_i]) +
0178                  (muon->eta() - etaMuon[off_i]) * (muon->eta() - etaMuon[off_i])) < 0.5) {
0179           indexOfMatchedMuon[matchedCounter] = offlineCounter;
0180           matchedCounter++;
0181           break;
0182         }
0183       }
0184       offlineCounter++;
0185     }
0186 
0187     float caloHT = 0.0;
0188     float pfHT = 0.0;
0189     for (reco::PFJetCollection::const_iterator i_pfjet = pfJetCollection->begin(); i_pfjet != pfJetCollection->end();
0190          ++i_pfjet) {
0191       if (i_pfjet->pt() < ptThrJet_)
0192         continue;
0193       if (fabs(i_pfjet->eta()) > etaThrJet_)
0194         continue;
0195       pfHT += i_pfjet->pt();
0196     }
0197     for (reco::CaloJetCollection::const_iterator i_calojet = caloJetCollection->begin();
0198          i_calojet != caloJetCollection->end();
0199          ++i_calojet) {
0200       if (i_calojet->pt() < ptThrJet_)
0201         continue;
0202       if (fabs(i_calojet->eta()) > etaThrJet_)
0203         continue;
0204       caloHT += i_calojet->pt();
0205     }
0206 
0207     if (hasFiredAuxiliaryForMuonLeg && MuonCollection->size() > 1) {
0208       if (hasFired && indexOfMatchedMuon[1] >= 0) {  // fill trailing leg

0209         h_MuTurnOn_num->Fill(MuonCollection->at(indexOfMatchedMuon[1]).pt());
0210       }
0211       h_MuTurnOn_den->Fill(MuonCollection->at(1).pt());
0212     }
0213     if (hasFiredAuxiliaryForHadronicLeg) {
0214       if (hasFired) {
0215         h_pfHTTurnOn_num->Fill(pfHT);
0216       }
0217       h_pfHTTurnOn_den->Fill(pfHT);
0218     }
0219   }
0220 }
0221 
0222 void SUSY_HLT_DoubleMuon_Hadronic::bookHistos(DQMStore::IBooker &ibooker_) {
0223   ibooker_.cd();
0224   ibooker_.setCurrentFolder("HLT/SUSYBSM/" + triggerPath_);
0225 
0226   // offline quantities

0227 
0228   // online quantities

0229   h_triggerMuPt = ibooker_.book1D("triggerMuPt", "Trigger Muon Pt; GeV", 50, 0.0, 500.0);
0230   h_triggerMuEta = ibooker_.book1D("triggerMuEta", "Trigger Muon Eta", 20, -3.0, 3.0);
0231   h_triggerMuPhi = ibooker_.book1D("triggerMuPhi", "Trigger Muon Phi", 20, -3.5, 3.5);
0232 
0233   h_triggerDoubleMuMass = ibooker_.book1D("triggerDoubleMuMass", "Trigger DoubleMuon Mass", 202, -2, 200);
0234 
0235   // num and den hists to be divided in harvesting step to make turn on curves

0236   h_pfHTTurnOn_num = ibooker_.book1D("pfHTTurnOn_num", "PF HT Turn On Numerator", 30, 0.0, 1500.0);
0237   h_pfHTTurnOn_den = ibooker_.book1D("pfHTTurnOn_den", "PF HT Turn On Denominator", 30, 0.0, 1500.0);
0238   h_MuTurnOn_num = ibooker_.book1D("MuTurnOn_num", "Muon Turn On Numerator", 30, 0.0, 150);
0239   h_MuTurnOn_den = ibooker_.book1D("MuTurnOn_den", "Muon Turn On Denominator", 30, 0.0, 150.0);
0240 
0241   ibooker_.cd();
0242 }
0243 
0244 // define this as a plug-in

0245 DEFINE_FWK_MODULE(SUSY_HLT_DoubleMuon_Hadronic);