CMS 3D CMS Logo

RPCEventSummary.cc

Go to the documentation of this file.
00001 /*  \author Anna Cimmino*/
00002 #include <string>
00003 #include <sstream>
00004 #include <map>
00005 #include <DQM/RPCMonitorClient/interface/RPCEventSummary.h>
00006 #include "DQM/RPCMonitorDigi/interface/RPCBookFolderStructure.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 using namespace edm;
00022 using namespace std;
00023 RPCEventSummary::RPCEventSummary(const ParameterSet& ps ){
00024   LogVerbatim ("rpceventsummary") << "[RPCEventSummary]: Constructor";
00025 
00026   enableReportSummary_ = ps.getUntrackedParameter<bool>("EnableSummaryReport",true);
00027   prescaleFactor_ =  ps.getUntrackedParameter<int>("PrescaleFactor", 10);
00028   eventInfoPath_ = ps.getUntrackedParameter<string>("EventInfoPath", "RPC/EventInfo");
00029   prefixDir_ = ps.getUntrackedParameter<string>("RPCPrefixDir", "RPC/RecHits");
00030   verbose_=ps.getUntrackedParameter<bool>("VerboseLevel", 0);
00031   minHitsInRoll_=ps.getUntrackedParameter<unsigned int>("MinimunHitsPerRoll", 2000);
00032  tier0_=ps.getUntrackedParameter<bool>("Tier0", false);
00033 
00034 }
00035 
00036 RPCEventSummary::~RPCEventSummary(){
00037   LogVerbatim ("rpceventsummary") << "[RPCEventSummary]: Destructor ";
00038   dbe_=0;
00039 }
00040 
00041 void RPCEventSummary::beginJob(const EventSetup& iSetup){
00042  LogVerbatim ("rpceventsummary") << "[RPCEventSummary]: Begin job ";
00043  dbe_ = Service<DQMStore>().operator->();
00044  dbe_->setVerbose(verbose_);
00045 }
00046 
00047 void RPCEventSummary::beginRun(const Run& r, const EventSetup& c){
00048  LogVerbatim ("rpceventsummary") << "[RPCEventSummary]: Begin run";
00049 
00050  nLumiSegs_=0;
00051 
00052  MonitorElement* me;
00053  dbe_->setCurrentFolder(eventInfoPath_);
00054 
00055  //a global summary float [0,1] providing a global summary of the status 
00056  //and showing the goodness of the data taken by the the sub-system 
00057  string histoName="reportSummary";
00058  if ( me = dbe_->get(eventInfoPath_ +"/"+ histoName) ) {
00059     dbe_->removeElement(me->getName());
00060   }
00061 
00062   me = dbe_->bookFloat(histoName);
00063   me->Fill(1);
00064 
00065   //TH2F ME providing a map of values[0-1] to show if problems are localized or distributed
00066   if ( me = dbe_->get(eventInfoPath_ + "/reportSummaryMap") ) {
00067      dbe_->removeElement(me->getName());
00068   }
00069   me = dbe_->book2D("reportSummaryMap", "RPC Report Summary Map", 15, -7.5, 7.5, 12, 0.5 ,12.5);
00070   
00071   //customize the 2d histo
00072   stringstream BinLabel;
00073   for (int i= 1 ; i<=15; i++){
00074     BinLabel.str("");
00075     if(i<13){
00076       BinLabel<<"Sec"<<i;
00077        me->setBinLabel(i,BinLabel.str(),2);
00078     } 
00079 
00080     BinLabel.str("");
00081     if(i<5)
00082       BinLabel<<"Disk"<<i-5;
00083     else if(i>11)
00084       BinLabel<<"Disk"<<i-11;
00085     else if(i==11 || i==5)
00086       BinLabel.str("");
00087     else
00088       BinLabel<<"Wheel"<<i-8;
00089  
00090      me->setBinLabel(i,BinLabel.str(),1);
00091   }
00092 
00093   //fill the histo with "1" --- just for the moment
00094   for(int i=1; i<=15; i++){
00095      for (int j=1; j<=12; j++ ){
00096        if(i==5 || i==11 || (j>6 && (i<6 || i>10)))    
00097          me->setBinContent(i,j,-1);//bins that not correspond to subdetector parts
00098        else     
00099          me->setBinContent(i,j,1);
00100      }
00101    }
00102 
00103  //the reportSummaryContents folder containins a collection of ME floats [0-1] (order of 5-10)
00104  // which describe the behavior of the respective subsystem sub-components.
00105   dbe_->setCurrentFolder(eventInfoPath_+ "/reportSummaryContents");
00106   
00107   stringstream segName;
00108   for(int i=-4; i<=4; i++){
00109     if(i>-3 && i<3) {
00110       segName.str("");
00111       segName<<"RPC_Wheel"<<i;
00112       segmentNames.push_back(segName.str());
00113     }
00114     if(i==0) continue;
00115     segName.str("");
00116     segName<<"RPC_Disk"<<i;
00117     segmentNames.push_back(segName.str());
00118   }
00119   
00120   //  segmentNames.push_back("RPC_DataIntegrity");
00121   // segmentNames.push_back("RPC_Timing");
00122 
00123   for(unsigned int i=0; i<segmentNames.size(); i++){
00124     if ( me = dbe_->get(eventInfoPath_ + "/reportSummaryContents/" +segmentNames[i]) ) {
00125       dbe_->removeElement(me->getName());
00126     }
00127     me = dbe_->bookFloat(segmentNames[i]);
00128     me->Fill(1);
00129   }
00130 }
00131 
00132 void RPCEventSummary::beginLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context){} 
00133 
00134 void RPCEventSummary::analyze(const Event& iEvent, const EventSetup& c) {
00135   nLumiSegs_=iEvent.luminosityBlock();
00136 }
00137 
00138 void RPCEventSummary::endLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& iSetup) {  
00139   LogVerbatim ("rpceventsummary") <<"[RPCEventSummary]: End of LS transition, performing DQM client operation";
00140 
00141   if (tier0_) return;
00142 
00143   // counts number of lumiSegs 
00144    nLumiSegs_ = lumiSeg.id().luminosityBlock();
00145    //nLumiSegs_++;
00146 
00147   //check some statements and prescale Factor
00148   if(enableReportSummary_  &&  (nLumiSegs_%prescaleFactor_ == 0)) {
00149  
00150   ESHandle<RPCGeometry> rpcGeo;
00151   iSetup.get<MuonGeometryRecord>().get(rpcGeo);
00152  
00153   map<int, map< int ,  pair<float,float> > >  barrelMap, endcapPlusMap, endcapMinusMap;
00154     
00155   //Loop on chambers
00156   for (TrackingGeometry::DetContainer::const_iterator it=rpcGeo->dets().begin();it<rpcGeo->dets().end();it++){
00157     if( dynamic_cast< RPCChamber* >( *it ) != 0 ){
00158        RPCChamber* ch = dynamic_cast< RPCChamber* >( *it ); 
00159        std::vector< const RPCRoll*> roles = (ch->rolls());
00160        int ty=1;
00161        //Loop on rolls in given chamber
00162        for(std::vector<const RPCRoll*>::const_iterator r = roles.begin();r != roles.end(); ++r){
00163          RPCDetId detId = (*r)->id();
00164          //Get Occupancy ME for roll
00165          RPCGeomServ RPCname(detId);
00166          RPCBookFolderStructure *  folderStr = new RPCBookFolderStructure();
00167          MonitorElement * myMe = dbe_->get(prefixDir_+"/"+ folderStr->folderStructure(detId)+"/Occupancy_"+RPCname.name()); 
00168          if (!myMe)continue;
00169          
00170          //check for enough statistics
00171          if (myMe->getEntries() < minHitsInRoll_) continue;
00172 
00173          const QReport * theOccupancyQReport = myMe->getQReport("DeadChannel_0");  
00174          if(!theOccupancyQReport) continue;
00175          vector<dqm::me_util::Channel> badChannels = theOccupancyQReport->getBadChannels();
00176          float goodFraction =((*r)->nstrips() - badChannels.size())/(*r)->nstrips();              
00177          if (detId.region()==0) {
00178            barrelMap[detId.ring()][detId.sector()].first += goodFraction;
00179            barrelMap[detId.ring()][detId.sector()].second++ ;
00180          }else if(detId.region()==-1){
00181            endcapMinusMap[-1 * detId.station()][detId.sector()].first +=  goodFraction;
00182            endcapMinusMap[-1 * detId.station()][detId.sector()].second++ ;
00183          }else {
00184            endcapPlusMap[detId.station()][detId.sector()].first += goodFraction;
00185            endcapPlusMap[detId.station()][detId.sector()].second++;
00186          }
00187          ty++;      
00188        }//End loop on rolls in given chambers
00189     }
00190   }//End loop on chamber
00191   
00192   //clear counters
00193   allRolls_=0;
00194   allGood_=0;
00195   
00196   this->fillReportSummary(barrelMap, 0);
00197   
00198   this->fillReportSummary(endcapPlusMap, 1);
00199   
00200   this->fillReportSummary(endcapMinusMap, -1);
00201 
00202   //Fill report summary
00203   MonitorElement *   reportSummary = dbe_->get(eventInfoPath_ +"/reportSummary");
00204   if(reportSummary == NULL) return;
00205 
00206   if (allRolls_!=0)   reportSummary->Fill(allGood_/allRolls_);
00207   else reportSummary->Fill(-1);
00208   }
00209 }
00210 
00211 
00212 //Fill report summary
00213 void  RPCEventSummary::fillReportSummary(const map<int,map<int,pair<float,float> > > & sumMap, int region){
00214 
00215   MonitorElement *   reportSummaryMap = dbe_->get(eventInfoPath_ +"/reportSummaryMap");
00216   
00217   string path;
00218   int binOffSet=0;
00219 
00220   if (region==0){
00221     path="/reportSummaryContents/RPC_Wheel";
00222     binOffSet=8;
00223   }else if (region==1){
00224     path="/reportSummaryContents/RPC_Disk";
00225     binOffSet=11;
00226   }else if (region==-1){
00227     path="/reportSummaryContents/RPC_Disk-";
00228     binOffSet=5;
00229   }
00230 
00231   map<int,map<int,pair<float,float> > >::const_iterator itr;
00232   stringstream meName;
00233 
00234   if (sumMap.size()!=0){
00235     //Loop on  report summary data 
00236     for (itr=sumMap.begin(); itr!=sumMap.end(); itr++){
00237       float Rolls=0; 
00238       float Good=0;
00239       for (map< int ,  pair<float,float> >::const_iterator meItr = (*itr).second.begin(); meItr!=(*itr).second.end();meItr++){
00240         //Fill report summary map, a TH2F ME.
00241         if ((*meItr).second.second != 0) {
00242           //      cout<<"i'm here"<<(*itr).first<<"_"<< region<<endl;
00243           reportSummaryMap->setBinContent((*itr).first+binOffSet,(*meItr).first, ((*meItr).second.first/(*meItr).second.second) ); 
00244       }  else reportSummaryMap->setBinContent((*itr).first+binOffSet,(*meItr).first,-1);
00245         Good += (*meItr).second.first;
00246         Rolls += (*meItr).second.second;
00247       }
00248       allGood_ += Good;
00249       allRolls_ +=  Rolls ;
00250       //Fill wheel/disk report summary
00251       meName.str("");
00252       meName<<eventInfoPath_<<path<<(*itr).first;
00253 
00254       MonitorElement *   reportSummaryContents = dbe_->get( meName.str());
00255       if (Rolls != 0)  reportSummaryContents->Fill(Good/Rolls);
00256       else reportSummaryContents->Fill(-1);
00257     }  //End Loop on report summary data 
00258   }else{
00259     for (int j=0; j<=4; j++){
00260       meName.str("");
00261       meName<<eventInfoPath_<<path<<j;
00262 
00263       MonitorElement *   reportSummaryContents = dbe_->get( meName.str());
00264       if ( reportSummaryContents == NULL) continue;
00265         reportSummaryContents->Fill(-1);
00266       for(int h =1; h<=12; h++){
00267         if(region!=0 && h>6) break; //endcap has only 6 sectors
00268         if (region == -1) reportSummaryMap->setBinContent(-j+binOffSet,h, -1); 
00269         else reportSummaryMap->setBinContent(j+binOffSet,h, -1); 
00270       }
00271     }   
00272   }
00273 }

Generated on Tue Jun 9 17:33:17 2009 for CMSSW by  doxygen 1.5.4