19 const int mxTP=2, mxBTiles=4800;
20 char cTile[mxTP]={
'T',
'P'};
21 char *cTile4[mxTP]={
"BTOW",
"BPRS"};
22 TH1F * hPed, *sigP, *hChi,*hSig;
30 doAvrPed(
int k=10,
int run=9067013) {
31 gStyle->SetPalette(1,0);
33 gStyle->SetOptStat(1001110);
35 char *pathIn=
"outA3/";
36 char *pathOut=
"iter4/";
37 char txt[1000], txt2[1000];
39 sprintf(txt,
"%s/R%dp.barCal.-1.hist.root",pathIn,run);
41 fd1=
new TFile(txt); assert(fd1->IsOpen());
43 sprintf(txt,
"%s/pedBprsR%davr.hist.root",pathOut,run);
44 fd2=
new TFile(txt,
"recreate");
45 assert(fd2->IsOpen());
49 grP->SetMarkerSize(0.5);
51 TH2F * h2T= (TH2F *)fd1->Get(
"BTOW_c0"); assert(h2T);
52 TH2F * h2P= (TH2F *)fd1->Get(
"BPRS_c0"); assert(h2P);
53 h2P->GetXaxis()->SetLabelSize(0.08);
54 h2P->GetYaxis()->SetLabelSize(0.08);
59 int id1=1, id2=id1+k-1;
60 if(k<0) { id1=1; id2=mxBTiles; }
61 c=
new TCanvas(
"aa",
"aa",400,300);
63 fitPedBT(1,run,h2P,id1,id2 );
67 fd2->cd(); hPed->Write();
74 c=
new TCanvas(fd1->GetName(),fd1->GetName(),1000,800);
76 gStyle->SetOptStat(10);
77 c->cd(1); h2P->Draw(
"colz"); h2P->SetAxisRange(id1,id2);
80 c->cd(2); hStat->Draw(); hStat->SetAxisRange(id1,id2);
81 hStat->SetMinimum(.5);
82 if(hStat->GetMaximum()>10) gPad->SetLogy();
86 hChi->Draw(); hChi->SetAxisRange(id1,id2);
90 hSig->Draw(); hSig->SetAxisRange(id1,id2); hSig->SetMaximum(5);
94 hPeak->Draw(); hPeak->SetAxisRange(id1,id2); hPeak->SetMinimum(0.7);
113 void fitPedBT(
int itp,
int run,TH2F *h2,
int id1,
int id2) {
114 if(id2>18000) id2=18000;
115 char txt[1000], txt2[1000];
117 sprintf(txt,
"ped%s",cTile4[itp]);
118 sprintf(txt2,
"ped %s R%d; %s soft ID; pedestal +/- fit err (ADC)",cTile4[itp],run,cTile4[itp]);
119 hPed=
new TH1F(txt,txt2,mxBTiles,0.5,mxBTiles+0.5);
121 hPed->GetXaxis()->SetLabelSize(0.08);
122 hPed->GetYaxis()->SetLabelSize(0.08);
124 sprintf(txt,
"stat%s",cTile4[itp]);
125 sprintf(txt2,
"status %s R%d; %s soft ID; jan status",cTile4[itp],run,cTile4[itp]);
126 hStat=
new TH1I(txt,txt2,mxBTiles,0.5,mxBTiles+0.5); hStat->Reset(-1);
127 hStat->GetXaxis()->SetLabelSize(0.08);
128 hStat->GetYaxis()->SetLabelSize(0.08);
130 sprintf(txt,
"chi%s",cTile4[itp]);
131 sprintf(txt2,
"chi2/DOF %s R%d; %s soft ID; ped Chi2/DOF",cTile4[itp],run,cTile4[itp]);
132 hChi=
new TH1F(txt,txt2,mxBTiles,0.5,mxBTiles+0.5); hStat->Reset(-1);
133 hChi->GetXaxis()->SetLabelSize(0.08);
134 hChi->GetYaxis()->SetLabelSize(0.08);
135 hChi->GetYaxis()->SetTitleSize(0.2);
137 sprintf(txt,
"sigPed%s",cTile4[itp]);
138 sprintf(txt2,
"sigma(ped) %s R%d; %s soft ID; sig(ped) ADC",cTile4[itp],run,cTile4[itp]);
139 hSig=
new TH1F(txt,txt2,mxBTiles,0.5,mxBTiles+0.5); hStat->Reset(-1);
140 hSig->GetXaxis()->SetLabelSize(0.08);
141 hSig->GetYaxis()->SetLabelSize(0.08);
143 hPeak=
new TH1F(
"hpedPeak",
"integral of pedestal peak;soft ID", mxBTiles,0.5,mxBTiles+0.5);
144 hPeak->GetXaxis()->SetLabelSize(0.08);
145 hPeak->GetYaxis()->SetLabelSize(0.08);
150 float cut_yield0=100;
151 float cut_yieldR1=0.7;
152 float cut_ch2min=0.1;
153 float cut_ch2ndf=200.;
157 float cut_sigPed=2.7;
162 float x1=axX->GetXmin();
163 float x2=axX->GetXmax();
164 int nbX=axX->GetNbins();
165 printf(
"X-axis range --> [%.1f, %.1f], nb=%d %s\n",x1,x2,nbX,axX->GetTitle());
168 float y1=axY->GetXmin();
169 float y2=axY->GetXmax();
170 int nbY=axY->GetNbins();
171 printf(
"Y-axis range --> [%.1f, %.1f], nb=%d\n",y1,y2,nbY);
173 TH1F*h=
new TH1F(
"h1",
"h1",nbY,y1,y2);
176 for(ih=id1; ih<=id2; ih++) {
177 char txt1[100], txt2[1000];
178 sprintf(txt1,
"id%d",ih);
179 sprintf(txt2,
"%s soft id=%d;%s ",cTile4[itp],ih,axY->GetTitle());
181 h->Reset(); h->SetAxisRange(y1,y2);
184 for(i=1;i<=nbY;i++) h->SetBinContent(i,h2->GetBinContent(ih,i));
186 float mean=h->GetMean();
187 float yield=h->Integral();
188 h->SetEntries(yield);
189 printf(
"******** work on %s mean=%.1f rms=%.1f yield=%.1f\n",txt1,mean,h->GetRMS(),yield);
191 if(yield<cut_yield0) { hStat->SetBinContent(ih,kBad);
continue; }
194 if(isSticky(h,mean)) { hStat->SetBinContent(ih,kBad);
continue; }
198 float adc1=mean-par_rms*par_nsig;
199 float adc2=mean+par_rms*par_nsig-1;
200 h->SetAxisRange( adc1,adc2);
201 float yield2=h->Integral();
202 float r1=yield2/yield;
203 printf(
" range=%d,%d r1=%.3f yield2=%.1f\n",adc1,adc2,r1,yield2);
205 if(r1< cut_yieldR1) { hStat->SetBinContent(ih,kBad);
continue; }
208 h->Fit(
"gaus",
"Q",
"Rh", adc1, adc2);
209 TF1 *ff=h->GetFunction(
"gaus"); assert(ff);
210 ff->SetLineColor(kRed);
211 ff->SetLineWidth(1.);
214 float ped=ff->GetParameter(1);
215 float pedErr=ff->GetParError(1);
216 float sig=ff->GetParameter(2);
217 float chi2=ff->GetChisquare();
218 float ndf=ff->GetNDF();
220 printf(
"chi2=%f ndf=%f\n", chi2,ndf);
221 if(chi2<cut_ch2min) { hStat->SetBinContent(ih,kBad);
continue; }
223 hChi->SetBinContent(ih, chi2/ndf);
224 if(chi2/ndf> cut_ch2ndf) { hStat->SetBinContent(ih,kBad);
continue; }
227 adc1=ped-sig*par_nsig;
228 adc2=ped+sig*par_nsig;
229 h->SetAxisRange( adc1,adc2);
230 float yield3=h->Integral();
231 float r2=yield2/yield;
232 printf(
"ped=%f sig=%f range=%d,%d r2=%.3f\n",ped,sig,adc1,adc2,r2);
234 hSig->SetBinContent(ih,sig);
235 if(sig>cut_sigPed || sig<0) { hStat->SetBinContent(ih,kBad);
continue; }
239 if(ped< cut_pedL) { hStat->SetBinContent(ih,kBad);
continue; }
240 if(ped> cut_pedH) { hStat->SetBinContent(ih,kBad);
continue; }
244 hPed->SetBinContent(ih,ped);
245 hPed->SetBinError(ih,pedErr);
248 grP->SetPoint(np,ih,ped);
249 grP->SetPointError(np,0,pedErr);
251 hPeak->SetBinContent(ih,r2);
252 hStat->SetBinContent(ih,0);
254 h->SetAxisRange(y1,y2);
262 void isSticky(TH1F *h,
float ped) {
265 int kPed=axX->FindBin(ped);
266 printf(
"%s ped=%f kPed=%d\n",h->GetName(),ped,kPed);
268 for(
int i=kPed-10;i<=kPed+10;i++) {
269 float val=h->GetBinContent(i);
271 if(i%2==0) sum1+=val;
272 if(i%2==1) sum2+=val;
275 if(sum1>sum2) r=sum2/sum1;
277 printf(
"sum1=%f sum2=%f, r=%f\n",sum1,sum2,r);
278 if(r<0.1)
return true;
285 void printStat(
int id1,
int id2) {
287 printf(
"softID stat \n",);
289 for(
int i=id1; i<=id2;i++) {
290 int val=hStat->GetBinContent(i);
295 printf(
"%d 0x%0x\n",i,val);
299 printf(
"\nstat summary: tot=%d good=%d bad=%d\n",id2-id1+1,nGood, nBad);