CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/SiStripMonitorClient/src/SiStripCertificationInfo.cc

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