CMS 3D CMS Logo

List of all members | Public Member Functions
JME::JetResolutionCompare Class Reference
Inheritance diagram for JME::JetResolutionCompare:
cond::payloadInspector::PlotImage< JetResolutionObject, SINGLE_IOV, 2 > cond::payloadInspector::PlotImpl< IOV_M, NTAGS > cond::payloadInspector::PlotBase

Public Member Functions

bool fill () override
 
 JetResolutionCompare ()
 
- Public Member Functions inherited from cond::payloadInspector::PlotImage< JetResolutionObject, SINGLE_IOV, 2 >
std::shared_ptr< JetResolutionObject > fetchPayload (const cond::Hash &payloadHash)
 
 PlotImage (const std::string &title)
 
std::string serializeData () override
 
- Public Member Functions inherited from cond::payloadInspector::PlotImpl< IOV_M, NTAGS >
 PlotImpl (const std::string &type, const std::string &title)
 
std::string processData () override
 
 ~PlotImpl () override=default
 
- Public Member Functions inherited from cond::payloadInspector::PlotBase
void addInputParam (const std::string &paramName)
 
cond::persistency::Session dbSession ()
 
template<typename PayloadType >
std::shared_ptr< PayloadType > fetchPayload (const cond::Hash &payloadHash)
 
template<int index>
TagReference getTag ()
 
cond::Tag_t getTagInfo (const std::string &tag)
 
virtual void init ()
 
const std::map< std::string, std::string > & inputParamValues () const
 
bool isSingleIov () const
 
bool isTwoTags () const
 
unsigned int ntags () const
 
std::string payloadType () const
 
 PlotBase ()
 
std::string title () const
 
std::string type () const
 
virtual ~PlotBase ()=default
 

Additional Inherited Members

- Public Types inherited from cond::payloadInspector::PlotImage< JetResolutionObject, SINGLE_IOV, 2 >
typedef PlotImpl< IOV_M, NTAGS > Base
 
- Protected Attributes inherited from cond::payloadInspector::PlotImage< JetResolutionObject, SINGLE_IOV, 2 >
std::string m_imageFileName
 
- Protected Attributes inherited from cond::payloadInspector::PlotBase
std::set< std::string > m_inputParams
 
std::map< std::string, std::string > m_inputParamValues
 
PlotAnnotations m_plotAnnotations
 
std::vector< std::pair< cond::Time_t, cond::Time_t > > m_tagBoundaries
 
std::vector< std::vector< std::tuple< cond::Time_t, cond::Hash > > > m_tagIovs
 
std::vector< std::string > m_tagNames
 

Detailed Description

Definition at line 346 of file JetResolution_PayloadInspector.cc.

Constructor & Destructor Documentation

◆ JetResolutionCompare()

JME::JetResolutionCompare::JetResolutionCompare ( )
inline

Member Function Documentation

◆ fill()

bool JME::JetResolutionCompare::fill ( )
inlineoverridevirtual

Implements cond::payloadInspector::PlotImpl< IOV_M, NTAGS >.

Definition at line 355 of file JetResolution_PayloadInspector.cc.

References svgfig::canvas(), f, mps_fire::i, heavyIonCSV_trainingSettings::idx, cond::payloadInspector::PlotBase::inputParamValues(), MAX_ETA, MAX_PT, MIN_ETA, MIN_PT, NBIN_ETA, NBIN_PT, AlCaHarvesting_cff::record, AlCaHLTBitMon_QueryRunRegistry::string, runGCPTkAlMap::title, and trigObjTnPSource_cfi::var.

