Beispiel #1
0
void anaFragShape(TString infile="dj_HCPR-GoodTrkAndPixel_CleanEvt1130.root")
{
  TChain * djcalo = new TChain("djcalo/djTree");
  djcalo->Add(infile);
  aliases_dijet(djcalo);
  TChain * djcalopix = new TChain("djcalo_pxl/djTree");
  djcalopix->Add(infile);
  aliases_dijet(djcalopix);
  TString evtSel("(cent<10 && nljet>120 && abs(nljeta)<2 && aljet>50 && abs(aljeta)<2 && jdphi>2.5 && Aj>0.24)");
  TH1::SetDefaultSumw2();

  TCanvas * c0 = new TCanvas("c0","c0",500,500);
  djcalo->Draw("Aj>>hAj(20,0,1)",evtSel);
  djcalopix->Draw("Aj",evtSel,"Esame");

  TCanvas * c2 = new TCanvas("c2","c2",500,500);
  TH1D * hJDPhi = new TH1D("hJDPhi","hJDPhi",50,0,3.1416);
  TH1D * hJDPhi2 = new TH1D("hJDPhi2","hJDPhi",50,0,3.1416);
  Float_t numDJ = djcalo->Draw("jdphi>>hJDPhi",evtSel);
  Float_t numDJ2 = djcalopix->Draw("jdphi>>hJDPhi2",evtSel);
  cout << "num djs: " << numDJ << "  djs(pix)" << numDJ2 << endl;

  TH1D * hPNDRTrk = new TH1D("hPNDRTrk",";R(trk,jet);1/(N_{DJ} 2#piR) dp_{T}^{Trk}/dR",10,0,TMath::PiOver2());
  TH1D * hPNDRPix = new TH1D("hPNDRPix",";R(trk,jet);1/(N_{DJ} 2#piR) dp_{T}^{Trk}/dR",10,0,TMath::PiOver2());
  TH1D * hPADRTrk = new TH1D("hPADRTrk",";R(trk,jet);1/(N_{DJ} 2#piR) dp_{T}^{Trk}/dR",10,0,TMath::PiOver2());
  TH1D * hPADRPix = new TH1D("hPADRPix",";R(trk,jet);1/(N_{DJ} 2#piR) dp_{T}^{Trk}/dR",10,0,TMath::PiOver2());
  djcalo->Draw("pndr>>hPNDRTrk",Form("(%s&&ppt>=1.2)*(ppt/(TMath::TwoPi()*pndr))",evtSel.Data()));
  djcalopix->Draw("pndr>>hPNDRPix",Form("(%s&&ppt>=0.3&&ppt<1.2)*(ppt/(TMath::TwoPi()*pndr))",evtSel.Data()));
  djcalo->Draw("padr>>hPADRTrk",Form("(%s&&ppt>=1.2)*(ppt/(TMath::TwoPi()*padr))",evtSel.Data()));
  djcalopix->Draw("padr>>hPADRPix",Form("(%s&&ppt>=0.3&&ppt<1.2)*(ppt/(TMath::TwoPi()*padr))",evtSel.Data()));
  hPNDRTrk->Scale(1./(numDJ*hPNDRTrk->GetBinWidth(1)));
  hPNDRPix->Scale(1./(numDJ*hPNDRPix->GetBinWidth(1)));
  hPADRTrk->Scale(1./(numDJ*hPADRTrk->GetBinWidth(1)));
  hPADRPix->Scale(1./(numDJ*hPADRPix->GetBinWidth(1)));
  hPNDRPix->SetMinimum(50);
  hPNDRPix->SetMaximum(100);
  hPNDRTrk->SetMinimum(10);
  hPNDRTrk->SetMaximum(2000);
  hPNDRPix->SetMarkerStyle(kFullCircle);
  hPNDRTrk->SetMarkerStyle(kFullSquare);
  hPNDRPix->SetMarkerColor(kRed);
  hPNDRTrk->SetMarkerColor(kRed);
  hPADRPix->SetMarkerStyle(kOpenCircle);
  hPADRTrk->SetMarkerStyle(kOpenSquare);
  hPADRPix->SetMarkerColor(kBlue);
  hPADRTrk->SetMarkerColor(kBlue);
  TCanvas * c3 = new TCanvas("c3","c3",500,500);
  hPNDRPix->Draw("E");
  hPADRPix->Draw("Esame");
  TCanvas * c3_2 = new TCanvas("c3_2","c3_2",500,500);
  c3_2->SetLogy();
  hPNDRTrk->Draw("E");
  hPADRTrk->Draw("Esame");
}
Beispiel #2
0
TH1D* makeRatioHist(TH1D& Hist1, TH1D& Hist2, char* name="CaloJetPtRatio2over1", double maxX=100.0) {
  
  TH1D* hist = Hist2.Clone(name);
  TH1D* temphist = Hist1.Clone("temphist");
  //temphist->Add( &Hist2, -1);
  hist->Divide(temphist);
  hist->GetXaxis()->SetTitle("jet p_{T} (GeV/c)");
  hist->SetMinimum(0.0);
  if(maxX > 110.0) hist->SetMaximum(0.35);
  else hist->SetMaximum(0.3);
  hist->GetXaxis()->SetRangeUser(0,maxX);
  delete temphist;
  return hist;
}
Beispiel #3
0
void plotV2vstheta(){
    gStyle->SetOptFit(1);
    gStyle->SetOptStat(0);
    gStyle->SetOptTitle(0);
    gStyle->SetErrorX(0);
    int xbin = 0;
    TFile *f = new TFile("mergedV_Prod.root");
    TVectorD *vecV = (TVectorD*)f->Get(Form("D_%d/V"));
    TVectorD *vecdeltaV = (TVectorD*)f->Get(Form("D_%d/deltaV"));
    TVectorD *vecVmean = (TVectorD*)f->Get(Form("Vmean"));
    double *V = vecV->GetMatrixArray();
    double *deltaV = vecdeltaV->GetMatrixArray();
    double *Vmean = vecVmean->GetMatrixArray();
    double theta[ntheta];
    for(int itheta=0;itheta<ntheta;itheta++){
        theta[itheta]=itheta*TMath::Pi()/ntheta/nn;
    }
    TH1D *hFrame = new TH1D("","",300,-1,2);
    hFrame->GetXaxis()->SetTitle("#theta");
    hFrame->GetYaxis()->SetTitle("referenceV_{2}");	
    hFrame->GetXaxis()->SetTitleSize(0.04);
    hFrame->GetYaxis()->SetTitleSize(0.04);
    hFrame->GetXaxis()->SetRangeUser(-0.1,1.5);
    hFrame->SetMaximum(0.055);
    hFrame->SetMinimum(0.045);
    hFrame->Draw();
    TGraphErrors *gr = new TGraphErrors(ntheta,theta,V,0,deltaV);
    gr->SetMarkerSize(1.2);
    gr->SetMarkerStyle(20);
    gr->Draw("Psame");
    TLine *l = new TLine(0,inV2,1.4,inV2);
    l->SetLineStyle(2);
    l->Draw("same");
    c1->Print("V2vstheta.png");
}
//__________________________________________________________________________
void drawDum(float min, float max, double drawXLabel)
{

  TH1D *hdum = new TH1D("hdum","",20,0,1);
  hdum->SetMaximum(max);

  hdum->SetStats(0);

  if(drawXLabel) hdum->SetXTitle("A_{J} = (E_{T}^{j1}-E_{T}^{j2})/(E_{T}^{j1}+E_{T}^{j2})");
  hdum->GetXaxis()->SetLabelSize(20);
  hdum->GetXaxis()->SetLabelFont(43);
  hdum->GetXaxis()->SetTitleSize(22);
  hdum->GetXaxis()->SetTitleFont(43);
  hdum->GetXaxis()->SetTitleOffset(1.5);
  hdum->GetXaxis()->CenterTitle();

  hdum->GetXaxis()->SetNdivisions(905,true);

  hdum->SetYTitle("Ratio");

  hdum->GetYaxis()->SetLabelSize(20);
  hdum->GetYaxis()->SetLabelFont(43);
  hdum->GetYaxis()->SetTitleSize(20);
  hdum->GetYaxis()->SetTitleFont(43);
  hdum->GetYaxis()->SetTitleOffset(2.5);
  hdum->GetYaxis()->CenterTitle();

  hdum->SetAxisRange(0,0.2,"Y");

  hdum->Draw("");

}
Beispiel #5
0
// ----------------------------------------------------------------------
void plotRatio(string era = "2016BF") {
  gStyle->SetOptStat(0);

  if (era == "all") {
    plotRatio("2011");
    plotRatio("2012");
    plotRatio("2016BF");
    plotRatio("2016GH");
    return;
  }


  TH1D *hresult = new TH1D("hresult", Form("n(gauss(5.28))/n(gauss(5.37)) %s", era.c_str()), 40, 0., 0.4);
  hresult->GetXaxis()->SetTitle("BDT > ");
  TH1D *hbdtcut = new TH1D("hbdtcut", Form("n(gauss(5.28))/n(gauss(5.37)) %s", era.c_str()), 40, 0., 0.4);
  hbdtcut->SetMarkerColor(kBlue);
  invertedMuonID(era, 0.15, hresult);
  invertedMuonID(era, 0.20, hresult);
  invertedMuonID(era, 0.25, hresult);
  invertedMuonID(era, 0.30, hresult);
  invertedMuonID(era, -99., hbdtcut);

  c0->Clear();
  double ymax(50.);
  if (hresult->GetMaximum() < 5.)  ymax = 10.;
  if (hresult->GetMaximum() < 0.5) ymax = 1.0;
  hresult->SetMinimum(-ymax);
  hresult->SetMaximum(ymax);
  hresult->Draw();
  hbdtcut->Draw("same");
  pl->DrawLine(0., 0., 0.4, 0.);
  c0->SaveAs(Form("invertedMuonID-%s-result.pdf", era.c_str()));
}
Beispiel #6
0
bool DrawPileupCorr(Str jetAlgo) {
  JetCalibrationTool *theJES = new JetCalibrationTool(jetAlgo,_jesFile,false);
  bool residual = theJES->JetAreaJES();

  TH1D *temp = new TH1D("","",100,-5,5);
  temp->SetXTitle("Jet #eta"); temp->SetYTitle("Jet offset at "+GetConstScale(jetAlgo)+"-scale [GeV]");
  if (residual) temp->SetYTitle("Residual jet offset at "+GetConstScale(jetAlgo)+"-scale [GeV]");
  temp->SetMinimum(-20); temp->SetMaximum(15); temp->SetStats(0);
  if ( residual && theJES->ResidualOffsetCorr_Description() == "" ) return false;
  Can->Clear(); temp->Draw();
  for (int npv=0;npv<9;++npv) {
    double NPV=(npv%3)*10, mu=(npv/3)*10;
    if (NPV==0) NPV=1;
    Graph *g = new Graph();
    FormatGraph(g,npv);
    for (int ieta=-50;ieta<50;++ieta) {
      double eta=0.05 + 0.1*ieta;
      double O = residual ? theJES->GetResidualOffset(eta,mu,NPV)/1000 :
	theJES->GetOffset(eta,mu,NPV)/1000; // convert to GeV
      g->SetPoint(g->GetN(),eta,O);
    }
    if (npv<4) DrawLabel(Form("N_{PV} = %.0f, #LT#mu#GT = %.0f",NPV,mu),0.18,0.35-0.04*npv,npv);
    else DrawLabel(Form("N_{PV} = %.0f, #LT#mu#GT = %.0f",NPV,mu),0.48,0.35-0.04*(npv-4),npv);
    
    g->Draw("P");
  }
  tex->SetNDC(); tex->SetTextAlign(12);
  if (residual)
    tex->DrawLatex(0.18,0.975,theJES->ResidualOffsetCorr_Description());
  else 
    tex->DrawLatex(0.18,0.975,theJES->OffsetCorr_Description());
  tex->DrawLatex(0.18,0.9,GetJetDesc(jetAlgo));
  return true;
}
void drawDum(float min, float max, double drawXLabel){

   TH1D *hdum = new  TH1D("h","",10,120,220);
  hdum->SetMaximum(max);

  hdum->SetStats(0);

  if(drawXLabel) hdum->SetXTitle("(p_{T}^{j1}-p_{T}^{j2})/(p_{T}^{j1}+p_{T}^{j2})");
  hdum->GetXaxis()->SetLabelSize(20);
  hdum->GetXaxis()->SetLabelFont(43);
  hdum->GetXaxis()->SetTitleSize(22);
  hdum->GetXaxis()->SetTitleFont(43);
  hdum->GetXaxis()->SetTitleOffset(1.5);
  hdum->GetXaxis()->CenterTitle();

  hdum->GetXaxis()->SetNdivisions(905,true);

  hdum->SetYTitle("Event Fraction");

  hdum->GetYaxis()->SetLabelSize(20);
  hdum->GetYaxis()->SetLabelFont(43);
  hdum->GetYaxis()->SetTitleSize(20);
  hdum->GetYaxis()->SetTitleFont(43);
  hdum->GetYaxis()->SetTitleOffset(2.5);
  hdum->GetYaxis()->CenterTitle();

  hdum->SetAxisRange(0,0.2,"Y");

  hdum->Draw("");

}
//--------------------------------------------------------------------------------------------------
void plotFrame(Double_t xMin, Double_t xMax, Double_t maxRate)
{
  // Make a good frame
  TH1D * h = new TH1D("tmp","Time Series of Rates",1,xMin,xMax);
  MitRootStyle::InitHistWide(h,"","",kBlack);  
  h->SetTitle("; Epoch Time [sec]; SmartCache transfer rate [MB/sec]");
  h->SetMaximum(maxRate*1.2);
  h->Draw("hist");
}
Beispiel #9
0
// ----------------------------------------------------------------------
void plotRatioRaw(string era = "2016BF") {
  gStyle->SetOptStat(0);

  if (era == "all") {
    plotRatioRaw("2011");
    plotRatioRaw("2012");
    plotRatioRaw("2016BF");
    plotRatioRaw("2016GH");
    return;
  }


  double eps(0.00001);
  TH1D *hresult = new TH1D("hresult", Form("%s", era.c_str()), 80, 0., 0.4);
  hresult->GetXaxis()->SetTitle("BDT > ");
  hresult->SetMarkerStyle(24); hresult->SetLineColor(kRed+2); hresult->SetMarkerColor(kRed+2);
  TH1D *hsresult = new TH1D("hsresult", Form("%s", era.c_str()), 80, 0.+eps, 0.4+eps);
  hsresult->SetMarkerStyle(25); hsresult->SetLineColor(kBlue);  hsresult->SetMarkerColor(kBlue);

  TH1D *hbdtcut = new TH1D("hbdtcut", Form("%s", era.c_str()), 80, 0., 0.4);
  hbdtcut->SetMarkerColor(kRed+2);  hbdtcut->SetMarkerStyle(20);
  TH1D *hsbdtcut = new TH1D("hsbdtcut", Form("%s", era.c_str()), 80, 0.+eps, 0.4+eps);
  hsbdtcut->SetMarkerColor(kBlue);  hsbdtcut->SetMarkerStyle(21);

  invertedMuonIDRaw(era, 0.15, hresult, hsresult);
  invertedMuonIDRaw(era, 0.20, hresult, hsresult);
  invertedMuonIDRaw(era, 0.25, hresult, hsresult);
  invertedMuonIDRaw(era, 0.30, hresult, hsresult);
  invertedMuonIDRaw(era, -99., hbdtcut, hsbdtcut);

  c0->Clear();
  double ymax(50.);
  double smax = hresult->GetMaximum();
  double dmax = hsresult->GetMaximum();
  double themax = (smax>dmax? smax: dmax);
  if (themax < 50.)  ymax = 50.;
  if (themax < 20.)  ymax = 30.;
  if (themax < 5.)  ymax = 10.;
  if (themax < 0.5) ymax = 1.0;
  hresult->SetMinimum(-ymax);
  hresult->SetMaximum(ymax);
  hresult->Draw();
  hsresult->Draw("same");
  hbdtcut->Draw("same");
  hsbdtcut->Draw("same");
  pl->DrawLine(0., 0., 0.4, 0.);

  TLegend *tle = new TLegend(0.25, 0.2, 0.50, 0.5);
  tle->SetFillStyle(0);
  tle->SetBorderSize(0);
  tle->SetHeader(era.c_str());
  tle->AddEntry(hresult, "yield at B0", "p");
  tle->AddEntry(hsresult, "yield at Bs", "p");
  tle->Draw();

  c0->SaveAs(Form("invertedMuonIDRaw-%s-result.pdf", era.c_str()));
}
//--------------------------------------------------------------------------------------------------
void plotFrame(Double_t xMin, Double_t xMax, Double_t max)
{
  // Make a good frame
  TH1D * h = new TH1D("tmp","Time Series of Failures",1,xMin,xMax);
  MitStyle::InitHistWide(h,"","",kBlack);
  h->SetTitle("; Epoch Time [sec]; SmartCache Failures / 90 sec");
  h->SetMaximum(max*1.2);
  h->Draw("hist");
}
Beispiel #11
0
void plotTurnOn(TTree* inttree, TString triggerpass, TString variable, TString varname, TString varlatex)
{
  if(varname=="vtxprob")
    {
      BIN_MIN = 0;
      BIN_MAX = 1;
    }
  else if(varname=="ffls3d")
    {
      BIN_MIN = 0;
      BIN_MAX = 50;
    }
  else if(varname=="cosalpha")
    {
      BIN_MIN = 0.9;
      BIN_MAX = 1;
    }
  TH1D* hAll = new TH1D(Form("h%s_%s_All",triggerpass.Data(),varname.Data()),Form(";%s;Probability",varlatex.Data()),BIN_NUM,BIN_MIN,BIN_MAX);
  inttree->Project(Form("h%s_%s_All",triggerpass.Data(),varname.Data()),variable,prefilter);
  TH1D* hMBseed = new TH1D(Form("h%s_%s_MBseed",triggerpass.Data(),varname.Data()),Form(";%s;Probability",varlatex.Data()),BIN_NUM,BIN_MIN,BIN_MAX);
  inttree->Project(Form("h%s_%s_MBseed",triggerpass.Data(),varname.Data()),variable,Form("%s&&%s",prefilter.Data(),triggerpass.Data()));
  //cout<<hAll->Integral()<<endl;
  hAll->Scale(1./hAll->Integral());
  hMBseed->Scale(1./hMBseed->Integral());
  hAll->SetStats(0);
  hMBseed->SetStats(0);
  hAll->SetMaximum(hMBseed->GetMaximum()*1.3);
  hAll->SetLineWidth(2);
  hAll->SetLineColor(kBlue-7);
  hAll->SetFillColor(kBlue-7);
  hAll->SetFillStyle(3001);
  hMBseed->SetLineWidth(2);
  hMBseed->SetLineColor(kRed);
  hMBseed->SetFillColor(kRed);
  hMBseed->SetFillStyle(3004);
  TCanvas* c = new TCanvas(Form("c%s_%s",triggerpass.Data(),varname.Data()),"",500,500);
  hAll->Draw();
  hMBseed->Draw("same");
  TLatex* tex = new TLatex(0.18,0.96,triggerpass);
  tex->SetNDC();
  tex->SetTextFont(42);
  tex->SetTextSize(0.04);
  tex->Draw();
  TLegend* leg = new TLegend(0.60,0.82,0.92,0.93);
  leg->SetFillStyle(0);
  leg->SetBorderSize(0);
  leg->AddEntry(hAll,"all","f");
  leg->AddEntry(hMBseed,"pass trigger","f");
  leg->Draw();
  c->SaveAs(Form("triggerturnonPlots/pthat%.0f/c%s_%s.pdf",pthat,triggerpass.Data(),varname.Data()));

}
Beispiel #12
0
// ----------------------------------------------------------------------
void plotRatio2Comb(string era = "2016BF") {
  gStyle->SetOptStat(0);

  if (era == "all") {
    plotRatio2Comb("2011");
    plotRatio2Comb("2012");
    plotRatio2Comb("2016BF");
    plotRatio2Comb("2016GH");
    return;
  }

  double eps(0.00001);
  TH1D *hresultBd = new TH1D("hresultBd", era.c_str(), 80, 0., 0.4);
  TH1D *hresultBs = new TH1D("hresultBs", era.c_str(), 80, 0.+eps, 0.4+eps);
  hresultBd->GetYaxis()->SetTitle("a.u.");
  hresultBd->GetXaxis()->SetTitle("BDT > "); hresultBd->SetMarkerStyle(24); hresultBd->SetLineColor(kRed+2); hresultBd->SetMarkerColor(kRed+2);
  hresultBs->GetXaxis()->SetTitle("BDT > "); hresultBs->SetMarkerStyle(25); hresultBs->SetLineColor(kBlue);  hresultBs->SetMarkerColor(kBlue);
  TH1D *hbdtcutBd = new TH1D("hbdtcutbd", "", 80, 0., 0.4);
  TH1D *hbdtcutBs = new TH1D("hbdtcutBs", "", 80, 0.+eps, 0.4+eps);
  hbdtcutBs->SetMarkerColor(kBlue);  hbdtcutBd->SetMarkerStyle(24); hbdtcutBs->SetLineColor(kBlue);
  hbdtcutBd->SetMarkerColor(kRed+2); hbdtcutBd->SetMarkerStyle(25); hbdtcutBd->SetLineColor(kRed+2);

  invertedMuonID2Comb(era, 0.15, hresultBd, hresultBs);
  invertedMuonID2Comb(era, 0.20, hresultBd, hresultBs);
  invertedMuonID2Comb(era, 0.25, hresultBd, hresultBs);
  invertedMuonID2Comb(era, 0.30, hresultBd, hresultBs);
  invertedMuonID2Comb(era, -99., hbdtcutBd, hbdtcutBs);

  c0->Clear();
  double ymax(5.);
  hresultBd->SetMinimum(-ymax);
  hresultBd->SetMaximum(ymax);
  hresultBd->Draw();
  hbdtcutBd->Draw("same");
  pl->DrawLine(0., 0., 0.4, 0.);

  tl->SetTextSize(0.035);
  tl->SetTextColor(kRed+2); tl->DrawLatexNDC(0.2, 0.85, "n(gauss(5.28))/combinatorial");
  tl->SetTextColor(kBlue);  tl->DrawLatexNDC(0.2, 0.81, "n(gauss(5.37))/combinatorial");
  tl->SetTextColor(kBlack);

  hresultBs->Draw("same");
  hbdtcutBs->Draw("same");

  c0->SaveAs(Form("invertedMuonID2Comb-%s-result.pdf", era.c_str()));

}
Beispiel #13
0
//========================
void PlotRatio1D(Int_t iEff, Int_t iVar){

  Char_t name[100];
  sprintf(name, "c1_%sEff_%s", effName[iEff], varName[iVar]);
  TCanvas *c1 = new TCanvas(name, name);

  sprintf(name, "hRatio_%sEff_%s", effName[iEff], varName[iVar]);
  TH1D *hRatio = (TH1D *) hEffTP[iEff][iVar]->Clone(name);
  hRatio->Divide(hEffMCTruth1D[iEff][iVar]);
  hRatio->SetMarkerStyle(20);
  hRatio->SetMinimum(0.);
  hRatio->SetMaximum(1.5);
  hRatio->Draw("p");

  sprintf(name, "Figures/ratio_%sEff_%s.pdf", effName[iEff], varName[iVar]);
  c1->Print(name);
}
TH1D* GetDummyHist(Float_t xmax, Float_t min, Float_t max,Char_t *xttl,Char_t *yttl) {

    TH1D *dum;
    dum = new TH1D("dum","",100,0.0,xmax);
    //dum = new TH1D("dum","",100,0.2,xmax);

    dum->SetMinimum(min);
    dum->SetMaximum(max);
    dum->SetStats(0);

    dum->GetYaxis()->SetTitle(yttl);
    dum->GetYaxis()->CenterTitle();
    dum->GetXaxis()->SetTitle(xttl);
    dum->GetXaxis()->CenterTitle();

    return dum;

}
Beispiel #15
0
void CompareBranch(string MCfilename, string CDfilename, string MCbranchname, string CDbranchname, string xtitle, string unit, string plotname, string MCcuts, string CDcuts, string MCweight, string CDweight, double xlow, double xup, int nbins)
{
  TH1D*  MChist = MakeBranchPlot(MCfilename,MCbranchname,MCcuts,MCweight,xlow,xup,nbins);
  TH1D*  CDhist = MakeBranchPlot(CDfilename,CDbranchname,CDcuts,CDweight,xlow,xup,nbins);
  MChist->Scale(1./MChist->Integral());
  CDhist->Scale(1./CDhist->Integral());
  MChist->SetDrawOption("B");
  MChist->SetFillColor(kOrange);
  MChist->SetLineColor(kOrange);
  MChist->SetMaximum(MChist->GetMaximum()*1.3);
  MChist->SetMinimum(0);
  // Draw everything
  plotmaker plotter(MChist);
  plotter.SetTitle(xtitle, unit);
  TCanvas* plot = plotter.Draw();
  CDhist->Draw("sameE1");
  plot->SaveAs((plotname+".pdf").c_str());
}
TH1D *HistoRatio (TH1D *hisNum, TH1D *hisDen){

  //Graph Ratio Clone
  TH1D *Ratio;
  Ratio = (TH1D*)hisNum->Clone();
  Ratio->Divide(hisDen);

  for(int ibin=1;ibin<=Ratio->GetNbinsX();ibin++) {
    if (Ratio->GetBinContent(ibin) == 0.0 ) {
      Ratio->SetBinContent(ibin, 1.0);
      Ratio->SetBinError(ibin, 0.0);
    }
  }

  Ratio->SetFillColor(0);
  Ratio->SetLineColor(kGray+2);
  // Ratio->SetLineColor(kMagenta-5);
  Ratio->SetLineWidth(1);
  Ratio->SetTitle("");
  
  Ratio->GetYaxis()->SetTitle("Obs/Exp");
  Ratio->GetYaxis()->CenterTitle();
  Ratio->GetYaxis()->SetTitleFont(42);
  Ratio->GetYaxis()->SetTitleSize(0.135);
  Ratio->GetYaxis()->SetTitleOffset(0.28);
  Ratio->GetYaxis()->SetLabelFont(42);
  Ratio->GetYaxis()->SetLabelSize(0.115);
  Ratio->GetYaxis()->SetNdivisions(402);
  
  Ratio->GetXaxis()->SetTitle("CSVv2 bin"); 
  Ratio->GetXaxis()->SetNdivisions(509); //(402)
  Ratio->GetXaxis()->SetTitleOffset(1.1);
  Ratio->GetXaxis()->SetTitleFont(42);
  Ratio->GetXaxis()->SetTitleSize(0.16);
  Ratio->GetXaxis()->SetTitleFont(42);
  Ratio->GetXaxis()->SetLabelSize(0.14);
  
  Ratio->SetMinimum(0.4);
  Ratio->SetMaximum(1.6);

  return Ratio;  

}
Beispiel #17
0
TH1D* momResHist(TFile* f, int i) {

  Double_t xbins[33] = {0,0.2,0.4,0.6,0.8,
			1.0,1.6,2.2,2.8,3.4,
			4.4,5.4,6.0,8.0,10.0,
			12.0,14.0,18.0,22.0,26.0,
			30.0,36.0,42.0,50.0,55.0,
			60.0,70.0,80.0,100.0,120.0,
			140.0,160.0,200.0};

  TH3F *hRes3D = (TH3F*) f->Get("trkEffAnalyzer/hresStoR3D");
  
  double feta = 2.4;
  int binMaxEta = hRes3D->GetXaxis()->FindBin(feta);
  int binMinEta = hRes3D->GetXaxis()->FindBin(-1.0*feta);

  hRes3D->GetXaxis()->SetRange(binMinEta,binMaxEta);
  TH2D *hRes2D = (TH2D*) hRes3D->Project3D("zy");  // zy: rec-> y axis, sim -> x axis
  hRes2D->SetName("hRes2D");

  hRes2D->FitSlicesY(0,0,-1,10);

  TH1D *h1 = (TH1D*)gDirectory->Get("hRes2D_1");
  TH1D *h2 = (TH1D*)gDirectory->Get("hRes2D_2");

  h1->Rebin(32,Form("h1new%d",i),xbins);
  h2->Rebin(32,Form("h2new%d",i),xbins);
  TH1D* h1new = (TH1D*) gDirectory->Get(Form("h1new%d",i));
  TH1D* h2new = (TH1D*) gDirectory->Get(Form("h2new%d",i));


  TH1D *momres = (TH1D*) h2new->Clone("momres");
  momres->SetName(Form("momres_%d",i));
  momres->SetMaximum(0.15); momres->SetMinimum(0.0);
  momres->SetTitle("Momentum resolution;p_{T} [GeV/c]");
  momres->SetStats(0);
  momres->SetMarkerStyle(20);
  momres->Divide(h1new);

  return momres;

}
Beispiel #18
0
void draw_graphs(void)
{
	const char title[4][20] = {"Na_mean;um", "Na_sigma;um", "Co_mean;um", "Co_sigma;um"};
	const double tgt[4] = {1.787, 0.394, 2.082, 0.473};
	const double mc[4][4] = {{2.008, 1.985, 1.974, 1.933}, {0.319, 0.326, 0.330, 0.336}, 
		{2.233, 2.211, 2.185, 2.149}, {0.377, 0.385, 0.394, 0.405}};
	const double dl[4] = {0, 50, 100, 200};
	const double mm[4][2] = {{1.7, 2.1}, {0.3, 0.4}, {2.0, 2.3}, {0.35, 0.5}};
	TGraph *gr;
	TLine *ln;
	TH1D *h;
	TLegend *lg;
	int i;
	
	TCanvas *cv = new TCanvas;
	cv->Divide(2,2);
	gr = new TGraph;
	ln = new TLine;
	gr->SetMarkerStyle(kFullCircle);
	gr->SetMarkerSize(1.5);
	gr->SetMarkerColor(kBlue);
	ln->SetLineWidth(4);
	ln->SetLineColor(kRed);
	lg = new TLegend(0.65, 0.65, 0.95, 0.85);
	lg->AddEntry(ln, "Exp.", "L");
	lg->AddEntry(gr, "MC", "P");
	for (i=0; i<4; i++) {
		cv->cd(i+1);
		
		h = new TH1D(title[i], title[i], 100, 0, 200);
		h->SetMinimum(mm[i][0]);
		h->SetMaximum(mm[i][1]);
		h->DrawCopy();
		gr->DrawGraph(4, dl, mc[i], "P");
		ln->DrawLine(0, tgt[i], 200, tgt[i]);
		lg->Draw();
		delete h;
	}
}
Beispiel #19
0
void plotTheory(TString name)
{
	_DEBUG("void plotTheory(TString name)");
	
	TFile* fTheory = new TFile("/srv01/tau/hod/z0analysis-tests/z0analysis-r170/run/plots/theory_mass1000GeV_withpdf_histos.root","READ");
	
	TH1D* hmassTheory = NULL;
	TH1D* hAfbTheory  = NULL;

	TString model = "";
	if     (name.Contains("DY"))     model = "DY";
	else if(name.Contains("ZP_ssm")) model = "ZP";
	else if(name.Contains("ZP_psi")) model = "E6_psi";
	else if(name.Contains("ZP_chi")) model = "E6_chi";
	else if(name.Contains("ZP_eta")) model = "E6_eta";
	else if(name.Contains("KK"))     model = "KK";
	
	hmassTheory = (TH1D*)fTheory->Get("h1Sumq"+model)->Clone("hmassTheory");
	hAfbTheory  = (TH1D*)fTheory->Get("h1AfbSumq"+model)->Clone("hAfbTheory");
	
	hmassTheory->SetLineColor(kOrange+2);
	// for(Int_t b=1 ; b<=hmassTheory->GetNbinsX() ; b++) hmassTheory->SetBinContent(b, hmassTheory->GetBinContent(b)*hmassTheory->GetBinCenter(b));
	TCanvas* cnv_mass_ratio = hratio("cnv_mass_ratio", hmassTheory, h1Map["hMass"+name], NULL,"Ratio", true,true);
	saveas(cnv_mass_ratio,"plots/"+name+"_mass_ratio_withTheory"+sRunNum);
	
	TCanvas* cnv_afb = new TCanvas("cnv_afb","cnv_afb",600,400);
	cnv_afb->SetTicks(1,1);
	cnv_afb->SetLogx();
	cnv_afb->cd();
	cnv_afb->Draw();
	hAfbTheory->SetLineColor(kOrange+2);
	hAfbTheory->SetMinimum(-1.);
	hAfbTheory->SetMaximum(+1.);
	hAfbTheory->Draw();
	h1Map["hMassAFB_QRK"+name]->Draw("SAMES");
	saveas(cnv_afb,"plots/"+name+"_Afb_withTheory"+sRunNum);
}
Beispiel #20
0
void compareGen(std::string mcfile1, std::string mcfile2, 
		std::string var1, std::string var2="",
		std::string xtitle, 
		std::string output="test",
		std::string header="Z(#rightarrow ee)+#geq 1 jet",
		std::string mcName1="Data",
		std::string mcName2="Madgraph",
		float xmin=-9999.0, float xmax=-9999.0,
		bool logScale=true
		)
{
  
  setTDRStyle();
  gStyle->SetOptStat(0);

  TH1F* h1;
  TH1F* h2;

  char tempName[300];
  if(var2 ==  "" )var2=var1;
  
  // first get the histogram files
  TFile *fmc1 = TFile::Open(mcfile1.data());
  TFile *fmc2   = TFile::Open(mcfile2.data());

  h1  = (TH1F*)(fmc1->Get(var1.data()));
  h2    = (TH1F*)(fmc2->Get(var2.data()));

  TH1D* hscale =(TH1D*) h1->Clone("hscale");
  hscale->SetYTitle(Form("%s/%s",mcName1.data(),mcName2.data()));

  h1->GetXaxis()->SetNdivisions(5);
  h1->GetYaxis()->SetDecimals();

  h2->GetXaxis()->SetNdivisions(5);
  h2->GetYaxis()->SetDecimals();

  hscale->GetXaxis()->SetNdivisions(5);
  hscale->GetYaxis()->SetDecimals();


  h1->SetLineColor(2);
  h1->SetMarkerColor(2);
  h1->SetMarkerSize(1);
  h1->SetMarkerStyle(24);


  h2->SetLineColor(4);
  h2->SetMarkerColor(4);
  h2->SetMarkerSize(1);
  h2->SetMarkerStyle(21);

  // if normalizing to the same area, set the scale 

  int binLo = -1;
  int binHi = -1;
  int nbins = h1->GetNbinsX();
  if(xmin>-9999.0 && xmax>-9999.0)
    {

      binLo = h1->FindBin(xmin);
      binHi = h1->FindBin(xmax)-1;

    }

  else
    {
      binLo = 1;
      binHi = nbins;
      xmin = h1->GetBinLowEdge(1);
      xmax = h1->GetBinLowEdge(nbins+1);
    }


  float scale_mc = (float)h1->Integral(binLo,binHi)/(float)h2->Integral(binLo,binHi);
//   cout << "binLo = " << binLo << ", binHi = " << binHi << endl;
//    cout << "xmin = " << xmin << "xmax = " << xmax << endl;

//   h2->Sumw2();
// //   scale_mc = 1000.0*4.890*3048.0/2.29809910000000000e+07;
//   h2->Scale(scale_mc);

  cout << "h2 integral = " << h2->Integral() << endl;
  cout << "h1 integral = "   << h1->Integral() << endl;;

  // get the ratio
  double chi2 = 0;
  int realbin = 0;
  for(int i=1;i<= nbins;i++){

    double nmc=h2->GetBinContent(i);
    double ndata=h1->GetBinContent(i); 
    double nmcerr=h2->GetBinError(i);
    double ndataerr=h1->GetBinError(i); 
    
    if(nmc<0 || ndata<0)continue;    
    
    if(nmcerr==0 && ndataerr==0)continue;

    if(nmc==0 && ndata==0)continue;

    double chi2ndef = (nmc-ndata)*(nmc-ndata)/
      ( nmcerr*nmcerr+ ndataerr*ndataerr);
    chi2 += chi2ndef;
    realbin++;

    cout << "Bin " << i << " : " << ndata << ", " << nmc;
    cout << " " << chi2ndef << endl;


    // now calculate the ratio
    if(nmc==0 || nmcerr==0 || ndata==0 || ndataerr==0)
      {
	hscale->SetBinContent(i,-9999);
	hscale->SetBinError(i,1e-4);
	continue;
      }

    cout << "Bin " << i << " ratio = " << ndata/nmc << endl;
    hscale->SetBinContent(i,ndata/nmc);
    double err = 0;
    err=
      (ndata/nmc)*sqrt(pow(nmcerr/nmc,2)+pow(ndataerr/ndata,2));
    hscale->SetBinError(i,err);

  }

  for(int i=1;i<=hscale->GetNbinsX();i++)
    cout << i << ": " << hscale->GetBinContent(i) << endl;

  h1->GetXaxis()->SetRangeUser(xmin,xmax);
  h2->GetXaxis()->SetRangeUser(xmin,xmax);
  hscale->GetXaxis()->SetRangeUser(xmin,xmax);


  TCanvas* c1 = new TCanvas("c1","",700,1000);  
  c1->Divide(1,2,0.01,0);
  c1->cd(1);
  if(logScale)
    gPad->SetLogy(1);
  gPad->SetTopMargin(0.01);
  gPad->SetBottomMargin(0);
  gPad->SetRightMargin(0.04);

  
  float max_data  = h1->GetBinError(h1->GetMaximumBin()) + h1->GetMaximum();
  float max_mc    = h2->GetBinError(h2->GetMaximumBin()) + h2->GetMaximum();

  if(max_data > max_mc)
    {
      h1->Draw("e");
      h2->Draw("hesame");
    }
  else
    { h2->Draw("he");
      h1->Draw("esame");
    }


  float x1NDC = 0.725;
  float y1NDC = 0.615;
  float x2NDC = 0.928;
  float y2NDC = 0.951;

  TLegend* leg = new TLegend(x1NDC,y1NDC,x2NDC,y2NDC);
  
  leg->SetHeader(header.data());
  leg->SetFillColor(0);
  leg->SetFillStyle(0);
  leg->SetTextSize(0.04);
  leg->SetBorderSize(0);
  leg->AddEntry(h1, mcName1.data());
  leg->AddEntry(h2, mcName2.data());
  leg->Draw("same");



  c1->cd(2);
  gStyle->SetStatW       (0.3);
  gStyle->SetStatH       (0.3);
  gStyle->SetStatX       (0.879447);
  gStyle->SetStatY       (0.939033);
  gStyle->SetStatFontSize(0.05);
  gStyle->SetStatBorderSize(0);
  gPad->SetRightMargin(0.04);
  gPad->SetTopMargin(0);
  gPad->SetBottomMargin(0.2);
  gPad->SetTickx();
  gStyle->SetOptFit(1);
  hscale->SetTitle("");
  hscale->GetXaxis()->SetTitle(xtitle.data());
//   hscale->SetMaximum(3.0);
//   hscale->SetMinimum(0.1);
  hscale->SetMaximum(2.0);
  hscale->SetMinimum(0.5);
  hscale->SetTitleOffset(1.2,"Y");
  hscale->Draw("e1");
  TF1* fline = new TF1("fline","pol1");
  TLine* l2 = new TLine(xmin,1.,xmax,1.);
  l2->SetLineColor(4);
  l2->SetLineStyle(3);
  fline->SetLineWidth(3);
  fline->SetLineColor(6);
  fline->SetNpx(2500);
//   hscale->Fit("fline","","");
  l2->Draw("same");


  string dirName = "compareGen";
  gSystem->mkdir(dirName.data());

  std::string filename;
  std::string psname = dirName + "/" + var1;
  if(output !="test")
    psname = dirName+ "/" + output;
  else
    psname = dirName+ "/" + var1;
  filename = psname + ".eps";
  c1->Print(filename.data());
  filename = psname + ".gif";
  c1->Print(filename.data());
  filename = psname + ".pdf";
  c1->Print(filename.data());
  //   c1->Close();
}
Beispiel #21
0
void plotr0vstheta(){
	TFile *f;
        int isSum=0;
        const int ntotbin=5;
        const int trkpointmin[ntotbin] = {120,150,185,220,260};
        const int trkpointmax[ntotbin] = {150,185,220,260,300};
	int xbin=0;
        c1 = new TCanvas("c1"," ",1200,700);
        makeMultiPanelCanvas(c1,3,2,0,0,0.25,0.2,0.03);
        gStyle->SetOptFit(1);
        gStyle->SetOptStat(0);
        gStyle->SetOptTitle(0);
        gStyle->SetErrorX(0);
        TH1D *hFrame = new TH1D("","",100,0,2);
        hFrame->SetTitle("");
        hFrame->GetXaxis()->SetTitle("#theta");
        hFrame->GetYaxis()->SetTitle("r_{0}");
        hFrame->GetYaxis()->SetTitleOffset(1.1);
        hFrame->GetXaxis()->SetTitleSize(0.04);
        hFrame->GetYaxis()->SetTitleSize(0.04);
        hFrame->GetXaxis()->SetRangeUser(0,1.5);
        hFrame->SetMinimum(0.04);
        hFrame->SetMaximum(0.25);
        for(int trkbin=0;trkbin<ntotbin; trkbin++){
	if(isSum==0){
	    f = TFile::Open(Form("M%d%d/mergedV_Prod.root",trkpointmax[trkbin],trkpointmin[trkbin]));
	}
	else{
	    f = TFile::Open(Form("M%d%d/mergedV_Sum.root",trkpointmax[trkbin],trkpointmin[trkbin]));
	}
	TVectorD* vecr0 = (TVectorD*)f->Get(Form("D_%d/D_0/r0",xbin));

        double *r0 = vecr0->GetMatrixArray();
        double r0mean = getmean(r0,ntheta);
        double theta[ntheta];
        for(int itheta=0;itheta<ntheta;itheta++){
            theta[itheta]=itheta*TMath::Pi()/ntheta/nn;
        }
        int maxper10 = findmaxper(r0,ntheta,r0mean);
        double maxper = (double)(maxper10+1)/10;
        c1->cd(trkbin+1);
        hFrame->Draw();
        TGraph *gr0theta = new TGraph(ntheta,theta,r0);
        gr0theta->SetMarkerStyle(20);
        gr0theta->SetMarkerSize(1.3);
        gr0theta->SetMarkerColor(1);
        gr0theta->SetLineColor(1);
	gr0theta->Draw("Psame");
        TLine *lup = new TLine(gr0theta->GetXaxis()->GetXmin(),r0mean*(1+maxper), gr0theta->GetXaxis()->GetXmax(),r0mean*(1+maxper));
        TLine *ldown = new TLine(gr0theta->GetXaxis()->GetXmin(),r0mean*(1-maxper), gr0theta->GetXaxis()->GetXmax(),r0mean*(1-maxper));
        TLine *l = new TLine(hFrame->GetXaxis()->GetXmin(),r0mean, hFrame->GetXaxis()->GetXmax(),r0mean);
        l->SetLineStyle(2);
        lup->SetLineStyle(2);
        ldown->SetLineStyle(2);
        l->SetLineWidth(1.2);
        lup->SetLineWidth(1.2);
        ldown->SetLineWidth(1.2);
        TLatex *tl = new TLatex();
 //     tl->SetNDC();
        tl->SetTextFont(42);
        tl->SetTextSize(0.04);
 //     tl->SetBorderStyle(0);
        tl->DrawLatex(0,r0mean*(1+maxper),Form("mean up %.f%%",maxper*100));
        tl->DrawLatex(0,r0mean*(1-maxper),Form("mean down %.f%%",maxper*100));
        tl->SetNDC();
        tl->DrawLatex(0.7,0.85,Form("Multiplicity %d to %d",trkpointmin[trkbin],trkpointmax[trkbin]));
        l->Draw("same");
        lup->Draw("same");
        ldown->Draw("same");
        }
        c1->cd(ntotbin+1);
        TLatex *tlx0 = new TLatex(0.12,0.3,Form("PF candidate"));
        TLatex *tlx1 = new TLatex(0.12,0.25,Form("%.1f<p_{T}<%.1f (GeV/c)",0.3,6.0));
        tlx0->SetNDC();
        tlx1->SetNDC();
        tlx0->SetTextSize(0.045);
        tlx1->SetTextSize(0.045);
        hFrame->Draw();
        tlx0->Draw("same");
        tlx1->Draw("same");
	if(isSum==0)c1->SaveAs("hr0theta_Prod.png");
	else c1->SaveAs("hr0theta_Sum.png");
}
Beispiel #22
0
void etaPlotter(){

  double HFbins[6] = {0,10,15,20,30,70};
  double multBins[7] = {0,35,60,90,110,150,1000};
  
  TFile *f0 = new TFile("FullForest_v77_etaLT3_akPu3PF.root","OLD");
  if(!f0){ cout << "You don't have this jet collection yet!!" << endl; exit(0);}
  TTree *dijetTree = (TTree*)f0->Get("dijetTree");

  TFile *f2 = new TFile("PythiaPP_MC_akPu3PF.root","OLD");
  TTree *ppTree = (TTree*)f2->Get("dijetTree");

  TFile *f3 = new TFile("YaxianPPData_etaLT3_akPu3PF.root","OLD");
  TTree *ppDatTree = (TTree*)f3->Get("dijetTree");
  
  TFile *f4 = new TFile("PythiaMIT_out_v77_etaLT3_akPu3PF.root","OLD");
  TTree *mcTree = (TTree*)f4->Get("dijetTree");

  TFile *f5 = new TFile("PbPb_ReReco_Full_etaLT3_akPu3PF.root","OLD");
  TTree *pbpbtree = (TTree*)f5->Get("dijetTree");

  TH1D *etaDistropPb[6];
  TH1D *etaDistroppData[6];
  TH1D *etaDistroppMC[6];
  TH1D *etaDistropPbMC[6];
  TH1D *etaDistroPbPb[6];

  TH2D *avgEtapPb[3];
  TH2D *avgEtapp[3];
  TH2D *avgEtapPbMC[3];
  TH2D *avgEtappMC[3];

  char* histoname = new char[30];
  char* histotitle = new char[50];
  for(int i=0; i<6; i++){
    sprintf(histoname,"%s%d","etaDistropPb_",i+1);
    sprintf(histotitle,"%s%d","Dijet Eta distro, HF bin",i+1);
    if(i==5){ sprintf(histoname,"%s%d","etaDistropPb_",0); sprintf(histotitle,"%s%d","Dijet Eta distro, HF bin",0); }
    etaDistropPb[i] = new TH1D(histoname,histotitle,12,-3,3);
    etaDistropPb[i]->Sumw2();
    sprintf(histoname,"%s%d","etaDistroppData_",i);
    etaDistroppData[i] = new TH1D(histoname,"",12,-3,3);
    etaDistroppData[i]->Sumw2();
    etaDistroppData[i]->SetMarkerColor(2);
    etaDistroppData[i]->SetLineColor(2);
    sprintf(histoname,"%s%d","etaDistroppMC_",i);
    etaDistroppMC[i] = new TH1D(histoname,"",12,-3,3);
    etaDistroppMC[i]->Sumw2();
    etaDistroppMC[i]->SetMarkerColor(4);
    etaDistroppMC[i]->SetLineColor(4);
    sprintf(histoname,"%s%d","etaDistropPbMC_",i);
    etaDistropPbMC[i] = new TH1D(histoname,"",12,-3,3);
    etaDistropPbMC[i]->Sumw2();
    etaDistropPbMC[i]->SetMarkerColor(8);
    etaDistropPbMC[i]->SetLineColor(8);
    sprintf(histoname,"%s%d","etaDistroPbPb_",i);
    etaDistroPbPb[i] = new TH1D(histoname,"",12,-3,3);
    etaDistroPbPb[i]->Sumw2();
    etaDistroPbPb[i]->SetMarkerColor(8);
    etaDistroPbPb[i]->SetLineColor(8);
  }
  for(int i=0; i<3; i++){
    sprintf(histoname,"%s%d","avgEtapPb_",i);
    avgEtapPb[i] = new TH2D(histoname,"",6,-2,2,30,0,3.1415);
    avgEtapPb[i]->Sumw2();
    sprintf(histoname,"%s%d","avgEtapp_",i);
    avgEtapp[i] = new TH2D(histoname,"",6,-2,2,30,0,3.1415);
    avgEtapp[i]->Sumw2();
    sprintf(histoname,"%s%d","avgEtapPbMC_",i);
    avgEtapPbMC[i] = new TH2D(histoname,"",6,-2,2,30,0,3.1415);
    avgEtapPbMC[i]->Sumw2();
    sprintf(histoname,"%s%d","avgEtappMC_",i);
    avgEtappMC[i] = new TH2D(histoname,"",6,-2,2,30,0,3.1415);
    avgEtappMC[i]->Sumw2();
  }
  
  //pPb Data
  double pt1,pt2,phi1,phi2,eta1,eta2,hiHF,rawPt1,rawPt2, hiHFminus;
  bool PU;
  int tracks;
  dijetTree->SetBranchAddress("pt1",&pt1);
  dijetTree->SetBranchAddress("pt2",&pt2);
  dijetTree->SetBranchAddress("rawPt1",&rawPt1);
  dijetTree->SetBranchAddress("rawPt2",&rawPt2);
  dijetTree->SetBranchAddress("phi1",&phi1);
  dijetTree->SetBranchAddress("phi2",&phi2);
  dijetTree->SetBranchAddress("eta1",&eta1);
  dijetTree->SetBranchAddress("eta2",&eta2);
  dijetTree->SetBranchAddress("tracks",&tracks);
  dijetTree->SetBranchAddress("hiHFplusEta4",&hiHF);
  dijetTree->SetBranchAddress("hiHFminusEta4",&hiHFminus);
  dijetTree->SetBranchAddress("PUFilterGplus",&PU);
  for(int i=0; i<dijetTree->GetEntries(); i++){
    dijetTree->GetEntry(i);
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && PU && hiHF<70){
      avgEtapPb[0]->Fill(eta1,acos(cos(phi1-phi2)));
      avgEtapPb[1]->Fill(eta2,acos(cos(phi1-phi2)));
      avgEtapPb[2]->Fill((eta1+eta2)/2,acos(cos(phi1-phi2)));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && PU && /*tracks>=multBins[0] && tracks<multBins[1] && */hiHF+hiHFminus>=0 && hiHF+hiHFminus<20 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPb[0]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && PU && /*tracks>=multBins[2] && tracks<multBins[3] && */hiHF+hiHFminus>=20 && hiHF+hiHFminus<25 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPb[1]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && PU && /*tracks>=multBins[3] && tracks<multBins[4] && */hiHF+hiHFminus>=25 && hiHF+hiHFminus<30 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPb[2]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && PU && /*tracks>=multBins[4] && tracks<multBins[5] && */hiHF+hiHFminus>=30 && hiHF+hiHFminus<40 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPb[3]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && PU && /*tracks>=multBins[5] && tracks<multBins[6] && */hiHF+hiHFminus>=40 && hiHF+hiHFminus<90 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPb[4]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && PU && acos(cos(phi1-phi2))>2.0944){
      etaDistropPb[5]->Fill((eta1+eta2)/2);
    }
  }

  //pPb MC
  double weight, MCentries, pthat;
  mcTree->SetBranchAddress("pt1",&pt1);
  mcTree->SetBranchAddress("pt2",&pt2);
  mcTree->SetBranchAddress("rawPt1",&rawPt1);
  mcTree->SetBranchAddress("rawPt2",&rawPt2);
  mcTree->SetBranchAddress("tracks",&tracks);
  mcTree->SetBranchAddress("pthat",&pthat);
  mcTree->SetBranchAddress("phi1",&phi1);
  mcTree->SetBranchAddress("phi2",&phi2);
  mcTree->SetBranchAddress("eta1",&eta1);
  mcTree->SetBranchAddress("eta2",&eta2);
  mcTree->SetBranchAddress("hiHFplusEta4",&hiHF);
  mcTree->SetBranchAddress("hiHFminusEta4",&hiHFminus);
  mcTree->SetBranchAddress("weight",&weight);
  mcTree->SetBranchAddress("MCpthatEntries",&MCentries);
  for(int i=0; i<mcTree->GetEntries(); i++){
    mcTree->GetEntry(i);
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && pthat>50 && hiHF<70){
      avgEtapPbMC[0]->Fill(eta1,acos(cos(phi1-phi2)),(weight/MCentries));
      avgEtapPbMC[1]->Fill(eta2,acos(cos(phi1-phi2)),(weight/MCentries));
      avgEtapPbMC[2]->Fill((eta1+eta2)/2,acos(cos(phi1-phi2)),(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && pthat>30 && /*tracks>=multBins[0] && tracks<multBins[1] &&*/ hiHF+hiHFminus>=0 && hiHF+hiHFminus<20 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPbMC[0]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && pthat>30 && /*tracks>=multBins[2] && tracks<multBins[3] && */hiHF+hiHFminus>=20 && hiHF+hiHFminus<25 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPbMC[1]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && pthat>30 && /*tracks>=multBins[3] && tracks<multBins[4] && */hiHF+hiHFminus>=25 && hiHF+hiHFminus<30 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPbMC[2]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && pthat>30 && /*tracks>=multBins[4] && tracks<multBins[5] && */hiHF+hiHFminus>=30 && hiHF+hiHFminus<40 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPbMC[3]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && pthat>30 && /*tracks>=multBins[5] && tracks<multBins[6] && */hiHF+hiHFminus>=40 && hiHF+hiHFminus<90 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistropPbMC[4]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
  }

  //pp MC
  ppTree->SetBranchAddress("pt1",&pt1);
  ppTree->SetBranchAddress("pt2",&pt2);
  ppTree->SetBranchAddress("rawPt1",&rawPt1);
  ppTree->SetBranchAddress("rawPt2",&rawPt2);
  ppTree->SetBranchAddress("weight",&weight);
  ppTree->SetBranchAddress("MCpthatEntries",&MCentries);
  ppTree->SetBranchAddress("phi1",&phi1);
  ppTree->SetBranchAddress("phi2",&phi2);
  ppTree->SetBranchAddress("eta1",&eta1);
  ppTree->SetBranchAddress("eta2",&eta2);
  ppTree->SetBranchAddress("hiHFplusEta4",&hiHF);
  ppTree->SetBranchAddress("hiHFminusEta4",&hiHFminus);
  for(int i=0; i<ppTree->GetEntries(); i++){
    ppTree->GetEntry(i);
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && pthat>50 && hiHF<70 && acos(cos(phi1-phi2)>2.0944)){
      avgEtappMC[0]->Fill(eta1,acos(cos(phi1-phi2)),(weight/MCentries));
      avgEtappMC[1]->Fill(eta2,acos(cos(phi1-phi2)),(weight/MCentries));
      avgEtappMC[2]->Fill((eta1+eta2)/2,acos(cos(phi1-phi2)),(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=0 && hiHF+hiHFminus<20 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppMC[0]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=20 && hiHF+hiHFminus<25 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppMC[1]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=25 && hiHF+hiHFminus<30 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppMC[2]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=30 && hiHF+hiHFminus<40 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppMC[3]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=40 && hiHF+hiHFminus<90 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppMC[4]->Fill((eta1+eta2)/2,(weight/MCentries));
    }
  }

  //pp data
  ppDatTree->SetBranchAddress("pt1",&pt1);
  ppDatTree->SetBranchAddress("pt2",&pt2);
  ppDatTree->SetBranchAddress("rawPt1",&rawPt1);
  ppDatTree->SetBranchAddress("rawPt2",&rawPt2);
  ppDatTree->SetBranchAddress("phi1",&phi1);
  ppDatTree->SetBranchAddress("phi2",&phi2);
  ppDatTree->SetBranchAddress("eta1",&eta1);
  ppDatTree->SetBranchAddress("eta2",&eta2);
  ppDatTree->SetBranchAddress("hiHFplusEta4",&hiHF);
  ppDatTree->SetBranchAddress("hiHFminusEta4",&hiHFminus);
  for(int i=0; i<ppDatTree->GetEntries(); i++){
    ppDatTree->GetEntry(i);
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF<70){
      avgEtapp[0]->Fill(eta1,acos(cos(phi1-phi2)));
      avgEtapp[1]->Fill(eta2,acos(cos(phi1-phi2)));
      avgEtapp[2]->Fill((eta1+eta2)/2,acos(cos(phi1-phi2)));
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=0 && hiHF+hiHFminus<90 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppData[0]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=20 && hiHF+hiHFminus<25 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppData[1]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=25 && hiHF+hiHFminus<30 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppData[2]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=30 && hiHF+hiHFminus<40 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppData[3]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=40 && hiHF+hiHFminus<90 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroppData[4]->Fill((eta1+eta2)/2);
    }
  }

  pbpbtree->SetBranchAddress("pt1",&pt1);
  pbpbtree->SetBranchAddress("pt2",&pt2);
  pbpbtree->SetBranchAddress("rawPt1",&rawPt1);
  pbpbtree->SetBranchAddress("rawPt2",&rawPt2);
  pbpbtree->SetBranchAddress("phi1",&phi1);
  pbpbtree->SetBranchAddress("phi2",&phi2);
  pbpbtree->SetBranchAddress("eta1",&eta1);
  pbpbtree->SetBranchAddress("eta2",&eta2);
  pbpbtree->SetBranchAddress("hiHFplusEta4",&hiHF);
  pbpbtree->SetBranchAddress("hiHFminusEta4",&hiHFminus);
  for(int i=0; i<pbpbtree->GetEntries(); i++){
    pbpbtree->GetEntry(i);
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=0 && hiHF+hiHFminus<25 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroPbPb[0]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=25 && hiHF+hiHFminus<50 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroPbPb[1]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=50 && hiHF+hiHFminus<90 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroPbPb[2]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=30 && hiHF+hiHFminus<40 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroPbPb[3]->Fill((eta1+eta2)/2);
    }
    if(pt1>120 && pt2>30 && rawPt1>15 && rawPt2>15 && hiHF+hiHFminus>=40 && hiHF+hiHFminus<90 && acos(cos(phi1-phi2)) > 2.0944){
      etaDistroPbPb[4]->Fill((eta1+eta2)/2);
    }
  }

  TCanvas *c2 = new TCanvas("c2","",1400,800);
  c2->cd();
  makeMultiPanelCanvas(c2,3,2,0.,0.,0.2,0.2,0.05);
  for(int i=0; i<5; i++){
    c2->cd(i+1);
    cout << "pPb:  " << etaDistropPb[i]->Integral() << endl;
    etaDistropPb[i]->Scale(1./etaDistropPb[i]->Integral());
    etaDistropPb[i]->SetMaximum(0.2);
    etaDistropPb[i]->SetYTitle("Event Fraction");
    etaDistropPb[i]->SetXTitle("(#eta_{1}+#eta_{2})/2");
    //etaDistropPb[i]->SetXTitle("#eta_{leading}");
    etaDistropPb[i]->Draw();
    cout << "ppMC:  " << etaDistroppMC[i]->Integral() << endl;
    etaDistroppMC[i]->Scale(1./etaDistroppMC[i]->Integral());
    etaDistroppMC[i]->Draw("same");
    etaDistropPbMC[i]->Scale(1./etaDistropPbMC[i]->Integral());
    etaDistropPbMC[i]->Draw("same");
    //if(etaDistroppData[i]->Integral() != 0){
    cout << "pp:  " << etaDistroppData[i]->Integral() << endl;
    etaDistroppData[i]->Scale(1./etaDistroppData[i]->Integral());
    etaDistroppData[i]->Draw("same");
    //}
    if(i==0){
      TLatex *l1 = new TLatex(0.5, 0.15,"E_{T}^{|#eta|<4}<20");
      l1->Draw();
    }
    if(i==1){
      TLatex *l2 = new TLatex(0.5, 0.15, "20#leqE_{T}^{|#eta|<4}<25");
      l2->Draw();
    }
    if(i==2){
      TLatex *l3 = new TLatex(0.5, 0.15, "25#leqE_{T}^{|#eta|<4}<30");
      l3->Draw();
    }
    if(i==3){
      TLatex *l4 = new TLatex(0.5, 0.15, "30#leqE_{T}^{|#eta|<4}<40");
      l4->Draw();
    }
    if(i==4){
      TLatex *l5 = new TLatex(0.5, 0.15, "40#leqE_{T}^{|#eta|<4}");
      l5->Draw();
    }
    if(i==0){
      TLegend *leg = new TLegend(0.2,0.77,0.80,0.91);
      leg->AddEntry(etaDistropPb[i],"pPb Data, #sqrt{s}=5 TeV");
      leg->AddEntry(etaDistroppMC[i], "pp PYTHIA MC, #sqrt{s}=5 TeV");
      leg->AddEntry(etaDistropPbMC[i], "pPb HIJING+PYTHIA MC, #sqrt{s}=5 TeV");
      leg->AddEntry(etaDistroppData[i], "pp Data, #sqrt{s}=2.76 TeV");
      leg->SetFillColor(0);
      leg->SetBorderSize(0);
      leg->Draw();
    }
  }
  
  TCanvas *c3 = new TCanvas("c3","",1400,600);
  c3->Divide(3,1);
  TH1D *profpPb[3];
  TH1D *profpp[3];
  TH1D *profpPbMC[3];
  TH1D *profppMC[3];
  for(int i=0; i<3; i++){
    c3->cd(i+1);
    profpPb[i] = avgEtapPb[i]->ProfileX();
    profpPb[i]->SetMaximum(3.0);
    profpPb[i]->SetMinimum(2.81);
    if(i==0) profpPb[i]->SetXTitle("#eta_{leading}");
    if(i==1) profpPb[i]->SetXTitle("#eta_{subleading}");
    if(i==2) profpPb[i]->SetXTitle("(#eta_{1}+#eta_{2})/2");
    profpPb[i]->SetYTitle("<#Delta#phi>");
    //profpPb[i]->Scale(1./profpPb[i]->Integral());
    profpPb[i]->Draw();
    profpp[i] = avgEtapp[i]->ProfileX();
    //profpp[i]->Scale(1./profpp[i]->Integral());
    profpp[i]->SetMarkerColor(4);
    profpp[i]->SetLineColor(4);
    profpp[i]->Draw("same");
    profpPbMC[i] = avgEtapPbMC[i]->ProfileX();
    //profpPbMC[i]->Scale(1./profpPbMC[i]->Integral());
    profpPbMC[i]->SetMarkerColor(2);
    profpPbMC[i]->SetLineColor(2);
    profpPbMC[i]->Draw("same");
    profppMC[i] = avgEtappMC[i]->ProfileX();
    // profppMC[i]->Scale(1./profppMC[i]->Integral());
    profppMC[i]->SetMarkerColor(8);
    profppMC[i]->SetLineColor(8);
    profppMC[i]->Draw("same");
  }

  //Plot mean
  /*Double_t pPb_nmult[5] = {5.658, 12.3924,17.3349,24.0448,36.3906};
  Double_t pPb_avgPt[5] = {etaDistropPb[0]->GetMean(), etaDistropPb[1]->GetMean(), etaDistropPb[2]->GetMean(), etaDistropPb[3]->GetMean(), etaDistropPb[4]->GetMean()};
  Double_t pPb_nmultErr[5] = {0.0097,0.01997,0.028038,0.0343,0.07198};
  Double_t pPb_avgPtErr[5] = {etaDistropPb[0]->GetMeanError(), etaDistropPb[1]->GetMeanError(), etaDistropPb[2]->GetMeanError(), etaDistropPb[3]->GetMeanError(), etaDistropPb[4]->GetMeanError()};

  Double_t MC_nmult[5] = {5.20261,12.3461,17.3005,23.8401,34.7769};
  Double_t MC_avgPt[5] = {etaDistropPbMC[0]->GetMean(), etaDistropPbMC[1]->GetMean(), etaDistropPbMC[2]->GetMean(), etaDistropPbMC[3]->GetMean(), etaDistropPbMC[4]->GetMean()};
  Double_t MC_nmultErr[5] = {0.0043,0.01139,0.01656.0.0211,0.0549};
  Double_t MC_avgPtErr[5] = {etaDistropPbMC[0]->GetMeanError(), etaDistropPbMC[1]->GetMeanError(), etaDistropPbMC[2]->GetMeanError(), etaDistropPbMC[3]->GetMeanError(), etaDistropPbMC[4]->GetMeanError()};

  Double_t PbPb_nmult[4] = {11.6405,30.6015,49.7908,64.897};
  Double_t PbPb_avgPt[4] = {etaDistroPbPb[0]->GetMean(), etaDistroPbPb[1]->GetMean(), etaDistroPbPb[2]->GetMean(), etaDistroPbPb[3]->GetMean()};
  Double_t PbPb_nmultErr[4] = {0.2618,0.2188,0.1961,0.1493};
  Double_t PbPb_avgPtErr[4] = {etaDistroPbPb[0]->GetMeanError(), etaDistroPbPb[1]->GetMeanError(), etaDistroPbPb[2]->GetMeanError(), etaDistroPbPb[3]->GetMeanError()};*/

 
  //Double_t pPb_nmult[5] = {5.658, 12.3924,17.3349,24.0448,36.3906}; //for hiHFplusEta4
  Double_t pPb_nmult[5] = {12.699,22.424,27.356,34.192,47.624}; //for HFplusEta4 + HFminusEta4
  Double_t pPb_avgPt[5] = {findDelPhiAngle(etaDistropPb[0],1), findDelPhiAngle(etaDistropPb[1],1), findDelPhiAngle(etaDistropPb[2],1), findDelPhiAngle(etaDistropPb[3],1), findDelPhiAngle(etaDistropPb[4],1)};
  Double_t pPb_nmultErr[5] = {0.012, 0.0296, 0.0375, 0.0406, 0.0715};
  Double_t pPb_avgPtErr[5] = {findDelPhiAngle(etaDistropPb[0],2), findDelPhiAngle(etaDistropPb[1],2), findDelPhiAngle(etaDistropPb[2],2), findDelPhiAngle(etaDistropPb[3],2), findDelPhiAngle(etaDistropPb[4],2)};

  //Double_t MC_nmult[5] = {5.20261,12.3461,17.3005,23.8401,34.7769}; //for hiHFplusEta4
  Double_t MC_nmult[5] = {11.9707, 22.4454, 27.4279, 34.4833, 47.2613}; //for hiHFplusEta4 + hiHFminusEta4
  //Double_t MC_nmult[5] = {1,3,5,8,12}; //for signal only sample
  Double_t MC_avgPt[5] = {findDelPhiAngle(etaDistropPbMC[0],1), findDelPhiAngle(etaDistropPbMC[1],1), findDelPhiAngle(etaDistropPbMC[2],1), findDelPhiAngle(etaDistropPbMC[3],1), findDelPhiAngle(etaDistropPbMC[4],1)};
  Double_t MC_nmultErr[5] = {0.004,0.013,0.015,0.015,0.022};
  Double_t MC_avgPtErr[5] = {findDelPhiAngle(etaDistropPbMC[0],2), findDelPhiAngle(etaDistropPbMC[1],2), findDelPhiAngle(etaDistropPbMC[2],2), findDelPhiAngle(etaDistropPbMC[3],2), findDelPhiAngle(etaDistropPbMC[4],2)};

  Double_t PbPb_nmult[3] = {15.1924, 37.45, 71.267};
  Double_t PbPb_avgPt[3] = {findDelPhiAngle(etaDistroPbPb[0],1), findDelPhiAngle(etaDistroPbPb[1],1), findDelPhiAngle(etaDistroPbPb[2],1)};
  Double_t PbPb_nmultErr[3] = {0.274, 0.296, 0.262};
  Double_t PbPb_avgPtErr[3] = {findDelPhiAngle(etaDistroPbPb[0],2), findDelPhiAngle(etaDistroPbPb[1],2), findDelPhiAngle(etaDistroPbPb[2],2)};

  Double_t pp_nmult[4] = {6.504, 21.78, 26.17, 31.65};
  Double_t pp_avgPt[4] = {findDelPhiAngle(etaDistroppData[0],1), findDelPhiAngle(etaDistroppData[1],1), findDelPhiAngle(etaDistroppData[2],1), findDelPhiAngle(etaDistroppData[3],1)};
  Double_t pp_nmultErr[4] = {0.04, 1.29, 3.62, 5.63};
  Double_t pp_avgPtErr[4] = {findDelPhiAngle(etaDistroppData[0],2), findDelPhiAngle(etaDistroppData[1],2), findDelPhiAngle(etaDistroppData[2],2), findDelPhiAngle(etaDistroppData[3],2)};

  /* TH1D *ppSum = etaDistroppData[0]->Clone("ppSum");
  for(int i=1; i<5; i++){
    ppSum->Add(etaDistroppData[i]);
  }
  Double_t pp_nmult[1] = {3.5};
  Double_t pp_nmultErr[1] = {0.1};
  Double_t pp_avgPt[1] = {findDelPhiAngle(ppSum,1)};
  Double_t pp_avgPtErr[1] = {findDelPhiAngle(ppSum,2)};*/

  TGraphErrors *centr2[3];
  centr2[0] = new TGraphErrors(5,pPb_nmult, pPb_avgPt, pPb_nmultErr, pPb_avgPtErr);
  centr2[1] = new TGraphErrors(3,PbPb_nmult, PbPb_avgPt, PbPb_nmultErr, PbPb_avgPtErr);
  centr2[2] = new TGraphErrors(5,MC_nmult, MC_avgPt, MC_nmultErr, MC_avgPtErr);
  centr2[3] = new TGraphErrors(1,pp_nmult, pp_avgPt, pp_nmultErr, pp_avgPtErr);
  TLatex *label1 = new TLatex(40,0.1,"|#eta|< 3");
  TH1D *temp = new TH1D("temp","",1,0,60);
  temp->SetMaximum(-0.1);
  temp->SetMinimum(-0.7);
  temp->SetXTitle("E_{T}^{HF[|#eta|>4]}");
  temp->SetYTitle("((#eta_{1}+#eta_{2})/2)_{#mu}");
  temp->GetXaxis()->CenterTitle();
  temp->GetYaxis()->CenterTitle();
  temp->GetYaxis()->SetLabelSize(0.08);
  temp->GetYaxis()->SetTitleOffset(0.5);
  temp->SetTitleSize(0.1, "y");
  temp->GetXaxis()->SetLabelSize(0.08);
  //temp->GetXaxis()->SetTitleOffset(0.5);
  temp->SetTitleSize(0.1, "x");
  TCanvas *c4 = new TCanvas("c4","",600,600);
  c4->cd();
  temp->Draw();
  centr2[0]->Draw("P,same");
  centr2[1]->SetLineColor(8);
  centr2[1]->SetMarkerColor(8);
  centr2[1]->SetMarkerStyle(25);
  //centr2[1]->Draw("P,same");
  centr2[2]->SetLineColor(2);
  centr2[2]->SetMarkerColor(2);
  centr2[2]->Draw("P,same");
  centr2[3]->SetMarkerColor(4);
  centr2[3]->SetLineColor(4);
  centr2[3]->SetMarkerStyle(24);
  //centr2[3]->Draw("P,same");
  //label1->Draw();

  etaDistropPb[0]->Scale(1./etaDistropPb[0]->Integral());
  TFile *fout = new TFile("hist_output_etaLT3_akPu3PF_ForPawan.root","UPDATE");
  fout->cd();
  for(int i=0; i<6; i++){
    etaDistropPb[i]->Write();
  }
  centr2[0]->SetNameTitle("dijEta","Dijet Eta vs Hf");
  centr2[0]->Write();
  fout->Close();
}
void makeEtaSliceComparisonPlots(   vector<mithep::TH2DAsymErr*> efficiencyGraphs,
                                    vector<string> efficiencyGraphLabels,
                                    string filename, string plotname,                                     
                                    string xAxisLabel = "" , string yAxisLabel = "", double maxY = -1,
                                    double legendX1 = -99, double legendY1 = -99, 
                                    double legendX2 = -99, double legendY2 = -99) {
   
  TCanvas *cv = MakeCanvas("cv", plotname.c_str(), 800, 900);
//   cv->Divide(2,3);

  int padIndex = 1;
    

  for(UInt_t j=1; j <= efficiencyGraphs[0]->GetYaxis()->GetNbins(); j++) {
  
    cout << "Start " << j << endl;
    char tmp[20]; 
    sprintf(tmp, "_Eta%.2fTo%.2f",  efficiencyGraphs[0]->GetYaxis()->GetBinLowEdge(j), 
            efficiencyGraphs[0]->GetYaxis()->GetBinUpEdge(j));
    string sliceEta = tmp;

    TLegend *leg1=0;
    if (legendX1 > -99) {
      leg1 = new TLegend(legendX1,legendY1,legendX2,legendY2);   
    } else {
      leg1 = new TLegend(0.25,0.75,0.55,0.9);   
    }
    leg1->SetBorderSize(0);
    leg1->SetTextSize(0.03);
    
    vector<TH1D*> slices;
    for(int s=0; s < efficiencyGraphs.size(); ++s) {
      char tmp1[20];
      sprintf(tmp, "%d", s);
      string sliceString = tmp;

      cout << efficiencyGraphs[s]->GetName() << endl;
      TH1D *slice = efficiencyGraphs[s]->ProjectionX(("projectionX1" + sliceString).c_str() , j,j);
      slices.push_back(slice);
      cout << "here1 \n";

      slice->SetTitle((plotname + " " + sliceEta).c_str());

      if (xAxisLabel != "") slice->GetXaxis()->SetTitle(xAxisLabel.c_str());
      slice->GetXaxis()->SetTitleOffset(1.0);
      slice->GetXaxis()->SetLabelSize(0.03);
      if (yAxisLabel != "") slice->GetYaxis()->SetTitle(yAxisLabel.c_str());
      slice->GetYaxis()->SetTitleOffset(1.75);
      double MAXY = 0.04;
      if (maxY > 0) MAXY = maxY;
      slice->SetMaximum(MAXY);
      slice->SetMinimum(0.0);
      cout << "here2 \n";

      leg1->AddEntry(slice, efficiencyGraphLabels[s].c_str(), "LP"); 
      slice->SetMarkerColor(COLORS[s]);
      slice->SetLineColor(COLORS[s]);
      slice->SetMarkerSize(0.75);
      slice->SetMarkerStyle(MARKERS[s]);
      cout << "here3 \n";

      if (s==0) {
        slice->Draw();
      } else {
        slice->Draw("same");
      }
    }
    leg1->Draw();
    cv->SaveAs((filename + sliceEta + ".gif").c_str());
    cv->SaveAs((filename + sliceEta + ".eps").c_str());
  }

  return;
}
Beispiel #24
0
void doit(const char *basename, const int nbins, const double lofit, const double hifit)
{

  // --- read in the data and create a vector with all the values
  // --- note that this code requires an duplicates to have already been cleaned out
  // --- this is automatically fixed with the new version of the DAQ/stepper code
  // --- but the user would do well do double check all output files anyway
  ifstream fin1(Form("TEMP/%s_Unaveraged_VMin1.txt",basename));
  double content;
  vector<double> voltage1;
  while(fin1>>content)
    {
      voltage1.push_back(content);
    }
  fin1.close();
  cout << voltage1.size() << endl;

  // --- do the same for SiPM2
  ifstream fin2(Form("TEMP/%s_Unaveraged_VMin2.txt",basename));
  vector<double> voltage2;
  while(fin2>>content)
    {
      voltage2.push_back(content);
    }
  fin2.close();
  cout << voltage2.size() << endl;

  // --- get the number of entries and the min and max
  int number = voltage1.size();
  double max = *max_element(voltage1.begin(),voltage1.end());
  double min = *min_element(voltage1.begin(),voltage1.end());
  cout << max << endl;
  cout << min << endl;
  // --- use the min and max to calculate a range for the histogram
  double newmax = min*-0.95;
  double newmin = max*-1.05 - newmax*0.1;
  // --- create the new histogram
  TH1D *h1 = new TH1D("h1","",nbins,newmin,newmax);
  TH1D *h2 = new TH1D("h2","",nbins,newmin,newmax);
  TH1D *hsum = new TH1D("hsum","",nbins,2*newmin,2*newmax);
  TH2D *hh1v2 = new TH2D("hh1v2","",nbins*2,newmin,newmax,nbins*2,newmin,newmax); // SiPM1 vs SiPM2
  TH2D *hhSvA = new TH2D("hhSvA","",nbins*2,2*newmin,2*newmax,nbins*2,-1,1); // Sum vs Asymmetry
  TH2D *hh1v2_cut1 = new TH2D("hh1v2_cut1","",nbins*2,newmin,newmax,nbins*2,newmin,newmax); // SiPM1 vs SiPM2
  TH2D *hhSvA_cut1 = new TH2D("hhSvA_cut1","",nbins*2,2*newmin,2*newmax,nbins*2,-1,1); // Sum vs Asymmetry
  TH2D *hh1v2_cut2 = new TH2D("hh1v2_cut2","",nbins*2,newmin,newmax,nbins*2,newmin,newmax); // SiPM1 vs SiPM2
  TH2D *hhSvA_cut2 = new TH2D("hhSvA_cut2","",nbins*2,2*newmin,2*newmax,nbins*2,-1,1); // Sum vs Asymmetry
  vector<double> sum;
  vector<double> asym;
  // --- loop over the vector to fill the histogram
  for(int i=0; i<number; i++)
    {
      // --- SiPM1
      h1->Fill(-voltage1[i]);
      // --- SiPM2
      h2->Fill(-voltage2[i]);
      // --- SiPM1 vs SiPM2
      hh1v2->Fill(-voltage1[i],-voltage2[i]);
      // --- sum vs asymmetry
      double tempsum = -voltage1[i] + -voltage2[i];
      double tempasym = (voltage1[i] - voltage2[i]) / (-voltage1[i] + -voltage2[i]);
      hsum->Fill(tempsum);
      hhSvA->Fill(tempsum,tempasym);
      sum.push_back(tempsum);
      asym.push_back(tempasym);
      // --- now do some cuts...
      if(fabs(tempasym)<0.4)
	{
	  hh1v2_cut1->Fill(-voltage1[i],-voltage2[i]);
	  hhSvA_cut1->Fill(tempsum,tempasym);
	}
      if((voltage1[i]<(voltage2[i]+20*peconvert))&&(voltage2[i]<(voltage1[i]+20*peconvert)))
	{
	  hh1v2_cut2->Fill(-voltage1[i],-voltage2[i]);
	  hhSvA_cut2->Fill(tempsum,tempasym);
	}
    }

  // --- make a canvas and draw the histogram
  TCanvas *c1 = new TCanvas("c1","",800,800);

  // --- rescale the histograms from volts to photoelectrons
  h1->GetXaxis()->SetLimits(newmin/peconvert,newmax/peconvert);
  h1->GetXaxis()->SetTitle("Number of photoelectrons");
  h1->GetYaxis()->SetTitle("Counts");

  // --- define Landau function and draw
  // --- don't fit yet because the data have tons of ugly low voltage1 background
  double height = 1049;
  double mu = 23;
  double sigma = 3;
  //TF1 *fun = new TF1("fun","[0]*TMath::Landau(x,[1],[2])",newmin/peconvert,newmax/peconvert);
  TF1 *fun = new TF1("fun","[0]*TMath::Landau(x,[1],[2])",2*newmin/peconvert,2*newmax/peconvert);
  fun->SetParameter(0,height);
  fun->SetParameter(1,mu);
  fun->SetParameter(2,sigma);


  double bgscale = 650; // guess...





  c1->SetLogy(0);
  c1->Clear();
  hh1v2->Draw("colz");
  hh1v2->GetXaxis()->SetLimits(newmin/peconvert,newmax/peconvert);
  hh1v2->GetYaxis()->SetLimits(newmin/peconvert,newmax/peconvert);
  hh1v2->GetXaxis()->SetTitle("#pe SiPM1");
  hh1v2->GetYaxis()->SetTitle("#pe SiPM2");
  c1->SetLogz(0);
  c1->Print(Form("Cosmics/%s_cosmics_1v2.png",basename));
  c1->Print(Form("Cosmics/%s_cosmics_1v2.pdf",basename));
  c1->SetLogz(1);
  c1->Print(Form("Cosmics/%s_cosmics_1v2_log.png",basename));
  c1->Print(Form("Cosmics/%s_cosmics_1v2_log.pdf",basename));

  hhSvA->Draw("colz");
  hhSvA->GetXaxis()->SetLimits(2*newmin/peconvert,2*newmax/peconvert);
  hhSvA->GetXaxis()->SetTitle("Sum");
  hhSvA->GetYaxis()->SetTitle("Asymmetry");
  c1->SetLogz(0);
  c1->Print(Form("Cosmics/%s_cosmics_SvA.png",basename));
  c1->Print(Form("Cosmics/%s_cosmics_SvA.pdf",basename));
  c1->SetLogz(1);
  c1->Print(Form("Cosmics/%s_cosmics_SvA_log.png",basename));
  c1->Print(Form("Cosmics/%s_cosmics_SvA_log.pdf",basename));


  // --- now for some cuts...

  c1->SetLogz(0);
  hh1v2_cut1->Draw("colz");
  hh1v2_cut1->GetXaxis()->SetLimits(newmin/peconvert,newmax/peconvert);
  hh1v2_cut1->GetYaxis()->SetLimits(newmin/peconvert,newmax/peconvert);
  hh1v2_cut1->GetXaxis()->SetTitle("#pe SiPM1");
  hh1v2_cut1->GetYaxis()->SetTitle("#pe SiPM2");
  TLatex *tex1 = new TLatex(0.2,0.8,"|Asymmetry|<0.4");
  tex1->SetTextSize(0.05);
  tex1->SetNDC(kTRUE);
  tex1->Draw();
  c1->SetLogz(0);
  c1->Print(Form("Cosmics/%s_cosmics_1v2_cut1.png",basename));
  c1->Print(Form("Cosmics/%s_cosmics_1v2_cut1.pdf",basename));
  c1->SetLogz(1);
  c1->Print(Form("Cosmics/%s_cosmics_1v2_cut1_log.png",basename));
  c1->Print(Form("Cosmics/%s_cosmics_1v2_cut1_log.pdf",basename));

  hhSvA_cut1->Draw("colz");
  hhSvA_cut1->GetXaxis()->SetLimits(2*newmin/peconvert,2*newmax/peconvert);
  hhSvA_cut1->GetXaxis()->SetTitle("Sum");
  hhSvA_cut1->GetYaxis()->SetTitle("Asymmetry");
  tex1->Draw();
  c1->SetLogz(0);
  c1->Print(Form("Cosmics/%s_cosmics_SvA_cut1.png",basename));
  c1->Print(Form("Cosmics/%s_cosmics_SvA_cut1.pdf",basename));
  c1->SetLogz(1);
  c1->Print(Form("Cosmics/%s_cosmics_SvA_cut1_log.png",basename));
  c1->Print(Form("Cosmics/%s_cosmics_SvA_cut1_log.pdf",basename));




  c1->SetLogz(0);
  hh1v2_cut2->Draw("colz");
  hh1v2_cut2->GetXaxis()->SetLimits(newmin/peconvert,newmax/peconvert);
  hh1v2_cut2->GetYaxis()->SetLimits(newmin/peconvert,newmax/peconvert);
  hh1v2_cut2->GetXaxis()->SetTitle("#pe SiPM1");
  hh1v2_cut2->GetYaxis()->SetTitle("#pe SiPM2");
  TLatex *tex2 = new TLatex(0.2,0.8,"SiPMA < SiPMB + 20");
  tex2->SetTextSize(0.05);
  tex2->SetNDC(kTRUE);
  tex2->Draw();
  c1->SetLogz(0);
  c1->Print(Form("Cosmics/%s_cosmics_1v2_cut2.png",basename));
  c1->Print(Form("Cosmics/%s_cosmics_1v2_cut2.pdf",basename));
  c1->SetLogz(1);
  c1->Print(Form("Cosmics/%s_cosmics_1v2_cut2_log.png",basename));
  c1->Print(Form("Cosmics/%s_cosmics_1v2_cut2_log.pdf",basename));

  hhSvA_cut2->Draw("colz");
  hhSvA_cut2->GetXaxis()->SetLimits(2*newmin/peconvert,2*newmax/peconvert);
  hhSvA_cut2->GetXaxis()->SetTitle("Sum");
  hhSvA_cut2->GetYaxis()->SetTitle("Asymmetry");
  tex2->Draw();
  c1->SetLogz(0);
  c1->Print(Form("Cosmics/%s_cosmics_SvA_cut2.png",basename));
  c1->Print(Form("Cosmics/%s_cosmics_SvA_cut2.pdf",basename));
  c1->SetLogz(1);
  c1->Print(Form("Cosmics/%s_cosmics_SvA_cut2_log.png",basename));
  c1->Print(Form("Cosmics/%s_cosmics_SvA_cut2_log.pdf",basename));



  hsum->SetLineColor(kBlack);
  hsum->SetLineWidth(2);
  hsum->GetXaxis()->SetLimits(2*newmin/peconvert,2*newmax/peconvert);
  //hsum->GetXaxis()->SetRangeUser(0.0,120.0);
  hsum->GetXaxis()->SetTitle("Number of photoelectrons SiPM1+SiPM2");
  hsum->Draw();
  c1->Print(Form("Cosmics/%s_temp.png",basename));
  c1->Print(Form("Cosmics/%s_temp.pdf",basename));
  hsum->SetMaximum(30);
  c1->Print(Form("Cosmics/%s_templow.png",basename));
  c1->Print(Form("Cosmics/%s_templow.pdf",basename));
  c1->SetLogy();
  hsum->SetMaximum(1.1*h1->GetBinContent(hsum->GetMaximumBin()));
  c1->Print(Form("Cosmics/%s_templog.png",basename));
  c1->Print(Form("Cosmics/%s_templog.pdf",basename));


  // ---------------------------------------------------------
  bgscale = 100;
  h1->Fit(fun,"","",lofit,hifit);
  fun->SetLineColor(kRed);
  fun->SetLineWidth(2);
  fun->Draw("same");

  cout << fun->GetChisquare() << "/" << fun->GetNDF() << endl;

  c1->SetLogy(0);
  c1->Print(Form("Cosmics/%s_tempfit.png",basename));
  c1->Print(Form("Cosmics/%s_tempfit.pdf",basename));
  h1->SetMaximum(175);
  c1->Print(Form("Cosmics/%s_templowfit.png",basename));
  c1->Print(Form("Cosmics/%s_templowfit.pdf",basename));
  h1->SetMaximum(100);
  c1->Print(Form("Cosmics/%s_tempLOWfit.png",basename));
  c1->Print(Form("Cosmics/%s_tempLOWfit.pdf",basename));
  c1->SetLogy(1);
  h1->SetMaximum(1.1*h1->GetBinContent(h1->GetMaximumBin()));
  c1->Print(Form("Cosmics/%s_templogfit.png",basename));
  c1->Print(Form("Cosmics/%s_templogfit.pdf",basename));

  c1->Clear();
  h1->Draw();
  double hax = fun->GetParameter(0);
  double mux = fun->GetParameter(1);
  double six = fun->GetParameter(2);
  fun->SetParameter(0,0.95*hax);
  fun->SetParameter(1,mux);
  fun->SetParameter(2,1.1*six);
  //fun->Draw("same");
  //h1->Fit(simplefun,"","",0,60);

  TF1 *fun2 = new TF1("fun2","([0]/sqrt(6.28))*TMath::Exp(-0.5*((x-[1])/[2] + TMath::Exp(-(x-[1])/[2])))",2*newmin/peconvert,2*newmax/peconvert);
  // fun2->SetParameter(0,hax);
  // fun2->SetParameter(1,mux);
  // fun2->SetParameter(2,six);
  // fun2->SetParameter(0,93);
  // fun2->SetParameter(1,35);
  // fun2->SetParameter(2,5);
  fun2->SetParameter(0,93);
  fun2->SetParameter(1,500);
  fun2->SetParameter(2,100);
  //fun2->SetLineColor(kBlack);

  h1->Fit(fun2,"","",lofit,hifit);
  fun2->Draw("same");

  cout << fun2->GetChisquare() << "/" << fun2->GetNDF() << endl;

  double par1 = fun2->GetParameter(1);
  TLine line(par1,0,par1,0.24*fun2->GetParameter(0));
  line.Draw();

  c1->SetLogy(0);
  c1->Print(Form("Cosmics/%s_tempffit.png",basename));
  c1->Print(Form("Cosmics/%s_tempffit.pdf",basename));
  h1->SetMaximum(25);
  c1->Print(Form("Cosmics/%s_templowffit.png",basename));
  c1->Print(Form("Cosmics/%s_templowffit.pdf",basename));
  h1->SetMaximum(0.3*fun2->GetParameter(0));
  TLatex *tex = new TLatex(0.6,0.8,Form("MPV = %.1f #pm %.1f",fun2->GetParameter(1),fun2->GetParError(1)));
  tex->SetNDC();
  tex->SetTextSize(0.05);
  tex->Draw();
  //h1->GetXaxis()->SetRangeUser(0.0,130.0); // new...
  c1->Print(Form("Cosmics/SmallTileCosmics_%s_tempLOWffit.png",basename));
  c1->Print(Form("Cosmics/SmallTileCosmics_%s_tempLOWffit.pdf",basename));
  c1->SetLogy(1);
  h1->SetMaximum(1.1*h1->GetBinContent(h1->GetMaximumBin()));
  c1->Print(Form("Cosmics/%s_templogffit.png",basename));
  c1->Print(Form("Cosmics/%s_templogffit.pdf",basename));



}
Beispiel #25
0
void test()
{	
	style();
	setLogBins(nlogfullimassbins,logfullimassmin,logfullimassmax,logfullimassbins);

	float Mhat;
	
	TCanvas* c = new TCanvas("c","c",600,400);
	c->SetLogx();
	c->SetLogy();
	c->Draw();
	c->cd();
	
	TLegend* leg = new TLegend(0.6627517,0.6846449,0.7919463,0.8261126,NULL,"brNDC");
	leg->SetFillStyle(4000); //will be transparent
	leg->SetFillColor(0);
	leg->SetTextFont(42);

	TFile fLoose("/data/hod/2011/NTUPLE/analysisLocalControl_TightLoose.root", "READ");
	TTree* tLoose = (TTree*)fLoose.Get("allCuts/allCuts_tree");
	tLoose->SetBranchAddress("Mhat",  &Mhat);
	Int_t nLoose = tLoose->GetEntries();
	TH1D* hLoose = new TH1D("hLoose","tight-loose vs. tight-tight selection;m_{#mu#mu} TeV;Events",nlogfullimassbins,logfullimassbins);
	hLoose->SetLineColor(kRed);
	hLoose->SetMarkerColor(kRed);
	hLoose->SetMarkerStyle(24);
	hLoose->SetMarkerSize(0.8);
	hLoose->SetMinimum(1.e-3);
	hLoose->SetMaximum(7.e+5);
	hLoose->GetXaxis()->SetMoreLogLabels();
	hLoose->GetXaxis()->SetNoExponent();
	leg->AddEntry(hLoose,"tight-loose","lep");
	for(Int_t i=0 ; i<nLoose ; i++)
	{
		tLoose->GetEntry(i);
		hLoose->Fill(Mhat*TeV2GeV);
	}
	
	TFile fTight("/data/hod/2011/NTUPLE/analysisLocalControl.root", "READ");
	TTree* tTight = (TTree*)fTight.Get("allCuts/allCuts_tree");
	tTight->SetBranchAddress("Mhat",  &Mhat);
	Int_t nTight = tTight->GetEntries();
	TH1D* hTight = new TH1D("hTight","tight-loose vs. tight-tight selection;m_{#mu#mu} TeV;Events",nlogfullimassbins,logfullimassbins);
	hTight->SetLineColor(kBlack);
	hTight->SetMarkerColor(kBlack);
	hTight->SetMarkerStyle(24);
	hTight->SetMarkerSize(0.8);
	hTight->SetMinimum(1.e-3);
	hTight->SetMaximum(7.e+5);
	hTight->GetXaxis()->SetMoreLogLabels();
	hTight->GetXaxis()->SetNoExponent();
	leg->AddEntry(hTight,"tight-tight","lep");
	for(Int_t i=0 ; i<nTight ; i++)
	{
		tTight->GetEntry(i);
		hTight->Fill(Mhat*TeV2GeV);
	}

	
	hTight->Draw("e1x1");
	hLoose->Draw("e1x1SAMES");
	leg->Draw("SAMES");
	c->RedrawAxis();
	c->SaveAs("plots/Wjets.png");
}
Beispiel #26
0
void massfitvn_Jpsi()
{
    double fit_range_low = 2.6;
    double fit_range_high = 3.5;
    double JPsi_mass = 3.097;
    int npt = 7;
    TFile* file1 = TFile::Open("HM185_JpsivnHist_etagap1p5_v30_eff_extdeta.root");
    
    TFile ofile("v2vspt_fromfit_jpsi_HM185_250_deta1p5_doubleCB_v30_eff_exp_extdeta.root","RECREATE");
    
    //v12
    double alpha_fit[14] = {4.30986,3.50841,3.03436,2.73741,2.37934,2.10685,2.03615};
    double n_fit[14] = {1.88853,1.9839,2.03198,2.07295,2.11001,2.15234,2.10154};
    
    TF1* fmasssig[9];
    TF1* fmassbkg[9];
    TF1* fmasstotal[9];
    TF1* fvn[9];
    
    double pt[13];
    double KET_ncq[13];
    double v2[13];
    double v2e[13];
    double v2_bkg[13];
    double v2_ncq[13];
    double v2e_ncq[13];
    double ptbin[14] = {0.2, 1.8, 3.0, 4.5, 6.0, 8.0, 10, 20};
    double a[13];
    double b[13];
    double sigfrac[13];
    
    TCanvas* c[10];
    for(int i=0;i<npt;i++)
    {
        c[i] = new TCanvas(Form("c_%d",i),Form("c_%d",i),800,400);
        c[i]->Divide(2,1);
    }
    
    for(int i=0;i<npt;i++)
    {
        c[i]->cd(1)->SetTopMargin(0.06);
        c[i]->cd(1)->SetLeftMargin(0.18);
        c[i]->cd(1)->SetRightMargin(0.043);
        c[i]->cd(1)->SetBottomMargin(0.145);
        c[i]->cd(2)->SetTopMargin(0.06);
        c[i]->cd(2)->SetLeftMargin(0.18);
        c[i]->cd(2)->SetRightMargin(0.043);
        c[i]->cd(2)->SetBottomMargin(0.145);

    }
    
    TCanvas* c2 = new TCanvas("c2","c2",100,100);
    
    TLatex* tex = new TLatex;
    tex->SetNDC();
    tex->SetTextFont(42);
    tex->SetTextSize(0.045);
    tex->SetLineWidth(2);
 
    TLatex* texCMS = new TLatex;
    texCMS->SetNDC();
    texCMS->SetTextFont(42);
    texCMS->SetTextSize(0.05);
    texCMS->SetTextAlign(12);
    
    TH1D* hist = new TH1D("hist","",10,2.6,3.5);
    hist->SetLineWidth(0);
    //hist->GetYaxis()->SetRangeUser(0,0.3);
    hist->GetXaxis()->SetTitle("#it{m}_{#mu#mu} (GeV)");
    hist->GetYaxis()->SetTitle("v_{2}^{S+B}");
    hist->GetXaxis()->CenterTitle();
    hist->GetYaxis()->CenterTitle();
    hist->GetXaxis()->SetTitleOffset(1.3);
    hist->GetYaxis()->SetTitleOffset(2);
    hist->GetXaxis()->SetLabelOffset(0.007);
    hist->GetYaxis()->SetLabelOffset(0.007);
    hist->GetXaxis()->SetTitleSize(0.045);
    hist->GetYaxis()->SetTitleSize(0.045);
    hist->GetXaxis()->SetTitleFont(42);
    hist->GetYaxis()->SetTitleFont(42);
    hist->GetXaxis()->SetLabelFont(42);
    hist->GetYaxis()->SetLabelFont(42);
    hist->GetXaxis()->SetLabelSize(0.04);
    hist->GetYaxis()->SetLabelSize(0.04);
    hist->SetMinimum(0.01);
    hist->SetMaximum(0.33);
    
    c2->cd();
    hist->Draw();
    
    for(int i=0;i<npt;i++)
    {
        TH1D* h_data = (TH1D*)file1->Get(Form("massjpsi_pt%d",i));
        h_data->SetMinimum(0);
        h_data->SetMarkerSize(0.8);
        h_data->SetMarkerStyle(20);
        h_data->SetLineWidth(1);
        h_data->SetOption("e");
        
        h_data->Rebin(2);

        h_data->GetXaxis()->SetRangeUser(2.6,3.5);
        h_data->GetXaxis()->SetTitle("#it{m}_{#mu#mu} (GeV)");
        h_data->GetYaxis()->SetTitle("Entries / 10 MeV");
        h_data->GetXaxis()->CenterTitle();
        h_data->GetYaxis()->CenterTitle();
        h_data->GetXaxis()->SetTitleOffset(1.3);
        h_data->GetYaxis()->SetTitleOffset(2);
        h_data->GetXaxis()->SetLabelOffset(0.007);
        h_data->GetYaxis()->SetLabelOffset(0.007);
        h_data->GetXaxis()->SetTitleSize(0.045);
        h_data->GetYaxis()->SetTitleSize(0.045);
        h_data->GetXaxis()->SetTitleFont(42);
        h_data->GetYaxis()->SetTitleFont(42);
        h_data->GetXaxis()->SetLabelFont(42);
        h_data->GetYaxis()->SetLabelFont(42);
        h_data->GetXaxis()->SetLabelSize(0.04);
        h_data->GetYaxis()->SetLabelSize(0.04);
        
        h_data->GetXaxis()->SetNoExponent(true);
        ((TGaxis*)h_data->GetXaxis())->SetMaxDigits(7);
        
        h_data->SetMaximum(h_data->GetMaximum()*1.5);
        
        TH1D* h_pt = (TH1D*)file1->Get(Form("Ptjpsi_eff_pt%d",i));
        TH1D* h_KET = (TH1D*)file1->Get(Form("KETjpsi_eff_pt%d",i));
        pt[i] = h_pt->GetMean();
        KET_ncq[i] = h_KET->GetMean()/2.0;

        c[i]->cd(1);
        
        /*p definitions
         [0] CB1 yield;
         [1] Common mean of CB and Gaus;
         [2] CB1 sigma;
         [3] CB n;
         [4] CB alpha;
         [5] CB2 yield;
         [6] CB2 sigma;
         [7-10] poly 3;
         [11] v2 signal;
         [12-13] v2 bkg;
         */
        TF1* f = new TF1(Form("f_%d",i), crystalball_function_total, fit_range_low, fit_range_high, 11);
        f->SetLineColor(2);
        f->SetLineWidth(1);
        f->SetParNames("CB1_Yield","common_mean","CB1_sigma","CB_N","CB_Alpha","CB2_Yield","CB2_Sigma","Pol0","Pol1","Pol2","Pol3");

        //first fit data mass signal + bkg
        
        f->SetParameter(0,10000.);
        f->SetParameter(1,JPsi_mass);
        f->SetParameter(2,0.03);
        f->SetParameter(3,1.0);
        f->SetParameter(4,1.0);
        f->SetParameter(5,10000);
        f->SetParameter(6,0.03);
        
        f->SetParLimits(2,0.01,0.1);
        f->SetParLimits(6,0.01,0.1);
        
        //fix alpha & n from MC
        f->FixParameter(4,alpha_fit[i]);
        f->FixParameter(3,n_fit[i]);
        
        f->FixParameter(1,JPsi_mass); //for first few attempt fix mean of gaussian to get reasonable estimation of other pars; later open it up
        h_data->Fit(Form("f_%d",i),"q","",fit_range_low,fit_range_high);
        h_data->Fit(Form("f_%d",i),"q","",fit_range_low,fit_range_high);
        f->ReleaseParameter(1); //now let gaussian mean float
        h_data->Fit(Form("f_%d",i),"L q","",fit_range_low,fit_range_high);
        h_data->Fit(Form("f_%d",i),"L q","",fit_range_low,fit_range_high);
        h_data->Fit(Form("f_%d",i),"L m","",fit_range_low,fit_range_high);
        
        
        //draw D0 signal separately
        TF1* f1 = new TF1(Form("f_sig_%d",i), crystalball_function_signal, fit_range_low, fit_range_high, 7);
        f1->SetLineColor(kOrange-3);
        f1->SetLineWidth(1);
        f1->SetLineStyle(2);
        f1->SetFillColorAlpha(kOrange-3,0.3);
        f1->SetFillStyle(1001);
        f1->FixParameter(0,f->GetParameter(0));
        f1->FixParameter(1,f->GetParameter(1));
        f1->FixParameter(2,f->GetParameter(2));
        f1->FixParameter(3,f->GetParameter(3));
        f1->FixParameter(4,f->GetParameter(4));
        f1->FixParameter(5,f->GetParameter(5));
        f1->FixParameter(6,f->GetParameter(6));
        
        fmasssig[i] = (TF1*)f1->Clone();
        fmasssig[i]->SetName(Form("masssigfcn_pt%d",i));
        fmasssig[i]->Write();
        
        f1->Draw("LSAME");
        
        //draw poly bkg separately
        TF1* f3 = new TF1(Form("f_bkg_%d",i),"[7] + [8]*x + [9]*x*x + [10]*x*x*x", fit_range_low, fit_range_high);
        f3->SetLineColor(4);
        f3->SetLineWidth(1);
        f3->SetLineStyle(2);
        f3->FixParameter(7,f->GetParameter(7));
        f3->FixParameter(8,f->GetParameter(8));
        f3->FixParameter(9,f->GetParameter(9));
        f3->FixParameter(10,f->GetParameter(10));
        
        fmassbkg[i] = (TF1*)f3->Clone();
        fmassbkg[i]->SetName(Form("massbkgfcn_pt%d",i));
        fmassbkg[i]->Write();
        
        f3->Draw("LSAME");
        
        tex->DrawLatex(0.22,0.86,"185 #leq N_{trk}^{offline} < 250");
        tex->DrawLatex(0.22,0.80,Form("%.1f < p_{T} < %.1f GeV",ptbin[i],ptbin[i+1]));
        tex->DrawLatex(0.22,0.74,"-2.86 < y_{cm} < -1.86 or 0.94 < y_{cm} < 1.94");
        
        texCMS->DrawLatex(.18,.97,"#font[61]{CMS} #it{Preliminary}");
        //texCMS->DrawLatex(.18,.97,"#font[61]{CMS}");
        texCMS->DrawLatex(0.73,0.97, "#scale[0.8]{pPb 8.16 TeV}");
        
        TLegend* leg = new TLegend(0.21,0.4,0.5,0.65,NULL,"brNDC");
        leg->SetBorderSize(0);
        leg->SetTextSize(0.045);
        leg->SetTextFont(42);
        leg->SetFillStyle(0);
        leg->AddEntry(h_data,"data","p");
        leg->AddEntry(f,"Fit","L");
        leg->AddEntry(f1,"J/#psi Signal","f");
        leg->AddEntry(f3,"Combinatorial","l");
        leg->Draw("SAME");
        
        sigfrac[i] = f1->Integral(2.94,3.24)/f->Integral(2.94,3.24);
        
        //c->Print(Form("plots/massfit_pt%d.pdf",i));
        
        //fit vn
        //[9] is vn_sig
        //[10-11] is vn bkg, const + linear vn(pT)
        TGraphErrors* vn_data = (TGraphErrors*)file1->Get(Form("v2_mass_pt%d",i));
        
        c[i]->cd(2);
        
        hist->Draw();
        
        TF1* fmass_combinemassvnfit = new TF1(Form("fmass_combinemassvnfit_%d",i),crystalball_function_total, fit_range_low, fit_range_high, 11);
        
        TF1* fvn_combinemassvnfit = new TF1(Form("fvn_combinemassvnfit_%d",i), crystalball_function_v2, fit_range_low, fit_range_high, 15);
        
        fmass_combinemassvnfit->SetLineColor(2);
        fmass_combinemassvnfit->SetLineWidth(1);
        
        fvn_combinemassvnfit->SetLineColor(2);
        fvn_combinemassvnfit->SetLineWidth(1);

        ROOT::Math::WrappedMultiTF1 wfmass_combinemassvnfit(*fmass_combinemassvnfit,1);
        ROOT::Math::WrappedMultiTF1 wfvn_combinemassvnfit(*fvn_combinemassvnfit,1);
        
        ROOT::Fit::DataOptions opt;
        ROOT::Fit::DataRange range_massfit;

        range_massfit.SetRange(fit_range_low,fit_range_high);
        ROOT::Fit::BinData datamass(opt,range_massfit);
        ROOT::Fit::FillData(datamass, h_data);
        
        ROOT::Fit::DataRange range_vnfit;
        range_vnfit.SetRange(fit_range_low,fit_range_high);
        ROOT::Fit::BinData datavn(opt,range_vnfit);
        ROOT::Fit::FillData(datavn, vn_data);
        
        ROOT::Fit::Chi2Function chi2_B(datamass, wfmass_combinemassvnfit);
        ROOT::Fit::Chi2Function chi2_SB(datavn, wfvn_combinemassvnfit);
        
        GlobalChi2_poly3bkg_floatwidth globalChi2(chi2_B, chi2_SB);

        ROOT::Fit::Fitter fitter;
        
        const int Npar = 15;
        double par0[Npar];
        for( int ipar = 0; ipar < f->GetNpar(); ipar++ ) par0[ipar] = f->GetParameter(ipar);
        par0[11] = 0.01;
        par0[12] = 0.10;
        par0[13] = 0.05;
        par0[14] = 0.01;

        
        fitter.Config().SetParamsSettings(Npar,par0);
        // fix parameter
        fitter.Config().ParSettings(0).Fix();
        fitter.Config().ParSettings(1).Fix();
        fitter.Config().ParSettings(2).Fix();
        fitter.Config().ParSettings(3).Fix();
        fitter.Config().ParSettings(4).Fix();
        fitter.Config().ParSettings(5).Fix();
        fitter.Config().ParSettings(6).Fix();
        fitter.Config().ParSettings(7).Fix();
        fitter.Config().ParSettings(8).Fix();
        fitter.Config().ParSettings(9).Fix();
        fitter.Config().ParSettings(10).Fix();
        
        fitter.Config().MinimizerOptions().SetPrintLevel(0);
        fitter.Config().SetMinimizer("Minuit2","Migrad");

        fitter.FitFCN(Npar,globalChi2,0,datamass.Size()+datavn.Size(),true);
        ROOT::Fit::FitResult result = fitter.Result();
        result.Print(std::cout);
        
        fmass_combinemassvnfit->SetFitResult( result, iparmassfit_poly3bkg_floatwidth);
        fmass_combinemassvnfit->SetRange(range_massfit().first, range_massfit().second);
        fmass_combinemassvnfit->SetLineColor(kRed);
        h_data->GetListOfFunctions()->Add(fmass_combinemassvnfit);
        //c->cd();
        //h_data->Draw();
        
        fvn_combinemassvnfit->SetFitResult( result, iparvnfit_poly3bkg_floatwidth);
        fvn_combinemassvnfit->SetRange(range_vnfit().first, range_vnfit().second);
        fvn_combinemassvnfit->SetLineColor(2);
        //fvn_combinemassvnfit->SetLineStyle(2);
        vn_data->GetListOfFunctions()->Add(fvn_combinemassvnfit);
        vn_data->SetTitle("");
        vn_data->SetMarkerSize(0.8);
        vn_data->SetLineWidth(1);
        //c1->cd();
        vn_data->Draw("PESAME");
        
        fvn[i] = (TF1*)fvn_combinemassvnfit->Clone();
        fvn[i]->SetName(Form("vnfit_pt%d",i));
        fvn[i]->Write();
        
        fmasstotal[i] = (TF1*)fmass_combinemassvnfit->Clone();
        fmasstotal[i]->SetName(Form("masstotalfcn_pt%d",i));
        fmasstotal[i]->Write();
        
        tex->DrawLatex(0.22,0.86,"185 #leq N_{trk}^{offline} < 250");
        tex->DrawLatex(0.22,0.80,Form("%.1f < p_{T} < %.1f GeV",ptbin[i],ptbin[i+1]));
        //tex->DrawLatex(0.22,0.74,"1.4 < |y_{cm}+0.46| < 2.4");
        tex->DrawLatex(0.22,0.74,"-2.86 < y_{cm} < -1.86 or 0.94 < y_{cm} < 1.94");
        //tex->DrawLatex(0.22,0.68,"|#Delta#eta| > 2");

        
        //texCMS->DrawLatex(.18,.97,"#font[61]{CMS}");
        texCMS->DrawLatex(.18,.97,"#font[61]{CMS} #it{Preliminary}");
        texCMS->DrawLatex(0.73,0.97, "#scale[0.8]{pPb 8.16 TeV}");
        
        v2[i] = fvn_combinemassvnfit->GetParameter(11);
        v2e[i] = fvn_combinemassvnfit->GetParError(11);
        v2_bkg[i] = fvn_combinemassvnfit->GetParameter(12) + fvn_combinemassvnfit->GetParameter(13) * JPsi_mass;
        v2_ncq[i] = v2[i]/2.0;
        v2e_ncq[i] = v2e[i]/2.0;
        a[i] = fvn_combinemassvnfit->GetParameter(12);
        b[i] = fvn_combinemassvnfit->GetParameter(13);
        
        TF1* fvnbkg = new TF1(Form("fvnbkg_%d",1),"( [0] + [1] * x)", fit_range_low, fit_range_high);
        fvnbkg->FixParameter(0,fvn_combinemassvnfit->GetParameter(12));
        fvnbkg->FixParameter(1,fvn_combinemassvnfit->GetParameter(13));
        
        fvnbkg->SetName(Form("fvnbkg_fcn_pt%d",i));
        fvnbkg->Write();
        
        fvnbkg->SetLineStyle(7);
        //fvnbkg->Draw("LSAME");
        
        TF1* fvnsig = new TF1(Form("fvnsig_%d",i),function_v2_sig,fit_range_low,fit_range_high,12);
        for(int k=0;k<12;k++)
        {
            fvnsig->FixParameter(k,fvn_combinemassvnfit->GetParameter(k));
            
        }
        
        fvnsig->SetLineColor(kOrange-3);
        fvnsig->SetLineWidth(1);
        fvnsig->SetLineStyle(2);
        fvnsig->SetFillColorAlpha(kOrange-3,0.3);
        fvnsig->SetFillStyle(1001);
        
        //fvnsig->Draw("LSAME");
        
        TLegend* leg1 = new TLegend(0.72,0.525,0.91,0.65,NULL,"brNDC");
        leg1->SetBorderSize(0);
        leg1->SetTextSize(0.045);
        leg1->SetTextFont(42);
        leg1->SetFillStyle(0);
        leg1->AddEntry(h_data,"data","p");
        leg1->AddEntry(fvn_combinemassvnfit,"Fit","l");
        //leg1->AddEntry(fvnsig,"#alpha(#it{m}_{#mu#mu})v_{2}^{S}","f");
        leg1->Draw("SAME");

        double xmass[200];
        double pullmass[200];
        
        float Chi2=0;
        int ndf = (fit_range_high - fit_range_low)/0.01 - 8;
        
        for(int k=0;k<h_data->GetNbinsX();k++)
        {
            xmass[k] = h_data->GetBinCenter(k);
            pullmass[k] = (h_data->GetBinContent(k) - fmass_combinemassvnfit->Eval(xmass[k]))/h_data->GetBinError(k);
            if(fabs(pullmass[k])<5)
            {
                //cout<<pullmass[k]<<endl;
                Chi2 += pullmass[k]*pullmass[k];
            }
        }

        c[i]->cd(1);
        tex->DrawLatex(0.22,0.67,Form("#chi^{2}/ndf = %.0f/%d",Chi2,ndf));
        
        double xv2[200];
        double pullv2[200];
        double v2y[200];
        
        float Chi2v2=0;
        int ndfv2 = 8 - 4; //Nbin - Npar
        
        for(int k=0;k<vn_data->GetN()-1;k++)
        {
            vn_data->GetPoint(k,xv2[k],v2y[k]);
            //xv2[k] = vn_dara->GetBinCenter(k);
            pullv2[k] = (v2y[k] - fvn_combinemassvnfit->Eval(xv2[k]))/vn_data->GetErrorY(k);
            cout<<k<<": "<<pullv2[k]<<endl;
            if(fabs(pullv2[k])<1000)
            {
                //cout<<pullmass[k]<<endl;
                Chi2v2 += pullv2[k]*pullv2[k];
            }
            cout<<"fcn: "<<fvn_combinemassvnfit->Eval(xv2[k])<<endl;
            cout<<"data: "<<v2y[k]<<endl;
        }

        c[i]->cd(2);
        tex->DrawLatex(0.22,0.67,Form("#chi^{2}/ndf = %.1f/%d",Chi2v2,ndfv2));
        
    }
    
    for(int i=0;i<npt;i++)
    {
        c[i]->Print(Form("plots/v30/eff/exp/JPsi_mass_vnfit_combine_pt%d.pdf",i));
        c[i]->Print(Form("plots/v30/eff/exp/JPsi_mass_vnfit_combine_pt%d.gif",i));
    }
    
    TGraphErrors* v2plot = new TGraphErrors(npt,pt,v2,0,v2e);
    TGraphErrors* v2ncqplot = new TGraphErrors(npt,KET_ncq,v2_ncq,0,v2e_ncq);
    TGraphErrors* v2bkgplot = new TGraphErrors(npt,pt,v2_bkg,0,0);
    
    v2plot->SetName("v2vspt");
    v2ncqplot->SetName("v2vsKET_ncq");
    v2bkgplot->SetName("v2bkgvspt");
    
    v2plot->Write();
    v2ncqplot->Write();
    v2bkgplot->Write();
}
Beispiel #27
0
void DrawEff_DS(){
gStyle->SetOptStat(kFALSE);
gStyle->SetErrorX(0);
//bool isweight=kFALSE;
bool isweight=kTRUE;
bool isHF=kTRUE;
//bool isHF=kFALSE;
if(isweight)
TString dir="weight";
else
TString dir="noweight";
const int Nhist=4;	const int NGen=1; const int Ncent=6;
//const double HFbin[]={0,0.1,0.2,0.4,0.6,0.8,1,2,4,6,9,12,15,20,30,50,75,100};
const double xerr[Ncent]={0,0,0,0,0,0};
/*
const double HFbin_cent[Nhist][Ncent+1]={
{0,2.92,10.1,19.3,23.7,30.2,100},
{0,1.03,5.00,11.6,15.0,20.3,100},
{0,2.7,12.6,28.6,36.9,49.6,100}};
*/
const double HFbin_cent[Nhist][Ncent+1]={
{0,2.725,10.065,19.565,23.975,30.455,100},
{0,0.975,5.005,11.775,15.285,20.725,100},
{0,2.515,12.465,28.855,37.235,50.085,100}};
const double cent[Ncent]={95,75,45,25,15,5};
const int nHFbin=sizeof(HFbin)/sizeof(double)-1;
//double color[NGen][Nhist]={{2,1,4},{2,1,4}};
//double Style[NGen][Nhist]={{20,24,28},{20,24,28}};
double color[NGen][Nhist]={{2,1,4}};
double Style[NGen][Nhist]={{20,24,28}};
//TString Gen[NGen]={"Hijing","Epos"};
TString Gen[NGen]={"Hijing"};
TString histoname[Nhist]={"HFEnergy4","HFEnergyPlus4","HFEnergyPlus","Ntrk"};
TString etarange[Nhist]={" HF E_{T} |#eta|>4"," HF E_{T} #eta>4"," HF E_{T} #eta>0",""};
TString filename[NGen];
TFile* f[NGen];
TH1F* h_or[NGen][Nhist];	TH1F* reh_or[NGen][Nhist];
TH1F* h_tr[NGen][Nhist];	TH1F* reh_tr[NGen][Nhist];
TH1F* h_ds[NGen][Nhist];	TH1F* reh_ds[NGen][Nhist];
TH1F* h_eff[NGen][Nhist];	TH1F* reh_eff[NGen][Nhist];

TLatex* T1[Nhist];	TLatex* T2;	TLatex* T3[NGen];
TF1 *fitEff[NGen][Nhist];
//TGraphAsymmErrors *gEff[NGen][Nhist];
TGraph *gEff[NGen][Nhist];
c1 = new TCanvas("c1"," ",800,500);
c2 = new TCanvas("c2"," ",800,700);
makeMultiPanelCanvas(c1,NGen,1,0.03,0.03,0.14,0.14,0.03);
makeMultiPanelCanvas(c2,1,1,0.03,0.03,0.03,0.03,0.03);

//for |eta|>4 HFEnergy:
/*
for(int k=0;k<NGen;k++)
for(int j=0;j<Nhist;j++)
fitEff[k][j]= new TF1(Form("fitEff_%s%s",Gen[k].Data(),histoname[j]),"[0]-[1]*exp([2]*x)-[3]*exp(-[4]*x)",0,300);

fitEff[0][0]->SetParameters(0.999876,0.44648,-1.78911,0.242036,0.549932);
fitEff[0][1]->SetParameters(1.,0.367894,-3.36629,0.104605,0.690272);
fitEff[0][2]->SetParameters(0.99981,0.697501,-2.59569,0.15323,0.411757);
fitEff[1][0]->SetParameters(0.999918,0.691843,-0.785042,0.0352768,0.449521);
fitEff[1][1]->SetParameters(0.999929,0.284,-2.25636,0.264114,0.951221);
fitEff[1][2]->SetParameters(0.999887,0.5,-2.39395,0.373215,0.550851);
*/

for(int k=0;k<NGen;k++){
T3[k]=new TLatex(0.45,0.93,Gen[k]);
T3[k]->SetNDC();
T3[k]->SetTextAlign(12);
T3[k]->SetTextSize(0.05);
T3[k]->SetTextColor(1);
T3[k]->SetTextFont(42);
}
for(int j=0;j<Nhist;j++){
T1[j]=new TLatex(0.4,0.85,etarange[j]);
T1[j]->SetNDC();
T1[j]->SetTextAlign(12);
T1[j]->SetTextSize(0.05);
T1[j]->SetTextColor(1);
T1[j]->SetTextFont(42);
}
T2=new TLatex(0.2,0.25,"Double Side");
T2->SetNDC();
T2->SetTextAlign(12);
T2->SetTextSize(0.06);
T2->SetTextColor(1);
T2->SetTextFont(42);
j=3;
for(int k=0;k<NGen;k++){
//for(int j=0;j<Nhist;j++){
filename[k]=Form("output/%s/pPbHist_%s_DS",dir.Data(),Gen[k].Data());
f[k]=TFile::Open(Form("%s.root",filename[k].Data()));
h_or[k][j]=(TH1F*)f[k]->Get(Form("h%s",histoname[j].Data()));
h_tr[k][j]=(TH1F*)f[k]->Get(Form("h%s_tr",histoname[j].Data()));
h_ds[k][j]=(TH1F*)f[k]->Get(Form("h%s_DS",histoname[j].Data()));
h_eff[k][j]=(TH1F*)f[k]->Get(Form("hEff_%s",histoname[j].Data()));
fixedFontHist(h_or[k][j],1.8,2);
fixedFontHist(h_tr[k][j],1.8,2);
fixedFontHist(h_ds[k][j],1.8,2);
//reh_or[k][j]=(TH1F*)h_or[k][j]->Clone(Form("re%s%s",Gen[k].Data(),histoname[j].Data()));
//reh_tr[k][j]=(TH1F*)h_tr[k][j]->Clone(Form("re%s%s_tr",Gen[k].Data(),histoname[j].Data()));
//reh_ds[k][j]=(TH1F*)h_ds[k][j]->Clone(Form("re%s%s_ds",Gen[k].Data(),histoname[j].Data()));

//reh_or[k][j]=(TH1F*)h_or[k][j]->Rebin(Ncent,Form("re%s%s",Gen[k].Data(),histoname[j].Data()),HFbin_cent[j]);
//reh_tr[k][j]=(TH1F*)h_tr[k][j]->Rebin(Ncent,Form("re%s%s_tr",Gen[k].Data(),histoname[j].Data()),HFbin_cent[j]);
//reh_ds[k][j]=(TH1F*)h_ds[k][j]->Rebin(Ncent,Form("re%s%s_ds",Gen[k].Data(),histoname[j].Data()),HFbin_cent[j]);
reh_or[k][j]=(TH1F*)h_or[k][j]->Rebin(nHFbin,Form("re%s%s",Gen[k].Data(),histoname[j].Data()),HFbin);
reh_tr[k][j]=(TH1F*)h_tr[k][j]->Rebin(nHFbin,Form("re%s%s_tr",Gen[k].Data(),histoname[j].Data()),HFbin);
reh_ds[k][j]=(TH1F*)h_ds[k][j]->Rebin(nHFbin,Form("re%s%s_ds",Gen[k].Data(),histoname[j].Data()),HFbin);
//normalizeByBinWidth(reh_or[k][j]);
//normalizeByBinWidth(reh_tr[k][j]);
//normalizeByBinWidth(reh_ds[k][j]);

//gEff[k][j]=new TGraphAsymmErrors();
gEff[k][j]=new TGraph(h_eff[k][j]);
gEff[k][j]->SetPoint(0,0,1);
gEff[k][j]->SetName(Form("gEff_%s%s",Gen[k].Data(),histoname[j].Data()));
//gEff[k][j]->BayesDivide(reh_tr[k][j],reh_ds[k][j]);
gEff[k][j]->SetMarkerColor(color[k][j]);
gEff[k][j]->SetLineColor(color[k][j]);
gEff[k][j]->SetMarkerStyle(Style[k][j]);
gEff[k][j]->SetMarkerSize(1.2);
gEff[k][j]->GetXaxis()->SetLimits(0.01,99.9);
gEff[k][j]->SetTitle("");
//}
}

TH1D * hFrame = new TH1D("","",100,0,100.);
if(!isHF){
   hFrame->GetXaxis()->SetLabelOffset(999);
   hFrame->GetXaxis()->SetTickLength(0);}
   hFrame->GetYaxis()->SetTitle("Event Selection Efficiency");
	hFrame->SetMaximum(1.09);
	hFrame->SetMinimum(0);
if(isHF)
hFrame->GetXaxis()->SetTitle("HF E_{T} (GeV/c)");
if(j==3)
hFrame->GetXaxis()->SetTitle("track Mult");
   hFrame->GetYaxis()->SetTitleSize(0.05);
        fixedFontHist(hFrame);
  hFrame->GetYaxis()->SetTitleOffset(1.5);

for(k=0;k<NGen;k++){
if(isHF)
c1->cd(k+1)->SetLogx();
else
c1->cd(k+1);
TLegend *leg=new TLegend(0.60,0.2,0.75,0.4);
if(k!=0){
hFrame->GetYaxis()->SetTitle("");
hFrame->GetYaxis()->SetLabelSize(0);
}
hFrame->DrawCopy();
//for(j=0;j<Nhist;j++){
if(isHF)
gEff[k][j]->Draw("Psame");
else{
ReverseXAxis(gEff[k][j],0.05);
ReverseXGraph(gEff[k][j]);
}
//fitEff[k][j]->SetLineStyle(color[k][j]);
//fitEff[k][j]->SetLineColor(color[k][j]);
//fitEff[k][j]->Draw("same");
leg->AddEntry(gEff[k][j],etarange[j],"lp");
//}
leg->SetTextSize(0.05);
leg->SetBorderSize(0);
leg->SetFillColor(0);
TLine *l=new TLine(0,1,100,1);
l->SetLineStyle(2);

l->Draw("same");
leg->Draw("same");
T3[k]->Draw("same");
}
if(isHF)
c1->Print(Form("pic/OwnBinning/pPbHist_%s_DS_HF.png",dir.Data()));
else
c1->Print(Form("pic/OwnBinning/pPbHist_%s_DS_cent.png",dir.Data()));


//------------------------------------------------------------------------------------------

if(isHF)
//c2->cd()->SetLogx();
//else
c2->cd();
TLegend *leg=new TLegend(0.7,0.2,0.85,0.4);
hFrame->GetYaxis()->SetTitle("Event Selection Efficiency");
hFrame->GetYaxis()->SetLabelSize(18);
hFrame->GetYaxis()->SetTitleOffset(1);
hFrame->DrawCopy();
for(k=0;k<NGen;k++){
if(k==0){
gEff[k][j]->SetMarkerColor(1);
gEff[k][j]->SetLineColor(1);
gEff[k][j]->SetMarkerStyle(20);
gEff[k][j]->SetMarkerSize(1.6);
}
else{
gEff[k][j]->SetMarkerColor(2);
gEff[k][j]->SetLineColor(2);
gEff[k][j]->SetMarkerStyle(24);
gEff[k][j]->SetMarkerSize(1.6);
}
if(isHF)
gEff[k][j]->Draw("Psame");
else{
ReverseXAxis(gEff[k][j],0.05);
ReverseXGraph(gEff[k][j]);
}
leg->SetTextSize(0.05);
leg->SetBorderSize(0);
leg->SetFillColor(0);
leg->AddEntry(gEff[k][j],Gen[k],"p");
TLine *l=new TLine(0,1,100,1);
l->SetLineStyle(2);
}
T1[j]->Draw("same");
leg->Draw("same");
l->Draw("same");

if(isHF)
c2->Print(Form("pic/OwnBinning/pPbHist_%s_DS_%s_HF.png",dir.Data(),histoname[j].Data()));
else
c2->Print(Form("pic/OwnBinning/pPbHist_%s_DS_%s_cent.png",dir.Data(),histoname[j].Data()));

}
Beispiel #28
0
void drawCMSresponse() {

  // New style settings
  // #include "tdrstyle_mod14.C"
  setTDRStyle();
  // call cmsPrel(iPeriod, iPos);
  // int iPeriod = 2;    // 1=7TeV, 2=8TeV, 3=7+8TeV, 7=7+8+13TeV 
  // second parameter in example_plot is iPos, which drives the position of the CMS logo in the plot
  // iPos=11 : top-left, left-aligned
  // iPos=33 : top-right, right-aligned
  // iPos=22 : center, centered
  // mode generally : 
  //   iPos = 10*(alignement 1/2/3) + position (1/2/3 = left/center/right)

  if (!_jec) {

    const char *sd = "CondFormats/JetMETObjects/data";
    //const char *st = "Winter14_V5_MC";
    //const char *st = "Winter14_V8_MC"; // 2012
    //const char *st = "Winter14_V8_DATA";
    //const char *st = "Summer15_25nsV3_DATA";
    //const char *st = "Summer15_25nsV6_DATA";
    //const char *st = "Summer15_25nsV7_DATA";
    //const char *st = "Fall15_25nsV1_DATA";
    //const char *st = "Spring16_25nsV3_MC";
    //const char *st = "Summer16_23Sep2016GV3_DATA"; // 2017
    //const char *st = "Summer16_03Feb2017G_V3_DATA"; // 2017 03FebV3
    const char *st = "Summer16_03Feb2017BCD_V7_DATA"; // 2017 03FebV7
    const char *s;

    //s = Form("%s/%s_L1FastJet_AK5PFchs.txt",sd,st); cout << s << endl;
    //JetCorrectorParameters *l1 = new JetCorrectorParameters(s);
    s = Form("%s/%s_L1FastJet_AK4PFchs.txt",sd,st); cout << s << endl;
    JetCorrectorParameters *l1 = new JetCorrectorParameters(s);
    //s = Form("%s/%s_L2Relative_AK5PFchs.txt",sd,st); cout << s << endl;
    s = Form("%s/%s_L2Relative_AK4PFchs.txt",sd,st); cout << s << endl;
    JetCorrectorParameters *l2 = new JetCorrectorParameters(s);
    //s = Form("%s/%s_L3Absolute_AK5PFchs.txt",sd,st); cout << s << endl;
    s = Form("%s/%s_L3Absolute_AK4PFchs.txt",sd,st); cout << s << endl;
    JetCorrectorParameters *l3 = new JetCorrectorParameters(s);
    s = Form("%s/%s_L2L3Residual_AK4PFchs.txt",sd,st); cout << s << endl;
    JetCorrectorParameters *l2l3 = new JetCorrectorParameters(s);

    vector<JetCorrectorParameters> v;
    v.push_back(l1);
    v.push_back(*l2);
    v.push_back(*l3);
    v.push_back(*l2l3);
    _jec = new FactorizedJetCorrector(v);
  }
  if (!_jecpt) {
    _jecpt = new TF1("jecpt",fJECPt,0,6500,3);
  }

  //double ergs[] = {30, 60, 110, 400, 2000};
  //const int ne = sizeof(ergs)/sizeof(ergs[0]);
  double pts[] = {10, 30, 100, 400, 2000};
  const int npt = sizeof(pts)/sizeof(pts[0]);
  const int neta = 48;//52;
  const int jeta = TMath::Pi()*0.4*0.4;
  const int mu = 0;

  TGraph *gs[npt];
  //for (int ie = 0; ie != ne; ++ie) {
  for (int ipt = 0; ipt != npt; ++ipt) {

    //double energy = ergs[ie];
    double pt = pts[ipt];

    TGraph *g = new TGraph(0); gs[ipt] = g;
    for (int ieta = 0; ieta != neta; ++ieta) {
      
      double eta = (ieta+0.5)*0.1;
      //double pt = energy / cosh(eta);
      double energy = pt * cosh(eta);
      if (pt >= 10. && energy < 6500.) { // 13 TeV

	double jes = getResp(pt, eta, jeta, mu);
	int n = g->GetN();
	g->SetPoint(n, eta, jes);
      }
    } // for ie
  } // for ieta


  // Draw results
  //TH1D *h = new TH1D("h",";Jet |#eta|;Simulated jet response",40,0,4.8);
  //TH1D *h = new TH1D("h",";Jet |#eta|;Data jet response",40,0,4.8);
  TH1D *h = new TH1D("h",";Jet |#eta|;Data response+offset",40,0,4.8);
  h->SetMaximum(1.25);
  h->SetMinimum(0.5);
  extraText = "Simulation";
  //extraText = "Simulation Preliminary";
  //extraText = "Preliminary";
  lumi_8TeV = "";
  lumi_13TeV = "";
  //lumi_13TeV = "2.1 fb^{-1}";
  //TCanvas *c1 = tdrCanvas("c1",h,2,0,kSquare);
  TCanvas *c1 = tdrCanvas("c1",h,4,0,kSquare);

  TLegend *leg1 = tdrLeg(0.25,0.25,0.55,0.30);
  TLegend *leg2 = tdrLeg(0.25,0.20,0.55,0.25);
  TLegend *leg3 = tdrLeg(0.25,0.15,0.55,0.20);
  TLegend *leg4 = tdrLeg(0.55,0.25,0.85,0.30);
  TLegend *leg5 = tdrLeg(0.55,0.20,0.85,0.25);
  TLegend *legs[npt] = {leg1, leg2, leg3, leg4, leg5};

  int colors[] = {kGreen+2, kBlack, kOrange+1, kBlue, kRed+1};
  int markers[] = {kFullCircle, kOpenCircle, kFullSquare, kOpenSquare,
		   kFullTriangleUp};

  for (int ipt = 0; ipt != npt; ++ipt) {
    
    TGraph *g = gs[ipt];
    g->SetMarkerColor(colors[ipt]);
    g->SetMarkerStyle(markers[ipt]);
    g->Draw("SAMEP");

    //TLegend *leg = (ie<3 ? leg1 : leg2);
    TLegend *leg = legs[ipt];
    leg->SetTextColor(colors[ipt]);
    //leg->AddEntry(g, Form("E = %1.0f GeV",ergs[ie]), "P");
    leg->AddEntry(g, Form("p_{T} = %1.0f GeV",pts[ipt]), "P");
  }


  TLatex *tex = new TLatex();
  tex->SetNDC();
  tex->SetTextSize(0.045);
  
  TLine *l = new TLine();
  l->DrawLine(1.3,0.7,1.3,1.1);
  l->DrawLine(2.5,0.7,2.5,1.1);
  l->DrawLine(3.0,0.7,3.0,1.1);
  l->DrawLine(4.5,0.7,4.5,1.1);
  l->SetLineStyle(kDashed);
  l->DrawLine(3.2,0.7,3.2,1.1);

  //tex->DrawLatex(0.23,0.86,"2012 JES: Anti-k_{t} R = 0.5, PF+CHS");
  //tex->DrawLatex(0.30,0.86,"53X JES: Anti-k_{t} R = 0.5, PF+CHS");
  //tex->DrawLatex(0.30,0.86,"74X JES: Anti-k_{t} R = 0.4, PF+CHS");
  //tex->DrawLatex(0.30,0.86,"76X JES: Anti-k_{t} R = 0.4, PF+CHS");
  //tex->DrawLatex(0.23,0.86,"2016 JES: Anti-k_{T} R=0.4, PF+CHS");
  tex->DrawLatex(0.23,0.86,"2017 JES: Anti-k_{t} R = 0.4, PF+CHS");
  //tex->DrawLatex(0.23,0.86,"2017 03FebV3: Anti-k_{t} R = 0.4, PF+CHS");
 
  tex->DrawLatex(0.19,0.78,"Barrel");
  tex->DrawLatex(0.47,0.78,"Endcap"); //0.42
  tex->DrawLatex(0.73,0.78,"Forward");

  tex->DrawLatex(0.21,0.73,"BB");
  tex->DrawLatex(0.43,0.73,"EC1");
  tex->DrawLatex(0.57,0.73,"EC2");
  tex->DrawLatex(0.77,0.73,"HF");

  c1->SaveAs("pdf/drawCMSresponse.pdf");
} // drawCMSresponse
Beispiel #29
0
void plottingmacro_IVF()
{


  double fa = 0.46502;
  double fb = 0.53498;
  bool debug_ = true;

  //  std::string path("Nov10thFall11Plots/");
  //  std::string path("Nov10Fall1160MTopSlimPlots/");
  std::string path("Nov10Fall1160MTopIVFPlots_b/");

  if(debug_)
    std::cout << "Init the style form setTDRStyle" << std::endl;
  setTDRStyle();
  gStyle->SetErrorX(0.5);
  gROOT->ForceStyle();
  initOptions();
  

  if(debug_)
    std::cout << "Init the sample" << std::endl;
  //  std::vector<Sample> s = Nov10thDiJetPtUpdatedSlimHistos();
  //std::vector<Sample> s = Nov10Fall1160MTopSlimHistos();
  std::vector<Sample> s = Nov10Fall1160MTopIVFHistos();

  Sample data(1,"fake data","S1.root",0,true,1000);

  if(debug_)
    std::cout << "Init the data sample" << std::endl;
  for(size_t i=0;i< s.size();i++) if(s[i].data) {data=s[i];break;}

  if(debug_)
    std::cout << "Ls data sample" << std::endl;
  data.file()->ls(); 

  if(debug_)
    std::cout << "Init the mc sample" << std::endl;
  for(size_t i=0;i< s.size();i++) s[i].dump(1,fa,fb);

  std::vector<std::string> names;

  if(debug_)
    std::cout << "Get List of Keys" << std::endl;
  TList * subs = data.file()->GetListOfKeys();
  for(size_t i=0;i< subs->GetSize();i++)
    {
      TString nn = subs->At(i)->GetName();
      if( nn.Contains(TRegexp("Count*")) )
	continue;
      if(debug_)
	std::cout << "Get List of Keys in subdirs" << std::endl;
      TList * objs = ((TDirectoryFile *)data.file()->Get(subs->At(i)->GetName()))->GetListOfKeys();
      for(size_t j=0;j< objs->GetSize();j++)
	{
	  if(debug_)
	    std::cout << "Name = " << subs->At(i)->GetName()+std::string("/")  + objs->At(j)->GetName() << std::endl;
	  names.push_back(subs->At(i)->GetName()+std::string("/")  + objs->At(j)->GetName());
	  //      std::cout << subs->At(i)->GetName() << "/"  << objs->At(j)->GetName() << std::endl;
	  //TODO: select plots via regexp
	}
    }


  if(debug_)
    std::cout << "Starting plotting" << std::endl;

  std::string process;

  for(size_t i = 0 ; i < names.size() ; i++) 
    {
      
      std::map<std::string,TH1F *> grouped;
      TString n=names[i];
      //      if(!n.Contains(TRegexp("VlightRegionHZee/HiggsPtVlightRegionHZee"))) continue;
      //      if(!n.Contains(TRegexp("VlightRegionHZee/ZPtVlightRegionHZee"))) continue;
      //      if(!n.Contains(TRegexp("VlightRegionHZee"))) continue;
      //      if(!n.Contains(TRegexp("ZSVRegionZmmSV"))) continue;
      //      if(!n.Contains(TRegexp("ZSVRegionZeeSV"))) continue;
      //      if(!n.Contains(TRegexp("ZSVRegionZcombSV"))) continue;
      //      if(!n.Contains(TRegexp("ZSVPureRegionZcombSV"))) continue;
      //      if(!n.Contains(TRegexp("ZSVTTbarPureRegionZcombSV"))) continue;
      if(!n.Contains(TRegexp("TTbarRegionZeeSVJets"))) continue;

      if(n.Contains(TRegexp("RegionHZcomb")))
	process = "Z(l^{+}l^{-})H(b#bar{b})";
      if(n.Contains(TRegexp("RegionHZmm")))
	process = "Z(#mu^{+}#mu^{-})H(b#bar{b})";
      if(n.Contains(TRegexp("RegionHZee")))
	process = "Z(e^{+}e^{-})H(b#bar{b})";

      if(debug_)
	std::cout << "Creating the Canvas" << std::endl;

      TCanvas *c = new TCanvas();
      c->SetLogy(false);
      c->SetTitle(names[i].c_str());

      if(debug_)
	std::cout << "Creating histograms" << std::endl;
  
      TH1F *hd = ((TH1F*)data.file()->Get(names[i].c_str()));
      hd->Sumw2();
      Options o=options[names[i]];
      //      hd->Rebin(o.rebin);
      hd->SetMarkerStyle(20);
      hd->GetXaxis()->SetLabelOffset(99);
      hd->SetYTitle(o.yaxis.c_str());
      double nbin = hd->GetNbinsX();
      double min_bin = hd->GetXaxis()->GetXmin();
      double max_bin = hd->GetXaxis()->GetXmax();
      TH1F *hmc = new TH1F("hmc","hmc", nbin, min_bin, max_bin);
      hmc->SetFillColor(kWhite);
      hmc->Sumw2();
      //      hmc->Rebin(o.rebin);

      if(debug_)
	std::cout << "Creating the THStack and Legend" << std::endl;
      THStack * sta = new THStack("sta",hd->GetTitle());
      TLegend * l = new TLegend(o.legendx1,o.legendy1,o.legendx2,o.legendy2); //0.7,0.1,0.9,0.6);
      l->SetFillColor(kWhite);
      l->SetBorderSize(0);
      l->SetTextFont(62);
      l->SetTextSize(0.03);
      if(debug_)
	std::cout << "Adding data to the legend" << std::endl;  
      l->AddEntry(hd, "Data","P");
      if(debug_)
	std::cout << "Adding MC to the THStack" << std::endl;  

      //with the proper trigger eff
      //      double SF[] = {1.01,1.03,1.00};
      //      double SF[] = {1.03,1.054,1.032};
      double SF[] = {1.0,1.0,1.0};

      if(debug_){
	for(int i = 0; i< 3; ++i)
	  std::cout << "SF [" << i << "] = " << SF[i] << std::endl;
      }

      double mcIntegral=0;
      for(size_t j=0;j< s.size() ;j++) 
	{ 
	  if(!s[j].data) 
	    {
	      if(debug_)
		std::cout << "Creating TH1F from file " << s[j].name << std::endl;  
	      TH1F * h = ((TH1F*)s[j].file()->Get(names[i].c_str()));
	      h->Sumw2();
	      if(debug_){
		std::cout << "TH1F created from file " << s[j].name << std::endl;  
		std::cout << "Scaling : " << s[j].scale(data.lumi(),fa,fb) << std::endl;  
		std::cout << "Scaling with SF : " << s[j].scale(data.lumi(),fa,fb,SF) << std::endl;  
		std::cout << "Histo integral before scaling = " << h->Integral() << std::endl;
	      }
	      h->Scale(s[j].scale(data.lumi(),fa,fb,SF));
	      if(debug_){
		std::cout << "Histo integral after scaling = " << h->Integral() << std::endl;
		std::cout << "Managing style... " << std::endl;  
	      }
	      h->SetLineWidth(1.);
	      h->SetFillColor(s[j].color);
	      h->SetLineColor(s[j].color);
	      //	      h->Rebin(options[names[i]].rebin);
	      if(debug_)
		std::cout << "Cloning and update legend " << std::endl;  
	      if(grouped.find(s[j].name) == grouped.end()){
		l->AddEntry(h,s[j].name.c_str(),"F");
	      }
	      std::cout << "Sample : " << s[j].name << " - Integral for plot " << names[i] << " = " << h->Integral(-10000,10000) << std::endl;
	      mcIntegral += h->Integral();
	      sta->Add(h);
	      hmc->Add(h);	      
	      //TO FIX grouped map
	      // sovrascrive histo con lo stesso nome tipo VV o ST etc...
	      grouped[s[j].name]=(TH1F *)h->Clone(("_"+names[i]).c_str());
	    }
	}

      if(debug_){
	std::cout << "Data total = " << hd->Integral() << std::endl;
	std::cout << "MC = " << mcIntegral << std::endl;
	std::cout << "Data/MC = " << hd->Integral()/mcIntegral << std::endl;
      }

      TPad * TopPad = new TPad("TopPad","Top Pad",0.,0.3,1.,1. ) ;
      TPad * BtmPad = new TPad("BtmPad","Bottom Pad",0.,0.,1.,0.313 ) ;
      TopPad->SetBottomMargin(0.02);
      BtmPad->SetTopMargin(0.0);
      BtmPad->SetFillStyle(4000);
      TopPad->SetFillStyle(4000);
      BtmPad->SetFillColor(0);
      BtmPad->SetBottomMargin(0.35);
      TopPad->Draw() ;
      BtmPad->Draw() ;
      std::cout << "hd maximum = " << hd->GetMaximum() << "  sta maximum = " << sta->GetMaximum() << std::endl;
      double maxY;
      if(hd->GetMaximum() > sta->GetMaximum()) maxY = (hd->GetMaximum())*1.5;
      else maxY = (sta->GetMaximum())*1.5;
      TopPad->cd();
      hd->Draw("E1X0");
      sta->Draw("sameHIST");
      hmc->Draw("sameE2");
      hmc->SetFillColor(2);
      hmc->SetMarkerSize(0);
      hmc->SetFillStyle(3013);
      hd->Draw("E1X0same");
      l->Draw("same");
      std::cout << "Set Maximum to = " << maxY << std::endl;
      hd->GetYaxis()->SetRangeUser(0.,maxY);
      hd->GetXaxis()->SetRangeUser(options[names[i]].min,options[names[i]].max);

      BtmPad->cd();
      std::cout << "Division" << std::endl;

      TH1D * divisionErrorBand = (TH1D*)(hmc)->Clone("divisionErrorBand");
      divisionErrorBand->Sumw2();
      divisionErrorBand->Divide(hmc);
      divisionErrorBand->Draw("E2");      
      divisionErrorBand->SetMaximum(2.49);
      divisionErrorBand->SetMinimum(0);
      divisionErrorBand->SetMarkerStyle(20);
      divisionErrorBand->SetMarkerSize(0.55);
      divisionErrorBand->GetXaxis()->SetTitleOffset(1.12);
      divisionErrorBand->GetXaxis()->SetLabelSize(0.12);
      divisionErrorBand->GetXaxis()->SetTitleSize(0.5);
      divisionErrorBand->GetYaxis()->SetTitle("Data/MC");
      divisionErrorBand->GetYaxis()->SetLabelSize(0.12);
      divisionErrorBand->GetYaxis()->SetTitleSize(0.12);
      divisionErrorBand->GetYaxis()->SetTitleOffset(0.40);
      divisionErrorBand->GetYaxis()->SetNdivisions(505);
      //divisionErrorBand->UseCurrentStyle();
      divisionErrorBand->SetFillColor(2);
      divisionErrorBand->SetFillStyle(3001);
      divisionErrorBand->SetMarkerSize(0.);

      TH1D * division = (TH1D*)(hd)->Clone("division");
      division->Sumw2();
      division->Divide(hmc);
//       division->SetMaximum(2.5);
//       division->SetMinimum(0);
//       division->SetMarkerStyle(20);
//       division->SetMarkerSize(0.55);
//       division->GetXaxis()->SetLabelSize(0.12);
//       division->GetXaxis()->SetTitleSize(0.14);
//       division->GetYaxis()->SetLabelSize(0.10);
//       division->GetYaxis()->SetTitleSize(0.10);
//      division->GetYaxis()->SetTitle("Data/MC");
      Double_t min = division->GetXaxis()->GetXmin();
      Double_t max = division->GetXaxis()->GetXmax();
      division->Draw("E1X0same");

      TLine *line = new TLine(min, 1.0, max, 1.0);
      line->SetLineColor(kRed);
      line->Draw("same");
      
      TLegend * leg3 =new TLegend(0.50,0.86,0.69,0.96);
      leg3->AddEntry(divisionErrorBand,"MC uncert. (stat.)","f");
      leg3->SetFillColor(0);
      leg3->SetLineColor(0);
      leg3->SetShadowColor(0);
      leg3->SetTextFont(62);
      leg3->SetTextSize(0.06);
      leg3->Draw();

      TPaveText *pave = new TPaveText(0.15,0.85,0.32,0.96,"brNDC");
      pave->SetTextAlign(12);
      pave->SetLineColor(0);
      pave->SetFillColor(0);
      pave->SetShadowColor(0);
      //TText *text = pave->AddText(Form("#chi_{#nu}^{2} = %.3f, K_{s} = %.3f",histDt->Chi2Test(histCopyMC5,"UWCHI2/NDF"),histDt->KolmogorovTest(histCopyMC5))); // stat + sys
      TText *text = pave->AddText(Form("#chi_{#nu}^{2} = %.3f, K_{s} = %.3f",hd->Chi2Test(hmc,"UWCHI2/NDF"),hd->KolmogorovTest(hmc))); // stat only
      text->SetTextFont(62);
      text->SetTextSize(0.08);
      pave->Draw();

      TopPad->cd();
      TLatex latex;
      latex.SetNDC();
      latex.SetTextAlign(12);
      latex.SetTextSize(0.052);
      latex.DrawLatex(0.17,0.89,"CMS Preliminary");
      latex.SetTextSize(0.04);
      latex.DrawLatex(0.17,0.84,"#sqrt{s} = 7 TeV, L = 4.7 fb^{-1}");
      //      latex.DrawLatex(0.17,0.79,"Z(e^{+}e^{-})H(b#bar{b})");
      latex.DrawLatex(0.17,0.79,process.c_str());
      c->Update();
      std::string cName= hd->GetName();
      cName += "_bare.pdf";
      cName = path+cName;
      c->Print(cName.c_str(),"pdf");

//       std::cout << names[i] << " d: " <<  hd->Integral() << " ";
//       THStack * sta2 = new THStack("sta2",hd->GetTitle());
//       float tot=0;
//       float toterr2=0;

//       if(debug_)
// 	std::cout << "Putting the iterator in the for loop" << std::endl;
//       for(std::map<std::string,TH1F *>::reverse_iterator it=grouped.rbegin(); it!=grouped.rend();++it)
//  	{
// 	  if(debug_)
// 	    std::cout << "Using the iterator" << std::endl;
// 	  std::cout << (*it).first << " " << (*it).second->Integral() << " | " << std::endl ;
// 	  if((*it).second->GetEntries() > 0) {
// 	    float er=1.*sqrt((*it).second->GetEntries())/(*it).second->GetEntries()*(*it).second->Integral();
// 	    toterr2+=er*er;
// 	  }
// 	  tot+=(*it).second->Integral();
// 	  sta2->Add(it->second);
//  	}
//       std::cout << " Tot: " << tot << "+-" << sqrt(toterr2) <<  " SF: " << hd->Integral()/tot << std::endl;
//       TCanvas *c2 = new TCanvas();
//       c2->SetTitle(names[i].c_str());
//       std::cout << "hd maximum = " << hd->GetMaximum() << "  sta2 maximum = " << sta2->GetMaximum() << std::endl;
//       if(hd->GetMaximum() > sta2->GetMaximum()) maxY =  hd->GetBinContent(hd->GetMaximumBin()) * 1.5;
//       else maxY = ( sta2->GetMaximum())*1.5;
//       //      hd->Draw("E1"); 
//       sta2->Draw("PADSHIST");
//       //    hd->Draw("E1same");
//       //      l->Draw("same");
//       std::cout << "Set Maximum to = " << maxY << std::endl;
//       hd->GetYaxis()->SetRangeUser(0.,maxY);
//       hd->GetXaxis()->SetRangeUser(options[names[i]].min,options[names[i]].max);
//       c2->Update();

//       std::string c2Name = hd->GetName();
//       c2Name = path+c2Name;
//       c2Name += "_norm.pdf";
//       c2->Print(c2Name.c_str(),"pdf");  

    }

}
void calculateTriggerRates(
			   TString inFile0Name = "root://eoscms//eos/cms/store/caf/user/velicanu/PA2013_merged_HiForest/pPb_hiForest2_pilotRun_200kHz_v3.root",
//         TString inFile0Name = "/castor/cern.ch/user/m/miheejo/openHLT/cms442/r181530_reco_v1_2/HIExpressPhysics_hiexp-hirun2011-r181530-reco-v1_2.root",
//         "/castor/cern.ch/user/k/kimy/openHLT//openhlt_run181531.root",
//         "/castor/cern.ch/user/v/velicanu/HIHLT_Validation_Test_GRIF_v10.root",
			   Int_t runNum        = 202792,
			   TString outdir      = "output",
			   char *projectTitle  = "HIpARun2013",
			   string source       = "data"
			   )
{
  char szBuf[256];
  int scale = 23;


  // event selectoin
  //Form("&&Run==%d&&LumiBlock>%d",runNum,goodLumiStart)
  // trigger under investigation
 //  const int ntrigs = 8;
//   const char* triggerPath[ntrigs] = {"","HLT_HIMinBiasHfOrBSC",
// 				     "L1_SingleMu3_BptxAND","HLT_HIL1SingleMu3","HLT_HIL2Mu3",
// 				     "L1_DoubleMuOpen_BptxAND","HLT_HIL1DoubleMuOpen","HLT_HIL2DoubleMu3"};

  /* const int ntrigs = 9;
  const char* triggerPath[ntrigs] = {
    "",
    "HLT_PAL1SingleMuOpen_v1",
    "HLT_PAL1SingleMu3_v1",
    "HLT_PAL1SingleMu7_v1",
    "HLT_PAL1SingleMu12_v1",
    "HLT_PAL1DoubleMu0_v1",
    "HLT_PADimuon0_NoVertexing_v1",
    "HLT_PAMu5_v1",
    "HLT_PAMu8_v1"
    }; */
  //trigger list for singleMu rate plot
  const int ntrigs = 4 ;
  const char* triggerPath[ntrigs] = {
    "",
    "HLT_PAMu3_v1",
    "HLT_PAMu7_v1",
    "HLT_PAMu12_v1"
  };
  /*
  //trigger list for DoubleMu rate plot
  const int ntrigs = 4 ;
  const char* triggerPath[ntrigs] = {
    "",
    "HLT_PAL1DoubleMuOpen_v1",
    "HLT_PAL1DoubleMu0_HighQ_v1",
    "HLT_PAL2DoubleMu3_v1"
  };
  
  //trigger list fo bJet+Mu rate plot
  const int ntrigs =5;
  const char* triggerPath[ntrigs] = {
    "",
    "HLT_PAMu3PFJet20_v1",
    "HLT_PAMu3PFJet40_v1",
    "HLT_PAMu7PFJet20_v1",
    "HLT_PABTagMu_Jet20_Mu4_v1"    
    };*/
  
  TString str;
  TH1D *ahTemp[ntrigs];
  double ahTempRate[ntrigs];  //Rates (Integrated over lumisections)
  // Load input
  TChain * HltTree = new TChain("hltanalysis/HltTree","HI OpenHLT Tree");
  HltTree->Add(inFile0Name);
  cout << inFile0Name << endl;
  cout << " # entries: " << HltTree->GetEntries() << endl;
  int nEvents = HltTree->GetEntries();
  for(int it=1; it<ntrigs; it++)
  {
    
    TH1D *ph  = new TH1D("ph",";Lumi Section; Counts ",1100,0,1100);
    HltTree->Draw("LumiBlock>>ph",str.Format("%s",triggerPath[it]));
    TLegend *lTemp= new TLegend(0.2,0.8,0.8,0.9);
    lTemp->SetHeader(str.Format("Run : %d",runNum));
    lTemp->SetMargin(0.05);
    lTemp->SetFillStyle(0);
    lTemp->SetLineColor(0);
    lTemp->SetLineWidth(5.0);
    lTemp->SetTextSize(0.03); 
    lTemp->AddEntry(ph,str.Format("%s",triggerPath[it],"l")); 
    lTemp->Draw("same");
    c1->SaveAs(str.Format("%d_%s.pdf",runNum,triggerPath[it]));
    TH1D *phLumi = (TH1D*)gDirectory->Get("ph");
    phLumi->SetDirectory(0);
    phLumi->Scale(1./(phLumi->GetBinWidth(1)*23));// 1lumi unit=23 sec
    ahTempRate[it] = phLumi->Integral()/phLumi->GetNbinsX();
    ahTemp[it] = phLumi;

    cout<< triggerPath[it]<<"\t"<<phLumi->GetEntries()<< "\t" << ahTempRate[it] << endl;
   
  }
     
  //----------------------------
  // drawing part
  // axis
  //  TH1D * phLumiAxis = new TH1D("phLumiAxis",";Lumi Section;dEvt/dLumiSec",1100,0,1100);
  TH1D * phLumiAxis = new TH1D("phLumiAxis",";Lumi Section;Rate [Hz]",1,0,1200);
  phLumiAxis->SetMinimum(0.01);
  phLumiAxis->SetMaximum(1e+3);
  gStyle->SetOptStat(kFALSE);

  // legend
  TLegend *l0= new TLegend(0.2,0.7,0.8,0.9);
  l0->SetHeader(str.Format("Run : %d",runNum));
  l0->SetMargin(0.03);
  l0->SetFillStyle(0);
  l0->SetLineColor(0);
  l0->SetLineWidth(1.0);
  l0->SetTextSize(0.03); 
  
  // canvas
  TCanvas *pcLumi = new TCanvas("pcLumi","pcLumi");
  pcLumi->cd();
  phLumiAxis->Draw();
  pcLumi->SetLogy();
 
  for(int it=1; it<ntrigs; it++)
    {
      TH1 *phLocal = (TH1 *)(ahTemp[it]->Clone("phLocal"));
      phLocal->SetDirectory(0); 
      phLocal->SetLineColor(it);
      if (it >= 10) phLocal->SetLineColor(it+20);
      if(it==5)	phLocal->SetLineColor(kOrange+2);
      phLocal->Draw("same");
      l0->AddEntry(phLocal,str.Format("%s: %.2f Hz",triggerPath[it],ahTempRate[it]),"l");
      pcLumi->Update();
     
    }
  l0->Draw("same");
  pcLumi->SaveAs(str.Format("%d_ratedMu.png",runNum));
}