00001 #include "DQMOffline/Trigger/interface/EgHLTOfflineSummaryClient.h"
00002
00003
00004 #include "FWCore/Framework/interface/Run.h"
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007 #include "FWCore/ServiceRegistry/interface/Service.h"
00008
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010
00011 #include "DQMServices/Core/interface/DQMStore.h"
00012 #include "DQMServices/Core/interface/MonitorElement.h"
00013
00014 #include "DQMOffline/Trigger/interface/EgHLTTrigTools.h"
00015 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00016 #include <boost/algorithm/string.hpp>
00017
00018 EgHLTOfflineSummaryClient::EgHLTOfflineSummaryClient(const edm::ParameterSet& iConfig):
00019 egHLTSumHistName_("egHLTTrigSum"),isSetup_(false)
00020 {
00021 dirName_=iConfig.getParameter<std::string>("DQMDirName");
00022 dbe_ = edm::Service<DQMStore>().operator->();
00023 if (!dbe_) {
00024 edm::LogError("EgHLTOfflineSummaryClient") << "unable to get DQMStore service, no summary histograms will be produced";
00025 }else{
00026 if(iConfig.getUntrackedParameter<bool>("DQMStore", false)) {
00027 dbe_->setVerbose(0);
00028 }
00029 dbe_->setCurrentFolder(dirName_);
00030 }
00031
00032 eleHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("eleHLTFilterNames");
00033 phoHLTFilterNames_ = iConfig.getParameter<std::vector<std::string> >("phoHLTFilterNames");
00034 eleHLTFilterNamesForSumBit_ = iConfig.getParameter<std::vector<std::string> >("eleHLTFilterNamesForSumBit");
00035 phoHLTFilterNamesForSumBit_ = iConfig.getParameter<std::vector<std::string> >("phoHLTFilterNamesForSumBit");
00036
00037
00038 filterInactiveTriggers_ =iConfig.getParameter<bool>("filterInactiveTriggers");
00039 hltTag_ = iConfig.getParameter<std::string>("hltTag");
00040
00041 usePathNames_ = iConfig.getParameter<bool>("usePathNames");
00042
00043
00044
00045
00046
00047 fillQTestData_(iConfig,egHLTSumHistXBins_,"egHLTSumQTests");
00048 fillQTestData_(iConfig,eleQTestsForSumBit_,"egHLTEleQTestsForSumBit");
00049 fillQTestData_(iConfig,phoQTestsForSumBit_,"egHLTPhoQTestsForSumBit");
00050
00051
00052
00053 runClientEndLumiBlock_ = iConfig.getParameter<bool>("runClientEndLumiBlock");
00054 runClientEndRun_ = iConfig.getParameter<bool>("runClientEndRun");
00055 runClientEndJob_ = iConfig.getParameter<bool>("runClientEndJob");
00056
00057
00058
00059
00060
00061
00062
00063 }
00064
00065
00066 EgHLTOfflineSummaryClient::~EgHLTOfflineSummaryClient()
00067 {
00068
00069 }
00070
00071 void EgHLTOfflineSummaryClient::beginJob()
00072 {
00073
00074
00075 }
00076
00077 void EgHLTOfflineSummaryClient::endJob()
00078 {
00079 if(runClientEndJob_) runClient_();
00080 }
00081
00082 void EgHLTOfflineSummaryClient::beginRun(const edm::Run& run, const edm::EventSetup& c)
00083 {
00084 if(!isSetup_){
00085 bool changed;
00086 HLTConfigProvider hltConfig;
00087 hltConfig.init(run,c,hltTag_,changed);
00088 if(filterInactiveTriggers_){
00089 std::vector<std::string> activeFilters;
00090 std::vector<std::string> activeEleFilters;
00091 std::vector<std::string> activeEle2LegFilters;
00092 std::vector<std::string> activePhoFilters;
00093 std::vector<std::string> activePho2LegFilters;
00094
00095 egHLT::trigTools::getActiveFilters(hltConfig,activeFilters,activeEleFilters,activeEle2LegFilters,activePhoFilters,activePho2LegFilters);
00096
00097 egHLT::trigTools::filterInactiveTriggers(eleHLTFilterNames_,activeFilters);
00098 egHLT::trigTools::filterInactiveTriggers(phoHLTFilterNames_,activePhoFilters);
00099 egHLT::trigTools::filterInactiveTriggers(eleHLTFilterNamesForSumBit_,activeEleFilters);
00100 egHLT::trigTools::filterInactiveTriggers(phoHLTFilterNamesForSumBit_,activePhoFilters);
00101
00102 }
00103 getEgHLTFiltersToMon_(egHLTFiltersToMon_);
00104
00105 if(usePathNames_) egHLT::trigTools::translateFiltersToPathNames(hltConfig,egHLTFiltersToMon_,egHLTFiltersToMonPaths_);
00106 isSetup_=true;
00107 }
00108 }
00109
00110
00111 void EgHLTOfflineSummaryClient::endRun(const edm::Run& run, const edm::EventSetup& c)
00112 {
00113 if(runClientEndRun_) runClient_();
00114 }
00115
00116
00117 void EgHLTOfflineSummaryClient::analyze(const edm::Event& iEvent,const edm::EventSetup& iSetup)
00118 {
00119
00120 }
00121
00122 void EgHLTOfflineSummaryClient::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,const edm::EventSetup& c)
00123 {
00124
00125 if(runClientEndLumiBlock_) runClient_();
00126 }
00127
00128 void EgHLTOfflineSummaryClient::runClient_()
00129 {
00130
00131 MonitorElement* egHLTSumME = getEgHLTSumHist_();
00132
00133 for(size_t filterNr=0;filterNr<egHLTFiltersToMon_.size();filterNr++){
00134 for(size_t xBinNr=0;xBinNr<egHLTSumHistXBins_.size();xBinNr++){
00135
00136 egHLTSumME->setBinContent(xBinNr+1,filterNr+1,
00137 getQTestResults_(egHLTFiltersToMon_[filterNr],egHLTSumHistXBins_[xBinNr].qTestPatterns));
00138 }
00139 }
00140
00141 MonitorElement* hltEleSumBit = dbe_->get("HLT/EventInfo/reportSummaryContents/HLT_Electron");
00142 MonitorElement* hltPhoSumBit = dbe_->get("HLT/EventInfo/reportSummaryContents/HLT_Photon");
00143 dbe_->setCurrentFolder("HLT/EventInfo/reportSummaryContents/");
00144 if(hltEleSumBit==NULL) hltEleSumBit = dbe_->bookFloat("HLT_Electron");
00145 if(hltPhoSumBit==NULL) hltPhoSumBit = dbe_->bookFloat("HLT_Photon");
00146
00147
00148 float eleSumBit=1.;
00149 for(size_t filterNr=0;filterNr<eleHLTFilterNamesForSumBit_.size() && eleSumBit==1;filterNr++){
00150 for(size_t testNr=0;testNr<eleQTestsForSumBit_.size() && eleSumBit==1;testNr++){
00151 if(getQTestResults_(eleHLTFilterNamesForSumBit_[filterNr],eleQTestsForSumBit_[testNr].qTestPatterns)==0) eleSumBit=0;
00152
00153 }
00154 }
00155 hltEleSumBit->Fill(eleSumBit);
00156
00157 float phoSumBit=1.;
00158 for(size_t filterNr=0;filterNr<phoHLTFilterNamesForSumBit_.size() && phoSumBit==1;filterNr++){
00159 for(size_t testNr=0;testNr<phoQTestsForSumBit_.size() && phoSumBit==1;testNr++){
00160 if(getQTestResults_(phoHLTFilterNamesForSumBit_[filterNr],phoQTestsForSumBit_[testNr].qTestPatterns)==0) phoSumBit=0;
00161 }
00162 }
00163 hltPhoSumBit->Fill(phoSumBit);
00164
00165
00166
00167 }
00168 void EgHLTOfflineSummaryClient::splitStringsToPairs_(const std::vector<std::string>& stringsToSplit,std::vector<std::pair<std::string,std::string> >& splitStrings)
00169 {
00170 splitStrings.clear();
00171 splitStrings.reserve(stringsToSplit.size());
00172 for(size_t stringNr=0;stringNr<stringsToSplit.size();stringNr++){
00173 std::vector<std::string> tempSplitStrings;
00174 boost::split(tempSplitStrings,stringsToSplit[stringNr],boost::is_any_of(std::string(":")));
00175 if(tempSplitStrings.size()==2){
00176 splitStrings.push_back(std::make_pair(tempSplitStrings[0],tempSplitStrings[1]));
00177 }else{
00178 edm::LogWarning("EgHLTOfflineSummaryClient") <<" Error : entry "<<stringsToSplit[stringNr]<<" is not of form A:B, ignoring (ie this quailty test isnt being included in the sumamry hist) ";
00179 }
00180 }
00181 }
00182
00183
00184
00185 MonitorElement* EgHLTOfflineSummaryClient::getEgHLTSumHist_()
00186 {
00187 MonitorElement* egHLTSumHist = dbe_->get(dirName_+"/"+egHLTSumHistName_);
00188 if(egHLTSumHist==NULL){
00189 TH2F* hist = new TH2F(egHLTSumHistName_.c_str(),"E/g HLT Offline Summary",egHLTSumHistXBins_.size(),0.,1.,egHLTFiltersToMon_.size(),0.,1.);
00190 for(size_t xBinNr=0;xBinNr<egHLTSumHistXBins_.size();xBinNr++){
00191 hist->GetXaxis()->SetBinLabel(xBinNr+1,egHLTSumHistXBins_[xBinNr].name.c_str());
00192 }
00193
00194 for(size_t yBinNr=0;yBinNr<egHLTFiltersToMon_.size();yBinNr++){
00195 if(usePathNames_ && egHLTFiltersToMonPaths_.size()==egHLTFiltersToMon_.size()){
00196 hist->GetYaxis()->SetBinLabel(yBinNr+1,egHLTFiltersToMonPaths_[yBinNr].c_str());
00197 }else{
00198 hist->GetYaxis()->SetBinLabel(yBinNr+1,egHLTFiltersToMon_[yBinNr].c_str());
00199 }
00200 }
00201 for(size_t xBinNr=0;xBinNr<egHLTSumHistXBins_.size();xBinNr++){
00202 for(size_t yBinNr=0;yBinNr<egHLTFiltersToMon_.size();yBinNr++){
00203 hist->SetBinContent(xBinNr+1,yBinNr+1,-2);
00204 }
00205 }
00206
00207 dbe_->setCurrentFolder(dirName_);
00208 egHLTSumHist = dbe_->book2D(egHLTSumHistName_,hist);
00209 }
00210 return egHLTSumHist;
00211
00212 }
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 void EgHLTOfflineSummaryClient::getEgHLTFiltersToMon_(std::vector<std::string>& filterNames)const
00224 {
00225 std::set<std::string> filterNameSet;
00226 for(size_t i=0;i<eleHLTFilterNames_.size();i++) filterNameSet.insert(eleHLTFilterNames_[i]);
00227 for(size_t i=0;i<phoHLTFilterNames_.size();i++) filterNameSet.insert(phoHLTFilterNames_[i]);
00228
00229
00230
00231 std::vector<std::string>(filterNameSet.begin(),filterNameSet.end()).swap(filterNames);
00232 }
00233
00234
00235
00236 int EgHLTOfflineSummaryClient::getQTestResults_(const std::string& filterName,const std::vector<std::string>& patterns)const
00237 {
00238 int nrFail =0;
00239 int nrQTests=0;
00240 for(size_t patternNr=0;patternNr<patterns.size();patternNr++){
00241 std::vector<MonitorElement*> monElems = dbe_->getMatchingContents(dirName_+"/"+filterName+patterns[patternNr]);
00242
00243 for(size_t monElemNr=0;monElemNr<monElems.size();monElemNr++){
00244
00245 std::vector<QReport*> qTests = monElems[monElemNr]->getQReports();
00246 nrQTests+=qTests.size();
00247
00248 if(monElems[monElemNr]->hasError()) nrFail++;
00249 }
00250 }
00251 if(nrQTests==0) return -1;
00252 else if(nrFail==0) return 1;
00253 else return 0;
00254 }
00255
00256
00257 void EgHLTOfflineSummaryClient::fillQTestData_(const edm::ParameterSet& iConfig,std::vector<SumHistBinData>& qTests,const std::string& label)
00258 {
00259 std::vector<edm::ParameterSet> qTestPara = iConfig.getParameter<std::vector<edm::ParameterSet> >(label);
00260 qTests.resize(qTestPara.size());
00261 for(size_t testNr=0;testNr<qTestPara.size();testNr++){
00262 qTests[testNr].name = qTestPara[testNr].getParameter<std::string>("name");
00263 qTests[testNr].qTestPatterns = qTestPara[testNr].getParameter<std::vector<std::string> >("qTestsToCheck");
00264 }
00265 }
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292