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 129 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.

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

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

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