CMS 3D CMS Logo

HLTScalers.cc

Go to the documentation of this file.
00001 // $Id: HLTScalers.cc,v 1.16 2008/09/03 13:59:06 wittich Exp $
00002 // 
00003 // $Log: HLTScalers.cc,v $
00004 // Revision 1.16  2008/09/03 13:59:06  wittich
00005 // make HLT DQM path configurable via python parameter,
00006 // which defaults to HLT/HLTScalers_EvF
00007 //
00008 // Revision 1.15  2008/09/03 02:13:47  wittich
00009 // - bug fix in L1Scalers
00010 // - configurable dqm directory in L1SCalers
00011 // - other minor tweaks in HLTScalers
00012 //
00013 // Revision 1.14  2008/09/02 02:37:22  wittich
00014 // - split L1 code from HLTScalers into L1Scalers
00015 // - update cfi file accordingly
00016 // - make sure to cd to correct directory before booking ME's
00017 //
00018 // Revision 1.13  2008/08/24 16:34:57  wittich
00019 // - rate calculation cleanups
00020 // - fix error logging with LogDebug
00021 // - report the actual lumi segment number that we think it might be
00022 //
00023 
00024 #include <iostream>
00025 
00026 
00027 // FW
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/Run.h"
00030 
00031 #include "FWCore/ServiceRegistry/interface/Service.h"
00032 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00033 
00034 #include "FWCore/Framework/interface/LuminosityBlock.h"
00035 
00036 // HLT
00037 #include "DataFormats/Common/interface/TriggerResults.h"
00038 #include "DataFormats/Common/interface/HLTenums.h"
00039 #include "FWCore/Framework/interface/TriggerNames.h"
00040 
00041 
00042 #include "DQM/TrigXMonitor/interface/HLTScalers.h"
00043 #include "DataFormats/Common/interface/Handle.h"
00044 #include "DQMServices/Core/interface/DQMStore.h"
00045 #include "DQMServices/Core/interface/MonitorElement.h"
00046 
00047 using namespace edm;
00048 
00049 
00050 
00051 HLTScalers::HLTScalers(const edm::ParameterSet &ps):
00052   dbe_(0),
00053   scalersException_(0),
00054   hltCorrelations_(0),
00055   detailedScalers_(0), 
00056   folderName_( ps.getUntrackedParameter< std::string>("dqmFolder", 
00057                                           std::string("HLT/HLTScalers_EvF"))),
00058   nProc_(0),
00059   nLumiBlock_(0),
00060   trigResultsSource_( ps.getParameter< edm::InputTag >("triggerResults")),
00061   resetMe_(true),
00062   monitorDaemon_(ps.getUntrackedParameter<bool>("MonitorDaemon", false)),
00063   nev_(0), 
00064   nLumi_(0),
00065   currentRun_(-1)
00066 {
00067 
00068 
00069 
00070   LogDebug("Status") << "HLTScalers: constructor...." ;
00071 
00072   dbe_ = Service<DQMStore>().operator->();
00073   dbe_->setVerbose(0);
00074   if (dbe_ ) {
00075     dbe_->setCurrentFolder(folderName_);
00076   }
00077   
00078 
00079 }
00080 
00081 
00082 
00083 void HLTScalers::beginJob(const edm::EventSetup& c)
00084 {
00085   LogDebug("Status") << "HLTScalers::beginJob()..." << std::endl;
00086 
00087   if (dbe_) {
00088     dbe_->setCurrentFolder(folderName_);
00089 
00090 
00091     nProc_ = dbe_->bookInt("nProcessed");
00092     nLumiBlock_ = dbe_->bookInt("nLumiBlock");
00093 
00094     // other ME's are now found on the first event of the new run, 
00095     // when we know more about the HLT configuration.
00096   
00097   }
00098   return;
00099 }
00100 
00101 void HLTScalers::analyze(const edm::Event &e, const edm::EventSetup &c)
00102 {
00103   nProc_->Fill(++nev_);
00104 
00105   edm::Handle<TriggerResults> hltResults;
00106   bool b = e.getByLabel(trigResultsSource_, hltResults);
00107   if ( !b ) {
00108     edm::LogInfo("Product") << "getByLabel for TriggerResults failed"
00109                            << " with label " << trigResultsSource_;
00110     return;
00111   }
00112   TriggerNames names(*hltResults);
00113   
00114   
00115   int npath = hltResults->size();
00116 
00117   // on the first event of a new run we book new ME's
00118   if (resetMe_ ) {
00119     LogInfo("Parameter") << "analyze(): new run. dump path for this evt " 
00120                          << e.id() << ", \n"
00121                          << *hltResults ;
00122     // need to get maxModules dynamically
00123     int maxModules = 200;
00124     //int npaths=hltResults->size();
00125 
00126     dbe_->setCurrentFolder(folderName_);
00127 
00128 
00129     detailedScalers_ = dbe_->book2D("detailedHltScalers", "HLT Scalers", 
00130                                     npath, -0.5, npath-0.5,
00131                                     maxModules, 0, maxModules-1);
00132     scalers_ = dbe_->book1D("hltScalers", "HLT scalers",
00133                             npath, -0.5, npath-0.5);
00134   
00135 
00136     scalersException_ = dbe_->book1D("hltExceptions", "HLT Exception scalers",
00137                             npath, -0.5, npath-0.5);
00138 
00139 
00140     hltCorrelations_ = dbe_->book2D("hltCorrelations", "HLT Scalers", 
00141                                 npath, -0.5, npath-0.5,
00142                                 npath, -0.5, npath-0.5);
00143 
00144     resetMe_ = false;
00145     // save path names in DQM-accessible format
00146     int q =0;
00147     for ( TriggerNames::Strings::const_iterator 
00148             j = names.triggerNames().begin();
00149           j !=names.triggerNames().end(); ++j ) {
00150       
00151       LogDebug("Parameter") << q << ": " << *j ;
00152       char pname[256];
00153       snprintf(pname, 256, "path%03d", q);
00154       ++q;
00155       MonitorElement *e = dbe_->bookString(pname, *j);
00156       hltPathNames_.push_back(e);  // I don't ever use these....
00157     }
00158   } // end resetme_ - pseudo-end-run record
00159   
00160 
00161 
00162   for ( int i = 0; i < npath; ++i ) {
00163     // state returns 0 on ready, 1 on accept, 2 on fail, 3 on exception.
00164     // these are defined in HLTEnums.h
00165     for ( unsigned int j = 0; j < hltResults->index(i); ++j ) {
00166       detailedScalers_->Fill(i,j);
00167     }
00168     if ( hltResults->state(i) == hlt::Pass) {
00169       scalers_->Fill(i);
00170       for ( int j = i + 1; j < npath; ++j ) {
00171         if ( hltResults->state(j) == hlt::Pass) {
00172           hltCorrelations_->Fill(i,j); // fill 
00173           hltCorrelations_->Fill(j,i);
00174         }
00175       }
00176     }
00177     else if ( hltResults->state(i) == hlt::Exception) {
00178       scalersException_->Fill(i);
00179     }
00180   }
00181   
00182 }
00183 
00184 
00185 void HLTScalers::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg, 
00186                                     const edm::EventSetup& c)
00187 {
00188   // put this in as a first-pass for figuring out the rate
00189   // each lumi block is 93 seconds in length
00190   nLumiBlock_->Fill(lumiSeg.id().luminosityBlock());
00191  
00192   LogDebug("Status") << "End of luminosity block." ;
00193 
00194 }
00195 
00196 
00198 void HLTScalers::beginRun(const edm::Run& run, const edm::EventSetup& c)
00199 {
00200   LogDebug("Status") << "HLTScalers::beginRun, run "
00201                      << run.id();
00202   if ( currentRun_ != int(run.id().run()) ) {
00203     resetMe_ = true;
00204     currentRun_ = run.id().run();
00205   }
00206 }
00207 
00209 void HLTScalers::endRun(const edm::Run& run, const edm::EventSetup& c)
00210 {
00211   LogDebug("Status") << "HLTScalers::endRun , run "
00212                      << run.id();
00213   if ( currentRun_ != int(run.id().run()) ) {
00214     resetMe_ = true;
00215     currentRun_ = run.id().run();
00216   }
00217 }

Generated on Tue Jun 9 17:33:43 2009 for CMSSW by  doxygen 1.5.4