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