//====================================== fitTower() { gStyle->SetStatW(0.22); gStyle->SetStatH(0.22); // f=new TFile("/star/data05/scratch/balewski/2005-eemcCal/day49-hist/iter2-out/sum-sect5.hist.root"); TH1F *h1=new TH1F("mpv","MPV gated w/ MIP ; MPV of ADC-ped",40,-5,35); TH1F *h2=new TH1F("mpvE","relative error of MPV , MIP gated; err(MPV)/MPV ",50,0,0.3); // stupid root tricks: hDum=new TH1F("aa","bb",10,1,9); hDum->Fill(5); char cT='T'; openAll(cT); int sec=5; char core[100]; int eta; char sub='C'; for(eta=1;eta<=12;eta++) { int nErr=0, nOK=0; float mpvL=999, mpvH=0; h1->Reset(); h2->Reset(); fprintf(wfd," <tr> <th> %d <td> \n",eta); gStyle->SetOptStat(1001111); for(sec=1; sec<=12;sec++) { TFile *f=fdA[sec-1]; for(sub='A';sub<='E';sub++) { sprintf(core,"%02d%c%c%02d",sec,cT,sub,eta); TString coreT=core; ha=(TH1F*)f->Get("a"+coreT); hd=(TH1F*)f->Get("d"+coreT); // special case of stuck low bits - sww - modified to include 06TA07 if( (eta==7 && sub=='B' && (sec==4 || sec==8)) || (eta==7 && sub=='A' && sec==6)) { ha->Rebin(4); hd->Rebin(4); printf("tower=%s rebinned\n",core); } c=new TCanvas("aa","aa",400,400); c->Divide(1,2); c->cd(1); hDum->Draw(); gPad->SetLogy(); float mpv, mpvEr; TString errS=plotOne(ha,hd, mpv, mpvEr); printf("errS=%s=\n",errS.Data()); bool isBad=errS.Sizeof()>1; if(isBad) { // report error channel fprintf(wfd," %s ,\n",(coreT+"-"+errS).Data()); nErr++; } if(errS.Contains("mask")) continue; nOK++; //return; if(mpvL>mpv) mpvL=mpv; if(mpvH<mpv) mpvH=mpv; h1->Fill(mpv); if(mpv>0) { h2->Fill(mpvEr/mpv); } } // end of eta bin }// end of sector loop fprintf(wfd," <td> %d <td> %d\n",nOK,nErr); char txt[100],sumN[100], pdfN[100]; sprintf(pdfN,"%cfitEta%02d.pdf",cT,eta); sprintf(txt,"cat *%02d.ps | ps2pdf - %s",eta,pdfN); printf("%s\n",txt); system(txt); sprintf(txt,"mv %s /star/u/wissink/cal2006/tmp/",pdfN); printf("%s\n",txt); system(txt); fprintf(wfd," <td> <a href=\"%s\"> PDF </a>\n",pdfN); fprintf(wfd," <td> %.1f to %.1f \n",mpvL,mpvH); gStyle->SetOptStat(1111111); sprintf(sumN,"mpv%c-eta%02d",cT,eta); c=new TCanvas(sumN,sumN,600,600); c->Divide(1,3); c->cd(1); h1->Draw(); c->cd(2); h2->Draw(); c->Print(); sprintf(txt,"ps2pdf %s.ps %s.pdf",sumN,sumN); printf("%s\n",txt); system(txt); sprintf(txt,"mv %s.pdf /star/u/wissink/cal2006/tmp/",sumN); printf("%s\n",txt); system(txt); fprintf(wfd," <td> <a href=\"%s.pdf\"> PDF </a>\n",sumN); fflush(wfd); }// end of loop over eta bins if(wfd!=stdout)fclose(wfd); fclose(gfd); return; }
//====================================== fitPrePost() { gStyle->SetStatW(0.22); gStyle->SetStatH(0.22); // f=new TFile("iter4-pp/sect05/sum-sect5.hist.root"); TH1F *h1=new TH1F("mpv","MPV MIP gated; MPV of ADC-ped",35,-5,65); TH1F *h2=new TH1F("mpvE","relative error of MPV , MIP gated; err(MPV)/MPV ",50,0,0.5); TH1F *h3=new TH1F("mpvS","relative width of L-peak, MIP gated; sigma/MPV",25,0.,1.); TH2F *h4=new TH2F("mpv2","MPV from ; gated w/ MIP ; inclusive spectrum;",25,0,50,25,0,25); //===sww===Set layer to analyze in next line char cT='R'; openAll(cT); const float feta[]= {1.95,1.855,1.765,1.675,1.59,1.51,1.435,1.365,1.3,1.235,1.17,1.115}; int sec=5; char core[100]; int eta; char sub='C'; //===sww===Set eta range and sector range in next two "for" statements for(eta=1; eta<=12; eta++) { int nErr=0, nOK=0; float mpvL=999, mpvH=0; h1->Reset(); h2->Reset(); h3->Reset(); h4->Reset(); fprintf(wfd," <tr> <th> %d <td> \n",eta); gStyle->SetOptStat(1001111); for(sec=1; sec<=12; sec++) { TFile *f=fdA[sec-1]; for(sub='A'; sub<='E'; sub++) { sprintf(core,"%02d%c%c%02d",sec,cT,sub,eta); TString coreT=core; ha=(TH1F*)f->Get("a"+coreT); hd=(TH1F*)f->Get("d"+coreT); c=new TCanvas("aa","aa",400,400); plotOne(ha,hd); //return; c->Print(coreT+".ps"); TString errS=QaOne(ha,hd,cT); printf("errS=%s=%d\n",errS.Data(),errS.Sizeof()); bool isBad=errS.Sizeof()>1; if(isBad) { // report error channel fprintf(wfd," %s ,\n",(coreT+"-"+errS).Data()); nErr++; // continue; } if(errS.Contains("mask")) continue; nOK++; // return; // // c->Print(coreT+".gif"); float mpv=par[4]; float mpvEr=epar[4]; if(mpvL>mpv) mpvL=mpv; if(mpvH<mpv) mpvH=mpv; int ieta=eta-1; float fac=TMath::TanH(feta[ieta])/0.0009; // assumed 0.9 MeV per plastic float err=sqrt(mpvEr*mpvEr+1); float gain=mpv*fac; float sig=err*fac; fprintf(gfd,"%s %.0f %.0f %.1f %.1f \n",core,gain,sig,mpv,mpvEr); h1->Fill(mpv); if(mpv>0) { h2->Fill(mpvEr/mpv); h3->Fill(par[5]/mpv); } // h4->Fill(mpv,mpvInc); } // end of eta bin }// end of sector loop fprintf(wfd," <td> %d <td> %d\n",nOK,nErr); char txt[100],sumN[100], pdfN[100]; sprintf(pdfN,"%cfitEta%02d.pdf",cT,eta); sprintf(txt,"cat *%02d.ps | ps2pdf - %s",eta,pdfN); printf("%s\n",txt); system(txt); sprintf(txt,"mv %s /star/u/wissink/cal2006/tmp/",pdfN); printf("%s\n",txt); system(txt); fprintf(wfd," <td> <a href=\"%s\"> PDF </a>\n",pdfN); fprintf(wfd," <td> %.1f to %.1f \n",mpvL,mpvH); gStyle->SetOptStat(1111111); sprintf(sumN,"mpv%c-eta%02d",cT,eta); c=new TCanvas(sumN,sumN,600,600); c->Divide(1,3); c->cd(1); h1->Draw(); c->cd(2); h2->Draw(); c->cd(3); h3->Draw(); // c->cd(4); h4->Draw("box"); c->Print(); sprintf(txt,"ps2pdf %s.ps %s.pdf",sumN,sumN); printf("%s\n",txt); system(txt); sprintf(txt,"mv %s.pdf /star/u/wissink/cal2006/tmp/",sumN); printf("%s\n",txt); system(txt); fprintf(wfd," <td> <a href=\"%s.pdf\"> PDF </a>\n",sumN); }// end of loop over eta bins if(wfd!=stdout)fclose(wfd); fclose(gfd); }
/* ALL VISITS */ void visNumSixAll() { int i, j, filt, nf, nmax, nmin, sum, flag; int nFields, *start, *len, **count; int maxnum[NFILTERS]; int hist[NFILTERS][NHIST], histmax[NFILTERS], histmin[NFILTERS], chist[NHIST], desired[NFILTERS], obsfilt[NFILTERS]; double xmin, xmax, ymin, ymax; double *ravec, *decvec, **value, valmin[NFILTERS], valmax[NFILTERS], frac, least; FILE *out; char labstr[1024]; start = malloc((numFields+1)*sizeof(int)); len = malloc(numFields*sizeof(int)); ravec = malloc(numFields*sizeof(double)); decvec =malloc(numFields*sizeof(double)); count = malloc(NFILTERS*sizeof(int *)); for(i=0; i<NFILTERS; i++) count[i] = malloc(numFields*sizeof(int)); value = malloc(NFILTERS*sizeof(double *)); for(i=0; i<NFILTERS; i++) value[i] = malloc(numFields*sizeof(double)); // order visits by field and get pointers getFieldData(&nFields, start, len); // count the number of visits per field, per fiter for(nf=0; nf<nFields; nf++) { for(filt=0; filt<NFILTERS; filt++) count[filt][nf]=0; for(filt=0; filt<NFILTERS; filt++) for(i=start[nf]; i<start[nf]+len[nf]; i++) if(obs[i].filter==filt) { count[filt][nf]++; } } for(filt=0; filt<NFILTERS; filt++) { obsfilt[filt] = 0; for(nf=0; nf<nFields; nf++) obsfilt[filt] += count[filt][nf]; } // now fill the value array for plotting for(nf=0; nf<nFields; nf++) { ravec[nf] = obs[start[nf]].ra; decvec[nf] = obs[start[nf]].dec; for(filt=0; filt<NFILTERS; filt++) { value[filt][nf] = (double) count[filt][nf]; } } // Reference maximum from SRD for 10-year survey if ( useDesignStretch == 0 ) { valmax[0] = 56; valmax[1] = 80; valmax[2] = 184; valmax[3] = 184; valmax[4] = 160; valmax[5] = 160; } else { valmax[0] = 70; valmax[1] = 100; valmax[2] = 230; valmax[3] = 230; valmax[4] = 200; valmax[5] = 200; } // adjust the desired values for survey duration for(filt=0; filt<NFILTERS; filt++) valmax[filt] *= (endMJD-startMJD)/365.25/10.0; for(filt=0; filt<NFILTERS; filt++) desired[filt] = valmax[filt]; // 120% SRD for 10-year survey for(filt=0; filt<NFILTERS; filt++) { valmax[filt] = 1.2 * desired[filt]; // 120% of SRD numbers valmin[filt] = 0.0; } // make the plot for the raw numbers plotSix(nFields, value, ravec, decvec, valmin, valmax, 1, "acquired number of visits", plotTitle, "SixVisitsAll-Num", 0); for(nf=0; nf<nFields; nf++) { ravec[nf] = obs[start[nf]].ra; decvec[nf] = obs[start[nf]].dec; for(filt=0; filt<NFILTERS; filt++) { value[filt][nf] *= (100.0/desired[filt]); } } // This is for plotting now, we are standardizing for 50 - 120 for(filt=0; filt<NFILTERS; filt++) { valmin[filt] = 50.0; valmax[filt] = 120.0; } plotSix(nFields, value, ravec, decvec, valmin, valmax, 1, "% of WFD visits", plotTitle, "SixVisits-All", 0); // now make histograms of completion for(filt=0; filt<NFILTERS; filt++) for(j=0; j<NHIST; j++) hist[filt][j] = 0; for(filt=0; filt<NFILTERS; filt++) { histmax[filt] = 0; histmin[filt] = 0; for(nf=0; nf<nFields; nf++) { if ((double)count[filt][nf]/(double)desired[filt] > 1.0 ) { histmax[filt]++; } else if ( count[filt][nf] == 0 ) { histmin[filt]++; } else { i = (int)((double)count[filt][nf]*10.0/(double)desired[filt]); hist[filt][i]++; } } } // intersection histogram for(j=0; j<NHIST; j++) { frac = (double)(j+1)/(double)NHIST; chist[j]=0; for(nf=0; nf<nFields; nf++) { flag = 1; for(filt=0; filt<NFILTERS; filt++) { if(count[filt][nf]<frac*desired[filt]) { flag = 0; break; } } if(flag==1) chist[j]++; } } /** * Making tex file for Six Visit */ FILE* tfp; char fName[80]; char s[100]; sprintf(fName, "../output/%s_%d_SixVisits-All.tex", hostname, sessionID); tfp = fopen(fName, "w"); fprintf(tfp, "\\begin{table}[H]{\\textbf{Frequency Distribution of Fields with Completeness}} \\\\ [1.0ex]\n"); fprintf(tfp, "\\begin{tabular*}{\\textwidth}{\\tblspace rrrrrrr}\n"); fprintf(tfp, "\\hline\n"); fprintf(tfp, "\\colhead{Percent Complete} &\n"); fprintf(tfp, "\\colhead{u} &\n"); fprintf(tfp, "\\colhead{g} &\n"); fprintf(tfp, "\\colhead{r} &\n"); fprintf(tfp, "\\colhead{i} &\n"); fprintf(tfp, "\\colhead{z} &\n"); fprintf(tfp, "\\colhead{y} \\\\ \n"); fprintf(tfp, "\\hline\n"); fprintf(tfp, "\\hline\n"); fprintf(tfp, "$N \\ge 100$ & "); for (filt=0; filt<NFILTERS; filt++) { if ( filt == NFILTERS - 1) { fprintf(tfp, "%4d \\\\", histmax[filt]); } else { fprintf(tfp, "%4d &", histmax[filt]); } } fprintf(tfp, "\n"); fprintf(quickfp, "All Fields &"); for(j=NHIST-1; j>=0; j--) { if ( j==0 ) { sprintf(s, "~~$%d \\le N < %d$ & ", j * NHIST, (j+1) * NHIST); } else { sprintf(s, "$%d \\le N < %d$ & ", j * NHIST, (j+1) * NHIST); } fprintf(tfp, "%s", s); for (filt=0; filt<NFILTERS; filt++) { if ( j == 9 ) { if ( filt == NFILTERS - 1) { fprintf(quickfp, "%4d \\\\", hist[filt][j] + histmax[filt]); } else { fprintf(quickfp, "%4d &", hist[filt][j] + histmax[filt]); } } if ( filt == NFILTERS - 1) { fprintf(tfp, "%4d \\\\", hist[filt][j]); } else { fprintf(tfp, "%4d &", hist[filt][j]); } } fprintf(tfp, "\n"); } /*fprintf(tfp, "~~~~~~~~~$N = 0$ & "); for (filt=0; filt<NFILTERS; filt++) { if ( filt == NFILTERS - 1) { fprintf(tfp, "%4d \\\\", histmin[filt]); } else { fprintf(tfp, "%4d &", histmin[filt]); } } fprintf(tfp, "\n");*/ fprintf(tfp, "\\hline\n"); fprintf(tfp, "\\hline\n"); fprintf(tfp, "\\end{tabular*}\n"); fprintf(tfp, "\\caption{The distribution of the number of fields with a given completeness for each filter. A fields completeness is given by the ratio of the number of visits to that field compared to the Scaled Design SRD number of visits. The N equals zero bin does not accurately represent the number of fields with no observations.}\n"); fprintf(tfp, "\\label{tab:FreqNumTable}\n"); fprintf(tfp, "\\end{table}\n"); fflush(tfp); fclose(tfp); /** * End of Making tex file for Six Visit */ printf("\nField Completeness:\n"); printf(" %% "); for(j=NHIST-1; j>=0; j--) printf("%4d ",(int)(100*(double)(j+1)/(double)NHIST)); printf("\n"); for(filt=0; filt<NFILTERS; filt++) { printf("%s ",filtername[filt]); for(j=NHIST-1; j>=0; j--) printf("%4d ",hist[filt][j]); printf("\n"); } printf("\nField Completeness (cumulative):\n"); printf(" %% "); for(j=NHIST-1; j>=0; j--) printf("%4d ",(int)(100*(double)(j+1)/(double)NHIST)); printf("\n"); for(filt=0; filt<NFILTERS; filt++) { printf("%s ",filtername[filt]); sum = 0; for(j=NHIST-1; j>=0; j--) { sum += hist[filt][j]; printf("%4d ",sum); hist[filt][j] = sum; } printf("\n"); } printf("all "); for(j=NHIST-1; j>=0; j--) printf("%4d ",chist[j]); printf("\n"); // plot of field completeness for(nf=0; nf<nFields; nf++) { least = 1.0; for(filt=0; filt<NFILTERS; filt++) { least = MIN(least,(double)count[filt][nf]/(double)desired[filt]); } value[0][nf] = least*100.0; } plotOne(nFields, value[0], ravec, decvec, 0.0, 100.0, "completed % in least-observed band", plotTitle, "completeness-all"); for(i=0; i<NFILTERS; i++) free(value[i]); free(value); free(decvec); free(ravec); for(i=0; i<NFILTERS; i++) free(count[i]); free(count); free(len); free(start); }