Code for ratio program.
// Ratio Program // This is a c++ program for ROOT that subtracts pedestals from two runs and finds their ratio, // one where one fiber is illuminated to one where all 8 fibers are illuminated. It creates a graph // with ratio on the vertical axis and phi bin on the horizontal axis. //==================================== //==================================== //==================================== float meancalc(int cent,float yval[],int offset){ float meanval=0; float N=0; int low=50; if (centDivide(3,4); gStyle->SetOptStat(0); c1->SetBorderMode(0); TString hFilea="/N/u1/bullinger/outLaser/pi"; hFilea+=runa; hFilea+=".hist.root"; TString hFileb="/N/u1/bullinger/outLaser/pi"; hFileb+=runb; hFileb+=".hist.root"; TString hFilec="/N/u1/bullinger/outLaser/pi"; hFilec+=peds; hFilec+=".hist.root"; fda=new TFile(hFilea); assert(fda->IsOpen()); fdb=new TFile(hFileb); assert(fdb->IsOpen()); fdc=new TFile(hFilec); assert(fdc->IsOpen()); int j=1; int i=1; int k,section; float N; float centa=0; float centb=0; float centc=0; int index; float meana[800]; float meanb[800]; float meanc[800]; float neta[65]; float div = 12; char ch; float ratio[800]; float ra[65],rb[65],rc[65],rd[65],re[65],rf[65],rg[65],rh[65],ri[65]; float rj[65],rk[65],rl[65]; int aa=0,bb=0,cc=0,dd=0,ee=0,ff=0,gg=0,hh=0,ii=0,jj=0,kk=0,ll=0; int index=1; TH2F *hd[14]; hd[1] = new TH2F("","",1,0,65,1,0,2); hd[2] = new TH2F("","",1,0,65,1,0,2); hd[3] = new TH2F("","",1,0,65,1,0,2); hd[4] = new TH2F("","",1,0,65,1,0,2); hd[5] = new TH2F("","",1,0,65,1,0,2); hd[6] = new TH2F("","",1,0,65,1,0,2); hd[7] = new TH2F("","",1,0,65,1,0,2); hd[8] = new TH2F("","",1,0,65,1,0,2); hd[9] = new TH2F("","",1,0,65,1,0,2); hd[10] = new TH2F("","",1,0,65,1,0,2); hd[11] = new TH2F("","",1,0,65,1,0,2); hd[12] = new TH2F("","",1,0,65,1,0,2); for (int k=1;k<=12;k++) { c1->cd(k); hd[k]->Draw(); } hd[1]->SetTitle("Eta=1"); hd[2]->SetTitle("Eta=2"); hd[3]->SetTitle("Eta=3"); hd[4]->SetTitle("Eta=4"); hd[5]->SetTitle("Eta=5"); hd[6]->SetTitle("Eta=6"); hd[7]->SetTitle("Eta=7"); hd[8]->SetTitle("Eta=8"); hd[9]->SetTitle("Eta=9"); hd[10]->SetTitle("Eta=10"); hd[11]->SetTitle("Eta=11"); hd[12]->SetTitle("Eta=12"); for (int d=0; d<60;d++){ neta[d]=d+1; } //Loop through all sec values 1 to 12 for (section=1;section<=12;section++) // Loop through all sub values 'A' to 'E' for (ch='A';ch<='E';ch++) // Loop through all eta values 1 to 12 for(index=1;index<=12;index++) { int sec=section,eta=index; char sub = ch; char namea[100]; char nameb[100]; sprintf(namea,"%02dT%c%02d",sec,sub,index); sprintf(nameb,"%02dT%c%02d",sec,sub,index); TH1F *ha=fda->Get(namea); assert(ha); TH1F *hb=fdb->Get(nameb); assert(hb); TH1F *hc=fdc->Get(namea); assert(hc); centa=ha->GetMaximumBin(); centb=hb->GetMaximumBin(); centc=hc->GetMaximumBin(); float *ya=ha->GetArray(); float *yb=hb->GetArray(); float *yc=hc->GetArray(); meana[j]=meancalc(centa,ya,50); meanb[j]=meancalc(centb,yb,50); meanc[j]=meancalc(centc,yc,5); meana[j]=meana[j]-meanc[j]; meanb[j]=meanb[j]-meanc[j]; // Flagging bad towers (with just pedestals). If mean a or b is around +/-10, set ratio to 0 if (((meana[j]>-10)&&(meana[j]<10))||((meanb[j]>-10)&&(meanb[j]<10))) { ratio[j]=0; printf("r=0 tower %s\n",namea); } else ratio[j]=meanb[j]/meana[j]; // If ratio = 1, output tower info (06TD11 is the only known case for this) if (ratio[j]==1) { printf("r=0 tower %s\n",namea); ratio[j]=0; } // If ratio is negative or greater than 1.9, output tower info and set equal to zero int cutoff=2; if (ratio[j]<0 || ratio[j]> cutoff) { printf("r=0 tower %s\n",namea); ratio[j]=0; } if (index==1) { ra[aa]=ratio[j]; // printf("ra[] = %f, aa= %d, tower %s\n",ra[aa],aa,namea); aa++; } if (index==2) { rb[bb]=ratio[j]; bb++; } if (index==3) { rc[cc]=ratio[j]; cc++; } if (index==4) { rd[dd]=ratio[j]; dd++; } if (index==5) { re[ee]=ratio[j]; ee++; } if (index==6) { rf[ff]=ratio[j]; ff++; } if (index==7) { rg[gg]=ratio[j]; gg++; } if (index==8) { rh[hh]=ratio[j]; hh++; } if (index==9) { ri[ii]=ratio[j]; ii++; } if (index==10) { rj[jj]=ratio[j]; jj++; } if (index==11) { rk[kk]=ratio[j]; kk++; } if (index==12) { rl[ll]=ratio[j]; ll++; } if (ratio[j]<0 ) printf("<0, ratio=%f,\n",ratio[j]); // if (ratio[j]<0.3) // printf("Ratio is %f tower is %s\n",ratio[j],namea); j++; } int mc = 4; TGraph *g1 = new TGraph(60,neta,ra); g1->SetMarkerStyle(7); g1->SetMarkerColor(mc); c1->cd(1); g1->Draw("P"); // g1->SetTitle("Eta=1"); TGraph *g2 = new TGraph(60,neta,rb); g2->SetMarkerStyle(7); g2->SetMarkerColor(mc); c1->cd(2); g2->Draw("P"); // g2->SetTitle("Eta=2"); TGraph *g3 = new TGraph(60,neta,rc); g3->SetMarkerStyle(7); g3->SetMarkerColor(mc); c1->cd(3); g3->Draw("P"); //g3->SetTitle("Eta=3"); TGraph *g4 = new TGraph(60,neta,rd); g4->SetMarkerStyle(7); g4->SetMarkerColor(mc); c1->cd(4); g4->Draw("P"); //g4 ->SetTitle("Eta=4"); TGraph *g5 = new TGraph(60,neta,re); g5->SetMarkerStyle(7); g5->SetMarkerColor(mc); c1->cd(5); g5->Draw("P"); //g5->SetTitle("Eta=5"); TGraph *g6 = new TGraph(60,neta,rf); g6->SetMarkerStyle(7); g6->SetMarkerColor(mc); c1->cd(6); g6->Draw("P"); //g6->SetTitle("Eta=6"); TGraph *g7 = new TGraph(60,neta,rg); g7->SetMarkerStyle(7); g7->SetMarkerColor(mc); c1->cd(7); g7->Draw("P"); //g7->SetTitle("Eta=7"); TGraph *g8 = new TGraph(60,neta,rh); g8->SetMarkerStyle(7); g8->SetMarkerColor(mc); c1->cd(8); g8->Draw("P"); //g8->SetTitle("Eta=8"); TGraph *g9 = new TGraph(60,neta,ri); g9->SetMarkerStyle(7); g9->SetMarkerColor(mc); c1->cd(9); g9->Draw("P"); //g9->SetTitle("Eta=9"); TGraph *g10 = new TGraph(60,neta,rj); g10->SetMarkerStyle(7); g10->SetMarkerColor(mc); c1->cd(10); g10->Draw("P"); //g10->SetTitle("Eta=10"); TGraph *g11 = new TGraph(60,neta,rk); g11->SetMarkerStyle(7); g11->SetMarkerColor(mc); c1->cd(11); g11->Draw("P"); //g11->SetTitle("Eta=11"); TGraph *g12 = new TGraph(60,neta,rl); g12->SetMarkerStyle(7); g12->SetMarkerColor(mc); c1->cd(12); g12->Draw("P"); //g12->SetTitle("Eta=12"); c1->cd(); return 0; }