GoodDataSelDuration.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 GoodDataSelDuration(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::Min(nevents,2999.99)";
133  TString sel = stdP1;
134  TString title = "Number of Triggers";
135  int nbins = 90;
136  double xmin = 0;
137  double xmax = 3000;
138  TString filenames = "MetricsTree*.root";
139  gStyle->SetTimeOffset(0);
140  gStyle->SetOptStat(0);
141 
142  if(sel=="") sel = "1";
143 
144  if(title=="") title = metricstr;
145 
146  TString selpre = "((" + sel + ") && preliminary)";
147  // TString selpre = "((" + sel + ") && 0)";
148  TChain *mytree = new TChain("mytree");
149  mytree->Add(filenames);
150  // MakeLongCanvas();
151  //*************************************************
152  // The code for the above function was copied below
153  TCanvas *c1 = new TCanvas("c1","c1",1000,600);
154  c1->SetBottomMargin(0.12);
155  c1->SetLeftMargin(0.12);
156  c1->SetRightMargin(0.07);
157  c1->SetTopMargin(0.07);
158  //*************************************************
159  TLegend *leg = new TLegend(0.15,0.65,0.65,0.9);
160  TLegend *legpre = new TLegend(0.67,0.65,0.95,0.9);
161  mytree->Draw(metricstr,sel,"hist");
162  TH1F* hAll = 0;
163  hAll = (TH1F*)(mytree->GetHistogram())->Clone("");
164 
165  if(xmin == -9999 || xmax == -9999){
166 
167  xmin = hAll->GetXaxis()->GetXmin();
168  xmax = hAll->GetXaxis()->GetXmax();
169 
170  }
171 
172  if(nbins<0){
173 
174  xmin = floor(xmin);
175  xmax = ceil(xmax);
176  nbins *= -1;
177 
178  if(int(xmax-xmin)%nbins!=0){
179 
180  xmax += (nbins - int(xmax-xmin)%nbins)/2;
181  xmin -= (nbins - int(xmax-xmin)%nbins);
182 
183  }
184 
185  nbins = (xmax - xmin) / nbins;
186 
187  }
188 
189  delete hAll;
190 
191  hAll = new TH1F("hAll","hAll",nbins,xmin,xmax);
192  mytree->Draw(metricstr+">>hAll",sel,"hist");
193  hAll->Clear();
194  hAll->Draw("hist");
195  hAll->SetLineColor(1);
196  hAll->SetLineWidth(2);
197  hAll->SetTitle(";"+title+";Subruns");
198  hAll->GetXaxis()->SetTitleOffset(1);
199  hAll->GetYaxis()->SetTitleOffset(1);
200  hAll->GetXaxis()->CenterTitle();
201  hAll->GetYaxis()->CenterTitle();
202  hAll->GetXaxis()->SetNdivisions();
203  hAll->GetYaxis()->SetNdivisions();
204  hAll->SetMinimum(0.1);
205  hAll->SetStats(kFALSE);
206  double max = hAll->GetMaximum();
207  hAll->SetMaximum(pow(10,1.5*(log10(max)+1)-1));
208  leg->AddEntry(hAll,"Good Subruns","f");
209  mytree->Draw(metricstr,"!(pass_all && !preliminary) && "+sel,"hist same");
210  mytree->GetHistogram()->SetLineColor(1);
211  mytree->GetHistogram()->SetLineWidth(2);
212  mytree->GetHistogram()->SetFillColor(kOrange+7);
213  leg->AddEntry(mytree->GetHistogram(),"Failed Slice","f");
214 
215  mytree->Draw(metricstr,"!(pass_db && pass_hits && passemptyspill && pass_timingpeak && pass_time && pass_duration && !preliminary) && "+sel,"hist same");
216  mytree->GetHistogram()->SetLineColor(1);
217  mytree->GetHistogram()->SetLineWidth(2);
218  mytree->GetHistogram()->SetFillColor(kGreen+1);
219  leg->AddEntry(mytree->GetHistogram(),"Failed Diblock","f");
220 
221  mytree->Draw(metricstr,"!(pass_hits && passemptyspill && pass_timingpeak && pass_time && pass_duration && !preliminary) && "+sel,"hist same");
222  mytree->GetHistogram()->SetLineColor(1);
223  mytree->GetHistogram()->SetLineWidth(2);
224  mytree->GetHistogram()->SetFillColor(kBlue+2);
225  leg->AddEntry(mytree->GetHistogram(),"Failed Hit Rate","f");
226 
227  mytree->Draw(metricstr,"!(passemptyspill && pass_timingpeak && pass_time && pass_duration && !preliminary) && "+sel,"hist same");
228  mytree->GetHistogram()->SetLineColor(1);
229  mytree->GetHistogram()->SetLineWidth(2);
230  mytree->GetHistogram()->SetFillColor(kBlue-9);
231  leg->AddEntry(mytree->GetHistogram(),"Failed Empty Spill","f");
232 
233  mytree->Draw(metricstr,"!(pass_timingpeak && pass_time && pass_duration && !preliminary) && "+sel,"hist same");
234  mytree->GetHistogram()->SetLineColor(1);
235  mytree->GetHistogram()->SetLineWidth(2);
236  //mytree->GetHistogram()->SetFillColor(kMagenta-8);
237  mytree->GetHistogram()->SetFillColor(kRed+1);
238  leg->AddEntry(mytree->GetHistogram(),"Failed Timing Peak","f");
239 
240  mytree->Draw(metricstr,"!(pass_time && pass_duration && !preliminary) && "+sel,"hist same");
241  mytree->GetHistogram()->SetLineColor(1);
242  mytree->GetHistogram()->SetLineWidth(2);
243  mytree->GetHistogram()->SetFillColor(kMagenta+2);
244  leg->AddEntry(mytree->GetHistogram(),"Failed NuMI Live Time","f");
245 
246  mytree->Draw(metricstr,"!(pass_time && !preliminary) && "+sel,"hist same");
247  mytree->GetHistogram()->SetLineColor(1);
248  mytree->GetHistogram()->SetLineWidth(2);
249  mytree->GetHistogram()->SetFillColor(kBlack);
250  leg->AddEntry(mytree->GetHistogram(),"Failed Timestamp","f");
251  mytree->Draw(metricstr,selpre,"hist same");
252  mytree->GetHistogram()->SetLineColor(1);
253  mytree->GetHistogram()->SetLineWidth(2);
254  mytree->GetHistogram()->SetFillColor(18);
255  legpre->AddEntry(mytree->GetHistogram()," ","f");
256 
257  mytree->Draw(metricstr,"!pass_all && "+selpre,"hist same");
258  mytree->GetHistogram()->SetLineColor(1);
259  mytree->GetHistogram()->SetLineWidth(2);
260  mytree->GetHistogram()->SetFillColor(kGreen-9);
261  legpre->AddEntry(mytree->GetHistogram()," ","f");
262 
263  mytree->Draw(metricstr,"!(pass_time && pass_duration) && "+selpre,"hist same");
264  mytree->GetHistogram()->SetLineColor(1);
265  mytree->GetHistogram()->SetLineWidth(2);
266  mytree->GetHistogram()->SetFillColor(kMagenta-7);
267  legpre->AddEntry(mytree->GetHistogram()," ","f");
268 
269  mytree->Draw(metricstr,"!(pass_time) && "+selpre,"hist same");
270  mytree->GetHistogram()->SetLineColor(1);
271  mytree->GetHistogram()->SetLineWidth(2);
272  mytree->GetHistogram()->SetFillColor(kGray+2);
273  legpre->AddEntry(mytree->GetHistogram()," Preliminary","f");
274  SetLeg(leg);
275  leg->SetNColumns(2);
276  leg->SetY1(0.9-leg->GetNRows()*0.05);
277  leg->Draw();
278  legpre->SetNColumns(2);
279  SetLeg(legpre);
280  legpre->SetColumnSeparation(-0.05);
281  legpre->Draw();
282  c1->SetLogy();
283  MiscText(0.15,0.94,0.055,"Near Detector");
284 
285  UpdateStamp(ptype,maxt);
286  DrawArrow(1000,-150,0.1,0.7*hAll->GetBinContent(hAll->GetMaximumBin()));
287  // c1->SaveAs("pngfiles/NearDet-t00-P1GoodDataSelTriggers"+suf+".png");
288  c1->SaveAs("pngfiles/NearDet-t00-P1GoodDataSelDuration"+suf+".png");
289  c1->Close();
290 
291 }
std::map< std::string, double > xmax
TLatex * MiscText(float x, float y, float size, TString text)
void SetLeg(TLegend *leg)
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]
void UpdateStamp(int ptype, int maxt)
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 GoodDataSelDuration(int ptype=0)
c1
Definition: demo5.py:24
Double_t ymin
Definition: plot.C:24
void DrawArrow(double x, double dx, double ymin, double ymax)
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
void StripSpecialChar(string &instr)
fvar< T > ceil(const fvar< T > &x)
Definition: ceil.hpp:11