HLTOverallSummary

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
#include <iostream>

/**\class PhotonDataCertification 
*/
//
// Original Author: Jason Slaunwhite
//
//         Created:  Thu Jan 22 13:42:28CET 2009
//

// system include files
#include <memory>
#include <vector>

//
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/Run.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/ServiceRegistry/interface/Service.h"

//root include files
#include "TFile.h"
#include "TH1.h"
#include "TH2.h"
#include "TTree.h"
#include "TVector3.h"
#include "TProfile.h"
//

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"

#include "FWCore/Framework/interface/Event.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

//DQM services
#include "DQMServices/Core/interface/DQMStore.h"
#include "FWCore/ServiceRegistry/interface/Service.h"

using namespace std;

//
// class decleration
//

class HLTOverallSummary : public edm::one::EDAnalyzer<edm::one::SharedResources, edm::one::WatchRuns> {
public:
  typedef dqm::legacy::MonitorElement MonitorElement;
  typedef dqm::legacy::DQMStore DQMStore;

  explicit HLTOverallSummary(const edm::ParameterSet& pset);
  ~HLTOverallSummary() override;

  void analyze(const edm::Event&, const edm::EventSetup&) override;
  void beginRun(const edm::Run&, const edm::EventSetup&) override;
  void endRun(const edm::Run&, const edm::EventSetup&) override;

private:
  DQMStore* dbe_;
  edm::ParameterSet parameters_;

  bool verbose_;

  // ----------member data ---------------------------
};

HLTOverallSummary::HLTOverallSummary(const edm::ParameterSet& pset)

{
  usesResource("DQMStore");
  using namespace edm;
  dbe_ = nullptr;
  dbe_ = edm::Service<DQMStore>().operator->();
  if (!dbe_) {
    LogInfo("HLTMuonVal") << "Can't find DQMStore, no results will be saved" << endl;
  }

  parameters_ = pset;
  verbose_ = parameters_.getUntrackedParameter<bool>("verbose", false);

  if (verbose_)
    LogInfo("HLTMuonVal") << ">>> Constructor (HLTOverallSummary) <<<" << endl;
}

HLTOverallSummary::~HLTOverallSummary() = default;

//
// member functions
//

// ------------ method called to for each event  ------------
void HLTOverallSummary::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
  using namespace edm;

  if (verbose_)
    LogInfo("HLTMuonVal") << ">>> Analyze (HLTOverallSummary) <<<" << std::endl;
}

// ------------ method called just before starting a new run  ------------
void HLTOverallSummary::beginRun(const edm::Run& run, const edm::EventSetup& c) {
  using namespace edm;
  if (verbose_)
    LogInfo("HLTMuonVal") << ">>> BeginRun (HLTOverallSummary) <<<" << std::endl;
  if (verbose_)
    LogInfo("HLTMuonVal") << ">>> " << run.id() << std::endl;
}

