CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
Trend Struct Reference

#include <Trend.h>

Public Member Functions

void operator() (TObject *obj, TString drawOpt, TString lgdOpt, bool fullRange=true)
 
 Trend (const char *name, const char *dir, const char *title, const char *ytitle, float ymin, float ymax, boost::property_tree::ptree &json, const Run2Lumi &GetLumiFunctor, const char *lumiAxisType)
 < constructor, prepares canvas and frame More...
 
 ~Trend ()
 

Public Attributes

TCanvas c
 
TString CMS = "#scale[1.1]{#bf{CMS}} #it{Internal}"
 top left label More...
 
float fontsize = 0.04
 
const Run2LumiGetLumi
 functor to get luminosity for given subrange More...
 
const boost::property_tree::ptree JSON
 contains coordinate for vertical lines More...
 
TLegend lgd
 
TString lumi
 top right label (not necessarily the lumi, just following the convention from CMS_lumi.h) More...
 
const char * lumiType
 
const char * outputDir
 
std::string plotUnit = "fb"
 

Detailed Description

Standard canvas for TkAl trends as a function of delivered lumi.

The constructor and the destructor take care of the style, The operator() is overloaded and should be given a trend as a function of the run number (either TGraphErrors or TH1). The verticles lines (e.g. pixel templates) are given via a JSON file.

Definition at line 78 of file Trend.h.

Constructor & Destructor Documentation

◆ Trend()

Trend::Trend ( const char *  name,
const char *  dir,
const char *  title,
const char *  ytitle,
float  ymin,
float  ymax,
boost::property_tree::ptree &  json,
const Run2Lumi GetLumiFunctor,
const char *  lumiAxisType 
)

< constructor, prepares canvas and frame

Parameters
nameTCanvas name, also used for output PDF
titleTCanvas title, also used for output PDF (but not shown on the canvas)
ytitley-axis title
yminy-axis minimum
ymaxy-axis maximum
jsonvertical lines from JSON
GetLumiFunctorfunctor

Definition at line 131 of file Trend.cc.

References cms::cuda::assert(), c, gather_cfg::cout, data, fontsize, GetLumi, JSON, cmsLHEtoEOSManager::l, lgd, mps_splice::line, groupFilesInBlocks::lines, lumiType, plotUnit, writedatasetfile::run, writedatasetfile::runs, runGCPTkAlMap::title, findQualityFiles::v, ApeEstimator_cff::width, TrackerOfflineValidation_Dqm_cff::xmax, L1TOccupancyClient_cfi::ymax, L1TOccupancyClient_cfi::ymin, and compareTotals::ytitle.

