Exemple #1
0
void graph() {
   //Draw a simple graph
   // To see the output of this macro, click begin_html <a href="gif/graph.gif">here</a>. end_html
   //Author: Rene Brun
   
   TCanvas *c1 = new TCanvas("c1","A Simple Graph Example",200,10,700,500);

   c1->SetFillColor(42);
   c1->SetGrid();

   const Int_t n = 20;
   Double_t x[n], y[n];
   for (Int_t i=0;i<n;i++) {
     x[i] = i*0.1;
     y[i] = 10*sin(x[i]+0.2);
     printf(" i %i %f %f \n",i,x[i],y[i]);
   }
   auto gr = new TGraph(n,x,y);
   gr->SetLineColor(2);
   gr->SetLineWidth(4);
   gr->SetMarkerColor(4);
   gr->SetMarkerStyle(21);
   gr->SetTitle("a simple graph");
   gr->GetXaxis()->SetTitle("X title");
   gr->GetYaxis()->SetTitle("Y title");
   gr->Draw("ACP");

   // TCanvas::Update() draws the frame, after which one can change it
   c1->Update();
   c1->GetFrame()->SetFillColor(21);
   c1->GetFrame()->SetBorderSize(12);
   c1->Modified();
}
void CreateOutput(const std::vector<double>& x_list, const std::vector<double>& y_list,
                  const std::vector<double>& z_list, std::shared_ptr<TFile> output_file, const std::string& name,
                  const std::shared_ptr<TH2F> ref_hist, double excl_threshold = -std::numeric_limits<double>::infinity(),
                  double graph_factor = 1, double graph_max = std::numeric_limits<double>::infinity(),
                  bool interpolate = false)
{
    std::ostringstream ss_name;
    ss_name << name << "_hist";
    auto hist = CreateTH2D(ss_name.str(), ref_hist);
    ss_name << "_excl";
    auto hist_excl = CreateTH2D(ss_name.str(), ref_hist);

    if(interpolate) {
        auto ref_graph = CreateTGraph2D("ref_tmp", x_list, y_list, z_list);
        for(Int_t x_id = 1; x_id <= hist->GetXaxis()->GetNbins(); ++x_id) {
            const double x = hist->GetXaxis()->GetBinCenter(x_id);
            for(Int_t y_id = 1; y_id <= hist->GetYaxis()->GetNbins(); ++y_id) {
                const double y = hist->GetYaxis()->GetBinCenter(y_id);
                const double z = ref_graph->Interpolate(x, y);
                hist->SetBinContent(x_id, y_id, z);
                if(z < excl_threshold)
                    hist_excl->SetBinContent(x_id, y_id, 1.0);
            }
        }
    } else {
        for(size_t n = 0; n < z_list.size(); ++n) {
            const Int_t bin_id = hist->FindBin(x_list.at(n), y_list.at(n));
            const double z =  z_list.at(n);
            hist->SetBinContent(bin_id, z);
            if(z < excl_threshold)
                hist_excl->SetBinContent(bin_id, 1.0);
        }
    }

    std::vector<double> z_list_graph(z_list.size());
    for(size_t n = 0; n < z_list.size(); ++n)
        z_list_graph.at(n) = std::min(graph_max, z_list.at(n) * graph_factor);
    auto graph = CreateTGraph2D(name, x_list, y_list, z_list_graph);

    output_file->WriteTObject(graph.get(), nullptr, "Overwrite");
    output_file->WriteTObject(hist.get(), nullptr, "Overwrite");
    output_file->WriteTObject(hist_excl.get(), nullptr, "Overwrite");
}
 virtual Model::PointDescriptorCollection CollectAvailablePoints() const override
 {
     Model::PointDescriptorCollection points;
     const auto ref_hist = *all_hists.begin();
     for(Int_t x_id = 1; x_id <= ref_hist->GetXaxis()->GetNbins(); ++x_id) {
         const double x = ref_hist->GetXaxis()->GetBinCenter(x_id);
         for(Int_t y_id = 1; y_id <= ref_hist->GetYaxis()->GetNbins(); ++y_id) {
             const double y = ref_hist->GetYaxis()->GetBinCenter(y_id);
             Model::PointDescriptor desc;
             desc.point = Model::Point({x, y});
             for(const auto& entry : masses)
                 desc.masses[entry.first] = entry.second->GetBinContent(x_id, y_id);
             for(const auto& entry : cross_sections)
                 desc.cross_sections[entry.first] = entry.second->GetBinContent(x_id, y_id);
             for(const auto& entry : branching_ratios)
                 desc.branching_ratios[entry.first] = entry.second->GetBinContent(x_id, y_id);
             points.push_back(desc);
         }
     }
     return points;
 }
