00001 #include "DQM/L1TMonitorClient/interface/L1TEMUEventInfoClient.h"
00002
00003 #include "FWCore/ServiceRegistry/interface/Service.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00005 #include "FWCore/Framework/interface/ESHandle.h"
00006 #include "FWCore/Framework/interface/EventSetup.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include "DQMServices/Core/interface/QReport.h"
00009 #include "DQMServices/Core/interface/DQMStore.h"
00010 #include "TRandom.h"
00011 #include <TF1.h>
00012 #include <stdio.h>
00013 #include <sstream>
00014 #include <math.h>
00015 #include <TProfile.h>
00016 #include <TProfile2D.h>
00017 #include <memory>
00018 #include <iostream>
00019 #include <vector>
00020 #include <iomanip>
00021 #include <string>
00022 #include <fstream>
00023 #include "TROOT.h"
00024
00025 using namespace edm;
00026 using namespace std;
00027
00028 L1TEMUEventInfoClient::L1TEMUEventInfoClient(const edm::ParameterSet& ps)
00029 {
00030 parameters_=ps;
00031 initialize();
00032 }
00033
00034 L1TEMUEventInfoClient::~L1TEMUEventInfoClient(){
00035 if(verbose_) cout <<"[TriggerDQM]: ending... " << endl;
00036 }
00037
00038
00039 void L1TEMUEventInfoClient::initialize(){
00040
00041 counterLS_=0;
00042 counterEvt_=0;
00043
00044
00045 dbe_ = Service<DQMStore>().operator->();
00046
00047
00048 verbose_ = parameters_.getUntrackedParameter<bool>("verbose", false);
00049
00050 monitorDir_ = parameters_.getUntrackedParameter<string>("monitorDir","");
00051 if(verbose_) cout << "Monitor dir = " << monitorDir_ << endl;
00052
00053 prescaleLS_ = parameters_.getUntrackedParameter<int>("prescaleLS", -1);
00054 if(verbose_) cout << "DQM lumi section prescale = " << prescaleLS_ << " lumi section(s)"<< endl;
00055
00056 prescaleEvt_ = parameters_.getUntrackedParameter<int>("prescaleEvt", -1);
00057 if(verbose_) cout << "DQM event prescale = " << prescaleEvt_ << " events(s)"<< endl;
00058
00059
00060
00061 std::string syslabel [nsysmon_]=
00062 {"DTTF","DTTPG","CSCTF","CSCTPG","RPC","GMT", "ECAL","HCAL","RCT","GCT","GT"};
00063 std::string syslabelext[nsysmon_]=
00064 {"DTF","DTP","CTF","CTP","RPC","GMT", "ETP","HTP","RCT","GCT","GLT"};
00065 std::vector<unsigned int> sysmask(0,nsysmon_);
00066 sysmask = parameters_.getUntrackedParameter<std::vector<unsigned int> >("maskedSystems", sysmask);
00067
00068 for(int i=0; i<nsysmon_; i++) {
00069 syslabel_[i] = syslabel[i];
00070 syslabelext_[i] = syslabelext[i];
00071 sysmask_[i] = sysmask[i];
00072 }
00073
00074 std::vector<string> emptyMask;
00075
00076 dataMask = parameters_.getUntrackedParameter<std::vector<string> >("dataMaskedSystems", emptyMask);
00077 emulMask = parameters_.getUntrackedParameter<std::vector<string> >("emulatorMaskedSystems", emptyMask);
00078
00079 s_mapDataValues["EMPTY"] = data_empty;
00080 s_mapDataValues["ALL"] = data_all;
00081 s_mapDataValues["GT"] = data_gt;
00082 s_mapDataValues["MUONS"] = data_muons;
00083 s_mapDataValues["JETS"] = data_jets;
00084 s_mapDataValues["TAUJETS"] = data_taujets;
00085 s_mapDataValues["ISOEM"] = data_isoem;
00086 s_mapDataValues["NONISOEM"] = data_nonisoem;
00087 s_mapDataValues["MET"] = data_met;
00088
00089 s_mapEmulValues["EMPTY"] = emul_empty;
00090 s_mapEmulValues["ALL"] = emul_all;
00091 s_mapEmulValues["DTTF"] = emul_dtf;
00092 s_mapEmulValues["DTTPG"] = emul_dtp;
00093 s_mapEmulValues["CSCTF"] = emul_ctf;
00094 s_mapEmulValues["CSCTPG"] = emul_ctp;
00095 s_mapEmulValues["RPC"] = emul_rpc;
00096 s_mapEmulValues["GMT"] = emul_gmt;
00097 s_mapEmulValues["ECAL"] = emul_etp;
00098 s_mapEmulValues["HCAL"] = emul_htp;
00099 s_mapEmulValues["RCT"] = emul_rct;
00100 s_mapEmulValues["GCT"] = emul_gct;
00101 s_mapEmulValues["GLT"] = emul_glt;
00102
00103 emulatorMap[0] = 13;
00104 emulatorMap[1] = 12;
00105 emulatorMap[2] = 11;
00106 emulatorMap[3] = 10;
00107 emulatorMap[4] = 9;
00108 emulatorMap[5] = 8;
00109 emulatorMap[6] = 15;
00110 emulatorMap[7] = 14;
00111 emulatorMap[8] = 17;
00112 emulatorMap[9] = 16;
00113 emulatorMap[10] = 7;
00114
00115 }
00116
00117
00118 void L1TEMUEventInfoClient::beginJob(void){
00119
00120 if(verbose_) cout <<"[TriggerDQM]: Begin Job" << endl;
00121
00122 dbe_ = Service<DQMStore>().operator->();
00123
00124 dbe_->setCurrentFolder("L1TEMU/EventInfo");
00125
00126
00127 if( (reportSummary_ = dbe_->get("L1TEMU/EventInfo/reportSumamry")) ){
00128 dbe_->removeElement(reportSummary_->getName());
00129 }
00130
00131 reportSummary_ = dbe_->bookFloat("reportSummary");
00132
00133
00134 if (reportSummary_) reportSummary_->Fill(1);
00135
00136 dbe_->setCurrentFolder("L1TEMU/EventInfo/reportSummaryContents");
00137
00138
00139 char histo[100];
00140
00141 for (int n = 0; n < nsys_; n++) {
00142
00143 switch(n){
00144 case 0 : sprintf(histo,"L1T_MET"); break;
00145 case 1 : sprintf(histo,"L1T_NonIsoEM"); break;
00146 case 2 : sprintf(histo,"L1T_IsoEM"); break;
00147 case 3 : sprintf(histo,"L1T_TauJets"); break;
00148 case 4 : sprintf(histo,"L1T_Jets"); break;
00149 case 5 : sprintf(histo,"L1T_Muons"); break;
00150 case 6 : sprintf(histo,"L1T_GT"); break;
00151 case 7 : sprintf(histo,"L1TEMU_GLT"); break;
00152 case 8 : sprintf(histo,"L1TEMU_GMT"); break;
00153 case 9 : sprintf(histo,"L1TEMU_RPC"); break;
00154 case 10: sprintf(histo,"L1TEMU_CTP"); break;
00155 case 11: sprintf(histo,"L1TEMU_CTF"); break;
00156 case 12: sprintf(histo,"L1TEMU_DTP"); break;
00157 case 13: sprintf(histo,"L1TEMU_DTF"); break;
00158 case 14: sprintf(histo,"L1TEMU_HTP"); break;
00159 case 15: sprintf(histo,"L1TEMU_ETP"); break;
00160 case 16: sprintf(histo,"L1TEMU_GCT"); break;
00161 case 17: sprintf(histo,"L1TEMU_RCT"); break;
00162 }
00163
00164 reportSummaryContent_[n] = dbe_->bookFloat(histo);
00165 }
00166
00167
00168 for (int k = 0; k < nsys_; k++) {
00169 summaryContent[k] = 0;
00170 reportSummaryContent_[k]->Fill(0.);
00171 }
00172
00173
00174 dbe_->setCurrentFolder("L1TEMU/EventInfo");
00175
00176 if( (reportSummaryMap_ = dbe_->get("L1TEMU/EventInfo/reportSummaryMap")) ){
00177 dbe_->removeElement(reportSummaryMap_->getName());
00178 }
00179
00180 reportSummaryMap_ = dbe_->book2D("reportSummaryMap", "reportSummaryMap", 2, 1, 3, 11, 1, 12);
00181 reportSummaryMap_->setAxisTitle("", 1);
00182 reportSummaryMap_->setAxisTitle("", 2);
00183
00184 reportSummaryMap_->setBinLabel(1," ",1);
00185 reportSummaryMap_->setBinLabel(2," ",1);
00186
00187 reportSummaryMap_->setBinLabel(1," ",2);
00188 reportSummaryMap_->setBinLabel(2," ",2);
00189 reportSummaryMap_->setBinLabel(3," ",2);
00190 reportSummaryMap_->setBinLabel(4," ",2);
00191 reportSummaryMap_->setBinLabel(5," ",2);
00192 reportSummaryMap_->setBinLabel(6," ",2);
00193 reportSummaryMap_->setBinLabel(7," ",2);
00194 reportSummaryMap_->setBinLabel(8," ",2);
00195 reportSummaryMap_->setBinLabel(9," ",2);
00196 reportSummaryMap_->setBinLabel(10," ",2);
00197 reportSummaryMap_->setBinLabel(11," ",2);
00198
00199
00200 }
00201
00202
00203 void L1TEMUEventInfoClient::beginRun(const Run& r, const EventSetup& context) {
00204 }
00205
00206
00207 void L1TEMUEventInfoClient::beginLuminosityBlock(const LuminosityBlock& lumiSeg, const EventSetup& context) {
00208
00209 }
00210
00211 void L1TEMUEventInfoClient::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
00212 const edm::EventSetup& c){
00213
00214
00215 for (int k = 0; k < nsys_; k++) {
00216 summaryContent[k] = 0;
00217 reportSummaryContent_[k]->Fill(0.);
00218 }
00219 summarySum = 0;
00220
00221
00222
00223
00224
00225
00226
00227 unsigned int NumDataMask = dataMask.size();
00228 std::vector<string> maskedData;
00229 for( unsigned int i=0; i<NumDataMask; i++ ){
00230 std::string mask_sys_tmp = dataMask[i];
00231 std::string mask_sys = StringToUpper(mask_sys_tmp);
00232 switch(s_mapDataValues[mask_sys])
00233 {
00234 case data_empty:
00235 break;
00236 case data_all:
00237 for( int m=0; m<7; m++ ) summaryContent[m] = -1;
00238 maskedData.push_back(mask_sys_tmp);
00239 break;
00240 case data_gt:
00241 summaryContent[6]=-1;
00242 maskedData.push_back(mask_sys_tmp);
00243 break;
00244 case data_muons:
00245 summaryContent[5]=-1;
00246 maskedData.push_back(mask_sys_tmp);
00247 break;
00248 case data_jets:
00249 summaryContent[4]=-1;
00250 maskedData.push_back(mask_sys_tmp);
00251 break;
00252 case data_taujets:
00253 summaryContent[3]=-1;
00254 maskedData.push_back(mask_sys_tmp);
00255 break;
00256 case data_isoem:
00257 summaryContent[2]=-1;
00258 maskedData.push_back(mask_sys_tmp);
00259 break;
00260 case data_nonisoem:
00261 summaryContent[1]=-1;
00262 maskedData.push_back(mask_sys_tmp);
00263 break;
00264 case data_met:
00265 summaryContent[0]=-1;
00266 maskedData.push_back(mask_sys_tmp);
00267 break;
00268 default:
00269 if( verbose_ ) cout << " User input mask '" << mask_sys_tmp << "' is not recognized." << endl;
00270 break;
00271 }
00272 }
00273
00274
00275 unsigned int NumEmulMask = emulMask.size();
00276 std::vector<string> maskedEmul;
00277 for( unsigned int i=0; i<NumEmulMask; i++ ){
00278 std::string mask_sys_tmp = emulMask[i];
00279 std::string mask_sys = StringToUpper(mask_sys_tmp);
00280 switch(s_mapEmulValues[mask_sys])
00281 {
00282 case emul_empty:
00283 break;
00284 case emul_all:
00285 for( int m=7; m<18; m++ ) summaryContent[m] = -1;
00286 maskedEmul.push_back(mask_sys_tmp);
00287 break;
00288 case emul_glt:
00289 summaryContent[7]=-1;
00290 maskedEmul.push_back(mask_sys_tmp);
00291 break;
00292 case emul_gmt:
00293 summaryContent[8]=-1;
00294 maskedEmul.push_back(mask_sys_tmp);
00295 break;
00296 case emul_rpc:
00297 summaryContent[9]=-1;
00298 maskedEmul.push_back(mask_sys_tmp);
00299 break;
00300 case emul_ctp:
00301 summaryContent[10]=-1;
00302 maskedEmul.push_back(mask_sys_tmp);
00303 break;
00304 case emul_ctf:
00305 summaryContent[11]=-1;
00306 maskedEmul.push_back(mask_sys_tmp);
00307 break;
00308 case emul_dtp:
00309 summaryContent[12]=-1;
00310 maskedEmul.push_back(mask_sys_tmp);
00311 break;
00312 case emul_dtf:
00313 summaryContent[13]=-1;
00314 maskedEmul.push_back(mask_sys_tmp);
00315 break;
00316 case emul_htp:
00317 summaryContent[14]=-1;
00318 maskedEmul.push_back(mask_sys_tmp);
00319 break;
00320 case emul_etp:
00321 summaryContent[15]=-1;
00322 maskedEmul.push_back(mask_sys_tmp);
00323 break;
00324 case emul_gct:
00325 summaryContent[16]=-1;
00326 maskedEmul.push_back(mask_sys_tmp);
00327 break;
00328 case emul_rct:
00329 summaryContent[17]=-1;
00330 maskedEmul.push_back(mask_sys_tmp);
00331 break;
00332 default:
00333 if( verbose_ ) cout << " User input mask '" << mask_sys_tmp << "' is not recognized." << endl;
00334 break;
00335 }
00336 }
00337
00338 for( int i=0; i<nsysmon_; i++ ){
00339 if( summaryContent[emulatorMap[i]]==-1 ) sysmask_[i] = 1;
00340 }
00341
00342
00343 MonitorElement* QHist[nsysmon_];
00344 std::string lbl("");
00345 for(int i=0; i<nsysmon_; i++) {
00346 lbl.clear();
00347 lbl+="L1TEMU/"; lbl+=syslabel_[i]; lbl+="/";
00348 lbl+=syslabelext_[i]; lbl+="ErrorFlag";
00349 QHist[i]=dbe_->get(lbl.data());
00350 float pv = -1.;
00351 if(!sysmask_[i]){
00352 pv = setSummary(QHist[i]);
00353 }
00354 summaryContent[emulatorMap[i]] = pv;
00355 }
00356
00357
00358
00359 int numUnMaskedSystems = 0;
00360 for( int m=0; m<nsys_; m++ ){
00361 if( summaryContent[m]!=-1){
00362 if( m>6 ){
00363 summarySum += summaryContent[m];
00364 numUnMaskedSystems++;
00365 }
00366
00367 reportSummaryContent_[m]->Fill( summaryContent[m] );
00368 }
00369 }
00370
00371
00372
00373
00374 reportSummary = summarySum/float(numUnMaskedSystems);
00375 if (reportSummary_) reportSummary_->Fill(reportSummary);
00376
00377
00378
00379 reportSummaryMap_->setBinContent(1,11,summaryContent[6]);
00380 reportSummaryMap_->setBinContent(1,10,summaryContent[5]);
00381 reportSummaryMap_->setBinContent(1,9, summaryContent[4]);
00382 reportSummaryMap_->setBinContent(1,8, summaryContent[3]);
00383 reportSummaryMap_->setBinContent(1,7, summaryContent[2]);
00384 reportSummaryMap_->setBinContent(1,6, summaryContent[1]);
00385 reportSummaryMap_->setBinContent(1,5, summaryContent[0]);
00386
00387
00388 reportSummaryMap_->setBinContent(2,11,summaryContent[7]);
00389 reportSummaryMap_->setBinContent(2,10,summaryContent[8]);
00390 reportSummaryMap_->setBinContent(2,9, summaryContent[9]);
00391 reportSummaryMap_->setBinContent(2,8, summaryContent[10]);
00392 reportSummaryMap_->setBinContent(2,7, summaryContent[11]);
00393 reportSummaryMap_->setBinContent(2,6, summaryContent[12]);
00394 reportSummaryMap_->setBinContent(2,5, summaryContent[13]);
00395 reportSummaryMap_->setBinContent(2,4, summaryContent[14]);
00396 reportSummaryMap_->setBinContent(2,3, summaryContent[15]);
00397 reportSummaryMap_->setBinContent(2,2, summaryContent[16]);
00398 reportSummaryMap_->setBinContent(2,1, summaryContent[17]);
00399
00400
00401 if( verbose_ ){
00402 if( maskedData.size()>0 ){
00403 std::cout << " Masked Data Systems = ";
00404 for( unsigned int i=0; i<maskedData.size(); i++ ){
00405 if( i!=maskedData.size()-1 ){
00406 std::cout << maskedData[i] << ", ";
00407 }
00408 else {
00409 std::cout << maskedData[i] << std::endl;
00410 }
00411 }
00412 }
00413 if( maskedEmul.size()>0 ){
00414 std::cout << " Masked Emul Systems = ";
00415 for( unsigned int i=0; i<maskedEmul.size(); i++ ){
00416 if( i!=maskedEmul.size()-1 ){
00417 std::cout << maskedEmul[i] << ", ";
00418 }
00419 else {
00420 std::cout << maskedEmul[i] << std::endl;
00421 }
00422 }
00423 }
00424
00425 std::cout << " L1T " << std::endl;
00426 std::cout << " summaryContent[0] = MET = " << summaryContent[0] << std::endl;
00427 std::cout << " summaryContent[1] = NonIsoEM = " << summaryContent[1] << std::endl;
00428 std::cout << " summaryContent[2] = IsoEM = " << summaryContent[2] << std::endl;
00429 std::cout << " summaryContent[3] = TauJets = " << summaryContent[3] << std::endl;
00430 std::cout << " summaryContent[4] = Jets = " << summaryContent[4] << std::endl;
00431 std::cout << " summaryContent[5] = Muons = " << summaryContent[5] << std::endl;
00432 std::cout << " summaryContent[6] = GT = " << summaryContent[6] << std::endl;
00433 std::cout << " L1T EMU" << std::endl;
00434 std::cout << " summaryContent[7] = GLT = " << summaryContent[7] << std::endl;
00435 std::cout << " summaryContent[8] = GMT = " << summaryContent[8] << std::endl;
00436 std::cout << " summaryContent[9] = RPC = " << summaryContent[9] << std::endl;
00437 std::cout << " summaryContent[10] = CTP = " << summaryContent[10] << std::endl;
00438 std::cout << " summaryContent[11] = CTF = " << summaryContent[11] << std::endl;
00439 std::cout << " summaryContent[12] = DTP = " << summaryContent[12] << std::endl;
00440 std::cout << " summaryContent[13] = DTF = " << summaryContent[13] << std::endl;
00441 std::cout << " summaryContent[14] = HTP = " << summaryContent[14] << std::endl;
00442 std::cout << " summaryContent[15] = ETP = " << summaryContent[15] << std::endl;
00443 std::cout << " summaryContent[16] = GCT = " << summaryContent[16] << std::endl;
00444 std::cout << " summaryContent[17] = RCT = " << summaryContent[17] << std::endl;
00445 }
00446
00447
00448 }
00449
00450
00451 void L1TEMUEventInfoClient::analyze(const Event& e, const EventSetup& context){
00452
00453 counterEvt_++;
00454 if (prescaleEvt_<1) return;
00455 if (prescaleEvt_>0 && counterEvt_%prescaleEvt_ != 0) return;
00456
00457 if(verbose_) cout << "L1TEMUEventInfoClient::analyze" << endl;
00458 }
00459
00460
00461 void L1TEMUEventInfoClient::endRun(const Run& r, const EventSetup& context){
00462 }
00463
00464
00465 void L1TEMUEventInfoClient::endJob(){
00466 }
00467
00468
00469 Float_t L1TEMUEventInfoClient::setSummary(MonitorElement* QHist) {
00470 bool isempty = QHist->getEntries()==0;
00471
00472 if(!isempty)
00473 for(int i=1; i<5; i++)
00474 if(QHist->getBinContent(i)>0)
00475 {isempty=false;continue;}
00476 return isempty ? -1. :
00477 (QHist->getBinContent(1)) / (QHist->getEntries());
00478 }
00479
00480 TH1F * L1TEMUEventInfoClient::get1DHisto(string meName, DQMStore * dbi)
00481 {
00482
00483 MonitorElement * me_ = dbi->get(meName);
00484
00485 if (!me_) {
00486 if(verbose_) cout << "ME NOT FOUND." << endl;
00487 return NULL;
00488 }
00489
00490 return me_->getTH1F();
00491 }
00492
00493 TH2F * L1TEMUEventInfoClient::get2DHisto(string meName, DQMStore * dbi)
00494 {
00495
00496
00497 MonitorElement * me_ = dbi->get(meName);
00498
00499 if (!me_) {
00500 if(verbose_) cout << "ME NOT FOUND." << endl;
00501 return NULL;
00502 }
00503
00504 return me_->getTH2F();
00505 }
00506
00507
00508
00509 TProfile2D * L1TEMUEventInfoClient::get2DProfile(string meName, DQMStore * dbi)
00510 {
00511
00512
00513 MonitorElement * me_ = dbi->get(meName);
00514
00515 if (!me_) {
00516 if(verbose_) cout << "ME NOT FOUND." << endl;
00517 return NULL;
00518 }
00519
00520 return me_->getTProfile2D();
00521 }
00522
00523
00524 TProfile * L1TEMUEventInfoClient::get1DProfile(string meName, DQMStore * dbi)
00525 {
00526
00527
00528 MonitorElement * me_ = dbi->get(meName);
00529
00530 if (!me_) {
00531 if(verbose_) cout << "ME NOT FOUND." << endl;
00532 return NULL;
00533 }
00534
00535 return me_->getTProfile();
00536 }
00537
00538 string L1TEMUEventInfoClient::StringToUpper(string strToConvert)
00539 {
00540 for(unsigned int i=0;i<strToConvert.length();i++)
00541 {
00542 strToConvert[i] = toupper(strToConvert[i]);
00543 }
00544 return strToConvert;
00545 }
00546
00547
00548
00549
00550
00551
00552
00553