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 130 of file Trend.cc.

References cms::cuda::assert(), c, data, fontsize, GetLumi, JSON, MainPageGenerator::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.

139  : c(name, title, 2000, 800),
140  outputDir(Form("%s", dir)),
141  lgd(0.7, 0.65, 0.97, 0.89, "", "NDC"),
142  JSON(json),
143  GetLumi(GetLumiFunctor),
144  lumiType(lumiAxisType) {
145  if (JSON.count("CMSlabel"))
146  CMS = Form("#scale[1.1]{#bf{CMS}} #it{%s}", JSON.get<string>("CMSlabel").data());
147 
148  if (JSON.get_child("trends").count("TitleCanvas"))
149  lumi = Form("#scale[0.8]{%s}", JSON.get_child("trends").get<string>("TitleCanvas").data());
150 
151  assert(ymin < ymax);
152  float xmax = GetLumi(GetLumi.firstRun, GetLumi.lastRun);
153  if (JSON.get_child("trends").count("plotUnit"))
154  plotUnit = JSON.get_child("trends").get<string>("plotUnit");
155  const char* axistitles = Form(";%s luminosity [%s^{-1} ];%s", lumiType, plotUnit.c_str(), ytitle);
156  auto frame = c.DrawFrame(0., ymin, xmax, ymax, axistitles);
157  frame->GetYaxis()->SetTitleOffset(0.8);
158  frame->GetYaxis()->SetTickLength(0.01);
159  frame->GetXaxis()->SetLabelSize(fontsize);
160  frame->GetXaxis()->SetTitleSize(fontsize);
161  frame->GetYaxis()->SetLabelSize(fontsize);
162  frame->GetYaxis()->SetTitleSize(fontsize);
163  lgd.SetTextSize(fontsize);
164 
165  if (ymax > 0 && ymin < 0) {
166  TLine l;
167  l.SetLineColor(kBlack);
168  l.SetLineStyle(kDashed);
169  l.DrawLine(0., 0., xmax, 0.);
170  }
171 
172  c.SetTicks(1, 1);
173  c.SetRightMargin(0.015);
174  c.SetLeftMargin(0.07);
175  c.SetTopMargin(0.07);
176 
177  // plot vertical lines (typically pixel template transitions)
178  pt::ptree lines = JSON.get_child("trends.lines");
179  for (auto& type : lines) {
180  auto line = type.second.get_child_optional("line");
181  auto runs = type.second.get_child_optional("runs");
182  if (!line || !runs)
183  continue;
184 
185  auto v = new TLine;
186 
187  auto style = line->get_optional<string>("style");
188  if (style)
189  v->SetLineStyle(StyleParser(*style));
190 
191  auto color = line->get_optional<string>("color");
192  if (color)
193  v->SetLineColor(ColorParser(*color));
194 
195  auto width = line->get_optional<int>("width");
196  if (width)
197  v->SetLineWidth(*width);
198 
199  auto title = line->get_optional<string>("title");
200  if (title)
201  lgd.AddEntry(v, title->c_str(), "l");
202 
203  for (auto& run : *runs) {
204  auto currentRun = run.second.get_value<int>();
205 
206  auto lumi = GetLumi(GetLumi.firstRun, currentRun);
207 
208  if (lumi > 0)
209  v->DrawLine(lumi, ymin, lumi, ymax);
210  }
211  }
212 }
const char * lumiType
Definition: Trend.h:92
assert(be >=bs)
float fontsize
Definition: Trend.h:84
nlohmann::json json
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:80
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 248 of file Trend.cc.

References cms::cuda::assert(), c, GetLumi, JSON, MainPageGenerator::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.

248  {
249  c.cd();
250  lgd.Draw();
251 
252  float l = c.GetLeftMargin(), t = c.GetTopMargin(), r = c.GetRightMargin(), lumiTextOffset = 0.2;
253 
254  TLatex latex;
255  latex.SetNDC();
256  latex.SetTextFont(42);
257 
258  latex.SetTextAlign(11);
259  latex.DrawLatex(l, 1 - t + lumiTextOffset * t, CMS);
260 
261  latex.SetTextAlign(31);
262  latex.DrawLatex(1 - r, 1 - t + lumiTextOffset * t, lumi);
263 
264  // plot labels
265  latex.SetTextAlign(13);
266  auto totLumi = GetLumi();
267  assert(totLumi > 0);
268  auto posY = 0.88;
269  pt::ptree lines = JSON.get_child("trends.lines");
270  for (auto& type : lines) {
271  auto labels = type.second.get_child_optional("labels");
272  auto runs = type.second.get_child_optional("runs");
273  if (!labels || !runs)
274  continue;
275 
276  auto runIt = runs->begin();
277  auto labelIt = labels->begin();
278  while (runIt != runs->end() && labelIt != labels->end()) {
279  auto currentRun = runIt->second.get_value<int>();
280  auto label = labelIt->second.get_value<string>();
281 
282  auto lumi = max(GetLumi(currentRun), (float)0.01);
283  auto posX = l + (lumi / totLumi) / (l + 1 + r) + 0.02;
284 
285  label = "#scale[0.8]{" + label + "}";
286  latex.DrawLatex(posX, posY, label.c_str());
287 
288  ++runIt;
289  ++labelIt;
290  }
291  posY -= 0.06;
292  }
293 
294  c.RedrawAxis();
295  c.SaveAs(Form("%s/%s.pdf", outputDir, c.GetName()), Form("Title:%s", c.GetTitle()));
296  c.SaveAs(Form("%s/%s.png", outputDir, c.GetName()), Form("Title:%s", c.GetTitle()));
297 }
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 214 of file Trend.cc.

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

214  {
215  c.cd();
216 
217  TString classname = obj->ClassName();
218  if (classname.Contains("TGraph")) {
219  auto g = dynamic_cast<TGraph*>(obj);
220  int n = g->GetN();
221 
222  if (fullRange) {
223  g->Set(n);
224  g->SetPoint(n, GetLumi.lastRun, 0);
225  }
226  g = GetLumi(g);
227  g->Draw("same" + drawOpt);
228  } else if (classname.Contains("TH1")) {
229  auto h = dynamic_cast<TH1*>(obj);
230  // TODO: full range?
231  h = GetLumi(h);
232  h->Draw("same" + drawOpt);
233  } else {
234  cerr << "No implementation for `" << classname << "`\n";
235  exit(EXIT_FAILURE);
236  }
237 
238  TString name = c.GetName();
239  name.ReplaceAll("vs_run", "vs_lumi");
240  c.SetName(name);
241 
242  TString title = obj->GetTitle();
243  if (title == "")
244  return;
245  lgd.AddEntry(obj, "", lgdOpt);
246 }
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 main(), 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().