GoodDataSelGoodDB.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 GoodDataSelGoodDB(int ptype=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  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  TString metricstr = "ngoodcdb";
122  TString sel = stdP1;
123  TString title = "# of Good Consecutive Diblocks";
124  int nbins = -1;
125  double xmin = 0;
126  double xmax = 15;
127  TString filenames = "MetricsTree*.root";
128  gStyle->SetTimeOffset(0);
129 
130  if(sel=="") sel = "1";
131 
132  if(title=="") title = metricstr;
133 
134  TString selpre = "((" + sel + ") && preliminary)";
135  // TString selpre = "((" + sel + ") && 0)";
136  TChain *mytree = new TChain("mytree");
137  mytree->Add(filenames);
138  // MakeLongCanvas();
139 
140  TCanvas *c1 = new TCanvas("c1","c1",1000,600);
141  c1->SetBottomMargin(0.12);
142  c1->SetLeftMargin(0.12);
143  c1->SetRightMargin(0.07);
144  c1->SetTopMargin(0.07);
145 
146  TLegend *leg = new TLegend(0.15,0.65,0.65,0.9);
147  TLegend *legpre = new TLegend(0.67,0.65,0.95,0.9);
148  mytree->Draw(metricstr,sel,"hist");
149  TH1F* hAll = 0;
150  hAll = (TH1F*)(mytree->GetHistogram())->Clone("");
151 
152  if(xmin == -9999 || xmax == -9999){
153 
154  xmin = hAll->GetXaxis()->GetXmin();
155  xmax = hAll->GetXaxis()->GetXmax();
156 
157  }
158 
159  if(nbins<0){
160 
161  xmin = floor(xmin);
162  xmax = ceil(xmax);
163  nbins *= -1;
164 
165  if(int(xmax-xmin)%nbins!=0){
166 
167  xmax += (nbins - int(xmax-xmin)%nbins)/2;
168  xmin -= (nbins - int(xmax-xmin)%nbins);
169 
170  }
171 
172  nbins = (xmax - xmin) / nbins;
173 
174  }
175 
176  delete hAll;
177 
178  hAll = new TH1F("hAll","hAll",nbins,xmin,xmax);
179  mytree->Draw(metricstr+">>hAll",sel,"hist");
180  hAll->Clear();
181  hAll->Draw("hist");
182  hAll->SetLineColor(1);
183  hAll->SetLineWidth(2);
184  hAll->SetTitle(";"+title+";Subruns");
185  hAll->GetXaxis()->SetTitleOffset(1);
186  hAll->GetYaxis()->SetTitleOffset(1);
187  hAll->GetXaxis()->CenterTitle();
188  hAll->GetYaxis()->CenterTitle();
189  hAll->GetXaxis()->SetNdivisions();
190  hAll->GetYaxis()->SetNdivisions();
191  hAll->SetMinimum(0.1);
192  hAll->SetStats(kFALSE);
193  double max = hAll->GetMaximum();
194  hAll->SetMaximum(pow(10,1.5*(log10(max)+1)-1));
195  leg->AddEntry(hAll,"Good Subruns","f");
196 
197  mytree->Draw(metricstr,"!(pass_all && ngoodcdb==14 && !preliminary) && "+sel,"hist same");
198  mytree->GetHistogram()->SetLineColor(1);
199  mytree->GetHistogram()->SetLineWidth(2);
200  mytree->GetHistogram()->SetFillColor(kRed-4);
201  leg->AddEntry(mytree->GetHistogram(),"Partial Detector","f");
202 
203  mytree->Draw(metricstr,"!(pass_all && !preliminary) && "+sel,"hist same");
204  mytree->GetHistogram()->SetLineColor(1);
205  mytree->GetHistogram()->SetLineWidth(2);
206  mytree->GetHistogram()->SetFillColor(kOrange+7);
207  leg->AddEntry(mytree->GetHistogram(),"Failed Reco","f");
208 
209  mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_hits && pass_db && pass_empty && !preliminary) && "+sel,"hist same");
210  mytree->GetHistogram()->SetLineColor(1);
211  mytree->GetHistogram()->SetLineWidth(2);
212  mytree->GetHistogram()->SetFillColor(kGreen+1);
213  leg->AddEntry(mytree->GetHistogram(),"Failed Diblock","f");
214 
215  mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_hits && pass_empty && !preliminary) && "+sel,"hist same");
216  mytree->GetHistogram()->SetLineColor(1);
217  mytree->GetHistogram()->SetLineWidth(2);
218  mytree->GetHistogram()->SetFillColor(4);
219  leg->AddEntry(mytree->GetHistogram(),"Failed Hit Rate","f");
220 
221  mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_empty && !preliminary) && "+sel,"hist same");
222  mytree->GetHistogram()->SetLineColor(1);
223  mytree->GetHistogram()->SetLineWidth(2);
224  mytree->GetHistogram()->SetFillColor(kMagenta+2);
225  leg->AddEntry(mytree->GetHistogram(),"Failed Live Time","f");
226 
227  mytree->Draw(metricstr,"!(pass_time && pass_empty && !preliminary) && "+sel,"hist same");
228  mytree->GetHistogram()->SetLineColor(1);
229  mytree->GetHistogram()->SetLineWidth(2);
230  mytree->GetHistogram()->SetFillColor(kBlack);
231  leg->AddEntry(mytree->GetHistogram(),"Failed Other","f");
232  mytree->Draw(metricstr,selpre,"hist same");
233  mytree->GetHistogram()->SetLineColor(1);
234  mytree->GetHistogram()->SetLineWidth(2);
235  mytree->GetHistogram()->SetFillColor(18);
236  legpre->AddEntry(mytree->GetHistogram()," ","f");
237 
238  mytree->Draw(metricstr,"!(pass_all && ngoodcdb==14) && "+selpre,"hist same");
239  mytree->GetHistogram()->SetLineColor(1);
240  mytree->GetHistogram()->SetLineWidth(2);
241  mytree->GetHistogram()->SetFillColor(kPink-4);
242  legpre->AddEntry(mytree->GetHistogram()," ","f");
243 
244  mytree->Draw(metricstr,"!pass_all && "+selpre,"hist same");
245  mytree->GetHistogram()->SetLineColor(1);
246  mytree->GetHistogram()->SetLineWidth(2);
247  mytree->GetHistogram()->SetFillColor(kOrange-9);
248  legpre->AddEntry(mytree->GetHistogram()," ","f");
249 
250  mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_hits && pass_db && pass_empty) && "+selpre,"hist same");
251  mytree->GetHistogram()->SetLineColor(1);
252  mytree->GetHistogram()->SetLineWidth(2);
253  mytree->GetHistogram()->SetFillColor(kGreen-9);
254  legpre->AddEntry(mytree->GetHistogram()," Preliminary","f");
255 
256  mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_hits && pass_empty) && "+selpre,"hist same");
257  mytree->GetHistogram()->SetLineColor(1);
258  mytree->GetHistogram()->SetLineWidth(2);
259  mytree->GetHistogram()->SetFillColor(kAzure-4);
260  legpre->AddEntry(mytree->GetHistogram()," ","f");
261 
262  mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_empty) && "+selpre,"hist same");
263  mytree->GetHistogram()->SetLineColor(1);
264  mytree->GetHistogram()->SetLineWidth(2);
265  mytree->GetHistogram()->SetFillColor(kMagenta-6);
266  legpre->AddEntry(mytree->GetHistogram()," ","f");
267 
268  mytree->Draw(metricstr,"!(pass_time && pass_empty) && "+selpre,"hist same");
269  mytree->GetHistogram()->SetLineColor(1);
270  mytree->GetHistogram()->SetLineWidth(2);
271  mytree->GetHistogram()->SetFillColor(kGray+2);
272  legpre->AddEntry(mytree->GetHistogram()," ","f");
273  leg->SetNColumns(2);
274  SetLeg(leg);
275  leg->Draw();
276  legpre->SetNColumns(2);
277  SetLeg(legpre);
278  legpre->SetColumnSeparation(-0.05);
279  legpre->Draw();
280  c1->SetLogy();
281  MiscText(0.15,0.94,0.055,"Far Detector");
282 
283  TLine line;
284  hAll->GetXaxis()->SetNdivisions(16);
285  UpdateStamp(ptype,maxt);
286  DrawArrow(2,-1,0.1,0.9*hAll->GetBinContent(hAll->GetMaximumBin()));
287  c1->Update();
288  c1->SaveAs("pngfiles/FarDet-t02-P1GoodDataSelGoodDB"+suf+".png");
289  c1->Close();
290 
291 }
void UpdateStamp(int ptype, int maxt)
std::map< std::string, double > xmax
void StripSpecialChar(string &instr)
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]
void GoodDataSelGoodDB(int ptype=0)
void DrawArrow(double x, double dx, double ymin, double ymax)
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
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