Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FitSlices.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FitSlices.C
1 int
2 FitSlices( TString fname )
3 {
4 
5  /* Get input 3D histogram */
6  TFile *fin = new TFile( fname, "OPEN");
7  TH3F *hin3D = (TH3F*)fin->Get("MomMagMap");
8 
9  /* Get bin counts for each axis */
10  cout << "X axis = " << hin3D->GetXaxis()->GetTitle() << endl;
11  cout << "Y axis = " << hin3D->GetYaxis()->GetTitle() << endl;
12  cout << "Z axis = " << hin3D->GetZaxis()->GetTitle() << endl;
13 
14  unsigned nbins_ptrue = hin3D->GetXaxis()->GetNbins();
15  unsigned nbins_eta = hin3D->GetYaxis()->GetNbins();
16  unsigned nbins_pdiff = hin3D->GetZaxis()->GetNbins();
17 
18  /* Fit all slices in eta-ptrue */
19  hin3D->FitSlicesZ();
20 
21  /* Open ofstream for output to csv file */
22  ofstream ofs("fitslices_out.csv");
23 
24  /* Loop over eta bins & slice */
25  TH2D* HistMomMagMap_0 = (TH2D*)gDirectory->Get("HistMomMagMap_0");
26  TH2D* HistMomMagMap_1 = (TH2D*)gDirectory->Get("HistMomMagMap_1");
27  TH2D* HistMomMagMap_2 = (TH2D*)gDirectory->Get("HistMomMagMap_2");
28 
29  for ( unsigned bin_eta = 1; bin_eta <= nbins_eta; bin_eta++ )
30  {
31 
32  for ( unsigned bin_ptrue = 1; bin_ptrue <= nbins_ptrue; bin_ptrue++ )
33  {
34 
35  double eta_i = HistMomMagMap_1->GetYaxis()->GetBinCenter(bin_eta);
36  double ptrue_i = HistMomMagMap_1->GetXaxis()->GetBinCenter(bin_ptrue);
37 
38  /* Access fit parameters */
39  double norm_i = HistMomMagMap_0->GetBinContent(bin_ptrue,bin_eta);
40  double mean_i = HistMomMagMap_1->GetBinContent(bin_ptrue,bin_eta);
41  double sigm_i = HistMomMagMap_2->GetBinContent(bin_ptrue,bin_eta);
42 
43  double mean_err_i = HistMomMagMap_1->GetBinError(bin_ptrue,bin_eta);
44  double sigm_err_i = HistMomMagMap_2->GetBinError(bin_ptrue,bin_eta);
45 
46  cout << eta_i << " " << ptrue_i << " " << norm_i << " " << mean_i << " " << sigm_i << " " << mean_err_i << " " << sigm_err_i << endl;
47 
48 
49  /* For Giorgian */
50  ofs << ptrue_i << "," << eta_i << "," << sigm_i << "," << sigm_err_i << "," << mean_i << "," << mean_err_i << "," << norm_i << endl;
51 
52  }
53 
54  }
55 
56  /* Close ofstream */
57  ofs.close();
58 
59  /* Loop over momentum bins & slice */
60 
61  /* Fit gaussian to 1D histogram */
62 
63  /* Store fit parameters */
64 
65  return 0;
66 }