355  {
356  double par_Pt = 100.;
357  double par_Eta = 1.;
358  double par_Rho = 20.;
359 
361  auto ip = paramValues.find("Jet_Pt");
362  if (ip != paramValues.end()) {
363  par_Pt = std::stod(ip->second);
364  }
365  ip = paramValues.find("Jet_Eta");
366  if (ip != paramValues.end()) {
367  par_Eta = std::stod(ip->second);
368  }
369  ip = paramValues.find("Jet_Rho");
370  if (ip != paramValues.end()) {
371  par_Rho = std::stod(ip->second);
372  }
373 
374  TH1D* resol_eta1 = new TH1D("Jet Resolution vs #eta one", "", NBIN_ETA, MIN_ETA, MAX_ETA);
375  TH1D* resol_eta2 = new TH1D("Jet Resolution vs #eta two", "", NBIN_ETA, MIN_ETA, MAX_ETA);
376  TH1D* resol_pt1 = new TH1D("Jet Resolution vs p_T one", "", NBIN_PT, MIN_PT, MAX_PT);
377  TH1D* resol_pt2 = new TH1D("Jet Resolution vs p_T two", "", NBIN_PT, MIN_PT, MAX_PT);
378  TLegend* leg_eta = new TLegend(0.26, 0.73, 0.935, 0.90);
379  TLegend* leg_pt = new TLegend(0.26, 0.73, 0.935, 0.90);
380 
381  leg_eta->SetBorderSize(0);
382  leg_eta->SetLineStyle(0);
383  leg_eta->SetFillStyle(0);
384 
385  leg_eta->SetTextFont(42);
386  leg_pt->SetBorderSize(0);
387  leg_pt->SetLineStyle(0);
388  leg_pt->SetFillStyle(0);
389 
390  auto tag1 = PlotBase::getTag<0>();
391  auto iov1 = tag1.iovs.front();
392  std::shared_ptr<JetResolutionObject> payload1 = fetchPayload(std::get<1>(iov1));
393  auto tag2 = PlotBase::getTag<1>();
394  auto iov2 = tag2.iovs.front();
395  std::shared_ptr<JetResolutionObject> payload2 = fetchPayload(std::get<1>(iov2));
396 
397  std::stringstream ss_tagname1(tag1.name);
398  std::stringstream ss_tagname2(tag1.name);
399  std::string stmp;
400 
401  std::string tag_ver1;
402  std::string tag_ver2;
403 
404  getline(ss_tagname1, stmp, '_'); // drop first
405  getline(ss_tagname1, stmp); // year
406  tag_ver1 = stmp;
407 
408  getline(ss_tagname2, stmp, '_'); // drop first
409  getline(ss_tagname2, stmp); // year
410  tag_ver2 = stmp;
411 
412  if (payload1.get() && payload2.get()) {
413  if (!payload1->getRecords().empty() && // No formula for SF
414  payload1->getDefinition().getFormulaString().compare("") == 0)
415  return false;
416 
417  for (const auto& record : payload1->getRecords()) {
418  // Check Pt & Rho
419  if (!record.getVariablesRange().empty() && payload1->getDefinition().getVariableName(0) == "JetPt" &&
420  record.getVariablesRange()[0].is_inside(par_Pt)) {
421  if (record.getBinsRange().size() > 1 && payload1->getDefinition().getBinName(1) == "Rho" &&
422  record.getBinsRange()[1].is_inside(par_Rho)) {
423  if (!record.getBinsRange().empty() && payload1->getDefinition().getBinName(0) == "JetEta") {
424  reco::FormulaEvaluator f(payload1->getDefinition().getFormulaString());
425 
426  for (size_t idx = 0; idx <= NBIN_ETA; idx++) {
427  double x_axis = (idx + 0.5) * (MAX_ETA - MIN_ETA) / NBIN_ETA + MIN_ETA;
428  if (record.getBinsRange()[0].is_inside(x_axis)) {
429  std::vector<double> var = {par_Pt};
430  std::vector<double> param;
431  for (size_t i = 0; i < record.getParametersValues().size(); i++) {
432  double par = record.getParametersValues()[i];
433  param.push_back(par);
434  }
435  float res = f.evaluate(var, param);
436  resol_eta1->SetBinContent(idx + 1, res);
437  }
438  }
439  }
440  }
441  }
442 
443  if (!record.getBinsRange().empty() && payload1->getDefinition().getBinName(0) == "JetEta" &&
444  record.getBinsRange()[0].is_inside(par_Eta)) {
445  if (record.getBinsRange().size() > 1 && payload1->getDefinition().getBinName(1) == "Rho" &&
446  record.getBinsRange()[1].is_inside(par_Rho)) {
447  if (!record.getVariablesRange().empty() && payload1->getDefinition().getVariableName(0) == "JetPt") {
448  reco::FormulaEvaluator f(payload1->getDefinition().getFormulaString());
449 
450  for (size_t idx = 0; idx <= NBIN_PT + 2; idx++) {
451  double x_axis = (idx + 0.5) * (MAX_PT - MIN_PT) / NBIN_PT + MIN_PT;
452  if (record.getVariablesRange()[0].is_inside(x_axis)) {
453  std::vector<double> var = {x_axis};
454  std::vector<double> param;
455  for (size_t i = 0; i < record.getParametersValues().size(); i++) {
456  double par = record.getParametersValues()[i];
457  param.push_back(par);
458  }
459  float res = f.evaluate(var, param);
460  resol_pt1->SetBinContent(idx + 1, res);
461  }
462  }
463  }
464  }
465  }
466  } // records
467 
468  for (const auto& record : payload2->getRecords()) {
469  // Check Pt & Rho
470  if (!record.getVariablesRange().empty() && payload2->getDefinition().getVariableName(0) == "JetPt" &&
471  record.getVariablesRange()[0].is_inside(par_Pt)) {
472  if (record.getBinsRange().size() > 1 && payload2->getDefinition().getBinName(1) == "Rho" &&
473  record.getBinsRange()[1].is_inside(par_Rho)) {
474  if (!record.getBinsRange().empty() && payload2->getDefinition().getBinName(0) == "JetEta") {
475  reco::FormulaEvaluator f(payload2->getDefinition().getFormulaString());
476 
477  for (size_t idx = 0; idx <= NBIN_ETA; idx++) {
478  double x_axis = (idx + 0.5) * (MAX_ETA - MIN_ETA) / NBIN_ETA + MIN_ETA;
479  if (record.getBinsRange()[0].is_inside(x_axis)) {
480  std::vector<double> var = {par_Pt};
481  std::vector<double> param;
482  for (size_t i = 0; i < record.getParametersValues().size(); i++) {
483  double par = record.getParametersValues()[i];
484  param.push_back(par);
485  }
486  float res = f.evaluate(var, param);
487  resol_eta2->SetBinContent(idx + 1, res);
488  }
489  }
490  }
491  }
492  }
493 
494  if (!record.getBinsRange().empty() && payload2->getDefinition().getBinName(0) == "JetEta" &&
495  record.getBinsRange()[0].is_inside(par_Eta)) {
496  if (record.getBinsRange().size() > 1 && payload2->getDefinition().getBinName(1) == "Rho" &&
497  record.getBinsRange()[1].is_inside(par_Rho)) {
498  if (!record.getVariablesRange().empty() && payload2->getDefinition().getVariableName(0) == "JetPt") {
499  reco::FormulaEvaluator f(payload2->getDefinition().getFormulaString());
500 
501  for (size_t idx = 0; idx <= NBIN_PT + 2; idx++) {
502  double x_axis = (idx + 0.5) * (MAX_PT - MIN_PT) / NBIN_PT + MIN_PT;
503  if (record.getVariablesRange()[0].is_inside(x_axis)) {
504  std::vector<double> var = {x_axis};
505  std::vector<double> param;
506  for (size_t i = 0; i < record.getParametersValues().size(); i++) {
507  double par = record.getParametersValues()[i];
508  param.push_back(par);
509  }
510  float res = f.evaluate(var, param);
511  resol_pt2->SetBinContent(idx + 1, res);
512  }
513  }
514  }
515  }
516  }
517  } // records
518 
519  gStyle->SetOptStat(0);
520  gStyle->SetLabelFont(42, "XYZ");
521  gStyle->SetLabelSize(0.05, "XYZ");
522  gStyle->SetFrameLineWidth(3);
523 
524  std::string title = Form("Comparison between %s and %s", tag1.name.c_str(), tag2.name.c_str());
525  TCanvas canvas("Jet Resolution Comparison", title.c_str(), 800, 1200);
526  canvas.Divide(1, 2);
527 
528  canvas.cd(1);
529  resol_eta1->SetTitle("Jet Resolution Comparison");
530  resol_eta1->SetXTitle("#eta");
531  resol_eta1->SetYTitle("Resolution");
532  resol_eta1->SetLineWidth(3);
533  resol_eta1->SetMaximum(resol_eta1->GetMaximum() * 1.25);
534  resol_eta1->Draw("][");
535 
536  resol_eta2->SetLineColor(2);
537  resol_eta2->SetLineWidth(3);
538  resol_eta2->SetLineStyle(2);
539  resol_eta2->Draw("][same");
540 
541  leg_eta->AddEntry(resol_eta1, tag_ver1.c_str(), "l");
542  leg_eta->AddEntry(resol_eta2, tag_ver2.c_str(), "l");
543  leg_eta->AddEntry((TObject*)nullptr, Form("JetPt=%.2f; JetRho=%.2f", par_Pt, par_Rho), "");
544  leg_eta->Draw();
545 
546  canvas.cd(2);
547  resol_pt1->SetXTitle("p_{T} [GeV]");
548  resol_pt1->SetYTitle("Resolution");
549  resol_pt1->SetLineWidth(3);
550  resol_pt1->Draw("][");
551 
552  resol_pt2->SetLineColor(2);
553  resol_pt2->SetLineWidth(3);
554  resol_pt2->SetLineStyle(2);
555  resol_pt2->Draw("][same");
556 
557  leg_pt->AddEntry(resol_pt1, tag_ver1.c_str(), "l");
558  leg_pt->AddEntry(resol_pt2, tag_ver2.c_str(), "l");
559  leg_pt->AddEntry((TObject*)nullptr, Form("JetEta=%.2f; JetRho=%.2f", par_Eta, par_Rho), "");
560  leg_pt->Draw();
561 
562  canvas.SaveAs(m_imageFileName.c_str());
563 
564  return true;
565  } else // no payload.get()
566  return false;
567  } // fill
Definition: Electron.h:6
double f[11][100]
const std::map< std::string, std::string > & inputParamValues() const
def canvas(sub, attr)
Definition: svgfig.py:482
std::shared_ptr< JetResolutionObject > fetchPayload(const cond::Hash &payloadHash)