예제 #1
0
int binfit_function_dy_y_squarecuts() {
  gROOT->Reset();

  float scaledps,scaledpsy,scalesps,scalenlo,siggg,siggu,sigug;
  float datamass[81]={0};
  int dpsmass[81]={0};
  int spsmass[81]={0};
  float nlomass[81]={0.0};
  int nloggmass[81]={0};
  int nlogumass[81]={0};
  int nlougmass[81]={0};
  float rapmax = 1.9;
  float ptmin  = 8.0;
  //  float datapt[60],datady[20],datay[20];
  TChain data("PATEventTree");
  TChain dps("PATEventTree");
  TChain sps("PATEventTree");
  TChain nlogg("PATEventTree");
  TChain nlogu("PATEventTree");
  TChain nloug("PATEventTree");

  data.Add("Selected_events_newAcc.root");
//  dps.Add("Modified_Input_To_Fit_2012DPS_TMTight_3MuL3Match.root");
  dps.Add("Modified_Input_To_Fit_2012DPS_PUold_TMTight_3MuL3MatchPv.root");
  //dps.Add("Modified_Input_To_Fit_2012DPS_GENTupleOnly_TMTight_MuL3Match.root");
  sps.Add("Modified_Input_To_Fit_2012SPSLOpy8_TMTight_3MuL3Match.root");
  //nlogg.Add("Modified_Input_To_Fit_2012SPSNLOpy8_gg_TMTight_3MuL3Match.root");
  nlogg.Add("Modified_Input_To_Fit_2012SPSNLO_gg_TMTight_MuL3Match_PU_OffsetBS.root");
  //float massbins[]={6.2,7,8,10,13,17,23,30,42,80};
  //float ptbins[]={0,7,12,16,20,25,80};
  //float dybins[]={0,0.2,0.4,0.6,0.9,1.3,1.8,2.4,4.5};
  ////float ybins[]={-2.2,-1.8,-1.6,-1.4,-1.2,-1.0,-0.8,-0.6,-0.4,-0.2,0,0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.2};
  //float ybins[]={0,0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.2};
  //int nmbins = 9; 
  //int nptbins = 6;
  //int ndybins = 8;
  //int nybins = 10;
  float massbins[]={0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80};
  float ptbins[]={0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80};
  float dybins[]={0,.3,.6,.9,1.2,1.5,1.8,2.1,2.4,2.7,3.0,3.3,3.6};
  //float dybins[]={0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3.0,3.1,3.2,3.3,3.4,3.5,3.6};
  float ybins[]={0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2};
    int nmbins = 40;
    int nptbins = 40;
    int ndybins =12;
    //int ndybins = 36;
    int nybins = 22;
  //int nybins = 20;
    int mbinerr = -99;
    int ptbinerr = -99;
    int dybinerr = -99;
    int ybinerr = -99;
  TH1F *mass_data = new TH1F("mass_data","mass_data",nmbins,massbins); 
  TH1F *mass_dps = new TH1F("mass_dps","mass_dps",nmbins,massbins); 
  TH1F *mass_sps = new TH1F("mass_sps","mass_sps",nmbins,massbins); 
  TH1F *mass_nlogg = new TH1F("mass_nlogg","mass_nlogg",nmbins,massbins); 
  TH1F *mass_nlogu = new TH1F("mass_nlogu","mass_nlogu",nmbins,massbins); 
  TH1F *mass_nloug = new TH1F("mass_nloug","mass_nloug",nmbins,massbins); 
  TH1F *mass_nlo = new TH1F("mass_nlo","mass_nlo",nmbins,massbins); 
  TH1F *pt_data = new TH1F("pt_data","pt_data",nptbins,ptbins); 
  TH1F *pt_dps = new TH1F("pt_dps","pt_dps",nptbins,ptbins); 
  TH1F *pt_sps = new TH1F("pt_sps","pt_sps",nptbins,ptbins); 
  TH1F *pt_nlogg = new TH1F("pt_nlogg","pt_nlogg",nptbins,ptbins); 
  TH1F *pt_nlogu = new TH1F("pt_nlogu","pt_nlogu",nptbins,ptbins); 
  TH1F *pt_nloug = new TH1F("pt_nloug","pt_nloug",nptbins,ptbins); 
  TH1F *pt_nlo = new TH1F("pt_nlo","pt_nlo",nptbins,ptbins); 
  TH1F *dy_data = new TH1F("dy_data","dy_data",ndybins,dybins); 
  TH1F *dy_dps = new TH1F("dy_dps","dy_dps",ndybins,dybins); 
  TH1F *dy_sps = new TH1F("dy_sps","dy_sps",ndybins,dybins); 
  TH1F *dy_nlogg = new TH1F("dy_nlogg","dy_nlogg",ndybins,dybins); 
  TH1F *dy_nlogu = new TH1F("dy_nlogu","dy_nlogu",ndybins,dybins); 
  TH1F *dy_nloug = new TH1F("dy_nloug","dy_nloug",ndybins,dybins); 
  TH1F *dy_nlo = new TH1F("dy_nlo","dy_nlo",ndybins,dybins); 
  TH1F *y_data = new TH1F("y_data","y_data",nybins,ybins); 
  TH1F *y_dps = new TH1F("y_dps","y_dps",nybins,ybins); 
  TH1F *y_sps = new TH1F("y_sps","y_sps",nybins,ybins); 
  TH1F *y_nlogg = new TH1F("y_nlogg","y_nlogg",nybins,ybins); 
  TH1F *y_nlogu = new TH1F("y_nlogu","y_nlogu",nybins,ybins); 
  TH1F *y_nloug = new TH1F("y_nloug","y_nloug",nybins,ybins); 
  TH1F *y_nlo = new TH1F("y_nlo","y_nlo",nybins,ybins); 
  data.Draw("FourMu_Mass >> mass_data",Form("FourMu_pT<80&&abs(FourMu_Rapidity)<1.8&&FourMu_Mass<60&&Sum$(Psi_pT>%.1f&&abs(Psi_y)<=%.1f)==2",ptmin,rapmax),"goff");
    mass_dps->SetEntries(109951.);
//    mass_dps->SetEntries(127.);
    dps.Draw("FourMu_Mass >> mass_dps",Form("FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4",rapmax,ptmin),"goff");
    sps.Draw("FourMu_Mass >> mass_sps",Form("FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4",rapmax,ptmin),"goff");
nlogg.Draw("FourMu_Mass >> mass_nlogg",Form("FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4",rapmax,ptmin),"goff");
nlogu.Draw("FourMu_Mass >> mass_nlogu",Form("FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4",rapmax,ptmin),"goff");
nloug.Draw("FourMu_Mass >> mass_nloug",Form("FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4",rapmax,ptmin),"goff");

  datamass[0]=mass_data->Integral();
  std::cout<<datamass[0]<<std::endl;
//dps MC reco integral
  dpsmass[2]=127.;
//data reshuffle integral
  dpsmass[1]=109951./7.14777;
  dpsmass[0]=mass_dps->Integral();
  spsmass[0]=mass_sps->Integral();
  nloggmass[0]=mass_nlogg->Integral();
  nlogumass[0]=mass_nlogu->Integral();
  nlougmass[0]=mass_nlogg->Integral();
  //siggg=2.01;siggu=0.45;sigug=0.13;
  siggg=1.0;siggu=0.0;sigug=0.0;
  nlomass[0]=siggg*nloggmass[0] + siggu*nlogumass[0] + sigug*nlougmass[0]; 

  scaledps = datamass[0]/ (float) dpsmass[0];
  scaledps1 = datamass[0]/ (float) dpsmass[1];
  scaledps2 = datamass[0]/ (float) dpsmass[1];
  scalesps= datamass[0]/ (float) spsmass[0];
  scalenlo= datamass[0]/ (float) nloggmass[0];
  float Chi2=0;
  float minchi2norm=99999999.9;
  float minchi2=9999999.9;
  float mina, minb, minc, minan, minbn, mincn;
    TH1F *DpsBestdy = new TH1F("DpsBestdy","DpsBestdy",ndybins,dybins);
    TH1F *DpsBesty = new TH1F("DpsBesty","DpsBesty",nybins,ybins);

  //   Chi2 = Chi2 + pow((datamass[1] - (0.00*scaledps*dpsmass[1] + 0.0*scalesps*spsmass[1] + 0.0*scalenlo*nlomass[1])),2)/sqrt(datamass[1]);
  //  std::cout<<"Scale: " <<datamass[0]<<" " << dpsmass[0]<<" "<<scaledps<<" "<<scalesps<<" "<<scalenlo<<" "<<std::endl;
  for(float a=0.0; a<0.5; a=a+0.01){
    for(float b=0.0; b<0.009; b=b+0.01){
      for(float c=0.5; c<1; c=c+0.01){
        data.Draw("FourMu_Mass >> mass_data",Form("FourMu_pT<80&&abs(FourMu_Rapidity)<1.8&&FourMu_Mass<60&&Sum$(Psi_pT>%.1f&&abs(Psi_y)<=%.1f)==2",ptmin,rapmax),"goff");
            dps.Draw("FourMu_Mass >> mass_dps",Form("FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4",rapmax,ptmin),"goff");
            sps.Draw("FourMu_Mass >> mass_sps",Form("FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4",rapmax,ptmin),"goff");
        nlogg.Draw("FourMu_Mass >> mass_nlogg",Form("FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4",rapmax,ptmin),"goff");
        data.Draw("FourMu_pT >> pt_data",Form("FourMu_pT<80&&abs(FourMu_Rapidity)<1.8&&FourMu_Mass<60&&Sum$(Psi_pT>%.1f&&abs(Psi_y)<=%.1f)==2",ptmin,rapmax),"goff");
                dps.Draw("FourMu_pT >> pt_dps",Form("FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4",rapmax,ptmin),"goff");
                sps.Draw("FourMu_pT >> pt_sps",Form("FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4",rapmax,ptmin),"goff");
            nlogg.Draw("FourMu_pT >> pt_nlogg",Form("FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4",rapmax,ptmin),"goff");
        data.Draw("Psi1To2_dY >> dy_data",Form("FourMu_pT<80&&abs(FourMu_Rapidity)<1.8&&FourMu_Mass<60&&Sum$(Psi_pT>%.1f&&abs(Psi_y)<=%.1f)==2",ptmin,rapmax),"goff");
              dps.Draw("Psi1To2_dY ",Form("FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4",rapmax,ptmin),"goff");
              sps.Draw("Psi1To2_dY >> dy_sps",Form("FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4",rapmax,ptmin),"goff");
          nlogg.Draw("Psi1To2_dY >> dy_nlogg",Form("FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4",rapmax,ptmin),"goff");
        data.Draw("abs(FourMu_Rapidity)>> y_data",Form("FourMu_pT<80&&abs(FourMu_Rapidity)<1.8&&FourMu_Mass<60&&Sum$(Psi_pT>%.1f&&abs(Psi_y)<=%.1f)==2",ptmin,rapmax),"goff");
       dps.Draw("abs(FourMu_Rapidity)",Form("FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4",rapmax,ptmin),"goff");
      sps.Draw("abs(FourMu_Rapidity) >> y_sps",Form("FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4",rapmax,ptmin),"goff");
  nlogg.Draw("abs(FourMu_Rapidity) >> y_nlogg",Form("FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4",rapmax,ptmin),"goff");
        for(int mbin=1; mbin<=nmbins; ++mbin){
          if (mass_data->GetBinContent(mbin) == 0){
            //mbinerr = 1.;
            continue;
          }
          else{mbinerr = sqrt(abs(mass_data->GetBinContent(mbin)));}
   //       Chi2=Chi2 + pow((mass_data->GetBinContent(mbin) - (a*scaledps*mass_dps->GetBinContent(mbin) + b*scalesps*mass_sps->GetBinContent(mbin) + c*scalenlo*mass_nlogg->GetBinContent(mbin))),2)/mbinerr;
//          Chi2=Chi2 + pow((mass_data->GetBinContent(mbin) - (a*scaledps*mass_dps->GetBinContent(mbin) + b*scalesps*mass_sps->GetBinContent(mbin) + c*scalenlo*mass_nlogg->GetBinContent(mbin)))/sqrt(abs(mass_data->GetBinContent(mbin))),2);
          //           std::cout<<Chi2<<std::endl;
        }
        for(int ptbin=1; ptbin<=nptbins; ++ptbin){
          if (pt_data->GetBinContent(ptbin) == 0){
            ptbinerr = 1.;
          }
          else{ptbinerr = sqrt(abs(pt_data->GetBinContent(ptbin)));}
          Chi2=Chi2 + pow((pt_data->GetBinContent(ptbin) - (a*scaledps*pt_dps->GetBinContent(ptbin) + b*scalesps*pt_sps->GetBinContent(ptbin) + c*scalenlo*pt_nlogg->GetBinContent(ptbin)))/ptbinerr,2);
            //         std::cout<<pt_data->GetBinContent(ptbin)<<std::endl;
        }
        for(int dybin=1; dybin<=ndybins; ++dybin){
          if (dy_data->GetBinContent(dybin) == 0){
            dybinerr = 1.;
          }
          else{dybinerr = sqrt(abs(dy_data->GetBinContent(dybin)));}
          float avgval = (dpsget(dybins[dybin])+dpsget(dybins[dybin-1]))/2.;
          dy_dps->SetBinContent(dybin,avgval);
          if(avgval>=0){
          DpsBestdy->SetBinContent(dybin,avgval);
          }
          Chi2=Chi2 + pow((dy_data->GetBinContent(dybin) - (a*scaledps1*dy_dps->GetBinContent(dybin) + b*scalesps*dy_sps->GetBinContent(dybin) + c*scalenlo*dy_nlogg->GetBinContent(dybin)))/dybinerr,2);
          //           std::cout<<Chi2<<std::endl;
        }
        for(int ybin=1; ybin<=nybins; ++ybin){
          if (y_data->GetBinContent(ybin) == 0){
            ybinerr = 1.;
          }
          else{ybinerr = sqrt(abs(y_data->GetBinContent(ybin)));}
          float avgval = (dpsgety(ybins[ybin])+dpsgety(ybins[ybin-1]))/2.;
          y_dps->SetBinContent(ybin,avgval);
          if(avgval>=0){
          DpsBesty->SetBinContent(ybin,avgval);
          }
          Chi2=Chi2 + pow((y_data->GetBinContent(ybin) - (a*scaledps2*y_dps->GetBinContent(ybin) + b*scalesps*y_sps->GetBinContent(ybin) + c*scalenlo*y_nlogg->GetBinContent(ybin)))/ybinerr,2);
          //           std::cout<<Chi2<<std::endl;
        }
//                std::cout<<"a, b, c: "<<a<<" "<<b<<" "<<c<<" Chi2: "<<Chi2<<std::endl;
        if (Chi2<=minchi2norm){
          if ( abs(1. - abs(a+b+c))<0.001){
            minchi2norm=Chi2; minan = a; minbn = b; mincn = c;
            std::cout<<a<<" "<<b<<" "<<c<<" "<<Chi2<<std::endl;
          }
        }
        if (Chi2<=minchi2){
          minchi2=Chi2; mina = a; minb = b; minc = c;
        }
        //        std::cout<<a<<" "<<b<<" "<<c<<" "<<Chi2<<std::endl;
        Chi2=0;
        }
      }
    }
    std::cout<<"Min Chi2: "<<minchi2<<" dps, sps, nlo: "<<mina<<" "<<minb<<" "<<minc<<std::endl;
    std::cout<<"Min normed Chi2: "<<minchi2norm<<" dps, sps, nlo: "<<minan<<" "<<minbn<<" "<<mincn<<std::endl;
    TCanvas* disp = new TCanvas("disp","disp",900,900);
    disp->Divide(2,2);
    TH1F *MassSum = new TH1F("MassSum","MassSum",nmbins,massbins);
    TH1F *MassBest = new TH1F("MassBest","MassBest",nmbins,massbins);
    TH1F *DpsBestM = new TH1F("DpsBestM","DpsBestM",nmbins,massbins);
    TH1F *SpsBestM = new TH1F("SpsBestM","SpsBestM",nmbins,massbins);
    TH1F *NloBestM = new TH1F("NloBestM","NloBestM",nmbins,massbins);
    TH1F *pTBest = new TH1F("pTBest","pTBest",nptbins,ptbins);
    TH1F *pTSum = new TH1F("pTSum","pTSum",nptbins,ptbins);
    TH1F *DpsBestpt = new TH1F("DpsBestpt","DpsBestpt",nptbins,ptbins);
    TH1F *SpsBestpt = new TH1F("SpsBestpt","SpsBestpt",nptbins,ptbins);
    TH1F *NloBestpt = new TH1F("NloBestpt","NloBestpt",nptbins,ptbins);
    TH1F *dyBest = new TH1F("dyBest","dyBest",ndybins,dybins);
    TH1F *dySum = new TH1F("dySum","dySum",ndybins,dybins);
    TH1F *SpsBestdy = new TH1F("SpsBestdy","SpsBestdy",ndybins,dybins);
    TH1F *NloBestdy = new TH1F("NloBestdy","NloBestdy",ndybins,dybins);
    TH1F *yBest = new TH1F("yBest","yBest",nybins,ybins);
    TH1F *ySum = new TH1F("ySum","ySum",nybins,ybins);
    TH1F *SpsBesty = new TH1F("SpsBesty","SpsBesty",nybins,ybins);
    TH1F *NloBesty = new TH1F("NloBesty","NloBesty",nybins,ybins);
    MassBest->SetMinimum(0);pTBest->SetMinimum(0);dyBest->SetMinimum(0);yBest->SetMinimum(0);
    dps.Draw("FourMu_Mass>>DpsBestM",Form("(FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4)",rapmax,ptmin),"goff");
    sps.Draw("FourMu_Mass>>SpsBestM",Form("(FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4)",rapmax,ptmin),"goff");
  nlogg.Draw("FourMu_Mass>>NloBestM",Form("(FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4)",rapmax,ptmin),"goff");
     dps.Draw("FourMu_pT>>DpsBestpt",Form("(FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4)",rapmax,ptmin),"goff");
     sps.Draw("FourMu_pT>>SpsBestpt",Form("(FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4)",rapmax,ptmin),"goff");
   nlogg.Draw("FourMu_pT>>NloBestpt",Form("(FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4)",rapmax,ptmin),"goff");
//    dps.Draw("Psi1To2_dY>>DpsBestdy",Form("(FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4)",rapmax,ptmin),"goff");
    sps.Draw("Psi1To2_dY>>SpsBestdy",Form("(FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4)",rapmax,ptmin),"goff");
  nlogg.Draw("Psi1To2_dY>>NloBestdy",Form("(FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4)",rapmax,ptmin),"goff");
//    dps.Draw("abs(FourMu_Rapidity)>>DpsBesty",Form("(FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4)",rapmax,ptmin),"goff");
    sps.Draw("abs(FourMu_Rapidity)>>SpsBesty",Form("(FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4)",rapmax,ptmin),"goff");
  nlogg.Draw("abs(FourMu_Rapidity)>>NloBesty",Form("(FourMu_Mass>=0&&FourMu_Mass<=60&&FourMu_VtxProb>=0.1&&Sum$(abs(Psi_y)<=%.1f&&Psi_pT>%.1f)==2&&Sum$(abs(Mu_Eta)<=1.2&&Mu_pT>3.5||abs(Mu_Eta)>1.2&&abs(Mu_Eta)<1.6&&(Mu_pT>-3.75*abs(Mu_Eta)+8)||abs(Mu_Eta)>=1.6&&abs(Mu_Eta)<=2.0&&Mu_pT>2.0)==4)",rapmax,ptmin),"goff");
    //MassSum->Add(DpsBest,(float) mina);
    //MassSum->Add(SpsBest,minb);
    //MassSum->Add(NloBest,minc);
    MassBest->SetMinimum(0);
    disp->cd(1);
    DpsBestM->SetLineColor(kRed);
    SpsBestM->SetLineColor(kBlue);
    NloBestM->SetLineColor(kGreen);
    DpsBestM->Scale(minan*scaledps);
    SpsBestM->Scale(minbn*scalesps);
    NloBestM->Scale(mincn*scalenlo);
    MassSum->Add(DpsBestM);
    MassSum->Add(SpsBestM);
    MassSum->Add(NloBestM);
    data.Draw("FourMu_Mass >> MassBest",Form("FourMu_pT<80&&abs(FourMu_Rapidity)<1.8&&FourMu_Mass<60&&Sum$(Psi_pT>%.1f&&abs(Psi_y)<=%.1f)==2",ptmin,rapmax),"e");
    MassSum->Draw("same");
    DpsBestM->Draw("same");
    SpsBestM->Draw("same");
    NloBestM->Draw("same");
    disp->cd(2);
    DpsBestpt->SetLineColor(kRed);
    SpsBestpt->SetLineColor(kBlue);
    NloBestpt->SetLineColor(kGreen);
    DpsBestpt->Scale(minan*scaledps);
    SpsBestpt->Scale(minbn*scalesps);
    NloBestpt->Scale(mincn*scalenlo);
    pTSum->Add(DpsBestpt);
    pTSum->Add(SpsBestpt);
    pTSum->Add(NloBestpt);
    data.Draw("FourMu_pT >> pTBest",Form("FourMu_pT<80&&abs(FourMu_Rapidity)<1.8&&FourMu_Mass<60&&Sum$(Psi_pT>%.1f&&abs(Psi_y)<=%.1f)==2",ptmin,rapmax),"e");
    pTSum->Draw("same");
    DpsBestpt->Draw("same");
    SpsBestpt->Draw("same");
    NloBestpt->Draw("same");
    disp->cd(3);
    DpsBestdy->SetLineColor(kRed);
    SpsBestdy->SetLineColor(kBlue);
    NloBestdy->SetLineColor(kGreen);
    DpsBestdy->Scale(minan*scaledps1);
    SpsBestdy->Scale(minbn*scalesps);
    NloBestdy->Scale(mincn*scalenlo);
    dySum->Add(DpsBestdy);
    dySum->Add(SpsBestdy);
    dySum->Add(NloBestdy);
    data.Draw("Psi1To2_dY >> dyBest",Form("FourMu_pT<80&&abs(FourMu_Rapidity)<1.8&&FourMu_Mass<60&&Sum$(Psi_pT>%0.1f&&abs(Psi_y)<=%0.1f)==2",ptmin,rapmax),"e");
    dySum->Draw("same");
    DpsBestdy->Draw("same");
    SpsBestdy->Draw("same");
    NloBestdy->Draw("same");
    disp->cd(4);
    DpsBesty->SetLineColor(kRed);
    SpsBesty->SetLineColor(kBlue);
    NloBesty->SetLineColor(kGreen);
    DpsBesty->Scale(minan*scaledps2);
    SpsBesty->Scale(minbn*scalesps);
    NloBesty->Scale(mincn*scalenlo);
    ySum->Add(DpsBesty);
    ySum->Add(SpsBesty);
    ySum->Add(NloBesty);
    data.Draw("abs(FourMu_Rapidity)>> yBest",Form("FourMu_pT<80&&abs(FourMu_Rapidity)<1.8&&FourMu_Mass<60&&Sum$(Psi_pT>%0.1f&&abs(Psi_y)<=%.1f)==2",ptmin,rapmax),"e");
    ySum->Draw("same");
    DpsBesty->Draw("same");
    SpsBesty->Draw("same");
    NloBesty->Draw("same");
  }
