00001 #include "DQM/HLTEvF/interface/HLTEventInfoClient.h"
00002
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/Run.h"
00005 #include "FWCore/Framework/interface/LuminosityBlock.h"
00006
00007 #include "FWCore/ServiceRegistry/interface/Service.h"
00008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00009 #include "FWCore/Framework/interface/ESHandle.h"
00010 #include "FWCore/Framework/interface/EventSetup.h"
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012 #include "DQMServices/Core/interface/QReport.h"
00013 #include "DQMServices/Core/interface/DQMStore.h"
00014 #include "DQMServices/Core/interface/MonitorElement.h"
00015 #include "TRandom.h"
00016 #include <TF1.h>
00017 #include <stdio.h>
00018 #include <sstream>
00019 #include <math.h>
00020 #include <TProfile.h>
00021 #include <TProfile2D.h>
00022 #include <memory>
00023 #include <iostream>
00024 #include <iomanip>
00025 #include <map>
00026 #include <vector>
00027 #include <string>
00028 #include <fstream>
00029 #include "TROOT.h"
00030
00031 using namespace edm;
00032 using namespace std;
00033
00034 HLTEventInfoClient::HLTEventInfoClient(const edm::ParameterSet& ps)
00035 {
00036 parameters_=ps;
00037 initialize();
00038 }
00039
00040 HLTEventInfoClient::~HLTEventInfoClient(){
00041 if(verbose_) std::cout <<"[TriggerDQM]: ending... " << std::endl;
00042 }
00043
00044
00045 void HLTEventInfoClient::initialize(){
00046
00047 counterLS_=0;
00048 counterEvt_=0;
00049
00050
00051 dbe_ = Service<DQMStore>().operator->();
00052
00053
00054 verbose_ = parameters_.getUntrackedParameter<bool>("verbose", false);
00055
00056 monitorDir_ = parameters_.getUntrackedParameter<std::string>("monitorDir","");
00057 if(verbose_) std::cout << "Monitor dir = " << monitorDir_ << std::endl;
00058
00059 prescaleLS_ = parameters_.getUntrackedParameter<int>("prescaleLS", -1);
00060 if(verbose_) std::cout << "DQM lumi section prescale = " << prescaleLS_ << " lumi section(s)"<< std::endl;
00061
00062 prescaleEvt_ = parameters_.getUntrackedParameter<int>("prescaleEvt", -1);
00063 if(verbose_) std::cout << "DQM event prescale = " << prescaleEvt_ << " events(s)"<< std::endl;
00064
00065
00066
00067 }
00068
00069
00070 void HLTEventInfoClient::beginJob(){
00071
00072 if(verbose_) std::cout <<"[TriggerDQM]: Begin Job" << std::endl;
00073
00074 dbe_ = Service<DQMStore>().operator->();
00075
00076 dbe_->setCurrentFolder("HLT/EventInfo");
00077
00078
00079 reportSummary_ = dbe_->get("HLT/EventInfo/reportSumamry");
00080 if ( reportSummary_ ) {
00081 dbe_->removeElement(reportSummary_->getName());
00082 }
00083
00084 reportSummary_ = dbe_->bookFloat("reportSummary");
00085
00086 int nPDs = 20;
00087
00088
00089 if (reportSummary_) reportSummary_->Fill(1);
00090
00091 dbe_->setCurrentFolder("HLT/EventInfo/reportSummaryContents");
00092
00093
00094 char histo[100];
00095
00096 for (int n = 0; n < nPDs; n++) {
00097
00098 switch(n){
00099 case 0 : sprintf(histo,"hlt_dqm_EGamma"); break;
00100 case 1 : sprintf(histo,"hlt_dqm_Muon"); break;
00101 case 2 : sprintf(histo,"hlt_dqm_JetMet"); break;
00102 case 3 : sprintf(histo,"hlt_dqm_BJets"); break;
00103 case 4 : sprintf(histo,"hlt_dqm_Tau"); break;
00104 case 5 : sprintf(histo,"hlt_dqm_Test1"); break;
00105 case 6 : sprintf(histo,"hlt_dqm_Test2"); break;
00106 case 7 : sprintf(histo,"hlt_dqm_Test3"); break;
00107 case 8 : sprintf(histo,"hlt_dqm_Test4"); break;
00108 case 9 : sprintf(histo,"hlt_dqm_Test5"); break;
00109 case 10 : sprintf(histo,"hlt_dqm_Test6"); break;
00110 case 11 : sprintf(histo,"hlt_dqm_Test7"); break;
00111 case 12 : sprintf(histo,"hlt_dqm_Test8"); break;
00112 case 13 : sprintf(histo,"hlt_dqm_Test9"); break;
00113 case 14 : sprintf(histo,"hlt_dqm_Test10"); break;
00114 case 15 : sprintf(histo,"hlt_dqm_Test11"); break;
00115 case 16 : sprintf(histo,"hlt_dqm_Test12"); break;
00116 case 17 : sprintf(histo,"hlt_dqm_Test13"); break;
00117 case 18 : sprintf(histo,"hlt_dqm_Test14"); break;
00118 case 19 : sprintf(histo,"hlt_dqm_Test15"); break;
00119 }
00120
00121
00122
00123
00124
00125
00126
00127
00128 reportSummaryContent_[n] = dbe_->bookFloat(histo);
00129 }
00130
00131
00132 for (int k = 0; k < nPDs; k++) {
00133 summaryContent[k] = 1;
00134 reportSummaryContent_[k]->Fill(1.);
00135 }
00136
00137
00138 dbe_->setCurrentFolder("HLT/EventInfo");
00139
00140 reportSummaryMap_ = dbe_->get("HLT/EventInfo/reportSummaryMap");
00141 if ( reportSummaryMap_ ) {
00142 dbe_->removeElement(reportSummaryMap_->getName());
00143 }
00144
00145
00146 reportSummaryMap_ = dbe_->book2D("reportSummaryMap", "reportSummaryMap", 1, 1, 2, 10, 1, 11);
00147 reportSummaryMap_->setAxisTitle("", 1);
00148 reportSummaryMap_->setAxisTitle("", 2);
00149 reportSummaryMap_->setBinLabel(1,"SingleElectron",2);
00150 reportSummaryMap_->setBinLabel(2,"DoubleElectron",2);
00151 reportSummaryMap_->setBinLabel(3,"SingleMu",2);
00152 reportSummaryMap_->setBinLabel(4,"DoubleMu",2);
00153 reportSummaryMap_->setBinLabel(5,"Photon",2);
00154 reportSummaryMap_->setBinLabel(6,"Tau",2);
00155 reportSummaryMap_->setBinLabel(7,"BTag",2);
00156 reportSummaryMap_->setBinLabel(8,"HT",2);
00157 reportSummaryMap_->setBinLabel(9,"Jet",2);
00158 reportSummaryMap_->setBinLabel(10,"MET",2);
00159 reportSummaryMap_->setBinLabel(1," ",1);
00160
00161 }
00162
00163
00164 void HLTEventInfoClient::beginRun(const Run& r, const EventSetup& context) {
00165 }
00166
00167
00168 void HLTEventInfoClient::beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& context) {
00169
00170 }
00171
00172 void HLTEventInfoClient::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& c) {
00173
00174
00175 int ilumi = int(lumiSeg.id().luminosityBlock());
00176
00177 const int nPDs = 10;
00178 MonitorElement* Pass_Hists[nPDs];
00179 int nPathsPD[nPDs];
00180 double PDResult[nPDs];
00181 int nTotPD[nPDs];
00182 for( int i = 0; i < nPDs; i++ ) {
00183 PDResult[i] = 1.0;
00184 nTotPD[i] = 0.0;
00185 }
00186 bool isCollision = true;
00187
00188 for( int i = 0; i < nPDs; i++ ) {
00189 if( i == 0 ) Pass_Hists[i] = dbe_->get("HLT/FourVector/PathsSummary/HLT_SingleElectron_Pass_Any");
00190 if( i == 1 ) Pass_Hists[i] = dbe_->get("HLT/FourVector/PathsSummary/HLT_DoubleElectron_Pass_Any");
00191 if( i == 2 ) Pass_Hists[i] = dbe_->get("HLT/FourVector/PathsSummary/HLT_SingleMu_Pass_Any");
00192 if( i == 3 ) Pass_Hists[i] = dbe_->get("HLT/FourVector/PathsSummary/HLT_DoubleMu_Pass_Any");
00193 if( i == 4 ) Pass_Hists[i] = dbe_->get("HLT/FourVector/PathsSummary/HLT_Photon_Pass_Any");
00194 if( i == 5 ) Pass_Hists[i] = dbe_->get("HLT/FourVector/PathsSummary/HLT_Tau_Pass_Any");
00195 if( i == 6 ) Pass_Hists[i] = dbe_->get("HLT/FourVector/PathsSummary/HLT_BTag_Pass_Any");
00196 if( i == 7 ) Pass_Hists[i] = dbe_->get("HLT/FourVector/PathsSummary/HLT_HT_Pass_Any");
00197 if( i == 8 ) Pass_Hists[i] = dbe_->get("HLT/FourVector/PathsSummary/HLT_Jet_Pass_Any");
00198 if( i == 9 ) Pass_Hists[i] = dbe_->get("HLT/FourVector/PathsSummary/HLT_MET_Pass_Any");
00199
00200 if( Pass_Hists[i] ) {
00201 if( i == 5 && !isCollision ) continue;
00202 nPathsPD[i] = Pass_Hists[i]->getNbinsX();
00203 int noBins = 2;
00204 if( i == 1 ) noBins = 3;
00205 if( i == 8 ) noBins = 4;
00206
00207 for( int j = 0; j < nPathsPD[i]-noBins; j++ ) {
00208
00209
00210 if( i == 1 && (j == 0) ) continue;
00211 if( i == 3 && (j == 1 || j == 4) ) continue;
00212 if( i == 4 && (j > 1) ) continue;
00213 if( i == 5 && (j > 4) ) continue;
00214 if( i == 7 && (j == 7) ) continue;
00215 if( i == 8 && (j == 8) ) continue;
00216 if( i == 9 && (j == 8 || j == 13 || j == 15) ) continue;
00217
00218 double val = Pass_Hists[i]->getBinContent(j+1);
00219 if( val == 0 ) {
00220 if( ilumi > 5 ) PDResult[i] = 0.5;
00221 }
00222 nTotPD[i] += val;
00223 }
00224 if( nTotPD[i] == 0 ) {
00225 if( ilumi > 5 ) PDResult[i] = 0.0;
00226 }
00227 }
00228 else {
00229 isCollision = false;
00230 }
00231 }
00232
00233 for (int k = 0; k < nPDs; k++) {
00234 if( k < 10 ) {
00235 summaryContent[k] = PDResult[k];
00236 reportSummaryContent_[k]->Fill(PDResult[k]);
00237 }
00238 else {
00239 summaryContent[k] = 1;
00240 reportSummaryContent_[k]->Fill(1.);
00241 }
00242 }
00243 summarySum = 0;
00244
00245 for (int m = 0; m < nPDs; m++) {
00246 summarySum += summaryContent[m];
00247 }
00248
00249
00250 reportSummary = summarySum / nPDs;;
00251 if (reportSummary_) reportSummary_->Fill(reportSummary);
00252
00253
00254 reportSummaryMap_->setBinContent(1,1,summaryContent[0]);
00255 reportSummaryMap_->setBinContent(1,2,summaryContent[1]);
00256 reportSummaryMap_->setBinContent(1,3,summaryContent[2]);
00257 reportSummaryMap_->setBinContent(1,4,summaryContent[3]);
00258 reportSummaryMap_->setBinContent(1,5,summaryContent[4]);
00259 reportSummaryMap_->setBinContent(1,6,summaryContent[5]);
00260 reportSummaryMap_->setBinContent(1,7,summaryContent[6]);
00261 reportSummaryMap_->setBinContent(1,8,summaryContent[7]);
00262 reportSummaryMap_->setBinContent(1,9,summaryContent[8]);
00263 reportSummaryMap_->setBinContent(1,10,summaryContent[9]);
00264
00265 }
00266
00267
00268 void HLTEventInfoClient::analyze(const Event& e, const EventSetup& context){
00269
00270 counterEvt_++;
00271 if (prescaleEvt_<1) return;
00272 if (prescaleEvt_>0 && counterEvt_%prescaleEvt_ != 0) return;
00273
00274 if(verbose_) std::cout << "HLTEventInfoClient::analyze" << std::endl;
00275
00276
00277 }
00278
00279
00280 void HLTEventInfoClient::endRun(const Run& r, const EventSetup& context){
00281 }
00282
00283
00284 void HLTEventInfoClient::endJob(){
00285 }
00286
00287
00288
00289 TH1F * HLTEventInfoClient::get1DHisto(std::string meName, DQMStore * dbi)
00290 {
00291
00292 MonitorElement * me_ = dbi->get(meName);
00293
00294 if (!me_) {
00295 if(verbose_) std::cout << "ME NOT FOUND." << std::endl;
00296 return NULL;
00297 }
00298
00299 return me_->getTH1F();
00300 }
00301
00302 TH2F * HLTEventInfoClient::get2DHisto(std::string meName, DQMStore * dbi)
00303 {
00304
00305
00306 MonitorElement * me_ = dbi->get(meName);
00307
00308 if (!me_) {
00309 if(verbose_) std::cout << "ME NOT FOUND." << std::endl;
00310 return NULL;
00311 }
00312
00313 return me_->getTH2F();
00314 }
00315
00316
00317
00318 TProfile2D * HLTEventInfoClient::get2DProfile(std::string meName, DQMStore * dbi)
00319 {
00320
00321
00322 MonitorElement * me_ = dbi->get(meName);
00323
00324 if (!me_) {
00325 if(verbose_) std::cout << "ME NOT FOUND." << std::endl;
00326 return NULL;
00327 }
00328
00329 return me_->getTProfile2D();
00330 }
00331
00332
00333 TProfile * HLTEventInfoClient::get1DProfile(std::string meName, DQMStore * dbi)
00334 {
00335
00336
00337 MonitorElement * me_ = dbi->get(meName);
00338
00339 if (!me_) {
00340 if(verbose_) std::cout << "ME NOT FOUND." << std::endl;
00341 return NULL;
00342 }
00343
00344 return me_->getTProfile();
00345 }
00346
00347
00348
00349
00350
00351
00352
00353