CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/DQM/RPCMonitorClient/src/RPCChamberQuality.cc

Go to the documentation of this file.
00001 #include <string>
00002 #include <sstream>
00003 #include <map>
00004 #include <DQM/RPCMonitorClient/interface/RPCChamberQuality.h>
00005 #include "DQM/RPCMonitorDigi/interface/RPCBookFolderStructure.h"
00006 #include "DQM/RPCMonitorDigi/interface/utils.h"
00007 // Framework
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 #include <FWCore/Framework/interface/LuminosityBlock.h>
00010 #include <FWCore/Framework/interface/Event.h>
00011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00012 //DQM Services
00013 #include "DQMServices/Core/interface/DQMStore.h"
00014 //DataFormats
00015 #include <DataFormats/MuonDetId/interface/RPCDetId.h>
00016 //Geometry
00017 #include "Geometry/RPCGeometry/interface/RPCGeomServ.h"
00018 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
00019 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00020 
00021 const std::string RPCChamberQuality::xLabels_[7] = {"Good", "OFF", "Nois.St","Nois.Ch","Part.Dead","Dead","Bad.Shape"};
00022 const std::string RPCChamberQuality::regions_[3] = {"EndcapNegative","Barrel","EndcapPositive"};
00023 
00024 RPCChamberQuality::RPCChamberQuality(const edm::ParameterSet& ps ){
00025   edm::LogVerbatim ("rpceventsummary") << "[RPCChamberQuality]: Constructor";
00026   
00027   prescaleFactor_ =  ps.getUntrackedParameter<int>("PrescaleFactor", 9);
00028   prefixDir_ = ps.getUntrackedParameter<std::string>("RPCGlobalFolder", "RPC/RecHits/SummaryHistograms");
00029   minEvents = ps.getUntrackedParameter<int>("MinimumRPCEvents", 10000);
00030   numberOfDisks_ = ps.getUntrackedParameter<int>("NumberOfEndcapDisks", 3);
00031 }
00032 
00033 RPCChamberQuality::~RPCChamberQuality(){
00034   edm::LogVerbatim ("rpceventsummary") << "[RPCChamberQuality]: Destructor ";
00035   dbe_=0;
00036 }
00037 
00038 void RPCChamberQuality::beginJob(){
00039   edm::LogVerbatim ("rpceventsummary") << "[RPCChamberQuality]: Begin job ";
00040   dbe_ = edm::Service<DQMStore>().operator->();
00041 }
00042 
00043 void RPCChamberQuality::beginRun(const edm::Run& r, const edm::EventSetup& c){
00044   edm::LogVerbatim ("rpceventsummary") << "[RPCChamberQuality]: Begin run";
00045   
00046   // init_ = false;  
00047   
00048   MonitorElement* me;
00049   dbe_->setCurrentFolder(prefixDir_);
00050   
00051   std::stringstream histoName;
00052   
00053   rpcdqm::utils rpcUtils;
00054 
00055   for (int r = 0 ; r < 3; r++){
00056 
00057   histoName.str("");
00058   histoName<<"RPCChamberQuality_"<<regions_[r]; 
00059   me = dbe_->get(prefixDir_+"/"+ histoName.str());
00060   if (0!=me)    dbe_->removeElement(me->getName());
00061   me = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(),  7, 0.5, 7.5);
00062   
00063   for (int x = 1; x <8 ; x++) me->setBinLabel(x, xLabels_[x-1]);
00064   }
00065 
00066 
00067   histoName.str("");
00068   histoName<<"RPC_System_Quality_Overview"; 
00069   me = dbe_->get(prefixDir_+"/"+ histoName.str());
00070   if (0!=me)       dbe_->removeElement(me->getName());
00071   me = dbe_->book2D(histoName.str().c_str(), histoName.str().c_str(),  7, 0.5, 7.5, 3, 0.5, 3.5);
00072   me->setBinLabel(1, "E+", 2);
00073   me->setBinLabel(2, "B", 2);
00074   me->setBinLabel(3, "E-", 2);
00075     
00076   for (int x = 1; x <8 ; x++) me->setBinLabel(x, xLabels_[x-1]);
00077     
00078   for(int w=-2; w<3;w++){//Loop on wheels
00079     
00080     histoName.str("");
00081     histoName<<"RPCChamberQuality_Roll_vs_Sector_Wheel"<<w;    
00082     me = dbe_->get(prefixDir_+"/"+ histoName.str());
00083     if (0!=me) dbe_->removeElement(me->getName());
00084     me = dbe_->book2D(histoName.str().c_str(), histoName.str().c_str(),  12, 0.5, 12.5, 21, 0.5, 21.5);
00085 
00086     rpcUtils.labelXAxisSector( me);
00087     rpcUtils.labelYAxisRoll(me, 0, w);
00088 
00089     histoName.str("");
00090     histoName<<"RPCChamberQuality_Distribution_Wheel"<<w;    
00091     me=0;
00092     me = dbe_->get(prefixDir_+"/"+ histoName.str());
00093     if (0!=me )   dbe_->removeElement(me->getName());
00094     me = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(),  7, 0.5, 7.5);
00095 
00096     for (int x = 1; x <8; x++) me->setBinLabel(x, xLabels_[x-1]);        
00097   }//end loop on wheels
00098 
00099   for(int d= -numberOfDisks_; d<= numberOfDisks_ ; d++) { // Loop on disk
00100     if(d==0) continue; 
00101       histoName.str("");
00102       histoName<<"RPCChamberQuality_Ring_vs_Segment_Disk"<<d;       //  2D histo for RPC Qtest
00103       me = 0;
00104       me = dbe_->get(prefixDir_+"/"+ histoName.str());
00105       if (0!=me) {
00106         dbe_->removeElement(me->getName());
00107       }
00108       me = dbe_->book2D(histoName.str().c_str(), histoName.str().c_str(),  36, 0.5, 36.5, 6, 0.5, 6.5);
00109       rpcUtils.labelXAxisSegment(me);
00110       rpcUtils.labelYAxisRing(me, 2);
00111 
00112       histoName.str("");
00113       histoName<<"RPCChamberQuality_Distribution_Disk"<<d;    
00114       me=0;
00115       me = dbe_->get(prefixDir_+"/"+ histoName.str());
00116       if (0!=me )   dbe_->removeElement(me->getName());
00117       me = dbe_->book1D(histoName.str().c_str(), histoName.str().c_str(),  7, 0.5, 7.5);
00118       
00119       for (int x = 1; x <8 ; x++) me->setBinLabel(x, xLabels_[x-1]); 
00120   } 
00121 }
00122 
00123 void RPCChamberQuality::beginLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& context){} 
00124 
00125 void RPCChamberQuality::analyze(const edm::Event& iEvent, const edm::EventSetup& c) {}
00126 
00127 void RPCChamberQuality::endRun(const edm::Run& r, const edm::EventSetup& c) {
00128   edm::LogVerbatim ("rpceventsummary") <<"[RPCChamberQuality]: End Job, performing DQM client operation";
00129 
00130    MonitorElement * RpcEvents = NULL;
00131    std::stringstream meName;
00132    
00133     
00134    meName.str("");
00135    meName<<prefixDir_<<"/RPCEvents"; 
00136    int rpcEvents=0;
00137    RpcEvents = dbe_->get(meName.str());
00138 
00139    if(RpcEvents) rpcEvents= (int)RpcEvents->getEntries();
00140 
00141    if(rpcEvents >= minEvents){
00142     
00143     MonitorElement * summary[3];
00144 
00145     for(int r = 0 ; r < 3 ; r++) {    
00146     meName.str("");
00147     meName<<prefixDir_<<"/RPCChamberQuality_"<<RPCChamberQuality::regions_[r]; 
00148     summary[r] = dbe_ -> get(meName.str());
00149 
00150     if( summary[r] != 0 ) summary[r]->Reset();
00151     }
00152 
00153     //Barrel
00154     for (int wheel=-2; wheel<3; wheel++) { // loop by Wheels
00155       meName.str("");
00156       meName<<"Roll_vs_Sector_Wheel"<<wheel;
00157 
00158       this->performeClientOperation(meName.str(), 0 , summary[1]);
00159     } // loop by Wheels
00160     
00161     
00162     // Endcap
00163     for(int i=-3; i<4; i++) {//loop on Disks
00164       if(i==0) continue;
00165       
00166       meName.str("");
00167       meName<<"Ring_vs_Segment_Disk"<<i;
00168 
00169       if(i<0) this->performeClientOperation(meName.str(), -1 , summary[0]);
00170       else this->performeClientOperation(meName.str(), 1 , summary[2]);
00171     }//loop on Disks
00172       
00173     MonitorElement * RpcOverview = NULL;
00174     meName.str("");
00175     meName<<prefixDir_<<"/RPC_System_Quality_Overview"; 
00176     RpcOverview = dbe_ -> get(meName.str());
00177     RpcOverview->Reset();
00178 
00179     if(RpcOverview) {//Fill Overview ME
00180       for(int r = 0 ; r< 3; r++) {
00181         if (summary[r] == 0 ) continue;
00182         double entries = summary[r]->getEntries();
00183         if(entries == 0) continue;
00184         for (int x = 1; x <= 7; x++) {
00185           RpcOverview->setBinContent(x,r+1,(summary[r]->getBinContent(x)/entries));
00186        } 
00187       } 
00188     } //loop by LimiBloks
00189   }
00190 } 
00191 
00192 void RPCChamberQuality::endLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& iSetup) {  }
00193 
00194 
00195 void RPCChamberQuality::performeClientOperation(std::string MESufix, int region, MonitorElement * quality){
00196 
00197 
00198   MonitorElement * RCQ=NULL;  
00199   MonitorElement * RCQD=NULL; 
00200   
00201   MonitorElement * DEAD=NULL;  
00202   MonitorElement * CLS=NULL;
00203   MonitorElement * MULT=NULL;
00204   MonitorElement * NoisySt=NULL;
00205   MonitorElement * Chip=NULL;
00206   MonitorElement * HV=NULL;
00207   MonitorElement * LV=NULL;
00208   std::stringstream meName; 
00209 
00210   meName.str("");
00211   meName<<prefixDir_<<"/RPCChamberQuality_"<<MESufix; 
00212   RCQ = dbe_ -> get(meName.str());
00213   if (RCQ)  RCQ->Reset();
00214 
00215 
00216   int pos = MESufix.find_last_of("_");
00217   meName.str("");
00218   meName<<prefixDir_<<"/RPCChamberQuality_Distribution"<<MESufix.substr(pos); 
00219   RCQD = dbe_ -> get(meName.str());
00220   if (RCQD) RCQD->Reset();
00221   
00222   //get HV Histo
00223   meName.str("");                        
00224   meName<<prefixDir_<<"/HVStatus_"<<MESufix;
00225   HV = dbe_ -> get(meName.str());       
00226   //get LV Histo
00227   meName.str("");                     
00228   meName<<prefixDir_<<"/LVStatus_"<<MESufix; 
00229   LV = dbe_ -> get(meName.str());
00230   //Dead 
00231   meName.str("");
00232   meName << prefixDir_<<"/DeadChannelFraction_"<<MESufix;
00233   DEAD = dbe_->get(meName.str());
00234   //ClusterSize
00235   meName.str("");
00236   meName<<prefixDir_<<"/ClusterSizeIn1Bin_"<<MESufix;
00237   CLS = dbe_ -> get(meName.str());
00238   //NoisyStrips
00239   meName.str("");
00240   meName<<prefixDir_<<"/RPCNoisyStrips_"<<MESufix;
00241   NoisySt = dbe_ -> get(meName.str());
00242   //Multiplicity
00243   meName.str("");
00244   meName<<prefixDir_<<"/NumberOfDigi_Mean_"<<MESufix;
00245   MULT = dbe_ -> get(meName.str());
00246   //Asymetry
00247   meName.str("");
00248   meName<<prefixDir_<<"/AsymmetryLeftRight_"<<MESufix;
00249   Chip = dbe_ -> get(meName.str());                
00250   
00251   int xBinMax, yBinMax;    
00252 
00253   if (region != 0) xBinMax = 37;
00254   else xBinMax = 13;
00255 
00256   for(int x=1; x<xBinMax; x++) {
00257     if (region != 0 )  {
00258       yBinMax = 7;
00259     }else {  
00260       if(x==4) yBinMax=22;
00261       else if(x==9 || x==11) yBinMax=16;
00262       else yBinMax=18;
00263     }  
00264     for(int y=1; y<yBinMax; y++) {
00265       int hv=1;
00266       int lv=1;
00267       float dead =0;
00268       float firstbin= 0;
00269       float noisystrips = 0;
00270       float mult = 0;
00271       float asy = 0;
00272       chamberQualityState chamberState = GoodState;
00273        
00274       if(HV) hv = (int)HV ->getBinContent(x,y);
00275       if(LV) lv = (int)LV ->getBinContent(x,y);
00276         
00277       if( hv!=1 || lv!=1) { 
00278         chamberState = OffState;
00279       }else {
00280         if(DEAD) dead= DEAD -> getBinContent(x,y);
00281         if(dead>=0.80 ) {  
00282           chamberState = DeadState;
00283         }else if (0.33<=dead && dead<0.80 ){
00284           chamberState = PartiallyDeadState;
00285         }else {        
00286           if(CLS ) firstbin = CLS -> getBinContent(x,y);
00287           if(firstbin >= 0.88) {
00288             chamberState = NoisyStripState;
00289           } else {   
00290             if(NoisySt)  noisystrips = NoisySt -> getBinContent(x,y);
00291             if (noisystrips > 0){ 
00292               chamberState = NoisyStripState;
00293             }else {  
00294               if(MULT) mult = MULT -> getBinContent(x,y);
00295               if(mult>=6) {  
00296                 chamberState = NoisyRollState;
00297               }else {  
00298                 if (Chip) asy = Chip->getBinContent(x,y);
00299                 if(asy>0.35) {  
00300                   chamberState  = BadShapeState;
00301                 }else {  
00302                   chamberState  = GoodState;
00303                 }
00304               }
00305             } 
00306           }
00307         }
00308       }
00309       if (RCQ)  RCQ -> setBinContent(x,y, chamberState);
00310       if (RCQD)   RCQD -> Fill(chamberState); 
00311       if (quality)   quality->Fill(chamberState); 
00312     }
00313   }
00314   return;
00315 } 
00316