Пример #1
0
  /** 
   * Create ratios to other data 
   * 
   * @param ib      Bin number  
   * @param res     Result
   * @param alice   ALICE result if any
   * @param cms     CMS result if any
   * @param all     Stack to add ratio to 
   */
  void Ratio2Stack(Int_t ib, TH1* res, TGraph* alice, TGraph* cms, THStack* all)
  {
    if (!all || !res || !(alice || cms)) return;

    Int_t        off  = 5*ib;
    TGraph*      gs[] = { (alice ? alice : cms), (alice ? cms : 0), 0 };
    TGraph**     pg   = gs;
    while (*pg) { 
      TGraph*     g = *pg;
      const char* n = (g == alice ? "ALICE" : "CMS");

      TH1*    r = static_cast<TH1*>(res->Clone(Form("ratio%s", n)));
      TString tit(r->GetTitle());
      tit.ReplaceAll("Corrected", Form("Ratio to %s", n));
      r->SetTitle(tit);
      r->SetMarkerColor(g->GetMarkerColor());
      r->SetLineColor(g->GetLineColor());

      TObject* tst = r->FindObject("legend");
      if (tst) r->GetListOfFunctions()->Remove(tst);

      for (Int_t i = 1; i <= r->GetNbinsX(); i++) {
	Double_t c = r->GetBinContent(i);
	Double_t e = r->GetBinError(i);
	Double_t o = g->Eval(r->GetBinCenter(i));
	if (o < 1e-12) { 
	  r->SetBinContent(i, 0);
	  r->SetBinError(i, 0);
	  continue;
	}
	r->SetBinContent(i, (c - o) / o + off);
	r->SetBinError(i, e / o);
      }
      all->Add(r);
      pg++;
    }
    TLegend* leg = StackLegend(all);
    if (!leg) return;
      
    TString   txt      = res->GetTitle();
    txt.ReplaceAll("Corrected P(#it{N}_{ch}) in ", "");
    if      (ib == 0) txt.Append(" "); // (#times1)");
    // else if (ib == 1) txt.Append(" (#times10)");
    else              txt.Append(Form(" (+%d)", off));

    TObject* dummy = 0;
    TLegendEntry* e = leg->AddEntry(dummy, txt, "p");
    e->SetMarkerStyle(res->GetMarkerStyle());
    e->SetMarkerSize(res->GetMarkerSize());
    e->SetMarkerColor(kBlack);
    e->SetFillColor(0);
    e->SetFillStyle(0);
    e->SetLineColor(kBlack);
  }
Пример #2
0
/** 
 * Draw final plot for QM2011
 * 
 * @param max 
 * 
 * @ingroup pwglf_forward_scripts
 */
