StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
makeqaplot.C
1 static const int NTB=15;
2 
3 static const int kFgtNumDiscs=6;
4 static const int kFgtNumQuads=4;
5 static const int kFgtNumElecIds=30720;
6 
7 static const int NHist=10;
8 static const int N1dHist=12;
9 static const int N2dHist=5;
10 static const int NTrkHist=6;
11 
12 static TH1F *hist0[NHist];
13 static TH1F *hist1[kFgtNumDiscs][kFgtNumQuads][N1dHist];
14 static TH2F *hist2[kFgtNumDiscs][N2dHist];
15 static TH1F *histTrk[kFgtNumQuads][NTrkHist];
16 
17 static const char* cquad[kFgtNumQuads]={"A","B","C","D"};
18 static const char* cHist[NHist]={"MaxTimeBin","ADC","DataSize","ZSdata","10sigma","Nevt","LandauChi2","LandauSig","LandauMpv","Mpv-3Sig"};
19 
20 static const char* c1dHist[N1dHist]={"NHitStrip", "PhiHit", "RHit", "NCluster","ClusterSize","ClusterCharge","MaxADC","ChargeAsy","CluChargeT","MaxADCT","ChargeAsyTrk","LandauN"};
21 //Log 0=linear 1=log
22 static const int l1dHist[N1dHist]={ 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0};
23 //Mode 0=4pad 6discs on a plot, 1=24pads for each quad
24 static const int m1dHist[N1dHist]={ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
25 //Fit 0=no fit show mean, 1=gaussian fit show rms, 2=landau fit, show peak
26 static const int f1dHist[N1dHist]={ 0, -1, -1, 0, 0, 2, 2, 1, 2, 2, 1, 2};
27 
28 //2d hists
29 static const char* c2dHist[N1dHist]={"XY","ADCvsTB","APVTB","XYT","APVTB2"};
30 
31 //Trk hists
32 static const char* cTrkHist[NTrkHist]={"NTrk","NHitTrk","DCA","ZVTX","Chi2","HitDisc"};
33 static const int lTrkHist[NTrkHist]={ 1, 1, 0, 0, 0, 0};
34 
35 static const int color[kFgtNumDiscs]={46,2,8,4,6,9};
36 static const int colorQuad[kFgtNumDiscs]={2,8,4,6};
37 
38 TCanvas *c1;
39 static TFile* file;
40 static int runnum, yearday, png, pdf;
41 
42 float mPeakC[kFgtNumDiscs][kFgtNumQuads];
43 float mPeakA[kFgtNumDiscs][kFgtNumQuads];
44 float mFracA[kFgtNumDiscs][kFgtNumQuads];
45 float mPeakL[kFgtNumDiscs][kFgtNumQuads];
46 
47 void colortable(){
48  static const UInt_t Number = 3;
49  Double_t Red[Number] = { 0.00, 0.00, 1.00};
50  Double_t Green[Number] = { 0.00, 1.00, 0.00};
51  Double_t Blue[Number] = { 1.00, 0.00, 0.00};
52  Double_t Length[Number] = { 0.00, 0.50, 1.00 };
53  Int_t nb=200;
54  TColor::CreateGradientColorTable(Number,Length,Red,Green,Blue,nb);
55 }
56 
57 void save(char* name){
58  char fname[100];
59  if(png){
60  if(yearday==0){
61  sprintf(fname,"plot/%d_%s.png",runnum,name);
62  }else{
63  sprintf(fname,"%d/%d_%s.png",yearday,runnum,name);
64  }
65  c1->SaveAs(fname);
66  }
67 }
68 
69 void plot1d(int hid) {
70  gStyle->SetOptStat(0);
71  char c[50];
72  c1->Clear();
73  if(m1dHist[hid]==0){
74  c1->Divide(2,2);
75  for(int quad=0; quad<kFgtNumQuads; quad++){
76  TVirtualPad* pad1 = c1->cd(quad+1);
77  pad1->SetLogy(l1dHist[hid]);
78  double xmin, xmax, ymin=0.0, ymax=0.0;
79  if(l1dHist[hid]==1) ymin=0.1;
80  for(int disc=0; disc<kFgtNumDiscs; disc++){
81  sprintf(c,"%1d%1s-%s",disc+1,cquad[quad],c1dHist[hid]);
82  //printf("Getting %s\n",c);
83  TH1F *h = hist1[disc][quad][hid] = (TH1F*)file->Get(c);
84  xmin=h->GetXaxis()->GetXmin();
85  xmax=h->GetXaxis()->GetXmax();
86  double m=h->GetMaximum();
87  if(ymax<m) ymax=m;
88  printf("disc=%d max=%6.1f ymax=%6.1f xmin=%6.1f xmax=%6.1f\n",disc+1,m,ymax,xmin,xmax);
89  }
90  sprintf(c,"Quad%1s-%s",cquad[quad],c1dHist[hid]);
91  TH2F *frame = new TH2F(c,c,1,xmin,xmax,1,ymin,ymax*1.2); frame->SetStats(0); frame->Draw();
92  for(int disc=0; disc<kFgtNumDiscs; disc++){
93  TH1F *h=hist1[disc][quad][hid];
94  h->SetLineColor(color[disc]); h->SetLineWidth(3); h->Draw("SAME");
95  if(f1dHist[hid]==0){
96  float mean=h->GetMean();
97  sprintf(c,"%1d%s mean=%6.2f",disc+1,cquad[quad],mean);
98  }else if(f1dHist[hid]==1){
99  int res = h->Fit("gaus","0Q");
100  TF1 *f = h->GetFunction("gaus");
101  float sig = f->GetParameter(2);
102  if(res==0 && sig>0.0001 && h->GetEntries()>5){
103  f->SetLineColor(color[disc]); f->SetLineWidth(2); f->Draw("SAME");
104  sprintf(c,"%1d%s sig=%6.3f",disc+1,cquad[quad],sig);
105  }else{
106  sprintf(c,"%1d%s",disc+1,cquad[quad]);
107  }
108  }else if(f1dHist[hid]==2){
109  int res = h->Fit("landau","0Q");
110  TF1 *f = h->GetFunction("landau");
111  float peak = f->GetParameter(1);
112  if(res==0 && peak>0 && h->GetEntries()>5){
113  f->SetLineColor(color[disc]); f->SetLineWidth(2); f->Draw("SAME");
114  sprintf(c,"%1d%s mpv=%6.0f",disc+1,cquad[quad],peak);
115  }else{
116  sprintf(c,"%1d%s",disc+1,cquad[quad]);
117  }
118  }
119  TText *t1;
120  float x1= 0.2, x2= 0.55;
121  float y1=0.8 - 0.07*disc;
122  float y2=0.8 - 0.07*(disc-3);
123  if(disc<3) { t1 = new TText(x1,y1,c); }
124  else { t1 = new TText(x2,y2,c); }
125  t1->SetNDC();
126  t1->SetTextSize(0.04);
127  t1->SetTextColor(color[disc]);
128  t1->Draw();
129  }
130  }
131  }else{
132  c1->Divide(4,6);
133  gStyle->SetOptStat(0);
134  gStyle->SetOptTitle(0);
135  gStyle->SetOptFit(0);
136  for(int disc=0; disc<kFgtNumDiscs; disc++){
137  for(int quad=0; quad<kFgtNumQuads; quad++){
138  TPad* pad = c1->cd(disc*4+quad+1);
139  pad->SetRightMargin(0.01); pad->SetLeftMargin(0.1);
140  pad->SetTopMargin(0.01); pad->SetBottomMargin(0.1);
141  pad->SetLogy(l1dHist[hid]);
142  sprintf(c,"%1d%1s-%s",disc+1,cquad[quad],c1dHist[hid]);
143  TH1F *h = hist1[disc][quad][hid] = (TH1F*)file->Get(c);
144  h->SetFillColor(color[disc]);
145  h->GetXaxis()->SetLabelSize(0.1);
146  h->GetYaxis()->SetLabelSize(0.1);
147  h->GetXaxis()->SetNdivisions(205);
148  h->Draw();
149 
150  if(f1dHist[hid]==0){
151  float mean=h->GetMean();
152  sprintf(c,"%1d%s mean=%6.2f",disc+1,cquad[quad],mean);
153  }else if(f1dHist[hid]==1){
154  int res = h->Fit("gaus","0Q");
155  TF1 *f = h->GetFunction("gaus");
156  float sig = f->GetParameter(2);
157  if(res==0 && sig>0.0001 && h->GetEntries()>5){
158  f->SetLineColor(color[disc]); f->SetLineWidth(2); f->Draw("SAME");
159  sprintf(c,"%1d%s sig=%6.3f",disc+1,cquad[quad],sig);
160  }else{
161  sprintf(c,"%1d%s",disc+1,cquad[quad]);
162  }
163  }else if(f1dHist[hid]==2){
164  int res = h->Fit("landau","0Q");
165  TF1 *f = h->GetFunction("landau");
166  float peak = f->GetParameter(1);
167  if(res==0 && peak>0 && h->GetEntries()>5){
168  f->SetLineColor(1); f->SetLineWidth(2); f->Draw("SAME");
169  sprintf(c,"%1d%s mpv=%6.0f",disc+1,cquad[quad],peak);
170  }else{
171  sprintf(c,"%1d%s",disc+1,cquad[quad]);
172  }
173  if(hid==8) {mPeakC[disc][quad]=peak;}
174  if(hid==9) {
175  mPeakA[disc][quad]=peak;
176  int n=h->GetEntries();
177  if(n>0){
178  float cut=2800;
179  int bin=h->FindBin(cut);
180  int nbin=h->GetNbinsX();
181  float sat=h->Integral(bin,nbin+1);
182  //printf("bin=%d nbin=%d sat=%f\n",bin,nbin,sat);
183  mFracA[disc][quad]=sat/float(n);
184  }
185  }
186  if(hid==11) {mPeakL[disc][quad]=peak;} // printf("LandauPeak=%f\n",peak);}
187  }
188  TText *t1 = new TText(0.3,0.85,c);
189  t1->SetNDC();
190  t1->SetTextSize(0.15);
191  t1->SetTextColor(color[disc]);
192  t1->Draw();
193  }
194  }
195  }
196  c1->Update();
197  save(c1dHist[hid]);
198 }
199 
200 void plot2d(int hid) {
201  gStyle->SetOptStat(0);
202  char c[50];
203  c1->Clear();
204  if(hid!=2 && hid!=4){
205  c1->Divide(2,3);
206  for(int disc=0; disc<kFgtNumDiscs; disc++){
207  TPad *pad = c1->cd(disc+1);
208  pad->SetLogz(1);
209  pad->SetTopMargin(0.01); pad->SetBottomMargin(0.02);
210  sprintf(c,"Disc%1d%s",disc+1,c2dHist[hid]);
211  //printf("Getting %s\n",c);
212  TH2F *h = hist2[disc][hid] = (TH2F*)file->Get(c);
213  h->Draw("COLZ");
214  }
215  }else if(hid==2){ // special case for timing per APVboard
216  gStyle->SetOptTitle(0);
217  gStyle->SetOptFit(0);
218  c1->Divide(2,1);
219  char txt[100];
220  //int disc=3; char name[100]="MaxAdc";
221  int disc=4; char name[100]="LandauMPV";
222  //int disc=5; char name[100]="LandauMPV-3Sing";
223  TVirtualPad *pad2 = c1->cd(1);
224  pad2->Divide(1,2);
225  TVirtualPad *pad3=pad2->cd(1);
226  pad3->SetLogz(1); pad2->SetLogz(0);
227  sprintf(c,"Disc%1d%s",disc,c2dHist[hid]);
228  TH2F *h = hist2[disc][hid] = (TH2F*)file->Get(c);
229  h->Draw("COLZ");
230  TText *tt1= new TText(0.05,0.1,"(RDO-1)*12+ARM*2+GRP"); tt1->SetTextAngle(90); tt1->SetNDC(); tt1->Draw();
231  sprintf(txt,"Tbin for %s",name);
232  TText *tt2= new TText(0.3,0,txt); tt2->SetNDC(); tt2->Draw();
233 
234  TVirtualPad* pad4 = c1->cd(2);
235  pad4->SetTopMargin(0.01); pad4->SetBottomMargin(0.1);
236  int maxid=0;
237  float off,max=0;
238  TH1D *h1[24];
239  float mean[24];
240  for(int i=0; i<24; i++){
241  char ccc[10]; sprintf(ccc,"_%d_%d",disc,i);
242  h1[i] = h->ProjectionX(ccc,i+1,i+1);
243  if(h1[i]->GetMaximum() > max && i!=0) {max=h1[i]->GetMaximum(); maxid=i; }
244  }
245  off=max/4.0;
246  printf("max=%f off=%f\n",max,off);
247  for(int i=0; i<24; i++){
248  h1[i]->GetXaxis()->SetRangeUser(2,11);
249  int res = h1[i]->Fit("gaus","0Q");
250  TF1* f=h1[i]->GetFunction("gaus");
251  if(h1[i]->GetMaximum()>max/3 && res==0){
252  mean[i] = f->GetParameter(1);
253  //mean[i]=h1[i]->GetMean();
254  }else{mean[i]=0;};
255  //printf("%d mean=%f\n",i,mean[i]);
256  }
257  //h1[maxid]->SetLineColor(maxid+1); h1[maxid]->SetLineWidth(2); h1[maxid]->Draw("PL");
258  for(int rdo=1; rdo<=2; rdo++){
259  for(int arm=0; arm<6; arm++){
260  for(int grp=0; grp<2; grp++){
261  i=(rdo-1)*12+arm*2+grp;
262  int nb=h1[i]->GetNbinsX();
263  for(int t=0; t<nb; t++){ h1[i]->AddBinContent(t+1,off*i); }
264  h1[i]->SetLineColor(i%6+1); h1[i]->SetLineWidth(3);
265  if(i==0) {
266  h1[i]->SetMinimum(0);
267  h1[i]->SetMaximum(max*6.5);
268  h1[i]->Draw("PL");
269  } else {h1[i]->Draw("PL same");}
270  char name[100];
271  sprintf(name,"Rdo%1dArm%1dGrp%1d",rdo,arm,grp);
272  TText *tx = new TText(8.5,(max/4.0)*(i+0.2),name); tx->SetTextColor(i%6+1); tx->SetTextSize(0.03);
273  tx->Draw();
274  }
275  }
276  }
277  // TText *tt3= new TText(0.95,0.1,"offsets added by (RDO-1)*12+ARM*2+GRP"); tt3->SetTextAngle(90); tt3->SetNDC(); tt3->Draw();
278  TText *tt4= new TText(0.4,0,txt); tt4->SetNDC(); tt4->Draw();
279 
280  //correlation
281  float t2[24]={-8.47, -5.16, -0.21, -2.23, 1.11, -4.09,
282  -3.13, -9.08, -5.88, -7.01, -6.22, -9.79,
283  0.75, -8.91, 0.16, 1.12, -0.99, -4.56,
284  7.57, -3.68, 7.12, -6.54, -4.08, -8.21};
285  TGraph *g= new TGraph(1);
286  int j=0;
287  for(int i=0; i<24; i++){
288  if(mean[i]>0) {g->SetPoint(j,(mean[i]-6.0)*27,t2[i]); j++;}
289  }
290  TVirtualPad* pad5=pad2->cd(2);
291  g->SetMarkerStyle(20+i/6); g->SetMarkerSize(1);
292  g->Draw("ap");
293  for(int i=0; i<24; i++){
294  TGraph *g2= new TGraph(1);
295  if(mean[i]>0) {g2->SetPoint(j,(mean[i]-6.0)*27,t2[i]); j++;}
296  g2->SetMarkerStyle(20+i/6); g2->SetMarkerSize(2); g2->SetMarkerColor(i%6+1);
297  g2->Draw("p");
298  }
299 
300  TText *tt5= new TText(0.05,0.1,"(VPHASE_ADC-1.2V)/0.95V*27nsec/2"); tt5->SetTextAngle(90); tt5->SetNDC(); tt5->Draw();
301  TText *tt6= new TText(0.5,0,"(Tbin-6)*27nsec"); tt6->SetNDC(); tt6->Draw();
302  }else{ // special case for timing per APVboard
303  gStyle->SetOptTitle(0);
304  gStyle->SetOptFit(0);
305  c1->Divide(4,6);
306  char txt[100];
307  //int disc=3; char name[100]="MaxAdc";
308  int disc=4; char name[100]="LandauMPV";
309  //int disc=5; char name[100]="LandauMPV-3Sing";
310  sprintf(c,"Disc%1d%s",disc,c2dHist[2]);
311  TH2F *h = hist2[disc][2] = (TH2F*)file->Get(c);
312  TH1D *h1[24];
313  float mean[24];
314  for(int rdo=1; rdo<=2; rdo++){
315  for(int arm=0; arm<6; arm++){
316  for(int grp=0; grp<2; grp++){
317  int i=(rdo-1)*12+arm*2+grp;
318  TVirtualPad *pad2 = c1->cd(i+1);
319  pad2->SetTopMargin(0.01); pad2->SetBottomMargin(0.1);
320  char ccc[10]; sprintf(ccc,"_%d_%d",disc,i);
321  h1[i]=h->ProjectionX(ccc,i+1,i+1);
322  h1[i]->GetXaxis()->SetRangeUser(2,12); h1[i]->SetFillColor(4);
323  h1[i]->GetXaxis()->SetLabelSize(0.1); h1[i]->GetYaxis()->SetLabelSize(0.1);
324  h1[i]->Draw();
325  int res = h1[i]->Fit("gaus","Q");
326  TF1* f=h1[i]->GetFunction("gaus"); f->SetLineColor(2); f->SetLineWidth(2);
327  if(res==0){
328  mean[i] = f->GetParameter(1);
329  }else{mean[i]=0;};
330  char name[100];
331  sprintf(name,"Rdo%1dArm%1d-%1d",rdo,arm,grp);
332  TText *tx = new TText(0.5,0.85,name); tx->SetTextSize(0.1); tx->SetNDC();
333  tx->Draw();
334  if(mean[i]>0){
335  sprintf(name,"peak=%4.1f",mean[i]);
336  TText *tx2 = new TText(0.55,0.75,name); tx2->SetTextSize(0.12); tx2->SetNDC();
337  tx2->Draw();
338  }
339  }
340  }
341  }
342  }
343  c1->Update();
344  save(c2dHist[hid]);
345 }
346 
347 void plotTrk() {
348  gStyle->SetOptStat(0);
349  gStyle->SetOptTitle(1);
350  char c[50];
351  c1->Clear();
352  c1->Divide(2,3);
353  for(int hid=0; hid<6; hid++){
354  TVirtualPad* pad = c1->cd(hid+1);
355  pad->SetLogy(lTrkHist[hid]);
356  double xmin, xmax, ymin=0.0, ymax=0.0;
357  if(lTrkHist[hid]==1) ymin=0.1;
358  for(int quad=0; quad<kFgtNumQuads; quad++){
359  sprintf(c,"Quad%1s-%s",cquad[quad],cTrkHist[hid]);
360  //printf("Getting %s\n",c);
361  TH1F *h = histTrk[quad][hid] = (TH1F*)file->Get(c);
362  xmin=h->GetXaxis()->GetXmin();
363  xmax=h->GetXaxis()->GetXmax();
364  double m=h->GetMaximum();
365  if(ymax<m) ymax=m;
366  //printf("quad=%d max=%6.1f ymax=%6.1f xmin=%6.1f xmax=%6.1f\n",quad,m,ymax,xmin,xmax);
367  }
368  ymax*=1.2; if(lTrkHist[hid]==1){ymax*=20.0;}
369  sprintf(c,"%s",cTrkHist[hid]);
370  TH2F *frame = new TH2F(c,c,1,xmin,xmax,1,ymin,ymax); frame->SetStats(0); frame->Draw();
371  for(int quad=0; quad<kFgtNumQuads; quad++){
372  TH1F *h=histTrk[quad][hid];
373  h->SetLineColor(colorQuad[quad]); h->SetLineWidth(3);
374  if(hid<5){
375  h->Draw("SAME");
376  float mean=h->GetMean();
377  if(hid==1 || hid==4) {sprintf(c,"%s mean=%6.4f",cquad[quad],mean);}
378  else {sprintf(c,"%s mean=%6.2f",cquad[quad],mean);}
379  }else{
380  h->SetMarkerColor(colorQuad[quad]); h->SetMarkerStyle(20); h->SetMarkerSize(1);
381  h->Draw("SAME PL");
382  sprintf(c,"Quad%s",cquad[quad]);
383  }
384  TText *t1;
385  float x1= 0.2, x2= 0.55;
386  float y1=0.8 - 0.07*quad;
387  float y2=0.8 - 0.07*(quad-2);
388  if(quad<2) { t1 = new TText(x1,y1,c); }
389  else { t1 = new TText(x2,y2,c); }
390  t1->SetNDC();
391  t1->SetTextSize(0.06);
392  t1->SetTextColor(colorQuad[quad]);
393  t1->Draw();
394  }
395  }
396  c1->Update();
397  save("trk");
398 }
399 
400 void makeqaplot(int run=0, int plt=0, int save=0){
401  runnum=run;
402  yearday=run/1000;
403  if(save==0) {png=0; pdf=0;}
404  if(save==1) {png=1; pdf=0;}
405  if(save==2) {png=0; pdf=1;}
406  if(save==3) {png=1; pdf=1;}
407 
408  c1 = new TCanvas("c1","QA",50,50,800,800);
409  gStyle->SetLabelSize(0.04,"xy");
410  //colortable();
411  gStyle->SetPalette(1);
412  gStyle->SetStatW(0.4);
413 
414  char fname[50];
415  if(run==0) {sprintf(fname,"fgtQA.root");}
416  else {sprintf(fname,"%d/fgtQA_%d.root",yearday,run);}
417 
418  cout << "Opening "<<fname<<endl;
419  file=new TFile(fname,"");
420 
421  char c[50];
422  if(plt==0 || plt==1) {
423  gStyle->SetOptStat(111110);
424  c1->Divide(1,3);
425  for(int i=0; i<3; i++){
426  TVirtualPad* pad = c1->cd(i+1);
427  int log=0;
428  if(i>0) {log=1;}
429  pad->SetLogy(log);
430  hist0[i]=(TH1F*) file->Get(cHist[i]);
431  hist0[i]->SetFillColor(kBlue);
432  hist0[i]->Draw();
433  if(i==2){
434  float ntot = float(hist0[i]->GetEntries());
435  if(ntot>0.0){
436  int nbin = hist0[i]->GetNbinsX();
437  float nofgt = hist0[i]->Integral(1,1);
438  int bin = hist0[i]->FindBin(float(kFgtNumElecIds));
439  float nonzs = hist0[i]->Integral(bin-1,nbin+1);
440  float zs = hist0[i]->Integral(2,bin-2);
441  hist0[i]->GetXaxis()->SetRange(2, bin-2);
442  float mean = hist0[i]->GetMean() / float(kFgtNumElecIds);
443  char c[100];
444  sprintf(c,"Total %d",ntot); TText *t1 = new TText(0.3,0.8,c); t1->SetNDC(); t1->SetTextSize(0.06); t1->Draw();
445  sprintf(c,"NoFGT %d (%5.2f)",nofgt,nofgt/ntot); TText *t2 = new TText(0.3,0.7,c); t2->SetNDC(); t2->SetTextSize(0.06); t2->Draw();
446  sprintf(c,"NoneZS %d (%5.2f)",nonzs,nonzs/ntot); TText *t3 = new TText(0.3,0.6,c); t3->SetNDC(); t3->SetTextSize(0.06); t3->Draw();
447  sprintf(c,"ZS %d (%5.2f)",zs,zs/ntot); TText *t4 = new TText(0.3,0.5,c); t4->SetNDC(); t4->SetTextSize(0.06); t4->Draw();
448  sprintf(c,"Mean ZS data size/fullsize= %5.3f",mean); TText *t5 = new TText(0.3,0.4,c); t5->SetNDC(); t5->SetTextSize(0.06); t5->Draw();
449  if(mean>0.08) { t5->SetTextColor(2); }
450  else { t5->SetTextColor(4); }
451  }
452  }
453  }
454  c1->Update();
455  save("plot");
456  }
457  if(plt==0 || plt==2) {
458  c1->Clear();
459  gStyle->SetOptStat(0);
460  gStyle->SetOptTitle(0);
461  c1->Divide(1,3);
462  for(int i=3; i<6; i++){ hist0[i]=(TH1F*) file->Get(cHist[i]); }
463  int nevt=hist0[5]->GetEntries();
464  printf("Nevent=%d\n",nevt);
465  TVirtualPad* pad;
466  pad=c1->cd(1); pad->SetLogy(); pad->SetTopMargin(0.01); pad->SetRightMargin(0.01);
467  hist0[3]->GetXaxis()->SetLabelSize(0.07); hist0[3]->GetYaxis()->SetLabelSize(0.07);
468  hist0[3]->SetFillColor(kRed); hist0[3]->Scale(1/float(nevt)); hist0[3]->Draw();
469  TText *tx= new TText(0.87,0.0,"EleID"); tx->SetNDC(); tx->SetTextSize(0.1); tx->Draw();
470  TText *t3= new TText(0.05,0.1,"F3=frac in 3sig/2tb"); t3->SetNDC(); t3->SetTextSize(0.08); t3->SetTextAngle(90); t3->Draw();
471 
472  pad=c1->cd(2); pad->SetLogy(); pad->SetTopMargin(0.01); pad->SetRightMargin(0.01);
473  hist0[4]->GetXaxis()->SetLabelSize(0.07); hist0[4]->GetYaxis()->SetLabelSize(0.07);
474  hist0[4]->SetFillColor(kBlue); hist0[4]->Scale(1/float(nevt)); hist0[4]->Draw();
475  tx->Draw();
476  TText *t4= new TText(0.05,0.1,"F10=frac in 10sig & >500"); t4->SetNDC(); t4->SetTextSize(0.08); t4->SetTextAngle(90); t4->Draw();
477 
478  float min=-4;
479  int max=hist0[3]->GetNbinsX();
480  printf("Max=%d\n",max);
481  TH1F *h1 = new TH1F("ZSdataFrac","ZSdataFrac",50,min,0);
482  TH1F *h2 = new TH1F("10SigmaFrac","10SigmaFrac",50,min,0);
483  float f1[kFgtNumElecIds],f2[kFgtNumElecIds];
484  for(int i=0; i<max; i++){
485  f1[i] = log10(hist0[3]->GetBinContent(i+1)); if(f1[i]<min) {f1[i]=min;} h1->Fill(f1[i]);
486  f2[i] = log10(hist0[4]->GetBinContent(i+1)); if(f2[i]<min) {f2[i]=min;} h2->Fill(f2[i]);
487  }
488  pad = c1->cd(3); pad->Divide(2,1);
489  TVirtualPad *pad2;
490  pad2 = pad->cd(1);
491  pad2->SetLogy(); pad2->SetTopMargin(0.01); pad2->SetRightMargin(0.01);
492  h1->GetXaxis()->SetLabelSize(0.1); h1->GetYaxis()->SetLabelSize(0.1);
493  h2->GetXaxis()->SetLabelSize(0.1); h2->GetYaxis()->SetLabelSize(0.1);
494  h1->SetLineColor(kRed); h2->SetLineColor(kBlue);
495  if(h1->GetMaximum()>h2->GetMaximum()){
496  h1->Draw(); h2->Draw("SAME");
497  }else{
498  h2->Draw(); h1->Draw("SAME");
499  }
500  TText *t5= new TText(0.2,0.88,"Log(F3)"); t5->SetNDC(); t5->SetTextSize(0.1); t5->SetTextColor(2); t5->Draw();
501  TText *t6= new TText(0.6,0.88,"Log(F10)"); t6->SetNDC(); t6->SetTextSize(0.1); t6->SetTextColor(4); t6->Draw();
502 
503  //read ped file
504  int eid, t;
505  float ped[kFgtNumElecIds],rms[kFgtNumElecIds],p,r;
506  int status[kFgtNumElecIds]; memset(status,0,sizeof(status));
507  cout<<"Reading Ped File "<<endl;
508  std::ifstream in("ped.txt");
509  if (!in.is_open()) {
510  cout << "Can't find file!\n";
511  exit(0);
512  }
513  while (!in.eof()){
514  in >> eid >> t >> p >> r;
515  ped[eid]=p;
516  rms[eid]=r;
517  }
518  in.close();
519  TH1F * hr1= new TH1F("RMS","RMS",60,0,120);
520  TH1F * hr2= new TH1F("RMS2","RMS2",60,0,120);
521  TH1F * hr3= new TH1F("RMS3","RMS3",60,0,120);
522  TH1F * hr4= new TH1F("RMS4","RMS4",60,0,120);
523  TH1F * hr5= new TH1F("RMS5","RMS5",60,0,120);
524  float f1l=-3.5, f1h=-0.5;
525  float f2l=-3.5, f2h=-1.2;
526  for(int i=0; i<kFgtNumElecIds; i++){
527  if(f1[i]<f1l) status[i]+=1;
528  if(f1[i]>f1h) status[i]+=2;
529  if(f1[i]<f2l) status[i]+=4;
530  if(f1[i]>f2h) status[i]+=8;
531  hr1->Fill(rms[i]);
532  if(f1[i]<f1l) {hr2->Fill(rms[i]);}
533  if(f1[i]<f1l || f1[i]>f1h) {hr3->Fill(rms[i]);}
534  if(f1[i]<f1l || f1[i]>f1h || f2[i]<f2l) {hr4->Fill(rms[i]);}
535  if(f1[i]<f1l || f1[i]>f1h || f2[i]<f2l || f2[i]>f2h) {hr5->Fill(rms[i]);}
536  }
537  char filename[150];
538  if(nevt>=1000){
539  sprintf(filename,"%d/status/status.%d.txt",yearday,run);
540  }else{
541  sprintf(filename,"%d/status/status.%d.lowstat.txt",yearday,run);
542  }
543  FILE* pfile=fopen(filename,"w");
544  if(!pfile){
545  printf("Couldn't open file %s\n",filename);
546  }else{
547  printf("Writing %s\n",filename);
548  for(int i=0; i<kFgtNumElecIds; i++){
549  fprintf(pfile,"%d 0x%d\n",i,status[i]);
550  }
551  fclose(pfile);
552  }
553 
554  pad2 = pad->cd(2);
555  pad2->SetLogy(0); pad2->SetTopMargin(0.01); pad2->SetRightMargin(0.01);
556  hr1->GetXaxis()->SetLabelSize(0.1); hr1->GetYaxis()->SetLabelSize(0.05);
557  hr1->SetFillColor(3); hr1->Draw();
558  hr5->SetFillColor(9); hr5->Draw("same");
559  hr4->SetFillColor(4); hr4->Draw("same");
560  hr3->SetFillColor(6); hr3->Draw("same");
561  hr2->SetFillColor(2); hr2->Draw("same");
562  char cc1[100]; sprintf(cc1,"Log(F3)<%4.1f",f1l);
563  char cc2[100]; sprintf(cc2,"Log(F3)>%4.1f",f1h);
564  char cc3[100]; sprintf(cc3,"Log(F10)<%4.1f",f2l);
565  char cc4[100]; sprintf(cc4,"Log(F10)>%4.1f",f2h);
566  TText *t7 = new TText(0.6,0.88,cc1); t7->SetNDC(); t7->SetTextSize(0.07); t7->SetTextColor(2); t7->Draw();
567  TText *t8 = new TText(0.6,0.78,cc2); t8->SetNDC(); t8->SetTextSize(0.07); t8->SetTextColor(6); t8->Draw();
568  TText *t9 = new TText(0.6,0.68,cc3); t9->SetNDC(); t9->SetTextSize(0.07); t9->SetTextColor(4); t9->Draw();
569  TText *t10= new TText(0.6,0.58,cc4); t10->SetNDC(); t10->SetTextSize(0.07); t10->SetTextColor(9); t10->Draw();
570  TText *t11= new TText(0.6,0.48,"OK"); t11->SetNDC(); t11->SetTextSize(0.07); t11->SetTextColor(3); t11->Draw();
571  TText *t12= new TText(0.8,0.15,"PedRMS"); t12->SetNDC(); t12->SetTextSize(0.07); t12->Draw();
572  c1->Update();
573  save("frac");
574  }
575  if(plt==0 || plt==3) {
576  c1->Clear();
577  c1->Divide(2,2);
578  gStyle->SetOptTitle(1);
579  gStyle->SetOptStat(111110);
580  for(int i=0; i<4; i++){
581  TVirtualPad* pad = c1->cd(i+1);
582  int log=0;
583  pad->SetLogy(log);
584  hist0[i+6]=(TH1F*) file->Get(cHist[i+6]);
585  hist0[i+6]->SetFillColor(kBlue);
586  hist0[i+6]->Draw();
587  }
588  c1->Update();
589  save("pfit");
590  }
591 
592  memset(mPeakC,0,sizeof(mPeakC));
593  memset(mPeakA,0,sizeof(mPeakA));
594  memset(mFracA,0,sizeof(mFracA));
595  memset(mPeakL,0,sizeof(mPeakL));
596  for(int i=0; i<N1dHist; i++) { if(plt==0 || plt==10+i) plot1d(i);}
597  for(int i=0; i<N2dHist; i++) { if(plt==0 || plt==50+i) plot2d(i);}
598  if(plt==0 || plt==60) plotTrk();
599 
600  if(plt==0){
601  char filename[100];
602  sprintf(filename,"%d/gain.%d.txt",yearday,run);
603  FILE* file=fopen(filename,"w");
604  if(!file){
605  printf("Couldn't open $file\n",filename);
606  }else{
607  printf("Writing %s\n",filename);
608  for(int i=0; i<kFgtNumDiscs; i++){
609  for(int j=0; j<kFgtNumQuads; j++){
610  fprintf(file,"%d %d %f %f %f %f\n",i,j,mPeakC[i][j],mPeakA[i][j],mFracA[i][j],mPeakL[i][j]);
611  }
612  }
613  fclose(file);
614  }
615  }
616 }