DDTModularPlotFunctions.h
Go to the documentation of this file.
1 #ifndef DDTMODULARPLOTFUNCTIONS_H
2 #define DDTMODULARPLOTFUNCTIONS_H
3 
4 // Set the number of triggers here.
5 // One day, this will be read in from elsewhere. Today is not that day.
6 #ifndef NTRIGS
7 #define NTRIGS 30
8 #endif /* NTRIGS */
9 
10 /*
11  These functions perform useful things for each modular metric.
12 
13  They'll be heavily used by the forthcoming metric creation wizard.
14 */
15 
16 ////////////////////////////////////////////////////////////////////////////////////
17 // FORMATTING PLOTS
18 ////////////////////////////////////////////////////////////////////////////////////
19 
20 // Configures the color of points, style of points, and title of a graph.
21 void configure_tgraph(TGraph *g, const Color_t color, const Style_t style, const char *title) {
22  g->SetMarkerColor(color);
23  g->SetMarkerStyle(style);
24  g->SetTitle(title);
25 };
26 
27 // Configures an axis to display the specified time range.
28 void configure_time_axis(TAxis *a, const int time_earlier, const int time_later, const char *time_format) {
29  a->SetTimeDisplay(1);
30  a->SetLabelSize(0.03);
31  a->SetTimeFormat(time_format);
32  a->SetLimits(time_earlier,time_later);
33  a->SetTitle("(central time)");
34 };
35 
36 // Configures a pad to use a transparent fill.
37 void transparent_pad(TPad *p) {
38  p->SetFillStyle(4000);
39  p->SetFillColor(0);
40  p->SetFrameFillStyle(4000);
41 }
42 
43 ////////////////////////////////////////////////////////////////////////////////////
44 // MANIPULATING PLOTS
45 ////////////////////////////////////////////////////////////////////////////////////
46 
47 // Print the entire canvas to a png and delete the canvas.
48 void print_plot(TCanvas *c, const char *filename) {
49  c->cd();
50  c->Print(filename);
51  delete c;
52 };
53 
54 
55 
56 ////////////////////////////////////////////////////////////////////////////////////
57 // MAKING PLOTS EXTRA FANCY
58 ////////////////////////////////////////////////////////////////////////////////////
59 
60 // Create good values text.
61 // Add a text box containing the good values range.
62 TPaveText *GoodValuesText(const double gv_low, const double gv_high) {
63  TPaveText *GoodValues = new TPaveText(0.10,0.90,0.40,0.93,"NDC");
64  GoodValues->SetLineColor(1);
65  GoodValues->SetFillColor(0);
66  GoodValues->SetBorderSize(1);
67 // Add the good values text.
68  char gvtext[128];
69  sprintf(gvtext,"Good Values: [%f, %f]", gv_low, gv_high);
70  GoodValues->Clear();
71  GoodValues->AddText(gvtext);
72  return GoodValues;
73 };
74 
75 ////////////////////////////////
76 
77 // Create last point and average text.
78 // Takes as arguments the graph containing the good values,
79 // the graph containing the outliers, and the trigger bit.
80 //
81 // Note that, for now, this only works for 2D graphs. I'll
82 // need to add in 3D functionality later.
83 //
84 // There's an implicit assumption that the y-axis is the
85 // axis containing the more important part of the metric
86 // at hand.
87 TPaveText *LastPointText(const TGraph *g1, const TGraph *g2) {
88  TPaveText *LastPoint = new TPaveText(0.50,0.90,0.90,0.93,"NDC");
89  LastPoint->SetLineColor(1);
90  LastPoint->SetFillColor(0);
91  LastPoint->SetBorderSize(1);
92 
93 // Check whether or not there are points in each graph.
94  bool no_g1 = true;
95  bool no_g2 = true;
96  if (g1->GetN() > 0) { no_g1 = false; }
97  if (g2->GetN() > 0) { no_g2 = false; }
98 
99 // Get the last point, taking into consideration both graphs.
100  double latest_Y;
101  // If there are points in both graphs, compare their last x values.
102  // Take the graph with the higher last x value and use the corresponding
103  // y value as the latest point.
104  if ( ! no_g1 && ! no_g2 ) {
105  if (g1->GetX()[g1->GetN()-1] >= g2->GetX()[g2->GetN()-1]) {
106  latest_Y = g1->GetY()[g1->GetN()-1]; }
107  else {
108  latest_Y = g2->GetY()[g2->GetN()-1]; } }
109  // If there are only points in g1, take its last
110  // y value as the latest point.
111  else if ( ! no_g1 ) {
112  latest_Y = g1->GetY()[g1->GetN()-1]; }
113  // If there are only points in g2, take its last
114  // y value as the latest point.
115  else if ( ! no_g2 ) {
116  latest_Y = g2->GetY()[g2->GetN()-1]; }
117  // If there are somehow no points in either graph,
118  // report the last point as 0.
119  else {
120  latest_Y = 0; }
121 
122  char lptext[128];
123  sprintf(lptext,"Last Point = %f / Average (Good Values) = %f", latest_Y, g1->GetMean(2));
124  LastPoint->Clear();
125  LastPoint->AddText(lptext);
126  return LastPoint;
127 };
128 
129 ////////////////////////////////
130 
131 // Create update text.
132 // This tells the user when this plot was updated
133 // by both time and run/subrun.
134 TPaveText *UpdatedText(const int GMToffset, const unsigned int LastRun, const unsigned int LastSR) {
135  TPaveText *Updated = new TPaveText(0.1, 0.0, 0.5, 0.05, "NDC");
136  TDatime *Ttemp = new TDatime; // finish time
137  int Xfin = Ttemp->Convert() - GMToffset;
138  TDatime *Tfinish = new TDatime(Xfin); // finish time
139  Updated->SetLineColor(0);
140  Updated->SetFillColor(0);
141  Updated->SetBorderSize(1);
142  Updated->SetMargin(0.0);
143  Updated->SetTextAlign(11);
144  char buff1[256];
145  sprintf(buff1, "Last updated on: %s (central time)", Tfinish->AsString());
146  Updated->AddText(buff1);
147  char buff2[256];
148  sprintf(buff2, "Last run / subrun: %d / %d", LastRun, LastSR);
149  Updated->AddText(buff2);
150  return Updated;
151 };
152 
153 
154 
155 
156 #endif /* DDTMODULARPLOTFUNCTIONS_H */
157 
TPaveText * GoodValuesText(const double gv_low, const double gv_high)
UInt_t LastSR
Definition: AnaPlotMaker.h:50
TPaveText * UpdatedText(const int GMToffset, const unsigned int LastRun, const unsigned int LastSR)
void configure_time_axis(TAxis *a, const int time_earlier, const int time_later, const char *time_format)
const char * p
Definition: xmltok.h:285
string filename
Definition: shutoffs.py:106
const double a
void print_plot(TCanvas *c, const char *filename)
UInt_t LastRun
Definition: AnaPlotMaker.h:49
TPaveText * LastPointText(const TGraph *g1, const TGraph *g2)
void transparent_pad(TPad *p)
Int_t GMToffset
Definition: AnaPlotMaker.h:43
void configure_tgraph(TGraph *g, const Color_t color, const Style_t style, const char *title)