ROOT logo
void SetStyles(TH1 *histo,int marker, int color,char *xtitle, char *ytitle);
TH1* bayneseffdiv(TH1* numerator, TH1* denominator,Char_t* name) ;
void PlotTrackMatchFractions(TString filename="rootFiles/LHC11a10a_bis/Et.ESD.simPbPb.EMCal.LHC11a10a_bis.Run139465.root", TString det = "EMCal"){
  gStyle->SetOptTitle(0);
  gStyle->SetOptStat(0);
  gStyle->SetOptFit(0);
  TString outname = "/tmp/TrackMatchFractionsGammas"+det+".png";
  TString outname2 = "/tmp/TrackMatchFractionsHadrons"+det+".png";
  //TString outnamebin = Form("%iTo%i",bin,binLast);

  TFile *f = TFile::Open(filename, "READ");
  
  TList *l = (TList*)f->Get("out1");
  TH1F *fHistGammasCut = l->FindObject("fHistGammasTracksCut");
  TH1F *fHistGammasAccepted = l->FindObject("fHistGammasTracksAccepted");
  TH1F *fHistChargedTracksCut = l->FindObject("fHistChargedTracksCut");
  TH1F *fHistChargedTracksAccepted = l->FindObject("fHistChargedTracksAccepted");
  TH1F *fHistGammasTotal = fHistGammasCut->Clone("fHistGammasTotal");
  fHistGammasTotal->Add(fHistGammasAccepted);
  TH1F *fHistGammasFracCut = bayneseffdiv(fHistGammasCut,fHistGammasTotal,"fHistGammasFracCut");
  TH1F *fHistGammasFracAcc = bayneseffdiv(fHistGammasAccepted,fHistGammasTotal,"fHistGammasFracCut");
  SetStyles(fHistGammasFracCut,20,2,"E_{T}","Fraction");
  SetStyles(fHistGammasFracAcc,25,4,"E_{T}","Fraction");
  TH1F *fHistChargedTracksTotal = fHistChargedTracksCut->Clone("fHistChargedTracksTotal");
  fHistChargedTracksTotal->Add(fHistChargedTracksAccepted);
  TH1F *fHistChargedTracksFracCut = bayneseffdiv(fHistChargedTracksCut,fHistChargedTracksTotal,"fHistChargedTracksFracCut");
  TH1F *fHistChargedTracksFracAcc = bayneseffdiv(fHistChargedTracksAccepted,fHistChargedTracksTotal,"fHistChargedTracksFracCut");
  SetStyles(fHistChargedTracksFracCut,20,2,"E_{T}","Fraction");
  SetStyles(fHistChargedTracksFracAcc,25,4,"E_{T}","Fraction");
  TLegend *leg = new TLegend(0.357383,0.47043,0.458054,0.75);
  leg->SetFillStyle(0);
  leg->SetFillColor(0);
  leg->SetBorderSize(0);
  leg->SetTextSize(0.03);
  leg->AddEntry(fHistGammasFracCut,"Fraction of #gamma cut");
  leg->AddEntry(fHistGammasFracAcc,"Fraction of #gamma accepted");
  leg->SetTextSize(0.061828);
  TCanvas *c1 = new TCanvas("c1","c1",600,400);
  c1->SetTopMargin(0.02);
  c1->SetRightMargin(0.02);
  c1->SetBorderSize(0);
  c1->SetFillColor(0);
  c1->SetFillColor(0);
  c1->SetBorderMode(0);
  c1->SetFrameFillColor(0);
  c1->SetFrameBorderMode(0);
  fHistGammasFracCut->SetMaximum(1.0);
  fHistGammasFracCut->SetMinimum(0.0);
  fHistGammasFracCut->Draw();
  fHistGammasFracAcc->Draw("same");
  leg->Draw();
  c1->SaveAs(outname.Data());

  TLegend *leg2 = new TLegend(0.357383,0.47043,0.458054,0.75);
  leg2->SetFillStyle(0);
  leg2->SetFillColor(0);
  leg2->SetBorderSize(0);
  leg2->SetTextSize(0.03);
  leg2->AddEntry(fHistGammasFracCut,"Fraction of hadrons cut");
  leg2->AddEntry(fHistGammasFracAcc,"Fraction of hadrons accepted");
  leg2->SetTextSize(0.061828);
  TCanvas *c2 = new TCanvas("c2","c2",600,400);
  c2->SetTopMargin(0.02);
  c2->SetRightMargin(0.02);
  c2->SetBorderSize(0);
  c2->SetFillColor(0);
  c2->SetFillColor(0);
  c2->SetBorderMode(0);
  c2->SetFrameFillColor(0);
  c2->SetFrameBorderMode(0);
  fHistChargedTracksFracCut->SetMaximum(1.0);
  fHistChargedTracksFracCut->SetMinimum(0.0);
  fHistChargedTracksFracCut->Draw();
  fHistChargedTracksFracAcc->Draw("same");
  leg2->Draw();

  c2->SaveAs(outname2.Data());

}
void SetStyles(TH1 *histo,int marker, int color,char *xtitle, char *ytitle){
  histo->SetMarkerStyle(marker);
  histo->SetMarkerColor(color);
  histo->SetLineColor(color);
  histo->GetXaxis()->SetTitle(xtitle);
  histo->GetYaxis()->SetTitle(ytitle);
}


