3 #include "TVirtualFitter.h" 
    7 vector<double> GetErrorN(
double n, 
bool debug = 
false)
 
   16         vector<double> result;
 
   21             cerr<<
"| Setting errors to zero."<<endl;
 
   26         vector<double> result;
 
   27         result.push_back(-0.5 + sqrt(n+0.25)); 
 
   28         result.push_back(0.5 + sqrt(n+0.25)); 
 
   34         vector<double> result;
 
   35         result.push_back(sqrt(n)); 
 
   36         result.push_back(sqrt(n)); 
 
   46 void SetEmptyBinsToOne (TH1D * h)
 
   48     for (
int j = 0; j <= h->GetNbinsX(); j++)
 
   50         double bin_content = h->GetBinContent(j);
 
   54         h->SetBinContent(j, bin_content);
 
   62 void NearestNeighborSmoothing (TH1D * h, 
double xmin, 
double xmax, 
int nPassMax = 10)
 
   65     while(iPass < nPassMax)
 
   67         for (
int j = 0; j <= h->GetNbinsX(); j++)
 
   69             if (h->GetBinCenter(j) >= xmin && h->GetBinCenter(j) < xmax)
 
   71                 double bin_content_xlow = h->GetBinContent(j-1);
 
   72                 double bin_content_xup  = h->GetBinContent(j+1);
 
   73                 double bin_content = (bin_content_xlow + bin_content_xup)/2;
 
   74                 h->SetBinContent(j, bin_content);
 
   86 TH1D * GetScaledTH1D(
double scale_factor, 
const TH1D * h1)
 
   88     TGraph * g = 
new TGraph(h1);
 
   91     TH1D * h = (TH1D*)h1->Clone();
 
   94     for (
int j = 1; j <= h->GetNbinsX(); j++)
 
   96         double bin_content = scale_factor*g->Eval(h->GetBinCenter(j), 0, 
"S");
 
   98         h->SetBinContent(j, bin_content);
 
  109 TH1D * Normalize_1D_Histogram (TH1D* h1, 
double nEvts, 
bool diagnostics = 
false)
 
  117     for (
int i = 0; i <= h1->GetNbinsX(); i++)
 
  119         if (h1->GetBinContent(i) > 0)
 
  121             double scaleFactor = 1/(nEvts*h1->GetXaxis()->GetBinWidth(i));
 
  122             double bin_content = h1->GetBinContent(i);
 
  123             double bin_error = h1->GetBinError(i);
 
  124             h1->SetBinContent( i, scaleFactor*bin_content);
 
  125             h1->SetBinError( i, scaleFactor*bin_error);
 
  127             if (diagnostics == 
true)
 
  129                 cout<<
"Bin "<<i<<
": "<<h1->GetBinContent(i)<<
", "<<h1->GetBinError(i)<<endl;
 
  134     if (diagnostics == 
true)
 
  147 TH2D * Normalize_2D_Histogram (TH2D * h1, 
double nEvts, 
const TString& option)
 
  153     double scaleFactor = 0; 
 
  155     for (
int i = 0; i <= h1->GetNbinsX(); i++)
 
  157         for (
int j = 0; j <= h1->GetNbinsY(); j++)
 
  159             if (h1->GetBinContent(i, j) > 0)
 
  161                 double bin_content = h1->GetBinContent(i, j);
 
  162                 double bin_error = h1->GetBinError(i);
 
  164                 if (option==
"probability")
 
  165                     scaleFactor = 1/(nEvts);
 
  167                     scaleFactor = 1/(nEvts * h1->GetXaxis()->GetBinWidth(i) * h1->GetYaxis()->GetBinWidth(j));
 
  169                 h1->SetBinContent(i, j, scaleFactor*bin_content);
 
  170                 h1->SetBinError  (i, j, scaleFactor*bin_error);
 
  182 void CorrectTH1DErrors (TH1D * h)
 
  184     for (
int j = 0; j <= h->GetNbinsX(); j++)
 
  186         double bin_content = h->GetBinContent(j);
 
  187         double bin_error = GetErrorN(bin_content)[0];
 
  188         h->SetBinError(j, bin_error);
 
  196 void CorrectTH2DErrors (TH2D * h)
 
  198     for (
int i = 0; i <= h->GetNbinsX(); i++)
 
  200         for (
int j = 0; j <= h->GetNbinsY(); j++)
 
  202             double bin_content = h->GetBinContent(i, j);
 
  203             double bin_error = GetErrorN(bin_content)[0];
 
  204             h->SetBinError(i, j, bin_error);
 
  213 TH2D * GetCleanedUpHistogram (TH2D * h1, 
double MinBinCount = 1)
 
  215     h1->SetName(Form(
"%s_cleaned", h1->GetName()));
 
  217     for (
int i = 0; i <= h1->GetNbinsX(); i++)
 
  219         for (
int j = 0; j <= h1->GetNbinsY(); j++)
 
  221             if (h1->GetBinContent(i, j) < MinBinCount)
 
  223                 h1->SetBinContent(i, j, 0);
 
  224                 h1->SetBinError(i, j, 0);
 
  236 TH2D * GetCleanedUpHistogram (
const TH2D * h, 
double MinBinCount = 1)
 
  238     TH2D * h1 = (TH2D*)h->Clone();
 
  239     h1->SetName(Form(
"%s_cleaned", h->GetName()));
 
  241     for (
int i = 0; i <= h1->GetNbinsX(); i++)
 
  243         for (
int j = 0; j <= h1->GetNbinsY(); j++)
 
  245             if (h1->GetBinContent(i, j) < MinBinCount)
 
  247                 h1->SetBinContent(i, j, 0);
 
  248                 h1->SetBinError(i, j, 0);
 
  260 TH2D * GetIntegratedSpectraHistogram (TH2D * h1_original, 
int yMin, 
int yMax)
 
  264     TH2D * h1 = (TH2D*)h1_original->Clone();
 
  266     for (
int i = 0; i <= h1->GetNbinsX(); i++)
 
  268         for (
int j = 0; j <= h1->GetNbinsY(); j++)
 
  270             if (j < yMin || j > yMax)
 
  272                 h1->SetBinContent(i, j, 0);
 
  273                 h1->SetBinError(i, j, 0);
 
  285 double GetIntegralTH2D (
const TH2D* h1)
 
  288     for (
int i = 1; i <= h1->GetNbinsX(); i++)
 
  290         for (
int j = 1; j <= h1->GetNbinsY(); j++)
 
  292             integral = integral + h1->GetBinContent(i, j);
 
  303 void printVector(
const vector<int> &vec) 
 
  314 std::vector<int> GetPPtFromVolumeId(
int volumeID, 
int ixx_MAX, 
bool debug = 
false)
 
  316     int ipt = (int)volumeID/(
int)ixx_MAX + 1;
 
  317     int ipp = volumeID % ixx_MAX;
 
  325     if (debug == 
true) cerr<<
"\nVerify (ipp, ipt) = "<<ipp<<
", "<<ipt<<endl;
 
  327     std::vector<int> ipp_ipt = {ipp, ipt};
 
  335 TH2D * MultiplyWithCorrectionFactor(
const TH2D * h1_original, 
const TH2D * hist_corrections, 
double MAX_CORRECTION = 50.0)
 
  339     TH2D * h1 = (TH2D*)h1_original->Clone();
 
  341     for (
int i = 0; i <= h1->GetNbinsX(); i++)
 
  343         for (
int j = 0; j <= h1->GetNbinsY(); j++)
 
  345             if (h1->GetBinContent(i, j) > 0 && hist_corrections->GetBinContent(i, j) < MAX_CORRECTION)
 
  347                 if(h1->GetXaxis()->GetBinCenter(i) != hist_corrections->GetXaxis()->GetBinCenter(i))
 
  348                     cerr<<
