fduptime.C
Go to the documentation of this file.
1 void uptime(const char * const in, const char * out, const bool potweighted)
2 {
3  const double textsize = 0.05;
4  const unsigned int week = 7, year = 365, month = 30;
5  TCanvas *c1 = new TCanvas("c1", "c1",0,0,800,500);
6  c1->SetCanvasSize(1000,500);
7  gStyle->SetOptStat(0);
8  gStyle->SetOptTitle(0);
9  gStyle->SetGridStyle(kSolid);
10  gStyle->SetGridColor(kGray);
11  c1->SetGrid(0,1);
12  c1->SetLeftMargin(0.08);
13  c1->SetBottomMargin(0.08);
14  c1->SetTopMargin(0.025);
15  c1->SetRightMargin(0.23);
16  c1->SetTicky(1);
17  c1->SetFrameLineWidth(2);
18 
19  ifstream infile(in);
20 
21  vector<string> date;
22  vector<double> uptimefrac, potdelivered, potrecorded, bins;
23 
24  struct datatmp{
25  string s;
26  double a, b, c;
27  };
28  datatmp tmp;
29 
30  int n = 0;
31  while(infile >> tmp.s >> tmp.a >> tmp.b >> tmp.c){
32  date .push_back(tmp.s);
33  uptimefrac .push_back(tmp.a);
34  potrecorded .push_back(tmp.b);
35  potdelivered.push_back(tmp.c);
36  bins .push_back(1 + n++);
37  }
38 
39  double minuptime = 1;
40  for(int i = 0; i < uptimefrac.size(); i++)
41  if(uptimefrac[i] < minuptime)
42  minuptime = uptimefrac[i];
43 
44  TGraph * uptime = potweighted?new TGraph:new TGraph(date.size(), &bins[0], &uptimefrac[0]);
45  uptime->SetName("uptime");
46 
47  if(potweighted)
48  for(int i = 0; i < bins.size(); i++)
49  uptime->SetPoint(i, i+1, potdelivered[i]>0?potrecorded[i]/potdelivered[i]:uptimefrac[i]);
50 
51  enum mode{weekmode, monthmode, yearmode } themode;
52  if(bins.size() < month+1) themode = weekmode;
53  else if(bins.size() < month*4) themode = monthmode;
54  else themode = yearmode;
55 
56  const int nbin = themode == weekmode? (week*((bins.size() + week - 1)/ week)+1):
57  themode ==monthmode? (month*((bins.size() + month - 1)/month)+1):
58  (year*((bins.size() + year - 1)/ year)+1);
59 
60  TH2D * dum = new TH2D("dum", "", nbin, 0, nbin, 1, 0, 1);
61 
62  int div = themode == weekmode? 700 + (uptime->GetN() + week - 1)/week:
63  themode ==monthmode? 300 + (uptime->GetN() + month- 1)/month:
64  1200 + (uptime->GetN() + year - 1)/year;
65  TGaxis * xa = new TGaxis(1, 0, nbin, 0, 0, nbin, div, "N");
66  TGaxis * xat = new TGaxis(1, 1, nbin, 1, 0, nbin, div, "N-");
67  xa->SetLabelSize(0);
68  xat->SetLabelSize(0);
69 
70  for(int i = 0; i < bins.size(); i += (themode == weekmode? week :
71  themode == monthmode?month: year))
72  // shift about half a bin right ---v
73  dum->GetXaxis()->SetBinLabel(i+1, Form(" %s", date[i].c_str()));
74 
75  dum->GetXaxis()->SetTitle("");
76  dum->GetYaxis()->SetTitle(Form("%sptime fraction", potweighted?"POT weighted u":"U"));
77  dum->GetYaxis()->SetTitleSize(textsize);
78  dum->GetXaxis()->SetTitleSize(textsize);
79  dum->GetYaxis()->SetLabelSize(textsize);
80  dum->GetXaxis()->SetLabelSize(textsize*1.5);
81  dum->GetXaxis()->SetLabelOffset(0.01);
82  dum->GetYaxis()->SetTitleOffset(0.70);
83  dum->GetXaxis()->SetBit(TAxis::kLabelsHori);
84  dum->GetYaxis()->CenterTitle(1);
85  dum->GetYaxis()->SetDecimals();
86  dum->GetXaxis()->CenterTitle(1);
87  dum->GetXaxis()->SetNdivisions(div); // ignored???
88  dum->GetXaxis()->SetTickSize(0);
89  dum->GetYaxis()->SetTickSize(0.01);
90  dum->Draw();
91  xa->Draw();
92  xat->Draw();
93 
94  uptime->SetMarkerStyle(kFullCircle);
95  uptime->SetMarkerSize(themode == yearmode?0.7:1.3);
96  uptime->SetMarkerColor(kBlue+1);
97  uptime->Draw("p");
98 
99  TGraph * uptimebyweek = dynamic_cast<TGraph*>(uptime->Clone("uptimebyweek"));
100  TGraph * uptimebybifortnight = dynamic_cast<TGraph*>(uptime->Clone("uptimebybifortnight"));
101 
102  const int weeklycolor = kGreen+2;
103 
104  for(int i = 0; i < uptime->GetN(); i+=week){
105  double sum = 0;
106  double sumx = 0;
107  int n = 0;
108  for(int j = i; j < i+week && j < uptime->GetN(); j++){
109  sum += uptime->GetY()[j];
110  sumx += uptime->GetX()[j];
111  n++;
112  }
113  const double mean = sum/n;
114  const double meanx = sumx/n;
115  for(int j = i; j < i+week && j < uptime->GetN(); j++){
116  uptimebyweek->GetY()[j] = mean;
117  }
118 
119  if(uptime->GetN() < 9*week){
120  TText * t = new TText(meanx, i%2?1/8.:1/6., Form("%.1f%%", mean*100));
121  t->SetTextSize(textsize);
122  t->SetTextFont(42);
123  t->SetTextAlign(22);
124  t->SetTextColor(weeklycolor);
125  t->Draw();
126  }
127  }
128 
129  for(int i = 0; i < uptime->GetN(); i+=28){
130  double sum = 0;
131  int n = 0;
132  for(int j = i; j < i+28 && j < uptime->GetN(); j++){
133  sum += uptime->GetY()[j];
134  n++;
135  }
136  const double mean = sum/n;
137  for(int j = i; j < i+28 && j < uptime->GetN(); j++){
138  uptimebybifortnight->GetY()[j] = mean;
139  }
140  }
141 
142  uptimebyweek->SetLineColor(weeklycolor);
143  uptimebyweek->SetLineWidth(3);
144  uptimebyweek->Draw("l");
145  uptimebybifortnight->SetLineColor(kRed);
146  uptimebybifortnight->SetLineWidth(3);
147  uptimebybifortnight->Draw("l");
148 
149  c1->SaveAs(Form("%s-noleg.pdf", out));
150  c1->SaveAs(Form("%s-noleg.eps", out));
151  c1->SaveAs(Form("%s-noleg.png", out));
152 
153  TLegend leg(0.77, 0.50, 0.995, 0.8);
154  leg.SetTextSize(textsize);
155  leg.SetBorderSize(0);
156  leg.SetMargin(0.2);
157  leg.SetFillStyle(0);
158  leg.AddEntry((TH1D*)NULL, out[0] == 'n'?"Near Detector":"Far Detector", "");
159  leg.AddEntry((TH1D*)NULL, "UTC days", "");
160  leg.AddEntry((TH1D*)NULL, "Sun-Sat weeks", "");
161  leg.AddEntry(uptime, "Daily", "p");
162  leg.AddEntry(uptimebyweek, "Weekly Average", "l");
163  leg.AddEntry(uptimebybifortnight, "4 Week Average", "l");
164  leg.Draw();
165  c1->SaveAs(Form("%s.pdf", out));
166  c1->SaveAs(Form("%s.eps", out));
167  c1->SaveAs(Form("%s.png", out));
168 }
169 
170 void nduptime(const char * const more = "")
171 {
172  uptime(Form("ndsane%s.dat", more), Form("nduptime%s", more), true);
173 }
174 
175 void fduptime(const char * const more = "")
176 {
177  uptime(Form("fdsane%s.dat", more), Form("fduptime%s", more), false);
178 }
::xsd::cxx::tree::date< char, simple_type > date
Definition: Database.h:186
void uptime(const char *const in, const char *out, const bool potweighted)
Definition: fduptime.C:1
Float_t tmp
Definition: plot.C:36
const XML_Char * s
Definition: expat.h:262
string infile
const double a
const double j
Definition: BetheBloch.cxx:29
const Binning bins
void fduptime(const char *const more="")
Definition: fduptime.C:175
void nduptime(const char *const more="")
Definition: fduptime.C:170
ifstream in
Definition: comparison.C:7
const hit & b
Definition: hits.cxx:21
c1
Definition: demo5.py:24
Double_t sum
Definition: plot.C:31
static constexpr Double_t year
Definition: Munits.h:185