Пример #1
0
TGraphErrors *makesysplot(TH1F *h, float dmu, int color)
{

  auto h1 = (TH1F *)h->Clone("h1");
  auto h2 = (TH1F *)h->Clone("h2");

  //if (h->GetTitle()=="Data b-jets 12")
    h->SetTitle("Data b-jets");
  h1->SetTitle("variation up");
  h2->SetTitle("variation down");

  float mu = h->GetMean();

  int n = round(mu*10);
  float i1=h->Integral(1,n);
  float w1 = weightedsum(h,1,n);

  float t = (mu-w1)/(1-i1);
  float alpha1 = (mu-dmu-t)/(w1-t*i1)-1;
  float beta1 = (1-(1+alpha1)*i1)/(1-i1)-1;
  float alpha2 = (mu+dmu-t)/(w1-t*i1)-1;
  float beta2 = (1-(1+alpha2)*i1)/(1-i1)-1;

  auto hbar = (TH1F *)h->Clone("hbar");


  for (int i=1;i<=h->GetNbinsX();i++) {
    float p = i>n ? 1+alpha1 : 1+beta1;
    h1->SetBinContent(i,h->GetBinContent(i)*p);
    p = i>n ? 1+alpha2 : 1+beta2;
    h2->SetBinContent(i,h->GetBinContent(i)*p);
  }
  Normalize({h1,h2}); //in principle it is not needed
  for (int i=1;i<=h->GetNbinsX();i++)
    hbar->SetBinError(i,fabs(h2->GetBinContent(i)-h1->GetBinContent(i))/2);



  hbar->SetFillColor(color);
  
  plotlegendpos = TopLeft;
  // plotsecondline = Form("%.3f,%.3f",h1->GetMean()-mu,mu-h2->GetMean()); //check means
  // plotthirdline = Form("%.3f",dmu);

  TGraphErrors *sys = new TGraphErrors(hbar->GetNbinsX());
  sys->SetFillColor(color);
  for (int i=1;i<=hbar->GetNbinsX();i++) {
    sys->SetPoint(i,hbar->GetBinCenter(i),hbar->GetBinContent(i));
    sys->SetPointError(i,0.05,hbar->GetBinError(i));
  }


  //draw true value, variation1 and variation2
  plotytitle = "Event fractions";
  // Draw({h,h1,h2},{"E1","hist","hist","e1p"});


  // auto c2 = getc();
  // h->Draw("e1");
  // sys->Draw("e2");
  // h->Draw("e1,same");
  // SavePlot(c2,Form("%ssys2",h->GetName()));


  return sys;


  //draw cdf (for fun)
  // auto hint = h->GetIntegral();
  // auto h1int = h1->GetIntegral();
  // auto h2int = h2->GetIntegral();

  // vector<double> xaxis;
  // for (int i=1;i<=h->GetNbinsX()+1;i++) xaxis.push_back(h->GetBinLowEdge(i));

  // auto g = new TGraph(xaxis.size()+1,&xaxis[0],hint); g->SetLineColor(kRed);
  // auto g1 = new TGraph(xaxis.size()+1,&xaxis[0],h1int); g1->SetLineColor(kGreen);
  // auto g2 = new TGraph(xaxis.size()+1,&xaxis[0],h2int); g2->SetLineColor(kBlue);

  // auto c = getc();
  // g->SetMinimum(0);g->SetMaximum(1);
  // g->Draw();
  // g1->Draw("same");
  // g2->Draw("same");

  // g->GetXaxis()->SetTitle("x_{J}");
  // g->GetXaxis()->SetTitle("prob");

  // SavePlots(c,"cum");

}
Пример #2
0
void dataDrivenFromCR(TFile* fdata, TFile* fmc, TFile* fout, TString ddtype, TString gentype) {
  // Additional hists to consider: dataStats, MCstats, impurity

  TList* listOfDirs = fmc->GetListOfKeys();
  for (auto k : *listOfDirs) {
    TString srname = k->GetName();
    if (!srname.Contains("sr")) continue;
    if (srname.Contains("base") || srname.Contains("incl") || srname.Contains("sb")) continue;
    if (ddtype == "cr0b" && (srname.EndsWith("2") || srname.EndsWith("3"))) continue;

    TString crname = srname;
    crname.ReplaceAll("sr", ddtype);

    TString hname_data_CR = crname + "/h_metbins";
    TString hname_MC_SR = srname + "/h_metbins" + gentype;
    TString hname_MC_CR = crname + "/h_metbins";

    auto outdir = (TDirectory*) fout->mkdir(srname);

    auto hist_data_CR = (TH1D*) fdata->Get(hname_data_CR);
    auto hist_MC_CR = (TH1D*) fmc->Get(hname_MC_CR);
    auto hist_MC_SR = (TH1D*) fmc->Get(hname_MC_SR);

    if (!fmc->Get(hname_MC_CR)) {
      cout << "Couldn't find yield hist for " << hist_MC_CR << " in " << fmc->GetName() << "!!" << endl;
      cout << "This should not happend! Can not use data driven on this region! Use MC yields directly use TF from other SR!" << endl;
      continue;  // <-- actions to be added
    }
    if (!fmc->Get(hname_MC_SR)) {
      cout << "Couldn't find yield hist for " << hist_MC_SR << " in " << fmc->GetName() << ". Cannot define TF!" << endl;
      continue;  // <-- actions to be added
    }
    if (!fdata->Get(hname_data_CR)) {
      cout << "Couldn't find yield hist for " << hist_data_CR << " in " << fdata->GetName() << ". Please use yield from MC!" << endl;
      continue;  // <-- actions to be added
    }

    int lastbin = hist_data_CR->GetNbinsX();
    int extr_start_bin = lastbin; // the bin to start extrapolation, if == lastbin means no MET extrapolation is needed

    auto combineYieldsInExtrBins = [&](TH1D* hist) {
      double err = 0;
      double ylds = hist->IntegralAndError(extr_start_bin, -1, err);
      for (int ibin = extr_start_bin; ibin <= lastbin; ++ibin) {
        hist->SetBinContent(ibin, ylds);
        hist->SetBinError(ibin, err);
      }
    };

    if (useMetExtrapolation) {
      double yldCR(0.0), err(0.0);
      for (; extr_start_bin > 1; --extr_start_bin) {
        yldCR = hist_MC_CR->IntegralAndError(extr_start_bin, -1, err);
        double TFval = hist_MC_SR->GetBinContent(extr_start_bin) / yldCR;
        if (yldCR > extr_threshold && (TFval < extr_TFcap)) break;
      }
      // if (gentype == "_2lep" && (srname == "srE2" || srname == "srG2")) extr_start_bin = lastbin; // temporary hack for 2016
      // if (gentype == "_2lep" && (srname == "srH")) extr_start_bin = 1; // temporary hack for 2016
      if (extr_start_bin != lastbin) {
        cout << "Doing MET extrapolation for  " << crname << "  from bin " << lastbin << " (last bin) to bin " << extr_start_bin << "!" << endl;
        hist_data_CR->Clone("h_datayields_CR_raw")->Write();
        combineYieldsInExtrBins(hist_data_CR);
      }
    }

    TH1D* centralHist;

    auto crdir = (TDirectoryFile*) fmc->Get(crname);
    for (auto h : *(crdir->GetListOfKeys())) {
      TString hname = h->GetName();
      if (!hname.BeginsWith("h_metbins")) continue;
      // hardcode genclass skipping for now
      if (hname.Contains("_2lep") || hname.Contains("_1lep") || hname.Contains("_Znunu") || hname.Contains("_unclass")) continue;

      TString hnameSR = hname;
      hnameSR.ReplaceAll("h_metbins", "h_metbins" + gentype);

      // Not using fraction
      auto hist_MC_CR = (TH1D*) crdir->Get(hname)->Clone(hname+"_cr");
      auto hist_MC_SR = (TH1D*) fmc->Get(srname + "/" + hnameSR);

      if (!hist_MC_SR) {
        if (!hnameSR.Contains("cr2lTriggerSF"))
          cout << "Couldn't find yield hist for " << (srname + "/" + hnameSR) << " in " << fmc->GetName() << ". Use centralHist!" << endl;
        hist_MC_SR = (TH1D*) fmc->Get(hname_MC_SR)->Clone(hnameSR);
      }

      auto alphaHist = (TH1D*) hist_MC_SR->Clone(hname+"_alpha");
      if (useMetExtrapolation && extr_start_bin != lastbin) {
        // To take the MET distribution from the CR
        double cerr_SR = 0;
        double cyld_SR = alphaHist->IntegralAndError(extr_start_bin, -1, cerr_SR);
        double cyld_CR = hist_MC_CR->Integral(extr_start_bin, -1);
        for (int ibin = extr_start_bin; ibin <= lastbin; ++ibin) {
          double metfrac = hist_MC_CR->GetBinContent(ibin) / cyld_CR;
          alphaHist->SetBinContent(ibin, metfrac * cyld_SR);
          alphaHist->SetBinError(ibin, metfrac * cerr_SR);
        }
        combineYieldsInExtrBins(hist_MC_CR);
      }
      alphaHist->Divide(hist_MC_CR);

      for (int i = 1; i <= alphaHist->GetNbinsX(); ++i) {
        // zero out negative yields
        if (alphaHist->GetBinContent(i) < 0) {
          alphaHist->SetBinContent(i, 0);
          alphaHist->SetBinError(i, 0);
        }
      }

      outdir->cd();
      TH1D* hout = (TH1D*) alphaHist->Clone(hname);
      hout->Multiply(hist_data_CR);
      hout->Write();

      if (yearSeparateSyst && (hname.EndsWith("Up") || hname.EndsWith("Dn"))) {
        for (int i = 1; i < 4; ++i) {

          auto hcen_MC_CR = (TH1D*) fbkgs[i]->Get(crname+"/h_metbins");
          auto hcen_MC_SR = (TH1D*) fbkgs[i]->Get(srname+"/h_metbins"+gentype);
          auto hsys_MC_CR = (TH1D*) fbkgs[i]->Get(crname+"/"+hname);
          auto hsys_MC_SR = (TH1D*) fbkgs[i]->Get(srname+"/"+hnameSR);

          if (!hist_MC_SR) {
            if (!hnameSR.Contains("cr2lTriggerSF"))
              cout << "Couldn't find yield hist for " << (srname + "/" + hnameSR) << " in " << fmc->GetName() << ". Use centralHist!" << endl;
            hist_MC_SR = (TH1D*) fmc->Get(hname_MC_SR)->Clone(hnameSR);
          }

          auto alphaHist_yi = (TH1D*) fmc->Get(hname_MC_SR)->Clone(TString(hname).Insert(hname.Length()-2, Form("%d", 15+i)));
          auto h_MC_CR_yi = (TH1D*) fmc->Get(hname_MC_CR)->Clone(Form("%s_den_%d", hname.Data(), 15+i));
          if (hcen_MC_SR) alphaHist_yi->Add(hcen_MC_SR, -1);
          if (hsys_MC_SR) alphaHist_yi->Add(hsys_MC_SR);
          if (hcen_MC_CR) h_MC_CR_yi->Add(hcen_MC_CR, -1);
          if (hsys_MC_CR) h_MC_CR_yi->Add(hsys_MC_CR);

          if (useMetExtrapolation && extr_start_bin != lastbin) {
            // To take the MET distribution from the CR
            double cerr_SR = 0;
            double cyld_SR = alphaHist_yi->IntegralAndError(extr_start_bin, -1, cerr_SR);
            double cyld_CR = h_MC_CR_yi->Integral(extr_start_bin, -1);
            for (int ibin = extr_start_bin; ibin <= lastbin; ++ibin) {
              double metfrac = h_MC_CR_yi->GetBinContent(ibin) / cyld_CR;
              alphaHist_yi->SetBinContent(ibin, metfrac * cyld_SR);
              alphaHist_yi->SetBinError(ibin, metfrac * cerr_SR);
            }
            combineYieldsInExtrBins(h_MC_CR_yi);
          }
          alphaHist_yi->Divide(h_MC_CR_yi);

          for (int i = 1; i <= alphaHist_yi->GetNbinsX(); ++i) {
            // zero out negative yields
            if (alphaHist_yi->GetBinContent(i) < 0) {
              alphaHist_yi->SetBinContent(i, 0);
              alphaHist_yi->SetBinError(i, 0);
            }
          }
          outdir->cd();
          alphaHist_yi->Multiply(hist_data_CR);
          alphaHist_yi->Write();
        }
      }

      if (hname.EndsWith("h_metbins")) {
        centralHist = hout;
        // Store the central alpha hist and extr_start_bin for signal contamination
        alphaHist->Write("h_alphaHist");
        if (useMetExtrapolation && extr_start_bin < lastbin) {
          TH1D* h_extrstart = new TH1D("h_extrstart", "MET extrapolation start bin", 1, 0, 1);
          h_extrstart->SetBinContent(1, extr_start_bin);
          h_extrstart->Write();
        }
        if (doCRPurityError) {
          auto hist_MC_CR_pure = (TH1D*) fmc->Get(hname_MC_CR + gentype);
          auto hout_purityUp = (TH1D*) hout->Clone(hname+"_CRpurityUp");
          auto hout_purityDn = (TH1D*) hout->Clone(hname+"_CRpurityDn");
          if (useMetExtrapolation && extr_start_bin < lastbin)
            combineYieldsInExtrBins(hist_MC_CR_pure);
          for (int ibin = 1; ibin <= lastbin; ++ibin) {
            double crpurityerr = 0.5 * (hist_MC_CR->GetBinContent(ibin) - hist_MC_CR_pure->GetBinContent(ibin)) / hist_MC_CR->GetBinContent(ibin);
            hout_purityUp->SetBinContent(ibin, hout->GetBinContent(ibin) / ( 1 - crpurityerr));
            hout_purityDn->SetBinContent(ibin, hout->GetBinContent(ibin) / ( 1 + crpurityerr));
          }
          hout_purityUp->Write();
          hout_purityDn->Write();

          auto purityHist = (TH1D*) hist_MC_CR_pure->Clone("h_CRpurity");
          purityHist->Divide(hist_MC_CR_pure, hist_MC_CR, 1, 1, "B");
          purityHist->Write();
        }
      }
    }

    // Create alphaHist for dataStats
    auto h_dataStats = (TH1D*) centralHist->Clone("h_metbins_dataStats");
    auto h_MCStats = (TH1D*) centralHist->Clone("h_metbins_MCStats");
    for (int ibin = 1; ibin <= extr_start_bin; ++ibin) {
      // If not doing met extrapolation, extr_start_bin will equal to lastbin
      double data_error_thisbin = (hist_data_CR->GetBinContent(ibin) < 0.01)? 0 : hist_data_CR->GetBinError(ibin) / hist_data_CR->GetBinContent(ibin);
      h_dataStats->SetBinError(ibin, data_error_thisbin * h_dataStats->GetBinContent(ibin));

      double MC_SR_error_thisbin = (hist_MC_SR->GetBinContent(ibin) < 1e-5)? 0 : hist_MC_SR->GetBinError(ibin) / hist_MC_SR->GetBinContent(ibin);
      double MC_CR_error_thisbin = (hist_MC_CR->GetBinContent(ibin) < 1e-5)? 0 : hist_MC_CR->GetBinError(ibin) / hist_MC_CR->GetBinContent(ibin);
      double MC_error_thisbin = sqrt(MC_SR_error_thisbin*MC_SR_error_thisbin + MC_CR_error_thisbin*MC_CR_error_thisbin);

      h_MCStats->SetBinError(ibin, MC_error_thisbin * h_MCStats->GetBinContent(ibin));
    }
    for (int ibin = extr_start_bin+1; ibin <= lastbin; ++ibin) {
      // If doing met extrapolation, the bins following extr_start_bin for data and MC CR will be set to have 0 stat error
      // TODO: verify that this is the right thing to do
      h_dataStats->SetBinError(ibin, 0);
      double MC_SR_error_thisbin = (hist_MC_SR->GetBinContent(ibin) < 1e-5)? 0 : hist_MC_SR->GetBinError(ibin) / hist_MC_SR->GetBinContent(ibin);
      h_MCStats->SetBinError(ibin, MC_SR_error_thisbin * h_MCStats->GetBinContent(ibin));
    }

    h_dataStats->Write();
    h_MCStats->Write();

    hist_data_CR->Clone("h_datayields_CR")->Write();
    hist_MC_CR->Clone("h_MCyields_CR")->Write();
    hist_MC_SR->Clone("h_MCyields_SR")->Write();
  }
}
Пример #3
0
void checkclosure()
{
  vector<TH1F *>hsig(Nbins);
  vector<TH1F *>hasd(Nbins);
  vector<TH1F *>hbkg(Nbins);
  vector<TH1F *>hsub(Nbins);
  vector<TH1F *>hhyj(Nbins);
  vector<TH1F *>hshj(Nbins);
  vector<TH1F *>hsbn(Nbins);


  for (int i=0;i<Nbins;i++) {
    seth(10,0,1);
    hsig[i] = geth(Form("hsig%d",i),Form("Signal away-side %s;x_{J}",binnames[i].Data())) ;
    hasd[i] = geth(Form("hasd%d",i),Form("Measured away-side %s;x_{J}",binnames[i].Data()));
    hbkg[i] = geth(Form("hbkg%d",i),Form("Near-side %s;x_{J}",binnames[i].Data()));
    hhyj[i] = geth(Form("hhyj%d",i),Form("Near-side hydjet %s;x_{J}",binnames[i].Data()));
    hsub[i] = geth(Form("hsub%d",i),Form("Subtracted NS %s;x_{J}",binnames[i].Data()));
    hshj[i] = geth(Form("hshj%d",i),Form("Subtracted Hydjet %s;x_{J}",binnames[i].Data()));
    hsbn[i] = geth(Form("hsbn%d",i),Form("Subtracted Naive %s;x_{J}",binnames[i].Data()));
  }




  auto fmcPb = config.getfile_djt("mcPbbfa");

  Fill(fmcPb,{"pthat","weight","jtpt1","refpt1","bProdCode","jtptSL","refptSL","dphiSL1","refparton_flavorForB1","subidSL","bin","pairCodeSL1","discr_csvV1_1","jteta1","jtetaSL"},[&] (dict d) {
      if (d["pthat"]<pthatcut) return;
      
      if (d["jtpt1"]>pt1cut && d["refpt1"]>50 && abs(d["refparton_flavorForB1"])==5 && d["jtptSL"]>pt2cut) {
        int bin = getbinindex(d["bin"]);
        
        float xj = d["jtptSL"]/d["jtpt1"];
        float w = weight1SLPbPb(d);
        if (AwaySide(d)) hasd[bin]->Fill(xj, w);
        if (AwaySide(d) && IsSignal(d)) hsig[bin]->Fill(xj,w);

        if (NearSide(d)) hbkg[bin]->Fill(xj,w);
        if (NearSide(d) && !IsSignal(d)) hhyj[bin]->Fill(xj,w);
      }
        



      });



  for (int i=0;i<Nbins;i++) {
    hsub[i]->Add(hasd[i],hbkg[i],1,-1*bkgfractionInNearSide[i]);
    hsbn[i]->Add(hasd[i],hbkg[i],1,-1);
    hshj[i]->Add(hasd[i],hhyj[i],1,-1);
  }
//  for (int i=0;i<Nbins;i++) 
//    hincsub[i]->Add(hincasd[i],hincbkg[i],1,-1);

  seth(bins);//Nbins,0,100);
  auto hcentrSubSIG = geth("hcentrSubSIG","Signal;bin;#LTx_{J}#GT");
  auto hcentrSubASD = geth("hcentrSubASD","Unsubtracted;bin;#LTx_{J}#GT");

  auto hcentrSubBKS = geth("hcentrSubBKS","Subtracted w/o bkg scaling;bin;#LTx_{J}#GT");
  auto hcentrSubCLS = geth("hcentrSubCLS","Subtracted with bkg scaling;bin;#LTx_{J}#GT");
  auto hcentrSubHJS = geth("hcentrSubHJS","Subtracted Hydjet;bin;#LTx_{J}#GT");


  plotlegendpos = BottomRight;


  for (int i=0;i<Nbins;i++) {
    hcentrSubSIG->SetBinContent(i+1,hsig[i]->GetMean());hcentrSubSIG->SetBinError(i+1,hsig[i]->GetMeanError());
    hcentrSubASD->SetBinContent(i+1,hasd[i]->GetMean());hcentrSubASD->SetBinError(i+1,hasd[i]->GetMeanError());
    hcentrSubBKS->SetBinContent(i+1,hsbn[i]->GetMean());hcentrSubBKS->SetBinError(i+1,hsbn[i]->GetMeanError());

    hcentrSubCLS->SetBinContent(i+1,hsub[i]->GetMean());hcentrSubCLS->SetBinError(i+1,hsub[i]->GetMeanError());
    hcentrSubHJS->SetBinContent(i+1,hshj[i]->GetMean());hcentrSubHJS->SetBinError(i+1,hshj[i]->GetMeanError());

    Draw({hsig[i],hsub[i],hshj[i]});
  }


  plotymin = 0.55;//0.4;
  plotymax = 0.7;//0.8;
  plotlegendpos = BottomRight;
  aktstring = "";


  plotputmean = false;
  //hcentrSubHJS - hydjet only subtraction
  // SetMC({hcentrSubSIG, hcentrSubBKS, hcentrSubASD});
  // SetData({hcentrSubCLS});

  hcentrSubSIG->SetMarkerStyle(kOpenSquare);
  hcentrSubBKS->SetMarkerStyle(kOpenSquare);
  hcentrSubASD->SetMarkerStyle(kOpenSquare);
  hcentrSubCLS->SetMarkerStyle(kFullCircle);


  hcentrSubSIG->SetMarkerColor(TColor::GetColorDark(2)); hcentrSubSIG->SetLineColor(TColor::GetColorDark(2));
  hcentrSubBKS->SetMarkerColor(TColor::GetColorDark(3)); hcentrSubBKS->SetLineColor(TColor::GetColorDark(3));
  hcentrSubASD->SetMarkerColor(TColor::GetColorDark(4)); hcentrSubASD->SetLineColor(TColor::GetColorDark(4));
  hcentrSubCLS->SetMarkerColor(TColor::GetColorDark(3)); hcentrSubCLS->SetLineColor(TColor::GetColorDark(3));

  plotoverwritecolors = false;
  plotlegenddx = -0.15;

  Draw({hcentrSubSIG,hcentrSubASD, hcentrSubBKS, hcentrSubCLS});


  auto syst = (TH1F *)hcentrSubSIG->Clone("syst");
  syst->Add(hcentrSubCLS,-1);
  map<TString,float> m;
  for (unsigned i=0;i<bins.size()-1;i++) {
    float misclosure = syst->GetBinContent(i+1);
    float err = hcentrSubCLS->GetBinError(i+1);
    m[Form("closure%d%d",(int)bins[i],(int)bins[i+1])]=sqrt(misclosure*misclosure+err*err);
  }

  WriteToFile(plotfoldername+"/hydjetclosuresyst.root",m);


}
Пример #4
0
void derivefromNS(bool data = false)
{
  // float shift = mode == 2 ? -2 : mode*2; //mode = 0,1,2 shift = 0,2,-2
  // cout<<"shift = "<<shift<<endl;

  auto file = config.getfile_djt(data ? "dtPbjcl" : "mcPbqcd");
  auto nt = (TTree *)file->Get("nt");

  for (unsigned i=1;i<binbounds.size();i++) {
    int b1 = binbounds[i-1];
    int b2 = binbounds[i];
    seth(71,38,180); //71,38
    auto h = geth(Form("h%d%d",b1,b2)); //allowing one more bin for overflow
    seth(b2-b1,b1,b2);
    auto hb = geth(Form("hb%d%d",b1,b2));

   
    TString mcappendix = data ? "" : "&& pthat>50";//"&& subid2!=0 && pthat>50"; //"&& pthat>50";//"&& !(subid2==0 && refpt2>20) && pthat>50"; //"&& pthat>80";//
   
    //Form("jtpt2+%f",shift)
    nt->Project(h->GetName(),"jtpt2", Form("weight*(jtpt1>100&&bin>=%d && bin<%d && dphi21<1.05 %s)",b1,b2,mcappendix.Data()));
    nt->Project(hb->GetName(),"bin", Form("weight*(jtpt1>100&&bin>=%d && bin<%d && dphi21<1.05 %s)",b1,b2,mcappendix.Data()));

    ScaleVisibleBins(h,NSfrac[i-1]);

    h->SetBinContent(1,h->GetBinContent(0)+h->GetBinContent(1));

    // auto p = new TProfile(Form("p%d%d",b1,b2),Form("prof"),71,38,180);
    // nt->Project(p->GetName(),"(subid2 == 0 && refpt2 > 20):jtptSignal2",Form("weight*(jtpt1>100&&bin>=%d && bin<%d && dphiSignal21<1.05 && !(subid2==0 && refpt2>20) && pthat>80)",b1,b2));


    auto g = getCDFgraph(h);
    g->GetXaxis()->SetTitle("p_{T,2} threshold [GeV]");
    g->GetYaxis()->SetTitle("found fraction");

    auto gtemp = getCDFgraph(h);
    meanb.push_back(hb->GetMean());
    prob.push_back(gtemp->Eval(pt));

    float c0=g->Eval(50);
    cout<<"prob at 50: "<<c0<<endl;

    auto gf = new TFile("graph.root","recreate");
    gtemp->Write();
    gf->Close();

    // auto f = new TF1(Form("f%d%d",b1,b2),"1-[0]*exp(-[1]*(x-40))",40,180);
    // f->SetParameters(0.1,0.1);
    // // f->FixParameter(1,0.08);

    // auto f = new TF1(Form("f%d%d",b1,b2),"TMath::Erf((x-[0])/[1])",40,180);
    // f->SetParameters(40,10);
    // f->FixParameter(1,25);

    auto f = new TF1(Form("f%d%d",b1,b2),"exp(-[0]*exp(-[1]*x))",40,180);
    f->SetParameters(100,0.1);
    // f->FixParameter(1,0.11); //!!!!!!!!!!

    f->SetLineColor(kRed);
    f->SetLineWidth(2);
    g->Fit(f,"RM");
    fs.push_back(f);
    binmean.push_back(hb->GetMean());

    float median = -1/f->GetParameter(1)*log(-1/f->GetParameter(0)*log(0.5));

    Draw({h});

    // h->Rebin(2);
    auto gcoarse = getCDFgraph(h);

    auto c = getc();
          TLatex *Tl = new TLatex();
    gcoarse->SetMinimum(0);g->SetMaximum(1);
    gcoarse->Draw("AP");
    f->Draw("same");
    Tl->DrawLatexNDC(0.6,0.55,"y=e^{-a e^{-b x} }");
    Tl->DrawLatexNDC(0.6,0.50,Form("a = %.1f",f->GetParameter(0)));
    Tl->DrawLatexNDC(0.6,0.45,Form("b = %.2f",f->GetParameter(1)));
    Tl->DrawLatexNDC(0.6,0.4,Form("PbPb bin %d-%d",b1,b2));
    Tl->DrawLatexNDC(0.6,0.35,Form("median = %.2f",median));

    TLine *l1 = new TLine(median,0,median, f->Eval(median));
    l1->Draw();
    TLine *l2 = new TLine(0,0.5,median, f->Eval(median));
    l2->Draw();

    // p->SetMarkerColor(kRed);
    // p->SetMarkerSize(1);
    // p->Draw("same");
    SavePlot(c,Form("fit%d%d",b1,b2));//return;
  }

}