StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
plGainBprs.C
1 plGainBprs(int page=1, int box0=0) {
2  gStyle->SetOptStat(1110);
3  gStyle->SetOptFit(1);
4  gStyle->SetPalette(1,0);
5 
6  char *fnameO="calib-nov-21-2008/barrelMipSpectV6ok.hist.root";
7  fd=new TFile(fnameO); assert(fd->IsOpen());
8  printf("Read %s\n", fd->GetName());
9  //fd->ls();
10 
11  char *fname1="mipGainBprs+Btow_v6.hist.root";
12  fout=new TFile(fname1,"update"); assert(fout->IsOpen());
13  printf("Write output to %s\n", fout->GetName());
14 
15 
16  switch(page) {
17  case 1:
18  {
19  c=new TCanvas("aa","aa",1000,600); c->Divide(5,4);
20  int k=1;
21  for(int box=1; box<=4; box++)
22  for(int pmt=1;pmt<=5;pmt++)
23  { char tt[100];
24  sprintf(tt,"gainBPM%d_%d",box+box0,pmt);
25 
26  TH1F *h=fd->Get(tt);
27  if(h==0) { printf("missing=%s \n",tt); k++; continue;}
28  c->cd(k);
29  h->Draw(); h->SetMaximum(10);
30  k++;
31  }
32 
33  } break;
34  //........................
35  case 2: // BPRS
36  case 3: // BTOW
37  {
38  // QA of gains
39  float cut_minYield=20;
40  float cut_mpvRE=0.5; // relative error of MPV
41  float cut_mipL=1.5; // lowest acceptable MIP peak position
42  gStyle->SetOptStat(0);
43 
44  // setup for BPRS
45  TString tt1="bprsMipGain2D", tt3="bprsMipGain", tt4="bprsMipSig", tt5="bprsMipStat";
46  char *core1="bprs";
47  if(page==3) { // changes for BTOW
48  tt1="btowMipGain2D"; tt3="btowMipGain"; tt4="btowMipSig"; tt5="btowMipStat";
49  core1="btow";
50  }
51 
52  float gMax=30;
53  c=new TCanvas(tt1,tt1,1200,800);
54  h2g=new TH2F(tt1,tt1+" Z=MIP position(ADC); phiBin, X=1+(softID-1)/20 ; etaBin, Y=1+(softID-1)%20",240,0.5,240.5,20,0.5,20.5);
55  h1g=new TH1F(tt3,tt3+" ; softID; MIP ADC",4800,0.5,4800.5);
56  h1sig=new TH1F(tt4,tt4+"; softID; MIP sigma",4800,0.5,4800.5);
57  h1stat=new TH1F(tt5,tt5+"; softID; MIP status",4800,0.5,4800.5);
58  h1g->GetYaxis()->SetTitleSize(0.055);
59  h1sig->GetYaxis()->SetTitleSize(0.055);
60  h1stat->GetYaxis()->SetTitleSize(0.055);
61 
62  pad=new TPad("pad2", "apd2",0.0,0.7,1.,1.); pad->Draw();
63  pad->cd();h2g->Draw("colz"); h2g->SetMaximum(gMax); gPad->SetGrid();
64  if(page==3) markBtow2D();
65  if(page==2) markBprs2D();
66 
67  c->cd(); pad=new TPad("pad1", "apd1",0.0,0.0,1.,0.7); pad->Draw();
68  pad->Divide(1,2);
69  pad->cd(1);h1g->Draw(); if(page==2) markBprs1D();
70  pad->cd(2);h1sig->Draw();gPad->SetGrid(); if(page==2) markBprs1D();
71  //tmp pad->cd(3);h1stat->Draw(); gPad->SetGrid();if(page==2) markBprs1D();
72  //return;
73  //............. LOOP over towers ........
74  for(int id=1;id<=4800;id++) {
75  char txt[100];
76  sprintf(txt,"%s%dm",core1,id);
77  TH1F *h=fd->Get(txt);
78  if(h==0) { h1stat->Fill(id,1); printf("missing=%s \n",txt); continue;}
79  // h->Draw();
80  float yield=h->GetEntries();
81  if(yield<cut_minYield) {h1stat->Fill(id,2); printf(" low MIP yield=%s %d \n",txt,yield); continue;}
82 
83  TF1 *ff=h->GetFunction("gaus");
84  float mean=ff->GetParameter(1);
85  float meanE=ff->GetParError(1);
86  float sig=ff->GetParameter(2);
87  float mpvRE=fabs(meanE/mean);
88 
89  if( (mpvRE>cut_mpvRE) ||
90  (mean<1 || mean>40) ) {
91  mean=h->GetMean();
92  sig=h->GetRMS();
93  if(mean< cut_mipL || mean>40) { h1stat->Fill(id,4); printf(" too low2 MIP=%s %f\n",txt,mean); continue;}
94 
95  meanE=sig/sqrt(yield);
96  mpvRE=fabs(meanE/mean);
97  printf(" %s bad fit, use mean/RMS\n", txt);
98  }
99  if( mpvRE>cut_mpvRE) { h1stat->Fill(id,8); printf(" bad mpvRE=%s %f\n",txt,mpvRE); continue;}
100  printf("id=%d yield=%d MIP=%.1f +/- %.1f\n",id,yield, mean,sig);
101  int ix=1+(id-1)/20;
102  int iy=1+(id-1)%20;
103  h2g->Fill(ix,iy,mean);
104  h1g->SetBinContent(id,mean);
105  h1g->SetBinError(id,meanE);
106  h1sig->SetBinContent(id,sig);
107  }
108  int nKill=(int) h1stat->GetEntries();
109  tt5="nKilled="; tt5+=nKill; tx=new TText(-500,26,tt5); tx->Draw(); tx->SetTextSize(0.08);tx->SetTextColor(kRed);
110 
111  fout->cd();
112  h2g->Write();
113  h1g->Write();
114  h1sig->Write();
115  h1stat->Write();
116 
117  } break;
118  //........................
119  default:
120  } // case END
121 }
122 
123 
124 //-----------------------
125 void markBtow2D() {
126  lnEW=new TLine(120.5,0, 120.5,23); lnEW->Draw(); lnEW->SetLineColor(kBlue);
127  tx=new TText(100,21.7,"West"); tx->Draw(); tx->SetTextColor(kBlue);
128  tx=new TText(140,21.7,"East"); tx->Draw(); tx->SetTextColor(kBlue);
129 
130  tx=new TText(-5,-1.5,"module=1"); tx->Draw(); tx->SetTextColor(kBlue);
131  tx=new TText(108,-1.5,"module=60,61"); tx->Draw(); tx->SetTextColor(kBlue);
132  tx=new TText(240,-1.5,"module=120"); tx->Draw(); tx->SetTextColor(kBlue);
133 }
134 //-----------------------
135 void markBprs2D() {
136  lnEW=new TLine(120.5,-2, 120.5,23); lnEW->Draw(); lnEW->SetLineColor(kBlue);
137  tx=new TText(100,21.7,"West"); tx->Draw(); tx->SetTextColor(kBlue);
138  tx=new TText(140,21.7,"East"); tx->Draw(); tx->SetTextColor(kBlue);
139 
140  lnEW=new TLine(17.5,-2, 17.5,21); lnEW->Draw(); lnEW->SetLineColor(kBlue);
141  lnEW=new TLine(77.5,-2, 77.5,21); lnEW->Draw(); lnEW->SetLineColor(kBlue);
142 
143  lnEW=new TLine(145.5,-2, 145.5,21); lnEW->Draw(); lnEW->SetLineColor(kBlue);
144  lnEW=new TLine(205.5,-2, 205.5,21); lnEW->Draw(); lnEW->SetLineColor(kBlue);
145 
146  tx=new TText(1,-1.5,"PSD-1W"); tx->Draw(); tx->SetTextColor(kBlue);
147  tx=new TText(80,-1.5,"PSD-1W"); tx->Draw(); tx->SetTextColor(kBlue);
148  tx=new TText(40,-1.5,"PSD-19W"); tx->Draw(); tx->SetTextColor(kBlue);
149 
150  tx=new TText(206,-0.5,"PSD-1E"); tx->Draw(); tx->SetTextColor(kBlue);
151  tx=new TText(130,-1.5,"PSD-1E"); tx->Draw(); tx->SetTextColor(kBlue);
152  tx=new TText(180,-1.5,"PSD-20E"); tx->Draw(); tx->SetTextColor(kBlue);
153 
154 }
155 
156 //-----------------------
157 void markBprs1D() {
158  float y=500;
159  lnEW=new TLine(2400,-2, 2400,y); lnEW->Draw(); lnEW->SetLineColor(kBlue);
160  // tx=new TText(100,21.7,"West"); tx->Draw(); tx->SetTextColor(kBlue);
161  // tx=new TText(140,21.7,"East"); tx->Draw(); tx->SetTextColor(kBlue);
162 
163  lnEW=new TLine(340,0,340,y); lnEW->Draw(); lnEW->SetLineColor(kBlue);
164  lnEW=new TLine(1540,0,1540,y); lnEW->Draw(); lnEW->SetLineColor(kBlue);
165 
166  lnEW=new TLine(2900,0,2900,y); lnEW->Draw(); lnEW->SetLineColor(kBlue);
167  lnEW=new TLine(4100,0,4100,y); lnEW->Draw(); lnEW->SetLineColor(kBlue);
168 
169  tx=new TText(10,-2,"PSD-1W"); tx->Draw(); tx->SetTextColor(kBlue);
170  tx=new TText(1600,-2,"PSD-1W"); tx->Draw(); tx->SetTextColor(kBlue);
171  tx=new TText(1000,-2,"PSD-19W"); tx->Draw(); tx->SetTextColor(kBlue);
172 
173  tx=new TText(2600,-2,"PSD-1E"); tx->Draw(); tx->SetTextColor(kBlue);
174  tx=new TText(3200,-2.,"PSD-1E"); tx->Draw(); tx->SetTextColor(kBlue);
175  tx=new TText(4200,-2.,"PSD-20E"); tx->Draw(); tx->SetTextColor(kBlue);
176 
177 }