"\n[ERROR]: x bin centers do not match!";
 
  349                 if(h1->GetYaxis()->GetBinCenter(j) != hist_corrections->GetYaxis()->GetBinCenter(j))
 
  350                     cerr<<
"\n[ERROR]: y bin centers do not match!";
 
  351                 if(h1->GetXaxis()->GetBinWidth(i) != hist_corrections->GetXaxis()->GetBinWidth(i))
 
  352                     cerr<<
"\n[ERROR]: x bin widths do not match!";
 
  353                 if(h1->GetYaxis()->GetBinWidth(j) != hist_corrections->GetYaxis()->GetBinWidth(j))
 
  354                     cerr<<
"\n[ERROR]: y bin widths do not match!";
 
  357                 double new_bin_content = h1->GetBinContent(i, j) * hist_corrections->GetBinContent(i, j);
 
  360                 double new_bin_error   = GetErrorN(h1->GetBinContent(i, j))[0] * hist_corrections->GetBinContent(i, j);
 
  362                 h1->SetBinContent(i, j, new_bin_content);
 
  363                 h1->SetBinError(i, j, new_bin_error);
 
  368                 h1->SetBinContent(i, j, 0);
 
  369                 h1->SetBinError(i, j, 0);
 
  384 template <
class TGraphAll>
 
  385 TGraphAll * RemoveZeroFromGraph (
const TGraphAll * G, 
bool diagnostics = 
false)
 
  393     TGraphAll * G_with_zeros = (TGraphAll*)G->Clone();
 
  396     int n = G_with_zeros->GetN();
 
  397     Double_t ax[n],ay[n];
 
  398     vector<int> point_indices_to_delete;
 
  399     for (
int i_bin = 0; i_bin < n; i_bin++)
 
  401         G_with_zeros->GetPoint(i_bin,ax[i_bin],ay[i_bin]);
 
  402         if (diagnostics == 
true)
 
  403             cout<<i_bin<<
", "<<ax[i_bin]<<
", "<<ay[i_bin]<<endl;
 
  407             if (diagnostics == 
true)
 
  408                 cout<<
"Bin to delete: "<<i_bin<<endl;
 
  410             point_indices_to_delete.push_back(i_bin);
 
  414     for (
int k = 0; k < int(point_indices_to_delete.size()); k++)
 
  416         if (diagnostics == 
true)
 
  417             cerr<<
"Deleting bin "<<point_indices_to_delete[k];
 
  419         G_with_zeros->RemovePoint(point_indices_to_delete[k]);        
if (diagnostics == 
true) cerr<<
"  ...done."<<endl;
 
  420         std::transform(std::begin(point_indices_to_delete),std::end(point_indices_to_delete),std::begin(point_indices_to_delete),[](
int x){
return x-1;});
 
  423     if (diagnostics == 
true)
 
  426         n = G_with_zeros->GetN();
 
  427         Double_t cx[n],cy[n];
 
  428         for (
int i_bin = 0; i_bin < n; i_bin++)
 
  430             G_with_zeros->GetPoint(i_bin,cx[i_bin],cy[i_bin]); 
 
  431             cout<<i_bin<<
", "<<cx[i_bin]<<
", "<<cy[i_bin]<<endl;
 
  433         cout<<endl<<endl<<endl;
 
  443 TGraphErrors * SetTGraphXErrorZero (
const TGraphErrors * G, 
bool ShowDiagnostics = 
false)
 
  446     TGraphErrors * G_with_errorX_zero = (TGraphErrors*)G->Clone();
 
  449     int n = G_with_errorX_zero->GetN();
 
  450     Double_t ax[n], ay[n];
 
  452     for (
int i_bin = 0; i_bin < n; i_bin++)
 
  454         if (ShowDiagnostics) {};
 
  456         G_with_errorX_zero->GetPoint(i_bin, ax[i_bin], ay[i_bin]);
 
  457         G_with_errorX_zero->SetPointError(i_bin, 0, G_with_errorX_zero->GetErrorY(i_bin));
 
  460     return G_with_errorX_zero;
 
  467 TGraphErrors * MergeSinglePointTGraphErrors (vector<TGraphErrors*> vGFitConfidenceBands)
 
  471     int n = vGFitConfidenceBands.size();
 
  472     Double_t ax[n], ay[n], ex[n], ey[n];
 
  474     for (
int i = 0; i < n; i++)
 
  476         vGFitConfidenceBands[i]->GetPoint(0, ax[i], ay[i]);
 
  478         ey[i] = vGFitConfidenceBands[i]->GetErrorY(0);
 
  480         cout<<
"Merged graph input: "<<ax[i]<<
", "<<ay[i]<<
", "<<ex[i]<<
", "<<ey[i]<<endl;
 
  483     auto gr = 
