Ejemplo n.º 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);
  }
Ejemplo n.º 2
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);
}