Пример #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();
}
Пример #2
0
void MuReco( )
{
  TCut CPdg    = "_tracks_Pdg==13||_tracks_Pdg==211"; 

  TFile   *inFileMC;
  //gStyle->SetOptStat(0);  
  inFileMC = new TFile("ERAnaOneToOneMuReco.root");
  inFileMC->cd();
  TTree* _algoMuMC_tree = (TTree*)(inFileMC->Get("_ana1to1_tree"));


  TCanvas *C1     = new TCanvas("C1","C1",600,600);
  C1->cd();
  
  auto cut2 = new TH1D("cut2","Muon deposited Energy;  E_{#mu} [MeV];Count",20,0,800);
  _algoMuMC_tree->Draw("_tracks_DepEnFromLength>>cut2",CPdg,"");
  cut2->SetLineWidth(3);
  cut2->SetLineColor(kRed);
  cut2->GetYaxis()->SetTitleOffset(1.5);

  C1->SaveAs("MuRecoEn.png");  
  //  TFile   *inFileReco;
  //  inFileReco = new TFile("ERAnaOneToOneMuMC.root");
  //  inFileReco->cd();
  //  TTree* _algoMuReco_tree = (TTree*)(inFileReco->Get("_ProtonSel_tree"));
}
Пример #3
0
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");
}
Пример #4
0
void macro6(){

    auto sig_h=new TH1F("sig_h","Signal Histo",50,0,10);
    auto gaus_h1=new TH1F("gaus_h1","Gauss Histo 1",30,0,10);
    auto gaus_h2=new TH1F("gaus_h2","Gauss Histo 2",30,0,10);
    auto bkg_h=new TH1F("exp_h","Exponential Histo",50,0,10);

    // simulate the measurements
    TRandom3 rndgen;
    for (int imeas=0;imeas<4000;imeas++){
        bkg_h->Fill(rndgen.Exp(4));
        if (imeas%4==0) gaus_h1->Fill(rndgen.Gaus(5,2));
        if (imeas%4==0) gaus_h2->Fill(rndgen.Gaus(5,2));
        if (imeas%10==0)sig_h->Fill(rndgen.Gaus(5,.5));}

    // Format Histograms
    int i=0;
    for (auto hist : {sig_h,bkg_h,gaus_h1,gaus_h2})
        format_h(hist,1+i++);

    // Sum
    auto sum_h= new TH1F(*bkg_h);
    sum_h->Add(sig_h,1.);
    sum_h->SetTitle("Exponential + Gaussian;X variable;Y variable");
    format_h(sum_h,kBlue);

    auto c_sum= new TCanvas();
    sum_h->Draw("hist");
    bkg_h->Draw("SameHist");
    sig_h->Draw("SameHist");

    // Divide
    auto dividend=new TH1F(*gaus_h1);
    dividend->Divide(gaus_h2);

    // Graphical Maquillage
    dividend->SetTitle(";X axis;Gaus Histo 1 / Gaus Histo 2");
    format_h(dividend,kOrange);
    gaus_h1->SetTitle(";;Gaus Histo 1 and Gaus Histo 2");
    gStyle->SetOptStat(0);

    TCanvas* c_divide= new TCanvas();
    c_divide->Divide(1,2,0,0);
    c_divide->cd(1);
    c_divide->GetPad(1)->SetRightMargin(.01);
    gaus_h1->DrawNormalized("Hist");
    gaus_h2->DrawNormalized("HistSame");

    c_divide->cd(2);
    dividend->GetYaxis()->SetRangeUser(0,2.49);
    c_divide->GetPad(2)->SetGridy();
    c_divide->GetPad(2)->SetRightMargin(.01);
    dividend->Draw();
}
Пример #5
0
 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;
 }
Пример #6
0

    
  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");

}
Пример #7
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();

}
Пример #8
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;
  }

}
Пример #9
0
gStyle->SetOptStat(0);
gStyle->SetOptFit(1111);
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;

}