Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-29 23:10:19

0001 // -*- C++ -*-
0002 //
0003 // Package:    DQM/HLTObjectMonitor
0004 // Class:      HLTObjectMonitor
0005 //
0006 /**\class HLTObjectMonitor HLTObjectMonitor.cc DQM/HLTEvF/plugins/HLTObjectMonitor.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Charles Nicholas Mueller
0015 //         Created:  Sun, 22 Mar 2015 22:29:00 GMT
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <sys/time.h>
0022 #include <cstdlib>
0023 
0024 // user include files
0025 #include "DataFormats/Common/interface/TriggerResults.h"
0026 #include "DataFormats/HLTReco/interface/TriggerObject.h"
0027 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
0028 #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
0029 #include "DataFormats/Scalers/interface/LumiScalers.h"
0030 
0031 #include "FWCore/Framework/interface/Frameworkfwd.h"
0032 #include "FWCore/Framework/interface/Event.h"
0033 #include "FWCore/Framework/interface/MakerMacros.h"
0034 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0035 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0036 
0037 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0038 
0039 //for collections
0040 #include "HLTrigger/JetMET/interface/AlphaT.h"
0041 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0042 #include "DataFormats/METReco/interface/MET.h"
0043 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
0044 #include "DataFormats/BTauReco/interface/JetTag.h"
0045 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
0046 #include "DataFormats/Math/interface/deltaR.h"
0047 #include "DataFormats/JetReco/interface/PFJet.h"
0048 #include "DataFormats/JetReco/interface/CaloJet.h"
0049 
0050 #include "DQMServices/Core/interface/DQMStore.h"
0051 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0052 
0053 #include "TMath.h"
0054 #include "TStyle.h"
0055 #include "TLorentzVector.h"
0056 
0057 #include <unordered_map>
0058 //
0059 // class declaration
0060 //
0061 
0062 //using namespace edm;
0063 using namespace trigger;
0064 using std::string;
0065 using std::unordered_map;
0066 using std::vector;
0067 
0068 class HLTObjectMonitor : public DQMEDAnalyzer {
0069   struct hltPlot {
0070     MonitorElement* ME;
0071     string pathName;
0072     string pathNameOR;
0073     string moduleName;
0074     string moduleNameOR;
0075     int pathIndex = -99;
0076     int pathIndexOR = -99;
0077     string plotLabel;
0078     string xAxisLabel;
0079     int nBins;
0080     double xMin;
0081     double xMax;
0082     bool displayInPrimary;
0083   };
0084 
0085 public:
0086   explicit HLTObjectMonitor(const edm::ParameterSet&);
0087   ~HLTObjectMonitor() override;
0088 
0089   //      static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0090 
0091 private:
0092   void analyze(const edm::Event&, const edm::EventSetup&) override;
0093   void bookHistograms(DQMStore::IBooker& i, edm::Run const&, edm::EventSetup const&) override;
0094   void dqmBeginRun(edm::Run const&, edm::EventSetup const&) override;
0095   vector<hltPlot*> plotList;
0096   //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0097   //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0098   double dxyFinder(double, double, edm::Handle<reco::RecoChargedCandidateCollection>, edm::Handle<reco::BeamSpot>);
0099   double get_wall_time(void);
0100   // ----------member data ---------------------------
0101 
0102   bool debugPrint;
0103   HLTConfigProvider hltConfig_;
0104   string topDirectoryName;
0105   string mainShifterFolder;
0106   string backupFolder;
0107   unordered_map<string, bool> acceptMap;
0108   unordered_map<hltPlot*, edm::ParameterSet*> plotMap;
0109 
0110   //set Token(-s)
0111   edm::EDGetTokenT<edm::TriggerResults> triggerResultsToken_;
0112   edm::EDGetTokenT<trigger::TriggerEvent> aodTriggerToken_;
0113   edm::EDGetTokenT<LumiScalersCollection> lumiScalersToken_;
0114   edm::EDGetTokenT<reco::BeamSpot> beamSpotToken_;
0115   edm::EDGetTokenT<reco::RecoChargedCandidateCollection> chargedCandToken_;
0116   edm::EDGetTokenT<reco::JetTagCollection> csvCaloTagsToken_;
0117   edm::EDGetTokenT<reco::JetTagCollection> csvPfTagsToken_;
0118   edm::EDGetTokenT<vector<reco::CaloJet>> csvCaloJetsToken_;
0119   edm::EDGetTokenT<vector<reco::PFJet>> csvPfJetsToken_;
0120 
0121   //declare params
0122   edm::ParameterSet rsq_pset;
0123   edm::ParameterSet mr_pset;
0124   edm::ParameterSet alphaT_pset;
0125   edm::ParameterSet photonPt_pset;
0126   edm::ParameterSet photonEta_pset;
0127   edm::ParameterSet photonPhi_pset;
0128   edm::ParameterSet muonPt_pset;
0129   edm::ParameterSet muonEta_pset;
0130   edm::ParameterSet muonPhi_pset;
0131   edm::ParameterSet l2muonPt_pset;
0132   edm::ParameterSet l2muonEta_pset;
0133   edm::ParameterSet l2muonPhi_pset;
0134   edm::ParameterSet l2NoBPTXmuonPt_pset;
0135   edm::ParameterSet l2NoBPTXmuonEta_pset;
0136   edm::ParameterSet l2NoBPTXmuonPhi_pset;
0137   edm::ParameterSet electronPt_pset;
0138   edm::ParameterSet electronEta_pset;
0139   edm::ParameterSet electronPhi_pset;
0140   edm::ParameterSet jetPt_pset;
0141   edm::ParameterSet jetAK8Pt_pset;
0142   edm::ParameterSet jetAK8Mass_pset;
0143   edm::ParameterSet tauPt_pset;
0144   edm::ParameterSet diMuonLowMass_pset;
0145   edm::ParameterSet caloMetPt_pset;
0146   edm::ParameterSet caloMetPhi_pset;
0147   edm::ParameterSet pfMetPt_pset;
0148   edm::ParameterSet pfMetPhi_pset;
0149   edm::ParameterSet caloHtPt_pset;
0150   edm::ParameterSet pfHtPt_pset;
0151   edm::ParameterSet bJetPhi_pset;
0152   edm::ParameterSet bJetEta_pset;
0153   edm::ParameterSet bJetCSVCalo_pset;
0154   edm::ParameterSet bJetCSVPF_pset;
0155   edm::ParameterSet diMuonMass_pset;
0156   edm::ParameterSet pAL1DoubleMuZMass_pset;
0157   edm::ParameterSet pAL2DoubleMuZMass_pset;
0158   edm::ParameterSet pAL3DoubleMuZMass_pset;
0159   edm::ParameterSet diElecMass_pset;
0160   edm::ParameterSet muonDxy_pset;
0161   edm::ParameterSet wallTime_pset;
0162 
0163   string processName_;
0164 
0165   hltPlot rsq_;
0166   hltPlot mr_;
0167   hltPlot alphaT_;
0168   hltPlot photonPt_;
0169   hltPlot photonEta_;
0170   hltPlot photonPhi_;
0171   hltPlot muonPt_;
0172   hltPlot muonEta_;
0173   hltPlot muonPhi_;
0174   hltPlot l2muonPt_;
0175   hltPlot l2muonEta_;
0176   hltPlot l2muonPhi_;
0177   hltPlot l2NoBPTXmuonPt_;
0178   hltPlot l2NoBPTXmuonEta_;
0179   hltPlot l2NoBPTXmuonPhi_;
0180   hltPlot electronPt_;
0181   hltPlot electronEta_;
0182   hltPlot electronPhi_;
0183   hltPlot jetPt_;
0184   hltPlot jetAK8Pt_;
0185   hltPlot jetAK8Mass_;
0186   hltPlot tauPt_;
0187   hltPlot diMuonLowMass_;
0188   hltPlot caloMetPt_;
0189   hltPlot caloMetPhi_;
0190   hltPlot pfMetPt_;
0191   hltPlot pfMetPhi_;
0192   hltPlot caloHtPt_;
0193   hltPlot pfHtPt_;
0194   hltPlot bJetPhi_;
0195   hltPlot bJetEta_;
0196   hltPlot bJetCSVCalo_;
0197   hltPlot bJetCSVPF_;
0198   hltPlot diMuonMass_;
0199   hltPlot pAL1DoubleMuZMass_;
0200   hltPlot pAL2DoubleMuZMass_;
0201   hltPlot pAL3DoubleMuZMass_;
0202   hltPlot diElecMass_;
0203   hltPlot muonDxy_;
0204   hltPlot wallTime_;
0205 };
0206 
0207 //
0208 // constants, enums and typedefs
0209 //
0210 
0211 //
0212 // static data member definitions
0213 //
0214 
0215 //
0216 // constructors and destructor
0217 //
0218 HLTObjectMonitor::HLTObjectMonitor(const edm::ParameterSet& iConfig)
0219 
0220 {
0221   //now do what ever initialization is needed
0222   debugPrint = false;
0223 
0224   topDirectoryName = "HLT/ObjectMonitor";
0225   mainShifterFolder = topDirectoryName + "/MainShifter";
0226   backupFolder = topDirectoryName + "/Backup";
0227 
0228   //parse params
0229   processName_ = iConfig.getParameter<string>("processName");
0230 
0231   rsq_pset = iConfig.getParameter<edm::ParameterSet>("rsq");
0232   plotMap[&rsq_] = &rsq_pset;
0233   mr_pset = iConfig.getParameter<edm::ParameterSet>("mr");
0234   plotMap[&mr_] = &mr_pset;
0235   alphaT_pset = iConfig.getParameter<edm::ParameterSet>("alphaT");
0236   plotMap[&alphaT_] = &alphaT_pset;
0237   photonPt_pset = iConfig.getParameter<edm::ParameterSet>("photonPt");
0238   plotMap[&photonPt_] = &photonPt_pset;
0239   photonEta_pset = iConfig.getParameter<edm::ParameterSet>("photonEta");
0240   plotMap[&photonEta_] = &photonEta_pset;
0241   photonPhi_pset = iConfig.getParameter<edm::ParameterSet>("photonPhi");
0242   plotMap[&photonPhi_] = &photonPhi_pset;
0243   muonPt_pset = iConfig.getParameter<edm::ParameterSet>("muonPt");
0244   plotMap[&muonPt_] = &muonPt_pset;
0245   muonEta_pset = iConfig.getParameter<edm::ParameterSet>("muonEta");
0246   plotMap[&muonEta_] = &muonEta_pset;
0247   muonPhi_pset = iConfig.getParameter<edm::ParameterSet>("muonPhi");
0248   plotMap[&muonPhi_] = &muonPhi_pset;
0249   l2muonPt_pset = iConfig.getParameter<edm::ParameterSet>("l2muonPt");
0250   plotMap[&l2muonPt_] = &l2muonPt_pset;
0251   l2muonEta_pset = iConfig.getParameter<edm::ParameterSet>("l2muonEta");
0252   plotMap[&l2muonEta_] = &l2muonEta_pset;
0253   l2muonPhi_pset = iConfig.getParameter<edm::ParameterSet>("l2muonPhi");
0254   plotMap[&l2muonPhi_] = &l2muonPhi_pset;
0255   l2NoBPTXmuonPt_pset = iConfig.getParameter<edm::ParameterSet>("l2NoBPTXmuonPt");
0256   plotMap[&l2NoBPTXmuonPt_] = &l2NoBPTXmuonPt_pset;
0257   l2NoBPTXmuonEta_pset = iConfig.getParameter<edm::ParameterSet>("l2NoBPTXmuonEta");
0258   plotMap[&l2NoBPTXmuonEta_] = &l2NoBPTXmuonEta_pset;
0259   l2NoBPTXmuonPhi_pset = iConfig.getParameter<edm::ParameterSet>("l2NoBPTXmuonPhi");
0260   plotMap[&l2NoBPTXmuonPhi_] = &l2NoBPTXmuonPhi_pset;
0261   electronPt_pset = iConfig.getParameter<edm::ParameterSet>("electronPt");
0262   plotMap[&electronPt_] = &electronPt_pset;
0263   electronEta_pset = iConfig.getParameter<edm::ParameterSet>("electronEta");
0264   plotMap[&electronEta_] = &electronEta_pset;
0265   electronPhi_pset = iConfig.getParameter<edm::ParameterSet>("electronPhi");
0266   plotMap[&electronPhi_] = &electronPhi_pset;
0267   jetPt_pset = iConfig.getParameter<edm::ParameterSet>("jetPt");
0268   plotMap[&jetPt_] = &jetPt_pset;
0269   jetAK8Mass_pset = iConfig.getParameter<edm::ParameterSet>("jetAK8Mass");
0270   plotMap[&jetAK8Mass_] = &jetAK8Mass_pset;
0271   diMuonLowMass_pset = iConfig.getParameter<edm::ParameterSet>("diMuonLowMass");
0272   plotMap[&diMuonLowMass_] = &diMuonLowMass_pset;
0273   caloMetPt_pset = iConfig.getParameter<edm::ParameterSet>("caloMetPt");
0274   plotMap[&caloMetPt_] = &caloMetPt_pset;
0275   caloMetPhi_pset = iConfig.getParameter<edm::ParameterSet>("caloMetPhi");
0276   plotMap[&caloMetPhi_] = &caloMetPhi_pset;
0277   pfMetPt_pset = iConfig.getParameter<edm::ParameterSet>("pfMetPt");
0278   plotMap[&pfMetPt_] = &pfMetPt_pset;
0279   pfMetPhi_pset = iConfig.getParameter<edm::ParameterSet>("pfMetPhi");
0280   plotMap[&pfMetPhi_] = &pfMetPhi_pset;
0281   caloHtPt_pset = iConfig.getParameter<edm::ParameterSet>("caloHtPt");
0282   plotMap[&caloHtPt_] = &caloHtPt_pset;
0283   pfHtPt_pset = iConfig.getParameter<edm::ParameterSet>("pfHtPt");
0284   plotMap[&pfHtPt_] = &pfHtPt_pset;
0285   bJetPhi_pset = iConfig.getParameter<edm::ParameterSet>("bJetPhi");
0286   plotMap[&bJetPhi_] = &bJetPhi_pset;
0287   bJetEta_pset = iConfig.getParameter<edm::ParameterSet>("bJetEta");
0288   plotMap[&bJetEta_] = &bJetEta_pset;
0289   bJetCSVCalo_pset = iConfig.getParameter<edm::ParameterSet>("bJetCSVCalo");
0290   plotMap[&bJetCSVCalo_] = &bJetCSVCalo_pset;
0291   bJetCSVPF_pset = iConfig.getParameter<edm::ParameterSet>("bJetCSVPF");
0292   plotMap[&bJetCSVPF_] = &bJetCSVPF_pset;
0293   diMuonMass_pset = iConfig.getParameter<edm::ParameterSet>("diMuonMass");
0294   plotMap[&diMuonMass_] = &diMuonMass_pset;
0295   pAL1DoubleMuZMass_pset = iConfig.getParameter<edm::ParameterSet>("pAL1DoubleMuZMass");
0296   plotMap[&pAL1DoubleMuZMass_] = &pAL1DoubleMuZMass_pset;
0297   pAL2DoubleMuZMass_pset = iConfig.getParameter<edm::ParameterSet>("pAL2DoubleMuZMass");
0298   plotMap[&pAL2DoubleMuZMass_] = &pAL2DoubleMuZMass_pset;
0299   pAL3DoubleMuZMass_pset = iConfig.getParameter<edm::ParameterSet>("pAL3DoubleMuZMass");
0300   plotMap[&pAL3DoubleMuZMass_] = &pAL3DoubleMuZMass_pset;
0301   diElecMass_pset = iConfig.getParameter<edm::ParameterSet>("diElecMass");
0302   plotMap[&diElecMass_] = &diElecMass_pset;
0303   muonDxy_pset = iConfig.getParameter<edm::ParameterSet>("muonDxy");
0304   plotMap[&muonDxy_] = &muonDxy_pset;
0305   jetAK8Pt_pset = iConfig.getParameter<edm::ParameterSet>("jetAK8Pt");
0306   plotMap[&jetAK8Pt_] = &jetAK8Pt_pset;
0307   tauPt_pset = iConfig.getParameter<edm::ParameterSet>("tauPt");
0308   plotMap[&tauPt_] = &tauPt_pset;
0309   wallTime_pset = iConfig.getParameter<edm::ParameterSet>("wallTime");
0310   plotMap[&wallTime_] = &wallTime_pset;
0311 
0312   for (auto item = plotMap.begin(); item != plotMap.end(); item++) {
0313     (*item->first).pathName = (*item->second).getParameter<string>("pathName");
0314     (*item->first).moduleName = (*item->second).getParameter<string>("moduleName");
0315     (*item->first).nBins = (*item->second).getParameter<int>("NbinsX");
0316     (*item->first).xMin = (*item->second).getParameter<double>("Xmin");
0317     (*item->first).xMax = (*item->second).getParameter<double>("Xmax");
0318     (*item->first).xAxisLabel = (*item->second).getParameter<string>("axisLabel");
0319     (*item->first).plotLabel = (*item->second).getParameter<string>("plotLabel");
0320     (*item->first).displayInPrimary = (*item->second).getParameter<bool>("mainWorkspace");
0321 
0322     if ((*item->second).exists("pathName_OR")) {
0323       (*item->first).pathNameOR = (*item->second).getParameter<string>("pathName_OR");
0324     }
0325     if ((*item->second).exists("moduleName_OR")) {
0326       (*item->first).moduleNameOR = (*item->second).getParameter<string>("moduleName_OR");
0327     }
0328 
0329     plotList.push_back(item->first);
0330   }
0331   plotMap.clear();
0332 
0333   //set Token(s)
0334   triggerResultsToken_ = consumes<edm::TriggerResults>(edm::InputTag("TriggerResults", "", processName_));
0335   aodTriggerToken_ = consumes<trigger::TriggerEvent>(edm::InputTag("hltTriggerSummaryAOD", "", processName_));
0336   lumiScalersToken_ = consumes<LumiScalersCollection>(edm::InputTag("hltScalersRawToDigi", "", ""));
0337   beamSpotToken_ = consumes<reco::BeamSpot>(edm::InputTag("hltOnlineBeamSpot", "", processName_));
0338   chargedCandToken_ = consumes<vector<reco::RecoChargedCandidate>>(
0339       edm::InputTag("hltL3NoFiltersNoVtxMuonCandidates", "", processName_));
0340   csvCaloTagsToken_ =
0341       consumes<reco::JetTagCollection>(edm::InputTag("hltCombinedSecondaryVertexBJetTagsCalo", "", processName_));
0342   csvPfTagsToken_ =
0343       consumes<reco::JetTagCollection>(edm::InputTag("hltCombinedSecondaryVertexBJetTagsPF", "", processName_));
0344   csvCaloJetsToken_ =
0345       consumes<vector<reco::CaloJet>>(edm::InputTag("hltSelector8CentralJetsL1FastJet", "", processName_));
0346   csvPfJetsToken_ = consumes<vector<reco::PFJet>>(edm::InputTag("hltPFJetForBtag", "", processName_));
0347 }
0348 
0349 HLTObjectMonitor::~HLTObjectMonitor() {
0350   // do anything here that needs to be done at desctruction time
0351   // (e.g. close files, deallocate resources etc.)
0352 }
0353 
0354 //
0355 // member functions
0356 //
0357 
0358 // ------------ method called for each event  ------------
0359 void HLTObjectMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0360   double start = get_wall_time();
0361 
0362   using namespace edm;
0363 
0364   if (debugPrint)
0365     std::cout << "Inside analyze(). " << std::endl;
0366 
0367   // access trigger results
0368   edm::Handle<edm::TriggerResults> triggerResults;
0369   iEvent.getByToken(triggerResultsToken_, triggerResults);
0370   if (!triggerResults.isValid())
0371     return;
0372 
0373   edm::Handle<trigger::TriggerEvent> aodTriggerEvent;
0374   iEvent.getByToken(aodTriggerToken_, aodTriggerEvent);
0375   if (!aodTriggerEvent.isValid())
0376     return;
0377 
0378   //reset everything to not accepted at beginning of each event
0379   unordered_map<string, bool> firedMap = acceptMap;
0380   for (auto plot : plotList)  //loop over paths
0381   {
0382     if (firedMap[plot->pathName])
0383       continue;
0384     bool triggerAccept = false;
0385     const TriggerObjectCollection objects = aodTriggerEvent->getObjects();
0386     edm::InputTag moduleFilter;
0387     std::string pathName;
0388     if (plot->pathIndex > 0 && triggerResults->accept(plot->pathIndex) && hltConfig_.saveTags(plot->moduleName)) {
0389       moduleFilter = edm::InputTag(plot->moduleName, "", processName_);
0390       pathName = plot->pathName;
0391       triggerAccept = true;
0392     } else if (plot->pathIndexOR > 0 && triggerResults->accept(plot->pathIndexOR) &&
0393                hltConfig_.saveTags(plot->moduleNameOR)) {
0394       if (firedMap[plot->pathNameOR])
0395         continue;
0396       moduleFilter = edm::InputTag(plot->moduleNameOR, "", processName_);
0397       pathName = plot->pathNameOR;
0398       triggerAccept = true;
0399     }
0400 
0401     if (triggerAccept) {
0402       unsigned int moduleFilterIndex = aodTriggerEvent->filterIndex(moduleFilter);
0403 
0404       if (moduleFilterIndex + 1 > aodTriggerEvent->sizeFilters())
0405         return;
0406       const Keys& keys = aodTriggerEvent->filterKeys(moduleFilterIndex);
0407 
0408       ////////////////////////////////
0409       ///
0410       /// single-object plots
0411       ///
0412       ////////////////////////////////
0413 
0414       //PFHT pt
0415       if (pathName == pfHtPt_.pathName) {
0416         for (const auto& key : keys)
0417           pfHtPt_.ME->Fill(objects[key].pt());
0418       }
0419 
0420       //jet pt
0421       else if (pathName == jetPt_.pathName) {
0422         for (const auto& key : keys)
0423           jetPt_.ME->Fill(objects[key].pt());
0424       }
0425 
0426       //photon pt + eta + phi (all use same path)
0427       else if (pathName == photonPt_.pathName) {
0428         for (const auto& key : keys) {
0429           photonPt_.ME->Fill(objects[key].pt());
0430           photonEta_.ME->Fill(objects[key].eta());
0431           photonPhi_.ME->Fill(objects[key].phi());
0432         }
0433       }
0434 
0435       //electron pt + eta + phi (all use same path)
0436       else if (pathName == electronPt_.pathName) {
0437         for (const auto& key : keys) {
0438           electronPt_.ME->Fill(objects[key].pt());
0439           electronEta_.ME->Fill(objects[key].eta());
0440           electronPhi_.ME->Fill(objects[key].phi());
0441         }
0442       }
0443 
0444       //muon pt + eta + phi (all use same path)
0445       else if (pathName == muonPt_.pathName) {
0446         for (const auto& key : keys) {
0447           muonPt_.ME->Fill(objects[key].pt());
0448           muonEta_.ME->Fill(objects[key].eta());
0449           muonPhi_.ME->Fill(objects[key].phi());
0450         }
0451       }
0452 
0453       //l2muon pt
0454       else if (pathName == l2muonPt_.pathName) {
0455         for (const auto& key : keys) {
0456           l2muonPt_.ME->Fill(objects[key].pt());
0457           l2muonEta_.ME->Fill(objects[key].eta());
0458           l2muonPhi_.ME->Fill(objects[key].phi());
0459         }
0460       }
0461 
0462       //l2NoBPTXmuon pt
0463       else if (pathName == l2NoBPTXmuonPt_.pathName) {
0464         for (const auto& key : keys) {
0465           l2NoBPTXmuonPt_.ME->Fill(objects[key].pt());
0466           l2NoBPTXmuonEta_.ME->Fill(objects[key].eta());
0467           l2NoBPTXmuonPhi_.ME->Fill(objects[key].phi());
0468         }
0469       }
0470 
0471       //Razor
0472       else if (pathName == mr_.pathName) {
0473         double onlineMR = 0, onlineRsq = 0;
0474         for (const auto& key : keys) {
0475           if (objects[key].id() == 0) {    //the MET object containing MR and Rsq will show up with ID = 0
0476             onlineMR = objects[key].px();  //razor variables stored in dummy reco::MET objects
0477             onlineRsq = objects[key].py();
0478           }
0479           mr_.ME->Fill(onlineMR);
0480           rsq_.ME->Fill(onlineRsq);
0481         }
0482       }
0483 
0484       //alphaT
0485       else if (pathName == alphaT_.pathName) {
0486         std::vector<ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiM4D<double>>> alphaT_jets;
0487         for (const auto& key : keys) {
0488           ROOT::Math::LorentzVector<ROOT::Math::PtEtaPhiM4D<double>> JetLVec(
0489               objects[key].pt(), objects[key].eta(), objects[key].phi(), objects[key].mass());
0490           alphaT_jets.push_back(JetLVec);
0491         }
0492 
0493         float alphaT = AlphaT(alphaT_jets, false).value();
0494         alphaT_.ME->Fill(alphaT);
0495       }
0496 
0497       //tau pt
0498       else if (pathName == tauPt_.pathName) {
0499         for (const auto& key : keys)
0500           tauPt_.ME->Fill(objects[key].pt());
0501       }
0502 
0503       //caloMET pt+phi
0504       else if (pathName == caloMetPt_.pathName) {
0505         for (const auto& key : keys) {
0506           caloMetPt_.ME->Fill(objects[key].pt());
0507           caloMetPhi_.ME->Fill(objects[key].phi());
0508         }
0509       }
0510 
0511       //caloHT pt
0512       else if (pathName == caloHtPt_.pathName) {
0513         for (const auto& key : keys) {
0514           if (objects[key].id() == 89)
0515             caloHtPt_.ME->Fill(objects[key].pt());
0516         }
0517       }
0518 
0519       //jetAK8 pt + mass
0520       else if (pathName == jetAK8Pt_.pathName) {
0521         for (const auto& key : keys) {
0522           jetAK8Pt_.ME->Fill(objects[key].pt());
0523           jetAK8Mass_.ME->Fill(objects[key].mass());
0524         }
0525       }
0526 
0527       //PFMET pt + phi
0528       else if (pathName == pfMetPt_.pathName) {
0529         for (const auto& key : keys) {
0530           pfMetPt_.ME->Fill(objects[key].pt());
0531           pfMetPhi_.ME->Fill(objects[key].phi());
0532         }
0533       }
0534 
0535       // bjet eta + phi
0536       else if (pathName == bJetEta_.pathName || pathName == bJetEta_.pathNameOR) {
0537         for (const auto& key : keys) {
0538           bJetEta_.ME->Fill(objects[key].eta());
0539           bJetPhi_.ME->Fill(objects[key].phi());
0540         }
0541       }
0542 
0543       //b-tagging CSV information
0544       if (pathName == bJetCSVPF_.pathName) {
0545         edm::Handle<reco::JetTagCollection> csvPfTags;
0546         iEvent.getByToken(csvPfTagsToken_, csvPfTags);
0547         edm::Handle<vector<reco::PFJet>> csvPfJets;
0548         iEvent.getByToken(csvPfJetsToken_, csvPfJets);
0549 
0550         if (csvPfTags.isValid() && csvPfJets.isValid()) {
0551           for (auto iter = csvPfTags->begin(); iter != csvPfTags->end(); iter++)
0552             bJetCSVPF_.ME->Fill(iter->second);
0553         }
0554       }
0555       if (pathName == bJetCSVCalo_.pathName) {
0556         edm::Handle<reco::JetTagCollection> csvCaloTags;
0557         iEvent.getByToken(csvCaloTagsToken_, csvCaloTags);
0558         edm::Handle<vector<reco::CaloJet>> csvCaloJets;
0559         iEvent.getByToken(csvCaloJetsToken_, csvCaloJets);
0560 
0561         if (csvCaloTags.isValid() && csvCaloJets.isValid()) {
0562           for (auto iter = csvCaloTags->begin(); iter != csvCaloTags->end(); iter++)
0563             bJetCSVCalo_.ME->Fill(iter->second);
0564         }
0565       }
0566 
0567       //muon dxy(use an unique path)
0568       else if (pathName == muonDxy_.pathName) {
0569         edm::Handle<vector<reco::RecoChargedCandidate>> recoChargedCands;
0570         iEvent.getByToken(chargedCandToken_, recoChargedCands);
0571         edm::Handle<reco::BeamSpot> recoBeamSpot;
0572         iEvent.getByToken(beamSpotToken_, recoBeamSpot);
0573         double muon_dxy;
0574 
0575         if (recoChargedCands.isValid() && recoBeamSpot.isValid()) {
0576           for (const auto& key : keys) {
0577             muon_dxy = dxyFinder(objects[key].eta(), objects[key].phi(), recoChargedCands, recoBeamSpot);
0578             if (muon_dxy != -99.)
0579               muonDxy_.ME->Fill(muon_dxy);
0580           }
0581         }
0582       }
0583 
0584       // ////////////////////////////////
0585       // ///
0586       // /// double-object plots
0587       // ///
0588       // ////////////////////////////////
0589 
0590       //double muon low mass
0591       else if (pathName == diMuonLowMass_.pathName) {
0592         const double mu_mass(.105658);
0593         unsigned int kCnt0 = 0;
0594         for (const auto& key0 : keys) {
0595           unsigned int kCnt1 = 0;
0596           for (const auto& key1 : keys) {
0597             if (key0 != key1 &&
0598                 kCnt1 > kCnt0)  // avoid filling hists with same objs && avoid double counting separate objs
0599             {
0600               if (abs(objects[key0].id()) == 13 &&
0601                   (objects[key0].id() + objects[key1].id() == 0))  // check muon id and dimuon charge
0602               {
0603                 TLorentzVector mu1, mu2, dimu;
0604                 mu1.SetPtEtaPhiM(objects[key0].pt(), objects[key0].eta(), objects[key0].phi(), mu_mass);
0605                 mu2.SetPtEtaPhiM(objects[key1].pt(), objects[key1].eta(), objects[key1].phi(), mu_mass);
0606                 dimu = mu1 + mu2;
0607                 diMuonLowMass_.ME->Fill(dimu.M());
0608               }
0609             }
0610             kCnt1 += 1;
0611           }
0612           kCnt0 += 1;
0613         }
0614       }  //end double object plot
0615 
0616       else if (pathName == diMuonMass_.pathName || pathName == diMuonMass_.pathNameOR) {
0617         const double mu_mass(.105658);
0618         unsigned int kCnt0 = 0;
0619         for (const auto& key0 : keys) {
0620           unsigned int kCnt1 = 0;
0621           for (const auto& key1 : keys) {
0622             if (key0 != key1 &&
0623                 kCnt1 > kCnt0)  // avoid filling hists with same objs && avoid double counting separate objs
0624             {
0625               if (abs(objects[key0].id()) == 13 &&
0626                   (objects[key0].id() + objects[key1].id() == 0))  // check muon id and dimuon charge
0627               {
0628                 TLorentzVector mu1, mu2, dimu;
0629                 mu1.SetPtEtaPhiM(objects[key0].pt(), objects[key0].eta(), objects[key0].phi(), mu_mass);
0630                 mu2.SetPtEtaPhiM(objects[key1].pt(), objects[key1].eta(), objects[key1].phi(), mu_mass);
0631                 dimu = mu1 + mu2;
0632                 diMuonMass_.ME->Fill(dimu.M());
0633               }
0634             }
0635             kCnt1 += 1;
0636           }
0637           kCnt0 += 1;
0638         }
0639       }
0640 
0641       else if (pathName == pAL1DoubleMuZMass_.pathName) {
0642         const double mu_mass(.105658);
0643         unsigned int kCnt0 = 0;
0644         for (const auto& key0 : keys) {
0645           unsigned int kCnt1 = 0;
0646           for (const auto& key1 : keys) {
0647             if (key0 != key1 &&
0648                 kCnt1 > kCnt0)  // avoid filling hists with same objs && avoid double counting separate objs
0649             {
0650               // if (abs(objects[key0].id()) == 13 && (objects[key0].id()+objects[key1].id()==0))  // id is not filled for l1 stage2 muons
0651               //  {
0652               TLorentzVector mu1, mu2, dimu;
0653               mu1.SetPtEtaPhiM(objects[key0].pt(), objects[key0].eta(), objects[key0].phi(), mu_mass);
0654               mu2.SetPtEtaPhiM(objects[key1].pt(), objects[key1].eta(), objects[key1].phi(), mu_mass);
0655               dimu = mu1 + mu2;
0656               if (dimu.M() > pAL1DoubleMuZMass_.xMin && dimu.M() < pAL1DoubleMuZMass_.xMax)
0657                 pAL1DoubleMuZMass_.ME->Fill(dimu.M());
0658               //  }
0659             }
0660             kCnt1 += 1;
0661           }
0662           kCnt0 += 1;
0663         }
0664       }
0665 
0666       else if (pathName == pAL2DoubleMuZMass_.pathName) {
0667         const double mu_mass(.105658);
0668         unsigned int kCnt0 = 0;
0669         for (const auto& key0 : keys) {
0670           unsigned int kCnt1 = 0;
0671           for (const auto& key1 : keys) {
0672             if (key0 != key1 &&
0673                 kCnt1 > kCnt0)  // avoid filling hists with same objs && avoid double counting separate objs
0674             {
0675               if (abs(objects[key0].id()) == 13 &&
0676                   (objects[key0].id() + objects[key1].id() == 0))  // check muon id and dimuon charge
0677               {
0678                 TLorentzVector mu1, mu2, dimu;
0679                 mu1.SetPtEtaPhiM(objects[key0].pt(), objects[key0].eta(), objects[key0].phi(), mu_mass);
0680                 mu2.SetPtEtaPhiM(objects[key1].pt(), objects[key1].eta(), objects[key1].phi(), mu_mass);
0681                 dimu = mu1 + mu2;
0682                 if (dimu.M() > pAL2DoubleMuZMass_.xMin && dimu.M() < pAL2DoubleMuZMass_.xMax)
0683                   pAL2DoubleMuZMass_.ME->Fill(dimu.M());
0684               }
0685             }
0686             kCnt1 += 1;
0687           }
0688           kCnt0 += 1;
0689         }
0690       }
0691 
0692       else if (pathName == pAL3DoubleMuZMass_.pathName) {
0693         const double mu_mass(.105658);
0694         unsigned int kCnt0 = 0;
0695         for (const auto& key0 : keys) {
0696           unsigned int kCnt1 = 0;
0697           for (const auto& key1 : keys) {
0698             if (key0 != key1 &&
0699                 kCnt1 > kCnt0)  // avoid filling hists with same objs && avoid double counting separate objs
0700             {
0701               if (abs(objects[key0].id()) == 13 &&
0702                   (objects[key0].id() + objects[key1].id() == 0))  // check muon id and dimuon charge
0703               {
0704                 TLorentzVector mu1, mu2, dimu;
0705                 mu1.SetPtEtaPhiM(objects[key0].pt(), objects[key0].eta(), objects[key0].phi(), mu_mass);
0706                 mu2.SetPtEtaPhiM(objects[key1].pt(), objects[key1].eta(), objects[key1].phi(), mu_mass);
0707                 dimu = mu1 + mu2;
0708                 if (dimu.M() > pAL3DoubleMuZMass_.xMin && dimu.M() < pAL3DoubleMuZMass_.xMax)
0709                   pAL3DoubleMuZMass_.ME->Fill(dimu.M());
0710               }
0711             }
0712             kCnt1 += 1;
0713           }
0714           kCnt0 += 1;
0715         }
0716       }
0717 
0718       else if (pathName == diElecMass_.pathName) {
0719         unsigned int kCnt0 = 0;
0720         for (const auto& key0 : keys) {
0721           unsigned int kCnt1 = 0;
0722           for (const auto& key1 : keys) {
0723             if (key0 != key1 &&
0724                 kCnt1 > kCnt0)  // avoid filling hists with same objs && avoid double counting separate objs
0725             {
0726               //                   if (abs(objects[key0].id()) == 11 && (objects[key0].id()+objects[key1].id()==0))  // id is not filled for electrons
0727               //                     {
0728               TLorentzVector el1, el2, diEl;
0729               el1.SetPtEtaPhiM(objects[key0].pt(), objects[key0].eta(), objects[key0].phi(), 0);
0730               el2.SetPtEtaPhiM(objects[key1].pt(), objects[key1].eta(), objects[key1].phi(), 0);
0731               diEl = el1 + el2;
0732               diElecMass_.ME->Fill(diEl.M());
0733               //                     }
0734             }
0735             kCnt1 += 1;
0736           }
0737           kCnt0 += 1;
0738         }
0739       }  //end double object plot
0740 
0741       firedMap[pathName] = true;
0742     }  //end if trigger accept
0743   }    //end loop over plots/paths
0744 
0745   //   sleep(1); //sleep for 1s, used to calibrate timing
0746   double end = get_wall_time();
0747   double wallTime = end - start;
0748   wallTime_.ME->Fill(wallTime);
0749 }
0750 
0751 // ------------ method called when starting to processes a run  ------------
0752 void HLTObjectMonitor::dqmBeginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
0753   if (debugPrint)
0754     std::cout << "Calling beginRun. " << std::endl;
0755   bool changed = true;
0756   if (hltConfig_.init(iRun, iSetup, processName_, changed)) {
0757     if (debugPrint)
0758       std::cout << "Extracting HLTconfig. " << std::endl;
0759   }
0760 
0761   //get path indicies from menu
0762   string pathName_noVersion;
0763   vector<string> triggerPaths = hltConfig_.triggerNames();
0764 
0765   for (const auto& pathName : triggerPaths) {
0766     pathName_noVersion = hltConfig_.removeVersion(pathName);
0767     for (auto plot : plotList) {
0768       if (plot->pathName == pathName_noVersion) {
0769         (*plot).pathIndex = hltConfig_.triggerIndex(pathName);
0770       } else if (plot->pathNameOR == pathName_noVersion) {
0771         (*plot).pathIndexOR = hltConfig_.triggerIndex(pathName);
0772       }
0773     }
0774   }
0775   vector<hltPlot*> plotList_temp;
0776   for (auto plot : plotList) {
0777     if (plot->pathIndex > 0 || plot->pathIndexOR > 0) {
0778       plotList_temp.push_back(plot);
0779       acceptMap[plot->pathName] = false;
0780       if (plot->pathIndexOR > 0)
0781         acceptMap[plot->pathNameOR] = false;
0782     }
0783   }
0784   //now re-assign plotList to contain only the plots with paths in the menu.
0785   plotList = plotList_temp;
0786   plotList_temp.clear();
0787 }
0788 
0789 // ------------ method called when ending the processing of a run  ------------
0790 
0791 void HLTObjectMonitor::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) {
0792   ////////////////////////////////
0793   ///
0794   /// Main shifter workspace plots
0795   ///
0796   ////////////////////////////////
0797 
0798   //book wall time separately
0799   ibooker.setCurrentFolder(mainShifterFolder);
0800   wallTime_.ME =
0801       ibooker.book1D(wallTime_.plotLabel, wallTime_.pathName, wallTime_.nBins, wallTime_.xMin, wallTime_.xMax);
0802   wallTime_.ME->setAxisTitle(wallTime_.xAxisLabel);
0803 
0804   for (auto plot : plotList) {
0805     std::string display_pathNames = plot->pathName;
0806     if (!plot->pathNameOR.empty())
0807       display_pathNames = plot->pathName + " OR " + plot->pathNameOR;
0808 
0809     if (plot->displayInPrimary) {
0810       ibooker.setCurrentFolder(mainShifterFolder);
0811       (*plot).ME = ibooker.book1D(plot->plotLabel, display_pathNames.c_str(), plot->nBins, plot->xMin, plot->xMax);
0812       (*plot).ME->setAxisTitle(plot->xAxisLabel);
0813       //need to add OR statement
0814     } else {
0815       ibooker.setCurrentFolder(backupFolder);
0816       (*plot).ME = ibooker.book1D(plot->plotLabel, display_pathNames.c_str(), plot->nBins, plot->xMin, plot->xMax);
0817       (*plot).ME->setAxisTitle(plot->xAxisLabel);
0818     }
0819   }
0820 }
0821 
0822 double HLTObjectMonitor::dxyFinder(double eta,
0823                                    double phi,
0824                                    edm::Handle<reco::RecoChargedCandidateCollection> recoChargedCands,
0825                                    edm::Handle<reco::BeamSpot> recoBeamSpot) {
0826   double dxy = -99.;
0827   for (reco::RecoChargedCandidateCollection::const_iterator l3Muon = recoChargedCands->begin();
0828        l3Muon != recoChargedCands->end();
0829        l3Muon++) {
0830     if (deltaR(eta, phi, l3Muon->eta(), l3Muon->phi()) < 0.1) {
0831       dxy = (-(l3Muon->vx() - recoBeamSpot->x0()) * l3Muon->py() + (l3Muon->vy() - recoBeamSpot->y0()) * l3Muon->px()) /
0832             l3Muon->pt();
0833       break;
0834     }
0835   }
0836   return dxy;
0837 }
0838 
0839 double HLTObjectMonitor::get_wall_time() {
0840   struct timeval time;
0841   if (gettimeofday(&time, nullptr))
0842     return 0;
0843   return (double)time.tv_sec + (double)time.tv_usec * .000001;
0844 }
0845 
0846 // ------------ method called when starting to processes a luminosity block  ------------
0847 /*
0848 void
0849 HLTObjectMonitor::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
0850 {
0851 }
0852 */
0853 
0854 // ------------ method called when ending the processing of a luminosity block  ------------
0855 /*
0856 void
0857 HLTObjectMonitor::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
0858 {
0859 }
0860 */
0861 
0862 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0863 // void
0864 // HLTObjectMonitor::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0865 //   //The following says we do not know what parameters are allowed so do no validation
0866 //   // Please change this to state exactly what you do use, even if it is no parameters
0867 //   edm::ParameterSetDescription desc;
0868 //   desc.setUnknown();
0869 //   descriptions.addDefault(desc);
0870 // }
0871 
0872 //define this as a plug-in
0873 DEFINE_FWK_MODULE(HLTObjectMonitor);