PlotDB_Web.C
Go to the documentation of this file.
1 #include "SetupHistos.C"
2 #include "TMath.h"
3 
4 /********************/
5 #include <algorithm>
6 #include <limits>
7 #include <cmath>
8 #include <vector>
9 #include <iostream>
10 /*********************/
11 
12 
13 
14 
15 
16 
17 void UpdateStamp(int ptype, int maxt){
18 
19  TDatime tnow(maxt);
20  TString lasttime = TString::Format("Last updated on: %s", tnow.AsString());
21 
22  TLatex *ltx = MiscText(0.94,0.9,0.03,lasttime);
23 
24  ltx->SetTextAngle(-90);
25 
26 }
27 
28 void DrawConfig(int dbcfg){
29 
30  for(int db=1; db<=14; db++){
31  TPave *box = new TPave(0.26+0.02*db,0.945,0.28+0.02*db,0.975,4,"BR NDC");
32  box->SetLineWidth(2);
33  box->SetShadowColor(0);
34  box->SetFillStyle(1001);
35  //box->DrawPave(0.17+0.03*db,0.95,0.20+0.03*db,0.98,4,"NDC BR");
36 // box->SetFillColor(10);
37  int bit = pow(2,db-1);
38  int isgood = ( (dbcfg - dbcfg % bit) / bit ) % 2;
39  if(isgood) box->SetFillColor(kGreen);
40  else box->SetFillColor(kWhite);
41  box->Draw();
42  }
43 
44 }
45 
46 
47 
48 void PlotDB_Web(int ptype=2){
49 
50 
51 
52 
53 
54 // TCanvas* ct=new TCanvas("ct","ct",500,500);
55 
56  gStyle->SetTimeOffset(0);
57 
58  TDatime t;
59  int GMToffset = (t.Convert(true) - t.Convert());
60 
61  gSystem->Setenv("TZ","UTC");
62 
63  TString stdP1 = "run>11495&&par==1";
64  t.Set();
65  int maxt = t.Convert();
66  int mint = TDatime(20130729,0).Convert();
67 
68 // TDatime(maxt).Print();
69 
70  int dt = 3600*24;
71  if(ptype==1) dt *= 7;
72  if(ptype==0) dt *= 30;
73 
74  TString tsel = TString::Format("&& lastsec > %d && lastsec < %d",maxt - dt + 2*GMToffset, maxt + 2*GMToffset);
75  stdP1 += tsel;
76 
77  int tdiv = 706;
78  int tbin = 3600*24;
79 
80  TString tlab = "Date (dd/mm/yy - Central Time)";
81  TString tform = "%d/%m/%y";
82  TString suf = "Month";
83 
84  if(ptype==1){
85  tbin = 3600*6;
86  tdiv = 408;
87  tlab = "Date (dd/mm - Central Time)";
88  tform = "%d/%m";
89  suf = "Week";
90  }
91  if(ptype==2){
92  tbin = 3600;
93  tdiv = 309;
94  tlab = "Central Time (hour:min)";
95  tform = "%H:%M";
96  suf = "Day";
97  }
98 
99  TChain *mytree = new TChain("mytree");
100  mytree->Add("MetricsTree_All.root");
101 
102 // MakeLongCanvas();
103 
104  TCanvas *c1 = new TCanvas("c1","c1",1000,600);
105  c1->SetBottomMargin(0.12);
106  c1->SetLeftMargin(0.12);
107  c1->SetRightMargin(0.07);
108  c1->SetTopMargin(0.07);
109 
110 
111 
112 
113 
115  int preliminary;
116 
117  mytree->SetBranchAddress("dbencoded",&dbencoded);
118  mytree->SetBranchAddress("dbaencoded",&dbaencoded);
119  mytree->SetBranchAddress("lastsec",&lastsec);
120  mytree->SetBranchAddress("run",&run);
121  mytree->SetBranchAddress("subrun",&subrun);
122  mytree->SetBranchAddress("par",&par);
123  mytree->SetBranchAddress("pass_all",&pass_all);
124  mytree->SetBranchAddress("preliminary",&preliminary);
125 
126 // preliminary = false;
127 
128  int nentries = mytree->GetEntries();
129 
130  TH2D *h2 = new TH2D("","",dt/10,maxt-dt,maxt,14,1,15);
131 
132  vector<int> dbconfigs;
133 
134  for(int i=0; i<nentries; i++){
135 
136  //if(i%(nentries/1000)==0) cout << i*100.0/nentries << "% done" << endl;
137 
138  mytree->GetEntry(i);
139 // if(par!=1 || !pass_all || run<16540) continue;
140  if(par!=1 || lastsec - 2*GMToffset < maxt - dt){
141  continue;
142  }
143 // if(run<16540) continue;
144  //if( mytree2->GetEntries(TString::Format("run==%d && subrun==%d && pass_all",run,subrun)) ) continue;
145  //if( !IsGood(run,subrun) ) continue;
146 
147  dbconfigs.push_back(dbencoded);
148 
149  for(int db=1; db<=14; db++){
150  int bit = pow(2,db-1);
151  int isgood = ( (dbencoded - dbencoded % bit) / bit ) % 2;
152  int isactive = ( (dbaencoded - dbaencoded % bit) / bit ) % 2;
153  if(!preliminary){
154  if(isgood) h2->Fill(lastsec - 2*GMToffset,db,2);
155  else if(isactive) h2->Fill(lastsec - 2*GMToffset,db,1);
156  }
157  else{
158  if(isgood) h2->Fill(lastsec - 2*GMToffset,db,1.75);
159  else if(isactive) h2->Fill(lastsec - 2*GMToffset,db,1.25);
160  }
161  }
162 
163  }
164 
165  if(dbconfigs.size()==0) dbconfigs.push_back(0);
166 
167  int *idx = new int[dbconfigs.size()];
168 
169  TMath::Sort(int(dbconfigs.size()),&dbconfigs[0],idx,kFALSE);
170 // std::sort(dbconfigs.begin(),dbconfigs.end());
171 
172  int napp = 0;
173  int maxapp = 0;
174  int tempcfg = -1;
175  int maxcfg = -1;
176 
177  for(int i=0; i<int(dbconfigs.size()); i++){
178  if(tempcfg != dbconfigs[idx[i]]){
179  if(napp > maxapp){
180  maxapp = napp;
181  maxcfg = tempcfg;
182  }
183  napp = 0;
184  tempcfg = dbconfigs[idx[i]];
185  }
186  napp++;
187  }
188  if(napp > maxapp){
189  maxapp = napp;
190  maxcfg = tempcfg;
191  }
192 
193  delete[] idx;
194 
195  SetHist(h2);
196 
197 // h3->GetXaxis()->SetRangeUser(11495,16300);
198  h2->GetYaxis()->SetNdivisions(14);
199  for(int i=1; i<=14; i++) h2->GetYaxis()->SetBinLabel(i,TString::Format("%d",i));
200 
201  h2->SetTitle(";"+tlab+";Diblock Number;");
202  h2->GetXaxis()->SetTimeDisplay(1);
203  h2->GetXaxis()->SetTimeFormat(tform);
204  h2->GetXaxis()->SetNdivisions(tdiv);
205  h2->SetStats(kFALSE);
206  h2->GetXaxis()->CenterTitle();
207  h2->GetYaxis()->CenterTitle();
208  h2->GetYaxis()->SetLabelSize(0.06);
209 
210  // Get moodier colours for colz
211  const Int_t NRGBs = 5;
212  const Int_t NCont = 255;
213  Double_t stops[NRGBs] = { 0.00, 0.25, 0.50, 0.75, 1.00 };
214  Double_t red[NRGBs] = { 1.00, 1.00, 1.00, 0.60, 0.00 };
215  Double_t green[NRGBs] = { 0.00, 0.70, 1.00, 0.80, 0.80 };
216  Double_t blue[NRGBs] = { 0.00, 0.70, 1.00, 0.60, 0.00 };
217  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
218  gStyle->SetNumberContours(NCont);
219 
220  h2->GetZaxis()->SetRangeUser(1,2);
221 
222  h2->Draw("col");
223 
224 
225 // ******************************************************************
226 // ct->cd();
227 //
228 // *****************************************************************
229 
230  c1->SetGridy();
231 
232  if(dbconfigs.size()==1 && dbconfigs[0]==0) maxapp = 0;
233 
234  TString bestcfg = TString::Format("# of Subruns = %d; Percentage = %2.1f%%",
235  maxapp,100.*maxapp/dbconfigs.size());
236 
237  MiscText(0.13,0.95,0.035,"Most Common = ");
238  MiscText(0.58,0.95,0.035,bestcfg);
239  DrawConfig(maxcfg);
240 
241  UpdateStamp(ptype,maxt);
242  c1->SaveAs("pngfiles/FarDet-t02-P1GoodDataSelDetConfig"+suf+".png");
243 c1->Close();
244 
245 }
246 
247 TString GetConfig(int dbcfg){
248 
249  TString out = "";
250 
251  for(int db=1; db<=14; db++){
252  int bit = pow(2,db-1);
253  int isgood = ( (dbcfg - dbcfg % bit) / bit ) % 2;
254  if(isgood) out += "1";
255  else out += "0";
256  }
257 
258  return out;
259 
260 }
261 
Int_t lastsec
Definition: SimpleIterate.C:27
Int_t pass_all
Definition: SimpleIterate.C:42
void SetHist(TH1 *hist, int col=1, bool fill=false)
Definition: SetupHistos.C:60
constexpr T pow(T x)
Definition: pow.h:75
Int_t par
Definition: SimpleIterate.C:24
TLatex * MiscText(float x, float y, float size, TString text)
Int_t dbencoded
Definition: SimpleIterate.C:54
Definition: Cand.cxx:23
void DrawConfig(int dbcfg)
Definition: PlotDB_Web.C:28
Int_t dbaencoded
Definition: SimpleIterate.C:55
void PlotDB_Web(int ptype=2)
Definition: PlotDB_Web.C:48
tuple blue
Definition: rootlogon.py:65
int NRGBs
Definition: rootlogon.py:77
Long64_t nentries
int NCont
Definition: rootlogon.py:78
Int_t preliminary
Definition: SimpleIterate.C:63
TTree * mytree
Definition: SimpleIterate.C:18
TH1F * h2
Definition: plot.C:45
TString GetConfig(int dbcfg)
Definition: PlotDB_Web.C:247
Int_t GMToffset
Definition: AnaPlotMaker.h:43
c1
Definition: demo5.py:24
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
void UpdateStamp(int ptype, int maxt)
Definition: PlotDB_Web.C:17