void vncent_sys_ratio() { gROOT->Reset(); gROOT->SetStyle("MyStyle"); // gROOT->LoadMacro("v2pt_12cen_MyDef.C"); // gROOT->LoadMacro("MyDef.C"); gStyle->SetTextFont(43); gStyle->SetLabelFont(43,"x"); gStyle->SetLabelFont(43,"y"); gStyle->SetLabelFont(43,"z"); gStyle->SetTitleFont(43,"x"); gStyle->SetTitleFont(43,"y"); gStyle->SetTitleFont(43,"z"); gStyle->SetEndErrorSize(0); double textsize = 19; //int mcol[8]={kRed,kMagenta,kBlue,kCyan,kGreen,kYellow,kOrange,kGray}; int mcol[8]={kRed,kOrange+1,kBlue,kGreen+1,kCyan,kYellow,kOrange,kGray}; int mcol2[4]={6,2,4,8}; //int msty[8][2]={{20,20},{25,24},{22,22},{28,26},{29,30},{33,27},{34,28},{20,24}}; int msty[8][2]={{20,20},{21,24},{22,29},{23,30},{24,30},{25,27},{28,28},{30,24}}; //float msiz[8]={1.11,0.9,1.2,1.24,1.5,1,1,1}; float msiz[8]={1.11,1.0,1.5,1.2,1.2,1.2,1.2,1.6}; float msiz2[4]={1.5,1.5,1.5,1.5}; // // arrays // const int Mfiles=50; int ndp[Mfiles]; char *cfn[Mfiles]; char *cft[Mfiles]; const int Mpoints=40; double xa[Mfiles][Mpoints],xe[Mfiles][Mpoints]; double ya[Mfiles][Mpoints],ye[Mfiles][Mpoints]; double nAxa[Mfiles][Mpoints],nAxe[Mfiles][Mpoints]; double nAya[Mfiles][Mpoints],nAye[Mfiles][Mpoints]; double nBxa[Mfiles][Mpoints],nBxe[Mfiles][Mpoints]; double nBya[Mfiles][Mpoints],nBye[Mfiles][Mpoints]; double nARxa[Mfiles][Mpoints],nARxe[Mfiles][Mpoints]; double nARya[Mfiles][Mpoints],nARye[Mfiles][Mpoints]; double nBRxa[Mfiles][Mpoints],nBRxe[Mfiles][Mpoints]; double nBRya[Mfiles][Mpoints],nBRye[Mfiles][Mpoints]; double aexl[Mfiles][Mpoints],aexh[Mfiles][Mpoints]; double aeyl[Mfiles][Mpoints],aeyh[Mfiles][Mpoints]; double ra[Mfiles][Mpoints],re[Mfiles][Mpoints]; const int Mpads=14; char *htit[Mpads]; char *atit[Mpads][3]; double ptit[Mpads][2]; double hxmin[Mpads],hxmax[Mpads]; double hymin[Mpads],hymax[Mpads]; double lxmin[Mpads],lxmax[Mpads]; double lymin[Mpads],lymax[Mpads]; // // Data input // char *cjob="v2pt_12cen_4x3"; int i=-1; // histogram parameter htit[0]="(a) v_{4}{#Psi_{22}}"; htit[1]="(b) v_{5}{#Psi_{23}}"; htit[2]="(c) v_{6}{#Psi_{222}}"; htit[3]="(d) v_{6}{#Psi_{33}}"; htit[4]="(e) v_{7}{#Psi_{223}}"; htit[5]="25-30%"; htit[6]="30-35%"; htit[7]="35-40%"; htit[8]="40-50%"; htit[9]="50-60%"; htit[10]="60-70%"; htit[11]="70-80%"; for (int ip=0;ip<Mpads;ip++) { // hxmin[ip]=0.0; hxmax[ip]=11.9; hxmin[ip]=0.0001; hxmax[ip]=62.8; hymin[ip]=0.00001; hymax[ip]=0.0559; lxmin[ip]=0.24; lxmax[ip]=0.88; lymin[ip]=0.65; lymax[ip]=0.94; ptit[ip][0]=5.0; ptit[ip][1]=0.00002*0.92;// position legends atit[ip][0]="Centrality (%)"; atit[ip][1]="v_{n}"; } // // Read data and create vector files // double sysXYZ[5]={6,7,8,8,9}; //double sysXYZ[5]={9,9,13,13,15}; //double sysXYZ[5]={8,9,20,20,20}; double sysEach[5]={0.0002, 0.0002, 0.0002, 0.0003, 0.0002}; double tmp; const int nw=5; const int npt=14; const int npt_oli=8; ifstream inEP; inEP.open("./data_vncent5020_integral.txt"); for(int i=0; i<nw; i++){ for(int j=0; j<npt; j++){ inEP>>xa[i][j]; inEP>>ya[i][j]; inEP>>ye[i][j]; xe[i][j]=0.0; } } inEP.close(); ifstream inEP; inEP.open("./data_vncent5020_integral_esA.txt"); for(int i=0; i<nw; i++){ for(int j=0; j<npt; j++){ inEP>>nAxa[i][j]; inEP>>nAya[i][j]; inEP>>nAye[i][j]; nAxe[i][j]=0.0; nARxa[i][j]=nAxa[i][j]; nARxe[i][j]=nAxe[i][j]; nARye[i][j]=nAya[i][j]/ya[i][j]*sqrt(ye[i][j]*ye[i][j]/ya[i][j]/ya[i][j] + nAye[i][j]*nAye[i][j]/nAya[i][j]/nAya[i][j] - 1.0*ye[i][j]*ye[i][j]/ya[i][j]/nAya[i][j] ); nARya[i][j]=nAya[i][j]/ya[i][j]; nARya[i][j]=1+(nARya[i][j]-1)*0.2; nARye[i][j]=0+(nARye[i][j]-0)*0.2; nAya[i][j]=nARya[i][j]*ya[i][j]; //needed for the top panels! //if(nARya[i][j]>1.05) nARya[i][j]=nARya[i][j]-nARya[i][j]*0.1; //else nARya[i][j]=nARya[i][j]+nARya[i][j]*0.1; } } inEP.close(); ifstream inEP; inEP.open("./data_vncent5020_integral_esB.txt"); for(int i=0; i<nw; i++){ for(int j=0; j<npt; j++){ inEP>>nBxa[i][j]; inEP>>nBya[i][j]; inEP>>nBye[i][j]; nBxe[i][j]=0.0; nBRxa[i][j]=nBxa[i][j]; nBRxe[i][j]=nBxe[i][j]; nBRye[i][j]=nBya[i][j]/ya[i][j]*sqrt(ye[i][j]*ye[i][j]/ya[i][j]/ya[i][j] + nBye[i][j]*nBye[i][j]/nBya[i][j]/nBya[i][j] - 1.5*ye[i][j]*ye[i][j]/ya[i][j]/nBya[i][j] ); nBRya[i][j]=nBya[i][j]/ya[i][j]; nBRya[i][j]=1+(nBRya[i][j]-1)*0.2; nBRye[i][j]=0+(nBRye[i][j]-0)*0.2; nBya[i][j]=nBRya[i][j]*ya[i][j]; //needed for the top panels! cout<<"ratio A: "<<nARya[i][j]<<", Aerr = "<<nARye[i][j]<<", ratio B="<<nBRya[i][j]<<", Berr = "<<nBRye[i][j]<<endl; //if(nBRya[i][j]>1) nBRya[i][j]=nBRya[i][j]-nBRya[i][j]*0.1; //else nBRya[i][j]=nBRya[i][j]+nBRya[i][j]*0.1; } } inEP.close(); TCanvas *can=new TCanvas("can","can",10,10,1050*0.8*1.3,800*0.3*1.3 * 1.5); can->Divide(5,2,0,0); //sticks the pads with no space inbetween TH1D *h1[nw]; for (int iw=0;iw<nw;iw++) { can->cd(iw+1); if(iw==4) gPad->SetRightMargin(0.02); gPad->SetLogy(); char ch1[8]; sprintf(ch1,"h1_%d",iw); h1[iw] = new TH1D(ch1,"",500,hxmin[iw],hxmax[iw]); h1[iw]->SetMinimum(hymin[iw]); h1[iw]->SetMaximum(hymax[iw]); h1[iw]->SetXTitle(atit[iw][0]); h1[iw]->SetYTitle(atit[iw][1]); h1[iw]->GetXaxis()->CenterTitle(1); h1[iw]->GetYaxis()->CenterTitle(1); // futz with the axes h1[iw]->GetYaxis()->SetNdivisions(606); h1[iw]->GetXaxis()->SetNdivisions(606); h1[iw]->GetYaxis()->SetTitleSize(textsize); h1[iw]->GetYaxis()->SetTitleOffset(2.5); h1[iw]->GetYaxis()->SetLabelSize(textsize); h1[iw]->GetXaxis()->SetTitleSize(textsize); h1[iw]->GetXaxis()->SetTitleOffset(1.3); h1[iw]->GetXaxis()->SetLabelSize(textsize); // h1[iw]->GetXaxis()->SetLabelOffset(1.2); h1[iw]->Draw(); } // // Draw! // cout << "Now Draw!" << endl; TGraphErrors *ge, *geB, *ge2; for (int iw=0;iw<nw;iw++) { can->cd(iw+1); // if (iw==3) { tex=new TLatex(11,0.0100,"CMS Preliminary"); tex->SetTextSize(textsize*1.0); //tex->Draw(); } if (iw==0) { tex=new TLatex(5,0.00015,"Hydro. at #sqrt{s_{NN}}=2.76TeV"); tex->SetTextSize(textsize*0.85); //tex->Draw(); tex=new TLatex(7,0.00033,"|#eta|<2.4"); tex->SetTextSize(textsize*1.0); //tex->Draw(); tex=new TLatex(7,0.00012,"0.3<p_{T}<3.0 GeV/c"); tex->SetTextSize(textsize*1.0); //tex->Draw(); } //if (iw < 4) tex=new TLatex(ptit[iw][0]+2,0.27,htit[iw]); tex=new TLatex(ptit[iw][0],ptit[iw][1],htit[iw]); if ( iw == 0) tex->SetTextSize(textsize); else if (iw == 8) tex->SetTextSize(textsize); else tex->SetTextSize(textsize); tex->Draw(); // // Read data // TLegend *leg = new TLegend(lxmin[iw]*0.3,lymin[iw]*1.05,lxmax[iw]*1.15,lymax[iw]*1.02); leg->SetFillStyle(0); leg->SetFillColor(0); leg->SetTextSize(textsize); for (int im=0;im<1;im++) { int j=im*5+iw; int col=2; //if (ndp[j]==0) continue; ge=new TGraphErrors(10,&nAxa[j][0],&nAya[j][0],&nAxe[j][0],&nAye[j][0]); ///drawSysBoxValue(ge,16,1.6, ye5sys[j]); //drawSysBox(ge,16,2., sysXYZ[j]); ge->SetTitle(""); ge->SetMarkerStyle(24); // ge->SetMarkerStyle(msty[im]); ge->SetMarkerSize(msiz[im]); ge->SetMarkerColor(col); ge->SetLineWidth(1.2); ge->SetLineColor(col); //ge->Draw("pe"); leg->AddEntry(ge,"Evt. sel. eff. -2%","pl"); } for (int im=0;im<1;im++) { int j=im*5+iw; int col=4; //if (ndp[j]==0) continue; geB=new TGraphErrors(10,&nBxa[j][0],&nBya[j][0],&nBxe[j][0],&nBye[j][0]); ///drawSysBoxValue(ge,16,1.6, ye5sys[j]); //drawSysBox(ge,16,2., sysXYZ[j]); geB->SetTitle(""); geB->SetMarkerStyle(25); // ge->SetMarkerStyle(msty[im]); geB->SetMarkerSize(msiz[im]); geB->SetMarkerColor(col); geB->SetLineWidth(1.2); geB->SetLineColor(col); //ge->Draw("pe"); leg->AddEntry(geB,"Evt. sel. eff. +2%","pl"); } for (int im=0;im<1;im++) { int j=im*5+iw; int col=1; //if (ndp[j]==0) continue; ge2=new TGraphErrors(10,&xa[j][0],&ya[j][0],&xe[j][0],&ye[j][0]); ///drawSysBoxValue(ge2,16,1.6, yesys[j]); //drawSysBox(ge2,16,2., sysXYZ[j]); ge2->SetTitle(""); ge2->SetMarkerStyle(20); // ge2->SetMarkerStyle(msty[im]); ge2->SetMarkerSize(msiz[im]); ge2->SetMarkerColor(col); ge2->SetLineWidth(1.2); ge2->SetLineColor(col); //ge2->Draw("pe"); leg->AddEntry(ge2,"Default","pl"); } ge2->Draw("pe"); ge->Draw("pe"); geB->Draw("pe"); if (iw==2) leg->Draw(); } //start new TH1D *h2[nw]; for (int iw=0;iw<nw;iw++) { can->cd(iw+1+5); if(iw==4) gPad->SetRightMargin(0.02); //gPad->SetLogy(); char ch2[8]; sprintf(ch2,"h2_%d",iw); h2[iw] = new TH1D(ch2,"",500,hxmin[iw],hxmax[iw]); h2[iw]->SetMinimum(0.5); h2[iw]->SetMaximum(1.5); h2[iw]->SetXTitle(atit[iw][0]); h2[iw]->SetYTitle("v_{n} ratio"); h2[iw]->GetXaxis()->CenterTitle(1); h2[iw]->GetYaxis()->CenterTitle(1); h2[iw]->GetYaxis()->SetNdivisions(606); h2[iw]->GetXaxis()->SetNdivisions(606); h2[iw]->GetYaxis()->SetTitleSize(textsize); h2[iw]->GetYaxis()->SetTitleOffset(1.8); h2[iw]->GetYaxis()->SetLabelSize(textsize); h2[iw]->GetXaxis()->SetTitleSize(textsize); h2[iw]->GetXaxis()->SetTitleOffset(1.8); h2[iw]->GetXaxis()->SetLabelSize(textsize); h2[iw]->Draw(); } for (int iw=0;iw<nw;iw++) { can->cd(iw+5+1); // if (iw==3+5) { tex=new TLatex(11,0.0100,"CMS Preliminary"); tex->SetTextSize(textsize*1.0); //tex->Draw(); } if (iw==0+5) { tex=new TLatex(5,0.00015,"Hydro. at #sqrt{s_{NN}}=2.76TeV"); tex->SetTextSize(textsize*0.85); //tex->Draw(); tex=new TLatex(7,0.00033,"|#eta|<2.4"); tex->SetTextSize(textsize*1.0); //tex->Draw(); tex=new TLatex(7,0.00012,"0.3<p_{T}<3.0 GeV/c"); tex->SetTextSize(textsize*1.0); //tex->Draw(); } //if (iw < 4) tex=new TLatex(ptit[iw][0]+2,0.27,htit[iw]); //tex=new TLatex(10,0.9,htit[iw]); tex=new TLatex(10,0.9,"CMS"); if ( iw == 0) tex->SetTextSize(textsize); else if (iw == 8) tex->SetTextSize(textsize); else tex->SetTextSize(textsize); //tex->Draw(); // // Read data // TLegend *leg2 = new TLegend(lxmin[iw]*0.3,lymin[iw]*1.16,lxmax[iw]*1.15,lymax[iw]*1.02); leg2->SetFillStyle(0); leg2->SetFillColor(0); leg2->SetTextSize(textsize); for (int im=0;im<1;im++) { int j=im*5+iw; int col=2; //if (ndp[j]==0) continue; ge=new TGraphErrors(10,&nARxa[j][0],&nARya[j][0],&nARxe[j][0],&nARye[j][0]); ///drawSysBoxValue(ge,16,1.6, ye5sys[j]); //drawSysBox(ge,16,2., sysXYZ[j]); ge->SetTitle(""); ge->SetMarkerStyle(24); // ge->SetMarkerStyle(msty[im]); ge->SetMarkerSize(msiz[im]); ge->SetMarkerColor(col); ge->SetLineWidth(1.2); ge->SetLineColor(col); //ge->Draw("pe"); leg2->AddEntry(ge,"eff.(-2%)/Default","pl"); } for (int im=0;im<1;im++) { int j=im*5+iw; int col=4; //if (ndp[j]==0) continue; geB=new TGraphErrors(10,&nBRxa[j][0],&nBRya[j][0],&nBRxe[j][0],&nBRye[j][0]); ///drawSysBoxValue(ge,16,1.6, ye5sys[j]); //drawSysBox(ge,16,2., sysXYZ[j]); geB->SetTitle(""); geB->SetMarkerStyle(25); // ge->SetMarkerStyle(msty[im]); geB->SetMarkerSize(msiz[im]); geB->SetMarkerColor(col); geB->SetLineWidth(1.2); geB->SetLineColor(col); //ge->Draw("pe"); leg2->AddEntry(geB,"eff.(+2%)/Default","pl"); } ge->Draw("pe"); geB->Draw("pe"); if (iw==2) leg2->Draw(); TLine *lines = new TLine(0,1,60,1); lines->SetLineStyle(2); lines->SetLineWidth(1); lines->Draw(); if(iw==0||iw==1){ TF1 *fitFun = new TF1("fitFun","pol2", 0, 60); fitFun->SetLineColor(4); geB->Fit("fitFun","R+"); fitFun->Draw("same"); cout<<fitFun->Eval(2.5)<<", "<<fitFun->Eval(7.5)<<", "<<fitFun->Eval(45)<<", "<<fitFun->Eval(55)<<endl; } else { TF1 *fitFun = new TF1("fitFun","pol0", 0, 60); fitFun->SetLineColor(4); geB->Fit("fitFun","R+"); fitFun->Draw("same"); cout<<fitFun->Eval(2.5)<<", "<<fitFun->Eval(7.5)<<", "<<fitFun->Eval(45)<<", "<<fitFun->Eval(55)<<endl; } double chi2 = fitFun->GetChisquare(); double ndf = fitFun->GetNDF(); TLatex *tex = new TLatex(10.06,0.6,Form("#chi^{2}/ndf = %2.1f", chi2/ndf)); //tex->SetNDC(); //tex->SetTextFont(42); tex->SetTextColor(4); tex->SetTextSize(16); //tex->SetLineWidth(2); tex->Draw("same"); //TLatex *text = new TLatex(); //text->DrawTextNDC(10.12, 1.14, "D0 Preliminary"); /* double p0 = fitFun->GetParameter(0); double p0Err = fitFun->GetParError(0); TLine *linesErrP = new TLine(0,p0+p0Err,60,p0+p0Err); linesErrP->SetLineStyle(2); linesErrP->SetLineWidth(1); linesErrP->SetLineColor(2); linesErrP->Draw(); TLine *linesErrM = new TLine(0,p0-p0Err,60,p0-p0Err); linesErrM->SetLineStyle(2); linesErrM->SetLineWidth(1); linesErrM->SetLineColor(2); linesErrM->Draw(); */ } //end new can->cd(); TLatex * tex = new TLatex(0.06,0.97,"CMS"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.034); tex->SetLineWidth(2); tex->Draw(); TLatex * tex = new TLatex(0.108,0.97,"Preliminary"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.044); tex->SetLineWidth(2); //tex->Draw(); TLatex * tex = new TLatex(0.24,0.970,"0.3<p_{T}<3.0 GeV/c |#eta|<0.8"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.044); tex->SetLineWidth(2); tex->Draw(); cout << "end of process" << endl; can->cd(); can->Print("./figures/plot_vncent_esSys_ratio.png"); can->Print("./figures/plot_vncent_esSys_ratio.pdf"); }
// Soft radiation corrections for L3Res void softrad(double etamin=0.0, double etamax=1.3, bool dodijet=false) { setTDRStyle(); writeExtraText = false; // for JEC paper CWR TDirectory *curdir = gDirectory; // Open jecdata.root produced by reprocess.C TFile *fin = new TFile("rootfiles/jecdata.root","UPDATE"); assert(fin && !fin->IsZombie()); const int ntypes = 3; const char* types[ntypes] = {"data", "mc", "ratio"}; const int nmethods = 2; const char* methods[nmethods] = {"mpfchs1", "ptchs"}; const int nsamples = (dodijet ? 4 : 3); const char* samples[4] = {"gamjet", "zeejet", "zmmjet", "dijet"}; string sbin = Form("eta%02.0f-%02.0f",10*etamin,10*etamax); const char* bin = sbin.c_str(); const int nalphas = 4; const int alphas[nalphas] = {30, 20, 15, 10}; // Z+jet bins const double ptbins1[] = {30, 40, 50, 60, 75, 95, 125, 180, 300, 1000}; const int npt1 = sizeof(ptbins1)/sizeof(ptbins1[0])-1; TH1D *hpt1 = new TH1D("hpt1","",npt1,&ptbins1[0]); TProfile *ppt1 = new TProfile("ppt1","",npt1,&ptbins1[0]); // gamma+jet bins const double ptbins2[] = {30, 40, 50, 60, 75, 100, 125, 155, 180, 210, 250, 300, 350, 400, 500, 600, 800}; const int npt2 = sizeof(ptbins2)/sizeof(ptbins2[0])-1; TH1D *hpt2 = new TH1D("hpt2","",npt2,&ptbins2[0]); TProfile *ppt2 = new TProfile("ppt2","",npt2,&ptbins2[0]); // dijet bins const double ptbins4[] = {20, 62, 107, 175, 242, 310, 379, 467, 628, 839, 1121, 1497, 2000}; const int npt4 = sizeof(ptbins4)/sizeof(ptbins4[0])-1; TH1D *hpt4 = new TH1D("hpt4","",npt4,&ptbins4[0]); TProfile *ppt4 = new TProfile("ppt4","",npt4,&ptbins4[0]); TLatex *tex = new TLatex(); tex->SetNDC(); tex->SetTextSize(0.045); map<string,const char*> texlabel; texlabel["gamjet"] = "#gamma+jet"; texlabel["zeejet"] = "Z#rightarrowee+jet"; texlabel["zmmjet"] = "Z#rightarrow#mu#mu+jet"; texlabel["dijet"] = "Dijet"; texlabel["ptchs"] = "p_{T} balance (CHS)"; texlabel["mpfchs"] = "MPF raw (CHS)"; texlabel["mpfchs1"] = "MPF type-I (CHS)"; // overlay of various alpha values TCanvas *c1 = new TCanvas("c1","c1",ntypes*400,nmethods*400); c1->Divide(ntypes,nmethods); TH1D *h1 = new TH1D("h1",";p_{T} (GeV);Response",1270,30,1300); // extrapolation vs alpha for each pT bin vector<TCanvas*> c2s(ntypes*nmethods); for (unsigned int icanvas = 0; icanvas != c2s.size(); ++icanvas) { TCanvas *c2 = new TCanvas(Form("c2_%d",icanvas),Form("c2_%d",icanvas), 1200,1200); c2->Divide(3,3); c2s[icanvas] = c2; } TH1D *h2 = new TH1D("h2",";#alpha;Response",10,0.,0.4); h2->SetMaximum(1.08); h2->SetMinimum(0.88); // krad corrections TCanvas *c3 = new TCanvas("c3","c3",ntypes*400,nmethods*400); c3->Divide(ntypes,nmethods); TH1D *h3 = new TH1D("h3",";p_{T,ref} (GeV);FSR sensitivity: -dR/d#alpha [%]", 1270,30,1300); cout << "Reading in data" << endl << flush; // Read in plots vs pT (and alpha) map<string, map<string, map<string, map<int, TGraphErrors*> > > > gemap; map<string, map<string, map<string, map<int, TGraphErrors*> > > > gamap; for (int itype = 0; itype != ntypes; ++itype) { for (int imethod = 0; imethod != nmethods; ++imethod) { for (int isample = 0; isample != nsamples; ++isample) { for (int ialpha = 0; ialpha != nalphas; ++ialpha) { fin->cd(); assert(gDirectory->cd(types[itype])); assert(gDirectory->cd(bin)); TDirectory *d = gDirectory; const char *ct = types[itype]; const char *cm = methods[imethod]; const char *cs = samples[isample]; const int a = alphas[ialpha]; // Get graph made vs pT string s = Form("%s/%s/%s_%s_a%d",types[itype],bin,cm,cs,a); TGraphErrors *g = (TGraphErrors*)fin->Get(s.c_str()); if (!g) cout << "Missing " << s << endl << flush; assert(g); // Clean out empty points // as well as trigger-biased ones for dijets // as well as weird gamma+jet high pT point for (int i = g->GetN()-1; i != -1; --i) { if (g->GetY()[i]==0 || g->GetEY()[i]==0 || (string(cs)=="dijet" && g->GetX()[i]<70.) || (string(cs)=="gamjet" && g->GetX()[i]>600. && etamin!=0)) g->RemovePoint(i); } gemap[ct][cm][cs][a] = g; // Sort points into new graphs vs alpha TH1D *hpt = (isample==0 ? hpt2 : hpt1); TProfile *ppt = (isample==0 ? ppt2 : ppt1); if (isample==3) { hpt = hpt4; ppt = ppt4; } // pas-v6 for (int i = 0; i != g->GetN(); ++i) { double pt = g->GetX()[i]; ppt->Fill(pt, pt); int ipt = int(hpt->GetBinLowEdge(hpt->FindBin(pt))+0.5); //int ipt = int(pt+0.5); TGraphErrors *ga = gamap[ct][cm][cs][ipt]; if (!ga) { ga = new TGraphErrors(0); ga->SetMarkerStyle(g->GetMarkerStyle()); ga->SetMarkerColor(g->GetMarkerColor()); ga->SetLineColor(g->GetLineColor()); gamap[ct][cm][cs][ipt] = ga; } int n = ga->GetN(); ga->SetPoint(n, 0.01*a, g->GetY()[i]); ga->SetPointError(n, 0, g->GetEY()[i]); } // for i } // for ialpha } // for isample } // for imethod } // for itype cout << "Drawing plots vs pT for each alpha" << endl << flush; // 2x6 plots for (int itype = 0; itype != ntypes; ++itype) { for (int imethod = 0; imethod != nmethods; ++imethod) { const char *ct = types[itype]; const char *cm = methods[imethod]; int ipad = ntypes*imethod + itype + 1; assert(ipad<=6); c1->cd(ipad); gPad->SetLogx(); h1->SetMaximum(itype<2 ? 1.15 : 1.08); h1->SetMinimum(itype<2 ? 0.85 : 0.93); h1->SetYTitle(Form("Response (%s)",ct)); h1->DrawClone("AXIS"); tex->DrawLatex(0.20,0.85,texlabel[cm]); tex->DrawLatex(0.20,0.80,"|#eta| < 1.3, #alpha=0.1--0.3"); TLegend *leg = tdrLeg(0.60,0.75,0.90,0.90); for (int isample = 0; isample != nsamples; ++isample) { for (int ialpha = 0; ialpha != nalphas; ++ialpha) { const char *cs = samples[isample]; const int a = alphas[ialpha]; TGraphErrors *g = gemap[ct][cm][cs][a]; assert(g); // Clean out points with very large uncertainty for plot readability for (int i = g->GetN()-1; i != -1; --i) { if (g->GetEY()[i]>0.02) g->RemovePoint(i); } g->Draw("SAME Pz"); if (ialpha==0) leg->AddEntry(g,texlabel[cs],"P"); } } // for isample // Individual plots for JEC paper if ( true ) { // paper TH1D *h = new TH1D(Form("h_5%s_%s",ct,cm), Form(";p_{T} (GeV);Response (%s)",ct), 1270,30,1300); h->GetXaxis()->SetMoreLogLabels(); h->GetXaxis()->SetNoExponent(); h->SetMinimum(0.88); h->SetMaximum(1.13); writeExtraText = true; extraText = (string(ct)=="mc" ? "Simulation" : ""); lumi_8TeV = (string(ct)=="mc" ? "" : "19.7 fb^{-1}"); TCanvas *c0 = tdrCanvas(Form("c0_%s_%s",cm,ct), h, 2, 11, true); c0->SetLogx(); TLegend *leg = tdrLeg(0.55,0.68,0.85,0.83); tex->DrawLatex(0.55,0.85,texlabel[cm]); tex->DrawLatex(0.55,0.18,"|#eta| < 1.3, #alpha=0.3"); //tex->DrawLatex(0.55,0.18,"Anti-k_{T} R=0.5"); // Loop over Z+jet and gamma+jet (only, no dijet/multijet) for (int isample = 0; isample != min(3,nsamples); ++isample) { const char *cs = samples[isample]; TGraphErrors *g = gemap[ct][cm][cs][30]; assert(g); g->Draw("SAME Pz"); leg->AddEntry(g,texlabel[cs],"P"); } // for isample if (etamin==0) { c0->SaveAs(Form("pdf/paper_softrad_%s_%s_vspt.pdf",ct,cm)); c0->SaveAs(Form("pdfC/paper_softrad_%s_%s_vspt.C",ct,cm)); } else { c0->SaveAs(Form("pdf/an_softrad_%s_%s_eta%1.0f-%1.0f_vspt.pdf", ct,cm,10*etamin,10*etamax)); } } // paper } // for imethod } // for itype c1->cd(0); //cmsPrel(_lumi, true); CMS_lumi(c1, 2, 33); c1->SaveAs("pdf/softrad_2x6_vspt.pdf"); cout << "Drawing plots vs alpha for each pT" << endl << flush; cout << "...and fitting slope vs alpha" << endl << flush; map<string, map<string, map<string, TGraphErrors* > > > gkmap; // 2x6 plots for (int itype = 0; itype != ntypes; ++itype) { for (int imethod = 0; imethod != nmethods; ++imethod) { int icanvas = nmethods*imethod + itype; assert(icanvas<=6); TCanvas *c2 = c2s[icanvas]; assert(c2); const char *ct = types[itype]; const char *cm = methods[imethod]; const int npads = 9; for (int ipad = 0; ipad != npads; ++ipad) { c2->cd(ipad+1); h2->SetYTitle(Form("Response (%s)",ct)); h2->DrawClone("AXIS"); tex->DrawLatex(0.20,0.85,texlabel[cm]); tex->DrawLatex(0.20,0.80,"|#eta| < 1.3"); tex->DrawLatex(0.20,0.75,Form("%1.0f < p_{T} < %1.0f GeV", hpt1->GetBinLowEdge(ipad+1), hpt1->GetBinLowEdge(ipad+2))); TLegend *leg = tdrLeg(0.65,0.75,0.90,0.90); leg->AddEntry(gemap[ct][cm]["gamjet"][30], texlabel["gamjet"], "P"); leg->AddEntry(gemap[ct][cm]["zeejet"][30], texlabel["zeejet"], "P"); leg->AddEntry(gemap[ct][cm]["zmmjet"][30], texlabel["zmmjet"], "P"); leg->AddEntry(gemap[ct][cm]["dijet"][30], texlabel["dijet"], "P"); } for (int isample = 0; isample != nsamples; ++isample) { const char *cs = samples[isample]; map<int, TGraphErrors*> &gam = gamap[ct][cm][cs]; map<int, TGraphErrors*>::iterator itpt; for (itpt = gam.begin(); itpt != gam.end(); ++itpt) { int ipt = itpt->first; int jpt = hpt1->FindBin(ipt); if (jpt>npads) continue; assert(jpt<=npads); c2->cd(jpt); TGraphErrors *ga = itpt->second; assert(ga); ga->Draw("SAME Pz"); // Fit slope TF1 *f1 = new TF1(Form("f1_%s_%s_%s_%d",ct,cm,cs,ipt), "(x<1)*([0]+[1]*x) + (x>1 && x<2)*[0] +" "(x>2)*[1]",-1,1); f1->SetLineColor(ga->GetLineColor()); f1->SetParameters(1,0); const double minalpha = (isample==0 ? 10./ipt : 5./ipt); // Constrain slope to within reasonable values // in the absence of sufficient data using priors if (true) { // use priors int n = ga->GetN(); // For response, limit to 1+/-0.02 (we've corrected for L3Res ga->SetPoint(n, 1.5, 1); ga->SetPointError(n, 0, 0.02); n = ga->GetN(); if (imethod==1) { // pT balance // For pT balance, estimate slope of <vecpT2>/alpha from data // => 7.5%/0.30 = 25% // Approximate uncertainty on this to be // 0.5%/0.30 ~ 1.5% for data, 0.5%/0.30 ~ 1.5% for Z+jet MC, and // 2%/0.30 ~ 6% for gamma+jet MC (same as slope) if (itype==0) ga->SetPoint(n, 2.5, -0.250); // DT if (itype==1 && isample!=0) ga->SetPoint(n, 2.5, -0.250); // MC if (itype==1 && isample==0) ga->SetPoint(n, 2.5, -0.190); if (itype==2 && isample!=0) ga->SetPoint(n, 2.5, -0.000); // rt if (itype==2 && isample==0) ga->SetPoint(n, 2.5, -0.060); // // BUG: found 2015-01-08 (no effect on ratio) //if (itype==1) ga->SetPointError(n, 0, -0.015); if (itype==0) ga->SetPointError(n, 0, -0.015); // DT if (itype==1 && isample!=0) ga->SetPointError(n, 0, -0.015); // MC if (itype==1 && isample==0) ga->SetPointError(n, 0, -0.060); if (itype==2 && isample!=0) ga->SetPointError(n, 0, -0.015); // rt if (itype==2 && isample==0) ga->SetPointError(n, 0, -0.060); } if (imethod==0) { // MPF // For MPF, expectation is no slope // Maximal slope would be approximately // (<vecpT2>/alpha ~ 25% from pT balance) times // (response difference between pT1 and vecpT2~10%) // => 0.25*0.10 = 2.5% // For data/MC, estimate uncertainty as half of this // => 1.25% ga->SetPoint(n, 2.5, 0.); if (itype!=2) ga->SetPointError(n, 0, 0.025); if (itype==2) ga->SetPointError(n, 0, 0.0125); } // MPF } // use priors if (ga->GetN()>2) { f1->SetRange(minalpha, 3.); ga->Fit(f1,"QRN"); if (f1->GetNDF()>=0) { f1->DrawClone("SAME"); f1->SetRange(0,0.4); f1->SetLineStyle(kDashed); f1->DrawClone("SAME"); // Store results TGraphErrors *gk = gkmap[ct][cm][cs]; if (!gk) { gk = new TGraphErrors(0); gk->SetMarkerStyle(ga->GetMarkerStyle()); gk->SetMarkerColor(ga->GetMarkerColor()); gk->SetLineColor(ga->GetLineColor()); gkmap[ct][cm][cs] = gk; } int n = gk->GetN(); TProfile *ppt = (isample==0 ? ppt2 : ppt1); if (isample==3) { ppt = ppt4; } // pas-v6 double pt = ppt->GetBinContent(ppt->FindBin(ipt)); gk->SetPoint(n, pt, f1->GetParameter(1)); gk->SetPointError(n, 0, f1->GetParError(1)); } // f1->GetNDF()>=0 } // ga->GetN()>2 } // for itpt } // for isample c2->SaveAs(Form("pdf/softrad_3x3_%s_%s_vsalpha.pdf",ct,cm)); } } cout << "Drawing plots of kFSR vs pT" << endl; // 2x6 plots for (int itype = 0; itype != ntypes; ++itype) { for (int imethod = 0; imethod != nmethods; ++imethod) { const char *ct = types[itype]; const char *cm = methods[imethod]; TMultiGraph *mgk = new TMultiGraph(); int ipad = ntypes*imethod + itype + 1; assert(ipad<=6); c3->cd(ipad); gPad->SetLogx(); h3->SetMaximum(imethod==0 ? 0.05 : (itype!=2 ? 0.1 : 0.25)); h3->SetMinimum(imethod==0 ? -0.05 : (itype!=2 ? -0.4 : -0.25)); h3->SetYTitle(Form("k_{FSR} = dR/d#alpha (%s)",ct)); h3->DrawClone("AXIS"); tex->DrawLatex(0.20,0.85,texlabel[cm]); tex->DrawLatex(0.20,0.80,"|#eta| < 1.3"); TLegend *leg = tdrLeg(0.60,0.75,0.90,0.90); for (int isample = 0; isample != nsamples; ++isample) { const char *cs = samples[isample]; TGraphErrors *gk = gkmap[ct][cm][cs]; assert(gk); leg->AddEntry(gk,texlabel[cs],"P"); // Fit each sample separately for pT balance if (true) { TF1 *fk = new TF1(Form("fk_%s_%s_%s",ct,cm,cs), "[0]+[1]*log(0.01*x)+[2]*pow(log(0.01*x),2)", 30,1300); fk->SetParameters(-0.25,-0.5); fk->SetLineColor(gk->GetLineColor()); gk->Fit(fk, "QRN"); tex->SetTextColor(fk->GetLineColor()); tex->DrawLatex(0.55,0.27-0.045*isample, Form("#chi^{2}/NDF = %1.1f / %d", fk->GetChisquare(), fk->GetNDF())); tex->SetTextColor(kBlack); // Error band const int n = fk->GetNpar(); TMatrixD emat(n,n); gMinuit->mnemat(emat.GetMatrixArray(), n); TF1 *fke = new TF1(Form("fk_%s_%s_%s",ct,cm,cs), sr_fitError, 30, 1300, 1); _sr_fitError_func = fk; _sr_fitError_emat = &emat; fke->SetLineStyle(kSolid); fke->SetLineColor(fk->GetLineColor()-10); fke->SetParameter(0,-1); fke->DrawClone("SAME"); fke->SetParameter(0,+1); fke->DrawClone("SAME"); fk->DrawClone("SAME"); gk->DrawClone("SAME Pz"); // Store soft radiation corrections in fsr subdirectory assert(fin->cd(ct)); assert(gDirectory->cd(bin)); if (!gDirectory->FindObject("fsr")) gDirectory->mkdir("fsr"); assert(gDirectory->cd("fsr")); TH1D *hk = (TH1D*)(isample==0 ? hpt2->Clone() : hpt1->Clone()); hk->SetName(Form("hkfsr_%s_%s",cm,cs)); TProfile *ppt = (isample==0 ? ppt2 : ppt1); if (isample==3) { ppt = ppt4; } // pas-v6 for (int i = 1; i != hk->GetNbinsX()+1; ++i) { double pt = ppt->GetBinContent(i); if (pt>30 && pt<1300) { hk->SetBinContent(i, fk->Eval(pt)); hk->SetBinError(i, fabs(fke->Eval(pt)-fk->Eval(pt))); } else { hk->SetBinContent(i, 0); hk->SetBinError(i, 0); } } hk->Write(hk->GetName(), TObject::kOverwrite); // Factorize error matrix into eigenvectors // Remember: A = Q*Lambda*Q^-1, where // A is emat, Q is eigmat, and Lambda is a diagonal matrix with // eigenvalues from eigvec on the diagonal. For eigenmatrix // Q^-1 = Q^T, i.e. inverse matrix is the original transposed TVectorD eigvec(n); TMatrixD eigmat = emat.EigenVectors(eigvec); // Eigenvectors are the columns and sum of eigenvectors squared // equals original uncertainty. Calculate histograms from the // eigenvectors and store them TF1 *fkeig = (TF1*)fk->Clone(Form("%s_eig",fk->GetName())); fkeig->SetLineStyle(kDotted); for (int ieig = 0; ieig != n; ++ieig) { // Eigenvector functions for (int i = 0; i != n; ++i) { fkeig->SetParameter(i, fk->GetParameter(i) + eigmat[i][ieig] * sqrt(eigvec[ieig])); } fkeig->DrawClone("SAMEL"); // Eigenvector histograms evaluated at bin mean pT TH1D *hke = (TH1D*)hk->Clone(Form("%s_eig%d",hk->GetName(),ieig)); hke->Reset(); for (int i = 0; i != gk->GetN(); ++i) { double pt = gk->GetX()[i]; int ipt = hke->FindBin(pt); // Need to store central value as well, because // uncertainty sources are signed hke->SetBinContent(ipt, fkeig->Eval(pt)-fk->Eval(pt)); hke->SetBinError(ipt, fabs(fkeig->Eval(pt)-fk->Eval(pt))); } hke->Write(hke->GetName(), TObject::kOverwrite); } cout << "." << flush; } // if tree } // for isample } // for imethod } // for itype c3->cd(0); //cmsPrel(_lumi, true); CMS_lumi(c3, 2, 33); c3->SaveAs("pdf/softrad_2x6_kfsr.pdf"); fin->Close(); curdir->cd(); } // softrad
void makeTrees_MuTau( int index = 0 ){ cout << "Now analyzing sample with index " << index << endl; TFile corrections("../data/corrections.root"); TF1 *ratioMuIDIsoBL = (TF1*)corrections.Get("ratioMuIDIsoBL"); TF1 *ratioMuIDIsoEC = (TF1*)corrections.Get("ratioMuIDIsoEC"); TF1 *ratioMuHLTBL = (TF1*)corrections.Get("ratioMuHLTBL"); TF1 *ratioMuHLTEC = (TF1*)corrections.Get("ratioMuHLTEC"); TF1 *ratioTauHLTBL = (TF1*)corrections.Get("ratioTauHLTBL"); TF1 *ratioTauHLTEC = (TF1*)corrections.Get("ratioTauHLTEC"); typedef ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > LV; std::vector<std::string> samples; std::vector<float> crossSec; // samples & x-sections & skim1 samples.push_back("Data"); crossSec.push_back( 0 ); samples.push_back("DYJets"); crossSec.push_back( 3048.0 * 0.00963); samples.push_back("TTJets"); crossSec.push_back( 157.5 * 0.0210); samples.push_back("WJets"); crossSec.push_back( 31314.0 * 0.00126); samples.push_back("VBFH130"); crossSec.push_back( 0.0632 * 0.066); samples.push_back("GGFH130"); crossSec.push_back( 0.774 * 0.055); samples.push_back("QCD"); crossSec.push_back( 641 ); // normalization Lumi Float_t Lumi= 100; string currentSample = samples[index]; TString sample(currentSample.c_str()); TString outName = "treeSkimmedMuTau_"+sample+".root"; TFile *outFile = new TFile(outName,"UPDATE"); TTree* outTreePtOrd = new TTree("outTreePtOrd","tree"); // kinematical variables of leading and trailing jet (ordered by pt) // pt, eta, |eta1-eta2|, mass of the di-jet system, azimuthal angle, phi1-phi2 float pt1,pt2,eta1,eta2,Deta,Mjj,Dphi,phi1,phi2; // number of jets above 30 or 20 GeV int nJets30, nJets20; // pt, eta and phi of the third veto float ptVeto, etaVeto, phiVeto; // bool saying if the third jet lies within the leading and trailing jets int isVetoInJets; // diTau related variables // full mass of the di-tau float diTauSVFitMass; // visible mass, pt , eta and phi of the di-tau float diTauVisMass,diTauVisPt,diTauVisEta,diTauVisPhi; // taus/MET related variables // pt and eta of the muon (1) and tau (2) float ptL1,ptL2,etaL1,etaL2,phiL1,phiL2,dPhiL1L2; // As in the input TTree.. float diTauCharge_; // As in the input TTree.. float MtLeg1_; // MET pt float MEt; // relative isolation variable: w/o and w/ pile-up correction float combRelIsoLeg1DBeta; // As in the input TTree.. int tightestHPSDBWP_, decayMode_; float visibleTauMass_; // event-related variables // numnber of reconstructed vertices float numPV_ ; // weight to normalize the sample to 100pb-1 float sampleWeight; // pile-up reweighting float puWeight; // Higgs boson pt spectrum reweighting float HqTWeight; // object-related weights and triggers // trigger bit: 1=FIRED ; 0=NOT FIRED float HLTx; // trigger matching: 1=MATCHED; 0=UNMATCHED float HLTmatch; // Trigger turn-on correction float HLTweightTau, HLTweightMu; // Muon and tau isolation(X)identification data/MC scale factor float SFMu, SFTau; // As in the input TTree.. int muFlag_; // As in the input TTree.. int genDecay_; // As in the input TTree.. ULong64_t event_,run_,lumi_; outTreePtOrd->Branch("pt1", &pt1,"pt1/F"); outTreePtOrd->Branch("pt2", &pt2,"pt2/F"); outTreePtOrd->Branch("eta1", &eta1,"eta1/F"); outTreePtOrd->Branch("eta2", &eta2,"eta2/F"); outTreePtOrd->Branch("phi1", &phi1,"phi1/F"); outTreePtOrd->Branch("phi2", &phi2,"phi2/F"); outTreePtOrd->Branch("Deta", &Deta,"Deta/F"); outTreePtOrd->Branch("Dphi", &Dphi,"Dphi/F"); outTreePtOrd->Branch("Mjj", &Mjj,"Mjj/F"); outTreePtOrd->Branch("nJets30", &nJets30, "nJets30/I"); outTreePtOrd->Branch("nJets20", &nJets20, "nJets20/I"); outTreePtOrd->Branch("ptVeto", &ptVeto, "ptVeto/F"); outTreePtOrd->Branch("phiVeto", &phiVeto,"phiVeto/F"); outTreePtOrd->Branch("etaVeto", &etaVeto,"etaVeto/F"); outTreePtOrd->Branch("isVetoInJets", &isVetoInJets,"isVetoInJets/I"); outTreePtOrd->Branch("diTauSVFitMass",&diTauSVFitMass,"diTauSVFitMass/F"); outTreePtOrd->Branch("diTauVisMass",&diTauVisMass,"diTauVisMass/F"); outTreePtOrd->Branch("diTauVisPt", &diTauVisPt,"diTauVisPt/F"); outTreePtOrd->Branch("diTauVisEta", &diTauVisEta,"diTauVisEta/F"); outTreePtOrd->Branch("diTauVisPhi", &diTauVisPhi,"diTauVisPhi/F"); outTreePtOrd->Branch("etaL1", &etaL1,"etaL1/F"); outTreePtOrd->Branch("etaL2", &etaL2,"etaL2/F"); outTreePtOrd->Branch("ptL1", &ptL1,"ptL1/F"); outTreePtOrd->Branch("ptL2", &ptL2,"ptL2/F"); outTreePtOrd->Branch("phiL1", &phiL1,"phiL1/F"); outTreePtOrd->Branch("phiL2", &phiL2,"phiL2/F"); outTreePtOrd->Branch("dPhiL1L2",&dPhiL1L2,"dPhiL1L2/F"); outTreePtOrd->Branch("diTauCharge", &diTauCharge_,"diTauCharge/F"); outTreePtOrd->Branch("MtLeg1", &MtLeg1_,"MtLeg1/F"); outTreePtOrd->Branch("MEt", &MEt,"MEt/F"); outTreePtOrd->Branch("combRelIsoLeg1DBeta",&combRelIsoLeg1DBeta,"combRelIsoLeg1DBeta/F"); outTreePtOrd->Branch("tightestHPSDBWP", &tightestHPSDBWP_,"tightestHPSDBWP/I"); outTreePtOrd->Branch("decayMode", &decayMode_,"decayMode/I"); outTreePtOrd->Branch("visibleTauMass",&visibleTauMass_,"visibleTauMass/F"); outTreePtOrd->Branch("numPV", &numPV_,"numPV/F"); outTreePtOrd->Branch("sampleWeight", &sampleWeight,"sampleWeight/F"); outTreePtOrd->Branch("puWeight", &puWeight,"puWeight/F"); outTreePtOrd->Branch("HqTWeight", &HqTWeight,"HqTWeight/F"); outTreePtOrd->Branch("HLTx", &HLTx, "HLTx/F"); outTreePtOrd->Branch("HLTmatch", &HLTmatch,"HLTmatch/F"); outTreePtOrd->Branch("HLTweightMu", &HLTweightMu,"HLTweightMu/F"); outTreePtOrd->Branch("HLTweightTau", &HLTweightTau,"HLTweightTau/F"); outTreePtOrd->Branch("SFTau", &SFTau,"SFTau/F"); outTreePtOrd->Branch("SFMu", &SFMu,"SFMu/F"); outTreePtOrd->Branch("muFlag", &muFlag_,"muFlag/I"); outTreePtOrd->Branch("genDecay", &genDecay_,"genDecay/I"); outTreePtOrd->Branch("event",&event_,"event/l"); outTreePtOrd->Branch("run", &run_, "run/l"); outTreePtOrd->Branch("lumi", &lumi_, "lumi/l"); string currentInName = "./treeMuTau_"+samples[index]+".root" ; TString inName(currentInName.c_str()); TFile* file = new TFile(inName,"READ"); if(file->IsZombie()){ cout << "No such file!" << endl; return; } TString treeName("muTauAnalyzer/tree"); TTree* currentTree = (TTree*)file->Get(treeName); int nEntries = currentTree->GetEntries() ; int nEventsRead = ((TH1F*)file->Get("allEventsFilter/totalEvents"))->GetBinContent(1) ; float crossSection = crossSec[index] ; float scaleFactor = (crossSection != 0) ? Lumi / ( float(nEventsRead)/crossSection ) : 1.0; cout << "Processing sample " << sample.Data() << endl; cout<< "nEventsRead = " << nEventsRead << endl; cout<< "nEntries = " << nEntries << endl; cout<< "crossSection " << crossSection << " pb ==> scaleFactor " << scaleFactor << endl; // jets currentTree->SetBranchStatus("jetsIDP4" ,1); currentTree->SetBranchStatus("genJetsIDP4" ,0); // diTaus currentTree->SetBranchStatus("diTauVisP4" ,1); currentTree->SetBranchStatus("diTauSVfitP4" ,1); currentTree->SetBranchStatus("diTauCharge" ,1); // taus currentTree->SetBranchStatus("diTauLegsP4" ,1); currentTree->SetBranchStatus("genDiTauLegsP4" ,1); currentTree->SetBranchStatus("chIsoLeg1v2" ,1); currentTree->SetBranchStatus("nhIsoLeg1v2" ,1); currentTree->SetBranchStatus("phIsoLeg1v2" ,1); currentTree->SetBranchStatus("nhIsoPULeg1v2" ,1); currentTree->SetBranchStatus("decayMode" ,1); currentTree->SetBranchStatus("tightestHPSDBWP" ,1); currentTree->SetBranchStatus("visibleTauMass" ,1); currentTree->SetBranchStatus("isTauLegMatched" ,0); currentTree->SetBranchStatus("isMuLegMatched" ,0); currentTree->SetBranchStatus("signalPFChargedHadrCands" ,1); currentTree->SetBranchStatus("signalPFGammaCands" ,1); // MET currentTree->SetBranchStatus("METP4" ,1); currentTree->SetBranchStatus("genMETP4" ,1); currentTree->SetBranchStatus("MtLeg1" ,1); // generator-level boson currentTree->SetBranchStatus("genVP4" ,1); currentTree->SetBranchStatus("genDecay" ,1); // extra-muons currentTree->SetBranchStatus("muFlag" ,1); // event-dependent variables currentTree->SetBranchStatus("numPV" ,1); currentTree->SetBranchStatus("nPUVertices" ,1); currentTree->SetBranchStatus("numOfLooseIsoDiTaus" ,0); currentTree->SetBranchStatus("run" ,1); currentTree->SetBranchStatus("event" ,1); currentTree->SetBranchStatus("lumi" ,1); // triggers currentTree->SetBranchStatus("tauXTriggers" ,1); currentTree->SetBranchStatus("triggerBits" ,1); //////////////////////////////////////////////////////////////////// std::vector< LV >* jets = new std::vector< LV >(); currentTree->SetBranchAddress("jetsIDP4", &jets); std::vector< LV >* diTauLegsP4 = new std::vector< LV >(); currentTree->SetBranchAddress("diTauLegsP4", &diTauLegsP4); std::vector< LV >* diTauVisP4 = new std::vector< LV >(); currentTree->SetBranchAddress("diTauVisP4", &diTauVisP4); std::vector< LV >* diTauSVfitP4 = new std::vector< LV >(); currentTree->SetBranchAddress("diTauSVfitP4", &diTauSVfitP4); std::vector< LV >* genDiTauLegsP4 = new std::vector< LV >(); currentTree->SetBranchAddress("genDiTauLegsP4", &genDiTauLegsP4); std::vector< LV >* genVP4 = new std::vector< LV >(); currentTree->SetBranchAddress("genVP4", &genVP4); std::vector< LV >* METP4 = new std::vector< LV >(); currentTree->SetBranchAddress("METP4", &METP4); std::vector< LV >* genMETP4 = new std::vector< LV >(); currentTree->SetBranchAddress("genMETP4", &genMETP4); std::vector< int >* tauXTriggers = new std::vector< int >(); currentTree->SetBranchAddress("tauXTriggers", &tauXTriggers); std::vector< int >* triggerBits = new std::vector< int >(); currentTree->SetBranchAddress("triggerBits", &triggerBits); // auxiliary float to store branch values float diTauCharge; int tightestHPSDBWP, decayMode; float numPV; int signalPFChargedHadrCands, signalPFGammaCands; int muFlag,genDecay, nPUVertices; float visibleTauMass; float chIsoLeg1,nhIsoLeg1,phIsoLeg1; float nhIsoPULeg1; ULong64_t event,run,lumi; currentTree->SetBranchAddress("chIsoLeg1v2", &chIsoLeg1); currentTree->SetBranchAddress("nhIsoLeg1v2", &nhIsoLeg1); currentTree->SetBranchAddress("phIsoLeg1v2", &phIsoLeg1); currentTree->SetBranchAddress("nhIsoPULeg1v2", &nhIsoPULeg1); currentTree->SetBranchAddress("tightestHPSDBWP", &tightestHPSDBWP); currentTree->SetBranchAddress("diTauCharge", &diTauCharge); currentTree->SetBranchAddress("numPV", &numPV); currentTree->SetBranchAddress("event", &event); currentTree->SetBranchAddress("run", &run); currentTree->SetBranchAddress("lumi", &lumi); currentTree->SetBranchAddress("nPUVertices", &nPUVertices); currentTree->SetBranchAddress("genDecay", &genDecay); currentTree->SetBranchAddress("decayMode", &decayMode); currentTree->SetBranchAddress("muFlag", &muFlag); currentTree->SetBranchAddress("visibleTauMass", &visibleTauMass); currentTree->SetBranchAddress("signalPFChargedHadrCands" ,&signalPFChargedHadrCands); currentTree->SetBranchAddress("signalPFGammaCands" ,&signalPFGammaCands); TFile* HqT = 0; int mH = 130; TH1F* histo = 0; if(samples[index].find("GGFH130")!=string::npos){ mH = 130; cout << "Reweighting powheg with HqT mH=" << mH << endl; HqT = new TFile(Form("../data/weight_ptH_%d.root", mH)); if(!HqT) cout << "Cannot find HqT file..." << endl; else{ histo = (TH1F*)(HqT->Get(Form("powheg_weight/weight_hqt_fehipro_fit_%d",mH))); } } for (int n = 0; n < nEntries ; n++) { currentTree->GetEntry(n); if(n%500==0) cout << n << endl; // initialize variables filled only in the two jet case pt1=-99;pt2=-99;eta1=-99,eta2=-99;Deta=-99;Dphi=-99;Mjj=-99;phi1=-99;phi2=-99; ptVeto = -99; phiVeto= -99; etaVeto= -99;isVetoInJets=-99; // define the relevant jet collection nJets30 = 0; int lead = -99; int trail = -99; int veto = -99; vector<int> indexes; for(int l = 0 ; l < jets->size() ; l++){ if((*jets)[l].Pt()>MINPt1 && TMath::Abs((*jets)[l].Eta())<MAXEta) indexes.push_back(l); } nJets20 = indexes.size(); if(indexes.size()>0) lead = indexes[0]; if(indexes.size()>1) trail = indexes[1]; if(indexes.size()>2) veto = indexes[2]; for(int v = 0 ; v < indexes.size() ; v++){ if( (*jets)[indexes[v]].Pt() > 30 ) nJets30++; } // first jet if(lead>=0){ pt1 = (*jets)[lead].Pt(); eta1 = (*jets)[lead].Eta(); phi1 = (*jets)[lead].Phi(); // second jet if(trail>=0){ pt2 = (*jets)[trail].Pt(); eta2 = (*jets)[trail].Eta(); phi2 = (*jets)[trail].Phi(); Deta = abs(eta1-eta2); Dphi = abs((*jets)[lead].Phi()-(*jets)[trail].Phi()) > TMath::Pi() ? -abs( (*jets)[lead].Phi()-(*jets)[trail].Phi() ) + 2*TMath::Pi() : abs( (*jets)[lead].Phi()-(*jets)[trail].Phi() ) ; Mjj = ((*jets)[lead]+(*jets)[trail]).M(); } } ptVeto = (veto>=0) ? (*jets)[veto].Pt() : -99; etaVeto = (veto>=0) ? (*jets)[veto].Eta(): -99; phiVeto = (veto>=0) ? (*jets)[veto].Phi(): -99; isVetoInJets = 0; for(int l = 0 ; l < indexes.size() ; l++){ if(lead>=0 && trail>=0 && (l!= lead && l!= trail) && (*jets)[indexes[l]].Pt()>PtVETO && ((*jets)[indexes[l]].Eta() - eta1)*((*jets)[indexes[l]].Eta() - eta2)<=0 ) isVetoInJets = 1; } diTauSVFitMass = (*diTauSVfitP4)[0].M(); diTauVisMass = (*diTauVisP4)[0].M(); diTauVisPt = (*diTauVisP4)[0].Pt(); diTauVisEta = (*diTauVisP4)[0].Eta(); diTauVisPhi = (*diTauVisP4)[0].Phi(); ptL1 = (*diTauLegsP4)[0].Pt(); ptL2 = (*diTauLegsP4)[1].Pt(); etaL1 = (*diTauLegsP4)[0].Eta(); etaL2 = (*diTauLegsP4)[1].Eta(); phiL1 = (*diTauLegsP4)[0].Phi(); phiL2 = (*diTauLegsP4)[1].Phi(); dPhiL1L2 = abs((*diTauLegsP4)[0].Phi()-(*diTauLegsP4)[1].Phi()) > TMath::Pi() ? -abs( (*diTauLegsP4)[0].Phi()-(*diTauLegsP4)[1].Phi() ) + 2*TMath::Pi() : abs( (*diTauLegsP4)[0].Phi()-(*diTauLegsP4)[1].Phi() ) ; diTauCharge_ = diTauCharge; //////////////////////////////////////////////////////////////////// float scalarSumPt = ( *diTauLegsP4)[0].Pt() + (*METP4)[0].Pt(); float vectorSumPt = ((*diTauLegsP4)[0] + (*METP4)[0]).Pt() ; MtLeg1_ = TMath::Sqrt( scalarSumPt*scalarSumPt - vectorSumPt*vectorSumPt ) ; MEt = (*METP4)[0].Et(); combRelIsoLeg1DBeta = (chIsoLeg1+ std::max( nhIsoLeg1+phIsoLeg1-0.5*(nhIsoPULeg1),double(0.0)))/(*diTauLegsP4)[0].Pt(); tightestHPSDBWP_ = tightestHPSDBWP; visibleTauMass_ = visibleTauMass; decayMode_ = decayMode; numPV_ = numPV; sampleWeight = scaleFactor; puWeight = (std::string(sample.Data())).find("Data")!=string::npos ? 1.0 : pileupWeight(nPUVertices); HqTWeight = histo!=0 ? histo->GetBinContent( histo->FindBin( (*genVP4)[0].Pt() ) ) : 1.0; if((std::string(sample.Data())).find("Data")!=string::npos){ HLTx = float((*triggerBits)[0]); //HLT_IsoMu15_LooseIsoPFTau15_v8 bool isTriggMatched = (*tauXTriggers)[0] && (*tauXTriggers)[1] ; //hltSingleMuIsoL3IsoFiltered15 && hltOverlapFilterIsoMu15IsoPFTau15 HLTmatch = isTriggMatched ? 1.0 : 0.0; HLTweightTau = 1.0; HLTweightMu = 1.0; SFTau = 1.0; SFMu = 1.0; } else{ HLTx = float((*triggerBits)[0]); //HLT_IsoMu15_LooseIsoPFTau15_v9 bool isTriggMatched = (*tauXTriggers)[0] && (*tauXTriggers)[1] ; //hltSingleMuIsoL3IsoFiltered15 && hltOverlapFilterIsoMu15IsoPFTau15 HLTmatch = isTriggMatched ? 1.0 : 0.0; HLTweightTau = TMath::Abs((*diTauLegsP4)[1].Eta())<1.5 ? ratioTauHLTBL->Eval( (*diTauLegsP4)[1].Pt() ) : ratioTauHLTEC->Eval( (*diTauLegsP4)[1].Pt() ); HLTweightMu = TMath::Abs((*diTauLegsP4)[0].Eta())<1.5 ? ratioMuHLTBL->Eval( (*diTauLegsP4)[0].Pt() ) : ratioMuHLTEC->Eval( (*diTauLegsP4)[0].Pt() ); SFTau = 1.0; SFMu = TMath::Abs((*diTauLegsP4)[0].Eta())<1.5 ? ratioMuIDIsoBL->Eval( (*diTauLegsP4)[0].Pt() ): ratioMuIDIsoEC->Eval( (*diTauLegsP4)[0].Pt() ); } muFlag_ = muFlag; genDecay_ = genDecay ; event_ = event; run_ = run; lumi_ = lumi; outTreePtOrd->Fill(); } file->Close(); if(SAVE) outFile->Write(); outFile->Close(); delete jets; delete diTauLegsP4; delete diTauVisP4; delete diTauSVfitP4; delete genDiTauLegsP4; delete tauXTriggers; delete triggerBits; delete METP4; delete genVP4; delete genMETP4; delete HqT; return; }
int main(int argc, char** argv){ ///=============================================================================== gROOT->Reset(); gROOT->SetStyle("Plain"); gStyle->SetPalette(1); gStyle->SetOptStat(1111); gStyle->SetOptFit(111); const Int_t __NRGBs = 5; const Int_t __NCont = 76; Double_t __stops[__NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 }; Double_t __red[__NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 }; Double_t __green[__NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 }; Double_t __blue[__NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 }; TColor::CreateGradientColorTable(__NRGBs, __stops, __red, __green, __blue, __NCont); gStyle->SetNumberContours(__NCont); ///=============================================================================== if(argc != 2) { std::cerr << ">>>>> analysis.cpp::usage: " << argv[0] << " configFileName" << std::endl ; return 1; } // Parse the config file parseConfigFile (argv[1]) ; std::string inputFile = gConfigParser -> readStringOption("Input::inputFile"); std::cout << ">>>>> Input::inputFile " << inputFile << std::endl; TFile *_file0 = TFile::Open(inputFile.c_str()); double minReco = gConfigParser -> readDoubleOption("Options::minReco"); std::cout << ">>>>> Options::minReco " << minReco << std::endl; TString Selection = Form("xRECO>%f",minReco); std::cout << ">>>>> Selection = " << Selection.Data() << std::endl; double maxTrue = gConfigParser -> readDoubleOption("Options::maxTrue"); std::cout << ">>>>> Options::maxTrue " << maxTrue << std::endl; double maxReco = gConfigParser -> readDoubleOption("Options::maxReco"); std::cout << ">>>>> Options::maxReco " << maxReco << std::endl; int binTrue = gConfigParser -> readIntOption("Options::binTrue"); std::cout << ">>>>> Options::binTrue " << binTrue << std::endl; int binReco = gConfigParser -> readIntOption("Options::binReco"); std::cout << ">>>>> Options::binReco " << binReco << std::endl; TTree* tree = (TTree*) _file0->Get("InputTree"); TCanvas cResult("cResult","cResult",800,400); cResult.Divide(2,1); TH2F h2("h2","h2",binReco,0,maxReco,binTrue,0,maxTrue); TH1F h1RECO("h1RECO","h1RECO",binReco,0,maxReco); TH1F h1MC("h1MC","h1MC",binTrue,0,maxTrue); cResult.cd(1); tree->Draw("xMC:xRECO >> h2",Selection.Data(),"colz"); h2.Draw("colz"); h2.GetXaxis()->SetTitle("RECO"); h2.GetYaxis()->SetTitle("TRUE"); h2.FitSlicesX(); TH1F* h2_1_X = (TH1F*) gDirectory->Get("h2_1"); h2_1_X->SetName("h2_1_X"); h2_1_X->SetLineWidth(2); double x[1000]; double y[1000]; for (int iBin=0; iBin < h2_1_X->GetNbinsX(); iBin++){ y[iBin] = h2_1_X->GetBinCenter(iBin+1); x[iBin] = h2_1_X->GetBinContent(iBin+1); } TGraph gr(h2_1_X->GetNbinsX(),x,y); gr.SetMarkerSize(1); gr.SetMarkerStyle(22); gr.SetMarkerColor(kRed); gr.Draw("Psame"); gPad->SetGrid(); double xMC[1000]; double yMC[1000]; TF1 *kFunction = new TF1("kFunction","1.3 + 0.001 * x - exp(-x/100)",0,2000); for (int iBin=0; iBin < 1000; iBin++){ yMC[iBin] = (maxTrue) / 1000. * iBin; xMC[iBin] = kFunction->Eval(yMC[iBin]) * yMC[iBin]; } TGraph grMC(1000,xMC,yMC); grMC.SetMarkerSize(0.5); grMC.SetMarkerStyle(20); grMC.SetMarkerColor(kGreen); grMC.Draw("Psame"); cResult.cd(2); TGraph grInv(h2_1_X->GetNbinsX(),y,x); grInv.SetMarkerSize(1); grInv.SetMarkerStyle(22); grInv.SetMarkerColor(kRed); grInv.Draw("AP"); TGraph grMCInv(1000,yMC,xMC); grMCInv.SetMarkerSize(0.5); grMCInv.SetMarkerStyle(20); grMCInv.SetMarkerColor(kGreen); grMCInv.Draw("Psame"); // gr.Draw("AP"); // grMC.Draw("Psame"); grInv.GetXaxis()->SetTitle("TRUE"); grInv.GetYaxis()->SetTitle("RECO"); gPad->SetGrid(); cResult.SaveAs("PlotCaVa.png"); TCanvas cResultWhy("cResultWhy","cResultWhy",800,400); cResultWhy.Divide(2,1); ///======================================== slices x-fixed ======================================== //PG build bands with getBand and same Tails along x //PG ---- ---- ---- ---- ---- ---- ---- ---- ---- -- h2.FitSlicesY(); TH1F* h2_1_Y = (TH1F*) gDirectory->Get("h2_1"); h2_1_Y->SetName("h2_1_Y"); h2_1_Y->SetLineWidth(2); std::cout << "getBand_integrY : getLimit_sameTails " << std::endl; std::vector<std::vector<double> > out_sameTails_x = getBand_integrY (h2, getLimit_sameTails ()) ; std::pair<std::vector<double>, std::vector<double> > x_lineAbove_sameTails ; x_lineAbove_sameTails.first = out_sameTails_x.at (0) ; x_lineAbove_sameTails.second = out_sameTails_x.at (2) ; std::pair<std::vector<double>, std::vector<double> > x_lineBelow_sameTails ; x_lineBelow_sameTails.first = out_sameTails_x.at (0) ; x_lineBelow_sameTails.second = out_sameTails_x.at (1) ; TPolyLine x_cont_sameTails = makePoly (x_lineAbove_sameTails, x_lineBelow_sameTails) ; x_cont_sameTails.SetLineWidth (2.5) ; x_cont_sameTails.SetFillColor (kGreen) ; x_cont_sameTails.SetLineColor (kGreen) ; //PG build bands with getBand and Neyman intervals along x //PG ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --- std::cout << "getBand_integrY : getLimit_FC " << std::endl; std::vector<std::vector<double> > out_Neyman_x = getBand_integrY (h2, getLimit_FC ()) ; std::pair<std::vector<double>, std::vector<double> > x_lineAbove_Neyman ; x_lineAbove_Neyman.first = out_Neyman_x.at (0) ; x_lineAbove_Neyman.second = out_Neyman_x.at (2) ; std::pair<std::vector<double>, std::vector<double> > x_lineBelow_Neyman ; x_lineBelow_Neyman.first = out_Neyman_x.at (0) ; x_lineBelow_Neyman.second = out_Neyman_x.at (1) ; TPolyLine x_cont_Neyman = makePoly (x_lineAbove_Neyman, x_lineBelow_Neyman) ; x_cont_Neyman.SetLineWidth (2.5) ; x_cont_Neyman.SetFillColor (kYellow) ; x_cont_Neyman.SetLineColor (kYellow) ; ///======================================== slices y-fixed ======================================== //PG build bands with getBand and same Tails along y //PG ---- ---- ---- ---- ---- ---- ---- ---- ---- -- double xYFixed[1000]; double yYFixed[1000]; for (int iBin=0; iBin < h2_1_Y->GetNbinsX(); iBin++){ xYFixed[iBin] = h2_1_Y->GetBinCenter(iBin+1); yYFixed[iBin] = h2_1_Y->GetBinContent(iBin+1); } TGraph grYFixed(h2_1_Y->GetNbinsX(),xYFixed,yYFixed); grYFixed.SetMarkerSize(1); grYFixed.SetMarkerStyle(22); grYFixed.SetMarkerColor(kRed); std::cout << "getBand_integrX : getLimit_sameTails " << std::endl; std::vector<std::vector<double> > out_sameTails_y = getBand_integrX (h2, getLimit_sameTails ()) ; std::pair<std::vector<double>, std::vector<double> > y_lineAbove_sameTails ; y_lineAbove_sameTails.first = out_sameTails_y.at (2) ; y_lineAbove_sameTails.second = out_sameTails_y.at (0) ; std::pair<std::vector<double>, std::vector<double> > y_lineBelow_sameTails ; y_lineBelow_sameTails.first = out_sameTails_y.at (1) ; y_lineBelow_sameTails.second = out_sameTails_y.at (0) ; TPolyLine y_cont_sameTails = makePoly (y_lineAbove_sameTails, y_lineBelow_sameTails) ; y_cont_sameTails.SetLineWidth (2.5) ; y_cont_sameTails.SetFillColor (kGreen) ; y_cont_sameTails.SetLineColor (kGreen) ; //PG build bands with getBand and Neyman intervals along y //PG ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --- std::cout << "getBand_integrX : getLimit_FC " << std::endl; std::vector<std::vector<double> > out_Neyman_y = getBand_integrX (h2, getLimit_FC ()) ; std::pair<std::vector<double>, std::vector<double> > y_lineAbove_Neyman ; y_lineAbove_Neyman.first = out_Neyman_y.at (2) ; y_lineAbove_Neyman.second = out_Neyman_y.at (0) ; std::pair<std::vector<double>, std::vector<double> > y_lineBelow_Neyman ; y_lineBelow_Neyman.first = out_Neyman_y.at (1) ; y_lineBelow_Neyman.second = out_Neyman_y.at (0) ; TPolyLine y_cont_Neyman = makePoly (y_lineAbove_Neyman, y_lineBelow_Neyman) ; y_cont_Neyman.SetLineWidth (2.5) ; y_cont_Neyman.SetFillColor (kYellow) ; y_cont_Neyman.SetLineColor (kYellow) ; ///======================================== plot ======================================== gROOT->Reset(); gROOT->SetStyle("Plain"); UInt_t Number = 5; Double_t Red[5] = { 0.00, 0.09, 0.18, 0.09, 0.00 }; Double_t Green[5] = { 0.01, 0.02, 0.39, 0.68, 0.97 }; Double_t Blue[5] = { 0.17, 0.39, 0.62, 0.79, 0.97 }; Double_t Length[5] = { 0.00, 0.34, 0.61, 0.84, 1.00 }; TColor::CreateGradientColorTable(Number,Length,Red,Green,Blue,999); // gStyle->SetPalette(20); cResultWhy.cd(1); h2.Draw ("colz") ; h2_1_Y->SetMarkerColor(kRed); h2_1_Y->Draw("Esame"); x_cont_sameTails.Draw () ; x_cont_Neyman.Draw () ; gPad->SetGrid(); gPad->SetLogz(); cResultWhy.cd(2); h2.Draw ("colz") ; grYFixed.Draw("Psame"); y_cont_sameTails.Draw () ; y_cont_Neyman.Draw () ; gPad->SetGrid(); gPad->SetLogz(); cResultWhy.SaveAs("CaVaXY.png") ; cResultWhy.SaveAs("CaVaXY.root") ; TCanvas cResultWhyDivided("cResultWhyDivided","cResultWhyDivided",800,800); cResultWhyDivided.Divide(2,2); cResultWhyDivided.cd(1); h2.Draw ("colz") ; h2_1_Y->Draw("Esame"); x_cont_Neyman.Draw () ; gPad->SetGrid(); gPad->SetLogz(); cResultWhyDivided.cd(2); h2.Draw ("colz") ; grYFixed.Draw("Psame"); y_cont_sameTails.Draw () ; gPad->SetGrid(); gPad->SetLogz(); cResultWhyDivided.cd(3); h2.Draw ("colz") ; h2_1_Y->Draw("Esame"); x_cont_sameTails.Draw () ; gPad->SetGrid(); gPad->SetLogz(); cResultWhyDivided.cd(4); h2.Draw ("colz") ; grYFixed.Draw("Psame"); y_cont_Neyman.Draw () ; gPad->SetGrid(); gPad->SetLogz(); cResultWhyDivided.SaveAs("CaVaXYDivided.png") ; cResultWhyDivided.SaveAs("CaVaXYDivided.root") ; TH1D * h1_ProjY = h2.ProjectionY ("h2_tempY", binTrue / 3, binTrue / 3 , "e") ; TH1D * h1_ProjX = h2.ProjectionX ("h2_tempX", binReco / 3, binReco / 3 , "e") ; TCanvas cProjection("cProjection","cProjection",800,400); cProjection.Divide(2,1); cProjection.cd(1); SetColorAndStyleHisto(*h1_ProjX,kGreen); h1_ProjX->Draw(); std::vector<double> band_ProjX = getSigmaBands_FeldmanCousins (*h1_ProjX) ; TLine* lVert_ProjX_Left95 = new TLine(band_ProjX.at(0),0,band_ProjX.at(0),1000); lVert_ProjX_Left95->SetLineColor(kBlue); lVert_ProjX_Left95->SetLineWidth(2); // lVert_ProjX_Left95->SetLineStyle(5); TLine* lVert_ProjX_Left68 = new TLine(band_ProjX.at(1),0,band_ProjX.at(1),1000); lVert_ProjX_Left68->SetLineColor(kMagenta); lVert_ProjX_Left68->SetLineWidth(2); // lVert_ProjX_Left68->SetLineStyle(5); TLine* lVert_ProjX_Middle = new TLine(band_ProjX.at(2),0,band_ProjX.at(2),1000); lVert_ProjX_Middle->SetLineColor(kGreen); lVert_ProjX_Middle->SetLineWidth(2); // lVert_ProjX_Middle->SetLineStyle(5); TLine* lVert_ProjX_Right68 = new TLine(band_ProjX.at(3),0,band_ProjX.at(3),1000); lVert_ProjX_Right68->SetLineColor(kMagenta); lVert_ProjX_Right68->SetLineWidth(2); // lVert_ProjX_Right68->SetLineStyle(5); TLine* lVert_ProjX_Right95 = new TLine(band_ProjX.at(4),0,band_ProjX.at(4),1000); lVert_ProjX_Right95->SetLineColor(kBlue); lVert_ProjX_Right95->SetLineWidth(2); // lVert_ProjX_Right95->SetLineStyle(5); lVert_ProjX_Left95->Draw(); lVert_ProjX_Left68->Draw(); lVert_ProjX_Middle->Draw(); lVert_ProjX_Right68->Draw(); lVert_ProjX_Right95->Draw(); gPad->SetGrid(); cProjection.cd(2); SetColorAndStyleHisto(*h1_ProjY,kRed); h1_ProjY->Draw(); std::vector<double> band_ProjY = getSigmaBands_FeldmanCousins (*h1_ProjY) ; TLine* lVert_ProjY_Left95 = new TLine(band_ProjY.at(0),0,band_ProjY.at(0),1000); lVert_ProjY_Left95->SetLineColor(kBlue); lVert_ProjY_Left95->SetLineWidth(2); // lVert_ProjY_Left95->SetLineStyle(5); TLine* lVert_ProjY_Left68 = new TLine(band_ProjY.at(1),0,band_ProjY.at(1),1000); lVert_ProjY_Left68->SetLineColor(kMagenta); lVert_ProjY_Left68->SetLineWidth(2); // lVert_ProjY_Left68->SetLineStyle(5); TLine* lVert_ProjY_Middle = new TLine(band_ProjY.at(2),0,band_ProjY.at(2),1000); lVert_ProjY_Middle->SetLineColor(kGreen); lVert_ProjY_Middle->SetLineWidth(2); // lVert_ProjY_Middle->SetLineStyle(5); TLine* lVert_ProjY_Right68 = new TLine(band_ProjY.at(3),0,band_ProjY.at(3),1000); lVert_ProjY_Right68->SetLineColor(kMagenta); lVert_ProjY_Right68->SetLineWidth(2); // lVert_ProjY_Right68->SetLineStyle(5); TLine* lVert_ProjY_Right95 = new TLine(band_ProjY.at(4),0,band_ProjY.at(4),1000); lVert_ProjY_Right95->SetLineColor(kBlue); lVert_ProjY_Right95->SetLineWidth(2); // lVert_ProjY_Right95->SetLineStyle(5); lVert_ProjY_Left95->Draw(); lVert_ProjY_Left68->Draw(); lVert_ProjY_Middle->Draw(); lVert_ProjY_Right68->Draw(); lVert_ProjY_Right95->Draw(); gPad->SetGrid(); cProjection.SaveAs("CaVaXYProjection.png") ; cProjection.SaveAs("CaVaXYProjection.root") ; cProjection.SaveAs("CaVaXYProjection.eps") ; TCanvas cProjection2D("cProjection2D","cProjection2D",800,1200); TPad oneC ("oneC","oneC",0.0,0.5,0.5,1.0); oneC.Draw(); oneC.cd(); h1_ProjX->Draw(); gPad->SetGrid(); cProjection2D.cd(); TPad twoC ("twoC","twoC",0.5,0.5,1.0,1.0); twoC.Draw(); twoC.cd(); h1_ProjY->Draw(); gPad->SetGrid(); cProjection2D.cd(); TPad threefourC ("threefourC","threefourC",0.0,0.0,1.0,0.5); threefourC.Draw(); threefourC.cd(); h2.Draw ("colz") ; cProjection2D.SaveAs("CaVaXYProjection2D.png") ; cProjection2D.SaveAs("CaVaXYProjection2D.root") ; cProjection2D.SaveAs("CaVaXYProjection2D.eps") ; }
void line_width() { TCanvas *c1 = MakeCanvas("c1", "c1", 800, 600); TF1 *fitPeak = new TF1("fitPeak", "[0]-[1]*([3]/2)^2/((x-[2])^2+([3]/2)^2)-[4]*([6]/2)^2/((x-[5])^2+([6]/2)^2)-[7]*([9]/2)^2/((x-[8])^2+([9]/2)^2)-[10]*([12]/2)^2/((x-[11])^2+([12]/2)^2)-[13]*([15]/2)^2/((x-[14])^2+([15]/2)^2)-[16]*([18]/2)^2/((x-[17])^2+([18]/2)^2)-[19]*(x-[20])**2",200, 2040); char outfile[50]; vector<Double_t> linewidths; vector<Double_t> linewidthsunc; vector<Double_t> err1; vector<Double_t> err2; for (Int_t i=21; i<27; i++) { TH1D *fecn = new TH1D("fecn", "fecn", 2048, 0, 2048); TH1D *cal = new TH1D("cal", "cal", 2048, 0, 2048); confParse("data_list.txt", i, fecn); if ((i==21)||(i==26)) confParse("data_list.txt", 4, cal); else confParse("data_list.txt", 30, cal); fitPeak->SetParameter(0, 120); fitPeak->SetParameter(1, 20); fitPeak->SetParameter(2, 500); fitPeak->SetParameter(3, 15); fitPeak->SetParameter(4, 20); fitPeak->SetParameter(5, 700); fitPeak->SetParameter(6, 15); fitPeak->SetParameter(7, 200); fitPeak->SetParameter(8, 1000); fitPeak->SetParameter(9, 15); fitPeak->SetParameter(10, 20); fitPeak->SetParameter(11, 1100); fitPeak->SetParameter(12, 15); fitPeak->SetParameter(13, 20); fitPeak->SetParameter(14, 1400); fitPeak->SetParameter(15, 15); fitPeak->SetParameter(16, 20); fitPeak->SetParameter(17, 1600); fitPeak->SetParameter(18, 15); cal->SetTitle(""); cal->GetXaxis()->SetTitle("MCA Channel"); cal->GetYaxis()->SetTitle("Counts"); cal->GetXaxis()->SetNdivisions(8,5,0); cal->SetLineColor(kRed); cal->Fit("fitPeak", "R"); sprintf(outfile, "linewidthcal%i.png", i); c1->SaveAs(outfile); vector<Double_t> peakPos; vector<Double_t> peakPosUnc; peakPos.push_back(fitPeak->GetParameter(2)); peakPosUnc.push_back(TMath::Sqrt(fabs(fitPeak->GetParameter(3)))); peakPos.push_back(fitPeak->GetParameter(5)); peakPosUnc.push_back(TMath::Sqrt(fabs(fitPeak->GetParameter(6)))); peakPos.push_back(fitPeak->GetParameter(8)); peakPosUnc.push_back(TMath::Sqrt(fabs(fitPeak->GetParameter(9)))); peakPos.push_back(fitPeak->GetParameter(11)); peakPosUnc.push_back(TMath::Sqrt(fabs(fitPeak->GetParameter(12)))); peakPos.push_back(fitPeak->GetParameter(14)); peakPosUnc.push_back(TMath::Sqrt(fabs(fitPeak->GetParameter(15)))); peakPos.push_back(fitPeak->GetParameter(17)); peakPosUnc.push_back(TMath::Sqrt(fabs(fitPeak->GetParameter(18)))); TF1 *velCurve = new TF1("velCurve", "[0]*x+[1]*x^2+[2]", 200, 2040); getVel(peakPos, peakPosUnc, velCurve); //TF1 *fitPeak2 = new TF1("fitPeak2", "[0]-[1]*([3]/2)^2/((x-[2])^2+([3]/2)^2)", 800, 1300); TF1 *fitPeak2 = new TF1("fitPeak2", "[0]-[1]*([3]/2)^2/((x-[2])^2+([3]/2)^2)", 900, 1200); //TF1 *fitPeak2 = new TF1("fitPeak2", "[0]-[1]*([3]/2)^2/((x-[2])^2+([3]/2)^2)-[4]*(x-[5])", 200, 2000); fitPeak2->SetParameter(0, 21500); fitPeak2->SetParameter(1, 2000); fitPeak2->SetParameter(2, 1040); fitPeak2->SetParameter(3, 50); fecn->SetTitle(""); fecn->GetXaxis()->SetRangeUser(800, 1300); fecn->GetXaxis()->SetTitle("MCA Channel"); fecn->GetYaxis()->SetTitle("Counts"); fecn->GetXaxis()->SetNdivisions(8,5,0); fecn->SetLineColor(kRed); fecn->Draw(); fecn->Fit("fitPeak2", "RN"); fitPeak2->Draw("same"); sprintf(outfile, "linewidth%i.png", i); c1->SaveAs(outfile); Double_t blah = fabs(velCurve->Eval(fitPeak2->GetParameter(2)+fitPeak2->GetParameter(3)/2)-velCurve->Eval(fitPeak2->GetParameter(2)-fitPeak2->GetParameter(3)/2)); linewidths.push_back(fabs(velCurve->Eval(fitPeak2->GetParameter(2)+fitPeak2->GetParameter(3)/2)-velCurve->Eval(fitPeak2->GetParameter(2)-fitPeak2->GetParameter(3)/2))); Double_t temp1=fabs(velCurve->Eval(fitPeak2->GetParameter(2)+fitPeak2->GetParameter(3)/2-fitPeak2->GetParError(3)/2)-velCurve->Eval(fitPeak2->GetParameter(2)-fitPeak2->GetParameter(3)/2+fitPeak2->GetParError(3)/2)); Double_t temp2=fabs(velCurve->Eval(fitPeak2->GetParameter(2)+fitPeak2->GetParameter(3)/2+fitPeak2->GetParError(3)/2)-velCurve->Eval(fitPeak2->GetParameter(2)-fitPeak2->GetParameter(3)/2-fitPeak2->GetParError(3)/2)); Double_t moreblah = TMath::Max(fabs(temp1-blah), fabs(temp2-blah)); Double_t andagain = fabs(getVelUnc(velCurve->Eval(fitPeak2->GetParameter(2)+fitPeak2->GetParameter(3)/2))); //Double_t andagain=0; err1.push_back(moreblah); err2.push_back(andagain); linewidthsunc.push_back(TMath::Sqrt(moreblah*moreblah+andagain*andagain)); delete cal; delete fecn; peakPos.clear(); peakPosUnc.clear(); } TGraphErrors *gr = new TGraphErrors(); for (Int_t i=0; i<linewidths.size(); i++) { cout << linewidths[i] << "\\pm" << err1[i] << "\\pm" << err2[i] << "\\pm" << linewidthsunc[i] << endl; gr->SetPoint(i, 25*(i+1), linewidths[i]); gr->SetPointError(i,0, linewidthsunc[i]); } gr->SetTitle(""); gr->GetXaxis()->SetTitle("Absorber Thickness [mg/cm^{2}]"); gr->GetYaxis()->SetTitle("Line Width [mm/s]"); gr->Draw("ap"); TF1 *thing = new TF1("thing", "[0]+[1]*x",0,7); gr->Fit("thing"); Double_t nomE=14.4e3; Double_t cLight=3e11; cout << thing->GetParameter(0)*nomE/cLight << " " << thing->GetParError(0)*nomE/cLight << endl; c1->SaveAs("linewidth.png"); }
void plot() { TGraph * gr1 = new TGraph(); gr1->SetMarkerStyle(21); int nPoints1 = 0; TGraph * gr2 = new TGraph(); gr2->SetMarkerStyle(21); int nPoints2 = 0; TGraph * gr3 = new TGraph(); gr3->SetMarkerStyle(21); int nPoints3 = 0; TGraph * gr4 = new TGraph(); gr4->SetMarkerStyle(21); int nPoints4 = 0; TGraph * gr5 = new TGraph(); gr5->SetMarkerStyle(21); int nPoints5 = 0; while (M1[nPoints1].bath!=-999.0) { gr1->SetPoint(nPoints1, M1[nPoints1].ambient, M1[nPoints1].slope); nPoints1++; gr2->SetPoint(nPoints2, M1[nPoints2].bath, M1[nPoints2].ambient); nPoints2++; gr3->SetPoint(nPoints3, M1[nPoints3].bottom, M1[nPoints3].ambient); nPoints3++; gr4->SetPoint(nPoints4, M1[nPoints4].top, M1[nPoints4].ambient); nPoints4++; gr5->SetPoint(nPoints5, M1[nPoints5].top, M1[nPoints5].slope); nPoints5++; } TF1 * fit = new TF1("fit", myfunction, 5, 35, 2); fit->SetLineColor(2); gr3->Draw("AP"); gr3->Fit(fit, "NR"); fit->Draw("same"); double Tbottom = fit->GetParameter(0) / (1.0 - fit->GetParameter(1)); cout << Tbottom << endl; gr4->Draw("AP"); gr4->Fit(fit, "NR"); fit->Draw("same"); double Ttop = fit->GetParameter(0) / (1.0 - fit->GetParameter(1)); cout << Ttop << endl; gr5->Draw("AP"); gr5->Fit(fit, "NR"); fit->Draw("same"); cout << fit->Eval(Tbottom) << endl; cout << fit->Eval(Ttop) << endl; cout << fit->Eval(Ttop + (Ttop-Tbottom)) << endl; }
void massBias(int mass_in=120) { gStyle->SetOptTitle(0); gStyle->SetOptStat(0); gStyle->SetCanvasColor(0); gStyle->SetFrameBorderMode(0); bool plot_chi2=false; bool saveGifs=false; bool fastsim=false; bool correctShape=false; int shift=0; float sig_sf=0.; float sidebandWidth=0.02; float signalRegionWidth=0.07; TString mass_str; mass_str+=mass_in; TString mass_str2= mass_str; if (mass_in==150) mass_str2="145"; float basemass[5]; if (shift==0) { basemass[0] = 118.5; basemass[1] = 133.5; basemass[2] = 116.; basemass[3] = 131.; basemass[4] = 148.; } else if (shift==1) { basemass[0] = 121.; basemass[1] = 136.5; basemass[2] = 118.5; basemass[3] = 133.5; basemass[4] = 150.; } else { basemass[0] = 115.; basemass[1] = 130.; basemass[2] = 115.; basemass[3] = 130.; basemass[4] = 150.; } TString basemass_str[5]; if (shift==0) { basemass_str[0] = "118.5"; basemass_str[1] = "133.5"; basemass_str[2] = "116.0"; basemass_str[3] = "131.0"; basemass_str[4] = "148.0"; } else if (shift==1) { basemass_str[0] = "121.0"; basemass_str[1] = "136.5"; basemass_str[2] = "118.5"; basemass_str[3] = "133.5"; basemass_str[4] = "150.0"; } else { basemass_str[0] = "115.0"; basemass_str[1] = "130.0"; basemass_str[2] = "115.0"; basemass_str[3] = "130.0"; basemass_str[4] = "150.0"; } float mass[15]; mass[2] = basemass[0]*(1-signalRegionWidth)/(1+sidebandWidth); mass[1] = mass[2]*(1-sidebandWidth)/(1+sidebandWidth); mass[0] = mass[1]*(1-sidebandWidth)/(1+sidebandWidth); mass[5] = basemass[1]*(1-signalRegionWidth)/(1+sidebandWidth); mass[4] = mass[5]*(1-sidebandWidth)/(1+sidebandWidth); mass[3] = mass[4]*(1-sidebandWidth)/(1+sidebandWidth); mass[6] = basemass[2]*(1+signalRegionWidth)/(1-sidebandWidth); mass[7] = mass[6]*(1+sidebandWidth)/(1-sidebandWidth); mass[8] = mass[7]*(1+sidebandWidth)/(1-sidebandWidth); mass[9] = basemass[3]*(1+signalRegionWidth)/(1-sidebandWidth); mass[10] = mass[9]*(1+sidebandWidth)/(1-sidebandWidth); mass[11] = mass[10]*(1+sidebandWidth)/(1-sidebandWidth); mass[12] = basemass[4]*(1+signalRegionWidth)/(1-sidebandWidth); mass[13] = mass[12]*(1+sidebandWidth)/(1-sidebandWidth); mass[14] = mass[13]*(1+sidebandWidth)/(1-sidebandWidth); int nbins[2]; TString boost_str[2] = {"grad","ada"}; Double_t xbins_nominal[20][2]; TH1* hist_nominal[2]; TFile *workspace = TFile::Open("/afs/cern.ch/user/f/futyand/scratch1/mva_ucsd/CMS-HGG_mit_2var_07_01_12_v2.root"); TFile *workspace_mc; if (fastsim) { workspace_mc = TFile::Open("/afs/cern.ch/user/f/futyand/scratch1/mva_ucsd/CMS-HGG_mva_fastsim_12Jan.root"); } else { workspace_mc = workspace; } for (int j=0; j<2; j++) { hist_nominal[j] = (TH1*)(workspace->Get("th1f_data_"+boost_str[j]+"_"+mass_str+".0_cat0"))->Clone(); nbins[j] = hist_nominal[j]->GetNbinsX(); for (int ibin=0; ibin<nbins[j]+1; ibin++) { xbins_nominal[ibin][j] = hist_nominal[j]->GetBinLowEdge(ibin+1); } } TH1* hist_data[15][2]; TH1* hist_bkg[15][2]; TH1* hist_data_fine[15][2]; TH1* hist_bkg_fine[15][2]; TH1* hist_data_corrected[15][2]; TH1* hist_bkg_corrected[15][2]; TH1* hist_sig_fine[2]; TH1* hist_sig[2]; for (int j=0; j<2; j++) { hist_sig_fine[j] = (TH1*)(workspace->Get("th1f_sig_BDT_"+boost_str[j]+"_ggh_140.0_cat0"))->Clone(); hist_data_fine[0][j] = (TH1*)(workspace->Get("th1f_data_3low_BDT_"+boost_str[j]+"_"+basemass_str[0]+"_cat0"))->Clone(); hist_data_fine[1][j] = (TH1*)(workspace->Get("th1f_data_2low_BDT_"+boost_str[j]+"_"+basemass_str[0]+"_cat0"))->Clone(); hist_data_fine[2][j] = (TH1*)(workspace->Get("th1f_data_1low_BDT_"+boost_str[j]+"_"+basemass_str[0]+"_cat0"))->Clone(); hist_data_fine[3][j] = (TH1*)(workspace->Get("th1f_data_3low_BDT_"+boost_str[j]+"_"+basemass_str[1]+"_cat0"))->Clone(); hist_data_fine[4][j] = (TH1*)(workspace->Get("th1f_data_2low_BDT_"+boost_str[j]+"_"+basemass_str[1]+"_cat0"))->Clone(); hist_data_fine[5][j] = (TH1*)(workspace->Get("th1f_data_1low_BDT_"+boost_str[j]+"_"+basemass_str[1]+"_cat0"))->Clone(); hist_data_fine[6][j] = (TH1*)(workspace->Get("th1f_data_1high_BDT_"+boost_str[j]+"_"+basemass_str[2]+"_cat0"))->Clone(); hist_data_fine[7][j] = (TH1*)(workspace->Get("th1f_data_2high_BDT_"+boost_str[j]+"_"+basemass_str[2]+"_cat0"))->Clone(); hist_data_fine[8][j] = (TH1*)(workspace->Get("th1f_data_3high_BDT_"+boost_str[j]+"_"+basemass_str[2]+"_cat0"))->Clone(); hist_data_fine[9][j] = (TH1*)(workspace->Get("th1f_data_1high_BDT_"+boost_str[j]+"_"+basemass_str[3]+"_cat0"))->Clone(); hist_data_fine[10][j] = (TH1*)(workspace->Get("th1f_data_2high_BDT_"+boost_str[j]+"_"+basemass_str[3]+"_cat0"))->Clone(); hist_data_fine[11][j] = (TH1*)(workspace->Get("th1f_data_3high_BDT_"+boost_str[j]+"_"+basemass_str[3]+"_cat0"))->Clone(); hist_data_fine[12][j] = (TH1*)(workspace->Get("th1f_data_1high_BDT_"+boost_str[j]+"_"+basemass_str[4]+"_cat0"))->Clone(); hist_data_fine[13][j] = (TH1*)(workspace->Get("th1f_data_2high_BDT_"+boost_str[j]+"_"+basemass_str[4]+"_cat0"))->Clone(); hist_data_fine[14][j] = (TH1*)(workspace->Get("th1f_data_3high_BDT_"+boost_str[j]+"_"+basemass_str[4]+"_cat0"))->Clone(); hist_bkg_fine[0][j] = (TH1*)(workspace_mc->Get("th1f_bkg_3low_BDT_"+boost_str[j]+"_"+basemass_str[0]+"_cat0"))->Clone(); hist_bkg_fine[1][j] = (TH1*)(workspace_mc->Get("th1f_bkg_2low_BDT_"+boost_str[j]+"_"+basemass_str[0]+"_cat0"))->Clone(); hist_bkg_fine[2][j] = (TH1*)(workspace_mc->Get("th1f_bkg_1low_BDT_"+boost_str[j]+"_"+basemass_str[0]+"_cat0"))->Clone(); hist_bkg_fine[3][j] = (TH1*)(workspace_mc->Get("th1f_bkg_3low_BDT_"+boost_str[j]+"_"+basemass_str[1]+"_cat0"))->Clone(); hist_bkg_fine[4][j] = (TH1*)(workspace_mc->Get("th1f_bkg_2low_BDT_"+boost_str[j]+"_"+basemass_str[1]+"_cat0"))->Clone(); hist_bkg_fine[5][j] = (TH1*)(workspace_mc->Get("th1f_bkg_1low_BDT_"+boost_str[j]+"_"+basemass_str[1]+"_cat0"))->Clone(); hist_bkg_fine[6][j] = (TH1*)(workspace_mc->Get("th1f_bkg_1high_BDT_"+boost_str[j]+"_"+basemass_str[2]+"_cat0"))->Clone(); hist_bkg_fine[7][j] = (TH1*)(workspace_mc->Get("th1f_bkg_2high_BDT_"+boost_str[j]+"_"+basemass_str[2]+"_cat0"))->Clone(); hist_bkg_fine[8][j] = (TH1*)(workspace_mc->Get("th1f_bkg_3high_BDT_"+boost_str[j]+"_"+basemass_str[2]+"_cat0"))->Clone(); hist_bkg_fine[9][j] = (TH1*)(workspace_mc->Get("th1f_bkg_1high_BDT_"+boost_str[j]+"_"+basemass_str[3]+"_cat0"))->Clone(); hist_bkg_fine[10][j] = (TH1*)(workspace_mc->Get("th1f_bkg_2high_BDT_"+boost_str[j]+"_"+basemass_str[3]+"_cat0"))->Clone(); hist_bkg_fine[11][j] = (TH1*)(workspace_mc->Get("th1f_bkg_3high_BDT_"+boost_str[j]+"_"+basemass_str[3]+"_cat0"))->Clone(); hist_bkg_fine[12][j] = (TH1*)(workspace_mc->Get("th1f_bkg_1high_BDT_"+boost_str[j]+"_"+basemass_str[4]+"_cat0"))->Clone(); hist_bkg_fine[13][j] = (TH1*)(workspace_mc->Get("th1f_bkg_2high_BDT_"+boost_str[j]+"_"+basemass_str[4]+"_cat0"))->Clone(); hist_bkg_fine[14][j] = (TH1*)(workspace_mc->Get("th1f_bkg_3high_BDT_"+boost_str[j]+"_"+basemass_str[4]+"_cat0"))->Clone(); Double_t xbins[20]; for (int i=0; i<nbins[j]+1; i++) xbins[i]= xbins_nominal[i][j]; workspace->cd(); hist_data_fine[0][j]->Rebin(nbins[0],"th1f_nominal_bkg_3low_"+boost_str[j]+"_"+basemass_str[0]+"_cat0",xbins); hist_data_fine[1][j]->Rebin(nbins[0],"th1f_nominal_bkg_2low_"+boost_str[j]+"_"+basemass_str[0]+"_cat0",xbins); hist_data_fine[2][j]->Rebin(nbins[0],"th1f_nominal_bkg_1low_"+boost_str[j]+"_"+basemass_str[0]+"_cat0",xbins); hist_data_fine[3][j]->Rebin(nbins[0],"th1f_nominal_bkg_3low_"+boost_str[j]+"_"+basemass_str[1]+"_cat0",xbins); hist_data_fine[4][j]->Rebin(nbins[0],"th1f_nominal_bkg_2low_"+boost_str[j]+"_"+basemass_str[1]+"_cat0",xbins); hist_data_fine[5][j]->Rebin(nbins[0],"th1f_nominal_bkg_1low_"+boost_str[j]+"_"+basemass_str[1]+"_cat0",xbins); hist_data_fine[6][j]->Rebin(nbins[0],"th1f_nominal_bkg_1high_"+boost_str[j]+"_"+basemass_str[2]+"_cat0",xbins); hist_data_fine[7][j]->Rebin(nbins[0],"th1f_nominal_bkg_2high_"+boost_str[j]+"_"+basemass_str[2]+"_cat0",xbins); hist_data_fine[8][j]->Rebin(nbins[0],"th1f_nominal_bkg_3high_"+boost_str[j]+"_"+basemass_str[2]+"_cat0",xbins); hist_data_fine[9][j]->Rebin(nbins[0],"th1f_nominal_bkg_1high_"+boost_str[j]+"_"+basemass_str[3]+"_cat0",xbins); hist_data_fine[10][j]->Rebin(nbins[0],"th1f_nominal_bkg_2high_"+boost_str[j]+"_"+basemass_str[3]+"_cat0",xbins); hist_data_fine[11][j]->Rebin(nbins[0],"th1f_nominal_bkg_3high_"+boost_str[j]+"_"+basemass_str[3]+"_cat0",xbins); hist_data_fine[12][j]->Rebin(nbins[0],"th1f_nominal_bkg_1high_"+boost_str[j]+"_"+basemass_str[4]+"_cat0",xbins); hist_data_fine[13][j]->Rebin(nbins[0],"th1f_nominal_bkg_2high_"+boost_str[j]+"_"+basemass_str[4]+"_cat0",xbins); hist_data_fine[14][j]->Rebin(nbins[0],"th1f_nominal_bkg_3high_"+boost_str[j]+"_"+basemass_str[4]+"_cat0",xbins); hist_sig_fine[j]->Rebin(nbins[0],"th1f_nominal_sig_"+boost_str[j]+"_ggh_140.0_cat0",xbins); workspace_mc->cd(); hist_bkg_fine[0][j]->Rebin(nbins[0],"th1f_nominal_bkg_mc_3low_"+boost_str[j]+"_"+basemass_str[0]+"_cat0",xbins); hist_bkg_fine[1][j]->Rebin(nbins[0],"th1f_nominal_bkg_mc_2low_"+boost_str[j]+"_"+basemass_str[0]+"_cat0",xbins); hist_bkg_fine[2][j]->Rebin(nbins[0],"th1f_nominal_bkg_mc_1low_"+boost_str[j]+"_"+basemass_str[0]+"_cat0",xbins); hist_bkg_fine[3][j]->Rebin(nbins[0],"th1f_nominal_bkg_mc_3low_"+boost_str[j]+"_"+basemass_str[1]+"_cat0",xbins); hist_bkg_fine[4][j]->Rebin(nbins[0],"th1f_nominal_bkg_mc_2low_"+boost_str[j]+"_"+basemass_str[1]+"_cat0",xbins); hist_bkg_fine[5][j]->Rebin(nbins[0],"th1f_nominal_bkg_mc_1low_"+boost_str[j]+"_"+basemass_str[1]+"_cat0",xbins); hist_bkg_fine[6][j]->Rebin(nbins[0],"th1f_nominal_bkg_mc_1high_"+boost_str[j]+"_"+basemass_str[2]+"_cat0",xbins); hist_bkg_fine[7][j]->Rebin(nbins[0],"th1f_nominal_bkg_mc_2high_"+boost_str[j]+"_"+basemass_str[2]+"_cat0",xbins); hist_bkg_fine[8][j]->Rebin(nbins[0],"th1f_nominal_bkg_mc_3high_"+boost_str[j]+"_"+basemass_str[2]+"_cat0",xbins); hist_bkg_fine[9][j]->Rebin(nbins[0],"th1f_nominal_bkg_mc_1high_"+boost_str[j]+"_"+basemass_str[3]+"_cat0",xbins); hist_bkg_fine[10][j]->Rebin(nbins[0],"th1f_nominal_bkg_mc_2high_"+boost_str[j]+"_"+basemass_str[3]+"_cat0",xbins); hist_bkg_fine[11][j]->Rebin(nbins[0],"th1f_nominal_bkg_mc_3high_"+boost_str[j]+"_"+basemass_str[3]+"_cat0",xbins); hist_bkg_fine[12][j]->Rebin(nbins[0],"th1f_nominal_bkg_mc_1high_"+boost_str[j]+"_"+basemass_str[4]+"_cat0",xbins); hist_bkg_fine[13][j]->Rebin(nbins[0],"th1f_nominal_bkg_mc_2high_"+boost_str[j]+"_"+basemass_str[4]+"_cat0",xbins); hist_bkg_fine[14][j]->Rebin(nbins[0],"th1f_nominal_bkg_mc_3high_"+boost_str[j]+"_"+basemass_str[4]+"_cat0",xbins); hist_data[0][j] = (TH1*)(workspace->Get("th1f_nominal_bkg_3low_"+boost_str[j]+"_"+basemass_str[0]+"_cat0"))->Clone(); hist_data[1][j] = (TH1*)(workspace->Get("th1f_nominal_bkg_2low_"+boost_str[j]+"_"+basemass_str[0]+"_cat0"))->Clone(); hist_data[2][j] = (TH1*)(workspace->Get("th1f_nominal_bkg_1low_"+boost_str[j]+"_"+basemass_str[0]+"_cat0"))->Clone(); hist_data[3][j] = (TH1*)(workspace->Get("th1f_nominal_bkg_3low_"+boost_str[j]+"_"+basemass_str[1]+"_cat0"))->Clone(); hist_data[4][j] = (TH1*)(workspace->Get("th1f_nominal_bkg_2low_"+boost_str[j]+"_"+basemass_str[1]+"_cat0"))->Clone(); hist_data[5][j] = (TH1*)(workspace->Get("th1f_nominal_bkg_1low_"+boost_str[j]+"_"+basemass_str[1]+"_cat0"))->Clone(); hist_data[6][j] = (TH1*)(workspace->Get("th1f_nominal_bkg_1high_"+boost_str[j]+"_"+basemass_str[2]+"_cat0"))->Clone(); hist_data[7][j] = (TH1*)(workspace->Get("th1f_nominal_bkg_2high_"+boost_str[j]+"_"+basemass_str[2]+"_cat0"))->Clone(); hist_data[8][j] = (TH1*)(workspace->Get("th1f_nominal_bkg_3high_"+boost_str[j]+"_"+basemass_str[2]+"_cat0"))->Clone(); hist_data[9][j] = (TH1*)(workspace->Get("th1f_nominal_bkg_1high_"+boost_str[j]+"_"+basemass_str[3]+"_cat0"))->Clone(); hist_data[10][j] = (TH1*)(workspace->Get("th1f_nominal_bkg_2high_"+boost_str[j]+"_"+basemass_str[3]+"_cat0"))->Clone(); hist_data[11][j] = (TH1*)(workspace->Get("th1f_nominal_bkg_3high_"+boost_str[j]+"_"+basemass_str[3]+"_cat0"))->Clone(); hist_data[12][j] = (TH1*)(workspace->Get("th1f_nominal_bkg_1high_"+boost_str[j]+"_"+basemass_str[4]+"_cat0"))->Clone(); hist_data[13][j] = (TH1*)(workspace->Get("th1f_nominal_bkg_2high_"+boost_str[j]+"_"+basemass_str[4]+"_cat0"))->Clone(); hist_data[14][j] = (TH1*)(workspace->Get("th1f_nominal_bkg_3high_"+boost_str[j]+"_"+basemass_str[4]+"_cat0"))->Clone(); hist_sig[j] = (TH1*)(workspace->Get("th1f_nominal_sig_"+boost_str[j]+"_ggh_140.0_cat0"))->Clone(); hist_data[8][j]->Add(hist_sig[j],sig_sf); hist_bkg[0][j] = (TH1*)(workspace_mc->Get("th1f_nominal_bkg_mc_3low_"+boost_str[j]+"_"+basemass_str[0]+"_cat0"))->Clone(); hist_bkg[1][j] = (TH1*)(workspace_mc->Get("th1f_nominal_bkg_mc_2low_"+boost_str[j]+"_"+basemass_str[0]+"_cat0"))->Clone(); hist_bkg[2][j] = (TH1*)(workspace_mc->Get("th1f_nominal_bkg_mc_1low_"+boost_str[j]+"_"+basemass_str[0]+"_cat0"))->Clone(); hist_bkg[3][j] = (TH1*)(workspace_mc->Get("th1f_nominal_bkg_mc_3low_"+boost_str[j]+"_"+basemass_str[1]+"_cat0"))->Clone(); hist_bkg[4][j] = (TH1*)(workspace_mc->Get("th1f_nominal_bkg_mc_2low_"+boost_str[j]+"_"+basemass_str[1]+"_cat0"))->Clone(); hist_bkg[5][j] = (TH1*)(workspace_mc->Get("th1f_nominal_bkg_mc_1low_"+boost_str[j]+"_"+basemass_str[1]+"_cat0"))->Clone(); hist_bkg[6][j] = (TH1*)(workspace_mc->Get("th1f_nominal_bkg_mc_1high_"+boost_str[j]+"_"+basemass_str[2]+"_cat0"))->Clone(); hist_bkg[7][j] = (TH1*)(workspace_mc->Get("th1f_nominal_bkg_mc_2high_"+boost_str[j]+"_"+basemass_str[2]+"_cat0"))->Clone(); hist_bkg[8][j] = (TH1*)(workspace_mc->Get("th1f_nominal_bkg_mc_3high_"+boost_str[j]+"_"+basemass_str[2]+"_cat0"))->Clone(); hist_bkg[9][j] = (TH1*)(workspace_mc->Get("th1f_nominal_bkg_mc_1high_"+boost_str[j]+"_"+basemass_str[3]+"_cat0"))->Clone(); hist_bkg[10][j] = (TH1*)(workspace_mc->Get("th1f_nominal_bkg_mc_2high_"+boost_str[j]+"_"+basemass_str[3]+"_cat0"))->Clone(); hist_bkg[11][j] = (TH1*)(workspace_mc->Get("th1f_nominal_bkg_mc_3high_"+boost_str[j]+"_"+basemass_str[3]+"_cat0"))->Clone(); hist_bkg[12][j] = (TH1*)(workspace_mc->Get("th1f_nominal_bkg_mc_1high_"+boost_str[j]+"_"+basemass_str[4]+"_cat0"))->Clone(); hist_bkg[13][j] = (TH1*)(workspace_mc->Get("th1f_nominal_bkg_mc_2high_"+boost_str[j]+"_"+basemass_str[4]+"_cat0"))->Clone(); hist_bkg[14][j] = (TH1*)(workspace_mc->Get("th1f_nominal_bkg_mc_3high_"+boost_str[j]+"_"+basemass_str[4]+"_cat0"))->Clone(); hist_bkg[8][j]->Add(hist_sig[j],sig_sf); } if (correctShape) { TString fastsim_str=""; if (fastsim) fastsim_str = "_fastsim"; TFile *f_bias = TFile::Open("/afs/cern.ch/user/f/futyand/scratch1/mva_ucsd/newBkgBias/BkgBias_mit_2var_07_01_12_v2"+fastsim_str+".root"); float slope_data_in[100][2]; float slope_mc_in[100][2]; for (int j=0; j<2; j++) { for (int ibin=1; ibin<hist_data[0][j]->GetNbinsX()+1; ibin++) { graph_data = (TGraphErrors*)(f_bias->Get("tgraph_biasslopes_data_"+boost_str[j]+"_"+mass_str))->Clone(); graph_mc = (TGraphErrors*)(f_bias->Get("tgraph_biasslopes_mc_"+boost_str[j]+"_"+mass_str))->Clone(); slope_data_in[ibin][j] = graph_data->Eval(float(ibin)-0.5); slope_mc_in[ibin][j] = graph_mc->Eval(float(ibin)-0.5); } } for (int j=0; j<2; j++) { for(int isb=0; isb<15; isb++) { hist_data_corrected[isb][j] = (TH1*)hist_data[isb][j]->Clone(); hist_bkg_corrected[isb][j] = (TH1*)hist_bkg[isb][j]->Clone(); for (int ibin=1; ibin<hist_data[isb][j]->GetNbinsX()+1; ibin++) { float deltam = mass[isb]-float(mass_in); float corrfac_data = 1./(1.+(slope_data_in[ibin][j]*deltam)); float corrfac_mc = 1./(1.+(slope_mc_in[ibin][j]*deltam)); if (ibin==6) cout << j << " " << isb << " " << deltam << " " << ibin << " " << hist_data[isb][j]->GetBinContent(ibin) << " " << slope_data_in[ibin][j] << " " << corrfac_data << endl; hist_data_corrected[isb][j]->SetBinContent(ibin,hist_data[isb][j]->GetBinContent(ibin)*corrfac_data); hist_bkg_corrected[isb][j]->SetBinContent(ibin,hist_bkg[isb][j]->GetBinContent(ibin)*corrfac_mc); } hist_data_corrected[isb][j]->Scale(hist_data[isb][j]->Integral()/hist_data_corrected[isb][j]->Integral()); hist_bkg_corrected[isb][j]->Scale(hist_bkg[isb][j]->Integral()/hist_bkg_corrected[isb][j]->Integral()); hist_data[isb][j] = hist_data_corrected[isb][j]; hist_bkg[isb][j] = hist_bkg_corrected[isb][j]; } } } TGraphErrors *G_bdtout_data[10][2]; TGraphErrors *G_bdtout_mc[10][2]; TGraphErrors *G_slope_data[2]; TGraphErrors *G_slope_mc[2]; TGraphErrors *G_chi2pol1_data[2]; TGraphErrors *G_chi2pol1_mc[2]; TGraphErrors *G_chi2pol2_data[2]; TGraphErrors *G_chi2pol2_mc[2]; TMultiGraph *mG_slope[2]; TMultiGraph *mG_chi2pol1[2]; TMultiGraph *mG_chi2pol2[2]; float slope_data[10][2]; float slope_mc[10][2]; float slope_data_err[10][2]; float slope_mc_err[10][2]; float slope_data_norm[10][2]; float slope_mc_norm[10][2]; float slope_data_temp[10]; float slope_mc_temp[10]; float slope_data_err_temp[10]; float slope_mc_err_temp[10]; float chi2pol1_data_temp[10]; float chi2pol1_mc_temp[10]; float chi2pol2_data_temp[10]; float chi2pol2_mc_temp[10]; float chi2pol1_data[10][2]; float chi2pol1_mc[10][2]; float chi2pol2_data[10][2]; float chi2pol2_mc[10][2]; float mass_err[15]; for(int i=0; i<15; i++) mass_err[i]=0.; float bdtout_data[15]; float bdtout_data_err[15]; float bdtout_mc[15]; float bdtout_mc_err[15]; float bin[10]; float bin_err[10]; for(int i=0; i<10; i++) { bin[i]=0.5+float(i); bin_err[i]=0.; } float bin_shifted[10]; float binshift[3]={-0.2,0.,0.2}; TCanvas *c_sidebands = new TCanvas("c_mass","Sidebands used for slope determination",1000,700); c_sidebands->SetFillColor(0); workspace->cd(); th1f_data_mass_cat0->SetMarkerStyle(20); th1f_data_mass_cat0->GetXaxis()->SetRangeUser(80.,190.); th1f_data_mass_cat0->Draw("e"); float max = th1f_data_mass_cat0->GetMaximum(); float max = th1f_data_mass_cat0->SetMaximum(max*1.1); float sideband_boundaries[2][15]; TBox* sideband_box[15]; for(int i=0; i<15; i++) { //cout << mass[i] << endl; sideband_boundaries[0][i] = mass[i]*(1-sidebandWidth); sideband_boundaries[1][i] = mass[i]*(1+sidebandWidth); sideband_box[i] = new TBox(sideband_boundaries[0][i],0.,sideband_boundaries[1][i],max*1.1); sideband_box[i]->SetFillColor(38); sideband_box[i]->SetFillStyle(3002); sideband_box[i]->Draw("same"); } th1f_data_mass_cat0->Draw("same"); gPad->RedrawAxis(); TLine* line_sb[2][15]; for (int i=0; i<15; i++) { for (int j=0; j<2; j++) { line_sb[j][i] = new TLine(sideband_boundaries[j][i],0.,sideband_boundaries[j][i],max*1.1); line_sb[j][i]->SetLineColor(38); line_sb[j][i]->SetLineWidth(3); line_sb[j][i]->SetLineStyle(9); line_sb[j][i]->Draw(); } } if (saveGifs) c_sidebands->SaveAs("sidebands.gif"); TH1* hist_bkg_scaled[15][2]; TH1* hist_data_scaled[15][2]; for(int j=0; j<2; j++) { for(int i=0; i<15; i++) { hist_data_scaled[i][j]=(TH1*)hist_data[i][j]->Clone(); hist_data_scaled[i][j]->Scale(1./hist_data[i][j]->Integral()); hist_bkg_scaled[i][j]=(TH1*)hist_bkg[i][j]->Clone(); hist_bkg_scaled[i][j]->Scale(1./hist_bkg[i][j]->Integral()); } } TCanvas *canvas[2]; TLine *line[2]; for(int j=0; j<2; j++) { line[j] = new TLine(0.,0.,float(nbins[j]),0.); line[j]->SetLineColor(4); line[j]->SetLineWidth(2); canvas[j] = new TCanvas("canvas_"+boost_str[j],"canvas_"+boost_str[j],1600,300); canvas[j]->Divide(nbins[j],2); canvas[j]->SetFillColor(0); TF1* func; float fitval_msig[15]; for(int bdtbin=0; bdtbin<nbins[j]; bdtbin++) fitval_msig[bdtbin]=0.; for(int bdtbin=0; bdtbin<nbins[j]; bdtbin++) { for(int i=0; i<15; i++) { bdtout_data[i] = hist_data_scaled[i][j]->GetBinContent(bdtbin+1); bdtout_data_err[i] = hist_data_scaled[i][j]->GetBinError(bdtbin+1); bdtout_mc[i] = hist_bkg_scaled[i][j]->GetBinContent(bdtbin+1); bdtout_mc_err[i] = hist_bkg_scaled[i][j]->GetBinError(bdtbin+1); } G_bdtout_data[bdtbin][j] = new TGraphErrors(15,mass,bdtout_data,mass_err,bdtout_data_err); for(int fitItr=0; fitItr<3; fitItr++) { G_bdtout_data[bdtbin][j]->Fit("pol1","Q"); func = G_bdtout_data[bdtbin][j]->GetFunction("pol1"); for(int i=0; i<15; i++) { float error_scalefac = sqrt(func->Eval(mass[i])/bdtout_data[i]); //if (i==11 && j==1 && bdtbin==5) cout << fitItr << " " << error_scalefac << " " << G_bdtout_data[bdtbin][j]->GetErrorY(i) << " "; G_bdtout_data[bdtbin][j]->SetPointError(i,0.,bdtout_data_err[i]*error_scalefac); //if (i==11 && j==1 && bdtbin==5) cout << G_bdtout_data[bdtbin][j]->GetErrorY(i) << endl; } } canvas[j]->cd(bdtbin+1); G_bdtout_data[bdtbin][j]->SetMarkerSize(.8); G_bdtout_data[bdtbin][j]->SetMarkerColor(1); G_bdtout_data[bdtbin][j]->SetMarkerStyle(20); G_bdtout_data[bdtbin][j]->Draw("AP"); G_bdtout_data[bdtbin][j]->GetXaxis()->SetLabelSize(0.07); G_bdtout_data[bdtbin][j]->GetYaxis()->SetLabelSize(0.07); G_bdtout_data[bdtbin][j]->GetXaxis()->SetTitleSize(0.07); G_bdtout_data[bdtbin][j]->GetXaxis()->SetNdivisions(5); G_bdtout_data[bdtbin][j]->Fit("pol2","Q"); func = G_bdtout_data[bdtbin][j]->GetFunction("pol2"); chi2pol2_data[bdtbin][j] = func->GetChisquare()/func->GetNDF(); G_bdtout_data[bdtbin][j]->Fit("pol1","Q"); func = G_bdtout_data[bdtbin][j]->GetFunction("pol1"); slope_data[bdtbin][j] = func->GetParameter(1); slope_data_err[bdtbin][j] = func->GetParError(1); if (fitval_msig[bdtbin]==0.) fitval_msig[bdtbin] = func->Eval(float(mass_in)); slope_data_norm[bdtbin][j] = func->Eval(float(mass_in)); chi2pol1_data[bdtbin][j] = func->GetChisquare()/func->GetNDF(); G_bdtout_data[bdtbin][j]->GetYaxis()->SetRangeUser(fitval_msig[bdtbin]*0.,fitval_msig[bdtbin]*2.); G_bdtout_mc[bdtbin][j] = new TGraphErrors(15,mass,bdtout_mc,mass_err,bdtout_mc_err); for(int fitItr=0; fitItr<3; fitItr++) { G_bdtout_mc[bdtbin][j]->Fit("pol1","Q"); func = G_bdtout_mc[bdtbin][j]->GetFunction("pol1"); for(int i=0; i<15; i++) { float error_scalefac = sqrt(func->Eval(mass[i])/bdtout_mc[i]); //if (i==12 && j==1 && bdtbin==5) cout << fitItr << " " << error_scalefac << " " << G_bdtout_mc[bdtbin][j]->GetErrorY(i) << " "; G_bdtout_mc[bdtbin][j]->SetPointError(i,0.,bdtout_mc_err[i]*error_scalefac); //if (i==12 && j==1 && bdtbin==5) cout << G_bdtout_mc[bdtbin][j]->GetErrorY(i) << endl; } } canvas[j]->cd(bdtbin+1+nbins[j]); G_bdtout_mc[bdtbin][j]->SetMarkerSize(.8); G_bdtout_mc[bdtbin][j]->SetMarkerColor(4); G_bdtout_mc[bdtbin][j]->SetMarkerStyle(20); G_bdtout_mc[bdtbin][j]->Draw("AP"); G_bdtout_mc[bdtbin][j]->GetXaxis()->SetLabelSize(0.07); G_bdtout_mc[bdtbin][j]->GetYaxis()->SetLabelSize(0.07); G_bdtout_mc[bdtbin][j]->GetXaxis()->SetTitleSize(0.07); G_bdtout_mc[bdtbin][j]->GetXaxis()->SetNdivisions(5); G_bdtout_mc[bdtbin][j]->Fit("pol2","Q"); func = G_bdtout_mc[bdtbin][j]->GetFunction("pol2"); chi2pol2_mc[bdtbin][j] = func->GetChisquare()/func->GetNDF(); G_bdtout_mc[bdtbin][j]->Fit("pol1","Q"); func = G_bdtout_mc[bdtbin][j]->GetFunction("pol1"); slope_mc[bdtbin][j] = func->GetParameter(1); slope_mc_err[bdtbin][j] = func->GetParError(1); slope_mc_norm[bdtbin][j] = func->Eval(float(mass_in)); chi2pol1_mc[bdtbin][j] = func->GetChisquare()/func->GetNDF(); G_bdtout_mc[bdtbin][j]->GetYaxis()->SetRangeUser(fitval_msig[bdtbin]*0.,fitval_msig[bdtbin]*2.); } Double_t nentries_bin; mG_slope[j] = new TMultiGraph(); mG_chi2pol1[j] = new TMultiGraph(); mG_chi2pol2[j] = new TMultiGraph(); for(int bdtbin=0; bdtbin<nbins[j]; bdtbin++) { slope_data_temp[bdtbin]=slope_data[bdtbin][j]/slope_data_norm[bdtbin][j]; slope_mc_temp[bdtbin]=slope_mc[bdtbin][j]/slope_mc_norm[bdtbin][j]; slope_data_err_temp[bdtbin]=slope_data_err[bdtbin][j]/slope_data_norm[bdtbin][j]; slope_mc_err_temp[bdtbin]=slope_mc_err[bdtbin][j]/slope_mc_norm[bdtbin][j]; chi2pol1_data_temp[bdtbin]=chi2pol1_data[bdtbin][j]; chi2pol2_data_temp[bdtbin]=chi2pol2_data[bdtbin][j]-chi2pol1_data[bdtbin][j]; chi2pol1_mc_temp[bdtbin]=chi2pol1_mc[bdtbin][j]; chi2pol2_mc_temp[bdtbin]=chi2pol2_mc[bdtbin][j]-chi2pol1_mc[bdtbin][j]; } for(int bdtbin=0; bdtbin<nbins[j]; bdtbin++) bin_shifted[bdtbin]=bin[bdtbin]+binshift[1]; G_slope_data[j] = new TGraphErrors(nbins[j],bin_shifted,slope_data_temp,bin_err,slope_data_err_temp); G_slope_data[j]->SetMarkerSize(1.); G_slope_data[j]->SetMarkerColor(1); G_slope_data[j]->SetMarkerStyle(20); G_chi2pol1_data[j] = new TGraphErrors(nbins[j],bin_shifted,chi2pol1_data_temp); G_chi2pol1_data[j]->SetMarkerSize(1.); G_chi2pol1_data[j]->SetMarkerColor(1); G_chi2pol1_data[j]->SetMarkerStyle(20); G_chi2pol2_data[j] = new TGraphErrors(nbins[j],bin_shifted,chi2pol2_data_temp); G_chi2pol2_data[j]->SetMarkerSize(1.); G_chi2pol2_data[j]->SetMarkerColor(1); G_chi2pol2_data[j]->SetMarkerStyle(20); for(int bdtbin=0; bdtbin<nbins[j]; bdtbin++) bin_shifted[bdtbin]=bin[bdtbin]+binshift[2]; G_slope_mc[j] = new TGraphErrors(nbins[j],bin_shifted,slope_mc_temp,bin_err,slope_mc_err_temp); G_slope_mc[j]->SetMarkerSize(1.); G_slope_mc[j]->SetMarkerColor(4); G_slope_mc[j]->SetMarkerStyle(20); G_chi2pol1_mc[j] = new TGraphErrors(nbins[j],bin_shifted,chi2pol1_mc_temp); G_chi2pol1_mc[j]->SetMarkerSize(1.); G_chi2pol1_mc[j]->SetMarkerColor(4); G_chi2pol1_mc[j]->SetMarkerStyle(20); G_chi2pol2_mc[j] = new TGraphErrors(nbins[j],bin_shifted,chi2pol2_mc_temp); G_chi2pol2_mc[j]->SetMarkerSize(1.); G_chi2pol2_mc[j]->SetMarkerColor(4); G_chi2pol2_mc[j]->SetMarkerStyle(20); mG_slope[j]->Add(G_slope_data[j]); mG_slope[j]->Add(G_slope_mc[j]); mG_chi2pol1[j]->Add(G_chi2pol1_data[j]); mG_chi2pol1[j]->Add(G_chi2pol1_mc[j]); mG_chi2pol2[j]->Add(G_chi2pol2_data[j]); mG_chi2pol2[j]->Add(G_chi2pol2_mc[j]); } TCanvas *canvas_summary[2]; txt = new TLatex(); txt->SetNDC(); txt->SetTextSize(0.07); TLegend *leg = new TLegend(.15,.68,.35,.88); leg->SetBorderSize(0); leg->SetTextSize(.05); leg->AddEntry(G_slope_data[0],"Data","LP"); leg->AddEntry(G_slope_mc[0],"MC","LP"); for(int j=0; j<2; j++) { canvas_summary[j] = new TCanvas("canvas_summary_"+boost_str[j],"canvas_summary_"+boost_str[j],800,400); canvas_summary[j]->SetFillColor(0); canvas_summary[j]->Divide(2,1); gPad->SetGrid(); mG_slope[j]->Draw("AP"); mG_slope[j]->GetXaxis()->SetLimits(0.,float(nbins[j])); mG_slope[j]->GetXaxis()->SetLabelSize(0.05); mG_slope[j]->GetYaxis()->SetLabelSize(0.05); mG_slope[j]->GetXaxis()->SetTitleSize(0.05); mG_slope[j]->GetYaxis()->SetTitleSize(0.05); mG_slope[j]->GetXaxis()->SetTitle("BDT output bin number"); mG_slope[j]->GetYaxis()->SetTitle("Fractional change in bin content / GeV"); mG_slope[j]->GetYaxis()->SetRangeUser(-0.02,0.02); if (j==0) { txt->DrawLatex(0.4,0.8,"Gradient"); } else { txt->DrawLatex(0.4,0.8,"Adaptive"); } txt->Draw(); line[j]->Draw(); leg->Draw(); } TCanvas *canvas_chi2pol1; TCanvas *canvas_chi2pol2; if (plot_chi2) { canvas_chi2pol1 = new TCanvas("canvas_chi2pol1","canvas_chi2pol1",1400,300); canvas_chi2pol1->SetFillColor(0); canvas_chi2pol1->Divide(2,1); txt = new TLatex(); txt->SetNDC(); txt->SetTextSize(0.07); for(int j=0; j<2; j++) { canvas_chi2pol1->cd(1+j); gPad->SetGrid(); mG_chi2pol1[j]->Draw("AP"); mG_chi2pol1[j]->GetXaxis()->SetLimits(0.,float(nbins[j])); mG_chi2pol1[j]->GetXaxis()->SetLabelSize(0.05); mG_chi2pol1[j]->GetYaxis()->SetLabelSize(0.05); mG_chi2pol1[j]->GetXaxis()->SetTitleSize(0.05); mG_chi2pol1[j]->GetYaxis()->SetTitleSize(0.05); mG_chi2pol1[j]->GetXaxis()->SetTitle("BDT output bin number"); mG_chi2pol1[j]->GetYaxis()->SetTitle("chi2/ndof pol1"); mG_chi2pol1[j]->GetYaxis()->SetRangeUser(0.,2.); if (j==0) { txt->DrawLatex(0.4,0.8,"Gradient"); } else { txt->DrawLatex(0.4,0.8,"Adaptive"); } txt->Draw(); leg->Draw(); } canvas_chi2pol2 = new TCanvas("canvas_chi2pol2","canvas_chi2pol2",1400,300); canvas_chi2pol2->SetFillColor(0); canvas_chi2pol2->Divide(2,1); txt = new TLatex(); txt->SetNDC(); txt->SetTextSize(0.07); for(int j=0; j<2; j++) { canvas_chi2pol2->cd(1+j); gPad->SetGrid(); mG_chi2pol2[j]->Draw("AP"); mG_chi2pol2[j]->GetXaxis()->SetLimits(0.,float(nbins[j])); mG_chi2pol2[j]->GetXaxis()->SetLabelSize(0.05); mG_chi2pol2[j]->GetYaxis()->SetLabelSize(0.05); mG_chi2pol2[j]->GetXaxis()->SetTitleSize(0.05); mG_chi2pol2[j]->GetYaxis()->SetTitleSize(0.05); mG_chi2pol2[j]->GetXaxis()->SetTitle("BDT output bin number"); mG_chi2pol2[j]->GetYaxis()->SetTitle("chi2/ndof(pol2) - chi2/ndof(pol1)"); mG_chi2pol2[j]->GetYaxis()->SetRangeUser(-1.,1.); if (j==0) { txt->DrawLatex(0.4,0.8,"Gradient"); } else { txt->DrawLatex(0.4,0.8,"Adaptive"); } txt->Draw(); line[j]->Draw(); leg->Draw(); if (saveGifs) { canvas_chi2pol1->SaveAs("chi2pol1_"+mass_str+".gif"); canvas_chi2pol2->SaveAs("chi2pol2_"+mass_str+".gif"); } } } TCanvas *canvas_bdtout[2]; TH1* hist_bdtout_scaled_binnum[15][2]; TString i_str[15] = {"0","1","2","3","4","5","6","7","8","9","10","11","12","13","14"}; for(int j=0; j<2; j++) { canvas_bdtout[j] = new TCanvas("canvas_bdtout_"+boost_str[j],"canvas_bdtout_"+boost_str[j]); canvas_bdtout[j]->SetFillColor(0); canvas_bdtout[j]->SetLogy(); float max=0.; for(int i=0; i<15; i++) { hist_bdtout_scaled_binnum[i][j] = new TH1F("hist_bdtout_scaled_binnum_"+boost_str[j]+i_str[i],"hist_bdtout_scaled_binnum_"+boost_str[j]+i_str[i],nbins[0],0,float(nbins[0])); for (int ibin=0; ibin<nbins[0]+1; ibin++) { hist_bdtout_scaled_binnum[i][j]->SetBinContent(ibin,hist_data_scaled[i][j]->GetBinContent(ibin)); hist_bdtout_scaled_binnum[i][j]->SetBinError(ibin,hist_data_scaled[i][j]->GetBinError(ibin)); } } for(int i=0; i<7; i++) { hist_bdtout_scaled_binnum[i][j]->SetLineColor(kRed-i); hist_bdtout_scaled_binnum[i][j]->SetMarkerColor(kRed-i); hist_bdtout_scaled_binnum[i][j]->SetMarkerStyle(20); hist_bdtout_scaled_binnum[i][j]->SetMarkerSize(.8); if (hist_bdtout_scaled_binnum[i][j]->GetMaximum()>max) max = hist_bdtout_scaled_binnum[i][j]->GetMaximum(); } for(int i=14; i>6; i--) { hist_bdtout_scaled_binnum[i][j]->SetLineColor(kGreen-i); hist_bdtout_scaled_binnum[i][j]->SetMarkerColor(kGreen-i); hist_bdtout_scaled_binnum[i][j]->SetMarkerStyle(20); hist_bdtout_scaled_binnum[i][j]->SetMarkerSize(.8); if (hist_bdtout_scaled_binnum[i][j]->GetMaximum()>max) max = hist_bdtout_scaled_binnum[i][j]->GetMaximum(); } hist_bdtout_scaled_binnum[0][j]->SetMaximum(max*1.1); hist_bdtout_scaled_binnum[0][j]->SetMinimum(0.); hist_bdtout_scaled_binnum[0][j]->Draw("e"); hist_bdtout_scaled_binnum[0][j]->GetXaxis()->SetTitle("BDT output bin number"); hist_bdtout_scaled_binnum[0][j]->GetYaxis()->UnZoom(); for(int i=0; i<15; i++) { hist_bdtout_scaled_binnum[i][j]->Draw("e,same"); } } if (saveGifs) { for(int j=0; j<2; j++) { canvas[j]->SaveAs("slope_"+boost_str[j]+"_"+mass_str+".gif"); canvas_summary[j]->SaveAs("slope_"+boost_str[j]+"_summary_"+mass_str+".gif"); canvas_bdtout[j]->SaveAs("bdtout_"+boost_str[j]+"_"+mass_str+".gif"); } } TFile *fout_slopes = new TFile("BkgBias.root","update"); fout_slopes->cd(); TGraphErrors *tgraph_biasslopes_data_grad = (TGraphErrors*)G_slope_data[0]->Clone("tgraph_biasslopes_data_grad_"+mass_str); TGraphErrors *tgraph_biasslopes_data_ada = (TGraphErrors*)G_slope_data[1]->Clone("tgraph_biasslopes_data_ada_"+mass_str); TGraphErrors *tgraph_biasslopes_mc_grad = (TGraphErrors*)G_slope_mc[0]->Clone("tgraph_biasslopes_mc_grad_"+mass_str); TGraphErrors *tgraph_biasslopes_mc_ada = (TGraphErrors*)G_slope_mc[1]->Clone("tgraph_biasslopes_mc_ada_"+mass_str); tgraph_biasslopes_data_grad->Write(); tgraph_biasslopes_data_ada->Write(); tgraph_biasslopes_mc_grad->Write(); tgraph_biasslopes_mc_ada->Write(); /* //For Paul for(int j=0; j<2; j++) { for(int bdtbin=0; bdtbin<nbins[j]; bdtbin++) { TString bin_str; bin_str+=bdtbin; TGraphErrors *tgraph_bdtoutvsmass_data = (TGraphErrors*)G_bdtout_data[bdtbin][j]->Clone("tgraph_bdtoutvsmass_data_"+boost_str[j]+"_"+mass_str+"_bin"+bin_str); TGraphErrors *tgraph_bdtoutvsmass_mc = (TGraphErrors*)G_bdtout_mc[bdtbin][j]->Clone("tgraph_bdtoutvsmass_mc_"+boost_str[j]+"_"+mass_str+"_bin"+bin_str); tgraph_bdtoutvsmass_data->Write(); tgraph_bdtoutvsmass_mc->Write(); } for(int i=0; i<15; i++) { TString sb_str; sb_str+=(i+1); TH1 *hist_bdtout_data = (TH1*)hist_data[i][j]->Clone("hist_bdtout_data_"+boost_str[j]+"_"+mass_str+"_sideband"+sb_str); TH1 *hist_bdtout_mc = (TH1*)hist_data[i][j]->Clone("hist_bdtout_mc_"+boost_str[j]+"_"+mass_str+"_sideband"+sb_str); hist_bdtout_data->Write(); hist_bdtout_mc->Write(); } } */ }
int main(int argc, char** argv) { gROOT->SetStyle("Plain"); gStyle->SetPalette(1); // load ntuple TChain *chain = new TChain ("myanalysis/EcalAnalysisTree","EcalAnalysisTree") ; chain->Add("/tmp/malberti/EcalTree_EG_Run2010A-WZEG-Nov4Skim_v1_RAW-RECO.root"); chain->Add("/tmp/malberti/EcalTree_Electron_Run2010B-WZEG-Nov4Skim_v1_RAW-RECO.root"); int nEntries = (int)chain->GetEntries() ; cout << "FOUND " << nEntries << " ENTRIES\n" << endl;; //ecalVariables variables unsigned int runId; unsigned int eventId; unsigned int eventNaiveId; int nEcalRecHits; float ecalRecHitType[3300]; float ecalRecHitEnergy[3300]; float ecalRecHitIEta[3300]; float ecalRecHitIPhi[3300]; float ecalRecHitTime[3300]; float ecalRecHitChi2[3300]; int ecalRecHitRecoFlag[3300]; float ecalRecHitMatrixFlag[3300][5][5]; float ecalRecHitMatrix[3300][5][5]; float ecalRecHitS4oS1[3300]; int ecalDigis[3300][10]; int ecalGainId[3300][10]; // Set branch addresses. chain -> SetBranchAddress("runId", &runId); chain -> SetBranchAddress("eventId", &eventId); chain -> SetBranchAddress("eventNaiveId", &eventNaiveId); chain -> SetBranchAddress("nEcalRecHits", &nEcalRecHits); chain -> SetBranchAddress("ecalRecHitType", ecalRecHitType); chain -> SetBranchAddress("ecalRecHitEnergy", ecalRecHitEnergy); chain -> SetBranchAddress("ecalRecHitIEta", ecalRecHitIEta); chain -> SetBranchAddress("ecalRecHitIPhi", ecalRecHitIPhi); chain -> SetBranchAddress("ecalRecHitTime", ecalRecHitTime); chain -> SetBranchAddress("ecalRecHitChi2", ecalRecHitChi2); chain -> SetBranchAddress("ecalRecHitRecoFlag", ecalRecHitRecoFlag); chain -> SetBranchAddress("ecalRecHitMatrixFlag", ecalRecHitMatrixFlag); chain -> SetBranchAddress("ecalRecHitMatrix", ecalRecHitMatrix); chain -> SetBranchAddress("ecalRecHitS4oS1", ecalRecHitS4oS1); chain -> SetBranchAddress("ecalDigis", ecalDigis); chain -> SetBranchAddress("ecalGainId", ecalGainId); // output file char outfileName[100]; sprintf(outfileName,"HistosSlewRate.root"); cout << "Saving histograms on file " << outfileName <<endl; TFile saving (outfileName,"recreate") ; // histos TH1F *hGainSwitch = new TH1F("hGainSwitch","hGainSwitch",10,-5,5); hGainSwitch->GetXaxis()->SetTitle("Gain(max) - Gain(max-1)"); TH1F *hSlewRate = new TH1F("hSlewRate","hSlewRate", 5000, 0, 5000); hSlewRate ->SetFillStyle(1); hSlewRate ->SetFillColor(kRed); hSlewRate ->GetXaxis()->SetTitle("Slew Rate (ADC/ns)"); TH2F *hAmplitude = new TH2F("hAmplitude","hAmplitude", 1000, 0, 10000, 500, 0, 5000); hAmplitude -> SetMarkerColor(kRed); hAmplitude -> SetMarkerStyle(20); hAmplitude -> SetMarkerSize(0.35); hAmplitude -> GetXaxis() -> SetTitle("Expected Amplitude (ADC)"); hAmplitude -> GetYaxis() -> SetTitle("Observed Amplitude (ADC)"); TH2F *hAmplitude2 = new TH2F("hAmplitude2","hAmplitude2", 1000, 0, 10000, 500, 0, 5000); hAmplitude2 -> SetMarkerColor(kBlue); hAmplitude2 -> SetMarkerStyle(20); hAmplitude2 -> SetMarkerSize(0.35); hAmplitude2 -> GetXaxis() -> SetTitle("Expected Amplitude (ADC)"); hAmplitude2 -> GetYaxis() -> SetTitle("Observed Amplitude (ADC)"); TH2F *hAmpl_vs_Time = new TH2F("hAmpl_vs_Time","hAmpl_vs_Time", 800, -100, 100, 1000, 0, 10000); hAmpl_vs_Time -> SetMarkerColor(kRed); hAmpl_vs_Time -> SetMarkerStyle(20); hAmpl_vs_Time -> SetMarkerSize(0.3); hAmpl_vs_Time -> GetXaxis() -> SetTitle("Time (ns)"); hAmpl_vs_Time -> GetYaxis() -> SetTitle("Expected Amplitude (ADC)"); TH2F *hRatio_vs_Time = new TH2F("hRatio_vs_Time","hRatio_vs_Time", 800, -100, 100, 200, 0, 2); hRatio_vs_Time -> SetMarkerColor(kRed); hRatio_vs_Time -> SetMarkerStyle(20); hRatio_vs_Time -> SetMarkerSize(0.3); hRatio_vs_Time -> GetXaxis() -> SetTitle("Time (ns)"); hRatio_vs_Time -> GetYaxis() -> SetTitle("Ratio"); TH1F *hr1 = new TH1F("hr1","hr1",200,0,2); TH1F *hr2 = new TH1F("hr2","hr2",200,0,2); TH1F *hTfit1 = new TH1F("hTfit1","hTfit1 (expected Amplitude < 3000 ADC)",400,-50,50); hTfit1 -> SetFillStyle(3001); hTfit1 -> SetFillColor(kRed+2); hTfit1 -> GetXaxis() -> SetTitle("T_{fit} (ns)"); TH1F *hTfit2 = new TH1F("hTfit2","hTfit2 (expected Amplitude > 3000 ADC)",400,-50,50); hTfit2 -> SetFillStyle(3001); hTfit2 -> SetFillColor(kBlue+2); hTfit2 -> GetXaxis() -> SetTitle("T_{fit} (ns)"); TH1F *hAmax1 = new TH1F("hAmax1","hTAmax1 (expected Amplitude < 3000 ADC)",1000,0,10000); hAmax1 -> SetFillStyle(3001); hAmax1 -> SetFillColor(kRed+2); hAmax1 -> GetXaxis() -> SetTitle("A_{max} (ADC counts)"); TH1F *hAmax2 = new TH1F("hAmax2","hTAmax2 (expected Amplitude > 3000 ADC)",1000,0,10000); hAmax2 -> SetFillStyle(3001); hAmax2 -> SetFillColor(kBlue+2); hAmax2 -> GetXaxis() -> SetTitle("A_{max} (ADC counts)"); TGraphErrors* gsample; char gname[100]; char gtitle[100]; int ievt=0; float A[3300][10]; float G[3] = {1.,2.,12.}; // gain ratios //loop over the events for (int entry = 0 ; entry < nEntries; ++entry) { chain -> GetEntry(entry) ; if (entry%10000==0) cout << " Analyzing entry " << entry << endl; for (int ihit =0 ; ihit < nEcalRecHits; ihit++) { // barrel only if ( ecalRecHitType[ihit]!=0) continue; float energy = ecalRecHitEnergy[ihit]; float eta = ecalRecHitIEta[ihit]*0.0175; float theta = 2. * atan(exp(-eta)); float et = energy*sin(theta); //if ( energy < 100. ) continue; // E>10 GeV //cerco il sample max float ped = (ecalDigis[ihit][0] + ecalDigis[ihit][1] + ecalDigis[ihit][2])/3; int imax = 0; int maxAmpl = 0; for (int isample = 0; isample < 10 ; isample++) { if (ecalGainId[ihit][isample]!=0) A[ihit][isample] = (ecalDigis[ihit][isample] - ped) * G[ ecalGainId[ihit][isample] - 1]; if ( A[ihit][isample] >= maxAmpl) { imax = isample; maxAmpl = A[ihit][isample] ; } } // end loop over 10 samples // check gain switch bool gainSwitch = false; if (ecalGainId[ihit][imax-1]==1 && ecalGainId[ihit][imax] != ecalGainId[ihit][imax-1]) gainSwitch = true; //Seleziono eventi con gain switch if (!gainSwitch) continue; hGainSwitch -> Fill( ecalGainId[ihit][imax]-ecalGainId[ihit][imax-1]); //cout << "MAX sample = "<< imax << " MAX amplitude = "<< A[ihit][imax] << " MAX gain Id =" << ecalGainId[ihit][imax]<< endl; //cout << "MAX-1 sample = "<< imax-1 << " MAX-1 amplitude = "<< A[ihit][imax-1] << " MAX-1 gain Id =" << ecalGainId[ihit][imax-1] << endl; //cout << endl; float slewRate = A[ihit][imax-1]; hSlewRate -> Fill(slewRate); // graphs gsample = new TGraphErrors(); sprintf(gtitle,"shape_Run%d_Evt%d",runId,eventId); sprintf(gname,"shape_%d",ievt); gsample->SetName(gname); gsample->SetTitle(gtitle); gsample->GetXaxis()->SetTitle("Time (ns)"); gsample->GetYaxis()->SetTitle("ADC counts"); for (int isample = 0; isample < 10 ; isample++) { gsample->SetPoint(isample, double(isample)*25., A[ihit][isample]); gsample->SetPointError(isample,0.,0.9); } // fit function TF1 *fpulseShape = new TF1("fpulseShape", pulseShape,0.,240.,3); fpulseShape->SetLineColor(kBlue); fpulseShape->SetParName(0,"Ped"); fpulseShape->SetParName(1,"A"); fpulseShape->SetParName(2,"T0"); fpulseShape->FixParameter(0,0); // ped fpulseShape->SetParameter(1,A[ihit][imax]); // ampl fpulseShape->SetParameter(2,imax*25.); // T0 gsample->RemovePoint(imax-1); gsample->Fit("fpulseShape","QSR+") ; //re-set dei punti, altrimenti root non li plotta! for (int isample = 0; isample < 10 ; isample++) { gsample->SetPoint(isample, double(isample)*25., A[ihit][isample]); gsample->SetPointError(isample,0.,0.9); } ievt++; float measuredAmpl = A[ihit][imax-1] ; float expectedAmpl = A[ihit][imax] * fpulseShape->Eval((imax-1)*25.)/fpulseShape->Eval(imax*25.); hAmplitude -> Fill(expectedAmpl,measuredAmpl); hAmplitude2 -> Fill( A[ihit][imax] * 0.774,measuredAmpl); float t0 = fpulseShape->GetParameter(2); hAmpl_vs_Time -> Fill(t0-125.,expectedAmpl); hRatio_vs_Time -> Fill(t0-125., fpulseShape->Eval((imax-1)*25.)/fpulseShape->Eval(imax*25.)); if (expectedAmpl > 3000) { hr2->Fill( fpulseShape->Eval((imax-1)*25.)/fpulseShape->Eval(imax*25.)); hTfit2->Fill(t0-125.); hAmax2->Fill(A[ihit][imax]); } else { hr1->Fill( fpulseShape->Eval((imax-1)*25.)/fpulseShape->Eval(imax*25.)); hTfit1->Fill(t0-125.); hAmax1->Fill(A[ihit][imax]); } if ( expectedAmpl < 3000 ) //if (ievt<10) gsample->Write(); } // end loop over recHits }//end loop over events chain->Delete(); saving.cd () ; hGainSwitch ->Write(); hSlewRate -> Write(); hAmplitude ->Write(); hAmplitude2 ->Write(); hAmpl_vs_Time ->Write(); hRatio_vs_Time ->Write(); hTfit1->Write(); hTfit2->Write(); hAmax1->Write(); hAmax2->Write(); hr1->Write(); hr2->Write(); saving.Close () ; return 0; }
//--------------------------------------------------------------- double *treat(TString fileData, double lumi, TString decay, vector<double> mtop, vector<double> xlim, int binned, TString date, TString version) //--------------------------------------------------------------- { //TString indir = date+"/v"+version+"/"; TString indir = date+"/"+version+"/"; TString outdir = indir; TString channel = " + Jets channel"; if (fileData.Contains("ElectronHad")) { outdir += "CalibEl/"; indir += "MyAnaEl/"; if (decay.Contains("semi", TString::kIgnoreCase)) channel = "e"+channel; if (decay.Contains("di", TString::kIgnoreCase)) channel = "ee/e#mu"+channel; if (decay.Contains("all", TString::kIgnoreCase)) channel = "e/ee/e#mu"+channel; } if (fileData.Contains("MuHad")) { outdir += "CalibMu/"; indir += "MyAnaMu/"; if (decay.Contains("semi", TString::kIgnoreCase)) channel = "#mu"+channel; if (decay.Contains("di", TString::kIgnoreCase)) channel = "#mu#mu/#mue"+channel; if (decay.Contains("all", TString::kIgnoreCase)) channel = "#mu/#mu#mu/#mue"+channel; } if (fileData.Contains("Run2012")) { outdir += "CalibAll/"; indir += "MyAnaAll/"; if (decay.Contains("semi", TString::kIgnoreCase)) channel = "e/#mu"+channel; if (decay.Contains("di", TString::kIgnoreCase)) channel = "ee/#mu#mu/e#mu"+channel; if (decay.Contains("all", TString::kIgnoreCase)) channel = "e/#mu/ee/#mu#mu/e#mu"+channel; } gROOT->ProcessLine(".! mkdir "+outdir); TLatex* channel_tex = new TLatex(0.22, 0.9, channel); channel_tex->SetNDC(true); channel_tex->SetTextFont(43); channel_tex->SetTextSize(TITLE_FONTSIZE - 6); const unsigned int numberOfPoints = mtop.size(); double x[numberOfPoints], ex[numberOfPoints]; double y[numberOfPoints], ey[numberOfPoints]; for (unsigned int itop = 0; itop < numberOfPoints; itop++) { TString fileMC = TString::Format("All_%d_5.root", (int)mtop[itop]); //TString fileMC = TString::Format("TTJets_MSDecays_JpsiFilter_%d_5.root", (int)mtop[itop]); double *mean_err = new double[2]; if (binned < 2) mean_err = unbinnedFit(indir+fileMC, xlim, mtop[itop], channel_tex, outdir, lumi); if (binned == 2) mean_err = binnedFit(indir+fileMC, xlim, mtop[itop], channel_tex, outdir, lumi); y[itop] = mean_err[0]; ey[itop] = mean_err[1]; x[itop] = mtop[itop]+0.5; ex[itop] = 0.; } TGraphErrors *gr = new TGraphErrors(numberOfPoints, x, y, ex, ey); TFitResultPtr fitptr = gr->Fit("pol1", "FSQ", ""); TF1 *fit = gr->GetFunction("pol1"); double yinte = fitptr->Parameter(0); double errYinte = fitptr->ParError(0); double slope = fitptr->Parameter(1); double errSlope = fitptr->ParError(1); double chi2 = fitptr->Chi2(); double ndf = fitptr->Ndf(); double err_up[numberOfPoints]; double err_down[numberOfPoints]; double err_val[numberOfPoints]; fitptr->GetConfidenceIntervals(numberOfPoints, 1, 1, x, err_val, 0.68); for(unsigned int itop = 0; itop < numberOfPoints; itop++) { double error = err_val[itop]; err_up[itop] = fit->Eval(x[itop]) + error; err_down[itop] = fit->Eval(x[itop]) - error; } TGraph *gr_up = new TGraph(numberOfPoints,x,err_up); gr_up->Fit("pol2","FQ",""); TF1 *fit_up = gr_up->GetFunction("pol2"); TGraph *gr_down = new TGraph(numberOfPoints,x,err_down); gr_down->Fit("pol2","FQ",""); TF1 *fit_down = gr_down->GetFunction("pol2"); TLegend *leg_calib = new TLegend(0.2,0.75,0.65,0.83,NULL,"brNDC"); leg_calib->SetTextSize(0.04); leg_calib->AddEntry(gr,TString::Format("Slope of %.2f #pm %.2f", slope, errSlope),"lp"); leg_calib->SetHeader("Calibration curve"); // Blinded analysis TCanvas *cn_calib = new TCanvas("cn_calib", "cn_calib", 800, 800); cn_calib->cd(); grapherrors_myStyle(gr,"gr",2,30,1,30,1001,-1111,-1111,510,510,21,36,1.,"M_{t} (GeV)","M_{J/#psi+l} (GeV)"); gr->Draw("AP"); cn_calib->Update(); fit->SetLineColor(30); fit_up->SetLineColor(29); fit_up->SetLineStyle(2); fit_up->SetLineWidth(2); fit_up->Draw("same"); fit_down->SetLineColor(29); fit_down->SetLineStyle(2); fit_down->SetLineWidth(2); fit_down->Draw("same"); leg_myStyle(leg_calib); leg_calib->SetTextAlign(22); leg_calib->Draw(); channel_tex->Draw("same"); cms_myStyle(lumi, false); TString outBlind = outdir; if (binned < 2) outBlind += "BlindedUnbinnedCalibration"; if (binned == 2) outBlind += "BlindedBinnedCalibration"; cn_calib->SaveAs(outBlind+".pdf"); cn_calib->SaveAs(outBlind+".C"); cn_calib->SaveAs(outBlind+".jpg"); cn_calib->SaveAs(outBlind+".eps"); // Unblinded analysis double *data_fit = new double[2]; if (binned == 0) data_fit = unbinnedFit(indir+fileData, xlim, 0., channel_tex, outdir, lumi); if (binned > 0) data_fit = binnedFit(indir+fileData, xlim, 0., channel_tex, outdir, lumi); double mean_gaus = data_fit[0]; double err_gaus = data_fit[1]; TString mjpsil_res = TString::Format("M_{J/#psi+l} = (%3.1f #pm %3.1f) GeV", mean_gaus, err_gaus); double x_horiz[4]={gr->GetXaxis()->GetXmin(),fit->GetX(mean_gaus+err_gaus,0,250),fit->GetX(mean_gaus-err_gaus,0,250),gr->GetXaxis()->GetXmin()}; double y_horiz[4]={mean_gaus+err_gaus,mean_gaus+err_gaus,mean_gaus-err_gaus,mean_gaus-err_gaus}; TPolyLine *horiz = new TPolyLine(4,x_horiz,y_horiz); TLine *horiz_sup = new TLine(x_horiz[0], y_horiz[0], x_horiz[1], y_horiz[1]); TLine *horiz_med = new TLine(gr->GetXaxis()->GetXmin(), mean_gaus, fit->GetX(mean_gaus,0,250), mean_gaus); TLine *horiz_inf = new TLine(x_horiz[2], y_horiz[2], x_horiz[3], y_horiz[3]); double x_vert_min[4]={fit_up->GetX(mean_gaus-err_gaus,0,250),fit_up->GetX(mean_gaus-err_gaus,0,250),x_horiz[2],x_horiz[2]}; double y_vert_min[4]={gr->GetYaxis()->GetXmin(),mean_gaus-err_gaus,mean_gaus-err_gaus,gr->GetYaxis()->GetXmin()}; TPolyLine *vert_min = new TPolyLine(4,x_vert_min,y_vert_min); double x_vert_mean[4]={x_horiz[2],x_horiz[2],x_horiz[1],x_horiz[1]}; double y_vert_mean[4]={gr->GetYaxis()->GetXmin(),y_horiz[2],y_horiz[1],gr->GetYaxis()->GetXmin()}; TPolyLine *vert_mean = new TPolyLine(4,x_vert_mean,y_vert_mean); double x_vert_max[4]={x_horiz[1],x_horiz[1],fit_down->GetX(mean_gaus+err_gaus,0,250),fit_down->GetX(mean_gaus+err_gaus,0,250)}; double y_vert_max[4]={gr->GetYaxis()->GetXmin(),mean_gaus+err_gaus,mean_gaus+err_gaus,gr->GetYaxis()->GetXmin()}; TPolyLine *vert_max = new TPolyLine(4,x_vert_max,y_vert_max); TLine *vert1 = new TLine(x_vert_min[0],y_vert_min[0],x_vert_min[1],y_vert_min[1]); TLine *vert2 = new TLine(x_vert_mean[0],y_vert_mean[0],x_vert_mean[1],y_vert_mean[1]); TLine *vert3 = new TLine(fit->GetX(mean_gaus,0,250),y_vert_mean[0],fit->GetX(mean_gaus,0,250),mean_gaus); TLine *vert4 = new TLine(x_vert_mean[3],y_vert_mean[3],x_vert_mean[2],y_vert_mean[2]); TLine *vert5 = new TLine(x_vert_max[3],y_vert_max[3],x_vert_max[2],y_vert_max[2]); TString mt_res; double pm_fit = (x_vert_mean[3]-x_vert_mean[0])/2.; double p_fit = x_vert_max[3]-x_vert_mean[3]; double m_fit = x_vert_mean[0]-x_vert_min[0]; if (fabs(p_fit-m_fit)<0.1) mt_res= TString::Format("M_{t} = (%0.1f #pm %0.1f #pm %0.1f) GeV", fit->GetX(mean_gaus,0,250), pm_fit, fabs(m_fit)); else mt_res= TString::Format("M_{t} = (%0.1f #pm %0.1f #splitline{_{+ %0.1f}}{_{- %0.1f}}) GeV", fit->GetX(mean_gaus,0,250),pm_fit, fabs(p_fit), fabs(m_fit)); double *mtop_res = new double[2]; mtop_res[0] = fit->GetX(mean_gaus,0,250); mtop_res[1] = pm_fit + max(fabs(p_fit), fabs(m_fit)); TLegend *leg_res = new TLegend(0.2,0.75,0.65,0.87,NULL,"brNDC"); leg_res->SetTextSize(0.04); leg_res->AddEntry(gr,TString::Format("Slope of %.2f #pm %.2f", slope, errSlope),"lp"); leg_res->AddEntry((TObject*)0, mjpsil_res, ""); leg_res->AddEntry((TObject*)0, mt_res, ""); TCanvas *cn_res = new TCanvas("cn_res", "cn_res", 800, 800); cn_res->cd(); grapherrors_myStyle(gr,"gr",2,30,1,30,1001,-1111,-1111,510,510,21,36,1.,"M_{t} (GeV)","M_{J/#psi+l} (GeV)"); gr->Draw("AP"); cn_res->Update(); fit->SetLineColor(30); fit_up->SetLineColor(29); fit_up->SetLineStyle(2); fit_up->SetLineWidth(2); fit_up->Draw("same"); fit_down->SetLineColor(29); fit_down->SetLineStyle(2); fit_down->SetLineWidth(2); fit_down->Draw("same"); poly_myStyle(horiz,0,30,1,9,3002); horiz->Draw("f"); horiz->Draw("same"); line_myStyle(horiz_sup,2,9,2); horiz_sup->Draw("same"); line_myStyle(horiz_med,2,4,1); horiz_med->Draw("same"); line_myStyle(horiz_inf,2,9,2); horiz_inf->Draw("same"); poly_myStyle(vert_min,0,9,2,38,3003); vert_min->Draw("f"); vert_min->Draw("same"); poly_myStyle(vert_mean,0,30,1,9,3002); vert_mean->Draw("f"); vert_mean->Draw("same"); poly_myStyle(vert_max,2,38,2,38,3003); vert_max->Draw("f"); vert_max->Draw("same"); line_myStyle(vert1,2,38,2); vert1->Draw("same"); line_myStyle(vert2,2,9,2); vert2->Draw("same"); line_myStyle(vert3,2,4,1); vert3->Draw("same"); line_myStyle(vert4,2,9,2); vert4->Draw("same"); line_myStyle(vert5,2,38,2); vert5->Draw("same"); leg_myStyle(leg_res); leg_res->SetTextAlign(22); leg_res->Draw(); channel_tex->Draw("same"); cms_myStyle(lumi, true); TString outUnblind = outdir; if (binned == 0) outUnblind += "UnblindedUnbinnedCalibration"; if (binned == 1) outUnblind += "UnblindedMixedCalibration"; if (binned == 2) outUnblind += "UnblindedBinnedCalibration"; cn_res->SaveAs(outUnblind+".pdf"); cn_res->SaveAs(outUnblind+".C"); cn_res->SaveAs(outUnblind+".jpg"); cn_res->SaveAs(outUnblind+".eps"); cout << "\n=============== " << channel <<" =================\n" <<endl; for (unsigned int itop = 0; itop < numberOfPoints; itop++) cout << "M_{top} = "<< x[itop] << " GeV, #tilde{M}_{J/#psi+l} = (" << y[itop] << " +/- "<< ey[itop] << ") GeV" << endl; cout << "\nCalibration:" << endl; cout << "#chi^{2}/Ndof = " << chi2/ndf << endl; cout << "slope = " << slope << " +/- " << errSlope << endl; cout << "y-intercept = " << yinte << " +/- " << errYinte << endl; if (binned == 0) cout << "\nUnbinned fit:" << endl; if (binned == 1) cout << "\nMixed fit:" << endl; if (binned == 2) cout << "\nBinned fit:" << endl; cout << mjpsil_res << endl; cout << mt_res << endl; cout << "\nFigures saved in " << outdir << endl; return mtop_res; }
// Determine sensitivity to tracker dynamic inefficiency // by studying ratio of jet responses in Runs G and F (and BCD / F, E / F) void drawAvsB() { setTDRStyle(); string epocha = "BCD";//"BCD";//"H";//"F";//"BCD";//"F";//"E";//"BCD";//"F"; string epochb = "GH";//"G";//"BCD";//"G";//"E";//"E";//"F";//"G"; // Add the rest as well string epocha2 = "";//"EF"; string epochb2 = "";//"G"; string type = "data"; vector<string> methods; methods.push_back("mpfchs1"); methods.push_back("ptchs"); bool nozjptb = false; bool nogjmpf = false; bool nogjptb = true; bool mjvsjes = false; vector<string> samples; samples.push_back("zeejet"); samples.push_back("zmmjet"); samples.push_back("gamjet"); //samples.push_back("multijet"); cout << "draw"<<epocha<<"vs"<<epochb<<endl; const char *ct = type.c_str(); const char *pa = epocha.c_str(); const char *pb = epochb.c_str(); const char *pa2 = epocha2.c_str(); const char *pb2 = epochb2.c_str(); TFile *fg = new TFile(Form("rootfiles/jecdata%s.root",pb),"READ"); assert(fg && !fg->IsZombie()); TFile *ff = new TFile(Form("rootfiles/jecdata%s.root",pa),"READ"); assert(ff && !ff->IsZombie()); TFile *fg2(0), *ff2(0); if (epochb2!="") fg2 = new TFile(Form("rootfiles/jecdata%s.root",pb2),"READ"); if (epocha2!="") ff2 = new TFile(Form("rootfiles/jecdata%s.root",pa2),"READ"); TH1D *h = new TH1D("h", Form(";p_{T,ref} (GeV);%s ratio (%s / %s)", (type=="ratio" ? "Data/MC" : type=="data" ? "Data/data" : "MC/MC"), (epocha + (epocha2!="" ? "+"+epocha2 : "")).c_str(), (epochb + (epochb2!="" ? "+"+epochb2 : "")).c_str()), 3470,30,3500); h->SetMinimum(0.90); h->SetMaximum(1.15); h->GetXaxis()->SetMoreLogLabels(); h->GetXaxis()->SetNoExponent(); if (epocha=="F" && epochb=="G") lumi_13TeV = "Run2016F+G, 3.1+7.1 fb^{-1}"; if (epocha=="BCD" && epochb=="G") lumi_13TeV = "Run2016BCD+H, 12.9+8.8 fb^{-1}"; if (epocha=="BCD" && epochb=="G") lumi_13TeV = "Run2016BCD+FearlyGH, 12.9+16.8 fb^{-1}"; if (epocha=="BCD" && epochb=="F") lumi_13TeV = "Run2016BCD+F, 13+3.1 fb^{-1}"; if (epocha=="BCD" && epochb=="E") lumi_13TeV = "Run2016BCD+E, 13+4.0 fb^{-1}"; if (epocha=="E" && epochb=="F") lumi_13TeV = "Run2016E+F, 4.0+3.1 fb^{-1}"; if (epocha=="F" && epochb=="E") lumi_13TeV = "Run2016E+F, 4.0+3.1 fb^{-1}"; if ((epocha=="BCDEF" && epochb=="GH") || (epocha=="BCD" && epocha2=="EF" && epochb=="H" && epochb2=="G")) lumi_13TeV = "Run2016BCDEF+GH, 19.7+16.8 fb^{-1}"; if (epocha=="EF" && epochb=="BCD") lumi_13TeV = "Run2016BCD+EF, 12.9+6.8 fb^{-1}"; if (epocha=="H" && epochb=="G") lumi_13TeV = "Run2016G+H, 8.0+8.8 fb^{-1}"; if ((epocha=="BCD" && epocha2=="EF" && epochb=="G" && epochb2=="H")) lumi_13TeV = "Run2016BCDFearly+FlateGH, 19.7+16.8 fb^{-1}"; if ((epocha=="BCD" && epocha2=="" && ((epochb=="GH" && epochb2=="") || (epochb=="G" && epochb2=="H")))) lumi_13TeV = "Run2016BCD+FlateGH, 12.9+16.8 fb^{-1}"; if ((epocha=="EF" && epocha2=="" && ((epochb=="GH" && epochb2=="") || (epochb=="G" && epochb2=="H")))) lumi_13TeV = "Run2016EF+FlateGH, 6.8+16.8 fb^{-1}"; if ((epocha=="EF" && epocha2=="" && epochb=="G" && epochb2=="H")) lumi_13TeV = "Run2016EFearly+FlateGH, 6.8+16.8 fb^{-1}"; TCanvas *c1 = tdrCanvas("c1",h,4,11,true); c1->SetLogx(); TLatex *tex = new TLatex(); tex->SetNDC(); tex->SetTextSize(0.045); TMultiGraph *mg = new TMultiGraph(); string s = "draw"+epocha+(epocha2!="" ? "p" + epocha2 : "") +"vs"+epochb+(epochb2!="" ? "p" + epochb2 : ""); TGraphErrors *gmjb(0), *gmpf(0); for (unsigned int im = 0; im != methods.size(); ++im) { const char *cm = methods[im].c_str(); tex->DrawLatex(0.20,0.75-0.06*im,cm); s += "_" + methods[im]; for (unsigned int is = 0; is != samples.size(); ++is) { const char *cs = samples[is].c_str(); TGraphErrors *gg = (TGraphErrors*)fg->Get(Form("%s/eta00-13/%s_%s_a30",ct,cm,cs)); cout << cm << " " << cs << endl << flush; assert(gg); if (fg2) { TGraphErrors *gg2 = (TGraphErrors*)fg2->Get(Form("%s/eta00-13/%s_%s_a30",ct,cm,cs)); assert(gg2); gg = addGraph(gg,gg2); } TGraphErrors *gf = (TGraphErrors*)ff->Get(Form("%s/eta00-13/%s_%s_a30",ct,cm,cs)); assert(gf); if (ff2) { TGraphErrors *gf2 = (TGraphErrors*)ff2->Get(Form("%s/eta00-13/%s_%s_a30",ct,cm,cs)); assert(gf2); gf = addGraph(gf,gf2); } if (!(gf->GetN()==gg->GetN())) { // Remove highest pT point is that is the offender (BCD vs GH) if (gg->GetN()>gf->GetN() && fabs(gg->GetX()[gg->GetN()-1]/gf->GetX()[gf->GetN()-1]-1)>0.1 && fabs(gg->GetX()[gg->GetN()-2]/gf->GetX()[gf->GetN()-1]-1)<0.1) { cout << "Remove point B(N-1)" << endl; gg->RemovePoint(gg->GetN()-1); } else { cout << "sample " << samples[is] << " method " << methods[im] << " gf->N: " << gf->GetN() << " gg->N: " << gg->GetN() << endl; cout << " x_gf(N-1)=" << gf->GetX()[gf->GetN()-1] << " x_gg(N-1)=" << gg->GetX()[gg->GetN()-1] << " x_gg(N-2)=" << gg->GetX()[gg->GetN()-2] << endl; } assert(gf->GetN()==gg->GetN()); } TGraphErrors *g = (TGraphErrors*)gg->Clone(Form("ge_%s_%s",cm,cs)); for (int i = 0; i != g->GetN(); ++i) { double yg = gg->GetY()[i]; double yf = gf->GetY()[i]; g->SetPoint(i, gg->GetX()[i], yf / yg); double ex = gg->GetEX()[i]; double eg = gg->GetEY()[i]; double ef = gf->GetEY()[i]; g->SetPointError(i, ex, yf/yg*sqrt(pow(eg/yg,2)+pow(ef/yf,2))); } //g->Draw(is==0 ? "AP" : "SAMEP"); g->SetLineWidth(1+is); g->Draw("SAMEPZ"); if (samples[is]=="gamjet" && methods[im]=="mpfchs1" && nogjmpf) { tex->SetTextColor(kBlue); tex->DrawLatex(0.20,0.63,"#gamma+jet MPF excl. from fit"); tex->SetTextColor(kBlack); } else if (samples[is]=="gamjet" && methods[im]=="ptchs" && nogjptb) { tex->SetTextColor(kBlue); tex->DrawLatex(0.20,0.63,"#gamma+jet p_{T}^{bal} excl. from fit"); tex->SetTextColor(kBlack); } else if ((samples[is]=="zmmjet" || samples[is]=="zeejet") && methods[im]=="ptchs" && nozjptb) { tex->SetTextColor(kRed); tex->DrawLatex(0.20,0.63,"Z+jet p_{T}^{bal} excl. from fit"); tex->SetTextColor(kBlack); } else if (samples[is]=="multijet") { g->SetMarkerColor(kGray+1); g->SetLineColor(kGray+1); if (methods[im]=="ptchs") gmjb = g; if (methods[im]=="mpfchs1") gmpf = g; } else mg->Add(g); } // for is } // for im if (nogjmpf) s += "_nogjmpf"; if (nogjptb) s += "_nogptb"; if (nozjptb) s += "_nozptb"; if (mjvsjes) { s += "_mjvsjes"; tex->SetTextColor(kBlack); tex->DrawLatex(0.20,0.58,"Multijet vs JES fit"); } TF1 *fjes = new TF1("fjes",jesFit,30,2200,2); fjes->SetParameters(0.99,0.05); mg->Fit(fjes,"RN"); fjes->SetLineColor(kBlack); fjes->SetLineStyle(kDashed); fjes->SetLineWidth(2); fjes->SetRange(10.,3500.); fjes->Draw("SAME"); //TF1 *ft = new TF1("ft","1-[0]-[1]*pow(x,[2]) + ([3]+[4]*log(x))/x",30,2200); //ft->SetParameters(0,0.05,-0.5,1,0.1); //ft->FixParameter(3,0); // Logarithmic sigmoid //TF1 *ft = new TF1("ft","[0]+(1-[0])/(1. + exp(-(log(x)-log(abs([1])))" // "/(log(abs([2])+abs([1]))-log(abs([1])))))", 30,2200); //ft->SetParameters(0.98, 150, 50); TF1 *ft = new TF1("ft","[0]+(1-[0])/(1. + exp(-(log(x)-[1])/[2]))",30,2200); //ft->SetParameters(0.98,log(145),log(190)-log(145)); //ft->SetParameters(0.982,4.967,0.271); //ft->SetParameters(0.976,5.040,0.370); // ENDCAP //ft->SetParameters(0.985,5.0,0.3); ft->SetParameters(0.985,5.025,0.3); //ft->FixParameter(1,5.03); // semi-weighted average of BCD and EF //ft->FixParameter(2,0.395); // combined fit to BCD+EF / G+H // ( 12.9*5.055+6.8*5.000)/(12.9+6.8) ft->FixParameter(1,5.036); // semi-weighted average of BCD/GH and EF/GH // ( 12.9*0.344 + 6.8*0.455)/(12.9+6.8) ft->FixParameter(2,0.391); // combined fit to BCD+EF / GH // Log-sigmoid + powerlaw //TF1 *ft = new TF1("ft","[0]+(1-[0])/(1. + exp(-(log(x)-[1])/[2]))" // "*(1-[3]*pow(x,[4]))",30,2200); //ft->SetParameters(0.982,4.967,0.271,0.1,-0.2); // Double powerlaw //TF1 *ft = new TF1("ft","[4]-[0]*pow(x,[1])-[2]*pow(x,[3])",30,2200); //ft->SetParameters(0.05,-0.15,0.01,-0.3,1); mg->Fit(ft,"RN"); ft->SetLineColor(kBlue); ft->SetLineWidth(2); ft->SetRange(10.,3500.); ft->Draw("SAME"); // Map multijet with response ratio if (gmpf) { // we have multijet available TGraphErrors *gmpf2 = (TGraphErrors*)gmpf->Clone("gmpf2"); gmpf2->SetMarkerColor(kBlack);//kGray+1); gmpf2->SetLineColor(kBlack);//kGray+1); for (int i = 0; i != gmpf->GetN(); ++i) { if (mjvsjes) { gmpf2->SetPoint(i, 0.4*gmpf->GetX()[i], fjes->Eval(gmpf->GetX()[i])/gmpf->GetY()[i]); gmpf2->SetPointError(i, 0.4*gmpf->GetEX()[i], gmpf->GetEY()[i]); } else { gmpf2->SetPoint(i, 0.4*gmpf->GetX()[i], ft->Eval(gmpf->GetX()[i])/gmpf->GetY()[i]); gmpf2->SetPointError(i, 0.4*gmpf->GetEX()[i], gmpf->GetEY()[i]); } } gmpf2->Draw("SAMEPz"); } // multijet tex->SetTextColor(kBlue); tex->DrawLatex(0.50,0.85,Form("#chi^{2} / NDF = %1.1f / %d", ft->GetChisquare(), ft->GetNDF())); tex->SetTextColor(kBlack); tex->SetTextSize(0.040); tex->DrawLatex(0.50,0.80,Form("(#chi^{2} / NDF = %1.1f / %d)", fjes->GetChisquare(), fjes->GetNDF())); tex->SetTextColor(kBlue-9); tex->SetTextSize(0.030); tex->DrawLatex(0.20,0.25,ft->GetExpFormula()); tex->DrawLatex(0.20,0.20, Form("p_{0}=%1.3f#pm%1.3f" ", p_{1}=%1.3f#pm%1.3f" ", p_{2}=%1.3f#pm%1.3f", ft->GetParameter(0),ft->GetParError(0), ft->GetParameter(1),ft->GetParError(1), ft->GetParameter(2),ft->GetParError(2))); if (ft->GetNpar()>3) tex->DrawLatex(0.20,0.17, Form("p_{3}=%1.3f#pm%1.3f" ", p_{4}=%1.3f#pm%1.3f", ft->GetParameter(3),ft->GetParError(3), ft->GetParameter(4),ft->GetParError(4))); c1->SaveAs(Form("pdf/%s.pdf",s.c_str())); for (int i = 0; i != ft->GetNpar(); ++i) { cout << Form("%s%1.4g",i==0 ? "{" : ", ",ft->GetParameter(i)); } cout << "}" << endl; }
void ratioPlots_Zxx() { // llbb_Mass_reco mfJetEta_450_600 mfJetEta_250_300 lljjMass_reco mjj_HighMass_reco drll_HighMass_reco TString Variable = "Zxx_Mass_reco"; // TString Variable2 = "Zbb_Mass_reco"; TString x_title = "M_{llxx}"; Int_t N_Rebin = 10; Double_t yTopLimit = 3; TFile *f1 = TFile::Open("/home/fynu/amertens/storage/test/MG_PY6_/output/MG_PY6_/MG_PY6v9.root"); TH1D *h1 = (TH1D*)f1->Get(Variable); h1->Sumw2(); // h1->Add((TH1D*)f1->Get(Variable2)); h1->SetDirectory(0); f1->Close(); TFile *f2 = TFile::Open("/home/fynu/amertens/storage/test/aMCNLO_PY8_/output/aMCNLO_PY8_/aMCNLO_PY8v9.root"); TH1D *h2 = (TH1D*)f2->Get(Variable); h2->Sumw2(); // h2->Add((TH1D*)f2->Get(Variable2)); h2->SetDirectory(0); f2->Close(); /* TFile *f3 = TFile::Open("/home/fynu/amertens/storage/test/MG_PY8_/output/MG_PY8_/MG_PY8.root"); TH1D *h3 = (TH1D*)f3->Get(Variable); h3->SetDirectory(0); f3->Close(); */ // h1->Sumw2(); // h2->Sumw2(); // h3->Sumw2(); cout << "MG_PY6 : " << h1->Integral() << endl; cout << "aMC@NLO_PY8 : " << h2->Integral() << endl; //h1->Scale(1.0/151456.0); //h2->Scale(1.0/1.45192e+09); //h2->Scale(1./12132.9); h1->Scale(1.0/h1->Integral()); h2->Scale(1.0/h2->Integral()); h1->Sumw2(); h2->Sumw2(); // h3->Scale(1.0/h3->Integral()); h1->Rebin(N_Rebin); h2->Rebin(N_Rebin); // h3->Rebin(N_Rebin); TH1D *h1c = h1->Clone(); h1c->Sumw2(); TH1D *h2c = h2->Clone(); h2c->Sumw2(); TH1D *h1c2 = h1->Clone(); h1c2->Sumw2(); h2c->Add(h1c,-1); h2c->Divide(h1c); h1->SetTitle(""); h2->SetTitle(""); // h3->SetTitle(""); h1->SetLineColor(kRed); // h3->SetLineColor(kGreen); TCanvas *c1 = new TCanvas("c1","example",600,700); TPad *pad1 = new TPad("pad1","pad1",0,0.5,1,1); pad1->SetBottomMargin(0); gStyle->SetOptStat(0); pad1->Draw(); pad1->cd(); h2->DrawCopy(); // h3->DrawCopy("same"); h1->GetYaxis()->SetLabelSize(0.1); h1->GetYaxis()->SetRangeUser(0, 0.2);// ,yTopLimit); h1->GetYaxis()->SetTitleSize(0.06); h1->GetYaxis()->SetTitleOffset(0.7); h1->Draw("same"); TLegend *leg = new TLegend(0.6,0.7,0.89,0.89); leg->SetLineColor(0); leg->SetFillColor(0); //leg->AddEntry(h1,"t#bar{t} uncertainty","f"); leg->AddEntry(h1,"MG5 + PY6","l"); leg->AddEntry(h2,"aMC@NLO + PY8","l"); // leg->AddEntry(h3,"MG5 + PY8","l"); leg->Draw(); c1->cd(); TPad *pad2 = new TPad("pad2","pad2",0,0,1,0.5); pad2->SetTopMargin(0); pad2->SetBottomMargin(0.4); pad2->Draw(); pad2->cd(); pad2->SetGrid(); h2->SetStats(0); h2->Divide(h1); //h2->SetMarkerStyle(21); h2->Draw("ep"); h2->GetYaxis()->SetLabelSize(0.1); h2->GetYaxis()->SetRangeUser(-0.5, 2.5);// ,yTopLimit); h2->GetYaxis()->SetTitle("aMC@NLO+PY8 / MG5+PY6"); h2->GetYaxis()->SetTitleSize(0.06); h2->GetYaxis()->SetTitleOffset(0.7); h2->GetXaxis()->SetLabelSize(0.1); h2->GetXaxis()->SetTitle(x_title); h2->GetXaxis()->SetTitleSize(0.16); h2->GetXaxis()->SetTitleOffset(0.9); // Double_t matrix[4][4]; h2->Fit("pol3","","",50.0,1200.0); TF1 *ratio = h2->GetFunction("pol3"); TVirtualFitter *fitter = TVirtualFitter::GetFitter(); TMatrixD matrix(4,4,fitter->GetCovarianceMatrix()); Double_t errorPar00 = fitter->GetCovarianceMatrixElement(0,0); Double_t errorPar11 = fitter->GetCovarianceMatrixElement(1,1); Double_t errorPar22 = fitter->GetCovarianceMatrixElement(2,2); Double_t errorPar33 = fitter->GetCovarianceMatrixElement(3,3); // c1->cd(); matrix.Print(); //const TMatrixDSym m = matrix; const TMatrixDEigen eigen(matrix); const TMatrixD eigenVal = eigen.GetEigenValues(); const TMatrixD V = eigen.GetEigenVectors(); cout << "V" << endl; V.Print(); cout << "eigenVal" << endl; eigenVal.Print(); cout << "Recomputed diag" << endl; //const TMatrixD Vt(TMatrixD::kTransposed,V); //const TMatrixD Vinv = V.Invert(); const TMatrixD Vt(TMatrixD::kTransposed,V); //cout << "V-1" << endl; //Vinv.Print(); cout << "Vt" << endl; Vt.Print(); const TMatrixD VAVt = Vt*matrix*V; VAVt.Print(); const TVectorD FittedParam(4); FittedParam(0) = fitter->GetParameter(0); FittedParam(1) = fitter->GetParameter(1); FittedParam(2) = fitter->GetParameter(2); FittedParam(3) = fitter->GetParameter(3); FittedParam.Print(); //const TVectorD FittedParamNB(4); const TVectorD PNb = V*FittedParam; cout << "Pnb" << endl; PNb.Print(); cout << " Generating other parameters values " << endl; cout <<" V " << V(0,0) << endl; TRandom3 r; const TVectorD NewP(4); TH1D *hist100 = new TH1D("h100","h100",200,-5,5); TH1D *hist200 = new TH1D("h200","h200",200,-5,5); TH1D *hist400 = new TH1D("h400","h400",200,-5,5); TH1D *hist600 = new TH1D("h600","h600",100,-5,5); TH1D *hist800 = new TH1D("h800","h800",100,-5,5); TH1D *hist1000 = new TH1D("h1000","h1000",100,-5,5); TH1D *histp0 = new TH1D("p0","p0",100,-0.2,0.3); TH1D *histp1 = new TH1D("p1","p1",100,0.0,0.01); TH1D *histp2 = new TH1D("p2","p2",100,-0.00001,0); TH1D *histp3 = new TH1D("p3","p3",100,0,0.000000002); for (Int_t i = 0; i< 500; i++){ NewP(0) = r.Gaus(PNb(0),sqrt(eigenVal(0,0))); NewP(1) = r.Gaus(PNb(1),sqrt(eigenVal(1,1))); NewP(2) = r.Gaus(PNb(2),sqrt(eigenVal(2,2))); NewP(3) = r.Gaus(PNb(3),sqrt(eigenVal(3,3))); //NewP.Print(); //FittedParam.Print(); const TVectorD NewP2 = Vt*NewP; //NewP2.Print(); histp0->Fill(NewP2(0)); histp1->Fill(NewP2(1)); histp2->Fill(NewP2(2)); histp3->Fill(NewP2(3)); TF1 *newFit=new TF1("test","[0]+x*[1]+[2]*pow(x,2)+[3]*pow(x,3)",0,1400); newFit->SetParameters(NewP2(0),NewP2(1),NewP2(2),NewP2(3)); newFit->SetLineColor(kBlue); Double_t area=0; for(Int_t it=1; it < 16; it++){ //cout << "bin : " << it << " " << h1c2->GetBinContent(it) << endl; area += h1c2->GetBinContent(it)*newFit->Eval(100*it+50); } //newFit->Draw("same"); //cout <<"val: " << newFit->Eval(200) << endl; hist100->Fill(newFit->Eval(100)/area); hist200->Fill(newFit->Eval(200)/area); hist400->Fill(newFit->Eval(400)/area); hist600->Fill(newFit->Eval(600)/area); hist800->Fill(newFit->Eval(800)/area); hist1000->Fill(newFit->Eval(1000)/area); } c1->cd(); TCanvas *c2 = new TCanvas("c2","c2",1000,1000); c2->cd(); c2->Divide(3,2); c2->cd(1); hist100->Draw(); c2->cd(2); hist200->Draw(); c2->cd(3); hist400->Draw(); c2->cd(4); hist600->Draw(); c2->cd(5); hist800->Draw(); c2->cd(6); hist1000->Draw(); Double_t m_100,m_200,m_400,m_600,m_800,m_1000; Double_t s_100,s_200,s_400,s_600,s_800,s_1000; hist100->Fit("gaus","","",0.3,1.2); TVirtualFitter *fitter = TVirtualFitter::GetFitter(); m_100 = fitter->GetParameter(1); s_100 = fitter->GetParameter(2); hist200->Fit("gaus","","",0.5,1.2); TVirtualFitter *fitter = TVirtualFitter::GetFitter(); m_200 = fitter->GetParameter(1); s_200 = fitter->GetParameter(2); hist400->Fit("gaus","","",0.8,1.2); TVirtualFitter *fitter = TVirtualFitter::GetFitter(); m_400 = fitter->GetParameter(1); s_400 = fitter->GetParameter(2); hist600->Fit("gaus","","",0.8,1.3); TVirtualFitter *fitter = TVirtualFitter::GetFitter(); m_600 = fitter->GetParameter(1); s_600 = fitter->GetParameter(2); hist800->Fit("gaus","","",0.5,2); TVirtualFitter *fitter = TVirtualFitter::GetFitter(); m_800 = fitter->GetParameter(1); s_800 = fitter->GetParameter(2); hist1000->Fit("gaus","","",0.5,2.5); TVirtualFitter *fitter = TVirtualFitter::GetFitter(); m_1000 = fitter->GetParameter(1); s_1000 = fitter->GetParameter(2); Double_t x[6],y[6],ym[6],yup[6],ydown[6]; x[0]=100; x[1]=200; x[2]=400;x[3]=600; x[4]=800; x[5]=1000; yup[0]=ratio->Eval(100)+s_100; yup[1]=ratio->Eval(200)+s_200; yup[2]=ratio->Eval(400)+s_400; yup[3]=ratio->Eval(600)+s_600; yup[4]=ratio->Eval(800)+s_800; yup[5]=ratio->Eval(1000)+s_1000; ydown[0]=ratio->Eval(100)-s_100; ydown[1]=ratio->Eval(200)-s_200; ydown[2]=ratio->Eval(400)-s_400; ydown[3]=ratio->Eval(600)-s_600; ydown[4]=ratio->Eval(800)-s_800; ydown[5]=ratio->Eval(1000)-s_1000; y[0]=1+s_100/ratio->Eval(100); y[1]=1+s_200/ratio->Eval(200); y[2]=1+s_400/ratio->Eval(400); y[3]=1+s_600/ratio->Eval(600); y[4]=1+s_800/ratio->Eval(800); y[5]=1+s_1000/ratio->Eval(1000); ym[0]=-s_100/m_100; ym[1]=-s_200/m_200; ym[2]=-s_400/m_400; ym[3]=-s_600/m_600; ym[4]=-s_800/m_800; ym[5]=-s_1000/m_1000; TGraph* g = new TGraph(6,x,y); TGraph* gm = new TGraph(6,x,ym); TGraph* gup = new TGraph(6,x,yup); TGraph* gdown = new TGraph(6,x,ydown); TCanvas *c3 = new TCanvas("c3","c3",1000,1000); c3->cd(); //gup->Draw("AC*"); //gdown->Draw("C*"); g->Draw("AC*"); gPad->SetBottomMargin(0.2); gPad->SetLeftMargin(0.2); gStyle->SetOptStat(0); g->GetXaxis()->SetTitle("M_{Zbb}"); g->GetXaxis()->SetRangeUser(50,1100); g->GetYaxis()->SetLabelSize(0.06); g->GetYaxis()->SetTitle("Uncertainty"); g->GetYaxis()->SetTitleSize(0.06); g->GetYaxis()->SetTitleOffset(1.4); g->GetXaxis()->SetLabelSize(0.06); g->GetXaxis()->SetTitleSize(0.06); g->GetXaxis()->SetTitleOffset(1); g->GetYaxis()->SetNdivisions(5); TFile f("syst_zxx.root","recreate"); g->Write(); f.Close(); //gm->Draw("C*"); //g->SetMaximum(1); //g->SetMinimum(-1); //h2c->Draw("same"); TH1D *h22=h2->Clone(); TCanvas *c5 = new TCanvas("c5","c5",1000,1000); gPad->SetBottomMargin(0.2); gPad->SetLeftMargin(0.2); gStyle->SetOptStat(0); h22->Draw(); h22->GetXaxis()->SetRangeUser(50,1100); h22->GetYaxis()->SetLabelSize(0.06); h22->GetYaxis()->SetTitleSize(0.06); h22->GetYaxis()->SetTitleOffset(1.4); h22->GetXaxis()->SetLabelSize(0.06); h22->GetXaxis()->SetTitleSize(0.06); h22->GetXaxis()->SetTitleOffset(1); ratio->SetLineColor(kRed); ratio->Draw("same"); gup->Draw("C"); gdown->Draw("C"); TLegend *leg = new TLegend(0.6,0.7,0.89,0.89); leg->SetLineColor(0); leg->SetFillColor(0); leg->AddEntry(h22,"aMC@NLO / MG5","lep"); leg->AddEntry(ratio,"best fit","l"); leg->AddEntry(gup,"Syst Error (#pm 1 #sigma)","l"); leg->Draw(); TCanvas *c4 = new TCanvas("c4","c4",1000,1000); c4->Divide(2,2); c4->cd(1); histp0->Draw(); c4->cd(2); histp1->Draw(); c4->cd(3); histp2->Draw(); c4->cd(4); histp3->Draw(); }
void ana_Run11_eff() { const int rebin = 1; TFile *f = TFile::Open("Rootfiles/Run11_eff.root","read"); // Run with weigth TH2F *hMcPtVsEta = (TH2F*)f->Get("mcJpsiPtY"); TH2F *hRcPtVsEta = (TH2F*)f->Get("hHt2JpsiPE"); draw2D(hMcPtVsEta); draw2D(hRcPtVsEta); hMcPtVsEta->GetXaxis()->SetRangeUser(-1+1e-6,1-1e-6); TH1F *hMcPt = (TH1F*)hMcPtVsEta->ProjectionY("hMcPt"); hMcPt->Rebin(rebin); hMcPt->SetMarkerStyle(20); draw1D(hMcPt,"",kTRUE); hRcPtVsEta->GetXaxis()->SetRangeUser(-1+1e-6,1-1e-6); TH1F *hRcPt = (TH1F*)hRcPtVsEta->ProjectionY("hRcPt"); hRcPt->Rebin(rebin); hRcPt->SetMarkerStyle(21); hRcPt->SetMarkerColor(2); hRcPt->SetLineColor(2); hRcPt->Draw("sames P"); TH1F *hRatio = (TH1F*)hRcPt->Clone("hRatio_fromRunning"); hRatio->Rebin(100); hMcPt->Rebin(100); hRatio->Divide(hMcPt); cEff = draw1D(hRatio,""); // Run without weight TH2F *hMcPtVsEtaNoWeight = (TH2F*)f->Get("mcJpsiPtY_Or"); draw2D(hMcPtVsEtaNoWeight); TH2F *hMcPtVsRcNoWeight = (TH2F*)f->Get("hJpsiRcvsMC_Cut1"); hMcPtVsRcNoWeight->RebinX(rebin); hMcPtVsRcNoWeight->RebinY(rebin); draw2D(hMcPtVsRcNoWeight); hMcPtVsEtaNoWeight->GetXaxis()->SetRangeUser(-1+1e-6,1-1e-6); TH1F *hMcPtNoWeight = (TH1F*)hMcPtVsEtaNoWeight->ProjectionY("hMcPtNoWeight"); hMcPtNoWeight->Rebin(rebin); hMcPtNoWeight->SetMarkerStyle(20); hMcPtNoWeight->SetMinimum(1); draw1D(hMcPtNoWeight,"",kTRUE); TH1F *hRcPtNoWeight = (TH1F*)hMcPtVsRcNoWeight->ProjectionX("hRcPtNoWeight"); hRcPtNoWeight->SetMarkerStyle(21); hRcPtNoWeight->SetMarkerColor(2); hRcPtNoWeight->SetLineColor(2); hRcPtNoWeight->Draw("sames P"); TH1F *hRatioNoWeight = (TH1F*)hRcPtNoWeight->Clone("hRatioNoWeight"); hRatioNoWeight->Divide(hMcPtNoWeight); cEff->cd(); hRatioNoWeight->SetMarkerColor(4); hRatioNoWeight->Draw("samesP"); // weight with input histogram TH1F *hMcPtWeight = (TH1F*)hMcPtNoWeight->Clone("hMcPtWeight"); TH2F *hMcPtVsRcWeight = (TH2F*)hMcPtVsRcNoWeight->Clone("hMcPtVsRcWeight"); for(int ibin=1; ibin<=hMcPtVsRcNoWeight->GetNbinsX(); ibin++) { double scale = hMcPt->GetBinContent(ibin); hMcPtWeight->SetBinContent(ibin,hMcPtWeight->GetBinContent(ibin)*scale); hMcPtWeight->SetBinError(ibin,hMcPtWeight->GetBinError(ibin)*scale); for(int jbin=1; jbin<=hMcPtVsRcNoWeight->GetNbinsY(); jbin++) { hMcPtVsRcWeight->SetBinContent(ibin,jbin,hMcPtVsRcWeight->GetBinContent(ibin,jbin)*scale); hMcPtVsRcWeight->SetBinError(ibin,jbin,hMcPtVsRcWeight->GetBinError(ibin,jbin)*scale); } } TH1F *hRcPtWeight = (TH1F*)hMcPtVsRcWeight->ProjectionY("hRcPtWeight"); hRcPtWeight->SetMarkerStyle(21); hRcPtWeight->SetMarkerColor(2); hRcPtWeight->SetLineColor(2); draw2D(hMcPtVsRcWeight); draw1D(hMcPtWeight,"",kTRUE); hRcPtWeight->Draw("sames P"); TH1F *hRatioWeight = (TH1F*)hRcPtWeight->Clone("hRatioWeight"); hRatioWeight->Divide(hMcPtWeight); cEff->cd(); hRatioWeight->SetMarkerColor(6); hRatioWeight->Draw("samesP"); TH1F *hCheck = (TH1F*)hRatioWeight->Clone("check"); hCheck->Divide(hRatio); draw1D(hCheck); // weight with fitted function TCanvas *c = new TCanvas("Fit","Fit",800,600); SetPadMargin(gPad,0.15,0.15); gPad->SetLogy(); TH1F *h = new TH1F("histogram",";;;",7,0,30); h->GetYaxis()->SetRangeUser(1e-7,100); h->Draw(); TFile *fdata = TFile::Open("Rootfiles/Spectrum_in_bin.root","read"); TGraphErrors *gr = (TGraphErrors*)fdata->Get("gall"); gr->SetMarkerColor(1); gr->SetLineColor(1); gr->GetXaxis()->SetRangeUser(0,30); gr->Draw("sames PE"); TF1 *func = new TF1("func",InvPt,0,30,4); func->SetParameters(0.4,-0.4796,4.229,-7.54); gr->Fit(func,"RL"); TH1F *hMcPtFunc = (TH1F*)hMcPtNoWeight->Clone("hMcPtFunc"); TH2F *hMcPtVsRcFunc = (TH2F*)hMcPtVsRcNoWeight->Clone("hMcPtVsRcFunc"); for(int ibin=1; ibin<=hMcPtVsRcFunc->GetNbinsX(); ibin++) { double scale = func->Eval(hMcPtFunc->GetBinCenter(ibin)); hMcPtFunc->SetBinContent(ibin,hMcPtFunc->GetBinContent(ibin)*scale); hMcPtFunc->SetBinError(ibin,hMcPtFunc->GetBinError(ibin)*scale); for(int jbin=1; jbin<=hMcPtVsRcNoWeight->GetNbinsY(); jbin++) { hMcPtVsRcFunc->SetBinContent(ibin,jbin,hMcPtVsRcFunc->GetBinContent(ibin,jbin)*scale); hMcPtVsRcFunc->SetBinError(ibin,jbin,hMcPtVsRcFunc->GetBinError(ibin,jbin)*scale); } } TH1F *hRcPtFunc = (TH1F*)hMcPtVsRcFunc->ProjectionY("hRcPtFunc"); hRcPtFunc->SetMarkerStyle(21); hRcPtFunc->SetMarkerColor(2); hRcPtFunc->SetLineColor(2); hMcPtVsRcFunc->GetZaxis()->SetRangeUser(1e-4,1e2); draw2D(hMcPtVsRcFunc); hMcPtFunc->GetYaxis()->SetRangeUser(1e-4,5e4); draw1D(hMcPtFunc,"",kTRUE); hRcPtFunc->Draw("sames P"); TH1F *hRatioFunc = (TH1F*)hRcPtFunc->Clone("hRatioFunc"); hRatioFunc->Rebin(100); hMcPtFunc->Rebin(100); hRatioFunc->Divide(hMcPtFunc); cEff->cd(); hRatioFunc->SetMarkerColor(5); hRatioFunc->Draw("samesP"); TH1F *hCheck2 = (TH1F*)hRatioFunc->Clone("check2"); hCheck2->Divide(hRatio); draw1D(hCheck2); }
void anaAsyJetTrig() { //for ak3PF jets, applied for pPb data only // TFile* fcrel3 = TFile::Open("/net/hidsk0001/d00/scratch/dgulhan/RelativeResponse/Corrections/Casym_pPb_double_hcalbins_algo_ak3PF_pt100_140_jet80_alphahigh_20_phicut250.root", "readonly"); //for akPu3PF jets and pPb data TFile* fcrel3 = TFile::Open("Casym_pPb_double_hcalbins_algo_akPu3PF_pt100_140_jet80_alphahigh_20_phicut250.root", "readonly"); TH1D * C_rel=(TH1D*)fcrel3->Get("C_asym"); // fcrel3->Close(); hist_class *my_hists = new hist_class("pfjet"); cout <<my_hists->IsMC<<endl ; //this function is to correct for UE subtraction (we are using akPu3PF algorithm) TF1 * fUE ; TF1 * fgaus ; if(my_hists->IsMC==kTRUE){ fUE = new TF1("fUE","[0]/pow(x,[1])"); // //for ak3PF jets // fUE->SetParameters(0.4183,0.4244); // //for akPu3PF jets fUE->SetParameters(1.052,0.5261); //for gauss smearing fgaus=new TF1("fgaus","gaus(0)",-20,20); fgaus->SetParameters(1,0,1); } else { fUE = new TF1("fUE","1-[0]/pow(x,[1])",20,300); // //for ak3PF jets // fUE->SetParameters(0.8648,0.8167); // //for akPu3PF jets fUE->SetParameters(0.3015,0.8913); } TF1 * fVz = new TF1("fVx","[0]+[1]*x+[2]*TMath::Power(x,2)+[3]*TMath::Power(x,3)+[4]*TMath::Power(x,4)", -15., 15.); fVz->SetParameters(1.60182e+00,1.08425e-03,-1.29156e-02,-7.24899e-06,2.80750e-05); if(my_hists->IsMC==kTRUE){ pthat=atoi(getenv("PTHAT")) ; ptmax=atoi(getenv("PTMAX")) ; cout <<"pthat = " <<pthat <<" pthatmax =" <<ptmax <<endl ; } std::cout << "start working\n"; if(my_hists->IsMC!=kTRUE){ if(coll=="HI") dataPath="/net/hidsk0001/d00/scratch/yjlee/merge/pbpbDijet_v20" ;//mit PbPb data path else { /* if(TrigName=="Jet20") dataPath="root://eoscms//eos/cms/store/group/phys_heavyions/krajczar/inbound/mnt/hadoop/cms/store/user/krajczar/pPb_Jet20_Full_v1" ; else if(TrigName=="Jet40" || TrigName=="Jet60") dataPath="root://eoscms//eos/cms/store/group/phys_heavyions/krajczar/inbound/mnt/hadoop/cms/store/user/krajczar/pPb_Jet40Jet60_Full_v1" ; else dataPath="root://eoscms//eos/cms/store/group/phys_heavyions/yjlee/pPb2013/promptReco"; */ if(TrigName=="Jet80" || TrigName=="Jet100") dataPath="root://eoscms//eos/cms/store/group/phys_heavyions/yjlee/pPb2013/promptReco"; else dataPath="root://eoscms//eos/cms/store/caf/user/ymao"; } } //data Path else { //MC analysis if(coll=="HI") { if(pthat==50||pthat==80||pthat==100||pthat==170) dataPath= Form("/mnt/hadoop/cms/store/user/yenjie/HiForest_v27/"); //MIT MC normial else dataPath= Form("/mnt/hadoop/cms/store/user/yenjie/HiForest_v28/"); //MIT MC normial } else if(coll=="PPb") dataPath=Form("/mnt/hadoop/cms/store/user/dgulhan/pPb/HP04/prod16/Hijing_Pythia_pt%d/HiForest_v77_merged01", pthat); // dataPath=Form("/mnt/hadoop/cms/store/user/dgulhan/pPb/HP04/prod16/Signal_Pythia_pt%d/HiForest_v77_v2_merged01", pthat); else if(coll=="PbP") dataPath=Form("/mnt/hadoop/cms/store/user/dgulhan/Pbp/HP05/prod24/Hijing_Pythia_pt%d/HiForest_v84_merged02", pthat); else if(coll=="PP2011") dataPath= Form("/net/hisrv0001/home/zhukova/scratch/HIHighPt/forest/pthat%d", pthat); //lxplus path for pp else { if(pthat==220) // dataPath= Form("/mnt/hadoop/cms/store/user/dgulhan/pPb/HP04/prod16/Signal_Pythia_pt%d/HiForest_v77_v2_merged02", pthat); //2013 pp tracking for 5.02TeV dataPath=Form("/store/user/ymao/HiForest/MC/PYTHIA_Z2_5TeV/"); else // dataPath= Form("/mnt/hadoop/cms/store/user/dgulhan/pPb/HP04/prod16/Signal_Pythia_pt%d/HiForest_v77_v2_merged01", pthat); //2013 pp tracking for 5.02TeV dataPath=Form("/store/user/ymao/HiForest/MC/PYTHIA_Z2_5TeV/"); } } if(my_hists->IsMC!=kTRUE){ //real data analysis if(coll=="HI") intputFile="promptskim-hihighpt-hltjet80-pt90-v20.root" ; //full dataset else if(coll=="PP2011") intputFile="hiForest2_pp_ppreco_415_90percent.root"; //! 2011 pp data rereco else if(coll=="PbPb") intputFile="PbPHiForest2_PbPbPAHighPtJet80_cent50-100_pprereco.root"; else if(coll=="PPb"){ if(TrigName=="Jet20") // intputFile="mergedJet20_KK.root" ; intputFile="mergedJet20_pPb_Jet20_Full_UsingKKForest_v1.root" ; else if(TrigName=="Jet40" || TrigName=="Jet60") // intputFile="mergedJet40Jet60_KK.root" ; intputFile="mergedJet40Jet60_pPb_Jet40Jet60_Full_UsingKKForest_v1.root" ; else if(TrigName=="Jet80" || TrigName=="Jet100") intputFile="PA2013_HiForest_PromptReco_JSonPPb_forestv77.root" ; else // intputFile="PA2013_HiForest_PromptReco_KrisztianMB_JSonPPb_forestv84.root" ; intputFile="mergedMB_pPb_SingleTrack_Full_UsingKKForest_v1.root" ; } else if(coll=="PbP"){ if(TrigName=="Jet20") intputFile="mergedJet20_KK.root" ; else if(TrigName=="Jet40" || TrigName=="Jet60") intputFile="mergedJet40Jet60_KK.root" ; else if(TrigName=="Jet80" || TrigName=="Jet100") intputFile="PA2013_HiForest_PromptReco_JSonPbp_JECdb_forestv84.root" ; else intputFile="PA2013_HiForest_PromptReco_KrisztianMB_JSonPPb_forestv84.root" ; } else // intputFile="PP2013_HiForest_PromptReco_JsonPP_Jet80_HIReco_forestv84_v2.root"; //! 2013 pp data with HI tracking intputFile="PP2013_HiForest_PromptReco_JsonPP_Jet80_PPReco_forestv82.root"; //! 2013 pp data with pp tracking } else { //MC sample if(coll=="HI"){ if(pthat==50||pthat==80||pthat==100||pthat==170) intputFile=Form("Dijet%d_HydjetDrum_v27_mergedV1.root", pthat); else intputFile=Form("Dijet%d_HydjetDrum_v28_mergedV1.root", pthat); } else if(coll=="PPb") intputFile=Form("pt%d_HP04_prod16_v77_merged_forest_0.root", pthat); // intputFile=Form("pt%d_HP04_hiforest77_hiSignal.root", pthat); else if(coll=="PbP") intputFile=Form("pt%d_HP05_prod24_v84_merged_forest_0.root", pthat); else if(coll=="PP2011") intputFile=Form("mergedFile.root"); // 2011 pp MC else intputFile=Form("pt%d_HP04_hiforest77_hiSignal.root", pthat); // ! 2013 pp 5.02TeV MC with pp tracking } TString inname=Form("%s/%s", dataPath.Data(),intputFile.Data()); // Define the input file and HiForest HiForest * c ; if(coll=="PP" || coll=="PP2011") c = new HiForest(inname,"forest",cPP); else if(coll=="PPb" || coll=="PbP") c = new HiForest(inname,"forest",cPPb); else c = new HiForest(inname,"forest",cPbPb); c->doTrackCorrections = false; c->doTrackingSeparateLeadingSubleading = false; c->InitTree(); // cout << "start working222222\n"; // TFile *my_file=TFile::Open(Form("%s/%s", dataPath.Data(),intputFile.Data())); cout <<"Input file" << inname<<endl ; TrackCorrector corr("trackCorrections_HIN12017v4_HijingCombined.root"); if(doTrackCorrections){ corr.load("trkCorr_HIN12017"); corr.setOption1(true); corr.setOption2(true); } Evts * offSel = &(c->evt); Skims * my_skim = &(c->skim); Hlts * trigSel = &(c->hlt); //jet tree // if(coll=="HI") // Jets * my_ct = &(c->akPu4Calo); Jets * my_ct = &(c->akPu3PF); // else // Jets * my_ct = &(c->ak3PF); // Jets * jetthres = &(c->icPu5); //track tree Tracks * my_tr = &(c->track); //GenParticle tree GenParticles * my_GenPart = &(c->genparticle); int curr_bin = nbin-1 ; int Nevents[nbin] = {0} ; Int_t Nevt_40_60[nbin] = {0} ; Int_t Nevt_60_75[nbin] = {0} ; Int_t Nevt_75_95[nbin] = {0} ; Int_t Nevt_95_120[nbin] = {0} ; Int_t Nevt_120[nbin] = {0} ; cout <<"Number of events ="<<c->GetEntries()<<endl ; for(int evi = 0; evi < c->GetEntries(); evi++) { c->GetEntry(evi); int noise_evt = my_skim->pHBHENoiseFilter ; // int ecal_noise = my_skim->phiEcalRecHitSpikeFilter ; // if(ecal_noise==0) continue ; double vz = offSel->vz ; int hiBin = offSel->hiBin ; weight = 1. ; int pileup_Gplus ; double HFbin ; HFbin = (offSel->hiHFplusEta4)+(offSel->hiHFminusEta4); /* if(coll=="PPb") HFbin = (offSel->hiHFplus); else HFbin = (offSel->hiHFminus); */ if(my_hists->IsMC!=kTRUE){ int evt_sel ; pileup_Gplus = my_skim->pVertexFilterCutGplus ; if(coll=="PbPb"|| coll=="HI"|| coll=="PP2011") evt_sel = my_skim->pcollisionEventSelection ; else evt_sel = my_skim->pPAcollisionEventSelectionPA; // if(evt_sel==0) continue ; if(!evt_sel) continue ; } if(my_hists->IsMC!=kTRUE){ // if(noise_evt==0) continue ; if(!noise_evt) continue ; int jetTr2 ; if(coll=="HI"|| coll=="PbPb") jetTr2 = trigSel->HLT_HIJet80_v1 ; else if (coll=="PP2011") jetTr2 = trigSel->HLT_Jet60_v1 ; else { // jetTr2 = trigSel->HLT_PAJet80_NoJetID_v1 ; if(TrigName=="Jet20") jetTr2 = trigSel->HLT_PAJet20_NoJetID_v1 ; else if(TrigName=="Jet40") jetTr2 = trigSel->HLT_PAJet40_NoJetID_v1 ; else if(TrigName=="Jet60") jetTr2 = trigSel->HLT_PAJet60_NoJetID_v1 ; else if(TrigName=="Jet80") jetTr2 = trigSel->HLT_PAJet80_NoJetID_v1 ; else if(TrigName=="Jet100") jetTr2 = trigSel->HLT_PAJet100_NoJetID_v1 ; else jetTr2 = trigSel->HLT_PAZeroBiasPixel_SingleTrack_v1 ; } if(!jetTr2) continue ; int run=offSel->run ; if( !(my_skim->phfPosFilter1 && my_skim->phfNegFilter1 && my_skim->pBeamScrapingFilter && my_skim->pprimaryvertexFilter)) continue ; if(coll=="PPb"){ // if( my_skim->phfPosFilter1==0 || my_skim->phfNegFilter1==0 ||my_skim->pBeamScrapingFilter==0 || my_skim->pprimaryvertexFilter==0) continue ; if(!pileup_Gplus) continue ; if(run>211256) continue ; if(run<210676) continue ; //remove the runs with old alignment } if(coll=="PbP"){ if(pileup_Gplus==0) continue ; if(run<=211256) continue ; } } if(TMath::Abs(vz)>15.) continue ; if(my_hists->IsMC==kTRUE) weight*=fVz->Eval(vz); //run selection if(my_hists->IsMC!=kTRUE && coll=="PPb") { if(offSel->run<210676 ||offSel->run>211256) //211256: last pPb run (Pb goes to +eta) continue; } bool event_accepted = true; /* if(!(my_skim->pPAcollisionEventSelectionPA && my_skim->phfPosFilter1 && my_skim->phfNegFilter1 && my_skim->pBeamScrapingFilter && my_skim->pprimaryvertexFilter && my_skim->pVertexFilterCutGplus && TMath::Abs(offSel->vz)<15. ) ) event_accepted = false; */ if(event_accepted == false) continue; /* //if there is no jets or no PF candidates, skip the event if(my_ct->nref==0) continue ; */ //put the higher pthat cut if(my_hists->IsMC==kTRUE && my_ct->pthat>ptmax ) continue ; if(my_hists->IsMC==kTRUE && my_ct->pthat<pthat) continue ; if(my_ct->pthat>ptmax) cout <<"pthat =" <<my_ct->pthat <<endl ; if(coll=="HI"|| coll=="PP2011") my_hists->CenBin->Fill(hiBin*2.5); else my_hists->CenBin->Fill(hiBin); my_hists->Vertex->Fill(vz); // cout <<"vz =" <<vz <<endl ; if(coll=="HI"){ double centrality = hiBin*2.5 ; // my_hists->CenBin->Fill(offSel->hiBin); for(int ibin = 0 ; ibin <nbin; ibin++){ if(centrality >=centr[ibin] && centrality<centr[ibin+1]) curr_bin = ibin ; } } else if(coll=="PPb" || coll=="PbP"){ double centrality = HFbin ; for(int ibin = 0 ; ibin <nbin; ibin++){ if(centrality <hfEta4[ibin] && centrality>=hfEta4[ibin+1]) curr_bin = ibin ; } } else { curr_bin=nbin-1 ; // weight = 1. ; } // weight = 1. ; // cout << " cent_bin:" <<curr_bin <<endl ; if(evi%10000==1)cout <<" coll = " <<coll <<" weight = " <<weight <<" evt = " <<evi <<endl ; //cout << "start working222222\n"; // cout << "still working222222\n"; if(my_hists->IsMC==kFALSE)my_hists->VertexWt->Fill(vz+0.4847, weight); else my_hists->VertexWt->Fill(vz, weight); if(coll=="HI"|| coll=="PP2011") my_hists->CenBinWt->Fill(offSel->hiBin*2.5,weight); else my_hists->CenBinWt->Fill(offSel->hiBin,weight); my_hists->NEvents[curr_bin]->Fill(1, weight); //Jets for event weights; eta-pt cut removed int trackMult = 0; double leadingJet = -999.; for(int j4i = 0; j4i < my_ct->nref ; j4i++) { if( my_hists->IsMC==kTRUE && my_ct->subid[j4i] != 0) continue; if (my_ct->rawpt[j4i]<15) continue; if(TMath::Abs(my_ct->jteta[j4i])>3.) continue ; trackMult++; if (my_ct->jtpt[j4i]>leadingJet) { leadingJet = my_ct->jtpt[j4i]; } } /* if(leadingJet<0.) continue ; // Don't analyze 0 multiplicity events; correction added later if(trackMult==0) continue; */ //Tracks for event classification: same as for analysis bool jetAbove = false ; bool jetAbove40 = false; bool jetAbove60 = false; bool jetAbove75 = false; bool jetAbove95 = false; bool jetAbove120 = false; if(leadingJet>40. ){ jetAbove40 = true ; } if(leadingJet>60. ){ jetAbove60 = true ; } if(leadingJet>75. ){ jetAbove75 = true ; } if(leadingJet>95. ){ jetAbove95 = true ; } if(leadingJet>120. ){ jetAbove120 = true ; } if(!jetAbove40) Nevents[curr_bin]++ ; if(jetAbove40 && !jetAbove60) Nevt_40_60[curr_bin]++; if(jetAbove60 && !jetAbove75) Nevt_60_75[curr_bin]++; if(jetAbove75 && !jetAbove95) Nevt_75_95[curr_bin]++; if(jetAbove95 && !jetAbove120) Nevt_95_120[curr_bin]++; if(jetAbove120) Nevt_120[curr_bin]++; if(TrigName=="Jet20") jetAbove = jetAbove40 && !jetAbove60 ; else if(TrigName=="Jet40") jetAbove = jetAbove60 && !jetAbove75 ; else if(TrigName=="Jet60") jetAbove = jetAbove75 && !jetAbove95 ; else if(TrigName=="Jet80") jetAbove = jetAbove95 && !jetAbove120 ; else if(TrigName=="Jet100") jetAbove = jetAbove120 ; else jetAbove = !jetAbove40 ; // if(!jetAbove) continue ; // for inclusive jet analysis for(int j4i = 0; j4i < my_ct->nref ; j4i++) { double jetweight = 1; double jet_pt= my_ct->jtpt[j4i]; double jet_eta = my_ct->jteta[j4i]; double ref_pt ; if(my_hists->IsMC==kTRUE) ref_pt = my_ct->refpt[j4i]; if (my_ct->rawpt[j4i]<15 || jet_pt<0.) continue; int dEtaBin = -1. ; if( my_hists->IsMC==kTRUE && my_ct->subid[j4i] != 0) continue; if(my_hists->IsMC==kTRUE && jet_pt>4*(pthat)) continue ; //for jet kinematcis cuts if(TMath::Abs(jet_eta)<=3.){ // if( my_hists->IsMC!=kTRUE ) jetweight*=(fUE->Eval(jet_pt))*C_rel->GetBinContent(C_rel->FindBin(jet_eta)); // else // jetweight*=((fUE->Eval(jet_pt))*fgaus->GetRandom()+1); my_hists->jetptEta[curr_bin]->Fill(jet_pt*jetweight, jet_eta, weight); if(coll=="PPb"){ if(TMath::Abs(jet_eta+0.465)<=1.) { my_hists->jetpt[curr_bin]->Fill(jet_pt*jetweight, weight); if(my_hists->IsMC==kTRUE) my_hists->refjetpt[curr_bin]->Fill(ref_pt, weight); } } else if(coll=="PbP"){ if(TMath::Abs(jet_eta-0.465)<=1.) { my_hists->jetpt[curr_bin]->Fill(jet_pt*jetweight, weight); if(my_hists->IsMC==kTRUE) my_hists->refjetpt[curr_bin]->Fill(ref_pt, weight); } } else { if(TMath::Abs(jet_eta+0.465)<=1.) { my_hists->jetpt[curr_bin]->Fill(jet_pt*jetweight, weight); if(my_hists->IsMC==kTRUE) my_hists->refjetpt[curr_bin]->Fill(ref_pt, weight); } } // if(coll=="PP" && TMath::Abs(jet_eta)<=1.) my_hists->jetpt[curr_bin]->Fill(jet_pt*jetweight, weight); if((jet_pt*jetweight)>100.) my_hists->jetEta[curr_bin]->Fill(jet_eta, weight); for(Int_t ieta = 0 ; ieta <netabin; ieta++){ if(coll=="PPb"){ if((jet_eta+0.465)>deta[ieta]&&(jet_eta+0.465)<=deta[ieta+1]) dEtaBin = ieta ; } else if(coll=="PbP"){ if((jet_eta-0.465)>deta[ieta]&&(jet_eta-0.465)<=deta[ieta+1]) dEtaBin = ieta ; } else { // if((jet_eta)>deta[ieta]&&(jet_eta)<=deta[ieta+1]) dEtaBin = ieta ; if((jet_eta+0.465)>deta[ieta]&&(jet_eta+0.465)<=deta[ieta+1]) dEtaBin = ieta ; } } //assign the eta bin for jets if(dEtaBin!=-1){ my_hists->jetptEtaBin[curr_bin][dEtaBin]->Fill(jet_pt*jetweight, weight); my_hists->NjetsEtaBin[curr_bin][dEtaBin]->Fill(1); if(my_hists->IsMC==kTRUE) my_hists->refjetptEtaBin[curr_bin][dEtaBin]->Fill(ref_pt, weight); } }// for jet kinematics cuts /* //MC histograms if(my_hists->IsMC==kTRUE&&DoGenAna){ double ref_pt= my_ct->refpt[j4i]; double ref_eta = my_ct->refeta[j4i]; Int_t GenEtaBin = -1 ; if(TMath::Abs(ref_eta)<=3.&& ref_pt>0.){ if(coll=="PPb" ){ if(TMath::Abs(ref_eta+0.465)<=1.) my_hists->refjetpt[curr_bin]->Fill(ref_pt, weight); } else if(coll=="PbP"){ if(TMath::Abs(ref_eta-0.465)<=1.) my_hists->refjetpt[curr_bin]->Fill(ref_pt, weight); } else { if(TMath::Abs(ref_eta+0.465)<=1.) my_hists->refjetpt[curr_bin]->Fill(ref_pt, weight); } for(Int_t ieta = 0 ; ieta <netabin; ieta++){ if(coll=="PPb"){ if((ref_eta+0.465)>deta[ieta]&&(ref_eta+0.465)<=deta[ieta+1]) GenEtaBin = ieta ; } else if(coll=="PbP"){ if((ref_eta-0.465)>deta[ieta]&&(ref_eta-0.465)<=deta[ieta+1]) GenEtaBin = ieta ; } else { if((ref_eta+0.465)>deta[ieta]&&(ref_eta+0.465)<=deta[ieta+1]) GenEtaBin = ieta ; } } //assign the eta bin for jets if(GenEtaBin!=-1){ my_hists->refjetptEtaBin[curr_bin][GenEtaBin]->Fill(ref_pt, weight); } } //ref jet kinematics cut } //MC histograms */ } //! jet loop //Leading Jets seach, for tracking efficiency double leadingJetPt = -1. ; Int_t leadingJetIndex = -1 ; for(int j = 0; j < my_ct->nref ; j++) { if (fabs(my_ct->jteta[j])>2.5) continue; if (my_ct->rawpt[j]<15) continue; if( my_hists->IsMC==kTRUE && my_ct->subid[j] != 0) continue; if (my_ct->jtpt[j]>leadingJetPt) { leadingJetPt = my_ct->jtpt[j]; leadingJetIndex = j; } } if(leadingJetPt==-1) //for corrections leadingJetPt=10.; //for inclusive track analysis, without jet selection and requirement for(int itr = 0 ; itr < my_tr->nTrk ; itr++){ double tr_pt = my_tr->trkPt[itr]; double tr_phi = my_tr->trkPhi[itr]; double tr_eta = my_tr->trkEta[itr]; if(TMath::Abs(tr_eta)>2.4) continue ; // if(my_tr->trkPtError[itr]/my_tr->trkPt[itr]>=0.1 || TMath::Abs(my_tr->trkDz1[itr]/my_tr->trkDzError1[itr])>=3.0 ||TMath::Abs(my_tr->trkDxy1[itr]/my_tr->trkDxyError1[itr])>=3.0) continue ; //ridge cut for tracks if(!((my_tr->highPurity[itr]) && (fabs(my_tr->trkDz1[itr]/my_tr->trkDzError1[itr])<3) && (fabs(my_tr->trkDxy1[itr]/my_tr->trkDxyError1[itr])<3) && (my_tr->trkPtError[itr]/my_tr->trkPt[itr]<0.1) )) continue; Int_t TrkEtaBin = -1 ; for(Int_t ieta = 0 ; ieta <ntrketabin; ieta++){ if(coll=="PPb"){ if((tr_eta+0.465)>dtrketa[ieta]&&(tr_eta+0.465)<=dtrketa[ieta+1]) TrkEtaBin = ieta ; } else if(coll=="PbP"){ if((tr_eta-0.465)>dtrketa[ieta]&&(tr_eta-0.465)<=dtrketa[ieta+1]) TrkEtaBin = ieta ; } else // if((tr_eta)>dtrketa[ieta]&&(tr_eta)<=dtrketa[ieta+1]) TrkEtaBin = ieta ; if((tr_eta+0.465)>dtrketa[ieta]&&(tr_eta+0.465)<=dtrketa[ieta+1]) TrkEtaBin = ieta ; } if((my_tr->highPurity[itr])){ // if(tr_pt<trackcut) continue ; double trkweight=1. ; if(doTrackCorrections){ // if(corrMet=="Hist")trkweight = c->getTrackCorrection(itr); // else trkweight = c->getTrackCorrectionPara(itr); trkweight = corr.getWeight(tr_pt,tr_eta,leadingJetPt); } my_hists->inctrkpt[curr_bin]->Fill(tr_pt, weight*trkweight); if(coll=="PPb"){ if(TMath::Abs(tr_eta+0.465)<=1.) my_hists->inctrkptM1P1[curr_bin]->Fill(tr_pt, weight*trkweight); } else if(coll=="PbP"){ if( TMath::Abs(tr_eta-0.465)<=1.) my_hists->inctrkptM1P1[curr_bin]->Fill(tr_pt, weight*trkweight); } else { if(TMath::Abs(tr_eta+0.465)<=1.) my_hists->inctrkptM1P1[curr_bin]->Fill(tr_pt, weight*trkweight); } // if(coll=="PP" &&TMath::Abs(tr_eta)<=1.) my_hists->inctrkptM1P1[curr_bin]->Fill(tr_pt, weight*trkweight); my_hists->Ntrack[curr_bin]->Fill(1); if(TrkEtaBin!=-1) my_hists->inctrkptEtaBin[curr_bin][TrkEtaBin]->Fill(tr_pt, weight*trkweight); if(TrkEtaBin!=-1) my_hists->NtrkEtaBin[curr_bin][TrkEtaBin]->Fill(1); } //! high purity track cuts } //! inclusive track loop // for jet-track analysis for(int j4i = 0; j4i < my_ct->nref ; j4i++) { TVector3 jet_vec; TVector3 track_vec; jet_vec.SetPtEtaPhi(0, 0, 0); track_vec.SetPtEtaPhi(0, 0, 0); double jetweight = 1; double jet_pt= my_ct->jtpt[j4i]; double jet_eta = my_ct->jteta[j4i]; double jet_phi = my_ct->jtphi[j4i]; if (my_ct->rawpt[j4i]<15) continue; int dEtaBin = -1. ; if( my_hists->IsMC==kTRUE && my_ct->subid[j4i]!= 0) continue; //for jet kinematcis cuts if(TMath::Abs(jet_eta)<=3.){ // if( my_hists->IsMC!=kTRUE ) jetweight*=(fUE->Eval(jet_pt))*C_rel->GetBinContent(C_rel->FindBin(jet_eta)); // else // jetweight*=((fUE->Eval(jet_pt))*fgaus->GetRandom()+1); jet_vec.SetPtEtaPhi(jet_pt, jet_eta, jet_phi); // for track loop in each jet, do jet-track analysis for(int itr = 0 ; itr < my_tr->nTrk ; itr++){ double tr_pt = my_tr->trkPt[itr]; double tr_phi = my_tr->trkPhi[itr]; double tr_eta = my_tr->trkEta[itr]; if(TMath::Abs(tr_eta)>2.4) continue ; if(!((my_tr->highPurity[itr]) && (fabs(my_tr->trkDz1[itr]/my_tr->trkDzError1[itr])<3) && (fabs(my_tr->trkDxy1[itr]/my_tr->trkDxyError1[itr])<3) && (my_tr->trkPtError[itr]/my_tr->trkPt[itr]<0.1) )) continue; Int_t TrkEtaBin = -1 ; for(Int_t ieta = 0 ; ieta <ntrketabin; ieta++){ if(coll=="PPb"){ if((tr_eta+0.465)>dtrketa[ieta]&&(tr_eta+0.465)<=dtrketa[ieta+1]) TrkEtaBin = ieta ; } else if(coll=="PbP"){ if((tr_eta-0.465)>dtrketa[ieta]&&(tr_eta-0.465)<=dtrketa[ieta+1]) TrkEtaBin = ieta ; } else if((tr_eta+0.465)>dtrketa[ieta]&&(tr_eta+0.465)<=dtrketa[ieta+1]) TrkEtaBin = ieta ; } track_vec.SetPtEtaPhi(tr_pt, tr_eta, tr_phi); if((my_tr->highPurity[itr])){ // if(tr_pt<trackcut) continue ; double trkweight=1. ; double dr = jet_vec.DeltaR(track_vec); if(dr>conesize) continue ; if(doTrackCorrections){ // if(corrMet=="Hist")trkweight = c->getTrackCorrection(itr); // else trkweight = c->getTrackCorrectionPara(itr); trkweight = corr.getWeight(tr_pt,tr_eta,leadingJetPt); } my_hists->jettrkpt[curr_bin]->Fill(jet_pt*jetweight, tr_pt, weight*trkweight); if(coll=="PPb"){ if( TMath::Abs(tr_eta+0.465)<=1.) my_hists->jettrkptM1P1[curr_bin]->Fill(tr_pt, weight*trkweight); } else if(coll=="PbP") { if(TMath::Abs(tr_eta-0.465)<=1.) my_hists->jettrkptM1P1[curr_bin]->Fill(tr_pt, weight*trkweight); } else { if(TMath::Abs(tr_eta+0.465)<=1.) my_hists->jettrkptM1P1[curr_bin]->Fill(tr_pt, weight*trkweight); } if(TrkEtaBin!=-1) my_hists->jettrkPtEtaBin[curr_bin][TrkEtaBin]->Fill(tr_pt, weight*trkweight); } //! high purity track cuts } //end of track loop } //jet kinematics } //jet loop if(my_hists->IsMC==kTRUE&&DoGenAna){ //using the sim track to calculate the tracking efficiency for(int ipart = 0 ; ipart < my_tr->nParticle ; ipart++){ //sim track loop double gen_pt = my_tr->pPt[ipart]; double gen_phi = my_tr->pPhi[ipart]; double gen_eta = my_tr->pEta[ipart]; // if(gen_pt<trackcut)continue ; if(TMath::Abs(gen_eta)>2.4)continue ; if(my_tr->pNRec[ipart]>0&&((my_tr->mtrkQual[ipart]))) { if((my_tr->mtrkPtError[ipart]/my_tr->mtrkPt[ipart]<0.1 && TMath::Abs(my_tr->mtrkDz1[ipart]/my_tr->mtrkDzError1[ipart])<3.0 && TMath::Abs(my_tr->mtrkDxy1[ipart]/my_tr->mtrkDxyError1[ipart])<3.0)){ my_hists->incgenmatchpt[curr_bin]->Fill(gen_pt, weight); } //tracking cut } // matching hist my_hists->incgenpartpt[curr_bin]->Fill(gen_pt,weight); } //! sim track loop } //only runs on MC } ///event loop my_hists->NevtCounter[curr_bin]->SetBinContent(1, Nevents[curr_bin]); my_hists->JetAbove40[curr_bin]->SetBinContent(1, Nevt_40_60[curr_bin]); my_hists->JetAbove60[curr_bin]->SetBinContent(1, Nevt_60_75[curr_bin]); my_hists->JetAbove75[curr_bin]->SetBinContent(1, Nevt_75_95[curr_bin]); my_hists->JetAbove95[curr_bin]->SetBinContent(1, Nevt_95_120[curr_bin]); my_hists->JetAbove120[curr_bin]->SetBinContent(1, Nevt_120[curr_bin]); my_hists->Write(); // my_hists->Delete(); // delete my_hists; std::cout << "working done\n"; }
//=== MAIN MACRO ================================================================================================= void computeAccSelZeeBinned_PileupSys(const TString conf, // input file const TString inputDir, const TString outputDir, // output directory const Int_t doPU, const Int_t doScaleCorr, const Int_t sigma, const TString PUtype ) { gBenchmark->Start("computeAccSelZeeBinned"); //-------------------------------------------------------------------------------------------------------------- // Settings //============================================================================================================== const Double_t MASS_LOW = 60; const Double_t MASS_HIGH = 120; const Double_t PT_CUT = 25; const Double_t ETA_CUT = 2.5; const Double_t ELE_MASS = 0.000511; const Double_t ETA_BARREL = 1.4442; const Double_t ETA_ENDCAP = 1.566; const Int_t BOSON_ID = 23; const Int_t LEPTON_ID = 11; // efficiency files const TString dataHLTEffName = inputDir+"EleHLTEff/MG/eff.root"; const TString dataHLTEffName_pos = inputDir+"EleHLTEff/MGpositive/eff.root"; const TString dataHLTEffName_neg = inputDir+"EleHLTEff/MGnegative/eff.root"; const TString zeeHLTEffName = inputDir+"EleHLTEff/CT/eff.root"; const TString zeeHLTEffName_pos = inputDir+"EleHLTEff/CTpositive/eff.root"; const TString zeeHLTEffName_neg = inputDir+"EleHLTEff/CTnegative/eff.root"; const TString dataGsfSelEffName = inputDir+"EleGsfSelEff/MG/eff.root"; const TString dataGsfSelEffName_pos = inputDir+"EleGsfSelEff/MGpositive_FineBin/eff.root"; const TString dataGsfSelEffName_neg = inputDir+"EleGsfSelEff/MGnegative_FineBin/eff.root"; const TString zeeGsfSelEffName = inputDir+"EleGsfSelEff/CT/eff.root"; const TString zeeGsfSelEffName_pos = inputDir+"EleGsfSelEff/CTpositive/eff.root"; const TString zeeGsfSelEffName_neg = inputDir+"EleGsfSelEff/CTnegative/eff.root"; const TString corrFiles = "../EleScale/76X_16DecRereco_2015_Etunc"; //data EnergyScaleCorrection_class eleCorr( corrFiles.Data()); eleCorr.doScale= true; eleCorr.doSmearings =true; // load pileup reweighting file TFile *f_rw = TFile::Open("../Tools/puWeights_76x.root", "read"); TH1D *h_rw = (TH1D*) f_rw->Get(PUtype.Data()); TFile *f_r9 = TFile::Open("../EleScale/transformation.root","read"); TGraph* gR9EB = (TGraph*) f_r9->Get("transformR90"); TGraph* gR9EE = (TGraph*) f_r9->Get("transformR91"); TFile *f_hlt_data_posi = TFile::Open("/afs/cern.ch/work/x/xniu/public/WZXSection/wz-efficiency/EleHLTEff/Nominal/EleTriggerTF1_Data_Positive.root"); TFile *f_hlt_data_nega = TFile::Open("/afs/cern.ch/work/x/xniu/public/WZXSection/wz-efficiency/EleHLTEff/Nominal/EleTriggerTF1_Data_Negative.root"); TFile *f_hlt_mc_posi = TFile::Open("/afs/cern.ch/work/x/xniu/public/WZXSection/wz-efficiency/EleHLTEff/Nominal/EleTriggerTF1_MC_Positive.root"); TFile *f_hlt_mc_nega = TFile::Open("/afs/cern.ch/work/x/xniu/public/WZXSection/wz-efficiency/EleHLTEff/Nominal/EleTriggerTF1_MC_Negative.root"); //-------------------------------------------------------------------------------------------------------------- // Main analysis code //============================================================================================================== vector<TString> fnamev; // file name per input file vector<TString> labelv; // TLegend label per input file vector<Int_t> colorv; // plot color per input file vector<Int_t> linev; // plot line style per input file // // parse .conf file // ifstream ifs; ifs.open(conf.Data()); assert(ifs.is_open()); string line; while(getline(ifs,line)) { if(line[0]=='#') continue; string fname; Int_t color, linesty; stringstream ss(line); ss >> fname >> color >> linesty; string label = line.substr(line.find('@')+1); fnamev.push_back(fname); labelv.push_back(label); colorv.push_back(color); linev.push_back(linesty); } ifs.close(); // Create output directory gSystem->mkdir(outputDir,kTRUE); TH2D *h=0; // // HLT efficiency // cout << "Loading trigger efficiencies..." << endl; TFile *dataHLTEffFile_pos = new TFile(dataHLTEffName_pos); CEffUser2D dataHLTEff_pos; dataHLTEff_pos.loadEff((TH2D*)dataHLTEffFile_pos->Get("hEffEtaPt"), (TH2D*)dataHLTEffFile_pos->Get("hErrlEtaPt"), (TH2D*)dataHLTEffFile_pos->Get("hErrhEtaPt")); TFile *dataHLTEffFile_neg = new TFile(dataHLTEffName_neg); CEffUser2D dataHLTEff_neg; dataHLTEff_neg.loadEff((TH2D*)dataHLTEffFile_neg->Get("hEffEtaPt"), (TH2D*)dataHLTEffFile_neg->Get("hErrlEtaPt"), (TH2D*)dataHLTEffFile_neg->Get("hErrhEtaPt")); TFile *zeeHLTEffFile_pos = new TFile(zeeHLTEffName_pos); CEffUser2D zeeHLTEff_pos; zeeHLTEff_pos.loadEff((TH2D*)zeeHLTEffFile_pos->Get("hEffEtaPt"), (TH2D*)zeeHLTEffFile_pos->Get("hErrlEtaPt"), (TH2D*)zeeHLTEffFile_pos->Get("hErrhEtaPt")); TFile *zeeHLTEffFile_neg = new TFile(zeeHLTEffName_neg); CEffUser2D zeeHLTEff_neg; zeeHLTEff_neg.loadEff((TH2D*)zeeHLTEffFile_neg->Get("hEffEtaPt"), (TH2D*)zeeHLTEffFile_neg->Get("hErrlEtaPt"), (TH2D*)zeeHLTEffFile_neg->Get("hErrhEtaPt")); h =(TH2D*)dataHLTEffFile_pos->Get("hEffEtaPt"); TH2D *hHLTErr_pos = new TH2D("hHLTErr_pos", "",h->GetNbinsX(),h->GetXaxis()->GetXmin(),h->GetXaxis()->GetXmax(), h->GetNbinsY(),h->GetYaxis()->GetXmin(),h->GetYaxis()->GetXmax()); TH2D *hHLTErr_neg = new TH2D("hHLTErr_neg", "",h->GetNbinsX(),h->GetXaxis()->GetXmin(),h->GetXaxis()->GetXmax(), h->GetNbinsY(),h->GetYaxis()->GetXmin(),h->GetYaxis()->GetXmax()); cout << "Loading GSF+selection efficiencies..." << endl; TFile *dataGsfSelEffFile_pos = new TFile(dataGsfSelEffName_pos); CEffUser2D dataGsfSelEff_pos; dataGsfSelEff_pos.loadEff((TH2D*)dataGsfSelEffFile_pos->Get("hEffEtaPt"), (TH2D*)dataGsfSelEffFile_pos->Get("hErrlEtaPt"), (TH2D*)dataGsfSelEffFile_pos->Get("hErrhEtaPt")); TFile *dataGsfSelEffFile_neg = new TFile(dataGsfSelEffName_neg); CEffUser2D dataGsfSelEff_neg; dataGsfSelEff_neg.loadEff((TH2D*)dataGsfSelEffFile_neg->Get("hEffEtaPt"), (TH2D*)dataGsfSelEffFile_neg->Get("hErrlEtaPt"), (TH2D*)dataGsfSelEffFile_neg->Get("hErrhEtaPt")); TFile *zeeGsfSelEffFile_pos = new TFile(zeeGsfSelEffName_pos); CEffUser2D zeeGsfSelEff_pos; zeeGsfSelEff_pos.loadEff((TH2D*)zeeGsfSelEffFile_pos->Get("hEffEtaPt"), (TH2D*)zeeGsfSelEffFile_pos->Get("hErrlEtaPt"), (TH2D*)zeeGsfSelEffFile_pos->Get("hErrhEtaPt")); TFile *zeeGsfSelEffFile_neg = new TFile(zeeGsfSelEffName_neg); CEffUser2D zeeGsfSelEff_neg; zeeGsfSelEff_neg.loadEff((TH2D*)zeeGsfSelEffFile_neg->Get("hEffEtaPt"), (TH2D*)zeeGsfSelEffFile_neg->Get("hErrlEtaPt"), (TH2D*)zeeGsfSelEffFile_neg->Get("hErrhEtaPt")); h =(TH2D*)dataGsfSelEffFile_pos->Get("hEffEtaPt"); TH2D *hGsfSelErr_pos = new TH2D("hGsfSelErr_pos", "",h->GetNbinsX(),h->GetXaxis()->GetXmin(),h->GetXaxis()->GetXmax(), h->GetNbinsY(),h->GetYaxis()->GetXmin(),h->GetYaxis()->GetXmax()); TH2D *hGsfSelErr_neg = new TH2D("hGsfSelErr_neg", "",h->GetNbinsX(),h->GetXaxis()->GetXmin(),h->GetXaxis()->GetXmax(), h->GetNbinsY(),h->GetYaxis()->GetXmin(),h->GetYaxis()->GetXmax()); // Data structures to store info from TTrees baconhep::TEventInfo *info = new baconhep::TEventInfo(); baconhep::TGenEventInfo *gen = new baconhep::TGenEventInfo(); TClonesArray *genPartArr = new TClonesArray("baconhep::TGenParticle"); TClonesArray *electronArr = new TClonesArray("baconhep::TElectron"); TClonesArray *vertexArr = new TClonesArray("baconhep::TVertex"); TFile *infile=0; TTree *eventTree=0; // Variables to store acceptances and uncertainties (per input file) vector<Double_t> nEvtsv, nSelv; vector<Double_t> nSelCorrv, nSelCorrVarv; vector<Double_t> accv, accCorrv; vector<Double_t> accErrv, accErrCorrv; const baconhep::TTrigger triggerMenu("../../BaconAna/DataFormats/data/HLT_50nsGRun"); // // loop through files // for(UInt_t ifile=0; ifile<fnamev.size(); ifile++) { // Read input file and get the TTrees cout << "Processing " << fnamev[ifile] << " ..." << endl; infile = TFile::Open(fnamev[ifile]); assert(infile); eventTree = (TTree*)infile->Get("Events"); assert(eventTree); eventTree->SetBranchAddress("Info", &info); TBranch *infoBr = eventTree->GetBranch("Info"); eventTree->SetBranchAddress("GenEvtInfo", &gen); TBranch *genBr = eventTree->GetBranch("GenEvtInfo"); eventTree->SetBranchAddress("GenParticle", &genPartArr); TBranch *genPartBr = eventTree->GetBranch("GenParticle"); eventTree->SetBranchAddress("Electron", &electronArr); TBranch *electronBr = eventTree->GetBranch("Electron"); eventTree->SetBranchAddress("PV", &vertexArr); TBranch *vertexBr = eventTree->GetBranch("PV"); nEvtsv.push_back(0); nSelv.push_back(0); nSelCorrv.push_back(0); nSelCorrVarv.push_back(0); // // loop over events // for(UInt_t ientry=0; ientry<eventTree->GetEntries(); ientry++) { genBr->GetEntry(ientry); genPartArr->Clear(); genPartBr->GetEntry(ientry); infoBr->GetEntry(ientry); Int_t glepq1=-99; Int_t glepq2=-99; if (fabs(toolbox::flavor(genPartArr, BOSON_ID))!=LEPTON_ID) continue; TLorentzVector *vec=new TLorentzVector(0,0,0,0); TLorentzVector *lep1=new TLorentzVector(0,0,0,0); TLorentzVector *lep2=new TLorentzVector(0,0,0,0); toolbox::fillGen(genPartArr, BOSON_ID, vec, lep1, lep2,&glepq1,&glepq2,1); if(vec->M()<MASS_LOW || vec->M()>MASS_HIGH) continue; delete vec; delete lep1; delete lep2; vertexArr->Clear(); vertexBr->GetEntry(ientry); double npv = vertexArr->GetEntries(); Double_t weight=gen->weight; if(doPU>0) weight*=h_rw->GetBinContent(h_rw->FindBin(info->nPUmean)); nEvtsv[ifile]+=weight; // trigger requirement if (!isEleTrigger(triggerMenu, info->triggerBits, kFALSE)) continue; // good vertex requirement if(!(info->hasGoodPV)) continue; electronArr->Clear(); electronBr->GetEntry(ientry); for(Int_t i1=0; i1<electronArr->GetEntriesFast(); i1++) { const baconhep::TElectron *ele1 = (baconhep::TElectron*)((*electronArr)[i1]); TLorentzVector vEle1(0,0,0,0); vEle1.SetPtEtaPhiM(ele1->pt, ele1->eta, ele1->phi, ELE_MASS); // check ECAL gap // if(fabs(ele1->scEta)>=ETA_BARREL && fabs(ele1->scEta)<=ETA_ENDCAP) continue; if(fabs(vEle1.Eta())>=ETA_BARREL && fabs(vEle1.Eta())<=ETA_ENDCAP) continue; if(doScaleCorr && (ele1->r9 < 1.)){ // set up variable and apply smear correction to ele1 float ele1Smear = 0.; float ele1Error = 0.; float ele1AbsEta = fabs(vEle1.Eta()); float ele1Et = vEle1.E() / cosh(ele1AbsEta); bool ele1isBarrel = ele1AbsEta < 1.4442; float ele1R9Prime = ele1->r9; // r9 corrections MC only if(ele1isBarrel){ ele1R9Prime = gR9EB->Eval(ele1->r9);} else { ele1R9Prime = gR9EE->Eval(ele1->r9); } double ele1Random = gRandom->Gaus(0,1); ele1Smear = eleCorr.getSmearingSigma(info->runNum, ele1isBarrel, ele1R9Prime, ele1AbsEta, ele1Et, 0., 0.); float ele1SmearEP = eleCorr.getSmearingSigma(info->runNum, ele1isBarrel, ele1R9Prime, ele1AbsEta, ele1Et, 1., 0.); float ele1SmearEM = eleCorr.getSmearingSigma(info->runNum, ele1isBarrel, ele1R9Prime, ele1AbsEta, ele1Et, -1., 0.); if(sigma==0){ (vEle1) *= 1. + ele1Smear * ele1Random; }else if(sigma==1){ (vEle1) *= 1. + ele1SmearEP * ele1Random; }else if(sigma==-1){ (vEle1) *= 1. + ele1SmearEM * ele1Random; } } //double ele1_pt = gRandom->Gaus(ele1->pt*getEleScaleCorr(ele1->scEta,0), getEleResCorr(ele1->scEta,0)); // if(ele1->pt < PT_CUT && ele1->scEt < PT_CUT) continue; // lepton pT cut // if(fabs(ele1->scEta) > ETA_CUT && fabs(ele1->eta) > ETA_CUT) continue; // lepton |eta| cut // if(!passEleID(ele1,info->rhoIso)) continue; // lepton selection if(vEle1.Pt() < PT_CUT) continue; // lepton pT cut if(fabs(vEle1.Eta()) > ETA_CUT) continue; // lepton |eta| cut if(!passEleID(ele1, vEle1, info->rhoIso)) continue; // lepton selection //if(!isEleTriggerObj(triggerMenu, ele1->hltMatchBits, kFALSE, kFALSE)) continue; //TLorentzVector vEle1(0,0,0,0); //vEle1.SetPtEtaPhiM(ele1->pt, ele1->eta, ele1->phi, ELE_MASS); //Bool_t isB1 = (fabs(ele1->scEta)<ETA_BARREL) ? kTRUE : kFALSE; for(Int_t i2=i1+1; i2<electronArr->GetEntriesFast(); i2++) { const baconhep::TElectron *ele2 = (baconhep::TElectron*)((*electronArr)[i2]); TLorentzVector vEle2(0,0,0,0); vEle2.SetPtEtaPhiM(ele2->pt, ele2->eta, ele2->phi, ELE_MASS); // check ECAL gap // if(fabs(ele2->scEta)>=ETA_BARREL && fabs(ele2->scEta)<=ETA_ENDCAP) continue; if(fabs(vEle2.Eta())>=ETA_BARREL && fabs(vEle2.Eta())<=ETA_ENDCAP) continue; if(doScaleCorr && (ele2->r9 < 1.)){ float ele2Smear = 0.; float ele2Error = 0.; float ele2AbsEta = fabs(vEle2.Eta()); float ele2Et = vEle2.E() / cosh(ele2AbsEta); bool ele2isBarrel = ele2AbsEta < 1.4442; float ele2R9Prime = ele2->r9; // r9 corrections MC only if(ele2isBarrel){ ele2R9Prime = gR9EB->Eval(ele2->r9);} else { ele2R9Prime = gR9EE->Eval(ele2->r9); } double ele2Random = gRandom->Gaus(0,1); ele2Smear = eleCorr.getSmearingSigma(info->runNum, ele2isBarrel, ele2R9Prime, ele2AbsEta, ele2Et, 0., 0.); float ele2SmearEP = eleCorr.getSmearingSigma(info->runNum, ele2isBarrel, ele2R9Prime, ele2AbsEta, ele2Et, 1., 0.); float ele2SmearEM = eleCorr.getSmearingSigma(info->runNum, ele2isBarrel, ele2R9Prime, ele2AbsEta, ele2Et, -1., 0.); if(sigma==0){ (vEle2) *= 1. + ele2Smear * ele2Random; }else if(sigma==1){ (vEle2) *= 1. + ele2SmearEP * ele2Random; }else if(sigma==-1){ (vEle2) *= 1. + ele2SmearEM * ele2Random; } } //double ele2_pt = gRandom->Gaus(ele2->scEt*getEleScaleCorr(ele2->scEta,0), getEleResCorr(ele2->scEta,0)); if(ele1->q == ele2->q) continue; // if(ele2->pt < PT_CUT && ele2->scEt < PT_CUT) continue; // lepton pT cut // if(fabs(ele2->scEta) > ETA_CUT && fabs(ele2->eta) > ETA_CUT) continue; // lepton |eta| cut // if(!passEleID(ele2,info->rhoIso)) continue; // lepton selection if(vEle2.Pt() < PT_CUT) continue; // lepton pT cut if(fabs(vEle2.Eta()) > ETA_CUT) continue; // lepton |eta| cut if(!passEleID(ele2, vEle2, info->rhoIso)) continue; // lepton selection //TLorentzVector vEle2(0,0,0,0); //vEle2.SetPtEtaPhiM(ele2->pt, ele2->eta, ele2->phi, ELE_MASS); //Bool_t isB2 = (fabs(ele2->scEta)<ETA_BARREL) ? kTRUE : kFALSE; if(!isEleTriggerObj(triggerMenu, ele1->hltMatchBits, kFALSE, kFALSE) && !isEleTriggerObj(triggerMenu, ele2->hltMatchBits, kFALSE, kFALSE)) continue; // mass window TLorentzVector vDilep = vEle1 + vEle2; if((vDilep.M()<MASS_LOW) || (vDilep.M()>MASS_HIGH)) continue; /******** We have a Z candidate! HURRAY! ********/ Double_t effdata, effmc; //Double_t sceta1 = (fabs(ele1->scEta)<2.5) ? ele1->scEta : 0.99*(ele1->scEta); // Double_t sceta1 = ele1->scEta; //Double_t sceta2 = (fabs(ele2->scEta)<2.5) ? ele2->scEta : 0.99*(ele2->scEta); // Double_t sceta2 = ele2->scEta; Double_t corr=1; effdata=1; effmc=1; char funcname1[20]; char funcname2[20]; sprintf(funcname1, "fitfcn_%d", getEtaBinLabel(vEle1.Eta())); sprintf(funcname2, "fitfcn_%d", getEtaBinLabel(vEle2.Eta())); if(ele1->q>0) { TF1 *fdt = (TF1*)f_hlt_data_posi->Get(funcname1); TF1 *fmc = (TF1*)f_hlt_mc_posi ->Get(funcname1); effdata *= (1.-fdt->Eval(TMath::Min(vEle1.Pt(),119.0))); effmc *= (1.-fmc->Eval(TMath::Min(vEle1.Pt(),119.0))); delete fdt; delete fmc; //effdata *= (1.-dataHLTEff_pos.getEff(vEle1.Eta(), vEle1.Pt())); //effmc *= (1.-zeeHLTEff_pos.getEff(vEle1.Eta(), vEle1.Pt())); } else { TF1 *fdt = (TF1*)f_hlt_data_nega->Get(funcname1); TF1 *fmc = (TF1*)f_hlt_mc_nega ->Get(funcname1); effdata *= (1.-fdt->Eval(TMath::Min(vEle1.Pt(),119.0))); effmc *= (1.-fmc->Eval(TMath::Min(vEle1.Pt(),119.0))); delete fdt; delete fmc; //effdata *= (1.-dataHLTEff_neg.getEff(vEle1.Eta(), vEle1.Pt())); //effmc *= (1.-zeeHLTEff_neg.getEff(vEle1.Eta(), vEle1.Pt())); } if(ele2->q>0) { TF1 *fdt = (TF1*)f_hlt_data_posi->Get(funcname2); TF1 *fmc = (TF1*)f_hlt_mc_posi ->Get(funcname2); effdata *= (1.-fdt->Eval(TMath::Min(vEle2.Pt(),119.0))); effmc *= (1.-fmc->Eval(TMath::Min(vEle2.Pt(),119.0))); delete fdt; delete fmc; //effdata *= (1.-dataHLTEff_pos.getEff(vEle2.Eta(), vEle2.Pt())); //effmc *= (1.-zeeHLTEff_pos.getEff(vEle2.Eta(), vEle2.Pt())); } else { TF1 *fdt = (TF1*)f_hlt_data_nega->Get(funcname2); TF1 *fmc = (TF1*)f_hlt_mc_nega ->Get(funcname2); effdata *= (1.-fdt->Eval(TMath::Min(vEle2.Pt(),119.0))); effmc *= (1.-fmc->Eval(TMath::Min(vEle2.Pt(),119.0))); delete fdt; delete fmc; //effdata *= (1.-dataHLTEff_neg.getEff(vEle2.Eta(), vEle2.Pt())); //effmc *= (1.-zeeHLTEff_neg.getEff(vEle2.Eta(), vEle2.Pt())); } effdata = 1.-effdata; effmc = 1.-effmc; corr *= effdata/effmc; effdata=1; effmc=1; if(ele1->q>0) { effdata *= dataGsfSelEff_pos.getEff(vEle1.Eta(), vEle1.Pt()); effmc *= zeeGsfSelEff_pos.getEff(vEle1.Eta(), vEle1.Pt()); } else { effdata *= dataGsfSelEff_neg.getEff(vEle1.Eta(), vEle1.Pt()); effmc *= zeeGsfSelEff_neg.getEff(vEle1.Eta(), vEle1.Pt()); } if(ele2->q>0) { effdata *= dataGsfSelEff_pos.getEff(vEle2.Eta(), vEle2.Pt()); effmc *= zeeGsfSelEff_pos.getEff(vEle2.Eta(), vEle2.Pt()); } else { effdata *= dataGsfSelEff_neg.getEff(vEle2.Eta(), vEle2.Pt()); effmc *= zeeGsfSelEff_neg.getEff(vEle2.Eta(), vEle2.Pt()); } corr *= effdata/effmc; // scale factor uncertainties // HLT if(ele1->q>0) { Double_t effdata = dataHLTEff_pos.getEff(vEle1.Eta(), vEle1.Pt()); Double_t errdata = TMath::Max(dataHLTEff_pos.getErrLow(vEle1.Eta(), vEle1.Pt()), dataHLTEff_pos.getErrHigh(vEle1.Eta(), vEle1.Pt())); Double_t effmc = zeeHLTEff_pos.getEff(vEle1.Eta(), vEle1.Pt()); Double_t errmc = TMath::Max(zeeHLTEff_pos.getErrLow(vEle1.Eta(), vEle1.Pt()), zeeHLTEff_pos.getErrHigh(vEle1.Eta(), vEle1.Pt())); Double_t errHLT = (effdata/effmc)*sqrt(errdata*errdata/effdata/effdata + errmc*errmc/effmc/effmc); hHLTErr_pos->Fill(vEle1.Eta(), vEle1.Pt(), errHLT); } else { Double_t effdata = dataHLTEff_neg.getEff(vEle1.Eta(), vEle1.Pt()); Double_t errdata = TMath::Max(dataHLTEff_neg.getErrLow(vEle1.Eta(), vEle1.Pt()), dataHLTEff_neg.getErrHigh(vEle1.Eta(), vEle1.Pt())); Double_t effmc = zeeHLTEff_neg.getEff(vEle1.Eta(), vEle1.Pt()); Double_t errmc = TMath::Max(zeeHLTEff_neg.getErrLow(vEle1.Eta(), vEle1.Pt()), zeeHLTEff_neg.getErrHigh(vEle1.Eta(), vEle1.Pt())); Double_t errHLT = (effdata/effmc)*sqrt(errdata*errdata/effdata/effdata + errmc*errmc/effmc/effmc); hHLTErr_neg->Fill(vEle1.Eta(), vEle1.Pt(), errHLT); } if(ele2->q>0) { Double_t effdata = dataHLTEff_pos.getEff(vEle2.Eta(), vEle2.Pt()); Double_t errdata = TMath::Max(dataHLTEff_pos.getErrLow(vEle2.Eta(), vEle2.Pt()), dataHLTEff_pos.getErrHigh(vEle2.Eta(), vEle2.Pt())); Double_t effmc = zeeHLTEff_pos.getEff(vEle2.Eta(), vEle2.Pt()); Double_t errmc = TMath::Max(zeeHLTEff_pos.getErrLow(vEle2.Eta(), vEle2.Pt()), zeeHLTEff_pos.getErrHigh(vEle2.Eta(), vEle2.Pt())); Double_t errHLT = (effdata/effmc)*sqrt(errdata*errdata/effdata/effdata + errmc*errmc/effmc/effmc); hHLTErr_pos->Fill(vEle2.Eta(), vEle2.Pt(), errHLT); } else { Double_t effdata = dataHLTEff_neg.getEff(vEle2.Eta(), vEle2.Pt()); Double_t errdata = TMath::Max(dataHLTEff_neg.getErrLow(vEle2.Eta(), vEle2.Pt()), dataHLTEff_neg.getErrHigh(vEle2.Eta(), vEle2.Pt())); Double_t effmc = zeeHLTEff_neg.getEff(vEle2.Eta(), vEle2.Pt()); Double_t errmc = TMath::Max(zeeHLTEff_neg.getErrLow(vEle2.Eta(), vEle2.Pt()), zeeHLTEff_neg.getErrHigh(vEle2.Eta(), vEle2.Pt())); Double_t errHLT = (effdata/effmc)*sqrt(errdata*errdata/effdata/effdata + errmc*errmc/effmc/effmc); hHLTErr_neg->Fill(vEle2.Eta(), vEle2.Pt(), errHLT); } // GsfSel if(ele1->q>0) { Double_t effdata = dataGsfSelEff_pos.getEff(vEle1.Eta(), vEle1.Pt()); Double_t errdata = TMath::Max(dataGsfSelEff_pos.getErrLow(vEle1.Eta(), vEle1.Pt()), dataGsfSelEff_pos.getErrHigh(vEle1.Eta(), vEle1.Pt())); Double_t effmc = zeeGsfSelEff_pos.getEff(vEle1.Eta(), vEle1.Pt()); Double_t errmc = TMath::Max(zeeGsfSelEff_pos.getErrLow(vEle1.Eta(), vEle1.Pt()), zeeGsfSelEff_pos.getErrHigh(vEle1.Eta(), vEle1.Pt())); Double_t errGsfSel = (effdata/effmc)*sqrt(errdata*errdata/effdata/effdata + errmc*errmc/effmc/effmc); hGsfSelErr_pos->Fill(vEle1.Eta(), vEle1.Pt(), errGsfSel); } else { Double_t effdata = dataGsfSelEff_neg.getEff(vEle1.Eta(), vEle1.Pt()); Double_t errdata = TMath::Max(dataGsfSelEff_neg.getErrLow(vEle1.Eta(), vEle1.Pt()), dataGsfSelEff_neg.getErrHigh(vEle1.Eta(), vEle1.Pt())); Double_t effmc = zeeGsfSelEff_neg.getEff(vEle1.Eta(), vEle1.Pt()); Double_t errmc = TMath::Max(zeeGsfSelEff_neg.getErrLow(vEle1.Eta(), vEle1.Pt()), zeeGsfSelEff_neg.getErrHigh(vEle1.Eta(), vEle1.Pt())); Double_t errGsfSel = (effdata/effmc)*sqrt(errdata*errdata/effdata/effdata + errmc*errmc/effmc/effmc); hGsfSelErr_neg->Fill(vEle1.Eta(), vEle1.Pt(), errGsfSel); } if(ele2->q>0) { Double_t effdata = dataGsfSelEff_pos.getEff(vEle2.Eta(), vEle2.Pt()); Double_t errdata = TMath::Max(dataGsfSelEff_pos.getErrLow(vEle2.Eta(), vEle2.Pt()), dataGsfSelEff_pos.getErrHigh(vEle2.Eta(), vEle2.Pt())); Double_t effmc = zeeGsfSelEff_pos.getEff(vEle2.Eta(), vEle2.Pt()); Double_t errmc = TMath::Max(zeeGsfSelEff_pos.getErrLow(vEle2.Eta(), vEle2.Pt()), zeeGsfSelEff_pos.getErrHigh(vEle2.Eta(), vEle2.Pt())); Double_t errGsfSel = (effdata/effmc)*sqrt(errdata*errdata/effdata/effdata + errmc*errmc/effmc/effmc); hGsfSelErr_pos->Fill(vEle2.Eta(), vEle2.Pt(), errGsfSel); } else { Double_t effdata = dataGsfSelEff_neg.getEff(vEle2.Eta(), vEle2.Pt()); Double_t errdata = TMath::Max(dataGsfSelEff_neg.getErrLow(vEle2.Eta(), vEle2.Pt()), dataGsfSelEff_neg.getErrHigh(vEle2.Eta(), vEle2.Pt())); Double_t effmc = zeeGsfSelEff_neg.getEff(vEle2.Eta(), vEle2.Pt()); Double_t errmc = TMath::Max(zeeGsfSelEff_neg.getErrLow(vEle2.Eta(), vEle2.Pt()), zeeGsfSelEff_neg.getErrHigh(vEle2.Eta(), vEle2.Pt())); Double_t errGsfSel = (effdata/effmc)*sqrt(errdata*errdata/effdata/effdata + errmc*errmc/effmc/effmc); hGsfSelErr_neg->Fill(vEle2.Eta(), vEle2.Pt(), errGsfSel); } nSelv[ifile]+=weight; nSelCorrv[ifile]+=weight*corr; nSelCorrVarv[ifile]+=weight*weight*corr*corr; } } } Double_t var=0; for(Int_t iy=0; iy<=hHLTErr_pos->GetNbinsY(); iy++) { for(Int_t ix=0; ix<=hHLTErr_pos->GetNbinsX(); ix++) { Double_t err=hHLTErr_pos->GetBinContent(ix,iy); var+=err*err; } } for(Int_t iy=0; iy<=hHLTErr_neg->GetNbinsY(); iy++) { for(Int_t ix=0; ix<=hHLTErr_neg->GetNbinsX(); ix++) { Double_t err=hHLTErr_neg->GetBinContent(ix,iy); var+=err*err; } } // cout << "var1: " << var << endl; for(Int_t iy=0; iy<=hGsfSelErr_pos->GetNbinsY(); iy++) { for(Int_t ix=0; ix<=hGsfSelErr_pos->GetNbinsX(); ix++) { Double_t err=hGsfSelErr_pos->GetBinContent(ix,iy); var+=err*err; } } for(Int_t iy=0; iy<=hGsfSelErr_neg->GetNbinsY(); iy++) { for(Int_t ix=0; ix<=hGsfSelErr_neg->GetNbinsX(); ix++) { Double_t err=hGsfSelErr_neg->GetBinContent(ix,iy); var+=err*err; } } // cout << "var2: " << var << endl; nSelCorrVarv[ifile]+=var; // compute acceptances std::cout << nEvtsv[ifile] << " " << nSelv[ifile] << std::endl; accv.push_back(nSelv[ifile]/nEvtsv[ifile]); accErrv.push_back(sqrt(accv[ifile]*(1. +accv[ifile])/nEvtsv[ifile])); accCorrv.push_back(nSelCorrv[ifile]/nEvtsv[ifile]); accErrCorrv.push_back(accCorrv[ifile]*sqrt((nSelCorrVarv[ifile])/(nSelCorrv[ifile]*nSelCorrv[ifile]) + 1./nEvtsv[ifile])); delete infile; infile=0, eventTree=0; } delete info; delete gen; delete electronArr; //-------------------------------------------------------------------------------------------------------------- // Output //============================================================================================================== cout << "*" << endl; cout << "* SUMMARY" << endl; cout << "*--------------------------------------------------" << endl; cout << " Z -> e e" << endl; cout << " Mass window: [" << MASS_LOW << ", " << MASS_HIGH << "]" << endl; cout << " pT > " << PT_CUT << endl; cout << " |eta| < " << ETA_CUT << endl; cout << endl; for(UInt_t ifile=0; ifile<fnamev.size(); ifile++) { cout << " ================================================" << endl; cout << " Label: " << labelv[ifile] << endl; cout << " File: " << fnamev[ifile] << endl; cout << endl; cout << " *** Acceptance ***" << endl; cout << " nominal: " << setw(12) << nSelv[ifile] << " / " << nEvtsv[ifile] << " = " << accv[ifile] << " +/- " << accErrv[ifile] << endl; cout << " SF corrected: " << accCorrv[ifile] << " +/- " << accErrCorrv[ifile] << endl; cout << endl; } char txtfname[100]; sprintf(txtfname,"%s/binned.txt",outputDir.Data()); ofstream txtfile; txtfile.open(txtfname); txtfile << "*" << endl; txtfile << "* SUMMARY" << endl; txtfile << "*--------------------------------------------------" << endl; txtfile << " Z -> e e" << endl; txtfile << " Mass window: [" << MASS_LOW << ", " << MASS_HIGH << "]" << endl; txtfile << " pT > " << PT_CUT << endl; txtfile << " |eta| < " << ETA_CUT << endl; txtfile << endl; for(UInt_t ifile=0; ifile<fnamev.size(); ifile++) { txtfile << " ================================================" << endl; txtfile << " Label: " << labelv[ifile] << endl; txtfile << " File: " << fnamev[ifile] << endl; txtfile << endl; txtfile << " *** Acceptance ***" << endl; txtfile << " nominal: " << setw(12) << nSelv[ifile] << " / " << nEvtsv[ifile] << " = " << accv[ifile] << " +/- " << accErrv[ifile] << endl; txtfile << " SF corrected: " << accCorrv[ifile] << " +/- " << accErrCorrv[ifile] << endl; txtfile << endl; } txtfile.close(); cout << endl; cout << " <> Output saved in " << outputDir << "/" << endl; cout << endl; gBenchmark->Show("computeAccSelZeeBinned"); }
void TriggerEfficienciesSF(TString datafile, TString mcfile, TString ref, TString id, TString variable, TString xtitle, Bool_t linear = true) { gROOT->SetStyle("Plain"); gStyle->SetOptStat(0); TFile * file = new TFile(datafile); TH1D * All = (TH1D*) file->Get(TString("AllEvents")+variable)->Clone(); TH1D * Ref = (TH1D*) file->Get("Trigger"+ref+variable)->Clone(); TH1D * Trigger = (TH1D*) file->Get("Trigger"+id+variable)->Clone(); Int_t ngroup = 2; All->Rebin(ngroup); Ref->Rebin(ngroup); Trigger->Rebin(ngroup); TCanvas * canvas = new TCanvas(); // canvas->SetLogy(); All->GetXaxis()->SetTitle(xtitle); All->GetYaxis()->SetTitle("Trigger efficiency"); All->GetYaxis()->SetRangeUser(0.0,1.1); All->Draw("axis"); TEfficiency * EffData = new TEfficiency(); EffData->SetTotalHistogram(*Ref, "f"); EffData->SetPassedHistogram(*Trigger, "f"); EffData->SetMarkerStyle(kFullCircle); EffData->SetMarkerColor(kBlack); EffData->SetLineColor(kBlack); EffData->Draw("samep"); TF1 * datafit = new TF1("datafit","[0] + [1]*(x-100)^2", 100, 800); datafit->SetParameter(0,1.0); datafit->SetParameter(1,0.0); if (linear) datafit->FixParameter(1,0.0); TBinomialEfficiencyFitter * fitter = new TBinomialEfficiencyFitter(Trigger,Ref); fitter->Fit(datafit); datafit->Draw("same"); Double_t * datamatrix = fitter->GetFitter()->GetCovarianceMatrix(); Double_t dataparam[7]; dataparam[1] = datafit->GetParameter(0); dataparam[2] = datafit->GetParameter(1); for (Int_t i = 0; i < 4; ++i) { if (linear && i) dataparam[i+3] = 0; else dataparam[i+3] = datamatrix[i]; } dataparam[0] = 1.0; TF1 * dataplus = new TF1("dataplus", fitSigma, 100.0, 1000, 7); dataplus->SetParameters(dataparam); dataplus->SetLineStyle(kDashed); dataplus->SetLineWidth(1); dataplus->Draw("same"); dataparam[0] = -1.0; TF1 * dataminus = new TF1("dataminus", fitSigma, 100.0, 1000, 7); dataminus->SetParameters(dataparam); dataminus->SetLineStyle(kDashed); dataminus->SetLineWidth(1); dataminus->Draw("same"); canvas->SaveAs(id+variable+"r"+ref+"-data.png"); file = new TFile(mcfile); Ref = (TH1D*) file->Get("Trigger"+ref+variable)->Clone(); Trigger = (TH1D*) file->Get("Trigger"+id+variable)->Clone(); Ref->Rebin(ngroup); Trigger->Rebin(ngroup); TEfficiency * EffMC = new TEfficiency(); EffMC->SetTotalHistogram(*Ref, "f"); EffMC->SetPassedHistogram(*Trigger, "f"); EffMC->SetMarkerStyle(kFullSquare); EffMC->SetMarkerColor(kRed); EffMC->SetLineColor(kRed); All->Draw("axis"); EffMC->Draw("samep"); TF1 * mcfit = new TF1("mcfit","[0] + [1]*(x-100)^2", 100, 800); mcfit->SetLineColor(kRed); mcfit->SetParameter(0,1.0); mcfit->SetParameter(1,0.0); if (linear) mcfit->FixParameter(1,0.0); TBinomialEfficiencyFitter * mcfitter = new TBinomialEfficiencyFitter(Trigger,Ref); mcfitter->Fit(mcfit); mcfit->Draw("same"); Double_t * mcmatrix = mcfitter->GetFitter()->GetCovarianceMatrix(); Double_t mcparam[7]; mcparam[1] = mcfit->GetParameter(0); mcparam[2] = mcfit->GetParameter(1); for (Int_t i = 0; i < 4; ++i) { if (linear && i) mcparam[i+3] = 0; else mcparam[i+3] = mcmatrix[i]; } mcparam[0] = 1.0; TF1 * mcplus = new TF1("dataplus", fitSigma, 100.0, 1000, 7); mcplus->SetParameters(mcparam); mcplus->SetLineStyle(kDashed); mcplus->SetLineColor(kRed); mcplus->SetLineWidth(1); mcplus->Draw("same"); mcparam[0] = -1.0; TF1 * mcminus = new TF1("dataminus", fitSigma, 100.0, 1000, 7); mcminus->SetParameters(mcparam); mcminus->SetLineStyle(kDashed); mcminus->SetLineColor(kRed); mcminus->SetLineWidth(1); mcminus->Draw("same"); canvas->SaveAs(id+variable+"r"+ref+"-mc.png"); Double_t sfparam[13]; sfparam[1] = dataparam[1]; sfparam[2] = dataparam[2]; sfparam[3] = mcparam[1]; sfparam[4] = mcparam[2]; for (Int_t i = 0; i < 4; ++i) sfparam[i+5] = dataparam[i+3]; for (Int_t i = 0; i < 4; ++i) sfparam[i+9] = mcparam[i+3]; for (Int_t i = 0; i < 13; ++i) cout << sfparam[i] << " "; cout << endl; sfparam[0] = 0.0; TF1 * sf = new TF1("sf", sffit, 100.0, 1000, 13); sf->SetParameters(sfparam); All->GetYaxis()->SetTitle("Trigger scale factor"); All->GetYaxis()->SetRangeUser(0.0,1.1); All->Draw("axis"); sf->Draw("same"); sfparam[0] = 1.0; TF1 * sfplus = new TF1("sfplus", sffit, 100.0, 1000, 13); sfplus->SetParameters(sfparam); sfplus->SetLineStyle(kDashed); sfplus->SetLineWidth(1); sfplus->Draw("same"); sfparam[0] = -1.0; TF1 * sfminus = new TF1("sfminus", sffit, 100.0, 1000, 13); sfminus->SetParameters(sfparam); sfminus->SetLineStyle(kDashed); sfminus->SetLineWidth(1); sfminus->Draw("same"); if (linear) cout << "Linear fit for sf: " << sf->Eval(100) << " +- " << (sfplus->Eval(100)-sf->Eval(100)) << endl; canvas->SaveAs(id+variable+"r"+ref+"-sf.png"); }