00001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00002 #include "FWCore/ServiceRegistry/interface/Service.h"
00003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00004
00005 #include "DQMServices/Core/interface/DQMStore.h"
00006 #include "DQMServices/Core/interface/MonitorElement.h"
00007 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
00008 #include "DQM/SiStripMonitorClient/interface/SiStripUtility.h"
00009 #include "DQM/SiStripMonitorClient/interface/SiStripCertificationInfo.h"
00010
00011 #include "CondFormats/DataRecord/interface/SiStripCondDataRecords.h"
00012 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
00013 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00014
00015 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00016 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00017 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00018 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00019 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00020
00021
00022 #include "CondFormats/DataRecord/interface/RunSummaryRcd.h"
00023 #include "CondFormats/RunInfo/interface/RunSummary.h"
00024 #include "CondFormats/RunInfo/interface/RunInfo.h"
00025
00026 #include <iostream>
00027 #include <iomanip>
00028 #include <stdio.h>
00029 #include <string>
00030 #include <sstream>
00031 #include <math.h>
00032
00033
00034
00035 SiStripCertificationInfo::SiStripCertificationInfo(edm::ParameterSet const& pSet) {
00036
00037 edm::LogInfo( "SiStripCertificationInfo") << "SiStripCertificationInfo::Deleting SiStripCertificationInfo ";
00038
00039 dqmStore_ = edm::Service<DQMStore>().operator->();
00040 trackingCertificationBooked_ = false;
00041 sistripCertificationBooked_ = false;
00042 }
00043 SiStripCertificationInfo::~SiStripCertificationInfo() {
00044 edm::LogInfo("SiStripCertificationInfo") << "SiStripCertificationInfo::Deleting SiStripCertificationInfo ";
00045
00046 }
00047
00048
00049
00050 void SiStripCertificationInfo::beginJob() {
00051
00052 }
00053
00054
00055
00056 void SiStripCertificationInfo::beginRun(edm::Run const& run, edm::EventSetup const& eSetup) {
00057
00058 edm::LogInfo ("SiStripCertificationInfo") <<"SiStripCertificationInfo:: Begining of Run";
00059 unsigned long long cacheID = eSetup.get<SiStripDetCablingRcd>().cacheIdentifier();
00060 if (m_cacheID_ != cacheID) {
00061 m_cacheID_ = cacheID;
00062 }
00063 eSetup.get<SiStripDetCablingRcd>().get(detCabling_);
00064
00065 nFEDConnected_ = 0;
00066 const int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
00067 const int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
00068
00069 edm::eventsetup::EventSetupRecordKey recordKey(edm::eventsetup::EventSetupRecordKey::TypeTag::findType("RunInfoRcd"));
00070 if( eSetup.find( recordKey ) != 0) {
00071
00072 edm::ESHandle<RunInfo> sumFED;
00073 eSetup.get<RunInfoRcd>().get(sumFED);
00074
00075 if ( sumFED.isValid() ) {
00076 std::vector<int> FedsInIds= sumFED->m_fed_in;
00077 for(unsigned int it = 0; it < FedsInIds.size(); ++it) {
00078 int fedID = FedsInIds[it];
00079 if(fedID>=siStripFedIdMin && fedID<=siStripFedIdMax) ++nFEDConnected_;
00080 }
00081 LogDebug ("SiStripDcsInfo") << " SiStripDcsInfo :: Connected FEDs " << nFEDConnected_;
00082 }
00083 }
00084
00085 bookSiStripCertificationMEs();
00086 bookTrackingCertificationMEs();
00087 fillDummySiStripCertification();
00088 fillDummyTrackingCertification();
00089
00090 }
00091
00092
00093
00094 void SiStripCertificationInfo::bookSiStripCertificationMEs() {
00095 if (!sistripCertificationBooked_) {
00096 dqmStore_->cd();
00097 std::string strip_dir = "";
00098 SiStripUtility::getTopFolderPath(dqmStore_, "SiStrip", strip_dir);
00099 if (strip_dir.size() > 0) dqmStore_->setCurrentFolder(strip_dir+"/EventInfo");
00100 else dqmStore_->setCurrentFolder("SiStrip/EventInfo");
00101
00102 SiStripCertification = dqmStore_->bookFloat("CertificationSummary");
00103
00104 std::string hname = "CertificationReportMap";
00105 std::string htitle = "SiStrip Certification for Good Detector Fraction";
00106 SiStripCertificationSummaryMap = dqmStore_->book2D(hname, htitle, 6,0.5,6.5,9,0.5,9.5);
00107 SiStripCertificationSummaryMap->setAxisTitle("Sub Detector Type", 1);
00108 SiStripCertificationSummaryMap->setAxisTitle("Layer/Disc Number", 2);
00109 int ibin = 0;
00110 for (std::map<std::string, SubDetMEs>::const_iterator it = SubDetMEsMap.begin();
00111 it != SubDetMEsMap.end(); it++) {
00112 ibin++;
00113 std::string det = it->first;
00114 SiStripCertificationSummaryMap->setBinLabel(ibin,det);
00115 }
00116
00117 SubDetMEs local_mes;
00118 std::string tag;
00119 dqmStore_->cd();
00120 if (strip_dir.size() > 0) dqmStore_->setCurrentFolder(strip_dir+"/EventInfo/CertificationContents");
00121 else dqmStore_->setCurrentFolder("SiStrip/EventInfo/CertificationContents");
00122 tag = "TIB";
00123
00124 local_mes.folder_name = "TIB";
00125 local_mes.subdet_tag = "TIB";
00126 local_mes.n_layer = 4;
00127 local_mes.det_fractionME = dqmStore_->bookFloat("SiStrip_"+tag);
00128 SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
00129
00130 tag = "TOB";
00131 local_mes.folder_name = "TOB";
00132 local_mes.subdet_tag = "TOB";
00133 local_mes.n_layer = 6;
00134 local_mes.det_fractionME = dqmStore_->bookFloat("SiStrip_"+tag);
00135 SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
00136
00137 tag = "TECF";
00138 local_mes.folder_name = "TEC/side_2";
00139 local_mes.subdet_tag = "TEC+";
00140 local_mes.n_layer = 9;
00141 local_mes.det_fractionME = dqmStore_->bookFloat("SiStrip_"+tag);
00142 SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
00143
00144 tag = "TECB";
00145 local_mes.folder_name = "TEC/side_1";
00146 local_mes.subdet_tag = "TEC-";
00147 local_mes.n_layer = 9;
00148 local_mes.det_fractionME = dqmStore_->bookFloat("SiStrip_"+tag);
00149 SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
00150
00151 tag = "TIDF";
00152 local_mes.folder_name = "TID/side_2";
00153 local_mes.subdet_tag = "TID+";
00154 local_mes.n_layer = 3;
00155 local_mes.det_fractionME = dqmStore_->bookFloat("SiStrip_"+tag);
00156 SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
00157
00158 tag = "TIDB";
00159 local_mes.folder_name = "TID/side_1";
00160 local_mes.subdet_tag = "TID-";
00161 local_mes.n_layer = 3;
00162 local_mes.det_fractionME = dqmStore_->bookFloat("SiStrip_"+tag);
00163 SubDetMEsMap.insert(std::pair<std::string, SubDetMEs >(tag, local_mes));
00164
00165 dqmStore_->cd();
00166 if (strip_dir.size() > 0) dqmStore_->setCurrentFolder(strip_dir+"/EventInfo");
00167
00168 sistripCertificationBooked_ = true;
00169 dqmStore_->cd();
00170 }
00171 }
00172
00173
00174
00175 void SiStripCertificationInfo::bookTrackingCertificationMEs() {
00176 if (!trackingCertificationBooked_) {
00177 std::string tracking_dir = "";
00178 SiStripUtility::getTopFolderPath(dqmStore_, "Tracking", tracking_dir);
00179 if (tracking_dir.size() > 0) {
00180 dqmStore_->setCurrentFolder(tracking_dir+"/EventInfo");
00181 TrackingCertification = dqmStore_->bookFloat("CertificationSummary");
00182
00183 dqmStore_->setCurrentFolder(tracking_dir+"/EventInfo/CertificationContents");
00184
00185 std::string type;
00186 MonitorElement* me;
00187 type = "Rate";
00188 me = dqmStore_->bookFloat("Track"+type);
00189 TrackingMEsMap.insert(std::pair<std::string,MonitorElement*>(type,me));
00190
00191 type = "Chi2";
00192 me = dqmStore_->bookFloat("Track"+type);
00193 TrackingMEsMap.insert(std::pair<std::string,MonitorElement*>(type,me));
00194
00195 type = "RecHits";
00196 me = dqmStore_->bookFloat("Track"+type);
00197 TrackingMEsMap.insert(std::pair<std::string,MonitorElement*>(type,me));
00198
00199 trackingCertificationBooked_ = true;
00200 dqmStore_->cd();
00201 }
00202 }
00203 }
00204
00205
00206
00207 void SiStripCertificationInfo::analyze(edm::Event const& event, edm::EventSetup const& eSetup) {
00208 }
00209
00210
00211
00212 void SiStripCertificationInfo::endLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& iSetup) {
00213 edm::LogInfo( "SiStripDaqInfo") << "SiStripDaqInfo::endLuminosityBlock";
00214
00215 if (nFEDConnected_ > 0) {
00216 fillSiStripCertificationMEsAtLumi();
00217 fillTrackingCertificationMEs();
00218 }
00219 }
00220
00221
00222
00223
00224 void SiStripCertificationInfo::endRun(edm::Run const& run, edm::EventSetup const& eSetup){
00225 edm::LogInfo ("SiStripCertificationInfo") <<"SiStripCertificationInfo:: End Run";
00226
00227 if (nFEDConnected_ > 0) {
00228 fillSiStripCertificationMEs();
00229 fillTrackingCertificationMEs();
00230 }
00231 }
00232
00233
00234
00235 void SiStripCertificationInfo::fillTrackingCertificationMEs() {
00236 if (!trackingCertificationBooked_) {
00237 edm::LogError("SiStripCertificationInfo") << " SiStripCertificationInfo::fillTrackingCertificationMEs : MEs missing ";
00238 return;
00239 }
00240 std::string tk_dir = "";
00241 SiStripUtility::getTopFolderPath(dqmStore_, "Tracking", tk_dir);
00242 if (tk_dir.size() == 0) {
00243 fillDummyTrackingCertification();
00244 return;
00245 }
00246
00247 std::vector<MonitorElement*> all_mes = dqmStore_->getContents(tk_dir+"/EventInfo/reportSummaryContents");
00248 float fval = 1.0;
00249 for (std::vector<MonitorElement *>::const_iterator it = all_mes.begin();
00250 it!= all_mes.end(); it++) {
00251 MonitorElement * me = (*it);
00252 if (!me) continue;
00253 if (me->kind() == MonitorElement::DQM_KIND_REAL) {
00254 std::string name = me->getName();
00255 float val = me->getFloatValue();
00256 for (std::map<std::string, MonitorElement*>::const_iterator it = TrackingMEsMap.begin();
00257 it != TrackingMEsMap.end(); it++) {
00258 std::string type = it->first;
00259 if (name.find(type) != std::string::npos) {
00260 it->second->Fill(val);
00261 break;
00262 }
00263 }
00264 fval *= val;
00265 }
00266 }
00267 TrackingCertification->Fill(fval);
00268 }
00269
00270
00271
00272 void SiStripCertificationInfo::fillSiStripCertificationMEs() {
00273 if (!sistripCertificationBooked_) {
00274 edm::LogError("SiStripCertificationInfo") << " SiStripCertificationInfo::fillSiStripCertificationMEs : MEs missing ";
00275 return;
00276 }
00277 resetSiStripCertificationMEs();
00278 std::string mdir = "MechanicalView";
00279 dqmStore_->cd();
00280 if (!SiStripUtility::goToDir(dqmStore_, mdir)) return;
00281 std::string mechanical_dir = dqmStore_->pwd();
00282 uint16_t nDetTot = 0;
00283 uint16_t nFaultyTot = 0;
00284 uint16_t nSToNTot = 0;
00285 float sToNTot = 0.0;
00286 SiStripFolderOrganizer folder_organizer;
00287 int xbin = 0;
00288 for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin();
00289 it != SubDetMEsMap.end(); it++) {
00290 xbin++;
00291 std::string name = it->first;
00292 std::string tag = it->second.subdet_tag;
00293 MonitorElement* me = it->second.det_fractionME;
00294 if (!me) continue;
00295 std::string bad_module_folder = mechanical_dir+"/"+it->second.folder_name+"/"+"BadModuleList";
00296 std::vector<MonitorElement *> faulty_detMEs = dqmStore_->getContents(bad_module_folder);
00297
00298 uint16_t ndet_subdet = 0;
00299 uint16_t nfaulty_subdet = 0;
00300 int nlayer = it->second.n_layer;
00301 int ybin = 0;
00302 for (int ilayer = 0; ilayer < nlayer; ilayer++) {
00303 uint16_t ndet_layer = detCabling_->connectedNumber(tag, ilayer+1);
00304 ndet_subdet += ndet_layer;
00305 ybin++;
00306 uint16_t nfaulty_layer = 0;
00307 for (std::vector<MonitorElement *>::iterator im = faulty_detMEs.begin(); im != faulty_detMEs.end(); im++) {
00308 if ((*im)->kind() != MonitorElement::DQM_KIND_INT ) continue;
00309 if ((*im)->getIntValue() == 0) continue;
00310 uint32_t detId = atoi((*im)->getName().c_str());
00311 std::pair<std::string,int32_t> det_layer_pair = folder_organizer.GetSubDetAndLayer(detId, false);
00312 if (abs(det_layer_pair.second) == ilayer+1) nfaulty_layer++;
00313 }
00314
00315 nfaulty_subdet += nfaulty_layer;
00316 float fraction_layer = -1.0;
00317 if ( ndet_layer > 0) fraction_layer = 1 - ((nfaulty_layer*1.0)/ndet_layer);
00318 if (SiStripCertificationSummaryMap) SiStripCertificationSummaryMap->Fill(xbin, ilayer+1,fraction_layer);
00319 }
00320 if (ybin <= SiStripCertificationSummaryMap->getNbinsY()) {
00321 for (int k = ybin+1; k <= SiStripCertificationSummaryMap->getNbinsY(); k++) SiStripCertificationSummaryMap->Fill(xbin, k, -1.0);
00322 }
00323 float fraction_subdet = -1.0;
00324 if (ndet_subdet > 0) fraction_subdet = 1 - ((nfaulty_subdet*1.0)/ndet_subdet);
00325
00326 std::string full_path = mechanical_dir.substr(0, mechanical_dir.find_last_of("/"))
00327 + "/EventInfo/reportSummaryContents/SiStrip_SToNFlag_"+name;
00328 MonitorElement* me_ston = dqmStore_->get(full_path);
00329 me->Reset();
00330 if (me_ston && me_ston->kind()==MonitorElement::DQM_KIND_REAL) {
00331 float ston_flg = me_ston->getFloatValue();
00332 sToNTot += ston_flg;
00333 nSToNTot++;
00334 me->Fill(fminf(fraction_subdet,ston_flg));
00335 } else me->Fill(fraction_subdet);
00336 nDetTot += ndet_subdet ;
00337 nFaultyTot += nfaulty_subdet;
00338 }
00339 float fraction_global = -1.0;
00340 if (nDetTot > 0) fraction_global = 1.0 - ((nFaultyTot*1.0)/nDetTot);
00341 float ston_frac_global = 1.0;
00342 if (nSToNTot > 0) ston_frac_global = sToNTot/nSToNTot;
00343 SiStripCertification->Fill(fminf(fraction_global,ston_frac_global));
00344 }
00345
00346
00347
00348 void SiStripCertificationInfo::resetTrackingCertificationMEs() {
00349 if (!trackingCertificationBooked_) bookTrackingCertificationMEs();
00350 if (trackingCertificationBooked_) {
00351 TrackingCertification->Reset();
00352 for (std::map<std::string, MonitorElement*>::const_iterator it = TrackingMEsMap.begin();
00353 it != TrackingMEsMap.end(); it++) {
00354 it->second->Reset();
00355 }
00356 }
00357 }
00358
00359
00360
00361 void SiStripCertificationInfo::resetSiStripCertificationMEs() {
00362 if (!sistripCertificationBooked_) bookSiStripCertificationMEs();
00363 if (sistripCertificationBooked_) {
00364 SiStripCertification->Reset();
00365 for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin();
00366 it != SubDetMEsMap.end(); it++) {
00367 it->second.det_fractionME->Reset();
00368 }
00369 SiStripCertificationSummaryMap->Reset();
00370 }
00371 }
00372
00373
00374
00375 void SiStripCertificationInfo::fillDummySiStripCertification() {
00376 resetSiStripCertificationMEs();
00377 if (sistripCertificationBooked_) {
00378 SiStripCertification->Fill(-1.0);
00379 for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin();
00380 it != SubDetMEsMap.end(); it++) {
00381 it->second.det_fractionME->Reset();
00382 it->second.det_fractionME->Fill(-1.0);
00383 }
00384
00385 for (int xbin = 1; xbin < SiStripCertificationSummaryMap->getNbinsX()+1; xbin++) {
00386 for (int ybin = 1; ybin < SiStripCertificationSummaryMap->getNbinsY()+1; ybin++) {
00387 SiStripCertificationSummaryMap->Fill(xbin, ybin, -1.0);
00388 }
00389 }
00390 }
00391 }
00392
00393
00394
00395 void SiStripCertificationInfo::fillDummyTrackingCertification() {
00396 resetTrackingCertificationMEs();
00397 if (trackingCertificationBooked_) {
00398 TrackingCertification->Fill(-1.0);
00399 for (std::map<std::string, MonitorElement*>::const_iterator it = TrackingMEsMap.begin();
00400 it != TrackingMEsMap.end(); it++) {
00401 it->second->Fill(-1.0);
00402 }
00403
00404 }
00405 }
00406
00407
00408
00409 void SiStripCertificationInfo::fillSiStripCertificationMEsAtLumi() {
00410 if (!sistripCertificationBooked_) {
00411 edm::LogError("SiStripCertificationInfo") << " SiStripCertificationInfo::fillSiStripCertificationMEsAtLumi : MEs missing ";
00412 return;
00413 }
00414 resetSiStripCertificationMEs();
00415 dqmStore_->cd();
00416 std::string strip_dir = "";
00417 SiStripUtility::getTopFolderPath(dqmStore_, "SiStrip", strip_dir);
00418 if (strip_dir.size() == 0) strip_dir = "SiStrip";
00419
00420 std::string full_path;
00421 float dcs_flag = 1.0;
00422 float dqm_flag = 1.0;
00423 for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin();
00424 it != SubDetMEsMap.end(); it++) {
00425 std::string type = it->first;
00426 full_path = strip_dir + "/EventInfo/DCSContents/SiStrip_" + type;
00427 MonitorElement* me_dcs = dqmStore_->get(full_path);
00428 if (me_dcs && me_dcs->kind() == MonitorElement::DQM_KIND_REAL) dcs_flag = me_dcs->getFloatValue();
00429 full_path = strip_dir + "/EventInfo/reportSummaryContents/SiStrip_" + type;
00430 MonitorElement* me_dqm = dqmStore_->get(full_path);
00431 if (me_dqm && me_dqm->kind() == MonitorElement::DQM_KIND_REAL) dqm_flag = me_dqm->getFloatValue();
00432 it->second.det_fractionME->Reset();
00433 it->second.det_fractionME->Fill(fminf(dqm_flag,dcs_flag));
00434 }
00435 dcs_flag = 1.0;
00436 dqm_flag = 1.0;
00437 full_path = strip_dir + "/EventInfo/reportSummary";
00438 MonitorElement* me_dqm = dqmStore_->get(full_path);
00439 if (me_dqm && me_dqm->kind() == MonitorElement::DQM_KIND_REAL) dqm_flag = me_dqm->getFloatValue();
00440 full_path = strip_dir + "/EventInfo/DCSSummary";
00441 MonitorElement* me_dcs = dqmStore_->get(full_path);
00442 if (me_dcs && me_dcs->kind() == MonitorElement::DQM_KIND_REAL) dcs_flag = me_dcs->getFloatValue();
00443 SiStripCertification->Reset();
00444 SiStripCertification->Fill(fminf(dqm_flag,dcs_flag));
00445 }
00446 #include "FWCore/Framework/interface/MakerMacros.h"
00447 DEFINE_FWK_MODULE(SiStripCertificationInfo);