TGraphAsymmErrors *getEfficiencyFrom(TH1F *h)
{
  if(h==0) return 0;

  // compute efficiency: N(x>cut) / N as function of x
  // we assume overflows / underflows are included
  
  TGraphAsymmErrors *effgr = new TGraphAsymmErrors;
  effgr->SetName(h->GetName()+TString("eff"));
  effgr->SetTitle(TString("#varepsilon_{")+h->GetTitle()+TString("}"));
  effgr->SetMarkerStyle(h->GetMarkerStyle());
  effgr->SetMarkerSize(1.3);
  effgr->SetMarkerColor(h->GetLineColor());
  effgr->SetLineColor(h->GetLineColor());
  effgr->SetFillStyle(0);
  int nbins=h->GetXaxis()->GetNbins();
  Double_t tot=h->Integral();
  for(int ibin=1; ibin<=nbins; ibin++)
    {
      Double_t cut = h->GetBinLowEdge(ibin);
      Double_t err;
      Double_t tot_cut=h->IntegralAndError(ibin,nbins,err);
      effgr->SetPoint(ibin-1,cut,tot_cut/tot);
      effgr->SetPointError(ibin-1,0,0,err/tot,err/tot);
    }
  
  return effgr;
}
Example #2
0
// nameSuffix is appended to histograms name, making the graph's name
TGraphAsymmErrors* makeEffGraph (TH1F& h, TString nameSuffix = "eff")
{
  int n = 1+h.GetNbinsX();

  vector<Double_t> ps(n); // a partial sum: integral of h from -infinity to high edge of bin n, counted TH1 style
  for (int i=0; i<n; ++i) {
    ps [i] = h.GetBinContent (i) + (i>0 ? ps [i-1] : 0);
  }

  Double_t *x = new Double_t [n], *y = new Double_t [n], *exl = new Double_t [n], *exh = new Double_t [n];
  Double_t *eyl = new Double_t [n], *eyh = new Double_t [n]; // for the graph

  for (int i=0; i<n; ++i) {
    exl [i] = exh [i] = 0;
    x [i] = h.GetBinLowEdge (i+1); // low edge of nBins+1 is the right edge of h.
    Double_t eff, deff;
    calcPoisEff (ps[n-1] - ps[i], ps[i], eff, deff);
    y [i] = eff;
    makeAsymmEffErrors (eff, deff, eyl [i], eyh [i]);
  }
  TGraphAsymmErrors *gae = new TGraphAsymmErrors (n, x, y, exl, exh, eyl, eyh);
  gae->SetTitle (h.GetTitle());
  gae->GetXaxis()->SetTitle (h.GetXaxis()->GetTitle());
  gae->GetYaxis()->SetTitle ("Efficiency");
  gae->SetName (TString (h.GetName()) + nameSuffix);

  delete[] x;
  delete[] y;
  delete[] exl;
  delete[] exh;
  delete[] eyl;
  delete[] eyh;
  return gae;
}
void applyEfficiencyToTauMuons() {

    TFile* _fPtSm = new TFile("smearedMuonPtFromTau.07.09.2013.root","read");
    TFile* _fEff = new TFile("mcWEffForTauMuonStudy_07_08_2013.root","read");
    TFile* _fPtSmEff = new TFile("smearedEffAppliedMuonPtFromTau.root","recreate");

    _fPtSm->cd();
    TH1F* hPtSm = (TH1F*)_fPtSm->Get("hSmearedMuonPt");
    _fEff->cd();
    TGraphAsymmErrors* grEff = (TGraphAsymmErrors*)_fEff->Get("pEffWAccCuts");

    double* yEff = grEff->GetY();
    TH1F*  hnew = (TH1F*)hPtSm->Clone("hnew");
    ///Apply efficiency bin by bin
    for(int igr=0; igr<grEff->GetN(); ++igr) {

        double ptNominal = hPtSm->GetBinContent(igr+1);
        std::cout << "pt nominal " << ptNominal << " eff " << yEff[igr] << " = " << yEff[igr]*ptNominal << std::endl;
        hnew->SetBinContent(igr+1,yEff[igr]*ptNominal);
    }

    _fPtSmEff->cd();
    hnew->Write();
    _fPtSmEff->Write();
    _fPtSmEff->Close();
}
Example #4
0
void
printVectorsToFile(wGraph_t *wg) // , const string& filename)
{
  if (wg->gr->InheritsFrom("TGraphAsymmErrors")) {
    TGraphAsymmErrors *agr = (TGraphAsymmErrors *)wg->gr;
    cout<<"lox\tctrx\thix\tloy\tctry\thiy\tex\tey"<<endl;
    for (int i=0; i<agr->GetN(); i++) {
      double x,y, ex, ey, lox,hix,loy,hiy;
      agr->GetPoint(i,x,y);
      ex = agr->GetErrorX(i);
      ey = agr->GetErrorY(i);
      lox = x-ex; hix = x+ex;
      loy = y-ey; hiy = y+ey;
      cout <<lox<<"\t"<<x<<"\t"<<hix<<"\t";
      cout <<loy<<"\t"<<y<<"\t"<<hiy<<"\t"<<ex<<"\t"<<ey<<endl;
    }
  } else {
    cout<<"x\ty\t"<<endl;
    for (int i=0; i<wg->gr->GetN(); i++) {
      double x,y;
      wg->gr->GetPoint(i,x,y);
      cout<<x<<"\t"<<y<<endl;
    }
  }
}                                                  // printVectorsToFile
//*************************************************************************************************
//
//*************************************************************************************************
TGraphAsymmErrors* MakeCurrentWPSigEffVsBkgEffGraph(Double_t signalEff, Double_t bkgEff, string name ) {
  //Make Met Plots
  double SigEff[1];
  double BkgEff[1];
  double SigEffErrLow[1];
  double SigEffErrHigh[1];
  double BkgEffErrLow[1];
  double BkgEffErrHigh[1];
  double NSigTotal = 0;
  double NBkgTotal = 0;
  double cutValue;

  SigEff[0] = signalEff;
  SigEffErrLow[0] = 0;
  SigEffErrHigh[0] = 0;
  BkgEff[0] = bkgEff;
  BkgEffErrLow[0] = 0;
  BkgEffErrHigh[0] = 0;

  TGraphAsymmErrors *tmpSigEffVsBkgEff = new TGraphAsymmErrors (1, BkgEff, SigEff, BkgEffErrLow, BkgEffErrHigh , SigEffErrLow, SigEffErrHigh );
  tmpSigEffVsBkgEff->SetName(name.c_str());
  tmpSigEffVsBkgEff->SetTitle("");
  tmpSigEffVsBkgEff->GetXaxis()->SetTitle("Bkg Eff");
  tmpSigEffVsBkgEff->GetYaxis()->SetTitle("Signal Eff");
  tmpSigEffVsBkgEff->GetYaxis()->SetTitleOffset(1.1);
  tmpSigEffVsBkgEff->GetXaxis()->SetTitleOffset(1.05);
  tmpSigEffVsBkgEff->SetMarkerColor(kBlack);
  tmpSigEffVsBkgEff->SetLineColor(kBlack);
  tmpSigEffVsBkgEff->SetMarkerSize(1.5);

  return tmpSigEffVsBkgEff;
}
TGraphAsymmErrors* FilterBins(std::vector<int> binsToSelect, TGraphAsymmErrors* inputGR) {
 int numbin = binsToSelect.size();
 
 TString name = Form ("%s_new",inputGR->GetName());
 TString title = Form ("%s",inputGR->GetTitle());
 
 TGraphAsymmErrors* newGR = new TGraphAsymmErrors();
 newGR -> SetName (name);
 
 for (int i=0; i< binsToSelect.size(); i++) {
  
  double X = i+0.5;
  double Y = (inputGR->GetY()) [binsToSelect.at(i)-1];
  
  double errXUp      = inputGR->GetErrorXhigh(binsToSelect.at(i)-1);
  double errXDown    = inputGR->GetErrorXlow(binsToSelect.at(i)-1);
  double errYUp      = inputGR->GetErrorYhigh(binsToSelect.at(i)-1);
  double errYDown    = inputGR->GetErrorYlow(binsToSelect.at(i)-1);
  
  newGR->SetPoint(i, X, Y);
  newGR->SetPointError(i, errXDown, errXUp, errYDown, errYUp);
  
  //     std::cout << " i = " << i << " X = " << X << " Y = " << Y << std::endl;
 }
 
 return newGR;
}
TGraph* makeGraph_response_asymmetric(std::vector<histogram_vs_X_Type>& histograms_vs_X, const std::vector<double>& y_true_array)
{
  //std::cout << "<makeGraph_response_asymmetric>:" << std::endl;

  unsigned numPoints = histograms_vs_X.size();
  assert(numPoints > 0);

  TGraphAsymmErrors* graph = new TGraphAsymmErrors(numPoints);

  for ( unsigned iPoint = 0; iPoint < numPoints; ++iPoint ) {
    double x = histograms_vs_X[iPoint].x_;
    double xErrUp = histograms_vs_X[iPoint].xErrUp_;
    double xErrDown = histograms_vs_X[iPoint].xErrDown_;

    TH1* histogram = histograms_vs_X[iPoint].histogram_;

    double max, maxErrUp, maxErrDown;
    compHistogram_yMax(histogram, max, maxErrUp, maxErrDown);
    //std::cout << "histogram = " << histogram->GetName() << ": max = " << max << " + " << maxErrUp << " - " << maxErrDown << std::endl;

    double y_true = y_true_array[iPoint];
    //std::cout << " y(true) = " << y_true << std::endl;

    double y = max/y_true;
    double yErrUp = maxErrUp/y_true;
    double yErrDown = maxErrDown/y_true;

    graph->SetPoint(iPoint, x, y);
    graph->SetPointError(iPoint, xErrDown, xErrUp, yErrDown, yErrUp);
  }

  return graph;
}
Example #8
0
TGraphAsymmErrors* ROC( TH1* hSignal, TH1* hQCD){
  TGraphAsymmErrors* out = new TGraphAsymmErrors();
  int nbins = hSignal->GetNbinsX();
  double totalS = hSignal->GetEntries();
  double totalB = hQCD->GetEntries();
  cout << "=============================================================" << endl;
  cout << hSignal->GetTitle() << endl;
  cout << "totalS = " << totalS << "      totalB= " << totalB << endl;
  cout << "=============================================================" << endl;
  int bin;
  for(int i=0 ; i < 51; i++){
    bin=i+1;
//    bin=i;
    double Bi = hQCD->Integral(0,bin);
    double Si = hSignal->Integral(0,bin);
    double eff_qcd = Bi / totalB;
    double eff_signal = Si/ totalS; 
    double err_qcd = sqrt(Bi) / totalB;
    double soverb = eff_signal/sqrt(eff_signal+eff_qcd);
    cout.setf(ios::fixed);
    cout.precision(5);
    cout << "isolation value = "  << 0.01*(bin) << "      signal eff = " << eff_signal << "      background eff = " << eff_qcd << "      s/sqrt(s+b)= " << soverb << endl ;
    cout.precision();
    //out->SetPoint(i, eff_signal, 1-eff_qcd);
    out->SetPoint(i, eff_qcd, eff_signal);
    out->SetPointEXhigh(i,err_qcd);
    out->SetPointEXlow(i, err_qcd);
  }   
  return out;
}
Example #9
0
void MakeNsignalEff_pt15(){
  
  setTDRStyle();
  gStyle->SetPalette(1);

  TH1* medium = makehist("PreSelection_medium_pt15");
  TH1* tight = makehist("PreSelection_tight_pt15");
  TH1* tight_dxy10= makehist("PreSelection_iso_10_10_pt15");
  TH1* tight_anal = makehist("PreSelection_pt15");


  TLegend* legendH = new TLegend(0.6, 0.7, 0.9, 0.9);
  legendH->SetFillColor(kWhite);
  legendH->SetTextSize(0.03);


  medium->GetXaxis()->SetTitle("m_{N} GeV");
  medium->GetYaxis()->SetTitle("ID efficiency");
  
  medium->SetMarkerColor(kRed);
  tight->SetMarkerColor(kRed);
  tight_dxy10->SetMarkerColor(kRed);
  tight_anal->SetMarkerColor(kRed);
  
  medium->SetMarkerStyle(20.);
  tight->SetMarkerStyle(21.);
  tight_dxy10->SetMarkerStyle(22.);
  tight_anal->SetMarkerStyle(23.);

  legendH->AddEntry(medium, "medium ID", "p");
  legendH->AddEntry(tight, "tight ID", "p");
  legendH->AddEntry(tight_dxy10, "tight+ dxy ", "p");
  legendH->AddEntry(tight_anal, "tight+ dxy+ iso ", "p");



  medium->Draw("p");
  tight->Draw("psame");
  tight_dxy10->Draw("psame");
  tight_anal->Draw("psame");


  legendH->Draw();


  TGraphAsymmErrors * g = new TGraphAsymmErrors(heff);
  g->SetLineWidth(2.0);
  g->SetMarkerSize(2.);
  //  g->Draw( "9pXsame" );
  
  
  CMS_lumi( c1, 2, 11 );
  c1->Update();
  c1->RedrawAxis();
  
  
  c1->SaveAs(("/home/jalmond/WebPlots/PreApproval/SignalPlots/SignalEff_presel_med_tight_pt15.pdf" ));
}
void MakeNPunziLowMass_lowmasscuts(){
  
  setTDRStyle();
  gStyle->SetPalette(1);

  TH1F* tight_anal1 = makehist("PreSelection_lowmass");
  TH1F* tight_anal2 = makehist("PreSelection_lowmass2");
  TH1F* tight_anal3 = makehist("PreSelection_lowmass3");


  TLegend* legendH = new TLegend(0.6, 0.7, 0.9, 0.9);
  legendH->SetFillColor(kWhite);
  legendH->SetTextSize(0.03);

  
  tight_anal3->GetXaxis()->SetTitle("m_{N} GeV");
  tight_anal3->GetYaxis()->SetTitle("ID efficiency");
 
  tight_anal1->SetMarkerColor(kRed);
  tight_anal1->SetMarkerStyle(20.);
  tight_anal2->SetMarkerColor(kRed);
  tight_anal2->SetMarkerStyle(21.);
  tight_anal3->SetMarkerColor(kRed);
  tight_anal3->SetMarkerStyle(22.);






  legendH->AddEntry(tight_anal1, "LowMass", "p");
  legendH->AddEntry(tight_anal2, "LowMass + m(ee) < 60", "p");
  legendH->AddEntry(tight_anal3, "LowMass + m(eejj) < 155", "p");

  tight_anal3->GetYaxis()->SetRangeUser(0., 0.001);
  tight_anal3->Draw("p");
  tight_anal1->Draw("psame");
  tight_anal2->Draw("psame");


  legendH->Draw();

  TGraphAsymmErrors * g = new TGraphAsymmErrors(heff);
  g->SetLineWidth(2.0);
  g->SetMarkerSize(2.);
  //  g->Draw( "9pXsame" );
  
  
  CMS_lumi( c1, 2, 11 );
  c1->Update();
  c1->RedrawAxis();
  
  
  c1->SaveAs(("/home/jalmond/WebPlots/PreApproval/SignalPlots/Punzi_presel_lowmasscuts.pdf" ));
  return;
  
}
Example #11
0
void Histograms::MakeL1GEfficiency(TH1F * num, TH1F * denom, const char * hname) {
  // Make an efficiency graph with the "L1G" style
  TGraphAsymmErrors * eff = new TGraphAsymmErrors( num, denom);
  eff->SetMarkerStyle(24);
  eff->SetMarkerColor(kBlue);
  eff->SetMarkerSize(1.5);
  eff->SetLineColor(kBlack);
  m_efficiencies[std::string( hname )] = eff;
  
}
TGraphAsymmErrors *fromGEpGMptoQ4GEp(TGraph *ogr) {
	if (!ogr) return 0;
	TGraphAsymmErrors *ogrE = dynamic_cast<TGraphAsymmErrors*>(ogr);
	int npts = ogr->GetN();
	Double_t x,y;
	Double_t Q2;
	Double_t Gd;
	TGraphAsymmErrors *gr = new TGraphAsymmErrors(npts);
	ogr->TAttMarker::Copy(*gr);
	ogr->TAttLine::Copy(*gr);
	ogr->TAttFill::Copy(*gr);
	gr->SetName(ogr->GetName());

	for (int i=0; i<npts; i++) {
		Double_t ex1=0,ex2=0,ey1=0,ey2=0;
		ogr->GetPoint(i,x,y);
		Q2=x;
		if (ogrE) {
			ex1 = ogrE->GetErrorXlow(i);
			ex2 = ogrE->GetErrorXhigh(i);
			ey1 = ogrE->GetErrorYlow(i);
			ey2 = ogrE->GetErrorYhigh(i);
		}
		Gd = pow( 1.0 + Q2/0.71, -2.0);
		y *= pow(Q2,2.0)*Gd;
		ey1 *= pow(Q2,2.0)*Gd;
		ey2 *= pow(Q2,2.0)*Gd;
		gr->SetPoint(i,x,y);
		gr->SetPointError(i,ex1,ex2,ey1,ey2);
	}
	return gr;
}
Example #13
0
TGraphAsymmErrors *fromGEntoGEnGd(TGraph *ogr) {
// take a curve (with errors) of GEn and make it into (GEn/Gd)
  if (!ogr) return 0;
  TGraphAsymmErrors *ogrE = dynamic_cast<TGraphAsymmErrors*>(ogr);
  int npts = ogr->GetN();
  Double_t x,y;
  Double_t Q2;
  Double_t Gd;
  TGraphAsymmErrors *gr = new TGraphAsymmErrors(npts);
  ogr->TAttMarker::Copy(*gr);
  ogr->TAttLine::Copy(*gr);
  ogr->TAttFill::Copy(*gr);
  gr->SetName(ogr->GetName());

  for (int i=0; i<npts; i++) {
    Double_t ex1=0,ex2=0,ey1=0,ey2=0;
    ogr->GetPoint(i,x,y);
    Q2=x;
    if (ogrE) {
      ex1 = ogrE->GetErrorXlow(i);
      ex2 = ogrE->GetErrorXhigh(i);
      ey1 = ogrE->GetErrorYlow(i);
      ey2 = ogrE->GetErrorYhigh(i);
    }
    Gd = gdipole(&Q2,0);
    y /= Gd;
    ey1 /= Gd;
    ey2 /= Gd;
    gr->SetPoint(i,x,y);
    gr->SetPointError(i,ex1,ex2,ey1,ey2);
  }
  return gr;
}
//*************************************************************************************************
//
//*************************************************************************************************
TGraphAsymmErrors* MakeCurrentWPSigEffVsCutValueGraph(TH1F* signalHist, string name, Double_t myCutValue ) {
  //Make Met Plots
  const UInt_t nPoints = signalHist->GetXaxis()->GetNbins();
  double cutValue[1] = {0};
  double cutValueErr[1] = {0};
  double SigEff[1] = {0};
  double SigEffErrLow[1] = {0};
  double SigEffErrHigh[1] = {0};
  double NSigTotal = 0;
  
  Double_t effDiff = 9999;

  for (UInt_t q=0; q < nPoints+2; ++q) {
    NSigTotal += signalHist->GetBinContent(q);
  }

  for(UInt_t b=0; b < nPoints; ++b) {
    Double_t nsig = 0;
    for (UInt_t q=b; q < nPoints+2; ++q) {
      nsig += signalHist->GetBinContent(q);
    }

    Double_t ratio;
    Double_t n1 = 0;
    Double_t n2 = 0;

    n1 = TMath::Nint(nsig);
    n2 = TMath::Nint(NSigTotal);
    ratio = n1/n2;
    
      cout << myCutValue << " : " << signalHist->GetXaxis()->GetBinCenter(b) << " , " << cutValue[0] << endl;
    if (fabs(myCutValue - signalHist->GetXaxis()->GetBinCenter(b)) < fabs(myCutValue - cutValue[0])) {
      SigEff[0] = ratio;
      SigEffErrLow[0] = 0;
      SigEffErrHigh[0] = 0;
      cutValue[0] = signalHist->GetXaxis()->GetBinCenter(b);
      cutValueErr[0] = 0;
    }
  }

//   cout << "Final: " << cutValue[0] << " , " << SigEff[0] << endl;

  TGraphAsymmErrors *tmpSigEffVsCut = new TGraphAsymmErrors (1, cutValue, SigEff, cutValueErr, cutValueErr, SigEffErrLow, SigEffErrHigh  );
  tmpSigEffVsCut->SetName(name.c_str());
  tmpSigEffVsCut->SetTitle("");
  tmpSigEffVsCut->GetXaxis()->SetTitle("Cut Value");
  tmpSigEffVsCut->GetYaxis()->SetTitle("Efficiency");
  tmpSigEffVsCut->GetYaxis()->SetTitleOffset(1.1);
  tmpSigEffVsCut->GetXaxis()->SetTitleOffset(1.05);
  tmpSigEffVsCut->SetMarkerColor(kBlack);
  tmpSigEffVsCut->SetLineColor(kBlack);
  tmpSigEffVsCut->SetMarkerSize(1.5);

  return tmpSigEffVsCut;
}
Example #15
0
TGraphAsymmErrors* fitTools::getGraphPoissonErrors( TH1D* histo, bool drawZeros, const std::string xerrType, float nSigma ) {

  
  TGraphAsymmErrors* graph = new TGraphAsymmErrors(0);

  for( unsigned iBin=1; iBin<(histo->GetXaxis()->GetNbins()+1); ++iBin ) {

    int y; // these are data histograms, so y has to be integer
    double x, xerr, yerrplus, yerrminus;
    //xerr = 0.; //no xerr for now (maybe binwidth / sqrt(12)?)

    x = histo->GetBinCenter(iBin);
    if( xerrType=="0" )
      xerr = 0.;
    else if( xerrType=="binWidth" )
      xerr = histo->GetBinWidth(iBin)/2.;
    else if( xerrType=="sqrt12" )
      xerr = histo->GetBinWidth(iBin)/sqrt(12.);
    else {
      std::cout << "Unkown xerrType '" << xerrType << "'. Setting to bin width." << std::endl;
      xerr = histo->GetBinWidth(iBin);
    }
    y = (int)histo->GetBinContent(iBin);

    if( y==0 && !drawZeros ) continue;
       
    double ym, yp;
    RooHistError::instance().getPoissonInterval(y,ym,yp,nSigma);

    yerrplus = yp - y;
    yerrminus = y - ym;

/*
    // and now poissonian errors (bayes flat prior):
    if( y==0 ) {
      yerrminus = 0.;
      yerrplus = 0.5*TMath::ChisquareQuantile(cl, 2.*(y+1.) );
    } else {  
      //float lowL = 0.5*TMath::ChisquareQuantile(1.-cl/2., 2.*y);
      //float upL = 0.5*TMath::ChisquareQuantile(cl/2., 2.*(y+1.) );
      float lowL = 0.5*TMath::ChisquareQuantile(1.-cl, 2.*y);
      float upL = 0.5*TMath::ChisquareQuantile(cl, 2.*(y+1.) );
      yerrminus = y - lowL;
      yerrplus = upL - y;
    }
*/
    int thisPoint = graph->GetN();
    graph->SetPoint( thisPoint, x, y );
    graph->SetPointError( thisPoint, xerr, xerr, yerrminus, yerrplus );

  }

  return graph;

}
Example #16
0
void drawROC(TString& type, TString& ytitle, TString& xtitle, TString& head, TString &leg1, TString& leg2, TString& leg3, TString & leg4){
  TCanvas *c = new TCanvas(Form("%s",type.Data()), Form("%s",type.Data()) ,5,49,400,400);
  SetStyleCanvas(c);

  TGraphAsymmErrors *grae1ROCdetrel = new TGraphAsymmErrors();
  TGraphAsymmErrors *grae1ROCdettrk = new TGraphAsymmErrors();
  TGraphAsymmErrors *grae1ROCpf = new TGraphAsymmErrors();
  TGraphErrors *grae1ROCLKT = new TGraphErrors();
  
  ROCDetectorRelIsoData(grae1ROCdetrel);
  ROCDetectorTrkIsoData(grae1ROCdettrk);
  ROCParticleIsoData(grae1ROCpf);

  TGraphErrors *graeTbkgData = new TGraphErrors();
  TGraphErrors *graeTsigData = new TGraphErrors();
  EffLKTIsoData(graeTsigData);
  SetDataQCDEffLKT(graeTbkgData);
  grae1ROCLKT = getROC(graeTsigData, graeTbkgData);

  //ROCLKTIsoData(grae1ROCLKT);
 
  //limit trk ROC to 10 points 
  grae1ROCdettrk = getModifiedROC(grae1ROCdettrk, 10);
 
  TGraphAsymmErrors *temp = new TGraphAsymmErrors();
  temp=getTemp(1, 14);
  SetStyleGraphErrors(temp, 2, 23, 0, 0.0,  ytitle, xtitle, 0.77, 1.02);

  SetStyleGraphErrors(grae1ROCdetrel, 2, 23, 0, 0.8,  ytitle, xtitle, 0.8, 1.1);
  SetStyleGraphErrors(grae1ROCdettrk, 3, 22, 0, 0.8, ytitle, xtitle, 0.8, 1.1);
  SetStyleGraphErrors(grae1ROCpf, 4, 20, 0, 0.8, ytitle, xtitle, 0.8, 1.1);
  SetStyleGraphErrors(grae1ROCLKT, 6, 20, 0, 0.8, ytitle, xtitle, 0.8, 1.1);

  //draw error band *****
  grae1ROCdetrel->SetFillColor(2);
  grae1ROCdetrel->SetFillStyle(3001);

  grae1ROCdettrk->SetFillColor(3);
  grae1ROCdettrk->SetFillStyle(3001);

  grae1ROCpf->SetFillColor(4);
  grae1ROCpf->SetFillStyle(3001);
  //end draw error band *****

  temp->Draw("APC");
  grae1ROCdetrel->Draw("3CPSame");
  grae1ROCdettrk->Draw("3CPSame");
  grae1ROCpf->Draw("3CPSame");
  grae1ROCLKT->Draw("PSame");

  SetLegend(grae1ROCpf, grae1ROCdetrel, grae1ROCdettrk, grae1ROCLKT, "Data", leg1, leg2, leg3, leg4, "PL","PL","PL","P",0.6, 0.20, 0.9,0.50);
  SetLabel(0.19,0.88,36);

  c->Print(Form("%s.eps",type.Data()));
}
//*************************************************************************************************
//
//*************************************************************************************************
TGraphAsymmErrors* MakeSigEffVsBkgEffGraph(TH1F* signalHist, TH1F* bkgHist, string name ) {
  //Make Met Plots
  const UInt_t nPoints = signalHist->GetXaxis()->GetNbins();
  double SigEff[nPoints];
  double BkgEff[nPoints];
  double SigEffErrLow[nPoints];
  double SigEffErrHigh[nPoints];
  double BkgEffErrLow[nPoints];
  double BkgEffErrHigh[nPoints];
  double NSigTotal = 0;
  double NBkgTotal = 0;
  
  for (UInt_t q=0; q < nPoints+2; ++q) {
    NSigTotal += signalHist->GetBinContent(q);
    NBkgTotal += bkgHist->GetBinContent(q);
  }

  for(UInt_t b=0; b < nPoints; ++b) {
    Double_t nsig = 0;
    Double_t nbkg = 0;
    for (UInt_t q=b; q < nPoints+2; ++q) {
      nsig += signalHist->GetBinContent(q);
      nbkg += bkgHist->GetBinContent(q);
    }

    Double_t ratio;
    Double_t n1 = 0;
    Double_t n2 = 0;

    n1 = TMath::Nint(nsig);
    n2 = TMath::Nint(NSigTotal);
    ratio = n1/n2;


    SigEff[b] = ratio;
    SigEffErrLow[b] = 0;
    SigEffErrHigh[b] = 0;

    n1 = TMath::Nint(nbkg);
    n2 = TMath::Nint(NBkgTotal);
    ratio = n1/n2;
    BkgEff[b] = ratio;
    BkgEffErrLow[b] = 0;
    BkgEffErrHigh[b] = 0;
  }

  TGraphAsymmErrors *tmpSigEffVsBkgEff = new TGraphAsymmErrors (nPoints, BkgEff, SigEff, BkgEffErrLow, BkgEffErrHigh, SigEffErrLow, SigEffErrHigh );
  tmpSigEffVsBkgEff->SetName(name.c_str());
  tmpSigEffVsBkgEff->SetTitle("");
  tmpSigEffVsBkgEff->GetXaxis()->SetTitle("Bkg Eff");
  tmpSigEffVsBkgEff->GetYaxis()->SetTitle("Signal Eff");
  tmpSigEffVsBkgEff->GetYaxis()->SetTitleOffset(1.1);
  tmpSigEffVsBkgEff->GetXaxis()->SetTitleOffset(1.05);
  tmpSigEffVsBkgEff->SetMarkerSize(0.5);
  tmpSigEffVsBkgEff->SetMarkerStyle(20);

  return tmpSigEffVsBkgEff;
}
Example #18
0
 void addLine(TString file,TString name,TString legend,Color_t color,Int_t linestyle = 0,Int_t linewidth = 3) 
 {
   TFile * f = new TFile(file);
   TGraphAsymmErrors *obs = (TGraphAsymmErrors*)f->Get(name);
   obs->SetLineColor(color);
   obs->SetLineStyle(linestyle);
   obs->SetLineWidth(linewidth);
   obs->Draw("LXsame");
   if(legend!="") {
     l->AddEntry(obs,legend,"l");
   }
 }