void
dndeta_final(Double_t max=6)
{
  gStyle->SetOptTitle(0);
  gStyle->SetOptFit(0);
  gStyle->SetTitleFont(132, "xyz");
  gStyle->SetTitleSize(0.1, "xyz");
  gStyle->SetTitleOffset(0.4, "y");
  gStyle->SetTitleOffset(0.8, "x");
  gStyle->SetLabelFont(132, "xyz");
  gStyle->SetLabelSize(0.08, "xyz");
  gStyle->SetNdivisions(212, "x");
  gStyle->SetNdivisions(208, "y");
  gStyle->SetTextFont(132);
  gStyle->SetPadColor(0);
  gStyle->SetPadBorderMode(0);
  // gStyle->SetFillColor(0);
  // gStyle->SetFillStyle(0);
  
  TCanvas* c = new TCanvas("c", "c", 900, 900);
  c->SetFillColor(0);
  c->SetFillStyle(0);
  c->SetBorderSize(0);
  c->SetBorderMode(0);
  c->SetRightMargin(0.02);
  c->SetTopMargin(0.02);
  c->SetBottomMargin(0.15);
  c->Divide(1,3,0,0);
  
  // --- INEL --------------------------------------------------------
  TVirtualPad* p = c->cd(1);
  p->SetGridx();
  p->SetRightMargin(.01);
  THStack* inel     = new THStack("inel", "INEL");
  TLatex*  inelT    = new TLatex(1-p->GetRightMargin()-.01, 
				 1-p->GetTopMargin()-.01, 
				 "INEL");
  inelT->SetNDC();
  inelT->SetTextAlign(33);
  inelT->SetTextSize(0.12);
  TLegend* inelL    = new TLegend(.3, .02, .8, .4);
  inelL->SetBorderSize(0);
  inelL->SetNColumns(2);
  inelL->SetFillColor(0);
  inelL->SetFillStyle(0);
  TLegendEntry* e = inelL->AddEntry("d1", "Forward", "lp");
  e->SetMarkerColor(kRed+2);
  e->SetMarkerStyle(29);
  e = inelL->AddEntry("d2", "Central", "lp");
  e->SetMarkerColor(kMagenta+2);    
  e->SetMarkerStyle(29);
  e = inelL->AddEntry("d3", "Data", "lp");
  e->SetMarkerStyle(29);
  e = inelL->AddEntry("d4", "Mirrored data", "lp");
  e->SetMarkerStyle(30);
  e = inelL->AddEntry("d5", "Systematic error", "f");
  e->SetFillColor(kGray); 
  e->SetLineColor(kGray);
  e->SetLineWidth(0);
  e->SetFillStyle(3001);
  
  gROOT->LoadMacro("export_pp_0900GeV_INEL_m10p10cm_000100000ev.C");
  export_pp_0900GeV_INEL_m10p10cm_000100000ev(inel, inelL, 20);
  export_pp_0900GeV_INEL_m10p10cm_000100000ev(inel, inelL, 21);
  export_pp_0900GeV_INEL_m10p10cm_000100000ev(inel, inelL, 22);
  inel->Draw("nostack e1");
  inel->GetHistogram()->SetYTitle("#frac{1}{N}#frac{dN_{ch}}{d#eta}");
  inel->GetHistogram()->SetXTitle("#eta");
  inel->GetHistogram()->GetYaxis()->SetDecimals();
  inelL->Draw();
  inelT->Draw();

  // --- INEL>0 ------------------------------------------------------
  p = c->cd(2);
  p->SetGridx();
  p->SetRightMargin(.01);
  THStack* inelgt0     = new THStack("inelgt0", "INEL>0");
  TLatex*  inelgt0T    = new TLatex(1-p->GetRightMargin()-.01, 
				    1-p->GetTopMargin()-.01, 
				    "INEL>0");
  inelgt0T->SetNDC();
  inelgt0T->SetTextAlign(33);
  inelgt0T->SetTextSize(0.12);
  gROOT->LoadMacro("export_pp_0900GeV_INEL_m10p10cm_000100000ev.C");
  export_pp_0900GeV_INEL_m10p10cm_000100000ev(inelgt0, 0, 20);
  export_pp_0900GeV_INEL_m10p10cm_000100000ev(inelgt0, 0, 21);
  export_pp_0900GeV_INEL_m10p10cm_000100000ev(inelgt0, 0, 22);
  inelgt0->Draw("nostack e1");
  inelgt0->GetHistogram()->SetXTitle("#eta");
  inelgt0->GetHistogram()->GetYaxis()->SetDecimals();
  inelgt0T->Draw();

  // --- NSD ---------------------------------------------------------
  p = c->cd(3);
  p->SetGridx();
  p->SetRightMargin(.01);
  THStack* nsd     = new THStack("nsd", "NSD");
  TLatex*  nsdT    = new TLatex(1-p->GetRightMargin()-.01, 
				1-p->GetTopMargin()-.01, 
				"NSD");
  nsdT->SetNDC();
  nsdT->SetTextAlign(33);
  nsdT->SetTextSize(0.12);
  gROOT->LoadMacro("export_pp_0900GeV_NSD_m10p10cm_000100000ev.C");
  export_pp_0900GeV_NSD_m10p10cm_000100000ev(nsd, 0, 20);
  export_pp_0900GeV_NSD_m10p10cm_000100000ev(nsd, 0, 21);
  export_pp_0900GeV_NSD_m10p10cm_000100000ev(nsd, 0, 22);
  nsd->Draw("nostack e1");
  nsd->GetHistogram()->SetXTitle("#eta");
  nsd->GetHistogram()->GetYaxis()->SetDecimals();
  nsdT->Draw();

  c->cd();
  c->SaveAs("dndeta_final.png");
}
Пример #3
0
fitYnSMassUnbinned(const char *filename = "YMassOS_186nb.txt",
  const char* plotOpt = "NEU",
  const int nbins = 40,
  const char* filenameB = "YMassSS_186nb.txt")
{

  gROOT->ProcessLine(".L tdrstyle.C");
  setTDRStyle();
  gStyle->SetPadRightMargin(0.05);

  RooRealVar  mass("mass","M(#mu^{+}#mu^{-})", 8.0, 12.0,"GeV/c^{2}");

  // Read data set

  RooDataSet *data = RooDataSet::read(filename,RooArgSet(mass));
  RooDataSet *dataB = RooDataSet::read(filenameB,RooArgSet(mass));

// Build p.d.f.

////////////////////////////////////////////////
//             Parameters                     //
////////////////////////////////////////////////

//  Signal p.d.f. parameters
//  Parameters for a Gaussian and a Crystal Ball Lineshape
  RooRealVar  m0   ("m_{0}", "Bias", 9.46, 9.2, 9.7,"GeV/c^{2}");
  RooRealVar  sigma("#sigma","Width", 0.04,0.01,0.1,"GeV/c^{2}");
  RooRealVar  cut  ("#alpha","Cut", 0.6,0.6,2.0);
  RooRealVar  power("power","Power", 10.0, 0.5, 20.0);


//  Background p.d.f. parameters
//  Parameters for a polynomial lineshape
  RooRealVar  c0("c_{0}", "c0", 0., -10, 10);
  RooRealVar  c1("c_{1}", "c1", 0., -100, 0);
  RooRealVar  c2("c_{2}", "c2", 0., -100, 100);
//  c0.setConstant();

// fraction of signal
//  RooRealVar  frac("frac", "Signal Fraction", 0.1,0.,0.3.);
  RooRealVar  nsig("N_{S}", "#signal events", 9000, 0.,10000.);
  RooRealVar  nbkg("N_{B}", "#background events", 1000,2,10000.);



////////////////////////////////////////////////
//               P.D.F.s                      //
////////////////////////////////////////////////

// Di-photon mass signal p.d.f.
  RooGaussian    signal("signal", "A  Gaussian Lineshape", mass, m0, sigma);
  // RooCBShape     signal("signal", "A  Crystal Ball Lineshape", mass, m0,sigma, cut, power);

// Di-photon mass background  p.d.f.
  RooPolynomial bg("bg", "Backgroung Distribution", mass, RooArgList(c0,c1));

// Di-photon mass model p.d.f.
//  RooAddPdf      model("model", "Di-photon mass model", signal, bg, frac);
  RooAddPdf      model("model", "Di-photon mass model", RooArgList(signal, bg), RooArgList(nsig, nbkg));


  TStopwatch t ;
  t.Start() ;
  model->fitTo(*data,FitOptions("mh"),Optimize(0),Timer(1));

  t.Print() ;

  c = new TCanvas("c","J/psi->mu mu Distributions", 0,0,800,600);
// Plot the fit results
  RooPlot* plot = mass.frame(Range(8.0,12.0),Bins(nbins));

// Plot 1
  dataB->plotOn(plot, MarkerColor(kRed));
  data->plotOn(plot);
  model.plotOn(plot);
  //model.paramOn(plot, Format(plotOpt, AutoPrecision(1)), Parameters(RooArgSet(nsig, nbkg, m0, sigma)));
  model.paramOn(plot, Format(plotOpt, AutoPrecision(1)), Parameters(RooArgSet(m0, sigma)));

  /// model.plotOn(plot, Components("signal"), LineStyle(kDashed), LineColor(kRed));

  model.plotOn(plot, Components("bg"), LineStyle(kDashed), LineColor(kRed));


  plot->Draw();

  TLatex *   tex = new TLatex(0.2,0.8,"CMS preliminary");
  tex->SetTextFont(42);
  tex->SetNDC();
  tex->SetLineWidth(2);
  tex->Draw();
  tex->DrawLatex(0.2, 0.725, "#sqrt{s} = 7 TeV");
  tex->DrawLatex(0.2, 0.650, "L = 186 nb^{-1}");

  float fsig_peak = NormalizedIntegral(signal,
                      mass,
                      m0.getVal() - 2.5*sigma.getVal(),
                      m0.getVal() + 2.5*sigma.getVal()
                    );

  float fbkg_peak = NormalizedIntegral(bg,
                      mass,
                      m0.getVal() - 2.5*sigma.getVal(),
                      m0.getVal() + 2.5*sigma.getVal()
                    );

  double nsigVal = fsig_peak * nsig.getVal();
  double nsigErr = fsig_peak * nsig.getError();
  double nsigErrRel = nsigErr / nsigVal;
  double nbkgVal = fbkg_peak * nbkg.getVal();
  double nbkgErr = fbkg_peak * nbkg.getError();
  double nbkgErrRel = nbkgErr / nbkgVal;

  cout << "nsig " << nsigVal << " +/- " << nsigErr << endl;
  cout << "S/B_{#pm2.5#sigma} " << nsigVal/nbkgVal << " +/- "
    << (nsigVal/nbkgVal)*sqrt(nsigErrRel*nsigErrRel + nbkgErrRel*nbkgErrRel)
    << endl;

  tex->DrawLatex(0.2, 0.5, Form("N_{S} = %.0f#pm%.0f", nsigVal, nsigErr) );
  tex->DrawLatex(0.2, 0.425, Form("S/B_{#pm2.5#sigma} = %.1f", nsigVal/nbkgVal) );
  tex->DrawLatex(0.2, 0.35, Form("#frac{S}{#sqrt{B}}_{#pm2.5#sigma} = %.1f", nsigVal/sqrt(nbkgVal)));

  leg = new TLegend(0.65,0.6,0.9,0.75);
  leg->SetFillColor(kWhite);
  leg->SetLineColor(kWhite);
  leg->SetShadowColor(kWhite);
  leg->SetTextFont(42);

  TLegendEntry * ldata  = leg->AddEntry(data, "Opposite Sign");
  TLegendEntry * ldataB = leg->AddEntry(dataB, "Same Sign");
  ldata->SetMarkerStyle(20);
  ldataB->SetMarkerStyle(20);
  ldataB->SetMarkerColor(kRed);

  leg->Draw();

}
Пример #4
0
  /** 
   * Add the bin histograms to our summary stacks 
   * 
   * @param bin       Bin stack
   * @param i         Current off-set in the stacks 
   * @param measured  All measured @f$ P(N_{ch})@f$ 
   * @param truth     All MC truth @f$ P(N_{ch})@f$ 
   * @param accepted  All MC accepted @f$ P(N_{ch})@f$ 
   * @param unfolded  All unfolded @f$ P(N_{ch})@f$ 
   * @param corrected All corrected @f$ P(N_{ch})@f$ 
   * @param result    The result in this bin
   */
  void Bin2Stack(const THStack* bin, Int_t i, 
		 THStack* measured, 
		 THStack* truth, 
		 THStack* accepted, 
		 THStack* unfolded,
		 THStack* corrected,
		 TH1*&    result)
  {
    Int_t open, closed;
    Double_t factor; 
    Float_t  size;
    BinAttributes(i, open, closed, size, factor);

    TIter next(bin->GetHists());
    TH1*  h = 0;
    while ((h = static_cast<TH1*>(next()))) {
      THStack* tmp = 0;
      Int_t    col = h->GetMarkerColor();
      Int_t    sty = 0;
      switch (col) { 
      case kColorMeasured:  tmp = measured;   sty = closed;  break;
      case kColorTruth:     tmp = truth;      sty = open;    break;
      case kColorAccepted:  tmp = accepted;   sty = open;    break;
      case kColorUnfolded:  tmp = unfolded;   sty = closed;  break;
      case kColorCorrected: tmp = corrected;  sty = closed;  break;
      default: continue; 
      }
      // Now clone, and add to the appropriate stack 
      TH1* cln = static_cast<TH1*>(h->Clone(h->GetName()));
      cln->SetDirectory(0);
      cln->SetMarkerStyle(sty);
      cln->SetMarkerSize(size);
      cln->Scale(factor); // Scale by 10^i
      if (col == kColorCorrected) result = cln;

      // Make sure we do not get the old legend 
      TObject* tst = cln->FindObject("legend");
      if (tst) cln->GetListOfFunctions()->Remove(tst);

      tmp->Add(cln, next.GetOption());
    }
    
    // Add entries to our stacks 
    TString   txt      = bin->GetTitle();
    if      (i == 0) txt.Append(" (#times1)");
    else if (i == 1) txt.Append(" (#times10)");
    else             txt.Append(Form(" (#times10^{%d})", i));
    THStack*  stacks[] = { measured, truth, accepted, unfolded, corrected, 0 };
    THStack** pstack   = stacks;
    while (*pstack) { 
      TLegend* leg = StackLegend(*pstack);
      pstack++;
      if (!leg) continue;
      
      TObject* dummy = 0;
      TLegendEntry* e = leg->AddEntry(dummy, txt, "p");
      e->SetMarkerStyle(closed);
      e->SetMarkerSize(1.2*size);
      e->SetMarkerColor(kBlack);
      e->SetFillColor(0);
      e->SetFillStyle(0);
      e->SetLineColor(kBlack);
    }
  }