Exemple #4
0
void ratioplot2() {
   gStyle->SetOptStat(0);
   auto c1 = new TCanvas("c1", "fit residual simple");
   auto h1 = new TH1D("h1", "h1", 50, -5, 5);
   h1->FillRandom("gaus", 2000);
   h1->Fit("gaus");
   h1->GetXaxis()->SetTitle("x");
   c1->Clear(); // Fit does not draw into correct pad
   auto rp1 = new TRatioPlot(h1);
   rp1->Draw();
   rp1->GetLowerRefYaxis()->SetTitle("ratio");
   rp1->GetUpperRefYaxis()->SetTitle("entries");
   c1->Update();
}
Exemple #5
0
//______________________________________________________________________________
void ROMETGraphErrors::SetLimits()
{
    Double_t rwxmin,rwxmax, rwymin, rwymax, dx, dy;
    ComputeRange(rwxmin, rwymin, rwxmax, rwymax);

    if (rwxmin == rwxmax) rwxmax += 1.;
    if (rwymin == rwymax) rwymax += 1.;
    dx = 0.1 * (rwxmax - rwxmin);
    dy = 0.1 * (rwymax - rwymin);
    fMinimum = rwymin - dy;
    fMaximum = rwymax + dy;
    TAxis *axis = GetXaxis();

    if(axis) {
        axis->SetLimits(rwxmin - dx, rwxmax + dx);
    }
}
    //study_string_low = "Razor #gamma#gamma + #geq 1 jet: Signal Injection Study";

    //study_string_low = "Razor #gamma#gamma + #geq 1 jet: Low R^{2} Fit ff Sample";
    //study_string_high = "Razor #gamma#gamma + #geq 1 jet: High R^{2} ff Sample";
    study_string_low = "Razor #gamma#gamma + #geq 1 jet: Low R^{2} Fit #gamma#gamma Sample";
    study_string_high = "Razor #gamma#gamma + #geq 1 jet: High R^{2} #gamma#gamma Sample";
    gStyle->SetOptStat(0);

    file = TFile("weight_hist.root","READ");

    mr = hist_high_data;
    //  mr->SetTitle("Data In High R^{2}");
    mr_toy = hist_high_pred;
    mr_toy->SetTitle("Estimation In High R^{2}");

    Float_t xmin = mr_toy->GetXaxis()->GetXmin();
    Float_t xmax = mr_toy->GetXaxis()->GetXmax();

    //build the canvas
    TCanvas *high_canvas = new TCanvas("c2","high canvas",1024,768);
    TPad *high_plot = new TPad("pad3","pad3",0,0.4,1,1);

    high_plot->SetTopMargin(.2);
    high_plot->SetBottomMargin(0);
    high_plot->Draw();
    high_plot->cd();

    high_plot->SetLogy();

    mr->SetLineColor(kBlack);
    mr->SetMarkerSize(1.2);
Exemple #7
0
  // h1.SetFillStyle(3005);


    
  h1.SetTitle("");
  h1.SetXTitle("NJets");
  h2.SetLineColor(kRed);
  // h1.SetFillColor(kRed);
  // h1.SetFillStyle(3005);
    
  //  h2.SetLineColor(kBlue);
  // h2.SetFillColor(kBlue);
  //h2.SetFillStyle(3005);
    
    
  TAxis* xax = h1.GetXaxis();
  TAxis* yax = h1.GetYaxis();
  xax->SetTitleSize(0.045);
  xax->SetTitleOffset(1.);

  //6519.8    
