CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DQM/RPCMonitorClient/src/RPCDBPopConAnalyzer.cc

Go to the documentation of this file.
00001 #include "CondCore/PopCon/interface/PopConAnalyzer.h"
00002 #include "DQM/RPCMonitorClient/interface/RPCDBHandler.h"
00003 #include "FWCore/Framework/interface/MakerMacros.h"
00004 #include "FWCore/Framework/interface/MakerMacros.h"
00005 #include <DataFormats/MuonDetId/interface/RPCDetId.h>
00006 #include <Geometry/RPCGeometry/interface/RPCGeomServ.h>
00007 #include <Geometry/CommonDetUnit/interface/GeomDet.h>
00008 #include <Geometry/Records/interface/MuonGeometryRecord.h>
00009 #include <Geometry/RPCGeometry/interface/RPCGeometry.h>
00010 #include "CondFormats/RPCObjects/interface/RPCDQMObject.h"
00011 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00012 #include "DQM/RPCMonitorDigi/interface/utils.h"
00013 #include "DQM/RPCMonitorDigi/interface/RPCBookFolderStructure.h"
00014 #include <FWCore/Framework/interface/Frameworkfwd.h>
00015 #include <FWCore/Framework/interface/EDAnalyzer.h>
00016 #include <FWCore/Framework/interface/Event.h>
00017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00018 #include "FWCore/ServiceRegistry/interface/Service.h"
00019 #include "DQMServices/Core/interface/DQMStore.h"
00020 #include "DQMServices/Core/interface/MonitorElement.h"
00021 #include "FWCore/Framework/interface/ESHandle.h"
00022 
00023 //typedef popcon::PopConAnalyzer<RPCDBHandler> RPCDBPopConAnalyzer;
00024 
00025 class RPCDBPopConAnalyzer: public popcon::PopConAnalyzer<RPCDBHandler>
00026 {
00027 public:
00028   typedef RPCDBHandler SourceHandler;
00029 
00030   RPCDBPopConAnalyzer(const edm::ParameterSet& pset): 
00031     popcon::PopConAnalyzer<RPCDBHandler>(pset),
00032     m_populator(pset),
00033     m_source(pset.getParameter<edm::ParameterSet>("Source")) {
00034       subsystemFolder_= pset.getUntrackedParameter<std::string>("RPCFolder", "RPC");
00035       recHitTypeFolder_= pset.getUntrackedParameter<std::string>("RecHitTypeFolder", "Noise");
00036       summaryFolder_= pset.getUntrackedParameter<std::string>("SummaryFolder", "SummaryHistograms");
00037       efficiencyFolder_= pset.getUntrackedParameter<std::string>("EfficiencyFolder", "RPCEfficiency");
00038     }
00039 
00040 private:
00041   virtual void endJob() 
00042   {
00043     m_source.initObject(rpcDQMObject);
00044     write();
00045     dbe =0;
00046   }
00047 
00048   virtual void beginRun(const edm::Run& run, const edm::EventSetup& iSetup){
00049     dbe = edm::Service<DQMStore>().operator->();
00050     dbe->setCurrentFolder("RPCPVT");
00051   }//beginRun
00052 
00053 
00054   virtual void analyze(const edm::Event& ev, const edm::EventSetup& iSetup){ //}
00055 
00056   //virtual void endRun(const edm::Run& r, const edm::EventSetup& iSetup){
00057 
00058     rpcDQMObject = new RPCDQMObject();
00059     RPCDQMObject::DQMObjectItem rpcDqmItem;
00060 
00061     edm::ESHandle<RPCGeometry> rpcGeo;
00062     iSetup.get<MuonGeometryRecord>().get(rpcGeo);
00063     //Loop on RPC geometry to access ME for each roll
00064 
00065     RPCBookFolderStructure *  folderStr = new RPCBookFolderStructure(); 
00066     rpcdqm::utils rpcUtils;
00067 
00068     for (TrackingGeometry::DetContainer::const_iterator it=rpcGeo->dets().begin();it<rpcGeo->dets().end();it++){
00069       if(dynamic_cast< RPCChamber* >( *it ) != 0 ){
00070         RPCChamber* ch = dynamic_cast< RPCChamber* >( *it );
00071         std::vector< const RPCRoll*> roles = (ch->rolls());
00072         for(std::vector<const RPCRoll*>::const_iterator r = roles.begin();r != roles.end(); ++r){
00073 
00074           //Get RPC DetId
00075           RPCDetId rpcId = (*r)->id();
00076 
00077           //Check if rpcId is Valid. If not continue;
00078 
00079           //Get roll name
00080           RPCGeomServ rpcsrv(rpcId);
00081           std::string nameRoll = rpcsrv.name();
00082 
00083           //Get ME
00084           std::stringstream mepath;
00085           mepath.str("");
00086           //          mepath<<"RPCPVT";
00087           MonitorElement * MEnumcls = dbe->get(subsystemFolder_ + "/" + recHitTypeFolder_ + "/" + folderStr->folderStructure(rpcId)  + "/" + "NumberOfClusters_" + nameRoll);
00088           MonitorElement * MEcls = dbe->get(subsystemFolder_ + "/" + recHitTypeFolder_ + "/" + folderStr->folderStructure(rpcId)  + "/" + "ClusterSize_" + nameRoll);
00089           MonitorElement * MEocc= dbe->get(subsystemFolder_ + "/" + recHitTypeFolder_ + "/" + folderStr->folderStructure(rpcId) + "/" + "Occupancy_" + nameRoll);
00090           MonitorElement * MEbx = dbe->get(subsystemFolder_ + "/" + recHitTypeFolder_ + "/" + folderStr->folderStructure(rpcId) + "/" + "BXN_" + nameRoll);
00091 
00092           MonitorElement * MEstatus = NULL;
00093           MonitorElement * MEeff = NULL;
00094           rpcDqmItem.status = -999;
00095           rpcDqmItem.efficiency= -999;
00096 
00097           if( rpcId.region() == 0){ //BARREL
00098 
00099             int nr = rpcUtils.detId2RollNr(rpcId);
00100             int sector = (int)rpcId.sector();
00101 
00102             //Status
00103             mepath.str("");
00104             mepath<<subsystemFolder_<<"/" << recHitTypeFolder_<<"/" <<  summaryFolder_<<"/RPCChamberQuality_Roll_vs_Sector_Wheel"<<rpcId.ring();
00105             MEstatus = dbe->get(mepath.str());  
00106             if(MEstatus != 0 ){
00107               rpcDqmItem.status =  MEstatus->getBinContent(sector, nr);
00108             }else{
00109             edm::LogWarning("rpcdbclient")<< "[RPCDBClient] Did not find Status for Barrel "<< nameRoll;
00110             }
00111 
00112             //Efficiency
00113             mepath.str("");
00114             if( rpcId.ring() > 0){
00115               mepath<<subsystemFolder_<<"/" << efficiencyFolder_<<"/Efficiency_Roll_vs_Sector_Wheel_+"<<rpcId.ring();
00116             }else{
00117               mepath<<subsystemFolder_<<"/" << efficiencyFolder_<<"/Efficiency_Roll_vs_Sector_Wheel_"<<rpcId.ring();
00118             }
00119 
00120             MEeff = dbe->get(mepath.str());  
00121             if(MEeff != 0 ){
00122               rpcDqmItem.efficiency =  MEeff->getBinContent(sector, nr);
00123             }else{
00124             edm::LogWarning("rpcdbclient")<< "[RPCDBClient] Did not find Efficiency for Barrel "<< nameRoll;
00125             }
00126 
00127 
00128           }else{
00129             int segment =  rpcsrv.segment() ;
00130             int endcapbin =  (rpcId.ring()-1)*3-rpcId.roll()+1;
00131             int disk = (rpcId.region() * rpcId.layer());
00132 
00133             //Status
00134             mepath.str("");
00135             mepath<<subsystemFolder_<<"/" << recHitTypeFolder_<<"/" <<  summaryFolder_<<"/RPCChamberQuality_Ring_vs_Segment_Disk"<<disk;
00136             MEstatus = dbe->get(mepath.str());
00137             if(MEstatus != 0 ){
00138               rpcDqmItem.status =   MEstatus->getBinContent(segment,endcapbin);
00139             }else{
00140             edm::LogWarning("rpcdbclient")<< "[RPCDBClient] Did not find Status for Endcap "<< nameRoll;
00141             }
00142 
00143 
00144             //Efficiency
00145             mepath.str("");
00146             mepath<<subsystemFolder_<<"/" << efficiencyFolder_<<"/Efficiency_Roll_vs_Segment_Disk_"<<disk;
00147             MEeff = dbe->get(mepath.str());  
00148             if(MEeff != 0 ){
00149               rpcDqmItem.efficiency =  MEeff->getBinContent(segment,endcapbin);
00150             }else{
00151             edm::LogWarning("rpcdbclient")<< "[RPCDBClient] Did not find Efficiency for Endcap "<< nameRoll;
00152             }
00153 
00154 
00155           }
00156     
00157           rpcDqmItem.dpid = (int)rpcId;
00158           rpcDqmItem.clusterSize = -999;
00159           rpcDqmItem.numdigi = -999;
00160             rpcDqmItem.numcluster =-999;
00161           rpcDqmItem.bx = -999;
00162           rpcDqmItem.bxrms = -999;
00163           //rpcDqmItem.status = -999;
00164 
00165           if (MEnumcls != 0) {
00166             rpcDqmItem.numcluster = (float)MEnumcls->getMean();
00167           }else{
00168             edm::LogWarning("rpcdbclient")<< "[RPCDBClient] Did not find Number of Clusters for Roll "<< nameRoll;
00169           }
00170 
00171           if (MEcls != 0) {
00172             rpcDqmItem.clusterSize = (float)MEcls->getMean();
00173           }else{
00174             edm::LogWarning("rpcdbclient")<< "[RPCDBClient] Did not find ClusterSize for Roll "<< nameRoll;
00175           }
00176 
00177           if (MEbx != 0) {
00178             rpcDqmItem.bx = (float)MEbx->getMean();
00179             rpcDqmItem.bxrms = (float)MEbx->getRMS();
00180           }else{
00181             edm::LogWarning("rpcdbclient")<< "[RPCDBClient] Did not find BX for Roll "<< nameRoll;
00182           }
00183          
00184           if (MEocc != 0) {
00185             rpcDqmItem.numdigi = (float)MEocc->getEntries();
00186           }else{
00187             edm::LogWarning("rpcdbclient")<< "[RPCDBClient] Did not find Occupancy for Roll "<< nameRoll;
00188           }
00189          
00190 
00191 
00192           (rpcDQMObject->v_cls).push_back(rpcDqmItem);
00193         }//End loop Rolls
00194       }
00195     }//End loop RPC Geometry
00196 
00197   }
00198   
00199   void write() { m_populator.write(m_source); }
00200 
00201 private:
00202   popcon::PopCon m_populator;
00203   SourceHandler m_source;
00204 
00205   std::string subsystemFolder_;
00206   std::string summaryFolder_;
00207   std::string recHitTypeFolder_;
00208   std::string efficiencyFolder_;
00209   DQMStore * dbe;
00210   RPCDQMObject * rpcDQMObject;
00211 
00212 };
00213 
00214 DEFINE_FWK_MODULE(RPCDBPopConAnalyzer);
00215