void Overlay_NeutralEnergyDifferenceMean()
{
   std::string canvasName = "canvas";
   std::string canvasTitle = "Neutral energy mean";
   int canvasX1 = 200;
   int canvasY1 = 52;
   int canvasX2 = 700;
   int canvasY2 = 650;
   int nPoints = 6;
   int nGraphs = 5;
   int neutralEnergy = 10;

   double zero [] = {0, 0, 0, 0, 0, 0, 0, 0};
   double energies[] = {10, 20, 30, 40, 50};
   double distances[] = {5, 10, 15, 20, 25, 30};

   std::string graphXTitle = "Distance between showers [cm]";
   std::string graphYTitle = "<E_{n,rec} - E_{n,meas}>";
   double rangeUserXMin = 0;
   double rangeUserXMax = 35;
   double rangeUserYMin = -10;
   double rangeUserYMax = 10;

   TCanvas *pCanvas = new TCanvas(canvasName.c_str(), canvasTitle.c_str(), canvasX1, canvasY1, canvasX2, canvasY2);
   pCanvas->SetFillColor(0);
   pCanvas->SetBorderMode(0);
   pCanvas->SetBorderSize(2);
   pCanvas->SetTickx(1);
   pCanvas->SetTicky(1);
   pCanvas->SetLeftMargin(0.15);
   pCanvas->SetRightMargin(0.03);
   pCanvas->SetTopMargin(0.05);
   pCanvas->SetBottomMargin(0.14);
   pCanvas->SetFrameBorderMode(0);
   pCanvas->SetFrameBorderMode(0);

   TH1F *pH = new TH1F("pouette", "", rangeUserXMax-rangeUserXMin, rangeUserXMin, rangeUserXMax);
   pH->SetMinimum(rangeUserYMin);
   pH->SetMaximum(rangeUserYMax);
   pH->Draw();
   gStyle->SetOptStat(0);
   pH->GetYaxis()->SetTitle(graphYTitle.c_str());
   pH->GetXaxis()->SetTitle(graphXTitle.c_str());
   pH->GetYaxis()->SetLabelFont(42);
   pH->GetYaxis()->SetTitleSize(0.05);
   pH->GetYaxis()->SetTitleOffset(1);
   pH->GetYaxis()->SetTitleFont(42);
   pH->GetYaxis()->SetLabelSize(0.045);

   TLegend *leg = new TLegend(0.3,0.55,0.8,0.8,NULL,"brNDC");
   leg->SetBorderSize(0);
   leg->SetLineColor(0);
   leg->SetLineStyle(1);
   leg->SetLineWidth(1);
   leg->SetFillColor(0);
   leg->SetTextSize(0.03);

   int currentColor = 1;

   for(unsigned int e=0 ; e<nGraphs ; e++)
   {
     int energy = energies[e];
  
     double *data = new double[nPoints];
     double *dataError = zero;//new double[nPoints];

     std::stringstream fileName;
     fileName << "data_neutralERecDifference_ArborPFA_Test\ Beam_" << energy << "Gev.txt";
     readData(fileName.str(), data, nPoints);
     
     // fileName.str("");
     // fileName << "fichier_data_error_energy_" << energy << "GeV.txt";
     // readData(fileName.str(), dataError, nPoints);
   
     TGraphErrors *gre = 0;
     std::stringstream graphName;
     graphName << "Charged particle energy = " << energy << " GeV";
     gre = new TGraphErrors(nPoints, distances, data, zero, dataError);
     gre->SetName(graphName.str().c_str());
     gre->SetTitle(graphName.str().c_str());
     gre->SetLineColor(currentColor);
     gre->SetMarkerColor(currentColor);
     gre->SetMarkerStyle(23);
     gre->SetMarkerSize(1.2);
     gre->Draw("lp same");
   
     TLegendEntry *entry = 0;
     entry=leg->AddEntry(gre, graphName.str().c_str(), "lp");
     entry->SetFillStyle(1001);
     entry->SetMarkerColor(currentColor);
     entry->SetMarkerStyle(23);
     entry->SetMarkerSize(1);

     currentColor++;
   }

   TPaveText *pt = new TPaveText(0.55, 0.2, 0.93, 0.3, "tbNDC");
   pt->SetTextSize(0.05);
   pt->SetTextColor(kGray+2);
   pt->SetFillColor(0);
   pt->SetLineWidth(0);
   pt->SetBorderSize(0);
   pt->AddText("CALICE Preliminary");
   pt->SetTextFont(62);
   pt->Draw();
   
   leg->Draw();

   pCanvas->Modified();
   pCanvas->cd();
   pCanvas->SetSelected(pCanvas);
}
Пример #6
0
  //____________________________________________________________________
  void DrawResCollection(TCollection* top, const TString& name)
  {
    TCollection* c = GetCollection(top, name, false);
    if (!c) return;

    THStack* s = GetStack(c, "all");
    s->SetTitle("");
    DrawInPad(fBody, 0, s, "nostack", kLogy);
    TLegend* l = new TLegend(.5, .75, .98, .98, "P(#it{N}_{ch})");
    l->SetBorderSize(0);
    // l->SetBorderMode(0);
    l->SetFillColor(0);
    l->SetFillStyle(0);
    TIter next(s->GetHists());
    TH1*  h = 0;
    Bool_t hasTrue = false;
    while ((h = static_cast<TH1*>(next()))) { 
      TString n(h->GetTitle());
      if (n.BeginsWith("True")) { hasTrue = true; continue; }
      n.ReplaceAll("Raw P(#it{N}_{ch}) in ", "");
      TLegendEntry* e = l->AddEntry("dummy", n, "p");
      e->SetMarkerStyle(h->GetMarkerStyle());
    }
    if (hasTrue) {
      TLegendEntry* e = l->AddEntry("dummy", "Raw", "p");
      e->SetMarkerStyle(20);
      e->SetMarkerColor(kRed+1);
      e = l->AddEntry("dummy", "MC truth", "p");
      e->SetMarkerStyle(24);
      e->SetMarkerColor(kBlue+1);
      e = l->AddEntry("dummy", "MC truth selected", "p");
      e->SetMarkerStyle(24);
      e->SetMarkerColor(kOrange+1);
    }
    fBody->cd();
    l->Draw();
    
    PrintCanvas(Form("%s results", name.Data()));

    // return;

    TIter       nextO(c);
    TObject*    o = 0;
    while ((o = nextO())) { 
      Double_t etaMin = 999;
      Double_t etaMax = 999;
      TCollection* bin = GetEtaBin(o, etaMin, etaMax);
      if (!bin) continue;

      fBody->Divide(2,3);
      DrawInPad(fBody, 1, GetH1(bin, "rawDist"),      "",     kLogy);
      DrawInPad(fBody, 1, GetH1(bin, "truthAccepted", false),
		"same", kSilent);
      DrawInPad(fBody, 1, GetH1(bin, "truth", false),"same", kSilent|kLegend);
      DrawInPad(fBody, 2, GetH1(bin, "coverage"));
      DrawInPad(fBody, 3, GetH2(bin, "corr"),            "colz");
      DrawInPad(fBody, 4, GetH2(bin, "response", false), "colz", kLogz|kSilent);
      DrawInPad(fBody, 5, GetH1(bin, "triggerVertex", false), "", kSilent);
      
      PrintCanvas(Form("%+5.1f < #eta < %+5.1f", etaMin, etaMax));
    }
  }