示例#1
0
TGraphErrors *ReadMWGraph(const char *name, Int_t flag)
{
  Double_t xreject = 0.49;

  TGraphErrors *g = new TGraphErrors(name);
  if (g->IsZombie()) return 0;
  while (g->GetX()[0] < xreject)
    g->RemovePoint(0);

  TGraphErrors *g2 = new TGraphErrors(name);
  if (g2->IsZombie()) return 0;
  while (g2->GetX()[0] < xreject)
    g2->RemovePoint(0);
  g2->SetMarkerStyle(4);
  g2->SetMarkerSize(1.00);
  g2->SetMarkerColor(kBlack);
  g2->SetLineColor(kBlack);

  TGraphErrors *gsys = new TGraphErrors(name, "%lg %lg %lg %*lg %lg");
  if (gsys->IsZombie()) return 0;
  while (gsys->GetX()[0] < xreject)
    gsys->RemovePoint(0);
  for (Int_t i = 0; i < gsys->GetN(); i++)
    gsys->SetPointError(i, gsys->GetErrorX(i)*0.75, gsys->GetErrorY(i));
  gsys->SetFillColor(kGray+2);
  gsys->SetLineColor(kGray+2);
  gsys->SetFillStyle(3000);

  if (flag == 1 || flag == 3) {
    TGraphErrors *gt = new TGraphErrors(Form("%s_%s", name, "trues"));
    if (gt->IsZombie()) return 0;
    while (gt->GetX()[0] < xreject)
      gt->RemovePoint(0);
    gt->SetMarkerStyle(20);
    gt->SetMarkerSize(0.75);
    gt->SetMarkerColor(kGreen+1);
    gt->SetLineColor(kGreen+1);

    TGraphErrors *gbw = new TGraphErrors(Form("%s_%s", name, "gen"));
    if (gbw->IsZombie()) return 0;
    while (gbw->GetX()[0] < xreject)
      gbw->RemovePoint(0);
    gbw->SetMarkerStyle(20);
    gbw->SetMarkerSize(0.75);
    gbw->SetMarkerColor(kBlue+1);
    gbw->SetLineColor(kBlue+1);

    for (Int_t i = 0; i < g->GetN(); i++) {
      g->SetPointError(i, g->GetEX()[i], 0.);
      gt->SetPointError(i, gt->GetEX()[i], 0.);
      gbw->SetPointError(i, gbw->GetEX()[i], 0.);
    }

    for (Int_t i = 0; i < g2->GetN(); i++) {
      g2->SetPoint(i, g2->GetX()[i], g2->GetY()[i] - gt->GetY()[i] + gbw->GetY()[i]);
      g2->SetPointError(i, g2->GetEX()[i], TMath::Sqrt(g2->GetEY()[i]*g2->GetEY()[i] + gt->GetEY()[i]*gt->GetEY()[i] +
                                                       gbw->GetEY()[i]*gbw->GetEY()[i]));

      //      g2->SetPoint(i, g2->GetX()[i], g2->GetY()[i] - gt->GetY()[i] + 1.01947);
      //      g2->SetPointError(i, g2->GetEX()[i], TMath::Sqrt(g2->GetEY()[i]*g2->GetEY()[i] + gt->GetEY()[i]*gt->GetEY()[i] +
      //                                                       7.78680e-06*7.78680e-06));

      gsys->SetPoint(i, gsys->GetX()[i], g2->GetY()[i]);
    }
  }

  g->SetTitle();
  g->SetName(name);
  g->GetXaxis()->SetTitle("p_{T}, GeV/c");
  g->SetMarkerStyle(20);
  g->SetMarkerSize(0.95);
  g->SetMarkerColor(kRed+1);
  g->SetLineColor(kRed+1);

  const Double_t mass = 1.019455;
  const Double_t mass_delta = 0.000020;
  const Double_t width = 0.00426;
  const Double_t width_delta = 0.00004;
  if (flag == 1) { // mass
    g->GetYaxis()->SetTitleOffset(1.50);
    g->GetYaxis()->SetTitle("mass, GeV/c^{2}");
    g->SetMaximum(mass+0.0015);
    g->SetMinimum(mass-0.0015);
    TBox *box = new TBox(g->GetXaxis()->GetXmin(), mass - mass_delta, g->GetXaxis()->GetXmax(), mass + mass_delta);
    box->SetFillColor(kGray+1);
    box->SetFillStyle(3001);
    g->GetListOfFunctions()->Add(box);
    g->GetListOfFunctions()->Add(g2, "CP");
    g->GetListOfFunctions()->Add(gt, "CP");
    g->GetListOfFunctions()->Add(gbw, "CP");
  }
  else if (flag == 3) { // mass simple
    g2->SetTitle();
    g2->SetName(Form("%s_only", name));
    g2->GetXaxis()->SetTitle("p_{T}, GeV/c");
    g2->SetMarkerStyle(20);
    g2->SetMarkerSize(0.75);
    g2->SetMarkerColor(kBlack);
    g2->SetLineColor(kBlack);
    g2->GetYaxis()->SetTitleOffset(1.50);
    g2->GetYaxis()->SetTitle("mass, GeV/c^{2}");
    g2->SetMaximum(mass+0.0015);
    g2->SetMinimum(mass-0.0015);
    TBox *box = new TBox(g->GetXaxis()->GetXmin(), mass - mass_delta, g2->GetXaxis()->GetXmax(), mass + mass_delta);
    box->SetFillColor(kGray+1);
    box->SetFillStyle(3001);
    g2->GetListOfFunctions()->Add(box);
    g2->GetListOfFunctions()->Add(gsys, "E5");
    return g2;
  }
  else if (flag == 2) { // width
    g->SetTitle();
    g->SetName(name);
    g->GetXaxis()->SetTitle("p_{T}, GeV/c");
    g->SetMarkerStyle(20);
    g->SetMarkerSize(0.75);
    g->SetMarkerColor(kBlack);
    g->SetLineColor(kBlack);
    g->GetYaxis()->SetTitleOffset(1.50);
    g->GetYaxis()->SetTitle("width, GeV/c^{2}");
    g->SetMaximum(0.01);
    g->SetMinimum(0.0);
    TBox *box = new TBox(g->GetXaxis()->GetXmin(), width - width_delta, g->GetXaxis()->GetXmax(), width + width_delta);
    box->SetFillColor(kGray+1);
    box->SetFillStyle(3001);
    g->GetListOfFunctions()->Add(box);
    g->GetListOfFunctions()->Add(gsys, "E5");
  }

  return g;
}
示例#2
0
void DrawKinvarPlot(TString filename="kinvarset/FMSOR_Pt_vs_run.root",
                    TString classname="pi0") {
  TFile * infile = new TFile(filename.Data(),"READ");

  char trig[32];
  char typ[32];
  char tmp[128];
  TString tmpstr = filename;
  tmpstr.ReplaceAll("_"," ");
  TRegexp re("^.*\/");
  tmpstr(re) = "";
  cout << tmpstr << endl;
  sscanf(tmpstr.Data(),"%s %s",trig,typ);
  printf("%s %s\n",trig,typ);

  TString hname = "h2_"+classname;
  TH2D * h = (TH2D*)infile->Get(hname.Data());
  TString gname = "g_"+classname;
  TGraphErrors * g = (TGraphErrors*)infile->Get(gname.Data());
  TString gtname = "gt_"+classname;
  TGraphErrors * gt;
  if(!strcmp(typ,"Pt")) gt = (TGraphErrors*)infile->Get(gtname.Data());
  
  char htitle[256];
  char hnewtitle[512];
  strcpy(htitle,h->GetTitle());
  sprintf(hnewtitle,"%s -- %s triggers",htitle,trig);
  h->SetTitle(hnewtitle);

  h->SetMinimum(0.001);

  if(!strcmp(typ,"Pt")) {
    gt->SetLineWidth(2);
    gt->SetLineColor(kBlack);
  };

  // temporary hack to cut out fluctuations of pt_thresh vs. run to 0
  Double_t xx,yy;
  Int_t gtn = gt->GetN();
  for(int ii=0; ii<gtn; ii++) {
    gt->GetPoint(ii,xx,yy);
    printf("xx=%f yy=%f\n",xx,yy);
    if(yy<0.001) gt->RemovePoint(ii);
  };
   
  // drawing range
  Float_t xmin = h->GetXaxis()->GetXmin();
  Float_t xmax = h->GetXaxis()->GetXmax();
  xmax = 515;
  if(xmax<gtn) { 
    fprintf(stderr,"\nWARNING: xmax < gt->GetN(); graphs will be cut off!\n\n");
  };
  
  TCanvas * c = new TCanvas("c","c",1500,700);
  c->Divide(1,2);
  gStyle->SetOptStat(0);
  for(int x=1; x<=2; x++) c->GetPad(x)->SetGrid(1,1);
  c->cd(1);
  c->GetPad(1)->SetLogz();
  h->GetXaxis()->SetRangeUser(xmin,xmax);
  h->Draw("colz");
  if(!strcmp(typ,"Pt")) gt->Draw("LX");
  c->cd(2);
  g->SetFillColor(kGray);
  printf("%f %f\n",xmin,xmax);
  g->GetXaxis()->SetLimits(xmin,xmax);
  g->GetXaxis()->SetRangeUser(xmin,xmax);
  /*
  g->Draw("A3");
  g->Draw("PLX");
  */
  g->Draw("APLX");
  
  TString outname = filename.ReplaceAll(".root"," "+classname);
  outname = outname+".png";
  c->Print(outname.Data(),"png");
};
示例#3
0
文件: softrad.C 项目: cihar29/jecsys
// Soft radiation corrections for L3Res
void softrad(double etamin=0.0, double etamax=1.3, bool dodijet=false) {

  setTDRStyle();
  writeExtraText = false; // for JEC paper CWR

  TDirectory *curdir = gDirectory;

  // Open jecdata.root produced by reprocess.C
  TFile *fin = new TFile("rootfiles/jecdata.root","UPDATE");
  assert(fin && !fin->IsZombie());
  
  const int ntypes = 3;
  const char* types[ntypes] = {"data", "mc", "ratio"};
  const int nmethods = 2;
  const char* methods[nmethods] = {"mpfchs1", "ptchs"};
  const int nsamples = (dodijet ? 4 : 3);
  const char* samples[4] = {"gamjet", "zeejet", "zmmjet", "dijet"};
  string sbin = Form("eta%02.0f-%02.0f",10*etamin,10*etamax);
  const char* bin = sbin.c_str();
  const int nalphas = 4;
  const int alphas[nalphas] = {30, 20, 15, 10};

  // Z+jet bins
  const double ptbins1[] = {30, 40, 50, 60, 75, 95, 125, 180, 300, 1000};
  const int npt1 = sizeof(ptbins1)/sizeof(ptbins1[0])-1;
  TH1D *hpt1 = new TH1D("hpt1","",npt1,&ptbins1[0]);
  TProfile *ppt1 = new TProfile("ppt1","",npt1,&ptbins1[0]);

  // gamma+jet bins
  const double ptbins2[] = {30, 40, 50, 60, 75, 100, 125, 155, 180,
			    210, 250, 300, 350, 400, 500, 600, 800};
  const int npt2 = sizeof(ptbins2)/sizeof(ptbins2[0])-1;
  TH1D *hpt2 = new TH1D("hpt2","",npt2,&ptbins2[0]);
  TProfile *ppt2 = new TProfile("ppt2","",npt2,&ptbins2[0]);

  // dijet bins
  const double ptbins4[] = {20, 62, 107, 175, 242, 310, 379, 467,
			    628, 839, 1121, 1497, 2000};
  const int npt4 = sizeof(ptbins4)/sizeof(ptbins4[0])-1;
  TH1D *hpt4 = new TH1D("hpt4","",npt4,&ptbins4[0]);
  TProfile *ppt4 = new TProfile("ppt4","",npt4,&ptbins4[0]);

  TLatex *tex = new TLatex();
  tex->SetNDC();
  tex->SetTextSize(0.045);

  map<string,const char*> texlabel;
  texlabel["gamjet"] = "#gamma+jet";
  texlabel["zeejet"] = "Z#rightarrowee+jet";
  texlabel["zmmjet"] = "Z#rightarrow#mu#mu+jet";
  texlabel["dijet"] = "Dijet";
  texlabel["ptchs"] = "p_{T} balance (CHS)";
  texlabel["mpfchs"] = "MPF raw (CHS)";
  texlabel["mpfchs1"] = "MPF type-I (CHS)";

  // overlay of various alpha values
  TCanvas *c1 = new TCanvas("c1","c1",ntypes*400,nmethods*400);
  c1->Divide(ntypes,nmethods);

  TH1D *h1 = new TH1D("h1",";p_{T} (GeV);Response",1270,30,1300);

  // extrapolation vs alpha for each pT bin
  vector<TCanvas*> c2s(ntypes*nmethods);
  for (unsigned int icanvas = 0; icanvas != c2s.size(); ++icanvas) {
    TCanvas *c2 = new TCanvas(Form("c2_%d",icanvas),Form("c2_%d",icanvas),
			      1200,1200);
    c2->Divide(3,3);
    c2s[icanvas] = c2;
  }

  TH1D *h2 = new TH1D("h2",";#alpha;Response",10,0.,0.4);
  h2->SetMaximum(1.08);
  h2->SetMinimum(0.88);

  // krad corrections
  TCanvas *c3 = new TCanvas("c3","c3",ntypes*400,nmethods*400);
  c3->Divide(ntypes,nmethods);

  TH1D *h3 = new TH1D("h3",";p_{T,ref} (GeV);FSR sensitivity: -dR/d#alpha [%]",
		      1270,30,1300);

  cout << "Reading in data" << endl << flush;
  // Read in plots vs pT (and alpha)
  map<string, map<string, map<string, map<int, TGraphErrors*> > > > gemap;
  map<string, map<string, map<string, map<int, TGraphErrors*> > > > gamap;
  for (int itype = 0; itype != ntypes; ++itype) {
    for (int  imethod = 0; imethod != nmethods; ++imethod) {
      for (int  isample = 0; isample != nsamples; ++isample) {

	for (int  ialpha = 0; ialpha != nalphas; ++ialpha) {

	  fin->cd();
	  assert(gDirectory->cd(types[itype]));
	  assert(gDirectory->cd(bin));
	  TDirectory *d = gDirectory;

	  const char *ct = types[itype];
	  const char *cm = methods[imethod];
	  const char *cs = samples[isample];
	  const int a = alphas[ialpha];
	  // Get graph made vs pT
	  string s = Form("%s/%s/%s_%s_a%d",types[itype],bin,cm,cs,a);
	  TGraphErrors *g = (TGraphErrors*)fin->Get(s.c_str());
	  if (!g) cout << "Missing " << s << endl << flush;
	  assert(g);

	  // Clean out empty points
	  // as well as trigger-biased ones for dijets
	  // as well as weird gamma+jet high pT point
	  for (int i = g->GetN()-1; i != -1; --i) {
	    if (g->GetY()[i]==0 || g->GetEY()[i]==0 ||
		(string(cs)=="dijet" && g->GetX()[i]<70.) ||
		(string(cs)=="gamjet" && g->GetX()[i]>600. && etamin!=0))
	      g->RemovePoint(i);
	  }

	  gemap[ct][cm][cs][a] = g;
	  
	  // Sort points into new graphs vs alpha
	  TH1D *hpt = (isample==0 ? hpt2 : hpt1);
	  TProfile *ppt = (isample==0 ? ppt2 : ppt1);
	  if (isample==3) { hpt = hpt4; ppt = ppt4; } // pas-v6
	  for (int i = 0; i != g->GetN(); ++i) {
	    
	    double pt = g->GetX()[i];
	    ppt->Fill(pt, pt);
	    int ipt = int(hpt->GetBinLowEdge(hpt->FindBin(pt))+0.5);
	    //int ipt = int(pt+0.5);
	    TGraphErrors *ga = gamap[ct][cm][cs][ipt];
	    if (!ga) {
	      ga = new TGraphErrors(0);
	      ga->SetMarkerStyle(g->GetMarkerStyle());
	      ga->SetMarkerColor(g->GetMarkerColor());
	      ga->SetLineColor(g->GetLineColor());
	      gamap[ct][cm][cs][ipt] = ga;
	    }
	    int n = ga->GetN();
	    ga->SetPoint(n, 0.01*a, g->GetY()[i]);
	    ga->SetPointError(n, 0, g->GetEY()[i]);
	  } // for i 

	} // for ialpha

      } // for isample
    } // for imethod
  } // for itype

  cout << "Drawing plots vs pT for each alpha" << endl << flush;

  // 2x6 plots
  for (int itype = 0; itype != ntypes; ++itype) {
    for (int  imethod = 0; imethod != nmethods; ++imethod) {

      const char *ct = types[itype];
      const char *cm = methods[imethod];

      int ipad = ntypes*imethod + itype + 1; assert(ipad<=6);
      c1->cd(ipad);
      gPad->SetLogx();
      h1->SetMaximum(itype<2 ? 1.15 : 1.08);
      h1->SetMinimum(itype<2 ? 0.85 : 0.93);
      h1->SetYTitle(Form("Response (%s)",ct));
      h1->DrawClone("AXIS");
      tex->DrawLatex(0.20,0.85,texlabel[cm]);
      tex->DrawLatex(0.20,0.80,"|#eta| < 1.3, #alpha=0.1--0.3");
      TLegend *leg = tdrLeg(0.60,0.75,0.90,0.90);

      for (int  isample = 0; isample != nsamples; ++isample) {
	for (int  ialpha = 0; ialpha != nalphas; ++ialpha) {

	  const char *cs = samples[isample];
	  const int a = alphas[ialpha];
	  TGraphErrors *g = gemap[ct][cm][cs][a]; assert(g);

	  // Clean out points with very large uncertainty for plot readability
	  for (int i = g->GetN()-1; i != -1; --i) {
	    if (g->GetEY()[i]>0.02) g->RemovePoint(i);
	  }

	  g->Draw("SAME Pz");

	  if (ialpha==0) leg->AddEntry(g,texlabel[cs],"P");
	}
      } // for isample

      // Individual plots for JEC paper
      if ( true ) { // paper

	TH1D *h = new TH1D(Form("h_5%s_%s",ct,cm),
			   Form(";p_{T} (GeV);Response (%s)",ct),
			   1270,30,1300);
	h->GetXaxis()->SetMoreLogLabels();
	h->GetXaxis()->SetNoExponent();
	h->SetMinimum(0.88);
	h->SetMaximum(1.13);

	writeExtraText = true;
	extraText = (string(ct)=="mc" ? "Simulation" : "");
	lumi_8TeV = (string(ct)=="mc" ? "" : "19.7 fb^{-1}");
	TCanvas *c0 = tdrCanvas(Form("c0_%s_%s",cm,ct), h, 2, 11, true);
	c0->SetLogx();
	

	TLegend *leg = tdrLeg(0.55,0.68,0.85,0.83);
	tex->DrawLatex(0.55,0.85,texlabel[cm]);
	tex->DrawLatex(0.55,0.18,"|#eta| < 1.3, #alpha=0.3");
	//tex->DrawLatex(0.55,0.18,"Anti-k_{T} R=0.5");

	// Loop over Z+jet and gamma+jet (only, no dijet/multijet)
	for (int  isample = 0; isample != min(3,nsamples); ++isample) {
	  
	  const char *cs = samples[isample];
	  TGraphErrors *g = gemap[ct][cm][cs][30]; assert(g);
	  g->Draw("SAME Pz");
	  
	  leg->AddEntry(g,texlabel[cs],"P");
	} // for isample

	if (etamin==0) {
	  c0->SaveAs(Form("pdf/paper_softrad_%s_%s_vspt.pdf",ct,cm));
	  c0->SaveAs(Form("pdfC/paper_softrad_%s_%s_vspt.C",ct,cm));
	}
	else {
	  c0->SaveAs(Form("pdf/an_softrad_%s_%s_eta%1.0f-%1.0f_vspt.pdf",
			  ct,cm,10*etamin,10*etamax));
	}
      } // paper

    } // for imethod
  } // for itype
  
  c1->cd(0);
  //cmsPrel(_lumi, true);
  CMS_lumi(c1, 2, 33);
  c1->SaveAs("pdf/softrad_2x6_vspt.pdf");


  cout << "Drawing plots vs alpha for each pT" << endl << flush;
  cout << "...and fitting slope vs alpha" << endl << flush;

  map<string, map<string, map<string, TGraphErrors* > > > gkmap;

  // 2x6 plots
  for (int itype = 0; itype != ntypes; ++itype) {
    for (int  imethod = 0; imethod != nmethods; ++imethod) {
      
      int icanvas = nmethods*imethod + itype; assert(icanvas<=6);
      TCanvas *c2 = c2s[icanvas]; assert(c2);

      const char *ct = types[itype];
      const char *cm = methods[imethod];

      const int npads = 9;
      for (int ipad = 0; ipad != npads; ++ipad) {
	c2->cd(ipad+1);
	h2->SetYTitle(Form("Response (%s)",ct));
	h2->DrawClone("AXIS");
	tex->DrawLatex(0.20,0.85,texlabel[cm]);
	tex->DrawLatex(0.20,0.80,"|#eta| < 1.3");
	tex->DrawLatex(0.20,0.75,Form("%1.0f < p_{T} < %1.0f GeV",
				      hpt1->GetBinLowEdge(ipad+1),
				      hpt1->GetBinLowEdge(ipad+2)));
	TLegend *leg = tdrLeg(0.65,0.75,0.90,0.90);
	leg->AddEntry(gemap[ct][cm]["gamjet"][30], texlabel["gamjet"], "P");
	leg->AddEntry(gemap[ct][cm]["zeejet"][30], texlabel["zeejet"], "P");
	leg->AddEntry(gemap[ct][cm]["zmmjet"][30], texlabel["zmmjet"], "P");
	leg->AddEntry(gemap[ct][cm]["dijet"][30], texlabel["dijet"], "P");
      }

      for (int  isample = 0; isample != nsamples; ++isample) {

	const char *cs = samples[isample];

	map<int, TGraphErrors*> &gam = gamap[ct][cm][cs];
	map<int, TGraphErrors*>::iterator itpt;
	for (itpt = gam.begin(); itpt != gam.end(); ++itpt) {

	  int ipt = itpt->first;
	  int jpt = hpt1->FindBin(ipt);
	  if (jpt>npads) continue;
	  assert(jpt<=npads);
	  c2->cd(jpt);
	  
	  TGraphErrors *ga = itpt->second; assert(ga);
	  
	  ga->Draw("SAME Pz");

	  // Fit slope
	  TF1 *f1 = new TF1(Form("f1_%s_%s_%s_%d",ct,cm,cs,ipt),
			    "(x<1)*([0]+[1]*x) + (x>1 && x<2)*[0] +"
			    "(x>2)*[1]",-1,1);
	  f1->SetLineColor(ga->GetLineColor());
	  f1->SetParameters(1,0);
	  const double minalpha = (isample==0 ? 10./ipt : 5./ipt);
	  // Constrain slope to within reasonable values
	  // in the absence of sufficient data using priors
	  if (true) { // use priors
	    int n = ga->GetN();
	    // For response, limit to 1+/-0.02 (we've corrected for L3Res
	    ga->SetPoint(n, 1.5, 1);
	    ga->SetPointError(n, 0, 0.02);
	    n = ga->GetN();
	    if (imethod==1) { // pT balance
	      // For pT balance, estimate slope of <vecpT2>/alpha from data
	      // => 7.5%/0.30 = 25%
	      // Approximate uncertainty on this to be
	      // 0.5%/0.30 ~ 1.5% for data, 0.5%/0.30 ~ 1.5% for Z+jet MC, and
	      // 2%/0.30 ~ 6% for gamma+jet MC (same as slope)
	      if (itype==0)               ga->SetPoint(n, 2.5, -0.250); // DT
	      if (itype==1 && isample!=0) ga->SetPoint(n, 2.5, -0.250); // MC
	      if (itype==1 && isample==0) ga->SetPoint(n, 2.5, -0.190);
	      if (itype==2 && isample!=0) ga->SetPoint(n, 2.5, -0.000); // rt
	      if (itype==2 && isample==0) ga->SetPoint(n, 2.5, -0.060); 
	      //
	      // BUG: found 2015-01-08 (no effect on ratio)
	      //if (itype==1)               ga->SetPointError(n, 0, -0.015);
	      if (itype==0)               ga->SetPointError(n, 0, -0.015); // DT
	      if (itype==1 && isample!=0) ga->SetPointError(n, 0, -0.015); // MC
	      if (itype==1 && isample==0) ga->SetPointError(n, 0, -0.060);
	      if (itype==2 && isample!=0) ga->SetPointError(n, 0, -0.015); // rt
	      if (itype==2 && isample==0) ga->SetPointError(n, 0, -0.060); 
	    }
	    if (imethod==0) { // MPF
	      // For MPF, expectation is no slope
	      // Maximal slope would be approximately
	      // (<vecpT2>/alpha ~ 25% from pT balance) times
	      // (response difference between pT1 and vecpT2~10%)
	      // => 0.25*0.10 = 2.5%
	      // For data/MC, estimate uncertainty as half of this
	      // => 1.25%
	      ga->SetPoint(n, 2.5, 0.);
	      if (itype!=2) ga->SetPointError(n, 0, 0.025);
	      if (itype==2) ga->SetPointError(n, 0, 0.0125);
	    } // MPF
	  } // use priors

	  if (ga->GetN()>2) {

	    f1->SetRange(minalpha, 3.);
	    ga->Fit(f1,"QRN");

	    if (f1->GetNDF()>=0) {
	      f1->DrawClone("SAME");
	      f1->SetRange(0,0.4);
	      f1->SetLineStyle(kDashed);
	      f1->DrawClone("SAME");

	      // Store results
	      TGraphErrors *gk = gkmap[ct][cm][cs];
	      if (!gk) {
		gk = new TGraphErrors(0);
		gk->SetMarkerStyle(ga->GetMarkerStyle());
		gk->SetMarkerColor(ga->GetMarkerColor());
		gk->SetLineColor(ga->GetLineColor());
		gkmap[ct][cm][cs] = gk;
	      }
	      int n = gk->GetN();
	      TProfile *ppt = (isample==0 ? ppt2 : ppt1);
	      if (isample==3) { ppt = ppt4; } // pas-v6
	      double pt = ppt->GetBinContent(ppt->FindBin(ipt));
	      gk->SetPoint(n, pt, f1->GetParameter(1));
	      gk->SetPointError(n, 0, f1->GetParError(1));
	    } // f1->GetNDF()>=0
	  } // ga->GetN()>2
	} // for itpt
	
      } // for isample
      
      c2->SaveAs(Form("pdf/softrad_3x3_%s_%s_vsalpha.pdf",ct,cm));
      
    }
  }


  cout << "Drawing plots of kFSR vs pT" << endl;

  // 2x6 plots
  for (int itype = 0; itype != ntypes; ++itype) {
    for (int  imethod = 0; imethod != nmethods; ++imethod) {

      const char *ct = types[itype];
      const char *cm = methods[imethod];

      TMultiGraph *mgk = new TMultiGraph();

      int ipad = ntypes*imethod + itype + 1; assert(ipad<=6);
      c3->cd(ipad);
      gPad->SetLogx();
      h3->SetMaximum(imethod==0 ? 0.05 : (itype!=2 ? 0.1 : 0.25));
      h3->SetMinimum(imethod==0 ? -0.05 : (itype!=2 ? -0.4 : -0.25));
      h3->SetYTitle(Form("k_{FSR} = dR/d#alpha (%s)",ct));
      h3->DrawClone("AXIS");
      tex->DrawLatex(0.20,0.85,texlabel[cm]);
      tex->DrawLatex(0.20,0.80,"|#eta| < 1.3");
      TLegend *leg = tdrLeg(0.60,0.75,0.90,0.90);

      for (int  isample = 0; isample != nsamples; ++isample) {

	const char *cs = samples[isample];
	TGraphErrors *gk = gkmap[ct][cm][cs]; assert(gk);
	
	leg->AddEntry(gk,texlabel[cs],"P");

	// Fit each sample separately for pT balance
	if (true) {

	  TF1 *fk = new TF1(Form("fk_%s_%s_%s",ct,cm,cs),
			    "[0]+[1]*log(0.01*x)+[2]*pow(log(0.01*x),2)",
			    30,1300);
	  fk->SetParameters(-0.25,-0.5);
	  fk->SetLineColor(gk->GetLineColor());
	  gk->Fit(fk, "QRN");

	  tex->SetTextColor(fk->GetLineColor());
	  tex->DrawLatex(0.55,0.27-0.045*isample,
			 Form("#chi^{2}/NDF = %1.1f / %d",
			      fk->GetChisquare(), fk->GetNDF()));
	  tex->SetTextColor(kBlack);

	  // Error band
	  const int n = fk->GetNpar();
	  TMatrixD emat(n,n);
	  gMinuit->mnemat(emat.GetMatrixArray(), n);
	  TF1 *fke = new TF1(Form("fk_%s_%s_%s",ct,cm,cs),
			     sr_fitError, 30, 1300, 1);
	  _sr_fitError_func = fk;
	  _sr_fitError_emat = &emat;

	  fke->SetLineStyle(kSolid);
	  fke->SetLineColor(fk->GetLineColor()-10);
	  fke->SetParameter(0,-1);
	  fke->DrawClone("SAME");
	  fke->SetParameter(0,+1);
	  fke->DrawClone("SAME");

	  fk->DrawClone("SAME");
	  gk->DrawClone("SAME Pz");

	  // Store soft radiation corrections in fsr subdirectory
	  assert(fin->cd(ct));
	  assert(gDirectory->cd(bin));
	  if (!gDirectory->FindObject("fsr")) gDirectory->mkdir("fsr");
	  assert(gDirectory->cd("fsr"));

	  TH1D *hk = (TH1D*)(isample==0 ? hpt2->Clone() : hpt1->Clone());
	  hk->SetName(Form("hkfsr_%s_%s",cm,cs));
	  TProfile *ppt = (isample==0 ? ppt2 : ppt1);
	  if (isample==3) { ppt = ppt4; } // pas-v6
	  for (int i = 1; i != hk->GetNbinsX()+1; ++i) {
	    double pt = ppt->GetBinContent(i);
	    if (pt>30 && pt<1300) {
	      hk->SetBinContent(i, fk->Eval(pt));
	      hk->SetBinError(i, fabs(fke->Eval(pt)-fk->Eval(pt)));
	    }
	    else {
	      hk->SetBinContent(i, 0);
	      hk->SetBinError(i, 0);
	    }
	  }
	  
	  hk->Write(hk->GetName(), TObject::kOverwrite);

	  // Factorize error matrix into eigenvectors
	  // Remember: A = Q*Lambda*Q^-1, where
	  // A is emat, Q is eigmat, and Lambda is a diagonal matrix with
	  // eigenvalues from eigvec on the diagonal. For eigenmatrix
	  // Q^-1 = Q^T, i.e. inverse matrix is the original transposed
	  TVectorD eigvec(n);
	  TMatrixD eigmat = emat.EigenVectors(eigvec);

	  // Eigenvectors are the columns and sum of eigenvectors squared
	  // equals original uncertainty. Calculate histograms from the
	  // eigenvectors and store them
	  TF1 *fkeig = (TF1*)fk->Clone(Form("%s_eig",fk->GetName()));
	  fkeig->SetLineStyle(kDotted);
	  for (int ieig = 0; ieig != n; ++ieig) {

	    // Eigenvector functions
	    for (int i = 0; i != n; ++i) {
	      fkeig->SetParameter(i, fk->GetParameter(i)
				  + eigmat[i][ieig] * sqrt(eigvec[ieig]));
	    }
	    fkeig->DrawClone("SAMEL");

	    // Eigenvector histograms evaluated at bin mean pT
	    TH1D *hke = (TH1D*)hk->Clone(Form("%s_eig%d",hk->GetName(),ieig));
	    hke->Reset();

	    for (int i = 0; i != gk->GetN(); ++i) {

	      double pt = gk->GetX()[i];
	      int ipt = hke->FindBin(pt);
	      // Need to store central value as well, because
	      // uncertainty sources are signed
	      hke->SetBinContent(ipt, fkeig->Eval(pt)-fk->Eval(pt));
	      hke->SetBinError(ipt, fabs(fkeig->Eval(pt)-fk->Eval(pt)));
	    }
	    hke->Write(hke->GetName(), TObject::kOverwrite);
	  }

	  cout << "." << flush;
	} // if tree
      } // for isample
    } // for imethod
  } // for itype
  
  c3->cd(0);
  //cmsPrel(_lumi, true);
  CMS_lumi(c3, 2, 33);
  c3->SaveAs("pdf/softrad_2x6_kfsr.pdf");

  fin->Close();
  curdir->cd();
} // softrad
示例#4
0
int main(int argc, char** argv) {
  
  gROOT->SetStyle("Plain");
  gStyle->SetPalette(1);

  // load ntuple
  TChain *chain = new TChain ("myanalysis/EcalAnalysisTree","EcalAnalysisTree") ;

  chain->Add("/tmp/malberti/EcalTree_EG_Run2010A-WZEG-Nov4Skim_v1_RAW-RECO.root");  
  chain->Add("/tmp/malberti/EcalTree_Electron_Run2010B-WZEG-Nov4Skim_v1_RAW-RECO.root");  

  int nEntries = (int)chain->GetEntries() ;
  cout << "FOUND " << nEntries  << " ENTRIES\n" << endl;;

 
  //ecalVariables variables
  unsigned int runId;
  unsigned int eventId;
  unsigned int eventNaiveId;
 
  int nEcalRecHits;
  float ecalRecHitType[3300];
  float ecalRecHitEnergy[3300];
  float ecalRecHitIEta[3300];
  float ecalRecHitIPhi[3300];
  float ecalRecHitTime[3300];
  float ecalRecHitChi2[3300];
  int ecalRecHitRecoFlag[3300];
  float ecalRecHitMatrixFlag[3300][5][5];
  float ecalRecHitMatrix[3300][5][5];
  float ecalRecHitS4oS1[3300];
  int ecalDigis[3300][10];
  int ecalGainId[3300][10];

  // Set branch addresses.
  chain -> SetBranchAddress("runId",                     &runId);
  chain -> SetBranchAddress("eventId",                   &eventId);
  chain -> SetBranchAddress("eventNaiveId",              &eventNaiveId);
  chain -> SetBranchAddress("nEcalRecHits",              &nEcalRecHits);
  chain -> SetBranchAddress("ecalRecHitType",            ecalRecHitType);
  chain -> SetBranchAddress("ecalRecHitEnergy",          ecalRecHitEnergy);
  chain -> SetBranchAddress("ecalRecHitIEta",            ecalRecHitIEta);
  chain -> SetBranchAddress("ecalRecHitIPhi",            ecalRecHitIPhi);
  chain -> SetBranchAddress("ecalRecHitTime",            ecalRecHitTime);
  chain -> SetBranchAddress("ecalRecHitChi2",            ecalRecHitChi2);
  chain -> SetBranchAddress("ecalRecHitRecoFlag",        ecalRecHitRecoFlag);
  chain -> SetBranchAddress("ecalRecHitMatrixFlag",      ecalRecHitMatrixFlag);
  chain -> SetBranchAddress("ecalRecHitMatrix",          ecalRecHitMatrix);
  chain -> SetBranchAddress("ecalRecHitS4oS1",           ecalRecHitS4oS1);
  chain -> SetBranchAddress("ecalDigis",                 ecalDigis);
  chain -> SetBranchAddress("ecalGainId",                ecalGainId);
   
   
  // output file
  char outfileName[100];
  sprintf(outfileName,"HistosSlewRate.root");
  cout << "Saving histograms on file " << outfileName  <<endl;

  TFile saving (outfileName,"recreate") ;
  

  // histos 
  TH1F *hGainSwitch = new TH1F("hGainSwitch","hGainSwitch",10,-5,5);
  hGainSwitch->GetXaxis()->SetTitle("Gain(max) - Gain(max-1)");

  TH1F *hSlewRate = new TH1F("hSlewRate","hSlewRate", 5000, 0, 5000); 
  hSlewRate ->SetFillStyle(1);
  hSlewRate ->SetFillColor(kRed);
  hSlewRate ->GetXaxis()->SetTitle("Slew Rate (ADC/ns)");

  TH2F *hAmplitude = new TH2F("hAmplitude","hAmplitude", 1000, 0, 10000, 500, 0, 5000); 
  hAmplitude -> SetMarkerColor(kRed);
  hAmplitude -> SetMarkerStyle(20);
  hAmplitude -> SetMarkerSize(0.35);
  hAmplitude -> GetXaxis() -> SetTitle("Expected Amplitude (ADC)");
  hAmplitude -> GetYaxis() -> SetTitle("Observed Amplitude (ADC)");

  TH2F *hAmplitude2 = new TH2F("hAmplitude2","hAmplitude2", 1000, 0, 10000, 500, 0, 5000); 
  hAmplitude2 -> SetMarkerColor(kBlue);
  hAmplitude2 -> SetMarkerStyle(20);
  hAmplitude2 -> SetMarkerSize(0.35);
  hAmplitude2 -> GetXaxis() -> SetTitle("Expected Amplitude (ADC)");
  hAmplitude2 -> GetYaxis() -> SetTitle("Observed Amplitude (ADC)");


  TH2F *hAmpl_vs_Time = new TH2F("hAmpl_vs_Time","hAmpl_vs_Time", 800, -100, 100, 1000, 0, 10000); 
  hAmpl_vs_Time -> SetMarkerColor(kRed);
  hAmpl_vs_Time -> SetMarkerStyle(20);
  hAmpl_vs_Time -> SetMarkerSize(0.3);
  hAmpl_vs_Time -> GetXaxis() -> SetTitle("Time (ns)");
  hAmpl_vs_Time -> GetYaxis() -> SetTitle("Expected Amplitude (ADC)");

  TH2F *hRatio_vs_Time = new TH2F("hRatio_vs_Time","hRatio_vs_Time", 800, -100, 100, 200, 0, 2); 
  hRatio_vs_Time -> SetMarkerColor(kRed);
  hRatio_vs_Time -> SetMarkerStyle(20);
  hRatio_vs_Time -> SetMarkerSize(0.3);
  hRatio_vs_Time -> GetXaxis() -> SetTitle("Time (ns)");
  hRatio_vs_Time -> GetYaxis() -> SetTitle("Ratio");

  TH1F *hr1 = new TH1F("hr1","hr1",200,0,2);
  TH1F *hr2 = new TH1F("hr2","hr2",200,0,2);

  TH1F *hTfit1 = new TH1F("hTfit1","hTfit1 (expected Amplitude < 3000 ADC)",400,-50,50);
  hTfit1 -> SetFillStyle(3001);
  hTfit1 -> SetFillColor(kRed+2);
  hTfit1 -> GetXaxis() -> SetTitle("T_{fit} (ns)");

  TH1F *hTfit2 = new TH1F("hTfit2","hTfit2 (expected Amplitude > 3000 ADC)",400,-50,50);
  hTfit2 -> SetFillStyle(3001);
  hTfit2 -> SetFillColor(kBlue+2);
  hTfit2 -> GetXaxis() -> SetTitle("T_{fit} (ns)");

  TH1F *hAmax1 = new TH1F("hAmax1","hTAmax1 (expected Amplitude < 3000 ADC)",1000,0,10000);
  hAmax1 -> SetFillStyle(3001);
  hAmax1 -> SetFillColor(kRed+2);
  hAmax1 -> GetXaxis() -> SetTitle("A_{max} (ADC counts)");

  TH1F *hAmax2 = new TH1F("hAmax2","hTAmax2 (expected Amplitude > 3000 ADC)",1000,0,10000);
  hAmax2 -> SetFillStyle(3001);
  hAmax2 -> SetFillColor(kBlue+2);
  hAmax2 -> GetXaxis() -> SetTitle("A_{max} (ADC counts)");


  TGraphErrors* gsample;
  char gname[100];
  char gtitle[100];
  int ievt=0;  

  float A[3300][10];
  float G[3] = {1.,2.,12.}; // gain ratios

  //loop over the events
  for (int entry = 0 ; entry < nEntries; ++entry) {
      
    chain -> GetEntry(entry) ;
    if (entry%10000==0) cout << "    Analyzing entry " << entry << endl;
        
    for (int ihit =0 ; ihit < nEcalRecHits; ihit++) {
      
      // barrel only
      if ( ecalRecHitType[ihit]!=0) continue; 

      float energy = ecalRecHitEnergy[ihit];
      float eta = ecalRecHitIEta[ihit]*0.0175;
      float theta = 2. * atan(exp(-eta));
      float et = energy*sin(theta); 
      
      //if ( energy < 100. ) continue;      // E>10 GeV
      
      //cerco il sample max
      float ped = (ecalDigis[ihit][0] + ecalDigis[ihit][1] + ecalDigis[ihit][2])/3;
      int imax = 0;
      int maxAmpl = 0;
      for (int isample = 0; isample < 10 ; isample++)
	{
	  if (ecalGainId[ihit][isample]!=0) A[ihit][isample] = (ecalDigis[ihit][isample] - ped) * G[ ecalGainId[ihit][isample] - 1]; 
	  
	  if ( A[ihit][isample] >= maxAmpl) 
	    {
	      imax = isample;
	      maxAmpl = A[ihit][isample] ;
	    }
	} // end loop over 10 samples
      


      // check gain switch
      bool gainSwitch = false;
      if (ecalGainId[ihit][imax-1]==1 && ecalGainId[ihit][imax] != ecalGainId[ihit][imax-1])   gainSwitch = true;
      
      //Seleziono eventi con gain switch
      if (!gainSwitch) continue;
      hGainSwitch -> Fill( ecalGainId[ihit][imax]-ecalGainId[ihit][imax-1]);

      //cout << "MAX sample = "<< imax << "   MAX amplitude = "<< A[ihit][imax] << "   MAX gain Id =" << ecalGainId[ihit][imax]<< endl;
      //cout << "MAX-1 sample = "<< imax-1 << "   MAX-1 amplitude = "<< A[ihit][imax-1] << "   MAX-1 gain Id =" << ecalGainId[ihit][imax-1] << endl;
      //cout << endl;   
      
     
      float slewRate = A[ihit][imax-1];
      hSlewRate -> Fill(slewRate); 

      // graphs
      gsample = new TGraphErrors();
      sprintf(gtitle,"shape_Run%d_Evt%d",runId,eventId);
      sprintf(gname,"shape_%d",ievt);
      gsample->SetName(gname);
      gsample->SetTitle(gtitle);
      gsample->GetXaxis()->SetTitle("Time (ns)");
      gsample->GetYaxis()->SetTitle("ADC counts");
      
      for (int isample = 0; isample < 10 ; isample++)
      	{
      	  gsample->SetPoint(isample, double(isample)*25., A[ihit][isample]);      
      	  gsample->SetPointError(isample,0.,0.9);      
      	}



      
      // fit function            
      TF1 *fpulseShape = new TF1("fpulseShape", pulseShape,0.,240.,3);
      fpulseShape->SetLineColor(kBlue);
      fpulseShape->SetParName(0,"Ped");
      fpulseShape->SetParName(1,"A");
      fpulseShape->SetParName(2,"T0");
      fpulseShape->FixParameter(0,0); // ped
      fpulseShape->SetParameter(1,A[ihit][imax]); // ampl
      fpulseShape->SetParameter(2,imax*25.); // T0
      gsample->RemovePoint(imax-1);
      gsample->Fit("fpulseShape","QSR+") ;
      //re-set dei punti, altrimenti root non li plotta!
      for (int isample = 0; isample < 10 ; isample++)
      	{
      	  gsample->SetPoint(isample, double(isample)*25., A[ihit][isample]);      
      	  gsample->SetPointError(isample,0.,0.9);      
      	}
      ievt++;
      

      float measuredAmpl = A[ihit][imax-1] ;
      float expectedAmpl = A[ihit][imax] * fpulseShape->Eval((imax-1)*25.)/fpulseShape->Eval(imax*25.);
                  
      hAmplitude  -> Fill(expectedAmpl,measuredAmpl);
      hAmplitude2 -> Fill( A[ihit][imax] * 0.774,measuredAmpl);
 

      float t0 = fpulseShape->GetParameter(2);
      
      hAmpl_vs_Time -> Fill(t0-125.,expectedAmpl);
      hRatio_vs_Time -> Fill(t0-125., fpulseShape->Eval((imax-1)*25.)/fpulseShape->Eval(imax*25.));
      
      if (expectedAmpl > 3000) {
	hr2->Fill( fpulseShape->Eval((imax-1)*25.)/fpulseShape->Eval(imax*25.));
	hTfit2->Fill(t0-125.);
	hAmax2->Fill(A[ihit][imax]);
      }
      else {
	hr1->Fill( fpulseShape->Eval((imax-1)*25.)/fpulseShape->Eval(imax*25.));
	hTfit1->Fill(t0-125.);
	hAmax1->Fill(A[ihit][imax]);
      }

      if ( expectedAmpl < 3000 )
	//if (ievt<10)
	gsample->Write();

    } // end loop over recHits
    
  }//end loop over events
 
 
  chain->Delete();

  saving.cd () ;

  hGainSwitch ->Write();
  hSlewRate   -> Write();
  hAmplitude  ->Write();
  hAmplitude2 ->Write();
  hAmpl_vs_Time ->Write();
  hRatio_vs_Time ->Write();
  hTfit1->Write();
  hTfit2->Write();
  hAmax1->Write();
  hAmax2->Write();

  hr1->Write();
  hr2->Write();

  saving.Close () ;
  
  return 0;
  
  
}
void plot_cent_allQQ(bool isPaper=false)
{
  gStyle->SetOptFit(0);
  gStyle->SetOptStat(0);

  // incl. and prompt J/psi
  // 0-100, 0-10, 10-20, 20-30, 30-40, 40-50, 50-100
  double promptTAA[] = {5.6625, 23.1857, 14.4777, 8.7830, 5.0892, 2.7484, 0.4682};
  double promptTAAError[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};

  double promptNpart[] = {113.0518, 355.3528, 261.4178, 187.1470, 129.9835, 86.2622, 22.0709};
  double promptNpartError[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};

  double promptNcoll[] = {362.4007, 1483.8875, 926.5725, 562.1105, 325.7105, 175.8948, 29.9663};
  double promptNcollError[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
  double promptrelCentBinWidth[] = {10.0, 1.0, 1.0, 1.0, 1.0, 1.0, 5.0};


  // Upsilon
  // 0-100, 0-10, 10-20, 20-100
  double upsTAA[] = {5.6625, 23.1857, 14.4777, 2.3702};
  double upsTAAError[] = {0.0, 0.0, 0.0, 0.0};

  double upsNpart[] = {113.0518, 355.3528, 261.4178, 64.2184};
  double upsNpartError[] = {0.0, 0.0, 0.0, 0.0};

  double upsNcoll[] = {362.4007, 1483.8875, 926.5725, 151.6934};
  double upsNcollError[] = {0.0, 0.0, 0.0, 0.0};
  double upsrelCentBinWidth[] = {10.0, 1.0, 1.0, 8.0};

  // non-prompt J/psi
  // 0-100, 0-20, 20-100
  double nonPromptTAA[] = {5.6625, 18.8317, 2.3702};
  double nonPromptTAAError[] = {0.0, 0.0, 0.0};

  double nonPromptNpart[] = {113.0518, 308.3853, 64.2184};
  double nonPromptNpartError[] = {0.0, 0.0, 0.0};

  double nonPromptNcoll[] = {362.4007, 1205.2300, 151.6934};
  double nonPromptNcollError[] = {0.0, 0.0, 0.0};
  double nonPromptrelCentBinWidth[] = {10.0, 2.0, 8.0};

  double promptSystX[] = {10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0};
  double nonPromptSystX[] = {10.0, 10.0, 10.0, 10.0, 10.0};
  double upsSystX[] = {10.0, 10.0, 10.0, 10.0, 10.0};

  
  double inclJpsiCent[] = {2.41, 1.78, 1.93, 2.37, 3.73, 5.23, 4.67};
  double inclJpsiCentError[] = {0.15, 0.20, 0.24, 0.33, 0.53, 0.81, 0.80};
  double inclJpsiCentSyst[] = {0.37, 0.28, 0.30, 0.37, 0.62, 0.93, 0.97};  

  double promptJpsiCent[] = {1.79, 1.18, 1.29, 2.18, 2.97, 3.88, 3.58};
  double promptJpsiCentError[] = {0.13, 0.17, 0.21, 0.33, 0.49, 0.75, 0.70};
  double promptJpsiCentSyst[] = {0.28, 0.18, 0.20, 0.34, 0.50, 0.69, 0.74};
    

  double inclJpsiCent2[] = {2.41, 1.84, 3.46};
  double inclJpsiCent2Error[] = {0.15, 0.15, 0.26};
  double inclJpsiCent2Syst[] = {0.37, 0.28, 0.57};

  double promptJpsiCent2[] = {1.79, 1.23, 2.85};
  double promptJpsiCent2Error[] = {0.13, 0.14, 0.25};
  double promptJpsiCent2Syst[] = {0.28, 0.18, 0.47};

  double nonPromptJpsiCent[] = {0.60, 0.59, 0.60};
  double nonPromptJpsiCentError[] = {0.09, 0.12, 0.14};
  double nonPromptJpsiCentSyst[] = {0.09, 0.10, 0.10};
  
  double upsCent[] = {0.485, 0.347, 0.643, 0.517};
  double upsCentError[] = {0.066, 0.096, 0.144, 0.101};
  double upsCentSyst[] = {0.089, 0.069, 0.118, 0.101};

  double upsCent2[] = {0.485, 0.468, 0.517};
  double upsCent2Error[] = {0.066, 0.081, 0.101};
  double upsCent2Syst[] = {0.089, 0.094, 0.101};

  TGraphErrors *gInclJpsiCent = new TGraphErrors(7, promptNpart, inclJpsiCent, promptNpartError, inclJpsiCentError);
  TGraphErrors *gPromptJpsiCent = new TGraphErrors(7, promptNpart, promptJpsiCent, promptNpartError, promptJpsiCentError);
  TGraphErrors *gNonPromptJpsiCent = new TGraphErrors(3, nonPromptNpart, nonPromptJpsiCent, nonPromptNpartError, nonPromptJpsiCentError);
  TGraphErrors *gUpsCent = new TGraphErrors(4, upsNpart, upsCent, upsNpartError, upsCentError);

  TGraphErrors *gInclJpsiCentSyst = new TGraphErrors(7, promptNpart, inclJpsiCent, promptSystX, inclJpsiCentSyst);
  TGraphErrors *gPromptJpsiCentSyst = new TGraphErrors(7, promptNpart, promptJpsiCent, promptSystX, promptJpsiCentSyst);
  TGraphErrors *gNonPromptJpsiCentSyst = new TGraphErrors(3, nonPromptNpart, nonPromptJpsiCent, nonPromptSystX, nonPromptJpsiCentSyst);
  TGraphErrors *gUpsCentSyst = new TGraphErrors(4, upsNpart, upsCent, upsSystX, upsCentSyst);

  TGraphErrors *gInclJpsiCentP = new TGraphErrors(7, promptNpart, inclJpsiCent, promptNpartError, promptNpartError);
  TGraphErrors *gPromptJpsiCentP = new TGraphErrors(7, promptNpart, promptJpsiCent, promptNpartError, promptNpartError);
  TGraphErrors *gNonPromptJpsiCentP = new TGraphErrors(3, nonPromptNpart, nonPromptJpsiCent, nonPromptNpartError, nonPromptNpartError);
  TGraphErrors *gUpsCentP = new TGraphErrors(4, upsNpart, upsCent, upsNpartError, upsNpartError);


  TGraphErrors *gInclJpsiMB = new TGraphErrors(1, promptNpart, inclJpsiCent, promptNpartError, inclJpsiCentError);
  TGraphErrors *gPromptJpsiMB = new TGraphErrors(1, promptNpart, promptJpsiCent, promptNpartError, promptJpsiCentError);
  TGraphErrors *gNonPromptJpsiMB = new TGraphErrors(1, nonPromptNpart, nonPromptJpsiCent, nonPromptNpartError, nonPromptJpsiCentError);
  TGraphErrors *gUpsMB = new TGraphErrors(1, upsNpart, upsCent, upsNpartError, upsCentError);

  TGraphErrors *gInclJpsiMBSyst = new TGraphErrors(1, promptNpart, inclJpsiCent, promptSystX, inclJpsiCentSyst);
  TGraphErrors *gPromptJpsiMBSyst = new TGraphErrors(1, promptNpart, promptJpsiCent, promptSystX, promptJpsiCentSyst);
  TGraphErrors *gNonPromptJpsiMBSyst = new TGraphErrors(1, nonPromptNpart, nonPromptJpsiCent, nonPromptSystX, nonPromptJpsiCentSyst);
  TGraphErrors *gUpsMBSyst = new TGraphErrors(1, upsNpart, upsCent, upsSystX, upsCentSyst);  


  TGraphErrors *gInclJpsiCent2 = new TGraphErrors(3, nonPromptNpart, inclJpsiCent2, nonPromptNpartError, inclJpsiCent2Error);
  TGraphErrors *gPromptJpsiCent2 = new TGraphErrors(3, nonPromptNpart, promptJpsiCent2, nonPromptNpartError, promptJpsiCent2Error);
  TGraphErrors *gInclJpsiCent2Syst = new TGraphErrors(3, nonPromptNpart, inclJpsiCent2, nonPromptSystX, inclJpsiCent2Syst);
  TGraphErrors *gPromptJpsiCent2Syst = new TGraphErrors(3, nonPromptNpart, promptJpsiCent2, nonPromptSystX, promptJpsiCent2Syst);


  // Remove MB point
  gInclJpsiCent->RemovePoint(0);
  gPromptJpsiCent->RemovePoint(0);
  gNonPromptJpsiCent->RemovePoint(0);
  gUpsCent->RemovePoint(0);

  gInclJpsiCentP->RemovePoint(0);
  gPromptJpsiCentP->RemovePoint(0);
  gNonPromptJpsiCentP->RemovePoint(0);
  gUpsCentP->RemovePoint(0);

  gInclJpsiCentSyst->RemovePoint(0);
  gPromptJpsiCentSyst->RemovePoint(0);
  gNonPromptJpsiCentSyst->RemovePoint(0);
  gUpsCentSyst->RemovePoint(0);

  gInclJpsiCent2->RemovePoint(0);
  gPromptJpsiCent2->RemovePoint(0);
  gInclJpsiCent2Syst->RemovePoint(0);
  gPromptJpsiCent2Syst->RemovePoint(0);


  gInclJpsiCent->SetName("gInclJpsiCent");
  gPromptJpsiCent->SetName("gPromptJpsiCent");
  gNonPromptJpsiCent->SetName("gNonPromptJpsiCent");

  gInclJpsiMB->SetName("gInclJpsiMB");
  gPromptJpsiMB->SetName("gPromptJpsiMB");
  gNonPromptJpsiMB->SetName("gNonPromptJpsiMB");

  gUpsCent->SetName("gUpsCent");
  gUpsMB->SetName("gUpsMB");

  gInclJpsiCent2->SetName("gInclJpsiCent2");
  gPromptJpsiCent2->SetName("gPromptJpsiCent2");

  gInclJpsiCentP->SetName("gInclJpsiCentP");
  gPromptJpsiCentP->SetName("gPromptJpsiCentP");
  gNonPromptJpsiCentP->SetName("gNonPromptJpsiCentP");
  gUpsCentP->SetName("gUpsCentP");

  gInclJpsiCentSyst->SetName("gInclJpsiCentSyst");
  gPromptJpsiCentSyst->SetName("gPromptJpsiCentSyst");
  gNonPromptJpsiCentSyst->SetName("gNonPromptJpsiCentSyst");

  gInclJpsiMBSyst->SetName("gInclJpsiMBSyst");
  gPromptJpsiMBSyst->SetName("gPromptJpsiMBSyst");
  gNonPromptJpsiMBSyst->SetName("gNonPromptJpsiMBSyst");

  gUpsCentSyst->SetName("gUpsCentSyst");
  gUpsMBSyst->SetName("gUpsMBSyst");

  gInclJpsiCent2Syst->SetName("gInclJpsiCent2Syst");
  gPromptJpsiCent2Syst->SetName("gPromptJpsiCent2Syst");

  // gInclJpsiCentSyst->SetFillColor(kGray+1);
  // gPromptJpsiCentSyst->SetFillColor(kAzure-9);
  // gNonPromptJpsiCentSyst->SetFillColor(kRed-10);
  // gUpsCentSyst->SetFillColor(kGreen-10);
  // gInclJpsiMBSyst->SetFillColor(kGray+1);
  // gPromptJpsiMBSyst->SetFillColor(kAzure-9);
  // gNonPromptJpsiMBSyst->SetFillColor(kRed-10);
  // gUpsMBSyst->SetFillColor(kGreen-10);
  // gInclJpsiCent->SetMarkerColor(kBlack);
  // gPromptJpsiCent->SetMarkerColor(kBlue);
  // gNonPromptJpsiCent->SetMarkerColor(kRed);
  // gUpsCent->SetMarkerColor(kGreen+2);

  gInclJpsiCentSyst->SetFillColor(kAzure-9);
  gPromptJpsiCentSyst->SetFillColor(kRed-9);
  gNonPromptJpsiCentSyst->SetFillColor(kOrange-9);
  gUpsCentSyst->SetFillColor(kGreen-9);

  gInclJpsiMBSyst->SetFillStyle(0);
  gPromptJpsiMBSyst->SetFillStyle(0);
  gNonPromptJpsiMBSyst->SetFillStyle(0);
  gUpsMBSyst->SetFillStyle(0);

  gInclJpsiMBSyst->SetLineWidth(3);
  gPromptJpsiMBSyst->SetLineWidth(3);
  gNonPromptJpsiMBSyst->SetLineWidth(3);
  gUpsMBSyst->SetLineWidth(3);

  gInclJpsiMBSyst->SetLineColor(kAzure-9);
  gPromptJpsiMBSyst->SetLineColor(kRed-9);
  gNonPromptJpsiMBSyst->SetLineColor(kOrange-9);
  gUpsMBSyst->SetLineColor(kGreen-9);

  if (isPaper) {
    gInclJpsiCent->SetMarkerColor(kBlue+1);
    gPromptJpsiCent->SetMarkerColor(kRed+2);
  }
  else {
    gInclJpsiCent->SetMarkerColor(kBlue);
    gPromptJpsiCent->SetMarkerColor(kRed);
  }
  gNonPromptJpsiCent->SetMarkerColor(kOrange+2);
  gUpsCent->SetMarkerColor(kGreen+2);

  gInclJpsiCent->SetMarkerStyle(20);
  gPromptJpsiCent->SetMarkerStyle(21);
  gNonPromptJpsiCent->SetMarkerStyle(29);
  gUpsCent->SetMarkerStyle(33);

  if (isPaper) {
    gInclJpsiMB->SetMarkerColor(kBlue+1);
    gPromptJpsiMB->SetMarkerColor(kRed+2);
  }
  else {
    gInclJpsiMB->SetMarkerColor(kBlue);
    gPromptJpsiMB->SetMarkerColor(kRed);
  }

  gNonPromptJpsiMB->SetMarkerColor(kOrange+2);
  gUpsMB->SetMarkerColor(kGreen+2);

  gInclJpsiMB->SetMarkerStyle(24);
  gPromptJpsiMB->SetMarkerStyle(25);
  gNonPromptJpsiMB->SetMarkerStyle(30);
  gUpsMB->SetMarkerStyle(27);

  gInclJpsiCent->SetMarkerSize(1.2);
  gInclJpsiMB->SetMarkerSize(1.2);

  gPromptJpsiCent->SetMarkerSize(1.2);
  gPromptJpsiMB->SetMarkerSize(1.2);

  gNonPromptJpsiCent->SetMarkerSize(2.0);
  gNonPromptJpsiMB->SetMarkerSize(2.0);

  gUpsCent->SetMarkerSize(2.0);
  gUpsMB->SetMarkerSize(2.0);

  gInclJpsiCentP->SetMarkerStyle(24);
  gPromptJpsiCentP->SetMarkerStyle(25);
  gNonPromptJpsiCentP->SetMarkerStyle(30);
  gUpsCentP->SetMarkerStyle(27);

  gInclJpsiCentP->SetMarkerColor(kBlack);
  gPromptJpsiCentP->SetMarkerColor(kBlack);
  gNonPromptJpsiCentP->SetMarkerColor(kBlack);
  gUpsCentP->SetMarkerColor(kBlack);

  gInclJpsiCentP->SetMarkerSize(1.2);
  gPromptJpsiCentP->SetMarkerSize(1.2);
  gNonPromptJpsiCentP->SetMarkerSize(2.0);
  gUpsCentP->SetMarkerSize(2.0);


  TH1F *f1 = new TH1F("f1","f1",1,0,400);
  TH1F *f1l = new TH1F("f1l","f1l",1,0,400);
  f1->SetBinContent(1,9.2);
  f1l->SetBinContent(1,3.8);
  f1->SetBinError(1,0.0);
  f1l->SetBinError(1,0.0);

  f1->SetLineWidth(1);
  f1->SetLineStyle(1);
  f1->SetFillColor(kGray);
  f1->SetFillStyle(1001);
  f1l->SetLineWidth(1);
  f1l->SetLineStyle(1);
  f1l->SetFillColor(10);
  f1l->SetFillStyle(1001);
  f1->GetXaxis()->SetTitle("N_{part}");
  f1->GetYaxis()->SetTitle("1/T_{AA} dN/dy (nb)");
  f1->GetXaxis()->CenterTitle(kTRUE);
  f1->GetYaxis()->SetRangeUser(0.0, 12.0);

  TCanvas *c1 = new TCanvas("c1","c1");

  f1->Draw("HIST2");
  f1l->Draw("HIST2same");
  gInclJpsiCentSyst->Draw("2");
  gPromptJpsiCentSyst->Draw("2");
  gInclJpsiCent->Draw("P");
  gPromptJpsiCent->Draw("P");
  gInclJpsiCentP->Draw("P");
  gPromptJpsiCentP->Draw("P");

  TLegend *leg1 = new TLegend(0.22,0.56,0.90,0.76);
  leg1->SetFillStyle(1001);
  leg1->SetFillColor(10);
  leg1->SetBorderSize(0);
  leg1->SetMargin(0.2);
  leg1->SetTextSize(0.04);

  leg1->AddEntry(gInclJpsiCent,"Inclusive J/#psi","P");
  leg1->AddEntry(gPromptJpsiCent,"Prompt J/#psi","P");
  leg1->AddEntry(f1,"pp interpolation (arXiv:1103.2394)","F");
  leg1->Draw();


  TLatex *pre = new TLatex(125,11.0,"CMS Preliminary");
  pre->SetTextFont(42);
  pre->SetTextSize(0.05);
  pre->Draw();

  TLatex *l1 = new TLatex(125,10.0,"PbPb  #sqrt{s_{NN}} = 2.76 TeV");
  l1->SetTextFont(42);
  l1->SetTextSize(0.05);
  l1->Draw();

  // TLatex *ly = new TLatex(200.0,5.25,"0.0 < |y| < 2.4");
  // ly->Draw();
  // TLatex *lpt = new TLatex(200.0,4.5,"6.5 < p_{T} < 30.0 GeV/c");
  // lpt->Draw();


  TLatex *ly = new TLatex(20.0,1.35,"0.0 < |y| < 2.4");
  ly->Draw();
  TLatex *lpt = new TLatex(20.0,0.6,"6.5 < p_{T} < 30.0 GeV/c");
  lpt->Draw();

  gPad->RedrawAxis();

  TCanvas *c1a = new TCanvas("c1a","c1a");

  TH1F *f1a = new TH1F("f1a","f1a",1,0,400);
  TH1F *f1al = new TH1F("f1al","f1al",1,0,400);
  f1a->SetBinContent(1,9.2*0.23); // MB high pT b-fraction
  f1al->SetBinContent(1,3.8*0.23); // MB high pT b-fraction
  f1a->SetBinError(1,0.0);
  f1al->SetBinError(1,0.0);

  f1a->SetLineWidth(1);
  f1a->SetLineStyle(1);
  f1a->SetFillColor(kGray);
  f1a->SetFillStyle(1001);
  f1al->SetLineWidth(1);
  f1al->SetLineStyle(1);
  f1al->SetFillColor(10);
  f1al->SetFillStyle(1001);
  f1a->GetXaxis()->SetTitle("N_{part}");
  f1a->GetYaxis()->SetTitle("1/T_{AA} dN/dy (nb)");
  f1a->GetXaxis()->CenterTitle(kTRUE);
  f1a->GetYaxis()->SetRangeUser(0.0,2.76);

  f1a->Draw("HIST2");
  f1al->Draw("HIST2same");
  gNonPromptJpsiCentSyst->Draw("2");
  gNonPromptJpsiCent->Draw("P");
  gNonPromptJpsiCentP->Draw("P");
  gNonPromptJpsiMBSyst->Draw("2");
  gNonPromptJpsiMB->Draw("P");


  TLegend *leg1a = new TLegend(0.22,0.56,0.90,0.69);
  leg1a->SetFillStyle(1001);
  leg1a->SetFillColor(kWhite);
  leg1a->SetBorderSize(0);
  leg1a->SetMargin(0.2);
  leg1a->SetTextSize(0.04);
  leg1a->SetNColumns(2);
  leg1a->SetColumnSeparation(-0.78);

  // leg1a->AddEntry(gNonPromptJpsiCent,"Non-prompt J/#psi (0-20%, 20-100%)","P");
  leg1a->AddEntry(gNonPromptJpsiCent,"Non-prompt J/#psi","P");
  leg1a->AddEntry(gNonPromptJpsiMB,"(0-100%)","P");
  //  leg1a->AddEntry(gNonPromptJpsiMB,"Non-prompt J/#psi (0-100%)","P");
  leg1a->AddEntry(f1a,"pp interpolation (arXiv:1103.2394)","F");
  leg1a->Draw();

  TLatex *prea = new TLatex(125,2.53,"CMS Preliminary");
  prea->SetTextFont(42);
  prea->SetTextSize(0.05);
  prea->Draw();

  TLatex *l1a = new TLatex(125,2.30,"PbPb  #sqrt{s_{NN}} = 2.76 TeV");
  l1a->SetTextSize(0.05);
  l1a->Draw();

  // TLatex *l1a = new TLatex(125,2.30,"L_{int} = 7.28");
  // l1a->SetTextSize(0.05);
  // l1a->Draw();

  // TLatex *lya = new TLatex(200.0,1.2075,"0.0 < |y| < 2.4");
  // lya->Draw();
  // TLatex *lpta = new TLatex(200.0,1.035,"6.5 < p_{T} < 30.0 GeV/c");
  // lpta->Draw();
  TLatex *lya = new TLatex(20.0,0.3105,"0.0 < |y| < 2.4");
  lya->Draw();
  TLatex *lpta = new TLatex(20.0,0.138,"6.5 < p_{T} < 30.0 GeV/c");
  lpta->Draw();

  gPad->RedrawAxis();
  
  TCanvas *c1b = new TCanvas("c1b","c1b");
  c1b->SetLogy();
  // TF1 *f1b = new TF1("f1b","0.753",0,400);
  // f1b->SetLineWidth(1);
  // f1b->SetLineStyle(2);
  // f1b->GetXaxis()->SetTitle("N_{part}");
  // f1b->GetYaxis()->SetTitle("1/T_{AA} dN/dy (pb)");
  // f1b->GetXaxis()->CenterTitle(kTRUE);

  // f1b->Draw();
  // f1b->GetYaxis()->SetRangeUser(0.0,1.6);

  TH1F *f1b = new TH1F("f1b","f1b",1,0,400);
  TH1F *f1bl = new TH1F("f1bl","f1bl",1,0,400);
  f1b->SetBinContent(1,0.753+sqrt(0.029*0.029+0.072*0.072));
  f1bl->SetBinContent(1,0.753-sqrt(0.029*0.029+0.072*0.072));
  f1b->SetBinError(1,0.0);
  f1bl->SetBinError(1,0.0);

  f1b->SetLineWidth(1);
  f1b->SetLineStyle(1);
  f1b->SetFillColor(kGray);
  f1b->SetFillStyle(1001);
  f1bl->SetLineWidth(2);
  f1bl->SetLineStyle(3);
  f1bl->SetFillColor(10);
  f1bl->SetFillStyle(1001);
  f1b->GetXaxis()->SetTitle("N_{part}");
  f1b->GetYaxis()->SetTitle("1/T_{AA} dN/dy (pb)");
  f1b->GetXaxis()->CenterTitle(kTRUE);
  f1b->GetYaxis()->SetRangeUser(0.0,1.8);



  TH1F *f2b = new TH1F("f2b","f2b",1,0,400);
  TH1F *f2bl = new TH1F("f2bl","f2bl",1,0,400);
  f2b->SetBinContent(1,7.37 + (0.13*0.13 + 0.61*0.61));
  f2bl->SetBinContent(1,7.37 - sqrt(0.13*0.13 + 0.42*0.42));
  f2b->SetBinError(1,0.0);
  f2bl->SetBinError(1,0.0);

  f2b->SetLineWidth(2);
  f2b->SetLineStyle(2);
  f2b->SetFillColor(kGray);
  f2b->SetFillStyle(1001);
  f2bl->SetLineWidth(1);
  f2bl->SetLineStyle(1);
  f2bl->SetFillColor(10);
  f2bl->SetFillStyle(1001);
  f2b->GetXaxis()->SetTitle("N_{part}");
  f2b->GetYaxis()->SetTitle("1/T_{AA} dN/dy (pb)");
  f2b->GetXaxis()->CenterTitle(kTRUE);
  f2b->GetYaxis()->SetRangeUser(0.1,20);


  f2b->Draw("HIST2");
  // f2bl->Draw("HIST2same");
  //  f1b->Draw("HIST2");
  f1bl->Draw("HIST2same");

  gUpsCentSyst->Draw("2");
  gUpsCent->Draw("P");
  gUpsCentP->Draw("P");
  gUpsMBSyst->Draw("2");
  gUpsMB->Draw("P");

  TLegend *leg1b = new TLegend(0.22,0.51,0.90,0.76);
  leg1b->SetFillStyle(1001);
  leg1b->SetFillColor(kWhite);
  leg1b->SetBorderSize(0);
  leg1b->SetMargin(0.2);
  leg1b->SetTextSize(0.04);
  leg1b->SetNColumns(2);
  leg1b->SetColumnSeparation(-1.25);
  leg1b->AddEntry(gUpsCent,"#Upsilon(1S)","P");
  leg1b->AddEntry(gUpsMB,"(0-100%)","P");
  leg1b->AddEntry(f1b,"CDF p#bar{p}  #sqrt{s} = 1.8 TeV","L");
  leg1b->AddEntry(f1b," ","");
  leg1b->AddEntry(f1b,"(PRL 75, 4358 (1995))","");
  leg1b->AddEntry(f2b," ","");
  leg1b->AddEntry(f2b,"CMS pp  #sqrt{s} = 7 TeV","L");
  leg1b->AddEntry(f2b," ","");
  leg1b->AddEntry(f2b,"(arXiv:1012.5545)","");
  leg1b->Draw();

  //  TLatex *preb = new TLatex(125,9.1667,"CMS Preliminary");
  TLatex *preb = new TLatex(125,12.816,"CMS Preliminary");
  preb->SetTextFont(42);
  preb->SetTextSize(0.05);
  preb->Draw();

  //  TLatex *l1b = new TLatex(125,8.889,"PbPb  #sqrt{s_{NN}} = 2.76 TeV");
  TLatex *l1b = new TLatex(125,8.752,"PbPb  #sqrt{s_{NN}} = 2.76 TeV");
  l1b->SetTextSize(0.05);
  l1b->Draw();

  TLatex *lyb = new TLatex(20.0,0.185,"0.0 < |y| < 2.4");
  //  TLatex *lyb = new TLatex(20.0,0.2025,"0.0 < |y| < 2.4");
  lyb->Draw();
  TLatex *lptb = new TLatex(20.0,0.130,"0.0 < p_{T} < 20.0 GeV/c");
  //  TLatex *lptb = new TLatex(20.0,0.09,"0.0 < p_{T} < 20.0 GeV/c");
  lptb->Draw();

  gPad->RedrawAxis();

  c1->SaveAs("inclJpsi_cent.pdf");
  c1a->SaveAs("nonpromptJpsi_cent.pdf");
  c1b->SaveAs("upsilon_cent.pdf");

  c1->SaveAs("inclJpsi_cent.png");
  c1a->SaveAs("nonpromptJpsi_cent.png");
  c1b->SaveAs("upsilon_cent.png");



  double bfractionCent[] = {0.2550, 0.3337, 0.3268, 0.0786, 0.2003, 0.2550, 0.2317};
  double bfractionCentError[] = {0.0351, 0.0723, 0.0833, 0.0541, 0.0738, 0.0966, 0.0885};
  double bfractionCentSyst[] = {0.0510, 0.0667, 0.0654, 0.0157, 0.0401, 0.0510, 0.0463}; // fixme: update syst. uncertainties

  double bfractionCoarseCent[] = {0.2550, 0.3289, 0.1757};
  double bfractionCoarseCentError[] = {0.0351, 0.0583, 0.0401};
  double bfractionCoarseCentSyst[] = {0.0510, 0.0658, 0.0351}; // fixme: update syst. uncertainties
  
  
  TGraphErrors *gBfractionCent = new TGraphErrors(7, promptNpart, bfractionCent, promptNpartError, bfractionCentError);

  TGraphErrors *gBfractionCentSyst = new TGraphErrors(7, promptNpart, bfractionCent, promptSystX, bfractionCentSyst);

  TGraphErrors *gBfractionCoarseCent = new TGraphErrors(3, nonPromptNpart, bfractionCoarseCent, nonPromptNpartError, bfractionCoarseCentError);

  TGraphErrors *gBfractionCoarseCentSyst = new TGraphErrors(3, nonPromptNpart, bfractionCoarseCent, nonPromptSystX, bfractionCoarseCentSyst);

  TGraphErrors *gBfractionCoarseCentP = new TGraphErrors(3, nonPromptNpart, bfractionCoarseCent, nonPromptNpartError, nonPromptNpartError);

  TGraphErrors *gBfractionMB = new TGraphErrors(1, promptNpart, bfractionCent, promptNpartError, bfractionCentError);

  TGraphErrors *gBfractionMBSyst = new TGraphErrors(1, promptNpart, bfractionCent, promptSystX, bfractionCentSyst);


  gBfractionCent->RemovePoint(0);
  gBfractionCoarseCent->RemovePoint(0);
  gBfractionCoarseCentP->RemovePoint(0);

  gBfractionCentSyst->RemovePoint(0);
  gBfractionCoarseCentSyst->RemovePoint(0);

  gBfractionCent->SetName("gBfractionCent");
  gBfractionMB->SetName("gBfractionMB");

  gBfractionCoarseCent->SetName("gBfractionCoarseCent");
  gBfractionCoarseCentP->SetName("gBfractionCoarseCentP");


  gBfractionCentSyst->SetName("gBfractionCentSyst");
  gBfractionMBSyst->SetName("gBfractionMBSyst");

  gBfractionCoarseCentSyst->SetName("gBfractionCoarseCentSyst");


  gBfractionCentSyst->SetFillColor(kAzure-9);
  gBfractionMBSyst->SetFillColor(kAzure-9);

  gBfractionCoarseCentSyst->SetFillColor(kAzure-9);

  gBfractionCentSyst->SetFillColor(kRed-9);
  gBfractionMBSyst->SetFillColor(kRed-9);
  gBfractionCoarseCentSyst->SetFillColor(kRed-9);


  if (isPaper) {
    gBfractionCent->SetMarkerColor(kRed+2);
    gBfractionMB->SetMarkerColor(kRed+2);
    gBfractionCoarseCent->SetMarkerColor(kRed+2);
  }
  else {
    gBfractionCent->SetMarkerColor(kRed);
    gBfractionMB->SetMarkerColor(kRed);
    gBfractionCoarseCent->SetMarkerColor(kRed);
  }

  gBfractionCent->SetMarkerStyle(20);
  gBfractionMB->SetMarkerStyle(24);
  gBfractionCoarseCent->SetMarkerStyle(20);

  gBfractionCent->SetMarkerSize(1.2);
  gBfractionMB->SetMarkerSize(1.2);
  gBfractionCoarseCent->SetMarkerSize(1.2);

  gBfractionCoarseCentP->SetMarkerStyle(24);
  gBfractionCoarseCentP->SetMarkerSize(1.2);


  TF1 *f2 = new TF1("f2","1",0,400);
  f2->SetLineWidth(1);
  f2->GetXaxis()->SetTitle("N_{part}");
  f2->GetYaxis()->SetTitle("B-fraction");
  f2->GetYaxis()->SetRangeUser(0.0,0.8);
  f2->GetXaxis()->CenterTitle(kTRUE);

  TCanvas *c2 = new TCanvas("c2","c2");
  f2->Draw();
  gBfractionCoarseCentSyst->Draw("2");
  gBfractionCoarseCent->Draw("P");
  gBfractionCoarseCentP->Draw("P");


  TLegend *leg2 = new TLegend(0.22,0.62,0.90,0.69);
  leg2->SetFillStyle(0);
  leg2->SetFillColor(kWhite);
  leg2->SetBorderSize(0);
  leg2->SetMargin(0.2);
  leg2->SetTextSize(0.04);
  leg2->AddEntry(gBfractionCoarseCent,"B-fraction","P");
  leg2->Draw();

  TLatex *pre2 = new TLatex(125,0.733336,"CMS Preliminary");
  pre2->SetTextFont(42);
  pre2->SetTextSize(0.05);
  pre2->Draw();

  TLatex *l2 = new TLatex(125,0.66664,"PbPb  #sqrt{s_{NN}} = 2.76 TeV");
  l2->SetTextSize(0.05);
  l2->Draw();

  TLatex *ly2 = new TLatex(20.0,0.090,"0.0 < |y| < 2.4");
  ly2->Draw();
  TLatex *lpt2 = new TLatex(20.0,0.04,"0.0 < p_{T} < 20.0 GeV/c");
  lpt2->Draw();

  gPad->RedrawAxis();
 
  c2->SaveAs("bFraction_cent.pdf");
  c2->SaveAs("bFraction_cent.png");
  return;

  TF1 *f3 = new TF1("f3","220",0,400);
  f3->GetXaxis()->SetTitle("N_{part}");
  f3->GetYaxis()->SetTitle("1/T_{AA} dN/dy (nb)");

  f3->GetYaxis()->SetRangeUser(0.0,1.0);
  f3->GetXaxis()->CenterTitle(kTRUE);


  double ppNpart[] = {2.0};
  double ppNpartError[] = {0.0};
  double ppNpartError2[] = {1.0};
  double ppCDF[] = {2.325};
  //  double ppCDF[] = {0.753};
  double ppCDFError[] = {0.029};
  double ppCDFSyst[] = {0.072};

  TGraphErrors *gUpsCDF = new TGraphErrors(1, ppNpart, ppCDF, ppNpartError, ppCDFError);
  TGraphErrors *gUpsCDFsyst = new TGraphErrors(1, ppNpart, ppCDF, ppNpartError2, ppCDFSyst);

  gUpsCDF->SetName("gUpsCDF");
  gUpsCDFsyst->SetName("gUpsCDFsyst");

  gUpsCDF->SetMarkerStyle(20);
  gUpsCDFsyst->SetFillColor(kGray);

  TCanvas *c3 = new TCanvas("c3","c3");
  // c3->SetRightMargin(rmargin);
  // c3->SetTopMargin(tmargin);

  f3->Draw();
  gUpsCent->Draw("P");
  gUpsMB->Draw("P");
  gUpsCDFsyst->Draw("2");
  gUpsCDF->Draw("P");

  // RAA
  double ppPromptJpsi = 226.0;
  double ppPromptJpsiError = 20;

  double inclJpsiRAA[5];
  double promptJpsiRAA[5];
  double nonPromptJpsiRAA[3];
  double upsRAA[4];

  double inclJpsiRAAError[5];
  double promptJpsiRAAError[5];
  double nonPromptJpsiRAAError[3];
  double upsRAAError[4];

  double inclJpsiRAASyst[5];
  double promptJpsiRAASyst[5];
  double nonPromptJpsiRAASyst[3];
  double upsRAASyst[4];

  for (int i=0; i<5; ++i) {
    inclJpsiRAA[i] = inclJpsiCent[i]/ppPromptJpsi;
    promptJpsiRAA[i] = promptJpsiCent[i]/ppPromptJpsi;

    inclJpsiRAAError[i] = inclJpsiRAA[i]*inclJpsiCentError[i]/inclJpsiCent[i];
    promptJpsiRAAError[i] = promptJpsiRAA[i]*promptJpsiCentError[i]/promptJpsiCent[i];

    inclJpsiRAASyst[i] = inclJpsiRAA[i]*inclJpsiCentSyst[i]/inclJpsiCent[i];
    promptJpsiRAASyst[i] = promptJpsiRAA[i]*promptJpsiCentSyst[i]/promptJpsiCent[i];
  }

  for (int i=0; i<3; ++i) {
    nonPromptJpsiRAA[i] = nonPromptJpsiCent[i]/(bfractionCent[i]*ppPromptJpsi);
    nonPromptJpsiRAAError[i] = nonPromptJpsiRAA[i]*nonPromptJpsiCentError[i]/nonPromptJpsiCent[i];
    nonPromptJpsiRAASyst[i] = nonPromptJpsiRAA[i]*nonPromptJpsiCentSyst[i]/nonPromptJpsiCent[i];
  }

  for (int i=0; i<4; ++i) {
    upsRAA[i] = upsCent[i]/ppCDF[0];
    upsRAAError[i] = upsRAA[i]*upsCentError[i]/upsCent[i];
    upsRAASyst[i] = upsRAA[i]*upsCentSyst[i]/upsCent[i];
  }

  TGraphErrors *gInclJpsiRAA = new TGraphErrors(5, promptNpart, inclJpsiRAA, promptNpartError, inclJpsiRAAError);
  TGraphErrors *gPromptJpsiRAA = new TGraphErrors(5, promptNpart, promptJpsiRAA, promptNpartError, promptJpsiRAAError);
  TGraphErrors *gNonPromptJpsiRAA = new TGraphErrors(3, nonPromptNpart, nonPromptJpsiRAA, nonPromptNpartError, nonPromptJpsiRAAError);
  TGraphErrors *gUpsRAA = new TGraphErrors(4, upsNpart, upsRAA, upsNpartError, upsRAAError);

  TGraphErrors *gInclJpsiRAAMB = new TGraphErrors(1, promptNpart, inclJpsiRAA, promptNpartError, inclJpsiRAAError);
  TGraphErrors *gPromptJpsiRAAMB = new TGraphErrors(1, promptNpart, promptJpsiRAA, promptNpartError, promptJpsiRAAError);
  TGraphErrors *gNonPromptJpsiRAAMB = new TGraphErrors(1, nonPromptNpart, nonPromptJpsiRAA, nonPromptNpartError, nonPromptJpsiRAAError);
  TGraphErrors *gUpsRAAMB = new TGraphErrors(1, upsNpart, upsRAA, upsNpartError, upsRAAError);


  TGraphErrors *gInclJpsiRAASyst = new TGraphErrors(5, promptNpart, inclJpsiRAA, promptSystX, inclJpsiRAASyst);
  TGraphErrors *gPromptJpsiRAASyst = new TGraphErrors(5, promptNpart, promptJpsiRAA, promptSystX, promptJpsiRAASyst);
  TGraphErrors *gNonPromptJpsiRAASyst = new TGraphErrors(3, nonPromptNpart, nonPromptJpsiRAA, nonPromptSystX, nonPromptJpsiRAASyst);
  TGraphErrors *gUpsRAASyst = new TGraphErrors(4, upsNpart, upsRAA, upsSystX, upsRAASyst);

  TGraphErrors *gInclJpsiRAAMBSyst = new TGraphErrors(1, promptNpart, inclJpsiRAA, promptSystX, inclJpsiRAASyst);
  TGraphErrors *gPromptJpsiRAAMBSyst = new TGraphErrors(1, promptNpart, promptJpsiRAA, promptSystX, promptJpsiRAASyst);
  TGraphErrors *gNonPromptJpsiRAAMBSyst = new TGraphErrors(1, nonPromptNpart, nonPromptJpsiRAA, nonPromptSystX, nonPromptJpsiRAASyst);
  TGraphErrors *gUpsRAAMBSyst = new TGraphErrors(1, upsNpart, upsRAA, upsSystX, upsRAASyst);


  gInclJpsiRAA->RemovePoint(0);
  gPromptJpsiRAA->RemovePoint(0);
  gNonPromptJpsiRAA->RemovePoint(0);
  gUpsRAA->RemovePoint(0);

  gInclJpsiRAASyst->RemovePoint(0);
  gPromptJpsiRAASyst->RemovePoint(0);
  gNonPromptJpsiRAASyst->RemovePoint(0);
  gUpsRAASyst->RemovePoint(0);

  gInclJpsiRAA->SetName("gInclJpsiRAA");
  gPromptJpsiRAA->SetName("gPromptJpsiRAA");
  gNonPromptJpsiRAA->SetName("gNonPromptJpsiRAA");

  gInclJpsiRAAMB->SetName("gInclJpsiRAAMB");
  gPromptJpsiRAAMB->SetName("gPromptJpsiRAAMB");
  gNonPromptJpsiRAAMB->SetName("gNonPromptJpsiRAAMB");

  gUpsRAA->SetName("gUpsRAASyst");
  gUpsRAAMB->SetName("gUpsRAAMBSyst");

  gInclJpsiRAASyst->SetName("gInclJpsiRAASyst");
  gPromptJpsiRAASyst->SetName("gPromptJpsiRAASyst");
  gNonPromptJpsiRAASyst->SetName("gNonPromptJpsiRAASyst");

  gInclJpsiRAAMBSyst->SetName("gInclJpsiRAAMBSyst");
  gPromptJpsiRAAMBSyst->SetName("gPromptJpsiRAAMBSyst");
  gNonPromptJpsiRAAMBSyst->SetName("gNonPromptJpsiRAAMBSyst");

  gUpsRAASyst->SetName("gUpsRAASyst");
  gUpsRAAMBSyst->SetName("gUpsRAAMBSyst");


  gInclJpsiRAASyst->SetFillColor(kGray+1);
  gPromptJpsiRAASyst->SetFillColor(kAzure-9);
  gNonPromptJpsiRAASyst->SetFillColor(kRed-10);
  gUpsRAASyst->SetFillColor(kGreen-10);

  gInclJpsiRAAMBSyst->SetFillColor(kGray+1);
  gPromptJpsiRAAMBSyst->SetFillColor(kAzure-9);
  gNonPromptJpsiRAAMBSyst->SetFillColor(kRed-10);
  gUpsRAAMBSyst->SetFillColor(kGreen-10);


  gInclJpsiRAA->SetMarkerColor(kBlack);
  gPromptJpsiRAA->SetMarkerColor(kBlue);
  gNonPromptJpsiRAA->SetMarkerColor(kRed);
  gUpsRAA->SetMarkerColor(kGreen+2);

  gInclJpsiRAAMB->SetMarkerColor(kBlack);
  gPromptJpsiRAAMB->SetMarkerColor(kBlue);
  gNonPromptJpsiRAAMB->SetMarkerColor(kRed);
  gUpsRAAMB->SetMarkerColor(kGreen+2);

  gInclJpsiRAA->SetMarkerStyle(20);
  gPromptJpsiRAA->SetMarkerStyle(21);
  gNonPromptJpsiRAA->SetMarkerStyle(22);
  gUpsRAA->SetMarkerStyle(23);

  gInclJpsiRAAMB->SetMarkerStyle(24);
  gPromptJpsiRAAMB->SetMarkerStyle(25);
  gNonPromptJpsiRAAMB->SetMarkerStyle(26);
  gUpsRAAMB->SetMarkerStyle(27);


  TF1 *f4 = new TF1("f4","1",0,400);
  f4->SetLineWidth(1);
  f4->GetXaxis()->SetTitle("N_{part}");
  f4->GetYaxis()->SetTitle("R_{AA}");
  f4->GetYaxis()->SetRangeUser(0.0,1.0);
  f4->GetXaxis()->CenterTitle(kTRUE);


  TCanvas *c4 = new TCanvas("c4","c4");
  // c4->SetRightMargin(rmargin);
  // c4->SetTopMargin(tmargin);
  c4->SetTickx();
  c4->SetTicky();

  f4->Draw();

  gInclJpsiRAASyst->Draw("2");
  gPromptJpsiRAASyst->Draw("2");
  gNonPromptJpsiRAASyst->Draw("2");
  gUpsRAASyst->Draw("2");


  gInclJpsiRAA->Draw("P");
  gPromptJpsiRAA->Draw("P");
  gNonPromptJpsiRAA->Draw("P");
  gUpsRAA->Draw("P");

  gInclJpsiRAAMBSyst->Draw("2");
  gPromptJpsiRAAMBSyst->Draw("2");
  gNonPromptJpsiRAAMBSyst->Draw("2");
  gUpsRAAMBSyst->Draw("2");

  gInclJpsiRAAMB->Draw("P");
  gPromptJpsiRAAMB->Draw("P");
  gNonPromptJpsiRAAMB->Draw("P");
  gUpsRAAMB->Draw("P");


  double ppg068RAA_mid[] = {0.37, 0.57, 0.66, 0.74};
  double ppg068RAA_midError[] = {0.04, 0.06, 0.07, 0.12};
  double ppg068RAA_midSyst[] = {0.06, 0.08, 0.10, 0.11};
  double ppg068Npart_mid[] = {279.9, 140.0, 60.0, 14.5};
  double ppg068Npart_midError[] = {4.0, 5.0, 4.0, 2.5};
  double ppg068SystX[] = {10.0, 10.0, 10.0, 10.0};

  TGraphErrors *gPPG068RAA_mid = new TGraphErrors(4, ppg068Npart_mid, ppg068RAA_mid, ppg068Npart_midError, ppg068RAA_midError);
  TGraphErrors *gPPG068RAA_midSyst = new TGraphErrors(4, ppg068Npart_mid, ppg068RAA_mid, ppg068SystX, ppg068RAA_midSyst);

  gPPG068RAA_midSyst->SetFillColor(kGray);
  gPPG068RAA_mid->SetMarkerStyle(24);
  gPPG068RAA_mid->SetMarkerColor(kBlack);


  double ppg068RAA_fwd[] = {0.16, 0.27, 0.3, 0.38, 0.6, 0.75};
  double ppg068RAA_fwdError[] = {0.05, 0.035, 0.035, 0.038, 0.032, 0.049};
  double ppg068RAA_fwdSyst[] = {0.035, 0.022, 0.02, 0.023, 0.017, 0.032};
  double ppg068Npart_fwd[] = {325.2, 234.6, 166.6, 114.2, 60.0, 14.5};
  double ppg068Npart_fwdError[] = {3.3, 4.7, 5.4, 4.4, 4.0, 2.5};
  double ppg068SystX_fwd[] = {10.0, 10.0, 10.0, 10.0, 10.0, 10.0};



  TGraphErrors *gPPG068RAA_fwd = new TGraphErrors(6, ppg068Npart_fwd, ppg068RAA_fwd, ppg068Npart_fwdError, ppg068RAA_fwdError);
  TGraphErrors *gPPG068RAA_fwdSyst = new TGraphErrors(6, ppg068Npart_fwd, ppg068RAA_fwd, ppg068SystX, ppg068RAA_fwdSyst);

  gPPG068RAA_fwdSyst->SetFillColor(kOrange-9);
  gPPG068RAA_fwd->SetMarkerStyle(20);
  gPPG068RAA_fwd->SetMarkerColor(kOrange+10);

  gPPG068RAA_midSyst->Draw("2");
  gPPG068RAA_mid->Draw("P");

  gPPG068RAA_fwdSyst->Draw("2");
  gPPG068RAA_fwd->Draw("P");

  return;
}
示例#6
0
文件: drawAvsB.C 项目: miquork/jecsys
// Determine sensitivity to tracker dynamic inefficiency
// by studying ratio of jet responses in Runs G and F (and BCD / F, E / F)
void drawAvsB() {

  setTDRStyle();

  string epocha = "BCD";//"BCD";//"H";//"F";//"BCD";//"F";//"E";//"BCD";//"F";
  string epochb = "GH";//"G";//"BCD";//"G";//"E";//"E";//"F";//"G";

  // Add the rest as well
  string epocha2 = "";//"EF";
  string epochb2 = "";//"G";

  string type = "data";

  vector<string> methods;
  methods.push_back("mpfchs1");
  methods.push_back("ptchs");
  bool nozjptb = false;
  bool nogjmpf = false;
  bool nogjptb = true;
  bool mjvsjes = false;
  
  vector<string> samples;
  samples.push_back("zeejet");
  samples.push_back("zmmjet");
  samples.push_back("gamjet");
  //samples.push_back("multijet");

  cout << "draw"<<epocha<<"vs"<<epochb<<endl;
  const char *ct = type.c_str();
  const char *pa = epocha.c_str();
  const char *pb = epochb.c_str();

  const char *pa2 = epocha2.c_str();
  const char *pb2 = epochb2.c_str();

  TFile *fg = new TFile(Form("rootfiles/jecdata%s.root",pb),"READ");
  assert(fg && !fg->IsZombie());

  TFile *ff = new TFile(Form("rootfiles/jecdata%s.root",pa),"READ");
  assert(ff && !ff->IsZombie());

  TFile *fg2(0), *ff2(0);
  if (epochb2!="") fg2 = new TFile(Form("rootfiles/jecdata%s.root",pb2),"READ");
  if (epocha2!="") ff2 = new TFile(Form("rootfiles/jecdata%s.root",pa2),"READ");

  TH1D *h = new TH1D("h",
		     Form(";p_{T,ref} (GeV);%s ratio (%s / %s)",
			  (type=="ratio" ? "Data/MC" :
			   type=="data" ? "Data/data" : "MC/MC"),
			  (epocha + (epocha2!="" ? "+"+epocha2 : "")).c_str(),
			  (epochb + (epochb2!="" ? "+"+epochb2 : "")).c_str()),
		     3470,30,3500);
  h->SetMinimum(0.90);
  h->SetMaximum(1.15);
  h->GetXaxis()->SetMoreLogLabels();
  h->GetXaxis()->SetNoExponent();

  if (epocha=="F" && epochb=="G")
    lumi_13TeV = "Run2016F+G, 3.1+7.1 fb^{-1}";
  if (epocha=="BCD" && epochb=="G")
    lumi_13TeV = "Run2016BCD+H, 12.9+8.8 fb^{-1}";
  if (epocha=="BCD" && epochb=="G")
    lumi_13TeV = "Run2016BCD+FearlyGH, 12.9+16.8 fb^{-1}";
  if (epocha=="BCD" && epochb=="F")
    lumi_13TeV = "Run2016BCD+F, 13+3.1 fb^{-1}";
  if (epocha=="BCD" && epochb=="E")
    lumi_13TeV = "Run2016BCD+E, 13+4.0 fb^{-1}";
  if (epocha=="E" && epochb=="F")
    lumi_13TeV = "Run2016E+F, 4.0+3.1 fb^{-1}";
  if (epocha=="F" && epochb=="E")
    lumi_13TeV = "Run2016E+F, 4.0+3.1 fb^{-1}";

  if ((epocha=="BCDEF" && epochb=="GH") ||
      (epocha=="BCD" && epocha2=="EF" && epochb=="H" && epochb2=="G")) 
    lumi_13TeV = "Run2016BCDEF+GH, 19.7+16.8 fb^{-1}";
  if (epocha=="EF" && epochb=="BCD")
    lumi_13TeV = "Run2016BCD+EF, 12.9+6.8 fb^{-1}";
  if (epocha=="H" && epochb=="G")
    lumi_13TeV = "Run2016G+H, 8.0+8.8 fb^{-1}";

  if ((epocha=="BCD" && epocha2=="EF" && epochb=="G" && epochb2=="H")) 
    lumi_13TeV = "Run2016BCDFearly+FlateGH, 19.7+16.8 fb^{-1}";

  if ((epocha=="BCD" && epocha2=="" && ((epochb=="GH" && epochb2=="") ||
					(epochb=="G" && epochb2=="H"))))
    lumi_13TeV = "Run2016BCD+FlateGH, 12.9+16.8 fb^{-1}";
  if ((epocha=="EF" && epocha2=="" && ((epochb=="GH" && epochb2=="") ||
				       (epochb=="G" && epochb2=="H"))))
    lumi_13TeV = "Run2016EF+FlateGH, 6.8+16.8 fb^{-1}";

  if ((epocha=="EF" && epocha2=="" && epochb=="G" && epochb2=="H")) 
    lumi_13TeV = "Run2016EFearly+FlateGH, 6.8+16.8 fb^{-1}";


  TCanvas *c1 = tdrCanvas("c1",h,4,11,true);
  c1->SetLogx();

  TLatex *tex = new TLatex();
  tex->SetNDC(); tex->SetTextSize(0.045);

  TMultiGraph *mg = new TMultiGraph();
  string s = "draw"+epocha+(epocha2!="" ? "p" + epocha2 : "")
    +"vs"+epochb+(epochb2!="" ? "p" + epochb2 : "");

  TGraphErrors *gmjb(0), *gmpf(0);

  for (unsigned int im = 0; im != methods.size(); ++im) {
    const char *cm = methods[im].c_str();

    tex->DrawLatex(0.20,0.75-0.06*im,cm);
    s += "_" + methods[im];

  for (unsigned int is = 0; is != samples.size(); ++is) {

    const char *cs = samples[is].c_str();
    TGraphErrors *gg = (TGraphErrors*)fg->Get(Form("%s/eta00-13/%s_%s_a30",ct,cm,cs));
    cout << cm << " " << cs << endl << flush;
    assert(gg);
    if (fg2) {
      TGraphErrors *gg2 = (TGraphErrors*)fg2->Get(Form("%s/eta00-13/%s_%s_a30",ct,cm,cs));
      assert(gg2);
      gg = addGraph(gg,gg2);
    }
    
    TGraphErrors *gf = (TGraphErrors*)ff->Get(Form("%s/eta00-13/%s_%s_a30",ct,cm,cs));
    assert(gf);
    if (ff2) {
      TGraphErrors *gf2 = (TGraphErrors*)ff2->Get(Form("%s/eta00-13/%s_%s_a30",ct,cm,cs));
      assert(gf2);
      gf = addGraph(gf,gf2);
    }
    
    if (!(gf->GetN()==gg->GetN())) {

      // Remove highest pT point is that is the offender (BCD vs GH)
      if (gg->GetN()>gf->GetN() &&
	  fabs(gg->GetX()[gg->GetN()-1]/gf->GetX()[gf->GetN()-1]-1)>0.1 &&
	  fabs(gg->GetX()[gg->GetN()-2]/gf->GetX()[gf->GetN()-1]-1)<0.1) {
	cout << "Remove point B(N-1)" << endl;
	gg->RemovePoint(gg->GetN()-1);
      }
      else {
	cout << "sample " << samples[is] << " method " << methods[im]
	     << " gf->N: " << gf->GetN() << " gg->N: " << gg->GetN() << endl;
	cout << " x_gf(N-1)=" << gf->GetX()[gf->GetN()-1]
	     << " x_gg(N-1)=" << gg->GetX()[gg->GetN()-1]
	     << " x_gg(N-2)=" << gg->GetX()[gg->GetN()-2] << endl;
      }

      assert(gf->GetN()==gg->GetN());
    }

    TGraphErrors *g = (TGraphErrors*)gg->Clone(Form("ge_%s_%s",cm,cs));
    for (int i = 0; i != g->GetN(); ++i) {
      double yg = gg->GetY()[i];
      double yf = gf->GetY()[i];
      g->SetPoint(i, gg->GetX()[i], yf / yg);
      double ex = gg->GetEX()[i];
      double eg = gg->GetEY()[i];
      double ef = gf->GetEY()[i];
      g->SetPointError(i, ex, yf/yg*sqrt(pow(eg/yg,2)+pow(ef/yf,2)));
    }
    //g->Draw(is==0 ? "AP" : "SAMEP");
    g->SetLineWidth(1+is);
    g->Draw("SAMEPZ");

    if (samples[is]=="gamjet" && methods[im]=="mpfchs1" && nogjmpf) {
      tex->SetTextColor(kBlue);
      tex->DrawLatex(0.20,0.63,"#gamma+jet MPF excl. from fit");
      tex->SetTextColor(kBlack);
    }
    else if (samples[is]=="gamjet" && methods[im]=="ptchs" && nogjptb) {
      tex->SetTextColor(kBlue);
      tex->DrawLatex(0.20,0.63,"#gamma+jet p_{T}^{bal} excl. from fit");
      tex->SetTextColor(kBlack);
    }
    else if ((samples[is]=="zmmjet" || samples[is]=="zeejet") &&
	     methods[im]=="ptchs" && nozjptb) {
      tex->SetTextColor(kRed);
      tex->DrawLatex(0.20,0.63,"Z+jet p_{T}^{bal} excl. from fit");
      tex->SetTextColor(kBlack);
    }
    else if (samples[is]=="multijet") {
      g->SetMarkerColor(kGray+1);
      g->SetLineColor(kGray+1);
      if (methods[im]=="ptchs") gmjb = g;
      if (methods[im]=="mpfchs1") gmpf = g;
    }
    else
      mg->Add(g);
  } // for is
  } // for im
  
  if (nogjmpf) s += "_nogjmpf";
  if (nogjptb) s += "_nogptb";
  if (nozjptb) s += "_nozptb";
  if (mjvsjes) {
    s += "_mjvsjes";
    tex->SetTextColor(kBlack);
    tex->DrawLatex(0.20,0.58,"Multijet vs JES fit");
  }

  TF1 *fjes = new TF1("fjes",jesFit,30,2200,2);
  fjes->SetParameters(0.99,0.05);
  mg->Fit(fjes,"RN");
  fjes->SetLineColor(kBlack);
  fjes->SetLineStyle(kDashed);
  fjes->SetLineWidth(2);
  fjes->SetRange(10.,3500.);
  fjes->Draw("SAME");
  
  //TF1 *ft = new TF1("ft","1-[0]-[1]*pow(x,[2]) + ([3]+[4]*log(x))/x",30,2200);
  //ft->SetParameters(0,0.05,-0.5,1,0.1);
  //ft->FixParameter(3,0);

  // Logarithmic sigmoid
  //TF1 *ft = new TF1("ft","[0]+(1-[0])/(1. + exp(-(log(x)-log(abs([1])))"
  //	       "/(log(abs([2])+abs([1]))-log(abs([1])))))", 30,2200);
  //ft->SetParameters(0.98, 150, 50);
  TF1 *ft = new TF1("ft","[0]+(1-[0])/(1. + exp(-(log(x)-[1])/[2]))",30,2200);
  //ft->SetParameters(0.98,log(145),log(190)-log(145));
  //ft->SetParameters(0.982,4.967,0.271);
  //ft->SetParameters(0.976,5.040,0.370); // ENDCAP
  //ft->SetParameters(0.985,5.0,0.3);
  ft->SetParameters(0.985,5.025,0.3);
  //ft->FixParameter(1,5.03); // semi-weighted average of BCD and EF
  //ft->FixParameter(2,0.395); // combined fit to BCD+EF / G+H 

  // ( 12.9*5.055+6.8*5.000)/(12.9+6.8)
  ft->FixParameter(1,5.036); // semi-weighted average of BCD/GH and EF/GH
  // ( 12.9*0.344 + 6.8*0.455)/(12.9+6.8)
  ft->FixParameter(2,0.391); // combined fit to BCD+EF / GH 

  // Log-sigmoid + powerlaw
  //TF1 *ft = new TF1("ft","[0]+(1-[0])/(1. + exp(-(log(x)-[1])/[2]))"
  //	       "*(1-[3]*pow(x,[4]))",30,2200);
  //ft->SetParameters(0.982,4.967,0.271,0.1,-0.2);
  // Double powerlaw
  //TF1 *ft = new TF1("ft","[4]-[0]*pow(x,[1])-[2]*pow(x,[3])",30,2200);
  //ft->SetParameters(0.05,-0.15,0.01,-0.3,1);
  

  mg->Fit(ft,"RN");
  ft->SetLineColor(kBlue);
  ft->SetLineWidth(2);
  ft->SetRange(10.,3500.);
  ft->Draw("SAME");

  // Map multijet with response ratio
  if (gmpf) { // we have multijet available
    TGraphErrors *gmpf2 = (TGraphErrors*)gmpf->Clone("gmpf2");
    gmpf2->SetMarkerColor(kBlack);//kGray+1);
    gmpf2->SetLineColor(kBlack);//kGray+1);
    for (int i = 0; i != gmpf->GetN(); ++i) {
      if (mjvsjes) {
	gmpf2->SetPoint(i, 0.4*gmpf->GetX()[i],
			fjes->Eval(gmpf->GetX()[i])/gmpf->GetY()[i]);
	gmpf2->SetPointError(i, 0.4*gmpf->GetEX()[i],
			     gmpf->GetEY()[i]);
      }
      else {
	gmpf2->SetPoint(i, 0.4*gmpf->GetX()[i],
			ft->Eval(gmpf->GetX()[i])/gmpf->GetY()[i]);
	gmpf2->SetPointError(i, 0.4*gmpf->GetEX()[i],
			     gmpf->GetEY()[i]);
      }
    }
    gmpf2->Draw("SAMEPz");
  } // multijet

  tex->SetTextColor(kBlue);
  tex->DrawLatex(0.50,0.85,Form("#chi^{2} / NDF = %1.1f / %d",
				ft->GetChisquare(),
				ft->GetNDF()));
  tex->SetTextColor(kBlack);
  tex->SetTextSize(0.040);
  tex->DrawLatex(0.50,0.80,Form("(#chi^{2} / NDF = %1.1f / %d)",
				fjes->GetChisquare(),
				fjes->GetNDF()));


  tex->SetTextColor(kBlue-9);
  tex->SetTextSize(0.030);
  tex->DrawLatex(0.20,0.25,ft->GetExpFormula());
  tex->DrawLatex(0.20,0.20,
		 Form("p_{0}=%1.3f#pm%1.3f"
		      ", p_{1}=%1.3f#pm%1.3f"
		      ", p_{2}=%1.3f#pm%1.3f",
		      ft->GetParameter(0),ft->GetParError(0),
		      ft->GetParameter(1),ft->GetParError(1),
		      ft->GetParameter(2),ft->GetParError(2)));
  if (ft->GetNpar()>3)
    tex->DrawLatex(0.20,0.17,
		   Form("p_{3}=%1.3f#pm%1.3f"
			", p_{4}=%1.3f#pm%1.3f",
			ft->GetParameter(3),ft->GetParError(3),
			ft->GetParameter(4),ft->GetParError(4)));

  c1->SaveAs(Form("pdf/%s.pdf",s.c_str()));

  for (int i = 0; i != ft->GetNpar(); ++i) {
    cout << Form("%s%1.4g",i==0 ? "{" : ", ",ft->GetParameter(i));
  }
  cout << "}" << endl;
    

}