TH1* bayneseffdiv(TH1* numerator, TH1* denominator,Char_t* name) 
{
    if(!numerator){
      cerr<<"Error:  numerator does not exist!"<<endl;
      return NULL;
    }
    if(!denominator){
      cerr<<"Error:  denominator does not exist!"<<endl;
      return NULL;
    }
    TH1* result = (TH1*)numerator->Clone(name);
    Int_t nbins = numerator->GetNbinsX();
    for (Int_t ibin=0; ibin<= nbins+1; ++ibin) {
      Double_t numeratorVal = numerator->GetBinContent(ibin);
      Double_t denominatorVal = denominator->GetBinContent(ibin);
      // Check if the errors are right or the thing is scaled
      Double_t numeratorValErr = numerator->GetBinError(ibin);
      if (!(numeratorValErr==0. || numeratorVal ==0.) ) {
	Double_t rescale = numeratorValErr*numeratorValErr/numeratorVal;
	numeratorVal /= rescale;
      }
      Double_t denominatorValErr = denominator->GetBinError(ibin);
      if (!(denominatorValErr==0. || denominatorVal==0. )) {
	Double_t rescale = denominatorValErr*denominatorValErr/denominatorVal;
	denominatorVal /= rescale;
      }
      Double_t quotient = 0.;
      if (denominatorVal!=0.) {
	quotient = numeratorVal/denominatorVal;
      }
      Double_t quotientErr=0;
      quotientErr = TMath::Sqrt(
				(numeratorVal+1.0)/(denominatorVal+2.0)*
				((numeratorVal+2.0)/(denominatorVal+3.0)-(numeratorVal+1.0)/(denominatorVal+2.0)));
      result->SetBinContent(ibin,quotient);
      result->SetBinError(ibin,quotientErr);
      //cout<<"Setting bin "<<ibin<<" to "<<quotient<<" "<<numeratorVal<<"/"<<denominatorVal<<endl;
    }
    return result;
}
 PlotTrackMatchFractions.C:1
 PlotTrackMatchFractions.C:2
 PlotTrackMatchFractions.C:3
 PlotTrackMatchFractions.C:4
 PlotTrackMatchFractions.C:5
 PlotTrackMatchFractions.C:6
 PlotTrackMatchFractions.C:7
 PlotTrackMatchFractions.C:8
 PlotTrackMatchFractions.C:9
 PlotTrackMatchFractions.C:10
 PlotTrackMatchFractions.C:11
 PlotTrackMatchFractions.C:12
 PlotTrackMatchFractions.C:13
 PlotTrackMatchFractions.C:14
 PlotTrackMatchFractions.C:15
 PlotTrackMatchFractions.C:16
 PlotTrackMatchFractions.C:17
 PlotTrackMatchFractions.C:18
 PlotTrackMatchFractions.C:19
 PlotTrackMatchFractions.C:20
 PlotTrackMatchFractions.C:21
 PlotTrackMatchFractions.C:22
 PlotTrackMatchFractions.C:23
 PlotTrackMatchFractions.C:24
 PlotTrackMatchFractions.C:25
 PlotTrackMatchFractions.C:26
 PlotTrackMatchFractions.C:27
 PlotTrackMatchFractions.C:28
 PlotTrackMatchFractions.C:29
 PlotTrackMatchFractions.C:30
 PlotTrackMatchFractions.C:31
 PlotTrackMatchFractions.C:32
 PlotTrackMatchFractions.C:33
 PlotTrackMatchFractions.C:34
 PlotTrackMatchFractions.C:35
 PlotTrackMatchFractions.C:36
 PlotTrackMatchFractions.C:37
 PlotTrackMatchFractions.C:38
 PlotTrackMatchFractions.C:39
 PlotTrackMatchFractions.C:40
 PlotTrackMatchFractions.C:41
 PlotTrackMatchFractions.C:42
 PlotTrackMatchFractions.C:43
 PlotTrackMatchFractions.C:44
 PlotTrackMatchFractions.C:45
 PlotTrackMatchFractions.C:46
 PlotTrackMatchFractions.C:47
 PlotTrackMatchFractions.C:48
 PlotTrackMatchFractions.C:49
 PlotTrackMatchFractions.C:50
 PlotTrackMatchFractions.C:51
 PlotTrackMatchFractions.C:52
 PlotTrackMatchFractions.C:53
 PlotTrackMatchFractions.C:54
 PlotTrackMatchFractions.C:55
 PlotTrackMatchFractions.C:56
 PlotTrackMatchFractions.C:57
 PlotTrackMatchFractions.C:58
 PlotTrackMatchFractions.C:59
 PlotTrackMatchFractions.C:60
 PlotTrackMatchFractions.C:61
 PlotTrackMatchFractions.C:62
 PlotTrackMatchFractions.C:63
 PlotTrackMatchFractions.C:64
 PlotTrackMatchFractions.C:65
 PlotTrackMatchFractions.C:66
 PlotTrackMatchFractions.C:67
 PlotTrackMatchFractions.C:68
 PlotTrackMatchFractions.C:69
 PlotTrackMatchFractions.C:70
 PlotTrackMatchFractions.C:71
 PlotTrackMatchFractions.C:72
 PlotTrackMatchFractions.C:73
 PlotTrackMatchFractions.C:74
 PlotTrackMatchFractions.C:75
 PlotTrackMatchFractions.C:76
 PlotTrackMatchFractions.C:77
 PlotTrackMatchFractions.C:78
 PlotTrackMatchFractions.C:79
 PlotTrackMatchFractions.C:80
 PlotTrackMatchFractions.C:81
 PlotTrackMatchFractions.C:82
 PlotTrackMatchFractions.C:83
 PlotTrackMatchFractions.C:84
 PlotTrackMatchFractions.C:85
 PlotTrackMatchFractions.C:86
 PlotTrackMatchFractions.C:87
 PlotTrackMatchFractions.C:88
 PlotTrackMatchFractions.C:89
 PlotTrackMatchFractions.C:90
 PlotTrackMatchFractions.C:91
 PlotTrackMatchFractions.C:92
 PlotTrackMatchFractions.C:93
 PlotTrackMatchFractions.C:94
 PlotTrackMatchFractions.C:95
 PlotTrackMatchFractions.C:96
 PlotTrackMatchFractions.C:97
 PlotTrackMatchFractions.C:98
 PlotTrackMatchFractions.C:99
 PlotTrackMatchFractions.C:100
 PlotTrackMatchFractions.C:101
 PlotTrackMatchFractions.C:102
 PlotTrackMatchFractions.C:103
 PlotTrackMatchFractions.C:104
 PlotTrackMatchFractions.C:105
 PlotTrackMatchFractions.C:106
 PlotTrackMatchFractions.C:107
 PlotTrackMatchFractions.C:108
 PlotTrackMatchFractions.C:109
 PlotTrackMatchFractions.C:110
 PlotTrackMatchFractions.C:111
 PlotTrackMatchFractions.C:112
 PlotTrackMatchFractions.C:113
 PlotTrackMatchFractions.C:114
 PlotTrackMatchFractions.C:115
 PlotTrackMatchFractions.C:116
 PlotTrackMatchFractions.C:117
 PlotTrackMatchFractions.C:118
 PlotTrackMatchFractions.C:119
 PlotTrackMatchFractions.C:120
 PlotTrackMatchFractions.C:121
 PlotTrackMatchFractions.C:122
 PlotTrackMatchFractions.C:123
 PlotTrackMatchFractions.C:124
 PlotTrackMatchFractions.C:125
 PlotTrackMatchFractions.C:126
 PlotTrackMatchFractions.C:127
 PlotTrackMatchFractions.C:128
 PlotTrackMatchFractions.C:129