GoodDataSelMipRate.C
Go to the documentation of this file.
1 void DrawArrow(double x, double dx, double ymin, double ymax){
2 
3  TLine line;
4  line.SetLineWidth(3);
5  line.SetLineColor(2);
6  line.DrawLine(x,ymin,x,ymax);
7  TArrow arr;
8  arr.SetLineWidth(3);
9  arr.SetLineColor(2);
10  arr.SetFillColor(2);
11  arr.DrawArrow(x,ymax,x+dx,ymax,0.01,"|>");
12 }
13 
14 void SetLeg(TLegend *leg){
15 
16  leg->SetFillStyle(0);
17  leg->SetBorderSize(0);
18  leg->SetTextSize(0.04);
19  leg->SetTextFont(42);
20  leg->SetY1(leg->GetY2()-leg->GetNRows()*0.05);
21 
22  return;
23 
24 }
25 
26 TLatex *MiscText(float x, float y, float size, TString text)
27 {
28 
29  TLatex *l = new TLatex(x,y,text);
30  l->SetNDC();
31  l->SetTextSize(size);
32  l->SetTextColor(kBlack);
33  l->Draw();
34 
35  return l;
36 
37 }
38 
39 void UpdateStamp(int ptype, int maxt){
40 
41  TDatime tnow(maxt);
42  TString lasttime = TString::Format("Last updated on: %s", tnow.AsString());
43  TLatex *ltx = MiscText(0.6,0.96,0.03,lasttime);
44  // ltx->SetTextAngle(-90);
45 
46 }
47 
48 void StripSpecialChar(string &instr){
49 
50  cout<<"\n"<<instr<<endl;
51  cout<<"\n"<<endl;
52  char str[50];
53  strcpy(str,instr.c_str());
54  // char str[50] = instr;
55  //std::string str[50]=instr.c_str();
56  char strStripped[50];
57  int c = 0;
58 
59  for(int i=0; i<strlen(str); i++){
60 
61  if (isalnum(str[i])){
62 
63  strStripped[c] = str[i];
64  c++;
65 
66  }
67 
68  }
69 
70  strStripped[c] = '\0';
71  instr = strStripped;
72 
73 }
74 
75 void GoodDataSelMipRate(int ptype=0){
76 
77  //int pt=1;
78  TDatime t;
79  int GMToffset = (t.Convert(true) - t.Convert());
80  gSystem->Setenv("TZ","UTC");
81  TString stdP1 = "run>11495&&par==1";
82  t.Set();
83  int maxt = t.Convert();
84  int mint = TDatime(20130729,0).Convert();
85  // TDatime(maxt).Print();
86  int dt = 3600*24;
87 
88  if(ptype==1) dt *= 7;
89 
90  if(ptype==0) dt *= 30;
91 
92  TString tsel = TString::Format("&& lastsec > %d && lastsec < %d",maxt - dt + 2*GMToffset, maxt + 2*GMToffset);
93  stdP1 += tsel;
94  int tdiv = 706;
95  int tbin = 3600*24;
96  TString tlab = "Date (dd/mm/yy - Central Time)";
97  TString tform = "%d/%m/%y";
98  TString suf = "Month";
99 
100  if(ptype==1){
101 
102  tbin = 3600*6;
103  tdiv = 408;
104  tlab = "Date (dd/mm - Central Time)";
105  tform = "%d/%m";
106  suf = "Week";
107 
108  }
109 
110  if(ptype==2){
111 
112  tbin = 3600;
113  tdiv = 309;
114  tlab = "Central Time (hour:min)";
115  tform = "%H:%M";
116  suf = "Day";
117 
118  }
119 
120  TString metricstr = "TMath::Min(midmiprate,39.999)";
121  TString sel = stdP1;
122  TString title = "Median MIP Hit Rate (Hz)";
123  int nbins = 100;
124  double xmin = 0;
125  double xmax = 40;
126  TString filenames = "MetricsTree*.root";
127  gStyle->SetTimeOffset(0);
128 
129  if(sel=="") sel = "1";
130 
131  if(title=="") title = metricstr;
132 
133  TString selpre = "((" + sel + ") && preliminary)";
134  // TString selpre = "((" + sel + ") && 0)";
135  TChain *mytree = new TChain("mytree");
136  mytree->Add(filenames);
137  // MakeLongCanvas();
138 
139  TCanvas *c1 = new TCanvas("c1","c1",1000,600);
140  c1->SetBottomMargin(0.12);
141  c1->SetLeftMargin(0.12);
142  c1->SetRightMargin(0.07);
143  c1->SetTopMargin(0.07);
144 
145  TLegend *leg = new TLegend(0.15,0.65,0.65,0.9);
146  TLegend *legpre = new TLegend(0.67,0.65,0.95,0.9);
147  mytree->Draw(metricstr,sel,"hist");
148  TH1F* hAll = 0;
149  hAll = (TH1F*)(mytree->GetHistogram())->Clone("");
150 
151  if(xmin == -9999 || xmax == -9999){
152 
153  xmin = hAll->GetXaxis()->GetXmin();
154  xmax = hAll->GetXaxis()->GetXmax();
155 
156  }
157 
158  if(nbins<0){
159 
160  xmin = floor(xmin);
161  xmax = ceil(xmax);
162  nbins *= -1;
163 
164  if(int(xmax-xmin)%nbins!=0){
165 
166  xmax += (nbins - int(xmax-xmin)%nbins)/2;
167  xmin -= (nbins - int(xmax-xmin)%nbins);
168 
169  }
170 
171  nbins = (xmax - xmin) / nbins;
172 
173  }
174 
175  delete hAll;
176 
177  hAll = new TH1F("hAll","hAll",nbins,xmin,xmax);
178  mytree->Draw(metricstr+">>hAll",sel,"hist");
179  hAll->Clear();
180  hAll->Draw("hist");
181  hAll->SetLineColor(1);
182  hAll->SetLineWidth(2);
183  hAll->SetTitle(";"+title+";Subruns");
184  hAll->GetXaxis()->SetTitleOffset(1);
185  hAll->GetYaxis()->SetTitleOffset(1);
186  hAll->GetXaxis()->CenterTitle();
187  hAll->GetYaxis()->CenterTitle();
188  hAll->GetXaxis()->SetNdivisions();
189  hAll->GetYaxis()->SetNdivisions();
190  hAll->SetMinimum(0.1);
191  hAll->SetStats(kFALSE);
192  double max = hAll->GetMaximum();
193  hAll->SetMaximum(pow(10,1.5*(log10(max)+1)-1));
194  leg->AddEntry(hAll,"Good Subruns","f");
195 
196  mytree->Draw(metricstr,"!(pass_all && ngoodcdb==14 && !preliminary) && "+sel,"hist same");
197  mytree->GetHistogram()->SetLineColor(1);
198  mytree->GetHistogram()->SetLineWidth(2);
199  mytree->GetHistogram()->SetFillColor(kRed-4);
200  leg->AddEntry(mytree->GetHistogram(),"Partial Detector","f");
201 
202  mytree->Draw(metricstr,"!(pass_all && !preliminary) && "+sel,"hist same");
203  mytree->GetHistogram()->SetLineColor(1);
204  mytree->GetHistogram()->SetLineWidth(2);
205  mytree->GetHistogram()->SetFillColor(kOrange+7);
206  leg->AddEntry(mytree->GetHistogram(),"Failed Reco","f");
207 
208  mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_hits && pass_db && pass_empty && !preliminary) && "+sel,"hist same");
209  mytree->GetHistogram()->SetLineColor(1);
210  mytree->GetHistogram()->SetLineWidth(2);
211  mytree->GetHistogram()->SetFillColor(kGreen+1);
212  leg->AddEntry(mytree->GetHistogram(),"Failed Diblock","f");
213 
214  mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_hits && pass_empty && !preliminary) && "+sel,"hist same");
215  mytree->GetHistogram()->SetLineColor(1);
216  mytree->GetHistogram()->SetLineWidth(2);
217  mytree->GetHistogram()->SetFillColor(4);
218  leg->AddEntry(mytree->GetHistogram(),"Failed Hit Rate","f");
219 
220  mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_empty && !preliminary) && "+sel,"hist same");
221  mytree->GetHistogram()->SetLineColor(1);
222  mytree->GetHistogram()->SetLineWidth(2);
223  mytree->GetHistogram()->SetFillColor(kMagenta+2);
224  leg->AddEntry(mytree->GetHistogram(),"Failed Live Time","f");
225 
226  mytree->Draw(metricstr,"!(pass_time && pass_empty && !preliminary) && "+sel,"hist same");
227  mytree->GetHistogram()->SetLineColor(1);
228  mytree->GetHistogram()->SetLineWidth(2);
229  mytree->GetHistogram()->SetFillColor(kBlack);
230  leg->AddEntry(mytree->GetHistogram(),"Failed Other","f");
231  mytree->Draw(metricstr,selpre,"hist same");
232  mytree->GetHistogram()->SetLineColor(1);
233  mytree->GetHistogram()->SetLineWidth(2);
234  mytree->GetHistogram()->SetFillColor(18);
235  legpre->AddEntry(mytree->GetHistogram()," ","f");
236 
237  mytree->Draw(metricstr,"!(pass_all && ngoodcdb==14) && "+selpre,"hist same");
238  mytree->GetHistogram()->SetLineColor(1);
239  mytree->GetHistogram()->SetLineWidth(2);
240  mytree->GetHistogram()->SetFillColor(kPink-4);
241  legpre->AddEntry(mytree->GetHistogram()," ","f");
242 
243  mytree->Draw(metricstr,"!pass_all && "+selpre,"hist same");
244  mytree->GetHistogram()->SetLineColor(1);
245  mytree->GetHistogram()->SetLineWidth(2);
246  mytree->GetHistogram()->SetFillColor(kOrange-9);
247  legpre->AddEntry(mytree->GetHistogram()," ","f");
248 
249  mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_hits && pass_db && pass_empty) && "+selpre,"hist same");
250  mytree->GetHistogram()->SetLineColor(1);
251  mytree->GetHistogram()->SetLineWidth(2);
252  mytree->GetHistogram()->SetFillColor(kGreen-9);
253  legpre->AddEntry(mytree->GetHistogram()," Preliminary","f");
254 
255  mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_hits && pass_empty) && "+selpre,"hist same");
256  mytree->GetHistogram()->SetLineColor(1);
257  mytree->GetHistogram()->SetLineWidth(2);
258  mytree->GetHistogram()->SetFillColor(kAzure-4);
259  legpre->AddEntry(mytree->GetHistogram()," ","f");
260 
261  mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_empty) && "+selpre,"hist same");
262  mytree->GetHistogram()->SetLineColor(1);
263  mytree->GetHistogram()->SetLineWidth(2);
264  mytree->GetHistogram()->SetFillColor(kMagenta-6);
265  legpre->AddEntry(mytree->GetHistogram()," ","f");
266 
267  mytree->Draw(metricstr,"!(pass_time && pass_empty) && "+selpre,"hist same");
268  mytree->GetHistogram()->SetLineColor(1);
269  mytree->GetHistogram()->SetLineWidth(2);
270  mytree->GetHistogram()->SetFillColor(kGray+2);
271  legpre->AddEntry(mytree->GetHistogram()," ","f");
272  leg->SetNColumns(2);
273  SetLeg(leg);
274  leg->Draw();
275  legpre->SetNColumns(2);
276  SetLeg(legpre);
277  legpre->SetColumnSeparation(-0.05);
278  legpre->Draw();
279  c1->SetLogy();
280  MiscText(0.15,0.94,0.055,"Far Detector");
281  TLine line;
282  UpdateStamp(ptype,maxt);
283  DrawArrow(18,-2,0.1,0.9*hAll->GetBinContent(hAll->GetMaximumBin()));
284  DrawArrow(28,2,0.1,0.9*hAll->GetBinContent(hAll->GetMaximumBin()));
285  c1->Update();
286  c1->SaveAs("pngfiles/FarDet-t02-P1GoodDataSelMipRate"+suf+".png");
287  c1->Close();
288 
289 }
std::map< std::string, double > xmax
void DrawArrow(double x, double dx, double ymin, double ymax)
constexpr T pow(T x)
Definition: pow.h:75
void SetLeg(TLegend *leg)
Double_t ymax
Definition: plot.C:25
Definition: Cand.cxx:23
const int nbins
Definition: cellShifts.C:15
double dx[NP][NC]
TTree * mytree
Definition: SimpleIterate.C:18
void StripSpecialChar(string &instr)
OStream cout
Definition: OStream.cxx:6
void GoodDataSelMipRate(int ptype=0)
T log10(T number)
Definition: d0nt_math.hpp:120
Int_t GMToffset
Definition: AnaPlotMaker.h:43
fvar< T > floor(const fvar< T > &x)
Definition: floor.hpp:11
c1
Definition: demo5.py:24
Double_t ymin
Definition: plot.C:24
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
TLatex * MiscText(float x, float y, float size, TString text)
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:68
fvar< T > ceil(const fvar< T > &x)
Definition: ceil.hpp:11
void UpdateStamp(int ptype, int maxt)