Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-09-18 22:46:53

0001 #include <iostream>
0002 
0003 /**\class PhotonDataCertification 
0004 */
0005 //
0006 // Original Author: Jason Slaunwhite
0007 //
0008 //         Created:  Thu Jan 22 13:42:28CET 2009
0009 //
0010 
0011 // system include files
0012 #include <memory>
0013 #include <vector>
0014 
0015 //
0016 #include "FWCore/Framework/interface/MakerMacros.h"
0017 #include "FWCore/Framework/interface/Run.h"
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 #include "FWCore/Utilities/interface/Exception.h"
0020 #include "FWCore/ServiceRegistry/interface/Service.h"
0021 
0022 //root include files
0023 #include "TFile.h"
0024 #include "TH1.h"
0025 #include "TH2.h"
0026 #include "TTree.h"
0027 #include "TVector3.h"
0028 #include "TProfile.h"
0029 //
0030 
0031 // user include files
0032 #include "FWCore/Framework/interface/Frameworkfwd.h"
0033 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0034 
0035 #include "FWCore/Framework/interface/Event.h"
0036 
0037 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0038 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0039 
0040 //DQM services
0041 #include "DQMServices/Core/interface/DQMStore.h"
0042 #include "FWCore/ServiceRegistry/interface/Service.h"
0043 
0044 using namespace std;
0045 
0046 //
0047 // class decleration
0048 //
0049 
0050 class HLTOverallSummary : public edm::one::EDAnalyzer<edm::one::SharedResources, edm::one::WatchRuns> {
0051 public:
0052   typedef dqm::legacy::MonitorElement MonitorElement;
0053   typedef dqm::legacy::DQMStore DQMStore;
0054 
0055   explicit HLTOverallSummary(const edm::ParameterSet& pset);
0056   ~HLTOverallSummary() override;
0057 
0058   void analyze(const edm::Event&, const edm::EventSetup&) override;
0059   void beginRun(const edm::Run&, const edm::EventSetup&) override;
0060   void endRun(const edm::Run&, const edm::EventSetup&) override;
0061 
0062 private:
0063   DQMStore* dbe_;
0064   edm::ParameterSet parameters_;
0065 
0066   bool verbose_;
0067 
0068   // ----------member data ---------------------------
0069 };
0070 
0071 HLTOverallSummary::HLTOverallSummary(const edm::ParameterSet& pset)
0072 
0073 {
0074   usesResource("DQMStore");
0075   using namespace edm;
0076   dbe_ = nullptr;
0077   dbe_ = edm::Service<DQMStore>().operator->();
0078   if (!dbe_) {
0079     LogInfo("HLTMuonVal") << "Can't find DQMStore, no results will be saved" << endl;
0080   }
0081 
0082   parameters_ = pset;
0083   verbose_ = parameters_.getUntrackedParameter<bool>("verbose", false);
0084 
0085   if (verbose_)
0086     LogInfo("HLTMuonVal") << ">>> Constructor (HLTOverallSummary) <<<" << endl;
0087 }
0088 
0089 HLTOverallSummary::~HLTOverallSummary() = default;
0090 
0091 //
0092 // member functions
0093 //
0094 
0095 // ------------ method called to for each event  ------------
0096 void HLTOverallSummary::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0097   using namespace edm;
0098 
0099   if (verbose_)
0100     LogInfo("HLTMuonVal") << ">>> Analyze (HLTOverallSummary) <<<" << std::endl;
0101 }
0102 
0103 // ------------ method called just before starting a new run  ------------
0104 void HLTOverallSummary::beginRun(const edm::Run& run, const edm::EventSetup& c) {
0105   using namespace edm;
0106   if (verbose_)
0107     LogInfo("HLTMuonVal") << ">>> BeginRun (HLTOverallSummary) <<<" << std::endl;
0108   if (verbose_)
0109     LogInfo("HLTMuonVal") << ">>> " << run.id() << std::endl;
0110 }
0111 
0112 // ------------ method called right after a run ends ------------
0113 void HLTOverallSummary::endRun(const edm::Run& run, const edm::EventSetup& c) {
0114   using namespace edm;
0115   if (verbose_)
0116     LogInfo("HLTMuonVal") << ">>> EndRun (HLTOverallSummary) <<<" << std::endl;
0117 
0118   if (!dbe_) {
0119     LogInfo("HLTMuonVal") << "No dqmstore... skipping processing step" << endl;
0120     return;
0121   }
0122 
0123   std::vector<string> histoNameVector;
0124 
0125   //booking histograms according to naming conventions
0126 
0127   float defaultValueIfNotFound = 1.0;
0128 
0129   dbe_->setCurrentFolder("HLT/EventInfo/reportSummaryContent");
0130 
0131   //============ Unpack information ==========
0132 
0133   MonitorElement* muonQualityBit = nullptr;
0134   muonQualityBit = dbe_->get("HLT_Muon");
0135 
0136   if (!muonQualityBit) {
0137     LogInfo("HLTMuonVal") << "Can't find muonQuality bit... making a bit, setting it to zero" << endl;
0138 
0139     muonQualityBit = dbe_->bookFloat("HLT_Muon");
0140     muonQualityBit->Fill(defaultValueIfNotFound);
0141   }
0142 
0143   MonitorElement* eleQualityBit = nullptr;
0144   eleQualityBit = dbe_->get("HLT_Electron");
0145 
0146   if (!eleQualityBit) {
0147     LogInfo("HLTMuonVal") << "Can't find eleQuality bit... making a bit, setting it to zero" << endl;
0148 
0149     eleQualityBit = dbe_->bookFloat("HLT_Electron");
0150     eleQualityBit->Fill(defaultValueIfNotFound);
0151   }
0152 
0153   MonitorElement* photonQualityBit = nullptr;
0154   photonQualityBit = dbe_->get("HLT_Photon");
0155 
0156   if (!photonQualityBit) {
0157     LogInfo("HLTMuonVal") << "Can't find photonQuality bit... making a bit, setting it to zero" << endl;
0158 
0159     photonQualityBit = dbe_->bookFloat("HLT_Photon");
0160     photonQualityBit->Fill(defaultValueIfNotFound);
0161   }
0162 
0163   //============ Book new storage locations =============
0164 
0165   dbe_->setCurrentFolder("HLT/EventInfo");
0166   MonitorElement* hltQualityBit = dbe_->bookFloat("reportSummary");
0167 
0168   MonitorElement* hltQualitySummaryWord = dbe_->bookInt("HLT_SUMMARY_WORD");
0169 
0170   //for now these will hold values from eta/phi tests for spikes/holes
0171   MonitorElement* reportSummaryMap =
0172       dbe_->book2D("reportSummaryMap", "HLT: ReportSummaryMap", 3, -0.5, 2.5, 1, -0.5, 0.5);
0173   MonitorElement* CertificationSummaryMap =
0174       dbe_->book2D("certificationSummaryMap", "HLT: CertificationSummaryMap", 3, -0.5, 2.5, 1, -0.5, 0.5);
0175 
0176   TH2* reportSummaryMapTH2 = reportSummaryMap->getTH2F();
0177 
0178   reportSummaryMapTH2->GetXaxis()->SetBinLabel(1, "Muon");
0179   reportSummaryMapTH2->GetXaxis()->SetBinLabel(2, "Electron");
0180   reportSummaryMapTH2->GetXaxis()->SetBinLabel(3, "Photon");
0181 
0182   reportSummaryMapTH2->GetYaxis()->SetBinLabel(1, "Quality");
0183 
0184   TH2* CertificationSummaryMapTH2 = CertificationSummaryMap->getTH2F();
0185 
0186   CertificationSummaryMapTH2->GetXaxis()->SetBinLabel(1, "Muon");
0187   CertificationSummaryMapTH2->GetXaxis()->SetBinLabel(2, "Electron");
0188   CertificationSummaryMapTH2->GetXaxis()->SetBinLabel(3, "Photon");
0189   CertificationSummaryMapTH2->GetYaxis()->SetBinLabel(1, "Quality");
0190 
0191   //=================== Interpret bits and store result
0192 
0193   float photonValue = photonQualityBit->getFloatValue();
0194 
0195   float electronValue = eleQualityBit->getFloatValue();
0196 
0197   float muonValue = muonQualityBit->getFloatValue();
0198 
0199   float hltOverallValue = 1.0;
0200 
0201   if ((photonValue > 0.99) && (electronValue > 0.99) && (muonValue > 0.99)) {
0202     hltOverallValue = 1.0;
0203 
0204   } else {
0205     hltOverallValue = 0.0;
0206   }
0207 
0208   hltQualityBit->Fill(hltOverallValue);
0209 
0210   unsigned int hltSummaryValue = 0x0;  //
0211 
0212   unsigned int ELECTRON_MASK = 0x1;
0213   unsigned int PHOTON_MASK = 0x2;
0214   unsigned int MUON_MASK = 0x4;
0215 
0216   if (electronValue > 0.99)
0217     hltSummaryValue = hltSummaryValue | ELECTRON_MASK;
0218   if (photonValue > 0.99)
0219     hltSummaryValue = hltSummaryValue | PHOTON_MASK;
0220   if (muonValue > 0.99)
0221     hltSummaryValue = hltSummaryValue | MUON_MASK;
0222 
0223   hltQualitySummaryWord->Fill(hltSummaryValue);
0224 
0225   reportSummaryMapTH2->SetBinContent(reportSummaryMapTH2->GetBin(1, 1), muonValue);
0226   reportSummaryMapTH2->SetBinContent(reportSummaryMapTH2->GetBin(2, 1), electronValue);
0227   reportSummaryMapTH2->SetBinContent(reportSummaryMapTH2->GetBin(3, 1), photonValue);
0228 
0229   CertificationSummaryMapTH2->SetBinContent(CertificationSummaryMapTH2->GetBin(1, 1), muonValue);
0230   CertificationSummaryMapTH2->SetBinContent(CertificationSummaryMapTH2->GetBin(2, 1), electronValue);
0231   CertificationSummaryMapTH2->SetBinContent(CertificationSummaryMapTH2->GetBin(3, 1), photonValue);
0232 }
0233 
0234 DEFINE_FWK_MODULE(HLTOverallSummary);