// Take a tree, a variable and calculate the efficiency
TGraphAsymmErrors* getEfficiency(TTree *t, char *variable, TCut preselection, TCut cut, int nBin, Float_t *bins)
{
   static int count = 0;
   count++;
   TH1D *hPass = new TH1D (Form("hPass%d",count),"",nBin,bins);
   TH1D *hAll = new TH1D (Form("hAll%d",count),"",nBin,bins);
   t->Draw(Form("%s>>hAll%d",variable,count),preselection);
   t->Draw(Form("%s>>hPass%d",variable,count),preselection&&cut);

   TGraphAsymmErrors *g = new TGraphAsymmErrors;
   g->BayesDivide(hPass,hAll);
   return g;
}
Example #20
0
//____________________________________________________________________________________
TGraphAsymmErrors *calcEfficiency(TH1* h1, TH1* h2)
{

  TH1 *phUp   = (TH1 *)h2->Clone("phUp");
  TH1 *phDown = (TH1 *)h1->Clone("phDown");
  
  phUp->SetDirectory(0);
  phDown->SetDirectory(0);
  
  TGraphAsymmErrors *pgEfficiency = new TGraphAsymmErrors();
  pgEfficiency->BayesDivide(phUp,phDown,"");
  return pgEfficiency;
}
TGraphAsymmErrors* ratio_tgraphs(TGraphAsymmErrors *n, TGraphAsymmErrors *d, double scale){

   cout<<"[ratio_tgraphs]"<<endl;
 
   if(!n || !d) return 0;
   int N = d->GetN();

   cout<<"number of bins "<<N<<endl;

   TGraphAsymmErrors *ratio = new TGraphAsymmErrors(N);
   char name[300];
   sprintf(name,"ratio_%s_over_%s",n->GetName(),d->GetName());
   
   ratio->SetName(name);

   for(int i=0;i<N;i++)
      {
	 double nx, ny;
	 double nex, ney;
	 
	 n->GetPoint(i,nx,ny);
	 nex = n->GetErrorX(i);
	 ney = n->GetErrorY(i);
	 
	 double dx, dy;
	 double dex, dey;
	 
	 d->GetPoint(i,dx,dy);
	 //cout<<" dy "<<dy<<endl;
	 dex = d->GetErrorX(i);
	 dey = d->GetErrorY(i);
	 
	 double rx, ry;
	 double rex, rey;
	 
	 //cout<<"nx :"<<nx<<"ny :"<<ny<<endl;
	 //cout<<"dx :"<<dx<<"dy :"<<dy<<endl;

	 if(dy==0) ry = 999;
	 else ry = (ny/dy)*scale;
	 //rex = rey = 0;
	 rex = 0;
	 //rey = sqrt((ney*ney)/(ny*ny)+(dey*dey)/(dy*dy));
	 rey = sqrt((ney*ney)+(dey*dey))*scale;          

	 ratio->SetPoint(i,dx,ry);
	 ratio->SetPointError(i,rex,rex,rey,rey);
   }

   return ratio;
}
Example #22
0
bool PlotManager::saveBayesEfficiency(const string& graphName, const string& graphTitle,
                                      const string& numeHistName, const string& denoHistName)
{
  if ( ! isSetup_ ) return false;
  
  TH1F* numeHist = (TH1F*)(theSrcFile_->Get(numeHistName.c_str()));
  TH1F* denoHist = (TH1F*)(theSrcFile_->Get(denoHistName.c_str()));
  
  // Check validity of objects
  if ( numeHist == 0 || denoHist == 0 ) {
    cerr << "Cannot get object : " << graphName << endl;
    return false;
  }

  if ( ! numeHist->IsA()->InheritsFrom("TH1") || 
       ! denoHist->IsA()->InheritsFrom("TH1") ||
       numeHist->IsA()->InheritsFrom("TH2") ||
       denoHist->IsA()->InheritsFrom("TH2") ) {
    return false;
  }

  // Check bin size
  if ( numeHist->GetNbinsX() != denoHist->GetNbinsX() ) {
    cerr << "Bin size of two histograms are not same" << endl;
    return false;
  }

  // Push to base directory
  string pwd(gDirectory->GetPath());

  string newGraphPath = dirname(graphName);
  string newGraphName = basename(graphName);

  if ( newGraphPath.empty() ) {
    theOutFile_->cd();
  }
  else if ( theOutFile_->cd(newGraphPath.c_str()) == kFALSE ) {
    cout << "Cannot find directory, do mkdirs" << endl;
    mkdirs(theOutFile_, newGraphPath)->cd();
  }

  // Create new TGraphAsymmErrors
  TGraphAsymmErrors* effGraph = new TGraphAsymmErrors(numeHist, denoHist);
  
  // Cosmetics
  effGraph->SetName(newGraphName.c_str());
  effGraph->SetTitle(graphTitle.c_str());
  effGraph->SetMinimum(0.8);
  effGraph->SetMaximum(1.0);
  effGraph->GetXaxis()->SetTitle(numeHist->GetXaxis()->GetTitle());
  effGraph->GetYaxis()->SetTitle("Efficiency");

  // Save histogram
  effGraph->Write();

  // Pop directory
  gDirectory->cd(pwd.c_str());
  
  return true;
}
Example #23
0
TGraphAsymmErrors* EFF( TH1* hSignal ){
  TGraphAsymmErrors* out = new TGraphAsymmErrors();
  int nbins = hSignal->GetNbinsX();
  double totalS = hSignal->GetEntries();
  int bin;
  for(int i=0 ; i < 1000; i++){
    bin=i+1;
    double Si = hSignal->Integral(0,bin);
    double eff_signal = Si/ totalS; 
    out->SetPoint(i, 0.01*(i+1), eff_signal);
    //out->SetPointEXhigh(i,err_signal);
    //out->SetPointEXlow(i, err_signal);
  }   
  return out;
}
//! Read TGraphAsymmErrors from file
// -------------------------------------------------------------------------------------
TGraphAsymmErrors* readTGraphAsymmErrors(const TString &fileName, const TString &gName, const TString &newGName) {
  TFile file(fileName,"READ");
  TGraphAsymmErrors *g = 0;
  file.GetObject(gName,g);
  if( g ) {
    if( newGName.Length() ) g->SetName(newGName);
  } else {
    std::cerr << "ERROR in FileOps::readTGraph: TGraphAsymmErrors with name '" << gName << "' does not exist in file '" << fileName << "'\n.";
    file.Close();
    exit(-1);
  }
  file.Close();
    
  return g;
}
TGraphAsymmErrors* OffSetter(vector<TGraphAsymmErrors*> Orginal, bool Data = false) {
    size_t Newnphistar = nphistar - 2;
    TGraphAsymmErrors* NewPlot = new TGraphAsymmErrors(Newnphistar * ny);
    for (size_t ybin = 0; ybin < ny; ybin++) {
        for (size_t j = 0; j < Newnphistar - 2; j++) {
            double x, y;
            Orginal[ybin]->GetPoint(j, x, y);
            double Error = Orginal[ybin]->GetErrorYhigh(j);
            NewPlot->SetPoint(j + ybin * Newnphistar, x, y + .5 * (ny - ybin - 1));
            if (Data)NewPlot->SetPointError(j + ybin * Newnphistar, (phistarBins[j + 1] - phistarBins[j]) / 2., (phistarBins[j + 1] - phistarBins[j]) / 2., Error, Error);
            else NewPlot->SetPointError(j + ybin*Newnphistar, 0, 0, Error, Error);
        }
    }
    return NewPlot;
}
Example #26
0
double GetError(TH1* h, bool up){
  const double alpha = 1 - 0.6827;
  if(!h) return 0.;
  TGraphAsymmErrors * g = new TGraphAsymmErrors(h);
  for (int i = 0; i < g->GetN(); ++i) {
    int N = g->GetY()[i];
    double L =  (N==0) ? 0  : (ROOT::Math::gamma_quantile(alpha/2,N,1.));
    double U =  (N==0) ?  ( ROOT::Math::gamma_quantile_c(alpha,N+1,1) ) :
      ( ROOT::Math::gamma_quantile_c(alpha/2,N+1,1) );
    if ( N!=0 ) {
      if(up) return U-N;
      else return N-L;
    }

  }
}
vector<TGraphAsymmErrors*> SplitGraph(TGraphAsymmErrors* graph, bool doXerrors = 0) {
    vector<TGraphAsymmErrors*> v;
    for (uint i = 0; i < ny; i++) {
        TGraphAsymmErrors* g = new TGraphAsymmErrors(nphistar);
        for (uint j = 0; j < nphistar; j++) {
            int bin = i * nphistar + j;
            double x, y;
            graph->GetPoint(bin, x, y);
            g->SetPoint(j, (phistarBins[j] + phistarBins[j + 1]) / 2., y);
            g->SetPointError(j, 0, 0, graph->GetErrorYlow(bin), graph->GetErrorYhigh(bin));
            if (doXerrors) g->SetPointError(j, (phistarBins[j + 1] - phistarBins[j]) / 2., (phistarBins[j + 1] - phistarBins[j]) / 2., graph->GetErrorYlow(bin), graph->GetErrorYhigh(bin));
            //cout << i << " " << j << " " << bin << " " << (phistarBins[j] + phistarBins[j + 1]) / 2. << " " << (phistarBins[j + 1] - phistarBins[j]) / 2. << " " << y << " " << graph->GetErrorYlow(bin) << " " << graph->GetErrorYhigh(bin) << endl;
        }
        v.push_back(g);
    }
    return v;
}
Example #28
0
  Hists(std::string name)
  {
    title            = name;
    h1McPt           = new TH1F(Form("h1McPt_%s",name.c_str()),";mcP_{T}(GeV/c)",40,1,5);
    h1HftMatchedMcPt = new TH1F(Form("h1HftMatchedMcPt_%s",name.c_str()),";mcP_{T}(GeV/c)",40,1,5);
    h1TpcMcPt        = new TH1F(Form("h1TpcMcPt_%s",name.c_str()),";mcP_{T}(GeV/c)",40,1,5);
    gTpcEff          = new TGraphAsymmErrors; gTpcEff->SetName(Form("gTpcEff_%s",name.c_str()));
    gHftEff          = new TGraphAsymmErrors; gHftEff->SetName(Form("gHftEff_%s",name.c_str()));
    h1DcaZPosEta     = new TH1F(Form("h1DcaZPosEta_%s",name.c_str()),";dcaZ(cm)",400,-1,1);
    h1DcaZNegEta     = new TH1F(Form("h1DcaZNegEta_%s",name.c_str()),";dcaZ(cm)",400,-1,1);
    h1DcaZ           = new TH1F(Form("h1DcaZ_%s",name.c_str()),";dcaZ(cm)",400,-1,1);

    h1McPt->SetDirectory(0);
    h1HftMatchedMcPt->SetDirectory(0);
    h1TpcMcPt->SetDirectory(0);
    h1DcaZ->SetDirectory(0);
  }
