Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ana_hijbkg.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ana_hijbkg.C
1 // This macro reads and analyzes the TTree created in hijbkg_upc.cc
2 //
3 
4 #include <cmath>
5 #include <TFile.h>
6 #include <TTree.h>
7 #include <TMath.h> // Include the TMath header for trigonometric functions
8 #include <TH1F.h>
9 #include <TCanvas.h>
10 #include <TParticle.h>
11 #include <TDatabasePDG.h>
12 
13 void ana_hijbkg(const char* filename = "hijbkg.root")
14 {
15  TDatabasePDG *pdg = new TDatabasePDG;
16 
17  TFile *tfile= new TFile(filename,"READ");
18  TTree* tree = (TTree*)tfile->Get("T"); // the TTree in the HIJING file
19 
20  vector<float> *m_pt = 0;
21  Int_t m_evt = 0;
22  Float_t m_b = 0;
23  Float_t m_cent = 0;
24  TParticle *m_part[2] = {0};
25 
26  //set the branches of the tree
27  tree->SetBranchAddress("evt", &m_evt);
28  tree->SetBranchAddress("b", &m_b);
29  tree->SetBranchAddress("part0", &m_part[0]);
30  tree->SetBranchAddress("part1", &m_part[1]);
31 
32  TFile *savefile = new TFile("hijbkg_results.root","RECREATE");
33 
34  // Plot histograms for pt, eta, phi, mass
35  TH1F *h_pt = new TH1F("h_pt", "Pt Distribution", 200, 0, 2.0 );
36  TH1F *h_eta = new TH1F("h_eta", "Eta Distribution", 200, -6, 6 );
37  TH1F *h_rap = new TH1F("h_rap", "Rapidity Distribution", 200, -4, 4 );
38  TH1F *h_phi = new TH1F("h_phi", "Phi Distribution", 100, -M_PI, M_PI );
39  TH1F *h_dphi = new TH1F("h_dphi", "dPhi Distribution", 100, -M_PI, M_PI );
40  TH1F *h_mass = new TH1F("h_mass", "Inv Mass", 200, 0., 6.);
41  h_pt->SetLineColor(4);
42  h_eta->SetLineColor(4);
43  h_phi->SetLineColor(4);
44  h_mass->SetLineColor(4);
45 
46  // Assuming all tracks are electrons
47  TH1F *he_pt = new TH1F("he_pt", "Pt, assuming e+/e-", 200, 0, 2.0 );
48  TH1F *he_eta = new TH1F("he_eta", "Eta, assuming e+/e- ", 200, -6, 6 );
49  TH1F *he_rap = new TH1F("he_rap", "Rapidity, assuming e+/e-", 200, -4, 4 );
50  TH1F *he_phi = new TH1F("he_phi", "Phi, assuming e+/e- ", 100, -M_PI, M_PI );
51  TH1F *he_dphi = new TH1F("he_dphi", "dPhi, assuming e+/e- ", 100, -M_PI, M_PI );
52  TH1F *he_mass = new TH1F("he_mass", "Mass, assuming e+/e-", 200, 0., 6.);
53 
54  // With cut on J/Psi mass
55  TH1F *hej_pt = new TH1F("hej_pt", "Pt, J/Psi mass cut", 200, 0, 2.0 );
56  TH1F *hej_eta = new TH1F("hej_eta", "Eta, J/Psi mass cut ", 200, -6, 6 );
57  TH1F *hej_rap = new TH1F("hej_rap", "Rapidity, J/Psi mass cut", 200, -4, 4 );
58  TH1F *hej_dphi = new TH1F("hej_dphi", "dPhi, J/Psi mass cut", 100, -M_PI, M_PI );
59  hej_pt->SetLineColor(2);
60  hej_eta->SetLineColor(2);
61  hej_rap->SetLineColor(2);
62  hej_dphi->SetLineColor(2);
63  hej_pt->SetXTitle("#p_T (GeV/c)");
64 
65  TLorentzVector part_v4[2];
66  TLorentzVector sum_v4;
67 
68  TLorentzVector epart_v4[2]; // assuming these are e+/e- pairs
69  TLorentzVector esum_v4;
70 
71  // Loop over the tree
72  Int_t nEntries = tree->GetEntries();
73  for (int iEntry = 0; iEntry < nEntries; iEntry++)
74  {
75  tree->GetEntry(iEntry);
76 
77  // Print out a message every 1000 events
78  if ( iEntry%10000 == 0 ) cout << iEntry << "\t" << m_evt << endl;
79 
80  //cout << m_part[0]->GetPdgCode() << "\t" << m_part[0]->Px() << endl;
81 
82  Double_t charge[2];
83  for (int ipart=0; ipart<2; ipart++)
84  {
85  charge[ipart] = m_part[ipart]->GetPDG()->Charge();
86 
87  if ( fabs( m_part[ipart]->GetPDG()->PdgCode() ) == 11 )
88  {
89  cout << m_part[ipart]->GetPDG()->PdgCode() << "\t" << charge[ipart] << endl;
90  }
91 
92  double px = m_part[ipart]->Px();
93  double py = m_part[ipart]->Py();
94  double pz = m_part[ipart]->Pz();
95 
96  part_v4[ipart].SetPxPyPzE( px, py, pz, m_part[ipart]->Energy() );
97 
98  // now assume this is an electron
99  const double m_e = 0.511e-3; // e- mass in GeV
100  double e_energy = sqrt( px*px + py*py + pz*pz + m_e*m_e );
101  epart_v4[ipart].SetPxPyPzE( px, py, pz, e_energy );
102 
103 
104  // check for bad eta
105  if ( fabs(part_v4[ipart].Eta()) > 1.1 )
106  {
107  cout << "ERROR " << iEntry << m_part[ipart]->GetPdgCode() << endl;
108  }
109  }
110 
111  // skip if they are like sign pairs
112  if ( charge[0]*charge[1] > 0 )
113  {
114  continue;
115  }
116 
117  sum_v4 = part_v4[0] + part_v4[1];
118  esum_v4 = epart_v4[0] + epart_v4[1];
119 
120  // Fill the histograms with the data from the TTree
121  h_pt->Fill( sum_v4.Pt() );
122  h_eta->Fill( sum_v4.Eta() );
123  h_phi->Fill( sum_v4.Phi() );
124  h_mass->Fill( sum_v4.M() );
125  h_rap->Fill( sum_v4.Rapidity() );
126  h_dphi->Fill( part_v4[0].DeltaPhi( part_v4[1] ) );
127 
128  // electron PID assumption
129  he_pt->Fill( esum_v4.Pt() );
130  he_eta->Fill( esum_v4.Eta() );
131  he_phi->Fill( esum_v4.Phi() );
132  he_mass->Fill( esum_v4.M() );
133  he_rap->Fill( esum_v4.Rapidity() );
134  he_dphi->Fill( epart_v4[0].DeltaPhi( epart_v4[1] ) );
135 
136  // in J/Psi mass window
137  if ( fabs( esum_v4.M() - 3.1 ) < 0.3 )
138  {
139  hej_pt->Fill( esum_v4.Pt() );
140  hej_eta->Fill( esum_v4.Eta() );
141  hej_rap->Fill( esum_v4.Rapidity() );
142  hej_dphi->Fill( epart_v4[0].DeltaPhi( epart_v4[1] ) );
143  }
144  }
145 
146  // Draw and save the histograms
147  TCanvas *ac = new TCanvas("ac","pt",550,425);
148  h_pt->SetMinimum(0.5);
149  h_pt->Draw();
150  he_pt->Draw("same");
151  hej_pt->Draw("same");
152  gPad->SetLogy(1);
153  ac->SaveAs("h_pt.png");
154 
155  TCanvas *dc = new TCanvas("dc","eta",550,425);
156  h_eta->SetMinimum(0.5);
157  h_eta->Draw();
158  he_eta->Draw("same");
159  hej_eta->Draw("same");
160  dc->SaveAs("h_eta.png");
161 
162  TCanvas *fc = new TCanvas("fc","rapidity",550,425);
163  h_rap->SetMinimum(0.5);
164  h_rap->Draw();
165  he_rap->Draw("same");
166  hej_rap->Draw("same");
167  dc->SaveAs("h_eta.png");
168 
169  TCanvas *bc = new TCanvas("bc","phi",550,425);
170  h_phi->SetMinimum(0.5);
171  h_phi->Draw();
172  he_phi->Draw("same");
173  bc->SaveAs("h_phi.png");
174 
175  TCanvas *gc = new TCanvas("gc","dphi",550,425);
176  h_dphi->SetMinimum(0.5);
177  h_dphi->Draw();
178  he_dphi->Draw("same");
179  hej_dphi->Draw("same");
180  dc->SaveAs("h_eta.png");
181 
182  TCanvas *ec = new TCanvas("ec","mass",550,425);
183  h_mass->SetMinimum(0.5);
184  h_mass->Draw();
185  he_mass->Draw("same");
186  gPad->SetLogy(1);
187  ec->SaveAs("h_mass.png");
188 
189  savefile->Write();
190 }