new TGraphErrors(n, ax, ay, ex, ey);
 
  493 void AddMissingPointAndErrorToGraphFromFit (TGraphErrors * G,
 
  494                                             const TFitResultPtr fit_ptr,
 
  496                                             vector<int> &vMissingPointIndex,
 
  497                                             bool debugMode = 
false)
 
  500         cerr<<
"\nChecking graph for missing points..."<<endl;
 
  502     vector<double> vXPoints = {0.05, 0.15, 0.25, 0.35, 0.45, 0.55};
 
  504     Double_t ax[n], ay[n];
 
  507     for (
unsigned int k = 0; k < vXPoints.size(); k++)
 
  511         bool point_missing = 
true; 
 
  513         for (
int i_bin = 0; i_bin < n; i_bin++)
 
  515             G->GetPoint(i_bin, ax[i_bin], ay[i_bin]);
 
  518             if (abs(ax[i_bin] - vXPoints[k]) < 0.01)  
 
  521                     cerr<<
"x-point "<<ax[i_bin]<<
" found."<<endl;
 
  523                 point_missing = 
false;
 
  529         if (point_missing == 
true)
 
  532                 cerr<<
"Adding missing point "<<vXPoints[k];
 
  534             vMissingPointIndex.push_back(k); 
 
  536             double x[1] = {vXPoints[k]};
 
  540             fit_ptr->GetConfidenceIntervals(1, 1, 1, x, err, 0.683, 
false);
 
  543                 cerr<<
":  Function value at "<<x[0]<<
" = "<<FitD->Eval(x[0])<<
" +/- "<<err[0]<<endl;
 
  545             int temp_n = G->GetN();
 
  546             G->SetPoint(temp_n, vXPoints[k], FitD->Eval(x[0]));
 
  547             G->SetPointError(temp_n, 0, err[0]);
 
  561 TH1D * GetRatioTH1D(
const TH1D * h1, 
const TH1D * h2)
 
  563     if (h1->GetNbinsX() != h2->GetNbinsX())
 
  564         cerr<<
"\n\n\n[ERROR]: The bins for calculating the ratio histogram do no match!\n\n"<<endl;
 
  566     TH1D * hUp = (TH1D*)h1->Clone();
 
  567     TH1D * hDown = (TH1D*)h2->Clone();
 
  569     TH1D * hRatio = (TH1D*)hUp->Clone();
 
  572     CorrectTH1DErrors(hUp);
 
  573     CorrectTH1DErrors(hDown);
 
  575     for (
int i = 0; i <= hUp->GetNbinsX(); i++)
 
  577         if (hUp->GetBinCenter(i) - hDown->GetBinCenter(i) < 0.01)
 
  579             if (hDown->GetBinContent(i) > 0)
 
  581                 double ratio = hUp->GetBinContent(i)/hDown->GetBinContent(i);
 
  582                 double error_ratio =  ratio * sqrt(pow(hUp->GetBinError(i)/hUp->GetBinContent(i), 2)  +  pow(hDown->GetBinError(i)/hDown->GetBinContent(i), 2));
 
  584                 hRatio->SetBinContent(i, ratio);
 
  585                 hRatio->SetBinError(i, error_ratio);
 
  589                 hRatio->SetBinContent(i, 0);
 
  590                 hRatio->SetBinError(i, 0);
 
  606 TH2D * GetRatioTH2D(
const TH2D * hNumerator, 
const TH2D * hDenominator)
 
  610     TH2D * hN = (TH2D*)hNumerator->Clone();
 
  611     TH2D * hD = (TH2D*)hDenominator->Clone();
 
  613     TH2D * hRatio = (TH2D*)hN->Clone();
 
  615     hRatio->GetZaxis()->SetTitle(
"Ratio");
 
  618     int n_xbins_hN = hN->GetXaxis()->GetNbins();
 
  619     int n_xbins_hD = hD->GetXaxis()->GetNbins();
 
  620     int n_ybins_hN = hN->GetYaxis()->GetNbins();
 
  621     int n_ybins_hD = hD->GetYaxis()->GetNbins();
 
  622     if (n_xbins_hN != n_xbins_hD || n_ybins_hN != n_ybins_hD)
 
  624         cerr<<
"\n\n\n[ERROR]:  nXBins or nYBins do not match!"<<endl;
 
  629     for (
int i = 1; i < n_xbins_hN ; i++) 
 
  631         for (
int j = 1; j < n_ybins_hN ; j++) 
 
  634             if (hN->GetXaxis()->GetBinCenter(i) != hD->GetXaxis()->GetBinCenter(i))
 
  636                 cerr<<
"\n\n\n[ERROR]:  bin centers for bin"<<i<<
" in the x-axis do not match!"<<endl;
 
  640             if (hN->GetYaxis()->GetBinCenter(j) != hD->GetYaxis()->GetBinCenter(j))
 
  642                 cerr<<
"\n\n\n[ERROR]:  bin centers for bin"<<j<<
" in the y-axis do not match!"<<endl;
 
  648             if (hD->GetBinContent(i, j) != 0)
 
  649                 hRatio->SetBinContent(i, j, 
double(hN->GetBinContent(i, j))/(
double)hD->GetBinContent(i, j));
 
  662 TGraphErrors * GetdndyGraphFromFit (
const TFitResultPtr fit_ptr,
 
  664                                 const TGraphErrors * DataGraph,
 
  665                                 TGraphErrors * GConfidenceBand,
 
  668                                 bool debugMode = 
false)
 
  671         cerr<<
"\n\nChecking graph for missing points..."<<endl;
 
  673     vector<double> vXPoints; 
 
  674     for (
int k = 0; k < nXPoints; k++)
 
  676         vXPoints.push_back(0.05 + 0.1*k);
 
  680     double integrated_y = 0;
 
  681     double y_fit_errSq  = 0;
 
  682     double y_stat_errSq = 0;
 
  683     double pT_bin_width = 0.1;
 
  686     for (
unsigned int k = 0; k < vXPoints.size(); k++)
 
  689             cerr<<
"Adding point "<<vXPoints[k];
 
  691         double x[1] = {vXPoints[k]};
 
  695         fit_ptr->GetConfidenceIntervals(1, 1, 1, x, fit_err, 0.683, 
false);
 
  698             cerr<<