Example #29
0
  /** 
   * Add distributions from other experiments to stacks 
   * 
   * @param name     Name of current bin 
   * @param i        Index of current bin
   * @param sNN      Center of mass energy 
   * @param allALICE Stack of ALICE data 
   * @param allCMS   Stack of CMS data 
   * @param alice    Possible ALICE result on return
   * @param cms      Possible CMS result on return
   */
  void Other2Stack(const TString& name, Int_t i,
		   UShort_t sNN, TMultiGraph* allALICE, TMultiGraph* allCMS,
		   TGraph*& alice, TGraph*& cms) 
  {
    if (!allALICE && !allCMS) return;

    TString tmp(name);
    tmp.ReplaceAll("p", "+");
    tmp.ReplaceAll("m", "-");
    tmp.ReplaceAll("_", " ");
    tmp.ReplaceAll("d", ".");
    TObjArray* tokens = tmp.Tokenize(" ");
    if (!tokens || tokens->GetEntriesFast() < 2) { 
      Error("Other2Stack", "Failed to decode eta range from %s", name.Data());
      if (tokens) tokens->Delete();
      return;
    }
    Double_t eta1 = static_cast<TObjString*>(tokens->At(0))->String().Atof();
    Double_t eta2 = static_cast<TObjString*>(tokens->At(1))->String().Atof();
    tokens->Delete();
    
    if (TMath::Abs(eta2+eta1) > 1e-3) {
      // Not symmetric bin 
      // Info("Other2Stack", "bin [%f,%f] is not symmetric (%f)",
      //      eta1, eta2, TMath::Abs(eta2-eta1));
      return;
    }
    Double_t aEta = TMath::Abs(eta1);

    Int_t open, closed;
    Double_t factor; 
    Float_t  size;
    BinAttributes(i, open, closed, size, factor);

    if (allALICE) {
      TGraphAsymmErrors* g = GetOther(1, aEta, sNN, factor);
      if (g) {
	g->SetMarkerStyle(closed);
	g->SetMarkerColor(kColorALICE);
	g->SetMarkerSize(size);
	allALICE->Add(g, "p same");
	alice = g;
      }
    }
    if (allCMS) {
      TGraphAsymmErrors* g = GetOther(0, aEta, sNN, factor);
      if (g) {
	g->SetMarkerStyle(closed);
	g->SetMarkerColor(kColorCMS);
	g->SetMarkerSize(size);
	allCMS->Add(g, "p same");
	cms = g;
      }
    }
  }
