Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-04-05 08:08:17

0001 #include "/sphenix/u/virgilemahaut/style/sPhenixStyle_Greg.C"
0002 
0003 void fit_shuffle_details_histograms()
0004 {
0005   SetsPhenixStyle();
0006 
0007   std::string plots_folder = "figures_details_runs_0312";
0008   gSystem->Exec(("mkdir -p " + plots_folder).c_str());
0009 
0010   std::string inputfilename = "shuffle_1_100000_runs_0312.root";
0011 
0012   TFile *inputfile = TFile::Open(inputfilename.c_str());
0013 
0014   const int nBeams = 2;
0015   const std::string beams[nBeams] = {"yellow", "blue"};
0016   const int nConfigs = 4;
0017   const std::string configs[nConfigs] = {"0mrad_mbd", "0mrad_photon", "15mrad_mbd", "15mrad_photon"};
0018   const int nParticles = 2;
0019   const std::string particles[nParticles] = {"pi0", "eta"};
0020   const int nDirections = 2;
0021   const std::string directions[nDirections] = {"forward", "backward"};
0022   const int nPtBins = 9;
0023   const double pTBins[nPtBins + 1] = {1, 2, 3, 4, 5, 6, 7, 8, 10, 20};
0024   const double pTMeans[nParticles][nPtBins] = {
0025     {1.665, 2.385, 3.440, 4.406, 5.399, 6.398, 7.397, 11.715},
0026     {1.665, 2.349, 3.356, 4.435, 5.418, 6.417, 7.424, 8.750, 11.715}
0027   };
0028   const int nEtaBins = 8;
0029   const double etaBins[nEtaBins + 1] = {-2.00, -1.05, -0.86, -0.61, 0.00, 0.61, 0.86, 1.05, 2.00};
0030   const double etaMeans[nParticles][nEtaBins] = {
0031     {-1.201, -0.957, -0.744, -0.342, 0.342, 0.744, 0.957, 1.201},
0032     {-1.192, -0.951, -0.741, -0.344, 0.344, 0.741, 0.951, 1.192}
0033   };
0034   const int nXfBins = 8;
0035   const double xfBins[nXfBins + 1] = {-0.200, -0.048, -0.035, -0.022, 0.00, 0.022, 0.035, 0.048, 0.200};
0036   const double xfMeans[nParticles][nXfBins] = {
0037     {-0.0606, -0.0410, -0.0284, -0.0130, 0.0130, 0.0284, 0.0410, 0.0606}, 
0038     {-0.0641, -0.0414, -0.0282, -0.0132, 0.0132, 0.0282, 0.0414, 0.0641}
0039   };
0040   
0041 
0042   TGraphErrors *gr_final_pt_mean[nParticles][nDirections] = {nullptr};
0043   TGraphErrors *gr_final_pt_sigma[nParticles][nDirections] = {nullptr};
0044   TGraphErrors *gr_final_eta_mean[nParticles] = {nullptr};
0045   TGraphErrors *gr_final_eta_sigma[nParticles] = {nullptr};
0046   TGraphErrors *gr_final_xf_mean[nParticles] = {nullptr};
0047   TGraphErrors *gr_final_xf_sigma[nParticles] = {nullptr};
0048 
0049   for (int iB = 0; iB < nBeams; iB++) {
0050     for (int iC = 0; iC < nConfigs; iC++) {
0051       for (int iP = 0; iP < nParticles; iP++) {
0052         std::string local_plots_folder = plots_folder + "/" + beams[iB] + "/" + configs[iC] + "/pT/";
0053         gSystem->Exec(("mkdir -p " + local_plots_folder).c_str());
0054         {
0055           std::stringstream graphname_template;
0056           graphname_template << "graph_shuffle_pt_nodir_"
0057                              << beams[iB] << "_"
0058                              << particles[iP] << "_"
0059                              << configs[iC] << "_";
0060           std::string graphname_mean = graphname_template.str() + "mean";
0061           std::string graphname_sigma = graphname_template.str() + "sigma";
0062           TGraphErrors *graph_mean = new TGraphErrors();
0063           graph_mean->SetName(graphname_mean.c_str());
0064           graph_mean->SetTitle(";p_{T} [GeV];#mu");
0065           TGraphErrors *graph_sigma = new TGraphErrors();
0066           graph_sigma->SetName(graphname_sigma.c_str());
0067           graph_sigma->SetTitle(";p_{T} [GeV];#sigma");
0068           for (int iPt = 0; iPt < nPtBins; iPt++) {
0069             // h_AN_xf_shuffle_eta_xf_3_sqrt
0070             std::stringstream hname;
0071             hname << "h_AN_pt_nodir_shuffle_"
0072                   << beams[iB] << "_"
0073                   << particles[iP] << "_pt_"
0074                   << iPt << "_"
0075                   << configs[iC] << "_sqrt";
0076             TH1F *h_AN = (TH1F*)inputfile->Get(hname.str().c_str());
0077             if (!h_AN) {
0078               std::cerr << "Error. Could not open histogram " << hname.str() << " in file " << inputfilename << "." << std::endl;
0079               continue;
0080             }
0081             TF1 *fit_amplitude = new TF1("fit_amplitude", "gaus", -4, 4);
0082             h_AN->Fit(fit_amplitude);
0083 
0084             graph_mean->SetPoint(iPt, pTMeans[iP][iPt], fit_amplitude->GetParameter(1));
0085             graph_mean->SetPointError(iPt, 0, fit_amplitude->GetParError(1));
0086             graph_sigma->SetPoint(iPt, pTMeans[iP][iPt], fit_amplitude->GetParameter(2));
0087             graph_sigma->SetPointError(iPt, 0, fit_amplitude->GetParError(2));
0088 
0089             // Plot histogram
0090             {
0091               std::stringstream canvas_name;
0092               canvas_name << "canvas_" << hname.str();
0093               TCanvas *canvas = new TCanvas(canvas_name.str().c_str());
0094               canvas->cd();
0095               fit_amplitude->SetLineColor(kRed);
0096               h_AN->Draw("HIST");
0097               fit_amplitude->Draw("SAME");
0098 
0099               std::stringstream stream;
0100               TLatex latex;
0101               latex.SetNDC();
0102               latex.SetTextColor(kBlue);
0103               std::cout << "text size: " << latex.GetTextSize() << std::endl;
0104               latex.SetTextSize(0.04);
0105               stream << "#mu = " << std::setprecision(2) << fit_amplitude->GetParameter(1) << " #pm " << fit_amplitude->GetParError(1);
0106               latex.DrawLatex(0.43, 0.25, stream.str().c_str());
0107               stream.str(""); stream << std::setprecision(2) << "#sigma = " << fit_amplitude->GetParameter(2) << " #pm " << fit_amplitude->GetParError(2);
0108               latex.DrawLatex(0.43,0.20, stream.str().c_str());
0109               latex.SetTextColor(kBlack);
0110               latex.SetTextSize(0.05);
0111               stream.str(""); stream << std::fixed << std::setprecision(0) << pTBins[iPt] << " < p_{T} < " << pTBins[iPt+1] << " GeV";
0112               latex.DrawLatex(0.2, 0.80, stream.str().c_str());
0113 
0114               canvas->Draw();
0115               canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".pdf").c_str());
0116               canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".png").c_str());
0117               delete canvas;
0118             }
0119           }
0120           {
0121             std::stringstream canvas_name;
0122             canvas_name << "canvas_" << graph_mean->GetName();
0123             TCanvas *canvas = new TCanvas(canvas_name.str().c_str());
0124             canvas->cd();
0125             int color = (iP == 0 ? kRed : kBlue);
0126             std::cout << "Print graph_mean" << std::endl;
0127             graph_mean->Print();
0128             graph_mean->SetLineColor(color);
0129             graph_mean->SetMarkerColor(color);
0130             graph_mean->SetMarkerStyle(kFullCircle);
0131             graph_mean->Draw("AP");
0132 
0133             graph_mean->SetMinimum(-0.05);
0134             graph_mean->SetMaximum(0.05);
0135 
0136             if (iP == 0) graph_mean->GetXaxis()->SetRangeUser(1.0, 10.0);
0137             else graph_mean->GetXaxis()->SetRangeUser(2.0, 20.0);
0138 
0139             gPad->Update();
0140             gPad->Modified();
0141             double min_x = gPad->GetUxmin();
0142             double max_x = gPad->GetUxmax();
0143 
0144             TLine *tline = new TLine();
0145             tline->SetLineWidth(2);
0146             tline->SetLineColor(kBlack);
0147             tline->SetLineStyle(kDashed);
0148             tline->DrawLine(min_x, 0, max_x, 0);
0149 
0150             canvas->Draw();
0151             canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".png").c_str());
0152             canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".pdf").c_str());
0153 
0154             delete canvas;
0155           }
0156           {
0157             std::stringstream canvas_name;
0158             canvas_name << "canvas_" << graph_sigma->GetName();
0159             TCanvas *canvas = new TCanvas(canvas_name.str().c_str());
0160             canvas->cd();
0161             int color = (iP == 0 ? kRed : kBlue);
0162             std::cout << "Print graph_sigma" << std::endl;
0163             graph_sigma->Print();
0164             graph_sigma->SetLineColor(color);
0165             graph_sigma->SetMarkerColor(color);
0166             graph_sigma->SetMarkerStyle(kFullCircle);
0167             graph_sigma->Draw("AP");
0168 
0169             graph_sigma->SetMinimum(0.95);
0170             graph_sigma->SetMaximum(1.05);
0171 
0172             if (iP == 0) graph_sigma->GetXaxis()->SetRangeUser(1.0, 10.0);
0173             else graph_sigma->GetXaxis()->SetRangeUser(2.0, 20.0);
0174 
0175             gPad->Update();
0176             gPad->Modified();
0177             double min_x = gPad->GetUxmin();
0178             double max_x = gPad->GetUxmax();
0179 
0180             TLine *tline = new TLine();
0181             tline->SetLineWidth(2);
0182             tline->SetLineColor(kBlack);
0183             tline->SetLineStyle(kDashed);
0184             tline->DrawLine(min_x, 1, max_x, 1);
0185 
0186             canvas->Draw();
0187             canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".png").c_str());
0188             canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".pdf").c_str());
0189 
0190             delete canvas;
0191           }
0192         }
0193         for (int iDir = 0; iDir < nDirections; iDir++) {
0194           std::stringstream graphname_template;
0195           graphname_template << "graph_shuffle_pt_"
0196                              << beams[iB] << "_"
0197                              << particles[iP] << "_"
0198                              << directions[iDir] << "_"
0199                              << configs[iC] << "_";
0200           std::string graphname_mean = graphname_template.str() + "mean";
0201           std::string graphname_sigma = graphname_template.str() + "sigma";
0202           TGraphErrors *graph_mean = new TGraphErrors();
0203           graph_mean->SetName(graphname_mean.c_str());
0204           graph_mean->SetTitle(";p_{T} [GeV];#mu");
0205           TGraphErrors *graph_sigma = new TGraphErrors();
0206           graph_sigma->SetName(graphname_sigma.c_str());
0207           graph_sigma->SetTitle(";p_{T} [GeV];#sigma");
0208           for (int iPt = 0; iPt < nPtBins; iPt++) {
0209             // h_AN_xf_shuffle_eta_xf_3_sqrt
0210             std::stringstream hname;
0211             hname << "h_AN_pt_shuffle_"
0212                   << beams[iB] << "_"
0213                   << particles[iP] << "_"
0214                   << directions[iDir] << "_pt_"
0215                   << iPt << "_"
0216                   << configs[iC] << "_sqrt";
0217             TH1F *h_AN = (TH1F*)inputfile->Get(hname.str().c_str());
0218             if (!h_AN) {
0219               std::cerr << "Error. Could not open histogram " << hname.str() << " in file " << inputfilename << "." << std::endl;
0220               continue;
0221             }
0222             TF1 *fit_amplitude = new TF1("fit_amplitude", "gaus", -4, 4);
0223             h_AN->Fit(fit_amplitude);
0224 
0225             graph_mean->SetPoint(iPt, pTMeans[iP][iPt], fit_amplitude->GetParameter(1));
0226             graph_mean->SetPointError(iPt, 0, fit_amplitude->GetParError(1));
0227             graph_sigma->SetPoint(iPt, pTMeans[iP][iPt], fit_amplitude->GetParameter(2));
0228             graph_sigma->SetPointError(iPt, 0, fit_amplitude->GetParError(2));
0229 
0230             // Plot histogram
0231             {
0232               std::stringstream canvas_name;
0233               canvas_name << "canvas_" << hname.str();
0234               TCanvas *canvas = new TCanvas(canvas_name.str().c_str());
0235               canvas->cd();
0236               fit_amplitude->SetLineColor(kRed);
0237               h_AN->Draw("HIST");
0238               fit_amplitude->Draw("SAME");
0239 
0240               std::stringstream stream;
0241               TLatex latex;
0242               latex.SetNDC();
0243               latex.SetTextColor(kBlue);
0244               std::cout << "text size: " << latex.GetTextSize() << std::endl;
0245               latex.SetTextSize(0.04);
0246               stream << "#mu = " << std::setprecision(2) << fit_amplitude->GetParameter(1) << " #pm " << fit_amplitude->GetParError(1);
0247               latex.DrawLatex(0.43, 0.25, stream.str().c_str());
0248               stream.str(""); stream << std::setprecision(2) << "#sigma = " << fit_amplitude->GetParameter(2) << " #pm " << fit_amplitude->GetParError(2);
0249               latex.DrawLatex(0.43,0.20, stream.str().c_str());
0250               latex.SetTextColor(kBlack);
0251               latex.SetTextSize(0.05);
0252               stream.str(""); stream << std::fixed << std::setprecision(0) << pTBins[iPt] << " < p_{T} < " << pTBins[iPt+1] << " GeV";
0253               latex.DrawLatex(0.2, 0.80, stream.str().c_str());
0254 
0255               canvas->Draw();
0256               canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".pdf").c_str());
0257               canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".png").c_str());
0258               delete canvas;
0259             }
0260           }
0261           {
0262             std::stringstream canvas_name;
0263             canvas_name << "canvas_" << graph_mean->GetName();
0264             TCanvas *canvas = new TCanvas(canvas_name.str().c_str());
0265             canvas->cd();
0266             int color = (iP == 0 ? kRed : kBlue);
0267             std::cout << "Print graph_mean" << std::endl;
0268             graph_mean->Print();
0269             graph_mean->SetLineColor(color);
0270             graph_mean->SetMarkerColor(color);
0271             graph_mean->SetMarkerStyle(kFullCircle);
0272             graph_mean->Draw("AP");
0273 
0274             graph_mean->SetMinimum(-0.05);
0275             graph_mean->SetMaximum(0.05);
0276 
0277             if (iP == 0) graph_mean->GetXaxis()->SetRangeUser(1.0, 10.0);
0278             else graph_mean->GetXaxis()->SetRangeUser(2.0, 20.0);
0279 
0280             gPad->Update();
0281             gPad->Modified();
0282             double min_x = gPad->GetUxmin();
0283             double max_x = gPad->GetUxmax();
0284 
0285             TLine *tline = new TLine();
0286             tline->SetLineWidth(2);
0287             tline->SetLineColor(kBlack);
0288             tline->SetLineStyle(kDashed);
0289             tline->DrawLine(min_x, 0, max_x, 0);
0290 
0291             canvas->Draw();
0292             canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".png").c_str());
0293             canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".pdf").c_str());
0294 
0295             delete canvas;
0296           }
0297           {
0298             std::stringstream canvas_name;
0299             canvas_name << "canvas_" << graph_sigma->GetName();
0300             TCanvas *canvas = new TCanvas(canvas_name.str().c_str());
0301             canvas->cd();
0302             int color = (iP == 0 ? kRed : kBlue);
0303             std::cout << "Print graph_sigma" << std::endl;
0304             graph_sigma->Print();
0305             graph_sigma->SetLineColor(color);
0306             graph_sigma->SetMarkerColor(color);
0307             graph_sigma->SetMarkerStyle(kFullCircle);
0308             graph_sigma->Draw("AP");
0309 
0310             graph_sigma->SetMinimum(0.95);
0311             graph_sigma->SetMaximum(1.05);
0312 
0313             if (iP == 0) graph_sigma->GetXaxis()->SetRangeUser(1.0, 10.0);
0314             else graph_sigma->GetXaxis()->SetRangeUser(2.0, 20.0);
0315 
0316             gPad->Update();
0317             gPad->Modified();
0318             double min_x = gPad->GetUxmin();
0319             double max_x = gPad->GetUxmax();
0320 
0321             TLine *tline = new TLine();
0322             tline->SetLineWidth(2);
0323             tline->SetLineColor(kBlack);
0324             tline->SetLineStyle(kDashed);
0325             tline->DrawLine(min_x, 1, max_x, 1);
0326 
0327             canvas->Draw();
0328             canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".png").c_str());
0329             canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".pdf").c_str());
0330 
0331             delete canvas;
0332           }
0333         }
0334         {
0335           std::string local_plots_folder = plots_folder + "/" + beams[iB] + "/" + configs[iC] + "/eta/";
0336           gSystem->Exec(("mkdir -p " + local_plots_folder).c_str());
0337           std::stringstream graphname_template;
0338           graphname_template << "graph_shuffle_eta_"
0339                              << beams[iB] << "_"
0340                              << particles[iP] << "_"
0341                              << configs[iC] << "_";
0342           std::string graphname_mean = graphname_template.str() + "mean";
0343           std::string graphname_sigma = graphname_template.str() + "sigma";
0344           TGraphErrors *graph_mean = new TGraphErrors();
0345           graph_mean->SetName(graphname_mean.c_str());
0346           graph_mean->SetTitle(";#eta;#mu");
0347           TGraphErrors *graph_sigma = new TGraphErrors();
0348           graph_sigma->SetName(graphname_sigma.c_str());
0349           graph_sigma->SetTitle(";#eta;#sigma");
0350           for (int iEta = 0; iEta < nEtaBins; iEta++) {
0351             // h_AN_xf_shuffle_eta_xf_3_sqrt
0352             std::stringstream hname;
0353             hname << "h_AN_eta_shuffle_"
0354                   << beams[iB] << "_"
0355                   << particles[iP] << "_eta_"
0356                   << iEta << "_"
0357                   << configs[iC] << "_sqrt";
0358             TH1F *h_AN = (TH1F*)inputfile->Get(hname.str().c_str());
0359             if (!h_AN) {
0360               std::cerr << "Error. Could not open histogram " << hname.str() << " in file " << inputfilename << "." << std::endl;
0361               continue;
0362             }
0363             TF1 *fit_amplitude = new TF1("fit_amplitude", "gaus", -4, 4);
0364             h_AN->Fit(fit_amplitude);
0365 
0366             graph_mean->SetPoint(iEta, etaMeans[iP][iEta], fit_amplitude->GetParameter(1));
0367             graph_mean->SetPointError(iEta, 0, fit_amplitude->GetParError(1));
0368             graph_sigma->SetPoint(iEta, etaMeans[iP][iEta], fit_amplitude->GetParameter(2));
0369             graph_sigma->SetPointError(iEta, 0, fit_amplitude->GetParError(2));
0370 
0371             // Plot histogram
0372             {
0373               std::stringstream canvas_name;
0374               canvas_name << "canvas_" << hname.str();
0375               TCanvas *canvas = new TCanvas(canvas_name.str().c_str());
0376               canvas->cd();
0377               fit_amplitude->SetLineColor(kRed);
0378               h_AN->Draw("HIST");
0379               fit_amplitude->Draw("SAME");
0380 
0381               std::stringstream stream;
0382               TLatex latex;
0383               latex.SetNDC();
0384               latex.SetTextColor(kBlue);
0385               std::cout << "text size: " << latex.GetTextSize() << std::endl;
0386               latex.SetTextSize(0.04);
0387               stream << "#mu = " << std::setprecision(2) << fit_amplitude->GetParameter(1) << " #pm " << fit_amplitude->GetParError(1);
0388               latex.DrawLatex(0.43, 0.25, stream.str().c_str());
0389               stream.str(""); stream << std::setprecision(3) << "#sigma = " << fit_amplitude->GetParameter(2) << " #pm " << fit_amplitude->GetParError(2);
0390               latex.DrawLatex(0.43,0.20, stream.str().c_str());
0391               latex.SetTextColor(kBlack);
0392               latex.SetTextSize(0.05);
0393               stream.str(""); stream << std::fixed << std::setprecision(2) << etaBins[iEta] << " < #eta < " << etaBins[iEta+1];
0394               latex.DrawLatex(0.2, 0.80, stream.str().c_str());
0395 
0396               canvas->Draw();
0397               canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".pdf").c_str());
0398               canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".png").c_str());
0399               delete canvas;
0400             }
0401           }
0402           {
0403             std::stringstream canvas_name;
0404             canvas_name << "canvas_" << graph_mean->GetName();
0405             TCanvas *canvas = new TCanvas(canvas_name.str().c_str());
0406             canvas->cd();
0407             int color = (iP == 0 ? kRed : kBlue);
0408             std::cout << "Print graph_mean" << std::endl;
0409             graph_mean->Print();
0410             graph_mean->SetLineColor(color);
0411             graph_mean->SetMarkerColor(color);
0412             graph_mean->SetMarkerStyle(kFullCircle);
0413             graph_mean->Draw("AP");
0414 
0415             graph_mean->SetMinimum(-0.05);
0416             graph_mean->SetMaximum(0.05);
0417 
0418             gPad->Update();
0419             gPad->Modified();
0420             double min_x = gPad->GetUxmin();
0421             double max_x = gPad->GetUxmax();
0422 
0423             TLine *tline = new TLine();
0424             tline->SetLineWidth(2);
0425             tline->SetLineColor(kBlack);
0426             tline->SetLineStyle(kDashed);
0427             tline->DrawLine(min_x, 0, max_x, 0);
0428 
0429             canvas->Draw();
0430             canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".png").c_str());
0431             canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".pdf").c_str());
0432 
0433             delete canvas;
0434           }
0435           {
0436             std::stringstream canvas_name;
0437             canvas_name << "canvas_" << graph_sigma->GetName();
0438             TCanvas *canvas = new TCanvas(canvas_name.str().c_str());
0439             canvas->cd();
0440             int color = (iP == 0 ? kRed : kBlue);
0441             std::cout << "Print graph_sigma" << std::endl;
0442             graph_sigma->Print();
0443             graph_sigma->SetLineColor(color);
0444             graph_sigma->SetMarkerColor(color);
0445             graph_sigma->SetMarkerStyle(kFullCircle);
0446             graph_sigma->Draw("AP");
0447 
0448             graph_sigma->SetMinimum(0.95);
0449             graph_sigma->SetMaximum(1.05);
0450 
0451             gPad->Update();
0452             gPad->Modified();
0453             double min_x = gPad->GetUxmin();
0454             double max_x = gPad->GetUxmax();
0455 
0456             TLine *tline = new TLine();
0457             tline->SetLineWidth(2);
0458             tline->SetLineColor(kBlack);
0459             tline->SetLineStyle(kDashed);
0460             tline->DrawLine(min_x, 1, max_x, 1);
0461 
0462             canvas->Draw();
0463             canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".png").c_str());
0464             canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".pdf").c_str());
0465 
0466             delete canvas;
0467           }
0468         }
0469         {
0470           std::string local_plots_folder = plots_folder + "/" + beams[iB] + "/" + configs[iC] + "/xF/";
0471           gSystem->Exec(("mkdir -p " + local_plots_folder).c_str());
0472           std::stringstream graphname_template;
0473           graphname_template << "graph_shuffle_xf_"
0474                              << beams[iB] << "_"
0475                              << particles[iP] << "_"
0476                              << configs[iC] << "_";
0477           std::string graphname_mean = graphname_template.str() + "mean";
0478           std::string graphname_sigma = graphname_template.str() + "sigma";
0479           TGraphErrors *graph_mean = new TGraphErrors();
0480           graph_mean->SetName(graphname_mean.c_str());
0481           graph_mean->SetTitle(";x_{F};#mu");
0482           TGraphErrors *graph_sigma = new TGraphErrors();
0483           graph_sigma->SetName(graphname_sigma.c_str());
0484           graph_sigma->SetTitle(";x_{F};#sigma");
0485           for (int iXf = 0; iXf < nXfBins; iXf++) {
0486             // h_AN_xf_shuffle_xf_xf_3_sqrt
0487             std::stringstream hname;
0488             hname << "h_AN_xf_shuffle_"
0489                   << beams[iB] << "_"
0490                   << particles[iP] << "_xf_"
0491                   << iXf << "_"
0492                   << configs[iC] << "_sqrt";
0493             TH1F *h_AN = (TH1F*)inputfile->Get(hname.str().c_str());
0494             if (!h_AN) {
0495               std::cerr << "Error. Could not open histogram " << hname.str() << " in file " << inputfilename << "." << std::endl;
0496               continue;
0497             }
0498             TF1 *fit_amplitude = new TF1("fit_amplitude", "gaus", -4, 4);
0499             h_AN->Fit(fit_amplitude);
0500 
0501             graph_mean->SetPoint(iXf, xfMeans[iP][iXf], fit_amplitude->GetParameter(1));
0502             graph_mean->SetPointError(iXf, 0, fit_amplitude->GetParError(1));
0503             graph_sigma->SetPoint(iXf, xfMeans[iP][iXf], fit_amplitude->GetParameter(2));
0504             graph_sigma->SetPointError(iXf, 0, fit_amplitude->GetParError(2));
0505 
0506             // Plot histogram
0507             {
0508               std::stringstream canvas_name;
0509               canvas_name << "canvas_" << hname.str();
0510               TCanvas *canvas = new TCanvas(canvas_name.str().c_str());
0511               canvas->cd();
0512               fit_amplitude->SetLineColor(kRed);
0513               h_AN->Draw("HIST");
0514               fit_amplitude->Draw("SAME");
0515 
0516               std::stringstream stream;
0517               TLatex latex;
0518               latex.SetNDC();
0519               latex.SetTextColor(kBlue);
0520               std::cout << "text size: " << latex.GetTextSize() << std::endl;
0521               latex.SetTextSize(0.04);
0522               stream << "#mu = " << std::setprecision(2) << fit_amplitude->GetParameter(1) << " #pm " << fit_amplitude->GetParError(1);
0523               latex.DrawLatex(0.43, 0.25, stream.str().c_str());
0524               stream.str(""); stream << std::setprecision(3) << "#sigma = " << fit_amplitude->GetParameter(2) << " #pm " << fit_amplitude->GetParError(2);
0525               latex.DrawLatex(0.43,0.20, stream.str().c_str());
0526               latex.SetTextColor(kBlack);
0527               latex.SetTextSize(0.05);
0528               stream.str(""); stream << std::fixed << std::setprecision(3) << xfBins[iXf] << " < x_{F} < " << xfBins[iXf+1];
0529               latex.DrawLatex(0.2, 0.80, stream.str().c_str());
0530 
0531               canvas->Draw();
0532               canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".pdf").c_str());
0533               canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".png").c_str());
0534               delete canvas;
0535             }
0536           }
0537           {
0538             std::stringstream canvas_name;
0539             canvas_name << "canvas_" << graph_mean->GetName();
0540             TCanvas *canvas = new TCanvas(canvas_name.str().c_str());
0541             canvas->cd();
0542             int color = (iP == 0 ? kRed : kBlue);
0543             std::cout << "Print graph_mean" << std::endl;
0544             graph_mean->Print();
0545             graph_mean->SetLineColor(color);
0546             graph_mean->SetMarkerColor(color);
0547             graph_mean->SetMarkerStyle(kFullCircle);
0548             graph_mean->Draw("AP");
0549 
0550             graph_mean->SetMinimum(-0.05);
0551             graph_mean->SetMaximum(0.05);
0552 
0553             gPad->Update();
0554             gPad->Modified();
0555             double min_x = gPad->GetUxmin();
0556             double max_x = gPad->GetUxmax();
0557 
0558             TLine *tline = new TLine();
0559             tline->SetLineWidth(2);
0560             tline->SetLineColor(kBlack);
0561             tline->SetLineStyle(kDashed);
0562             tline->DrawLine(min_x, 0, max_x, 0);
0563 
0564             canvas->Draw();
0565             canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".png").c_str());
0566             canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".pdf").c_str());
0567 
0568             delete canvas;
0569           }
0570           {
0571             std::stringstream canvas_name;
0572             canvas_name << "canvas_" << graph_sigma->GetName();
0573             TCanvas *canvas = new TCanvas(canvas_name.str().c_str());
0574             canvas->cd();
0575             int color = (iP == 0 ? kRed : kBlue);
0576             std::cout << "Print graph_sigma" << std::endl;
0577             graph_sigma->Print();
0578             graph_sigma->SetLineColor(color);
0579             graph_sigma->SetMarkerColor(color);
0580             graph_sigma->SetMarkerStyle(kFullCircle);
0581             graph_sigma->Draw("AP");
0582 
0583             graph_sigma->SetMinimum(0.95);
0584             graph_sigma->SetMaximum(1.05);
0585 
0586             gPad->Update();
0587             gPad->Modified();
0588             double min_x = gPad->GetUxmin();
0589             double max_x = gPad->GetUxmax();
0590 
0591             TLine *tline = new TLine();
0592             tline->SetLineWidth(2);
0593             tline->SetLineColor(kBlack);
0594             tline->SetLineStyle(kDashed);
0595             tline->DrawLine(min_x, 1, max_x, 1);
0596 
0597             canvas->Draw();
0598             canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".png").c_str());
0599             canvas->SaveAs((local_plots_folder + "/" + canvas_name.str() + ".pdf").c_str());
0600 
0601             delete canvas;
0602           }
0603         }
0604       }
0605     }
0606   }
0607   gSystem->Exit(0);
0608 }