int Xsec_calcTtreeFewerbins_Jan2017SavedXSEC() {
  gROOT->Reset();

  float scaledps,scalesps,scalenlo,siggg,siggu,sigug;
  //  float datapt[60],datady[20],datay[20];
  TChain data("ntuple");
  TChain dps("PATEventTree");
  TChain sps("PATEventTree");
  TChain nlogg("PATEventTree");
  TChain nlogu("PATEventTree");
  TChain nloug("PATEventTree");
  float massbins[]={6.2,7,9,11,14,18,25,30,45,80};
  float massbins2[]={0,6.2,7,9,11,14,18,25,30,45,80};
  float ptbins[]={0,7,12,16,20,25,80};
  float dybins[]={0,0.2,0.4,0.6,0.9,1.3,1.8,2.4,4.5};
  //float ybins[]={-2.2,-1.8,-1.6,-1.4,-1.2,-1.0,-0.8,-0.6,-0.4,-0.2,0,0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.2};
  float ybins[]={0,0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.2};
  int nmbins = 9;
  int nmbins2 = 10;
  int nptbins = 6;
  int ndybins = 8;
  int nybins = 10;
  //  float massbins[]={6.2,6.5,7,8.5,11,14,18,24,30,45,80};
  //  float massbins2[]={0,6.2,6.5,7,8.5,11,14,18,24,30,45,80};
  //  float ptbins[]={0,4,8,12,15,18,22,26,30,80};
  //  float dybins[]={0,0.1,0.2,0.3,0.45,0.6,0.9,1.3,1.8,2.4,4.5};
  ////  float ybins[]={-2.2,-1.8,-1.6,-1.4,-1.2,-1.0,-0.8,-0.6,-0.4,-0.2,0,0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.2};
  //  float ybins[]={0,0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.2};
  //  int nmbins = 10; 
  //  int nmbins2 = 10; 
  //  int nptbins = 9;
  //  int ndybins = 10;
  //  int nybins = 10;
  float fracDPS = 0.3;
  float fracNLO = 0.7;
  float corrPop = 0;
  float corrPoppt = 0;
  float corrPopdy = 0;
  float corrPopy = 0;
  float xsec_sum_mass = 0;
  float xsec_sum_dy= 0;
  float xsec_sum_y= 0;
  float xsec_sum_pt = 0;

  TH1F *mass_data = new TH1F("mass_data","mass_data",nmbins,massbins); 
  TH1F *pt_data = new TH1F("pt_data","pt_data",nptbins,ptbins); 
  TH1F *dy_data = new TH1F("dy_data","dy_data",ndybins,dybins); 
  TH1F *y_data = new TH1F("y_data","y_data",nybins,ybins); 
  TH1F *xsec_mass = new TH1F("xsec_mass","xsec_mass",nmbins2,massbins2); 
  TH1F *xsec_pt = new TH1F("xsec_pt","xsec_pt",nptbins,ptbins); 
  TH1F *xsec_dy = new TH1F("xsec_dy","xsec_dy",ndybins,dybins); 
  TH1F *xsec_y = new TH1F("xsec_y","xsec_y",nybins,ybins); 
  mass_data->Sumw2();
  pt_data->Sumw2();
  dy_data->Sumw2();
  y_data->Sumw2();
  xsec_mass->Sumw2();
  xsec_pt->Sumw2();
  xsec_dy->Sumw2();
  xsec_y->Sumw2();
  xsec_pt->SetMinimum(0);
  xsec_dy->SetMinimum(0);
  xsec_y->SetMinimum(0);
  data.Add("TMTight_Selected.root");
  //data.Draw("FourMu_Mass>>mass_data","","egoff"); 
  //data.Draw("FourMu_pT>>pt_data","","egoff"); 
  //data.Draw("Psi1To2_dY>>dy_data","","egoff"); 
  //data.Draw("abs(FourMu_Rapidity)>>y_data","","egoff"); 
  mass_data->SetBinContent(1,123.); 
  mass_data->SetBinContent(2,141.);   
  mass_data->SetBinContent(3,82.);
  mass_data->SetBinContent(4,91.);
  mass_data->SetBinContent(5,78.);
  mass_data->SetBinContent(6,87.);
  mass_data->SetBinContent(7,63.);
  mass_data->SetBinContent(8,79.);
  mass_data->SetBinContent(9,55.);
  pt_data->SetBinContent(1,144.);
  pt_data->SetBinContent(2,106.);
  pt_data->SetBinContent(3,111.);
  pt_data->SetBinContent(4,123.);
  pt_data->SetBinContent(5,140.);
  pt_data->SetBinContent(6,171.);
  dy_data->SetBinContent(1,268.);
  dy_data->SetBinContent(2,157.);
  dy_data->SetBinContent(3,79.);
  dy_data->SetBinContent(4,66.);
  dy_data->SetBinContent(5,58.);
  dy_data->SetBinContent(6,46.);
  dy_data->SetBinContent(7,48.);
  dy_data->SetBinContent(8,74.);
  y_data->SetBinContent(1,67.);
  y_data->SetBinContent(2,78.);
  y_data->SetBinContent(3,63.);
  y_data->SetBinContent(4,78.);
  y_data->SetBinContent(5,67.);
  y_data->SetBinContent(6,65.);
  y_data->SetBinContent(7,87.);
  y_data->SetBinContent(8,105.);
  y_data->SetBinContent(9,98.);
  y_data->SetBinContent(10,78.);



  //corrections from DPS PU
  TH1D *acc_eff_shape_dps = new TH1D("acc_eff_shape_dps","acc_eff_shape_dps",nmbins, massbins);
  acc_eff_shape_dps->SetBinContent(1,0.004512168);
  acc_eff_shape_dps->SetBinContent(2,0.005237332);
  acc_eff_shape_dps->SetBinContent(3,0.004232796);
  acc_eff_shape_dps->SetBinContent(4,0.006519035);
  acc_eff_shape_dps->SetBinContent(5,0.01182224);
  acc_eff_shape_dps->SetBinContent(6,0.01551388);
  acc_eff_shape_dps->SetBinContent(7,0.01087612);
  acc_eff_shape_dps->SetBinContent(8,0.006657566);
  acc_eff_shape_dps->SetBinContent(9,0.01604464);
  acc_eff_shape_dps->SetBinError(1,0.001010145);
  acc_eff_shape_dps->SetBinError(2,0.0007732624);
  acc_eff_shape_dps->SetBinError(3,0.0006617851);
  acc_eff_shape_dps->SetBinError(4,0.0007255745);
  acc_eff_shape_dps->SetBinError(5,0.001216691);
  acc_eff_shape_dps->SetBinError(6,0.001440083);
  acc_eff_shape_dps->SetBinError(7,0.001342571);
  acc_eff_shape_dps->SetBinError(8,0.0004800581);
  acc_eff_shape_dps->SetBinError(9,0.001441102);
  TH1D *acc_eff_shape_dps_pt = new TH1D("acc_eff_shape_dps_pt","acc_eff_shape_dps_pt",nptbins, ptbins);
  acc_eff_shape_dps_pt->SetBinContent(1,0.00547208);
  acc_eff_shape_dps_pt->SetBinContent(2,0.005942975);
  acc_eff_shape_dps_pt->SetBinContent(3,0.01422075);
  acc_eff_shape_dps_pt->SetBinContent(4,0.02905163);
  acc_eff_shape_dps_pt->SetBinContent(5,0.0450849);
  acc_eff_shape_dps_pt->SetBinContent(6,0.03631651);
  acc_eff_shape_dps_pt->SetBinError(1,0.0003975557);
  acc_eff_shape_dps_pt->SetBinError(2,0.0003866389);
  acc_eff_shape_dps_pt->SetBinError(3,0.0009944951);
  acc_eff_shape_dps_pt->SetBinError(4,0.002856667);
  acc_eff_shape_dps_pt->SetBinError(5,0.007399703);
  acc_eff_shape_dps_pt->SetBinError(6,0.01296153);
  TH1D *acc_eff_shape_dps_dy = new TH1D("acc_eff_shape_dps_dy","acc_eff_shape_dps_dy",ndybins, dybins);
  acc_eff_shape_dps_dy->SetBinContent(1,0.005870714);
  acc_eff_shape_dps_dy->SetBinContent(2,0.007500112);
  acc_eff_shape_dps_dy->SetBinContent(3,0.007700724);
  acc_eff_shape_dps_dy->SetBinContent(4,0.01043607);
  acc_eff_shape_dps_dy->SetBinContent(5,0.01419795);
  acc_eff_shape_dps_dy->SetBinContent(6,0.0144408);
  acc_eff_shape_dps_dy->SetBinContent(7,0.01547821);
  acc_eff_shape_dps_dy->SetBinContent(8,0.007100947);
  acc_eff_shape_dps_dy->SetBinError(1,0.0006340292);
  acc_eff_shape_dps_dy->SetBinError(2,0.0008150998);
  acc_eff_shape_dps_dy->SetBinError(3,0.001031129);
  acc_eff_shape_dps_dy->SetBinError(4,0.001362374);
  acc_eff_shape_dps_dy->SetBinError(5,0.001855286);
  acc_eff_shape_dps_dy->SetBinError(6,0.001770893);
  acc_eff_shape_dps_dy->SetBinError(7,0.001705836);
  acc_eff_shape_dps_dy->SetBinError(8,0.0004184799);
  TH1D *acc_eff_shape_dps_y = new TH1D("acc_eff_shape_dps_y","acc_eff_shape_dps_y",nybins, ybins);
  acc_eff_shape_dps_y->SetBinContent(1,0.006797462);
  acc_eff_shape_dps_y->SetBinContent(2,0.008447607);
  acc_eff_shape_dps_y->SetBinContent(3,0.01434022);
  acc_eff_shape_dps_y->SetBinContent(4,0.01521911);
  acc_eff_shape_dps_y->SetBinContent(5,0.01412309);
  acc_eff_shape_dps_y->SetBinContent(6,0.01530765);
  acc_eff_shape_dps_y->SetBinContent(7,0.01599881);
  acc_eff_shape_dps_y->SetBinContent(8,0.008404481);
  acc_eff_shape_dps_y->SetBinContent(9,0.005915134);
  acc_eff_shape_dps_y->SetBinContent(10,0.005450354);
  acc_eff_shape_dps_y->SetBinError(1,0.000494813);
  acc_eff_shape_dps_y->SetBinError(2,0.0008358758);
  acc_eff_shape_dps_y->SetBinError(3,0.001751432);
  acc_eff_shape_dps_y->SetBinError(4,0.002086759);
  acc_eff_shape_dps_y->SetBinError(5,0.002096988);
  acc_eff_shape_dps_y->SetBinError(6,0.002249875);
  acc_eff_shape_dps_y->SetBinError(7,0.002117485);
  acc_eff_shape_dps_y->SetBinError(8,0.001127806);
  acc_eff_shape_dps_y->SetBinError(9,0.0007090816);
  acc_eff_shape_dps_y->SetBinError(10,0.0005697851);


  TH1D *acc_eff_shape_nlo = new TH1D("acc_eff_shape_nlo","acc_eff_shape_nlo",nmbins, massbins);
  acc_eff_shape_nlo->SetBinContent(0,0.01846972);
  acc_eff_shape_nlo->SetBinContent(1,0.02142697);
  acc_eff_shape_nlo->SetBinContent(2,0.02221486);
  acc_eff_shape_nlo->SetBinContent(3,0.02262098);
  acc_eff_shape_nlo->SetBinContent(4,0.01853098);
  acc_eff_shape_nlo->SetBinContent(5,0.02843624);
  acc_eff_shape_nlo->SetBinContent(6,0.04699465);
  acc_eff_shape_nlo->SetBinContent(7,0.06688011);
  acc_eff_shape_nlo->SetBinContent(8,0.1080789);
  acc_eff_shape_nlo->SetBinContent(9,0.09860529);
  acc_eff_shape_nlo->SetBinError(0,0.002909392);
  acc_eff_shape_nlo->SetBinError(1,0.001357906);
  acc_eff_shape_nlo->SetBinError(2,0.001055741);
  acc_eff_shape_nlo->SetBinError(3,0.001298359);
  acc_eff_shape_nlo->SetBinError(4,0.001058198);
  acc_eff_shape_nlo->SetBinError(5,0.001610718);
  acc_eff_shape_nlo->SetBinError(6,0.002596644);
  acc_eff_shape_nlo->SetBinError(7,0.007227739);
  acc_eff_shape_nlo->SetBinError(8,0.01309785);
  acc_eff_shape_nlo->SetBinError(9,0.046094);
  TH1D *acc_eff_shape_nlo_pt = new TH1D("acc_eff_shape_nlo_pt","acc_eff_shape_nlo_pt",nptbins, ptbins);
  acc_eff_shape_nlo_pt->SetBinContent(1,0.01642734);
  acc_eff_shape_nlo_pt->SetBinContent(2,0.01386493);
  acc_eff_shape_nlo_pt->SetBinContent(3,0.01767661);
  acc_eff_shape_nlo_pt->SetBinContent(4,0.02705417);
  acc_eff_shape_nlo_pt->SetBinContent(5,0.05204162);
  acc_eff_shape_nlo_pt->SetBinContent(6,0.09543021);
  acc_eff_shape_nlo_pt->SetBinError(1,0.0009637853);
  acc_eff_shape_nlo_pt->SetBinError(2,0.0008030143);
  acc_eff_shape_nlo_pt->SetBinError(3,0.0009694275);
  acc_eff_shape_nlo_pt->SetBinError(4,0.001426161);
  acc_eff_shape_nlo_pt->SetBinError(5,0.002597588);
  acc_eff_shape_nlo_pt->SetBinError(6,0.004561025);
  TH1D *acc_eff_shape_nlo_dy = new TH1D("acc_eff_shape_nlo_dy","acc_eff_shape_nlo_dy",ndybins, dybins);
  acc_eff_shape_nlo_dy->SetBinContent(1,0.02650818);
  acc_eff_shape_nlo_dy->SetBinContent(2,0.0255388);
  acc_eff_shape_nlo_dy->SetBinContent(3,0.02563938);
  acc_eff_shape_nlo_dy->SetBinContent(4,0.02482702);
  acc_eff_shape_nlo_dy->SetBinContent(5,0.02566114);
  acc_eff_shape_nlo_dy->SetBinContent(6,0.02265824);
  acc_eff_shape_nlo_dy->SetBinContent(7,0.01357843);
  acc_eff_shape_nlo_dy->SetBinContent(8,0.02730608);
  acc_eff_shape_nlo_dy->SetBinError(1,0.0009077435);
  acc_eff_shape_nlo_dy->SetBinError(2,0.001072157);
  acc_eff_shape_nlo_dy->SetBinError(3,0.001377081);
  acc_eff_shape_nlo_dy->SetBinError(4,0.001666925);
  acc_eff_shape_nlo_dy->SetBinError(5,0.002453789);
  acc_eff_shape_nlo_dy->SetBinError(6,0.003491914);
  acc_eff_shape_nlo_dy->SetBinError(7,0.005164781);
  acc_eff_shape_nlo_dy->SetBinError(8,0.01596601);
  TH1D *acc_eff_shape_nlo_y = new TH1D("acc_eff_shape_nlo_y","acc_eff_shape_nlo_y",nybins, ybins);
  acc_eff_shape_nlo_y->SetBinContent(1,0.03577394);
  acc_eff_shape_nlo_y->SetBinContent(2,0.03567842);
  acc_eff_shape_nlo_y->SetBinContent(3,0.04134786);
  acc_eff_shape_nlo_y->SetBinContent(4,0.03799442);
  acc_eff_shape_nlo_y->SetBinContent(5,0.04216027);
  acc_eff_shape_nlo_y->SetBinContent(6,0.03112481);
  acc_eff_shape_nlo_y->SetBinContent(7,0.03069787);
  acc_eff_shape_nlo_y->SetBinContent(8,0.02323072);
  acc_eff_shape_nlo_y->SetBinContent(9,0.02243196);
  acc_eff_shape_nlo_y->SetBinContent(10,0.01597226);
  acc_eff_shape_nlo_y->SetBinError(1,0.003503381);
  acc_eff_shape_nlo_y->SetBinError(2,0.003430908);
  acc_eff_shape_nlo_y->SetBinError(3,0.003631484);
  acc_eff_shape_nlo_y->SetBinError(4,0.003283295);
  acc_eff_shape_nlo_y->SetBinError(5,0.003130688);
  acc_eff_shape_nlo_y->SetBinError(6,0.002317426);
  acc_eff_shape_nlo_y->SetBinError(7,0.00187935);
  acc_eff_shape_nlo_y->SetBinError(8,0.001321922);
  acc_eff_shape_nlo_y->SetBinError(9,0.001154492);
  acc_eff_shape_nlo_y->SetBinError(10,0.0008532619);


  for(int mbin=1; mbin<=nmbins; ++mbin){
    corrPop = mass_data->GetBinContent(mbin)/(0.0593*0.0593*20.339*((fracDPS*acc_eff_shape_dps->GetBinContent(mbin))+(fracNLO*acc_eff_shape_nlo->GetBinContent(mbin)))*(massbins[mbin]-massbins[mbin-1]));
    xsec_mass->SetBinContent(mbin+1,corrPop*1e-6);
    xsec_sum_mass = xsec_sum_mass+(corrPop*1e-6*(massbins[mbin]-massbins[mbin-1]));
    xsec_mass->SetBinError(mbin+1, xsec_mass->GetBinContent(mbin)/sqrt(mass_data->GetBinContent(mbin)));
  }
  for(int ptbin=1; ptbin<=nptbins; ++ptbin){
    corrPoppt = pt_data->GetBinContent(ptbin)/(pow(0.0593,2)*20.339*(fracDPS*acc_eff_shape_dps_pt->GetBinContent(ptbin)+fracNLO*acc_eff_shape_nlo_pt->GetBinContent(ptbin))*(ptbins[ptbin]-ptbins[ptbin-1]));
    //          std::cout<<pt_data->GetBinContent(ptbin)<<" over "<<0.0593*0.0593*20.339<<" times "<<((fracDPS*acc_eff_shape_dps_pt->GetBinContent(ptbin))+(fracNLO*acc_eff_shape_nlo_pt->GetBinContent(ptbin)))<<" times "<<(ptbins[ptbin]-ptbins[ptbin-1])<<" equals??? "<<corrPoppt<<std::endl;
    xsec_pt->SetBinContent(ptbin,corrPoppt*1e-6);
    xsec_sum_pt = xsec_sum_pt+(corrPoppt*1e-6*(ptbins[ptbin]-ptbins[ptbin-1]));
    xsec_pt->SetBinError(ptbin, xsec_pt->GetBinContent(ptbin)/sqrt(pt_data->GetBinContent(ptbin)));
  }
  for(int dybin=1; dybin<=ndybins; ++dybin){
    corrPopdy = dy_data->GetBinContent(dybin)/(pow(0.0593,2)*20.339*(fracDPS*acc_eff_shape_dps_dy->GetBinContent(dybin)+fracNLO*acc_eff_shape_nlo_dy->GetBinContent(dybin))*(dybins[dybin]-dybins[dybin-1]));
    //          std::cout<<dy_data->GetBinContent(dybin)<<" over "<<0.0593*0.0593*20.339<<" times "<<((fracDPS*acc_eff_shape_dps_dy->GetBinContent(dybin))+(fracNLO*acc_eff_shape_nlo_dy->GetBinContent(dybin)))<<" times "<<(dybins[dybin]-dybins[dybin-1])<<" equals??? "<<corrPopdy<<std::endl;
    xsec_dy->SetBinContent(dybin,corrPopdy*1e-6);
    xsec_sum_dy = xsec_sum_dy+(corrPopdy*1e-6*(dybins[dybin]-dybins[dybin-1]));
    xsec_dy->SetBinError(dybin, xsec_dy->GetBinContent(dybin)/sqrt(dy_data->GetBinContent(dybin)));
  }
  for(int ybin=1; ybin<=nybins; ++ybin){
    corrPopy = y_data->GetBinContent(ybin)/(pow(0.0593,2)*20.339*(fracDPS*acc_eff_shape_dps_y->GetBinContent(ybin)+fracNLO*acc_eff_shape_nlo_y->GetBinContent(ybin))*(ybins[ybin]-ybins[ybin-1]));
    //          std::cout<<dy_data->GetBinContent(dybin)<<" over "<<0.0593*0.0593*20.339<<" times "<<((fracDPS*acc_eff_shape_dps_dy->GetBinContent(dybin))+(fracNLO*acc_eff_shape_nlo_dy->GetBinContent(dybin)))<<" times "<<(dybins[dybin]-dybins[dybin-1])<<" equals??? "<<corrPopdy<<std::endl;
    xsec_y->SetBinContent(ybin,corrPopy*1e-6);
    xsec_sum_y = xsec_sum_y+(corrPopy*1e-6*(ybins[ybin]-ybins[ybin-1]));
    xsec_y->SetBinError(ybin, xsec_y->GetBinContent(ybin)/sqrt(y_data->GetBinContent(ybin)));
  }
  std::cout<<"Mass Integral: "<<xsec_sum_mass<<std::endl;
  std::cout<<"pT Integral: "<<xsec_sum_pt<<std::endl;
  std::cout<<"dY Integral: "<<xsec_sum_dy<<std::endl;
  std::cout<<"Y Integral: "<<xsec_sum_y<<std::endl;
  TCanvas* disp = new TCanvas("disp","disp",900,900);
  disp->Divide(2,2);
  disp->cd(1);
  xsec_mass->SetXTitle("M_{J/#psi J/#psi} (GeV/c^{2})");
  xsec_mass->SetYTitle("d#sigma/dM_{J/#psi J/#psi} (nb/(GeV/c^{2}))");
  xsec_mass->Draw("e1");
  disp->cd(2);
  xsec_pt->SetXTitle("p_{T}^{J/#psi J/#psi} (GeV/c)");
  xsec_pt->SetYTitle("d#sigma/dp_{T}^{J/#psi J/#psi} (nb/(GeV/c))");
  xsec_pt->Draw("e1");
  disp->cd(3);
  xsec_dy->SetXTitle("|#Delta y| between J/#psi");
  xsec_dy->SetYTitle("d#sigma/d|#Delta y| (nb)");
  xsec_dy->Draw("e1");
  disp->cd(4);
  xsec_y->SetXTitle("|Rapidity|_{J/#psi J/#psi}");
  xsec_y->SetYTitle("d#sigma/d|y| (nb)");
  xsec_y->Draw("e1");
  //  dy_data.Draw("e");    
}