CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DQM/HcalMonitorTasks/src/HcalTrigPrimMonitor.cc

Go to the documentation of this file.
00001 #include "DQM/HcalMonitorTasks/interface/HcalTrigPrimMonitor.h"
00002 #include "FWCore/Framework/interface/LuminosityBlock.h"
00003 
00004 HcalTrigPrimMonitor::HcalTrigPrimMonitor (const edm::ParameterSet& ps) :
00005    dataLabel_(ps.getParameter<edm::InputTag>("dataLabel")),
00006    emulLabel_(ps.getParameter<edm::InputTag>("emulLabel")),
00007    ZSAlarmThreshold_(ps.getParameter< std::vector<int> >("ZSAlarmThreshold"))
00008 {
00009    Online_                = ps.getUntrackedParameter<bool>("online",false);
00010    mergeRuns_             = ps.getUntrackedParameter<bool>("mergeRuns",false);
00011    enableCleanup_         = ps.getUntrackedParameter<bool>("enableCleanup",false);
00012    debug_                 = ps.getUntrackedParameter<int>("debug",false);
00013    prefixME_              = ps.getUntrackedParameter<std::string>("subSystemFolder","Hcal/");
00014    if (prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
00015     prefixME_.append("/");
00016    subdir_                = ps.getUntrackedParameter<std::string>("TaskFolder","TrigPrimMonitor_Hcal"); 
00017    if (subdir_.size()>0 && subdir_.substr(subdir_.size()-1,subdir_.size())!="/")
00018     subdir_.append("/");
00019    subdir_=prefixME_+subdir_;
00020    AllowedCalibTypes_     = ps.getUntrackedParameter<std::vector<int> > ("AllowedCalibTypes");
00021    skipOutOfOrderLS_      = ps.getUntrackedParameter<bool>("skipOutOfOrderLS",true);
00022    NLumiBlocks_           = ps.getUntrackedParameter<int>("NLumiBlocks",4000);
00023    makeDiagnostics_       = ps.getUntrackedParameter<bool>("makeDiagnostics",false);
00024 
00025 }
00026 
00027 
00028 HcalTrigPrimMonitor::~HcalTrigPrimMonitor () {
00029 }
00030 
00031 
00032 void
00033 HcalTrigPrimMonitor::reset () {
00034 }
00035 
00036 
00037 void
00038 HcalTrigPrimMonitor::setup() {
00039    HcalBaseDQMonitor::setup();
00040    
00041    if (dbe_ == 0)
00042       return;
00043 
00044    dbe_->setCurrentFolder(subdir_ + "TP Occupancy");
00045    TPOccupancyEta_ = dbe_->book1D("TPOccupancyVsEta", "TPOccupancyVsEta", 65, -32.5, 32.5);
00046    TPOccupancyPhi_ = dbe_->book1D("TPOccupancyVsPhi", "TPOccupancyVsPhi", 72, 0.5, 72.5);
00047    TPOccupancyPhiHFP_ = dbe_->book1D("TPOccupancyHFPVsPhi", "TPOccupancyHFPVsPhi", 72, 0.5, 72.5);
00048    TPOccupancyPhiHFM_ = dbe_->book1D("TPOccupancyHFMVsPhi", "TPOccupancyHFMVsPhi", 72, 0.5, 72.5);
00049    TPOccupancy_ = create_map(subdir_ + "TP Occupancy", "TPOccupancy");
00050 
00051    for (int isZS = 0; isZS <= 1; ++isZS) {
00052 
00053       std::string folder(subdir_);
00054       std::string zsname="_ZS";
00055       if (isZS == 0)
00056         {
00057           folder += "noZS/";
00058           zsname="_noZS";
00059         }
00060 
00061       std::string problem_folder(folder);
00062       problem_folder += "Problem TPs/";
00063       
00064       good_tps[isZS] = create_map(folder, "Good TPs"+zsname);
00065       bad_tps[isZS] = create_map(folder, "Bad TPs"+zsname);
00066 
00067       errorflag[isZS] = create_errorflag(folder, "Error Flag"+zsname);
00068       problem_map[isZS][kMismatchedEt] = create_map(problem_folder, "Mismatched Et"+zsname);
00069       problem_map[isZS][kMismatchedFG] = create_map(problem_folder, "Mismatched FG"+zsname);
00070       problem_map[isZS][kMissingData] = create_map(problem_folder, "Missing Data"+zsname);
00071       problem_map[isZS][kMissingEmul] = create_map(problem_folder, "Missing Emul"+zsname);
00072 
00073       for (int isHF = 0; isHF <= 1; ++isHF) {
00074          std::string subdet = (isHF == 0 ? "HBHE " : "HF ");
00075          tp_corr[isZS][isHF] = create_tp_correlation(folder, subdet + "TP Correlation"+zsname);
00076          fg_corr[isZS][isHF] = create_fg_correlation(folder, subdet + "FG Correlation"+zsname);
00077 
00078          problem_et[isZS][isHF][kMismatchedFG]
00079             = create_et_histogram(problem_folder + "TP Values/", subdet + "Mismatched FG"+zsname);
00080 
00081          problem_et[isZS][isHF][kMissingData]
00082             = create_et_histogram(problem_folder + "TP Values/", subdet + "Missing Data"+zsname);
00083 
00084          problem_et[isZS][isHF][kMissingEmul]
00085             = create_et_histogram(problem_folder + "TP Values/", subdet + "Missing Emul"+zsname);
00086       }//isHF
00087    }//isZS
00088 
00089    // Number of bad cells vs. luminosity block
00090    ProblemsVsLB = dbe_->bookProfile(
00091          "TotalBadTPs_HCAL_vs_LS",
00092          "Total Number of Bad HCAL TPs vs lumi section",
00093          NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00094 
00095    ProblemsVsLB_HB = dbe_->bookProfile(
00096          "TotalBadTPs_HB_vs_LS",
00097          "Total Number of Bad HB TPs vs lumi section",
00098          NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,3000);
00099 
00100    ProblemsVsLB_HE = dbe_->bookProfile(
00101          "TotalBadTPs_HE_vs_LS",
00102          "Total Number of Bad HE TPs vs lumi section",
00103          NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,3000);
00104 
00105    ProblemsVsLB_HF = dbe_->bookProfile(
00106          "TotalBadTPs_HF_vs_LS",
00107          "Total Number of Bad HF TPs vs lumi section",
00108          NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,3000);
00109 
00110    // No TPs for HO, DO NOT fill this histogram
00111    ProblemsVsLB_HO = dbe_->bookProfile(
00112          "TotalBadTPs_HO_vs_LS",
00113          "Total Number of Bad HO TPs vs lumi section",
00114          NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,3000);
00115 
00116    ProblemsVsLB->getTProfile()->SetMarkerStyle(20);
00117    ProblemsVsLB_HB->getTProfile()->SetMarkerStyle(20);
00118    ProblemsVsLB_HE->getTProfile()->SetMarkerStyle(20);
00119    ProblemsVsLB_HO->getTProfile()->SetMarkerStyle(20);
00120    ProblemsVsLB_HF->getTProfile()->SetMarkerStyle(20);
00121 }
00122 
00123 void HcalTrigPrimMonitor::beginRun(const edm::Run& run, const edm::EventSetup& c)
00124 {
00125   HcalBaseDQMonitor::beginRun(run,c);
00126   if (mergeRuns_ && tevt_>0) return; // don't reset counters if merging runs
00127   if (tevt_==0) this->setup(); // create all histograms; not necessary if merging runs together
00128   if (mergeRuns_==false) this->reset(); // call reset at start of all runs
00129 } // void HcalTrigPrimMonitor::beginRun()
00130 
00131 void
00132 HcalTrigPrimMonitor::analyze (edm::Event const &e, edm::EventSetup const &s) {
00133    if (!IsAllowedCalibType()) return;
00134    if (LumiInOrder(e.luminosityBlock())==false) return;
00135 
00136    edm::Handle<HcalTrigPrimDigiCollection> data_tp_col;
00137    if (!e.getByLabel(dataLabel_, data_tp_col)) {
00138       edm::LogWarning("HcalTrigPrimMonitor")<< dataLabel_<< " data TP not available";
00139       return;
00140    }
00141 
00142    edm::Handle<HcalTrigPrimDigiCollection> emul_tp_col;
00143    if (!e.getByLabel(emulLabel_, emul_tp_col)) {
00144       edm::LogWarning("HcalTrigPrimMonitor")<< emulLabel_<< " emul TP not available";
00145       return;
00146    }
00147 
00148    HcalBaseDQMonitor::analyze(e,s); // base class increments ievt_, etc. counters
00149    processEvent(data_tp_col, emul_tp_col);
00150 }
00151 
00152 
00153 void
00154 HcalTrigPrimMonitor::processEvent (
00155       const edm::Handle <HcalTrigPrimDigiCollection>& data_tp_col,
00156       const edm::Handle <HcalTrigPrimDigiCollection>& emul_tp_col) {
00157 
00158    if(dbe_ == 0) 
00159       return;
00160 
00161    std::vector<int> errorflag_per_event[2][2];
00162    for (int isZS = 0; isZS <= 1; ++isZS) {
00163       for (int isHF = 0; isHF <= 1; ++isHF) {
00164          errorflag_per_event[isZS][isHF] = std::vector<int>(kNErrorFlag, 0);
00165       }//for isHF
00166    }//for isZS
00167 
00168    good_tps[0]->setBinContent(-1,-1,ievt_);
00169    bad_tps[0]->setBinContent(-1,-1,ievt_);
00170    good_tps[1]->setBinContent(-1,-1,ievt_);
00171    bad_tps[1]->setBinContent(-1,-1,ievt_);
00172 
00173    for (HcalTrigPrimDigiCollection::const_iterator data_tp = data_tp_col->begin();
00174                                                   data_tp != data_tp_col->end();
00175                                                   ++data_tp) {
00176       int ieta = data_tp->id().ieta();
00177       int iphi = data_tp->id().iphi();
00178       int isHF = data_tp->id().ietaAbs() >= 29 ? 1 : 0;
00179 
00180 
00181       //
00182       if (data_tp->SOI_compressedEt() > 0) {
00183          TPOccupancy_->Fill(ieta, iphi);
00184          TPOccupancyEta_->Fill(ieta);
00185          TPOccupancyPhi_->Fill(iphi);
00186 
00187          if (isHF) {
00188             if (ieta > 0) {
00189                TPOccupancyPhiHFP_->Fill(iphi);
00190             }
00191             else {
00192                TPOccupancyPhiHFM_->Fill(iphi);
00193             }
00194          }
00195       }
00196 
00197       //check missing from emulator
00198       HcalTrigPrimDigiCollection::const_iterator emul_tp = emul_tp_col->find(data_tp->id());
00199       if (emul_tp == emul_tp_col->end()) {
00200          bool pass_ZS = true;
00201 
00202          for (int i=0; i<data_tp->size(); ++i) {
00203             int dataEt(data_tp->sample(i).compressedEt());
00204             problem_et[0][isHF][kMissingEmul]->Fill(dataEt);
00205 
00206             if (dataEt > ZSAlarmThreshold_[abs(ieta)]) {
00207                problem_et[1][isHF][kMissingEmul]->Fill(dataEt);
00208                pass_ZS = false;
00209             }
00210          }//for tp sample
00211 
00212          problem_map[0][kMissingEmul]->Fill(ieta, iphi);
00213          ++errorflag_per_event[0][isHF][kMissingEmul];
00214          bad_tps[0]->Fill(ieta, iphi);
00215 
00216          if (!pass_ZS) {
00217             problem_map[1][kMissingEmul]->Fill(ieta, iphi);
00218             ++errorflag_per_event[1][isHF][kMissingEmul];
00219             bad_tps[1]->Fill(ieta, iphi);
00220 
00221             // counts per LS
00222             if (abs(ieta) <= 16)
00223                ++nBad_TP_per_LS_HB_;
00224             else if(abs(ieta) <= 28)
00225                ++nBad_TP_per_LS_HE_;
00226             else
00227                ++nBad_TP_per_LS_HF_;
00228          }
00229       } //emul tp not found
00230       else {
00231          bool mismatchedEt_noZS = false;
00232          bool mismatchedEt_ZS = false;
00233          bool mismatchedFG_noZS = false;
00234          bool mismatchedFG_ZS = false;
00235 
00236          for (int i=0; i<data_tp->size(); ++i) {
00237             int dataEt(data_tp->sample(i).compressedEt());
00238             int dataFG(data_tp->sample(i).fineGrain());
00239             int emulEt(emul_tp->sample(i).compressedEt());
00240             int emulFG(emul_tp->sample(i).fineGrain());
00241 
00242             int diff = abs(dataEt - emulEt);
00243             bool fill_corr_ZS = true;
00244             
00245             if (diff == 0) {
00246                if (dataFG != emulFG) {
00247                   mismatchedFG_noZS = true;
00248                   problem_et[0][isHF][kMismatchedFG]->Fill(dataEt);
00249 
00250                   // exclude mismatched FG when HF TP < ZS_AlarmThreshold
00251                   if (isHF == 1 && dataEt <= ZSAlarmThreshold_.at(abs(ieta))) {
00252                      // Do not fill ZS correlation plots.
00253                      fill_corr_ZS = false;
00254                   }
00255                   else {
00256                      mismatchedFG_ZS = true;
00257                      problem_et[1][isHF][kMismatchedFG]->Fill(dataEt);
00258                   }
00259                } // matched et but not fg
00260             }
00261             else {
00262                mismatchedEt_noZS = true;
00263                if (diff > ZSAlarmThreshold_.at(abs(ieta))) {
00264                   mismatchedEt_ZS = true;
00265                   fill_corr_ZS = false;
00266                }
00267             } // mismatche et
00268 
00269             // Correlation plots
00270             tp_corr[0][isHF]->Fill(dataEt, emulEt);
00271             fg_corr[0][isHF]->Fill(dataFG, emulFG);
00272 
00273             if (fill_corr_ZS) {
00274                tp_corr[1][isHF]->Fill(dataEt, emulEt);
00275                fg_corr[1][isHF]->Fill(dataFG, emulFG);
00276             }
00277          }//for tp sample
00278 
00279          // Fill Problem Map and error counts
00280          if (mismatchedEt_noZS) {
00281             problem_map[0][kMismatchedEt]->Fill(ieta, iphi);
00282             ++errorflag_per_event[0][isHF][kMismatchedEt];
00283          }
00284          if (mismatchedEt_ZS) {
00285             problem_map[1][kMismatchedEt]->Fill(ieta, iphi);
00286             ++errorflag_per_event[1][isHF][kMismatchedEt];
00287          }
00288          if (mismatchedFG_noZS) {
00289             problem_map[0][kMismatchedFG]->Fill(ieta, iphi);
00290             ++errorflag_per_event[0][isHF][kMismatchedFG];
00291          }
00292          if (mismatchedFG_ZS) {
00293             problem_map[1][kMismatchedFG]->Fill(ieta, iphi);
00294             ++errorflag_per_event[1][isHF][kMismatchedFG];
00295          }
00296          if (mismatchedEt_noZS || mismatchedFG_noZS)
00297             bad_tps[0]->Fill(ieta, iphi);
00298          else
00299             good_tps[0]->Fill(ieta, iphi);
00300          if (mismatchedEt_ZS || mismatchedFG_ZS) {
00301             bad_tps[1]->Fill(ieta, iphi);
00302 
00303             // counts per LS
00304             if (abs(ieta) <= 16)
00305                ++nBad_TP_per_LS_HB_;
00306             else if(abs(ieta) <= 28)
00307                ++nBad_TP_per_LS_HE_;
00308             else
00309                ++nBad_TP_per_LS_HF_;
00310          }
00311          else
00312             good_tps[1]->Fill(ieta, iphi);
00313       }//emul tp found
00314    }//for data_tp_col
00315 
00316 
00317    //check missing from data
00318    for (HcalTrigPrimDigiCollection::const_iterator emul_tp = emul_tp_col->begin();
00319                                                    emul_tp != emul_tp_col->end();
00320                                                    ++emul_tp) {
00321       int ieta(emul_tp->id().ieta());
00322       int iphi(emul_tp->id().iphi());
00323       int isHF = emul_tp->id().ietaAbs() >= 29 ? 1 : 0;
00324 
00325       HcalTrigPrimDigiCollection::const_iterator data_tp = data_tp_col->find(emul_tp->id());
00326       if (data_tp == data_tp_col->end()) {
00327          bool pass_ZS = true;
00328 
00329          for (int i=0; i<emul_tp->size(); ++i) {
00330             int emulEt(emul_tp->sample(i).compressedEt());
00331             problem_et[0][isHF][kMissingData]->Fill(emulEt);
00332 
00333             if (emulEt > ZSAlarmThreshold_[abs(ieta)]) {
00334                problem_et[1][isHF][kMissingData]->Fill(emulEt);
00335                pass_ZS = false;
00336             }
00337          }//for tp sample
00338 
00339          problem_map[0][kMissingData]->Fill(ieta, iphi);
00340          ++errorflag_per_event[0][isHF][kMissingData];
00341          bad_tps[0]->Fill(ieta, iphi);
00342 
00343          if (!pass_ZS) {
00344             problem_map[1][kMissingData]->Fill(ieta, iphi);
00345             ++errorflag_per_event[1][isHF][kMissingData];
00346             bad_tps[1]->Fill(ieta, iphi);
00347 
00348             // counts per LS
00349             if (abs(ieta) <= 16)
00350                ++nBad_TP_per_LS_HB_;
00351             else if(abs(ieta) <= 28)
00352                ++nBad_TP_per_LS_HE_;
00353             else
00354                ++nBad_TP_per_LS_HF_;
00355          }
00356       } //data tp not found
00357    } //for emul_tp_col
00358 
00359    // Fill error flag per event
00360    for (int isZS = 0; isZS <= 1; ++isZS) {
00361       for (int isHF = 0; isHF <= 1; ++isHF) {
00362          for (int i=0; i<kNErrorFlag; ++i) {
00363             if (errorflag_per_event[isZS][isHF][i] > 0)
00364                errorflag[isZS]->Fill(i, isHF);
00365          }//for i
00366       }//for isHF
00367    }//for isZS
00368 }
00369 
00370 void
00371 HcalTrigPrimMonitor::cleanup() {
00372    if (!enableCleanup_) return;
00373    if (dbe_) {
00374       dbe_->setCurrentFolder(subdir_);
00375       dbe_->removeContents();
00376 
00377       dbe_->setCurrentFolder(subdir_ + "noZS/Problem TPs/TP Values");
00378       dbe_->removeContents();
00379       dbe_->setCurrentFolder(subdir_ + "noZS/Problem TPs");
00380       dbe_->removeContents();
00381       dbe_->setCurrentFolder(subdir_ + "noZS");
00382 
00383       dbe_->setCurrentFolder(subdir_ + "Problem TPs/TP Values");
00384       dbe_->removeContents();
00385       dbe_->setCurrentFolder(subdir_ + "Problem TPs");
00386       dbe_->removeContents();
00387    }
00388 }
00389 
00390 void HcalTrigPrimMonitor::endJob()
00391 {
00392   if (enableCleanup_) cleanup(); 
00393 }
00394 
00395 void HcalTrigPrimMonitor::beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& c) {
00396    if (LumiInOrder(lumiSeg.luminosityBlock())==false) return;
00397    HcalBaseDQMonitor::beginLuminosityBlock(lumiSeg,c);
00398    ProblemsCurrentLB->Reset();
00399    // Rest counter
00400    nBad_TP_per_LS_HB_ = 0;
00401    nBad_TP_per_LS_HE_ = 0;
00402    nBad_TP_per_LS_HF_ = 0;
00403 }
00404 
00405 void HcalTrigPrimMonitor::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& c) {
00406    if (LumiInOrder(lumiSeg.luminosityBlock())==false) return;
00407    // Fill histograms for this LS
00408    ProblemsVsLB_HB->Fill(currentLS, nBad_TP_per_LS_HB_);
00409    ProblemsVsLB_HE->Fill(currentLS, nBad_TP_per_LS_HE_);
00410    ProblemsVsLB_HF->Fill(currentLS, nBad_TP_per_LS_HF_);
00411    ProblemsVsLB->Fill(currentLS, nBad_TP_per_LS_HB_ + nBad_TP_per_LS_HE_ + nBad_TP_per_LS_HF_);
00412 
00413    ProblemsCurrentLB->Fill(-1,-1,levt_);
00414    ProblemsCurrentLB->Fill(0,0, nBad_TP_per_LS_HB_);
00415    ProblemsCurrentLB->Fill(1,0, nBad_TP_per_LS_HE_);
00416    ProblemsCurrentLB->Fill(3,0, nBad_TP_per_LS_HF_);
00417 }
00418 
00419 
00420 MonitorElement*
00421 HcalTrigPrimMonitor::create_summary(const std::string& folder, const std::string& name) {
00422    edm::LogInfo("HcalTrigPrimMonitor") << "Creating MonitorElement " << name << " in folder " << folder << "\n";
00423 
00424    dbe_->setCurrentFolder(folder);
00425    return dbe_->book2D(name, name, 65, -32.5, 32.5, 72, 0.5, 72.5);
00426 }
00427 
00428 MonitorElement*
00429 HcalTrigPrimMonitor::create_errorflag(const std::string& folder, const std::string& name) {
00430    edm::LogInfo("HcalTrigPrimMonitor") << "Creating MonitorElement " << name << " in folder " << folder << "\n";
00431 
00432    dbe_->setCurrentFolder(folder);
00433    MonitorElement* element = dbe_->book2D(name, name, 4, 1, 5, 2, 0, 2);
00434    element->setBinLabel(1, "Mismatched E");
00435    element->setBinLabel(2, "Mismatched FG");
00436    element->setBinLabel(3, "Missing Data");
00437    element->setBinLabel(4, "Missing Emul");
00438    element->setBinLabel(1, "HBHE", 2);
00439    element->setBinLabel(2, "HF", 2);
00440    return element;
00441 }
00442 
00443 MonitorElement*
00444 HcalTrigPrimMonitor::create_tp_correlation(const std::string& folder, const std::string& name) {
00445    edm::LogInfo("HcalTrigPrimMonitor") << "Creating MonitorElement " << name << " in folder " << folder << "\n";
00446 
00447    dbe_->setCurrentFolder(folder);
00448    MonitorElement* element = dbe_->book2D(name, name, 50, 0, 256, 50, 0, 256);
00449    element->setAxisTitle("data TP", 1);
00450    element->setAxisTitle("emul TP", 2);
00451    return element;
00452 }
00453 
00454 MonitorElement*
00455 HcalTrigPrimMonitor::create_fg_correlation(const std::string& folder, const std::string& name) {
00456    edm::LogInfo("HcalTrigPrimMonitor") << "Creating MonitorElement " << name << " in folder " << folder << "\n";
00457 
00458    dbe_->setCurrentFolder(folder);
00459    MonitorElement* element = dbe_->book2D(name, name, 2, 0, 2, 2, 0, 2);
00460    element->setAxisTitle("data FG", 1);
00461    element->setAxisTitle("emul FG", 2);
00462    return element;
00463 }
00464 
00465 MonitorElement*
00466 HcalTrigPrimMonitor::create_map(const std::string& folder, const std::string& name) {
00467    edm::LogInfo("HcalTrigPrimMonitor") << "Creating MonitorElement " << name << " in folder " << folder << "\n";
00468 
00469    dbe_->setCurrentFolder(folder);
00470    std::string title = name +";ieta;iphi";
00471    return dbe_->book2D(name, title, 65, -32.5, 32.5, 72, 0.5, 72.5);
00472 }
00473 
00474 MonitorElement*
00475 HcalTrigPrimMonitor::create_et_histogram(const std::string& folder, const std::string& name) {
00476    edm::LogInfo("HcalTrigPrimMonitor") << "Creating MonitorElement " << name << " in folder " << folder << "\n";
00477 
00478    dbe_->setCurrentFolder(folder);
00479    return dbe_->book1D(name, name, 256, 0, 256);
00480 }
00481 
00482 DEFINE_FWK_MODULE (HcalTrigPrimMonitor);