Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hera_dis_fillbins.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file hera_dis_fillbins.C
1 int
3 {
4  gSystem->Load("libeicsmear");
5 
6  /* Open input files. */
7  TFile *file_mc = new TFile("/gpfs/mnt/gpfs04/sphenix/user/nfeege/data/TEST/pythia.ep.27.5x820.1Mevents.RadCor=0.Q2gt1.root");
8 
9  /* Get trees from files. */
10  TTree *tree = (TTree*)file_mc->Get("EICTree");
11 
12  /* Output file. */
13  TFile *fout = new TFile("hera_dis_histo.root", "RECREATE");
14 
15  erhic::EventPythia *event = NULL;
16 
17  tree->SetBranchAddress("event", &event);
18 
19  /* Create n-dimensional histogram to collect statistic for SIDIS events in kinematics bins:
20  *
21  * Event properties:
22  * - x
23  * - Q2
24  */
25  const int nbins_x = 10;
26  const int nbins_Q2 = 10;
27 
28  const int hn_dis_ndim = 2;
29  int hn_dis_nbins[] = { nbins_x,
30  nbins_Q2 };
31  double hn_dis_xmin[] = {0., 0. };
32  double hn_dis_xmax[] = {0., 0. };
33 
34  THnSparse* hn_dis = new THnSparseF("hn_dis",
35  "DIS Kinematis; x; Q2;",
36  hn_dis_ndim,
37  hn_dis_nbins,
38  hn_dis_xmin,
39  hn_dis_xmax );
40 
41  hn_dis->GetAxis(0)->SetName("x");
42  hn_dis->GetAxis(1)->SetName("Q2");
43 
44  double min_x = -5;
45  double max_x = 0;
46  double width_x = (max_x - min_x) / nbins_x;
47  double bins_x[nbins_x+1];
48  for( int i =0; i <= nbins_x; i++)
49  {
50  cout << TMath::Power( 10, min_x + i*width_x) << endl;
51  bins_x[i] = TMath::Power( 10, min_x + i*width_x);
52  }
53 
54  double min_Q2 = 0;
55  double max_Q2 = 5;
56  double width_Q2 = (max_Q2 - min_Q2) / nbins_Q2;
57  double bins_Q2[nbins_Q2+1];
58  for( int i =0; i <= nbins_Q2; i++)
59  bins_Q2[i] = TMath::Power( 10, min_Q2 + i*width_Q2);
60 
61  hn_dis->SetBinEdges(0,bins_x);
62  hn_dis->SetBinEdges(1,bins_Q2);
63 
64  /* print all bin centers */
65  TH2F* hxQ2 = (TH2F*)hn_dis->Projection(1,0);
66  for ( int bin_x = 1; bin_x <= hxQ2->GetNbinsX(); bin_x++ )
67  {
68 
69  for ( int bin_y = 1; bin_y <= hxQ2->GetNbinsY(); bin_y++ )
70  {
71  cout << "x = " << TMath::Power(10, 0.5 * ( ( TMath::Log10( hxQ2->GetXaxis()->GetBinLowEdge(bin_x) ) )
72  + ( TMath::Log10( hxQ2->GetXaxis()->GetBinLowEdge(bin_x) + hxQ2->GetXaxis()->GetBinWidth(bin_x) ) ) ) ) << endl;
73 
74  cout << "Q2 = " << TMath::Power(10, 0.5 * ( ( TMath::Log10( hxQ2->GetYaxis()->GetBinLowEdge(bin_y) ) )
75  + ( TMath::Log10( hxQ2->GetYaxis()->GetBinLowEdge(bin_y) + hxQ2->GetYaxis()->GetBinWidth(bin_y) ) ) ) ) << endl;
76  }
77  }
78 
79  /* Loop over all events in tree. */
80  for ( unsigned ievent = 0; ievent < tree->GetEntries(); ievent++ )
81  {
82  if ( ievent%1000 == 0 )
83  cout << "Processing event " << ievent << endl;
84 
85  /* load event */
86  tree->GetEntry(ievent);
87 
88  /* Cut on scattered lepton properties */
89  float Emin = 5;
90  if ( event->ScatteredLepton()->GetE() < Emin )
91  continue;
92 
93  if ( event->ScatteredLepton()->GetTheta() >= ( 177./ 180. * TMath::Pi() ) )
94  continue;
95 
96  /* Cut on kinematics */
97  float x = event->GetTrueX();
98  float Q2 = event->GetTrueQ2();
99  float y = event->GetTrueY();
100 
101  if ( Q2 < 1 )
102  continue;
103 
104  if ( y >= 0.9 || y <= 0.01 )
105  continue;
106 
107 
108  double fill_hn_dis[] = {x, Q2};
109  hn_dis->Fill( fill_hn_dis );
110  }
111 
112  /* Write histogram. */
113  hn_dis->Write();
114 
115  /* Close output file. */
116  fout->Close();
117 
118  return 0;
119 }