CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/DQMOffline/PFTau/plugins/PFClient.cc

Go to the documentation of this file.
00001 #include "DQMOffline/PFTau/plugins/PFClient.h"
00002 
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "DataFormats/Common/interface/Handle.h"
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 #include "FWCore/Utilities/interface/InputTag.h"
00007 
00008 
00009 #include "DQMServices/Core/interface/DQMStore.h"
00010 #include "DQMServices/Core/interface/MonitorElement.h"
00011 #include "FWCore/ServiceRegistry/interface/Service.h"
00012 
00013 //
00014 // -- Constructor
00015 //
00016 PFClient::PFClient(const edm::ParameterSet& parameterSet)  
00017 {
00018   folderNames_ = parameterSet.getParameter< std::vector<std::string> >( "FolderNames" );
00019   histogramNames_  = parameterSet.getParameter< std::vector<std::string> >( "HistogramNames" );
00020   efficiencyFlag_ =  parameterSet.getParameter< bool> ("CreateEfficiencyPlots" );
00021   effHistogramNames_  = parameterSet.getParameter< std::vector<std::string> >( "HistogramNamesForEfficiencyPlots" );
00022 }
00023 //
00024 // -- BeginJob
00025 //
00026 void PFClient::beginJob() {
00027 
00028   dqmStore_ = edm::Service<DQMStore>().operator->();
00029 }
00030 //
00031 // -- EndJobBegin Run
00032 // 
00033 void PFClient::endRun(edm::Run const& run, edm::EventSetup const& eSetup) {
00034   doSummaries();
00035   if (efficiencyFlag_) doEfficiency();
00036 }
00037 //
00038 // -- EndJob
00039 // 
00040 void PFClient::endJob() {
00041 
00042 }
00043 //
00044 // -- Create Summaries
00045 //
00046 void PFClient::doSummaries() {
00047 
00048   for (std::vector<std::string>::const_iterator ifolder = folderNames_.begin();
00049                                     ifolder != folderNames_.end(); ifolder++) {
00050     std::string path  = "ParticleFlow/"+(*ifolder);
00051 
00052     for (std::vector<std::string>::const_iterator ihist = histogramNames_.begin();
00053        ihist != histogramNames_.end(); ihist++) {
00054       std::string hname = (*ihist); 
00055       createResolutionPlots(path, hname);
00056     }
00057   }
00058 }
00059 //
00060 // -- Create Summaries
00061 //
00062 void PFClient::doEfficiency() {
00063   for (std::vector<std::string>::const_iterator ifolder = folderNames_.begin();
00064                                     ifolder != folderNames_.end(); ifolder++) {
00065     std::string path  = "ParticleFlow/"+(*ifolder);
00066 
00067     for (std::vector<std::string>::const_iterator ihist = effHistogramNames_.begin();
00068          ihist != effHistogramNames_.end(); ihist++) {
00069       std::string hname = (*ihist);
00070       createEfficiencyPlots(path, hname);
00071     }
00072   }
00073 }
00074 //
00075 // -- Create Resolution Plots
00076 //
00077 void PFClient::createResolutionPlots(std::string& folder, std::string& name) {     
00078   MonitorElement* me = dqmStore_->get(folder+"/"+name);
00079   if (!me) return;
00080   MonitorElement* me_average;
00081   MonitorElement* me_rms;
00082   MonitorElement* me_mean;
00083   MonitorElement* me_sigma;
00084   if ( (me->kind() == MonitorElement::DQM_KIND_TH2F) ||
00085        (me->kind() == MonitorElement::DQM_KIND_TH2S) ||
00086        (me->kind() == MonitorElement::DQM_KIND_TH2D) ) {
00087     TH2* th = me->getTH2F();
00088     size_t nbinx = me->getNbinsX();
00089     size_t nbiny = me->getNbinsY();
00090     
00091     float ymin = th->GetYaxis()->GetXmin();
00092     float ymax = th->GetYaxis()->GetXmax();
00093     std::string xtit = th->GetXaxis()->GetTitle();
00094     std::string ytit = th->GetYaxis()->GetTitle();
00095     float* xbins = new float[nbinx+1];
00096     for (size_t ix = 1; ix < nbinx+1; ++ix) {
00097        xbins[ix-1] = th->GetBinLowEdge(ix);
00098        if (ix == nbinx) xbins[ix] = th->GetXaxis()->GetBinUpEdge(ix);
00099     }    
00100 
00101     std::string tit_new;
00102     dqmStore_->setCurrentFolder(folder);
00103     MonitorElement* me_slice = dqmStore_->book1D("PFlowSlice","PFlowSlice",nbiny,ymin,ymax); 
00104     
00105     tit_new = ";"+xtit+";Average_"+ytit; 
00106     me_average = dqmStore_->book1D("average_"+name,tit_new, nbinx, xbins); 
00107     tit_new = ";"+xtit+";RMS_"+ytit; 
00108     me_rms     = dqmStore_->book1D("rms_"+name,tit_new, nbinx, xbins); 
00109     tit_new = ";"+xtit+";Mean_"+ytit; 
00110     me_mean    = dqmStore_->book1D("mean_"+name,tit_new, nbinx, xbins); 
00111     tit_new = ";"+xtit+";Sigma_"+ytit;                           
00112     me_sigma   = dqmStore_->book1D("sigma_"+name,tit_new, nbinx, xbins); 
00113                                  
00114     double  average, rms, mean, sigma;
00115     for (size_t ix = 1; ix < nbinx+1; ++ix) {
00116       me_slice->Reset();
00117       for (size_t iy = 1; iy < nbiny+1; ++iy) {
00118         me_slice->setBinContent(iy,th->GetBinContent(ix,iy)); 
00119       }
00120       getHistogramParameters(me_slice, average, rms, mean, sigma);
00121       me_average->setBinContent(ix,average);
00122       me_rms->setBinContent(ix,rms);
00123       me_mean->setBinContent(ix,mean);
00124       me_sigma->setBinContent(ix,sigma);
00125     }
00126     if (me_slice) dqmStore_->removeElement(me_slice->getName());
00127     delete [] xbins;
00128   }
00129 }
00130 //
00131 // -- Get Histogram Parameters
00132 //
00133 void PFClient::getHistogramParameters(MonitorElement* me_slice, double& average, 
00134                                              double& rms,double& mean, double& sigma) {
00135   average = 0.0;
00136   rms     = 0.0;
00137   mean    = 0.0;
00138   sigma   = 0.0;
00139 
00140   if (!me_slice) return;
00141   if  (me_slice->kind() == MonitorElement::DQM_KIND_TH1F) {
00142     average = me_slice->getMean();
00143     rms     = me_slice->getRMS();  
00144     TH1F* th_slice = me_slice->getTH1F();
00145     if (th_slice && th_slice->GetEntries() > 0) {
00146       th_slice->Fit( "gaus","Q0");
00147       TF1* gaus = th_slice->GetFunction( "gaus" );
00148       if (gaus) {
00149         sigma = gaus->GetParameter(2);
00150         mean  = gaus->GetParameter(1);
00151       }
00152     }
00153   }
00154 }
00155 //
00156 // -- Create Resolution Plots
00157 //
00158 void PFClient::createEfficiencyPlots(std::string& folder, std::string& name) {     
00159   MonitorElement* me1 = dqmStore_->get(folder+"/"+name);
00160   MonitorElement* me2 = dqmStore_->get(folder+"/"+name+"ref_");
00161   if (!me1 || !me2) return;
00162   MonitorElement* me_eff;
00163   if ( (me1->kind() == MonitorElement::DQM_KIND_TH1F) &&
00164        (me1->kind() == MonitorElement::DQM_KIND_TH1F) ) {
00165     TH1* th1 = me1->getTH1F();
00166     size_t nbinx = me1->getNbinsX();
00167     
00168     float xmin = th1->GetXaxis()->GetXmin();
00169     float xmax = th1->GetXaxis()->GetXmax();
00170     std::string xtit = me1->getAxisTitle(1);
00171     std::string tit_new;
00172     tit_new = ";"+xtit+";Efficiency"; 
00173 
00174     dqmStore_->setCurrentFolder(folder);
00175     me_eff = dqmStore_->book1D("efficiency_"+name,tit_new, nbinx, xmin, xmax); 
00176                                  
00177     double  efficiency;
00178     me_eff->Reset();
00179     for (size_t ix = 1; ix < nbinx+1; ++ix) {
00180       float val1 = me1->getBinContent(ix);
00181       float val2 = me2->getBinContent(ix);
00182       if (val2 > 0.0) efficiency = val1/val2;
00183       else efficiency = 0;   
00184       me_eff->setBinContent(ix,efficiency);
00185     }
00186   }
00187 }
00188 #include "FWCore/Framework/interface/MakerMacros.h"
00189 DEFINE_FWK_MODULE (PFClient) ;