55 if (
seta.length() < 2)
82 for (
unsigned int idir = 0; idir <
jetResponseDir.size(); idir++) {
84 std::vector<std::string> sME_genjets = iget_.
getMEs();
85 std::for_each(sME_genjets.begin(), sME_genjets.end(), [&](
auto&
s) {
s.insert(0,
genjetDir); });
89 std::vector<std::string> sME_response = iget_.
getMEs();
90 std::for_each(sME_response.begin(), sME_response.end(), [&](
auto&
s) {
s.insert(0,
jetResponseDir[idir]); });
95 double ptBinsArray[
ptBins.size()];
102 std::vector<MonitorElement*> vME_presponse;
103 std::vector<MonitorElement*> vME_preso;
104 std::vector<MonitorElement*> vME_preso_rms;
117 std::vector<std::string>::const_iterator it =
std::find(sME_genjets.begin(), sME_genjets.end(), stitle);
118 if (it == sME_genjets.end())
120 me = iget_.
get(stitle);
121 h_genjet_pt = (TH1F*)
me->getTH1F();
130 TH1F* h_presponse =
new TH1F(stitle.c_str(), ctitle,
nPtBins, ptBinsArray);
138 TH1F* h_preso =
new TH1F(stitle.c_str(), ctitle,
nPtBins, ptBinsArray);
146 TH1F* h_preso_rms =
new TH1F(stitle.c_str(), ctitle,
nPtBins, ptBinsArray);
148 for (
unsigned int ipt = 0; ipt <
ptBins.size() - 1; ++ipt) {
150 std::vector<std::string>::const_iterator it =
std::find(sME_response.begin(), sME_response.end(), stitle);
151 if (it == sME_response.end())
153 me = iget_.
get(stitle);
154 h_resp = (TH1F*)
me->getTH1F();
157 double resp = 1.0, resp_err = 0.0, reso = 0.0, reso_err = 0.0;
160 h_presponse->SetBinContent(ipt + 1, resp);
161 h_presponse->SetBinError(ipt + 1, resp_err);
162 h_preso->SetBinContent(ipt + 1, reso);
163 h_preso->SetBinError(ipt + 1, reso_err);
166 double std = h_resp->GetStdDev();
167 double std_error = h_resp->GetStdDevError();
171 double mean_error = 0.0;
173 if (h_resp->GetMean() > 0) {
174 mean = h_resp->GetMean();
175 mean_error = h_resp->GetMeanError();
184 h_preso_rms->SetBinContent(ipt + 1,
std);
185 h_preso_rms->SetBinError(ipt + 1,
err);
190 me = ibook_.
book1D(stitle.c_str(), h_presponse);
191 vME_presponse.push_back(
me);
194 me = ibook_.
book1D(stitle.c_str(), h_preso);
195 vME_preso.push_back(
me);
198 me = ibook_.
book1D(stitle.c_str(), h_preso_rms);
199 vME_preso_rms.push_back(
me);
207 for (std::vector<MonitorElement*>::const_iterator
i = vME_presponse.begin();
i != vME_presponse.end(); ++
i)
209 for (std::vector<MonitorElement*>::const_iterator
i = vME_preso.begin();
i != vME_preso.end(); ++
i)
210 (*i)->getTH1F()->Print();
211 for (std::vector<MonitorElement*>::const_iterator
i = vME_preso_rms.begin();
i != vME_preso_rms.end(); ++
i)
212 (*i)->getTH1F()->Print();
233 bool doPlots =
false;
235 double ptlow =
ptBins[ptbinlow];
236 double pthigh =
ptBins[ptbinlow + 1];
240 double rmswidth = hreso->GetStdDev();
241 double rmsmean = hreso->GetMean();
242 double fitlow = rmsmean - 1.5 * rmswidth;
244 double fithigh = rmsmean + 1.5 * rmswidth;
246 TF1* fg =
new TF1(
"mygaus",
"gaus", fitlow, fithigh);
247 TF1* fg2 =
new TF1(
"fg2",
"TMath::Gaus(x,[0],[1],true)*[2]", fitlow, fithigh);
249 hreso->Fit(
"mygaus",
"RQNL");
251 fg2->SetParameter(0, fg->GetParameter(1));
252 fg2->SetParameter(1, fg->GetParameter(2));
255 float ngenjet = h_genjet_pt->GetBinContent(ptbinlow + 1);
260 fg2->FixParameter(2, ngenjet * 3. / 100.);
262 hreso->Fit(
"fg2",
"RQNL");
264 fitlow = fg2->GetParameter(0) - 1.5 * fg2->GetParameter(1);
266 fithigh = fg2->GetParameter(0) + 1.5 * fg2->GetParameter(1);
268 fg2->SetRange(fitlow, fithigh);
270 hreso->Fit(
"fg2",
"RQ");
275 fg2->SetLineColor(kGreen + 2);
277 hreso->GetXaxis()->SetRangeUser(0, 2);
280 if (doPlots & (hreso->GetEntries() > 0)) {
281 TCanvas* cfit =
new TCanvas(Form(
"respofit_%i",
int(ptlow)),
"respofit", 600, 600);
282 hreso->Draw(
"ehist");
286 Form(
"debug/respo_smartfit_%04d_%i_eta%s.pdf", (
int)ptlow, (
int)pthigh,
seta(
etaBins[ietahigh]).c_str()));
289 resp = fg2->GetParameter(0);
290 resp_err = fg2->GetParError(0);
296 reso = fg2->GetParameter(1) / resp;
297 reso_err = fg2->GetParError(1) / resp;
299 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
double getRespUnc(double width, double width_err, double mean, double mean_err)