Two point ratio plot

I have two points in data and in MC, and I want to plot them along with the ratio of data/MC. Currently I have an empty plot at the bottom, I don’t know how to fix the problem. Is this even the best way of going about this task?

void HistoricalCrossSec()
{

  double bottommargin = 0.25;
  double topmargin = 0.06;
  double leftmargin = 0.09;
  double rightmargin = 0.01;

  gStyle->SetPadBottomMargin(bottommargin);
  gStyle->SetPadTopMargin(topmargin);
  gStyle->SetPadLeftMargin(leftmargin);
  gStyle->SetPadRightMargin(rightmargin);
  
  gStyle->SetMarkerStyle(8);
  gStyle->SetOptStat(0);
  
  double myDataCrossSec = 1e10;
  double myDataCrossSecerr = 0.42e10;

  double myMCCrossSec = 0.9e10;
  double myMCCrossSecerr = 0.0288e10;

  
  double slacDataCrossSec = 2e10;
  double slacDataCrossSecerr = 0.45e10;

  double slacMCCrossSec = 1.8e10;
  double slacMCCrossSecerr = 0.036e10;

  TH1F* hData = new TH1F("hData",";Positron Energy (MeV); Cross section (pb)",300,149.5,449.5);
  TH1F* hMC = new TH1F("hMC",";Positron Energy (MeV); Cross section (pb)",300,149.5,449.5);

  std::cout<<hData->FindBin(199)<<" "<<hData->FindBin(431.6)<<"\n";
  
  hData->Fill(199,slacDataCrossSec);
  hData->SetBinError(hData->FindBin(199),1.);
  
  hData->Fill(431.6,myDataCrossSec);
  hData->SetBinError(hData->FindBin(431.6),1.);

  hMC->Fill(199,slacMCCrossSec);
  hMC->SetBinError(hMC->FindBin(199),slacMCCrossSecerr);
  
  hMC->Fill(431.6,myMCCrossSec);
  hMC->SetBinError(hMC->FindBin(431.6),myMCCrossSecerr);

  hData->SetMarkerColor(kRed);
  
  TCanvas* crp = new TCanvas("crp","crp",900,700);
  TRatioPlot* rpCrossSec = new TRatioPlot(hData,hMC);
  rpCrossSec->Draw();
  rpCrossSec->SetH1DrawOpt("E");
}

Hello,

Thanks for posting. I think the problem here is a numerical one, not ROOT’s. You are trying to calculate the ratio of floating point numbers in the range of 1e10. I suggest to use numbers nearer to 1, where the density of floating points is at its maximum, e.g.

  double myDataCrossSec = 1.;
  double myDataCrossSecerr = 0.42;

  double myMCCrossSec = 0.9;
  double myMCCrossSecerr = 0.0288;

  
  double slacDataCrossSec = 2;
  double slacDataCrossSecerr = 0.45;

  double slacMCCrossSec = 1.8;
  double slacMCCrossSecerr = 0.036;

And then adapt the cross section units on the y axis accordingly.

I hope this helps.

Cheers,
D

1 Like

Hi, that works perfectly thank you! Just for future reference for anyone who may come upon this: SetH1DrawOpt() has to be done before the Draw() to take effect apparently. I learned this the hard way!

Thank you again!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.