File indexing completed on 2023-03-17 11:10:08
0001 #include "DataFormats/HLTReco/interface/TriggerObject.h"
0002 #include "FWCore/Common/interface/TriggerNames.h"
0003 #include "FWCore/Framework/interface/Frameworkfwd.h"
0004 #include "FWCore/Framework/interface/MakerMacros.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "HLTriggerOffline/SUSYBSM/interface/SUSY_HLT_Muon_Hadronic.h"
0007
0008 bool comparePt(Lepton a, Lepton b) { return (a.pt > b.pt); }
0009
0010 SUSY_HLT_Muon_Hadronic::SUSY_HLT_Muon_Hadronic(const edm::ParameterSet &ps) {
0011 edm::LogInfo("SUSY_HLT_Muon_Hadronic") << "Constructor SUSY_HLT_Muon_Hadronic::SUSY_HLT_Muon_Hadronic " << std::endl;
0012
0013 theTrigSummary_ = consumes<trigger::TriggerEvent>(ps.getParameter<edm::InputTag>("trigSummary"));
0014 theMuonCollection_ = consumes<reco::MuonCollection>(ps.getParameter<edm::InputTag>("MuonCollection"));
0015 thePfMETCollection_ = consumes<reco::PFMETCollection>(ps.getParameter<edm::InputTag>("pfMETCollection"));
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 ptMuonOffline_ = ps.getUntrackedParameter<double>("ptMuonOffline");
0025 etaMuonOffline_ = ps.getUntrackedParameter<double>("etaMuonOffline");
0026 HTOffline_ = ps.getUntrackedParameter<double>("HTOffline");
0027 METOffline_ = ps.getUntrackedParameter<double>("METOffline");
0028 ptThrJet_ = ps.getUntrackedParameter<double>("PtThrJet");
0029 etaThrJet_ = ps.getUntrackedParameter<double>("EtaThrJet");
0030 }
0031
0032 SUSY_HLT_Muon_Hadronic::~SUSY_HLT_Muon_Hadronic() {
0033 edm::LogInfo("SUSY_HLT_Muon_Hadronic") << "Destructor SUSY_HLT_Muon_Hadronic::~SUSY_HLT_Muon_Hadronic " << std::endl;
0034 }
0035
0036 void SUSY_HLT_Muon_Hadronic::dqmBeginRun(edm::Run const &run, edm::EventSetup const &e) {
0037 bool changed;
0038
0039 if (!fHltConfig.init(run, e, HLTProcess_, changed)) {
0040 edm::LogError("SUSY_HLT_Muon_Hadronic") << "Initialization of HLTConfigProvider failed!!";
0041 return;
0042 }
0043
0044 bool pathFound = false;
0045 const std::vector<std::string> allTrigNames = fHltConfig.triggerNames();
0046 for (size_t j = 0; j < allTrigNames.size(); ++j) {
0047 if (allTrigNames[j].find(triggerPath_) != std::string::npos) {
0048 pathFound = true;
0049 }
0050 }
0051
0052 if (!pathFound) {
0053 LogDebug("SUSY_HLT_Muon_Hadronic") << "Path not found"
0054 << "\n";
0055 return;
0056 }
0057
0058
0059
0060
0061
0062
0063 edm::LogInfo("SUSY_HLT_Muon_Hadronic") << "SUSY_HLT_Muon_Hadronic::beginRun" << std::endl;
0064 }
0065
0066 void SUSY_HLT_Muon_Hadronic::bookHistograms(DQMStore::IBooker &ibooker_, edm::Run const &, edm::EventSetup const &) {
0067 edm::LogInfo("SUSY_HLT_Muon_Hadronic") << "SUSY_HLT_Muon_Hadronic::bookHistograms" << std::endl;
0068
0069 bookHistos(ibooker_);
0070 }
0071
0072 void SUSY_HLT_Muon_Hadronic::analyze(edm::Event const &e, edm::EventSetup const &eSetup) {
0073 edm::LogInfo("SUSY_HLT_Muon_Hadronic") << "SUSY_HLT_Muon_Hadronic::analyze" << std::endl;
0074
0075
0076
0077
0078 edm::Handle<reco::PFMETCollection> pfMETCollection;
0079 e.getByToken(thePfMETCollection_, pfMETCollection);
0080 if (!pfMETCollection.isValid()) {
0081 edm::LogError("SUSY_HLT_Muon_Hadronic") << "invalid collection: PFMET"
0082 << "\n";
0083 return;
0084 }
0085
0086
0087
0088 edm::Handle<reco::PFJetCollection> pfJetCollection;
0089 e.getByToken(thePfJetCollection_, pfJetCollection);
0090 if (!pfJetCollection.isValid()) {
0091 edm::LogError("SUSY_HLT_Muon_Hadronic") << "invalid collection: PFJets"
0092 << "\n";
0093 return;
0094 }
0095 edm::Handle<reco::CaloJetCollection> caloJetCollection;
0096 e.getByToken(theCaloJetCollection_, caloJetCollection);
0097 if (!caloJetCollection.isValid()) {
0098 edm::LogError("SUSY_HLT_Muon_Hadronic") << "invalid collection: CaloJets"
0099 << "\n";
0100 return;
0101 }
0102
0103
0104
0105
0106 edm::Handle<reco::MuonCollection> MuonCollection;
0107 e.getByToken(theMuonCollection_, MuonCollection);
0108 if (!MuonCollection.isValid()) {
0109 edm::LogError("SUSY_HLT_Mu_Hadronic") << "invalid collection: Muons "
0110 << "\n";
0111 return;
0112 }
0113
0114
0115
0116
0117 edm::Handle<edm::TriggerResults> hltresults;
0118 e.getByToken(triggerResults_, hltresults);
0119 if (!hltresults.isValid()) {
0120 edm::LogError("SUSY_HLT_Muon_Hadronic") << "invalid collection: TriggerResults"
0121 << "\n";
0122 return;
0123 }
0124 edm::Handle<trigger::TriggerEvent> triggerSummary;
0125 e.getByToken(theTrigSummary_, triggerSummary);
0126 if (!triggerSummary.isValid()) {
0127 edm::LogError("SUSY_HLT_Muon_Hadronic") << "invalid collection: TriggerSummary"
0128 << "\n";
0129 return;
0130 }
0131
0132
0133 std::vector<Lepton> onlineMuons;
0134 size_t filterIndex = triggerSummary->filterIndex(triggerFilter_);
0135 trigger::TriggerObjectCollection triggerObjects = triggerSummary->getObjects();
0136 if (!(filterIndex >= triggerSummary->sizeFilters())) {
0137 const trigger::Keys &keys = triggerSummary->filterKeys(filterIndex);
0138 for (size_t j = 0; j < keys.size(); ++j) {
0139 trigger::TriggerObject foundObject = triggerObjects[keys[j]];
0140 if (fabs(foundObject.id()) == 13) {
0141 h_triggerMuPt->Fill(foundObject.pt());
0142 h_triggerMuEta->Fill(foundObject.eta());
0143 h_triggerMuPhi->Fill(foundObject.phi());
0144 Lepton theMuon;
0145 theMuon.pt = foundObject.pt();
0146 theMuon.phi = foundObject.phi();
0147 theMuon.eta = foundObject.eta();
0148 onlineMuons.push_back(theMuon);
0149 }
0150 }
0151 }
0152
0153 bool hasFired = false;
0154 bool hasFiredAuxiliaryForMuonLeg = false;
0155 bool hasFiredAuxiliaryForHadronicLeg = false;
0156 const edm::TriggerNames &trigNames = e.triggerNames(*hltresults);
0157 unsigned int numTriggers = trigNames.size();
0158 for (unsigned int hltIndex = 0; hltIndex < numTriggers; ++hltIndex) {
0159 if (trigNames.triggerName(hltIndex).find(triggerPath_) != std::string::npos && hltresults->wasrun(hltIndex) &&
0160 hltresults->accept(hltIndex))
0161 hasFired = true;
0162 if (trigNames.triggerName(hltIndex).find(triggerPathAuxiliaryForMuon_) != std::string::npos &&
0163 hltresults->wasrun(hltIndex) && hltresults->accept(hltIndex))
0164 hasFiredAuxiliaryForMuonLeg = true;
0165 if (trigNames.triggerName(hltIndex).find(triggerPathAuxiliaryForHadronic_) != std::string::npos &&
0166 hltresults->wasrun(hltIndex) && hltresults->accept(hltIndex))
0167 hasFiredAuxiliaryForHadronicLeg = true;
0168 }
0169
0170 if (hasFiredAuxiliaryForMuonLeg || hasFiredAuxiliaryForHadronicLeg || !e.isRealData()) {
0171 std::vector<Lepton> offlineMuons;
0172 for (reco::MuonCollection::const_iterator muon = MuonCollection->begin(); muon != MuonCollection->end(); ++muon) {
0173 if (fabs(muon->eta()) > etaMuonOffline_)
0174 continue;
0175 Lepton theMuon;
0176 theMuon.pt = muon->pt();
0177 theMuon.phi = muon->phi();
0178 theMuon.eta = muon->eta();
0179 offlineMuons.push_back(theMuon);
0180 }
0181
0182 std::sort(onlineMuons.begin(), onlineMuons.end(), comparePt);
0183 std::sort(offlineMuons.begin(), offlineMuons.end(), comparePt);
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197 int indexOfMatchedMuon = -1;
0198 int offlineCounter = 0;
0199 for (std::vector<Lepton>::iterator offline_muon = offlineMuons.begin();
0200 (offline_muon != offlineMuons.end() && indexOfMatchedMuon == -1);
0201 offline_muon++) {
0202 for (std::vector<Lepton>::iterator online_muon = onlineMuons.begin(); online_muon != onlineMuons.end();
0203 online_muon++) {
0204 if (sqrt((offline_muon->phi - online_muon->phi) * (offline_muon->phi - online_muon->phi) +
0205 (offline_muon->eta - online_muon->eta) * (offline_muon->eta - online_muon->eta)) < 0.5) {
0206 indexOfMatchedMuon = offlineCounter;
0207
0208
0209 break;
0210 }
0211 }
0212 offlineCounter++;
0213 }
0214 float pfHT = 0.0;
0215 for (reco::PFJetCollection::const_iterator i_pfjet = pfJetCollection->begin(); i_pfjet != pfJetCollection->end();
0216 ++i_pfjet) {
0217 if (i_pfjet->pt() < ptThrJet_)
0218 continue;
0219 if (fabs(i_pfjet->eta()) > etaThrJet_)
0220 continue;
0221 pfHT += i_pfjet->pt();
0222 }
0223 for (reco::CaloJetCollection::const_iterator i_calojet = caloJetCollection->begin();
0224 i_calojet != caloJetCollection->end();
0225 ++i_calojet) {
0226 if (i_calojet->pt() < ptThrJet_)
0227 continue;
0228 if (fabs(i_calojet->eta()) > etaThrJet_)
0229 continue;
0230 }
0231
0232 if ((hasFiredAuxiliaryForMuonLeg || !e.isRealData()) && !offlineMuons.empty() &&
0233 pfMETCollection->begin()->et() > METOffline_ && pfHT > HTOffline_) {
0234 if (hasFired && indexOfMatchedMuon >= 0) {
0235 h_MuTurnOn_num->Fill(offlineMuons.at(indexOfMatchedMuon).pt);
0236 h_MuTurnOn_den->Fill(offlineMuons.at(indexOfMatchedMuon).pt);
0237 } else {
0238 h_MuTurnOn_den->Fill(offlineMuons.at(0).pt);
0239 }
0240 }
0241
0242 if ((hasFiredAuxiliaryForHadronicLeg || !e.isRealData()) && indexOfMatchedMuon >= 0 &&
0243 offlineMuons.at(indexOfMatchedMuon).pt > ptMuonOffline_ && pfHT > HTOffline_) {
0244 if (hasFired) {
0245 h_pfMetTurnOn_num->Fill(pfMETCollection->begin()->et());
0246 }
0247 h_pfMetTurnOn_den->Fill(pfMETCollection->begin()->et());
0248 }
0249 if ((hasFiredAuxiliaryForHadronicLeg || !e.isRealData()) && indexOfMatchedMuon >= 0 &&
0250 offlineMuons.at(indexOfMatchedMuon).pt > ptMuonOffline_ && pfMETCollection->begin()->et() > METOffline_) {
0251 if (hasFired) {
0252 h_pfHTTurnOn_num->Fill(pfHT);
0253 }
0254 h_pfHTTurnOn_den->Fill(pfHT);
0255 }
0256 }
0257 }
0258
0259 void SUSY_HLT_Muon_Hadronic::bookHistos(DQMStore::IBooker &ibooker_) {
0260 ibooker_.cd();
0261 ibooker_.setCurrentFolder("HLT/SUSYBSM/" + triggerPath_);
0262
0263
0264
0265
0266 h_triggerMuPt = ibooker_.book1D("triggerMuPt", "Trigger Muon Pt; GeV", 20, 0.0, 500.0);
0267 h_triggerMuEta = ibooker_.book1D("triggerMuEta", "Trigger Muon Eta", 20, -3.0, 3.0);
0268 h_triggerMuPhi = ibooker_.book1D("triggerMuPhi", "Trigger Muon Phi", 20, -3.5, 3.5);
0269
0270
0271 h_pfMetTurnOn_num = ibooker_.book1D("pfMetTurnOn_num", "PF MET Turn On Numerator", 20, 0.0, 500.0);
0272 h_pfMetTurnOn_den = ibooker_.book1D("pfMetTurnOn_den", "PF MET Turn OnDenominator", 20, 0.0, 500.0);
0273 h_pfHTTurnOn_num = ibooker_.book1D("pfHTTurnOn_num", "PF HT Turn On Numerator", 30, 0.0, 1500.0);
0274 h_pfHTTurnOn_den = ibooker_.book1D("pfHTTurnOn_den", "PF HT Turn On Denominator", 30, 0.0, 1500.0);
0275 h_MuTurnOn_num = ibooker_.book1D("MuTurnOn_num", "Muon Turn On Numerator", 30, 0.0, 150);
0276 h_MuTurnOn_den = ibooker_.book1D("MuTurnOn_den", "Muon Turn On Denominator", 30, 0.0, 150.0);
0277
0278 ibooker_.cd();
0279 }
0280
0281
0282 DEFINE_FWK_MODULE(SUSY_HLT_Muon_Hadronic);