00001 plGainBprs(int page=1, int box0=0) {
00002 gStyle->SetOptStat(1110);
00003 gStyle->SetOptFit(1);
00004 gStyle->SetPalette(1,0);
00005
00006 char *fnameO="calib-nov-21-2008/barrelMipSpectV6ok.hist.root";
00007 fd=new TFile(fnameO); assert(fd->IsOpen());
00008 printf("Read %s\n", fd->GetName());
00009
00010
00011 char *fname1="mipGainBprs+Btow_v6.hist.root";
00012 fout=new TFile(fname1,"update"); assert(fout->IsOpen());
00013 printf("Write output to %s\n", fout->GetName());
00014
00015
00016 switch(page) {
00017 case 1:
00018 {
00019 c=new TCanvas("aa","aa",1000,600); c->Divide(5,4);
00020 int k=1;
00021 for(int box=1; box<=4; box++)
00022 for(int pmt=1;pmt<=5;pmt++)
00023 { char tt[100];
00024 sprintf(tt,"gainBPM%d_%d",box+box0,pmt);
00025
00026 TH1F *h=fd->Get(tt);
00027 if(h==0) { printf("missing=%s \n",tt); k++; continue;}
00028 c->cd(k);
00029 h->Draw(); h->SetMaximum(10);
00030 k++;
00031 }
00032
00033 } break;
00034
00035 case 2:
00036 case 3:
00037 {
00038
00039 float cut_minYield=20;
00040 float cut_mpvRE=0.5;
00041 float cut_mipL=1.5;
00042 gStyle->SetOptStat(0);
00043
00044
00045 TString tt1="bprsMipGain2D", tt3="bprsMipGain", tt4="bprsMipSig", tt5="bprsMipStat";
00046 char *core1="bprs";
00047 if(page==3) {
00048 tt1="btowMipGain2D"; tt3="btowMipGain"; tt4="btowMipSig"; tt5="btowMipStat";
00049 core1="btow";
00050 }
00051
00052 float gMax=30;
00053 c=new TCanvas(tt1,tt1,1200,800);
00054 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);
00055 h1g=new TH1F(tt3,tt3+" ; softID; MIP ADC",4800,0.5,4800.5);
00056 h1sig=new TH1F(tt4,tt4+"; softID; MIP sigma",4800,0.5,4800.5);
00057 h1stat=new TH1F(tt5,tt5+"; softID; MIP status",4800,0.5,4800.5);
00058 h1g->GetYaxis()->SetTitleSize(0.055);
00059 h1sig->GetYaxis()->SetTitleSize(0.055);
00060 h1stat->GetYaxis()->SetTitleSize(0.055);
00061
00062 pad=new TPad("pad2", "apd2",0.0,0.7,1.,1.); pad->Draw();
00063 pad->cd();h2g->Draw("colz"); h2g->SetMaximum(gMax); gPad->SetGrid();
00064 if(page==3) markBtow2D();
00065 if(page==2) markBprs2D();
00066
00067 c->cd(); pad=new TPad("pad1", "apd1",0.0,0.0,1.,0.7); pad->Draw();
00068 pad->Divide(1,2);
00069 pad->cd(1);h1g->Draw(); if(page==2) markBprs1D();
00070 pad->cd(2);h1sig->Draw();gPad->SetGrid(); if(page==2) markBprs1D();
00071
00072
00073
00074 for(int id=1;id<=4800;id++) {
00075 char txt[100];
00076 sprintf(txt,"%s%dm",core1,id);
00077 TH1F *h=fd->Get(txt);
00078 if(h==0) { h1stat->Fill(id,1); printf("missing=%s \n",txt); continue;}
00079
00080 float yield=h->GetEntries();
00081 if(yield<cut_minYield) {h1stat->Fill(id,2); printf(" low MIP yield=%s %d \n",txt,yield); continue;}
00082
00083 TF1 *ff=h->GetFunction("gaus");
00084 float mean=ff->GetParameter(1);
00085 float meanE=ff->GetParError(1);
00086 float sig=ff->GetParameter(2);
00087 float mpvRE=fabs(meanE/mean);
00088
00089 if( (mpvRE>cut_mpvRE) ||
00090 (mean<1 || mean>40) ) {
00091 mean=h->GetMean();
00092 sig=h->GetRMS();
00093 if(mean< cut_mipL || mean>40) { h1stat->Fill(id,4); printf(" too low2 MIP=%s %f\n",txt,mean); continue;}
00094
00095 meanE=sig/sqrt(yield);
00096 mpvRE=fabs(meanE/mean);
00097 printf(" %s bad fit, use mean/RMS\n", txt);
00098 }
00099 if( mpvRE>cut_mpvRE) { h1stat->Fill(id,8); printf(" bad mpvRE=%s %f\n",txt,mpvRE); continue;}
00100 printf("id=%d yield=%d MIP=%.1f +/- %.1f\n",id,yield, mean,sig);
00101 int ix=1+(id-1)/20;
00102 int iy=1+(id-1)%20;
00103 h2g->Fill(ix,iy,mean);
00104 h1g->SetBinContent(id,mean);
00105 h1g->SetBinError(id,meanE);
00106 h1sig->SetBinContent(id,sig);
00107 }
00108 int nKill=(int) h1stat->GetEntries();
00109 tt5="nKilled="; tt5+=nKill; tx=new TText(-500,26,tt5); tx->Draw(); tx->SetTextSize(0.08);tx->SetTextColor(kRed);
00110
00111 fout->cd();
00112 h2g->Write();
00113 h1g->Write();
00114 h1sig->Write();
00115 h1stat->Write();
00116
00117 } break;
00118
00119 default:
00120 }
00121 }
00122
00123
00124
00125 void markBtow2D() {
00126 lnEW=new TLine(120.5,0, 120.5,23); lnEW->Draw(); lnEW->SetLineColor(kBlue);
00127 tx=new TText(100,21.7,"West"); tx->Draw(); tx->SetTextColor(kBlue);
00128 tx=new TText(140,21.7,"East"); tx->Draw(); tx->SetTextColor(kBlue);
00129
00130 tx=new TText(-5,-1.5,"module=1"); tx->Draw(); tx->SetTextColor(kBlue);
00131 tx=new TText(108,-1.5,"module=60,61"); tx->Draw(); tx->SetTextColor(kBlue);
00132 tx=new TText(240,-1.5,"module=120"); tx->Draw(); tx->SetTextColor(kBlue);
00133 }
00134
00135 void markBprs2D() {
00136 lnEW=new TLine(120.5,-2, 120.5,23); lnEW->Draw(); lnEW->SetLineColor(kBlue);
00137 tx=new TText(100,21.7,"West"); tx->Draw(); tx->SetTextColor(kBlue);
00138 tx=new TText(140,21.7,"East"); tx->Draw(); tx->SetTextColor(kBlue);
00139
00140 lnEW=new TLine(17.5,-2, 17.5,21); lnEW->Draw(); lnEW->SetLineColor(kBlue);
00141 lnEW=new TLine(77.5,-2, 77.5,21); lnEW->Draw(); lnEW->SetLineColor(kBlue);
00142
00143 lnEW=new TLine(145.5,-2, 145.5,21); lnEW->Draw(); lnEW->SetLineColor(kBlue);
00144 lnEW=new TLine(205.5,-2, 205.5,21); lnEW->Draw(); lnEW->SetLineColor(kBlue);
00145
00146 tx=new TText(1,-1.5,"PSD-1W"); tx->Draw(); tx->SetTextColor(kBlue);
00147 tx=new TText(80,-1.5,"PSD-1W"); tx->Draw(); tx->SetTextColor(kBlue);
00148 tx=new TText(40,-1.5,"PSD-19W"); tx->Draw(); tx->SetTextColor(kBlue);
00149
00150 tx=new TText(206,-0.5,"PSD-1E"); tx->Draw(); tx->SetTextColor(kBlue);
00151 tx=new TText(130,-1.5,"PSD-1E"); tx->Draw(); tx->SetTextColor(kBlue);
00152 tx=new TText(180,-1.5,"PSD-20E"); tx->Draw(); tx->SetTextColor(kBlue);
00153
00154 }
00155
00156
00157 void markBprs1D() {
00158 float y=500;
00159 lnEW=new TLine(2400,-2, 2400,y); lnEW->Draw(); lnEW->SetLineColor(kBlue);
00160
00161
00162
00163 lnEW=new TLine(340,0,340,y); lnEW->Draw(); lnEW->SetLineColor(kBlue);
00164 lnEW=new TLine(1540,0,1540,y); lnEW->Draw(); lnEW->SetLineColor(kBlue);
00165
00166 lnEW=new TLine(2900,0,2900,y); lnEW->Draw(); lnEW->SetLineColor(kBlue);
00167 lnEW=new TLine(4100,0,4100,y); lnEW->Draw(); lnEW->SetLineColor(kBlue);
00168
00169 tx=new TText(10,-2,"PSD-1W"); tx->Draw(); tx->SetTextColor(kBlue);
00170 tx=new TText(1600,-2,"PSD-1W"); tx->Draw(); tx->SetTextColor(kBlue);
00171 tx=new TText(1000,-2,"PSD-19W"); tx->Draw(); tx->SetTextColor(kBlue);
00172
00173 tx=new TText(2600,-2,"PSD-1E"); tx->Draw(); tx->SetTextColor(kBlue);
00174 tx=new TText(3200,-2.,"PSD-1E"); tx->Draw(); tx->SetTextColor(kBlue);
00175 tx=new TText(4200,-2.,"PSD-20E"); tx->Draw(); tx->SetTextColor(kBlue);
00176
00177 }