CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/DQM/TrigXMonitorClient/src/L1ScalersClient.cc

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