":  Function value at "<<x[0]<<
" = "<<FitD->Eval(x[0])<<
" +/- "<<fit_err[0]<<endl;
 
  700         integrated_y = integrated_y  + pT_bin_width*FitD->Eval(x[0]);
 
  701         y_fit_errSq   = y_fit_errSq  + fit_err[0]*fit_err[0];
 
  702         if (DataGraph->GetErrorY(k) > 0)
 
  703             y_stat_errSq  = y_stat_errSq + pT_bin_width*DataGraph->GetErrorY(k)*DataGraph->GetErrorY(k);
 
  708     cerr<<
"y          = "<<integrated_y<<endl;
 
  709     cerr<<
"y_fit_err  = "<<sqrt(y_fit_errSq)<<endl;
 
  710     cerr<<
"y_stat_err = "<<sqrt(y_stat_errSq)<<endl;
 
  714     GConfidenceBand->SetPoint(0, -1.1+2*
double(ySeries)/10, integrated_y);
 
  715     GConfidenceBand->SetPointError(0, 0, sqrt(y_fit_errSq));
 
  718     Double_t x[1], y[1], ex[1], ey[1];
 
  719     x[0]  = -1.1+2*double(ySeries)/10;
 
  722     ey[0] = sqrt(y_stat_errSq);
 
  723     auto gr = 
new TGraphErrors(1, x, y, ex, ey);
 
  735 vector<TGraphErrors*> GetGraphsfromTH2D(
const TH2D * h,
 
  737                                         const string &particle_name,
 
  738                                         int rapidity_bin_max_data,
 
  739                                         int rapidity_bin_min_data = 11,
 
  740                                         bool doScaling = 
true)
 
  742     vector<TGraphErrors*> dataGraphs;
 
  746     for (
int yBin = rapidity_bin_min_data; yBin <= rapidity_bin_max_data; yBin++) 
 
  748         auto htemp = h->ProjectionY(Form(
"py_bin_%d", yBin), yBin, yBin);
 
  750         for (
int pT_bin = 1; pT_bin <= htemp->GetNbinsX(); pT_bin++) 
 
  752             if (doScaling == 
true)
 
  754                 htemp->SetBinContent(pT_bin, pow (10, -(yBin - rapidity_bin_min_data))*htemp->GetBinContent(pT_bin));
 
  755                 htemp->SetBinError(pT_bin, pow (10, -(yBin - rapidity_bin_min_data))*htemp->GetBinError(pT_bin));
 
  760             if (particle_name==
"kMinus")
 
  765                     htemp->SetBinContent(pT_bin, 0);
 
  767                     if (yBin > 18 && pT_bin > 13)
 
  768                     htemp->SetBinContent(pT_bin, 0);
 
  770                     if (yBin > 19 && pT_bin > 9)
 
  771                     htemp->SetBinContent(pT_bin, 0);
 
  777             else if (particle_name==
"kPlus")
 
  782                     htemp->SetBinContent(pT_bin, 0);
 
  784                     if (yBin > 18 && pT_bin > 13)
 
  785                     htemp->SetBinContent(pT_bin, 0);
 
  787                     if (yBin > 19 && pT_bin > 9)
 
  788                     htemp->SetBinContent(pT_bin, 0);
 
  794             else if (particle_name==
"piMinus")
 
  799                     htemp->SetBinContent(pT_bin, 0);
 
  801                     if (yBin == 11 && pT_bin < 5)
 
  802                     htemp->SetBinContent(pT_bin, 0);
 
  804                     if (yBin == 12 && pT_bin < 4)
 
  805                     htemp->SetBinContent(pT_bin, 0);
 
  807                     if (yBin == 13 && pT_bin < 3)
 
  808                     htemp->SetBinContent(pT_bin, 0);
 
  810                     if (yBin == 14 && pT_bin < 3)
 
  811                     htemp->SetBinContent(pT_bin, 0);
 
  813                     if (yBin == 15 && pT_bin < 2)
 
  814                     htemp->SetBinContent(pT_bin, 0);
 
  816                     if (yBin == 20 && pT_bin > 12)
 
  817                     htemp->SetBinContent(pT_bin, 0);
 
  819                     if (yBin == 21 && pT_bin > 11)
 
  820                     htemp->SetBinContent(pT_bin, 0);
 
  822                     if (yBin == 22 && pT_bin > 10)
 
  823                     htemp->SetBinContent(pT_bin, 0);
 
  829             else if (particle_name==
"piPlus")
 
  834                     htemp->SetBinContent(pT_bin, 0);
 
  836                     if (yBin == 11 && pT_bin < 5)
 
  837                     htemp->SetBinContent(pT_bin, 0);
 
  839                     if (yBin == 12 && pT_bin < 4)
 
  840                     htemp->SetBinContent(pT_bin, 0);
 
  842                     if (yBin == 13 && pT_bin < 3)
 
  843                     htemp->SetBinContent(pT_bin, 0);
 
  845                     if (yBin == 14 && pT_bin < 3)
 
  846                     htemp->SetBinContent(pT_bin, 0);
 
  848                     if (yBin == 15 && pT_bin < 2)
 
  849                     htemp->SetBinContent(pT_bin, 0);
 
  851                     if (yBin == 21 && pT_bin > 12)
 
  852                     htemp->SetBinContent(pT_bin, 0);
 
  854                     if (yBin == 22 && pT_bin > 11)
 
  855                     htemp->SetBinContent(pT_bin, 0);
 
  861             else if (particle_name==
"proton")
 
  866                     htemp->SetBinContent(pT_bin, 0);
 
  878             else if (particle_name==
"antiproton")
 
  883                     htemp->SetBinContent(pT_bin, 0);
 
  885                     if (yBin > 18 && pT_bin > 13)
 
  886                     htemp->SetBinContent(pT_bin, 0);
 
  888                     if (yBin > 19 && pT_bin > 9)
 
  889                     htemp->SetBinContent(pT_bin, 0);
 
  895             else if (particle_name==
"deuteron")
 
  900                     htemp->SetBinContent(pT_bin, 0);
 
  908                 cerr<<
"\n\n\nERROR in GetGraphsfromTH2D(): string  "<<particle_name<<
"  does not match any known name"<<endl; 
 
  912         TGraphErrors * Gtemp = 
