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