10 void openAll(
char cT) {
14 sprintf(txt,
"iter5-pp/sect%02d/sum-sect%d.hist.root",i+1,i+1);
15 fdA[i]=
new TFile(txt);
16 assert(fdA[i]->IsOpen());
18 sprintf(txt,
"/star/u/wissink/cal2006/iter5-pp/gains%c-allSect.dat",cT);
21 fprintf(gfd,
"# final %c-gains from MIP using UxV\n",cT);
22 fprintf(gfd,
"# format: gain (ch/GeV) & errGain, GausLandauFit: MPV(ADC) & errMPV, pedFit: means(ADC) & err \n");
25 sprintf(txt,
"/star/u/wissink/cal2006/iter5-pp/gains%c.html",cT);
30 fprintf(wfd,
"MIP -- > <a href=\"gains%c-allSect.dat\"> final %c-gains</a> table \n",cT,cT);
31 fprintf(wfd,
"<table border=1>\n");
32 fprintf(wfd,
"<tr> <th> etaBin <th> problems <th> # of good<th> # of errors <br> +warn <th> spectra <br> (60 tiles)<th> MPV range <br>(ADC) <th> summary <br> plot\n");
40 gStyle->SetStatW(0.22);
41 gStyle->SetStatH(0.22);
45 TH1F *h1=
new TH1F(
"mpv",
"MPV gated w/ MIP ; MPV of ADC-ped",40,-5,35);
46 TH1F *h2=
new TH1F(
"mpvE",
"relative error of MPV , MIP gated; err(MPV)/MPV ",50,0,0.3);
50 hDum=
new TH1F(
"aa",
"bb",10,1,9);
63 for(eta=1;eta<=12;eta++) {
65 float mpvL=999, mpvH=0;
66 h1->Reset(); h2->Reset();
67 fprintf(wfd,
" <tr> <th> %d <td> \n",eta);
68 gStyle->SetOptStat(1001111);
70 for(sec=1; sec<=12;sec++) {
72 for(sub=
'A';sub<=
'E';sub++) {
73 sprintf(core,
"%02d%c%c%02d",sec,cT,sub,eta);
75 ha=(TH1F*)f->Get(
"a"+coreT);
76 hd=(TH1F*)f->Get(
"d"+coreT);
79 if( (eta==7 && sub==
'B' && (sec==4 || sec==8)) || (eta==7 && sub==
'A' && sec==6)) {
82 printf(
"tower=%s rebinned\n",core);
85 c=
new TCanvas(
"aa",
"aa",400,400);
86 c->Divide(1,2); c->cd(1);
87 hDum->Draw(); gPad->SetLogy();
89 TString errS=plotOne(ha,hd, mpv, mpvEr);
90 printf(
"errS=%s=\n",errS.Data());
92 bool isBad=errS.Sizeof()>1;
94 fprintf(wfd,
" %s ,\n",(coreT+
"-"+errS).Data());
97 if(errS.Contains(
"mask"))
continue;
101 if(mpvL>mpv) mpvL=mpv;
102 if(mpvH<mpv) mpvH=mpv;
112 fprintf(wfd,
" <td> %d <td> %d\n",nOK,nErr);
114 char txt[100],sumN[100], pdfN[100];
115 sprintf(pdfN,
"%cfitEta%02d.pdf",cT,eta);
116 sprintf(txt,
"cat *%02d.ps | ps2pdf - %s",eta,pdfN);
119 sprintf(txt,
"mv %s /star/u/wissink/cal2006/tmp/",pdfN);
122 fprintf(wfd,
" <td> <a href=\"%s\"> PDF </a>\n",pdfN);
123 fprintf(wfd,
" <td> %.1f to %.1f \n",mpvL,mpvH);
125 gStyle->SetOptStat(1111111);
127 sprintf(sumN,
"mpv%c-eta%02d",cT,eta);
128 c=
new TCanvas(sumN,sumN,600,600);
130 c->cd(1); h1->Draw();
131 c->cd(2); h2->Draw();
134 sprintf(txt,
"ps2pdf %s.ps %s.pdf",sumN,sumN);
137 sprintf(txt,
"mv %s.pdf /star/u/wissink/cal2006/tmp/",sumN);
140 fprintf(wfd,
" <td> <a href=\"%s.pdf\"> PDF </a>\n",sumN);
145 if(wfd!=stdout)fclose(wfd);
151 TString plotOne(TH1F *ha, TH1F *hd,
float &MPV,
float &MPVerr) {
155 {1.95,1.855,1.765,1.675,1.59,1.51,1.435,1.365,1.3,1.235,1.17,1.115};
157 char *core =ha->GetName()+1;
160 ha->SetAxisRange(-10,xMax);
161 hd->SetAxisRange(-10,xMax/2.);
164 int maxbina=ha->GetMaximumBin();
165 float xcenta=ha->GetBinCenter(maxbina);
166 printf(
"\n============================\n working on %s\n",ha->GetName());
172 ha->Fit(func,
"RQI",
"",xcenta-5,xcenta+5);
174 TF1* gausa=ha->GetFunction(func);
175 gausa->SetLineWidth(1);
176 gausa->SetLineColor(2);
177 float meanA=gausa->GetParameter(1);
178 float errorA=gausa->GetParError(1);
185 TF1 *f1 =
new TF1(
"myfunc",myfunction,-10,100,5);
186 f1->SetParNames(
"x0",
"aL",
"aG",
"sigL",
"sigG");
187 f1->SetLineColor(kRed);
189 hd->Fit(
"gaus",
"RQ",
"",0,30);
190 TF1 *ff=hd->GetFunction(
"gaus");
191 f1->SetParameter(0,ff->GetParameter(1));
192 f1->SetParameter(1,ff->GetParameter(0));
193 f1->FixParameter(2,0);
196 c->Print(coreT+
".ps");
199 f1->GetParameters(par);
200 epar= f1->GetParErrors();
202 ha->SetAxisRange(-3,3);
204 if(ha->Integral()/ha->GetEntries()>0.999)
return "mask";
207 float errorD=epar[0];
209 int ieta=atoi(core+4) -1;
213 MPVerr=sqrt(errorA*errorA+errorD*errorD+0.09);
214 float gain=2.89*TMath::TanH(feta[ieta])*MPV;
215 float sig=2.89*TMath::TanH(feta[ieta])*MPVerr;
216 fprintf(gfd,
"%s %.2f %.2f %5.1f %5.2f %5.2f %5.2f\n",core,gain,sig,meanD,errorD,meanA,errorA);
218 if(fabs(meanA)>1.)
return "pedOff";
219 if(ha->GetEntries() <=5)
return "noPed";
220 ha->SetAxisRange(-3.,3.);
221 if(ha->Integral()<0.9*ha->GetEntries())
return "Multped";
223 if(hd->GetEntries() <=5)
return "noMip";
226 TListIter it(hd->GetListOfFunctions());
227 TLine *w=(TLine*)it.Next() ;
229 float del=MPV-w->GetX1();
230 printf(
" %s MPV=%f, del=%f goal=%f\n",hd->GetName(),MPV,del,w->GetX1());
232 if(MPV<(1-eps)*w->GetX1())
return "lowG";
233 if(MPV>(1+eps)*w->GetX1())
return "highG";
235 if(par[1]<0 || par[2]<0)
return "amplNeg";
236 if(gain<10.)
return "gainNeg";
238 if(fabs(epar[0])<0.05)
return "singF";
239 if(par[4]/par[0]>0.60)
return "wideG";
240 hd->SetAxisRange(3,50);
241 float sum=hd->Integral();
242 if(sum<20)
return "lowS";
251 Double_t myfunction(Double_t *x, Double_t *par)
255 float aL=par[1]*fabs(par[3]);
259 Double_t fland = TMath::Landau(xx,mpv,sigL);
260 if(sigL!=0) fland/=sigL;
261 Double_t fgaus = TMath::Gaus(xx,mpv,sigG);
262 double f=aL*fland + aG*fgaus;
266 float fitGausLand(TH1F *h) {
267 char *funcd=
"myfunc";
268 int maxbind=h->GetMaximumBin();
269 float sig=h->GetRMS();
270 float sum=h->Integral();
271 float xcentd=h->GetBinCenter(maxbind);
272 float eta=atoi(h->GetName()+5);
274 TF1 *f1=(TF1 *)gROOT->GetFunction(funcd);
275 f1->SetParameters(xcentd,0,0,sig,sig);
279 if(x2<xcentd) x2=xcentd+10;
281 h->Fit(funcd,
"R",
"",x1,x2);