new TGraphErrors (htemp);
 
  913         TGraphErrors * GtempZero = SetTGraphXErrorZero(Gtemp);
 
  915         dataGraphs.push_back(GtempZero);
 
  925 TLegend * GetTLegend(
const string &particle_name, 
double year,  
const string &legend_type)
 
  927     TLegend * leg = 
new TLegend();
 
  930     if (particle_name==
"kMinus")
 
  932         if      (legend_type==
"points" && year == 2009) leg = 
new TLegend(0.70,0.20,0.94,0.91); 
 
  933         else if (legend_type==
"points" && year == 2010) leg = 
new TLegend(0.70,0.15,0.94,0.84);
 
  934         else if (legend_type==
"header" && year == 2009) leg = 
new TLegend(0.60,0.90,0.95,0.97);
 
  935         else if (legend_type==
"header" && year == 2010) leg = 
new TLegend(0.60,0.90,0.95,0.97);
 
  936         else if (legend_type==
"ratiop" && year == 2009) leg = 
new TLegend(0.70,0.07,0.90,0.86);
 
  937         else if (legend_type==
"ratiop" && year == 2010) leg = 
new TLegend(0.70,0.02,0.90,0.75);
 
  944     else if (particle_name==
"kPlus")
 
  946         if      (legend_type==
"points" && year == 2009) leg = 
new TLegend(0.70,0.15,0.94,0.89); 
 
  947         else if (legend_type==
"points" && year == 2010) leg = 
new TLegend(0.70,0.17,0.94,0.86);
 
  948         else if (legend_type==
"header" && year == 2009) leg = 
new TLegend(0.60,0.90,0.95,0.97);
 
  949         else if (legend_type==
"header" && year == 2010) leg = 
new TLegend(0.60,0.90,0.95,0.97);
 
  950         else if (legend_type==
"ratiop" && year == 2009) leg = 
new TLegend(0.70,0.07,0.90,0.86);
 
  951         else if (legend_type==
"ratiop" && year == 2010) leg = 
new TLegend(0.70,0.02,0.90,0.75);
 
  958     else if (particle_name==
"piMinus")
 
  960         if      (legend_type==
"points" && year == 2009) leg = 
new TLegend(0.70,0.15,0.94,0.89); 
 
  961         else if (legend_type==
"points" && year == 2010) leg = 
new TLegend(0.70,0.12,0.94,0.82);
 
  962         else if (legend_type==
"header" && year == 2009) leg = 
new TLegend(0.60,0.90,0.95,0.97); 
 
  963         else if (legend_type==
"header" && year == 2010) leg = 
new TLegend(0.60,0.90,0.95,0.97); 
 
  964         else if (legend_type==
"ratiop" && year == 2009) leg = 
new TLegend(0.70,0.07,0.90,0.86);
 
  965         else if (legend_type==
"ratiop" && year == 2010) leg = 
new TLegend(0.70,0.02,0.90,0.75);
 
  972     else if (particle_name==
"piPlus")
 
  974         if      (legend_type==
"points" && year == 2009) leg = 
new TLegend(0.70,0.15,0.94,0.90); 
 
  975         else if (legend_type==
"points" && year == 2010) leg = 
new TLegend(0.70,0.12,0.94,0.83);
 
  976         else if (legend_type==
"header" && year == 2009) leg = 
new TLegend(0.60,0.90,0.95,0.97); 
 
  977         else if (legend_type==
"header" && year == 2010) leg = 
new TLegend(0.60,0.90,0.95,0.97); 
 
  978         else if (legend_type==
"ratiop" && year == 2009) leg = 
new TLegend(0.70,0.07,0.90,0.86);
 
  979         else if (legend_type==
"ratiop" && year == 2010) leg = 
new TLegend(0.70,0.02,0.90,0.75);
 
  986     else if (particle_name==
"proton")
 
  988         if      (legend_type==
"points" && year == 2009) leg = 
new TLegend(0.70,0.21,0.94,0.91); 
 
  989         else if (legend_type==
"points" && year == 2010) leg = 
new TLegend(0.70,0.22,0.94,0.87); 
 
  990         else if (legend_type==
"header" && year == 2009) leg = 
new TLegend(0.60,0.90,0.95,0.97); 
 
  991         else if (legend_type==
"header" && year == 2010) leg = 
new TLegend(0.60,0.90,0.95,0.97); 
 
  992         else if (legend_type==
"ratiop" && year == 2009) leg = 
new TLegend(0.70,0.07,0.90,0.86);
 
  993         else if (legend_type==
"ratiop" && year == 2010) leg = 
new TLegend(0.70,0.02,0.90,0.75);
 
  996         else if (legend_type==
"stackedspectra" && year == 2010) leg = 
new TLegend(0.70,0.40,0.90,0.80);
 
  997         else if (legend_type==
"ExtraPoints" && year == 2010)    leg = 
new TLegend(0.65,0.13,0.96,0.90);
 
 1002     else if (particle_name==
"antiproton")
 
 1004         if      (legend_type==
"points" && year == 2009) leg = 
new TLegend(0.70,0.18,0.94,0.88); 
 
 1005         else if (legend_type==
"points" && year == 2010) leg = 
new TLegend(0.70,0.13,0.94,0.81);
 
 1007         else if (legend_type==
"header" && year == 2009) leg = 
new TLegend(0.60,0.90,0.95,0.97); 
 
 1008         else if (legend_type==
"header" && year == 2010) leg = 
new TLegend(0.60,0.90,0.95,0.97); 
 
 1009         else if (legend_type==
"ratiop" && year == 2009) leg = 
new TLegend(0.70,0.07,0.90,0.86);
 
 1010         else if (legend_type==
"ratiop" && year == 2010) leg = 
new TLegend(0.70,0.02,0.90,0.75);
 
 1017     else if (particle_name==
"deuteron")
 
 1019         if      (legend_type==
"points" && year == 2009) leg = 
new TLegend(0.70,0.13,0.94,0.90); 
 
 1020         else if (legend_type==
"points" && year == 2010) leg = 
new TLegend(0.70,0.13,0.94,0.90);
 
 1022         else if (legend_type==
"header" && year == 2009) leg = 
new TLegend(0.60,0.90,0.95,0.97); 
 
 1023         else if (legend_type==
"header" && year == 2010) leg = 
new TLegend(0.60,0.90,0.95,0.97); 
 
 1024         else if (legend_type==
"ratiop" && year == 2009) leg = 
new TLegend(0.70,0.07,0.90,0.86);
 
 1025         else if (legend_type==
"ratiop" && year == 2010) leg = 
new TLegend(0.70,0.02,0.90,0.75);
 
 1028         else if (legend_type==
"stackedspectra" && year == 2010) leg = 
new TLegend(0.70,0.40,0.90,0.80);
 
 1029         else if (legend_type==
"ExtraPoints" && year == 2010)    leg = 
new TLegend(0.65,0.13,0.96,0.90);
 
 1038         else if (legend_type==
"p0" && year == 6) leg = 
new TLegend(0.80,0.82,0.97,0.87);  
 
 1039         else if (legend_type==
"p0" && year == 5) leg = 
new TLegend(0.80,0.67,0.97,0.72);
 
 1040         else if (legend_type==
"p0" && year == 4) leg = 
new TLegend(0.80,0.54,0.97,0.59);
 
 1041         else if (legend_type==
"p0" && year == 3) leg = 
new TLegend(0.80,0.44,0.97,0.48);
 
 1042         else if (legend_type==
"p0" && year == 2) leg = 
new TLegend(0.80,0.35,0.97,0.40);
 
 1043         else if (legend_type==
"p0" && year == 1) leg = 
new TLegend(0.80,0.27,0.97,0.32);
 
 1044         else if (legend_type==
"p0" && year == 0) leg = 
new TLegend(0.80,0.21,0.97,0.26);
 
 1047         else if (legend_type==
"p0" && year == 2010)        leg = 
new TLegend(0.75,0.85,0.95,0.97);  
 
 1049         else if (legend_type==
"p0percent" && year == 2010) leg = 
new TLegend(0.75,0.60,0.94,0.95);  
 
 1056         cerr<<
