CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/DQMOffline/JetMET/src/JetMETDQMOfflineClient.cc

Go to the documentation of this file.
00001 #include "DQMOffline/JetMET/interface/JetMETDQMOfflineClient.h"
00002 
00003 #include "FWCore/Framework/interface/Run.h"
00004 #include "FWCore/Framework/interface/Event.h"
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 #include "FWCore/ServiceRegistry/interface/Service.h"
00007 
00008 #include "DQMServices/Core/interface/DQMStore.h"
00009 #include "DQMServices/Core/interface/MonitorElement.h"
00010 
00011 JetMETDQMOfflineClient::JetMETDQMOfflineClient(const edm::ParameterSet& iConfig):conf_(iConfig)
00012 {
00013 
00014   dbe_ = edm::Service<DQMStore>().operator->();
00015   if (!dbe_) {
00016     edm::LogError("JetMETDQMOfflineClient") 
00017     << "unable to get DQMStore service, upshot is no client histograms will be made";
00018   }
00019   if(iConfig.getUntrackedParameter<bool>("DQMStore", false)) {
00020     if(dbe_) dbe_->setVerbose(0);
00021   }
00022  
00023   verbose_ = conf_.getUntrackedParameter<int>("Verbose");
00024 
00025   dirName_=iConfig.getUntrackedParameter<std::string>("DQMDirName");
00026   if(dbe_) dbe_->setCurrentFolder(dirName_);
00027 
00028   dirNameJet_=iConfig.getUntrackedParameter<std::string>("DQMJetDirName");
00029   dirNameMET_=iConfig.getUntrackedParameter<std::string>("DQMMETDirName");
00030  
00031 }
00032 
00033 
00034 JetMETDQMOfflineClient::~JetMETDQMOfflineClient()
00035 { 
00036   
00037 }
00038 
00039 void JetMETDQMOfflineClient::beginJob(void)
00040 {
00041  
00042 
00043 }
00044 
00045 void JetMETDQMOfflineClient::endJob() 
00046 {
00047 
00048 }
00049 
00050 void JetMETDQMOfflineClient::beginRun(const edm::Run& run, const edm::EventSetup& c)
00051 {
00052  
00053 }
00054 
00055 
00056 void JetMETDQMOfflineClient::endRun(const edm::Run& run, const edm::EventSetup& c)
00057 {
00058   runClient_();
00059 }
00060 
00061 //dummy analysis function
00062 void JetMETDQMOfflineClient::analyze(const edm::Event& iEvent,const edm::EventSetup& iSetup)
00063 {
00064   
00065 }
00066 
00067 void JetMETDQMOfflineClient::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,const edm::EventSetup& c)
00068 { 
00069 
00070 }
00071 
00072 void JetMETDQMOfflineClient::runClient_()
00073 {
00074   
00075   if(!dbe_) return; //we dont have the DQMStore so we cant do anything
00076 
00077   LogDebug("JetMETDQMOfflineClient") << "runClient" << std::endl;
00078   if (verbose_) std::cout << "runClient" << std::endl; 
00079 
00080   std::vector<MonitorElement*> MEs;
00081 
00083   // Total number of lumi sections and time for this run
00085 
00086   TH1F* tlumisec;
00087   MonitorElement *meLumiSec = dbe_->get("JetMET/lumisec");
00088 
00089   int    totlsec=0;
00090   double totltime=0;
00091 
00092   if ( meLumiSec->getRootObject() ){
00093 
00094     tlumisec = meLumiSec->getTH1F();    
00095     for (int i=0; i<500; i++){
00096       if (tlumisec->GetBinContent(i+1)) totlsec++;
00097     }
00098 
00099   }
00100   totltime = totlsec * 90.;
00101 
00103   // MET
00105 
00106   dbe_->setCurrentFolder(dirName_+"/"+dirNameMET_);
00107 
00108   MonitorElement *me;
00109   TH1F *tMET;
00110   TH1F *tMETRate;
00111   MonitorElement *hMETRate;
00112 
00113   //
00114   // --- Producing MET rate plots
00115   //
00116 
00117   // Look at all folders (JetMET/MET/CaloMET, JetMET/MET/CaloMETNoHF, etc)
00118   std::vector<std::string> fullPathDQMFolders = dbe_->getSubdirs();
00119   for(unsigned int i=0;i<fullPathDQMFolders.size();i++) {
00120 
00121     if (verbose_) std::cout << fullPathDQMFolders[i] << std::endl;      
00122     dbe_->setCurrentFolder(fullPathDQMFolders[i]);
00123 
00124     // Look at all subfolders (JetMET/MET/CaloMET/{All,Cleaup,BeamHaloIDLoosePass, etc})
00125     std::vector<std::string> fullPathDQMSubFolders = dbe_->getSubdirs();
00126     for(unsigned int j=0;j<fullPathDQMSubFolders.size();j++) {
00127 
00128       if (verbose_) std::cout << fullPathDQMSubFolders[j] << std::endl;      
00129       dbe_->setCurrentFolder(fullPathDQMSubFolders[j]);
00130       if (verbose_) std::cout << "setCurrentFolder done" << std::endl;      
00131 
00132       // Look at all MonitorElements in this folder
00133       std::string METMEName="METTask_CaloMET";
00134       if ( dbe_->get(fullPathDQMSubFolders[j]+"/"+"METTask_MET") )  METMEName="METTask_MET";
00135       if ( dbe_->get(fullPathDQMSubFolders[j]+"/"+"METTask_PfMET")) METMEName="METTask_PfMET";
00136 
00137       me = dbe_->get(fullPathDQMSubFolders[j]+"/"+METMEName);
00138       if (verbose_) std::cout << "get done" << std::endl;      
00139       
00140       if ( me ) {
00141         if (verbose_) std::cout << "me true" << std::endl;      
00142         if ( me->getRootObject() ) {
00143           if (verbose_) std::cout << "me getRootObject true" << std::endl;      
00144 
00145           MonitorElement *metest = dbe_->get(fullPathDQMSubFolders[j]+"/"+METMEName+"Rate");
00146           if (metest) dbe_->removeElement(METMEName+"Rate");
00147 
00148           if (verbose_) std::cout << "metest done" << std::endl;      
00149           
00150           tMET     = me->getTH1F();
00151           if (verbose_) std::cout << "getTH1F done" << std::endl;      
00152 
00153           // Integral plot 
00154           tMETRate = (TH1F*) tMET->Clone((METMEName+"Rate").c_str());
00155           for (int i = tMETRate->GetNbinsX()-1; i>=0; i--){
00156             tMETRate->SetBinContent(i+1,tMETRate->GetBinContent(i+2)+tMET->GetBinContent(i+1));
00157           }
00158           if (verbose_) std::cout << "making integral plot done" << std::endl;      
00159       
00160           // Convert number of events to Rate (Hz)
00161           if (totltime){
00162             for (int i=tMETRate->GetNbinsX()-1;i>=0;i--){
00163               tMETRate->SetBinContent(i+1,tMETRate->GetBinContent(i+1)/double(totltime));
00164             }
00165           }
00166           if (verbose_) std::cout << "making rate plot done" << std::endl;      
00167 
00168           hMETRate      = dbe_->book1D(METMEName+"Rate",tMETRate);
00169           hMETRate->setTitle(METMEName+" Rate");
00170           hMETRate->setAxisTitle("MET Threshold [GeV]",1);
00171           if (verbose_) std::cout << "booking rate plot ME done" << std::endl;      
00172 
00173         } // me->getRootObject()
00174       } // me
00175       if (verbose_) std::cout << "end of subfolder loop" << std::endl;
00176     }   // fullPathDQMSubFolders-loop - All, Cleanup, ...
00177     if (verbose_) std::cout << "end of folder loop" << std::endl;
00178   }   // fullPathDQMFolders-loop - CaloMET, CaloMETNoHF, ...
00179 
00181   // Jet
00183    
00184   dbe_->setCurrentFolder(dirName_+"/"+dirNameJet_);
00185 
00186   // Look at all folders (JetMET/Jet/AntiKtJets,JetMET/Jet/CleanedAntiKtJets, etc)
00187   fullPathDQMFolders.clear();
00188   fullPathDQMFolders = dbe_->getSubdirs();
00189   for(unsigned int i=0;i<fullPathDQMFolders.size();i++) {
00190 
00191     if (verbose_) std::cout << fullPathDQMFolders[i] << std::endl;      
00192     dbe_->setCurrentFolder(fullPathDQMFolders[i]);
00193 
00194     std::vector<std::string> getMEs = dbe_->getMEs();
00195 
00196     std::vector<std::string>::const_iterator cii;
00197     for(cii=getMEs.begin(); cii!=getMEs.end(); cii++) {
00198       if ((*cii).find("_binom")!=std::string::npos) continue;
00199       if ((*cii).find("JIDPassFractionVS")!=std::string::npos){  // Look for MEs with "JIDPassFractionVS"
00200         me = dbe_->get(fullPathDQMFolders[i]+"/"+(*cii));
00201 
00202         if ( me ) {
00203         if ( me->getRootObject() ) {
00204           TProfile *tpro = (TProfile*) me->getRootObject();
00205           TH1F *tPassFraction = new TH1F(((*cii)+"_binom").c_str(),((*cii)+"_binom").c_str(),
00206             tpro->GetNbinsX(),tpro->GetBinLowEdge(1),tpro->GetBinLowEdge(tpro->GetNbinsX()+1));
00207           for (int ibin=0; ibin<tpro->GetNbinsX(); ibin++){
00208             double nentries = tpro->GetBinEntries(ibin+1);
00209             double epsilon  = tpro->GetBinContent(ibin+1);
00210             if (epsilon>1. || epsilon<0.) continue;
00211             tPassFraction->SetBinContent(ibin+1,epsilon);                        // 
00212             if(nentries>0) tPassFraction->SetBinError(ibin+1,pow(epsilon*(1.-epsilon)/nentries,0.5));
00213           }
00214         } // me->getRootObject()
00215         } // me
00216       } // if find
00217     }   // cii-loop
00218 
00219   } // i-loop 
00220 
00221 }
00222