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