File indexing completed on 2024-04-06 12:18:55
0001
0002
0003 #include "FWCore/Common/interface/TriggerNames.h"
0004 #include "HLTriggerOffline/JetMET/interface/HLTJetMETValidation.h"
0005 #include "Math/GenVector/VectorUtil.h"
0006
0007 using namespace std;
0008 using namespace edm;
0009 using namespace reco;
0010 using namespace l1extra;
0011 using namespace trigger;
0012
0013 HLTJetMETValidation::HLTJetMETValidation(const edm::ParameterSet &ps)
0014 : triggerEventObject_(
0015 consumes<TriggerEventWithRefs>(ps.getUntrackedParameter<edm::InputTag>("triggerEventObject"))),
0016 PFJetAlgorithm(consumes<PFJetCollection>(ps.getUntrackedParameter<edm::InputTag>("PFJetAlgorithm"))),
0017 GenJetAlgorithm(consumes<GenJetCollection>(ps.getUntrackedParameter<edm::InputTag>("GenJetAlgorithm"))),
0018 CaloMETColl(consumes<CaloMETCollection>(ps.getUntrackedParameter<edm::InputTag>("CaloMETCollection"))),
0019 GenMETColl(consumes<GenMETCollection>(ps.getUntrackedParameter<edm::InputTag>("GenMETCollection"))),
0020 HLTriggerResults(consumes<edm::TriggerResults>(ps.getParameter<edm::InputTag>("HLTriggerResults"))),
0021 triggerTag_(ps.getUntrackedParameter<std::string>("DQMFolder", "SingleJet")),
0022 patternJetTrg_(ps.getUntrackedParameter<std::string>("PatternJetTrg", "")),
0023 patternMetTrg_(ps.getUntrackedParameter<std::string>("PatternMetTrg", "")),
0024 patternMuTrg_(ps.getUntrackedParameter<std::string>("PatternMuTrg", "")),
0025 HLTinit_(false) {
0026 evtCnt = 0;
0027 }
0028
0029 HLTJetMETValidation::~HLTJetMETValidation() {}
0030
0031
0032
0033
0034
0035
0036 void HLTJetMETValidation::dqmBeginRun(edm::Run const &iRun, edm::EventSetup const &iSetup) {
0037 bool foundMuTrg = false;
0038 std::string trgMuNm;
0039 bool changedConfig = true;
0040
0041
0042 TPRegexp patternJet(patternJetTrg_);
0043 TPRegexp patternMet(patternMetTrg_);
0044 TPRegexp patternMu(patternMuTrg_);
0045
0046 if (!hltConfig_.init(iRun, iSetup, "HLT", changedConfig)) {
0047 edm::LogError("HLTJetMETValidation") << "Initialization of HLTConfigProvider failed!!";
0048 return;
0049 }
0050
0051 std::vector<std::string> validTriggerNames = hltConfig_.triggerNames();
0052 for (size_t j = 0; j < validTriggerNames.size(); j++) {
0053
0054 if (TString(validTriggerNames[j]).Contains(patternMu)) {
0055
0056 if (!foundMuTrg)
0057 trgMuNm = validTriggerNames[j];
0058 foundMuTrg = true;
0059 }
0060
0061 if (TString(validTriggerNames[j]).Contains(patternJet)) {
0062 hltTrgJet.push_back(validTriggerNames[j]);
0063 }
0064
0065 if (TString(validTriggerNames[j]).Contains(patternMet)) {
0066 hltTrgMet.push_back(validTriggerNames[j]);
0067 }
0068 }
0069
0070
0071 for (size_t it = 0; it < hltTrgJet.size(); it++) {
0072 if (it == 0 && foundMuTrg)
0073 hltTrgJetLow.push_back(trgMuNm);
0074 if (it == 0 && !foundMuTrg)
0075 hltTrgJetLow.push_back(hltTrgJet[it]);
0076 if (it != 0)
0077 hltTrgJetLow.push_back(hltTrgJet[it - 1]);
0078
0079
0080 }
0081 int itm(0), itpm(0), itmh(0), itpmh(0);
0082 for (size_t it = 0; it < hltTrgMet.size(); it++) {
0083 if (TString(hltTrgMet[it]).Contains("PF")) {
0084 if (TString(hltTrgMet[it]).Contains("MHT")) {
0085 if (0 == itpmh) {
0086 if (foundMuTrg)
0087 hltTrgMetLow.push_back(trgMuNm);
0088 else
0089 hltTrgMetLow.push_back(hltTrgMet[it]);
0090 } else
0091 hltTrgMetLow.push_back(hltTrgMet[it - 1]);
0092 itpmh++;
0093 }
0094 if (TString(hltTrgMet[it]).Contains("MET")) {
0095 if (0 == itpm) {
0096 if (foundMuTrg)
0097 hltTrgMetLow.push_back(trgMuNm);
0098 else
0099 hltTrgMetLow.push_back(hltTrgMet[it]);
0100 } else
0101 hltTrgMetLow.push_back(hltTrgMet[it - 1]);
0102 itpm++;
0103 }
0104 } else {
0105 if (TString(hltTrgMet[it]).Contains("MHT")) {
0106 if (0 == itmh) {
0107 if (foundMuTrg)
0108 hltTrgMetLow.push_back(trgMuNm);
0109 else
0110 hltTrgMetLow.push_back(hltTrgMet[it]);
0111 } else
0112 hltTrgMetLow.push_back(hltTrgMet[it - 1]);
0113 itmh++;
0114 }
0115 if (TString(hltTrgMet[it]).Contains("MET")) {
0116 if (0 == itm) {
0117 if (foundMuTrg)
0118 hltTrgMetLow.push_back(trgMuNm);
0119 else
0120 hltTrgMetLow.push_back(hltTrgMet[it]);
0121 } else
0122 hltTrgMetLow.push_back(hltTrgMet[it - 1]);
0123 itm++;
0124 }
0125 }
0126
0127
0128 }
0129 }
0130
0131
0132
0133 void HLTJetMETValidation::bookHistograms(DQMStore::IBooker &iBooker,
0134 edm::Run const &iRun,
0135 edm::EventSetup const &iSetup) {
0136
0137 for (size_t it = 0; it < hltTrgJet.size(); it++) {
0138
0139
0140 std::string trgPathName = HLTConfigProvider::removeVersion(triggerTag_ + hltTrgJet[it]);
0141
0142
0143 iBooker.setCurrentFolder(trgPathName);
0144 _meHLTJetPt.push_back(iBooker.book1D("_meHLTJetPt", "Single HLT Jet Pt", 100, 0, 500));
0145 _meHLTJetPtTrgMC.push_back(iBooker.book1D("_meHLTJetPtTrgMC", "Single HLT Jet Pt - HLT Triggered", 100, 0, 500));
0146 _meHLTJetPtTrg.push_back(iBooker.book1D("_meHLTJetPtTrg", "Single HLT Jet Pt - HLT Triggered", 100, 0, 500));
0147 _meHLTJetPtTrgLow.push_back(
0148 iBooker.book1D("_meHLTJetPtTrgLow", "Single HLT Jet Pt - HLT Triggered Low", 100, 0, 500));
0149
0150 _meHLTJetEta.push_back(iBooker.book1D("_meHLTJetEta", "Single HLT Jet Eta", 100, -10, 10));
0151 _meHLTJetEtaTrgMC.push_back(
0152 iBooker.book1D("_meHLTJetEtaTrgMC", "Single HLT Jet Eta - HLT Triggered", 100, -10, 10));
0153 _meHLTJetEtaTrg.push_back(iBooker.book1D("_meHLTJetEtaTrg", "Single HLT Jet Eta - HLT Triggered", 100, -10, 10));
0154 _meHLTJetEtaTrgLow.push_back(
0155 iBooker.book1D("_meHLTJetEtaTrgLow", "Single HLT Jet Eta - HLT Triggered Low", 100, -10, 10));
0156
0157 _meHLTJetPhi.push_back(iBooker.book1D("_meHLTJetPhi", "Single HLT Jet Phi", 100, -4., 4.));
0158 _meHLTJetPhiTrgMC.push_back(
0159 iBooker.book1D("_meHLTJetPhiTrgMC", "Single HLT Jet Phi - HLT Triggered", 100, -4., 4.));
0160 _meHLTJetPhiTrg.push_back(iBooker.book1D("_meHLTJetPhiTrg", "Single HLT Jet Phi - HLT Triggered", 100, -4., 4.));
0161 _meHLTJetPhiTrgLow.push_back(
0162 iBooker.book1D("_meHLTJetPhiTrgLow", "Single HLT Jet Phi - HLT Triggered Low", 100, -4., 4.));
0163
0164 _meGenJetPt.push_back(iBooker.book1D("_meGenJetPt", "Single Generated Jet Pt", 100, 0, 500));
0165 _meGenJetPtTrgMC.push_back(
0166 iBooker.book1D("_meGenJetPtTrgMC", "Single Generated Jet Pt - HLT Triggered", 100, 0, 500));
0167 _meGenJetPtTrg.push_back(iBooker.book1D("_meGenJetPtTrg", "Single Generated Jet Pt - HLT Triggered", 100, 0, 500));
0168 _meGenJetPtTrgLow.push_back(
0169 iBooker.book1D("_meGenJetPtTrgLow", "Single Generated Jet Pt - HLT Triggered Low", 100, 0, 500));
0170
0171 _meGenJetEta.push_back(iBooker.book1D("_meGenJetEta", "Single Generated Jet Eta", 100, -10, 10));
0172 _meGenJetEtaTrgMC.push_back(
0173 iBooker.book1D("_meGenJetEtaTrgMC", "Single Generated Jet Eta - HLT Triggered", 100, -10, 10));
0174 _meGenJetEtaTrg.push_back(
0175 iBooker.book1D("_meGenJetEtaTrg", "Single Generated Jet Eta - HLT Triggered", 100, -10, 10));
0176 _meGenJetEtaTrgLow.push_back(
0177 iBooker.book1D("_meGenJetEtaTrgLow", "Single Generated Jet Eta - HLT Triggered Low", 100, -10, 10));
0178
0179 _meGenJetPhi.push_back(iBooker.book1D("_meGenJetPhi", "Single Generated Jet Phi", 100, -4., 4.));
0180 _meGenJetPhiTrgMC.push_back(
0181 iBooker.book1D("_meGenJetPhiTrgMC", "Single Generated Jet Phi - HLT Triggered", 100, -4., 4.));
0182 _meGenJetPhiTrg.push_back(
0183 iBooker.book1D("_meGenJetPhiTrg", "Single Generated Jet Phi - HLT Triggered", 100, -4., 4.));
0184 _meGenJetPhiTrgLow.push_back(
0185 iBooker.book1D("_meGenJetPhiTrgLow", "Single Generated Jet Phi - HLT Triggered Low", 100, -4., 4.));
0186 }
0187 for (size_t it = 0; it < hltTrgMet.size(); it++) {
0188
0189
0190 std::string trgPathName = HLTConfigProvider::removeVersion(triggerTag_ + hltTrgMet[it]);
0191 iBooker.setCurrentFolder(trgPathName);
0192 _meHLTMET.push_back(iBooker.book1D("_meHLTMET", "HLT Missing ET", 100, 0, 500));
0193 _meHLTMETTrgMC.push_back(iBooker.book1D("_meHLTMETTrgMC", "HLT Missing ET - HLT Triggered", 100, 0, 500));
0194 _meHLTMETTrg.push_back(iBooker.book1D("_meHLTMETTrg", "HLT Missing ET - HLT Triggered", 100, 0, 500));
0195 _meHLTMETTrgLow.push_back(iBooker.book1D("_meHLTMETTrgLow", "HLT Missing ET - HLT Triggered Low", 100, 0, 500));
0196
0197 _meGenMET.push_back(iBooker.book1D("_meGenMET", "Generated Missing ET", 100, 0, 500));
0198 _meGenMETTrgMC.push_back(iBooker.book1D("_meGenMETTrgMC", "Generated Missing ET - HLT Triggered", 100, 0, 500));
0199 _meGenMETTrg.push_back(iBooker.book1D("_meGenMETTrg", "Generated Missing ET - HLT Triggered", 100, 0, 500));
0200 _meGenMETTrgLow.push_back(
0201 iBooker.book1D("_meGenMETTrgLow", "Generated Missing ET - HLT Triggered Low", 100, 0, 500));
0202 }
0203 }
0204
0205
0206 void HLTJetMETValidation::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0207 using namespace std;
0208 using namespace edm;
0209 using namespace reco;
0210 using namespace l1extra;
0211 using namespace trigger;
0212
0213 evtCnt++;
0214
0215
0216 Handle<TriggerEventWithRefs> trigEv;
0217 iEvent.getByToken(triggerEventObject_, trigEv);
0218
0219
0220 bool gotHLT = true;
0221 std::vector<bool> myTrigJ;
0222 for (size_t it = 0; it < hltTrgJet.size(); it++)
0223 myTrigJ.push_back(false);
0224 std::vector<bool> myTrigJLow;
0225 for (size_t it = 0; it < hltTrgJetLow.size(); it++)
0226 myTrigJLow.push_back(false);
0227 std::vector<bool> myTrigM;
0228 for (size_t it = 0; it < hltTrgMet.size(); it++)
0229 myTrigM.push_back(false);
0230 std::vector<bool> myTrigMLow;
0231 for (size_t it = 0; it < hltTrgMetLow.size(); it++)
0232 myTrigMLow.push_back(false);
0233
0234 Handle<TriggerResults> hltresults;
0235 iEvent.getByToken(HLTriggerResults, hltresults);
0236 if (!hltresults.isValid()) {
0237
0238
0239 gotHLT = false;
0240 }
0241
0242 if (gotHLT) {
0243 const edm::TriggerNames &triggerNames = iEvent.triggerNames(*hltresults);
0244 getHLTResults(*hltresults, triggerNames);
0245
0246
0247 for (size_t it = 0; it < hltTrgJet.size(); it++) {
0248 trig_iter = hltTriggerMap.find(hltTrgJet[it]);
0249 if (trig_iter == hltTriggerMap.end()) {
0250
0251
0252
0253
0254 } else {
0255 myTrigJ[it] = trig_iter->second;
0256 }
0257
0258 }
0259 for (size_t it = 0; it < hltTrgJetLow.size(); it++) {
0260 trig_iter = hltTriggerMap.find(hltTrgJetLow[it]);
0261 if (trig_iter == hltTriggerMap.end()) {
0262
0263
0264
0265
0266 } else {
0267 myTrigJLow[it] = trig_iter->second;
0268 }
0269
0270 }
0271
0272 for (size_t it = 0; it < hltTrgMet.size(); it++) {
0273 trig_iter = hltTriggerMap.find(hltTrgMet[it]);
0274 if (trig_iter == hltTriggerMap.end()) {
0275
0276
0277
0278
0279 } else {
0280 myTrigM[it] = trig_iter->second;
0281 }
0282
0283 }
0284 for (size_t it = 0; it < hltTrgMetLow.size(); it++) {
0285 trig_iter = hltTriggerMap.find(hltTrgMetLow[it]);
0286 if (trig_iter == hltTriggerMap.end()) {
0287
0288
0289
0290
0291 } else {
0292 myTrigMLow[it] = trig_iter->second;
0293 }
0294
0295 }
0296 }
0297
0298
0299
0300 Handle<PFJetCollection> pfJets;
0301 iEvent.getByToken(PFJetAlgorithm, pfJets);
0302 double pfJetPt = -1.;
0303 double pfJetEta = -999.;
0304 double pfJetPhi = -999.;
0305
0306 if (pfJets.isValid()) {
0307
0308 int jetInd = 0;
0309 for (PFJetCollection::const_iterator pf = pfJets->begin(); pf != pfJets->end(); ++pf) {
0310
0311
0312 if (jetInd == 0) {
0313 pfJetPt = pf->pt();
0314 pfJetEta = pf->eta();
0315 pfJetPhi = pf->phi();
0316 for (size_t it = 0; it < hltTrgJet.size(); it++) {
0317 _meHLTJetPt[it]->Fill(pfJetPt);
0318 _meHLTJetEta[it]->Fill(pfJetEta);
0319 _meHLTJetPhi[it]->Fill(pfJetPhi);
0320 if (myTrigJ[it])
0321 _meHLTJetPtTrgMC[it]->Fill(pfJetPt);
0322 if (myTrigJ[it])
0323 _meHLTJetEtaTrgMC[it]->Fill(pfJetEta);
0324 if (myTrigJ[it])
0325 _meHLTJetPhiTrgMC[it]->Fill(pfJetPhi);
0326 if (myTrigJ[it] && myTrigJLow[it])
0327 _meHLTJetPtTrg[it]->Fill(pfJetPt);
0328 if (myTrigJ[it] && myTrigJLow[it])
0329 _meHLTJetEtaTrg[it]->Fill(pfJetEta);
0330 if (myTrigJ[it] && myTrigJLow[it])
0331 _meHLTJetPhiTrg[it]->Fill(pfJetPhi);
0332 if (myTrigJLow[it])
0333 _meHLTJetPtTrgLow[it]->Fill(pfJetPt);
0334 if (myTrigJLow[it])
0335 _meHLTJetEtaTrgLow[it]->Fill(pfJetEta);
0336 if (myTrigJLow[it])
0337 _meHLTJetPhiTrgLow[it]->Fill(pfJetPhi);
0338 }
0339 jetInd++;
0340 }
0341 }
0342 } else {
0343
0344
0345
0346 }
0347
0348
0349 Handle<GenJetCollection> genJets;
0350 iEvent.getByToken(GenJetAlgorithm, genJets);
0351 double genJetPt = -1.;
0352 double genJetEta = -999.;
0353 double genJetPhi = -999.;
0354
0355 if (genJets.isValid()) {
0356
0357 int jetInd = 0;
0358 for (GenJetCollection::const_iterator gen = genJets->begin(); gen != genJets->end(); ++gen) {
0359 if (jetInd == 0) {
0360 genJetPt = gen->pt();
0361 genJetEta = gen->eta();
0362 genJetPhi = gen->phi();
0363 for (size_t it = 0; it < hltTrgJet.size(); it++) {
0364 _meGenJetPt[it]->Fill(genJetPt);
0365 _meGenJetEta[it]->Fill(genJetEta);
0366 _meGenJetPhi[it]->Fill(genJetPhi);
0367 if (myTrigJ[it])
0368 _meGenJetPtTrgMC[it]->Fill(genJetPt);
0369 if (myTrigJ[it])
0370 _meGenJetEtaTrgMC[it]->Fill(genJetEta);
0371 if (myTrigJ[it])
0372 _meGenJetPhiTrgMC[it]->Fill(genJetPhi);
0373 if (myTrigJ[it] && myTrigJLow[it])
0374 _meGenJetPtTrg[it]->Fill(genJetPt);
0375 if (myTrigJ[it] && myTrigJLow[it])
0376 _meGenJetEtaTrg[it]->Fill(genJetEta);
0377 if (myTrigJ[it] && myTrigJLow[it])
0378 _meGenJetPhiTrg[it]->Fill(genJetPhi);
0379 if (myTrigJLow[it])
0380 _meGenJetPtTrgLow[it]->Fill(genJetPt);
0381 if (myTrigJLow[it])
0382 _meGenJetEtaTrgLow[it]->Fill(genJetEta);
0383 if (myTrigJLow[it])
0384 _meGenJetPhiTrgLow[it]->Fill(genJetPhi);
0385 }
0386 jetInd++;
0387 }
0388 }
0389 } else {
0390
0391
0392
0393 }
0394
0395
0396
0397 edm::Handle<CaloMETCollection> recmet;
0398 iEvent.getByToken(CaloMETColl, recmet);
0399
0400 double calMet = -1;
0401 if (recmet.isValid()) {
0402 typedef CaloMETCollection::const_iterator cmiter;
0403
0404 for (cmiter i = recmet->begin(); i != recmet->end(); i++) {
0405 calMet = i->pt();
0406 for (size_t it = 0; it < hltTrgMet.size(); it++) {
0407 _meHLTMET[it]->Fill(calMet);
0408 if (myTrigM.size() > it && myTrigM[it])
0409 _meHLTMETTrgMC[it]->Fill(calMet);
0410 if (myTrigM.size() > it && myTrigMLow.size() > it && myTrigM[it] && myTrigMLow[it])
0411 _meHLTMETTrg[it]->Fill(calMet);
0412 if (myTrigMLow.size() > it && myTrigMLow[it])
0413 _meHLTMETTrgLow[it]->Fill(calMet);
0414 }
0415 }
0416 } else {
0417
0418
0419
0420 }
0421
0422 edm::Handle<GenMETCollection> genmet;
0423 iEvent.getByToken(GenMETColl, genmet);
0424
0425 double genMet = -1;
0426 if (genmet.isValid()) {
0427 typedef GenMETCollection::const_iterator cmiter;
0428 for (cmiter i = genmet->begin(); i != genmet->end(); i++) {
0429 genMet = i->pt();
0430 for (size_t it = 0; it < hltTrgMet.size(); it++) {
0431 _meGenMET[it]->Fill(genMet);
0432 if (myTrigM.size() > it && myTrigM[it])
0433 _meGenMETTrgMC[it]->Fill(genMet);
0434 if (myTrigM.size() > it && myTrigMLow.size() > it && myTrigM[it] && myTrigMLow[it])
0435 _meGenMETTrg[it]->Fill(genMet);
0436 if (myTrigMLow.size() > it && myTrigMLow[it])
0437 _meGenMETTrgLow[it]->Fill(genMet);
0438 }
0439 }
0440 } else {
0441
0442
0443
0444 }
0445 }
0446
0447 void HLTJetMETValidation::getHLTResults(const edm::TriggerResults &hltresults, const edm::TriggerNames &triggerNames) {
0448 int ntrigs = hltresults.size();
0449 if (!HLTinit_) {
0450 HLTinit_ = true;
0451
0452 for (int itrig = 0; itrig != ntrigs; ++itrig) {
0453
0454 }
0455 }
0456
0457 for (int itrig = 0; itrig != ntrigs; ++itrig) {
0458 std::string trigName = triggerNames.triggerName(itrig);
0459 bool accept = hltresults.accept(itrig);
0460
0461
0462
0463
0464 typedef std::map<std::string, bool>::value_type valType;
0465 trig_iter = hltTriggerMap.find(trigName);
0466 if (trig_iter == hltTriggerMap.end())
0467 hltTriggerMap.insert(valType(trigName, accept));
0468 else
0469 trig_iter->second = accept;
0470 }
0471 }