TGraphAsymmErrors* CombineTwoTGraphAsymm(TGraphAsymmErrors *graph1, TGraphAsymmErrors *graph2, TH1D *baseHist, Bool_t shouldAddQuadrature)
{

  if (!graph1 || !graph2 || !baseHist) {
    cout << "Missing component. Cannot combine graphs" <<endl;
    return NULL;
  }
  
  // Initialize the TGraph from the base histogram
  TGraphAsymmErrors *combinedGraph = new TGraphAsymmErrors(baseHist);

  // Loop over the bins and combine the errors
  for (Int_t iBin = 0; iBin < combinedGraph->GetN(); iBin++) {
    Double_t errYHigh = 0;
    Double_t errYLow = 0;
    if (shouldAddQuadrature) {
      // Add the errors in quadrature
      errYHigh = pow(graph1->GetErrorYhigh(iBin), 2);
      errYHigh += pow(graph2->GetErrorYhigh(iBin), 2);
      errYHigh = sqrt(errYHigh);

      errYLow = pow(graph1->GetErrorYlow(iBin), 2);
      errYLow += pow(graph2->GetErrorYlow(iBin), 2);
      errYLow = sqrt(errYLow);
    } else {
      // Just take the largest value for the bin
      if (errYHigh < graph1->GetErrorYhigh(iBin)) {
	errYHigh = graph1->GetErrorYhigh(iBin);
      }
      if (errYHigh < graph2->GetErrorYhigh(iBin)) {
	errYHigh = graph2->GetErrorYhigh(iBin);
      }
      if (errYLow < graph1->GetErrorYlow(iBin)) {
	errYLow = graph1->GetErrorYlow(iBin);
      }
      if (errYLow < graph2->GetErrorYlow(iBin)) {
	errYLow = graph2->GetErrorYlow(iBin);
      }
    }

    combinedGraph->SetPointEYhigh(iBin, errYHigh);
    combinedGraph->SetPointEYlow(iBin, errYLow);
  }
  return combinedGraph;
}