00001 TCanvas *c;
00002 double par[6];
00003 double *epar;
00004 TFile *fdA[12];
00005 FILE *wfd=stdout;
00006 FILE *gfd;
00007
00008
00009
00010 void openAll(char cT) {
00011 int i;
00012 char txt[200];
00013 for(i=0;i<12;i++) {
00014 sprintf(txt,"iter5-pp/sect%02d/sum-sect%d.hist.root",i+1,i+1);
00015 fdA[i]=new TFile(txt);
00016 assert(fdA[i]->IsOpen());
00017 }
00018 sprintf(txt,"/star/u/wissink/cal2006/iter5-pp/gains%c-allSect.dat",cT);
00019 gfd=fopen(txt,"w");
00020 assert(gfd);
00021 fprintf(gfd,"# final %c-gains from MIP using UxV\n",cT);
00022 fprintf(gfd,"# format: gain (ch/GeV) & errGain, GausLandauFit: MPV(ADC) & errMPV, pedFit: means(ADC) & err \n");
00023
00024
00025 sprintf(txt,"/star/u/wissink/cal2006/iter5-pp/gains%c.html",cT);
00026
00027 wfd=fopen(txt,"w");
00028 assert(wfd);
00029
00030 fprintf(wfd,"MIP -- > <a href=\"gains%c-allSect.dat\"> final %c-gains</a> table \n",cT,cT);
00031 fprintf(wfd,"<table border=1>\n");
00032 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");
00033
00034
00035 }
00036
00037
00038
00039 fitTower() {
00040 gStyle->SetStatW(0.22);
00041 gStyle->SetStatH(0.22);
00042
00043
00044
00045 TH1F *h1=new TH1F("mpv","MPV gated w/ MIP ; MPV of ADC-ped",40,-5,35);
00046 TH1F *h2=new TH1F("mpvE","relative error of MPV , MIP gated; err(MPV)/MPV ",50,0,0.3);
00047
00048
00049
00050 hDum=new TH1F("aa","bb",10,1,9);
00051 hDum->Fill(5);
00052
00053
00054 char cT='T';
00055 openAll(cT);
00056
00057 int sec=5;
00058 char core[100];
00059
00060 int eta;
00061 char sub='C';
00062
00063 for(eta=1;eta<=12;eta++) {
00064 int nErr=0, nOK=0;
00065 float mpvL=999, mpvH=0;
00066 h1->Reset(); h2->Reset();
00067 fprintf(wfd," <tr> <th> %d <td> \n",eta);
00068 gStyle->SetOptStat(1001111);
00069
00070 for(sec=1; sec<=12;sec++) {
00071 TFile *f=fdA[sec-1];
00072 for(sub='A';sub<='E';sub++) {
00073 sprintf(core,"%02d%c%c%02d",sec,cT,sub,eta);
00074 TString coreT=core;
00075 ha=(TH1F*)f->Get("a"+coreT);
00076 hd=(TH1F*)f->Get("d"+coreT);
00077
00078
00079 if( (eta==7 && sub=='B' && (sec==4 || sec==8)) || (eta==7 && sub=='A' && sec==6)) {
00080 ha->Rebin(4);
00081 hd->Rebin(4);
00082 printf("tower=%s rebinned\n",core);
00083 }
00084
00085 c=new TCanvas("aa","aa",400,400);
00086 c->Divide(1,2); c->cd(1);
00087 hDum->Draw(); gPad->SetLogy();
00088 float mpv, mpvEr;
00089 TString errS=plotOne(ha,hd, mpv, mpvEr);
00090 printf("errS=%s=\n",errS.Data());
00091
00092 bool isBad=errS.Sizeof()>1;
00093 if(isBad) {
00094 fprintf(wfd," %s ,\n",(coreT+"-"+errS).Data());
00095 nErr++;
00096 }
00097 if(errS.Contains("mask")) continue;
00098 nOK++;
00099
00100
00101 if(mpvL>mpv) mpvL=mpv;
00102 if(mpvH<mpv) mpvH=mpv;
00103
00104 h1->Fill(mpv);
00105 if(mpv>0) {
00106 h2->Fill(mpvEr/mpv);
00107 }
00108
00109 }
00110
00111 }
00112 fprintf(wfd," <td> %d <td> %d\n",nOK,nErr);
00113
00114 char txt[100],sumN[100], pdfN[100];
00115 sprintf(pdfN,"%cfitEta%02d.pdf",cT,eta);
00116 sprintf(txt,"cat *%02d.ps | ps2pdf - %s",eta,pdfN);
00117 printf("%s\n",txt);
00118 system(txt);
00119 sprintf(txt,"mv %s /star/u/wissink/cal2006/tmp/",pdfN);
00120 printf("%s\n",txt);
00121 system(txt);
00122 fprintf(wfd," <td> <a href=\"%s\"> PDF </a>\n",pdfN);
00123 fprintf(wfd," <td> %.1f to %.1f \n",mpvL,mpvH);
00124
00125 gStyle->SetOptStat(1111111);
00126
00127 sprintf(sumN,"mpv%c-eta%02d",cT,eta);
00128 c=new TCanvas(sumN,sumN,600,600);
00129 c->Divide(1,3);
00130 c->cd(1); h1->Draw();
00131 c->cd(2); h2->Draw();
00132 c->Print();
00133
00134 sprintf(txt,"ps2pdf %s.ps %s.pdf",sumN,sumN);
00135 printf("%s\n",txt);
00136 system(txt);
00137 sprintf(txt,"mv %s.pdf /star/u/wissink/cal2006/tmp/",sumN);
00138 printf("%s\n",txt);
00139 system(txt);
00140 fprintf(wfd," <td> <a href=\"%s.pdf\"> PDF </a>\n",sumN);
00141
00142 fflush(wfd);
00143 }
00144
00145 if(wfd!=stdout)fclose(wfd);
00146 fclose(gfd);
00147 return;
00148 }
00149
00150
00151 TString plotOne(TH1F *ha, TH1F *hd, float &MPV, float &MPVerr) {
00152 assert(ha);
00153 assert(hd);
00154 const float feta[]=
00155 {1.95,1.855,1.765,1.675,1.59,1.51,1.435,1.365,1.3,1.235,1.17,1.115};
00156
00157 char *core =ha->GetName()+1;
00158 TString coreT=core;
00159 float xMax=120;
00160 ha->SetAxisRange(-10,xMax);
00161 hd->SetAxisRange(-10,xMax/2.);
00162
00163
00164 int maxbina=ha->GetMaximumBin();
00165 float xcenta=ha->GetBinCenter(maxbina);
00166 printf("\n============================\n working on %s\n",ha->GetName());
00167
00168 c->cd(1);
00169 ha->SetLineColor(4);
00170 ha->SetMinimum(0.9);
00171 char *func="gaus";
00172 ha->Fit(func,"RQI","",xcenta-5,xcenta+5);
00173 gPad->SetLogy();
00174 TF1* gausa=ha->GetFunction(func);
00175 gausa->SetLineWidth(1);
00176 gausa->SetLineColor(2);
00177 float meanA=gausa->GetParameter(1);
00178 float errorA=gausa->GetParError(1);
00179
00180 hx=hd->Clone();
00181 hx->Draw("same");
00182
00183 c->cd(2);
00184
00185 TF1 *f1 = new TF1("myfunc",myfunction,-10,100,5);
00186 f1->SetParNames("x0","aL","aG","sigL","sigG");
00187 f1->SetLineColor(kRed);
00188 f1->SetLineWidth(1);
00189 hd->Fit("gaus","RQ","",0,30);
00190 TF1 *ff=hd->GetFunction("gaus");
00191 f1->SetParameter(0,ff->GetParameter(1));
00192 f1->SetParameter(1,ff->GetParameter(0));
00193 f1->FixParameter(2,0);
00194
00195 fitGausLand(hd);
00196 c->Print(coreT+".ps");
00197
00198
00199 f1->GetParameters(par);
00200 epar= f1->GetParErrors();
00201
00202 ha->SetAxisRange(-3,3);
00203
00204 if(ha->Integral()/ha->GetEntries()>0.999) return "mask";
00205
00206 float meanD=par[0];
00207 float errorD=epar[0];
00208
00209 int ieta=atoi(core+4) -1;
00210
00211
00212 MPV=(meanD-meanA);
00213 MPVerr=sqrt(errorA*errorA+errorD*errorD+0.09);
00214 float gain=2.89*TMath::TanH(feta[ieta])*MPV;
00215 float sig=2.89*TMath::TanH(feta[ieta])*MPVerr;
00216 fprintf(gfd,"%s %.2f %.2f %5.1f %5.2f %5.2f %5.2f\n",core,gain,sig,meanD,errorD,meanA,errorA);
00217
00218 if(fabs(meanA)>1.) return "pedOff";
00219 if(ha->GetEntries() <=5) return "noPed";
00220 ha->SetAxisRange(-3.,3.);
00221 if(ha->Integral()<0.9*ha->GetEntries()) return "Multped";
00222
00223 if(hd->GetEntries() <=5) return "noMip";
00224
00225
00226 TListIter it(hd->GetListOfFunctions());
00227 TLine *w=(TLine*)it.Next() ;
00228 w->Print();
00229 float del=MPV-w->GetX1();
00230 printf(" %s MPV=%f, del=%f goal=%f\n",hd->GetName(),MPV,del,w->GetX1());
00231 float eps=0.30;
00232 if(MPV<(1-eps)*w->GetX1()) return "lowG";
00233 if(MPV>(1+eps)*w->GetX1()) return "highG";
00234
00235 if(par[1]<0 || par[2]<0) return "amplNeg";
00236 if(gain<10.) return "gainNeg";
00237
00238 if(fabs(epar[0])<0.05) return "singF";
00239 if(par[4]/par[0]>0.60) return "wideG";
00240 hd->SetAxisRange(3,50);
00241 float sum=hd->Integral();
00242 if(sum<20) return "lowS";
00243
00244
00245 return "";
00246 }
00247
00248
00249
00250
00251 Double_t myfunction(Double_t *x, Double_t *par)
00252 {
00253 Float_t xx =x[0];
00254 float mpv=par[0];
00255 float aL=par[1]*fabs(par[3]);
00256 float aG=par[1];
00257 float sigL=2*par[3];
00258 float sigG=par[4];
00259 Double_t fland = TMath::Landau(xx,mpv,sigL);
00260 if(sigL!=0) fland/=sigL;
00261 Double_t fgaus = TMath::Gaus(xx,mpv,sigG);
00262 double f=aL*fland + aG*fgaus;
00263 return f;
00264 }
00265
00266 float fitGausLand(TH1F *h) {
00267 char *funcd="myfunc";
00268 int maxbind=h->GetMaximumBin();
00269 float sig=h->GetRMS();
00270 float sum=h->Integral();
00271 float xcentd=h->GetBinCenter(maxbind);
00272 float eta=atoi(h->GetName()+5);
00273
00274 TF1 *f1=(TF1 *)gROOT->GetFunction(funcd);
00275 f1->SetParameters(xcentd,0,0,sig,sig);
00276 float x1=xcentd-10;
00277 float x2=xcentd*2.;
00278 if(x1<0) x1=0;
00279 if(x2<xcentd) x2=xcentd+10;
00280
00281 h->Fit(funcd,"R","",x1,x2);
00282
00283
00284 }