140  : c(name, title, 2000, 800),
141  outputDir(Form("%s", dir)),
142  lgd(0.7, 0.65, 0.97, 0.89, "", "NDC"),
143  JSON(json),
144  GetLumi(GetLumiFunctor),
145  lumiType(lumiAxisType) {
146  cout << __func__ << endl;
147 
148  if (JSON.count("CMSlabel"))
149  CMS = Form("#scale[1.1]{#bf{CMS}} #it{%s}", JSON.get<string>("CMSlabel").data());
150 
151  if (JSON.get_child("trends").count("TitleCanvas"))
152  lumi = Form("#scale[0.8]{%s}", JSON.get_child("trends").get<string>("TitleCanvas").data());
153 
154  assert(ymin < ymax);
155  float xmax = GetLumi(GetLumi.firstRun, GetLumi.lastRun);
156  if (JSON.get_child("trends").count("plotUnit"))
157  plotUnit = JSON.get_child("trends").get<string>("plotUnit");
158  const char* axistitles = Form(";%s luminosity [%s^{-1} ];%s", lumiType, plotUnit.c_str(), ytitle);
159  auto frame = c.DrawFrame(0., ymin, xmax, ymax, axistitles);
160  frame->GetYaxis()->SetTitleOffset(0.8);
161  frame->GetYaxis()->SetTickLength(0.01);
162  frame->GetXaxis()->SetLabelSize(fontsize);
163  frame->GetXaxis()->SetTitleSize(fontsize);
164  frame->GetYaxis()->SetLabelSize(fontsize);
165  frame->GetYaxis()->SetTitleSize(fontsize);
166  lgd.SetTextSize(fontsize);
167  cout << "frame->GetXaxis()->GetLabelSize() = " << frame->GetXaxis()->GetLabelSize() << endl;
168  cout << "frame->GetXaxis()->GetTitleSize() = " << frame->GetXaxis()->GetTitleSize() << endl;
169 
170  if (ymax > 0 && ymin < 0) {
171  cout << "Plotting horizontal line at zero" << endl;
172  TLine l;
173  l.SetLineColor(kBlack);
174  l.SetLineStyle(kDashed);
175  l.DrawLine(0., 0., xmax, 0.);
176  }
177 
178  c.SetTicks(1, 1);
179  c.SetRightMargin(0.015);
180  c.SetLeftMargin(0.07);
181  c.SetTopMargin(0.07);
182 
183  // plot vertical lines (typically pixel template transitions)
184  pt::ptree lines = JSON.get_child("trends.lines");
185  for (auto& type : lines) {
186  auto line = type.second.get_child_optional("line");
187  auto runs = type.second.get_child_optional("runs");
188  if (!line || !runs)
189  continue;
190 
191  auto v = new TLine;
192 
193  auto style = line->get_optional<string>("style");
194  if (style)
195  v->SetLineStyle(StyleParser(*style));
196 
197  auto color = line->get_optional<string>("color");
198  if (color)
199  v->SetLineColor(ColorParser(*color));
200 
201  auto width = line->get_optional<int>("width");
202  if (width)
203  v->SetLineWidth(*width);
204 
205  auto title = line->get_optional<string>("title");
206  if (title)
207  lgd.AddEntry(v, title->c_str(), "l");
208 
209  for (auto& run : *runs) {
210  auto currentRun = run.second.get_value<int>();
211 
212  auto lumi = GetLumi(GetLumi.firstRun, currentRun);
213  //cout << currentRun << '\t' << lumi << endl;
214  if (lumi > 0)
215  v->DrawLine(lumi, ymin, lumi, ymax);
216  }
217  }
218 }
nlohmann::json json
const char * lumiType
Definition: Trend.h:92
assert(be >=bs)
float fontsize
Definition: Trend.h:84
TCanvas c
Definition: Trend.h:86
Struct holding legacy CMS convention for process types.
std::string plotUnit
Definition: Trend.h:82
Definition: style.py:1
const boost::property_tree::ptree JSON
contains coordinate for vertical lines
Definition: Trend.h:90
const char * outputDir
Definition: Trend.h:87
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
const Run2Lumi & GetLumi
functor to get luminosity for given subrange
Definition: Trend.h:91
TLegend lgd
Definition: Trend.h:88

◆ ~Trend()

Trend::~Trend ( )

Destructor applies fine tuning of the plots, e.g. legend, labels, etc. and finally prints to PDF.

Definition at line 257 of file Trend.cc.

References cms::cuda::assert(), c, gather_cfg::cout, GetLumi, JSON, cmsLHEtoEOSManager::l, label, SummaryClient_cfi::labels, lgd, groupFilesInBlocks::lines, lumiTextOffset, SiStripPI::max, outputDir, RecoTauValidation_cfi::posX, RecoTauValidation_cfi::posY, alignCSCRings::r, writedatasetfile::runs, and submitPVValidationJobs::t.

257  {
258  cout << __func__ << endl;
259 
260  c.cd();
261  lgd.Draw();
262 
263  float l = c.GetLeftMargin(), t = c.GetTopMargin(), r = c.GetRightMargin(), lumiTextOffset = 0.2;
264 
265  TLatex latex;
266  latex.SetNDC();
267  latex.SetTextFont(42);
268 
269  latex.SetTextAlign(11);
270  latex.DrawLatex(l, 1 - t + lumiTextOffset * t, CMS);
271 
272  latex.SetTextAlign(31);
273  latex.DrawLatex(1 - r, 1 - t + lumiTextOffset * t, lumi);
274 
275  // plot labels
276  latex.SetTextAlign(13);
277  auto totLumi = GetLumi();
278  assert(totLumi > 0);
279  auto posY = 0.88;
280  pt::ptree lines = JSON.get_child("trends.lines");
281  for (auto& type : lines) {
282  auto labels = type.second.get_child_optional("labels");
283  auto runs = type.second.get_child_optional("runs");
284  if (!labels || !runs)
285  continue;
286 
287  auto runIt = runs->begin();
288  auto labelIt = labels->begin();
289  while (runIt != runs->end() && labelIt != labels->end()) {
290  auto currentRun = runIt->second.get_value<int>();
291  auto label = labelIt->second.get_value<string>();
292 
293  auto lumi = max(GetLumi(currentRun), (float)0.01);
294  auto posX = l + (lumi / totLumi) / (l + 1 + r) + 0.02;
295  cout << currentRun << setw(20) << label << setw(20) << lumi << setw(20) << posX << endl;
296  label = "#scale[0.8]{" + label + "}";
297  latex.DrawLatex(posX, posY, label.c_str());
298 
299  ++runIt;
300  ++labelIt;
301  }
302  posY -= 0.06;
303  }
304 
305  c.RedrawAxis();
306  c.SaveAs(Form("%s/%s.pdf", outputDir, c.GetName()), Form("Title:%s", c.GetTitle()));
307 }
assert(be >=bs)
char const * label
TCanvas c
Definition: Trend.h:86
Struct holding legacy CMS convention for process types.
const boost::property_tree::ptree JSON
contains coordinate for vertical lines
Definition: Trend.h:90
const char * outputDir
Definition: Trend.h:87
const Run2Lumi & GetLumi
functor to get luminosity for given subrange
Definition: Trend.h:91
TLegend lgd
Definition: Trend.h:88
float lumiTextOffset
Definition: CMS_lumi.h:24

