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