StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
makepedplot.C
1 #include <iomanip>
2 #include "fgtPedestal.h"
3 
4 static const int MAX=2*6*20*128;
5 static const float markerSize=0.38;
6 
7 makepedplot(int run, int statonly=0, int comp=0){
8  char filename[100];
9  float ped[MAX],rms[MAX],frac[MAX],p,r,f;
10  float ped2[MAX],rms2[MAX];
11  int eleId[MAX],status[MAX],eid,s,t,i;
12  TString statread;
13 
14  int day=run/1000;
15  if(run>0 && statonly==0){
16  sprintf(filename,"%d/ped/ped.%d.txt",day,run);
17  }else{
18  sprintf(filename,"ped.txt");
19  }
20  cout<<"Reading File "<<filename<<endl;
21  std::ifstream in(filename);
22  if (!in.is_open()) {
23  cout << "Can't find file!\n";
24  exit(0);
25  }
26  while (!in.eof()){
27  // in >> eid >> t >> p >> r >> f;
28  in >> eid >> t >> p >> r;
29  eleId[eid]=eid;
30  ped[eid]=p;
31  rms[eid]=r;
32  //frac[eid]=f;
33  //printf("%5d %6.1f %6.1f\n",eid,ped[eid],rms[eid]);
34  }
35  in.close();
36 
37  if(run>0){
38  sprintf(filename,"%d/status/status.%d.txt",day,run);
39  }else{
40  sprintf(filename,"status.txt");
41  }
42  cout<<"Reading File "<<filename<<endl;
43  std::ifstream in2(filename);
44  if (!in2.is_open()) {
45  cout << "Can't find file!\n";
46  exit(0);
47  }
48  while (!in2.eof()){
49  in2 >> eid >> statread;
50  statread.Remove(0,2);
51  status[eid] = statread.Atoi();
52  //printf("%5d %4d\n",eid,status[eid]);
53  }
54  in2.close();
55 
56  if(comp==2){
57  memset(ped2,0,sizeof(ped2));
58  memset(rms2,0,sizeof(rms2));
59  TH1F * hd = new TH1F("PED Offline-Tonko","PED Offline-Tonko",50,-30,30);
60  TH1F * he = new TH1F("RMS Offline-Tonko","RMS Offline-Tonko",50,-30,30);
61  TGraph * de=new TGraphErrors();
62  TGraph * dp=new TGraphErrors();
63  cout<<"Reading File fgt_pedestals.txt"<<endl;
64  std::ifstream in3("fgt_pedestals.txt");
65  if (!in3.is_open()) {
66  cout << "Can't find file!\n";
67  exit(0);
68  }
69  int rdo,arm,apv,ch,t;
70  while (!in3.eof()){
71  in3 >> rdo >> arm >> apv >> ch >> t >> p >> r;
72  if(apv>9) apv-=2;
73  eid=(rdo-1)*6*20*128 + arm*20*128 + apv*128 + ch;
74  ped2[eid]+=p/15.0;
75  rms2[eid]+=r/15.0;
76  }
77  in3.close();
78  int j=0;
79  for(int i=0; i<MAX; i++){
80  float d=ped[i]-ped2[i]; hd->Fill(d);
81  float e=rms[i]-rms2[i]; he->Fill(e);
82  if(fabs(d)<50){
83  de->SetPoint(j,float(i),d);
84  dp->SetPoint(j,ped[i],d);
85  j++;
86  }
87  // printf("%6d %8.2f %8.2f %8.2f %8.2f %8.2f%8.2f\n",i,ped[i],ped2[i],d,rms[i],rms2[i],e);
88  }
89  TCanvas * c1 = new TCanvas("ped","ped",50,0,800,800);
90  c1->Divide(2,2);
91  gStyle->SetOptStat(1111110);
92  c1->cd(1); hd->Draw();
93  c1->cd(2); he->Draw();
94  de->GetHistogram()->SetTitle("PED:Offline-Tonko:Id");
95  dp->GetHistogram()->SetTitle("PED:Offline-Tonko:Ped");
96  c1->cd(3); de->SetMarkerStyle(22); de->SetMarkerSize(markerSize); de->Draw("AP");
97  c1->cd(4); dp->SetMarkerStyle(22); dp->SetMarkerSize(markerSize); dp->Draw("AP");
98  return;
99  }
100 
101  TGraph * gped=new TGraphErrors();
102  TGraph * grms=new TGraphErrors();
103  TGraph * bped=new TGraphErrors();
104  TGraph * brms=new TGraphErrors();
105  TGraph * gcor=new TGraphErrors();
106  TGraph * bcor=new TGraphErrors();
107  TH1F * hgped = new TH1F("PED" , "PED", 100,0,2000);
108  TH1F * hbped = new TH1F("PEDb", "PEDb", 100,0,2000);
109  TH1F * hgrms = new TH1F("RMS", "RMS", 100,0,120);
110  TH1F * hbrms = new TH1F("RNSb", "RMSb", 100,0,120);
111  //TH1F * hgfrac= new TH1F("Frac", "Frac", 100,0,1);
112  //TH1F * hbfrac= new TH1F("Fracb","Fracb",100,0,1);
113  int g=0, b=0, a=0;
114  for(eid=0; eid<MAX; eid++){
115  if(status[eid]==0) {
116  gped->SetPoint(g,float(eid),ped[eid]);
117  grms->SetPoint(g,float(eid),rms[eid]);
118  gcor->SetPoint(g,ped[eid],rms[eid]);
119  hgped->Fill(ped[eid]);
120  hgrms->Fill(rms[eid]);
121  //hgfrac->Fill(frac[eid]);
122  g++;
123  }else{
124  bped->SetPoint(b,float(eid),ped[eid]);
125  brms->SetPoint(b,float(eid),rms[eid]);
126  bcor->SetPoint(b,ped[eid],rms[eid]);
127  hbped->Fill(ped[eid]);
128  hbrms->Fill(rms[eid]);
129  //hbfrac->Fill(frac[eid]);
130  b++;
131  }
132  a++;
133  }
134  printf("Status Good=%5d Bad=%5d",g,b);
135 
136  TCanvas * c1 = new TCanvas("ped","ped",0,0,1200,800);
137  c1->Divide(1,3);
138 
139  c1->cd(1);
140  gped->GetHistogram()->SetTitle("Pedestals;ElecId;ADC");
141  gped->SetMinimum(0); gped->SetMaximum(1500); gped->GetXaxis()->SetRangeUser(0,float(MAX+1));
142  gped->SetMarkerStyle(21); gped->SetMarkerSize(markerSize); gped->SetMarkerColor(kBlue); gped->SetLineColor(kBlue);
143  gped->Draw("AP");
144  bped->SetMarkerStyle(22); bped->SetMarkerSize(markerSize); bped->SetMarkerColor(kRed); bped->SetLineColor(kRed);
145  bped->Draw("P");
146 
147  c1->cd(2);
148  grms->GetHistogram()->SetTitle("PedRMS;ElecId;ADC");
149  grms->SetMinimum(0); grms->SetMaximum(200); grms->GetXaxis()->SetRangeUser(0,float(MAX+1));
150  grms->SetMarkerStyle(21); grms->SetMarkerSize(markerSize); grms->SetMarkerColor(kBlue); grms->SetLineColor(kBlue);
151  grms->Draw("AP");
152  brms->SetMarkerStyle(22); brms->SetMarkerSize(markerSize); brms->SetMarkerColor(kRed); brms->SetLineColor(kRed);
153  brms->Draw("P");
154 
155  const char c[200]; Double_t x=500, y=160;
156  sprintf(c,"Status Good=%d Bad=%d R(Bad/Total)=%5.2f",g,b,float(b)/float(a));
157  TText* t1=new TText(x,y,c); t1->SetTextSize(0.1); t1->Draw();
158 
159  c1->cd(3); gPad->Divide(3,1);
160 
161  c1->cd(3); gPad->cd(1);
162  gcor->GetHistogram()->SetTitle("PEDvsRMS;PED;RMS");
163  gcor->SetMinimum(0); gcor->SetMaximum(150); gcor->GetXaxis()->SetRangeUser(0,1200);
164  gcor->SetMarkerStyle(21); gcor->SetMarkerSize(markerSize); gcor->SetMarkerColor(kBlue); gcor->SetLineColor(kBlue);
165  gcor->Draw("AP");
166  bcor->SetMarkerStyle(22); bcor->SetMarkerSize(markerSize); bcor->SetMarkerColor(kRed); bcor->SetLineColor(kRed);
167  bcor->Draw("P");
168 
169  c1->cd(3); gPad->cd(2); gPad->SetLogy(); hgped->SetFillColor(kBlue); hgped->Draw(); hbped->SetFillColor(kRed); hbped->Draw("same");
170  c1->cd(3); gPad->cd(3); gPad->SetLogy(); hgrms->SetFillColor(kBlue); hgrms->Draw(); hbrms->SetFillColor(kRed); hbrms->Draw("same");
171  //c1->cd(3); gPad->cd(4); gPad->SetLogy(); hgfrac->SetFillColor(kBlue); hgfrac->Draw(); hbfrac->SetFillColor(kRed); hbfrac->Draw("same");
172 
173  c1->Update();
174 
175  sprintf(filename,"%d/%d_ped.png",day,run);
176  c1->SaveAs(filename);
177 }