CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DQM/SiStripMonitorClient/src/SiStripQualityChecker.cc

Go to the documentation of this file.
00001 #include "DQM/SiStripMonitorClient/interface/SiStripQualityChecker.h"
00002 #include "FWCore/ServiceRegistry/interface/Service.h"
00003 #include "DQMServices/Core/interface/DQMStore.h"
00004 #include "DQMServices/Core/interface/MonitorElement.h"
00005 #include "DQMServices/Core/interface/QReport.h"
00006 
00007 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00008 
00009 #include "CalibTracker/SiStripCommon/interface/TkDetMap.h"
00010 
00011 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00012 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00013 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00014 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00015 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00016 
00017 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
00018 #include "DQM/SiStripMonitorClient/interface/SiStripUtility.h"
00019 
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00022 
00023 
00024 #include <iomanip>
00025 //
00026 // -- Constructor
00027 // 
00028 SiStripQualityChecker::SiStripQualityChecker(edm::ParameterSet const& ps):pSet_(ps) {
00029   edm::LogInfo("SiStripQualityChecker") << 
00030     " Creating SiStripQualityChecker " << "\n" ;
00031 
00032   bookedStripStatus_ = false;
00033   bookedTrackingStatus_ = false;
00034 
00035   SubDetFolderMap.insert(std::pair<std::string, std::string>("TIB",  "TIB"));
00036   SubDetFolderMap.insert(std::pair<std::string, std::string>("TOB",  "TOB"));
00037   SubDetFolderMap.insert(std::pair<std::string, std::string>("TECF", "TEC/side_2"));
00038   SubDetFolderMap.insert(std::pair<std::string, std::string>("TECB", "TEC/side_1"));
00039   SubDetFolderMap.insert(std::pair<std::string, std::string>("TIDF", "TID/side_2"));
00040   SubDetFolderMap.insert(std::pair<std::string, std::string>("TIDB", "TID/side_1"));
00041   badModuleList.clear();
00042 
00043   if(!edm::Service<TkDetMap>().isAvailable()){
00044     edm::LogError("TkHistoMap") <<
00045       "\n------------------------------------------"
00046       "\nUnAvailable Service TkHistoMap: please insert in the configuration file an instance like"
00047       "\n\tprocess.TkDetMap = cms.Service(\"TkDetMap\")"
00048       "\n------------------------------------------";
00049   }
00050   tkDetMap_=edm::Service<TkDetMap>().operator->();
00051 
00052   TrackingMEs tracking_mes;
00053   edm::ParameterSet TkPSet;
00054  
00055   TkPSet = pSet_.getParameter<edm::ParameterSet>("TrackRatePSet"); 
00056   tracking_mes.TrackingFlag = 0;
00057   tracking_mes.HistoName    = TkPSet.getParameter<std::string>("Name");
00058   tracking_mes.LowerCut = TkPSet.getParameter<double>("LowerCut");
00059   tracking_mes.UpperCut = TkPSet.getParameter<double>("UpperCut");
00060   TrackingMEsMap.insert(std::pair<std::string, TrackingMEs>("Rate", tracking_mes));
00061 
00062   TkPSet = pSet_.getParameter<edm::ParameterSet>("TrackChi2PSet"); 
00063   tracking_mes.TrackingFlag = 0;
00064   tracking_mes.HistoName    = TkPSet.getParameter<std::string>("Name");
00065   tracking_mes.LowerCut = TkPSet.getParameter<double>("LowerCut");
00066   tracking_mes.UpperCut = TkPSet.getParameter<double>("UpperCut");
00067   TrackingMEsMap.insert(std::pair<std::string, TrackingMEs>("Chi2", tracking_mes));
00068 
00069   TkPSet = pSet_.getParameter<edm::ParameterSet>("TrackHitPSet"); 
00070   tracking_mes.TrackingFlag = 0;
00071   tracking_mes.HistoName    = TkPSet.getParameter<std::string>("Name");
00072   tracking_mes.LowerCut = TkPSet.getParameter<double>("LowerCut");
00073   tracking_mes.UpperCut = TkPSet.getParameter<double>("UpperCut");
00074   TrackingMEsMap.insert(std::pair<std::string, TrackingMEs>("RecHits", tracking_mes));
00075 
00076 }
00077 //
00078 // --  Destructor
00079 // 
00080 SiStripQualityChecker::~SiStripQualityChecker() {
00081   edm::LogInfo("SiStripQualityChecker") << 
00082     " Deleting SiStripQualityChecker " << "\n" ;
00083 }
00084 //
00085 // -- create reportSummary MEs
00086 //
00087 void SiStripQualityChecker::bookStatus(DQMStore* dqm_store) {
00088 
00089   if (!bookedStripStatus_) {
00090     dqm_store->cd();
00091     std::string strip_dir = "";
00092     SiStripUtility::getTopFolderPath(dqm_store, "SiStrip", strip_dir); 
00093     if (strip_dir.size() == 0) strip_dir = "SiStrip";
00094 
00095     // Non Standard Plots and should be put outside EventInfo folder
00096 
00097     dqm_store->setCurrentFolder(strip_dir+"/MechanicalView"); 
00098       
00099     std::string hname, htitle;
00100     hname  = "detFractionReportMap";
00101     htitle = "SiStrip Report for Good Detector Fraction";
00102     DetFractionReportMap  = dqm_store->book2D(hname, htitle, 6,0.5,6.5,9,0.5,9.5);
00103     DetFractionReportMap->setAxisTitle("Sub Detector Type", 1);
00104     DetFractionReportMap->setAxisTitle("Layer/Disc Number", 2);
00105     hname  = "sToNReportMap";
00106     htitle = "SiStrip Report for Signal-to-Noise";
00107     SToNReportMap         = dqm_store->book2D(hname, htitle, 6,0.5,6.5,9,0.5,9.5);
00108     SToNReportMap->setAxisTitle("Sub Detector Type", 1);
00109     SToNReportMap->setAxisTitle("Layer/Disc Number", 2);
00110 
00111     // this is the main reportSummary 2D plot and should be in EventInfo    
00112     dqm_store->setCurrentFolder(strip_dir+"/EventInfo"); 
00113 
00114     hname  = "reportSummaryMap";
00115     htitle = "SiStrip Report Summary Map";
00116     SummaryReportMap      = dqm_store->book2D(hname, htitle, 6,0.5,6.5,9,0.5,9.5);
00117     SummaryReportMap->setAxisTitle("Sub Detector Type", 1);
00118     SummaryReportMap->setAxisTitle("Layer/Disc Number", 2);
00119     
00120     SummaryReportGlobal = dqm_store->bookFloat("reportSummary");
00121     int ibin = 0;
00122     
00123     dqm_store->setCurrentFolder(strip_dir+"/EventInfo/reportSummaryContents");      
00124     for (std::map<std::string, std::string>::const_iterator it = SubDetFolderMap.begin(); 
00125          it != SubDetFolderMap.end(); it++) {
00126       ibin++;
00127       std::string det = it->first;
00128       DetFractionReportMap->setBinLabel(ibin,det);
00129       SToNReportMap->setBinLabel(ibin,det);
00130       SummaryReportMap->setBinLabel(ibin,det);
00131       
00132       SubDetMEs local_mes;
00133       
00134       if (det == "TECF")      local_mes.detectorTag = "TEC+";
00135       else if (det == "TECB") local_mes.detectorTag = "TEC-";         
00136       else if (det == "TIDF") local_mes.detectorTag = "TID+";
00137       else if (det == "TIDB") local_mes.detectorTag = "TID-";
00138       else                    local_mes.detectorTag = det;
00139       
00140       std::string me_name;
00141       me_name = "SiStrip_" + det;
00142       local_mes.SummaryFlag = dqm_store->bookFloat(me_name);
00143       
00144       me_name = "SiStrip_DetFraction_" + det;
00145       local_mes.DetFraction = dqm_store->bookFloat(me_name);
00146       
00147       me_name = "SiStrip_SToNFlag_" + det;
00148       local_mes.SToNFlag    = dqm_store->bookFloat(me_name);
00149       SubDetMEsMap.insert(std::pair<std::string, SubDetMEs>(det, local_mes));
00150     }
00151     bookedStripStatus_ = true;
00152   }  
00153   if (!bookedTrackingStatus_) {
00154     dqm_store->cd();     
00155     std::string tracking_dir = "";
00156     SiStripUtility::getTopFolderPath(dqm_store, "Tracking", tracking_dir);
00157     if (tracking_dir.size() ==  0) tracking_dir = "Tracking";
00158     dqm_store->setCurrentFolder(tracking_dir+"/EventInfo"); 
00159     
00160     TrackSummaryReportGlobal = dqm_store->bookFloat("reportSummary");
00161     
00162     std::string hname, htitle;
00163     hname  = "reportSummaryMap";
00164     htitle = "Tracking Report Summary Map";
00165     
00166     TrackSummaryReportMap    = dqm_store->book2D(hname, htitle, 3,0.5,3.5,1,0.5,1.5);
00167     TrackSummaryReportMap->setAxisTitle("Track Quality Type", 1);
00168     TrackSummaryReportMap->setAxisTitle("QTest Flag", 2);
00169     TrackSummaryReportMap->setBinLabel(1,"Rate");
00170     TrackSummaryReportMap->setBinLabel(2,"Chi2");
00171     TrackSummaryReportMap->setBinLabel(3,"RecHits");
00172     
00173     dqm_store->setCurrentFolder(tracking_dir+"/EventInfo/reportSummaryContents");  
00174     int ibin = 0;
00175     for (std::map<std::string, TrackingMEs>::iterator it = TrackingMEsMap.begin();
00176          it != TrackingMEsMap.end(); it++) {
00177       ibin++;
00178       std::string name = it->first;
00179       it->second.TrackingFlag = dqm_store->bookFloat("Track"+name);
00180       TrackSummaryReportMap->setBinLabel(ibin,name);
00181     }
00182     bookedTrackingStatus_ = true;
00183     dqm_store->cd();
00184   }
00185 }
00186 //
00187 // -- Fill Dummy  Status
00188 //
00189 void SiStripQualityChecker::fillDummyStatus(){
00190  
00191   resetStatus();
00192   if (bookedStripStatus_) {
00193     for (std::map<std::string, SubDetMEs>::const_iterator it = SubDetMEsMap.begin(); 
00194          it != SubDetMEsMap.end(); it++) {
00195       SubDetMEs local_mes = it->second;
00196       local_mes.DetFraction->Fill(-1.0);
00197       local_mes.SToNFlag->Fill(-1.0);
00198       local_mes.SummaryFlag->Fill(-1.0);
00199     }
00200     
00201     for (int xbin = 1; xbin < SummaryReportMap->getNbinsX()+1; xbin++) {
00202       for (int ybin = 1; ybin < SummaryReportMap->getNbinsY()+1; ybin++) {
00203         DetFractionReportMap->Fill(xbin, ybin, -1.0);
00204         SToNReportMap->Fill(xbin, ybin, -1.0);
00205         SummaryReportMap->Fill(xbin, ybin, -1.0);
00206       }
00207     }
00208     SummaryReportGlobal->Fill(-1.0);
00209   }
00210   if (bookedTrackingStatus_) {  
00211     TrackSummaryReportGlobal->Fill(-1.0);
00212     for (int xbin = 1; xbin < TrackSummaryReportMap->getNbinsX()+1; xbin++) {
00213       for (int ybin = 1; ybin < TrackSummaryReportMap->getNbinsY()+1; ybin++) {
00214         TrackSummaryReportMap->Fill(xbin, ybin, -1.0);
00215       }
00216     }
00217     for (std::map<std::string, TrackingMEs>::iterator it = TrackingMEsMap.begin();
00218          it != TrackingMEsMap.end(); it++) {
00219       it->second.TrackingFlag->Fill(-1.0);
00220     }
00221   }
00222 }
00223 //
00224 // -- Reset Status
00225 //
00226 void SiStripQualityChecker::resetStatus() {
00227   if (bookedStripStatus_) {
00228     for (std::map<std::string, SubDetMEs>::const_iterator it = SubDetMEsMap.begin(); 
00229          it != SubDetMEsMap.end(); it++) {
00230       SubDetMEs local_mes = it->second;
00231       local_mes.DetFraction->Reset();
00232       local_mes.SToNFlag->Reset();
00233       local_mes.SummaryFlag->Reset();
00234     }
00235 
00236     DetFractionReportMap->Reset();
00237     SToNReportMap->Reset();
00238     SummaryReportMap->Reset();
00239 
00240     SummaryReportGlobal->Reset();
00241   }
00242   if (bookedTrackingStatus_) {  
00243     TrackSummaryReportGlobal->Reset();
00244     TrackSummaryReportMap->Reset();
00245     for (std::map<std::string, TrackingMEs>::iterator it = TrackingMEsMap.begin();
00246          it != TrackingMEsMap.end(); it++) {
00247       it->second.TrackingFlag->Reset();
00248     }
00249   }
00250 }
00251 //
00252 // -- Fill Status
00253 //
00254 void SiStripQualityChecker::fillStatus(DQMStore* dqm_store, const edm::ESHandle< SiStripDetCabling >& cabling) {
00255   if (!bookedStripStatus_ || !bookedTrackingStatus_) bookStatus(dqm_store);
00256 
00257   fillDummyStatus();
00258   fillDetectorStatus(dqm_store, cabling);
00259   fillTrackingStatus(dqm_store);
00260 
00261   int faulty_moduleflag  = pSet_.getUntrackedParameter<bool>("PrintFaultyModuleList", false);
00262   if (faulty_moduleflag) fillFaultyModuleStatus(dqm_store);   
00263 }
00264 //
00265 // Fill Detector Status
00266 //
00267 void SiStripQualityChecker::fillDetectorStatus(DQMStore* dqm_store, const edm::ESHandle< SiStripDetCabling >& cabling) {
00268   unsigned int xbin = 0;
00269   float global_flag = 0;
00270   dqm_store->cd();
00271   std::string mdir = "MechanicalView"; 
00272   if (!SiStripUtility::goToDir(dqm_store, mdir)) return;
00273   std::string mechanicalview_dir = dqm_store->pwd();
00274 
00275   initialiseBadModuleList();
00276   for (std::map<std::string, SubDetMEs>::const_iterator it = SubDetMEsMap.begin(); 
00277        it != SubDetMEsMap.end(); it++) {
00278     std::string det = it->first;
00279     std::map<std::string, std::string>::const_iterator cPos = SubDetFolderMap.find(det);
00280     if (cPos == SubDetFolderMap.end()) continue; 
00281     std::string dname = mechanicalview_dir + "/" + cPos->second;
00282     if (!dqm_store->dirExists(dname)) continue;
00283     dqm_store->cd(dname);
00284     SubDetMEs local_mes = it->second;
00285     xbin++;
00286     float flag;
00287     fillSubDetStatus(dqm_store, cabling, local_mes, xbin,flag);
00288     global_flag += flag; 
00289   }
00290   global_flag = global_flag/xbin*1.0;
00291   if (SummaryReportGlobal) SummaryReportGlobal->Fill(global_flag);
00292   dqm_store->cd();
00293 }
00294 //
00295 // -- Fill Tracking Status
00296 //
00297 void SiStripQualityChecker::fillTrackingStatus(DQMStore* dqm_store) {
00298 
00299   dqm_store->cd();
00300   std::string dir = "Tracking"; 
00301   if (!SiStripUtility::goToDir(dqm_store, dir)) return;
00302   dir = "TrackParameters"; 
00303   if (!SiStripUtility::goToDir(dqm_store, dir)) return;
00304   
00305   std::vector<MonitorElement*> meVec1 = dqm_store->getContents(dqm_store->pwd()+"/GeneralProperties");
00306   std::vector<MonitorElement*> meVec2 = dqm_store->getContents(dqm_store->pwd()+"/HitProperties");
00307   std::vector<MonitorElement*> meVec(meVec1.size() + meVec2.size()); 
00308   std::merge(meVec1.begin(), meVec1.end(), meVec2.begin(), meVec2.end(), meVec.begin());
00309 
00310   float gstatus = 1.0;
00311   for (std::vector<MonitorElement*>::const_iterator it = meVec.begin(); it != meVec.end(); it++) {
00312     MonitorElement * me = (*it);     
00313     if (!me) continue;     
00314     std::vector<QReport *> qt_reports = me->getQReports();          
00315     if (qt_reports.size() == 0) continue;
00316     std::string name = me->getName();
00317 
00318     float status = 1.0; 
00319 
00320     int ibin = 0;
00321     for (std::map<std::string, TrackingMEs>::const_iterator it = TrackingMEsMap.begin();
00322          it != TrackingMEsMap.end(); it++) {
00323       ibin++;
00324       std::string hname = it->second.HistoName;
00325       if (name.find(hname) != std::string::npos) {
00326         status = qt_reports[0]->getQTresult();
00327         it->second.TrackingFlag->Fill(status);
00328         fillStatusHistogram(TrackSummaryReportMap, ibin, 1, status);
00329         break;
00330       }
00331     }
00332     gstatus = gstatus * status; 
00333   }
00334   TrackSummaryReportGlobal->Fill(gstatus);
00335   dqm_store->cd();
00336 }
00337 //
00338 // -- Fill Sub detector Reports
00339 //
00340 void SiStripQualityChecker::fillSubDetStatus(DQMStore* dqm_store, 
00341                      const edm::ESHandle< SiStripDetCabling >& cabling,
00342                          SubDetMEs& mes, unsigned int xbin, float& gflag) {
00343   int status_flag  = pSet_.getUntrackedParameter<int>("GlobalStatusFilling", 1);
00344   
00345   if (status_flag < 1) return;
00346 
00347   std::vector<std::string> subDirVec = dqm_store->getSubdirs();
00348 
00349   unsigned int ybin   = 0;
00350   int tot_ndet        = 0;
00351   int tot_errdet      = 0;
00352   float tot_ston_stat = 0;
00353 
00354   for (std::vector<std::string>::const_iterator ic = subDirVec.begin();
00355        ic != subDirVec.end(); ic++) {
00356     std::string dname = (*ic);
00357     if (dname.find("BadModuleList") != std::string::npos) continue;
00358     std::vector<MonitorElement*> meVec;
00359     ybin++;
00360     dqm_store->cd((*ic));
00361     meVec = dqm_store->getContents((*ic));
00362     uint16_t ndet = 100;
00363     int errdet = 0;       
00364 
00365     int ston_stat = 1;
00366     int lnum = atoi(dname.substr(dname.find_last_of("_")+1).c_str());
00367     ndet = cabling->connectedNumber(mes.detectorTag, lnum);
00368      
00369     getModuleStatus(meVec, errdet);
00370 
00371     for (std::vector<MonitorElement*>::const_iterator it = meVec.begin();
00372          it != meVec.end(); it++) {
00373       MonitorElement * me = (*it);
00374       if (!me) continue;
00375       std::vector<QReport *> reports = me->getQReports();
00376 
00377       if (reports.size() == 0) continue;
00378       std::string name = me->getName();
00379       
00380       if( name.find("Summary_ClusterStoNCorr__OnTrack") != std::string::npos){
00381         int istat =  SiStripUtility::getMEStatus((*it)); 
00382         if (reports[0]->getQTresult() == -1) {
00383           ston_stat =-1;
00384         } else {
00385           if (istat == dqm::qstatus::ERROR) ston_stat = 0;
00386           else if (istat == dqm::qstatus::STATUS_OK) ston_stat = 1;
00387         }
00388       }
00389     }
00390     if (ndet > 0) {
00391       float eff_fac = 1 - (errdet*1.0/ndet);
00392       fillStatusHistogram(SToNReportMap,        xbin, ybin, ston_stat);
00393       fillStatusHistogram(DetFractionReportMap, xbin, ybin, eff_fac);
00394       if (ston_stat < 0) fillStatusHistogram(SummaryReportMap, xbin, ybin, eff_fac);
00395       else       fillStatusHistogram(SummaryReportMap, xbin, ybin, ston_stat*eff_fac);
00396 
00397       tot_ndet      += ndet;
00398       tot_errdet    += errdet;
00399       tot_ston_stat += ston_stat;  
00400     }
00401     dqm_store->cd((*ic));
00402   }
00403   if (tot_ndet > 0) { 
00404     float tot_eff_fac = 1 - (tot_errdet*1.0/tot_ndet);
00405     if (mes.DetFraction) mes.DetFraction->Fill(tot_eff_fac);
00406     float tot_ston_fac = tot_ston_stat/ybin;
00407     if (mes.SToNFlag) mes.SToNFlag->Fill(tot_ston_fac);
00408     if (tot_ston_fac < 0){
00409       gflag = tot_eff_fac;    
00410     }else{
00411       gflag = std::min(tot_eff_fac,tot_ston_fac);    
00412     }
00413     if (mes.SummaryFlag) mes.SummaryFlag->Fill(gflag);
00414   }
00415 }    
00416 //
00417 // -- Print Status Report
00418 //
00419 void SiStripQualityChecker::printStatusReport() {
00420   std::ostringstream det_summary_str;
00421   for (std::map<std::string, SubDetMEs>::const_iterator it = SubDetMEsMap.begin(); 
00422        it != SubDetMEsMap.end(); it++) {
00423     std::string det = it->first;
00424     det_summary_str << std::setprecision(4);
00425     det_summary_str << std::setiosflags(std::ios::fixed);
00426 
00427     det_summary_str << " Printing Status for " <<   det << " : " << std::endl;
00428     SubDetMEs local_mes = it->second;
00429 
00430     std::string sval;
00431     float fval1, fval2, fval3;
00432     fval1 = fval2 = fval3 = -1.0;   
00433     
00434 
00435     SiStripUtility::getMEValue(local_mes.DetFraction, sval); 
00436     if (sval.size() > 0) fval1 = atof(sval.c_str());
00437     SiStripUtility::getMEValue(local_mes.SToNFlag, sval); 
00438     if (sval.size() > 0) fval2 = atof(sval.c_str());
00439     SiStripUtility::getMEValue(local_mes.SummaryFlag, sval); 
00440     if (sval.size() > 0) fval3 = atof(sval.c_str());
00441 
00442     det_summary_str << std::setw(7) << " % of good detectors " << fval1
00443                     << " SToN Flag           " << fval2
00444                     << " Summary Flag        " << fval3 << std::endl;
00445   }
00446   std::cout << det_summary_str.str() << std::endl;
00447 }
00448 //
00449 // -- Get Module Status from Layer Level Histograms
00450 //
00451 void SiStripQualityChecker::getModuleStatus(std::vector<MonitorElement*>& layer_mes,int& errdet) { 
00452   
00453   std::string lname;
00454   std::map<uint32_t,uint16_t> bad_modules;
00455   for (std::vector<MonitorElement*>::const_iterator it = layer_mes.begin();
00456        it != layer_mes.end(); it++) {
00457     MonitorElement * me = (*it);
00458     if (!me) continue;
00459     std::vector<QReport *> qreports = me->getQReports();
00460     if (qreports.size() == 0) continue;
00461     std::string name = me->getName();
00462     std::vector<DQMChannel>  bad_channels_me;
00463     if (me->kind() == MonitorElement::DQM_KIND_TPROFILE) {
00464       bad_channels_me = qreports[0]->getBadChannels();
00465       lname = "";
00466     } else if (me->kind() == MonitorElement::DQM_KIND_TPROFILE2D && name.find("TkHMap") != std::string::npos) {
00467       bad_channels_me = qreports[0]->getBadChannels();
00468       lname = name.substr(name.find("TkHMap_")+7);
00469       lname = lname.substr(lname.find("_T")+1);
00470 
00471     }
00472     for (std::vector<DQMChannel>::iterator it = bad_channels_me.begin(); it != bad_channels_me.end(); it++){
00473       int xval = (*it).getBinX();
00474       int yval = (*it).getBinY();
00475       uint32_t detId = tkDetMap_->getDetFromBin(lname, xval, yval);       
00476       std::map<uint32_t,uint16_t>::iterator iPos = bad_modules.find(detId);
00477       uint16_t flag;
00478       if (iPos != bad_modules.end()){
00479         flag = iPos->second;
00480         SiStripUtility::setBadModuleFlag(name,flag);            
00481         iPos->second = flag;
00482       } else {
00483         flag = 0;
00484         SiStripUtility::setBadModuleFlag(name,flag);              
00485         bad_modules.insert(std::pair<uint32_t,uint16_t>(detId,flag));
00486       }
00487     }
00488   }
00489   for(std::map<uint32_t,uint16_t>::const_iterator it = bad_modules.begin();
00490       it != bad_modules.end(); it++) {
00491     uint32_t detId = it->first;
00492     uint16_t flag  = it->second;
00493     std::map<uint32_t,uint16_t>::iterator iPos = badModuleList.find(detId);
00494     if (iPos != badModuleList.end()){
00495       iPos->second = flag;
00496     } else {
00497       badModuleList.insert(std::pair<uint32_t,uint16_t>(detId,flag));
00498     }
00499   }    
00500   errdet = bad_modules.size();  
00501 }
00502 //
00503 // -- Fill Report Summary Map
00504 //
00505  void SiStripQualityChecker::fillStatusHistogram(MonitorElement* me, int xbin, int ybin, float val){
00506    if (me &&  me->kind() == MonitorElement::DQM_KIND_TH2F) {
00507      TH2F*  th2d = me->getTH2F();
00508      th2d->SetBinContent(xbin, ybin, val);
00509    }
00510  }
00511 //
00512 // -- Create Monitor Elements for Modules
00513 //
00514 void SiStripQualityChecker::fillFaultyModuleStatus(DQMStore* dqm_store) {
00515   if (badModuleList.size() == 0) return;
00516   dqm_store->cd();
00517   std::string mdir = "MechanicalView";
00518   if (!SiStripUtility::goToDir(dqm_store, mdir)) return;
00519   std::string mechanical_dir = dqm_store->pwd();
00520 
00521   SiStripFolderOrganizer folder_organizer;
00522   for (std::map<uint32_t,uint16_t>::const_iterator it =  badModuleList.begin() ; it != badModuleList.end(); it++) {
00523     uint32_t detId =  it->first;
00524     std::string subdet_folder ;
00525     folder_organizer.getSubDetFolder(detId,subdet_folder);
00526     if (!dqm_store->dirExists(subdet_folder)) {
00527       subdet_folder = mechanical_dir + subdet_folder.substr(subdet_folder.find("MechanicalView")+14);
00528       if (!dqm_store->dirExists(subdet_folder)) continue;
00529     }
00530     std::string bad_module_folder = subdet_folder + "/" + "BadModuleList";
00531     dqm_store->setCurrentFolder(bad_module_folder);
00532 
00533     std::ostringstream detid_str;
00534     detid_str << detId;
00535     std::string full_path = bad_module_folder + "/" + detid_str.str();
00536     MonitorElement* me = dqm_store->get(full_path);
00537     if (me) me->Reset();
00538     else me = dqm_store->bookInt(detid_str.str());
00539     me->Fill(it->second);
00540   }
00541   dqm_store->cd();
00542 }
00543 //
00544 // -- Initialise Bad Module List
00545 //
00546 void SiStripQualityChecker::initialiseBadModuleList() {
00547   for (std::map<uint32_t,uint16_t>::iterator it=badModuleList.begin(); it!=badModuleList.end(); it++) {
00548     it->second = 0;
00549   }
00550 }
00551 //
00552 // -- Fill Status information and the lumi block
00553 //
00554 void SiStripQualityChecker::fillStatusAtLumi(DQMStore* dqm_store){
00555   if (!bookedStripStatus_ || !bookedTrackingStatus_) bookStatus(dqm_store);
00556   fillDummyStatus();
00557   fillDetectorStatusAtLumi(dqm_store);
00558   fillTrackingStatusAtLumi(dqm_store);
00559 }
00560 //
00561 // Fill Detector Status MEs at the Lumi block
00562 // 
00563 void SiStripQualityChecker::fillDetectorStatusAtLumi(DQMStore* dqm_store){
00564   dqm_store->cd();
00565   std::string rdir = "ReadoutView"; 
00566   if (!SiStripUtility::goToDir(dqm_store, rdir)) return;
00567   std::string fullpath = dqm_store->pwd() 
00568                           + "/FedSummary/PerLumiSection/"
00569                           + "lumiErrorFraction";  
00570   MonitorElement* me = dqm_store->get(fullpath);
00571   if (me && me->kind() == MonitorElement::DQM_KIND_TH1F) {
00572     TH1F* th1 = me->getTH1F(); 
00573     float global_fraction = 0.0;
00574     float dets = 0.0;
00575     for (int ibin = 1; ibin <= th1->GetNbinsX(); ibin++) {
00576       std::string label = th1->GetXaxis()->GetBinLabel(ibin);
00577       std::map<std::string, SubDetMEs>::iterator iPos = SubDetMEsMap.find(label);
00578       if (iPos != SubDetMEsMap.end()) {
00579         float fraction = 1.0 - th1->GetBinContent(ibin);
00580         global_fraction +=  fraction;
00581         dets++; 
00582         iPos->second.DetFraction->Fill(fraction);
00583         iPos->second.SToNFlag->Fill(-1.0);
00584         iPos->second.SummaryFlag->Fill(fraction);
00585       }
00586     }
00587     global_fraction = global_fraction/dets;
00588     if (SummaryReportGlobal) SummaryReportGlobal->Fill(global_fraction);    
00589   }
00590   dqm_store->cd();
00591 }
00592 //
00593 // Fill Tracking Status MEs at the Lumi block
00594 // 
00595 void SiStripQualityChecker::fillTrackingStatusAtLumi(DQMStore* dqm_store){
00596   dqm_store->cd();
00597   std::string dir = "Tracking"; 
00598   if (!SiStripUtility::goToDir(dqm_store, dir)) return;
00599   dir = "TrackParameters"; 
00600   if (!SiStripUtility::goToDir(dqm_store, dir)) return;
00601   
00602   std::vector<MonitorElement*> meVec1 = dqm_store->getContents(dqm_store->pwd()+"/GeneralProperties");
00603   std::vector<MonitorElement*> meVec2 = dqm_store->getContents(dqm_store->pwd()+"/HitProperties");
00604   std::vector<MonitorElement*> meVec(meVec1.size() + meVec2.size()); 
00605   std::merge(meVec1.begin(), meVec1.end(), meVec2.begin(), meVec2.end(), meVec.begin());
00606   float gstatus = 1.0;
00607   for (std::vector<MonitorElement*>::const_iterator it = meVec.begin(); it != meVec.end(); it++) {
00608     MonitorElement * me = (*it);     
00609     if (!me) continue;     
00610     std::string name = me->getName();
00611 
00612     float status = -1.0; 
00613     int ibin = 0;
00614     for (std::map<std::string, TrackingMEs>::const_iterator it = TrackingMEsMap.begin();
00615          it != TrackingMEsMap.end(); it++) {
00616       ibin++;
00617       std::string hname = it->second.HistoName;
00618       float lower_cut = it->second.LowerCut; 
00619       float upper_cut = it->second.UpperCut; 
00620       if (name.find(hname) != std::string::npos) {
00621         if (me->getMean() <= lower_cut || me->getMean() > upper_cut) status = 0.0;
00622         else status = 1.0; 
00623         it->second.TrackingFlag->Fill(status);
00624         fillStatusHistogram(TrackSummaryReportMap, ibin, 1, status);
00625         break;
00626       }
00627     }
00628     if (status == -1.0) gstatus = -1.0;
00629     else gstatus = gstatus * status; 
00630   }
00631   TrackSummaryReportGlobal->Fill(gstatus);
00632   dqm_store->cd();
00633 }