Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
trackpT.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file trackpT.C
1 #include <iostream>
2 using namespace std;
3 
4 #include "TFile.h"
5 #include "TTree.h"
6 #include "TChain.h"
7 #include "TLegend.h"
8 #include "math.h"
9 #include "TH1.h"
10 #include "TH2.h"
11 #include "TEfficiency.h"
12 #include "TLine.h"
13 #include "TGraphAsymmErrors.h"
14 
15 TChain* handleFile(string name, string extension, string treename, unsigned int filecount){
16  TChain *all = new TChain(treename.c_str());
17  string temp;
18  for (int i = 0; i < filecount; ++i)
19  {
20 
21  ostringstream s;
22  s<<i;
23  temp = name+string(s.str())+extension;
24  all->Add(temp.c_str());
25  }
26  return all;
27 }
28 
29 void trackpT()
30 {
31  float electron_pt[200];
32  float positron_pt[200];
33  float electron_reco_pt[200];
34  float positron_reco_pt[200];
35  double rVtx[200];
36  int b_layer[20];
37  int truth_n;
38  int reco_n;
39  int nVtx;
40 
41 
42  string treePath = "/sphenix/user/vassalli/gammasample/fourembededonlineanalysis";
43  string treeExtension = ".root";
44  unsigned int nFiles=100;
45  TChain *ttree = handleFile(treePath,treeExtension,"ttree",nFiles);
46  ttree->SetBranchAddress("electron_pt", &electron_pt );
47  ttree->SetBranchAddress("electron_reco_pt",&electron_reco_pt );
48  ttree->SetBranchAddress("positron_pt", &positron_pt );
49  ttree->SetBranchAddress("positron_reco_pt",&positron_reco_pt );
50  ttree->SetBranchAddress("nTpair", &truth_n );
51  ttree->SetBranchAddress("nRpair", &reco_n );
52  ttree->SetBranchAddress("fLayer", &b_layer );
53  ttree->SetBranchAddress("nVtx", &nVtx );
54  ttree->SetBranchAddress("rVtx", &rVtx );
55 
56 
57  string outfilename = "pTeffdists.root";
58  TFile *out = new TFile(outfilename.c_str(),"RECREATE");
59 
60  TH1F *h_TepT = new TH1F("TepT","",100,0,30);
61  TH1F *h_RepT = new TH1F("RepT","",100,0,30);
62 
63  TH1F *h_rvtx = new TH1F("rvtx","",100,0,30);
64  TH1F *h_layer = new TH1F("layer","",24,-.5,23.5);
65 
66  h_TepT->GetXaxis()->SetTitle("pT");
67  h_TepT->GetYaxis()->SetTitle("N");
68  h_RepT->GetXaxis()->SetTitle("pT");
69  h_RepT->GetYaxis()->SetTitle("N");
70 
71  h_rvtx->GetXaxis()->SetTitle("radius [cm]");
72  h_rvtx->GetYaxis()->SetTitle("N");
73 
74  for (int event = 0; event < ttree->GetEntries(); ++event)
75  {
76  ttree->GetEvent(event);
77  for (int i = 0; i < truth_n; ++i)
78  {
79  h_RepT->Fill(electron_reco_pt[i]);
80  h_RepT->Fill(positron_reco_pt[i]);
81  }
82  for (int i = 0; i < nVtx; ++i)
83  {
84  h_TepT->Fill(electron_pt[i]);
85  h_TepT->Fill(positron_pt[i]);
86  h_rvtx->Fill(rVtx[i]);
87  }
88  for (int i = 0; i < reco_n; ++i)
89  {
90  h_layer->Fill(b_layer[i]);
91  }
92  }
93  out->Write();
94  out->Close();
95  delete ttree;
96  delete out;
97 }