StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
history.C
1 static int startday=050;
2 static int endday=365;
3 
4 static const int NRUN=10000;
5 static int nrun=0;
6 static int ngoodrun=0;
7 
8 static const int NVAL=19;
9 static int run[NRUN];
10 static int flag[NRUN];
11 static Float_t frun[NRUN];
12 static Long64_t idx[NRUN];
13 static double val[NVAL][NRUN];
14 static TGraph* g[NVAL];
15 
16 void read(int irun, int runnum, int log){
17  char file[100];
18  int yearday=runnum/1000;
19  sprintf(file,"www/%d/%d.Mismatch.txt",yearday,runnum);
20  FILE* f=fopen(file,"r");
21  if(!f) { printf("Failed to open %s\n",file); return; }
22  //printf("Reading %s\n",file);
23  run[irun]=runnum;
24  flag[irun]=1;
25  int nzero=0;
26  char line[200];
27  for(int i=0; i<NVAL+1; i++){
28  float v;
29  fscanf(f,"%f",&v);
30  if(i<18) val[i][irun]=v;
31  if(i==19) val[i-1][irun]=v;
32  }
33  printf("irun=%d run=%8d : ",irun,runnum);
34  for(int i=0; i<NVAL; i++) {printf("%6.3f ",val[i][irun]);}
35  printf("\n");
36  fclose(f);
37  if(val[NVAL-1][irun]>=0.0 && val[NVAL-1][irun]<=100.0){
38  for(int i=0; i<NVAL; i++){
39  if(log==1){
40  float v=-3;
41  if(val[i][irun]>=0.001) v=log10(val[i][irun]);
42  g[i]->SetPoint(ngoodrun,double(irun),v);
43  }else{
44  g[i]->SetPoint(ngoodrun,double(irun),val[i][irun]);
45  }
46  }
47  ngoodrun++;
48  }
49 }
50 
51 void readall(int day, int log){
52  int i=0;
53  char tmp[100];
54  float r;
55  int year=day/1000;
56  int yearday=day%1000;
57  printf("Yearday=%d Year=%d Day=%d\n",day,year,yearday);
58  if(yearday!=0) {startday=yearday; endday=yearday;}
59  for(int d=startday; d<=endday; d++){
60  int yday=year*1000+d;
61  char dirname[100]; sprintf(dirname,"www/%5d/",yday);
62  TSystemDirectory dir(dirname,dirname);
63  TList *files = dir.GetListOfFiles();
64  if(files){
65  TSystemFile *file;
66  TString fname;
67  TIter next(files);
68  while ((file=(TSystemFile*)next())) {
69  fname = file->GetName();
70  if (!file->IsDirectory() && fname.EndsWith(".Mismatch.txt")) {
71  sscanf(fname.Data(),"%8f",&r);
72  frun[i]=(Long64_t)r;
73  i++;
74  printf("%s %8.0f\n",fname.Data(),r);
75  }
76  }
77  }
78  }
79  nrun=i;
80  TMath::Sort((long)i,frun,idx,0);
81  for(int j=0; j<nrun; j++){
82  read(j,(int)frun[idx[j]], log);
83  }
84 }
85 
86 void plot(float xmin=-1, float xmax=0, float ymin=-3.1, float ymax=2){
87  if(xmax==0) xmax=nrun;
88  TH2F *frame = new TH2F("frame","",1,xmin,xmax,1,ymin,ymax);
89  frame->Draw();
90  for(int v=0; v<NVAL; v++){
91  g[v]->Draw("L");
92  }
93  TText* t0=new TText(0.05 ,0.95,"BitMismatch%"); t0->SetNDC(); t0->SetTextSize(0.05); t0->SetTextColor(kBlack); t0->Draw();
94  TText* t1=new TText(0.15 ,0.85,"QT12->Layer0"); t1->SetNDC(); t1->SetTextSize(0.05); t1->SetTextColor(kRed); t1->Draw();
95  TText* t2=new TText(0.15 ,0.80,"QT34->Layer0"); t2->SetNDC(); t2->SetTextSize(0.05); t2->SetTextColor(kMagenta);t2->Draw();
96  TText* t3=new TText(0.15 ,0.75,"Layer0->1"); t3->SetNDC(); t3->SetTextSize(0.05); t3->SetTextColor(kBlue); t3->Draw();
97  TText* t4=new TText(0.15 ,0.70,"Layer1->2"); t4->SetNDC(); t4->SetTextSize(0.05); t4->SetTextColor(kOrange); t4->Draw();
98  TText* t5=new TText(0.15 ,0.65,"Layer2->TCU"); t5->SetNDC(); t5->SetTextSize(0.05); t5->SetTextColor(kGreen); t5->Draw();
99  TText* t6=new TText(0.15 ,0.60,"Average"); t6->SetNDC(); t6->SetTextSize(0.05); t6->SetTextColor(kBlack); t6->Draw();
100 }
101 
102 void history(int day=16054, int log=0){
103  int color[NVAL]={kRed,kRed,kMagenta,kMagenta,
104  kRed,kRed,kRed,kRed,
105  kMagenta,kMagenta,kMagenta,kMagenta,
106  kBlue,kBlue,kBlue,kBlue,
107  kOrange, kGreen, kBlack};
108  for(int v=0; v<NVAL; v++){
109  g[v]=new TGraph(1);
110  g[v]->SetMarkerStyle(20);
111  g[v]->SetMarkerSize(1);
112  g[v]->SetLineColor(color[v]);
113  g[v]->SetLineWidth(2);
114  }
115  readall(day,log);
116  gStyle->SetOptStat(0);
117  c1 = new TCanvas("c1","History",50,0,700,720);
118  if(log==0) {
119  c1->Divide(1,2);
120  c1->cd(1); plot(-1,0,-5.0,60.0);
121  c1->cd(2); plot(-1,0,-0.5,4.0);
122  }else {
123  plot();
124  }
125  c1->Update();
126  char file[100];
127  if(day%1000!=0) { sprintf(file,"%d/history.%5d.png",day,day); }
128  else { sprintf(file,"history.png",day);}
129  c1->SaveAs(file);
130  printf("Create %s\n",file);
131 }
132