GoodDataSelNumSlices.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  TLatex *l = new TLatex(x,y,text);
30  l->SetNDC();
31  l->SetTextSize(size);
32  l->SetTextColor(kBlack);
33  l->Draw();
34 
35  return l;
36 
37 }
38 
39 void UpdateStamp(int ptype, int maxt){
40 
41  TDatime tnow(maxt);
42  TString lasttime = TString::Format("Last updated on: %s", tnow.AsString());
43  TLatex *ltx = MiscText(0.6,0.96,0.03,lasttime);
44  // ltx->SetTextAngle(-90);
45 
46 }
47 
48 void StripSpecialChar(string &instr){
49 
50  cout<<"\n"<<instr<<endl;
51  cout<<"\n"<<endl;
52  char str[50];
53  strcpy(str,instr.c_str());
54  // char str[50] = instr;
55  //std::string str[50]=instr.c_str();
56  char strStripped[50];
57  int c = 0;
58 
59  for(int i=0; i<strlen(str); i++){
60 
61  if (isalnum(str[i])){
62 
63  strStripped[c] = str[i];
64  c++;
65  }
66 
67  }
68 
69  strStripped[c] = '\0';
70  instr = strStripped;
71 
72 }
73 
74 void GoodDataSelNumSlices(int ptype=0){
75 
76  //int pt=1;
77  TDatime t;
78  int GMToffset = (t.Convert(true) - t.Convert());
79  gSystem->Setenv("TZ","UTC");
80  TString stdP1 = "run>11495&&par==1";
81  t.Set();
82  int maxt = t.Convert();
83  int mint = TDatime(20130729,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  TString tsel = TString::Format("&& lastsec > %d && lastsec < %d",maxt - dt + 2*GMToffset, maxt + 2*GMToffset);
92  stdP1 += tsel;
93  int tdiv = 706;
94  int tbin = 3600*24;
95  TString tlab = "Date (dd/mm/yy - Central Time)";
96  TString tform = "%d/%m/%y";
97  TString suf = "Month";
98 
99  if(ptype==1){
100 
101  tbin = 3600*6;
102  tdiv = 408;
103  tlab = "Date (dd/mm - Central Time)";
104  tform = "%d/%m";
105  suf = "Week";
106 
107  }
108 
109  if(ptype==2){
110 
111  tbin = 3600;
112  tdiv = 309;
113  tlab = "Central Time (hour:min)";
114  tform = "%H:%M";
115  suf = "Day";
116 
117  }
118 
119  TString metricstr = "TMath::Min(numslc,9.999)";
120  TString sel = stdP1;
121  TString title = "Slices / Trigger / 10^{4} Channels";
122  int nbins = 110;
123  double xmin = -1;
124  double xmax = 10;
125  TString filenames = "MetricsTree*.root";
126  gStyle->SetTimeOffset(0);
127 
128  if(sel=="") sel = "1";
129 
130  if(title=="") title = metricstr;
131 
132  TString selpre = "((" + sel + ") && preliminary)";
133  // TString selpre = "((" + sel + ") && 0)";
134  TChain *mytree = new TChain("mytree");
135  mytree->Add(filenames);
136  // MakeLongCanvas();
137 
138  TCanvas *c1 = new TCanvas("c1","c1",1000,600);
139  c1->SetBottomMargin(0.12);
140  c1->SetLeftMargin(0.12);
141  c1->SetRightMargin(0.07);
142  c1->SetTopMargin(0.07);
143 
144  TLegend *leg = new TLegend(0.15,0.65,0.65,0.9);
145  TLegend *legpre = new TLegend(0.67,0.65,0.95,0.9);
146  mytree->Draw(metricstr,sel,"hist");
147  TH1F* hAll = 0;
148  hAll = (TH1F*)(mytree->GetHistogram())->Clone("");
149 
150  if(xmin == -9999 || xmax == -9999){
151 
152  xmin = hAll->GetXaxis()->GetXmin();
153  xmax = hAll->GetXaxis()->GetXmax();
154 
155  }
156 
157  if(nbins<0){
158 
159  xmin = floor(xmin);
160  xmax = ceil(xmax);
161  nbins *= -1;
162 
163  if(int(xmax-xmin)%nbins!=0){
164 
165  xmax += (nbins - int(xmax-xmin)%nbins)/2;
166  xmin -= (nbins - int(xmax-xmin)%nbins);
167 
168  }
169 
170  nbins = (xmax - xmin) / nbins;
171 
172  }
173 
174  delete hAll;
175 
176  hAll = new TH1F("hAll","hAll",nbins,xmin,xmax);
177  mytree->Draw(metricstr+">>hAll",sel,"hist");
178  hAll->Clear();
179  hAll->Draw("hist");
180  hAll->SetLineColor(1);
181  hAll->SetLineWidth(2);
182  hAll->SetTitle(";"+title+";Subruns");
183  hAll->GetXaxis()->SetTitleOffset(1);
184  hAll->GetYaxis()->SetTitleOffset(1);
185  hAll->GetXaxis()->CenterTitle();
186  hAll->GetYaxis()->CenterTitle();
187  hAll->GetXaxis()->SetNdivisions();
188  hAll->GetYaxis()->SetNdivisions();
189  hAll->SetMinimum(0.1);
190  hAll->SetStats(kFALSE);
191  double max = hAll->GetMaximum();
192  hAll->SetMaximum(pow(10,1.5*(log10(max)+1)-1));
193  leg->AddEntry(hAll,"Good Subruns","f");
194 
195  mytree->Draw(metricstr,"!(pass_all && ngoodcdb==14 && !preliminary) && "+sel,"hist same");
196  mytree->GetHistogram()->SetLineColor(1);
197  mytree->GetHistogram()->SetLineWidth(2);
198  mytree->GetHistogram()->SetFillColor(kRed-4);
199  leg->AddEntry(mytree->GetHistogram(),"Partial Detector","f");
200 
201  mytree->Draw(metricstr,"!(pass_all && !preliminary) && "+sel,"hist same");
202  mytree->GetHistogram()->SetLineColor(1);
203  mytree->GetHistogram()->SetLineWidth(2);
204  mytree->GetHistogram()->SetFillColor(kOrange+7);
205  leg->AddEntry(mytree->GetHistogram(),"Failed Reco","f");
206 
207  mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_hits && pass_db && pass_empty && !preliminary) && "+sel,"hist same");
208  mytree->GetHistogram()->SetLineColor(1);
209  mytree->GetHistogram()->SetLineWidth(2);
210  mytree->GetHistogram()->SetFillColor(kGreen+1);
211  leg->AddEntry(mytree->GetHistogram(),"Failed Diblock","f");
212 
213  mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_hits && pass_empty && !preliminary) && "+sel,"hist same");
214  mytree->GetHistogram()->SetLineColor(1);
215  mytree->GetHistogram()->SetLineWidth(2);
216  mytree->GetHistogram()->SetFillColor(4);
217  leg->AddEntry(mytree->GetHistogram(),"Failed Hit Rate","f");
218 
219  mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_empty && !preliminary) && "+sel,"hist same");
220  mytree->GetHistogram()->SetLineColor(1);
221  mytree->GetHistogram()->SetLineWidth(2);
222  mytree->GetHistogram()->SetFillColor(kMagenta+2);
223  leg->AddEntry(mytree->GetHistogram(),"Failed Live Time","f");
224 
225  mytree->Draw(metricstr,"!(pass_time && pass_empty && !preliminary) && "+sel,"hist same");
226  mytree->GetHistogram()->SetLineColor(1);
227  mytree->GetHistogram()->SetLineWidth(2);
228  mytree->GetHistogram()->SetFillColor(kBlack);
229  leg->AddEntry(mytree->GetHistogram(),"Failed Other","f");
230  mytree->Draw(metricstr,selpre,"hist same");
231  mytree->GetHistogram()->SetLineColor(1);
232  mytree->GetHistogram()->SetLineWidth(2);
233  mytree->GetHistogram()->SetFillColor(18);
234  legpre->AddEntry(mytree->GetHistogram()," ","f");
235 
236  mytree->Draw(metricstr,"!(pass_all && ngoodcdb==14) && "+selpre,"hist same");
237  mytree->GetHistogram()->SetLineColor(1);
238  mytree->GetHistogram()->SetLineWidth(2);
239  mytree->GetHistogram()->SetFillColor(kPink-4);
240  legpre->AddEntry(mytree->GetHistogram()," ","f");
241 
242  mytree->Draw(metricstr,"!pass_all && "+selpre,"hist same");
243  mytree->GetHistogram()->SetLineColor(1);
244  mytree->GetHistogram()->SetLineWidth(2);
245  mytree->GetHistogram()->SetFillColor(kOrange-9);
246  legpre->AddEntry(mytree->GetHistogram()," ","f");
247 
248  mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_hits && pass_db && pass_empty) && "+selpre,"hist same");
249  mytree->GetHistogram()->SetLineColor(1);
250  mytree->GetHistogram()->SetLineWidth(2);
251  mytree->GetHistogram()->SetFillColor(kGreen-9);
252  legpre->AddEntry(mytree->GetHistogram()," Preliminary","f");
253 
254  mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_hits && pass_empty) && "+selpre,"hist same");
255  mytree->GetHistogram()->SetLineColor(1);
256  mytree->GetHistogram()->SetLineWidth(2);
257  mytree->GetHistogram()->SetFillColor(kAzure-4);
258  legpre->AddEntry(mytree->GetHistogram()," ","f");
259 
260  mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_empty) && "+selpre,"hist same");
261  mytree->GetHistogram()->SetLineColor(1);
262  mytree->GetHistogram()->SetLineWidth(2);
263  mytree->GetHistogram()->SetFillColor(kMagenta-6);
264  legpre->AddEntry(mytree->GetHistogram()," ","f");
265 
266  mytree->Draw(metricstr,"!(pass_time && pass_empty) && "+selpre,"hist same");
267  mytree->GetHistogram()->SetLineColor(1);
268  mytree->GetHistogram()->SetLineWidth(2);
269  mytree->GetHistogram()->SetFillColor(kGray+2);
270  legpre->AddEntry(mytree->GetHistogram()," ","f");
271  leg->SetNColumns(2);
272  SetLeg(leg);
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,"Far Detector");
280 
281  UpdateStamp(ptype,maxt);
282  DrawArrow(1.2,-0.5,0.1,0.9*hAll->GetBinContent(hAll->GetMaximumBin()));
283  DrawArrow(3.2,0.5,0.1,0.9*hAll->GetBinContent(hAll->GetMaximumBin()));
284  TLine line;
285  line.SetLineStyle(7);
286  line.SetLineWidth(2);
287  line.DrawLine(0,0.1,0,pow(hAll->GetMaximum(),0.58));
288  line.DrawLine(-1,pow(hAll->GetMaximum(),0.58),0,pow(hAll->GetMaximum(),0.58));
289  TLatex *ltx = MiscText(0.165,0.29,0.03,"No Slicing Information");
290  ltx->SetTextAngle(90);
291  c1->Update();
292  c1->SaveAs("pngfiles/FarDet-t02-P1GoodDataSelNumSlices"+suf+".png");
293  c1->Close();
294 
295 }
std::map< std::string, double > xmax
void SetLeg(TLegend *leg)
constexpr T pow(T x)
Definition: pow.h:75
void StripSpecialChar(string &instr)
Double_t ymax
Definition: plot.C:25
Definition: Cand.cxx:23
const int nbins
Definition: cellShifts.C:15
void DrawArrow(double x, double dx, double ymin, double ymax)
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
c1
Definition: demo5.py:24
TLatex * MiscText(float x, float y, float size, TString text)
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
void GoodDataSelNumSlices(int ptype=0)
fvar< T > ceil(const fvar< T > &x)
Definition: ceil.hpp:11