test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFClient_JetRes.cc
Go to the documentation of this file.
2 
7 
8 
12 
13 #include "TGraph.h"
14 #include "TCanvas.h"
15 
16 
17 //
18 // -- Constructor
19 //
21 {
22  folderNames_ = parameterSet.getParameter< std::vector<std::string> >( "FolderNames" );
23  histogramNames_ = parameterSet.getParameter< std::vector<std::string> >( "HistogramNames" );
24  efficiencyFlag_ = parameterSet.getParameter< bool> ("CreateEfficiencyPlots" );
25  effHistogramNames_ = parameterSet.getParameter< std::vector<std::string> >( "HistogramNamesForEfficiencyPlots" );
26  PtBins_ = parameterSet.getParameter< std::vector<int> >( "VariablePtBins" ) ;
27 }
28 
29 
30 //
31 // -- EndJobBegin Run
32 //
34 {
35  doSummaries(ibooker, igetter);
36  if (efficiencyFlag_) doEfficiency(ibooker, igetter);
37 }
38 
39 
40 //
41 // -- Create Summaries
42 //
44 
45  for (std::vector<std::string>::const_iterator ifolder = folderNames_.begin();
46  ifolder != folderNames_.end(); ifolder++) {
47  std::string path = "ParticleFlow/"+(*ifolder);
48 
49  for (std::vector<std::string>::const_iterator ihist = histogramNames_.begin();
50  ihist != histogramNames_.end(); ihist++) {
51  std::string hname = (*ihist);
52  createResolutionPlots(ibooker, igetter, path, hname);
53  }
54  }
55 }
56 
57 
58 //
59 // -- Create Efficiency
60 //
62  for (std::vector<std::string>::const_iterator ifolder = folderNames_.begin();
63  ifolder != folderNames_.end(); ifolder++) {
64  std::string path = "ParticleFlow/"+(*ifolder);
65 
66  for (std::vector<std::string>::const_iterator ihist = effHistogramNames_.begin();
67  ihist != effHistogramNames_.end(); ihist++) {
68  std::string hname = (*ihist);
69  createEfficiencyPlots(ibooker, igetter, path, hname);
70  }
71  }
72 }
73 
74 
75 //
76 // -- Create Resolution Plots
77 //
79  MonitorElement* me = igetter.get(folder+"/"+name);
80  if (!me) return;
81 
82  MonitorElement* pT[PtBins_.size() -1];
83  std::vector<double> pTEntries(PtBins_.size()-1, 0) ;
84 
85  //std::vector<std::string> pTRange (PtBins_.size() -1) ;
86  //char* pTRange[PtBins_.size() -1] ;
87  std::vector<TString> pTRange(PtBins_.size() -1) ;
88  //float pTCenter[PtBins_.size() -1] ;
89 
90  MonitorElement* me_average;
91  MonitorElement* me_rms;
92  MonitorElement* me_mean;
93  MonitorElement* me_sigma;
94 
95  if ( (me->kind() == MonitorElement::DQM_KIND_TH2F) ||
97  (me->kind() == MonitorElement::DQM_KIND_TH2D) ) {
98  TH2* th = me->getTH2F();
99  //size_t nbinx = me->getNbinsX();
100  size_t nbinx = PtBins_.size() -1;
101  size_t nbiny = me->getNbinsY();
102 
103  float ymin = th->GetYaxis()->GetXmin();
104  float ymax = th->GetYaxis()->GetXmax();
105  std::string xtit = th->GetXaxis()->GetTitle();
106  //std::string ytit = th->GetYaxis()->GetTitle();
107  std::string ytit = "#Deltap_{T}/p_{T}";
108 
109  float* xbins = new float[nbinx+1];
110  for (size_t ix = 1; ix < nbinx+1; ++ix) {
111  //xbins[ix-1] = th->GetBinLowEdge(ix);
112  xbins[ix-1] = PtBins_[ix-1];
113  //snprintf(pTRange[ix-1].data(), 15, "Pt%d_%d", PtBins_[ix-1], PtBins_[ix]);
114  pTRange[ix-1] = TString::Format("Pt%d_%d", PtBins_[ix-1], PtBins_[ix]) ;
115  if (name == "BRdelta_et_Over_et_VS_et_") pTRange[ix-1] = TString::Format("BRPt%d_%d", PtBins_[ix-1], PtBins_[ix]) ;
116  else if (name == "ERdelta_et_Over_et_VS_et_") pTRange[ix-1] = TString::Format("ERPt%d_%d", PtBins_[ix-1], PtBins_[ix]) ;
117 
118  //pTCenter[ix-1] = (PtBins_[ix] - PtBins_[ix-1]) / 2. ;
119  if (ix == nbinx) {
120  //xbins[ix] = th->GetXaxis()->GetBinUpEdge(ix);
121  xbins[ix] = PtBins_[ix];
122  }
123  }
124 
125  std::string tit_new;
126  ibooker.setCurrentFolder(folder);
127  //MonitorElement* me_slice = ibooker.book1D("PFlowSlice", "PFlowSlice", nbiny, ymin, ymax);
128 
129  tit_new = "Average "+ytit+";"+xtit+";Average_"+ytit ;
130  me_average = ibooker.book1D("average_"+name,tit_new, nbinx, xbins);
131  me_average->setEfficiencyFlag();
132  tit_new = "RMS "+ytit+";"+xtit+";RMS_"+ytit ;
133  me_rms = ibooker.book1D("rms_"+name,tit_new, nbinx, xbins);
134  me_rms->setEfficiencyFlag();
135  tit_new = ";"+xtit+";Mean_"+ytit;
136  me_mean = ibooker.book1D("mean_"+name,tit_new, nbinx, xbins);
137  me_mean->setEfficiencyFlag();
138  tit_new = ";"+xtit+";Sigma_"+ytit;
139  me_sigma = ibooker.book1D("sigma_"+name,tit_new, nbinx, xbins);
140  me_sigma->setEfficiencyFlag();
141 
142  double average, rms, mean, sigma;
143  for (size_t ix = 1; ix < nbinx+1; ++ix) {
144  //me_slice->Reset();
145  if (name == "delta_et_Over_et_VS_et_") pT[ix-1] = ibooker.book1D(pTRange[ix-1], TString::Format("Total %s;%s;Events", ytit.data(), ytit.data() ), nbiny, ymin, ymax) ;
146  if (name == "BRdelta_et_Over_et_VS_et_") pT[ix-1] = ibooker.book1D(pTRange[ix-1], TString::Format("Barrel %s;%s;Events", ytit.data(), ytit.data()), nbiny, ymin, ymax) ;
147  else if (name == "ERdelta_et_Over_et_VS_et_") pT[ix-1] = ibooker.book1D(pTRange[ix-1], TString::Format("Endcap %s;%s;Events", ytit.data(), ytit.data() ), nbiny, ymin, ymax) ;
148 
149  for (size_t iy = 0; iy <= nbiny+1; ++iy) // add under and overflow
150  if (th->GetBinContent(ix,iy)) {
151  //me_slice->setBinContent(iy,th->GetBinContent(ix,iy));
152  pT[ix-1]->setBinContent(iy, th->GetBinContent(ix,iy));
153  pT[ix-1]->setBinError(iy, th->GetBinError(ix,iy));
154  pTEntries[ix-1] += th->GetBinContent(ix,iy); }
155 
156  pT[ix-1]->setEntries( pTEntries[ix-1] ) ;
157 
158  //getHistogramParameters(me_slice, average, rms, mean, sigma);
159  getHistogramParameters(pT[ix-1], average, rms, mean, sigma);
160  me_average->setBinContent(ix,average);
161  me_rms->setBinContent(ix,rms);
162  me_mean->setBinContent(ix,mean);
163  me_sigma->setBinContent(ix,sigma);
164  }
165  //if (me_slice) igetter.removeElement(me_slice->getName());
166  delete [] xbins;
167  }
168 }
169 
170 
171 //
172 // -- Get Histogram Parameters
173 //
175  double& rms,double& mean, double& sigma) {
176  average = 0.0;
177  rms = 0.0;
178  mean = 0.0;
179  sigma = 0.0;
180 
181  if (!me_slice) return;
182  if (me_slice->kind() == MonitorElement::DQM_KIND_TH1F) {
183  average = me_slice->getMean();
184  rms = me_slice->getRMS();
185  TH1F* th_slice = me_slice->getTH1F();
186  if (th_slice && th_slice->GetEntries() > 0) {
187  //need our own copy for thread safety
188  TF1 gaus("mygaus","gaus");
189  th_slice->Fit( &gaus,"Q0");
190  sigma = gaus.GetParameter(2);
191  mean = gaus.GetParameter(1);
192  }
193  }
194 }
195 
196 
197 //
198 // -- Create Resolution Plots
199 //
201  MonitorElement* me1 = igetter.get(folder+"/"+name);
202  MonitorElement* me2 = igetter.get(folder+"/"+name+"ref_");
203  if (!me1 || !me2) return;
204  MonitorElement* me_eff;
205  if ( (me1->kind() == MonitorElement::DQM_KIND_TH1F) &&
206  (me1->kind() == MonitorElement::DQM_KIND_TH1F) ) {
207  TH1* th1 = me1->getTH1F();
208  size_t nbinx = me1->getNbinsX();
209 
210  float xmin = th1->GetXaxis()->GetXmin();
211  float xmax = th1->GetXaxis()->GetXmax();
212  std::string xtit = me1->getAxisTitle(1);
213  std::string tit_new;
214  tit_new = ";"+xtit+";Efficiency";
215 
216  ibooker.setCurrentFolder(folder);
217  me_eff = ibooker.book1D("efficiency_"+name,tit_new, nbinx, xmin, xmax);
218 
219  double efficiency;
220  me_eff->Reset(); me_eff->setEfficiencyFlag();
221  for (size_t ix = 1; ix < nbinx+1; ++ix) {
222  float val1 = me1->getBinContent(ix);
223  float val2 = me2->getBinContent(ix);
224  if (val2 > 0.0) efficiency = val1/val2;
225  else efficiency = 0;
226  me_eff->setBinContent(ix,efficiency);
227  }
228  }
229 }
230 
T getParameter(std::string const &) const
void setBinContent(int binx, double content)
set content of bin (1-D)
void doSummaries(DQMStore::IBooker &, DQMStore::IGetter &)
const double xbins[]
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:304
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::string getAxisTitle(int axis=1) const
get x-, y- or z-axis title (axis=1, 2, 3 respectively)
double getMean(int axis=1) const
get mean value of histogram along x, y or z axis (axis=1, 2, 3 respectively)
void createResolutionPlots(DQMStore::IBooker &, DQMStore::IGetter &, std::string &folder, std::string &name)
void createEfficiencyPlots(DQMStore::IBooker &, DQMStore::IGetter &, std::string &folder, std::string &name)
PFClient_JetRes(const edm::ParameterSet &parameterSet)
int getNbinsY(void) const
get # of bins in Y-axis
void getHistogramParameters(MonitorElement *me_slice, double &avarage, double &rms, double &mean, double &sigma)
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
Kind kind(void) const
Get the type of the monitor element.
void setEntries(double nentries)
set # of entries
void doEfficiency(DQMStore::IBooker &, DQMStore::IGetter &)
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:276
std::vector< std::string > effHistogramNames_
TH1F * getTH1F(void) const
std::vector< int > PtBins_
int average
Definition: PDRates.py:137
double getBinContent(int binx) const
get content of bin (1-D)
double getRMS(int axis=1) const
get RMS of histogram along x, y or z axis (axis=1, 2, 3 respectively)
std::vector< std::string > folderNames_
int getNbinsX(void) const
get # of bins in X-axis
void setEfficiencyFlag(void)
TH2F * getTH2F(void) const
void Reset(void)
reset ME (ie. contents, errors, etc)
std::vector< std::string > histogramNames_
ParameterSet const & parameterSet(Provenance const &provenance)
Definition: Provenance.cc:11
tuple folder
Histograms Source for live online DQM in P5