StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
makeqaplot.C
1 TCanvas *c1;
2 static TFile* file;
3 static int runnum, yearday, png, pdf;
4 
5 static const int NCRATE=14;
6 static const char* CRATE[NCRATE]={"L1","BC1","MXQ","MIX","BCW","BCE","FEQ",
7  "BBC","BBQ","FMS","QT1","QT2","QT3","QT4"};
8 static const int color[NCRATE]= {kGreen+2,kBlue,kRed,kBlue,kBlue,kBlue,kOrange-3,
9  kBlue,kRed,kBlue,kMagenta,kMagenta,kMagenta,kMagenta};
10 
11 float mMean[NCRATE];
12 float mRms[NCRATE];
13 float mMax[NCRATE];
14 static float MAX=65536*3.0;
15 
16 void makeqaplot(int run=0, float max=MAX, int plt=0, float min=0){
17  if(max==0) max=MAX;
18  runnum=run;
19  yearday=run/1000;
20 
21  c1 = new TCanvas("c1","RCC Counter",50,0,1200,900);
22  gStyle->SetPalette(1);
23  gStyle->SetStatW(0.4);
24  gStyle->SetStatH(0.3);
25  gStyle->SetTitleH(0.2);
26 
27  char fname[100];
28  if(run==0) {sprintf(fname,"rccqa.root");}
29  else {sprintf(fname,"%d/rccqa.%d.root",yearday,run);}
30 
31  cout << "Opening "<<fname<<endl;
32  file=new TFile(fname,"old");
33 
34  if(plt==0 || plt==1){
35  gStyle->SetOptStat(111110);
36  gStyle->SetOptTitle(1);
37  c1->Clear();
38  c1->Divide(2,7);
39  TH1F *h;
40  for(int i=0; i<NCRATE; i++){
41  c1->cd(i+1)->SetLogy();
42  h=(TH1F*)file->Get(CRATE[i]);
43  mMean[i]=h->GetMean();
44  mRms[i]=h->GetRMS();
45  mMax[i]=h->GetXaxis()->GetBinCenter(h->FindLastBinAbove(0.0,1));
46  if(mMax[i]>=65536) {h->SetFillColor(kRed);}
47  else {h->SetFillColor(kBlue);}
48  h->SetLabelSize(0.1);
49  if(max<MAX) {
50  h->GetXaxis()->SetRangeUser(0, max);
51  }
52  h->Draw();
53  cout << Form("%3s Mean=%9.1f RMS=%9.1f MaxDiff=%9.1f",CRATE[i],mMean[i],mRms[i],mMax[i])<<endl;
54  }
55 
56  if(yearday==0){
57  sprintf(fname,"%d.diff.png",runnum);
58  }else{
59  if(max==MAX){
60  sprintf(fname,"%d/%d.diff.png",yearday,runnum);
61  }else{
62  sprintf(fname,"%d/%d.diff.zoom.png",yearday,runnum);
63  }
64  }
65  c1->SaveAs(fname);
66 
67  if(max==MAX){
68  if(run==0) {sprintf(fname,"rcc.txt");}
69  else {sprintf(fname,"%d/rcc.%d.txt",yearday,run);}
70  printf("Writing %s\n",fname);
71  FILE* txfile = fopen(fname,"w");
72  if(!txfile){
73  printf("Could not open file\n");
74  }else{
75  for(int i=0; i<NCRATE; i++){
76  fprintf(txfile,"%12.1f %12.1f %12.1f\n",
77  mMean[i],mRms[i],mMax[i]);
78  }
79  fclose(txfile);
80  }
81  }
82  }
83 
84  if(plt==0 || plt==2){
85  c1->Clear();
86  gStyle->SetTitleH(0.05);
87  gStyle->SetOptStat(0);
88  TTree* t=(TTree*)file->Get("RCC");
89  unsigned int EVT;
90  unsigned int TCU;
91  unsigned int DIFF[NCRATE];
92  t->SetBranchAddress("evt",&EVT);
93  t->SetBranchAddress("tcu",&TCU);
94  t->SetBranchAddress("diff",&DIFF);
95  int n = t->GetEntries();
96  unsigned long long one=1;
97  unsigned long long tmin=one<<32;
98  unsigned long long tmax=0;
99  unsigned long long dmin=one<<32;
100  unsigned long long dmax=0;
101 
102  TGraph* g[NCRATE];
103  for(int i=0; i<NCRATE; i++){
104  g[i] = new TGraph(1);
105  g[i]->SetLineColor(color[i]);
106  }
107  printf("Found %d entries in Tree\n",n);
108  for(int i=0; i<n; i++){
109  t->GetEvent(i);
110  //printf("%d %u %u %u\n",i,EVT,TCU,DIFF[2],DIFF[9]);
111  if(tmin>TCU) tmin=TCU;
112  if(tmax<TCU) tmax=TCU;
113  for(int j=0; j<NCRATE; j++){
114  long long diff=DIFF[j];
115  int diff2;
116  if(diff>2147483647) diff=diff-4294967296;
117  diff2=diff;
118  if(j==6) printf("Crate=%2d TCU=%10d tmin=%10d DIFF=%10u diff=%10d diff2=%10d %f\n",
119  j,TCU,tmin,DIFF[j],diff,diff2,(double)diff2);
120 
121  g[j]->SetPoint(i,double(TCU),double(diff2));
122  if(dmin>diff) dmin=diff;
123  if(dmax<diff) dmax=diff;
124  }
125  }
126  // tmax=111000000;
127  printf("Tmin=%f Tmax=%f Dmin=%f Dmax=%f\n",tmin,tmax,dmin,max);
128  TH2F* frame=new TH2F("diff","RCC-TCU [xing]",1,
129  float(tmin),float(tmax),1,min,max);
130  frame->Draw();
131  for(int i=0; i<NCRATE; i++){
132  g[i]->Draw("L");
133  }
134  TLine *l = new TLine(tmin, 65536.0 , tmax, 65536.0);
135  l->Draw();
136  TText *tt;
137  tt=new TText(0.7,0.03,"TCU counter [xing]"); tt->SetNDC(); tt->SetTextSize(0.03); tt->Draw();
138  tt=new TText(0.7,0.38,"Memory Overwrite above"); tt->SetNDC(); tt->SetTextSize(0.02); tt->Draw();
139  float x=0.15, y=0.87, dy=0.025;
140  for(int i=0; i<NCRATE; i++){
141  tt=new TText(x,y,CRATE[i]); tt->SetNDC(); tt->SetTextSize(0.025); tt->SetTextColor(color[i]); tt->Draw();
142  y-=dy;
143  }
144  if(yearday==0){
145  sprintf(fname,"%d.tdiff.png",runnum);
146  }else{
147  if(max==MAX){
148  sprintf(fname,"%d/%d.tdiff.png",yearday,runnum);
149  }else{
150  sprintf(fname,"%d/%d.tdiff.%d.png",yearday,runnum,max);
151  }
152  }
153  c1->SaveAs(fname);
154  }
155 
156  if(plt==0 || plt==3){
157  c1->Clear();
158  gStyle->SetTitleH(0.05);
159  gStyle->SetOptStat(0);
160  TTree* t=(TTree*)file->Get("RCC");
161  t->Draw("evt:tcu");
162  if(yearday==0){
163  sprintf(fname,"%d.rate.png",runnum);
164  }else{
165  sprintf(fname,"%d/%d.rate.png",yearday,runnum);
166  }
167  c1->SaveAs(fname);
168  }
169 }
Definition: TCU.hh:18