"\n\n\nERROR in GetTLegend(): string  "<<particle_name<<
"  does not match any known name"<<endl; 
 
 1060     if (legend_type==
"headerWithEPOS" && year == 2009) leg = 
new TLegend(0.22,0.845,0.955,0.995); 
 
 1061     if (legend_type==
"headerWithEPOS" && year == 2010) leg = 
new TLegend(0.22,0.845,0.955,0.995); 
 
 1071 vector<TH1D*> GetEPOSYGraphs(
const string &particle_name, 
const vector<double> &vP0)
 
 1073     TFile * fEPOSpp158 = 
new TFile (
"inputfiles_EPOSAfterburner/pp_158_combo.root", 
"READ");
 
 1074     if (fEPOSpp158->IsOpen())
 
 1075         cout<<
"\n[INFO] Opened MC flatphasespace file "<<fEPOSpp158->GetName()<<
" in READ mode."<<endl;
 
 1077     auto hEvents = (TH1D*)fEPOSpp158->Get(
"Hist_header"); 
 
 1078     double nEvents = hEvents->GetEntries();
 
 1080     vector<TH1D*> vHistEPOS;
 
 1082     for (
unsigned int k = 0; k < vP0.size(); k++)
 
 1084         TH1D * Hist_y_deuteron = (TH1D*)fEPOSpp158->Get(Form(
"Hist_y_%s_dp0_%.2f", particle_name.c_str(), vP0[k]));
 
 1085         Hist_y_deuteron->Rebin(2);
 
 1086         Hist_y_deuteron = Normalize_1D_Histogram(Hist_y_deuteron, nEvents);
 
 1088         vHistEPOS.push_back(Hist_y_deuteron);
 
 1097 vector<TGraphErrors*> GetEPOS_Y_PT_Spectra_Graphs(
const string &particle = 
"deuteron",
 
 1098                                                   const double p0 = 84.19,
 
 1100                                                   bool doScaling = 
false,
 
 1101                                                   double pT_max_EPOS = 1.0,
 
 1102                                                   int rapidity_bin_max_data = 45,
 
 1103                                                   int rapidity_bin_min_data = 48)
 
 1113     TFile * fEPOSpp158 = 
new TFile (
"inputfiles_EPOSAfterburner/pp_158_combo.root", 
"READ");
 
 1114     if (fEPOSpp158->IsOpen())
 
 1115         cerr<<
"[INFO] Opened MC flatphasespace file "<<fEPOSpp158->GetName()<<
" in READ mode."<<endl;
 
 1117     TH1D * hEvents = (TH1D*)fEPOSpp158->Get(
"Hist_header"); 
 
 1118     double nEvents = hEvents->GetEntries();
 
 1119     cerr<<
"[INFO] Number of p+p events simulated with EPOS+Afterburner:  "<<nEvents<<endl;
 
 1121     string histname = 
"Hist_pT_y_" + particle + 
"_";
 
 1122     string str_p0 = string(Form(
"%.2f", p0));
 
 1123     if      (particle == 
"antiproton" || particle == 
"piMinus" || particle == 
"kMinus")                        histname = histname + 
"dbarp0_" + str_p0;
 
 1124     else if (particle == 
"proton" || particle == 
"piPlus" || particle == 
"kPlus" || particle == 
"deuteron")    histname = histname + 
"dp0_"    + str_p0;
 
 1126         cerr<<
"\n\n\nERROR in "<<__PRETTY_FUNCTION__<<
": string  "<<particle<<
"  does not match any saved name."<<endl;
 
 1129     TH2D * h2D_pT_y = (TH2D*)fEPOSpp158->Get(histname.c_str());
 
 1130     h2D_pT_y->RebinY(rebinY); 
 
 1131     h2D_pT_y = Normalize_2D_Histogram(h2D_pT_y, nEvents, 
"");
 
 1134     string filenamestring = 
"plots_EPOS/" + particle + 
"/Y_PT_Spectra_Graphs_" + particle + 
"_" + str_p0 + 
"_DataCheck.root";
 
 1135     TFile * fOut = 
new TFile(filenamestring.c_str(), 
"RECREATE");
 
 1140     cerr<<
