CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/DQM/SiPixelMonitorClient/src/SiPixelDataQuality.cc

Go to the documentation of this file.
00001 
00007 #include "DQM/SiPixelMonitorClient/interface/SiPixelDataQuality.h"
00008 #include "DQM/SiPixelMonitorClient/interface/SiPixelUtility.h"
00009 #include "DQM/SiPixelMonitorClient/interface/SiPixelEDAClient.h"
00010 #include "DQM/SiPixelMonitorClient/interface/ANSIColors.h"
00011 #include "DQM/SiPixelMonitorClient/interface/SiPixelHistoPlotter.h"
00012 #include "DQM/SiPixelCommon/interface/SiPixelFolderOrganizer.h"
00013 
00014 #include "DQMServices/Core/interface/DQMStore.h"
00015 #include "DQMServices/Core/interface/MonitorElement.h"
00016 #include "DQM/TrackerCommon/interface/CgiReader.h"
00017 
00018 #include "FWCore/ParameterSet/interface/FileInPath.h"
00019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00020 
00021 #include "DataFormats/DetId/interface/DetId.h"
00022 #include "DataFormats/GeometrySurface/interface/Surface.h"
00023 #include "DataFormats/SiPixelDetId/interface/PixelBarrelName.h"
00024 #include "DataFormats/SiPixelDetId/interface/PixelEndcapName.h"
00025 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00026 
00027 #include "CondFormats/SiPixelObjects/interface/DetectorIndex.h"
00028 #include "CondFormats/SiPixelObjects/interface/SiPixelFrameConverter.h"
00029 
00030 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
00031 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00032 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00033 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00034 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
00035 
00036 #include "TClass.h"
00037 #include "TText.h"
00038 #include "TROOT.h"
00039 #include "TPad.h"
00040 #include "TStyle.h"
00041 #include "TSystem.h"
00042 #include "TString.h"
00043 #include "TImage.h"
00044 #include "TPaveText.h"
00045 #include "TImageDump.h"
00046 #include "TRandom.h"
00047 #include "TStopwatch.h"
00048 #include "TAxis.h"
00049 #include "TPaveLabel.h"
00050 #include "Rtypes.h"
00051 #include "TH1F.h"
00052 #include "TH2F.h"
00053 #include "TProfile.h"
00054 
00055 #include <iostream>
00056 #include <math.h>
00057 #include <map>
00058 
00059 #include <fstream>
00060 #include <cstdlib> // for free() - Root can allocate with malloc() - sigh...
00061  
00062 using namespace std;
00063 using namespace edm;
00064 
00065 //------------------------------------------------------------------------------
00069 SiPixelDataQuality::SiPixelDataQuality(bool offlineXMLfile) : offlineXMLfile_(offlineXMLfile) {
00070   edm::LogInfo("SiPixelDataQuality") << 
00071     " Creating SiPixelDataQuality " << "\n" ;
00072   
00073   allMods_=0;
00074   errorMods_=0;
00075   qflag_=1.;
00076 
00077   allmodsMap=0;
00078   errmodsMap=0;
00079   goodmodsMap=0;
00080   allmodsVec=0;
00081   errmodsVec=0;
00082   goodmodsVec=0;
00083   for (int i = 0; i < 40; ++i)
00084     {lastallmods_[i] = 0; lasterrmods_[i] = 0;}
00085   timeoutCounter_=0;
00086   lastLS_=-1;
00087 }
00088 
00089 //------------------------------------------------------------------------------
00093 SiPixelDataQuality::~SiPixelDataQuality() {
00094   edm::LogInfo("SiPixelDataQuality") << 
00095     " Deleting SiPixelDataQuality " << "\n" ;
00096   if(allmodsMap) delete allmodsMap;
00097   if(errmodsMap) delete errmodsMap;
00098   if(goodmodsMap) delete goodmodsMap;
00099   if(allmodsVec) delete allmodsVec;
00100   if(errmodsVec) delete errmodsVec;
00101   if(goodmodsVec) delete goodmodsVec;
00102 }
00103 
00104 
00105 //------------------------------------------------------------------------------
00110 int SiPixelDataQuality::getDetId(MonitorElement * mE) 
00111 {
00112  string mEName = mE->getName() ;
00113 
00114  int detId = 0;
00115  
00116  if( mEName.find("_3") != string::npos )
00117  {
00118   string detIdString = mEName.substr((mEName.find_last_of("_"))+1,9);
00119   std::istringstream isst;
00120   isst.str(detIdString);
00121   isst>>detId;
00122 // } else {
00123 //  cout << ACYellow << ACBold
00124 //       << "[SiPixelInformationExtractor::getDetId()] "
00125 //       << ACPlain
00126 //       << "Could not extract detId from "
00127 //       << mEName
00128 //       << endl ;
00129  }
00130       
00131   return detId ;
00132   
00133 }
00134 
00136 
00137 void SiPixelDataQuality::bookGlobalQualityFlag(DQMStore * bei, bool Tier0Flag, int nFEDs) {
00138 //std::cout<<"BOOK GLOBAL QUALITY FLAG MEs!"<<std::endl;
00139   bei->cd();
00140 
00141   bei->setCurrentFolder("Pixel/Barrel");
00142   if(!Tier0Flag){
00143     ClusterModAll = bei->book1D("NClustertoChargeRatio_AllMod","Cluster Noise All Modules", 768, 0., 768.);
00144     ClusterMod1   = bei->book1D("NClustertoChargeRatio_NormMod1",  "Normalized N_{Clusters} to Charge Ratio per Module1", 192, 0., 192.);
00145     ClusterMod2   = bei->book1D("NClustertoChargeRatio_NormMod2",  "Normalized N_{Clusters} to Charge Ratio per Module2", 192, 0., 192.);
00146     ClusterMod3   = bei->book1D("NClustertoChargeRatio_NormMod3",  "Normalized N_{Clusters} to Charge Ratio per Module3", 192, 0., 192.);
00147     ClusterMod4   = bei->book1D("NClustertoChargeRatio_NormMod4",  "Normalized N_{Clusters} to Charge Ratio per Module4", 192, 0., 192.);
00148   } 
00149   bei->setCurrentFolder("Pixel/EventInfo");
00150   if(!Tier0Flag){
00151     /*SummaryReportMap = bei->book2D("reportSummaryMap","Pixel Summary Map",40,0.,40.,36,1.,37.);
00152     SummaryReportMap->setAxisTitle("Pixel FED #",1);
00153     SummaryReportMap->setAxisTitle("Pixel FED Channel #",2);
00154     allmodsMap = new TH2F("allmodsMap","allmodsMap",40,0.,40.,36,1.,37.);
00155     errmodsMap = new TH2F("errmodsMap","errmodsMap",40,0.,40.,36,1.,37.);
00156     goodmodsMap = new TH2F("goodmodsMap","goodmodsMap",40,0.,40.,36,1.,37.);
00157     */
00158     SummaryReportMap = bei->book2D("reportSummaryMap","Pixel Summary Map",3000,0.,3000.,40,0.,40.);
00159     SummaryReportMap->setAxisTitle("Lumi Section",1);
00160     SummaryReportMap->setAxisTitle("Pixel FED #",2);
00161     allmodsVec = new TH1D("allmodsVec","allmodsVec",40,0.,40.);
00162     errmodsVec = new TH1D("errmodsVec","errmodsVec",40,0.,40.);
00163     goodmodsVec = new TH1D("goodmodsVec","goodmodsVec",40,0.,40.);
00164   }else{
00165     SummaryReportMap = bei->book2D("reportSummaryMap","Pixel Summary Map",2,0.,2.,7,0.,7.);
00166     SummaryReportMap->setBinLabel(1,"Barrel",1);
00167     SummaryReportMap->setBinLabel(2,"Endcaps",1);
00168     SummaryReportMap->setBinLabel(1,"Errors",2);
00169     SummaryReportMap->setBinLabel(2,"NDigis",2);
00170     SummaryReportMap->setBinLabel(3,"DigiCharge",2);
00171     SummaryReportMap->setBinLabel(4,"ClusterSize",2);
00172     SummaryReportMap->setBinLabel(5,"NClusters",2);
00173     SummaryReportMap->setBinLabel(6,"ClusterCharge",2);
00174     SummaryReportMap->setBinLabel(7,"HitEff",2);
00175     allmodsMap = new TH2F("allmodsMap","allmodsMap",2,0.,2.,7,0.,7.);
00176     errmodsMap = new TH2F("errmodsMap","errmodsMap",2,0.,2.,7,0.,7.);
00177     goodmodsMap = new TH2F("goodmodsMap","goodmodsMap",2,0.,2.,7,0.,7.);
00178   }  
00179     SummaryPixel = bei->bookFloat("reportSummary");
00180   bei->setCurrentFolder("Pixel/EventInfo/reportSummaryContents");
00181     SummaryBarrel = bei->bookFloat("PixelBarrelFraction");
00182     SummaryEndcap = bei->bookFloat("PixelEndcapFraction");
00183   // book the data certification cuts:
00184   bei->setCurrentFolder("Pixel/AdditionalPixelErrors");
00185     NErrorsFEDs = bei->bookFloat("FEDsNErrorsCut");
00186   bei->setCurrentFolder("Pixel/Barrel");
00187     NErrorsBarrel = bei->bookFloat("BarrelNErrorsCut");
00188     NDigisBarrel = bei->bookInt("BarrelNDigisCut");
00189     DigiChargeBarrel = bei->bookInt("BarrelDigiChargeCut");
00190     ClusterSizeBarrel = bei->bookInt("BarrelClusterSizeCut");
00191     NClustersBarrel = bei->bookInt("BarrelNClustersCut");
00192     ClusterChargeBarrel = bei->bookInt("BarrelClusterChargeCut");
00193   bei->setCurrentFolder("Pixel/Endcap");
00194     NErrorsEndcap = bei->bookFloat("EndcapNErrorsCut");
00195     NDigisEndcap = bei->bookInt("EndcapNDigisCut");
00196     DigiChargeEndcap = bei->bookInt("EndcapDigiChargeCut");
00197     ClusterSizeEndcap = bei->bookInt("EndcapClusterSizeCut");
00198     NClustersEndcap = bei->bookInt("EndcapNClustersCut");
00199     ClusterChargeEndcap = bei->bookInt("EndcapClusterChargeCut");
00200   if(Tier0Flag){
00201     bei->setCurrentFolder("Pixel/Tracks");
00202       NPixelTracks = bei->bookInt("PixelTracksCut");
00203   }
00204     
00205     // Init MonitoringElements:
00206     if(nFEDs>0){
00207       SummaryPixel = bei->get("Pixel/EventInfo/reportSummary");
00208       if(SummaryPixel) SummaryPixel->Fill(1.);
00209       SummaryBarrel = bei->get("Pixel/EventInfo/reportSummaryContents/PixelBarrelFraction");
00210       if(SummaryBarrel) SummaryBarrel->Fill(1.);
00211       SummaryEndcap = bei->get("Pixel/EventInfo/reportSummaryContents/PixelEndcapFraction");
00212       if(SummaryEndcap) SummaryEndcap->Fill(1.);
00213     }else{
00214       SummaryPixel = bei->get("Pixel/EventInfo/reportSummary");
00215       if(SummaryPixel) SummaryPixel->Fill(-1.);
00216       SummaryBarrel = bei->get("Pixel/EventInfo/reportSummaryContents/PixelBarrelFraction");
00217       if(SummaryBarrel) SummaryBarrel->Fill(-1.);
00218       SummaryEndcap = bei->get("Pixel/EventInfo/reportSummaryContents/PixelEndcapFraction");
00219       if(SummaryEndcap) SummaryEndcap->Fill(-1.);
00220     }
00221     NErrorsBarrel = bei->get("Pixel/Barrel/BarrelNErrorsCut");
00222     if(NErrorsBarrel) NErrorsBarrel->Fill(1.);
00223     NErrorsEndcap = bei->get("Pixel/Endcap/EndcapNErrorsCut");
00224     if(NErrorsEndcap) NErrorsEndcap->Fill(1.);
00225     NErrorsFEDs = bei->get("Pixel/AdditionalPixelErrors/FEDsNErrorsCut");
00226     if(NErrorsFEDs) NErrorsFEDs->Fill(1.);
00227     NDigisBarrel = bei->get("Pixel/Barrel/BarrelNDigisCut");
00228     if(NDigisBarrel) NDigisBarrel->Fill(1);
00229     NDigisEndcap = bei->get("Pixel/Endcap/EndcapNDigisCut");
00230     if(NDigisEndcap) NDigisEndcap->Fill(1);
00231     DigiChargeBarrel = bei->get("Pixel/Barrel/BarrelDigiChargeCut");
00232     if(DigiChargeBarrel) DigiChargeBarrel->Fill(1);
00233     DigiChargeEndcap = bei->get("Pixel/Endcap/EndcapDigiChargeCut");
00234     if(DigiChargeEndcap) DigiChargeEndcap->Fill(1);
00235     ClusterSizeBarrel = bei->get("Pixel/Barrel/BarrelClusterSizeCut");
00236     if(ClusterSizeBarrel) ClusterSizeBarrel->Fill(1);
00237     ClusterSizeEndcap = bei->get("Pixel/Endcap/EndcapClusterSizeCut");
00238     if(ClusterSizeEndcap) ClusterSizeEndcap->Fill(1);
00239     ClusterChargeBarrel = bei->get("Pixel/Barrel/BarrelClusterChargeCut");
00240     if(ClusterChargeBarrel) ClusterChargeBarrel->Fill(1);
00241     ClusterChargeEndcap = bei->get("Pixel/Endcap/EndcapClusterChargeCut");
00242     if(ClusterChargeEndcap) ClusterChargeEndcap->Fill(1);
00243     NClustersBarrel = bei->get("Pixel/Barrel/BarrelNClustersCut");
00244     if(NClustersBarrel) NClustersBarrel->Fill(1);
00245     NClustersEndcap = bei->get("Pixel/Endcap/EndcapNClustersCut");
00246     if(NClustersEndcap) NClustersEndcap->Fill(1);
00247     if(Tier0Flag){
00248       NPixelTracks = bei->get("Pixel/Tracks/PixelTracksCut");
00249       if(NPixelTracks) NPixelTracks->Fill(1);
00250     }
00251    
00252     SummaryReportMap = bei->get("Pixel/EventInfo/reportSummaryMap");
00253     if(SummaryReportMap){
00254       if(!Tier0Flag) for(int i=1; i!=3001; i++) for(int j=1; j!=41; j++) SummaryReportMap->setBinContent(i,j,-1.);
00255       if(Tier0Flag) for(int i=1; i!=3; i++) for(int j=1; j!=8; j++) SummaryReportMap->setBinContent(i,j,-1.);
00256     }
00257     if(!Tier0Flag){
00258       for(int j=1; j!=41; j++){
00259         if(allmodsVec) allmodsVec->SetBinContent(j,0.);
00260         if(errmodsVec) errmodsVec->SetBinContent(j,0.);
00261         if(goodmodsVec) goodmodsVec->SetBinContent(j,0.);
00262       }
00263     }
00264     if(Tier0Flag){
00265       for(int i=1; i!=3; i++) for(int j=1; j!=8; j++){
00266         if(allmodsMap) allmodsMap->SetBinContent(i,j,0.);
00267         if(errmodsMap) errmodsMap->SetBinContent(i,j,0.);
00268         if(goodmodsMap) goodmodsMap->SetBinContent(i,j,0.);
00269       }
00270     }
00271     
00272   bei->cd();  
00273 }
00274 
00275 //**********************************************************************************************
00276 
00277 void SiPixelDataQuality::computeGlobalQualityFlag(DQMStore * bei, 
00278                                                            bool init,
00279                                                            int nFEDs,
00280                                                            bool Tier0Flag){
00281 //cout<<"entering SiPixelDataQuality::ComputeGlobalQualityFlag"<<endl;
00282 //   cout << ACRed << ACBold
00283 //        << "[SiPixelDataQuality::ComputeGlobalQualityFlag]"
00284 //        << ACPlain
00285 //        << " Enter" 
00286 //        << endl ;
00287   if(init){
00288 //cout<<"Entering SiPixelDataQuality::computeGlobalQualityFlag for the first time"<<endl;
00289     allMods_=0; errorMods_=0; qflag_=0.; 
00290     barrelMods_=0; endcapMods_=0;
00291     objectCount_=0;
00292     DONE_ = false;
00293     
00294     //Error counters and flags:
00295     n_errors_barrel_=0; barrel_error_flag_=0.;
00296     n_errors_endcap_=0; endcap_error_flag_=0.;
00297     n_errors_pixel_=0; pixel_error_flag_=0.;
00298     digiStatsBarrel = false, clusterStatsBarrel = false, trackStatsBarrel = false;
00299     digiCounterBarrel = 0, clusterCounterBarrel = 0, trackCounterBarrel = 0;
00300     digiStatsEndcap = false, clusterStatsEndcap = false, trackStatsEndcap = false;
00301     digiCounterEndcap = 0, clusterCounterEndcap = 0, trackCounterEndcap = 0;
00302     init=false;
00303   }
00304   if(nFEDs==0) return;  
00305   
00306   string currDir = bei->pwd();
00307   string dname = currDir.substr(currDir.find_last_of("/")+1);
00308 //cout<<"currDir="<<currDir<<endl;
00309   
00310   if((!Tier0Flag && dname.find("Module_")!=string::npos) || 
00311      (Tier0Flag && (dname.find("Ladder_")!=string::npos || dname.find("Blade_")!=string::npos))){
00312 
00313     objectCount_++;
00314 
00315     if(currDir.find("Pixel")!=string::npos) allMods_++;
00316     if(currDir.find("Barrel")!=string::npos) barrelMods_++;
00317     if(currDir.find("Endcap")!=string::npos) endcapMods_++;
00318     vector<string> meVec = bei->getMEs();
00319     for (vector<string>::const_iterator it = meVec.begin(); it != meVec.end(); it++) {
00320       string full_path = currDir + "/" + (*it);
00321       //cout<<"full_path:"<<full_path<<endl;
00322       if(full_path.find("ndigis_")!=string::npos){
00323       //cout<<"found an ndigi histo now"<<endl;
00324         MonitorElement * me = bei->get(full_path);
00325         if(!me) continue;
00326         //cout<<"got the histo now"<<endl;
00327         if(me->getEntries()>25){
00328         //cout<<"histo has more than 50 entries"<<endl;
00329           if(full_path.find("Barrel")!=string::npos) digiCounterBarrel++;
00330           if(full_path.find("Endcap")!=string::npos) digiCounterEndcap++;
00331           //cout<<"counter are now: "<<digiCounterBarrel<<","<<digiCounterBarrelL1<<endl;
00332         }
00333       }else if(Tier0Flag && full_path.find("nclusters_OnTrack_")!=string::npos){
00334         MonitorElement * me = bei->get(full_path);
00335         if(!me) continue;
00336         if(me->getEntries()>25){
00337           if(full_path.find("Barrel")!=string::npos) clusterCounterBarrel++;
00338           if(full_path.find("Endcap")!=string::npos) clusterCounterEndcap++;
00339         }
00340       }else if(!Tier0Flag && full_path.find("nclusters_")!=string::npos){
00341         MonitorElement * me = bei->get(full_path);
00342         if(!me) continue;
00343         if(me->getEntries()>25){
00344           if(full_path.find("Barrel")!=string::npos) clusterCounterBarrel++;
00345           if(full_path.find("Endcap")!=string::npos) clusterCounterEndcap++;
00346         }
00347       }
00348     }
00349   }
00350   vector<string> subDirVec = bei->getSubdirs();  
00351   for (vector<string>::const_iterator ic = subDirVec.begin();
00352        ic != subDirVec.end(); ic++) {
00353     bei->cd(*ic);
00354     init=false;
00355     computeGlobalQualityFlag(bei,init,nFEDs,Tier0Flag);
00356     bei->goUp();
00357   }
00358   
00359   // Make sure I have finished looping over all Modules/Ladders/Blades:
00360   if(!Tier0Flag){ // online case
00361     if(objectCount_ == 1440) DONE_ = true;
00362   }else{ // offline case
00363     if(objectCount_ == 288) DONE_ = true;
00364   } 
00365   
00366   if(DONE_ && currDir=="Pixel/EventInfo/reportSummaryContents"){ 
00367 
00368   // Evaluate error flag now, only stored in AdditionalPixelErrors:
00369   MonitorElement * me_err = bei->get("Pixel/AdditionalPixelErrors/FedETypeNErrArray");
00370   MonitorElement * me_evt = bei->get("Pixel/EventInfo/processedEvents");
00371   if(me_err && me_evt){
00372     for(int i=1; i!=41; i++)for(int j=1; j!=22; j++)
00373       if(me_err->getBinContent(i,j)>0){
00374         n_errors_pixel_=n_errors_pixel_+int(me_err->getBinContent(i,j));
00375         if(i<33) n_errors_barrel_=n_errors_barrel_+int(me_err->getBinContent(i,j));
00376         if(i>32) n_errors_endcap_=n_errors_endcap_+int(me_err->getBinContent(i,j));
00377       }
00378     int NProcEvts = me_evt->getIntValue();
00379     if(NProcEvts>0){
00380       barrel_error_flag_ = (float(NProcEvts)-float(n_errors_barrel_))/float(NProcEvts);
00381       endcap_error_flag_ = (float(NProcEvts)-float(n_errors_endcap_))/float(NProcEvts);
00382       pixel_error_flag_ = (float(NProcEvts)-float(n_errors_barrel_)-float(n_errors_endcap_))/float(NProcEvts);
00383     }
00384   }
00385   NErrorsBarrel = bei->get("Pixel/Barrel/BarrelNErrorsCut");
00386   if(NErrorsBarrel) NErrorsBarrel->Fill(barrel_error_flag_);
00387   NErrorsEndcap = bei->get("Pixel/Endcap/EndcapNErrorsCut");
00388   if(NErrorsEndcap)   NErrorsEndcap->Fill(endcap_error_flag_);
00389   
00390   string meName0;
00391   MonitorElement * me;
00392   
00393   // Fill the Digi flags:
00394   if(!Tier0Flag){
00395     meName0 = "Pixel/Barrel/SUMDIG_ndigis_Barrel";
00396     if(digiCounterBarrel/768 > 0.5) digiStatsBarrel = true;
00397     if(digiCounterEndcap/672 > 0.5) digiStatsEndcap = true;
00398     //cout<<"digiStatsBarrel="<<digiStatsBarrel<<" , digiStatsEndcap="<<digiStatsEndcap<<endl;
00399   }else{
00400     meName0 = "Pixel/Barrel/SUMOFF_ndigis_Barrel"; 
00401     if(digiCounterBarrel/192 > 0.5) digiStatsBarrel = true;
00402     if(digiCounterEndcap/96 > 0.5) digiStatsEndcap = true;
00403   }
00404   me = bei->get(meName0);
00405   if(me){
00406     NDigisBarrel = bei->get("Pixel/Barrel/BarrelNDigisCut");
00407    // cout<<"NDigis: "<<NDigisBarrel<<" , "<<digiStatsBarrel<<" , "<<me->hasError()<<endl;
00408     if(NDigisBarrel && digiStatsBarrel){
00409       if(me->hasError()) NDigisBarrel->Fill(0);
00410       else NDigisBarrel->Fill(1); 
00411     }
00412   }
00413   if(!Tier0Flag) meName0 = "Pixel/Endcap/SUMDIG_ndigis_Endcap";
00414   else meName0 = "Pixel/Endcap/SUMOFF_ndigis_Endcap"; 
00415   me = bei->get(meName0);
00416   if(me){
00417     NDigisEndcap = bei->get("Pixel/Endcap/EndcapNDigisCut");
00418     if(NDigisEndcap && digiStatsEndcap){
00419       if(me->hasError()) NDigisEndcap->Fill(0);
00420       else NDigisEndcap->Fill(1);
00421     }
00422   }
00423   if(!Tier0Flag) meName0 = "Pixel/Barrel/SUMDIG_adc_Barrel";
00424   else meName0 = "Pixel/Barrel/SUMOFF_adc_Barrel"; 
00425   me = bei->get(meName0);
00426   if(me){
00427     DigiChargeBarrel = bei->get("Pixel/Barrel/BarrelDigiChargeCut");
00428     if(DigiChargeBarrel && digiStatsBarrel){
00429       if(me->hasError()) DigiChargeBarrel->Fill(0);
00430       else DigiChargeBarrel->Fill(1);
00431     }
00432   }
00433   if(!Tier0Flag) meName0 = "Pixel/Endcap/SUMDIG_adc_Endcap";
00434   else meName0 = "Pixel/Endcap/SUMOFF_adc_Endcap"; 
00435   me = bei->get(meName0);
00436   if(me){
00437     DigiChargeEndcap = bei->get("Pixel/Endcap/EndcapDigiChargeCut");
00438     if(DigiChargeEndcap && digiStatsEndcap){
00439       if(me->hasError()) DigiChargeEndcap->Fill(0);
00440       else DigiChargeEndcap->Fill(1);
00441     }
00442   }
00443      
00444      
00445     // Fill the Cluster flags:
00446   if(!Tier0Flag){
00447     meName0 = "Pixel/Barrel/SUMCLU_size_Barrel";
00448     if(clusterCounterBarrel/768 > 0.5) clusterStatsBarrel = true;
00449     if(clusterCounterEndcap/672 > 0.5) clusterStatsEndcap = true;
00450   }else{
00451     meName0 = "Pixel/Barrel/SUMOFF_size_OnTrack_Barrel"; 
00452     if(clusterCounterBarrel/192 > 0.5) clusterStatsBarrel = true;
00453     if(clusterCounterEndcap/96 > 0.5) clusterStatsEndcap = true;
00454   }
00455   me = bei->get(meName0);
00456   if(me){
00457     ClusterSizeBarrel = bei->get("Pixel/Barrel/BarrelClusterSizeCut");
00458     if(ClusterSizeBarrel && clusterStatsBarrel){
00459       if(me->hasError()) ClusterSizeBarrel->Fill(0);
00460       else ClusterSizeBarrel->Fill(1);
00461     }
00462   }
00463   if(!Tier0Flag) meName0 = "Pixel/Endcap/SUMCLU_size_Endcap";
00464   else meName0 = "Pixel/Endcap/SUMOFF_size_OnTrack_Endcap"; 
00465   me = bei->get(meName0);
00466   if(me){
00467     ClusterSizeEndcap = bei->get("Pixel/Endcap/EndcapClusterSizeCut");
00468     if(ClusterSizeEndcap && clusterStatsEndcap){
00469       if(me->hasError()) ClusterSizeEndcap->Fill(0);
00470       else ClusterSizeEndcap->Fill(1);
00471     }
00472   }
00473   if(!Tier0Flag) meName0 = "Pixel/Barrel/SUMCLU_charge_Barrel";
00474   else meName0 = "Pixel/Barrel/SUMOFF_charge_OnTrack_Barrel"; 
00475   me = bei->get(meName0);
00476   if(me){
00477     ClusterChargeBarrel = bei->get("Pixel/Barrel/BarrelClusterChargeCut");
00478     if(ClusterChargeBarrel && clusterStatsBarrel){
00479       if(me->hasError()) ClusterChargeBarrel->Fill(0);
00480       else ClusterChargeBarrel->Fill(1);
00481     }
00482   }
00483   if(!Tier0Flag) meName0 = "Pixel/Endcap/SUMCLU_charge_Endcap";
00484   else meName0 = "Pixel/Endcap/SUMOFF_charge_OnTrack_Endcap"; 
00485   me = bei->get(meName0);
00486   if(me){
00487     ClusterChargeEndcap = bei->get("Pixel/Endcap/EndcapClusterChargeCut");
00488     if(ClusterChargeEndcap && clusterStatsEndcap){
00489       if(me->hasError()) ClusterChargeEndcap->Fill(0);
00490       else ClusterChargeEndcap->Fill(1);
00491     }
00492   }
00493   if(!Tier0Flag) meName0 = "Pixel/Barrel/SUMCLU_nclusters_Barrel";
00494   else meName0 = "Pixel/Barrel/SUMOFF_nclusters_OnTrack_Barrel"; 
00495   me = bei->get(meName0);
00496   if(me){
00497     NClustersBarrel = bei->get("Pixel/Barrel/BarrelNClustersCut");
00498     if(NClustersBarrel && clusterStatsBarrel){
00499       if(me->hasError()) NClustersBarrel->Fill(0);
00500       else NClustersBarrel->Fill(1);
00501     }
00502   }
00503   if(!Tier0Flag) meName0 = "Pixel/Endcap/SUMCLU_nclusters_Endcap";
00504   else meName0 = "Pixel/Endcap/SUMOFF_nclusters_OnTrack_Endcap"; 
00505   me = bei->get(meName0);
00506   if(me){
00507     NClustersEndcap = bei->get("Pixel/Endcap/EndcapNClustersCut");
00508     if(NClustersEndcap && clusterStatsEndcap){
00509       if(me->hasError()) NClustersEndcap->Fill(0);
00510       else NClustersEndcap->Fill(1);
00511     }
00512   }
00513   // Pixel Track multiplicity / Pixel hit efficiency
00514   meName0 = "Pixel/Tracks/ntracks_generalTracks";
00515   me = bei->get(meName0);
00516   if(me){
00517     NPixelTracks = bei->get("Pixel/Tracks/PixelTracksCut");
00518     if(NPixelTracks && me->getBinContent(1)>1000){
00519       if((float)me->getBinContent(2)/(float)me->getBinContent(1)<0.01){
00520         NPixelTracks->Fill(0);
00521       }else{ 
00522         NPixelTracks->Fill(1);
00523       }
00524     }
00525   }
00526   
00527   
00528 //********************************************************************************************************  
00529   
00530   // Final combination of all Data Quality results:
00531   float pixelFlag = -1., barrelFlag = -1., endcapFlag = -1.;
00532   float barrel_errors_temp[1]={-1.}; int barrel_cuts_temp[5]={5*-1}; 
00533   float endcap_errors_temp[1]={-1.}; int endcap_cuts_temp[5]={5*-1}; 
00534   int pixel_cuts_temp[1]={-1};
00535   float combinedCuts = 1.; int numerator = 0, denominator = 0;
00536 
00537   // Barrel results:
00538   me = bei->get("Pixel/Barrel/BarrelNErrorsCut");
00539   if(me) barrel_errors_temp[0] = me->getFloatValue();
00540   me = bei->get("Pixel/Barrel/BarrelNDigisCut");
00541   if(me) barrel_cuts_temp[0] = me->getIntValue();
00542   me = bei->get("Pixel/Barrel/BarrelDigiChargeCut");
00543   if(me) barrel_cuts_temp[1] = me->getIntValue();
00544   me = bei->get("Pixel/Barrel/BarrelClusterSizeCut");
00545   if(me) barrel_cuts_temp[2] = me->getIntValue();
00546   me = bei->get("Pixel/Barrel/BarrelNClustersCut");
00547   if(me) barrel_cuts_temp[3] = me->getIntValue();
00548   me = bei->get("Pixel/Barrel/BarrelClusterChargeCut");
00549   if(me) barrel_cuts_temp[4] = me->getIntValue();
00550   for(int k=0; k!=5; k++){
00551     if(barrel_cuts_temp[k]>=0){
00552       numerator = numerator + barrel_cuts_temp[k];
00553       denominator++;
00554       //cout<<"cut flag, Barrel: "<<k<<","<<barrel_cuts_temp[k]<<","<<numerator<<","<<denominator<<endl;
00555     }
00556   } 
00557   if(denominator!=0) combinedCuts = float(numerator)/float(denominator);  
00558   barrelFlag = barrel_errors_temp[0] * combinedCuts;
00559   
00560   
00561   //cout<<" the resulting barrel flag is: "<<barrel_errors_temp[0]<<"*"<<combinedCuts<<"="<<barrelFlag<<endl;
00562   
00563   // Endcap results:
00564   combinedCuts = 1.; numerator = 0; denominator = 0;
00565   me = bei->get("Pixel/Endcap/EndcapNErrorsCut");
00566   if(me) endcap_errors_temp[0] = me->getFloatValue();
00567   me = bei->get("Pixel/Endcap/EndcapNDigisCut");
00568   if(me) endcap_cuts_temp[0] = me->getIntValue();
00569   me = bei->get("Pixel/Endcap/EndcapDigiChargeCut");
00570   if(me) endcap_cuts_temp[1] = me->getIntValue();
00571   me = bei->get("Pixel/Endcap/EndcapClusterSizeCut");
00572   if(me) endcap_cuts_temp[2] = me->getIntValue();
00573   me = bei->get("Pixel/Endcap/EndcapNClustersCut");
00574   if(me) endcap_cuts_temp[3] = me->getIntValue();
00575   me = bei->get("Pixel/Endcap/EndcapClusterChargeCut");
00576   if(me) endcap_cuts_temp[4] = me->getIntValue();
00577   for(int k=0; k!=5; k++){
00578     if(endcap_cuts_temp[k]>=0){
00579       numerator = numerator + endcap_cuts_temp[k];
00580       denominator++;
00581       //cout<<"cut flag, Endcap: "<<k<<","<<endcap_cuts_temp[k]<<","<<numerator<<","<<denominator<<endl;
00582     }
00583   } 
00584   if(denominator!=0) combinedCuts = float(numerator)/float(denominator);  
00585   endcapFlag = endcap_errors_temp[0] * combinedCuts;
00586   //cout<<" the resulting endcap flag is: "<<endcap_errors_temp[0]<<"*"<<combinedCuts<<"="<<endcapFlag<<endl;
00587   
00588   // Track results:
00589   combinedCuts = 1.; numerator = 0; denominator = 0;
00590   me = bei->get("Pixel/Tracks/PixelTracksCut");
00591   if(me) pixel_cuts_temp[0] = me->getIntValue();
00592 
00593   //Combination of all:
00594   combinedCuts = 1.; numerator = 0; denominator = 0;
00595   for(int k=0; k!=5; k++){
00596     if(barrel_cuts_temp[k]>=0){
00597       numerator = numerator + barrel_cuts_temp[k];
00598       denominator++;
00599     }
00600     //cout<<"after barrel: num="<<numerator<<" , den="<<denominator<<endl;
00601     if(endcap_cuts_temp[k]>=0){
00602       numerator = numerator + endcap_cuts_temp[k];
00603       denominator++;
00604     }
00605     if(k<1 && pixel_cuts_temp[k]>=0){
00606       numerator = numerator + pixel_cuts_temp[k];
00607       denominator++;
00608     }
00609     //cout<<"after both: num="<<numerator<<" , den="<<denominator<<endl;
00610   } 
00611   if(denominator!=0) combinedCuts = float(numerator)/float(denominator); 
00612   pixelFlag = float(pixel_error_flag_) * float(combinedCuts);
00613   
00614   
00615   //cout<<"barrel, endcap, pixel flags: "<<barrelFlag<<","<<endcapFlag<<","<<pixelFlag<<endl;
00616   SummaryPixel = bei->get("Pixel/EventInfo/reportSummary");
00617   if(SummaryPixel) SummaryPixel->Fill(pixelFlag);
00618   SummaryBarrel = bei->get("Pixel/EventInfo/reportSummaryContents/PixelBarrelFraction");
00619   if(SummaryBarrel) SummaryBarrel->Fill(barrelFlag);
00620   SummaryEndcap = bei->get("Pixel/EventInfo/reportSummaryContents/PixelEndcapFraction");
00621   if(SummaryEndcap)   SummaryEndcap->Fill(endcapFlag);
00622   }
00623 }
00624 
00625 //**********************************************************************************************
00626 
00627 void SiPixelDataQuality::computeGlobalQualityFlagByLumi(DQMStore * bei, 
00628                                                            bool init,
00629                                                            int nFEDs,
00630                                                            bool Tier0Flag,
00631                                                            int nEvents_lastLS_,
00632                                                            int nErrorsBarrel_lastLS_,
00633                                                            int nErrorsEndcap_lastLS_){
00634 //cout<<"entering SiPixelDataQuality::ComputeGlobalQualityFlagByLumi"<<endl;
00635 //   cout << ACRed << ACBold
00636 //        << "[SiPixelDataQuality::ComputeGlobalQualityFlag]"
00637 //        << ACPlain
00638 //        << " Enter" 
00639 //        << endl ;
00640 
00641   if(nFEDs==0) return;  
00642   
00643   // evaluate fatal FED errors for data quality:
00644   float BarrelRate_LS = 1.;
00645   float EndcapRate_LS = 1.;
00646   float PixelRate_LS = 1.;
00647   MonitorElement * me = bei->get("Pixel/AdditionalPixelErrors/byLumiErrors");
00648   if(me){
00649     //cout<<"NENTRIES: "<<me->getEntries()<<" "<<nEvents_lastLS_<<" "<<nErrorsBarrel_lastLS_<<" "<<nErrorsEndcap_lastLS_<<endl;
00650     double nBarrelErrors_LS = me->getBinContent(1) - nErrorsBarrel_lastLS_;
00651     double nEndcapErrors_LS = me->getBinContent(2) - nErrorsEndcap_lastLS_;
00652     double nEvents_LS = me->getBinContent(0) - nEvents_lastLS_;
00653     //cout<<"BINS: "<<me->getBinContent(0)<<" "<<me->getBinContent(1)<<" "<<me->getBinContent(2)<<endl;
00654     if(nBarrelErrors_LS/nEvents_LS>0.5) BarrelRate_LS=0.;
00655     if(nEndcapErrors_LS/nEvents_LS>0.5) EndcapRate_LS=0.;
00656     if((nBarrelErrors_LS + nEndcapErrors_LS)/nEvents_LS>0.5) PixelRate_LS=0.;
00657     //std::cout<<"nEvents_LS: "<<nEvents_LS<<" , nBarrelErrors_LS: "<<nBarrelErrors_LS<<" , nEndcapErrors_LS: "<<nEndcapErrors_LS<<" , BarrelRate_LS: "<<BarrelRate_LS<<" , EndcapRate_LS: "<<EndcapRate_LS<<" , PixelRate_LS: "<<PixelRate_LS<<std::endl;
00658   }
00659   
00660   // evaluate mean cluster charge on tracks for data quality:
00661   float BarrelClusterCharge = 1.;
00662   float EndcapClusterCharge = 1.;
00663   float PixelClusterCharge = 1.;
00664   MonitorElement * me1 = bei->get("Pixel/Clusters/OnTrack/charge_siPixelClusters_Barrel");
00665   if(me1 && me1->getMean()<12.) BarrelClusterCharge = 0.;
00666   //if(me1) cout<<"Mean cluster charge in Barrel: "<<me1->getMean()<<endl;
00667   MonitorElement * me2 = bei->get("Pixel/Clusters/OnTrack/charge_siPixelClusters_Endcap");
00668   if(me2 && me2->getMean()<12.) EndcapClusterCharge = 0.;
00669   //if(me2) cout<<"Mean cluster charge in Endcap: "<<me2->getMean()<<endl;
00670   MonitorElement * me3 = bei->get("Pixel/Clusters/OnTrack/charge_siPixelClusters");
00671   if(me3 && me3->getMean()<12.) PixelClusterCharge = 0.;
00672   //if(me3) cout<<"Mean cluster charge in Pixel: "<<me3->getMean()<<endl;
00673   
00674   // evaluate average FED occupancy for data quality:
00675   float BarrelOccupancy = 1.;
00676   float EndcapOccupancy = 1.;
00677   float PixelOccupancy = 1.;
00678   MonitorElement * me4 = bei->get("Pixel/averageDigiOccupancy");
00679   if(me4){
00680     double minBarrelOcc = 999999.; 
00681     double maxBarrelOcc = -1.; 
00682     double meanBarrelOcc = 0.;
00683     double minEndcapOcc = 999999.;
00684     double maxEndcapOcc = -1.;
00685     double meanEndcapOcc = 0.;
00686     for(int i=1; i!=41; i++){
00687       if(i<=32 && me4->getBinContent(i)<minBarrelOcc) minBarrelOcc=me4->getBinContent(i); 
00688       if(i<=32 && me4->getBinContent(i)>maxBarrelOcc) maxBarrelOcc=me4->getBinContent(i);
00689       if(i<=32) meanBarrelOcc+=me4->getBinContent(i);
00690       if(i>32 && me4->getBinContent(i)<minEndcapOcc) minEndcapOcc=me4->getBinContent(i); 
00691       if(i>32 && me4->getBinContent(i)>maxEndcapOcc) maxEndcapOcc=me4->getBinContent(i); 
00692       if(i>32) meanEndcapOcc+=me4->getBinContent(i);
00693       //cout<<"OCCUPANCY: "<<i<<" "<<me4->getBinContent(i)<<" : "<<minBarrelOcc<<" "<<maxBarrelOcc<<" "<<minEndcapOcc<<" "<<maxEndcapOcc<<endl;
00694     } 
00695     meanBarrelOcc = meanBarrelOcc/32.;
00696     meanEndcapOcc = meanEndcapOcc/8.;
00697     //cout<<"MEANS: "<<meanBarrelOcc<<" "<<meanEndcapOcc<<endl;
00698     if(minBarrelOcc<0.1*meanBarrelOcc || maxBarrelOcc>2.5*meanBarrelOcc) BarrelOccupancy=0.;
00699     if(minEndcapOcc<0.2*meanEndcapOcc || maxEndcapOcc>1.8*meanEndcapOcc) EndcapOccupancy=0.;
00700     PixelOccupancy=BarrelOccupancy*EndcapOccupancy;
00701     //cout<<"Occupancies: "<<meanBarrelOcc<<" "<<meanEndcapOcc<<endl;
00702   }
00703   
00704   float pixelFlag = PixelRate_LS * PixelClusterCharge * PixelOccupancy;
00705   float barrelFlag = BarrelRate_LS * BarrelClusterCharge * BarrelOccupancy;
00706   float endcapFlag = EndcapRate_LS * EndcapClusterCharge * EndcapOccupancy;
00707   //cout<<"barrel, endcap, pixel flags: "<<barrelFlag<<","<<endcapFlag<<","<<pixelFlag<<endl;
00708   SummaryPixel = bei->get("Pixel/EventInfo/reportSummary");
00709   if(SummaryPixel) SummaryPixel->Fill(pixelFlag);
00710   SummaryBarrel = bei->get("Pixel/EventInfo/reportSummaryContents/PixelBarrelFraction");
00711   if(SummaryBarrel) SummaryBarrel->Fill(barrelFlag);
00712   SummaryEndcap = bei->get("Pixel/EventInfo/reportSummaryContents/PixelEndcapFraction");
00713   if(SummaryEndcap)   SummaryEndcap->Fill(endcapFlag);
00714   
00715 }
00716 
00717 //**********************************************************************************************
00718 
00719 void SiPixelDataQuality::fillGlobalQualityPlot(DQMStore * bei, bool init, edm::EventSetup const& eSetup, int nFEDs, bool Tier0Flag, int lumisec){
00720 //std::cout<<"Entering SiPixelDataQuality::fillGlobalQualityPlot: "<<nFEDs<<std::endl;
00721   //calculate eta and phi of the modules and fill a 2D plot:
00722   //if(lastLS_<lumisec){ cout<<"lastLS_="<<lastLS_<<" ,lumisec="<<lumisec<<endl; lastLS_=lumisec; init=true; cout<<"init="<<init<<endl; }
00723   if(init){
00724     count=0; errcount=0;
00725     init=false;
00726     count1=0;
00727     count2=0;
00728     count3=0;
00729     count4=0;
00730     count5=0;
00731     count6=0;
00732     modCounter_=0;
00733   if(!Tier0Flag){
00734     
00735     //cout<<"RESETS"<<endl;
00736     //The plots that these Vecs are integrated throughout a run
00737     //So at each lumi section I save their last values (lastmods)
00738     //And then subtract them out later when filling the SummaryMap
00739     for(int j=1; j!=41; j++){
00740       if(allmodsVec) lastallmods_[j-1] = allmodsVec->GetBinContent(j);
00741       if(errmodsVec) lasterrmods_[j-1] = errmodsVec->GetBinContent(j);
00742       if(allmodsVec) allmodsVec->SetBinContent(j,0.);
00743       if(errmodsVec) errmodsVec->SetBinContent(j,0.);
00744       if(goodmodsVec) goodmodsVec->SetBinContent(j,0.);
00745     }
00746   }
00747   if(Tier0Flag){
00748     for(int i=1; i!=3; i++) for(int j=1; j!=8; j++){
00749       if(allmodsMap) allmodsMap->SetBinContent(i,j,0.);
00750       if(errmodsMap) errmodsMap->SetBinContent(i,j,0.);
00751       if(goodmodsMap) goodmodsMap->SetBinContent(i,j,0.);
00752     }
00753   }
00754   }
00755   
00756 //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
00757 // Fill Maps:
00758   // Online:    
00759   if(nFEDs==0) return;
00760 /*  if(!Tier0Flag){
00761     eSetup.get<SiPixelFedCablingMapRcd>().get(theCablingMap);
00762     string currDir = bei->pwd();
00763     if(currDir.find("Reference")!=string::npos) return;
00764     //cout<<"currDir="<<currDir<<endl;
00765     string dname = currDir.substr(currDir.find_last_of("/")+1);
00766     // find a detId for Blades and Ladders (first of the contained Modules!):
00767     ifstream infile(edm::FileInPath("DQM/SiPixelMonitorClient/test/detId.dat").fullPath().c_str(),ios::in);
00768     string I_name[1440];
00769     int I_detId[1440];
00770     int I_fedId[1440];
00771     int I_linkId[1440];
00772     int nModsInFile=0;
00773     while(!infile.eof()) {
00774       infile >> I_name[nModsInFile] >> I_detId[nModsInFile] >> I_fedId[nModsInFile] >> I_linkId[nModsInFile] ;
00775       //cout<<I_name<<" "<<I_detId<<" "<<I_fedId<<" "<<I_linkId ;
00776       //getline(infile,dummys); //necessary to reach end of record
00777       infile.close();
00778       nModsInFile++;
00779     }
00780     if(dname.find("Module_")!=string::npos && currDir.find("Reference")==string::npos){
00781       vector<string> meVec = bei->getMEs();
00782       int detId=-1; int fedId=-1; int linkId=-1;
00783       for (vector<string>::const_iterator it = meVec.begin(); it != meVec.end(); it++) {
00784         //checking for any digis or FED errors to decide if this module is in DAQ:  
00785         string full_path = currDir + "/" + (*it);
00786         //cout<<"path: "<<full_path<<" , detId= "<<detId<<endl;
00787         if(detId==-1 && full_path.find("SUMOFF")==string::npos &&
00788            (full_path.find("ndigis")!=string::npos && full_path.find("SUMDIG")==string::npos) && 
00789            (getDetId(bei->get(full_path)) > 100)){
00790           //cout<<"Got into the first ndigis or NErrors histogram!"<<endl;
00791           MonitorElement * me = bei->get(full_path);
00792           if (!me) continue;
00793           if((full_path.find("ndigis")!=string::npos)){ 
00794             modCounter_++;
00795             detId = getDetId(me);
00796             for(int fedid=0; fedid!=40; ++fedid){
00797               SiPixelFrameConverter converter(theCablingMap.product(),fedid);
00798               uint32_t newDetId = detId;
00799               if(converter.hasDetUnit(newDetId)){
00800                 fedId=fedid;
00801                 break;   
00802               }
00803             }
00804             if(fedId==-1) continue; 
00805             sipixelobjects::ElectronicIndex cabling; 
00806             SiPixelFrameConverter formatter(theCablingMap.product(),fedId);
00807             sipixelobjects::DetectorIndex detector = {detId, 1, 1};      
00808             formatter.toCabling(cabling,detector);
00809             linkId = cabling.link;
00810             //cout<<"it has this FED ID and channel ID: "<<fedId<<" , "<<linkId<<endl;
00811             int NDigis = 0;
00812             if(full_path.find("ndigis")!=string::npos) NDigis = me->getEntries(); 
00813             float weight = (allmodsMap->GetBinContent(fedId+1,linkId))+NDigis;
00814             allmodsMap->Fill(fedId,linkId,weight);
00815             static const char buf[] = "Pixel/AdditionalPixelErrors/FED_%d/FedChNErrArray_%d";
00816             char fedplot[sizeof(buf)+4]; 
00817             sprintf(fedplot,buf,fedId,linkId);
00818             me = bei->get(fedplot);
00819             int NErrors = 0;
00820             if(me) NErrors = me->getIntValue();
00821             //if(fedId==37&&linkId==5) std::cout<<"THIS CHANNEL: "<<fedplot<<" , "<<NErrors<<" , "<<bei->pwd()<<std::endl;
00822             if(NErrors>0) {errmodsMap->Fill(fedId,linkId,NErrors);} //if(fedId==37&&linkId==5) std::cout<<"filling errmodsMap now : "<<errmodsMap->GetBinContent(fedId+1,linkId)<<" , and: "<<NErrors<<std::endl;}
00823           }
00824         }
00825       }//end loop over MEs
00826     }//end of module dir's
00827     vector<string> subDirVec = bei->getSubdirs();  
00828     for (vector<string>::const_iterator ic = subDirVec.begin();
00829          ic != subDirVec.end(); ic++) {
00830       bei->cd(*ic);
00831       init=false;
00832       fillGlobalQualityPlot(bei,init,eSetup,nFEDs,Tier0Flag);
00833       bei->goUp();
00834     }
00835     if(modCounter_==1440){
00836       bei->cd("Pixel/EventInfo/reportSummaryContents");
00837       //cout<<"B: Loop over all modules is done, now I am in    "<<bei->pwd()<<"     and currDir is    "<<currDir<<endl;
00838       if(bei->pwd()=="Pixel/EventInfo/reportSummaryContents"){
00839         SummaryReportMap = bei->get("Pixel/EventInfo/reportSummaryMap");
00840         if(SummaryReportMap){ 
00841           float contents=0.;
00842           for(int i=0; i!=40; i++)for(int j=1; j!=37; j++){
00843             //cout<<"bin: "<<i<<","<<j<<endl;
00844             if((allmodsMap->GetBinContent(i+1,j)) + (errmodsMap->GetBinContent(i+1,j)) > 0){
00845               contents = (allmodsMap->GetBinContent(i+1,j))/((allmodsMap->GetBinContent(i+1,j))+(errmodsMap->GetBinContent(i+1,j)));
00846             }else{
00847               contents = -1.;
00848             }
00849             //if(contents>=0.&&contents<0.8) std::cout<<"HERE: "<<i<<" , "<<j<<" , "<<allmodsMap->GetBinContent(i+1,j)<<" , "<<errmodsMap->GetBinContent(i+1,j)<<std::endl;
00850             if(i==13&&j==17&&contents>0) count1++;
00851             if(i==13&&j==18&&contents>0) count2++;
00852             if(i==15&&j==5&&contents>0) count3++;
00853             if(i==15&&j==6&&contents>0) count4++;
00854             //cout<<"\t\t MAP: "<<i<<","<<j<<","<<contents<<endl;
00855             if(((i==0||i==2||i==3||i==5||i==11||i==8)&&(j==1||j==8||j==13||j==17||j==20))||
00856                ((i==1||i==9||i==10||i==13)&&(j==1||j==5||j==8||j==20||j==22))||
00857                ((i==4||i==12)&&(j==5||j==10||j==13||j==17||j==22))||
00858                ((i==2||i==5||i==6||i==7||i==14)&&(j==5||j==10||j==22))||
00859                ((i==7||i==10)&&(j==13||j==17))||
00860                ((i==6||i==14)&&(j==1||j==20))||
00861                ((i==10||i==13)&&(j==10))||
00862                ((i==4||i==12)&&(j==2))||
00863                ((i==14)&&(j==15))){
00864               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j+1));
00865             }else if(((i==16||i==19||i==21||i==24||i==26||i==27||i==29)&&(j==2||j==9||j==14||j==18||j==21))||
00866                ((i==17||i==18||i==25)&&(j==2||j==6||j==9||j==21||j==23))||
00867                ((i==20||i==23||i==28||i==31)&&(j==6||j==11||j==14||j==18||j==23))||
00868                ((i==21||i==22||i==26||i==29||i==30)&&(j==6||j==11||j==23))||
00869                ((i==18)&&(j==14||j==18))||
00870                ((i==22||i==30)&&(j==2||j==21))||
00871                ((i==18)&&(j==11))||
00872                ((i==17||i==25)&&(j==16))||
00873                ((i==19||i==27)&&(j==5))){
00874               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j-1));
00875             }else if(i==6&&(j==14||j==15)){
00876               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j+2));
00877             }else if((i==14)&&j==14){
00878               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j+3));
00879             }else if((i==17||i==25)&&j==17){
00880               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j-3));
00881             }else if(((i==0||i==2||i==3||i==5||i==8||i==10||i==11||i==13)&&(j==3||j==15))||
00882                      ((i==1||i==9)&&j==3)||
00883                      ((i==7||i==12||i==15)&&j==15)){
00884               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j+4));
00885             }else if(((i==16||i==18||i==19||i==21||i==24||i==26||i==27||i==29)&&(j==7||j==19))||
00886                      ((i==17||i==25)&&j==7)||
00887                      ((i==20||i==23||i==28||i==31)&&j==19)){
00888               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j-4));
00889             }else if((i==6||i==14)&&(j==13||j==19)){
00890               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j+5));
00891             }else if((i==17||i==25)&&(j==18||j==24)){
00892               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j-5));
00893             }else if(((i==4||i==12)&&j==1)||
00894                      ((i==3||i==11)&&j==6)){
00895               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j+6));
00896             }else if((i==9||i==1)&&j==4){
00897               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j+8));
00898             }else if((i==17||i==25)&&j==12){
00899               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j-8));
00900             }else if(((i==20||i==28)&&j==20)||
00901                      ((i==19||i==27)&&j==22)){
00902               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j-11));
00903             }else if(((i==20||i==28)&&j==21)||
00904                      ((i==19||i==27)&&j==23)){
00905               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j-13));
00906             }else{
00907               SummaryReportMap->setBinContent(i+1,j,contents);
00908             }
00909           }//end for loop over summaryReportMap bins
00910           for(int i=0; i!=40; i++)for(int j=1; j!=37; j++){ // catch the last few holes...
00911             if(((i==2||i==4||i==5||i==6||i==7||i==10||i==12||i==13||i==14||i==15)&&j==12)||
00912                ((i==0||i==2||i==3||i==4||i==5||i==7||i==8||i==10||i==11||i==12||i==13||i==15)&&j==24)){
00913               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j-8));
00914             }else if(((i==18||i==20||i==21||i==22||i==23||i==26||i==28||i==29||i==30||i==31)&&j==4)||
00915                ((i==16||i==18||i==19||i==20||i==21||i==23||i==24||i==26||i==27||i==28||i==29||i==31)&&j==16)){
00916               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j+8));
00917             }else if(((i==6||i==14)&&j==9)||
00918                      ((i==3||i==11)&&j==5)||
00919                      ((i==1||i==9)&&(j==11||j==16))){
00920               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j-1));
00921             }else if(((i==17||i==25)&&j==10)||
00922                      ((i==22||i==30)&&(j==8||j==15))||
00923                      ((i==20||i==28)&&(j==2))){
00924               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j+1));
00925             }else if((i==1||i==9)&&j==17){
00926               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j-3));
00927             }else if((i==22||i==30)&&j==14){
00928               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j+3));
00929             }else if((i==6||i==14)&&j==7){
00930               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j-4));
00931             }else if((i==22||i==30)&&j==3){
00932               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j+4));
00933             }else if((i==1||i==9)&&(j==18||j==24)){
00934               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j-5));
00935             }else if((i==22||i==30)&&(j==13||j==19)){
00936               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j+5));
00937             }else if(((i==20||i==28)&&j==1)||
00938                      ((i==19||i==27)&&j==6)){
00939               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j+6));
00940             }else if(((i==4||i==12)&&j==20)||
00941                      ((i==3||i==11)&&j==22)){
00942               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j-11));
00943             }else if(((i==4||i==12)&&j==21)||
00944                      ((i==3||i==11)&&j==23)){
00945               SummaryReportMap->setBinContent(i+1,j,SummaryReportMap->getBinContent(i+1,j-13));
00946             }
00947           }//end of loop over bins
00948           //std::cout<<"COUNTERS: "<<count1<<" , "<<count2<<" , "<<count3<<" , "<<count4<<" , "<<count5<<" , "<<count6<<std::endl;
00949         }//end if reportSummaryMap ME exists
00950       }//end if in summary directory
00951     }//end if modCounter_  
00952 */
00953 //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
00954   if(!Tier0Flag){
00955     //Not elegant, but not sure where else to put this sweet new plot!
00956     MonitorElement * meTmp = bei->get("Pixel/Barrel/NClustertoChargeRatio_AllMod");
00957     MonitorElement * meTop = bei->get("Pixel/Barrel/SUMCLU_nclusters_Barrel");
00958     MonitorElement * meBot = bei->get("Pixel/Barrel/SUMCLU_charge_Barrel");
00959     if(meTop && meBot && meTmp){
00960       for (int bin = 1; bin < 769; ++bin){
00961         float content = 0.0;
00962         if (meBot->getBinContent(bin) > 0.0){
00963           content = meTop->getBinContent(bin)/meBot->getBinContent(bin); 
00964         }
00965         meTmp->setBinContent(bin,content);
00966       }
00967       for (int j = 0; j < 4; ++j){
00968         static const char buf[] = "Pixel/Barrel/NClustertoChargeRatio_NormMod%i";
00969         char modplot[sizeof(buf)+2];
00970         sprintf(modplot,buf,j+1);
00971         MonitorElement * meFinal = bei->get(modplot);
00972         if(!meFinal) continue;
00973         for (int i = 1; i < 769; ++i){
00974           int k = 3 - j;
00975           if (int(i+k)%4 == 0)
00976             meFinal->setBinContent(int((i+k)/4), meTmp->getBinContent(i));
00977         }
00978         //Filling done. Now modification.
00979         float SFLay[3], TotLay[3];
00980         for (int ll = 0; ll < 3; ++ll) TotLay[ll] = 0.0;
00981         for (int bin = 1; bin < (meFinal->getNbinsX()+1);++bin){
00982           int layer     =   int((bin%48)/16);
00983           TotLay[layer] += meFinal->getBinContent(bin);
00984         }
00985         float laynorm = TotLay[1]/64.;
00986         for (int ll = 0; ll < 3; ++ll){
00987           SFLay[ll] = 0.0; if (TotLay[ll] > 0.0 && TotLay[1] > 0.0) SFLay[ll] = TotLay[1]/TotLay[ll]*(1./laynorm);
00988         }
00989         //now loop through plot
00990         for (int bin = 1; bin < (meFinal->getNbinsX()+1); ++bin){
00991           //access the layer number for bin: int((i%48)/16)
00992           int layer     =   int((bin%48)/16);
00993           float content =   meFinal->getBinContent(bin);
00994           //apply scale factor to bin content
00995           meFinal->setBinContent(bin,content*SFLay[layer]);
00996         }
00997       }
00998     }
00999     
01000     eSetup.get<SiPixelFedCablingMapRcd>().get(theCablingMap);
01001     string currDir = bei->pwd();
01002     if(currDir.find("Reference")!=string::npos || currDir.find("Additional")!=string::npos) return;
01003     //cout<<"currDir="<<currDir<<endl;
01004     string dname = currDir.substr(currDir.find_last_of("/")+1);
01005     if(dname.find("Module_")!=string::npos && currDir.find("Reference")==string::npos){
01006       vector<string> meVec = bei->getMEs();
01007       int detId=-1; int fedId=-1;
01008       for (vector<string>::const_iterator it = meVec.begin(); it != meVec.end(); it++){//loop over all modules and fill ndigis into allmodsMap
01009         //checking for any digis or FED errors to decide if this module is in DAQ:  
01010         string full_path = currDir + "/" + (*it);
01011         if(detId==-1 && full_path.find("SUMOFF")==string::npos &&
01012            (full_path.find("ndigis")!=string::npos && full_path.find("SUMDIG")==string::npos) && 
01013            (getDetId(bei->get(full_path)) > 100)){
01014           MonitorElement * me = bei->get(full_path);
01015           if (!me) continue;
01016           if((full_path.find("ndigis")!=string::npos)){ 
01017             modCounter_++;
01018             detId = getDetId(me);
01019             for(int fedid=0; fedid!=40; ++fedid){
01020               SiPixelFrameConverter converter(theCablingMap.product(),fedid);
01021               uint32_t newDetId = detId;
01022               if(converter.hasDetUnit(newDetId)){
01023                 fedId=fedid;
01024                 break;   
01025               }
01026             }
01027             double NDigis = 0;
01028             if(full_path.find("ndigis")!=string::npos) NDigis = me->getEntries(); 
01029             float weight = (allmodsVec->GetBinContent(fedId+1))+NDigis;
01030             //cout<<"DIGIS: "<<currDir<<" , "<<fedId<<" , "<<weight<<" , "<<NDigis<<endl;
01031             allmodsVec->SetBinContent(fedId+1,weight);
01032             //cout<<"\t filled: "<<allmodsVec->GetBinContent(fedId+1,weight)<<endl;
01033           }
01034         }
01035       }//end loop over MEs
01036     }//end of module dir's
01037     //if(currDir.find("FED_")!=std::string::npos){
01038       //fillGlobalQualityPlot(bei,init,eSetup,nFEDs,Tier0Flag,lumisec);
01039       //bei->goUp();
01040     //}
01041     vector<string> subDirVec = bei->getSubdirs();  
01042     for (vector<string>::const_iterator ic = subDirVec.begin();
01043          ic != subDirVec.end(); ic++) {
01044       bei->cd(*ic);
01045       init=false;
01046       fillGlobalQualityPlot(bei,init,eSetup,nFEDs,Tier0Flag,lumisec);
01047       bei->goUp();
01048     }
01049     //cout<<"modCounter_: "<<modCounter_<<" , "<<bei->pwd()<<endl;
01050     if(modCounter_==1440){
01051       bei->cd("Pixel/EventInfo/reportSummaryContents");
01052       if(bei->pwd()=="Pixel/EventInfo/reportSummaryContents"){
01053         for(int i=0; i!=40; i++){//loop over FEDs to fetch the errors
01054           static const char buf[] = "Pixel/AdditionalPixelErrors/FED_%d/FedChNErrArray_%d";
01055           char fedplot[sizeof(buf)+4]; 
01056           int NErrors = 0;
01057           for(int j=0; j!=37; j++){//loop over FED channels within a FED
01058             sprintf(fedplot,buf,i,j);
01059             MonitorElement * me = bei->get(fedplot);
01060             if(me) NErrors = NErrors + me->getIntValue();
01061           }
01062           //If I fill, then I end up majorly overcounting the numbers of errors...
01063           //if(NErrors>0){ errmodsVec->Fill(i,NErrors); } 
01064           if(NErrors>0){ errmodsVec->SetBinContent(i+1,NErrors); } 
01065         }
01066         SummaryReportMap = bei->get("Pixel/EventInfo/reportSummaryMap");
01067         if(SummaryReportMap){ 
01068           float contents=0.;
01069           for(int i=1; i!=41; i++){
01070             //Dynamically subtracting previous (integrated) lumi section values
01071             //in order to only show current lumi section's numbers
01072             float mydigis = allmodsVec->GetBinContent(i) - lastallmods_[i-1];
01073             float myerrs  = errmodsVec->GetBinContent(i) - lasterrmods_[i-1];
01074             if ((mydigis + myerrs) > 0.){
01075               contents = mydigis/(mydigis + myerrs);
01076               //std::cout<<"Fed: "<<i-1<<" , nevents: "<<nevents<<" , ndigis: "<< mydigis <<" , nerrors: "<< myerrs << " , contents: " << contents << std::endl;
01077             }else{
01078               //Changed so that dynamic zooming will still
01079               //advance over these bins(in renderplugins)
01080               contents = -0.5;
01081             }
01082             SummaryReportMap->setBinContent(lumisec+1,i,contents);
01083           }//end for loop over summaryReportMap bins
01084         }//end if reportSummaryMap ME exists
01085       }//end if in summary directory
01086     }//end if modCounter_  
01087   }else{ // Offline
01088     float barrel_errors_temp[1]={-1.}; int barrel_cuts_temp[6]={6*-1}; 
01089     float endcap_errors_temp[1]={-1.}; int endcap_cuts_temp[6]={6*-1}; 
01090     int pixel_cuts_temp[1]={-1};
01091     // Barrel results:
01092     MonitorElement * me;
01093     me = bei->get("Pixel/Barrel/BarrelNErrorsCut");
01094     if(me) barrel_errors_temp[0] = me->getFloatValue();
01095     me = bei->get("Pixel/Endcap/EndcapNErrorsCut");
01096     if(me) endcap_errors_temp[0] = me->getFloatValue();
01097     SummaryReportMap->setBinContent(1,1,barrel_errors_temp[0]);
01098     SummaryReportMap->setBinContent(2,1,endcap_errors_temp[0]);
01099     me = bei->get("Pixel/Barrel/BarrelNDigisCut");
01100     if(me) barrel_cuts_temp[0] = me->getIntValue();
01101     me = bei->get("Pixel/Barrel/BarrelDigiChargeCut");
01102     if(me) barrel_cuts_temp[1] = me->getIntValue();
01103     me = bei->get("Pixel/Barrel/BarrelClusterSizeCut");
01104     if(me) barrel_cuts_temp[2] = me->getIntValue();
01105     me = bei->get("Pixel/Barrel/BarrelNClustersCut");
01106     if(me) barrel_cuts_temp[3] = me->getIntValue();
01107     me = bei->get("Pixel/Barrel/BarrelClusterChargeCut");
01108     if(me) barrel_cuts_temp[4] = me->getIntValue();  
01109     me = bei->get("Pixel/Endcap/EndcapNDigisCut");
01110     if(me) endcap_cuts_temp[0] = me->getIntValue();
01111     me = bei->get("Pixel/Endcap/EndcapDigiChargeCut");
01112     if(me) endcap_cuts_temp[1] = me->getIntValue();
01113     me = bei->get("Pixel/Endcap/EndcapClusterSizeCut");
01114     if(me) endcap_cuts_temp[2] = me->getIntValue();
01115     me = bei->get("Pixel/Endcap/EndcapNClustersCut");
01116     if(me) endcap_cuts_temp[3] = me->getIntValue();
01117     me = bei->get("Pixel/Endcap/EndcapClusterChargeCut");
01118     if(me) endcap_cuts_temp[4] = me->getIntValue();  
01119     for(int j=2; j!=7; j++){
01120       SummaryReportMap->setBinContent(1,j,barrel_cuts_temp[j-2]);
01121       SummaryReportMap->setBinContent(2,j,endcap_cuts_temp[j-2]);
01122       //cout<<"error cut values: "<<j<<" , "<<barrel_cuts_temp[j-2]<<" , "<<endcap_cuts_temp[j-2]<<endl;
01123     }
01124     me = bei->get("Pixel/Tracks/PixelTracksCut");
01125     if(me) pixel_cuts_temp[0] = me->getIntValue();  
01126     SummaryReportMap->setBinContent(1,7,pixel_cuts_temp[0]);
01127     SummaryReportMap->setBinContent(2,7,pixel_cuts_temp[0]);
01128   }//end of offline map
01129   if(allmodsMap) allmodsMap->Clear();
01130   if(goodmodsMap) goodmodsMap->Clear();
01131   if(errmodsMap) errmodsMap->Clear();
01132 }
01133 
01134 //**********************************************************************************************
01135