21 #include "TGraphAsymmErrors.h" 57 if (
seta.length() < 2)
85 for (
unsigned int idir = 0; idir <
jetResponseDir.size(); idir++) {
87 std::vector<std::string> sME_genjets = iget_.
getMEs();
88 std::for_each(sME_genjets.begin(), sME_genjets.end(), [&](
auto&
s) {
s.insert(0,
genjetDir); });
91 std::vector<std::string> sME_offset = iget_.
getMEs();
92 std::for_each(sME_offset.begin(), sME_offset.end(), [&](
auto&
s) {
s.insert(0,
offsetDir); });
95 std::vector<std::string> sME_response = iget_.
getMEs();
96 std::for_each(sME_response.begin(), sME_response.end(), [&](
auto&
s) {
s.insert(0,
jetResponseDir[idir]); });
100 double ptBinsArray[
ptBins.size()];
107 std::vector<MonitorElement*> vME_presponse;
108 std::vector<MonitorElement*> vME_presponse_mean;
109 std::vector<MonitorElement*> vME_presponse_median;
110 std::vector<MonitorElement*> vME_preso;
111 std::vector<MonitorElement*> vME_preso_rms;
112 std::vector<MonitorElement*> vME_efficiency;
113 std::vector<MonitorElement*> vME_purity;
114 std::vector<MonitorElement*> vME_ratePUJet;
118 TH1F *h_genjet_pt, *h_genjet_matched_pt =
nullptr;
119 TH1F *h_recojet_pt =
nullptr, *h_recojet_matched_pt =
nullptr, *h_recojet_unmatched_pt =
nullptr;
122 std::vector<std::string>::const_iterator
it =
std::find(sME_offset.begin(), sME_offset.end(), stitle);
123 if (
it == sME_offset.end())
125 me = iget_.
get(stitle);
126 int nEvents = ((TH1F*)
me->getTH1F())->GetEntries();
131 bool isNoJEC = (
jetResponseDir[idir].find(
"noJEC") != std::string::npos);
142 std::vector<std::string>::const_iterator
it =
std::find(sME_genjets.begin(), sME_genjets.end(), stitle);
143 if (
it == sME_genjets.end())
145 me = iget_.
get(stitle);
146 h_genjet_pt = (TH1F*)
me->getTH1F();
151 me = iget_.
get(stitle);
152 h_genjet_matched_pt = (TH1F*)
me->getTH1F();
162 me = iget_.
get(stitle);
163 h_recojet_pt = (TH1F*)
me->getTH1F();
167 me = iget_.
get(stitle);
168 h_recojet_matched_pt = (TH1F*)
me->getTH1F();
172 me = iget_.
get(stitle);
173 h_recojet_unmatched_pt = (TH1F*)
me->getTH1F();
183 TH1F* h_presponse =
new TH1F(stitle.c_str(), ctitle,
nPtBins, ptBinsArray);
192 TH1F* h_presponse_mean =
new TH1F(stitle.c_str(), ctitle,
nPtBins, ptBinsArray);
201 TH1F* h_presponse_median =
new TH1F(stitle.c_str(), ctitle,
nPtBins, ptBinsArray);
209 TH1F* h_preso =
new TH1F(stitle.c_str(), ctitle,
nPtBins, ptBinsArray);
217 TH1F* h_preso_rms =
new TH1F(stitle.c_str(), ctitle,
nPtBins, ptBinsArray);
222 TH1F* h_efficiency =
new TH1F(stitle.c_str(), ctitle,
nPtBins, ptBinsArray);
227 TH1F* h_purity =
new TH1F(stitle.c_str(), ctitle,
nPtBins, ptBinsArray);
232 TH1F* h_ratePUJet =
new TH1F(stitle.c_str(), ctitle,
nPtBins, ptBinsArray);
235 h_efficiency->Divide(h_genjet_matched_pt, h_genjet_pt, 1, 1,
"B");
238 h_purity->Divide(h_recojet_matched_pt, h_recojet_pt, 1, 1,
"B");
239 h_ratePUJet = (TH1F*)h_recojet_unmatched_pt->Clone();
240 h_ratePUJet->SetName(
"h_ratePUJet");
241 h_ratePUJet->Scale(1. /
double(
nEvents));
244 for (
unsigned int ipt = 0; ipt <
ptBins.size() - 1; ++ipt) {
246 std::vector<std::string>::const_iterator
it =
std::find(sME_response.begin(), sME_response.end(), stitle);
247 if (
it == sME_response.end())
249 me = iget_.
get(stitle);
250 h_resp = (TH1F*)
me->getTH1F();
253 double resp = 1.0, resp_err = 0.0, reso = 0.0, reso_err = 0.0;
256 h_presponse->SetBinContent(ipt + 1, resp);
257 h_presponse->SetBinError(ipt + 1, resp_err);
258 h_preso->SetBinContent(ipt + 1, reso);
259 h_preso->SetBinError(ipt + 1, reso_err);
262 double std = h_resp->GetStdDev();
263 double std_error = h_resp->GetStdDevError();
267 double mean_error = 0.0;
269 if (h_resp->GetMean() > 0) {
270 mean = h_resp->GetMean();
271 mean_error = h_resp->GetMeanError();
280 h_preso_rms->SetBinContent(ipt + 1,
std);
281 h_preso_rms->SetBinError(ipt + 1,
err);
284 h_presponse_mean->SetBinContent(ipt + 1, h_resp->GetMean());
285 h_presponse_mean->SetBinError(ipt + 1, h_resp->GetMeanError());
288 if (h_resp->GetEntries() > 0) {
289 int numBins = h_resp->GetXaxis()->GetNbins();
290 Double_t
x1[numBins];
291 Double_t
y1[numBins];
292 for (
int i = 0;
i < numBins;
i++) {
293 x1[
i] = h_resp->GetBinCenter(
i + 1);
294 y1[
i] = h_resp->GetBinContent(
i + 1) > 0 ? h_resp->GetBinContent(
i + 1) : 0.0;
296 const auto x =
x1,
y =
y1;
297 double median = TMath::Median(numBins,
x,
y);
298 h_presponse_median->SetBinContent(ipt + 1,
median);
299 h_presponse_median->SetBinError(ipt + 1, 1.2533 * (h_resp->GetMeanError()));
306 me = ibook_.
book1D(stitle.c_str(), h_efficiency);
307 vME_efficiency.push_back(
me);
312 me = ibook_.
book1D(stitle.c_str(), h_purity);
313 vME_purity.push_back(
me);
316 me = ibook_.
book1D(stitle.c_str(), h_ratePUJet);
317 vME_ratePUJet.push_back(
me);
321 me = ibook_.
book1D(stitle.c_str(), h_presponse);
322 vME_presponse.push_back(
me);
325 me = ibook_.
book1D(stitle.c_str(), h_presponse_mean);
326 vME_presponse_mean.push_back(
me);
329 me = ibook_.
book1D(stitle.c_str(), h_presponse_median);
330 vME_presponse_median.push_back(
me);
333 me = ibook_.
book1D(stitle.c_str(), h_preso);
334 vME_preso.push_back(
me);
337 me = ibook_.
book1D(stitle.c_str(), h_preso_rms);
338 vME_preso_rms.push_back(
me);
347 for (std::vector<MonitorElement*>::const_iterator
i = vME_efficiency.begin();
i != vME_efficiency.end(); ++
i)
351 for (std::vector<MonitorElement*>::const_iterator
i = vME_purity.begin();
i != vME_purity.end(); ++
i)
352 (*i)->getTH1F()->Print();
353 for (std::vector<MonitorElement*>::const_iterator
i = vME_ratePUJet.begin();
i != vME_ratePUJet.end(); ++
i)
354 (*i)->getTH1F()->Print();
357 for (std::vector<MonitorElement*>::const_iterator
i = vME_presponse.begin();
i != vME_presponse.end(); ++
i)
358 (*i)->getTH1F()->Print();
359 for (std::vector<MonitorElement*>::const_iterator
i = vME_presponse_mean.begin();
i != vME_presponse_mean.end();
361 (*i)->getTH1F()->Print();
362 for (std::vector<MonitorElement*>::const_iterator
i = vME_presponse_median.begin();
363 i != vME_presponse_median.end();
365 (*i)->getTH1F()->Print();
366 for (std::vector<MonitorElement*>::const_iterator
i = vME_preso.begin();
i != vME_preso.end(); ++
i)
367 (*i)->getTH1F()->Print();
368 for (std::vector<MonitorElement*>::const_iterator
i = vME_preso_rms.begin();
i != vME_preso_rms.end(); ++
i)
369 (*i)->getTH1F()->Print();
390 bool doPlots =
false;
392 double ptlow =
ptBins[ptbinlow];
393 double pthigh =
ptBins[ptbinlow + 1];
397 double rmswidth = hreso->GetStdDev();
398 double rmsmean = hreso->GetMean();
399 double fitlow = rmsmean - 1.5 * rmswidth;
401 double fithigh = rmsmean + 1.5 * rmswidth;
403 TF1* fg =
new TF1(
"mygaus",
"gaus", fitlow, fithigh);
404 TF1* fg2 =
new TF1(
"fg2",
"TMath::Gaus(x,[0],[1],true)*[2]", fitlow, fithigh);
406 hreso->Fit(
"mygaus",
"RQN");
408 fg2->SetParameter(0, fg->GetParameter(1));
409 fg2->SetParameter(1, fg->GetParameter(2));
412 float ngenjet = h_genjet_pt->GetBinContent(ptbinlow + 1);
417 fg2->FixParameter(2, ngenjet * 3. / 100.);
419 hreso->Fit(
"fg2",
"RQN");
421 fitlow = fg2->GetParameter(0) - 1.5 * fg2->GetParameter(1);
423 fithigh = fg2->GetParameter(0) + 1.5 * fg2->GetParameter(1);
425 fg2->SetRange(fitlow, fithigh);
427 hreso->Fit(
"fg2",
"RQ");
432 fg2->SetLineColor(kGreen + 2);
434 hreso->GetXaxis()->SetRangeUser(0, 2);
437 if (doPlots & (hreso->GetEntries() > 0)) {
438 TCanvas* cfit =
new TCanvas(Form(
"respofit_%i",
int(ptlow)),
"respofit", 600, 600);
439 hreso->Draw(
"ehist");
443 Form(
"debug/respo_smartfit_%04d_%i_eta%s.pdf", (
int)ptlow, (
int)pthigh,
seta(
etaBins[ietahigh]).c_str()));
446 resp = fg2->GetParameter(0);
447 resp_err = fg2->GetParError(0);
453 reso = fg2->GetParameter(1) / resp;
454 reso_err = fg2->GetParError(1) / resp;
456 reso_err =
getRespUnc(reso, reso_err, resp, resp_err);
T getParameter(std::string const &) const
PFJetDQMPostProcessor(const edm::ParameterSet &)
virtual void setCurrentFolder(std::string const &fullpath)
std::vector< std::string > jetResponseDir
virtual std::vector< std::string > getMEs() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
static std::string to_string(const XMLCh *ch)
std::string spt(double ptmin, double ptmax)
std::vector< double > etaBins
#define DEFINE_FWK_MODULE(type)
virtual TH1F * getTH1F() const
void fitResponse(TH1F *hreso, TH1F *h_genjet_pt, int ptbinlow, int ietahigh, double recoptcut, double &resp, double &resp_err, double &reso, double &reso_err)
virtual MonitorElement * get(std::string const &fullpath) const
std::vector< double > ptBins
std::string seta(double eta)
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
~PFJetDQMPostProcessor() override
Power< A, B >::type pow(const A &a, const B &b)
double getRespUnc(double width, double width_err, double mean, double mean_err)