"[INFO] In "<<histname<<
" from "<<fEPOSpp158->GetName()<<
", getting y-Bins:  ";
 
 1141     vector<TGraphErrors*> EPOSGraphs;
 
 1143     for (
int yBin = rapidity_bin_min_data; yBin <= rapidity_bin_max_data; yBin++) 
 
 1145         auto htemp = h2D_pT_y->ProjectionX(Form(
"y_bin_%d_y=%.2f", yBin, h2D_pT_y->GetYaxis()->GetBinCenter(yBin)), yBin, yBin);
 
 1146         cerr<<
"["<<h2D_pT_y->GetYaxis()->GetBinLowEdge(yBin)<<
", "<<h2D_pT_y->GetYaxis()->GetBinLowEdge(yBin)+h2D_pT_y->GetYaxis()->GetBinWidth(yBin)<<
"], ";
 
 1149         for (
int pT_bin = 1; pT_bin <= htemp->GetNbinsX(); pT_bin++) 
 
 1152             if (doScaling == 
true)
 
 1154                 if (htemp->GetBinContent(pT_bin) > 0)
 
 1155                     htemp->SetBinContent(pT_bin, 1.0 * pow (10, -(yBin - rapidity_bin_min_data))*htemp->GetBinContent(pT_bin));
 
 1160             if (htemp->GetBinCenter(pT_bin) > pT_max_EPOS)
 
 1162                 htemp->SetBinContent(pT_bin, 0);
 
 1163                 htemp->SetBinError(pT_bin, 0);
 
 1171         TGraphErrors * Gtemp = 
new TGraphErrors(htemp);
 
 1172         Gtemp = RemoveZeroFromGraph(Gtemp);
 
 1173         TGraphErrors * GtempZero = SetTGraphXErrorZero(Gtemp);
 
 1174         EPOSGraphs.push_back(GtempZero);
 
 1183     cerr<<
