GoodDataSelLiveTime.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  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 
70  strStripped[c] = '\0';
71  instr = strStripped;
72 
73 }
74 
75 void GoodDataSelLiveTime(int ptype=0){
76 
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(setlivetime,4.999)";
120  TString sel = stdP1;
121  TString title = "Live Time of Subrun set (s)";
122  int nbins = 100;
123  double xmin = 0;
124  double xmax = 5;
125 
126  TString filenames = "MetricsTree*.root";
127  //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 
233  mytree->Draw(metricstr,selpre,"hist same");
234  mytree->GetHistogram()->SetLineColor(1);
235  mytree->GetHistogram()->SetLineWidth(2);
236  mytree->GetHistogram()->SetFillColor(18);
237  legpre->AddEntry(mytree->GetHistogram()," ","f");
238 
239  mytree->Draw(metricstr,"!(pass_all && ngoodcdb==14) && "+selpre,"hist same");
240  mytree->GetHistogram()->SetLineColor(1);
241  mytree->GetHistogram()->SetLineWidth(2);
242  mytree->GetHistogram()->SetFillColor(kPink-4);
243  legpre->AddEntry(mytree->GetHistogram()," ","f");
244 
245  mytree->Draw(metricstr,"!pass_all && "+selpre,"hist same");
246  mytree->GetHistogram()->SetLineColor(1);
247  mytree->GetHistogram()->SetLineWidth(2);
248  mytree->GetHistogram()->SetFillColor(kOrange-9);
249  legpre->AddEntry(mytree->GetHistogram()," ","f");
250 
251  mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_hits && pass_db && pass_empty) && "+selpre,"hist same");
252  mytree->GetHistogram()->SetLineColor(1);
253  mytree->GetHistogram()->SetLineWidth(2);
254  mytree->GetHistogram()->SetFillColor(kGreen-9);
255  legpre->AddEntry(mytree->GetHistogram()," Preliminary","f");
256 
257  mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_hits && pass_empty) && "+selpre,"hist same");
258  mytree->GetHistogram()->SetLineColor(1);
259  mytree->GetHistogram()->SetLineWidth(2);
260  mytree->GetHistogram()->SetFillColor(kAzure-4);
261  legpre->AddEntry(mytree->GetHistogram()," ","f");
262 
263  mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_empty) && "+selpre,"hist same");
264  mytree->GetHistogram()->SetLineColor(1);
265  mytree->GetHistogram()->SetLineWidth(2);
266  mytree->GetHistogram()->SetFillColor(kMagenta-6);
267  legpre->AddEntry(mytree->GetHistogram()," ","f");
268 
269  mytree->Draw(metricstr,"!(pass_time && pass_empty) && "+selpre,"hist same");
270  mytree->GetHistogram()->SetLineColor(1);
271  mytree->GetHistogram()->SetLineWidth(2);
272  mytree->GetHistogram()->SetFillColor(kGray+2);
273  legpre->AddEntry(mytree->GetHistogram()," ","f");
274  leg->SetNColumns(2);
275  SetLeg(leg);
276  leg->Draw();
277  legpre->SetNColumns(2);
278  SetLeg(legpre);
279  legpre->SetColumnSeparation(-0.05);
280  legpre->Draw();
281  c1->SetLogy();
282  MiscText(0.15,0.94,0.055,"Far Detector");
283 
284  TLine line;
285  hAll->GetXaxis()->SetNoExponent();
286  UpdateStamp(ptype,maxt);
287  DrawArrow(1.00,-0.6,0.1,0.9*hAll->GetBinContent(hAll->GetMaximumBin()));
288  c1->Update();
289  c1->SaveAs("pngfiles/FarDet-t02-P1GoodDataSelLiveTime"+suf+".png");
290  c1->Close();
291 
292 }
enum BeamMode kOrange
enum BeamMode kRed
std::map< std::string, double > xmax
constexpr T pow(T x)
Definition: pow.h:75
TLatex * MiscText(float x, float y, float size, TString text)
void StripSpecialChar(string &instr)
Double_t ymax
Definition: plot.C:25
Definition: Cand.cxx:23
const int nbins
Definition: cellShifts.C:15
void SetLeg(TLegend *leg)
double dx[NP][NC]
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 UpdateStamp(int ptype, int maxt)
c1
Definition: demo5.py:24
void GoodDataSelLiveTime(int ptype=0)
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 DrawArrow(double x, double dx, double ymin, double ymax)
enum BeamMode kGreen
fvar< T > ceil(const fvar< T > &x)
Definition: ceil.hpp:11