Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
calculate_g1_projection_per_bin.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file calculate_g1_projection_per_bin.C
1 #include "calculate_g1.C"
2 
3 int
5 {
6  TFile *fin = new TFile(fin_name,"OPEN");
7  THnSparse *hfull = (THnSparse*)fin->Get("hn_dis_electron_accept");
8 
9  TH2F* hxQ2 = (TH2F*)hfull->Projection(1,0);
10  hxQ2->SetName("hxQ2");
11 
12  /* beam energies */
13  float ebeam_e = 18;
14  float ebeam_p = 275;
15 
16  /* Retrieve Pythia generated events luminosity information */
17  /* @TODO: Get this from string in file */
18  TObjString* gen_crossSection_s = (TObjString*)fin->Get("crossSection");
19  TObjString* gen_nEvents_s = (TObjString*)fin->Get("nEvents");
20  TObjString* gen_lumi_ifb_s = (TObjString*)fin->Get("luminosity");
21 
22  float gen_crossSection_mb = (TString((gen_crossSection_s)->GetName())).Atof(); // microbarn (10^-6) from pythiaeRHIC
23  float gen_nEvents = (TString((gen_nEvents_s)->GetName())).Atof();
24  float gen_lumi_ifb = (TString((gen_lumi_ifb_s)->GetName())).Atof();
25 
26  float target_lumi_ifb = 10.;
27 
28  cout << "Pythia cross section (microbarn): " << gen_crossSection_mb << " mb" << endl;
29  //cout << "Pythia cross section (femtobarn): " << gen_crossSection_fb << " fb" << endl;
30  cout << "Pythia generated (scaled) luminosity: " << gen_lumi_ifb << " fb^-1" << endl;
31  cout << "Target luminosity: " << target_lumi_ifb << " fb^-1" << endl;
32 
33  /* create tree to store information */
34  TTree *tcount = new TTree("tcount", "A tree with counts in kinematics bins");
35  float t_pbeam_lepton = 0;
36  float t_pbeam_proton = 0;
37  float t_lumi_ifb = 0;
38  float t_s = 0;
39  float t_x = 0;
40  float t_Q2 = 0;
41  float t_y = 0;
42  float t_N = 0;
43  float t_stdev_N = 0;
44  float t_stdev_g1 = 0;
45  float t_stdev_A1 = 0;
46  tcount->Branch("pbeam_lepton", &t_pbeam_lepton, "pbeam_lepton/F");
47  tcount->Branch("pbeam_proton", &t_pbeam_proton, "pbeam_proton/F");
48  tcount->Branch("luminosity", &t_lumi_ifb, "luminosity/F"); // in inverse femtobarn
49  tcount->Branch("s", &t_s, "s/F");
50  tcount->Branch("x", &t_x, "x/F");
51  tcount->Branch("Q2", &t_Q2, "Q2/F");
52  tcount->Branch("y", &t_y, "y/F");
53  tcount->Branch("N", &t_N, "N/F");
54  tcount->Branch("stdev_N", &t_stdev_N, "stdev_N/F");
55  tcount->Branch("stdev_g1", &t_stdev_g1, "stdev_g1/F");
56  tcount->Branch("stdev_A1", &t_stdev_A1, "stdev_A1/F");
57 
58  /* copy beam parameters */
59  t_pbeam_lepton = ebeam_e;
60  t_pbeam_proton = ebeam_p;
61  t_lumi_ifb = gen_lumi_ifb;
62 
63  /* center of mass energy */
64  t_s = 4 * ebeam_e * ebeam_p;
65 
66  /* collect all x-bins */
67  set<float> s_binc_x;
68 
69  /* loop over all bins */
70  for ( int bin_x = 1; bin_x <= hxQ2->GetNbinsX(); bin_x++ )
71  {
72  for ( int bin_y = 1; bin_y <= hxQ2->GetNbinsY(); bin_y++ )
73  {
74  t_x = TMath::Power(10, 0.5 * ( ( TMath::Log10( hxQ2->GetXaxis()->GetBinLowEdge(bin_x) ) )
75  + ( TMath::Log10( hxQ2->GetXaxis()->GetBinLowEdge(bin_x) + hxQ2->GetXaxis()->GetBinWidth(bin_x) ) ) ) );
76 
77  t_Q2 = TMath::Power(10, 0.5 * ( ( TMath::Log10( hxQ2->GetYaxis()->GetBinLowEdge(bin_y) ) )
78  + ( TMath::Log10( hxQ2->GetYaxis()->GetBinLowEdge(bin_y) + hxQ2->GetYaxis()->GetBinWidth(bin_y) ) ) ) );
79 
80  t_y = t_Q2 / ( t_x * t_s );
81 
82  t_N = (float)hxQ2->GetBinContent( bin_x, bin_y ) * (target_lumi_ifb / gen_lumi_ifb);
83 
84  /* skip bins with no entries */
85  if ( t_N < 1 )
86  continue;
87 
88  t_stdev_N = 1./(sqrt(t_N));
89  t_stdev_g1 = get_g1_sigma( t_x, t_Q2, t_y, t_N, 0.000511 );
90  t_stdev_A1 = get_A1_sigma( t_x, t_Q2, t_y, t_N, 0.000511 );
91 
92  tcount->Fill();
93  s_binc_x.insert(t_x);
94 
95  /* print values */
96  std::cout.precision(3);
97 
98  cout << "lepton = " << std::fixed << t_pbeam_lepton
99  << " x proton = " << std::fixed << t_pbeam_proton
100  << " , L = " << std::fixed << t_lumi_ifb << " fb^-1"
101  << " , sqrt(s) = " << std::fixed << sqrt( t_s ) << " GeV"
102  << " , x = " << std::scientific << t_x
103  << " , Q2 = " << std::scientific << t_Q2
104  << " , y = " << std::fixed << t_y
105  << " , N = " << std::scientific << t_N
106  << " , g1 = " << std::fixed << -1
107  << " , g1_stdev = " << std::fixed << t_stdev_g1
108  << " , A1_stdev = " << std::fixed << t_stdev_A1
109  << endl;
110  }
111  }
112 
113  /* create tree to store information */
114  TFile *fout = new TFile("output/eic_sphenix_dis_tree.root", "RECREATE");
115  fout->cd();
116 
117  /* save input histogram in output */
118  hxQ2->Write();
119 
120  /* Write tree to output */
121  tcount->Write();
122 
123  /* copy string */
124  gen_lumi_ifb_s->Write("luminosity");
125 
126  /* close file */
127  fout->Close();
128 
129  return 0;
130 }