GoodDataSelDate.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 void SetLeg(TLegend *leg){
15 
16  leg->SetFillStyle(0);
17  leg->SetBorderSize(0);
18  leg->SetTextSize(0.04);
19  leg->SetTextFont(42);
20  leg->SetY1(leg->GetY2()-leg->GetNRows()*0.05);
21 
22  return;
23 
24 }
25 
26 TLatex *MiscText(float x, float y, float size, TString text)
27 {
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  TDatime tnow(maxt);
41  TString lasttime = TString::Format("Last updated on: %s", tnow.AsString());
42  TLatex *ltx = MiscText(0.6,0.96,0.03,lasttime);
43  // ltx->SetTextAngle(-90);
44 
45 }
46 
47 void StripSpecialChar(string &instr){
48  cout<<"\n"<<instr<<endl;
49  cout<<"\n"<<endl;
50  char str[50];
51  strcpy(str,instr.c_str());
52  // char str[50] = instr;
53  //std::string str[50]=instr.c_str();
54  char strStripped[50];
55  int c = 0;
56 
57  for(int i=0; i<strlen(str); i++){
58 
59  if (isalnum(str[i])){
60  strStripped[c] = str[i];
61  c++;
62 
63  }
64 
65  }
66 
67  strStripped[c] = '\0';
68  instr = strStripped;
69 
70 }
71 
72 void GoodDataSelDate(int ptype=0, int run_lowlimit =0, int run_highlimit=0){
73 
74  TDatime t;
75  int GMToffset = (t.Convert(true) - t.Convert());
76  gSystem->Setenv("TZ","UTC");
77  TString stdP1 = "run>11495&&par==1";
78  t.Set();
79  int maxt = t.Convert();
80  int mint = TDatime(20130729,0).Convert();
81  // TDatime(maxt).Print();
82  int dt = 3600*24;
83 
84  if(ptype==1) dt *= 7;
85 
86  if(ptype==0) dt *= 30;
87 
88 
89  TString tsel = TString::Format("&& lastsec > %d && lastsec < %d",maxt - dt + 2*GMToffset, maxt + 2*GMToffset);
90  stdP1 += tsel;
91  int tdiv = 706;
92  int tbin = 3600*24;
93  TString tlab = "Date (dd/mm/yy - Central Time)";
94  TString tform = "%d/%m/%y";
95  TString suf = "Month";
96 
97  if(ptype==1){
98 
99  tbin = 3600*6;
100  tdiv = 408;
101  tlab = "Date (dd/mm - Central Time)";
102  tform = "%d/%m";
103  suf = "Week";
104 
105  }
106 
107  if(ptype==2){
108 
109  tbin = 3600;
110  tdiv = 309;
111  tlab = "Central Time (hour:min)";
112  tform = "%H:%M";
113  suf = "Day";
114 
115  }
116  TString metricstr = TString::Format("lastsec-%d",2*GMToffset);
117  TString sel = stdP1;
118  TString title = tlab;
119  int nbins = 100;
120  double xmin = maxt-dt;
121  double xmax = maxt;
122  TString filenames = "MetricsTree*.root";
123  gStyle->SetTimeOffset(0);
124 
125  if(sel=="") sel = "1";
126 
127  if(title=="") title = metricstr;
128 
129  TString selpre = "((" + sel + ") && preliminary)";
130  // TString selpre = "((" + sel + ") && 0)";
131  TChain *mytree = new TChain("mytree");
132  mytree->Add(filenames);
133  // MakeLongCanvas();
134 
135  //my: Option to plot a run subset: fix xmin and xmax
136  //The axes format are still given with ptype
137  bool gotRunLimits = run_highlimit != run_lowlimit;
138  TString runlabel ="";
139  if(gotRunLimits){
140  //Get lower time
141  mytree->Draw("firstsec",
142  TString::Format("run>=%d && run<=%d && firstsec>=%d"
143  , run_lowlimit, run_highlimit, mint));
144  xmin = mytree->GetHistogram()->GetXaxis()->GetXmin();
145  //Get Higher time
146  mytree->Draw("lastsec",
147  TString::Format("run>=%d && run<=%d && firstsec>=%d"
148  , run_lowlimit, run_highlimit, mint));
149  xmax = mytree->GetHistogram()->GetXaxis()->GetXmax();
150  //Now fix the run subset into the selection strings
151  TString stdP1 = "run>11495&&par==1"; //Before it gets the time cuts
152  sel = stdP1 + TString::Format(
153  "&& run>=%d && run<=%d",run_lowlimit, run_highlimit);
154  selpre = "((" + sel + ") && preliminary)";
155  //Set the suffix for saving
156  suf = "CustomRunRange";
157  //Set a label for the plot title
158  runlabel = TString::Format("%d < Run < %d",run_lowlimit, run_highlimit);
159  }
160  //endmy
161 
162  TCanvas *c1 = new TCanvas("c1","c1",1000,600);
163  c1->SetBottomMargin(0.12);
164  c1->SetLeftMargin(0.12);
165  c1->SetRightMargin(0.07);
166  c1->SetTopMargin(0.07);
167  TLegend *leg = new TLegend(0.15,0.65,0.65,0.9);
168  TLegend *legpre = new TLegend(0.67,0.65,0.95,0.9);
169  mytree->Draw(metricstr,sel,"hist");
170  TH1F* hAll = 0;
171  hAll = (TH1F*)(mytree->GetHistogram())->Clone("");
172 
173  if(xmin == -9999 || xmax == -9999){
174 
175  xmin = hAll->GetXaxis()->GetXmin();
176  xmax = hAll->GetXaxis()->GetXmax();
177 
178  }
179 
180 if(nbins<0){
181 
182  xmin = floor(xmin);
183  xmax = ceil(xmax);
184  nbins *= -1;
185  if(int(xmax-xmin)%nbins!=0){
186  xmax += (nbins - int(xmax-xmin)%nbins)/2;
187  xmin -= (nbins - int(xmax-xmin)%nbins);
188 
189  }
190 
191  nbins = (xmax - xmin) / nbins;
192 }
193 
194 delete hAll;
195 
196 hAll = new TH1F("hAll","hAll",nbins,xmin,xmax);
197 mytree->Draw(metricstr+">>hAll",sel,"hist");
198 hAll->Clear();
199 hAll->Draw("hist");
200 hAll->SetLineColor(1);
201 hAll->SetLineWidth(2);
202 hAll->SetTitle(";"+title+";Subruns");
203 hAll->GetXaxis()->SetTitleOffset(1);
204 hAll->GetYaxis()->SetTitleOffset(1);
205 hAll->GetXaxis()->CenterTitle();
206 hAll->GetYaxis()->CenterTitle();
207 hAll->GetXaxis()->SetNdivisions();
208 hAll->GetYaxis()->SetNdivisions();
209 hAll->SetMinimum(0.1);
210 hAll->SetStats(kFALSE);
211 double max = hAll->GetMaximum();
212 hAll->SetMaximum(pow(10,1.5*(log10(max)+1)-1));
213 leg->AddEntry(hAll,"Good Subruns","f");
214 
215 mytree->Draw(metricstr,"!(pass_all && ngoodcdb==14 && !preliminary) && "+sel,"hist same");
216 mytree->GetHistogram()->SetLineColor(1);
217 mytree->GetHistogram()->SetLineWidth(2);
218 mytree->GetHistogram()->SetFillColor(kRed-4);
219 leg->AddEntry(mytree->GetHistogram(),"Partial Detector","f");
220 
221 mytree->Draw(metricstr,"!(pass_all && !preliminary) && "+sel,"hist same");
222 mytree->GetHistogram()->SetLineColor(1);
223 mytree->GetHistogram()->SetLineWidth(2);
224 mytree->GetHistogram()->SetFillColor(kOrange+7);
225 leg->AddEntry(mytree->GetHistogram(),"Failed Reco","f");
226 
227 mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_hits && pass_db && pass_empty && !preliminary) && "+sel,"hist same");
228 mytree->GetHistogram()->SetLineColor(1);
229 mytree->GetHistogram()->SetLineWidth(2);
230 mytree->GetHistogram()->SetFillColor(kGreen+1);
231 leg->AddEntry(mytree->GetHistogram(),"Failed Diblock","f");
232 
233 mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_hits && pass_empty && !preliminary) && "+sel,"hist same");
234 mytree->GetHistogram()->SetLineColor(1);
235 mytree->GetHistogram()->SetLineWidth(2);
236 mytree->GetHistogram()->SetFillColor(4);
237 leg->AddEntry(mytree->GetHistogram(),"Failed Hit Rate","f");
238 
239 mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_empty && !preliminary) && "+sel,"hist same");
240 mytree->GetHistogram()->SetLineColor(1);
241 mytree->GetHistogram()->SetLineWidth(2);
242 mytree->GetHistogram()->SetFillColor(kMagenta+2);
243 leg->AddEntry(mytree->GetHistogram(),"Failed Live Time","f");
244 
245 mytree->Draw(metricstr,"!(pass_time && pass_empty && !preliminary) && "+sel,"hist same");
246 mytree->GetHistogram()->SetLineColor(1);
247 mytree->GetHistogram()->SetLineWidth(2);
248 mytree->GetHistogram()->SetFillColor(kBlack);
249 leg->AddEntry(mytree->GetHistogram(),"Failed Other","f");
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 && ngoodcdb==14) && "+selpre,"hist same");
257 mytree->GetHistogram()->SetLineColor(1);
258 mytree->GetHistogram()->SetLineWidth(2);
259 mytree->GetHistogram()->SetFillColor(kPink-4);
260 legpre->AddEntry(mytree->GetHistogram()," ","f");
261 
262 mytree->Draw(metricstr,"!pass_all && "+selpre,"hist same");
263 mytree->GetHistogram()->SetLineColor(1);
264 mytree->GetHistogram()->SetLineWidth(2);
265 mytree->GetHistogram()->SetFillColor(kOrange-9);
266 legpre->AddEntry(mytree->GetHistogram()," ","f");
267 
268 mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_hits && pass_db && pass_empty) && "+selpre,"hist same");
269 mytree->GetHistogram()->SetLineColor(1);
270 mytree->GetHistogram()->SetLineWidth(2);
271 mytree->GetHistogram()->SetFillColor(kGreen-9);
272 legpre->AddEntry(mytree->GetHistogram()," Preliminary","f");
273 
274 mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_hits && pass_empty) && "+selpre,"hist same");
275 mytree->GetHistogram()->SetLineColor(1);
276 mytree->GetHistogram()->SetLineWidth(2);
277 mytree->GetHistogram()->SetFillColor(kAzure-4);
278 legpre->AddEntry(mytree->GetHistogram()," ","f");
279 
280 mytree->Draw(metricstr,"!(pass_time && pass_runlen && pass_empty) && "+selpre,"hist same");
281 mytree->GetHistogram()->SetLineColor(1);
282 mytree->GetHistogram()->SetLineWidth(2);
283 mytree->GetHistogram()->SetFillColor(kMagenta-6);
284 legpre->AddEntry(mytree->GetHistogram()," ","f");
285 
286 mytree->Draw(metricstr,"!(pass_time && pass_empty) && "+selpre,"hist same");
287 mytree->GetHistogram()->SetLineColor(1);
288 mytree->GetHistogram()->SetLineWidth(2);
289 mytree->GetHistogram()->SetFillColor(kGray+2);
290 
291 legpre->AddEntry(mytree->GetHistogram()," ","f");
292 leg->SetNColumns(2);
293 SetLeg(leg);
294 leg->Draw();
295 legpre->SetNColumns(2);
296 SetLeg(legpre);
297 legpre->SetColumnSeparation(-0.05);
298 legpre->Draw();
299 c1->SetLogy();
300 MiscText(0.15,0.94,0.055,"Far Detector");
301 
302 hAll->GetXaxis()->SetTimeFormat(tform);
303 hAll->GetXaxis()->SetTimeDisplay(1);
304 hAll->GetXaxis()->SetNdivisions(tdiv);
305 hAll->SetStats(kFALSE);
306 gPad->SetGridx();
307 //Add label if got runlimits
308 if(gotRunLimits) MiscText(0.7,0.96,0.04,runlabel);
309 else UpdateStamp(ptype,maxt);
310 c1->SaveAs("pngfiles/FarDet-t02-P1GoodDataSelDate"+suf+".png");
311 c1->Close();
312 }
enum BeamMode kOrange
enum BeamMode kRed
void DrawArrow(double x, double dx, double ymin, double ymax)
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)
Double_t ymax
Definition: plot.C:25
Definition: Cand.cxx:23
const int nbins
Definition: cellShifts.C:15
double dx[NP][NC]
void StripSpecialChar(string &instr)
TTree * mytree
Definition: SimpleIterate.C:18
void SetLeg(TLegend *leg)
OStream cout
Definition: OStream.cxx:6
void UpdateStamp(int ptype, int maxt)
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
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:68
enum BeamMode kGreen
fvar< T > ceil(const fvar< T > &x)
Definition: ceil.hpp:11
void GoodDataSelDate(int ptype=0, int run_lowlimit=0, int run_highlimit=0)