CMS 3D CMS Logo

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