Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
eic_unsmeared_eta_p.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file eic_unsmeared_eta_p.C
1 // A quick look at the momentum vs pseudorapidity of the unsmeared particles
2 // Currently loads both smeared and unsmeared input files for later use
3 // Only unsmeared input file used right now
4 
5 // --------------------------
6 
7 /* STL includes */
8 #include <iostream>
9 
10 /* ROOT includes */
11 #include <TROOT.h>
12 //#include <gSystem.h>
13 #include <TFile.h>
14 #include <TTree.h>
15 #include <TH2F.h>
16 #include <THnSparse.h>
17 
18 /* eicsmear includes */
19 //#include <eicsmear/erhic/EventPythia.h>
20 //#include <eicsmear/erhic/ParticleMC.h>
21 
22 using namespace std;
23 
24 int
25 eic_unsmeared_eta_p( TString filename_output,
26  TString filename_mc,
27  TString filename_mc_smeared = "",
28  bool debug = false )
29 {
30  /* Uncomment this line when running without compilation */
31  gSystem->Load("libeicsmear");
32 
33  /* Open input files. */
34  TFile *file_mc = new TFile(filename_mc, "OPEN");
35  TFile *file_mc_smeared = new TFile(filename_mc_smeared, "OPEN");
36 
37  /* Get trees from files. */
38  TTree *tree = (TTree*)file_mc->Get("EICTree");
39  TTree *tree_smeared = (TTree*)file_mc_smeared->Get("Smeared");
40 
41  /* Output file. */
42  TFile *file_out = new TFile(filename_output, "RECREATE");
43 
44  /* Add friend to match branches in trees. */
45  tree->AddFriend(tree_smeared);
46 
47  erhic::EventPythia *event = NULL;
48  Smear::Event *eventS = NULL;
49 
50  tree->SetBranchAddress("event", &event);
51  tree->SetBranchAddress("eventS", &eventS);
52 
53  /* Create histogram for eta versus momentum. */
54  TH2F* h_eta = new TH2F("h_eta","Momentum vs. Pseudorapidity",80,-4,4,45,-5,40 );
55  TH2F* h_eta_accept = (TH2F*)h_eta->Clone("h_eta_accept");
56  h_eta->GetXaxis()->SetTitle("#eta");
57  h_eta->GetYaxis()->SetTitle("Momentum (GeV)");
58 
59  /* Create canvas */
60  TCanvas *c1 = new TCanvas;
61  h_eta->Draw("AXIS");
62 
63  /* Loop over all events in tree. */
64  unsigned max_event = tree->GetEntries();
65 
66  for ( unsigned ievent = 0; ievent < max_event; ievent++ )
67  {
68  if ( ievent%1000 == 0 )
69  cout << "Processing event " << ievent << endl;
70 
71  /* load event */
72  tree->GetEntry(ievent);
73 
74  /* Cut on EVENT kinematics */
75  float y = event->GetTrueY();
76  if ( y > 0.99 || y < 0.01 )
77  continue;
78 
79  float eta = event->ScatteredLepton()->GetEta();
80  float p = event->ScatteredLepton()->GetP();
81 
82  h_eta->Fill(eta,p);
83 
84  } // end loop over events
85 
86  /* Write histogram. */
87 
88  h_eta->Write();
89  h_eta_accept->Write();
90 
91  /*draw histogram */
92 
93  h_eta->Draw("COLZ");
94  h_eta->Draw("sameaxis");
95  return c1;
96 
97  /* Close output file. */
98  file_out->Close();
99 
100  return 0;
101 }