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
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 }
00021
00022
00023
00024 void PFClient::beginJob() {
00025
00026 dqmStore_ = edm::Service<DQMStore>().operator->();
00027 }
00028
00029
00030
00031 void PFClient::endRun(edm::Run const& run, edm::EventSetup const& eSetup) {
00032 doSummaries();
00033 }
00034
00035
00036
00037 void PFClient::endJob() {
00038
00039 }
00040
00041
00042
00043 void PFClient::doSummaries() {
00044
00045 for (std::vector<std::string>::const_iterator ifolder = folderNames_.begin();
00046 ifolder != folderNames_.end(); ifolder++) {
00047 std::string path = "ParticleFlow/"+(*ifolder);
00048
00049 for (std::vector<std::string>::const_iterator ihist = histogramNames_.begin();
00050 ihist != histogramNames_.end(); ihist++) {
00051 std::string hname = (*ihist);
00052 createResolutionPlots(path, hname);
00053 }
00054 }
00055 }
00056
00057
00058
00059 void PFClient::createResolutionPlots(std::string& folder, std::string& name) {
00060 MonitorElement* me = dqmStore_->get(folder+"/"+name);
00061 if (!me) return;
00062 MonitorElement* me_average;
00063 MonitorElement* me_rms;
00064 MonitorElement* me_mean;
00065 MonitorElement* me_sigma;
00066 if ( (me->kind() == MonitorElement::DQM_KIND_TH2F) ||
00067 (me->kind() == MonitorElement::DQM_KIND_TH2S) ||
00068 (me->kind() == MonitorElement::DQM_KIND_TH2D) ) {
00069 TH2* th = me->getTH2F();
00070 size_t nbinx = me->getNbinsX();
00071 size_t nbiny = me->getNbinsY();
00072
00073 float ymin = th->GetYaxis()->GetXmin();
00074 float ymax = th->GetYaxis()->GetXmax();
00075 std::string xtit = th->GetXaxis()->GetTitle();
00076 std::string ytit = th->GetYaxis()->GetTitle();
00077 float* xbins = new float[nbinx+1];
00078 for (size_t ix = 1; ix < nbinx+1; ++ix) {
00079 xbins[ix-1] = th->GetBinLowEdge(ix);
00080 if (ix == nbinx) xbins[ix] = th->GetXaxis()->GetBinUpEdge(ix);
00081 }
00082
00083 std::string tit_new;
00084 dqmStore_->setCurrentFolder(folder);
00085 MonitorElement* me_slice = dqmStore_->book1D("PFlowSlice","PFlowSlice",nbiny,ymin,ymax);
00086
00087 tit_new = ";"+xtit+";Average_"+ytit;
00088 me_average = dqmStore_->book1D("average_"+name,tit_new, nbinx, xbins);
00089 tit_new = ";"+xtit+";RMS_"+ytit;
00090 me_rms = dqmStore_->book1D("rms_"+name,tit_new, nbinx, xbins);
00091 tit_new = ";"+xtit+";Mean_"+ytit;
00092 me_mean = dqmStore_->book1D("mean_"+name,tit_new, nbinx, xbins);
00093 tit_new = ";"+xtit+";Sigma_"+ytit;
00094 me_sigma = dqmStore_->book1D("sigma_"+name,tit_new, nbinx, xbins);
00095
00096 double average, rms, mean, sigma;
00097 for (size_t ix = 1; ix < nbinx+1; ++ix) {
00098 me_slice->Reset();
00099 for (size_t iy = 1; iy < nbiny+1; ++iy) {
00100 me_slice->setBinContent(iy,th->GetBinContent(ix,iy));
00101 }
00102 getHistogramParameters(me_slice, average, rms, mean, sigma);
00103 me_average->setBinContent(ix,average);
00104 me_rms->setBinContent(ix,rms);
00105 me_mean->setBinContent(ix,mean);
00106 me_sigma->setBinContent(ix,sigma);
00107 }
00108 if (me_slice) dqmStore_->removeElement(me_slice->getName());
00109 delete [] xbins;
00110 }
00111 }
00112
00113
00114
00115 void PFClient::getHistogramParameters(MonitorElement* me_slice, double& average,
00116 double& rms,double& mean, double& sigma) {
00117 average = 0.0;
00118 rms = 0.0;
00119 mean = 0.0;
00120 sigma = 0.0;
00121
00122 if (!me_slice) return;
00123 if (me_slice->kind() == MonitorElement::DQM_KIND_TH1F) {
00124 average = me_slice->getMean();
00125 rms = me_slice->getRMS();
00126 TH1F* th_slice = me_slice->getTH1F();
00127 if (th_slice && th_slice->GetEntries() > 0) {
00128 th_slice->Fit( "gaus","Q0");
00129 TF1* gaus = th_slice->GetFunction( "gaus" );
00130 if (gaus) {
00131 sigma = gaus->GetParameter(2);
00132 mean = gaus->GetParameter(1);
00133 }
00134 }
00135 }
00136 }
00137 #include "FWCore/Framework/interface/MakerMacros.h"
00138 DEFINE_FWK_MODULE (PFClient) ;