CMS 3D CMS Logo

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