double scale1 =   6519.8/h1.Integral();
double scale2 =  6519.8/h2.Integral();

 h1.Scale(scale1);
 h2.Scale(scale2);


  h1.Draw("HIST");
  h2.Draw("HISTsame");
Exemple #8
0
void findfunc()
{

  //dijet case
  // auto fmcppbjt = config.getfile_djt("mcppbfa");
  // auto nt = (TTree *)fmcppbjt->Get("nt");
  // seth(18,40,220);
  // auto hd = geth("hd");
  // auto hn = geth("hn");
  // nt->Project("hd","jtpt2","weight*(pthat>80 && jtpt1>100 && abs(refparton_flavorForB1)==5 && abs(refparton_flavorForB2)!=5 && dphi21>2.1)");
  // nt->Project("hn","jtpt2","weight*(pthat>80 && jtpt1>100 && abs(refparton_flavorForB1)==5 && abs(refparton_flavorForB2)!=5 && dphi21>2.1 && discr_csvV1_2>0.9)");
  // hn->Divide(hn,hd,1,1,"B")
  // hn->Fit(f)
  

  auto fpp = new TF1("fpp","expo",40,200);
  auto f1 = new TF1("fPb1","expo",40,200);
  auto f2 = new TF1("fPb2","expo",40,200);
  auto f3 = new TF1("fPb3","expo",40,200);
  seth(18,40,200);


  auto ntpp = (TTree *)config.getfile_inc("mcppqcd")->Get("nt");

  auto hd = geth("hd");
  auto hn = geth("hn",";p_{T} [GeV];mistag probability");
  ntpp->Project("hd","jtpt","weight*(pthat>50 && refpt>20 && abs(refparton_flavorForB)!=5)");
  ntpp->Project("hn","jtpt","weight*(pthat>50 && refpt>20 && abs(refparton_flavorForB)!=5 && discr_csvV1>0.9)");
  hn->Divide(hn,hd,1,1,"B");
  // hn->Scale(1/hn->Integral());
  hn->Fit(fpp);

  auto nt = (TTree *)config.getfile_inc("mcPbqcd")->Get("nt");

  auto hd1 = geth("hd1");
  auto hn1 = geth("hn1",";p_{T} [GeV];mistag probability");
  nt->Project("hd1","jtpt","weight*(pthat>50 && refpt>20 && bin < 20 && abs(refparton_flavorForB)!=5)");
  nt->Project("hn1","jtpt","weight*(pthat>50 && refpt>20 && bin < 20 && abs(refparton_flavorForB)!=5 && discr_csvV1>0.9)");
  hn1->Divide(hn1,hd1,1,1,"B");
  // hn1->Scale(1/hn1->Integral());
  hn1->Fit(f1);

  auto hd2 = geth("hd2");
  auto hn2 = geth("hn2",";p_{T} [GeV];mistag probability");
  nt->Project("hd2","jtpt","weight*(pthat>50 && refpt>20 && bin>=20 && bin<60 && abs(refparton_flavorForB)!=5)");
  nt->Project("hn2","jtpt","weight*(pthat>50 && refpt>20 && bin>=20 && bin<60 && abs(refparton_flavorForB)!=5 && discr_csvV1>0.9)");
  hn2->Divide(hn2,hd2,1,1,"B");
  // hn2->Scale(1/hn2->Integral());
  hn2->Fit(f2);

  auto hd3 = geth("hd3");
  auto hn3 = geth("hn3",";p_{T} [GeV];mistag probability");
  nt->Project("hd3","jtpt","weight*(pthat>50 && refpt>20 && bin>=60 && abs(refparton_flavorForB)!=5)");
  nt->Project("hn3","jtpt","weight*(pthat>50 && refpt>20 && bin>=60 && abs(refparton_flavorForB)!=5 && discr_csvV1>0.9)");
  hn3->Divide(hn3,hd3,1,1,"B");
  // hn3->Scale(1/hn3->Integral());
  hn3->Fit(f3);


  // because of backward imcompatibility with root version on polui

  cout<<"auto fpp = new TF1(\"fpp\",\"expo\","<<fpp->GetXmin()<<","<<fpp->GetXmax()<<");"<<endl;
  cout<<"auto fPb1 = new TF1(\"fPb1\",\"expo\","<<f1->GetXmin()<<","<<f1->GetXmax()<<");"<<endl;
  cout<<"auto fPb2 = new TF1(\"fPb2\",\"expo\","<<f2->GetXmin()<<","<<f2->GetXmax()<<");"<<endl;
  cout<<"auto fPb3 = new TF1(\"fPb3\",\"expo\","<<f3->GetXmin()<<","<<f3->GetXmax()<<");"<<endl;


  cout<<"fpp->SetParameters("<<fpp->GetParameter(0)<<","<<fpp->GetParameter(1)<<");"<<endl;
  cout<<"fPb1->SetParameters("<<f1->GetParameter(0)<<","<<f1->GetParameter(1)<<");"<<endl;
  cout<<"fPb2->SetParameters("<<f2->GetParameter(0)<<","<<f2->GetParameter(1)<<");"<<endl;
  cout<<"fPb3->SetParameters("<<f3->GetParameter(0)<<","<<f3->GetParameter(1)<<");"<<endl;

  // hn->SetMinimum(0);
  // hn1->SetMinimum(0);
  // hn2->SetMinimum(0);
  // hn3->SetMinimum(0);


  auto fout = new TFile("../correctionfiles/BXmistagfunc.root","recreate");
  fout->cd();
  fpp->Write();
  f1->Write();
  f2->Write();
  f3->Write();
  hn->Write();
  hn1->Write();
  hn2->Write();
  hn3->Write();



  auto c = getc();
  f1->SetLineColor(kRed);
  f2->SetLineColor(kGreen);
  f3->SetLineColor(kOrange);
  fpp->SetLineColor(kBlue);

  auto l = getLegend();
  l->AddEntry(fpp,"pp","L");
  l->AddEntry(f1,"bin<20","L");
  l->AddEntry(f2,"20<bin<60","L");
  l->AddEntry(f3,"bin>60","L");

  f1->GetXaxis()->SetTitle("p_{T} [GeV]");
  f1->GetYaxis()->SetTitle("mistag probability");


  f1->Draw();
  f2->Draw("same");
  f3->Draw("same");
  fpp->Draw("same");

  l->Draw();

  SavePlot(c,"func");

  float x = 0.55;
  float y = 0.75;

  auto t= new TLatex();

  auto cpp = getc();
  hn->Draw();
  fpp->Draw("same");
  t->DrawLatexNDC(x,y,"pp");
  SavePlot(cpp,"pp");


  auto c1 = getc();
  hn1->Draw();
  f1->Draw("same");
  t->DrawLatexNDC(x,y,"PbPb 0-10%");
  SavePlot(c1,"bin_0_20");

  auto c2 = getc();
  hn2->Draw();
  f2->Draw("same");
  t->DrawLatexNDC(x,y,"PbPb 10-30%");
  SavePlot(c2,"bin_20_60");

  auto c3 = getc();
  hn3->Draw();
  f3->Draw("same");
  t->DrawLatexNDC(x,y,"PbPb 30-100%");
  SavePlot(c3,"bin_60");


  fout->Close();

}
Exemple #9
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;
  }

}
Exemple #10
0
gStyle->SetOptTitle(0);

int i;

// overlay of cocktail

file_exodus_new->cd();
TH1D *ratio;
ratio = (TH1D*)pte->Clone();
ratio->Scale(0.75);
file_exodus_old->cd();
ratio->Divide(pte);

TAxis *yaxis=ratio->GetYaxis();
yaxis->SetTitle("ratio of trigger biased cocktail: new/old");
TAxis *xaxis=ratio->GetXaxis();
xaxis->SetTitle("p_{T} [GeV/c]");
ratio->SetTitleOffset(1.5,"Y");
ratio->SetMinimum(0.0);
ratio->SetMaximum(1.2);
ratio->Draw("");
ratio->Fit("pol0","R","",0.4,5.);

return;

}