GoodDataSelTimingPeakEnd.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 GoodDataSelTimingPeakEnd(int ptype=0){
77 
78  TDatime t;
79  int GMToffset = (t.Convert(true) - t.Convert());
80  gSystem->Setenv("TZ","UTC");
81  TString stdP1 = "1";
82  t.Set();
83  int maxt = t.Convert();
84  int mint = TDatime(20140801,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  if(ptype==3) dt = maxt - mint;
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  if(ptype==3){
123 
124  tbin = (maxt - mint)/30;
125  tdiv = 706;
126  tlab = "Date (dd/mm/yy - Central Time)";
127  tform = "%d/%m/%y";
128  suf = "All";
129 
130  }
131 
132  TString metricstr = "TMath::Max(TMath::Min(timingPeakEnd * 1e-3, 240.24), 220.26)";
133  TString sel = stdP1;
134  TString title = "Timing Peak End (#mus)";
135  int nbins = 40;
136  double xmin = 220.25;
137  double xmax = 240.25;
138  TString filenames = "MetricsTree*.root";
139  gStyle->SetTimeOffset(0);
140  gStyle->SetOptStat(0);
141  if(sel=="") sel = "1";
142  if(title=="") title = metricstr;
143  TString selpre = "((" + sel + ") && preliminary)";
144  // TString selpre = "((" + sel + ") && 0)";
145  TChain *mytree = new TChain("mytree");
146  mytree->Add(filenames);
147  // MakeLongCanvas();
148 
149  TCanvas *c1 = new TCanvas("c1","c1",1000,600);
150  c1->SetBottomMargin(0.12);
151  c1->SetLeftMargin(0.12);
152  c1->SetRightMargin(0.07);
153  c1->SetTopMargin(0.07);
154 
155  TLegend *leg = new TLegend(0.15,0.65,0.65,0.9);
156  TLegend *legpre = new TLegend(0.67,0.65,0.95,0.9);
157  mytree->Draw(metricstr,sel,"hist");
158  TH1F* hAll = 0;
159  hAll = (TH1F*)(mytree->GetHistogram())->Clone("");
160 
161  if(xmin == -9999 || xmax == -9999){
162 
163  xmin = hAll->GetXaxis()->GetXmin();
164  xmax = hAll->GetXaxis()->GetXmax();
165 
166  }
167 
168  if(nbins<0){
169 
170  xmin = floor(xmin);
171  xmax = ceil(xmax);
172  nbins *= -1;
173 
174  if(int(xmax-xmin)%nbins!=0){
175 
176  xmax += (nbins - int(xmax-xmin)%nbins)/2;
177  xmin -= (nbins - int(xmax-xmin)%nbins);
178 
179  }
180 
181  nbins = (xmax - xmin) / nbins;
182 
183  }
184 
185  delete hAll;
186 
187  hAll = new TH1F("hAll","hAll",nbins,xmin,xmax);
188  mytree->Draw(metricstr+">>hAll",sel,"hist");
189  hAll->Clear();
190  hAll->Draw("hist");
191  hAll->SetLineColor(1);
192  hAll->SetLineWidth(2);
193  hAll->SetTitle(";"+title+";Subruns");
194  hAll->GetXaxis()->SetTitleOffset(1);
195  hAll->GetYaxis()->SetTitleOffset(1);
196  hAll->GetXaxis()->CenterTitle();
197  hAll->GetYaxis()->CenterTitle();
198  hAll->GetXaxis()->SetNdivisions();
199  hAll->GetYaxis()->SetNdivisions();
200  hAll->SetMinimum(0.1);
201  hAll->SetStats(kFALSE);
202  double max = hAll->GetMaximum();
203  hAll->SetMaximum(pow(10,1.5*(log10(max)+1)-1));
204  leg->AddEntry(hAll,"Good Subruns","f");
205  mytree->Draw(metricstr,"!(pass_all && !preliminary) && "+sel,"hist same");
206  mytree->GetHistogram()->SetLineColor(1);
207  mytree->GetHistogram()->SetLineWidth(2);
208  mytree->GetHistogram()->SetFillColor(kOrange+7);
209  leg->AddEntry(mytree->GetHistogram(),"Failed Slice","f");
210 
211  mytree->Draw(metricstr,"!(pass_db && pass_hits && passemptyspill && pass_timingpeak && pass_time && pass_duration && !preliminary) && "+sel,"hist same");
212  mytree->GetHistogram()->SetLineColor(1);
213  mytree->GetHistogram()->SetLineWidth(2);
214  mytree->GetHistogram()->SetFillColor(kGreen+1);
215  leg->AddEntry(mytree->GetHistogram(),"Failed Diblock","f");
216 
217  mytree->Draw(metricstr,"!(pass_hits && passemptyspill && pass_timingpeak && pass_time && pass_duration && !preliminary) && "+sel,"hist same");
218  mytree->GetHistogram()->SetLineColor(1);
219  mytree->GetHistogram()->SetLineWidth(2);
220  mytree->GetHistogram()->SetFillColor(kBlue+2);
221  leg->AddEntry(mytree->GetHistogram(),"Failed Hit Rate","f");
222 
223  mytree->Draw(metricstr,"!(passemptyspill && pass_timingpeak && pass_time && pass_duration && !preliminary) && "+sel,"hist same");
224  mytree->GetHistogram()->SetLineColor(1);
225  mytree->GetHistogram()->SetLineWidth(2);
226  mytree->GetHistogram()->SetFillColor(kBlue-9);
227  leg->AddEntry(mytree->GetHistogram(),"Failed Empty Spill","f");
228 
229  mytree->Draw(metricstr,"!(pass_timingpeak && pass_time && pass_duration && !preliminary) && "+sel,"hist same");
230  mytree->GetHistogram()->SetLineColor(1);
231  mytree->GetHistogram()->SetLineWidth(2);
232  //mytree->GetHistogram()->SetFillColor(kMagenta-8);
233  mytree->GetHistogram()->SetFillColor(kRed+1);
234  leg->AddEntry(mytree->GetHistogram(),"Failed Timing Peak","f");
235 
236  mytree->Draw(metricstr,"!(pass_time && pass_duration && !preliminary) && "+sel,"hist same");
237  mytree->GetHistogram()->SetLineColor(1);
238  mytree->GetHistogram()->SetLineWidth(2);
239  mytree->GetHistogram()->SetFillColor(kMagenta+2);
240  leg->AddEntry(mytree->GetHistogram(),"Failed NuMI Live Time","f");
241 
242  mytree->Draw(metricstr,"!(pass_time && !preliminary) && "+sel,"hist same");
243  mytree->GetHistogram()->SetLineColor(1);
244  mytree->GetHistogram()->SetLineWidth(2);
245  mytree->GetHistogram()->SetFillColor(kBlack);
246  leg->AddEntry(mytree->GetHistogram(),"Failed Timestamp","f");
247  mytree->Draw(metricstr,selpre,"hist same");
248  mytree->GetHistogram()->SetLineColor(1);
249  mytree->GetHistogram()->SetLineWidth(2);
250  mytree->GetHistogram()->SetFillColor(18);
251  legpre->AddEntry(mytree->GetHistogram()," ","f");
252 
253  mytree->Draw(metricstr,"!pass_all && "+selpre,"hist same");
254  mytree->GetHistogram()->SetLineColor(1);
255  mytree->GetHistogram()->SetLineWidth(2);
256  mytree->GetHistogram()->SetFillColor(kGreen-9);
257  legpre->AddEntry(mytree->GetHistogram()," ","f");
258 
259  mytree->Draw(metricstr,"!(pass_time && pass_duration) && "+selpre,"hist same");
260  mytree->GetHistogram()->SetLineColor(1);
261  mytree->GetHistogram()->SetLineWidth(2);
262  mytree->GetHistogram()->SetFillColor(kMagenta-7);
263  legpre->AddEntry(mytree->GetHistogram()," ","f");
264 
265  mytree->Draw(metricstr,"!(pass_time) && "+selpre,"hist same");
266  mytree->GetHistogram()->SetLineColor(1);
267  mytree->GetHistogram()->SetLineWidth(2);
268  mytree->GetHistogram()->SetFillColor(kGray+2);
269  legpre->AddEntry(mytree->GetHistogram()," Preliminary","f");
270  SetLeg(leg);
271  leg->SetNColumns(2);
272  leg->SetY1(0.9-leg->GetNRows()*0.05);
273  leg->Draw();
274  legpre->SetNColumns(2);
275  SetLeg(legpre);
276  legpre->SetColumnSeparation(-0.05);
277  legpre->Draw();
278  c1->SetLogy();
279  MiscText(0.15,0.94,0.055,"Near Detector");
280 
281  UpdateStamp(ptype,maxt);
282  DrawArrow(226.75,-1,0.1,0.7*hAll->GetBinContent(hAll->GetMaximumBin()));
283  DrawArrow(229.25,1,0.1,0.7*hAll->GetBinContent(hAll->GetMaximumBin()));
284  c1->SaveAs("pngfiles/NearDet-t00-P1GoodDataSelTimingPeakEnd"+suf+".png");
285  c1->Close();
286 
287 }
std::map< std::string, double > xmax
void SetLeg(TLegend *leg)
void UpdateStamp(int ptype, int maxt)
void StripSpecialChar(string &instr)
constexpr T pow(T x)
Definition: pow.h:75
Double_t ymax
Definition: plot.C:25
Definition: Cand.cxx:23
const int nbins
Definition: cellShifts.C:15
double dx[NP][NC]
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
void DrawArrow(double x, double dx, double ymin, double ymax)
void GoodDataSelTimingPeakEnd(int ptype=0)
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
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