CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DQM/RPCMonitorClient/src/RPCEventSummary.cc

Go to the documentation of this file.
00001 /*  \author Anna Cimmino*/
00002 #include <sstream>
00003 
00004 #include <DQM/RPCMonitorClient/interface/RPCEventSummary.h>
00005 //CondFormats
00006 #include "CondFormats/RunInfo/interface/RunInfo.h"
00007 #include "CondFormats/DataRecord/interface/RunSummaryRcd.h"
00008 // Framework
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include "FWCore/Framework/interface/LuminosityBlock.h"
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "FWCore/Framework/interface/EventSetup.h"
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 //DQM Services
00015 #include "DQMServices/Core/interface/DQMStore.h"
00016 
00017 RPCEventSummary::RPCEventSummary(const edm::ParameterSet& ps ){
00018   edm::LogVerbatim ("rpceventsummary") << "[RPCEventSummary]: Constructor";
00019 
00020   enableReportSummary_ = ps.getUntrackedParameter<bool>("EnableSummaryReport",true);
00021   prescaleFactor_ =  ps.getUntrackedParameter<int>("PrescaleFactor", 1);
00022   eventInfoPath_ = ps.getUntrackedParameter<std::string>("EventInfoPath", "RPC/EventInfo");
00023   globalFolder_ = ps.getUntrackedParameter<std::string>("RPCSummaryFolder", "RPC/RecHits/SummaryHistograms");
00024   minimumEvents_= ps.getUntrackedParameter<int>("MinimumRPCEvents", 10000);
00025   numberDisk_ = ps.getUntrackedParameter<int>("NumberOfEndcapDisks", 3);
00026   doEndcapCertification_ = ps.getUntrackedParameter<bool>("EnableEndcapSummary", false);
00027 
00028   FEDRange_.first  = ps.getUntrackedParameter<unsigned int>("MinimumRPCFEDId", 790);
00029   FEDRange_.second = ps.getUntrackedParameter<unsigned int>("MaximumRPCFEDId", 792);
00030   
00031   NumberOfFeds_ =FEDRange_.second -  FEDRange_.first +1;
00032 
00033 }
00034 
00035 RPCEventSummary::~RPCEventSummary(){
00036   edm::LogVerbatim ("rpceventsummary") << "[RPCEventSummary]: Destructor ";
00037   dbe_=0;
00038 }
00039 
00040 void RPCEventSummary::beginJob(){
00041  edm::LogVerbatim ("rpceventsummary") << "[RPCEventSummary]: Begin job ";
00042  dbe_ = edm::Service<DQMStore>().operator->();
00043 }
00044 
00045 void RPCEventSummary::beginRun(const edm::Run& r, const edm::EventSetup& setup){
00046  edm::LogVerbatim ("rpceventsummary") << "[RPCEventSummary]: Begin run";
00047 
00048 
00049  edm::eventsetup::EventSetupRecordKey recordKey(edm::eventsetup::EventSetupRecordKey::TypeTag::findType("RunInfoRcd"));
00050  
00051  int defaultValue = 1;
00052  
00053  if(0 != setup.find( recordKey ) ) {
00054    defaultValue = -1;
00055    //get fed summary information
00056    edm::ESHandle<RunInfo> sumFED;
00057    setup.get<RunInfoRcd>().get(sumFED);    
00058    std::vector<int> FedsInIds= sumFED->m_fed_in;   
00059    unsigned int f = 0;
00060    bool flag = false;
00061    while(!flag && f < FedsInIds.size()) {
00062      int fedID=FedsInIds[f];
00063      //make sure fed id is in allowed range  
00064      if(fedID>=FEDRange_.first && fedID<=FEDRange_.second) {
00065        defaultValue = 1;
00066        flag = true;
00067      } 
00068      f++;
00069    }   
00070  }   
00071  
00072  init_=false;
00073 
00074  MonitorElement* me;
00075  dbe_->setCurrentFolder(eventInfoPath_);
00076 
00077  //a global summary float [0,1] providing a global summary of the status 
00078  //and showing the goodness of the data taken by the the sub-system 
00079  std::string histoName="reportSummary";
00080  me =0;
00081  me = dbe_->get(eventInfoPath_ +"/"+ histoName);
00082  if ( 0!=me) {
00083     dbe_->removeElement(me->getName());
00084   }
00085 
00086   me = dbe_->bookFloat(histoName);
00087   me->Fill(defaultValue);
00088 
00089   //TH2F ME providing a mapof values[0-1] to show if problems are localized or distributed
00090   me =0;
00091   me = dbe_->get(eventInfoPath_ +"/reportSummaryMap");
00092   if ( 0!=me) {
00093     dbe_->removeElement(me->getName());
00094   }
00095  
00096   me = dbe_->book2D("reportSummaryMap", "RPC Report Summary Map", 15, -7.5, 7.5, 12, 0.5 ,12.5);
00097  
00098   //customize the 2d histo
00099   std::stringstream BinLabel;
00100   for (int i= 1 ; i<=15; i++){
00101     BinLabel.str("");
00102     if(i<13){
00103       BinLabel<<"Sec"<<i;
00104        me->setBinLabel(i,BinLabel.str(),2);
00105     } 
00106 
00107     BinLabel.str("");
00108     if(i<5)
00109       BinLabel<<"Disk"<<i-5;
00110     else if(i>11)
00111       BinLabel<<"Disk"<<i-11;
00112     else if(i==11 || i==5)
00113       BinLabel.str("");
00114     else
00115       BinLabel<<"Wheel"<<i-8;
00116  
00117      me->setBinLabel(i,BinLabel.str(),1);
00118   }
00119 
00120   //fill the histo with "1" --- just for the moment
00121   for(int i=1; i<=15; i++){
00122      for (int j=1; j<=12; j++ ){
00123        if(i==5 || i==11 || (j>6 && (i<6 || i>10)))    
00124          me->setBinContent(i,j,-1);//bins that not correspond to subdetector parts
00125        else
00126          me->setBinContent(i,j,defaultValue);
00127      }
00128    }
00129 
00130   if(numberDisk_ < 4)
00131     for (int j=1; j<=12; j++ ){
00132         me->setBinContent(1,j,-1);//bins that not correspond to subdetector parts
00133         me->setBinContent(15,j,-1);
00134     }
00135 
00136  //the reportSummaryContents folder containins a collection of ME floats [0-1] (order of 5-10)
00137  // which describe the behavior of the respective subsystem sub-components.
00138   dbe_->setCurrentFolder(eventInfoPath_+ "/reportSummaryContents");
00139   
00140   std::stringstream segName;
00141   std::vector<std::string> segmentNames;
00142   for(int i=-4; i<=4; i++){
00143     if(i>-3 && i<3) {
00144       segName.str("");
00145       segName<<"RPC_Wheel"<<i;
00146       segmentNames.push_back(segName.str());
00147     }
00148     if(i==0) continue;
00149     segName.str("");
00150     segName<<"RPC_Disk"<<i;
00151     segmentNames.push_back(segName.str());
00152   }
00153   
00154 
00155   for(unsigned int i=0; i<segmentNames.size(); i++){
00156     me =0;
00157     me = dbe_->get(eventInfoPath_ + "/reportSummaryContents/" +segmentNames[i]);
00158     if ( 0!=me) {
00159       dbe_->removeElement(me->getName());
00160     }
00161     me = dbe_->bookFloat(segmentNames[i]);
00162     me->Fill(defaultValue);
00163   }
00164 
00165   //excluded endcap parts
00166   if(numberDisk_ < 4){
00167     me=dbe_->get(eventInfoPath_ + "/reportSummaryContents/RPC_Disk4");
00168     if(me)  me->Fill(-1);
00169     me=dbe_->get(eventInfoPath_ + "/reportSummaryContents/RPC_Disk-4");
00170     if(me)  me->Fill(-1);
00171   }
00172 }
00173 
00174 void RPCEventSummary::beginLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& context){} 
00175 
00176 void RPCEventSummary::analyze(const edm::Event& iEvent, const edm::EventSetup& c) {}
00177 
00178 void RPCEventSummary::endLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& iSetup) {  
00179   edm::LogVerbatim ("rpceventsummary") <<"[RPCEventSummary]: End of LS transition, performing DQM client operation";
00180 }
00181 
00182 void RPCEventSummary::endRun(const edm::Run& r, const edm::EventSetup& c){
00183 
00184 
00185   float  rpcevents = 0;
00186    MonitorElement * RPCEvents = dbe_->get(globalFolder_ +"/RPCEvents");  
00187 
00188   if(RPCEvents) {
00189     rpcevents = RPCEvents -> getEntries();
00190    }
00191 
00192   if(rpcevents < minimumEvents_) return;
00193 
00194    std::stringstream meName;
00195    MonitorElement * myMe;
00196    
00197    meName.str("");
00198    meName<<eventInfoPath_ + "/reportSummaryMap";
00199    MonitorElement * reportMe = dbe_->get(meName.str());
00200    
00201    MonitorElement * globalMe;
00202    
00203    //BARREL
00204    float barrelFactor = 0;
00205    
00206      for(int w = -2 ; w<3; w++){
00207      
00208        meName.str("");
00209        meName<<globalFolder_<<"/RPCChamberQuality_Roll_vs_Sector_Wheel"<<w;
00210        myMe = dbe_->get(meName.str());
00211        
00212        if(myMe){      
00213          float wheelFactor = 0;
00214          
00215          for(int s = 1; s<=myMe->getNbinsX() ; s++){
00216            float sectorFactor = 0;
00217            int rollInSector = 0;
00218          
00219            
00220          for(int r = 1;r<=myMe->getNbinsY(); r++){
00221            if((s!=4 && r > 17 ) || ((s ==9 ||s ==10)  && r >15 ) )  continue;
00222            rollInSector++;
00223            
00224            
00225            if(myMe->getBinContent(s,r) == PARTIALLY_DEAD) sectorFactor+=0.8;
00226            else if(myMe->getBinContent(s,r) == DEAD )sectorFactor+=0;
00227            else sectorFactor+=1;        
00228            
00229          }
00230          if(rollInSector!=0)
00231            sectorFactor = sectorFactor/rollInSector;
00232          
00233          if(reportMe)   reportMe->setBinContent(w+8, s, sectorFactor);
00234          wheelFactor += sectorFactor;
00235          
00236          }//end loop on sectors
00237          
00238          wheelFactor = wheelFactor/myMe->getNbinsX();
00239          
00240          meName.str("");
00241          meName<<eventInfoPath_ + "/reportSummaryContents/RPC_Wheel"<<w; 
00242          globalMe=dbe_->get(meName.str());
00243          if(globalMe) globalMe->Fill(wheelFactor);
00244          
00245          barrelFactor += wheelFactor;
00246        }//
00247      }//end loop on wheel
00248   
00249      barrelFactor = barrelFactor/5;
00250   
00251 
00252      float endcapFactor = 0;
00253      
00254      if(doEndcapCertification_){
00255        
00256        //Endcap
00257        for(int d = -numberDisk_ ; d<= numberDisk_; d++){
00258          if (d==0) continue;
00259          
00260          meName.str("");
00261          meName<<globalFolder_<<"/RPCChamberQuality_Ring_vs_Segment_Disk"<<d;
00262          myMe = dbe_->get(meName.str());
00263          
00264          if(myMe){      
00265            float diskFactor = 0;
00266            
00267            float sectorFactor[6]= {0,0,0,0,0,0};
00268            
00269            for (int i = 0 ;i <6;i++){
00270              int firstSeg = (i *6 )+1;
00271              int lastSeg = firstSeg +6;
00272              int rollInSector = 0; 
00273              for(int seg = firstSeg; seg< lastSeg ; seg++){
00274                
00275                for(int y = 1;y<=myMe->getNbinsY(); y++){
00276                  rollInSector++;
00277                  if(myMe->getBinContent(seg,y) == PARTIALLY_DEAD) sectorFactor[i]+=0.8;
00278                  else if(myMe->getBinContent(seg,y) == DEAD )sectorFactor[i]+=0;
00279                  else sectorFactor[i]+=1;       
00280                  
00281                }
00282              }
00283              sectorFactor[i] = sectorFactor[i]/rollInSector;
00284            }//end loop on Sectors
00285            
00286            
00287            for (int sec = 0 ; sec<6; sec++){
00288              diskFactor += sectorFactor[sec];   
00289              if(reportMe)       {
00290                if (d<0) reportMe->setBinContent(d+5, sec+1 , sectorFactor[sec]);
00291                else  reportMe->setBinContent(d+11, sec+1 , sectorFactor[sec]);
00292              }   
00293            }
00294            
00295            diskFactor = diskFactor/6;
00296            
00297            meName.str("");
00298            meName<<eventInfoPath_ + "/reportSummaryContents/RPC_Disk"<<d; 
00299            globalMe=dbe_->get(meName.str());
00300            if(globalMe) globalMe->Fill(diskFactor);
00301            
00302            endcapFactor += diskFactor;
00303          }//end loop on disks
00304          
00305        }
00306        
00307        endcapFactor=endcapFactor/ (numberDisk_ * 2);
00308        
00309      } 
00310      
00311      //Fill repor summary
00312      float rpcFactor = barrelFactor;
00313      if(doEndcapCertification_){ rpcFactor =  ( barrelFactor + endcapFactor)/2; }
00314      
00315      globalMe = dbe_->get(eventInfoPath_ +"/reportSummary"); 
00316      if(globalMe) globalMe->Fill(rpcFactor);
00317      
00318      
00319 }