Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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_MuonFakes.h"
0007 
0008 SUSY_HLT_MuonFakes::SUSY_HLT_MuonFakes(const edm::ParameterSet &ps) {
0009   edm::LogInfo("SUSY_HLT_MuonFakes") << "Constructor SUSY_HLT_MuonFakes::SUSY_HLT_MuonFakes " << std::endl;
0010   // Get parameters from configuration file
0011   theTrigSummary_ = consumes<trigger::TriggerEvent>(ps.getParameter<edm::InputTag>("trigSummary"));
0012   triggerResults_ = consumes<edm::TriggerResults>(ps.getParameter<edm::InputTag>("TriggerResults"));
0013   HLTProcess_ = ps.getParameter<std::string>("HLTProcess");
0014   triggerPath_ = ps.getParameter<std::string>("TriggerPath");
0015   triggerFilter_ = ps.getParameter<edm::InputTag>("TriggerFilter");
0016 }
0017 
0018 SUSY_HLT_MuonFakes::~SUSY_HLT_MuonFakes() {
0019   edm::LogInfo("SUSY_HLT_MuonFakes") << "Destructor SUSY_HLT_MuonFakes::~SUSY_HLT_MuonFakes " << std::endl;
0020 }
0021 
0022 void SUSY_HLT_MuonFakes::dqmBeginRun(edm::Run const &run, edm::EventSetup const &e) {
0023   bool changed;
0024 
0025   if (!fHltConfig.init(run, e, HLTProcess_, changed)) {
0026     edm::LogError("SUSY_HLT_MuonFakes") << "Initialization of HLTConfigProvider failed!!";
0027     return;
0028   }
0029 
0030   bool pathFound = false;
0031   const std::vector<std::string> allTrigNames = fHltConfig.triggerNames();
0032   for (size_t j = 0; j < allTrigNames.size(); ++j) {
0033     if (allTrigNames[j].find(triggerPath_) != std::string::npos) {
0034       pathFound = true;
0035     }
0036   }
0037 
0038   if (!pathFound) {
0039     edm::LogInfo("SUSY_HLT_MuonFakes") << "Path not found"
0040                                        << "\n";
0041     return;
0042   }
0043   edm::LogInfo("SUSY_HLT_MuonFakes") << "SUSY_HLT_MuonFakes::beginRun" << std::endl;
0044 }
0045 
0046 void SUSY_HLT_MuonFakes::bookHistograms(DQMStore::IBooker &ibooker_, edm::Run const &, edm::EventSetup const &) {
0047   edm::LogInfo("SUSY_HLT_MuonFakes") << "SUSY_HLT_MuonFakes::bookHistograms" << std::endl;
0048   // book at beginRun
0049   bookHistos(ibooker_);
0050 }
0051 
0052 void SUSY_HLT_MuonFakes::analyze(edm::Event const &e, edm::EventSetup const &eSetup) {
0053   edm::LogInfo("SUSY_HLT_MuonFakes") << "SUSY_HLT_MuonFakes::analyze" << std::endl;
0054 
0055   //-------------------------------
0056   //--- Trigger
0057   //-------------------------------
0058   edm::Handle<edm::TriggerResults> hltresults;
0059   e.getByToken(triggerResults_, hltresults);
0060   if (!hltresults.isValid()) {
0061     edm::LogError("SUSY_HLT_MuonFakes") << "invalid collection: TriggerResults"
0062                                         << "\n";
0063     return;
0064   }
0065   edm::Handle<trigger::TriggerEvent> triggerSummary;
0066   e.getByToken(theTrigSummary_, triggerSummary);
0067   if (!triggerSummary.isValid()) {
0068     edm::LogError("SUSY_HLT_MuonFakes") << "invalid collection: TriggerSummary"
0069                                         << "\n";
0070     return;
0071   }
0072 
0073   // get online objects
0074   std::vector<float> ptMuon, etaMuon, phiMuon;
0075   size_t filterIndex = triggerSummary->filterIndex(triggerFilter_);
0076   trigger::TriggerObjectCollection triggerObjects = triggerSummary->getObjects();
0077   if (!(filterIndex >= triggerSummary->sizeFilters())) {
0078     const trigger::Keys &keys = triggerSummary->filterKeys(filterIndex);
0079     for (size_t j = 0; j < keys.size(); ++j) {
0080       trigger::TriggerObject foundObject = triggerObjects[keys[j]];
0081       if (foundObject.id() == 13) {  // Muons check number
0082         h_triggerMuPt->Fill(foundObject.pt());
0083         h_triggerMuEta->Fill(foundObject.eta());
0084         h_triggerMuPhi->Fill(foundObject.phi());
0085         ptMuon.push_back(foundObject.pt());
0086         etaMuon.push_back(foundObject.eta());
0087         phiMuon.push_back(foundObject.phi());
0088       }
0089     }
0090   }
0091 
0092   //  bool hasFired = false;
0093   //  const edm::TriggerNames& trigNames = e.triggerNames(*hltresults);
0094   //  unsigned int numTriggers = trigNames.size();
0095   //  for( unsigned int hltIndex=0; hltIndex<numTriggers; ++hltIndex ){
0096   //    if (trigNames.triggerName(hltIndex)==triggerPath_ &&
0097   //    hltresults->wasrun(hltIndex) && hltresults->accept(hltIndex)) hasFired =
0098   //    true;
0099   //  }
0100 }
0101 
0102 void SUSY_HLT_MuonFakes::bookHistos(DQMStore::IBooker &ibooker_) {
0103   ibooker_.cd();
0104   ibooker_.setCurrentFolder("HLT/SUSYBSM/" + triggerPath_);
0105 
0106   // online quantities
0107   h_triggerMuPt = ibooker_.book1D("triggerMuPt", "Trigger Mu Pt; GeV", 40, 0.0, 80.0);
0108   h_triggerMuEta = ibooker_.book1D("triggerMuEta", "Trigger Mu Eta", 20, -2.5, 2.5);
0109   h_triggerMuPhi = ibooker_.book1D("triggerMuPhi", "Trigger Mu Phi", 20, -3.5, 3.5);
0110 
0111   // num and den hists to be divided in harvesting step to make turn on curves
0112   ibooker_.cd();
0113 }
0114 
0115 // define this as a plug-in
0116 DEFINE_FWK_MODULE(SUSY_HLT_MuonFakes);