// ------------ method called right after a run ends ------------
void HLTOverallSummary::endRun(const edm::Run& run, const edm::EventSetup& c) {
  using namespace edm;
  if (verbose_)
    LogInfo("HLTMuonVal") << ">>> EndRun (HLTOverallSummary) <<<" << std::endl;

  if (!dbe_) {
    LogInfo("HLTMuonVal") << "No dqmstore... skipping processing step" << endl;
    return;
  }

  std::vector<string> histoNameVector;

  //booking histograms according to naming conventions

  float defaultValueIfNotFound = 1.0;

  dbe_->setCurrentFolder("HLT/EventInfo/reportSummaryContent");

  //============ Unpack information ==========

  MonitorElement* muonQualityBit = nullptr;
  muonQualityBit = dbe_->get("HLT_Muon");

  if (!muonQualityBit) {
    LogInfo("HLTMuonVal") << "Can't find muonQuality bit... making a bit, setting it to zero" << endl;

    muonQualityBit = dbe_->bookFloat("HLT_Muon");
    muonQualityBit->Fill(defaultValueIfNotFound);
  }

  MonitorElement* eleQualityBit = nullptr;
  eleQualityBit = dbe_->get("HLT_Electron");

  if (!eleQualityBit) {
    LogInfo("HLTMuonVal") << "Can't find eleQuality bit... making a bit, setting it to zero" << endl;

    eleQualityBit = dbe_->bookFloat("HLT_Electron");
    eleQualityBit->Fill(defaultValueIfNotFound);
  }

  MonitorElement* photonQualityBit = nullptr;
  photonQualityBit = dbe_->get("HLT_Photon");

  if (!photonQualityBit) {
    LogInfo("HLTMuonVal") << "Can't find photonQuality bit... making a bit, setting it to zero" << endl;

    photonQualityBit = dbe_->bookFloat("HLT_Photon");
    photonQualityBit->Fill(defaultValueIfNotFound);
  }

  //============ Book new storage locations =============

  dbe_->setCurrentFolder("HLT/EventInfo");
  MonitorElement* hltQualityBit = dbe_->bookFloat("reportSummary");

  MonitorElement* hltQualitySummaryWord = dbe_->bookInt("HLT_SUMMARY_WORD");

  //for now these will hold values from eta/phi tests for spikes/holes
  MonitorElement* reportSummaryMap =
      dbe_->book2D("reportSummaryMap", "HLT: ReportSummaryMap", 3, -0.5, 2.5, 1, -0.5, 0.5);
  MonitorElement* CertificationSummaryMap =
      dbe_->book2D("certificationSummaryMap", "HLT: CertificationSummaryMap", 3, -0.5, 2.5, 1, -0.5, 0.5);

  TH2* reportSummaryMapTH2 = reportSummaryMap->getTH2F();

  reportSummaryMapTH2->GetXaxis()->SetBinLabel(1, "Muon");
  reportSummaryMapTH2->GetXaxis()->SetBinLabel(2, "Electron");
  reportSummaryMapTH2->GetXaxis()->SetBinLabel(3, "Photon");

  reportSummaryMapTH2->GetYaxis()->SetBinLabel(1, "Quality");

  TH2* CertificationSummaryMapTH2 = CertificationSummaryMap->getTH2F();

  CertificationSummaryMapTH2->GetXaxis()->SetBinLabel(1, "Muon");
  CertificationSummaryMapTH2->GetXaxis()->SetBinLabel(2, "Electron");
  CertificationSummaryMapTH2->GetXaxis()->SetBinLabel(3, "Photon");
  CertificationSummaryMapTH2->GetYaxis()->SetBinLabel(1, "Quality");

  //=================== Interpret bits and store result

  float photonValue = photonQualityBit->getFloatValue();

  float electronValue = eleQualityBit->getFloatValue();

  float muonValue = muonQualityBit->getFloatValue();

  float hltOverallValue = 1.0;

  if ((photonValue > 0.99) && (electronValue > 0.99) && (muonValue > 0.99)) {
    hltOverallValue = 1.0;

  } else {
    hltOverallValue = 0.0;
  }

  hltQualityBit->Fill(hltOverallValue);

  unsigned int hltSummaryValue = 0x0;  //

  unsigned int ELECTRON_MASK = 0x1;
  unsigned int PHOTON_MASK = 0x2;
  unsigned int MUON_MASK = 0x4;

  if (electronValue > 0.99)
    hltSummaryValue = hltSummaryValue | ELECTRON_MASK;
  if (photonValue > 0.99)
    hltSummaryValue = hltSummaryValue | PHOTON_MASK;
  if (muonValue > 0.99)
    hltSummaryValue = hltSummaryValue | MUON_MASK;

  hltQualitySummaryWord->Fill(hltSummaryValue);

  reportSummaryMapTH2->SetBinContent(reportSummaryMapTH2->GetBin(1, 1), muonValue);
  reportSummaryMapTH2->SetBinContent(reportSummaryMapTH2->GetBin(2, 1), electronValue);
  reportSummaryMapTH2->SetBinContent(reportSummaryMapTH2->GetBin(3, 1), photonValue);

  CertificationSummaryMapTH2->SetBinContent(CertificationSummaryMapTH2->GetBin(1, 1), muonValue);
  CertificationSummaryMapTH2->SetBinContent(CertificationSummaryMapTH2->GetBin(2, 1), electronValue);
  CertificationSummaryMapTH2->SetBinContent(CertificationSummaryMapTH2->GetBin(3, 1), photonValue);
}

DEFINE_FWK_MODULE(HLTOverallSummary);