CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DPGAnalysis/SiStripTools/plugins/SiPixelQualityHistory.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    SiStripTools
00004 // Class:      SiPixelQualityHistory
00005 // 
00013 //
00014 // Original Author:  Andrea Venturi
00015 //         Created:  Tue Sep 18 17:52:00 CEST 2009
00016 //
00017 //
00018 
00019 
00020 // system include files
00021 #include <memory>
00022 
00023 // user include files
00024 
00025 #include <vector>
00026 #include <map>
00027 
00028 //#include "TGraph.h"
00029 #include "TH1F.h"
00030 
00031 #include "FWCore/Framework/interface/Frameworkfwd.h"
00032 #include "FWCore/Framework/interface/EDAnalyzer.h"
00033 
00034 #include "FWCore/Framework/interface/Event.h"
00035 #include "FWCore/Framework/interface/MakerMacros.h"
00036 #include "FWCore/Framework/interface/Run.h"
00037 
00038 #include "FWCore/Framework/interface/ESHandle.h"
00039 #include "FWCore/Framework/interface/EventSetup.h"
00040 
00041 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00042 
00043 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00044 
00045 #include "FWCore/ServiceRegistry/interface/Service.h"
00046 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00047 
00048 #include "FWCore/Utilities/interface/InputTag.h"
00049 
00050 #include "CondFormats/SiPixelObjects/interface/SiPixelQuality.h"
00051 #include "CondFormats/DataRecord/interface/SiPixelQualityRcd.h"
00052 
00053 #include "DPGAnalysis/SiStripTools/interface/RunHistogramManager.h"
00054 //
00055 // class decleration
00056 //
00057 
00058 class SiPixelQualityHistory : public edm::EDAnalyzer {
00059  public:
00060     explicit SiPixelQualityHistory(const edm::ParameterSet&);
00061     ~SiPixelQualityHistory();
00062 
00063   enum {Summary,Module,ROC};
00064 
00065    private:
00066       virtual void beginJob() ;
00067       virtual void beginRun(const edm::Run&, const edm::EventSetup&) override;
00068       virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
00069       virtual void endJob() ;
00070 
00071       // ----------member data ---------------------------
00072 
00073   RunHistogramManager m_rhm;
00074   const std::vector<edm::ParameterSet> m_monitoredspq;
00075   const unsigned int m_mode;
00076   const bool m_run;
00077   const unsigned int m_maxLS;
00078   const unsigned int m_LSfrac;
00079   //  std::map<std::string,TGraph*> m_history;
00080   std::map<std::string,TH1F*> m_history;
00081   std::map<std::string,TProfile**> m_badmodrun;
00082 
00083 };
00084 
00085 //
00086 // constants, enums and typedefs
00087 //
00088 
00089 //
00090 // static data member definitions
00091 //
00092 
00093 //
00094 // constructors and destructor
00095 //
00096 SiPixelQualityHistory::SiPixelQualityHistory(const edm::ParameterSet& iConfig):
00097   m_rhm(),
00098   m_monitoredspq(iConfig.getParameter<std::vector<edm::ParameterSet> >("monitoredSiPixelQuality")),
00099   m_mode(iConfig.getUntrackedParameter<unsigned int>("granularityMode",Module)),
00100   m_run(iConfig.getParameter<bool>("runProcess")),
00101   m_maxLS(iConfig.getUntrackedParameter<unsigned int>("maxLSBeforeRebin",100)),
00102   m_LSfrac(iConfig.getUntrackedParameter<unsigned int>("startingLSFraction",4)),
00103   m_history(),m_badmodrun()
00104 {
00105    //now do what ever initialization is needed
00106 
00107   edm::Service<TFileService> tfserv;
00108 
00109   for(std::vector<edm::ParameterSet>::const_iterator ps=m_monitoredspq.begin();ps!=m_monitoredspq.end();++ps) {
00110     
00111     std::string name = ps->getParameter<std::string>("name");
00112 
00113     if(m_run) m_history[name] = tfserv->make<TH1F>(name.c_str(),name.c_str(),10,0,10);
00114 
00115     char hrunname[400];
00116     sprintf(hrunname,"badmodrun_%s",name.c_str());
00117     char hruntitle[400];
00118     sprintf(hruntitle,"Number of bad modules %s",name.c_str());
00119     m_badmodrun[name] = m_rhm.makeTProfile(hrunname,hruntitle,m_LSfrac*m_maxLS,0,m_maxLS*262144);
00120   }
00121 
00122 }
00123 
00124 
00125 SiPixelQualityHistory::~SiPixelQualityHistory()
00126 {
00127  
00128    // do anything here that needs to be done at desctruction time
00129    // (e.g. close files, deallocate resources etc.)
00130 
00131 }
00132 
00133 
00134 //
00135 // member functions
00136 //
00137 
00138 // ------------ method called to for each event  ------------
00139 void
00140 SiPixelQualityHistory::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00141 {
00142   //  edm::LogInfo("EventProcessing") << "event being processed";
00143 
00144   for(std::vector<edm::ParameterSet>::const_iterator ps=m_monitoredspq.begin();ps!=m_monitoredspq.end();++ps) {
00145     
00146     std::string name = ps->getParameter<std::string>("name");
00147     std::string label = ps->getParameter<std::string>("spqLabel");
00148     
00149     
00150     
00151     edm::ESHandle<SiPixelQuality> spq;
00152     iSetup.get<SiPixelQualityRcd>().get(label,spq);
00153     
00154     int nbad=0;
00155 
00156     if(m_mode==Summary) {
00157 
00158       //      nbad = spq->BadModuleNumber();
00159 
00160     }  
00161     else {
00162     
00163       std::vector<SiPixelQuality::disabledModuleType> bads = spq->getBadComponentList();
00164       
00165       LogDebug("BadComponents") << bads.size() << " bad components found";
00166     
00167       for(std::vector<SiPixelQuality::disabledModuleType>::const_iterator bc=bads.begin();bc!=bads.end();++bc) {
00168         
00169         if(m_mode==Module) {
00170           if(spq->IsModuleBad(bc->DetID)) ++nbad;
00171           //      if(bc->errorType==0) ++nbad;
00172         }
00173         else if(m_mode == ROC) {
00174           for(int roc=1;roc<2*2*2*2*2*2*2+1;roc*=2) {
00175             if((bc->BadRocs & roc)>0) ++nbad;
00176           }
00177         }
00178       }
00179     }
00180     if(m_badmodrun.find(name)!=m_badmodrun.end() && m_badmodrun[name] && *m_badmodrun[name]) {
00181       (*m_badmodrun[name])->Fill(iEvent.orbitNumber(),nbad);
00182     }
00183     
00184   }
00185 }
00186 
00187 void 
00188 SiPixelQualityHistory::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
00189 {
00190 
00191   m_rhm.beginRun(iRun);
00192   
00193   // loop on all the SiPixelQuality objects to be monitored
00194 
00195   for(std::vector<edm::ParameterSet>::const_iterator ps=m_monitoredspq.begin();ps!=m_monitoredspq.end();++ps) {
00196     
00197     std::string name = ps->getParameter<std::string>("name");
00198     std::string label = ps->getParameter<std::string>("spqLabel");
00199     
00200     if(m_badmodrun.find(name)!=m_badmodrun.end()) {
00201       if(m_badmodrun[name] && *m_badmodrun[name]) {
00202         (*m_badmodrun[name])->SetBit(TH1::kCanRebin);
00203         (*m_badmodrun[name])->GetXaxis()->SetTitle("time [Orb#]"); (*m_badmodrun[name])->GetYaxis()->SetTitle("bad components"); 
00204       }
00205     }
00206     
00207     if(m_run) {
00208 
00209       edm::ESHandle<SiPixelQuality> spq;
00210       iSetup.get<SiPixelQualityRcd>().get(label,spq);
00211       
00212       int nbad=0;
00213       
00214       if(m_mode==Summary) {
00215         
00216         //      nbad = spq->BadModuleNumber();
00217         
00218       }  
00219       else {
00220         
00221         std::vector<SiPixelQuality::disabledModuleType> bads = spq->getBadComponentList();
00222         
00223         LogDebug("BadComponents") << bads.size() << " bad components found";
00224         
00225         for(std::vector<SiPixelQuality::disabledModuleType>::const_iterator bc=bads.begin();bc!=bads.end();++bc) {
00226           
00227           if(m_mode==Module) {
00228             if(spq->IsModuleBad(bc->DetID)) ++nbad;
00229             //    if(bc->errorType==0) ++nbad;
00230           }
00231           else if(m_mode == ROC) {
00232             for(int roc=1;roc<2*2*2*2*2*2*2+1;roc*=2) {
00233               if((bc->BadRocs & roc)>0) ++nbad;
00234             }
00235           }
00236         }
00237       }
00238       char runname[100];
00239       sprintf(runname,"%d",iRun.run());
00240       LogDebug("AnalyzedRun") << name << " " << runname << " " << nbad;
00241       m_history[name]->Fill(runname,nbad);
00242     }    
00243   }
00244   
00245 }
00246 
00247 // ------------ method called once each job just before starting event loop  ------------
00248 void 
00249 SiPixelQualityHistory::beginJob()
00250 {}
00251 
00252 // ------------ method called once each job just after ending the event loop  ------------
00253 void 
00254 SiPixelQualityHistory::endJob() 
00255 {
00256   /*
00257   for(std::vector<edm::ParameterSet>::const_iterator ps=m_monitoredspq.begin();ps!=m_monitoredspq.end();++ps) {
00258     
00259     std::string name = ps->getParameter<std::string>("name");
00260     m_history[name]->Write();
00261 
00262   }
00263   */
00264 }
00265 
00266 
00267 //define this as a plug-in
00268 DEFINE_FWK_MODULE(SiPixelQualityHistory);