CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/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     gflag = std::min(tot_eff_fac,tot_ston_fac);    
00409     if (mes.SummaryFlag) mes.SummaryFlag->Fill(gflag);
00410   }
00411 }    
00412 //
00413 // -- Print Status Report
00414 //
00415 void SiStripQualityChecker::printStatusReport() {
00416   std::ostringstream det_summary_str;
00417   for (std::map<std::string, SubDetMEs>::const_iterator it = SubDetMEsMap.begin(); 
00418        it != SubDetMEsMap.end(); it++) {
00419     std::string det = it->first;
00420     det_summary_str << std::setprecision(4);
00421     det_summary_str << std::setiosflags(std::ios::fixed);
00422 
00423     det_summary_str << " Printing Status for " <<   det << " : " << std::endl;
00424     SubDetMEs local_mes = it->second;
00425 
00426     std::string sval;
00427     float fval1, fval2, fval3;
00428     fval1 = fval2 = fval3 = -1.0;   
00429     
00430 
00431     SiStripUtility::getMEValue(local_mes.DetFraction, sval); 
00432     if (sval.size() > 0) fval1 = atof(sval.c_str());
00433     SiStripUtility::getMEValue(local_mes.SToNFlag, sval); 
00434     if (sval.size() > 0) fval2 = atof(sval.c_str());
00435     SiStripUtility::getMEValue(local_mes.SummaryFlag, sval); 
00436     if (sval.size() > 0) fval3 = atof(sval.c_str());
00437 
00438     det_summary_str << std::setw(7) << " % of good detectors " << fval1
00439                     << " SToN Flag           " << fval2
00440                     << " Summary Flag        " << fval3 << std::endl;
00441   }
00442   std::cout << det_summary_str.str() << std::endl;
00443 }
00444 //
00445 // -- Get Module Status from Layer Level Histograms
00446 //
00447 void SiStripQualityChecker::getModuleStatus(std::vector<MonitorElement*>& layer_mes,int& errdet) { 
00448   
00449   std::string lname;
00450   std::map<uint32_t,uint16_t> bad_modules;
00451   for (std::vector<MonitorElement*>::const_iterator it = layer_mes.begin();
00452        it != layer_mes.end(); it++) {
00453     MonitorElement * me = (*it);
00454     if (!me) continue;
00455     std::vector<QReport *> qreports = me->getQReports();
00456     if (qreports.size() == 0) continue;
00457     std::string name = me->getName();
00458     std::vector<DQMChannel>  bad_channels_me;
00459     if (me->kind() == MonitorElement::DQM_KIND_TPROFILE) {
00460       bad_channels_me = qreports[0]->getBadChannels();
00461       lname = "";
00462     } else if (me->kind() == MonitorElement::DQM_KIND_TPROFILE2D && name.find("TkHMap") != std::string::npos) {
00463       bad_channels_me = qreports[0]->getBadChannels();
00464       lname = name.substr(name.find("TkHMap_")+7);
00465       lname = lname.substr(lname.find("_T")+1);
00466 
00467     }
00468     for (std::vector<DQMChannel>::iterator it = bad_channels_me.begin(); it != bad_channels_me.end(); it++){
00469       int xval = (*it).getBinX();
00470       int yval = (*it).getBinY();
00471       uint32_t detId = tkDetMap_->getDetFromBin(lname, xval, yval);       
00472       std::map<uint32_t,uint16_t>::iterator iPos = bad_modules.find(detId);
00473       uint16_t flag;
00474       if (iPos != bad_modules.end()){
00475         flag = iPos->second;
00476         SiStripUtility::setBadModuleFlag(name,flag);            
00477         iPos->second = flag;
00478       } else {
00479         flag = 0;
00480         SiStripUtility::setBadModuleFlag(name,flag);              
00481         bad_modules.insert(std::pair<uint32_t,uint16_t>(detId,flag));
00482       }
00483     }
00484   }
00485   for(std::map<uint32_t,uint16_t>::const_iterator it = bad_modules.begin();
00486       it != bad_modules.end(); it++) {
00487     uint32_t detId = it->first;
00488     uint16_t flag  = it->second;
00489     std::map<uint32_t,uint16_t>::iterator iPos = badModuleList.find(detId);
00490     if (iPos != badModuleList.end()){
00491       iPos->second = flag;
00492     } else {
00493       badModuleList.insert(std::pair<uint32_t,uint16_t>(detId,flag));
00494     }
00495   }    
00496   errdet = bad_modules.size();  
00497 }
00498 //
00499 // -- Fill Report Summary Map
00500 //
00501  void SiStripQualityChecker::fillStatusHistogram(MonitorElement* me, int xbin, int ybin, float val){
00502    if (me &&  me->kind() == MonitorElement::DQM_KIND_TH2F) {
00503      TH2F*  th2d = me->getTH2F();
00504      th2d->SetBinContent(xbin, ybin, val);
00505    }
00506  }
00507 //
00508 // -- Create Monitor Elements for Modules
00509 //
00510 void SiStripQualityChecker::fillFaultyModuleStatus(DQMStore* dqm_store) {
00511   if (badModuleList.size() == 0) return;
00512   dqm_store->cd();
00513   std::string mdir = "MechanicalView";
00514   if (!SiStripUtility::goToDir(dqm_store, mdir)) return;
00515   std::string mechanical_dir = dqm_store->pwd();
00516 
00517   SiStripFolderOrganizer folder_organizer;
00518   for (std::map<uint32_t,uint16_t>::const_iterator it =  badModuleList.begin() ; it != badModuleList.end(); it++) {
00519     uint32_t detId =  it->first;
00520     std::string subdet_folder ;
00521     folder_organizer.getSubDetFolder(detId,subdet_folder);
00522     if (!dqm_store->dirExists(subdet_folder)) {
00523       subdet_folder = mechanical_dir + subdet_folder.substr(subdet_folder.find("MechanicalView")+14);
00524       if (!dqm_store->dirExists(subdet_folder)) continue;
00525     }
00526     std::string bad_module_folder = subdet_folder + "/" + "BadModuleList";
00527     dqm_store->setCurrentFolder(bad_module_folder);
00528 
00529     std::ostringstream detid_str;
00530     detid_str << detId;
00531     std::string full_path = bad_module_folder + "/" + detid_str.str();
00532     MonitorElement* me = dqm_store->get(full_path);
00533     if (me) me->Reset();
00534     else me = dqm_store->bookInt(detid_str.str());
00535     me->Fill(it->second);
00536   }
00537   dqm_store->cd();
00538 }
00539 //
00540 // -- Initialise Bad Module List
00541 //
00542 void SiStripQualityChecker::initialiseBadModuleList() {
00543   for (std::map<uint32_t,uint16_t>::iterator it=badModuleList.begin(); it!=badModuleList.end(); it++) {
00544     it->second = 0;
00545   }
00546 }
00547 //
00548 // -- Fill Status information and the lumi block
00549 //
00550 void SiStripQualityChecker::fillStatusAtLumi(DQMStore* dqm_store){
00551   if (!bookedStripStatus_ || !bookedTrackingStatus_) bookStatus(dqm_store);
00552   fillDummyStatus();
00553   fillDetectorStatusAtLumi(dqm_store);
00554   fillTrackingStatusAtLumi(dqm_store);
00555 }
00556 //
00557 // Fill Detector Status MEs at the Lumi block
00558 // 
00559 void SiStripQualityChecker::fillDetectorStatusAtLumi(DQMStore* dqm_store){
00560   dqm_store->cd();
00561   std::string rdir = "ReadoutView"; 
00562   if (!SiStripUtility::goToDir(dqm_store, rdir)) return;
00563   std::string fullpath = dqm_store->pwd() 
00564                           + "/FedMonitoringSummary/"
00565                           + "lumiErrorFraction";  
00566   MonitorElement* me = dqm_store->get(fullpath);
00567   if (me && me->kind() == MonitorElement::DQM_KIND_TH1F) {
00568     TH1F* th1 = me->getTH1F(); 
00569     float global_fraction = 0.0;
00570     float dets = 0.0;
00571     for (int ibin = 1; ibin <= th1->GetNbinsX(); ibin++) {
00572       std::string label = th1->GetXaxis()->GetBinLabel(ibin);
00573       std::map<std::string, SubDetMEs>::iterator iPos = SubDetMEsMap.find(label);
00574       if (iPos != SubDetMEsMap.end()) {
00575         float fraction = 1.0 - th1->GetBinContent(ibin);
00576         global_fraction +=  fraction;
00577         dets++; 
00578         iPos->second.DetFraction->Fill(fraction);
00579         iPos->second.SToNFlag->Fill(-1.0);
00580         iPos->second.SummaryFlag->Fill(fraction);
00581       }
00582     }
00583     global_fraction = global_fraction/dets;
00584     if (SummaryReportGlobal) SummaryReportGlobal->Fill(global_fraction);    
00585   }
00586   dqm_store->cd();
00587 }
00588 //
00589 // Fill Tracking Status MEs at the Lumi block
00590 // 
00591 void SiStripQualityChecker::fillTrackingStatusAtLumi(DQMStore* dqm_store){
00592   dqm_store->cd();
00593   std::string dir = "Tracking"; 
00594   if (!SiStripUtility::goToDir(dqm_store, dir)) return;
00595   dir = "TrackParameters"; 
00596   if (!SiStripUtility::goToDir(dqm_store, dir)) return;
00597   
00598   std::vector<MonitorElement*> meVec1 = dqm_store->getContents(dqm_store->pwd()+"/GeneralProperties");
00599   std::vector<MonitorElement*> meVec2 = dqm_store->getContents(dqm_store->pwd()+"/HitProperties");
00600   std::vector<MonitorElement*> meVec(meVec1.size() + meVec2.size()); 
00601   std::merge(meVec1.begin(), meVec1.end(), meVec2.begin(), meVec2.end(), meVec.begin());
00602   float gstatus = 1.0;
00603   for (std::vector<MonitorElement*>::const_iterator it = meVec.begin(); it != meVec.end(); it++) {
00604     MonitorElement * me = (*it);     
00605     if (!me) continue;     
00606     std::string name = me->getName();
00607 
00608     float status = -1.0; 
00609     int ibin = 0;
00610     for (std::map<std::string, TrackingMEs>::const_iterator it = TrackingMEsMap.begin();
00611          it != TrackingMEsMap.end(); it++) {
00612       ibin++;
00613       std::string hname = it->second.HistoName;
00614       float lower_cut = it->second.LowerCut; 
00615       float upper_cut = it->second.UpperCut; 
00616       if (name.find(hname) != std::string::npos) {
00617         if (me->getMean() <= lower_cut || me->getMean() > upper_cut) status = 0.0;
00618         else status = 1.0; 
00619         it->second.TrackingFlag->Fill(status);
00620         fillStatusHistogram(TrackSummaryReportMap, ibin, 1, status);
00621         break;
00622       }
00623     }
00624     if (status == -1.0) gstatus = -1.0;
00625     else gstatus = gstatus * status; 
00626   }
00627   TrackSummaryReportGlobal->Fill(gstatus);
00628   dqm_store->cd();
00629 }