Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-04-06 08:08:18

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