Member Function Documentation

◆ operator()()

void Trend::operator() ( TObject *  obj,
TString  drawOpt,
TString  lgdOpt,
bool  fullRange = true 
)

Operator overloading to plot a trend (given as a function of run number) as a function of the luminosity.

Parameters
obje.g. graph
drawOpte.g. option for TGraph::Draw()
lgdOptoption for TLegend::Draw()
fullRangeflag to force the graph to touch the right edge

Definition at line 220 of file Trend.cc.

References c, DMR_cfg::cerr, data-class-funcs::classname, gather_cfg::cout, beamvalidation::exit(), g, GetLumi, h, lgd, dqmiodumpmetadata::n, Skims_PA_cff::name, getGTfromDQMFile::obj, and runGCPTkAlMap::title.

220  {
221  cout << __func__ << endl;
222  c.cd();
223 
224  TString classname = obj->ClassName();
225  if (classname.Contains("TGraph")) {
226  auto g = dynamic_cast<TGraph*>(obj);
227  int n = g->GetN();
228  cout << g->GetPointX(n - 1) << ' ' << GetLumi.lastRun;
229  if (fullRange) {
230  cout << " -> adding one point" << endl;
231  g->Set(n);
232  g->SetPoint(n, GetLumi.lastRun, 0);
233  } else
234  cout << " -> hole between end of graph and right edge" << endl;
235  g = GetLumi(g);
236  g->Draw("same" + drawOpt);
237  } else if (classname.Contains("TH1")) {
238  auto h = dynamic_cast<TH1*>(obj);
239  // TODO: full range?
240  h = GetLumi(h);
241  h->Draw("same" + drawOpt);
242  } else {
243  cerr << "No implementation for `" << classname << "`\n";
244  exit(EXIT_FAILURE);
245  }
246 
247  TString name = c.GetName();
248  name.ReplaceAll("vs_run", "vs_lumi");
249  c.SetName(name);
250 
251  TString title = obj->GetTitle();
252  if (title == "")
253  return;
254  lgd.AddEntry(obj, "", lgdOpt);
255 }
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
TCanvas c
Definition: Trend.h:86
const Run2Lumi & GetLumi
functor to get luminosity for given subrange
Definition: Trend.h:91
TLegend lgd
Definition: Trend.h:88
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
def exit(msg="")

Member Data Documentation

◆ c

TCanvas Trend::c

Definition at line 86 of file Trend.h.

Referenced by operator()(), Trend(), and ~Trend().

◆ CMS

TString Trend::CMS = "#scale[1.1]{#bf{CMS}} #it{Internal}"

top left label

Definition at line 79 of file Trend.h.

◆ fontsize

float Trend::fontsize = 0.04

Definition at line 84 of file Trend.h.

Referenced by Trend().

◆ GetLumi

const Run2Lumi& Trend::GetLumi

functor to get luminosity for given subrange

Definition at line 91 of file Trend.h.

Referenced by operator()(), Trend(), and ~Trend().

◆ JSON

const boost::property_tree::ptree Trend::JSON

contains coordinate for vertical lines

Definition at line 90 of file Trend.h.

Referenced by Trend(), and ~Trend().

◆ lgd

TLegend Trend::lgd

Definition at line 88 of file Trend.h.

Referenced by operator()(), Trend(), trends(), and ~Trend().

◆ lumi

TString Trend::lumi
Initial value:
=
"#scale[0.8]{pp collisions (2016+2017+2018)}"

top right label (not necessarily the lumi, just following the convention from CMS_lumi.h)

Definition at line 80 of file Trend.h.

Referenced by generateEDF.LumiInfo::__str__(), and upgradeWorkflowComponents.UpgradeWorkflowAging::setup_().

◆ lumiType

const char* Trend::lumiType

Definition at line 92 of file Trend.h.

Referenced by Trend().

◆ outputDir

const char* Trend::outputDir

◆ plotUnit

std::string Trend::plotUnit = "fb"

Definition at line 82 of file Trend.h.

Referenced by Trend().