00001 #include <cassert>
00002 #include <sstream>
00003
00004 #include "DQM/TrigXMonitorClient/interface/L1ScalersClient.h"
00005
00006 #include "FWCore/ServiceRegistry/interface/Service.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include "FWCore/Framework/interface/LuminosityBlock.h"
00009
00010
00011 #include "DQMServices/Core/interface/DQMStore.h"
00012 #include "DQMServices/Core/interface/MonitorElement.h"
00013
00014
00015 using edm::LogInfo;
00016 using edm::LogWarning;
00017
00018 #define SECS_PER_LUMI_SECTION 93.3
00019 const int kPerHisto = 20;
00020 const int kNumAlgoHistos = MAX_ALGOS/kPerHisto;
00021 const int kNumTTHistos = MAX_TT/kPerHisto;
00022
00023
00025 L1ScalersClient::L1ScalersClient(const edm::ParameterSet& ps):
00026 dbe_(0),
00027 nLumi_(0),
00028 l1AlgoCurrentRate_(0),
00029 l1TechTrigCurrentRate_(0),
00030 selected_(0),
00031 bxSelected_(0),
00032 algoSelected_(ps.getUntrackedParameter<std::vector<int> >("algoMonitorBits")),
00033 techSelected_(ps.getUntrackedParameter<std::vector<int> >("techMonitorBits")),
00034 folderName_(ps.getUntrackedParameter<std::string>("dqmFolder", "L1T/L1Scalers_EvF")),
00035 currentLumiBlockNumber_(0),
00036 first_algo(true),
00037 first_tt(true)
00038 {
00039 LogDebug("Status") << "constructor" ;
00040
00041 dbe_ = edm::Service<DQMStore>().operator->();
00042 assert(dbe_ != 0);
00043 dbe_->setCurrentFolder(folderName_);
00044
00045 l1AlgoCurrentRate_ = dbe_->book1D("algo_cur_rate",
00046 "current lumi section rate per Algo Bits",
00047 MAX_ALGOS, -0.5, MAX_ALGOS-0.5);
00048
00049 l1TechTrigCurrentRate_ = dbe_->book1D("tt_cur_rate",
00050 "current lumi section rate per Tech. Trig.s",
00051 MAX_TT, -0.5, MAX_TT-0.5);
00052
00053 numSelected_ = algoSelected_.size() + techSelected_.size();
00054 selected_ = dbe_->book1D("l1BitsSel", "Selected L1 Algorithm"
00055 " and tech Bits", numSelected_,
00056 -0.5, numSelected_-0.5);
00057 bxSelected_ = dbe_->book2D("l1BitsBxSel",
00058 "Selected L1 Algorithm Bits vs Bx",
00059 3600, -0.5, 3599.5,
00060 numSelected_, -0.5, numSelected_-0.5);
00061 int j = 1;
00062 for ( unsigned int i = 0; i < algoSelected_.size(); ++i ) {
00063 char title[256];
00064 snprintf(title, 256, "Algo %d", algoSelected_[i]);
00065 selected_->setBinLabel(j, title);
00066 bxSelected_->setBinLabel(j, title, 2);
00067 ++j;
00068 }
00069 for ( unsigned int i = 0; i < techSelected_.size(); ++i ) {
00070 char title[256];
00071 snprintf(title, 256, "Tech %d", techSelected_[i]);
00072 selected_->setBinLabel(j, title);
00073 bxSelected_->setBinLabel(j, title, 2);
00074 ++j;
00075 }
00076
00077
00078
00079 totalAlgoRate_ = dbe_->book1D("totAlgoRate", "Total Algo Rate" , MAX_LUMI_SEG,
00080 -0.5, MAX_LUMI_SEG-0.5);
00081 totalTtRate_ = dbe_->book1D("totTtRate", "Total Tech. Trig Rate" , MAX_LUMI_SEG,
00082 -0.5, MAX_LUMI_SEG-0.5);
00083
00084 totAlgoPrevCount=0UL;
00085 totTtPrevCount=0UL;
00086 for (int i = 0; i < MAX_ALGOS; ++i ) {
00087 l1AlgoScalerCounters_[i] = 0UL;
00088 l1AlgoRateHistories_[i] = 0;
00089 char name[256]; snprintf(name, 256, "rate_algobit%03d", i);
00090 LogDebug("Parameter") << "name " << i << " is " << name ;
00091 l1AlgoRateHistories_[i] = dbe_->book1D(name, name, MAX_LUMI_SEG,
00092 -0.5, MAX_LUMI_SEG-0.5);
00093 }
00094
00095
00096 for (int i = 0; i < MAX_TT; ++i ) {
00097 l1TechTrigScalerCounters_[i] = 0UL;
00098 l1TechTrigRateHistories_[i] = 0;
00099 char name[256]; snprintf(name, 256, "rate_ttbit%03d", i);
00100 LogDebug("Parameter") << "name " << i << " is " << name ;
00101 l1TechTrigRateHistories_[i] = dbe_->book1D(name, name, MAX_LUMI_SEG,
00102 -0.5, MAX_LUMI_SEG-0.5);
00103 }
00104
00105
00106 char metitle1[40];
00107 char mename1[40];
00108 for( int k = 0; k < kNumAlgoHistos; k++ ) {
00109 int npath_low = kPerHisto*k;
00110 int npath_high = kPerHisto*(k+1)-1;
00111 snprintf(mename1, 40, "L1AlgoBits_%0d", k);
00112 snprintf(metitle1, 40, "L1 rates - Algo Bits %d to %d", npath_low,
00113 npath_high);
00114 l1AlgoCurrentRatePerAlgo_[k]= dbe_->book1D(mename1, metitle1, kPerHisto,
00115 -0.5 + npath_low, npath_high+0.5);
00116 }
00117
00118
00119 char metitle2[40];
00120 char mename2[40];
00121 for( int k = 0; k < kNumTTHistos; k++ ) {
00122 int npath_low = kPerHisto*k;
00123 int npath_high = kPerHisto*(k+1)-1;
00124 snprintf(mename2, 40, "L1TechBits_%0d", k);
00125 snprintf(metitle2, 40, "L1 rates - Tech. Trig. Bits %d to %d", npath_low,
00126 npath_high);
00127 l1TechTrigCurrentRatePerAlgo_[k]= dbe_->book1D(mename2, metitle2, kPerHisto,
00128 -0.5 + npath_low, npath_high+0.5);
00129 }
00130
00131 std::ostringstream params;
00132 params << "Algo: ";
00133 for ( unsigned int i = 0; i < algoSelected_.size(); ++i ) {
00134 params << algoSelected_[i] << " ";
00135 }
00136 params << ", Tech: ";
00137 for ( unsigned int i = 0; i < techSelected_.size(); ++i ) {
00138 params << techSelected_[i] << " ";
00139 }
00140 LogDebug("Parameter") << "L1 bits to monitor are " << params.str();
00141 }
00142
00143
00145 void L1ScalersClient::beginJob(const edm::EventSetup& c)
00146 {
00147 LogDebug("Status") << "beingJob" ;
00148 if (dbe_) {
00149 dbe_->setCurrentFolder(folderName_);
00150 }
00151 }
00152
00153
00155 void L1ScalersClient::beginRun(const edm::Run& run, const edm::EventSetup& c)
00156 {
00157 }
00158
00160 void L1ScalersClient::endRun(const edm::Run& run, const edm::EventSetup& c)
00161 {
00162 }
00163
00164
00167 void L1ScalersClient::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
00168 const edm::EventSetup& c)
00169 {
00170 nLumi_ = lumiSeg.id().luminosityBlock();
00171
00172
00173
00174 MonitorElement *algoScalers = dbe_->get(folderName_+std::string("/l1AlgoBits"));
00175 MonitorElement *ttScalers = dbe_->get(folderName_+std::string("/l1TechAlgoBits"));
00176
00177 if ( algoScalers == 0 || ttScalers ==0) {
00178 LogInfo("Status") << "cannot get l1 scalers histogram, bailing out.";
00179 return;
00180 }
00181
00182
00183 int nalgobits = algoScalers->getNbinsX();
00184 int nttbits = ttScalers->getNbinsX();
00185
00186 if ( nalgobits > MAX_ALGOS ) nalgobits = MAX_ALGOS;
00187 if ( nttbits > MAX_TT ) nttbits = MAX_TT;
00188
00189 LogDebug("Status") << "I see " << nalgobits << " algo paths. ";
00190 LogDebug("Status") << "I see " << nttbits << " tt paths. ";
00191
00192
00193 if ( first_algo) {
00194 for ( int i = 0; i < nalgobits; ++i ) {
00195 int whichHisto = i/kPerHisto;
00196 int whichBin = i%kPerHisto + 1;
00197 char pname[256];
00198 snprintf(pname, 256, "AlgoBit%03d", i);
00199 l1AlgoCurrentRatePerAlgo_[whichHisto]->setBinLabel(whichBin, pname);
00200 snprintf(pname, 256, "Rate - Algorithm Bit %03d", i);
00201 l1AlgoRateHistories_[i]->setTitle(pname);
00202 }
00203 first_algo = false;
00204 }
00205
00206
00207 if ( first_tt) {
00208 for ( int i = 0; i < nttbits; ++i ) {
00209 int whichHisto = i/kPerHisto;
00210 int whichBin = i%kPerHisto + 1;
00211 char pname[256];
00212 snprintf(pname, 256, "TechBit%03d", i);
00213 l1TechTrigCurrentRatePerAlgo_[whichHisto]->setBinLabel(whichBin, pname);
00214 snprintf(pname, 256, "Rate - Technical Bit %03d", i);
00215 l1TechTrigRateHistories_[i]->setTitle(pname);
00216 }
00217 first_tt = false;
00218 }
00219
00220 MonitorElement *nLumi = dbe_->get(folderName_+std::string("nLumiBlock"));
00221
00222 int testval = (nLumi!=0?nLumi->getIntValue():-1);
00223 LogDebug("Parameter") << "Lumi Block from DQM: "
00224 << testval
00225 << ", local is " << nLumi_;
00226
00227 int nL = (nLumi!=0?nLumi->getIntValue():nLumi_);
00228 if ( nL > MAX_LUMI_SEG ) {
00229 LogDebug("Status") << "Too many Lumi segments, "
00230 << nL << " is greater than MAX_LUMI_SEG,"
00231 << " wrapping to "
00232 << (nL%MAX_LUMI_SEG);
00233 nL = nL%MAX_LUMI_SEG;
00234 }
00235 float delta_t = (nL - currentLumiBlockNumber_)*SECS_PER_LUMI_SECTION;
00236 if ( delta_t < 0 ) {
00237 LogDebug("Status") << " time is negative ... " << delta_t;
00238 delta_t = -delta_t;
00239 }
00240 else if ( nL == currentLumiBlockNumber_ ) {
00241 LogInfo("Status") << "divide by zero: same lumi section 2x " << nL;
00242 return;
00243 }
00244
00245 int currSlot = 1;
00246 MonitorElement *algoBx = dbe_->get(folderName_+
00247 std::string("/l1AlgoBits_Vs_Bx"));
00248
00249 for ( int i = 1; i <= nalgobits; ++i ) {
00250 float current_count = algoScalers->getBinContent(i);
00251
00252 int bit = i -1;
00253 if ( std::find(algoSelected_.begin(), algoSelected_.end(),bit)
00254 != algoSelected_.end() ) {
00255 selected_->setBinContent(currSlot, current_count);
00256 if ( algoBx ) {
00257 for ( int j = 1; j <= 3600; ++j ) {
00258 bxSelected_->setBinContent(j, currSlot,
00259 algoBx->getBinContent(j, i));
00260 }
00261 }
00262 ++currSlot;
00263 }
00264
00265 float rate = (current_count-l1AlgoScalerCounters_[i-1])/delta_t;
00266 if ( rate > 1E-3 ) {
00267 LogDebug("Parameter") << "rate path " << i << " is " << rate;
00268 }
00269 l1AlgoCurrentRate_->setBinContent(i, rate);
00270 l1AlgoCurrentRatePerAlgo_[i/kPerHisto]->setBinContent(i%kPerHisto+1, rate);
00271
00272 l1AlgoScalerCounters_[i-1] = ulong(current_count);
00273 l1AlgoRateHistories_[i-1]->setBinContent(nL, rate);
00274 }
00275
00276 MonitorElement *techBx = dbe_->get(folderName_+std::string("/l1TechAlgoBits_Vs_Bx"));
00277
00278
00279 for ( int i = 1; i <= nttbits; ++i ) {
00280 float current_count = ttScalers->getBinContent(i);
00281
00282 int bit = i -1;
00283 if ( std::find(techSelected_.begin(), techSelected_.end(),bit)
00284 != techSelected_.end() ) {
00285 selected_->setBinContent(currSlot, current_count);
00286 if ( techBx ) {
00287 for ( int j = 1; j <= 3600; ++j ) {
00288 bxSelected_->setBinContent(j, currSlot,
00289 techBx->getBinContent(j, i));
00290 }
00291 }
00292 ++currSlot;
00293 }
00294
00295 float rate = (current_count-l1TechTrigScalerCounters_[i-1])/delta_t;
00296 if ( rate > 1E-3 ) {
00297 LogDebug("Parameter") << "rate path " << i << " is " << rate;
00298 }
00299 l1TechTrigCurrentRate_->setBinContent(i, rate);
00300 l1TechTrigCurrentRatePerAlgo_[i/kPerHisto]->setBinContent(i%kPerHisto+1, rate);
00301
00302 l1TechTrigScalerCounters_[i-1] = ulong(current_count);
00303 l1TechTrigRateHistories_[i-1]->setBinContent(nL, rate);
00304 }
00305
00306
00307 MonitorElement *l1AlgoCounter = dbe_->get(folderName_+std::string("/l1AlgoCounter"));
00308 MonitorElement *l1TtCounter = dbe_->get(folderName_+std::string("/l1TtCounter"));
00309 if ( l1AlgoCounter != 0 && l1TtCounter != 0 ) {
00310 float totAlgoCount = l1AlgoCounter->getIntValue();
00311 float totTtCount = l1TtCounter->getIntValue();
00312 float totAlgRate = (totAlgoCount - totAlgoPrevCount)/delta_t;
00313 float totTtRate = (totTtCount - totTtPrevCount)/delta_t;
00314 totalAlgoRate_->setBinContent(nL, totAlgRate);
00315 totAlgoPrevCount = totAlgoCount;
00316 totalTtRate_->setBinContent(nL, totTtRate);
00317 totTtPrevCount = totTtCount;
00318 }
00319
00320
00321 currentLumiBlockNumber_ = nL;
00322
00323 }
00324
00325
00326 void L1ScalersClient::analyze(const edm::Event& e, const edm::EventSetup& c)
00327 {
00328 }