00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 #include <iostream>
00061
00062
00063
00064 #include "FWCore/Framework/interface/Event.h"
00065 #include "FWCore/Framework/interface/Run.h"
00066
00067 #include "FWCore/ServiceRegistry/interface/Service.h"
00068 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00069
00070 #include "FWCore/Framework/interface/LuminosityBlock.h"
00071 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00072
00073
00074 #include "DataFormats/Common/interface/TriggerResults.h"
00075 #include "DataFormats/Common/interface/HLTenums.h"
00076 #include "FWCore/Common/interface/TriggerNames.h"
00077
00078
00079 #include "DQM/TrigXMonitor/interface/HLTScalers.h"
00080 #include "DataFormats/Common/interface/Handle.h"
00081 #include "DQMServices/Core/interface/DQMStore.h"
00082 #include "DQMServices/Core/interface/MonitorElement.h"
00083
00084 using namespace edm;
00085
00086
00087
00088 HLTScalers::HLTScalers(const edm::ParameterSet &ps):
00089 folderName_(ps.getUntrackedParameter<std::string>("dqmFolder", "HLT/HLTScalers_EvF")),
00090 processname_(ps.getParameter<std::string>("processname")),
00091 pairPDPaths_(),
00092 trigResultsSource_(ps.getParameter<edm::InputTag>("triggerResults")),
00093 dbe_(0),
00094 scalersN_(0),
00095 scalersException_(0),
00096 hltCorrelations_(0),
00097 detailedScalers_(0),
00098 nProc_(0),
00099 nLumiBlock_(0),
00100 hltBx_(0),
00101 hltBxVsPath_(0),
00102 hltOverallScaler_(0),
00103 hltOverallScalerN_(0),
00104 diagnostic_(0),
00105 resetMe_(true),
00106 sentPaths_(false),
00107 monitorDaemon_(ps.getUntrackedParameter<bool>("MonitorDaemon", false)),
00108 nev_(0),
00109 nLumi_(0),
00110 currentRun_(-1)
00111 {
00112 LogDebug("HLTScalers") << "HLTScalers: constructor...." ;
00113
00114 dbe_ = Service<DQMStore>().operator->();
00115 if (dbe_ ) {
00116 dbe_->setVerbose(0);
00117 dbe_->setCurrentFolder(folderName_);
00118 }
00119 }
00120
00121
00122 void HLTScalers::beginJob(void)
00123 {
00124 LogDebug("HLTScalers") << "HLTScalers::beginJob()..." << std::endl;
00125
00126 if (dbe_) {
00127 std::string rawdir(folderName_ + "/raw");
00128 dbe_->setCurrentFolder(rawdir);
00129
00130 nProc_ = dbe_->bookInt("nProcessed");
00131 nLumiBlock_ = dbe_->bookInt("nLumiBlock");
00132 diagnostic_ = dbe_->book1D("hltMerge", "HLT merging diagnostic",
00133 1, 0.5, 1.5);
00134
00135
00136 hltOverallScaler_ = dbe_->book1D("hltOverallScaler", "HLT Overall Scaler",
00137 1, 0.5, 1.5);
00138 hltOverallScalerN_ = dbe_->book1D("hltOverallScalerN",
00139 "Reset HLT Overall Scaler", 1, 0.5, 1.5);
00140
00141
00142
00143 }
00144 }
00145
00146 void HLTScalers::analyze(const edm::Event &e, const edm::EventSetup &c)
00147 {
00148 nProc_->Fill(++nev_);
00149 diagnostic_->setBinContent(1,1);
00150
00151
00152 edm::Handle<TriggerResults> hltResults;
00153 bool b = e.getByLabel(trigResultsSource_, hltResults);
00154 if ( !b ) {
00155 edm::LogInfo("HLTScalers") << "getByLabel for TriggerResults failed"
00156 << " with label " << trigResultsSource_;
00157 return;
00158 }
00159
00160
00161 int npath = hltResults->size();
00162 unsigned int nPD = pairPDPaths_.size();
00163
00164
00165 if (resetMe_ ) {
00166 LogInfo("HLTScalers") << "analyze(): new run. dump path for this evt "
00167 << e.id() << ", \n"
00168 << *hltResults ;
00169
00170 if (not dbe_)
00171 return;
00172
00173
00174 int maxModules = 200;
00175
00176 std::string rawdir(folderName_ + "/raw");
00177 dbe_->setCurrentFolder(rawdir);
00178
00179 scalersPD_ = dbe_->book1D("pdScalers", "PD scalers (stream A)",
00180 nPD, -0.5, nPD-0.5);
00181 detailedScalers_ = dbe_->book2D("detailedHltScalers", "HLT Scalers",
00182 npath, -0.5, npath-0.5,
00183 maxModules, 0, maxModules-1);
00184 scalers_ = dbe_->book1D("hltScalers", "HLT scalers",
00185 npath, -0.5, npath-0.5);
00186 scalersN_ = dbe_->book1D("hltScalersN", "Reset HLT scalers",
00187 npath, -0.5, npath-0.5);
00188 scalersException_ = dbe_->book1D("hltExceptions", "HLT Exception scalers",
00189 npath, -0.5, npath-0.5);
00190 hltCorrelations_ = dbe_->book2D("hltCorrelations", "HLT Scalers",
00191 npath, -0.5, npath-0.5,
00192 npath, -0.5, npath-0.5);
00193
00194
00195 dbe_->setCurrentFolder(folderName_);
00196 hltBxVsPath_ = dbe_->book2D("hltBxVsPath", "HLT Accept vs Bunch Number",
00197 3600, -0.5, 3599.5,
00198 npath, -0.5, npath-0.5);
00199 hltBx_ = dbe_->book1D("hltBx", "Bx of HLT Accepted Events ",
00200 3600, -0.5, 3599.5);
00201
00202 resetMe_ = false;
00203 }
00204
00205 const edm::TriggerNames & trigNames = e.triggerNames(*hltResults);
00206
00207 if ( ! sentPaths_ ) {
00208 const edm::TriggerNames & names = e.triggerNames(*hltResults);
00209
00210
00211 int q = 0;
00212 for ( TriggerNames::Strings::const_iterator
00213 j = names.triggerNames().begin();
00214 j !=names.triggerNames().end(); ++j ) {
00215
00216 LogDebug("HLTScalers") << q << ": " << *j ;
00217 ++q;
00218 scalers_->getTH1()->GetXaxis()->SetBinLabel(q, j->c_str());
00219 }
00220
00221 for (unsigned int i = 0; i < nPD; i++) {
00222 LogDebug("HLTScalers") << i << ": " << pairPDPaths_[i].first << std::endl ;
00223 scalersPD_->getTH1()->GetXaxis()->SetBinLabel(i+1, pairPDPaths_[i].first.c_str());
00224 }
00225
00226 sentPaths_ = true;
00227 }
00228
00229 bool accept = false;
00230 int bx = e.bunchCrossing();
00231 for ( int i = 0; i < npath; ++i ) {
00232
00233
00234 for ( unsigned int j = 0; j < hltResults->index(i); ++j ) {
00235 detailedScalers_->Fill(i,j);
00236 }
00237 if ( hltResults->state(i) == hlt::Pass) {
00238 scalers_->Fill(i);
00239 scalersN_->Fill(i);
00240 hltBxVsPath_->Fill(bx, i);
00241 accept = true;
00242 for ( int j = i + 1; j < npath; ++j ) {
00243 if ( hltResults->state(j) == hlt::Pass) {
00244 hltCorrelations_->Fill(i,j);
00245 hltCorrelations_->Fill(j,i);
00246 }
00247 }
00248 }
00249 else if ( hltResults->state(i) == hlt::Exception) {
00250 scalersException_->Fill(i);
00251 }
00252 }
00253 if ( accept ) {
00254 hltOverallScaler_->Fill(1.0);
00255 hltOverallScalerN_->Fill(1.0);
00256 hltBx_->Fill(int(bx));
00257 }
00258
00259 bool anyGroupPassed = false;
00260 for (unsigned int mi = 0; mi < pairPDPaths_.size(); mi++) {
00261
00262 bool groupPassed = false;
00263
00264 for (unsigned int i = 0; i < pairPDPaths_[mi].second.size(); i++)
00265 {
00266
00267
00268 std::string hltPathName = pairPDPaths_[mi].second[i];
00269
00270
00271
00272 unsigned int pathByIndex = trigNames.triggerIndex(pairPDPaths_[mi].second[i]);
00273 if(pathByIndex >= hltResults->size() ) continue;
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 if(hltResults->accept(pathByIndex)) {
00284 groupPassed = true;
00285 break;
00286 }
00287
00288 }
00289
00290 if(groupPassed) {
00291 scalersPD_->Fill(mi);
00292 anyGroupPassed = true;
00293 }
00294
00295 }
00296
00297 if(anyGroupPassed) scalersPD_->Fill(pairPDPaths_.size()-1);
00298 }
00299
00300 void HLTScalers::beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
00301 const edm::EventSetup& c)
00302 {
00303 LogDebug("HLTScalers") << "Start of luminosity block." ;
00304
00305 if ( scalersN_ )
00306 scalersN_->Reset();
00307 if ( hltOverallScalerN_ )
00308 hltOverallScalerN_->Reset();
00309 }
00310
00311
00312 void HLTScalers::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
00313 const edm::EventSetup& c)
00314 {
00315
00316
00317 nLumiBlock_->Fill(lumiSeg.id().luminosityBlock());
00318
00319 LogDebug("HLTScalers") << "End of luminosity block." ;
00320
00321 }
00322
00323
00325 void HLTScalers::beginRun(const edm::Run& run, const edm::EventSetup& c)
00326 {
00327 LogDebug("HLTScalers") << "HLTScalers::beginRun, run "
00328 << run.id();
00329 if ( currentRun_ != int(run.id().run()) ) {
00330 resetMe_ = true;
00331 currentRun_ = run.id().run();
00332 }
00333
00334
00335 bool changed=false;
00336
00337
00338 pairPDPaths_.clear();
00339
00340 if (not hltConfig_.init(run, c, processname_, changed)) {
00341 edm::LogError("TrigXMonitor") << "HLTConfigProvider failed to initialize.";
00342 } else {
00343
00344
00345
00346
00347
00348 if (hltConfig_.streamIndex("A")<hltConfig_.streamNames().size()) {
00349
00350
00351 const std::vector<std::string> & PD = hltConfig_.streamContent("A") ;
00352
00353 for (unsigned int i = 0; i < PD.size(); i++) {
00354
00355 const std::vector<std::string> & datasetPaths = hltConfig_.datasetContent(PD[i]);
00356 pairPDPaths_.push_back(make_pair(PD[i], datasetPaths));
00357
00358 }
00359
00360
00361 pairPDPaths_.push_back(make_pair("A", PD));
00362
00363 } else {
00364
00365 LogDebug("HLTScalers") << "HLTScalers::beginRun, steamm A not in the HLT menu ";
00366
00367 }
00368
00369 }
00370 }
00371
00373 void HLTScalers::endRun(const edm::Run& run, const edm::EventSetup& c)
00374 {
00375 LogDebug("HLTScalers") << "HLTScalers::endRun , run "
00376 << run.id();
00377 if ( currentRun_ != int(run.id().run()) ) {
00378 resetMe_ = true;
00379 currentRun_ = run.id().run();
00380 }
00381 }