"\n[INFO] Graphs returned."<<endl;
 
 1191 vector<TGraphErrors*> GetEPOS_Y_PT_Spectra_Graphs(TH2D * h2D_pT_y,
 
 1192                                                   const string &particle = 
"deuteron",
 
 1193                                                   const double p0 = 84.19,
 
 1194                                                   int rapidity_bin_min_data = 45, 
 
 1195                                                   int rapidity_bin_max_data = 48, 
 
 1196                                                   bool doScaling = 
false,
 
 1197                                                   bool doCleanup = 
true 
 1202     string str_p0 = string(Form(
"%.2f", p0));    
 
 1203     string filenamestring = 
"plots_EPOS/" + particle + 
"/Y_PT_Spectra_Graphs_" + particle + 
"_" + str_p0 + 
".root";
 
 1204     TFile * fOut = 
new TFile(filenamestring.c_str(), 
"RECREATE");
 
 1208     cerr<<
"[INFO] From "<<h2D_pT_y->GetName()<<
", getting y-Bins:  ";
 
 1209     vector<TGraphErrors*> EPOSGraphs;
 
 1211     for (
int yBin = rapidity_bin_min_data; yBin <= rapidity_bin_max_data; yBin++) 
 
 1213         auto htemp = h2D_pT_y->ProjectionX(Form(
"y_bin_%d_y=%.2f", yBin, h2D_pT_y->GetYaxis()->GetBinCenter(yBin)), yBin, yBin);
 
 1214         cerr<<
"["<<h2D_pT_y->GetYaxis()->GetBinLowEdge(yBin)<<
", "<<h2D_pT_y->GetYaxis()->GetBinLowEdge(yBin)+h2D_pT_y->GetYaxis()->GetBinWidth(yBin)<<
"], ";
 
 1217         for (
int pT_bin = 1; pT_bin <= htemp->GetNbinsX(); pT_bin++) 
 
 1220             if (doScaling == 
true)
 
 1222                 if (htemp->GetBinContent(pT_bin) > 0)
 
 1223                     htemp->SetBinContent(pT_bin, 1.0 * pow (10, -(yBin - rapidity_bin_min_data))*htemp->GetBinContent(pT_bin));
 
 1227             if (doCleanup == 
true)
 
 1229                 if (particle == 
"deuteron" && pT_bin > 15)
 
 1231                     htemp->SetBinContent(pT_bin, 0);
 
 1232                     htemp->SetBinError(pT_bin, 0);
 
 1235                 if (particle == 
"proton" && pT_bin > 15)
 
 1237                     htemp->SetBinContent(pT_bin, 0);
 
 1238                     htemp->SetBinError(pT_bin, 0);
 
 1247         TGraphErrors * Gtemp = 
new TGraphErrors(htemp);
 
 1248         Gtemp = RemoveZeroFromGraph(Gtemp);
 
 1249         TGraphErrors * GtempZero = SetTGraphXErrorZero(Gtemp);
 
 1250         EPOSGraphs.push_back(GtempZero);
 
 1255     cerr<<
"\n[INFO] Graphs returned.\n[INFO] Intermediate histograms saved to "<<fOut->GetName()<<endl;
 
 1264 vector<TGraphAsymmErrors*> GetTGraphAsymm(
const TH2D* h,
 
 1267                                           const string &particle_name,
 
 1268                                           int rapidity_bin_min_data = 45,
 
 1269                                           int rapidity_bin_max_data = 48,
 
 1270                                           bool doScaling = 
true,
 
 1271                                           bool printNumbers = 
false)
 
 1273     vector<TGraphAsymmErrors*> dataGraphs;
 
 1274     TH1D * h_copy = (TH1D*)h->Clone();
 
 1275     TH1D * h_high_copy = (TH1D*)h_high->Clone();
 
 1276     TH1D * h_low_copy = (TH1D*)h_low->Clone();
 
 1280     if (printNumbers == 
true)
 
 1282         fprintf(stderr, 
"\n\nParticle: %10s\n", particle_name.c_str());
 
 1283         fprintf(stderr,
"     ");
 
 1284         for (
int pT_bin = 1; pT_bin <= 15; pT_bin++)
 
 1286             fprintf(stderr, 
"%7s%2.1f", 
"pT=", 0.1*pT_bin);
 
 1292     for (
int yBin = rapidity_bin_min_data; yBin <= rapidity_bin_max_data; yBin++) 
 
 1294         std::vector<double> x;
 
 1295         std::vector<double> x_low;
 
 1296         std::vector<double> x_high;
 
 1297         std::vector<double> y;
 
 1298         std::vector<double> y_errorLow;
 
 1299         std::vector<double> y_errorHigh;
 
 1301         if (printNumbers == 
true)
 
 1303             fprintf(stderr, 
"\nFor y=%2.1f", -1.1+2*
double(yBin-rapidity_bin_min_data)/10);
 
 1306         for (
int pT_bin = 1; pT_bin <= pT_max_bin; pT_bin++) 
 
 1308             x.push_back(h_copy->GetXaxis()->GetBinCenter(pT_bin));
 
 1310             x_high.push_back(0);
 
 1312             std::vector<double> unsorted_bin_Counts = {h_low_copy->GetBinContent(pT_bin, yBin), h_copy->GetBinContent(pT_bin, yBin), h_high_copy->GetBinContent(pT_bin, yBin)};
 
 1315             if (doScaling == 
true)
 
 1317                 for (
int k = 0; k < int(unsorted_bin_Counts.size()); k++)
 
 1319                     if (unsorted_bin_Counts[k] > 0)
 
 1320                         unsorted_bin_Counts[k] = 1.0 * pow (10, -(yBin - rapidity_bin_min_data)) * unsorted_bin_Counts[k];
 
 1324             if (std::is_sorted(unsorted_bin_Counts.begin(), unsorted_bin_Counts.end())) 
 
 1331                 sort(unsorted_bin_Counts.begin(), unsorted_bin_Counts.end());
 
 1334             y_errorLow.push_back(unsorted_bin_Counts[1]-unsorted_bin_Counts[0]);
 
 1335             y.push_back(unsorted_bin_Counts[1]);
 
 1336             y_errorHigh.push_back(unsorted_bin_Counts[2]-unsorted_bin_Counts[1]);
 
 1339             if (printNumbers == 
true)
 
 1341                 fprintf(stderr, 
"%10.2e", unsorted_bin_Counts[1]);
 
 1345         TVectorD tv_x(x.size(), &x[0]);
 
 1346         TVectorD tv_x_high(x_high.size(), &x_high[0]);
 
 1347         TVectorD tv_x_low(x_low.size(), &x_low[0]);
 
 1348         TVectorD tv_y(y.size(), &y[0]);
 
 1349         TVectorD tv_y_errorLow(y_errorLow.size(), &y_errorLow[0]);
 
 1350         TVectorD tv_y_errorHigh(y_errorHigh.size(), &y_errorHigh[0]);
 
 1352         TGraphAsymmErrors * G = 
new TGraphAsymmErrors(tv_x, tv_y, tv_x_low, tv_x_high, tv_y_errorLow, tv_y_errorHigh);
 
 1353         dataGraphs.push_back(G);
 
 1360         y_errorHigh.clear();
 
 1363     if (printNumbers == 
true)
 
 1365         fprintf(stderr,
"\n\n");
 
 1378 vector<TGraphAsymmErrors*> GetEPOS_Y_PT_SpectraBand_Graphs(
const string &particle = 
"deuteron",
 
 1383     TFile * fEPOSpp158 = 
new TFile (
"inputfiles_EPOSAfterburner/pp_158_combo.root", 
"READ");
 
 1384     if (fEPOSpp158->IsOpen())
 
 1385         cout<<
"[INFO] Opened MC flatphasespace file "<<fEPOSpp158->GetName()<<
" in READ mode."<<endl;
 
 1387     TH1D * hEvents = (TH1D*)fEPOSpp158->Get(
"Hist_header"); 
 
 1388     double nEvents = hEvents->GetEntries();
 
 1389     cout<<
"[INFO] Number of p+p events simulated with EPOS+Afterburner:  "<<nEvents<<endl;
 
 1391     string histname = 
"Hist_pT_y_" + particle + 
"_";
 
 1392     if      (particle == 
"antiproton" || particle == 
"piMinus" || particle == 
"kMinus")                        histname = histname + 
"dbarp0_";
 
 1393     else if (particle == 
"proton" || particle == 
"piPlus" || particle == 
"kPlus" || particle == 
"deuteron")    histname = histname + 
"dp0_";
 
 1395         cerr<<
"\n\n\nERROR in "<<__PRETTY_FUNCTION__<<
": string  "<<particle<<
"  does not match any saved name."<<endl;
 
 1397     string histname_UPP = histname + 
"109.45";
 
 1398     cerr<<
"[INFO] Getting "<<histname_UPP<<
" from "<<fEPOSpp158->GetName()<<endl;
 
 1399     TH2D * h2D_pT_y_UPP = (TH2D*)fEPOSpp158->Get(histname_UPP.c_str());
 
 1400     h2D_pT_y_UPP->RebinY(rebinY); 
 
 1401     h2D_pT_y_UPP = Normalize_2D_Histogram(h2D_pT_y_UPP, nEvents, 
"");
 
 1403     string histname_MID = histname + 
"84.19";
 
 1404     cerr<<
"[INFO] Getting "<<histname_MID<<
" from "<<fEPOSpp158->GetName()<<endl;
 
 1405     TH2D * h2D_pT_y_MID = (TH2D*)fEPOSpp158->Get(histname_MID.c_str());
 
 1406     h2D_pT_y_MID->RebinY(rebinY); 
 
 1407     h2D_pT_y_MID = Normalize_2D_Histogram(h2D_pT_y_MID, nEvents, 
"");
 
 1409     string histname_LOW = histname + 
"58.94";
 
 1410     cerr<<
"[INFO] Getting "<<histname_LOW<<
" from "<<fEPOSpp158->GetName()<<endl;
 
 1411     TH2D * h2D_pT_y_LOW = (TH2D*)fEPOSpp158->Get(histname_LOW.c_str());
 
 1412     h2D_pT_y_LOW->RebinY(rebinY); 
 
 1413     h2D_pT_y_LOW = Normalize_2D_Histogram(h2D_pT_y_LOW, nEvents, 
"");
 
 1415     vector<TGraphAsymmErrors*> EPOSBandGraphs = GetTGraphAsymm(h2D_pT_y_MID, h2D_pT_y_UPP, h2D_pT_y_LOW, 
"deuteron");
 
 1417     delete h2D_pT_y_UPP;
 
 1418     delete h2D_pT_y_MID;
 
 1419     delete h2D_pT_y_LOW;
 
 1422     return EPOSBandGraphs;